diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 376728c21..101d2e34a 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -286,7 +286,7 @@ public class OpenRocketDocument implements ComponentChangeListener { removeSimulation(s); } } - rocket.removeFlightConfigurationID(configId); + rocket.removeFlightConfiguration(configId); } diff --git a/core/src/net/sf/openrocket/motor/MotorConfiguration.java b/core/src/net/sf/openrocket/motor/MotorConfiguration.java index 115e35350..6da292a50 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorConfiguration.java @@ -16,19 +16,18 @@ public class MotorConfiguration implements FlightConfigurableParameter> in: %28s::%10s %8s ign@: %12s ", + buf.append(String.format("[in: %28s][fcid %10s][mid %10s][ %8s ign@: %12s]", mount.getDebugName(), fcid.toShortKey(), + mid.toDebug(), toMotorDescription(), toIgnitionDescription() )); return buf.toString(); } - + } diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationId.java b/core/src/net/sf/openrocket/motor/MotorConfigurationId.java index d77d5467e..dc9c69362 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationId.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationId.java @@ -33,10 +33,9 @@ public final class MotorConfigurationId { throw new NullPointerException("Provided FlightConfigurationId was null"); } - // Use intern so comparison can be done using == instead of equals() - final long upper = ((long)_mount.getID().hashCode()) << 32; - final long lower = _fcid.key.getLeastSignificantBits(); - this.key = new UUID( upper, lower); + final long mountHash= ((long)_mount.getID().hashCode()) << 32; + final long fcidLower = _fcid.key.getMostSignificantBits(); + this.key = new UUID( mountHash, fcidLower); } @Override @@ -56,6 +55,10 @@ public final class MotorConfigurationId { return key.hashCode(); } + public String toDebug(){ + return toShortKey(); + } + @Override public String toString(){ if( this.key == MotorConfigurationId.ERROR_KEY){ @@ -64,4 +67,13 @@ public final class MotorConfigurationId { return key.toString(); } } + + public String toShortKey() { + final String keyString = key.toString(); + final int lastIndex = -1 + keyString.length(); + final int chunkLen = 4; + + // return the head + tail of the full 64-character id + return (keyString.substring(0,chunkLen)+"/"+keyString.substring(lastIndex - chunkLen,lastIndex)); + } } diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java index 16bf1cf2e..c986f06cb 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java @@ -4,7 +4,6 @@ import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.RocketComponent; /** * FlightConfigurationSet for motors. @@ -24,8 +23,15 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet configSet, RocketComponent component) { - super(configSet); + public MotorConfigurationSet(FlightConfigurableParameterSet sourceSet, final MotorMount newMount) { + // creates a new empty config w/ default value + super( new MotorConfiguration( newMount, FlightConfigurationId.DEFAULT_VALUE_FCID )); + + for( MotorConfiguration sourceConfig : sourceSet ){ + FlightConfigurationId nextFCID = sourceConfig.getFCID(); + MotorConfiguration nextValue = new MotorConfiguration( newMount, nextFCID, sourceConfig); + set( nextFCID, nextValue ); + } } @Override @@ -42,10 +48,18 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet getComponentBounds() { diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index b1f976b6d..734a96a4b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -92,7 +92,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial return outerRadius; } - /** * Set the outer radius of the body tube. If the radius is less than the wall thickness, * the wall thickness is decreased accordingly of the value of the radius. @@ -395,6 +394,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial public Iterator getMotorIterator(){ return this.motors.iterator(); } + + @Override + public void reset( final FlightConfigurationId fcid){ + this.motors.reset(fcid); + } @Override public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java index 53434956f..187f276a2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java @@ -16,4 +16,11 @@ public interface FlightConfigurableComponent { */ void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId); + /** + * Reset a specific flight configuration ID to use the default parameter value. + * + * @param fcid the flight configuration ID + */ + void reset( final FlightConfigurationId fcid); + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index a8d48be8e..135f84c10 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -371,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter iterator = this.iterator(); + while (iterator.hasNext()) { + RocketComponent comp = iterator.next(); + + if (comp instanceof FlightConfigurableComponent){ + FlightConfigurableComponent confbl = (FlightConfigurableComponent)comp; + confbl.reset( fcid); + } + } + // Get current configuration: this.configSet.reset( fcid); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index ddae1784b..8f3521489 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -29,9 +29,10 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.Pair; + +@SuppressWarnings("serial") public abstract class FlightConfigurablePanel extends JPanel { - private static final long serialVersionUID = 3359871704879603700L; protected static final Translator trans = Application.getTranslator(); private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class); protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); @@ -160,7 +161,6 @@ public abstract class FlightConfigurablePanel if ( (null == fcid )||( null == curMount )){ return; } - - //MotorInstance curInstance = curMount.getMotorInstance( fcid ); - // curInstance may be empty here... - //String mountName = ((RocketComponent)curMount).getName(); - //System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey()); - + + if( fcid.equals( FlightConfigurationId.DEFAULT_VALUE_FCID)){ + throw new IllegalStateException("Attempting to set a motor on the default FCID."); + } + motorChooserDialog.setMotorMountAndConfig( fcid, curMount ); motorChooserDialog.setVisible(true); - Motor mtr = motorChooserDialog.getSelectedMotor(); + Motor mtr = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); if (mtr != null) { - MotorConfiguration curConfig = curMount.getMotorConfig(fcid); - curConfig.setMotor(mtr); - curConfig.setEjectionDelay(d); - curConfig.setIgnitionEvent( IgnitionEvent.NEVER); - curMount.setMotorConfig( curConfig, fcid); + final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid); + final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig); + newConfig.setMotor(mtr); + newConfig.setEjectionDelay(d); + curMount.setMotorConfig( newConfig, fcid); } fireTableDataChanged();