1 package net.sf.openrocket.file.rocksim.export;
3 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
4 import net.sf.openrocket.rocketcomponent.BodyTube;
5 import net.sf.openrocket.rocketcomponent.NoseCone;
6 import net.sf.openrocket.rocketcomponent.RocketComponent;
7 import net.sf.openrocket.rocketcomponent.Stage;
8 import net.sf.openrocket.rocketcomponent.Transition;
9 import net.sf.openrocket.util.ArrayList;
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElementRef;
14 import javax.xml.bind.annotation.XmlElementRefs;
15 import java.util.List;
18 * Placeholder for a Rocksim Stage.
20 @XmlAccessorType(XmlAccessType.FIELD)
21 public class StageDTO {
24 @XmlElementRef(name = RocksimCommonConstants.BODY_TUBE, type = BodyTubeDTO.class),
25 @XmlElementRef(name = RocksimCommonConstants.NOSE_CONE, type = NoseConeDTO.class),
26 @XmlElementRef(name = RocksimCommonConstants.TRANSITION, type = TransitionDTO.class)
28 private List<BasePartDTO> externalPart = new ArrayList<BasePartDTO>();
31 * Default constructor.
39 * @param theORStage the OR stage
40 * @param design the encompassing container DTO
41 * @param stageNumber the stage number (3 is always at the top, even if it's the only one)
43 public StageDTO(Stage theORStage, RocketDesignDTO design, int stageNumber) {
45 if (stageNumber == 3) {
46 if (theORStage.isMassOverridden()) {
47 design.setStage3Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
48 design.setUseKnownMass(1);
50 if (theORStage.isCGOverridden()) {
51 design.setStage3CG(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
55 if (stageNumber == 2) {
56 if (theORStage.isMassOverridden()) {
57 design.setStage2Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
58 design.setUseKnownMass(1);
60 if (theORStage.isCGOverridden()) {
61 design.setStage2CGAlone(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
65 if (stageNumber == 1) {
66 if (theORStage.isMassOverridden()) {
67 design.setStage1Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
68 design.setUseKnownMass(1);
70 if (theORStage.isCGOverridden()) {
71 design.setStage1CGAlone(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
75 List<RocketComponent> children = theORStage.getChildren();
76 for (int i = 0; i < children.size(); i++) {
77 RocketComponent rocketComponents = children.get(i);
78 if (rocketComponents instanceof NoseCone) {
79 addExternalPart(toNoseConeDTO((NoseCone) rocketComponents));
80 } else if (rocketComponents instanceof BodyTube) {
81 addExternalPart(toBodyTubeDTO((BodyTube) rocketComponents));
82 } else if (rocketComponents instanceof Transition) {
83 addExternalPart(toTransitionDTO((Transition) rocketComponents));
88 public List<BasePartDTO> getExternalPart() {
92 public void addExternalPart(BasePartDTO theExternalPartDTO) {
93 externalPart.add(theExternalPartDTO);
96 private NoseConeDTO toNoseConeDTO(NoseCone nc) {
97 return new NoseConeDTO(nc);
100 private BodyTubeDTO toBodyTubeDTO(BodyTube bt) {
101 return new BodyTubeDTO(bt);
104 private TransitionDTO toTransitionDTO(Transition tran) {
105 return new TransitionDTO(tran);