diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculator.java b/core/src/net/sf/openrocket/masscalc/MassCalculator.java index 2fee4989d..21c48bc7b 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculator.java @@ -15,7 +15,6 @@ import net.sf.openrocket.motor.MotorInstanceConfiguration; import net.sf.openrocket.motor.MotorInstanceId; import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.FlightConfiguration; -import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.simulation.MassData; import net.sf.openrocket.util.Coordinate; @@ -125,8 +124,7 @@ public class MassCalculator implements Monitorable { if(MotorInstanceId.EMPTY_ID == inst.getMotorID()){ throw new IllegalArgumentException(" detected empty motor from .getActiveMotors()"); } - MotorMount mount = inst.getMount(); - if( null == mount ){ + if( null == inst.getMount()){ throw new NullPointerException(" detected null mount"); } if( null == inst.getMotor()){ diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 0c58d0254..9e6966775 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -378,22 +378,17 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ - if( null == fcid){ - throw new NullPointerException(" null FCID passed passed to 'setMotorInstance(...)': bug "); - } if( null == newMotorInstance){ throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug "); - } - + }else{ + if( null == newMotorInstance.getMount()){ + newMotorInstance.setMount(this); + }else if( !this.equals( newMotorInstance.getMount())){ + throw new BugException(" attempt to add a MotorInstance to a second mount, when it's already owned by another mount!"); + } + } + this.motors.set(fcid,newMotorInstance); - - if( newMotorInstance.isEmpty() ){ - return; - }else if( null == newMotorInstance.getMount()){ - newMotorInstance.setMount(this); - }else if( !this.equals( newMotorInstance.getMount())){ - throw new BugException(" adding a MotorInstance to a mount that it isn't owned by... "); - } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index a0ce1f05d..b538b8223 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -219,8 +219,8 @@ public class FlightConfiguration implements FlightConfigurableParameter { } return buffer.toString(); } + // public void printDebug(FlightConfigurationID curFCID){ // if( this.map.containsKey(curFCID)){ diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 9115f5834..a7756ecbd 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -599,10 +599,23 @@ public class Rocket extends RocketComponent { checkState(); return this.configSet.get(id); } + + public void setDefaultConfiguration(final FlightConfigurationID fcid) { + checkState(); + if ( null == fcid ){ + // silently ignore + return; + }else if( this.configSet.containsKey(fcid)){ + configSet.setDefault( configSet.get(fcid)); + }else{ + return; + } + fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); + } /** - * Set the name of the flight configuration. A name can be unset by passing + * Associate the given ID and flight configuration. * null or an empty string. * * @param id the flight configuration id diff --git a/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java b/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java index e3c1a3dcd..3e65635dd 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java @@ -10,6 +10,9 @@ import javax.swing.event.EventListenerList; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameter; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; @@ -22,7 +25,7 @@ import net.sf.openrocket.util.StateChangeListener; */ public class ParameterSetModel> implements ComboBoxModel, StateChangeListener { //private static final Translator trans = Application.getTranslator(); - + private static final Logger log = LoggerFactory.getLogger(ParameterSetModel.class); //private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); private EventListenerList listenerList = new EventListenerList(); @@ -69,6 +72,7 @@ public class ParameterSetModel> impleme } if (!(item instanceof FlightConfigurationID)) { + throw new IllegalArgumentException("MotorConfigurationModel item=" + item); } FlightConfigurationID fcid= (FlightConfigurationID) item; diff --git a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java index 46eb09884..4d4c93507 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -140,7 +140,7 @@ public class GeneralOptimizationDialog extends JDialog { private final DescriptionArea selectedModifierDescription; private final SimulationModifierTree availableModifierTree; - private final JComboBox simulationSelectionCombo; + private final JComboBox simulationSelectionCombo; private final JComboBox optimizationParameterCombo; private final JComboBox optimizationGoalCombo; @@ -375,7 +375,7 @@ public class GeneralOptimizationDialog extends JDialog { disableComponents.add(label); sub.add(label, ""); - simulationSelectionCombo = new JComboBox(); + simulationSelectionCombo = new JComboBox(); simulationSelectionCombo.setToolTipText(tip); populateSimulations(); simulationSelectionCombo.addActionListener(clearHistoryActionListener); @@ -389,7 +389,7 @@ public class GeneralOptimizationDialog extends JDialog { disableComponents.add(label); sub.add(label, ""); - optimizationParameterCombo = new JComboBox(); + optimizationParameterCombo = new JComboBox(); optimizationParameterCombo.setToolTipText(tip); populateParameters(); optimizationParameterCombo.addActionListener(clearHistoryActionListener); @@ -403,7 +403,7 @@ public class GeneralOptimizationDialog extends JDialog { disableComponents.add(label); sub.add(label, ""); - optimizationGoalCombo = new JComboBox(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK }); + optimizationGoalCombo = new JComboBox(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK }); optimizationGoalCombo.setToolTipText(tip); optimizationGoalCombo.setEditable(false); optimizationGoalCombo.addActionListener(clearHistoryActionListener); @@ -502,9 +502,7 @@ public class GeneralOptimizationDialog extends JDialog { panel.add(sub, "span 2, grow, wrap para*2"); // // Rocket figure - FlightConfigurationID fcid = getSelectedSimulation().getOptions().getConfigID(); - FlightConfiguration config = this.getSelectedSimulation().getRocket().getFlightConfiguration( fcid); - figure = new RocketFigure( config ); + figure = new RocketFigure( getSelectedSimulation().getRocket() ); figure.setBorderPixels(1, 1); ScaleScrollPane figureScrollPane = new ScaleScrollPane(figure); figureScrollPane.setFitting(true); @@ -969,8 +967,6 @@ public class GeneralOptimizationDialog extends JDialog { } Simulation sim = new Simulation(rocket); - FlightConfiguration fc = new FlightConfiguration(fcid, rocket); - String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, fcid)); simulations.add(new Named(sim, name)); } @@ -980,7 +976,7 @@ public class GeneralOptimizationDialog extends JDialog { simulations.add(new Named(sim, name)); - simulationSelectionCombo.setModel(new DefaultComboBoxModel(simulations.toArray())); + simulationSelectionCombo.setModel(new DefaultComboBoxModel((String[])simulations.toArray())); simulationSelectionCombo.setSelectedIndex(0); if (current != null) { for (int i = 0; i < simulations.size(); i++) { @@ -1167,10 +1163,9 @@ public class GeneralOptimizationDialog extends JDialog { selectedModifierDescription.setText(""); } - // Update the figure + // Update the active configuration FlightConfigurationID fcid = getSelectedSimulation().getOptions().getConfigID(); - FlightConfiguration config = this.getSelectedSimulation().getRocket().getFlightConfiguration( fcid); - figure.setConfiguration( config); + getSelectedSimulation().getRocket().setDefaultConfiguration(fcid); updating = false; } diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 3e619e820..e928d9f34 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -34,23 +34,24 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import javax.swing.event.MouseInputAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.jogamp.opengl.util.awt.Overlay; + import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.figureelements.CGCaret; import net.sf.openrocket.gui.figureelements.CPCaret; import net.sf.openrocket.gui.figureelements.FigureElement; import net.sf.openrocket.gui.main.Splash; import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.jogamp.opengl.util.awt.Overlay; - /* * @author Bill Kuker */ @@ -74,7 +75,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener { private static final int CARET_SIZE = 20; private final OpenRocketDocument document; - private final FlightConfiguration configuration; + private final Rocket rkt; private Component canvas; @@ -95,9 +96,9 @@ public class RocketFigure3d extends JPanel implements GLEventListener { RocketRenderer rr = new FigureRenderer(); - public RocketFigure3d(final OpenRocketDocument document, final FlightConfiguration config) { + public RocketFigure3d(final OpenRocketDocument document) { this.document = document; - this.configuration = config; + this.rkt = document.getRocket(); this.setLayout(new BorderLayout()); //Only initizlize GL if 3d is enabled. @@ -292,8 +293,10 @@ public class RocketFigure3d extends JPanel implements GLEventListener { setupView(gl, glu); + final FlightConfiguration configuration = rkt.getDefaultConfiguration(); if (pickPoint != null) { gl.glDisable(GLLightingFunc.GL_LIGHTING); + final RocketComponent picked = rr.pick(drawable, configuration, pickPoint, pickEvent.isShiftDown() ? selection : null); if (csl != null) { @@ -485,6 +488,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener { return cachedBounds; } else { final Bounds b = new Bounds(); + final FlightConfiguration configuration = rkt.getDefaultConfiguration(); final Collection bounds = configuration.getBounds(); for (Coordinate c : bounds) { b.xMax = Math.max(b.xMax, c.x); 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 78ec3705e..fd523e4a1 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -27,6 +27,7 @@ import net.sf.openrocket.gui.dialogs.flightconfiguration.MotorMountConfiguration import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorInstance; +import net.sf.openrocket.motor.ThrustCurveMotorInstance; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; @@ -212,11 +213,17 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel Motor m = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); - MotorInstance curInstance = curMount.getMotorInstance(fcid); + //System.err.println("Just selected motor: "+m+" for config: "+fcid); if (m != null) { - curInstance = m.getNewInstance(); + // DEBUG + //System.err.println(" >> new motor: "+m.getDesignation()+" delay: "+d); + + ThrustCurveMotorInstance curInstance = (ThrustCurveMotorInstance) m.getNewInstance(); curInstance.setEjectionDelay(d); curMount.setMotorInstance( fcid, curInstance); + + // DEBUG + //System.err.println(" set?: "+curMount.getMotorInstance(fcid).getMotor().getDesignation()); } fireTableDataChanged(); @@ -281,9 +288,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel MotorInstance curMotor = mount.getMotorInstance( configId); String motorString = getMotorSpecification( curMotor ); -// if( mount instanceof BodyTube ){ +// if( mount instanceof InnerTube ){ // System.err.println("Formatting Cell: fcid="+configId.key.substring(0, 8)); -// ((BodyTube) mount).printMotorDebug(); +// System.err.println( ((InnerTube) mount).toDebugString() ); // } // System.err.println("rendering "+configId.getShortKey()+" cell: " ); // if( rocket.getConfigurationSet().isDefault( configId) ){ diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index 3cd144ba8..ba38bf4f4 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -168,7 +168,7 @@ public class DesignReport { configuration.setAllStages(); PdfContentByte canvas = writer.getDirectContent(); - final PrintFigure figure = new PrintFigure(configuration); + final PrintFigure figure = new PrintFigure(rocket); figure.setRotation(rotation); FigureElement cp = panel.getExtraCP(); diff --git a/swing/src/net/sf/openrocket/gui/print/PrintFigure.java b/swing/src/net/sf/openrocket/gui/print/PrintFigure.java index 784ba8e75..13661be97 100644 --- a/swing/src/net/sf/openrocket/gui/print/PrintFigure.java +++ b/swing/src/net/sf/openrocket/gui/print/PrintFigure.java @@ -4,21 +4,22 @@ package net.sf.openrocket.gui.print; import net.sf.openrocket.gui.scalefigure.RocketFigure; -import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.Rocket; /** * A figure used to override the scale factor in RocketFigure. This allows pinpoint scaling to allow a diagram * to fit in the width of the chosen page size. */ public class PrintFigure extends RocketFigure { - + private static final long serialVersionUID = -3843219909502782607L; + /** * Constructor. * * @param configuration the configuration */ - public PrintFigure(final FlightConfiguration configuration) { - super(configuration); + public PrintFigure(final Rocket rkt) { + super(rkt); } @Override diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index c00320064..8fcf9acae 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -59,7 +59,8 @@ public class RocketFigure extends AbstractScaleFigure { public static final double SELECTED_WIDTH = 2.0; - private FlightConfiguration configuration; + private Rocket rocket; + private RocketComponent[] selection = new RocketComponent[0]; private double figureWidth = 0, figureHeight = 0; protected int figureWidthPx = 0, figureHeightPx = 0; @@ -91,10 +92,9 @@ public class RocketFigure extends AbstractScaleFigure { /** * Creates a new rocket figure. */ - public RocketFigure(FlightConfiguration configuration) { + public RocketFigure(Rocket _rkt) { super(); - - this.configuration = configuration; + this.rocket = _rkt; this.rotation = 0.0; this.transformation = Transformation.rotate_x(0.0); @@ -102,15 +102,8 @@ public class RocketFigure extends AbstractScaleFigure { updateFigure(); } - - /** - * Set the configuration displayed by the figure. It may use the same or different rocket. - * - * @param configuration the configuration to display. - */ - public void setConfiguration(FlightConfiguration configuration) { - this.configuration = configuration; - updateFigure(); + public FlightConfiguration getConfiguration() { + return this.rocket.getDefaultConfiguration(); } @@ -184,7 +177,8 @@ public class RocketFigure extends AbstractScaleFigure { figureShapes.clear(); calculateSize(); - getShapes( figureShapes, configuration); + FlightConfiguration config = rocket.getDefaultConfiguration(); + getShapes( figureShapes, config); repaint(); fireChangeEvent(); @@ -340,7 +334,8 @@ public class RocketFigure extends AbstractScaleFigure { Color borderColor = ((SwingPreferences)Application.getPreferences()).getMotorBorderColor(); //MotorInstanceConfiguration mic = new MotorInstanceConfiguration(configuration); - for( MotorInstance curInstance : configuration.getActiveMotors()){ + FlightConfiguration config = rocket.getDefaultConfiguration(); + for( MotorInstance curInstance : config.getActiveMotors()){ MotorMount mount = curInstance.getMount(); Motor motor = curInstance.getMotor(); double motorLength = motor.getLength(); @@ -352,11 +347,9 @@ public class RocketFigure extends AbstractScaleFigure { Coordinate[] mountLocations = mountComponent.getLocations(); double mountLength = mountComponent.getLength(); - System.err.println("motors are drawing wrong... from here?"); + //System.err.println("Drawing motor from here. Motor: "+motor.getDesignation()+" of length: "+motor.getLength()); for ( Coordinate curMountLocation : mountLocations ){ Coordinate curMotorLocation = curMountLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0); - System.err.println("Translating from mount at "+curMountLocation+" to motor at "+curMotorLocation); - Coordinate coord = curMotorLocation; { @@ -523,7 +516,7 @@ public class RocketFigure extends AbstractScaleFigure { * The bounds are stored in the variables minX, maxX and maxR. */ private void calculateFigureBounds() { - Collection bounds = configuration.getBounds(); + Collection bounds = rocket.getDefaultConfiguration().getBounds(); if (bounds.isEmpty()) { minX = 0; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 4be799148..7e377f201 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -5,6 +5,8 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -128,7 +130,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change private MassCalculator massCalculator; private final OpenRocketDocument document; - private final FlightConfiguration configuration; private Caret extraCP = null; private Caret extraCG = null; @@ -169,17 +170,17 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change } public RocketPanel(OpenRocketDocument document) { - this.document = document; - configuration = document.getDefaultConfiguration(); - + Rocket rkt = document.getRocket(); + + // TODO: FUTURE: calculator selection aerodynamicCalculator = new BarrowmanCalculator(); massCalculator = new MassCalculator(); // Create figure and custom scroll pane - figure = new RocketFigure(configuration); - figure3d = new RocketFigure3d(document, configuration); + figure = new RocketFigure(rkt); + figure3d = new RocketFigure3d(document); figureHolder = new JPanel(new BorderLayout()); @@ -199,7 +200,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change is3d = true; go2D(); - configuration.addChangeListener(new StateChangeListener() { + rkt.addChangeListener(new StateChangeListener() { @Override public void stateChanged(EventObject e) { updateExtras(); @@ -207,7 +208,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change } }); - document.getRocket().addComponentChangeListener(new ComponentChangeListener() { + rkt.addComponentChangeListener(new ComponentChangeListener() { @Override public void componentChanged(ComponentChangeEvent e) { if (is3d) { @@ -296,6 +297,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change add(scaleSelector); // Stage selector + final FlightConfiguration configuration = document.getDefaultConfiguration(); StageSelector stageSelector = new StageSelector(configuration); add(stageSelector); @@ -305,14 +307,29 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change label.setHorizontalAlignment(JLabel.RIGHT); add(label, "growx, right"); - // ?? this model should operate off of either: the rocket (or the FlightConfigurationSet contained in the rocket... ) - ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigurationSet()); - JComboBox flightConfigurationcomboBox = new JComboBox(psm); - add(flightConfigurationcomboBox, "wrap"); + JComboBox flightConfigurationComboBox = new JComboBox(psm); + add(flightConfigurationComboBox, "wrap"); + flightConfigurationComboBox.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent ae) { + Object source = ae.getSource(); + if( source instanceof JComboBox ){ + JComboBox box = (JComboBox) source; + FlightConfiguration newConfig = (FlightConfiguration)box.getSelectedItem(); + document.getRocket().getConfigurationSet().setDefault( newConfig); + updateExtras(); + updateFigures(); + // fireChangeEvent(); + + System.err.println(" processing actionevent for flight config combo box... cmd: "+ae.getActionCommand()); + System.err.println(" seld key: "+newConfig); + } + } + }); + // Create slider and scroll pane - DoubleModel theta = new DoubleModel(figure, "Rotation", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI); UnitSelector us = new UnitSelector(theta, true); @@ -347,7 +364,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change } public FlightConfiguration getConfiguration() { - return configuration; + return document.getDefaultConfiguration(); } /** @@ -550,8 +567,9 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change Coordinate cp, cg; double cpx, cgx; + FlightConfiguration curConfig = document.getDefaultConfiguration(); // TODO: MEDIUM: User-definable conditions - FlightConditions conditions = new FlightConditions(configuration); + FlightConditions conditions = new FlightConditions(curConfig); warnings.clear(); if (!Double.isNaN(cpMach)) { @@ -577,13 +595,13 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change if (!Double.isNaN(cpTheta)) { conditions.setTheta(cpTheta); - cp = aerodynamicCalculator.getCP(configuration, conditions, warnings); + cp = aerodynamicCalculator.getCP(curConfig, conditions, warnings); } else { - cp = aerodynamicCalculator.getWorstCP(configuration, conditions, warnings); + cp = aerodynamicCalculator.getWorstCP(curConfig, conditions, warnings); } extraText.setTheta(cpTheta); - cg = massCalculator.getCG(configuration, MassCalcType.LAUNCH_MASS); + cg = massCalculator.getCG(curConfig, MassCalcType.LAUNCH_MASS); // System.out.println("CG computed as "+cg+ " CP as "+cp); if (cp.weight > 0.000001) @@ -601,7 +619,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change // Length bound is assumed to be tight double length = 0, diameter = 0; - Collection bounds = configuration.getBounds(); + Collection bounds = curConfig.getBounds(); if (!bounds.isEmpty()) { double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; for (Coordinate c : bounds) { @@ -613,7 +631,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change length = maxX - minX; } - for (RocketComponent c : configuration.getActiveComponents()) { + for (RocketComponent c : curConfig.getActiveComponents()) { if (c instanceof SymmetricComponent) { double d1 = ((SymmetricComponent) c).getForeRadius() * 2; double d2 = ((SymmetricComponent) c).getAftRadius() * 2; @@ -652,18 +670,18 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change } // Check whether data is already up to date - if (flightDataFunctionalID == configuration.getRocket().getFunctionalModID() && - flightDataMotorID == configuration.getFlightConfigurationID()) { + if (flightDataFunctionalID == curConfig.getRocket().getFunctionalModID() && + flightDataMotorID == curConfig.getFlightConfigurationID()) { return; } - flightDataFunctionalID = configuration.getRocket().getFunctionalModID(); - flightDataMotorID = configuration.getFlightConfigurationID(); + flightDataFunctionalID = curConfig.getRocket().getFunctionalModID(); + flightDataMotorID = curConfig.getFlightConfigurationID(); // Stop previous computation (if any) stopBackgroundSimulation(); - MotorInstanceConfiguration mic = new MotorInstanceConfiguration( configuration); + MotorInstanceConfiguration mic = new MotorInstanceConfiguration( curConfig); // Check that configuration has motors if (!mic.hasMotors()){ @@ -676,10 +694,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change if(((SwingPreferences) Application.getPreferences()).computeFlightInBackground()){ extraText.setCalculatingData(true); - Rocket duplicate = (Rocket) configuration.getRocket().copy(); + Rocket duplicate = (Rocket) document.getRocket().copy(); Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); simulation.getOptions().setMotorConfigurationID( - configuration.getFlightConfigurationID()); + document.getDefaultConfiguration().getFlightConfigurationID()); backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation); backgroundSimulationExecutor.execute(backgroundSimulationWorker); @@ -765,9 +783,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change * Adds the extra data to the figure. Currently this includes the CP and CG carets. */ private void addExtras() { + FlightConfiguration curConfig = document.getDefaultConfiguration(); extraCG = new CGCaret(0, 0); extraCP = new CPCaret(0, 0); - extraText = new RocketInfo(configuration); + extraText = new RocketInfo(curConfig); updateExtras(); figure.clearRelativeExtra();