diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index a579e3902..e857f667c 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -71,7 +71,16 @@ public class FlightConfiguration implements FlightConfigurableParameterRocket. + * + * @param rocket the rocket + */ + public FlightConfiguration(final Rocket rocket) { + this(rocket, FlightConfigurationId.DEFAULT_VALUE_FCID); + } + /** * Create a new configuration with the specified Rocket. * diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 8cde7c7ad..1be373b40 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -79,7 +79,7 @@ public class Rocket extends ComponentAssembly { functionalModID = modID; // must be after the hashmaps :P - FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID); + final FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID); configSet = new FlightConfigurableParameterSet<>( defaultConfig ); this.selectedConfiguration = defaultConfig; } @@ -330,15 +330,26 @@ public class Rocket extends ComponentAssembly { */ @Override public Rocket copyWithOriginalID() { - Rocket copy = (Rocket) super.copyWithOriginalID(); - + final Rocket copyRocket = (Rocket) super.copyWithOriginalID(); + // Rocket copy is cloned, so non-trivial members must be cloned as well: - copy.stageMap = new HashMap(); - copy.configSet = new FlightConfigurableParameterSet( this.configSet ); - copy.selectedConfiguration = copy.configSet.get( this.getSelectedConfiguration().getId()); - copy.listenerList = new HashSet(); + copyRocket.stageMap = new HashMap<>(); + for( Map.Entry entry : this.stageMap.entrySet()){ + final AxialStage stage = (AxialStage)copyRocket.findComponent(entry.getValue().getID()); + copyRocket.stageMap.put(entry.getKey(), stage); + } + + // these flight configurations need to reference the _new_ Rocket copy + // the default value needs to be explicitly set, because it has different semantics + copyRocket.configSet = new FlightConfigurableParameterSet<>(new FlightConfiguration(copyRocket)); + for (FlightConfigurationId key : this.configSet.getIds()) { + copyRocket.configSet.set(key, new FlightConfiguration(copyRocket, key)); + } + + copyRocket.selectedConfiguration = copyRocket.configSet.get( this.getSelectedConfiguration().getId()); + copyRocket.listenerList = new HashSet<>(); - return copy; + return copyRocket; } public int getFlightConfigurationCount() { @@ -376,8 +387,13 @@ public class Rocket extends ComponentAssembly { this.functionalModID = r.functionalModID; this.refType = r.refType; this.customReferenceLength = r.customReferenceLength; - this.configSet = new FlightConfigurableParameterSet( r.configSet ); - + + // these flight configurations need to reference the _this_ Rocket: + this.configSet.setDefault(new FlightConfiguration(this)); + for (FlightConfigurationId key : r.configSet.map.keySet()) { + this.configSet.set(key, new FlightConfiguration(this, key)); + } + this.perfectFinish = r.perfectFinish; this.checkComponentStructure();