diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java index 890c85af0..5aaa42cc3 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java @@ -62,9 +62,7 @@ class MotorConfigurationHandler extends AbstractElementHandler { } if ("true".equals(attributes.remove("default"))) { - // also associate this configuration with the default. - FlightConfiguration fc = rocket.getFlightConfiguration(fcid); - rocket.setSelectedConfiguration( fc); + rocket.setSelectedConfiguration( fcid); } super.closeElement(element, attributes, content, warnings); diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index e86aa4b4c..fc562d5e2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -343,15 +343,7 @@ public class FlightConfiguration implements FlightConfigurableParameter getMotorIDs() { - return motors.keySet(); - } - - public MotorConfiguration getMotorInstance(MotorConfigurationId id) { - return motors.get(id); - } - + public boolean hasMotors() { return (0 < motors.size()); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 2fcecc70e..bcd9b3fb7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -511,7 +511,7 @@ public class Rocket extends RocketComponent { public void freeze() { checkState(); if (freezeList == null) { - freezeList = new LinkedList(); + freezeList = new LinkedList<>(); log.debug("Freezing Rocket"); } else { Application.getExceptionHandler().handleErrorCondition("Attempting to freeze Rocket when it is already frozen, " + @@ -702,24 +702,12 @@ public class Rocket extends RocketComponent { return idList.get(configIndex); } - public void setSelectedConfiguration(final FlightConfiguration config) { + public void setSelectedConfiguration(final FlightConfigurationId selectId) { checkState(); - this.selectedConfiguration = config; + this.selectedConfiguration = this.configSet.get( selectId ); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } - - public void setDefaultConfiguration(final FlightConfigurationId fcid) { - checkState(); - - if( fcid.hasError() ){ - log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid)); - return; - }else if( this.configSet.containsId(fcid)){ - this.selectedConfiguration = configSet.get(fcid); - fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); - } - } - + /** * Associate the given ID and flight configuration. * null or an empty string. diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 580dd5600..9c5ed9b77 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -515,7 +515,7 @@ public class TestRockets { bodytube.setMaterial(material); finset.setMaterial(material); - rocket.setSelectedConfiguration( rocket.getFlightConfiguration( fcid[0])); + rocket.setSelectedConfiguration( fcid[0] ); rocket.getSelectedConfiguration().setAllStages(); rocket.enableEvents(); return rocket; @@ -535,8 +535,7 @@ public class TestRockets { fcid[i] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[i]); } - FlightConfiguration selectedConfiguration = rocket.getFlightConfiguration(fcid[0]); - + double noseconeLength = 0.07; double noseconeRadius = 0.012; NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius); @@ -708,7 +707,7 @@ public class TestRockets { } rocket.getSelectedConfiguration().setAllStages(); - rocket.setSelectedConfiguration( selectedConfiguration ); + rocket.setSelectedConfiguration( fcid[0] ); rocket.enableEvents(); return rocket; } @@ -1024,11 +1023,10 @@ public class TestRockets { Rocket rocket = new Rocket(); rocket.setName("Falcon9H Scale Rocket"); + FlightConfiguration selConfig = rocket.createFlightConfiguration(null); + FlightConfigurationId selFCID = selConfig.getFlightConfigurationID(); + rocket.setSelectedConfiguration(selFCID); - FlightConfiguration selConfig = rocket.createFlightConfiguration(null); - rocket.setSelectedConfiguration(selConfig); - FlightConfigurationId selFCID = selConfig.getFlightConfigurationID(); - // ====== Payload Stage ====== // ====== ====== ====== ====== AxialStage payloadStage = new AxialStage(); @@ -1175,7 +1173,7 @@ public class TestRockets { } rocket.enableEvents(); - rocket.setSelectedConfiguration(selConfig); + rocket.setSelectedConfiguration( selFCID); selConfig.setAllStages(); return rocket; 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 e8c42a5cd..33ec67823 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -1165,11 +1165,7 @@ public class GeneralOptimizationDialog extends JDialog { } else { selectedModifierDescription.setText(""); } - - // Update the active configuration - FlightConfigurationId fcid = getSelectedSimulation().getId(); - getSelectedSimulation().getRocket().setDefaultConfiguration(fcid); - + updating = false; } 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 223256343..724ed3b95 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -115,23 +115,22 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe updateButtonState(); this.add(tabs, "spanx, grow, wrap rel"); - } private void addConfiguration() { - FlightConfigurationId newFCID = new FlightConfigurationId(); - FlightConfiguration newConfig = new FlightConfiguration( rocket, newFCID ); - rocket.setFlightConfiguration(newFCID, newConfig); - + FlightConfigurationId newId = new FlightConfigurationId(); + FlightConfiguration newConfig = new FlightConfiguration( rocket, newId ); + rocket.setFlightConfiguration( newId, newConfig); + // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); + createSimulationForNewConfiguration( newId ); configurationChanged(); } private void copyConfiguration() { - FlightConfiguration oldConfig = rocket.getSelectedConfiguration(); - FlightConfigurationId oldId = oldConfig.getFlightConfigurationID(); + FlightConfigurationId oldId = this.motorConfigurationPanel.getSelectedConfigurationId(); + FlightConfiguration oldConfig = rocket.getFlightConfiguration(oldId); FlightConfigurationId newId = new FlightConfigurationId(); FlightConfiguration newConfig = oldConfig.copy( newId); @@ -141,10 +140,11 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe ((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId); } } - rocket.setFlightConfiguration(newId, newConfig); - - // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); + rocket.setFlightConfiguration( newId, newConfig); + + + // Create a new simulation for this configuration. + createSimulationForNewConfiguration( newId); configurationChanged(); } @@ -165,7 +165,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe /** * prereq - assumes that the new configuration has been set as the default configuration. */ - private void createSimulationForNewConfiguration() { + private void createSimulationForNewConfiguration( final FlightConfigurationId fcid ) { Simulation newSim = new Simulation(rocket); OpenRocketDocument doc = BasicFrame.findDocument(rocket); if (doc != null) { diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 988cfed62..a843a00e8 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -320,7 +320,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change @Override public void actionPerformed(ActionEvent ae) { FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem(); - document.getRocket().setSelectedConfiguration( newConfig); + document.getRocket().setSelectedConfiguration( newConfig.getId()); updateExtras(); updateFigures(); }