bugfix: motors now display correctly on clusters and booster clusters.

This commit is contained in:
Daniel_M_Williams 2015-08-14 12:12:18 -04:00
parent 0fbdc33188
commit 1d879c2281
6 changed files with 48 additions and 45 deletions

View File

@ -325,21 +325,19 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
private List<RocketComponent> getActiveComponents(List<RocketComponent> accumulator, final List<RocketComponent> toScan) { private List<RocketComponent> getActiveComponents(List<RocketComponent> accumulator, final List<RocketComponent> toScan) {
for (RocketComponent rc : toScan) { for (RocketComponent rc : toScan) {
if (rc instanceof Stage) { if (rc instanceof Stage) {
if (isStageActive(rc.getStageNumber())) { if (!isStageActive(rc.getStageNumber())) {
// recurse to children
getActiveComponents(accumulator, rc.getChildren());
} else {
continue; continue;
} }
} else { } else {
accumulator.add(rc); accumulator.add(rc);
} }
// recurse to children
getActiveComponents(accumulator, rc.getChildren());
} }
return accumulator; return accumulator;
} }
/** /**
* Return an iterator that iterates over all <code>MotorMount</code>s within the * Return an iterator that iterates over all <code>MotorMount</code>s within the
* current configuration that have an active motor. * current configuration that have an active motor.

View File

@ -128,6 +128,11 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
return cluster.getClusterCount(); 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 * 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 * touching each other, larger values separate the tubes and smaller values

View File

@ -205,13 +205,18 @@ public class Rocket extends RocketComponent {
} }
private static ArrayList<Stage> getStages(ArrayList<Stage> accumulator, final RocketComponent parent) { private static ArrayList<Stage> getStages(ArrayList<Stage> accumulator, final RocketComponent parent) {
if ((null == accumulator) || (null == parent)) {
return new ArrayList<Stage>();
}
for (RocketComponent curChild : parent.getChildren()) { for (RocketComponent curChild : parent.getChildren()) {
if (curChild instanceof Stage) { if (curChild instanceof Stage) {
Stage curStage = (Stage) curChild; Stage curStage = (Stage) curChild;
accumulator.add(curStage); accumulator.add(curStage);
} }
getStages(accumulator, curChild);
} }
return accumulator; // technically redundant, btw. return accumulator;
} }

View File

@ -1118,7 +1118,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
mutex.lock(lockText); mutex.lock(lockText);
Coordinate[] thesePositions = this.getLocation(); Coordinate[] thesePositions = this.getLocation();
final int instanceCount = this.getInstanceCount(); final int instanceCount = thesePositions.length;
Coordinate[] toReturn = new Coordinate[instanceCount]; Coordinate[] toReturn = new Coordinate[instanceCount];
for (int coordIndex = 0; coordIndex < instanceCount; coordIndex++) { for (int coordIndex = 0; coordIndex < instanceCount; coordIndex++) {
toReturn[coordIndex] = thesePositions[coordIndex].add(c); toReturn[coordIndex] = thesePositions[coordIndex].add(c);

View File

@ -127,7 +127,8 @@ public class StageConfig extends RocketComponentConfig {
motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap"); motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap");
parallelEnabledModel.addEnableComponent( axialOffsetUnitSelector , true); parallelEnabledModel.addEnableComponent( axialOffsetUnitSelector , true);
System.err.println(stage.getRocket().toDebugTree()); // For DEBUG purposes
//System.err.println(stage.getRocket().toDebugTree());
return motherPanel; return motherPanel;
} }

View File

@ -23,7 +23,12 @@ import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.util.ColorConversion; import net.sf.openrocket.gui.util.ColorConversion;
import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.motor.Motor; 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.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.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -61,6 +66,8 @@ public class RocketFigure extends AbstractScaleFigure {
private Configuration configuration; private Configuration configuration;
private RocketComponent[] selection = new RocketComponent[0]; 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; 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; private double minX = 0, maxX = 0, maxR = 0;
// Figure width and height in SI-units and pixels // 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; private AffineTransform g2transformation = null;
@ -338,7 +343,6 @@ public class RocketFigure extends AbstractScaleFigure {
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE); RenderingHints.VALUE_STROKE_NORMALIZE);
// Draw motors // Draw motors
String motorID = configuration.getFlightConfigurationID(); String motorID = configuration.getFlightConfigurationID();
Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor(); Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor();
@ -358,16 +362,17 @@ public class RocketFigure extends AbstractScaleFigure {
RocketComponent mountComponent = ((RocketComponent) mount); RocketComponent mountComponent = ((RocketComponent) mount);
Coordinate[] mountLocations = mountComponent.getLocation(); Coordinate[] mountLocations = mountComponent.getLocation();
//Coordinate curInstancePosition = mountLocations[0]; // placeholder
double mountLength = mountComponent.getLength(); double mountLength = mountComponent.getLength();
for ( Coordinate curInstanceLocation : mountLocations ){ for ( Coordinate curInstanceLocation : mountLocations ){
Coordinate[] motorPositions; Coordinate[] motorPositions;
Coordinate[] clusterCenterTop = new Coordinate[]{ curInstanceLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0)}; Coordinate[] clusterCenterTop = new Coordinate[]{ curInstanceLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0)};
motorPositions = mountComponent.shiftCoordinates(clusterCenterTop); motorPositions = mountComponent.shiftCoordinates(clusterCenterTop);
for (int i = 0; i < motorPositions.length; i++) { for (int i = 0; i < motorPositions.length; i++) {
motorPositions[i] = transformation.transform(motorPositions[i]); motorPositions[i] = transformation.transform(motorPositions[i]);
} }
for (Coordinate coord : motorPositions) { for (Coordinate coord : motorPositions) {
Shape s; Shape s;
if (currentViewType == RocketPanel.VIEW_TYPE.SideView) { if (currentViewType == RocketPanel.VIEW_TYPE.SideView) {
@ -545,16 +550,15 @@ public class RocketFigure extends AbstractScaleFigure {
} }
} }
// public double getBestZoom(Rectangle2D bounds) {
public double getBestZoom(Rectangle2D bounds) { // double zh = 1, zv = 1;
double zh = 1, zv = 1; // if (bounds.getWidth() > 0.0001)
if (bounds.getWidth() > 0.0001) // zh = (getWidth() - 2 * borderPixelsWidth) / bounds.getWidth();
zh = (getWidth() - 2 * borderPixelsWidth) / bounds.getWidth(); // if (bounds.getHeight() > 0.0001)
if (bounds.getHeight() > 0.0001) // zv = (getHeight() - 2 * borderPixelsHeight) / bounds.getHeight();
zv = (getHeight() - 2 * borderPixelsHeight) / bounds.getHeight(); // return Math.min(zh, zv);
return Math.min(zh, zv); // }
} //
/** /**
@ -562,39 +566,28 @@ public class RocketFigure extends AbstractScaleFigure {
* property accordingly. * property accordingly.
*/ */
private void calculateSize() { private void calculateSize() {
calculateFigureBounds(); Rectangle2D dimensions = this.getDimensions();
switch (currentViewType) { figureHeight = dimensions.getHeight();
case SideView: figureWidth = dimensions.getWidth();
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;
}
figureWidthPx = (int) (figureWidth * scale); figureWidthPx = (int) (figureWidth * scale);
figureHeightPx = (int) (figureHeight * scale); figureHeightPx = (int) (figureHeight * scale);
Dimension d = new Dimension(figureWidthPx + 2 * borderPixelsWidth, Dimension dpx = new Dimension(
figureWidthPx + 2 * borderPixelsWidth,
figureHeightPx + 2 * borderPixelsHeight); figureHeightPx + 2 * borderPixelsHeight);
if (!d.equals(getPreferredSize()) || !d.equals(getMinimumSize())) { if (!dpx.equals(getPreferredSize()) || !dpx.equals(getMinimumSize())) {
setPreferredSize(d); setPreferredSize(dpx);
setMinimumSize(d); setMinimumSize(dpx);
revalidate(); revalidate();
} }
} }
public Rectangle2D getDimensions() { public Rectangle2D getDimensions() {
calculateFigureBounds();
switch (currentViewType) { switch (currentViewType) {
case SideView: case SideView:
return new Rectangle2D.Double(minX, -maxR, maxX - minX, 2 * maxR); return new Rectangle2D.Double(minX, -maxR, maxX - minX, 2 * maxR);