diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java index 8a1fea22a..7b7c8807e 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java @@ -71,12 +71,11 @@ class MotorMountHandler extends AbstractElementHandler { warnings.add(Warning.fromString("Illegal motor specification, ignoring.")); return; } - Motor motor = motorHandler.getMotor(warnings); MotorInstance motorInstance = motor.getNewInstance(); - RocketComponent rc = (RocketComponent)mount; - motorInstance.setID( new MotorInstanceId(rc.getID(), 1)); + RocketComponent mountComponent = (RocketComponent)mount; + motorInstance.setID( new MotorInstanceId(mountComponent.getID(), 1)); motorInstance.setEjectionDelay(motorHandler.getDelay(warnings)); mount.setMotorInstance(fcid, motorInstance); diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java index b6d18d07d..bcdc60efe 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotorInstance.java @@ -256,14 +256,14 @@ public class ThrustCurveMotorInstance extends MotorInstance { sb.append(String.format("%s Ignite: %s at %+f\n",prefix, this.ignitionEvent.name, this.ignitionDelay)); //sb.append(String.format("%s Eject at: %+f\n",prefix, this.ejectionDelay)); sb.append(String.format("%s L:%f W:%f @:%f mm\n",prefix, motor.getLength(), motor.getDiameter(), this.position.multiply(1000).x )); - sb.append(String.format("%s currentTimem: %f\n", prefix, this.prevTime)); + sb.append(String.format("%s currentTime: %f\n", prefix, this.prevTime)); sb.append("\n"); return sb.toString(); } @Override public String toString(){ - return this.id.toString(); + return this.motor.getDesignation() + this.id.toShortKey(); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 895c4a658..e0a694619 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -13,6 +13,7 @@ import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.motor.MotorInstanceId; import net.sf.openrocket.util.ArrayList; @@ -39,9 +40,13 @@ public class FlightConfiguration implements FlightConfigurableParameter listenerList = new ArrayList(); - protected class StageFlags { + protected class StageFlags implements Cloneable { public boolean active = true; public int prev = -1; public AxialStage stage = null; @@ -51,6 +56,16 @@ public class FlightConfiguration implements FlightConfigurableParameterfalse) or active (true) */ - public void setStageActive(final int stageNumber, final boolean _active) { + public void setStageActive(final int stageNumber, final boolean _active ) { + this.setStageActive(stageNumber, _active, true ); + } + + private void setStageActive(final int stageNumber, final boolean _active, final boolean fireEvent) { if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) { stages.get(stageNumber).active = _active; - fireChangeEvent(); + if( fireEvent ){ + fireChangeEvent(); + } return; } log.error("error: attempt to retrieve via a bad stage number: " + stageNumber); @@ -158,10 +186,6 @@ public class FlightConfiguration implements FlightConfigurableParameter= this.rocket.getStageCount()) { - return false; - } - if( ! stages.containsKey(stageNumber)){ throw new IllegalArgumentException(" Configuration does not contain stage number: "+stageNumber); } @@ -200,7 +224,7 @@ public class FlightConfiguration implements FlightConfigurableParameter \n", curMotor.getID().toShortKey())); + buff.append( String.format( " ..[%2d/%2d][%8s] \n", motorInstanceNumber+1, intanceCount, curMotor.getID().toShortKey())); }else{ - buff.append( String.format( " ..[%8s] (%s) %10s (in: %s)\n", - curMotor.getID().toShortKey(), - (curMotor.isActive()? " on": "off"), - curMotor.getMotor().getDesignation(), - ((RocketComponent)curMotor.getMount()).toDebugName() )); + buff.append( String.format( " ..[%2d/%2d](%6s) %-10s (in: %s)(id: %8s)\n", + motorInstanceNumber+1, intanceCount, + (curMotor.isActive()? "active": "inactv"),curMotor.getMotor().getDesignation(), + ((RocketComponent)curMotor.getMount()).getName(), curMotor.getID().toShortKey() )); } + ++motorInstanceNumber; } return buff.toString(); - } - - public String getMotorsOneline(){ StringBuilder buff = new StringBuilder("["); boolean first = true; + int activeMotorCount = 0; for ( RocketComponent comp : getActiveComponents() ){ if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ MotorMount mount = (MotorMount)comp; @@ -388,15 +412,17 @@ public class FlightConfiguration implements FlightConfigurableParameter motor.refpoint Coordinate curMotorOffset = cloneInstance.getOffset(); cloneInstance.setPosition( curMountLocation.add(curMotorOffset) ); this.motors.put( cloneInstance.getID(), cloneInstance); - instanceNumber ++; + motorInstanceNumber ++; } } } - //System.err.println("returning "+toReturn.size()+" active motor instances for this configuration: "+this.fcid.getShortKey()); - //System.err.println(this.rocket.getConfigurationSet().toDebug()); } /////////////// Helper methods /////////////// @@ -597,9 +621,11 @@ public class FlightConfiguration implements FlightConfigurableParameter(); - clone.stages.putAll( (Map) this.stages); + for( StageFlags flags : this.stages.values()){ + clone.stages.put( flags.stage.getStageNumber(), flags.clone()); + } for( MotorInstance mi : this.motors.values()){ clone.motors.put( mi.getID(), mi.clone()); } @@ -607,7 +633,6 @@ public class FlightConfiguration implements FlightConfigurableParameter> implements F * @param component the rocket component on which events are fired when the parameter values are changed * @param eventType the event type that will be fired on changes */ - public ParameterSet(ParameterSet flightConfiguration, RocketComponent component, int eventType) { + public ParameterSet(ParameterSet configSet, RocketComponent component, int eventType) { this.component = component; this.eventType = eventType; - this.defaultValue= flightConfiguration.getDefault().clone(); - for (FlightConfigurationID key : flightConfiguration.map.keySet()) { - this.map.put(key, flightConfiguration.map.get(key).clone()); + this.defaultValue= configSet.getDefault().clone(); + for (FlightConfigurationID key : configSet.map.keySet()) { + E cloneConfig = configSet.map.get(key).clone(); + this.map.put(key, cloneConfig); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 94316b5bc..b3d39854b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -989,6 +989,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab * @deprecated name is ambiguous in three-dimensional space: value may refer to any of the three dimensions. Please use 'setAxialOffset' instead. * @param value the position value of the component. */ + @Deprecated public void setPositionValue(double value) { // if (MathUtil.equals(this.position.x, value)) // return; @@ -1097,6 +1098,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab * @deprecated kept around as example code. instead use getLocations * @return */ + @Deprecated private Coordinate getAbsoluteVector() { if (null == this.parent) { // == improperly initialized components OR the root Rocket instance @@ -2127,7 +2129,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab } public void toDebugTreeNode(final StringBuilder buffer, final String prefix) { - buffer.append(String.format("%-42s; %5.3f; %24s; %24s;\n", prefix+" "+this.getName(), + buffer.append(String.format("%-40s; %5.3f; %24s; %24s;\n", prefix+" "+this.getName(), this.getLength(), this.getOffset(), this.getLocations()[0])); } @@ -2136,7 +2138,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab Iterator iterator = this.children.iterator(); while (iterator.hasNext()) { - iterator.next().dumpTreeHelper(buffer, prefix + " "); + iterator.next().dumpTreeHelper(buffer, prefix + "...."); } } } diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java index 7e7c288de..25c3f9e8a 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -146,6 +146,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe } } rocket.setFlightConfiguration(newId, newConfig); + rocket.addComponentChangeListener( newConfig); // Create a new simulation for this configuration. createSimulationForNewConfiguration(); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 25e9c8aa4..e73e9a5a8 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -34,6 +34,7 @@ import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.Chars; @@ -169,7 +170,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel configurationTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - MotorConfigurationPanel.this.updateButtonState(); + updateButtonState(); int selectedColumn = table.getSelectedColumn(); if (e.getClickCount() == 2) { if (selectedColumn > 0) { @@ -200,7 +201,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel } } - private void selectMotor() { MotorMount curMount = getSelectedComponent(); FlightConfigurationID fcid= getSelectedConfigurationId(); @@ -208,26 +208,21 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel return; } + //MotorInstance curInstance = curMount.getMotorInstance( fcid ); + // curInstance may be empty here... + //String mountName = ((RocketComponent)curMount).getName(); + //System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey()); + motorChooserDialog.setMotorMountAndConfig( fcid, curMount ); motorChooserDialog.setVisible(true); Motor mtr = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); - - // DEBUG - //System.err.println("Just selected motor for config: "+fcid.toShortKey()); if (mtr != null) { - // DEBUG - //System.err.println(" >> new motor: "+mtr.getDesignation()+" delay: "+d); - MotorInstance curInstance = mtr.getNewInstance(); - //System.err.println(" >> new instance: "+curInstance.toString()); curInstance.setEjectionDelay(d); curInstance.setIgnitionEvent( IgnitionEvent.AUTOMATIC); curMount.setMotorInstance( fcid, curInstance); - - // DEBUG - //System.err.println(" set?: "+curMount.getMotorInstance(fcid).toString()); } fireTableDataChanged(); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 4a0bfad19..2696fb973 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -18,6 +18,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import net.sf.openrocket.gui.figureelements.FigureElement; import net.sf.openrocket.gui.rocketfigure.RocketComponentShape; import net.sf.openrocket.gui.util.ColorConversion; @@ -30,6 +33,7 @@ import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.simulation.BasicEventSimulationEngine; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; @@ -46,7 +50,9 @@ import net.sf.openrocket.util.Transformation; * @author Sampo Niskanen */ public class RocketFigure extends AbstractScaleFigure { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 45884403769043138L; + + private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class); private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure"; private static final String ROCKET_FIGURE_SUFFIX = "Shapes"; @@ -228,7 +234,7 @@ public class RocketFigure extends AbstractScaleFigure { // Update figure shapes if necessary if (figureShapes == null) updateFigure(); - + double tx, ty; // Calculate translation for figure centering @@ -277,10 +283,9 @@ public class RocketFigure extends AbstractScaleFigure { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - + int shapeCount = figureShapes.size(); // Draw all shapes - - for (int i = 0; i < figureShapes.size(); i++) { + for (int i = 0; i < shapeCount; i++) { RocketComponentShape rcs = figureShapes.get(i); RocketComponent c = rcs.getComponent(); boolean selected = false; @@ -321,7 +326,6 @@ public class RocketFigure extends AbstractScaleFigure { RenderingHints.VALUE_STROKE_NORMALIZE); } g2.draw(rcs.shape); - } g2.setStroke(new BasicStroke((float) (NORMAL_WIDTH * EXTRA_SCALE / scale), @@ -332,9 +336,8 @@ public class RocketFigure extends AbstractScaleFigure { // Draw motors Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor(); Color borderColor = ((SwingPreferences)Application.getPreferences()).getMotorBorderColor(); - - //MotorInstanceConfiguration mic = new MotorInstanceConfiguration(configuration); - FlightConfiguration config = rocket.getDefaultConfiguration(); + + FlightConfiguration config = rocket.getDefaultConfiguration(); for( MotorInstance curInstance : config.getActiveMotors()){ MotorMount mount = curInstance.getMount(); Motor motor = curInstance.getMotor(); @@ -372,7 +375,6 @@ public class RocketFigure extends AbstractScaleFigure { } - // Draw relative extras for (FigureElement e : relativeExtra) { e.paint(g2, scale / EXTRA_SCALE); @@ -421,17 +423,13 @@ public class RocketFigure extends AbstractScaleFigure { // facade for the recursive function below private void getShapes(ArrayList allShapes, FlightConfiguration configuration){ for( AxialStage stage : configuration.getActiveStages()){ - // for debug... - //int stageNumber = stage.getStageNumber(); - //String activeString = ( configuration.isStageActive(stageNumber) ? "active" : "inactive"); - getShapeTree( allShapes, stage, Coordinate.ZERO); } } // NOTE: Recursive function private void getShapeTree( - ArrayList allShapes, // this is the output parameter + ArrayList allShapes, // output parameter final RocketComponent comp, final Coordinate parentLocation){