Clean up sim cloning & loading
This commit is contained in:
parent
5aad8b9722
commit
3acdda83c3
@ -542,24 +542,27 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
Simulation clone = (Simulation) super.clone();
|
Simulation clone = (Simulation) super.clone();
|
||||||
|
|
||||||
clone.mutex = SafetyMutex.newInstance();
|
clone.mutex = SafetyMutex.newInstance();
|
||||||
clone.status = status;
|
clone.name = this.name;
|
||||||
|
clone.configId = this.configId;
|
||||||
|
clone.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
|
||||||
|
clone.simulatedConfigurationID = this.simulatedConfigurationID;
|
||||||
clone.options = this.options.clone();
|
clone.options = this.options.clone();
|
||||||
|
clone.listeners = new ArrayList<>();
|
||||||
|
if (this.simulatedConditions != null) {
|
||||||
|
clone.simulatedConditions = this.simulatedConditions.clone();
|
||||||
|
} else {
|
||||||
|
clone.simulatedConditions = null;
|
||||||
|
}
|
||||||
clone.simulationExtensions = new ArrayList<>();
|
clone.simulationExtensions = new ArrayList<>();
|
||||||
for (SimulationExtension c : this.simulationExtensions) {
|
for (SimulationExtension c : this.simulationExtensions) {
|
||||||
clone.simulationExtensions.add(c.clone());
|
clone.simulationExtensions.add(c.clone());
|
||||||
}
|
}
|
||||||
clone.listeners = new ArrayList<>();
|
clone.status = this.status;
|
||||||
if (simulatedConditions != null) {
|
clone.simulatedData = this.simulatedData != null ? this.simulatedData.clone() : this.simulatedData;
|
||||||
clone.simulatedConditions = simulatedConditions.clone();
|
clone.simulationStepperClass = this.simulationStepperClass;
|
||||||
} else {
|
clone.aerodynamicCalculatorClass = this.aerodynamicCalculatorClass;
|
||||||
clone.simulatedConditions = null;
|
|
||||||
}
|
|
||||||
clone.simulatedConfigurationDescription = simulatedConfigurationDescription;
|
|
||||||
clone.simulatedData = simulatedData.clone();
|
|
||||||
clone.simulatedConfigurationID = simulatedConfigurationID;
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
|
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new BugException("Clone not supported, BUG", e);
|
throw new BugException("Clone not supported, BUG", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -576,17 +579,25 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
try {
|
try {
|
||||||
this.name = simulation.name;
|
this.name = simulation.name;
|
||||||
this.configId = simulation.configId;
|
this.configId = simulation.configId;
|
||||||
this.options.copyFrom(simulation.options);
|
|
||||||
this.simulatedConfigurationDescription = simulation.simulatedConfigurationDescription;
|
this.simulatedConfigurationDescription = simulation.simulatedConfigurationDescription;
|
||||||
this.simulatedConfigurationID = simulation.simulatedConfigurationID;
|
this.simulatedConfigurationID = simulation.simulatedConfigurationID;
|
||||||
|
this.options.copyConditionsFrom(simulation.options);
|
||||||
if (simulation.simulatedConditions == null) {
|
if (simulation.simulatedConditions == null) {
|
||||||
this.simulatedConditions = null;
|
this.simulatedConditions = null;
|
||||||
} else {
|
} else {
|
||||||
this.simulatedConditions = simulation.simulatedConditions.clone();
|
this.simulatedConditions.copyConditionsFrom(simulation.simulatedConditions);
|
||||||
|
}
|
||||||
|
copyExtensionsFrom(simulation.getSimulationExtensions());
|
||||||
|
this.status = simulation.status;
|
||||||
|
// Status change, so reset the change listeners to be sure
|
||||||
|
for (EventListener listener : this.options.getChangeListeners()) {
|
||||||
|
if (listener instanceof ConditionListener) {
|
||||||
|
((ConditionListener) listener).reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.simulatedData = simulation.simulatedData;
|
this.simulatedData = simulation.simulatedData;
|
||||||
this.status = simulation.status;
|
this.simulationStepperClass = simulation.simulationStepperClass;
|
||||||
copyExtensionsFrom(simulation.getSimulationExtensions());
|
this.aerodynamicCalculatorClass = simulation.aerodynamicCalculatorClass;
|
||||||
} finally {
|
} finally {
|
||||||
mutex.unlock("loadFrom");
|
mutex.unlock("loadFrom");
|
||||||
}
|
}
|
||||||
@ -610,7 +621,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
final Simulation newSim = new Simulation(this.document, newRocket);
|
final Simulation newSim = new Simulation(this.document, newRocket);
|
||||||
newSim.name = this.name;
|
newSim.name = this.name;
|
||||||
newSim.configId = this.configId;
|
newSim.configId = this.configId;
|
||||||
newSim.options.copyFrom(this.options);
|
newSim.options.copyConditionsFrom(this.options);
|
||||||
newSim.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
|
newSim.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
|
||||||
for (SimulationExtension c : this.simulationExtensions) {
|
for (SimulationExtension c : this.simulationExtensions) {
|
||||||
newSim.simulationExtensions.add(c.clone());
|
newSim.simulationExtensions.add(c.clone());
|
||||||
@ -653,16 +664,20 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
|
|
||||||
|
|
||||||
private class ConditionListener implements StateChangeListener {
|
private class ConditionListener implements StateChangeListener {
|
||||||
|
private boolean resetState = false;
|
||||||
private Status oldStatus = null;
|
private Status oldStatus = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(EventObject e) {
|
public void stateChanged(EventObject e) {
|
||||||
if (getStatus() != oldStatus) {
|
if (resetState || getStatus() != oldStatus) {
|
||||||
oldStatus = getStatus();
|
oldStatus = getStatus();
|
||||||
fireChangeEvent();
|
fireChangeEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
resetState = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user