]> git.gag.com Git - debian/openrocket/commitdiff
DGP - updated Rocksim export to support clusters
authorrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sat, 14 Jan 2012 05:33:15 +0000 (05:33 +0000)
committerrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sat, 14 Jan 2012 05:33:15 +0000 (05:33 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@354 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/file/rocksim/export/AbstractTransitionDTO.java
core/src/net/sf/openrocket/file/rocksim/export/AttachedParts.java [new file with mode: 0644]
core/src/net/sf/openrocket/file/rocksim/export/BodyTubeDTO.java
core/src/net/sf/openrocket/file/rocksim/export/InnerBodyTubeDTO.java

index 88b19e4c657402db89d55643df18a2faa724cd10..d729ebdd3b566ad39f3bc829c5888fea5653ecb4 100644 (file)
@@ -29,7 +29,7 @@ import java.util.List;
  * Transition to a Rocksim Transition.
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-public class AbstractTransitionDTO extends BasePartDTO {
+public class AbstractTransitionDTO extends BasePartDTO implements AttachedParts {
 
     @XmlElement(name = RocksimCommonConstants.SHAPE_CODE)
     private int shapeCode = 1;
@@ -80,7 +80,7 @@ public class AbstractTransitionDTO extends BasePartDTO {
         for (int i = 0; i < children.size(); i++) {
             RocketComponent rocketComponents = children.get(i);
             if (rocketComponents instanceof InnerTube) {
-                attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents));
+                attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents, this));
             } else if (rocketComponents instanceof BodyTube) {
                 attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents));
             } else if (rocketComponents instanceof Transition) {
@@ -136,4 +136,14 @@ public class AbstractTransitionDTO extends BasePartDTO {
     public void setShapeParameter(double theShapeParameter) {
         shapeParameter = theShapeParameter;
     }
+
+    @Override
+    public void addAttachedPart(BasePartDTO part) {
+        attachedParts.add(part);
+    }
+
+    @Override
+    public void removeAttachedPart(BasePartDTO part) {
+        attachedParts.remove(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
new file mode 100644 (file)
index 0000000..a7a8c30
--- /dev/null
@@ -0,0 +1,9 @@
+package net.sf.openrocket.file.rocksim.export;
+
+/**
+ */
+public interface AttachedParts {
+    void removeAttachedPart(BasePartDTO part);
+
+    void addAttachedPart(BasePartDTO part);
+}
index 10f77d694a02e215244e0c7e522272172410c386..3a043a0cf22ce1ff1699e7d7ebbc624a68a0e0b8 100644 (file)
@@ -30,7 +30,7 @@ import java.util.List;
  */
 @XmlRootElement(name = RocksimCommonConstants.BODY_TUBE)
 @XmlAccessorType(XmlAccessType.FIELD)
-public class BodyTubeDTO extends BasePartDTO {
+public class BodyTubeDTO extends BasePartDTO implements AttachedParts {
 
     @XmlElement(name = RocksimCommonConstants.OD)
     private double od = 0d;
@@ -77,7 +77,11 @@ public class BodyTubeDTO extends BasePartDTO {
         for (int i = 0; i < children.size(); i++) {
             RocketComponent rocketComponents = children.get(i);
             if (rocketComponents instanceof InnerTube) {
-                attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents));
+                final InnerTube innerTube = (InnerTube) rocketComponents;
+                final InnerBodyTubeDTO innerBodyTubeDTO = new InnerBodyTubeDTO(innerTube, this);
+                if (innerTube.getClusterCount() == 1) {
+                    attachedParts.add(innerBodyTubeDTO);
+                }
             } else if (rocketComponents instanceof BodyTube) {
                 attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents));
             } else if (rocketComponents instanceof Transition) {
@@ -175,7 +179,13 @@ public class BodyTubeDTO extends BasePartDTO {
         return attachedParts;
     }
 
-    public void addAttachedParts(BasePartDTO thePart) {
+    @Override
+    public void addAttachedPart(BasePartDTO thePart) {
         attachedParts.add(thePart);
     }
-}
+
+    @Override
+    public void removeAttachedPart(BasePartDTO part) {
+        attachedParts.remove(part);
+    }
+}
\ No newline at end of file
index 88ddbfe297869af5bd0c9403ec400f3e0dc309d9..c52c4b80fcf87466c25ea47f36805536a5ecc06e 100644 (file)
@@ -24,17 +24,13 @@ import java.util.List;
  */
 @XmlRootElement(name = RocksimCommonConstants.BODY_TUBE)
 @XmlAccessorType(XmlAccessType.FIELD)
-public class InnerBodyTubeDTO extends BodyTubeDTO {
+public class InnerBodyTubeDTO extends BodyTubeDTO implements AttachedParts {
 
     public InnerBodyTubeDTO() {
         super.setInsideTube(true);
     }
 
-    public InnerBodyTubeDTO(InnerTube bt) {
-        this(bt, true);
-    }
-
-    public InnerBodyTubeDTO(InnerTube bt, boolean deep) {
+    public InnerBodyTubeDTO(InnerTube bt, AttachedParts parent) {
         super(bt);
         setEngineOverhang(bt.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
         setID(bt.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
@@ -45,12 +41,14 @@ public class InnerBodyTubeDTO extends BodyTubeDTO {
         setRadialAngle(bt.getRadialDirection());
         setRadialLoc(bt.getRadialPosition() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
 
-        if (deep) {
             List<RocketComponent> 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));
+                    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) {
@@ -71,17 +69,17 @@ public class InnerBodyTubeDTO extends BodyTubeDTO {
                     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.
         if (bt.getClusterConfiguration().getClusterCount() > 1) {
-            handleCluster(bt);
+            handleCluster(bt, parent);
+            parent.removeAttachedPart(this);
         }
     }
 
-    private void handleCluster(InnerTube it) {
+    private void handleCluster(InnerTube it, AttachedParts p) {
 
         Coordinate[] coords = {Coordinate.NUL};
         coords = it.shiftCoordinates(coords);
@@ -92,11 +90,21 @@ public class InnerBodyTubeDTO extends BodyTubeDTO {
             copy.setClusterScale(1.0);
             copy.setRadialShift(coords[x].y, coords[x].z);
             copy.setName(copy.getName() + " #" + (x + 1));
-            attachedParts.add(copy(copy));
+            p.addAttachedPart(copy(copy, p));
         }
     }
 
-    private InnerBodyTubeDTO copy(InnerTube it) {
-        return new InnerBodyTubeDTO(it, false);
+    private InnerBodyTubeDTO copy(InnerTube it, AttachedParts p) {
+        return new InnerBodyTubeDTO(it, p);
+    }
+
+    @Override
+    public void addAttachedPart(BasePartDTO part) {
+        attachedParts.add(part);
+    }
+
+    @Override
+    public void removeAttachedPart(BasePartDTO part) {
+        attachedParts.remove(part);
     }
 }