diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index da2bcd383..85a2ad7db 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -1,6 +1,5 @@ package net.sf.openrocket.document; -import java.util.Collection; import java.util.EventListener; import java.util.EventObject; import java.util.List; @@ -13,7 +12,6 @@ import net.sf.openrocket.aerodynamics.BarrowmanCalculator; import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.masscalc.MassCalculator; -import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.Rocket; @@ -147,6 +145,10 @@ public class Simulation implements ChangeSource, Cloneable { this.name = name; this.options = options; + + FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID(); + options.setFlightConfigurationId(fcid); + options.addChangeListener(new ConditionListener()); if (extensions != null) { @@ -280,6 +282,13 @@ public class Simulation implements ChangeSource, Cloneable { status = Status.OUTDATED; } } + + // if the id hasn't been set yet, skip. + if ( options.getId().hasError() ){ + log.warn(" simulationOptions lacks a valid id. Skipping."); + status = Status.CANT_RUN; + return status; + } FlightConfiguration config = rocket.getFlightConfiguration(options.getId()); diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 272cbb8ab..620abb3a8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -568,7 +568,9 @@ public class Rocket extends RocketComponent { public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) { checkState(); - if( fcid.hasError() ){ + if( null == fcid ){ + throw new NullPointerException("Attempted to create a flightConfiguration from a null key!"); + }else if( fcid.hasError() ){ throw new NullPointerException("Attempted to create a flightConfiguration from an error key!"); }else if( configSet.containsKey(fcid)){ return this.configSet.get(fcid); @@ -815,6 +817,7 @@ public class Rocket extends RocketComponent { StringBuilder buf = new StringBuilder(); buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName())); final String fmt = " [%-12s]: %s\n"; + buf.append(String.format(fmt, " *SELECTED* ", selectedConfiguration.getName() )); for( FlightConfiguration config : this.configSet.values() ){ String shortKey = config.getId().toShortKey(); if( this.selectedConfiguration.equals( config)){ diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index 562df836c..fd2eabd5f 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -51,7 +51,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { protected final Preferences preferences = Application.getPreferences(); private final Rocket rocket; - private FlightConfigurationId configId = new FlightConfigurationId(); + private FlightConfigurationId configId = FlightConfigurationId.ERROR_FCID; /* * NOTE: When adding/modifying parameters, they must also be added to the @@ -439,7 +439,6 @@ public class SimulationOptions implements ChangeSource, Cloneable { if (this.rocket == src.rocket) { this.configId = src.configId; } else { - if (src.rocket.hasMotors(src.configId)) { // First check for exact match: if (this.rocket.containsFlightConfigurationID(src.configId)) { @@ -462,7 +461,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { this.configId = matchID; } } else { - this.configId = null; + this.configId = FlightConfigurationId.ERROR_FCID; } } @@ -588,7 +587,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { */ @Override public int hashCode() { - if (configId == null) + if (configId.hasError()) return rocket.hashCode(); return rocket.hashCode() + configId.hashCode(); } diff --git a/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java b/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java index 608788a3e..b067c6c97 100644 --- a/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java +++ b/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java @@ -3,6 +3,15 @@ package net.sf.openrocket.optimization.rocketoptimization; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.auto.Mock; +import org.jmock.integration.junit4.JMock; +import org.jmock.integration.junit4.JUnit4Mockery; +import org.junit.Test; +import org.junit.runner.RunWith; + import net.sf.openrocket.document.Simulation; import net.sf.openrocket.optimization.general.OptimizationException; import net.sf.openrocket.optimization.general.Point; @@ -13,14 +22,6 @@ import net.sf.openrocket.unit.Value; import net.sf.openrocket.util.Pair; import net.sf.openrocket.util.BaseTestCase.BaseTestCase; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.auto.Mock; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Test; -import org.junit.runner.RunWith; - @RunWith(JMock.class) public class TestRocketOptimizationFunction extends BaseTestCase { @@ -222,12 +223,13 @@ public class TestRocketOptimizationFunction extends BaseTestCase { @Test - public void testNewSimulationInstance() { + public void testNewSimulationNames() { final Rocket rocket = new Rocket(); rocket.setName("Foobar"); final Simulation simulation = new Simulation(rocket); simulation.setName("MySim"); + RocketOptimizationFunction function = new RocketOptimizationFunction(simulation, parameter, goal, domain, modifier1, modifier2);