From 8d488430a2c174141e267d72a8ea3551bb3826b8 Mon Sep 17 00:00:00 2001 From: Doug Pedrick Date: Sun, 22 Jan 2012 22:58:08 +0000 Subject: [PATCH] DGP - minor refactorings and added JavaDoc --- .../file/rocksim/RocksimCommonConstants.java | 3 + .../rocksim/export/AbstractTransitionDTO.java | 2 +- .../file/rocksim/export/AttachableParts.java | 21 ++++ .../file/rocksim/export/AttachedParts.java | 9 -- .../file/rocksim/export/BodyTubeDTO.java | 37 ++++--- .../file/rocksim/export/BulkheadDTO.java | 6 +- .../file/rocksim/export/CenteringRingDTO.java | 34 +++++-- .../file/rocksim/export/EngineBlockDTO.java | 13 ++- .../file/rocksim/export/FinSetDTO.java | 43 ++++---- .../file/rocksim/export/InnerBodyTubeDTO.java | 98 +++++++++++-------- .../file/rocksim/export/LaunchLugDTO.java | 19 +++- .../file/rocksim/export/MassObjectDTO.java | 2 +- .../file/rocksim/export/NoseConeDTO.java | 3 +- .../file/rocksim/export/ParachuteDTO.java | 26 +++-- .../file/rocksim/export/RocketDesignDTO.java | 5 + .../file/rocksim/export/StageDTO.java | 35 ++++--- .../file/rocksim/export/StreamerDTO.java | 17 +++- .../file/rocksim/export/TransitionDTO.java | 26 +++-- .../rocksim/importt/AttachedPartsHandler.java | 6 +- .../file/rocksim/importt/FinSetHandler.java | 48 ++++----- .../file/rocksim/importt/RocksimHandler.java | 12 +-- .../gui/configdialog/InnerTubeConfig.java | 63 ++++++------ 22 files changed, 327 insertions(+), 201 deletions(-) create mode 100644 core/src/net/sf/openrocket/file/rocksim/export/AttachableParts.java delete mode 100644 core/src/net/sf/openrocket/file/rocksim/export/AttachedParts.java diff --git a/core/src/net/sf/openrocket/file/rocksim/RocksimCommonConstants.java b/core/src/net/sf/openrocket/file/rocksim/RocksimCommonConstants.java index f0d9c859c..d44ef1a27 100644 --- a/core/src/net/sf/openrocket/file/rocksim/RocksimCommonConstants.java +++ b/core/src/net/sf/openrocket/file/rocksim/RocksimCommonConstants.java @@ -102,4 +102,7 @@ public class RocksimCommonConstants { * Radius conversion. Rocksim is always in diameters, OpenRocket mostly in radius. */ public static final int ROCKSIM_TO_OPENROCKET_RADIUS = 2 * ROCKSIM_TO_OPENROCKET_LENGTH; + public static final String TUBE_FIN_SET = "TubeFinSet"; + public static final String RING_TAIL = "RingTail"; + public static final String EXTERNAL_POD = "ExternalPod"; } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/AbstractTransitionDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/AbstractTransitionDTO.java index d729ebdd3..987bc2033 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/AbstractTransitionDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/AbstractTransitionDTO.java @@ -29,7 +29,7 @@ import java.util.List; * Transition to a Rocksim Transition. */ @XmlAccessorType(XmlAccessType.FIELD) -public class AbstractTransitionDTO extends BasePartDTO implements AttachedParts { +public class AbstractTransitionDTO extends BasePartDTO implements AttachableParts { @XmlElement(name = RocksimCommonConstants.SHAPE_CODE) private int shapeCode = 1; diff --git a/core/src/net/sf/openrocket/file/rocksim/export/AttachableParts.java b/core/src/net/sf/openrocket/file/rocksim/export/AttachableParts.java new file mode 100644 index 000000000..61b6f4ddd --- /dev/null +++ b/core/src/net/sf/openrocket/file/rocksim/export/AttachableParts.java @@ -0,0 +1,21 @@ +package net.sf.openrocket.file.rocksim.export; + +/** + * An interface that defines methods for attaching and detaching child components. Rocksim has a special + * XML element that acts as a container, called
. Implementors of + * this interface are those Rocksim DTO classes that support the attached parts element. + */ +public interface AttachableParts { + /** + * Remove a previously attached part from this component. + * + * @param part the instance to remove + */ + void removeAttachedPart(BasePartDTO part); + + /** + * Attach (associate) a DTO with this component. + * @param part + */ + void addAttachedPart(BasePartDTO part); +} diff --git a/core/src/net/sf/openrocket/file/rocksim/export/AttachedParts.java b/core/src/net/sf/openrocket/file/rocksim/export/AttachedParts.java deleted file mode 100644 index a7a8c307d..000000000 --- a/core/src/net/sf/openrocket/file/rocksim/export/AttachedParts.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.sf.openrocket.file.rocksim.export; - -/** - */ -public interface AttachedParts { - void removeAttachedPart(BasePartDTO part); - - void addAttachedPart(BasePartDTO part); -} diff --git a/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java index 3a043a0cf..4f9f708d9 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java @@ -27,10 +27,11 @@ import java.util.ArrayList; import java.util.List; /** + * Models the XML element for a Rocksim body tube. */ @XmlRootElement(name = RocksimCommonConstants.BODY_TUBE) @XmlAccessorType(XmlAccessType.FIELD) -public class BodyTubeDTO extends BasePartDTO implements AttachedParts { +public class BodyTubeDTO extends BasePartDTO implements AttachableParts { @XmlElement(name = RocksimCommonConstants.OD) private double od = 0d; @@ -57,28 +58,42 @@ public class BodyTubeDTO extends BasePartDTO implements AttachedParts { @XmlElementRef(name = RocksimCommonConstants.MASS_OBJECT, type = MassObjectDTO.class)}) List attachedParts = new ArrayList(); + /** + * Constructor. + */ public BodyTubeDTO() { } - public BodyTubeDTO(InnerTube inner) { - super(inner); + /** + * Copy constructor. + * + * @param theORInnerTube an OR inner tube; used by subclasses + */ + protected BodyTubeDTO(InnerTube theORInnerTube) { + super(theORInnerTube); } - protected BodyTubeDTO(BodyTube bt) { - super(bt); + /** + * Copy constructor. + * + * @param theORBodyTube an OR body tube + */ + protected BodyTubeDTO(BodyTube theORBodyTube) { + super(theORBodyTube); - setEngineOverhang(bt.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setID(bt.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOD(bt.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setMotorDia((bt.getMotorMountDiameter() / 2) * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setMotorMount(bt.isMotorMount()); + setEngineOverhang(theORBodyTube.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setID(theORBodyTube.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setOD(theORBodyTube.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setMotorDia((theORBodyTube.getMotorMountDiameter() / 2) * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setMotorMount(theORBodyTube.isMotorMount()); - List children = bt.getChildren(); + List children = theORBodyTube.getChildren(); for (int i = 0; i < children.size(); i++) { RocketComponent rocketComponents = children.get(i); if (rocketComponents instanceof InnerTube) { final InnerTube innerTube = (InnerTube) rocketComponents; final InnerBodyTubeDTO innerBodyTubeDTO = new InnerBodyTubeDTO(innerTube, this); + //Only add the inner tube if it is NOT a cluster. if (innerTube.getClusterCount() == 1) { attachedParts.add(innerBodyTubeDTO); } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/BulkheadDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/BulkheadDTO.java index 847c7dc23..e8b78e11f 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/BulkheadDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/BulkheadDTO.java @@ -17,10 +17,10 @@ public class BulkheadDTO extends CenteringRingDTO { /** * Constructor. * - * @param bh bulkhead + * @param theORBulkhead the OR bulkhead */ - public BulkheadDTO(Bulkhead bh) { - super(bh); + public BulkheadDTO(Bulkhead theORBulkhead) { + super(theORBulkhead); setUsageCode(CenteringRingDTO.UsageCode.Bulkhead); } } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/CenteringRingDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/CenteringRingDTO.java index 742999a37..e925c10f2 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/CenteringRingDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/CenteringRingDTO.java @@ -42,20 +42,34 @@ public class CenteringRingDTO extends BasePartDTO { @XmlElement(name = RocksimCommonConstants.AUTO_SIZE) private int autoSize = 0; + /** + * Default Constructor. + */ public CenteringRingDTO() { - - } - public CenteringRingDTO(RadiusRingComponent cr) { - super(cr); - setId(cr.getInnerRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOd(cr.getOuterRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); } - public CenteringRingDTO(ThicknessRingComponent trc) { - super(trc); - setId(trc.getInnerRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOd(trc.getOuterRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + /** + * Copy constructor. + * + * @param theORRadiusRing + */ + public CenteringRingDTO(RadiusRingComponent theORRadiusRing) { + super(theORRadiusRing); + setId(theORRadiusRing.getInnerRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setOd(theORRadiusRing.getOuterRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); } + + /** + * Copy constructor. + * + * @param theORThicknessRing + */ + public CenteringRingDTO(ThicknessRingComponent theORThicknessRing) { + super(theORThicknessRing); + setId(theORThicknessRing.getInnerRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setOd(theORThicknessRing.getOuterRadius()* RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + } + public double getOd() { return od; } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/EngineBlockDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/EngineBlockDTO.java index bcb6d5751..6a742fb34 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/EngineBlockDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/EngineBlockDTO.java @@ -7,13 +7,20 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; /** + * Models a Rocksim XML Element for an EngineBlock. EngineBlocks in Rocksim are treated as rings with a special + * usage code. */ @XmlRootElement(name = "Ring") @XmlAccessorType(XmlAccessType.FIELD) public class EngineBlockDTO extends CenteringRingDTO{ - - public EngineBlockDTO(EngineBlock eb) { - super(eb); + + /** + * Copy constructor. + * + * @param theOREngineBlock + */ + public EngineBlockDTO(EngineBlock theOREngineBlock) { + super(theOREngineBlock); setUsageCode(UsageCode.EngineBlock); } } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/FinSetDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/FinSetDTO.java index b8238dd7e..0879c3b78 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/FinSetDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/FinSetDTO.java @@ -13,6 +13,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** + * This class models XML elements for Rocksim finsets. */ @XmlRootElement(name = RocksimCommonConstants.FIN_SET) @XmlAccessorType(XmlAccessType.FIELD) @@ -45,36 +46,44 @@ public class FinSetDTO extends BasePartDTO { @XmlElement(name = RocksimCommonConstants.CANT_ANGLE) private double cantAngle = 0d; + /** + * Constructor. + */ public FinSetDTO() { } - public FinSetDTO(FinSet ec) { - super(ec); + /** + * Full copy constructor. + * + * @param theORFinSet the OpenRocket finset + */ + public FinSetDTO(FinSet theORFinSet) { + super(theORFinSet); - setFinCount(ec.getFinCount()); - setCantAngle(ec.getCantAngle()); - setTabDepth(ec.getTabHeight() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setTabLength(ec.getTabLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setTabOffset(ec.getTabShift() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setThickness(ec.getThickness() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setFinCount(theORFinSet.getFinCount()); + setCantAngle(theORFinSet.getCantAngle()); + setTabDepth(theORFinSet.getTabHeight() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setTabLength(theORFinSet.getTabLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setTabOffset(theORFinSet.getTabShift() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setThickness(theORFinSet.getThickness() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setRadialAngle(ec.getBaseRotation()); - setTipShapeCode(TipShapeCode.convertTipShapeCode(ec.getCrossSection())); - if (ec instanceof TrapezoidFinSet) { - TrapezoidFinSet tfs = (TrapezoidFinSet) ec; + setRadialAngle(theORFinSet.getBaseRotation()); + setTipShapeCode(TipShapeCode.convertTipShapeCode(theORFinSet.getCrossSection())); + if (theORFinSet instanceof TrapezoidFinSet) { + TrapezoidFinSet tfs = (TrapezoidFinSet) theORFinSet; setShapeCode(0); - setRootChord(ec.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setRootChord(theORFinSet.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); setSemiSpan(tfs.getHeight() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); setTipChord(tfs.getTipChord() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); setSweepDistance(tfs.getSweep() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } - else if (ec instanceof EllipticalFinSet) { - EllipticalFinSet efs = (EllipticalFinSet) ec; + else if (theORFinSet instanceof EllipticalFinSet) { + EllipticalFinSet efs = (EllipticalFinSet) theORFinSet; setShapeCode(1); - setRootChord(ec.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setRootChord(theORFinSet.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); setSemiSpan(efs.getHeight() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } - else if (ec instanceof FreeformFinSet) { + else if (theORFinSet instanceof FreeformFinSet) { setShapeCode(2); } } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java index c52c4b80f..8b040395e 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java @@ -1,10 +1,10 @@ package net.sf.openrocket.file.rocksim.export; import net.sf.openrocket.file.rocksim.RocksimCommonConstants; +import net.sf.openrocket.gui.configdialog.InnerTubeConfig; import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.Bulkhead; import net.sf.openrocket.rocketcomponent.CenteringRing; -import net.sf.openrocket.rocketcomponent.ClusterConfiguration; import net.sf.openrocket.rocketcomponent.EngineBlock; import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.MassObject; @@ -21,16 +21,29 @@ import javax.xml.bind.annotation.XmlRootElement; import java.util.List; /** + * This class models the XML element for a Rocksim inside tube. */ @XmlRootElement(name = RocksimCommonConstants.BODY_TUBE) @XmlAccessorType(XmlAccessType.FIELD) -public class InnerBodyTubeDTO extends BodyTubeDTO implements AttachedParts { +public class InnerBodyTubeDTO extends BodyTubeDTO implements AttachableParts { + /** + * Constructor. + */ public InnerBodyTubeDTO() { super.setInsideTube(true); } - public InnerBodyTubeDTO(InnerTube bt, AttachedParts parent) { + /** + * Full copy constructor. + * + * @param bt the corresponding OR inner body tube + * @param parent the attached parts (subcomponents in Rocksim speak) of the InnerTube's parent. This instance + * is a member of those attached parts, as well as all sibling components. This is passed in the + * event that the inner tube is a cluster. In that situation this instance will be removed and + * individual instances for each cluster member will be added. + */ + public InnerBodyTubeDTO(InnerTube bt, AttachableParts parent) { super(bt); setEngineOverhang(bt.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); setID(bt.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); @@ -41,35 +54,37 @@ public class InnerBodyTubeDTO extends BodyTubeDTO implements AttachedParts { setRadialAngle(bt.getRadialDirection()); setRadialLoc(bt.getRadialPosition() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - List children = bt.getChildren(); - for (int i = 0; i < children.size(); i++) { - RocketComponent rocketComponents = children.get(i); - if (rocketComponents instanceof InnerTube) { - final InnerTube innerTube = (InnerTube) rocketComponents; - if (innerTube.getClusterCount() == 1) { - attachedParts.add(new InnerBodyTubeDTO(innerTube, this)); - } - } else if (rocketComponents instanceof BodyTube) { - attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents)); - } else if (rocketComponents instanceof Transition) { - attachedParts.add(new TransitionDTO((Transition) rocketComponents)); - } else if (rocketComponents instanceof EngineBlock) { - attachedParts.add(new EngineBlockDTO((EngineBlock) rocketComponents)); - } else if (rocketComponents instanceof TubeCoupler) { - attachedParts.add(new TubeCouplerDTO((TubeCoupler) rocketComponents)); - } else if (rocketComponents instanceof CenteringRing) { - attachedParts.add(new CenteringRingDTO((CenteringRing) rocketComponents)); - } else if (rocketComponents instanceof Bulkhead) { - attachedParts.add(new BulkheadDTO((Bulkhead) rocketComponents)); - } else if (rocketComponents instanceof Streamer) { - attachedParts.add(new StreamerDTO((Streamer) rocketComponents)); - } else if (rocketComponents instanceof Parachute) { - attachedParts.add(new ParachuteDTO((Parachute) rocketComponents)); - } else if (rocketComponents instanceof MassObject) { - attachedParts.add(new MassObjectDTO((MassObject) rocketComponents)); + List children = bt.getChildren(); + for (int i = 0; i < children.size(); i++) { + RocketComponent rocketComponents = children.get(i); + if (rocketComponents instanceof InnerTube) { + final InnerTube innerTube = (InnerTube) rocketComponents; + //Only if the inner tube is NOT a cluster, then create the corresponding Rocksim DTO and add it + //to the list of attached parts. If it is a cluster, then it is handled specially outside of this + //loop. + if (innerTube.getClusterCount() == 1) { + attachedParts.add(new InnerBodyTubeDTO(innerTube, this)); } + } else if (rocketComponents instanceof BodyTube) { + attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents)); + } else if (rocketComponents instanceof Transition) { + attachedParts.add(new TransitionDTO((Transition) rocketComponents)); + } else if (rocketComponents instanceof EngineBlock) { + attachedParts.add(new EngineBlockDTO((EngineBlock) rocketComponents)); + } else if (rocketComponents instanceof TubeCoupler) { + attachedParts.add(new TubeCouplerDTO((TubeCoupler) rocketComponents)); + } else if (rocketComponents instanceof CenteringRing) { + attachedParts.add(new CenteringRingDTO((CenteringRing) rocketComponents)); + } else if (rocketComponents instanceof Bulkhead) { + attachedParts.add(new BulkheadDTO((Bulkhead) rocketComponents)); + } else if (rocketComponents instanceof Streamer) { + attachedParts.add(new StreamerDTO((Streamer) rocketComponents)); + } else if (rocketComponents instanceof Parachute) { + attachedParts.add(new ParachuteDTO((Parachute) rocketComponents)); + } else if (rocketComponents instanceof MassObject) { + attachedParts.add(new MassObjectDTO((MassObject) rocketComponents)); } - + } //Do the cluster. For now this splits the cluster into separate tubes, which is how Rocksim represents it. //The import (from Rocksim to OR) could be augmented to be more intelligent and try to determine if the //co-located tubes are a cluster. @@ -79,25 +94,24 @@ public class InnerBodyTubeDTO extends BodyTubeDTO implements AttachedParts { } } - private void handleCluster(InnerTube it, AttachedParts p) { + + /** + * Handle the inner tube as a cluster. This amounts to splitting it up so that each motor mount in the cluster + * is created individually to support Rocksim's view of clusters. + * + * @param it the clustered tube + * @param p the collection (parent's attached parts really) to which all cluster tubes will be added + */ + private void handleCluster(InnerTube it, AttachableParts p) { Coordinate[] coords = {Coordinate.NUL}; coords = it.shiftCoordinates(coords); for (int x = 0; x < coords.length; x++) { - InnerTube copy = (InnerTube) it.copy(); - copy.setClusterConfiguration(ClusterConfiguration.SINGLE); - copy.setClusterRotation(0.0); - copy.setClusterScale(1.0); - copy.setRadialShift(coords[x].y, coords[x].z); - copy.setName(copy.getName() + " #" + (x + 1)); - p.addAttachedPart(copy(copy, p)); + InnerTube partialClone = InnerTubeConfig.makeIndividualClusterComponent(coords[x], it.getName() + " #" + (x + 1), it); + p.addAttachedPart(new InnerBodyTubeDTO(partialClone, p)); } } - private InnerBodyTubeDTO copy(InnerTube it, AttachedParts p) { - return new InnerBodyTubeDTO(it, p); - } - @Override public void addAttachedPart(BasePartDTO part) { attachedParts.add(part); diff --git a/core/src/net/sf/openrocket/file/rocksim/export/LaunchLugDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/LaunchLugDTO.java index 274082288..4c287202b 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/LaunchLugDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/LaunchLugDTO.java @@ -9,6 +9,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** + * This class models an XML element for a Rocksim LaunchLug. */ @XmlRootElement(name = RocksimCommonConstants.LAUNCH_LUG) @XmlAccessorType(XmlAccessType.FIELD) @@ -19,14 +20,22 @@ public class LaunchLugDTO extends BasePartDTO { @XmlElement(name = RocksimCommonConstants.ID) private double id = 0d; + /** + * Default constructor. + */ public LaunchLugDTO() { } - public LaunchLugDTO(LaunchLug ec) { - super(ec); - setId(ec.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOd(ec.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setRadialAngle(ec.getRadialDirection()); + /** + * Copy constructor. Fully populates this instance with values taken from the OR LaunchLug. + * + * @param theORLaunchLug + */ + public LaunchLugDTO(LaunchLug theORLaunchLug) { + super(theORLaunchLug); + setId(theORLaunchLug.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setOd(theORLaunchLug.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setRadialAngle(theORLaunchLug.getRadialDirection()); } public double getOd() { diff --git a/core/src/net/sf/openrocket/file/rocksim/export/MassObjectDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/MassObjectDTO.java index 74a0347dd..85782b27b 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/MassObjectDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/MassObjectDTO.java @@ -25,7 +25,7 @@ public class MassObjectDTO extends BasePartDTO{ } /** - * Typed constructor. + * Typed copy constructor. * * @param mo OR MassObject */ diff --git a/core/src/net/sf/openrocket/file/rocksim/export/NoseConeDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/NoseConeDTO.java index aa838e0df..79914c132 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/NoseConeDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/NoseConeDTO.java @@ -9,6 +9,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** + * This class models a Rocksim XML Element for a nose cone. */ @XmlRootElement(name = RocksimCommonConstants.NOSE_CONE) @XmlAccessorType(XmlAccessType.FIELD) @@ -29,7 +30,7 @@ public class NoseConeDTO extends AbstractTransitionDTO { } /** - * Full copy constructor. + * Full copy constructor. Fully populates this instance with values taken from the OR NoseCone instance. * * @param nc the OR nose cone */ diff --git a/core/src/net/sf/openrocket/file/rocksim/export/ParachuteDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/ParachuteDTO.java index 5b4dcef5a..7f0f25077 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/ParachuteDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/ParachuteDTO.java @@ -31,21 +31,29 @@ public class ParachuteDTO extends BasePartDTO { private String shroudLineMaterial = ""; @XmlElement(name = RocksimCommonConstants.DRAG_COEFFICIENT) private double dragCoefficient = 0.75d; - + + /** + * Default constructor. + */ public ParachuteDTO() { } - public ParachuteDTO(Parachute ec) { - super(ec); + /** + * Copy constructor. Fully populates this instance with values taken from the corresponding OR Parachute. + * + * @param theORParachute the OR Parachute instance + */ + public ParachuteDTO(Parachute theORParachute) { + super(theORParachute); setChuteCount(1); - setDia(ec.getDiameter() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setDragCoefficient(ec.getCD()); - setShroudLineCount(ec.getLineCount()); - setShroudLineLen(ec.getLineLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setDia(theORParachute.getDiameter() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setDragCoefficient(theORParachute.getCD()); + setShroudLineCount(theORParachute.getLineCount()); + setShroudLineLen(theORParachute.getLineLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - String material = ec.getLineMaterial().getName(); - setShroudLineMassPerMM(ec.getLineMaterial().getDensity() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LINE_DENSITY); + String material = theORParachute.getLineMaterial().getName(); + setShroudLineMassPerMM(theORParachute.getLineMaterial().getDensity() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LINE_DENSITY); if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) { material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length()); diff --git a/core/src/net/sf/openrocket/file/rocksim/export/RocketDesignDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/RocketDesignDTO.java index 697b5af82..10ecf38c3 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/RocketDesignDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/RocketDesignDTO.java @@ -5,6 +5,8 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; /** + * This class models a Rocksim XML element for a rocket design container. It's really nothing more than + * a bunch of boilerplate XML that does not change, coupled with the stage DTOs that are part of the rocket design. */ @XmlAccessorType(XmlAccessType.FIELD) public class RocketDesignDTO { @@ -67,6 +69,9 @@ public class RocketDesignDTO { @XmlElement(name = "Stage1Parts", required = false, nillable = false) private StageDTO stage1 = new StageDTO(); + /** + * Default constructor. + */ public RocketDesignDTO() { } diff --git a/core/src/net/sf/openrocket/file/rocksim/export/StageDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/StageDTO.java index 3146619c9..e0303e7fc 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/StageDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/StageDTO.java @@ -33,39 +33,46 @@ public class StageDTO { public StageDTO() { } - public StageDTO(Stage stage, RocketDesignDTO design, int stageNumber) { + /** + * Copy constructor. + * + * @param theORStage the OR stage + * @param design the encompassing container DTO + * @param stageNumber the stage number (3 is always at the top, even if it's the only one) + */ + public StageDTO(Stage theORStage, RocketDesignDTO design, int stageNumber) { if (stageNumber == 3) { - if (stage.isMassOverridden()) { - design.setStage3Mass(stage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); + if (theORStage.isMassOverridden()) { + design.setStage3Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); design.setUseKnownMass(1); } - if (stage.isCGOverridden()) { - design.setStage3CG(stage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + if (theORStage.isCGOverridden()) { + design.setStage3CG(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } } if (stageNumber == 2) { - if (stage.isMassOverridden()) { - design.setStage2Mass(stage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); + if (theORStage.isMassOverridden()) { + design.setStage2Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); design.setUseKnownMass(1); } - if (stage.isCGOverridden()) { - design.setStage2CGAlone(stage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + if (theORStage.isCGOverridden()) { + design.setStage2CGAlone(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } } if (stageNumber == 1) { - if (stage.isMassOverridden()) { - design.setStage1Mass(stage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); + if (theORStage.isMassOverridden()) { + design.setStage1Mass(theORStage.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); design.setUseKnownMass(1); } - if (stage.isCGOverridden()) { - design.setStage1CGAlone(stage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + if (theORStage.isCGOverridden()) { + design.setStage1CGAlone(theORStage.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } } - List children = stage.getChildren(); + List children = theORStage.getChildren(); for (int i = 0; i < children.size(); i++) { RocketComponent rocketComponents = children.get(i); if (rocketComponents instanceof NoseCone) { diff --git a/core/src/net/sf/openrocket/file/rocksim/export/StreamerDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/StreamerDTO.java index dbcd64895..c959ce546 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/StreamerDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/StreamerDTO.java @@ -9,6 +9,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** + * This class models a Rocksim XML element for a streamer. */ @XmlRootElement(name = RocksimCommonConstants.STREAMER) @XmlAccessorType(XmlAccessType.FIELD) @@ -19,13 +20,21 @@ public class StreamerDTO extends BasePartDTO { @XmlElement(name = RocksimCommonConstants.DRAG_COEFFICIENT) private double dragCoefficient = 0.75d; + /** + * The default constructor. + */ public StreamerDTO() { } - public StreamerDTO(Streamer ec) { - super(ec); - setWidth(ec.getStripWidth() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setDragCoefficient(ec.getCD()); + /** + * Copy constructor. This constructor fully populates this instance with values taken from the OR component. + * + * @param theORStreamer the OR streamer component + */ + public StreamerDTO(Streamer theORStreamer) { + super(theORStreamer); + setWidth(theORStreamer.getStripWidth() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setDragCoefficient(theORStreamer.getCD()); } public double getWidth() { diff --git a/core/src/net/sf/openrocket/file/rocksim/export/TransitionDTO.java b/core/src/net/sf/openrocket/file/rocksim/export/TransitionDTO.java index bf4674766..563605601 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/TransitionDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/TransitionDTO.java @@ -9,6 +9,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** + * This class models a transition XML element in Rocksim file format. */ @XmlRootElement(name = RocksimCommonConstants.TRANSITION) @XmlAccessorType(XmlAccessType.FIELD) @@ -28,17 +29,26 @@ public class TransitionDTO extends AbstractTransitionDTO { @XmlElement(name = RocksimCommonConstants.REAR_DIA) private double rearDia = 0d; + /** + * Default constructor. + */ public TransitionDTO() { } - public TransitionDTO(Transition tran) { - super(tran); - setFrontDia(tran.getForeRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setRearDia(tran.getAftRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setFrontShoulderDia(tran.getForeShoulderRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setFrontShoulderLen(tran.getForeShoulderLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setRearShoulderDia(tran.getAftShoulderRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setRearShoulderLen(tran.getAftShoulderLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + /** + * Copy constructor. This TransitionDTO instance will be as equivalent as possible to the OR tran + * once the constructor returns. No further modification (invoking setters) is necessary. + * + * @param theORTransition the OR transition + */ + public TransitionDTO(Transition theORTransition) { + super(theORTransition); + setFrontDia(theORTransition.getForeRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setRearDia(theORTransition.getAftRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setFrontShoulderDia(theORTransition.getForeShoulderRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setFrontShoulderLen(theORTransition.getForeShoulderLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); + setRearShoulderDia(theORTransition.getAftShoulderRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + setRearShoulderLen(theORTransition.getAftShoulderLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); } diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/AttachedPartsHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/AttachedPartsHandler.java index 155fdd890..bfb7692ad 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/AttachedPartsHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/AttachedPartsHandler.java @@ -60,13 +60,13 @@ class AttachedPartsHandler extends ElementHandler { if (RocksimCommonConstants.TRANSITION.equals(element)) { return new TransitionHandler(component, warnings); } - if ("TubeFinSet".equals(element)) { + if (RocksimCommonConstants.TUBE_FIN_SET.equals(element)) { warnings.add("Tube fins are not currently supported. Ignoring."); } - if ("RingTail".equals(element)) { + if (RocksimCommonConstants.RING_TAIL.equals(element)) { warnings.add("Ring tails are not currently supported. Ignoring."); } - if ("ExternalPod".equals(element)) { + if (RocksimCommonConstants.EXTERNAL_POD.equals(element)) { warnings.add("Pods are not currently supported. Ignoring."); } return null; diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/FinSetHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/FinSetHandler.java index 693792a33..9b42617b0 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/FinSetHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/FinSetHandler.java @@ -162,79 +162,79 @@ class FinSetHandler extends ElementHandler { public void closeElement (String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { try { - if ("Name".equals(element)) { + if (RocksimCommonConstants.NAME.equals(element)) { name = content; } - if ("Material".equals(element)) { + if (RocksimCommonConstants.MATERIAL.equals(element)) { materialName = content; } - if ("FinishCode".equals(element)) { + if (RocksimCommonConstants.FINISH_CODE.equals(element)) { finish = RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket(); } - if ("Xb".equals(element)) { + if (RocksimCommonConstants.XB.equals(element)) { location = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("LocationMode".equals(element)) { + if (RocksimCommonConstants.LOCATION_MODE.equals(element)) { position = RocksimLocationMode.fromCode(Integer.parseInt(content)).asOpenRocket(); } - if ("FinCount".equals(element)) { + if (RocksimCommonConstants.FIN_COUNT.equals(element)) { finCount = Integer.parseInt(content); } - if ("RootChord".equals(element)) { + if (RocksimCommonConstants.ROOT_CHORD.equals(element)) { rootChord = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("TipChord".equals(element)) { + if (RocksimCommonConstants.TIP_CHORD.equals(element)) { tipChord = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("SemiSpan".equals(element)) { + if (RocksimCommonConstants.SEMI_SPAN.equals(element)) { semiSpan = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } if ("MidChordLen".equals(element)) { midChordLen = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("SweepDistance".equals(element)) { + if (RocksimCommonConstants.SWEEP_DISTANCE.equals(element)) { sweepDistance = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("Thickness".equals(element)) { + if (RocksimCommonConstants.THICKNESS.equals(element)) { thickness = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("TipShapeCode".equals(element)) { + if (RocksimCommonConstants.TIP_SHAPE_CODE.equals(element)) { tipShapeCode = Integer.parseInt(content); } - if ("TabLength".equals(element)) { + if (RocksimCommonConstants.TAB_LENGTH.equals(element)) { tabLength = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("TabDepth".equals(element)) { + if (RocksimCommonConstants.TAB_DEPTH.equals(element)) { tabDepth = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("TabOffset".equals(element)) { + if (RocksimCommonConstants.TAB_OFFSET.equals(element)) { taboffset = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } - if ("RadialAngle".equals(element)) { + if (RocksimCommonConstants.RADIAL_ANGLE.equals(element)) { radialAngle = Double.parseDouble(content); } - if ("ShapeCode".equals(element)) { + if (RocksimCommonConstants.SHAPE_CODE.equals(element)) { shapeCode = Integer.parseInt(content); } - if ("PointList".equals(element)) { + if (RocksimCommonConstants.POINT_LIST.equals(element)) { pointList = content; } - if ("KnownMass".equals(element)) { + if (RocksimCommonConstants.KNOWN_MASS.equals(element)) { mass = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); } - if ("Density".equals(element)) { + if (RocksimCommonConstants.DENSITY.equals(element)) { density = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_BULK_DENSITY); } - if ("KnownCG".equals(element)) { + if (RocksimCommonConstants.KNOWN_CG.equals(element)) { cg = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS); } - if ("UseKnownCG".equals(element)) { + if (RocksimCommonConstants.USE_KNOWN_CG.equals(element)) { override = "1".equals(content); } - if ("CalcMass".equals(element)) { + if (RocksimCommonConstants.CALC_MASS.equals(element)) { calcMass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS; } - if ("CalcCg".equals(element)) { + if (RocksimCommonConstants.CALC_CG.equals(element)) { calcCg = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; } } diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/RocksimHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/RocksimHandler.java index 6b5765e2a..9228d6b10 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/RocksimHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/RocksimHandler.java @@ -103,15 +103,15 @@ class RocksimContentHandler extends ElementHandler { @Override public ElementHandler openElement(String element, HashMap attributes, WarningSet warnings) { - if ("DesignInformation".equals(element)) { + if (RocksimCommonConstants.DESIGN_INFORMATION.equals(element)) { //The next sub-element is "RocketDesign", which is really the only thing that matters. Rather than //create another handler just for that element, handle it here. return this; } - if ("FileVersion".equals(element)) { + if (RocksimCommonConstants.FILE_VERSION.equals(element)) { return PlainTextHandler.INSTANCE; } - if ("RocketDesign".equals(element)) { + if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) { return new RocketDesignHandler(rocket); } return null; @@ -124,7 +124,7 @@ class RocksimContentHandler extends ElementHandler { * SAX handler for Rocksim file version number. The value is not used currently, but could be used in the future * for backward/forward compatibility reasons (different lower level handlers could be called via a strategy pattern). */ - if ("FileVersion".equals(element)) { + if (RocksimCommonConstants.FILE_VERSION.equals(element)) { version = content; } } @@ -243,7 +243,7 @@ class RocketDesignHandler extends ElementHandler { return new StageHandler(stage); } } - if ("Name".equals(element)) { + if (RocksimCommonConstants.NAME.equals(element)) { return PlainTextHandler.INSTANCE; } if ("StageCount".equals(element)) { @@ -274,7 +274,7 @@ class RocketDesignHandler extends ElementHandler { public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { try { - if ("Name".equals(element)) { + if (RocksimCommonConstants.NAME.equals(element)) { component.setName(content); } if ("StageCount".equals(element)) { diff --git a/core/src/net/sf/openrocket/gui/configdialog/InnerTubeConfig.java b/core/src/net/sf/openrocket/gui/configdialog/InnerTubeConfig.java index b7c0afeaa..e679ed05d 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/InnerTubeConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/InnerTubeConfig.java @@ -1,30 +1,6 @@ package net.sf.openrocket.gui.configdialog; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.geom.Ellipse2D; -import java.util.EventObject; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.SwingUtilities; -import javax.swing.border.BevelBorder; - import net.miginfocom.swing.MigLayout; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.Resettable; @@ -44,6 +20,17 @@ import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.StateChangeListener; +import javax.swing.*; +import javax.swing.border.BevelBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.geom.Ellipse2D; +import java.util.EventObject; +import java.util.List; + public class InnerTubeConfig extends ThicknessRingComponentConfig { private static final Translator trans = Application.getTranslator(); @@ -163,12 +150,7 @@ public class InnerTubeConfig extends ThicknessRingComponentConfig { coords = component.shiftCoordinates(coords); parent.removeChild(index); for (int i = 0; i < coords.length; i++) { - InnerTube copy = (InnerTube) component.copy(); - copy.setClusterConfiguration(ClusterConfiguration.SINGLE); - copy.setClusterRotation(0.0); - copy.setClusterScale(1.0); - copy.setRadialShift(coords[i].y, coords[i].z); - copy.setName(copy.getName() + " #" + (i + 1)); + InnerTube copy = makeIndividualClusterComponent(coords[i], component.getName() + " #" + (i + 1), component); parent.addChild(copy, index + i); } @@ -198,6 +180,27 @@ public class InnerTubeConfig extends ThicknessRingComponentConfig { return panel; } + + /** + * For a given coordinate that represents one tube in a cluster, create an instance of that tube. Must be called + * once for each tube in the cluster. + * + * @param coord the coordinate of the clustered tube to create + * @param splitName the name of the individual tube + * @param theInnerTube the 'parent' from which this tube will be created. + * + * @return an instance of an inner tube that represents ONE of the clustered tubes in the cluster represented + * by theInnerTube + */ + public static InnerTube makeIndividualClusterComponent(Coordinate coord, String splitName, RocketComponent theInnerTube) { + InnerTube copy = (InnerTube) theInnerTube.copy(); + copy.setClusterConfiguration(ClusterConfiguration.SINGLE); + copy.setClusterRotation(0.0); + copy.setClusterScale(1.0); + copy.setRadialShift(coord.y, coord.z); + copy.setName(splitName); + return copy; + } }