From 1d879c22816aaac5f2bd3e011d19b35c59f31cbb Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 14 Aug 2015 12:12:18 -0400 Subject: [PATCH] bugfix: motors now display correctly on clusters and booster clusters. --- .../rocketcomponent/Configuration.java | 8 +-- .../openrocket/rocketcomponent/InnerTube.java | 5 ++ .../sf/openrocket/rocketcomponent/Rocket.java | 7 +- .../rocketcomponent/RocketComponent.java | 3 +- .../gui/configdialog/StageConfig.java | 3 +- .../gui/scalefigure/RocketFigure.java | 67 +++++++++---------- 6 files changed, 48 insertions(+), 45 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/Configuration.java b/core/src/net/sf/openrocket/rocketcomponent/Configuration.java index 93d039372..338aa8fae 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Configuration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Configuration.java @@ -325,21 +325,19 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi private List getActiveComponents(List accumulator, final List toScan) { for (RocketComponent rc : toScan) { if (rc instanceof Stage) { - if (isStageActive(rc.getStageNumber())) { - // recurse to children - getActiveComponents(accumulator, rc.getChildren()); - } else { + if (!isStageActive(rc.getStageNumber())) { continue; } } else { accumulator.add(rc); } + // recurse to children + getActiveComponents(accumulator, rc.getChildren()); } return accumulator; } - /** * Return an iterator that iterates over all MotorMounts within the * current configuration that have an active motor. diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 4b9737028..ca437e723 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -128,6 +128,11 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra return cluster.getClusterCount(); } + @Override + public int getInstanceCount() { + return cluster.getClusterCount(); + } + /** * Get the cluster scaling. A value of 1.0 indicates that the tubes are packed * touching each other, larger values separate the tubes and smaller values diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index ab9d5f681..68fb6d07c 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -205,13 +205,18 @@ public class Rocket extends RocketComponent { } private static ArrayList getStages(ArrayList accumulator, final RocketComponent parent) { + if ((null == accumulator) || (null == parent)) { + return new ArrayList(); + } + for (RocketComponent curChild : parent.getChildren()) { if (curChild instanceof Stage) { Stage curStage = (Stage) curChild; accumulator.add(curStage); } + getStages(accumulator, curChild); } - return accumulator; // technically redundant, btw. + return accumulator; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 20b3a1112..0df623409 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1118,7 +1118,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab mutex.lock(lockText); Coordinate[] thesePositions = this.getLocation(); - final int instanceCount = this.getInstanceCount(); + final int instanceCount = thesePositions.length; + Coordinate[] toReturn = new Coordinate[instanceCount]; for (int coordIndex = 0; coordIndex < instanceCount; coordIndex++) { toReturn[coordIndex] = thesePositions[coordIndex].add(c); diff --git a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java index edb43fb2b..d8c82d6de 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java @@ -127,7 +127,8 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap"); parallelEnabledModel.addEnableComponent( axialOffsetUnitSelector , true); - System.err.println(stage.getRocket().toDebugTree()); + // For DEBUG purposes + //System.err.println(stage.getRocket().toDebugTree()); return motherPanel; } diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 846a1eaa4..87a381fb5 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -23,7 +23,12 @@ import net.sf.openrocket.gui.figureelements.FigureElement; import net.sf.openrocket.gui.util.ColorConversion; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.motor.Motor; +import net.sf.openrocket.rocketcomponent.BodyTube; +import net.sf.openrocket.rocketcomponent.ClusterConfiguration; import net.sf.openrocket.rocketcomponent.Configuration; +import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.InnerTube; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -61,6 +66,8 @@ public class RocketFigure extends AbstractScaleFigure { private Configuration configuration; private RocketComponent[] selection = new RocketComponent[0]; + private double figureWidth = 0, figureHeight = 0; + protected int figureWidthPx = 0, figureHeightPx = 0; private RocketPanel.VIEW_TYPE currentViewType = RocketPanel.VIEW_TYPE.SideView; @@ -79,8 +86,6 @@ public class RocketFigure extends AbstractScaleFigure { private double minX = 0, maxX = 0, maxR = 0; // Figure width and height in SI-units and pixels - private double figureWidth = 0, figureHeight = 0; - protected int figureWidthPx = 0, figureHeightPx = 0; private AffineTransform g2transformation = null; @@ -337,8 +342,7 @@ public class RocketFigure extends AbstractScaleFigure { BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); - - + // Draw motors String motorID = configuration.getFlightConfigurationID(); Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor(); @@ -358,16 +362,17 @@ public class RocketFigure extends AbstractScaleFigure { RocketComponent mountComponent = ((RocketComponent) mount); Coordinate[] mountLocations = mountComponent.getLocation(); - //Coordinate curInstancePosition = mountLocations[0]; // placeholder double mountLength = mountComponent.getLength(); for ( Coordinate curInstanceLocation : mountLocations ){ Coordinate[] motorPositions; Coordinate[] clusterCenterTop = new Coordinate[]{ curInstanceLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0)}; motorPositions = mountComponent.shiftCoordinates(clusterCenterTop); + for (int i = 0; i < motorPositions.length; i++) { motorPositions[i] = transformation.transform(motorPositions[i]); } + for (Coordinate coord : motorPositions) { Shape s; if (currentViewType == RocketPanel.VIEW_TYPE.SideView) { @@ -545,16 +550,15 @@ public class RocketFigure extends AbstractScaleFigure { } } - - public double getBestZoom(Rectangle2D bounds) { - double zh = 1, zv = 1; - if (bounds.getWidth() > 0.0001) - zh = (getWidth() - 2 * borderPixelsWidth) / bounds.getWidth(); - if (bounds.getHeight() > 0.0001) - zv = (getHeight() - 2 * borderPixelsHeight) / bounds.getHeight(); - return Math.min(zh, zv); - } - +// public double getBestZoom(Rectangle2D bounds) { +// double zh = 1, zv = 1; +// if (bounds.getWidth() > 0.0001) +// zh = (getWidth() - 2 * borderPixelsWidth) / bounds.getWidth(); +// if (bounds.getHeight() > 0.0001) +// zv = (getHeight() - 2 * borderPixelsHeight) / bounds.getHeight(); +// return Math.min(zh, zv); +// } +// /** @@ -562,39 +566,28 @@ public class RocketFigure extends AbstractScaleFigure { * property accordingly. */ private void calculateSize() { - calculateFigureBounds(); - - switch (currentViewType) { - case SideView: - figureWidth = maxX - minX; - figureHeight = 2 * maxR; - break; - - case BackView: - figureWidth = 2 * maxR; - figureHeight = 2 * maxR; - break; - - default: - assert (false) : "Should not occur, type=" + currentViewType; - figureWidth = 0; - figureHeight = 0; - } + Rectangle2D dimensions = this.getDimensions(); + figureHeight = dimensions.getHeight(); + figureWidth = dimensions.getWidth(); + figureWidthPx = (int) (figureWidth * scale); figureHeightPx = (int) (figureHeight * scale); - Dimension d = new Dimension(figureWidthPx + 2 * borderPixelsWidth, + Dimension dpx = new Dimension( + figureWidthPx + 2 * borderPixelsWidth, figureHeightPx + 2 * borderPixelsHeight); - if (!d.equals(getPreferredSize()) || !d.equals(getMinimumSize())) { - setPreferredSize(d); - setMinimumSize(d); + if (!dpx.equals(getPreferredSize()) || !dpx.equals(getMinimumSize())) { + setPreferredSize(dpx); + setMinimumSize(dpx); revalidate(); } } public Rectangle2D getDimensions() { + calculateFigureBounds(); + switch (currentViewType) { case SideView: return new Rectangle2D.Double(minX, -maxR, maxX - minX, 2 * maxR);