From 14741cf4601ad20c797f56024736f2c46cb4dfdf Mon Sep 17 00:00:00 2001 From: rodinia814 Date: Sat, 14 Jan 2012 04:29:24 +0000 Subject: [PATCH] DGP - updated Rocksim export to support clusters git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@353 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../sf/openrocket/aerodynamics/Warning.java | 4 +- .../file/rocksim/export/BodyTubeDTO.java | 15 ++-- .../file/rocksim/export/InnerBodyTubeDTO.java | 88 +++++++++++++------ 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/core/src/net/sf/openrocket/aerodynamics/Warning.java b/core/src/net/sf/openrocket/aerodynamics/Warning.java index e44541c0..52911df0 100644 --- a/core/src/net/sf/openrocket/aerodynamics/Warning.java +++ b/core/src/net/sf/openrocket/aerodynamics/Warning.java @@ -35,8 +35,8 @@ public abstract class Warning { */ @Override public boolean equals(Object o) { - return (o.getClass() == this.getClass()); - } + return o != null && (o.getClass() == this.getClass()); + } /** * A hashCode method compatible with the equals method. 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 a39a2f77..10f77d69 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java @@ -64,12 +64,12 @@ public class BodyTubeDTO extends BasePartDTO { super(inner); } - public BodyTubeDTO(BodyTube bt) { + protected BodyTubeDTO(BodyTube bt) { super(bt); setEngineOverhang(bt.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setId(bt.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOd(bt.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + 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()); @@ -103,23 +103,22 @@ public class BodyTubeDTO extends BasePartDTO { } else if (rocketComponents instanceof FinSet) { attachedParts.add(new FinSetDTO((FinSet) rocketComponents)); } - } } - public double getOd() { + public double getOD() { return od; } - public void setOd(double theOd) { + public void setOD(double theOd) { od = theOd; } - public double getId() { + public double getID() { return id; } - public void setId(double theId) { + public void setID(double theId) { id = theId; } 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 a2343c89..88ddbfe2 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java @@ -4,6 +4,7 @@ import net.sf.openrocket.file.rocksim.RocksimCommonConstants; 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; @@ -12,6 +13,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.Streamer; import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.TubeCoupler; +import net.sf.openrocket.util.Coordinate; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -29,38 +31,72 @@ public class InnerBodyTubeDTO extends BodyTubeDTO { } public InnerBodyTubeDTO(InnerTube bt) { + this(bt, true); + } + + public InnerBodyTubeDTO(InnerTube bt, boolean deep) { super(bt); setEngineOverhang(bt.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH); - setId(bt.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); - setOd(bt.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); + 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()); + setInsideTube(true); + 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) { - attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents)); - } 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)); + if (deep) { + List children = bt.getChildren(); + for (int i = 0; i < children.size(); i++) { + RocketComponent rocketComponents = children.get(i); + if (rocketComponents instanceof InnerTube) { + attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents)); + } 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)); + } } } - setInsideTube(true); + + //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. + if (bt.getClusterConfiguration().getClusterCount() > 1) { + handleCluster(bt); + } + } + + private void handleCluster(InnerTube it) { + + 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)); + attachedParts.add(copy(copy)); + } + } + + private InnerBodyTubeDTO copy(InnerTube it) { + return new InnerBodyTubeDTO(it, false); } } -- 2.30.2