diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index 8afdbde59..23e3ea620 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -164,7 +164,12 @@ public class Simulation implements ChangeSource, Cloneable { } } - + + public FlightConfiguration getActiveConfiguration() { + mutex.verify(); + return rocket.getFlightConfiguration(this.configId); + } + /** * Return the rocket associated with this simulation. * @@ -185,7 +190,7 @@ public class Simulation implements ChangeSource, Cloneable { /** * Set the motor configuration ID. If this id does not yet exist, it will be created. * - * @param id the configuration to set. + * @param fcid the configuration to set. */ public void setFlightConfigurationId(FlightConfigurationId fcid) { if ( null == fcid ){ @@ -487,26 +492,29 @@ public class Simulation implements ChangeSource, Cloneable { /** * Create a duplicate of this simulation with the specified rocket. The new * simulation is in non-simulated state. + * This methods performs + * synchronization on the simulation for thread protection. + *
+ * Note: This method is package-private for unit testing purposes.
*
* @param newRocket the rocket for the new simulation.
- * @return a new simulation with the same conditions and properties.
+ * @return a new deep copy of the simulation and rocket with the same conditions and properties.
*/
public Simulation duplicateSimulation(Rocket newRocket) {
mutex.lock("duplicateSimulation");
try {
- Simulation copy = new Simulation(newRocket);
-
- copy.name = this.name;
- copy.configId = this.configId;
- copy.options.copyFrom(this.options);
- copy.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
+ final Simulation newSim = new Simulation(newRocket);
+ newSim.name = this.name;
+ newSim.configId = this.configId;
+ newSim.options.copyFrom(this.options);
+ newSim.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
for (SimulationExtension c : this.simulationExtensions) {
- copy.simulationExtensions.add(c.clone());
+ newSim.simulationExtensions.add(c.clone());
}
- copy.simulationStepperClass = this.simulationStepperClass;
- copy.aerodynamicCalculatorClass = this.aerodynamicCalculatorClass;
+ newSim.simulationStepperClass = this.simulationStepperClass;
+ newSim.aerodynamicCalculatorClass = this.aerodynamicCalculatorClass;
- return copy;
+ return newSim;
} finally {
mutex.unlock("duplicateSimulation");
}
diff --git a/core/src/net/sf/openrocket/optimization/rocketoptimization/RocketOptimizationFunction.java b/core/src/net/sf/openrocket/optimization/rocketoptimization/RocketOptimizationFunction.java
index 5386e299b..ddc47d19a 100644
--- a/core/src/net/sf/openrocket/optimization/rocketoptimization/RocketOptimizationFunction.java
+++ b/core/src/net/sf/openrocket/optimization/rocketoptimization/RocketOptimizationFunction.java
@@ -83,12 +83,12 @@ public class RocketOptimizationFunction implements Function {
modifiers.length + " simulation modifiers");
}
- Simulation simulation = newSimulationInstance(baseSimulation);
+ final Simulation simulation = newSimulationInstance(baseSimulation);
+
for (int i = 0; i < modifiers.length; i++) {
modifiers[i].modify(simulation, p[i]);
}
-
// Check whether the point is within the simulation domain
Pair
* Note: This method is package-private for unit testing purposes.
- *
- * @return a new deep copy of the simulation and rocket
+ *
+ * @return a new deep copy of the simulation and rocket
*/
Simulation newSimulationInstance(Simulation simulation) {
- synchronized (baseSimulation) {
- Rocket newRocket = simulation.getRocket().copyWithOriginalID();
- return simulation.duplicateSimulation(newRocket);
- }
+ return simulation.duplicateSimulation(simulation.getRocket().copyWithOriginalID());
}
-
/**
* Add a listener to this function. The listener will be notified each time the
* function is successfully evaluated.
diff --git a/core/src/net/sf/openrocket/optimization/rocketoptimization/modifiers/GenericComponentModifier.java b/core/src/net/sf/openrocket/optimization/rocketoptimization/modifiers/GenericComponentModifier.java
index bd80889a8..7970139ff 100644
--- a/core/src/net/sf/openrocket/optimization/rocketoptimization/modifiers/GenericComponentModifier.java
+++ b/core/src/net/sf/openrocket/optimization/rocketoptimization/modifiers/GenericComponentModifier.java
@@ -39,7 +39,8 @@ public class GenericComponentModifier extends GenericModifier