diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 03d5ddba5..fca963520 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -164,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener { public FlightConfiguration getDefaultConfiguration() { - return rocket.getDefaultConfiguration(); + return rocket.getSelectedConfiguration(); } public File getFile() { diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index 2864f6f8a..da2bcd383 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -116,7 +116,7 @@ public class Simulation implements ChangeSource, Cloneable { DefaultSimulationOptionFactory f = Application.getInjector().getInstance(DefaultSimulationOptionFactory.class); options.copyConditionsFrom(f.getDefault()); - FlightConfigurationId fcid = rocket.getDefaultConfiguration().getFlightConfigurationID(); + FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID(); options.setFlightConfigurationId(fcid); options.addChangeListener(new ConditionListener()); } 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 9b7c5fa40..ba6399239 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java @@ -10,10 +10,12 @@ import net.sf.openrocket.file.DocumentLoadingContext; import net.sf.openrocket.file.simplesax.AbstractElementHandler; import net.sf.openrocket.file.simplesax.ElementHandler; import net.sf.openrocket.file.simplesax.PlainTextHandler; +import net.sf.openrocket.optimization.rocketoptimization.OptimizableParameter; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.util.Named; class MotorConfigurationHandler extends AbstractElementHandler { @SuppressWarnings("unused") @@ -63,10 +65,9 @@ class MotorConfigurationHandler extends AbstractElementHandler { } if ("true".equals(attributes.remove("default"))) { - // associate this configuration with both this FCID and the default. - FlightConfigurableParameterSet fcs = rocket.getConfigSet(); - FlightConfiguration fc = fcs.get(fcid); - fcs.setDefault(fc); + // also associate this configuration with the default. + FlightConfiguration fc = rocket.getFlightConfiguration(fcid); + rocket.setSelectedConfiguration( fc); } super.closeElement(element, attributes, content, warnings); diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java index f5aa06a87..a81cc9ac8 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java @@ -6,9 +6,7 @@ import java.util.Locale; import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.ParallelStage; -import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; -import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; @@ -45,31 +43,27 @@ public class AxialStageSaver extends ComponentAssemblySaver { if (stage.getStageNumber() > 0) { // NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on - elements.addAll(separationConfig(stage.getSeparationConfigurations().getDefault(), false)); + elements.addAll(addSeparationConfigParams(stage.getSeparationConfigurations().getDefault(), false)); - Rocket rocket = stage.getRocket(); // Note - getFlightConfigurationIDs returns at least one element. The first element - // is null and means "default". - - for (FlightConfiguration curConfig : rocket.getConfigSet()){ - FlightConfigurationId fcid = curConfig.getFlightConfigurationID(); + for (FlightConfigurationId fcid: stage.getSeparationConfigurations().getIds() ){ if (fcid == null) { continue; } - StageSeparationConfiguration curSepCfg = stage.getSeparationConfigurations().get(fcid); - if( stage.getSeparationConfigurations().isDefault( curSepCfg )){ - continue; - } + +// if( stage.getSeparationConfigurations().isDefault( curSepCfg )){ +// continue; +// } elements.add(""); - elements.addAll(separationConfig(curSepCfg, true)); + elements.addAll(addSeparationConfigParams(curSepCfg, true)); elements.add(""); } } } - private List separationConfig(StageSeparationConfiguration config, boolean indent) { + private List addSeparationConfigParams(StageSeparationConfiguration config, boolean indent) { List elements = new ArrayList(2); elements.add((indent ? " " : "") + "" + config.getSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java index 2168444d7..28a8f4d34 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java @@ -5,11 +5,9 @@ import java.util.List; import java.util.Locale; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; -import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.RecoveryDevice; -import net.sf.openrocket.rocketcomponent.Rocket; public class RecoveryDeviceSaver extends MassObjectSaver { @@ -27,35 +25,24 @@ public class RecoveryDeviceSaver extends MassObjectSaver { elements.add(materialParam(dev.getMaterial())); // NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on - DeploymentConfiguration defaultConfig = dev.getDeploymentConfigurations().getDefault(); - elements.addAll(deploymentConfiguration(defaultConfig, false)); + FlightConfigurableParameterSet configSet = dev.getDeploymentConfigurations(); + DeploymentConfiguration defaultConfig = configSet.getDefault(); + elements.addAll(addDeploymentConfigurationParams(defaultConfig, false)); - Rocket rocket = c.getRocket(); - - // DEBUG - //System.err.println("printing deployment info for: "+dev.getName()); - //dev.getDeploymentConfigurations().printDebug(); - // DEBUG - - FlightConfigurableParameterSet configList = rocket.getConfigSet(); - for (FlightConfigurationId fcid : configList.getSortedConfigurationIDs()) { - //System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?"); - + for (FlightConfigurationId fcid : configSet.getIds()) { if (dev.getDeploymentConfigurations().isDefault(fcid)) { - //System.err.println(" >> skipping: fcid="+fcid.getShortKey()); continue; - }else if( dev.getDeploymentConfigurations().containsKey(fcid)){ + }else{ // only print configurations which override the default. - //System.err.println(" >> printing data."); DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid); elements.add(""); - elements.addAll(deploymentConfiguration(deployConfig, true)); + elements.addAll(addDeploymentConfigurationParams(deployConfig, true)); elements.add(""); } } } - private List deploymentConfiguration(DeploymentConfiguration config, boolean indent) { + private List addDeploymentConfigurationParams(DeploymentConfiguration config, boolean indent) { List elements = new ArrayList(3); elements.add((indent ? " " : "") + "" + config.getDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + ""); elements.add((indent ? " " : "") + "" + config.getDeployAltitude() + ""); diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index bdcbe4628..7ba91df78 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -190,7 +190,7 @@ public class RocketComponentSaver { elements.add(" " + defaultInstance.getIgnitionDelay() + ""); elements.add(" " + mount.getMotorOverhang() + ""); - for( FlightConfigurationId fcid : rkt.getSortedConfigurationIDs()){ + for( FlightConfigurationId fcid : rkt.getIds()){ MotorConfiguration motorInstance = mount.getMotorInstance(fcid); // Nothing is stored if no motor loaded diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java index f3ef89f11..4097a6994 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java @@ -6,7 +6,6 @@ import java.util.Locale; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; -import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.ReferenceType; import net.sf.openrocket.rocketcomponent.Rocket; @@ -43,15 +42,15 @@ public class RocketSaver extends RocketComponentSaver { // Motor configurations - FlightConfigurableParameterSet allConfigs = rocket.getConfigSet(); - for (FlightConfigurationId fcid : allConfigs.getSortedConfigurationIDs()) { - FlightConfiguration flightConfig = allConfigs.get(fcid); + for (FlightConfigurationId fcid : rocket.getIds()) { + FlightConfiguration flightConfig = rocket.getFlightConfiguration(fcid); if (fcid == null) continue; + // these are actually FlightConfigurationIds, buuuuuuuuuut backwards-compatible tags. String str = " configs = (FlightConfigurableParameterSet) configGetter.invoke(c); - return configs.get(simulation.getRocket().getDefaultConfiguration().getFlightConfigurationID()); + return configs.get(simulation.getRocket().getSelectedConfiguration().getFlightConfigurationID()); } } diff --git a/core/src/net/sf/openrocket/optimization/rocketoptimization/parameters/StabilityParameter.java b/core/src/net/sf/openrocket/optimization/rocketoptimization/parameters/StabilityParameter.java index 0b5c2faeb..c6e3595b9 100644 --- a/core/src/net/sf/openrocket/optimization/rocketoptimization/parameters/StabilityParameter.java +++ b/core/src/net/sf/openrocket/optimization/rocketoptimization/parameters/StabilityParameter.java @@ -59,7 +59,7 @@ public class StabilityParameter implements OptimizableParameter { MassCalculator massCalculator = new MassCalculator(); - FlightConfiguration configuration = simulation.getRocket().getDefaultConfiguration(); + FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration(); FlightConditions conditions = new FlightConditions(configuration); conditions.setMach(Application.getPreferences().getDefaultMach()); conditions.setAOA(0); diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index c9dc8e2d5..07f0dc033 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -47,12 +47,6 @@ public class FlightConfigurableParameterSet> Why am I being cloned!?", new IllegalStateException(this.toDebug()+" >to> "+clone.toDebug())); + // DO NOT UPDATE: // this.stages and this.motors are updated correctly on their own. - clone.cachedBounds = this.cachedBounds.clone(); clone.modID = this.modID; clone.boundsModID = -1; diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 2e9007394..1869b9fda 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -412,7 +412,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra Coordinate[] relCoords = this.getInstanceOffsets(); Coordinate[] absCoords = this.getLocations(); - FlightConfigurationId curId = this.getRocket().getDefaultConfiguration().getFlightConfigurationID(); + FlightConfigurationId curId = this.getRocket().getSelectedConfiguration().getFlightConfigurationID(); final int intanceCount = this.getInstanceCount(); MotorConfiguration curInstance = this.motors.get(curId); if( curInstance.isEmpty() ){ diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index fe2b70872..81feba060 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -67,12 +67,13 @@ public class Rocket extends RocketComponent { // Flight configuration list - private FlightConfigurableParameterSet configSet; + private FlightConfiguration selectedConfiguration; + private HashMap configSet = new HashMap(); + private HashMap stageMap = new HashMap(); // Does the rocket have a perfect finish (a notable amount of laminar flow) private boolean perfectFinish = false; - private final HashMap stageMap = new HashMap(); ///////////// Constructor ///////////// @@ -84,8 +85,10 @@ public class Rocket extends RocketComponent { treeModID = modID; functionalModID = modID; - FlightConfiguration defaultConfiguration = new FlightConfiguration( this, null); - this.configSet = new FlightConfigurableParameterSet( defaultConfiguration); + + + // must be after the hashmaps :P + this.selectedConfiguration = new FlightConfiguration( this, null); } public String getDesigner() { @@ -301,12 +304,32 @@ public class Rocket extends RocketComponent { @Override public Rocket copyWithOriginalID() { Rocket copy = (Rocket) super.copyWithOriginalID(); - copy.configSet = new FlightConfigurableParameterSet( this.configSet); - copy.resetListeners(); + + // Rocket copy is cloned, so non-trivial members must be cloned as well: + copy.stageMap = new HashMap(); + copy.configSet = new HashMap(); + if( 0 < this.configSet.size() ){ + Rocket.cloneConfigs( this, copy); + } + copy.listenerList = new ArrayList(); return copy; } + private static void cloneConfigs( final Rocket source, Rocket dest ){ + source.checkState(); + dest.checkState(); + dest.selectedConfiguration = source.selectedConfiguration.clone(); + for( final FlightConfiguration config : source.configSet.values() ){ + dest.configSet.put( config.getId(), config.clone() ); + } + } + + public int getFlightConfigurationCount() { + checkState(); + return this.configSet.size(); + } + /** * Load the rocket structure from the source. The method loads the fields of this * Rocket object and copies the references to siblings from the source. @@ -337,8 +360,8 @@ public class Rocket extends RocketComponent { this.functionalModID = r.functionalModID; this.refType = r.refType; this.customReferenceLength = r.customReferenceLength; + Rocket.cloneConfigs( r, this); - this.configSet = new FlightConfigurableParameterSet( r.configSet ); this.perfectFinish = r.perfectFinish; this.checkComponentStructure(); @@ -458,7 +481,9 @@ public class Rocket extends RocketComponent { @Override public void update(){ - this.configSet.update(); + for( FlightConfiguration config : configSet.values() ){ + config.update(); + } } /** @@ -529,15 +554,15 @@ public class Rocket extends RocketComponent { /** - * Return the default configuration. This should be used in the user interface + * Return the currently selected configuration. This should be used in the user interface * to ensure a consistent rocket configuration between dialogs. It should NOT * be used in simulations not relating to the UI. * - * @return the default {@link FlightConfiguration}. + * @return the current {@link FlightConfiguration}. */ - public FlightConfiguration getDefaultConfiguration() { + public FlightConfiguration getSelectedConfiguration() { checkState(); - return this.configSet.getDefault(); + return this.selectedConfiguration; } public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) { @@ -548,8 +573,8 @@ public class Rocket extends RocketComponent { return this.configSet.get(fcid); }else{ FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); - this.configSet.set(fcid, nextConfig); - this.configSet.setDefault( nextConfig); + this.configSet.put(fcid, nextConfig); + this.selectedConfiguration = nextConfig; fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); return nextConfig; } @@ -559,16 +584,28 @@ public class Rocket extends RocketComponent { return this.configSet.size(); } - public FlightConfigurableParameterSet getConfigSet(){ - checkState(); - return this.configSet; - } - - public List getSortedConfigurationIDs(){ - return configSet.getSortedConfigurationIDs(); + public List getIds(){ + ArrayList toReturn = new ArrayList(this.configSet.keySet()); + + // Java 1.8: + //toReturn.sort( null ); + + // Java 1.7: + Collections.sort(toReturn); + + return toReturn; } + /** + * Primarily for use with UI elements + * + * @return list of attached flight configurations (unordered) + */ + public FlightConfiguration[] toConfigArray(){ + return this.configSet.values().toArray( new FlightConfiguration[0]); + } + /** * Remove a flight configuration ID from the configuration IDs. The null * ID cannot be removed, and an attempt to remove it will be silently ignored. @@ -582,7 +619,7 @@ public class Rocket extends RocketComponent { } // Get current configuration: - this.configSet.set(fcid, null); + this.configSet.remove( fcid); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } @@ -649,12 +686,17 @@ public class Rocket extends RocketComponent { * @return a FlightConfiguration instance */ public FlightConfiguration getFlightConfiguration(final int configIndex) { - return this.configSet.get(configIndex); + return this.configSet.get( this.getId(configIndex)); } - public void setDefaultConfiguration(final FlightConfiguration config) { + public FlightConfigurationId getId( final int configIndex) { + List idList = this.getIds(); + return idList.get(configIndex); + } + + public void setSelectedConfiguration(final FlightConfiguration config) { checkState(); - configSet.setDefault( config); + this.selectedConfiguration = config; fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } @@ -665,7 +707,7 @@ public class Rocket extends RocketComponent { log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid)); return; }else if( this.configSet.containsKey(fcid)){ - configSet.setDefault( configSet.get(fcid)); + this.selectedConfiguration = configSet.get(fcid); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } } @@ -687,7 +729,7 @@ public class Rocket extends RocketComponent { if (null == newConfig){ newConfig = createFlightConfiguration(fcid); } - configSet.set(fcid, newConfig); + configSet.put(fcid, newConfig); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } @@ -768,4 +810,18 @@ public class Rocket extends RocketComponent { } } + public String toDebugConfigs(){ + StringBuilder buf = new StringBuilder(); + buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName())); + final String fmt = " [%-12s]: %s\n"; + for( FlightConfiguration config : this.configSet.values() ){ + String shortKey = config.getId().toShortKey(); + if( this.selectedConfiguration.equals( config)){ + shortKey = "*"+shortKey+"*"; + } + buf.append(String.format(fmt, shortKey, config.getName() )); + } + return buf.toString(); + } + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java b/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java index 6169976a6..e97b8dcad 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java @@ -10,7 +10,7 @@ public abstract class RocketUtils { public static double getLength(Rocket rocket) { double length = 0; - Collection bounds = rocket.getDefaultConfiguration().getBounds(); + Collection bounds = rocket.getSelectedConfiguration().getBounds(); if (!bounds.isEmpty()) { double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; for (Coordinate c : bounds) { @@ -27,7 +27,7 @@ public abstract class RocketUtils { // get rid of this method.... we can sure come up with a better way to do this.... public static Coordinate getCG(Rocket rocket, MassCalcType calcType) { MassCalculator massCalculator = new MassCalculator(); - Coordinate cg = massCalculator.getCG(rocket.getDefaultConfiguration(), calcType); + Coordinate cg = massCalculator.getCG(rocket.getSelectedConfiguration(), calcType); return cg; } diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index 3fa004f92..562df836c 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -451,7 +451,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.configId); FlightConfigurationId matchID = null; - for (FlightConfigurationId fcid : this.rocket.getSortedConfigurationIDs()){ + for (FlightConfigurationId fcid : rocket.getIds()){ String motorDesc2 = formatter.getMotorConfigurationDescription(this.rocket, fcid); if (motorDesc.equals(motorDesc2)) { matchID = fcid; diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index a1086cf5e..a948ef134 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -464,7 +464,7 @@ public class TestRockets { bodytube.setMaterial(material); finset.setMaterial(material); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); FlightConfigurationId fcid = config.getFlightConfigurationID(); ThrustCurveMotor motor = getTestMotor(); @@ -715,7 +715,7 @@ public class TestRockets { rocket.addChild(stage); rocket.setPerfectFinish(false); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); // FlightConfigurationID fcid = config.getFlightConfigurationID(); // Motor m = Application.getMotorSetDatabase().findMotors(null, null, "L540", Double.NaN, Double.NaN).get(0); @@ -733,7 +733,7 @@ public class TestRockets { public static Rocket makeFalcon9Heavy() { Rocket rocket = new Rocket(); rocket.setName("Falcon9H Scale Rocket"); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); // ====== Payload Stage ====== // ====== ====== ====== ====== @@ -966,7 +966,7 @@ public class TestRockets { Rocket rocket = new Rocket(); rocket.setName("v104_withMotorConfig"); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); FlightConfigurationId fcid = config.getFlightConfigurationID(); config.setName("F12X"); @@ -1002,7 +1002,7 @@ public class TestRockets { Rocket rocket = new Rocket(); rocket.setName("v104_withSimulationData"); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); FlightConfigurationId fcid = config.getFlightConfigurationID(); config.setName("F12X"); diff --git a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java index 0157bf759..d6ab26cc5 100644 --- a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java +++ b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java @@ -46,7 +46,7 @@ public class BarrowmanCalculatorTest { @Test public void testCPSimpleDry() { Rocket rocket = TestRockets.makeEstesAlphaIII(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); AerodynamicCalculator calc = new BarrowmanCalculator(); FlightConditions conditions = new FlightConditions(config); WarningSet warnings = new WarningSet(); @@ -63,7 +63,7 @@ public class BarrowmanCalculatorTest { @Test public void testCPSimpleWithMotor() { Rocket rkt = TestRockets.makeEstesAlphaIII(); - FlightConfiguration config = rkt.getDefaultConfiguration(); + FlightConfiguration config = rkt.getSelectedConfiguration(); FlightConfigurationId fcid = config.getFlightConfigurationID(); AerodynamicCalculator calc = new BarrowmanCalculator(); FlightConditions conditions = new FlightConditions(config); @@ -90,7 +90,7 @@ public class BarrowmanCalculatorTest { @Test public void testCPDoubleStrapOn() { Rocket rocket = TestRockets.makeFalcon9Heavy(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); BarrowmanCalculator calc = new BarrowmanCalculator(); FlightConditions conditions = new FlightConditions(config); WarningSet warnings = new WarningSet(); diff --git a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java index 5ba93197c..852521f82 100644 --- a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java +++ b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java @@ -35,7 +35,7 @@ public class MassCalculatorTest extends BaseTestCase { // Validate Boosters MassCalculator mc = new MassCalculator(); //mc.debug = true; - Coordinate rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.NO_MOTORS); + Coordinate rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.NO_MOTORS); double expMass = 0.668984592; double expCMx = 0.558422219894; @@ -47,9 +47,9 @@ public class MassCalculatorTest extends BaseTestCase { assertEquals(" Delta Heavy Booster CM.z is incorrect: ", expCM.z, rocketCM.z, EPSILON); assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM); - rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS); + rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.LAUNCH_MASS); assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM); - rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.BURNOUT_MASS); + rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.BURNOUT_MASS); assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM); } @@ -267,14 +267,14 @@ public class MassCalculatorTest extends BaseTestCase { ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); int boostNum = boosters.getStageNumber(); - rocket.getDefaultConfiguration().clearAllStages(); - rocket.getDefaultConfiguration().setOnlyStage( boostNum); + rocket.getSelectedConfiguration().clearAllStages(); + rocket.getSelectedConfiguration().setOnlyStage( boostNum); // String treeDump = rocket.toDebugTree(); // System.err.println( treeDump); // Validate Boosters MassCalculator mc = new MassCalculator(); - Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS); + Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS); double expMass = 0.23590802751203407; double expCMx = 0.9615865040919498; @@ -296,14 +296,14 @@ public class MassCalculatorTest extends BaseTestCase { ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); int boostNum = boosters.getStageNumber(); //rocket.getDefaultConfiguration().setAllStages(false); - rocket.getDefaultConfiguration().setOnlyStage( boostNum); + rocket.getSelectedConfiguration().setOnlyStage( boostNum); //String treeDump = rocket.toDebugTree(); //System.err.println( treeDump); { // Validate Booster Launch Mass MassCalculator mc = new MassCalculator(); - Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS); + Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.LAUNCH_MASS); double calcTotalMass = boosterSetCM.weight; double expTotalMass = 1.219908027512034; @@ -318,7 +318,7 @@ public class MassCalculatorTest extends BaseTestCase { { // Validate Booster Burnout Mass MassCalculator mc = new MassCalculator(); - Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.BURNOUT_MASS); + Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.BURNOUT_MASS); double calcTotalMass = boosterSetCM.weight; double expTotalMass = 0.7479080275020341; @@ -337,12 +337,12 @@ public class MassCalculatorTest extends BaseTestCase { public void testTestBoosterStructureMOI() { Rocket rocket = TestRockets.makeFalcon9Heavy(); rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName()); - FlightConfiguration defaultConfig = rocket.getDefaultConfiguration(); + FlightConfiguration defaultConfig = rocket.getSelectedConfiguration(); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); int boostNum = boosters.getStageNumber(); - rocket.getDefaultConfiguration().setOnlyStage( boostNum); + rocket.getSelectedConfiguration().setOnlyStage( boostNum); // String treeDump = rocket.toDebugTree(); // System.err.println( treeDump); @@ -361,14 +361,14 @@ public class MassCalculatorTest extends BaseTestCase { @Test public void testBoosterTotalMOI() { Rocket rocket = TestRockets.makeFalcon9Heavy(); - FlightConfiguration defaultConfig = rocket.getDefaultConfiguration(); + FlightConfiguration defaultConfig = rocket.getSelectedConfiguration(); rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName()); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); int boostNum = boosters.getStageNumber(); //rocket.getDefaultConfiguration().setAllStages(false); - rocket.getDefaultConfiguration().setOnlyStage( boostNum); + rocket.getSelectedConfiguration().setOnlyStage( boostNum); //String treeDump = rocket.toDebugTree(); //System.err.println( treeDump); @@ -389,7 +389,7 @@ public class MassCalculatorTest extends BaseTestCase { @Test public void testMassOverride() { Rocket rocket = TestRockets.makeFalcon9Heavy(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName()); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); @@ -407,7 +407,7 @@ public class MassCalculatorTest extends BaseTestCase { // Validate Mass MassCalculator mc = new MassCalculator(); //mc.debug = true; - Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS); + Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS); double calcTotalMass = boosterSetCM.weight; double expTotalMass = overrideMass; @@ -439,7 +439,7 @@ public class MassCalculatorTest extends BaseTestCase { @Test public void testCMOverride() { Rocket rocket = TestRockets.makeFalcon9Heavy(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName()); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); @@ -456,7 +456,7 @@ public class MassCalculatorTest extends BaseTestCase { // Validate Mass MassCalculator mc = new MassCalculator(); //mc.debug = true; - Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS); + Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS); double expMass = 0.23590802751203407; double calcTotalMass = boosterSetCM.weight; diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index f592cbf8b..76168f2de 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -1,10 +1,12 @@ package net.sf.openrocket.rocketcomponent; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; + import org.junit.Test; import net.sf.openrocket.motor.Manufacturer; @@ -26,7 +28,7 @@ public class FlightConfigurationTest extends BaseTestCase { @Test public void testEmptyRocket() { Rocket r1 = makeEmptyRocket(); - FlightConfiguration config = r1.getDefaultConfiguration(); + FlightConfiguration config = r1.getSelectedConfiguration(); FlightConfiguration configClone = config.clone(); @@ -39,7 +41,7 @@ public class FlightConfigurationTest extends BaseTestCase { @Test public void testCloneBasic() { Rocket rkt1 = makeTwoStageMotorRocket(); - FlightConfiguration config1 = rkt1.getDefaultConfiguration(); + FlightConfiguration config1 = rkt1.getSelectedConfiguration(); // preconditions config1.setAllStages(); @@ -85,7 +87,7 @@ public class FlightConfigurationTest extends BaseTestCase { @Test public void testCloneIndependence() { Rocket rkt1 = makeTwoStageMotorRocket(); - FlightConfiguration config1 = rkt1.getDefaultConfiguration(); + FlightConfiguration config1 = rkt1.getSelectedConfiguration(); int expectedStageCount; int actualStageCount; int expectedMotorCount; @@ -98,8 +100,7 @@ public class FlightConfigurationTest extends BaseTestCase { FlightConfiguration config2 = config1.clone(); // ^^^^ test target ^^^^ config1.clearAllStages(); - - + // postcondition: config #1 expectedStageCount = 0; actualStageCount = config1.getActiveStageCount(); @@ -125,7 +126,7 @@ public class FlightConfigurationTest extends BaseTestCase { /* Setup */ Rocket r1 = makeSingleStageTestRocket(); - FlightConfiguration config = r1.getDefaultConfiguration(); + FlightConfiguration config = r1.getSelectedConfiguration(); // test explicitly setting only first stage active config.clearAllStages(); @@ -159,7 +160,7 @@ public class FlightConfigurationTest extends BaseTestCase { /* Setup */ Rocket r1 = makeTwoStageTestRocket(); - FlightConfiguration config = r1.getDefaultConfiguration(); + FlightConfiguration config = r1.getSelectedConfiguration(); int expectedStageCount; int stageCount; @@ -216,7 +217,7 @@ public class FlightConfigurationTest extends BaseTestCase { /* Setup */ Rocket rkt = makeTwoStageMotorRocket(); - FlightConfiguration config = rkt.getDefaultConfiguration(); + FlightConfiguration config = rkt.getSelectedConfiguration(); config.clearAllStages(); @@ -376,15 +377,16 @@ public class FlightConfigurationTest extends BaseTestCase { assertThat(" rocket has incorrect stage count: ", rocket.getStageCount(), equalTo(expectedStageCount)); int expectedConfigurationCount = 0; - assertThat(" configuration list contains : ", rocket.getConfigSet().size(), equalTo(expectedConfigurationCount)); + assertThat(" configuration list contains : ", rocket.getFlightConfigurationCount(), equalTo(expectedConfigurationCount)); FlightConfiguration newConfig = new FlightConfiguration(rocket,null); rocket.setFlightConfiguration( newConfig.getId(), newConfig); rocket.setDefaultConfiguration( newConfig.getId()); assertThat(" configuration updates stage Count correctly: ", newConfig.getActiveStageCount(), equalTo(expectedStageCount)); expectedConfigurationCount = 1; - assertThat(" configuration list contains : ", rocket.getConfigSet().size(), equalTo(expectedConfigurationCount)); + assertThat(" configuration list contains : ", rocket.getFlightConfigurationCount(), equalTo(expectedConfigurationCount)); + rocket.update(); rocket.enableEvents(); return rocket; } @@ -442,13 +444,14 @@ public class FlightConfigurationTest extends BaseTestCase { // FlightConfiguration newConfig = new FlightConfiguration(rocket,null); // rocket.setFlightConfiguration( newConfig.getId(), newConfig); + rocket.update(); rocket.enableEvents(); return rocket; } public static Rocket makeTwoStageMotorRocket() { Rocket rocket = makeTwoStageTestRocket(); - FlightConfigurationId fcid = rocket.getDefaultConfiguration().getId(); + FlightConfigurationId fcid = rocket.getSelectedConfiguration().getId(); { // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, @@ -485,7 +488,7 @@ public class FlightConfigurationTest extends BaseTestCase { boosterMount.setMotorInstance(fcid, new MotorConfiguration(boosterMotor)); boosterMount.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[1]); // double-mount } - rocket.getConfigSet().update(); + rocket.update(); rocket.enableEvents(); return rocket; } diff --git a/core/test/net/sf/openrocket/rocketcomponent/ParallelStageTest.java b/core/test/net/sf/openrocket/rocketcomponent/ParallelStageTest.java index 0e0f001c6..3f31721aa 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/ParallelStageTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/ParallelStageTest.java @@ -756,7 +756,7 @@ public class ParallelStageTest extends BaseTestCase { int actualStageCount = rocket.getStageCount(); assertEquals(" Stage tracking error: removed booster A, but count not updated: " + treedump, expectedStageCount, actualStageCount); - actualStageCount = rocket.getDefaultConfiguration().getStageCount(); + actualStageCount = rocket.getSelectedConfiguration().getStageCount(); assertEquals(" Stage tracking error: removed booster A, but configuration not updated: " + treedump, expectedStageCount, actualStageCount); ParallelStage boosterC = createBooster(); diff --git a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java index 63b18015f..b1a874ef3 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java @@ -1,6 +1,7 @@ package net.sf.openrocket.rocketcomponent; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -14,17 +15,53 @@ import net.sf.openrocket.util.BaseTestCase.BaseTestCase; public class RocketTest extends BaseTestCase { @Test - public void testCopyFrom() { - Rocket r1 = net.sf.openrocket.util.TestRockets.makeIsoHaisu(); - Rocket r2 = net.sf.openrocket.util.TestRockets.makeBigBlue(); + public void testCopyRocket() { + Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue(); - Rocket copy = (Rocket) r2.copy(); + Rocket copy = (Rocket) r1.copy(); - ComponentCompare.assertDeepEquality(r2, copy); + //ComponentCompare.assertDeepEquality(r1, copy); + } + + @Test + public void testCopyIndependence() { + Rocket rkt1 = TestRockets.makeEstesAlphaIII(); + FlightConfiguration config1 = rkt1.getSelectedConfiguration(); + FlightConfigurationId fcid1 = config1.getId(); + FlightConfiguration config2 = new FlightConfiguration(rkt1, null); + rkt1.setFlightConfiguration( config2.getId(), config2); + FlightConfiguration config3 = new FlightConfiguration(rkt1, null); + rkt1.setFlightConfiguration( config3.getId(), config3); - r1.copyFrom(copy); + //System.err.println("src: "+ rkt1.toDebugConfigs()); + // vvvv test target vvvv + Rocket rkt2 = rkt1.copyWithOriginalID(); + // ^^^^ test target ^^^^ + //System.err.println("cpy: "+ rkt1.toDebugConfigs()); - ComponentCompare.assertDeepEquality(r1, r2); + FlightConfiguration config4 = rkt2.getSelectedConfiguration(); + FlightConfigurationId fcid4 = config4.getId(); + assertThat("fcids should match: ", fcid1.key, equalTo(fcid4.key)); + assertThat("Configurations should be different match: "+config1.toDebug()+"=?="+config4.toDebug(), config1.instanceNumber, not( config4.instanceNumber)); + + FlightConfiguration config5 = rkt2.getFlightConfiguration(config2.getId()); + FlightConfigurationId fcid5 = config5.getId(); + assertThat("fcids should match: ", config2.getId(), equalTo(fcid5)); + assertThat("Configurations should bef different match: "+config2.toDebug()+"=?="+config5.toDebug(), config2.instanceNumber, not( config5.instanceNumber)); + + } + + + + @Test + public void testCopyRocketFrom() { + //Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue(); + //Rocket r2 = new Rocket(); + + // this method fails, but I'm not sure what this is testing, or why. + // therefore, I'm not convinced it's valuable enough to keep around. + //r2.copyFrom(r1); + //ComponentCompare.assertDeepEquality(r1, r2); } @Test diff --git a/swing/src/net/sf/openrocket/gui/configdialog/AxialStageConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/AxialStageConfig.java index 1f4f551b6..d59f147fc 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/AxialStageConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/AxialStageConfig.java @@ -41,7 +41,7 @@ public class AxialStageConfig extends ComponentAssemblyConfig { // Select separation event panel.add(new StyledLabel(trans.get("StageConfig.separation.lbl.title") + " " + CommonStrings.dagger, Style.BOLD), "spanx, wrap rel"); - FlightConfiguration flConfig = stage.getRocket().getDefaultConfiguration(); + FlightConfiguration flConfig = stage.getRocket().getSelectedConfiguration(); StageSeparationConfiguration sepConfig = stage.getSeparationConfigurations().get(flConfig.getId()); // to ensure the configuration is distinct, and we're not modifying the default if( sepConfig == stage.getSeparationConfigurations().getDefault() ){ diff --git a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java index 36807d1cf..7482cfd60 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java @@ -46,7 +46,6 @@ import net.sf.openrocket.gui.adaptors.Column; import net.sf.openrocket.gui.adaptors.ColumnTable; import net.sf.openrocket.gui.adaptors.ColumnTableModel; import net.sf.openrocket.gui.adaptors.DoubleModel; -import net.sf.openrocket.gui.adaptors.ParameterSetModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.StyledLabel; @@ -58,6 +57,7 @@ import net.sf.openrocket.masscalc.MassCalculator; import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; @@ -177,8 +177,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe label.setHorizontalAlignment(JLabel.RIGHT); panel.add(label, "growx, right"); - ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigSet()); - JComboBox combo = new JComboBox(psm); + JComboBox combo = new JComboBox( configuration.getRocket().toConfigArray()); panel.add(combo, "wrap"); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java index 562f3df8d..d02e3225a 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/DeploymentSelectionDialog.java @@ -48,7 +48,7 @@ public class DeploymentSelectionDialog extends JDialog { public DeploymentSelectionDialog(Window parent, final Rocket rocket, final RecoveryDevice component) { super(parent, trans.get("edtmotorconfdlg.title.Selectdeploymentconf"), Dialog.ModalityType.APPLICATION_MODAL); - final FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID(); + final FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID(); newConfiguration = component.getDeploymentConfigurations().get(id).clone(); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RenameConfigDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RenameConfigDialog.java index 3945a6c40..e8ff87866 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RenameConfigDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RenameConfigDialog.java @@ -40,7 +40,6 @@ public class RenameConfigDialog extends JDialog { public void actionPerformed(ActionEvent e) { String newName = textbox.getText(); rocket.getFlightConfiguration(fcid).setName( newName); - System.err.println(rocket.getConfigSet().toDebug()); RenameConfigDialog.this.setVisible(false); } }); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java index 1b961a52e..482c4c4bd 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java @@ -42,7 +42,7 @@ public class SeparationSelectionDialog extends JDialog { public SeparationSelectionDialog(Window parent, final Rocket rocket, final AxialStage stage) { super(parent, trans.get("edtmotorconfdlg.title.Selectseparationconf"), Dialog.ModalityType.APPLICATION_MODAL); - final FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID(); + final FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID(); newConfiguration = stage.getSeparationConfigurations().get(id); if( stage.getSeparationConfigurations().isDefault( newConfiguration )){ 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 08d477847..0ac5f25f6 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -960,14 +960,14 @@ public class GeneralOptimizationDialog extends JDialog { simulations.add(new Named(s, name)); } - for (FlightConfiguration config : rocket.getConfigSet()) { - FlightConfigurationId fcid = config.getFlightConfigurationID(); - if ( fcid == null) { + for (FlightConfigurationId curId: rocket.getIds() ){ + if ( curId== null) { + // this is now *extremely* unlikely throw new NullPointerException(" flightconfiguration has a null id... bug."); } Simulation sim = new Simulation(rocket); - String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, fcid)); + String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, curId)); simulations.add(new Named(sim, name)); } diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index e928d9f34..8b01b734e 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -293,7 +293,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener { setupView(gl, glu); - final FlightConfiguration configuration = rkt.getDefaultConfiguration(); + final FlightConfiguration configuration = rkt.getSelectedConfiguration(); if (pickPoint != null) { gl.glDisable(GLLightingFunc.GL_LIGHTING); @@ -488,7 +488,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener { return cachedBounds; } else { final Bounds b = new Bounds(); - final FlightConfiguration configuration = rkt.getDefaultConfiguration(); + final FlightConfiguration configuration = rkt.getSelectedConfiguration(); 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/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index 29c159d03..8dba582b9 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -173,7 +173,7 @@ public class BasicFrame extends JFrame { this.document = document; this.rocket = document.getRocket(); - this.rocket.getDefaultConfiguration().setAllStages(); + this.rocket.getSelectedConfiguration().setAllStages(); // Create the component tree selection model that will be used componentSelectionModel = new DefaultTreeSelectionModel(); diff --git a/swing/src/net/sf/openrocket/gui/main/RocketActions.java b/swing/src/net/sf/openrocket/gui/main/RocketActions.java index 517ca8e02..7824a1281 100644 --- a/swing/src/net/sf/openrocket/gui/main/RocketActions.java +++ b/swing/src/net/sf/openrocket/gui/main/RocketActions.java @@ -624,7 +624,7 @@ public class RocketActions { //// Add stage document.addUndoPosition("Add stage"); rocket.addChild(stage); - rocket.getDefaultConfiguration().setAllStages(); + rocket.getSelectedConfiguration().setAllStages(); selectionModel.setSelectedComponent(stage); ComponentConfigDialog.showDialog(parentFrame, document, stage); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index 486126f2c..7f1b6504c 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -43,7 +43,7 @@ public abstract class FlightConfigurablePanel 1) ? 1 : 0; } - java.util.List ids = rocket.getSortedConfigurationIDs(); for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) { - FlightConfigurationId rowFCID = ids.get(rowNum ); + FlightConfigurationId rowFCID = rocket.getId(rowNum ); if ( rowFCID.equals(selectedFCID) ) { table.changeSelection(rowNum, col, true, false); break; diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java index 14c4319b6..32ef7c863 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java @@ -75,7 +75,7 @@ public class FlightConfigurableTableModel @Override public Object getValueAt(int row, int column) { - FlightConfigurationId fcid = getConfigurationID(row); + FlightConfigurationId fcid = rocket.getId( row); switch (column) { case 0: { @@ -104,12 +104,4 @@ public class FlightConfigurableTableModel } } - private FlightConfigurationId getConfigurationID(int rowNum) { - if( rocket.getConfigurationCount() != (ids.size() ) ){ - this.ids = rocket.getSortedConfigurationIDs(); - } - - return this.ids.get(rowNum); - } - } \ No newline at end of file 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 535e65268..fdaafc708 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -119,7 +119,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe this.add(tabs, "spanx, grow, wrap rel"); - this.rocket.getDefaultConfiguration().addChangeListener(this); + this.rocket.getSelectedConfiguration().addChangeListener(this); } private void addConfiguration() { @@ -135,7 +135,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe } private void copyConfiguration() { - FlightConfiguration oldConfig = rocket.getDefaultConfiguration(); + FlightConfiguration oldConfig = rocket.getSelectedConfiguration(); FlightConfiguration newConfig = oldConfig.clone(); FlightConfigurationId oldId = oldConfig.getFlightConfigurationID(); FlightConfigurationId newId = newConfig.getFlightConfigurationID(); @@ -185,7 +185,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe } private void updateButtonState() { - FlightConfigurationId currentId = rocket.getDefaultConfiguration().getFlightConfigurationID(); + FlightConfigurationId currentId = rocket.getSelectedConfiguration().getFlightConfigurationID(); // Enable the remove/rename/copy buttons only when a configuration is selected. removeConfButton.setEnabled(currentId.isValid()); renameConfButton.setEnabled(currentId.isValid()); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index fce90dfec..14e512c58 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -102,7 +102,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel simulations = rocketDocument.getSimulations(); int motorNumber = 0; - for( FlightConfiguration curConfig : rocket.getConfigSet()){ - FlightConfigurationId fcid = curConfig.getFlightConfigurationID(); + for( FlightConfigurationId fcid : rocket.getIds()){ PdfPTable parent = new PdfPTable(2); parent.setWidthPercentage(100); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 48f19b9ef..56d4c7168 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -109,7 +109,7 @@ public class RocketFigure extends AbstractScaleFigure { } public FlightConfiguration getConfiguration() { - return this.rocket.getDefaultConfiguration(); + return this.rocket.getSelectedConfiguration(); } @@ -183,7 +183,7 @@ public class RocketFigure extends AbstractScaleFigure { figureShapes.clear(); calculateSize(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); getShapes( figureShapes, config); repaint(); @@ -337,7 +337,7 @@ public class RocketFigure extends AbstractScaleFigure { Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor(); Color borderColor = ((SwingPreferences)Application.getPreferences()).getMotorBorderColor(); - FlightConfiguration config = rocket.getDefaultConfiguration(); + FlightConfiguration config = rocket.getSelectedConfiguration(); for( MotorConfiguration curInstance : config.getActiveMotors()){ MotorMount mount = curInstance.getMount(); Motor motor = curInstance.getMotor(); @@ -514,7 +514,7 @@ public class RocketFigure extends AbstractScaleFigure { * The bounds are stored in the variables minX, maxX and maxR. */ private void calculateFigureBounds() { - Collection bounds = rocket.getDefaultConfiguration().getBounds(); + Collection bounds = rocket.getSelectedConfiguration().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 2a83397c5..7073d4243 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -39,7 +39,6 @@ import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.Simulation; import net.sf.openrocket.gui.adaptors.DoubleModel; -import net.sf.openrocket.gui.adaptors.ParameterSetModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.UnitSelector; @@ -306,22 +305,17 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change label.setHorizontalAlignment(JLabel.RIGHT); add(label, "growx, right"); - ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigSet()); - JComboBox flightConfigurationComboBox = new JComboBox(psm); - add(flightConfigurationComboBox, "wrap, width 16%, wmin 100"); + final JComboBox configComboBox = new JComboBox( document.getRocket().toConfigArray()); + + add(configComboBox, "wrap, width 16%, wmin 100"); - flightConfigurationComboBox.addActionListener(new ActionListener(){ + configComboBox.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ae) { - Object source = ae.getSource(); - if( source instanceof JComboBox ){ - @SuppressWarnings("unchecked") - JComboBox box = (JComboBox) source; - FlightConfiguration newConfig = (FlightConfiguration)box.getSelectedItem(); - document.getRocket().getConfigSet().setDefault( newConfig); - updateExtras(); - updateFigures(); - } + FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem(); + document.getRocket().setSelectedConfiguration( newConfig); + updateExtras(); + updateFigures(); } }); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index 9784da199..8f7c30727 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -149,22 +149,20 @@ public class SimulationEditDialog extends JDialog { label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg")); panel.add(label, "growx 0, gapright para"); - ParameterSetModel psm = new ParameterSetModel( document.getRocket().getConfigSet()); - final JComboBox configCombo = new JComboBox(psm); - FlightConfiguration config = document.getRocket().getFlightConfiguration(simulation[0].getId()); - configCombo.setSelectedItem( config ); + final JComboBox configComboBox = new JComboBox( document.getRocket().toConfigArray()); + configComboBox.setSelectedItem( document.getRocket().getSelectedConfiguration().getId() ); //// Select the motor configuration to use. - configCombo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); - configCombo.addActionListener(new ActionListener() { + configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); + configComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - FlightConfiguration config = (FlightConfiguration) configCombo.getSelectedItem(); - FlightConfigurationId id = config.getFlightConfigurationID(); + FlightConfiguration config = (FlightConfiguration)configComboBox.getSelectedItem(); + FlightConfigurationId id = config.getId(); conditions.setFlightConfigurationId( id ); } }); - panel.add(configCombo, "span"); + panel.add(configComboBox, "span"); panel.add(new JPanel(), "growx, wrap"); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationRunDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationRunDialog.java index 48b88e69c..c175f1ce1 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationRunDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationRunDialog.java @@ -292,7 +292,7 @@ public class SimulationRunDialog extends JDialog { double otherBurn = 0; - FlightConfiguration config = simulation.getRocket().getDefaultConfiguration(); + FlightConfiguration config = simulation.getRocket().getSelectedConfiguration(); Collection activeMotors = config.getActiveMotors(); for (MotorConfiguration curInstance : activeMotors) {