Merge branch 'unstable' into fix-852

This commit is contained in:
JoePfeiffer 2024-08-09 10:03:24 -06:00
commit ae501caab4
41 changed files with 398 additions and 308 deletions

View File

@ -6,6 +6,7 @@ import info.openrocket.core.logging.WarningSet;
import info.openrocket.core.rocketcomponent.FlightConfiguration; import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
/** /**
@ -28,8 +29,8 @@ public abstract class AbstractAerodynamicCalculator implements AerodynamicCalcul
protected WarningSet ignoreWarningSet = new WarningSet(); protected WarningSet ignoreWarningSet = new WarningSet();
/** The aerodynamic modification ID of the latest rocket */ /** The aerodynamic modification ID of the latest rocket */
private int rocketAeroModID = -1; private ModID rocketAeroModID = new ModID();
private int rocketTreeModID = -1; private ModID rocketTreeModID = new ModID();
//////////////// Aerodynamic calculators //////////////// //////////////// Aerodynamic calculators ////////////////

View File

@ -5,6 +5,7 @@ import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
public class AerodynamicForces implements Cloneable, Monitorable { public class AerodynamicForces implements Cloneable, Monitorable {
@ -67,7 +68,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
private double pitchDampingMoment = Double.NaN; private double pitchDampingMoment = Double.NaN;
private double yawDampingMoment = Double.NaN; private double yawDampingMoment = Double.NaN;
private int modID = 0; private ModID modID = ModID.INVALID;
private boolean axisymmetric = true; private boolean axisymmetric = true;
@ -76,7 +77,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setAxisymmetric(final boolean isSym) { public void setAxisymmetric(final boolean isSym) {
if (this.axisymmetric == isSym)
return;
this.axisymmetric = isSym; this.axisymmetric = isSym;
modID = new ModID();
} }
/** /**
@ -86,8 +91,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
* @param component The rocket component * @param component The rocket component
*/ */
public void setComponent(RocketComponent component) { public void setComponent(RocketComponent component) {
if (this.component == component)
return;
this.component = component; this.component = component;
modID++; modID = new ModID();
} }
/** /**
@ -99,8 +107,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCP(Coordinate cp) { public void setCP(Coordinate cp) {
if ((this.cp != null) && this.cp.equals(cp))
return;
this.cp = cp; this.cp = cp;
modID++; modID = new ModID();
} }
public Coordinate getCP() { public Coordinate getCP() {
@ -108,8 +119,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCNa(double cNa) { public void setCNa(double cNa) {
if (CNa == cNa)
return;
CNa = cNa; CNa = cNa;
modID++; modID = new ModID();
} }
public double getCNa() { public double getCNa() {
@ -117,8 +131,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCN(double cN) { public void setCN(double cN) {
if (CN == cN)
return;
CN = cN; CN = cN;
modID++; modID = new ModID();
} }
public double getCN() { public double getCN() {
@ -126,8 +143,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCm(double cm) { public void setCm(double cm) {
if (Cm == cm)
return;
Cm = cm; Cm = cm;
modID++; modID = new ModID();
} }
public double getCm() { public double getCm() {
@ -135,8 +155,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCside(double cside) { public void setCside(double cside) {
if (Cside == cside)
return;
Cside = cside; Cside = cside;
modID++; modID = new ModID();
} }
public double getCside() { public double getCside() {
@ -144,8 +167,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCyaw(double cyaw) { public void setCyaw(double cyaw) {
if (Cyaw == cyaw)
return;
Cyaw = cyaw; Cyaw = cyaw;
modID++; modID = new ModID();
} }
public double getCyaw() { public double getCyaw() {
@ -153,8 +179,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCroll(double croll) { public void setCroll(double croll) {
if (Croll == croll)
return;
Croll = croll; Croll = croll;
modID++; modID = new ModID();
} }
public double getCroll() { public double getCroll() {
@ -162,8 +191,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCrollDamp(double crollDamp) { public void setCrollDamp(double crollDamp) {
if (CrollDamp == crollDamp)
return;
CrollDamp = crollDamp; CrollDamp = crollDamp;
modID++; modID = new ModID();
} }
public double getCrollDamp() { public double getCrollDamp() {
@ -171,8 +203,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCrollForce(double crollForce) { public void setCrollForce(double crollForce) {
if (CrollForce == crollForce)
return;
CrollForce = crollForce; CrollForce = crollForce;
modID++; modID = new ModID();
} }
public double getCrollForce() { public double getCrollForce() {
@ -180,8 +215,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCDaxial(double cdaxial) { public void setCDaxial(double cdaxial) {
if (CDaxial == cdaxial)
return;
CDaxial = cdaxial; CDaxial = cdaxial;
modID++; modID= new ModID();
} }
public double getCDaxial() { public double getCDaxial() {
@ -189,8 +227,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setCD(double cD) { public void setCD(double cD) {
if (CD == cD)
return;
CD = cD; CD = cD;
modID++; modID = new ModID();
} }
public double getCD() { public double getCD() {
@ -205,8 +246,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setPressureCD(double pressureCD) { public void setPressureCD(double pressureCD) {
if (this.pressureCD == pressureCD)
return;
this.pressureCD = pressureCD; this.pressureCD = pressureCD;
modID++; modID = new ModID();
} }
public double getPressureCD() { public double getPressureCD() {
@ -220,8 +264,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setBaseCD(double baseCD) { public void setBaseCD(double baseCD) {
if (this.baseCD == baseCD)
return;
this.baseCD = baseCD; this.baseCD = baseCD;
modID++; modID = new ModID();
} }
public double getBaseCD() { public double getBaseCD() {
@ -235,8 +282,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setFrictionCD(double frictionCD) { public void setFrictionCD(double frictionCD) {
if (this.frictionCD == frictionCD)
return;
this.frictionCD = frictionCD; this.frictionCD = frictionCD;
modID++; modID = new ModID();
} }
public double getFrictionCD() { public double getFrictionCD() {
@ -250,8 +300,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setOverrideCD(double overrideCD) { public void setOverrideCD(double overrideCD) {
if (this.overrideCD == overrideCD)
return;
this.overrideCD = overrideCD; this.overrideCD = overrideCD;
modID++; modID = new ModID();
} }
public double getOverrideCD() { public double getOverrideCD() {
@ -265,8 +318,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setPitchDampingMoment(double pitchDampingMoment) { public void setPitchDampingMoment(double pitchDampingMoment) {
if (this.pitchDampingMoment == pitchDampingMoment)
return;
this.pitchDampingMoment = pitchDampingMoment; this.pitchDampingMoment = pitchDampingMoment;
modID++; modID = new ModID();
} }
public double getPitchDampingMoment() { public double getPitchDampingMoment() {
@ -274,8 +330,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
public void setYawDampingMoment(double yawDampingMoment) { public void setYawDampingMoment(double yawDampingMoment) {
if (this.yawDampingMoment == yawDampingMoment)
return;
this.yawDampingMoment = yawDampingMoment; this.yawDampingMoment = yawDampingMoment;
modID++; modID = new ModID();
} }
public double getYawDampingMoment() { public double getYawDampingMoment() {
@ -404,7 +463,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }
@ -419,7 +478,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
this.CrollDamp = CrollDamp + other.getCrollDamp(); this.CrollDamp = CrollDamp + other.getCrollDamp();
this.CrollForce = CrollForce + other.getCrollForce(); this.CrollForce = CrollForce + other.getCrollForce();
modID++; modID = new ModID();
return this; return this;
} }

View File

@ -28,6 +28,7 @@ import info.openrocket.core.rocketcomponent.SymmetricComponent;
import info.openrocket.core.unit.UnitGroup; import info.openrocket.core.unit.UnitGroup;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.PolyInterpolator; import info.openrocket.core.util.PolyInterpolator;
import info.openrocket.core.util.Reflection; import info.openrocket.core.util.Reflection;
@ -1030,9 +1031,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
@Override @Override
public int getModID() { public ModID getModID() {
// Only cached data is stored, return constant mod ID // Only cached data is stored, return constant mod ID
return 0; return ModID.ZERO;
} }
} }

View File

@ -13,7 +13,7 @@ import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
import info.openrocket.core.util.UniqueID; import info.openrocket.core.util.ModID;
/** /**
* A class defining the momentary flight conditions of a rocket, including * A class defining the momentary flight conditions of a rocket, including
@ -69,8 +69,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
private AtmosphericConditions atmosphericConditions = new AtmosphericConditions(); private AtmosphericConditions atmosphericConditions = new AtmosphericConditions();
private int modID; private ModID modID;
private int modIDadd = 0;
/** /**
* Sole constructor. The reference length is initialized to the reference length * Sole constructor. The reference length is initialized to the reference length
@ -83,7 +82,6 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
public FlightConditions(FlightConfiguration config) { public FlightConditions(FlightConfiguration config) {
if (config != null) if (config != null)
setRefLength(config.getReferenceLength()); setRefLength(config.getReferenceLength());
this.modID = UniqueID.next();
} }
/** /**
@ -100,9 +98,12 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
* fires change event * fires change event
*/ */
public void setRefLength(double length) { public void setRefLength(double length) {
if (refLength == length)
return;
refLength = length; refLength = length;
refArea = Math.PI * MathUtil.pow2(length / 2); refArea = Math.PI * MathUtil.pow2(length / 2);
fireChangeEvent(); fireChangeEvent();
} }
@ -118,8 +119,12 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
* fires change event * fires change event
*/ */
public void setRefArea(double area) { public void setRefArea(double area) {
if (refArea == area)
return;
refArea = area; refArea = area;
refLength = MathUtil.safeSqrt(area / Math.PI) * 2; refLength = MathUtil.safeSqrt(area / Math.PI) * 2;
fireChangeEvent(); fireChangeEvent();
} }
@ -150,6 +155,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
this.sinAOA = Math.sin(aoa); this.sinAOA = Math.sin(aoa);
this.sincAOA = sinAOA / aoa; this.sincAOA = sinAOA / aoa;
} }
fireChangeEvent(); fireChangeEvent();
} }
@ -179,6 +185,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} else { } else {
this.sincAOA = sinAOA / aoa; this.sincAOA = sinAOA / aoa;
} }
fireChangeEvent(); fireChangeEvent();
} }
@ -213,6 +220,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
if (MathUtil.equals(this.theta, theta)) if (MathUtil.equals(this.theta, theta))
return; return;
this.theta = theta; this.theta = theta;
fireChangeEvent(); fireChangeEvent();
} }
@ -239,6 +247,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
this.beta = MathUtil.safeSqrt(1 - mach * mach); this.beta = MathUtil.safeSqrt(1 - mach * mach);
else else
this.beta = MathUtil.safeSqrt(mach * mach - 1); this.beta = MathUtil.safeSqrt(mach * mach - 1);
fireChangeEvent(); fireChangeEvent();
} }
@ -295,6 +304,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
return; return;
this.rollRate = rate; this.rollRate = rate;
fireChangeEvent(); fireChangeEvent();
} }
@ -370,21 +380,19 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
public void setAtmosphericConditions(AtmosphericConditions cond) { public void setAtmosphericConditions(AtmosphericConditions cond) {
if (atmosphericConditions.equals(cond)) if (atmosphericConditions.equals(cond))
return; return;
modIDadd += atmosphericConditions.getModID();
atmosphericConditions = cond; atmosphericConditions = cond;
fireChangeEvent(); fireChangeEvent();
} }
/** /**
* Retrieve the modification count of this object. Each time it is modified * Retrieve the modification count of this object.
* the modification count is increased by one.
* *
* @return the number of times this object has been modified since * @return modification ID
* instantiation.
*/ */
@Override @Override
public int getModID() { public ModID getModID() {
return modID + modIDadd + this.atmosphericConditions.getModID(); return modID;
} }
@Override @Override
@ -459,7 +467,8 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
* wake up call to listeners * wake up call to listeners
*/ */
protected void fireChangeEvent() { protected void fireChangeEvent() {
modID = UniqueID.next(); modID = new ModID();
// Copy the list before iterating to prevent concurrent modification exceptions. // Copy the list before iterating to prevent concurrent modification exceptions.
EventListener[] listeners = listenerList.toArray(new EventListener[0]); EventListener[] listeners = listenerList.toArray(new EventListener[0]);
for (EventListener l : listeners) { for (EventListener l : listeners) {

View File

@ -3,10 +3,6 @@ package info.openrocket.core.document;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import info.openrocket.core.file.wavefrontobj.export.OBJExportOptions;
import info.openrocket.core.rocketcomponent.*;
import info.openrocket.core.startup.Preferences;
import info.openrocket.core.util.StateChangeListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,12 +12,23 @@ import info.openrocket.core.appearance.DecalImage;
import info.openrocket.core.document.events.DocumentChangeEvent; import info.openrocket.core.document.events.DocumentChangeEvent;
import info.openrocket.core.document.events.DocumentChangeListener; import info.openrocket.core.document.events.DocumentChangeListener;
import info.openrocket.core.document.events.SimulationChangeEvent; import info.openrocket.core.document.events.SimulationChangeEvent;
import info.openrocket.core.file.wavefrontobj.export.OBJExportOptions;
import info.openrocket.core.logging.Markers; import info.openrocket.core.logging.Markers;
import info.openrocket.core.rocketcomponent.ComponentChangeEvent;
import info.openrocket.core.rocketcomponent.ComponentChangeListener;
import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.FlightConfigurationId;
import info.openrocket.core.rocketcomponent.InsideColorComponent;
import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.simulation.FlightDataType; import info.openrocket.core.simulation.FlightDataType;
import info.openrocket.core.simulation.customexpression.CustomExpression; import info.openrocket.core.simulation.customexpression.CustomExpression;
import info.openrocket.core.simulation.extension.SimulationExtension; import info.openrocket.core.simulation.extension.SimulationExtension;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
import info.openrocket.core.startup.Preferences;
import info.openrocket.core.util.ArrayList; import info.openrocket.core.util.ArrayList;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.StateChangeListener;
/** /**
* Class describing an entire OpenRocket document, including a rocket and * Class describing an entire OpenRocket document, including a rocket and
@ -90,8 +97,8 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL
private final ArrayList<UndoRedoListener> undoRedoListeners = new ArrayList<UndoRedoListener>(2); private final ArrayList<UndoRedoListener> undoRedoListeners = new ArrayList<UndoRedoListener>(2);
private File file = null; private File file = null;
private int modID = -1; private ModID modID = ModID.INVALID;
private int savedID = -1; private ModID savedID = ModID.INVALID;
private final StorageOptions storageOptions = new StorageOptions(); private final StorageOptions storageOptions = new StorageOptions();
private final OBJExportOptions objOptions; private final OBJExportOptions objOptions;
@ -232,7 +239,7 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL
* @return if the current rocket is saved * @return if the current rocket is saved
*/ */
public boolean isSaved() { public boolean isSaved() {
return rocket.getModID() + modID == savedID; return modID == savedID;
} }
/** /**
@ -241,9 +248,9 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL
*/ */
public void setSaved(boolean saved) { public void setSaved(boolean saved) {
if (!saved) if (!saved)
this.savedID = -1; this.savedID = ModID.INVALID;
else else
this.savedID = rocket.getModID() + modID; this.savedID = modID;
} }
/** /**
@ -645,7 +652,7 @@ public class OpenRocketDocument implements ComponentChangeListener, StateChangeL
@Override @Override
public void stateChanged(EventObject e) { public void stateChanged(EventObject e) {
modID++; modID = new ModID();
fireDocumentChangeEvent(new DocumentChangeEvent(e.getSource())); fireDocumentChangeEvent(new DocumentChangeEvent(e.getSource()));
} }

View File

@ -32,6 +32,7 @@ import info.openrocket.core.startup.Application;
import info.openrocket.core.util.ArrayList; import info.openrocket.core.util.ArrayList;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.ChangeSource; import info.openrocket.core.util.ChangeSource;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.SafetyMutex; import info.openrocket.core.util.SafetyMutex;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
@ -100,7 +101,7 @@ public class Simulation implements ChangeSource, Cloneable {
private SimulationOptions simulatedConditions = null; private SimulationOptions simulatedConditions = null;
private String simulatedConfigurationDescription = null; private String simulatedConfigurationDescription = null;
private FlightData simulatedData = null; private FlightData simulatedData = null;
private int simulatedConfigurationID = -1; private ModID simulatedConfigurationModID = ModID.INVALID;
/** /**
* Create a new simulation for the rocket. Parent document should also be provided. * Create a new simulation for the rocket. Parent document should also be provided.
@ -158,7 +159,7 @@ public class Simulation implements ChangeSource, Cloneable {
final FlightConfiguration config = rocket.getSelectedConfiguration(); final FlightConfiguration config = rocket.getSelectedConfiguration();
this.setFlightConfigurationId(config.getFlightConfigurationID()); this.setFlightConfigurationId(config.getFlightConfigurationID());
this.simulatedConfigurationID = config.getModID(); this.simulatedConfigurationModID = config.getModID();
this.simulationExtensions.addAll(extensions); this.simulationExtensions.addAll(extensions);
} }
@ -330,7 +331,7 @@ public class Simulation implements ChangeSource, Cloneable {
final FlightConfiguration config = rocket.getFlightConfiguration(this.getId()).clone(); final FlightConfiguration config = rocket.getFlightConfiguration(this.getId()).clone();
if (isStatusUpToDate(status)) { if (isStatusUpToDate(status)) {
if (config.getModID() != simulatedConfigurationID || !options.equals(simulatedConditions)) { if (config.getModID() != simulatedConfigurationModID || !options.equals(simulatedConditions)) {
status = Status.OUTDATED; status = Status.OUTDATED;
} }
} }
@ -385,7 +386,7 @@ public class Simulation implements ChangeSource, Cloneable {
* Syncs the modID with its flight configuration. * Syncs the modID with its flight configuration.
*/ */
public void syncModID() { public void syncModID() {
this.simulatedConfigurationID = getActiveConfiguration().getModID(); this.simulatedConfigurationModID = getActiveConfiguration().getModID();
fireChangeEvent(); fireChangeEvent();
} }
@ -441,7 +442,7 @@ public class Simulation implements ChangeSource, Cloneable {
// Set simulated info after simulation // Set simulated info after simulation
simulatedConditions = options.clone(); simulatedConditions = options.clone();
simulatedConfigurationDescription = descriptor.format(this.rocket, getId()); simulatedConfigurationDescription = descriptor.format(this.rocket, getId());
simulatedConfigurationID = getActiveConfiguration().getModID(); simulatedConfigurationModID = getActiveConfiguration().getModID();
if (simulator != null) { if (simulator != null) {
simulatedData = simulator.getFlightData(); simulatedData = simulator.getFlightData();
} }
@ -554,7 +555,7 @@ public class Simulation implements ChangeSource, Cloneable {
copy.simulatedConditions = null; copy.simulatedConditions = null;
copy.simulatedConfigurationDescription = null; copy.simulatedConfigurationDescription = null;
copy.simulatedData = null; copy.simulatedData = null;
copy.simulatedConfigurationID = -1; copy.simulatedConfigurationModID = ModID.INVALID;
return copy; return copy;
@ -574,7 +575,7 @@ public class Simulation implements ChangeSource, Cloneable {
clone.name = this.name; clone.name = this.name;
clone.configId = this.configId; clone.configId = this.configId;
clone.simulatedConfigurationDescription = this.simulatedConfigurationDescription; clone.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
clone.simulatedConfigurationID = this.simulatedConfigurationID; clone.simulatedConfigurationModID = this.simulatedConfigurationModID;
clone.options = this.options.clone(); clone.options = this.options.clone();
clone.listeners = new ArrayList<>(); clone.listeners = new ArrayList<>();
if (this.simulatedConditions != null) { if (this.simulatedConditions != null) {
@ -609,7 +610,7 @@ public class Simulation implements ChangeSource, Cloneable {
this.name = simulation.name; this.name = simulation.name;
this.configId = simulation.configId; this.configId = simulation.configId;
this.simulatedConfigurationDescription = simulation.simulatedConfigurationDescription; this.simulatedConfigurationDescription = simulation.simulatedConfigurationDescription;
this.simulatedConfigurationID = simulation.simulatedConfigurationID; this.simulatedConfigurationModID = simulation.simulatedConfigurationModID;
this.options.copyConditionsFrom(simulation.options); this.options.copyConditionsFrom(simulation.options);
if (simulation.simulatedConditions == null) { if (simulation.simulatedConditions == null) {
this.simulatedConditions = null; this.simulatedConditions = null;

View File

@ -1,6 +1,7 @@
package info.openrocket.core.file.openrocket.importt; package info.openrocket.core.file.openrocket.importt;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID;
import info.openrocket.core.logging.SimulationAbort; import info.openrocket.core.logging.SimulationAbort;
import info.openrocket.core.logging.SimulationAbort.Cause; import info.openrocket.core.logging.SimulationAbort.Cause;
@ -153,7 +154,7 @@ class FlightDataBranchHandler extends AbstractElementHandler {
Rocket rocket = context.getOpenRocketDocument().getRocket(); Rocket rocket = context.getOpenRocketDocument().getRocket();
sourceID = attributes.get("source"); sourceID = attributes.get("source");
if (sourceID != null) { if (sourceID != null) {
source = rocket.findComponent(sourceID); source = rocket.findComponent(UUID.fromString(sourceID));
} }
// For aborts, get the cause // For aborts, get the cause

View File

@ -87,6 +87,7 @@ class SingleSimulationHandler extends AbstractElementHandler {
extensions.add(compatibilityExtension(content.trim())); extensions.add(compatibilityExtension(content.trim()));
} else if (element.equals("extension") && !StringUtils.isEmpty(attributes.get("extensionid"))) { } else if (element.equals("extension") && !StringUtils.isEmpty(attributes.get("extensionid"))) {
String id = attributes.get("extensionid"); String id = attributes.get("extensionid");
id = id.replace("net.sf.openrocket", "info.openrocket.core");
SimulationExtension extension = null; SimulationExtension extension = null;
Set<SimulationExtensionProvider> extensionProviders = Application.getInjector() Set<SimulationExtensionProvider> extensionProviders = Application.getInjector()
.getInstance(new Key<Set<SimulationExtensionProvider>>() { .getInstance(new Key<Set<SimulationExtensionProvider>>() {

View File

@ -3,6 +3,7 @@ package info.openrocket.core.logging;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.util.ArrayList; import info.openrocket.core.util.ArrayList;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.Mutable; import info.openrocket.core.util.Mutable;
@ -25,7 +26,7 @@ public abstract class MessageSet<E extends Message> extends AbstractSet<E> imple
protected ArrayList<E> messages = new ArrayList<>(); protected ArrayList<E> messages = new ArrayList<>();
protected Mutable mutable = new Mutable(); protected Mutable mutable = new Mutable();
private int modID = 0; private ModID modID = ModID.ZERO;
/** /**
* Add a <code>Message</code> to the set. If a message of the same type * Add a <code>Message</code> to the set. If a message of the same type
@ -38,7 +39,7 @@ public abstract class MessageSet<E extends Message> extends AbstractSet<E> imple
public boolean add(E m) { public boolean add(E m) {
mutable.check(); mutable.check();
modID++; modID = new ModID();
int index = messages.indexOf(m); int index = messages.indexOf(m);
if (index < 0) { if (index < 0) {
@ -166,7 +167,7 @@ public abstract class MessageSet<E extends Message> extends AbstractSet<E> imple
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }
} }

View File

@ -9,8 +9,10 @@ import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.simulation.MotorClusterState; import info.openrocket.core.simulation.MotorClusterState;
import info.openrocket.core.simulation.SimulationStatus; import info.openrocket.core.simulation.SimulationStatus;
import info.openrocket.core.util.*; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.Transformation;
public class MassCalculator implements Monitorable { public class MassCalculator implements Monitorable {
public static final double MIN_MASS = MathUtil.EPSILON; public static final double MIN_MASS = MathUtil.EPSILON;
@ -24,7 +26,7 @@ public class MassCalculator implements Monitorable {
// private MassData rocketSpentMassCache; // private MassData rocketSpentMassCache;
// private MassData motorMassCache; // private MassData motorMassCache;
private final int modId = 0; private final ModID modID = ModID.ZERO;
////////////////// Constructors /////////////////// ////////////////// Constructors ///////////////////
public MassCalculator() { public MassCalculator() {
@ -176,8 +178,8 @@ public class MassCalculator implements Monitorable {
////////////////// Mass property calculations /////////////////// ////////////////// Mass property calculations ///////////////////
@Override @Override
public int getModID() { public ModID getModID() {
return this.modId; return modID;
} }
} }

View File

@ -3,7 +3,7 @@ package info.openrocket.core.models.atmosphere;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.UniqueID; import info.openrocket.core.util.ModID;
public class AtmosphericConditions implements Cloneable, Monitorable { public class AtmosphericConditions implements Cloneable, Monitorable {
@ -25,7 +25,7 @@ public class AtmosphericConditions implements Cloneable, Monitorable {
/** Air temperature, in Kelvins. */ /** Air temperature, in Kelvins. */
private double temperature; private double temperature;
private int modID; private ModID modID;
/** /**
* Construct standard atmospheric conditions. * Construct standard atmospheric conditions.
@ -43,7 +43,7 @@ public class AtmosphericConditions implements Cloneable, Monitorable {
public AtmosphericConditions(double temperature, double pressure) { public AtmosphericConditions(double temperature, double pressure) {
this.setTemperature(temperature); this.setTemperature(temperature);
this.setPressure(pressure); this.setPressure(pressure);
this.modID = UniqueID.next(); this.modID = new ModID();
} }
public double getPressure() { public double getPressure() {
@ -52,7 +52,7 @@ public class AtmosphericConditions implements Cloneable, Monitorable {
public void setPressure(double pressure) { public void setPressure(double pressure) {
this.pressure = pressure; this.pressure = pressure;
this.modID = UniqueID.next(); this.modID = new ModID();
} }
public double getTemperature() { public double getTemperature() {
@ -61,7 +61,7 @@ public class AtmosphericConditions implements Cloneable, Monitorable {
public void setTemperature(double temperature) { public void setTemperature(double temperature) {
this.temperature = temperature; this.temperature = temperature;
this.modID = UniqueID.next(); this.modID = new ModID();
} }
/** /**
@ -133,7 +133,7 @@ public class AtmosphericConditions implements Cloneable, Monitorable {
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }

View File

@ -2,6 +2,7 @@ package info.openrocket.core.models.atmosphere;
import static info.openrocket.core.models.atmosphere.AtmosphericConditions.R; import static info.openrocket.core.models.atmosphere.AtmosphericConditions.R;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
/** /**
* An atmospheric temperature/pressure model based on the International Standard * An atmospheric temperature/pressure model based on the International Standard
@ -122,8 +123,8 @@ public class ExtendedISAModel extends InterpolatingAtmosphericModel {
} }
@Override @Override
public int getModID() { public ModID getModID() {
return 0; return ModID.ZERO;
} }
} }

View File

@ -1,6 +1,7 @@
package info.openrocket.core.models.gravity; package info.openrocket.core.models.gravity;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.WorldCoordinate; import info.openrocket.core.util.WorldCoordinate;
/** /**
@ -28,9 +29,9 @@ public class WGSGravityModel implements GravityModel {
} }
@Override @Override
public int getModID() { public ModID getModID() {
// The model is immutable, so it can return a constant mod ID // The model is immutable, so it can return a constant mod ID
return 0; return ModID.ZERO;
} }
private double calcGravity(WorldCoordinate wc) { private double calcGravity(WorldCoordinate wc) {

View File

@ -4,6 +4,7 @@ import java.util.Random;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.PinkNoise; import info.openrocket.core.util.PinkNoise;
/** /**
@ -161,8 +162,8 @@ public class PinkNoiseWindModel implements WindModel {
} }
@Override @Override
public int getModID() { public ModID getModID() {
return (int) (average * 1000 + standardDeviation); return ModID.ZERO;
} }
} }

View File

@ -9,6 +9,7 @@ import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.Inertia; import info.openrocket.core.util.Inertia;
import info.openrocket.core.util.ModID;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -34,7 +35,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
private final List<MotorConfiguration> configListeners = new LinkedList<>(); private final List<MotorConfiguration> configListeners = new LinkedList<>();
private int modID = 0; private ModID modID = ModID.INVALID;
public MotorConfiguration(final MotorMount _mount, final FlightConfigurationId _fcid) { public MotorConfiguration(final MotorMount _mount, final FlightConfigurationId _fcid) {
if (null == _mount) { if (null == _mount) {
@ -48,7 +49,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.fcid = _fcid; this.fcid = _fcid;
this.mid = new MotorConfigurationId(_mount, _fcid); this.mid = new MotorConfigurationId(_mount, _fcid);
modID++; modID = new ModID();
} }
public MotorConfiguration(final MotorMount _mount, final FlightConfigurationId _fcid, public MotorConfiguration(final MotorMount _mount, final FlightConfigurationId _fcid,
@ -262,7 +263,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.ignitionEvent = configuration.ignitionEvent; this.ignitionEvent = configuration.ignitionEvent;
} }
public int getModID() { public ModID getModID() {
return modID; return modID;
} }

View File

@ -1,6 +1,7 @@
package info.openrocket.core.optimization.rocketoptimization.modifiers; package info.openrocket.core.optimization.rocketoptimization.modifiers;
import java.util.Locale; import java.util.Locale;
import java.util.UUID;
import info.openrocket.core.document.Simulation; import info.openrocket.core.document.Simulation;
import info.openrocket.core.optimization.general.OptimizationException; import info.openrocket.core.optimization.general.OptimizationException;
@ -14,7 +15,7 @@ import info.openrocket.core.util.Reflection.Method;
public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E>> extends GenericModifier<E> { public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E>> extends GenericModifier<E> {
private final Class<? extends RocketComponent> componentClass; private final Class<? extends RocketComponent> componentClass;
private final String componentId; private final UUID componentId;
private final Method configGetter; private final Method configGetter;
/** /**
@ -47,7 +48,7 @@ public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E
UnitGroup unitGroup, UnitGroup unitGroup,
double multiplier, double multiplier,
Class<? extends RocketComponent> componentClass, Class<? extends RocketComponent> componentClass,
String componentId, UUID componentId,
String configName, String configName,
Class<E> flightConfigClass, Class<E> flightConfigClass,
String methodName) { String methodName) {

View File

@ -1,5 +1,7 @@
package info.openrocket.core.optimization.rocketoptimization.modifiers; package info.openrocket.core.optimization.rocketoptimization.modifiers;
import java.util.UUID;
import info.openrocket.core.document.Simulation; import info.openrocket.core.document.Simulation;
import info.openrocket.core.optimization.general.OptimizationException; import info.openrocket.core.optimization.general.OptimizationException;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
@ -15,7 +17,7 @@ import info.openrocket.core.unit.UnitGroup;
public class GenericComponentModifier extends GenericModifier<RocketComponent> { public class GenericComponentModifier extends GenericModifier<RocketComponent> {
private final Class<? extends RocketComponent> componentClass; private final Class<? extends RocketComponent> componentClass;
private final String componentId; private final UUID componentId;
/** /**
* Sole constructor. * Sole constructor.
@ -39,7 +41,7 @@ public class GenericComponentModifier extends GenericModifier<RocketComponent> {
*/ */
public GenericComponentModifier(String modifierName, String modifierDescription, Object relatedObject, public GenericComponentModifier(String modifierName, String modifierDescription, Object relatedObject,
UnitGroup unitGroup, UnitGroup unitGroup,
double multiplier, Class<? extends RocketComponent> componentClass, String componentId, String methodName) { double multiplier, Class<? extends RocketComponent> componentClass, UUID componentId, String methodName) {
super(modifierName, modifierDescription, relatedObject, unitGroup, multiplier, componentClass, methodName); super(modifierName, modifierDescription, relatedObject, unitGroup, multiplier, componentClass, methodName);
this.componentClass = componentClass; this.componentClass = componentClass;

View File

@ -8,7 +8,11 @@ import info.openrocket.core.motor.MotorConfiguration;
import info.openrocket.core.motor.MotorConfigurationSet; import info.openrocket.core.motor.MotorConfigurationSet;
import info.openrocket.core.preset.ComponentPreset; import info.openrocket.core.preset.ComponentPreset;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
import info.openrocket.core.util.*; import info.openrocket.core.util.BoundingBox;
import info.openrocket.core.util.BugException;
import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
/** /**
* Rocket body tube component. Has only two parameters, a radius and length. * Rocket body tube component. Has only two parameters, a radius and length.

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import info.openrocket.core.formatting.RocketDescriptor; import info.openrocket.core.formatting.RocketDescriptor;
@ -20,6 +21,7 @@ import info.openrocket.core.util.ArrayList;
import info.openrocket.core.util.BoundingBox; import info.openrocket.core.util.BoundingBox;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.Transformation; import info.openrocket.core.util.Transformation;
@ -47,9 +49,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
private class StageFlags implements Cloneable { private class StageFlags implements Cloneable {
public boolean active = true; public boolean active = true;
public int stageNumber = -1; public int stageNumber = -1;
public String stageId; public UUID stageId;
public StageFlags(int _num, String stageId, boolean _active) { public StageFlags(int _num, UUID stageId, boolean _active) {
this.stageNumber = _num; this.stageNumber = _num;
this.stageId = stageId; this.stageId = stageId;
this.active = _active; this.active = _active;
@ -71,16 +73,16 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
final private InstanceMap extraRenderInstances = new InstanceMap(); // Extra instances to be rendered, besides the final private InstanceMap extraRenderInstances = new InstanceMap(); // Extra instances to be rendered, besides the
// active instances // active instances
private int boundsModID = -1; private ModID boundsModID = ModID.INVALID;
private BoundingBox cachedBoundsAerodynamic = new BoundingBox(); // Bounding box of all aerodynamic components private BoundingBox cachedBoundsAerodynamic = new BoundingBox(); // Bounding box of all aerodynamic components
private BoundingBox cachedBounds = new BoundingBox(); // Bounding box of all components private BoundingBox cachedBounds = new BoundingBox(); // Bounding box of all components
private double cachedLengthAerodynamic = -1; // Rocket length of all aerodynamic components private double cachedLengthAerodynamic = -1; // Rocket length of all aerodynamic components
private double cachedLength = -1; // Rocket length of all components private double cachedLength = -1; // Rocket length of all components
private int refLengthModID = -1; private ModID refLengthModID = ModID.INVALID;
private double cachedRefLength = -1; private double cachedRefLength = -1;
private int modID = 0; private ModID modID = ModID.ZERO;
/** /**
* Create a Default configuration with the specified <code>Rocket</code>. * Create a Default configuration with the specified <code>Rocket</code>.
@ -542,9 +544,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
// for outgoing events only // for outgoing events only
protected void fireChangeEvent() { protected void fireChangeEvent() {
this.modID++; this.modID = new ModID();
boundsModID = -1; boundsModID = ModID.INVALID;
refLengthModID = -1; refLengthModID = ModID.INVALID;
updateStages(); updateStages();
updateMotors(); updateMotors();
@ -555,7 +557,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
* Update the configuration's modID, thus staging it in need to update. * Update the configuration's modID, thus staging it in need to update.
*/ */
public void updateModID() { public void updateModID() {
this.modID++; modID = new ModID();
} }
private void updateStages() { private void updateStages() {
@ -627,7 +629,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.motors.put(motorConfig.getID(), motorConfig); this.motors.put(motorConfig.getID(), motorConfig);
modID++; modID = new ModID();
} }
public boolean hasMotors() { public boolean hasMotors() {
@ -870,8 +872,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
clone.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone(); clone.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone();
clone.cachedBounds = this.cachedBounds.clone(); clone.cachedBounds = this.cachedBounds.clone();
clone.modID = this.modID; clone.modID = this.modID;
clone.boundsModID = -1; clone.boundsModID = ModID.INVALID;
clone.refLengthModID = -1; clone.refLengthModID = ModID.INVALID;
return clone; return clone;
} }
@ -906,14 +908,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
copy.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone(); copy.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone();
copy.cachedBounds = this.cachedBounds.clone(); copy.cachedBounds = this.cachedBounds.clone();
copy.modID = this.modID; copy.modID = this.modID;
copy.boundsModID = -1; copy.boundsModID = ModID.INVALID;
copy.refLengthModID = -1; copy.refLengthModID = ModID.INVALID;
copy.configurationName = configurationName; copy.configurationName = configurationName;
return copy; return copy;
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }
@ -952,7 +954,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
final String fmt = " [%-2s][%4s]: %6s \n"; final String fmt = " [%-2s][%4s]: %6s \n";
buf.append(String.format(fmt, "#", "?actv", "Name")); buf.append(String.format(fmt, "#", "?actv", "Name"));
for (StageFlags flags : stages.values()) { for (StageFlags flags : stages.values()) {
final String stageId = flags.stageId; final UUID stageId = flags.stageId;
buf.append(String.format(fmt, stageId, (flags.active ? " on" : "off"), rocket.getStage(stageId).getName())); buf.append(String.format(fmt, stageId, (flags.active ? " on" : "off"), rocket.getStage(stageId).getName()));
} }
buf.append("\n"); buf.append("\n");

View File

@ -13,11 +13,13 @@ import info.openrocket.core.motor.Motor;
import info.openrocket.core.motor.MotorConfiguration; import info.openrocket.core.motor.MotorConfiguration;
import info.openrocket.core.motor.MotorConfigurationSet; import info.openrocket.core.motor.MotorConfigurationSet;
import info.openrocket.core.preset.ComponentPreset; import info.openrocket.core.preset.ComponentPreset;
import info.openrocket.core.rocketcomponent.ThicknessRingComponent;
import info.openrocket.core.rocketcomponent.position.AxialPositionable; import info.openrocket.core.rocketcomponent.position.AxialPositionable;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
/** /**
* This class defines an inner tube that can be used as a motor mount. The * This class defines an inner tube that can be used as a motor mount. The

View File

@ -1,6 +1,7 @@
package info.openrocket.core.rocketcomponent; package info.openrocket.core.rocketcomponent;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID;
import info.openrocket.core.motor.MotorConfiguration; import info.openrocket.core.motor.MotorConfiguration;
import info.openrocket.core.motor.MotorConfigurationSet; import info.openrocket.core.motor.MotorConfigurationSet;
@ -74,7 +75,7 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent {
public double getLength(); public double getLength();
// duplicate of RocketComponent // duplicate of RocketComponent
public String getID(); public UUID getID();
// duplicate of RocketComponent // duplicate of RocketComponent
public String getDebugName(); public String getDebugName();

View File

@ -12,8 +12,9 @@ import info.openrocket.core.startup.Application;
import info.openrocket.core.util.BoundingBox; import info.openrocket.core.util.BoundingBox;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
import info.openrocket.core.util.UniqueID; import info.openrocket.core.util.ModID;
/** /**
* Base for all rocket components. This is the "starting point" for all rocket trees. * Base for all rocket components. This is the "starting point" for all rocket trees.
@ -43,11 +44,11 @@ public class Rocket extends ComponentAssembly {
private List<ComponentChangeEvent> freezeList = null; private List<ComponentChangeEvent> freezeList = null;
private int modID; private ModID modID;
private int massModID; private ModID massModID;
private int aeroModID; private ModID aeroModID;
private int treeModID; private ModID treeModID;
private int functionalModID; private ModID functionalModID;
private boolean eventsEnabled = false; private boolean eventsEnabled = false;
@ -72,7 +73,7 @@ public class Rocket extends ComponentAssembly {
public Rocket() { public Rocket() {
super(AxialMethod.ABSOLUTE); super(AxialMethod.ABSOLUTE);
modID = UniqueID.next(); modID = new ModID();
massModID = modID; massModID = modID;
aeroModID = modID; aeroModID = modID;
treeModID = modID; treeModID = modID;
@ -148,37 +149,37 @@ public class Rocket extends ComponentAssembly {
* *
* @return a unique ID number for this modification state. * @return a unique ID number for this modification state.
*/ */
public int getModID() { public ModID getModID() {
return modID; return modID;
} }
/** /**
* Return the non-negative mass modification ID of this rocket. See * Return the mass modification ID of this rocket. See
* {@link #getModID()} for details. * {@link #getModID()} for details.
* *
* @return a unique ID number for this mass-modification state. * @return a unique ID number for this mass-modification state.
*/ */
public int getMassModID() { public ModID getMassModID() {
return massModID; return massModID;
} }
/** /**
* Return the non-negative aerodynamic modification ID of this rocket. See * Return the aerodynamic modification ID of this rocket. See
* {@link #getModID()} for details. * {@link #getModID()} for details.
* *
* @return a unique ID number for this aerodynamic-modification state. * @return a unique ID number for this aerodynamic-modification state.
*/ */
public int getAerodynamicModID() { public ModID getAerodynamicModID() {
return aeroModID; return aeroModID;
} }
/** /**
* Return the non-negative tree modification ID of this rocket. See * Return the tree modification ID of this rocket. See
* {@link #getModID()} for details. * {@link #getModID()} for details.
* *
* @return a unique ID number for this tree-modification state. * @return a unique ID number for this tree-modification state.
*/ */
public int getTreeModID() { public ModID getTreeModID() {
return treeModID; return treeModID;
} }
@ -188,7 +189,7 @@ public class Rocket extends ComponentAssembly {
* *
* @return a unique ID number for this functional modification state. * @return a unique ID number for this functional modification state.
*/ */
public int getFunctionalModID() { public ModID getFunctionalModID() {
return functionalModID; return functionalModID;
} }
@ -200,7 +201,7 @@ public class Rocket extends ComponentAssembly {
return this.stageMap.get(stageNumber); return this.stageMap.get(stageNumber);
} }
public AxialStage getStage(final String stageId) { public AxialStage getStage(final UUID stageId) {
for (AxialStage stage : getStageList()) { for (AxialStage stage : getStageList()) {
if (stage.getID().equals(stageId)) { if (stage.getID().equals(stageId)) {
return stage; return stage;
@ -547,7 +548,7 @@ public class Rocket extends ComponentAssembly {
// Update modification ID's only for normal (not undo/redo) events // Update modification ID's only for normal (not undo/redo) events
if (!cce.isUndoChange()) { if (!cce.isUndoChange()) {
modID = UniqueID.next(); modID = new ModID();
if (cce.isMassChange()) if (cce.isMassChange())
massModID = modID; massModID = modID;
if (cce.isAerodynamicChange()) if (cce.isAerodynamicChange())

View File

@ -9,6 +9,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.UUID;
import info.openrocket.core.aerodynamics.AerodynamicCalculator; import info.openrocket.core.aerodynamics.AerodynamicCalculator;
import info.openrocket.core.aerodynamics.AerodynamicForces; import info.openrocket.core.aerodynamics.AerodynamicForces;
@ -18,6 +19,7 @@ import info.openrocket.core.logging.WarningSet;
import info.openrocket.core.rocketcomponent.position.AnglePositionable; import info.openrocket.core.rocketcomponent.position.AnglePositionable;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
import info.openrocket.core.startup.Preferences; import info.openrocket.core.startup.Preferences;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.ORColor; import info.openrocket.core.util.ORColor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,7 +41,6 @@ import info.openrocket.core.util.LineStyle;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.SafetyMutex; import info.openrocket.core.util.SafetyMutex;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
import info.openrocket.core.util.UniqueID;
/** /**
* Master class that defines components of rockets * Master class that defines components of rockets
@ -133,7 +134,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
private String comment = ""; private String comment = "";
// Unique ID of the component // Unique ID of the component
private String id = null; private UUID id = null;
// Preset component this component is based upon // Preset component this component is based upon
private ComponentPreset presetComponent = null; private ComponentPreset presetComponent = null;
@ -1296,12 +1297,12 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* *
* @return the ID of the component. * @return the ID of the component.
*/ */
public final String getID() { public final UUID getID() {
return id; return id;
} }
public final String getDebugName() { public final String getDebugName() {
return (name + "/" + id.substring(0,8)); return (name + "/" + id.toString().substring(0,8));
} }
/** /**
@ -1309,7 +1310,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
*/ */
private final void newID() { private final void newID() {
mutex.verify(); mutex.verify();
this.id = UniqueID.uuid(); this.id = UUID.randomUUID();
} }
/** /**
@ -1317,12 +1318,14 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* Generally not recommended to directly set the ID, this is done automatically. Only use this in case you have to. * Generally not recommended to directly set the ID, this is done automatically. Only use this in case you have to.
* @param newID new ID * @param newID new ID
*/ */
public void setID(String newID) { public void setID(UUID newID) {
mutex.verify(); mutex.verify();
this.id = newID; this.id = newID;
} }
public void setID(String newID) {
setID(UUID.fromString(newID));
}
/** /**
* Get the characteristic length of the component, for example the length of a body tube * Get the characteristic length of the component, for example the length of a body tube
* of the length of the root chord of a fin. This is used in positioning the component * of the length of the root chord of a fin. This is used in positioning the component
@ -2392,7 +2395,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* @param idToFind ID to search for. * @param idToFind ID to search for.
* @return The component with the ID, or null if not found. * @return The component with the ID, or null if not found.
*/ */
public final RocketComponent findComponent(String idToFind) { public final RocketComponent findComponent(UUID idToFind) {
checkState(); checkState();
mutex.lock("findComponent"); mutex.lock("findComponent");
Iterator<RocketComponent> iter = this.iterator(true); Iterator<RocketComponent> iter = this.iterator(true);
@ -2960,7 +2963,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
private final Deque<Iterator<RocketComponent>> iteratorStack = new ArrayDeque<Iterator<RocketComponent>>(); private final Deque<Iterator<RocketComponent>> iteratorStack = new ArrayDeque<Iterator<RocketComponent>>();
private final Rocket root; private final Rocket root;
private final int treeModID; private final ModID treeModID;
private final RocketComponent original; private final RocketComponent original;
private boolean returnSelf = false; private boolean returnSelf = false;
@ -2974,7 +2977,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
treeModID = root.getTreeModID(); treeModID = root.getTreeModID();
} else { } else {
root = null; root = null;
treeModID = -1; treeModID = ModID.INVALID;
} }
Iterator<RocketComponent> i = c.children.iterator(); Iterator<RocketComponent> i = c.children.iterator();
@ -3041,7 +3044,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/// debug functions /// debug functions
public String toDebugName() { public String toDebugName() {
return this.getName() + "<" + this.getClass().getSimpleName() + ">(" + this.getID().substring(0, 8) + ")"; return this.getName() + "<" + this.getClass().getSimpleName() + ">(" + this.getID().toString().substring(0, 8) + ")";
} }
// multi-line output // multi-line output

View File

@ -2,6 +2,7 @@ package info.openrocket.core.simulation;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
/** /**
@ -13,7 +14,7 @@ import info.openrocket.core.util.Monitorable;
*/ */
public class EventQueue extends PriorityQueue<FlightEvent> implements Monitorable { public class EventQueue extends PriorityQueue<FlightEvent> implements Monitorable {
private int modID = 0; private ModID modID = ModID.INVALID;
public EventQueue() { public EventQueue() {
super(); super();
@ -25,36 +26,36 @@ public class EventQueue extends PriorityQueue<FlightEvent> implements Monitorabl
@Override @Override
public boolean add(FlightEvent e) { public boolean add(FlightEvent e) {
modID++; modID = new ModID();
return super.add(e); return super.add(e);
} }
@Override @Override
public void clear() { public void clear() {
modID++; modID = new ModID();
super.clear(); super.clear();
} }
@Override @Override
public boolean offer(FlightEvent e) { public boolean offer(FlightEvent e) {
modID++; modID = new ModID();
return super.offer(e); return super.offer(e);
} }
@Override @Override
public FlightEvent poll() { public FlightEvent poll() {
modID++; modID = new ModID();
return super.poll(); return super.poll();
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
modID++; modID = new ModID();
return super.remove(o); return super.remove(o);
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }

View File

@ -10,6 +10,7 @@ import info.openrocket.core.rocketcomponent.AxialStage;
import info.openrocket.core.rocketcomponent.Rocket; import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.util.ArrayList; import info.openrocket.core.util.ArrayList;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.Mutable; import info.openrocket.core.util.Mutable;
@ -51,7 +52,7 @@ public class FlightDataBranch implements Monitorable {
private final Mutable mutable = new Mutable(); private final Mutable mutable = new Mutable();
private int modID = 0; private ModID modID = ModID.INVALID;
/** /**
* Sole constructor. Defines the name of the FlightDataBranch and at least one variable type. * Sole constructor. Defines the name of the FlightDataBranch and at least one variable type.
@ -117,7 +118,7 @@ public class FlightDataBranch implements Monitorable {
sanityCheckValues(type, Double.NaN); sanityCheckValues(type, Double.NaN);
values.get(type).add(Double.NaN); values.get(type).add(Double.NaN);
} }
modID++; modID = new ModID();
} }
private void sanityCheckValues(FlightDataType type, Double value) { private void sanityCheckValues(FlightDataType type, Double value) {
@ -162,7 +163,7 @@ public class FlightDataBranch implements Monitorable {
if (Double.isNaN(max) || (value > max)) { if (Double.isNaN(max) || (value > max)) {
maxValues.put(type, value); maxValues.put(type, value);
} }
modID++; modID = new ModID();
} }
/** /**
@ -381,7 +382,7 @@ public class FlightDataBranch implements Monitorable {
public void addEvent(FlightEvent event) { public void addEvent(FlightEvent event) {
mutable.check(); mutable.check();
events.add(event); events.add(event);
modID++; modID = new ModID();
} }
@ -441,7 +442,7 @@ public class FlightDataBranch implements Monitorable {
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }

View File

@ -15,6 +15,7 @@ import info.openrocket.core.simulation.listeners.SimulationListener;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.GeodeticComputationStrategy; import info.openrocket.core.util.GeodeticComputationStrategy;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.WorldCoordinate; import info.openrocket.core.util.WorldCoordinate;
@ -62,8 +63,8 @@ public class SimulationConditions implements Monitorable, Cloneable {
private int randomSeed = 0; private int randomSeed = 0;
private int modID = 0; private ModID modID = ModID.INVALID;
private int modIDadd = 0; private ModID modIDadd = ModID.INVALID;
public AerodynamicCalculator getAerodynamicCalculator() { public AerodynamicCalculator getAerodynamicCalculator() {
return aerodynamicCalculator; return aerodynamicCalculator;
@ -71,8 +72,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) { public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) {
if (this.aerodynamicCalculator != null) if (this.aerodynamicCalculator != null)
this.modIDadd += this.aerodynamicCalculator.getModID(); this.modIDadd = new ModID();
this.modID++;
this.aerodynamicCalculator = aerodynamicCalculator; this.aerodynamicCalculator = aerodynamicCalculator;
} }
@ -82,8 +82,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setMassCalculator(MassCalculator massCalculator) { public void setMassCalculator(MassCalculator massCalculator) {
if (this.massCalculator != null) if (this.massCalculator != null)
this.modIDadd += this.massCalculator.getModID(); this.modIDadd = new ModID();
this.modID++;
this.massCalculator = massCalculator; this.massCalculator = massCalculator;
} }
@ -105,7 +104,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setLaunchRodLength(double launchRodLength) { public void setLaunchRodLength(double launchRodLength) {
this.launchRodLength = launchRodLength; this.launchRodLength = launchRodLength;
this.modID++; this.modID = new ModID();
} }
public double getLaunchRodAngle() { public double getLaunchRodAngle() {
@ -114,7 +113,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setLaunchRodAngle(double launchRodAngle) { public void setLaunchRodAngle(double launchRodAngle) {
this.launchRodAngle = launchRodAngle; this.launchRodAngle = launchRodAngle;
this.modID++; this.modID = new ModID();
} }
public double getLaunchRodDirection() { public double getLaunchRodDirection() {
@ -123,7 +122,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setLaunchRodDirection(double launchRodDirection) { public void setLaunchRodDirection(double launchRodDirection) {
this.launchRodDirection = launchRodDirection; this.launchRodDirection = launchRodDirection;
this.modID++; this.modID = new ModID();
} }
public WorldCoordinate getLaunchSite() { public WorldCoordinate getLaunchSite() {
@ -134,7 +133,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
if (this.launchSite.equals(site)) if (this.launchSite.equals(site))
return; return;
this.launchSite = site; this.launchSite = site;
this.modID++; this.modID = new ModID();
} }
public Coordinate getLaunchPosition() { public Coordinate getLaunchPosition() {
@ -145,7 +144,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
if (this.launchPosition.equals(launchPosition)) if (this.launchPosition.equals(launchPosition))
return; return;
this.launchPosition = launchPosition; this.launchPosition = launchPosition;
this.modID++; this.modID = new ModID();
} }
public Coordinate getLaunchVelocity() { public Coordinate getLaunchVelocity() {
@ -156,7 +155,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
if (this.launchVelocity.equals(launchVelocity)) if (this.launchVelocity.equals(launchVelocity))
return; return;
this.launchVelocity = launchVelocity; this.launchVelocity = launchVelocity;
this.modID++; this.modID = new ModID();
} }
public GeodeticComputationStrategy getGeodeticComputation() { public GeodeticComputationStrategy getGeodeticComputation() {
@ -170,7 +169,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
throw new IllegalArgumentException("strategy cannot be null"); throw new IllegalArgumentException("strategy cannot be null");
} }
this.geodeticComputation = geodeticComputation; this.geodeticComputation = geodeticComputation;
this.modID++; this.modID = new ModID();
} }
public WindModel getWindModel() { public WindModel getWindModel() {
@ -179,8 +178,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setWindModel(WindModel windModel) { public void setWindModel(WindModel windModel) {
if (this.windModel != null) if (this.windModel != null)
this.modIDadd += this.windModel.getModID(); this.modIDadd = new ModID();
this.modID++;
this.windModel = windModel; this.windModel = windModel;
} }
@ -190,8 +188,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setAtmosphericModel(AtmosphericModel atmosphericModel) { public void setAtmosphericModel(AtmosphericModel atmosphericModel) {
if (this.atmosphericModel != null) if (this.atmosphericModel != null)
this.modIDadd += this.atmosphericModel.getModID(); this.modIDadd = new ModID();
this.modID++;
this.atmosphericModel = atmosphericModel; this.atmosphericModel = atmosphericModel;
} }
@ -200,9 +197,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
} }
public void setGravityModel(GravityModel gravityModel) { public void setGravityModel(GravityModel gravityModel) {
// if (this.gravityModel != null) this.modID = new ModID();
// this.modIDadd += this.gravityModel.getModID();
this.modID++;
this.gravityModel = gravityModel; this.gravityModel = gravityModel;
} }
@ -212,7 +207,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setTimeStep(double timeStep) { public void setTimeStep(double timeStep) {
this.timeStep = timeStep; this.timeStep = timeStep;
this.modID++; this.modID = new ModID();
} }
public double getMaximumAngleStep() { public double getMaximumAngleStep() {
@ -221,7 +216,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setMaximumAngleStep(double maximumAngle) { public void setMaximumAngleStep(double maximumAngle) {
this.maximumAngleStep = maximumAngle; this.maximumAngleStep = maximumAngle;
this.modID++; this.modID = new ModID();
} }
public int getRandomSeed() { public int getRandomSeed() {
@ -230,7 +225,7 @@ public class SimulationConditions implements Monitorable, Cloneable {
public void setRandomSeed(int randomSeed) { public void setRandomSeed(int randomSeed) {
this.randomSeed = randomSeed; this.randomSeed = randomSeed;
this.modID++; this.modID = new ModID();
} }
public void setSimulation(Simulation sim) { public void setSimulation(Simulation sim) {
@ -247,11 +242,8 @@ public class SimulationConditions implements Monitorable, Cloneable {
} }
@Override @Override
public int getModID() { public ModID getModID() {
//return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() + return modID;
// gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID());
return (modID + modIDadd + simulation.getRocket().getModID() + windModel.getModID() + atmosphericModel.getModID() +
aerodynamicCalculator.getModID() + massCalculator.getModID());
} }
@Override @Override

View File

@ -21,6 +21,7 @@ import info.openrocket.core.simulation.listeners.SimulationListenerHelper;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.Monitorable; import info.openrocket.core.util.Monitorable;
import info.openrocket.core.util.MonitorableSet; import info.openrocket.core.util.MonitorableSet;
import info.openrocket.core.util.Quaternion; import info.openrocket.core.util.Quaternion;
@ -92,8 +93,8 @@ public class SimulationStatus implements Cloneable, Monitorable {
double maxAlt = Double.NEGATIVE_INFINITY; double maxAlt = Double.NEGATIVE_INFINITY;
double maxAltTime = 0; double maxAltTime = 0;
private int modID = 0; private ModID modID = ModID.INVALID;
private int modIDadd = 0; private ModID modIDadd = ModID.INVALID;
public SimulationStatus(FlightConfiguration configuration, SimulationConditions simulationConditions) { public SimulationStatus(FlightConfiguration configuration, SimulationConditions simulationConditions) {
@ -211,7 +212,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setSimulationTime(double time) { public void setSimulationTime(double time) {
this.time = time; this.time = time;
this.modID++; this.modID = new ModID();
} }
public double getSimulationTime() { public double getSimulationTime() {
@ -220,8 +221,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setConfiguration(FlightConfiguration configuration) { public void setConfiguration(FlightConfiguration configuration) {
if (this.configuration != null) if (this.configuration != null)
this.modIDadd += this.configuration.getModID(); this.modIDadd = new ModID();
this.modID++;
this.configuration = configuration; this.configuration = configuration;
} }
@ -250,8 +250,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setFlightDataBranch(FlightDataBranch flightDataBranch) { public void setFlightDataBranch(FlightDataBranch flightDataBranch) {
if (this.flightDataBranch != null) if (this.flightDataBranch != null)
this.modIDadd += this.flightDataBranch.getModID(); this.modIDadd = new ModID();
this.modID++;
this.flightDataBranch = flightDataBranch; this.flightDataBranch = flightDataBranch;
} }
@ -261,7 +260,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setRocketPosition(Coordinate position) { public void setRocketPosition(Coordinate position) {
this.position = position; this.position = position;
this.modID++; modID = new ModID();
} }
public Coordinate getRocketPosition() { public Coordinate getRocketPosition() {
@ -270,7 +269,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setRocketWorldPosition(WorldCoordinate wc) { public void setRocketWorldPosition(WorldCoordinate wc) {
this.worldPosition = wc; this.worldPosition = wc;
this.modID++; modID = new ModID();
} }
public WorldCoordinate getRocketWorldPosition() { public WorldCoordinate getRocketWorldPosition() {
@ -279,7 +278,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setRocketVelocity(Coordinate velocity) { public void setRocketVelocity(Coordinate velocity) {
this.velocity = velocity; this.velocity = velocity;
this.modID++; modID = new ModID();
} }
public Coordinate getRocketVelocity() { public Coordinate getRocketVelocity() {
@ -288,7 +287,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setRocketAcceleration(Coordinate acceleration) { public void setRocketAcceleration(Coordinate acceleration) {
this.acceleration = acceleration; this.acceleration = acceleration;
this.modID++; modID = new ModID();
} }
public Coordinate getRocketAcceleration() { public Coordinate getRocketAcceleration() {
@ -308,7 +307,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setRocketOrientationQuaternion(Quaternion orientation) { public void setRocketOrientationQuaternion(Quaternion orientation) {
this.orientation = orientation; this.orientation = orientation;
this.modID++; modID = new ModID();
} }
public Coordinate getRocketRotationVelocity() { public Coordinate getRocketRotationVelocity() {
@ -321,7 +320,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setEffectiveLaunchRodLength(double effectiveLaunchRodLength) { public void setEffectiveLaunchRodLength(double effectiveLaunchRodLength) {
this.effectiveLaunchRodLength = effectiveLaunchRodLength; this.effectiveLaunchRodLength = effectiveLaunchRodLength;
this.modID++; modID = new ModID();
} }
public double getEffectiveLaunchRodLength() { public double getEffectiveLaunchRodLength() {
@ -330,7 +329,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setSimulationStartWallTime(long simulationStartWallTime) { public void setSimulationStartWallTime(long simulationStartWallTime) {
this.simulationStartWallTime = simulationStartWallTime; this.simulationStartWallTime = simulationStartWallTime;
this.modID++; modID = new ModID();
} }
public long getSimulationStartWallTime() { public long getSimulationStartWallTime() {
@ -339,7 +338,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setMotorIgnited(boolean motorIgnited) { public void setMotorIgnited(boolean motorIgnited) {
this.motorIgnited = motorIgnited; this.motorIgnited = motorIgnited;
this.modID++; modID = new ModID();
} }
public boolean isMotorIgnited() { public boolean isMotorIgnited() {
@ -348,7 +347,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setLiftoff(boolean liftoff) { public void setLiftoff(boolean liftoff) {
this.liftoff = liftoff; this.liftoff = liftoff;
this.modID++; modID = new ModID();
} }
public boolean isLiftoff() { public boolean isLiftoff() {
@ -357,7 +356,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setLaunchRodCleared(boolean launchRod) { public void setLaunchRodCleared(boolean launchRod) {
this.launchRodCleared = launchRod; this.launchRodCleared = launchRod;
this.modID++; modID = new ModID();
} }
public boolean isLaunchRodCleared() { public boolean isLaunchRodCleared() {
@ -366,7 +365,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setApogeeReached(boolean apogeeReached) { public void setApogeeReached(boolean apogeeReached) {
this.apogeeReached = apogeeReached; this.apogeeReached = apogeeReached;
this.modID++; modID = new ModID();
} }
public boolean isApogeeReached() { public boolean isApogeeReached() {
@ -375,7 +374,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setTumbling(boolean tumbling) { public void setTumbling(boolean tumbling) {
this.tumbling = tumbling; this.tumbling = tumbling;
this.modID++; modID = new ModID();
} }
public boolean isTumbling() { public boolean isTumbling() {
@ -384,7 +383,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setLanded(boolean landed) { public void setLanded(boolean landed) {
this.landed = landed; this.landed = landed;
this.modID++; modID = new ModID();
} }
public boolean isLanded() { public boolean isLanded() {
@ -397,7 +396,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setMaxAlt(double maxAlt) { public void setMaxAlt(double maxAlt) {
this.maxAlt = maxAlt; this.maxAlt = maxAlt;
this.modID++; modID = new ModID();
} }
public double getMaxAltTime() { public double getMaxAltTime() {
@ -406,7 +405,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setMaxAltTime(double maxAltTime) { public void setMaxAltTime(double maxAltTime) {
this.maxAltTime = maxAltTime; this.maxAltTime = maxAltTime;
this.modID++; modID = new ModID();
} }
public Set<RecoveryDevice> getDeployedRecoveryDevices() { public Set<RecoveryDevice> getDeployedRecoveryDevices() {
@ -415,8 +414,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setWarnings(WarningSet warnings) { public void setWarnings(WarningSet warnings) {
if (this.warnings != null) if (this.warnings != null)
this.modIDadd += this.warnings.getModID(); this.modIDadd = new ModID();
this.modID++;
this.warnings = warnings; this.warnings = warnings;
} }
@ -430,8 +428,7 @@ public class SimulationStatus implements Cloneable, Monitorable {
public void setSimulationConditions(SimulationConditions simulationConditions) { public void setSimulationConditions(SimulationConditions simulationConditions) {
if (this.simulationConditions != null) if (this.simulationConditions != null)
this.modIDadd += this.simulationConditions.getModID(); this.modIDadd = new ModID();
this.modID++;
this.simulationConditions = simulationConditions; this.simulationConditions = simulationConditions;
} }
@ -480,10 +477,8 @@ public class SimulationStatus implements Cloneable, Monitorable {
} }
@Override @Override
public int getModID() { public ModID getModID() {
return (modID + modIDadd + simulationConditions.getModID() + configuration.getModID() + return modID;
flightDataBranch.getModID() + deployedRecoveryDevices.getModID() +
eventQueue.getModID() + warnings.getModID());
} }
public String toEventDebug() { public String toEventDebug() {

View File

@ -18,6 +18,7 @@ import info.openrocket.core.simulation.SimulationStatus;
import info.openrocket.core.simulation.exception.SimulationException; import info.openrocket.core.simulation.exception.SimulationException;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
/** /**
* Helper methods for firing events to simulation listeners. * Helper methods for firing events to simulation listeners.
@ -35,7 +36,7 @@ public class SimulationListenerHelper {
*/ */
public static void fireStartSimulation(SimulationStatus status) public static void fireStartSimulation(SimulationStatus status)
throws SimulationException { throws SimulationException {
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
l.startSimulation(status); l.startSimulation(status);
@ -50,7 +51,7 @@ public class SimulationListenerHelper {
* Fire endSimulation event. * Fire endSimulation event.
*/ */
public static void fireEndSimulation(SimulationStatus status, SimulationException exception) { public static void fireEndSimulation(SimulationStatus status, SimulationException exception) {
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
l.endSimulation(status, exception); l.endSimulation(status, exception);
@ -70,7 +71,7 @@ public class SimulationListenerHelper {
public static boolean firePreStep(SimulationStatus status) public static boolean firePreStep(SimulationStatus status)
throws SimulationException { throws SimulationException {
boolean b; boolean b;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
b = l.preStep(status); b = l.preStep(status);
@ -91,7 +92,7 @@ public class SimulationListenerHelper {
*/ */
public static void firePostStep(SimulationStatus status) public static void firePostStep(SimulationStatus status)
throws SimulationException { throws SimulationException {
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
l.postStep(status); l.postStep(status);
@ -112,7 +113,7 @@ public class SimulationListenerHelper {
*/ */
public static boolean fireAddFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException { public static boolean fireAddFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException {
boolean b; boolean b;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationEventListener) { if (l instanceof SimulationEventListener) {
@ -138,7 +139,7 @@ public class SimulationListenerHelper {
*/ */
public static boolean fireHandleFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException { public static boolean fireHandleFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException {
boolean b; boolean b;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationEventListener) { if (l instanceof SimulationEventListener) {
@ -165,7 +166,7 @@ public class SimulationListenerHelper {
public static boolean fireMotorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount, public static boolean fireMotorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount,
MotorClusterState instance) throws SimulationException { MotorClusterState instance) throws SimulationException {
boolean result; boolean result;
int modID = status.getModID(); // Contains also motor instance ModID modID = status.getModID(); // Contains also motor instance
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationEventListener) { if (l instanceof SimulationEventListener) {
@ -192,7 +193,7 @@ public class SimulationListenerHelper {
public static boolean fireRecoveryDeviceDeployment(SimulationStatus status, RecoveryDevice device) public static boolean fireRecoveryDeviceDeployment(SimulationStatus status, RecoveryDevice device)
throws SimulationException { throws SimulationException {
boolean result; boolean result;
int modID = status.getModID(); // Contains also motor instance ModID modID = status.getModID(); // Contains also motor instance
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationEventListener) { if (l instanceof SimulationEventListener) {
@ -220,7 +221,7 @@ public class SimulationListenerHelper {
public static AtmosphericConditions firePreAtmosphericModel(SimulationStatus status) public static AtmosphericConditions firePreAtmosphericModel(SimulationStatus status)
throws SimulationException { throws SimulationException {
AtmosphericConditions conditions; AtmosphericConditions conditions;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -248,7 +249,7 @@ public class SimulationListenerHelper {
throws SimulationException { throws SimulationException {
AtmosphericConditions c; AtmosphericConditions c;
AtmosphericConditions clone = conditions.clone(); AtmosphericConditions clone = conditions.clone();
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -275,7 +276,7 @@ public class SimulationListenerHelper {
public static Coordinate firePreWindModel(SimulationStatus status) public static Coordinate firePreWindModel(SimulationStatus status)
throws SimulationException { throws SimulationException {
Coordinate wind; Coordinate wind;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -300,7 +301,7 @@ public class SimulationListenerHelper {
*/ */
public static Coordinate firePostWindModel(SimulationStatus status, Coordinate wind) throws SimulationException { public static Coordinate firePostWindModel(SimulationStatus status, Coordinate wind) throws SimulationException {
Coordinate w; Coordinate w;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -326,7 +327,7 @@ public class SimulationListenerHelper {
public static double firePreGravityModel(SimulationStatus status) public static double firePreGravityModel(SimulationStatus status)
throws SimulationException { throws SimulationException {
double gravity; double gravity;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -351,7 +352,7 @@ public class SimulationListenerHelper {
*/ */
public static double firePostGravityModel(SimulationStatus status, double gravity) throws SimulationException { public static double firePostGravityModel(SimulationStatus status, double gravity) throws SimulationException {
double g; double g;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -377,7 +378,7 @@ public class SimulationListenerHelper {
public static FlightConditions firePreFlightConditions(SimulationStatus status) public static FlightConditions firePreFlightConditions(SimulationStatus status)
throws SimulationException { throws SimulationException {
FlightConditions conditions; FlightConditions conditions;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -406,7 +407,7 @@ public class SimulationListenerHelper {
throws SimulationException { throws SimulationException {
FlightConditions c; FlightConditions c;
FlightConditions clone = conditions.clone(); FlightConditions clone = conditions.clone();
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -433,7 +434,7 @@ public class SimulationListenerHelper {
public static AerodynamicForces firePreAerodynamicCalculation(SimulationStatus status) public static AerodynamicForces firePreAerodynamicCalculation(SimulationStatus status)
throws SimulationException { throws SimulationException {
AerodynamicForces forces; AerodynamicForces forces;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -460,7 +461,7 @@ public class SimulationListenerHelper {
throws SimulationException { throws SimulationException {
AerodynamicForces f; AerodynamicForces f;
AerodynamicForces clone = forces.clone(); AerodynamicForces clone = forces.clone();
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -487,7 +488,7 @@ public class SimulationListenerHelper {
public static RigidBody firePreMassCalculation(SimulationStatus status) public static RigidBody firePreMassCalculation(SimulationStatus status)
throws SimulationException { throws SimulationException {
RigidBody mass; RigidBody mass;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -513,7 +514,7 @@ public class SimulationListenerHelper {
public static RigidBody firePostMassCalculation(SimulationStatus status, RigidBody mass) public static RigidBody firePostMassCalculation(SimulationStatus status, RigidBody mass)
throws SimulationException { throws SimulationException {
RigidBody m; RigidBody m;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -539,7 +540,7 @@ public class SimulationListenerHelper {
public static double firePreThrustCalculation(SimulationStatus status) public static double firePreThrustCalculation(SimulationStatus status)
throws SimulationException { throws SimulationException {
double thrust; double thrust;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -564,7 +565,7 @@ public class SimulationListenerHelper {
*/ */
public static double firePostThrustCalculation(SimulationStatus status, double thrust) throws SimulationException { public static double firePostThrustCalculation(SimulationStatus status, double thrust) throws SimulationException {
double t; double t;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -589,7 +590,7 @@ public class SimulationListenerHelper {
*/ */
public static AccelerationData firePreAccelerationCalculation(SimulationStatus status) throws SimulationException { public static AccelerationData firePreAccelerationCalculation(SimulationStatus status) throws SimulationException {
AccelerationData acceleration; AccelerationData acceleration;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {
@ -615,7 +616,7 @@ public class SimulationListenerHelper {
public static AccelerationData firePostAccelerationCalculation(SimulationStatus status, public static AccelerationData firePostAccelerationCalculation(SimulationStatus status,
AccelerationData acceleration) throws SimulationException { AccelerationData acceleration) throws SimulationException {
AccelerationData a; AccelerationData a;
int modID = status.getModID(); ModID modID = status.getModID();
for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) { for (SimulationListener l : status.getSimulationConditions().getSimulationListenerList()) {
if (l instanceof SimulationComputationListener) { if (l instanceof SimulationComputationListener) {

View File

@ -32,7 +32,6 @@ import info.openrocket.core.util.GeodeticComputationStrategy;
import info.openrocket.core.util.LineStyle; import info.openrocket.core.util.LineStyle;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
import info.openrocket.core.util.UniqueID;
public abstract class Preferences implements ChangeSource { public abstract class Preferences implements ChangeSource {
private static final String SPLIT_CHARACTER = "|"; private static final String SPLIT_CHARACTER = "|";
@ -747,20 +746,6 @@ public abstract class Preferences implements ChangeSource {
public void setMotorNameColumn(boolean value) { public void setMotorNameColumn(boolean value) {
putBoolean(info.openrocket.core.startup.Preferences.MOTOR_NAME_COLUMN, value); putBoolean(info.openrocket.core.startup.Preferences.MOTOR_NAME_COLUMN, value);
} }
/**
* Return the OpenRocket unique ID.
*
* @return a random ID string that stays constant between OpenRocket executions
*/
public final String getUniqueID() {
String id = this.getString("id", null);
if (id == null) {
id = UniqueID.uuid();
this.putString("id", id);
}
return id;
}
/** /**
* Returns a limited-range integer value from the preferences. If the value * Returns a limited-range integer value from the preferences. If the value

View File

@ -8,6 +8,7 @@ import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.rocketcomponent.SymmetricComponent; import info.openrocket.core.rocketcomponent.SymmetricComponent;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
public class CaliberUnit extends GeneralUnit { public class CaliberUnit extends GeneralUnit {
@ -16,8 +17,8 @@ public class CaliberUnit extends GeneralUnit {
private final FlightConfiguration configuration; private final FlightConfiguration configuration;
private final Rocket rocket; private final Rocket rocket;
private int rocketModId = -1; private ModID rocketModId = ModID.INVALID;
private int configurationModId = -1; private ModID configurationModId = ModID.INVALID;
private double caliber = -1; private double caliber = -1;

View File

@ -3,14 +3,15 @@ package info.openrocket.core.unit;
import info.openrocket.core.rocketcomponent.FlightConfiguration; import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.Rocket; import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.util.BugException; import info.openrocket.core.util.BugException;
import info.openrocket.core.util.ModID;
public class PercentageOfLengthUnit extends GeneralUnit { public class PercentageOfLengthUnit extends GeneralUnit {
private final FlightConfiguration configuration; private final FlightConfiguration configuration;
private final Rocket rocket; private final Rocket rocket;
private int rocketModId = -1; private ModID rocketModId = ModID.INVALID;
private int configurationModId = -1; private ModID configurationModId = ModID.INVALID;
private double referenceLength = -1; private double referenceLength = -1;
@ -96,4 +97,4 @@ public class PercentageOfLengthUnit extends GeneralUnit {
return getReferenceLength(rocket.getSelectedConfiguration()); return getReferenceLength(rocket.getSelectedConfiguration());
} }
} }

View File

@ -1,12 +1,11 @@
package info.openrocket.core.util; package info.openrocket.core.util;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public class UniqueID { public class ModID implements Comparable {
private static final AtomicInteger nextId = new AtomicInteger(1); private static final AtomicInteger nextId = new AtomicInteger(1);
private final int id;
/** /**
* Return a positive integer ID unique during this program execution. * Return a positive integer ID unique during this program execution.
* <p> * <p>
@ -21,17 +20,26 @@ public class UniqueID {
* *
* @return a positive integer ID unique in this program execution. * @return a positive integer ID unique in this program execution.
*/ */
public static int next() { public ModID() {
return nextId.getAndIncrement(); id = nextId.getAndIncrement();
} }
/** // There are a few places in the code that want a constant or invalid ModID value; see Barrowman.java
* Return a new universally unique ID string. private ModID(int val) {
* id = val;
* @return a unique identifier string. }
*/ public static ModID ZERO = new ModID(0);
public static String uuid() { public static ModID INVALID = new ModID(-1);
return UUID.randomUUID().toString();
public int toInt() {
return id;
}
public String toString() {
return String.valueOf(id);
} }
public int compareTo(Object o) {
return id - ((ModID) o).id;
}
} }

View File

@ -48,8 +48,8 @@ public interface Monitorable {
* object. * object.
* *
* @return a modification ID value for this object. * @return a modification ID value for this object.
* @see UniqueID#next() * @see ModID()
*/ */
public int getModID(); public ModID getModID();
} }

View File

@ -4,6 +4,8 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import info.openrocket.core.util.ModID;
/** /**
* A Set that additionally implements the Monitorable interface. * A Set that additionally implements the Monitorable interface.
* *
@ -11,23 +13,23 @@ import java.util.Iterator;
*/ */
public class MonitorableSet<E> extends HashSet<E> implements Monitorable { public class MonitorableSet<E> extends HashSet<E> implements Monitorable {
private int modID; private ModID modID;
@Override @Override
public boolean add(E e) { public boolean add(E e) {
modID++; modID = new ModID();
return super.add(e); return super.add(e);
} }
@Override @Override
public boolean addAll(Collection<? extends E> c) { public boolean addAll(Collection<? extends E> c) {
modID++; modID = new ModID();
return super.addAll(c); return super.addAll(c);
} }
@Override @Override
public void clear() { public void clear() {
modID++; modID = new ModID();
super.clear(); super.clear();
} }
@ -38,24 +40,24 @@ public class MonitorableSet<E> extends HashSet<E> implements Monitorable {
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
modID++; modID = new ModID();
return super.remove(o); return super.remove(o);
} }
@Override @Override
public boolean removeAll(Collection<?> c) { public boolean removeAll(Collection<?> c) {
modID++; modID = new ModID();
return super.removeAll(c); return super.removeAll(c);
} }
@Override @Override
public boolean retainAll(Collection<?> c) { public boolean retainAll(Collection<?> c) {
modID++; modID = new ModID();
return super.retainAll(c); return super.retainAll(c);
} }
@Override @Override
public int getModID() { public ModID getModID() {
return modID; return modID;
} }
@ -85,7 +87,7 @@ public class MonitorableSet<E> extends HashSet<E> implements Monitorable {
@Override @Override
public void remove() { public void remove() {
iterator.remove(); iterator.remove();
modID++; modID = new ModID();
} }
} }
} }

View File

@ -22,6 +22,7 @@ import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.TestRockets; import info.openrocket.core.util.TestRockets;
import info.openrocket.core.util.BaseTestCase; import info.openrocket.core.util.BaseTestCase;
import info.openrocket.core.util.ModID;
public class FlightConfigurationTest extends BaseTestCase { public class FlightConfigurationTest extends BaseTestCase {
private final static double EPSILON = MathUtil.EPSILON * 1E3; private final static double EPSILON = MathUtil.EPSILON * 1E3;
@ -767,14 +768,14 @@ public class FlightConfigurationTest extends BaseTestCase {
// Test boundModID // Test boundModID
Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID"); Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID");
boundsModIDField.setAccessible(true); boundsModIDField.setAccessible(true);
int boundsModIDCopy = (int) boundsModIDField.get(copy); ModID boundsModIDCopy = (ModID) boundsModIDField.get(copy);
assertEquals(-1, boundsModIDCopy); assertEquals(ModID.INVALID, boundsModIDCopy);
// Test refLengthModID // Test refLengthModID
Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID"); Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID");
refLengthModIDField.setAccessible(true); refLengthModIDField.setAccessible(true);
int refLengthModIDCopy = (int) refLengthModIDField.get(copy); ModID refLengthModIDCopy = (ModID) refLengthModIDField.get(copy);
assertEquals(-1, refLengthModIDCopy); assertEquals(ModID.INVALID, refLengthModIDCopy);
// Test stageActiveness copy // Test stageActiveness copy
for (int i = 0; i < original.getStageCount(); i++) { for (int i = 0; i < original.getStageCount(); i++) {
@ -833,14 +834,14 @@ public class FlightConfigurationTest extends BaseTestCase {
// Test boundModID // Test boundModID
Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID"); Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID");
boundsModIDField.setAccessible(true); boundsModIDField.setAccessible(true);
int boundsModIDClone = (int) boundsModIDField.get(clone); ModID boundsModIDClone = (ModID) boundsModIDField.get(clone);
assertEquals(-1, boundsModIDClone); assertEquals(ModID.INVALID, boundsModIDClone);
// Test refLengthModID // Test refLengthModID
Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID"); Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID");
refLengthModIDField.setAccessible(true); refLengthModIDField.setAccessible(true);
int refLengthModIDClone = (int) refLengthModIDField.get(clone); ModID refLengthModIDClone = (ModID) refLengthModIDField.get(clone);
assertEquals(-1, refLengthModIDClone); assertEquals(ModID.INVALID, refLengthModIDClone);
// Test stageActiveness copy // Test stageActiveness copy
for (int i = 0; i < original.getStageCount(); i++) { for (int i = 0; i < original.getStageCount(); i++) {

View File

@ -0,0 +1,23 @@
package info.openrocket.core.util;
import info.openrocket.core.util.ModID;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class ModIDTest {
@Test
public void modIDTest() {
ModID n1 = new ModID();
ModID n2 = new ModID();
ModID n3 = new ModID();
// assertTrue(n > 0);
assertEquals(n2, n2);
assertTrue(n1.toInt() < n2.toInt());
assertTrue(n3.toInt() > n2.toInt());
}
}

View File

@ -1,28 +0,0 @@
package info.openrocket.core.util;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class UniqueIDTest {
@Test
public void integerTest() {
int n = UniqueID.next();
assertTrue(n > 0);
assertEquals(n + 1, UniqueID.next());
assertEquals(n + 2, UniqueID.next());
assertEquals(n + 3, UniqueID.next());
}
@Test
public void stringTest() {
String id = UniqueID.uuid();
assertNotNull(id);
assertNotSame(id, UniqueID.uuid());
assertNotSame(id, UniqueID.uuid());
}
}

View File

@ -5,6 +5,7 @@ import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelEvent;
@ -102,7 +103,7 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
// Get currently expanded path IDs // Get currently expanded path IDs
Enumeration<TreePath> enumer = tree.getExpandedDescendants(new TreePath(path)); Enumeration<TreePath> enumer = tree.getExpandedDescendants(new TreePath(path));
ArrayList<String> expanded = new ArrayList<String>(); ArrayList<UUID> expanded = new ArrayList<UUID>();
if (enumer != null) { if (enumer != null) {
while (enumer.hasMoreElements()) { while (enumer.hasMoreElements()) {
TreePath p = enumer.nextElement(); TreePath p = enumer.nextElement();
@ -117,7 +118,7 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
((TreeModelListener) l[i]).treeStructureChanged(e); ((TreeModelListener) l[i]).treeStructureChanged(e);
// Re-expand the paths // Re-expand the paths
for (String id : expanded) { for (UUID id : expanded) {
RocketComponent c = root.findComponent(id); RocketComponent c = root.findComponent(id);
if (c == null) if (c == null)
continue; continue;

View File

@ -28,6 +28,7 @@ import info.openrocket.core.unit.UnitGroup;
import info.openrocket.core.util.BoundingBox; import info.openrocket.core.util.BoundingBox;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
@ -47,7 +48,7 @@ public class FinPointFigure extends AbstractScaleFigure {
private static final double MAJOR_TICKS = 100.0; private static final double MAJOR_TICKS = 100.0;
private final FreeformFinSet finset; private final FreeformFinSet finset;
private int modID = -1; private ModID modID = ModID.INVALID;
protected BoundingBox finBounds_m = null; protected BoundingBox finBounds_m = null;
// Fin parent bounds // Fin parent bounds

View File

@ -59,6 +59,7 @@ import info.openrocket.core.util.ChangeSource;
import info.openrocket.core.util.Chars; import info.openrocket.core.util.Chars;
import info.openrocket.core.util.Coordinate; import info.openrocket.core.util.Coordinate;
import info.openrocket.core.util.MathUtil; import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.ModID;
import info.openrocket.core.util.StateChangeListener; import info.openrocket.core.util.StateChangeListener;
import info.openrocket.swing.gui.components.StyledLabel; import info.openrocket.swing.gui.components.StyledLabel;
@ -159,7 +160,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
private double cpRoll = Double.NaN; private double cpRoll = Double.NaN;
// The functional ID of the rocket that was simulated // The functional ID of the rocket that was simulated
private int flightDataFunctionalID = -1; private ModID flightDataFunctionalID = ModID.INVALID;
private FlightConfigurationId flightDataMotorID = null; private FlightConfigurationId flightDataMotorID = null;
private SimulationWorker backgroundSimulationWorker = null; private SimulationWorker backgroundSimulationWorker = null;

View File

@ -10,6 +10,7 @@ import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.UUID;
import javax.swing.Action; import javax.swing.Action;
@ -69,7 +70,7 @@ public class IntegrationTest {
private AerodynamicCalculator aeroCalc = new BarrowmanCalculator(); private AerodynamicCalculator aeroCalc = new BarrowmanCalculator();
private FlightConfigurationId fcid; private FlightConfigurationId fcid;
private FlightConditions conditions; private FlightConditions conditions;
private String massComponentID = null; private UUID massComponentID = null;
@BeforeAll @BeforeAll
public static void setUp() throws Exception { public static void setUp() throws Exception {