From 55acf6cebf902a621f2e8666769176eb02c93496 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Thu, 15 Oct 2015 11:33:33 -0400 Subject: [PATCH] [Bugfix] Fixing Configuration Editing UI - Default Parameter in FlightConfigurationSet is now totally separate from those listed in the map. - note: the default option =/= the option for the default FlightConfiguration ... - defaultValue is now included in the map, with a dedicated static final key. - defaultValue may only be replaced, not removed. - "Select Ignition" button now functions correctly - "Reset Ignition" button functions correctly --- .../importt/IgnitionConfigurationHandler.java | 2 +- .../importt/MotorConfigurationHandler.java | 2 +- .../openrocket/importt/MotorMountHandler.java | 39 +++-- .../sf/openrocket/motor/MotorInstance.java | 3 + .../sf/openrocket/motor/MotorInstanceId.java | 12 +- .../openrocket/rocketcomponent/BodyTube.java | 6 +- .../rocketcomponent/FlightConfigurable.java | 9 +- .../rocketcomponent/FlightConfiguration.java | 29 ++-- .../FlightConfigurationID.java | 25 ++- .../FlightConfigurationSet.java | 159 +++++++++--------- .../rocketcomponent/IgnitionEvent.java | 56 +++--- .../openrocket/rocketcomponent/InnerTube.java | 9 +- .../MotorConfigurationSet.java | 40 ++++- .../sf/openrocket/rocketcomponent/Rocket.java | 23 +-- .../adaptors/FlightConfigurationModel.java | 7 +- .../gui/configdialog/MotorConfig.java | 7 +- .../IgnitionSelectionDialog.java | 68 +++++--- .../FlightConfigurablePanel.java | 6 +- .../FlightConfigurableTableModel.java | 8 +- .../FlightConfigurationPanel.java | 7 +- .../MotorConfigurationPanel.java | 6 + .../RecoveryConfigurationPanel.java | 2 +- .../SeparationConfigurationPanel.java | 7 +- 23 files changed, 320 insertions(+), 212 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/IgnitionConfigurationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/IgnitionConfigurationHandler.java index 605782c27..f0317ac0a 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/IgnitionConfigurationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/IgnitionConfigurationHandler.java @@ -51,7 +51,7 @@ class IgnitionConfigurationHandler extends AbstractElementHandler { if (element.equals("ignitionevent")) { - for (IgnitionEvent ie : IgnitionEvent.events) { + for (IgnitionEvent ie : IgnitionEvent.values()) { if (ie.equals(content)) { ignitionEvent = ie; break; diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java index 7e03194fa..6e6127e15 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java @@ -61,7 +61,7 @@ class MotorConfigurationHandler extends AbstractElementHandler { } if ("true".equals(attributes.remove("default"))) { - rocket.getConfigurationSet().resetDefault(fcid); + rocket.getConfigurationSet().reset(fcid); } super.closeElement(element, attributes, content, warnings); diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java index 1a7681ca6..dc5cb869c 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java @@ -15,6 +15,8 @@ import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.rocketcomponent.RocketComponent; class MotorMountHandler extends AbstractElementHandler { private final DocumentLoadingContext context; @@ -57,6 +59,7 @@ class MotorMountHandler extends AbstractElementHandler { @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { + // DEBUG ONLY // System.err.println("closing MotorMount element: "+ element); @@ -72,20 +75,32 @@ class MotorMountHandler extends AbstractElementHandler { MotorInstance motorInstance = motor.getNewInstance(); motorInstance.setEjectionDelay(motorHandler.getDelay(warnings)); mount.setMotorInstance(fcid, motorInstance); + + Rocket rkt = ((RocketComponent)mount).getRocket(); + rkt.createFlightConfiguration(fcid); + // // vvvvvvv DEBUG vvvvvvv -// System.err.println(" processing element:"+fcid.key); -// MotorInstance justSet = mount.getMotorInstance(fcid); -// System.err.println(" just set Motor: "+motor.getDesignation()+" to Mount: "+((RocketComponent)mount).getName()+"."); -// String contains; -// if( justSet.isEmpty()){ -// contains = "empty"; -// }else{ -// contains = justSet.getMotor().getDesignation(); +// if( mount instanceof BodyTube ){ +// System.err.println(" processing <"+element+"> element with mount: "+((RocketComponent)mount).getName()+" with content: "+content); +// MotorInstance justSet = mount.getMotorInstance(fcid); +// String shortKey = fcid.key.substring(0,8); +// String motorKey = justSet.getMotorID().toString().substring(0,8); +// String contains; +// if( justSet.isEmpty()){ +// contains = "empty"; +// }else{ +// contains = justSet.getMotor().getDesignation(); +// } +// System.err.println(" set( key:"+ shortKey + " to Motor: "+motorKey+ " containing: "+contains); +// +// // exhaustive part... +// +// ((BodyTube)mount).printMotorDebug( fcid ); +// +// rkt.getConfigurationSet().printDebug(); // } -// System.err.println(" to Motor: "+justSet.getMotorID()+ " containing: "+contains); -// System.err.println(" mount now contains "+mount.getMotorCount()+" motors."); -// // ... well, we know it's at least 2 configurations now.... // // ^^^^^^^ DEBUG ^^^^^^^^ + return; } @@ -106,7 +121,7 @@ class MotorMountHandler extends AbstractElementHandler { if (element.equals("ignitionevent")) { IgnitionEvent event = null; - for (IgnitionEvent ie : IgnitionEvent.events) { + for (IgnitionEvent ie : IgnitionEvent.values()) { if (ie.equals(content)) { event = ie; break; diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index 33e0ef854..86678195d 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -38,6 +38,9 @@ public class MotorInstance implements FlightConfigurableParameter protected MotorInstance() { this.id = MotorInstanceId.EMPTY_ID; + ejectionDelay = 0.0; + ignitionEvent = IgnitionEvent.NEVER; + ignitionDelay = 0.0; modID++; } diff --git a/core/src/net/sf/openrocket/motor/MotorInstanceId.java b/core/src/net/sf/openrocket/motor/MotorInstanceId.java index dda00fa54..33b7a196b 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstanceId.java +++ b/core/src/net/sf/openrocket/motor/MotorInstanceId.java @@ -12,10 +12,10 @@ public final class MotorInstanceId { private final String componentId; private final int number; - private final static String COMPONENT_ERROR_TEXT = "Error Motor Instance"; + private final static String COMPONENT_ERROR_TEXT = "Error Motor Id"; private final static int ERROR_NUMBER = -1; public final static MotorInstanceId ERROR_ID = new MotorInstanceId(); - private final static String EMPTY_COMPONENT_TEXT = "Empty Motor Instance"; + private final static String EMPTY_COMPONENT_TEXT = "Empty Motor Id"; private final static int EMPTY_NUMBER = 1; public final static MotorInstanceId EMPTY_ID = new MotorInstanceId(EMPTY_COMPONENT_TEXT, EMPTY_NUMBER); @@ -71,6 +71,12 @@ public final class MotorInstanceId { @Override public String toString(){ - return Integer.toString( this.hashCode()); + if( this == ERROR_ID){ + return "ERROR_ID"; + }else if( this == EMPTY_ID){ + return "EMPTY_ID"; + }else{ + return Integer.toString( this.hashCode()); + } } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 9412c7de8..caad76f59 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -461,8 +461,10 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang()); } - - + + public void printMotorDebug(){ + this.motors.printDebug(); + } @Override protected RocketComponent copyWithOriginalID() { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java index a0349d071..e670432a1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java @@ -1,5 +1,7 @@ package net.sf.openrocket.rocketcomponent; +import java.util.List; + import net.sf.openrocket.util.ChangeSource; /** @@ -60,6 +62,11 @@ public interface FlightConfigurable extends FlightConfig */ public void set(FlightConfigurationID id, E value); + /** + * + * @return a sorted list of all the contained FlightConfigurationIDs + */ + public List getSortedConfigurationIDs(); /** * Return whether a specific flight configuration ID is using the @@ -75,7 +82,7 @@ public interface FlightConfigurable extends FlightConfig * * @param id the flight configuration ID */ - public void resetDefault(FlightConfigurationID id); + public void reset(FlightConfigurationID id); /** * Return the number of specific flight configurations other than the default. diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index e796be135..71c3d6d36 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -63,7 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter.getActiveComponents()"); } // DEVEL + // see planning notes... if ( comp instanceof MotorMount ){ MotorMount mount = (MotorMount)comp; - //if( mount.isActive() ){ - + MotorInstance inst = mount.getMotorInstance(this.fcid); + // if( mount instanceof Clusterable ){ // if( 1 < comp.getInstanceCount() ){ // if comp is clustered, it will be clustered from the innerTube, no? //List instanceList = mount.getMotorInstance(this.fcid); - - MotorInstance inst = mount.getMotorInstance(this.fcid); - if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){ - // DEVEL - log.error("Detected 'Empty' Motor Instance on Activated MotorMount: "+this.getName()+" / "+comp.getName()+" / (#)"); - continue; - } + +// // vvvv DEVEL vvvv +// +// if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){ +// if( mount instanceof BodyTube){ +// MotorInstance bt_inst = ((BodyTube)mount).getMotorInstance(this.fcid); +// log.error("Detected EMPTY_INSTANCE in config: "+this.fcid.key.substring(0,8)+", mount: \""+comp.getName()+"\""); +// ((BodyTube)mount).printMotorDebug(); +// } +// continue; +// } +// // ^^^^ DEVEL ^^^^ + // motors go inactive after burnout, so we if (inst.isActive()){ @@ -457,7 +464,7 @@ public class FlightConfiguration implements FlightConfigurableParameter { final public String key; - private final static String ERROR_CONFIGURATION_KEY = "j567uryk2489yfjbr8i1fi"; - private final static String DEFAULT_CONFIGURATION_KEY = "default_configuration_662002"; + private final static String ERROR_CONFIGURATION_KEYTEXT = "j567uryk2489yfjbr8i1fi"; + private final static String DEFAULT_CONFIGURATION_KEYTEXT = "default_configuration_662002"; + private final static String DEFAULT_VALUE_KEYTEXT = "default_value_567866"; - public final static FlightConfigurationID ERROR_CONFIGURATION_ID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEY); - public final static FlightConfigurationID DEFAULT_CONFIGURATION_ID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEY ); + public final static FlightConfigurationID ERROR_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT); + public final static FlightConfigurationID DEFAULT_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEYTEXT ); + public final static FlightConfigurationID DEFAULT_VALUE_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_VALUE_KEYTEXT ); public FlightConfigurationID() { this(UUID.randomUUID().toString()); @@ -22,9 +24,9 @@ public final class FlightConfigurationID implements Comparable_val.length()){ - this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY; + this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT; } else { // vv temp vv String temp_val = _val; @@ -60,7 +62,7 @@ public final class FlightConfigurationID implements Comparable> implements FlightConfigurable { private static final Logger log = LoggerFactory.getLogger(FlightConfigurationSet.class); - private final HashMap map = new HashMap(); - private E defaultValue = null; + protected final HashMap map = new HashMap(); + protected final static FlightConfigurationID DEFAULT_VALUE_FCID = FlightConfigurationID.DEFAULT_VALUE_FCID; - private final RocketComponent component; - private final int eventType; + protected final RocketComponent component; + protected final int eventType; private final Listener listener = new Listener(); @@ -40,13 +42,9 @@ public class FlightConfigurationSet> im this.component = component; this.eventType = eventType; - this.defaultValue = _defaultValue; - if ( null == defaultValue ) { - throw new NullPointerException("defaultValue is null"); - } - this.map.put( FlightConfigurationID.DEFAULT_CONFIGURATION_ID, defaultValue ); + this.map.put( DEFAULT_VALUE_FCID, _defaultValue ); - add(defaultValue); + addListener(_defaultValue); } @@ -60,7 +58,7 @@ public class FlightConfigurationSet> im this.component = component; this.eventType = eventType; - this.defaultValue = flightConfiguration.defaultValue.clone(); + this.map.put( DEFAULT_VALUE_FCID, flightConfiguration.getDefault().clone()); for (FlightConfigurationID key : flightConfiguration.map.keySet()) { this.map.put(key, flightConfiguration.map.get(key).clone()); } @@ -72,21 +70,18 @@ public class FlightConfigurationSet> im @Override public E getDefault(){ - return defaultValue; + return this.map.get(DEFAULT_VALUE_FCID); } - + @Override - public void setDefault(E value) { - if (value == null) { - throw new NullPointerException("value is null"); + public void setDefault(E nextDefaultValue) { + if (nextDefaultValue == null) { + throw new NullPointerException("new Default Value is null"); } - if( this.isDefault(value)){ + if( this.isDefault(nextDefaultValue)){ return; } - remove(this.defaultValue); - this.defaultValue = value; - add(value); - fireEvent(); + this.set( DEFAULT_VALUE_FCID, nextDefaultValue); } @Override @@ -123,11 +118,21 @@ public class FlightConfigurationSet> im if (map.containsKey(id)) { toReturn = map.get(id); } else { - toReturn = defaultValue; + toReturn = this.getDefault(); } return toReturn; } + @Override + public List getSortedConfigurationIDs(){ + Vector toReturn = new Vector(); + + toReturn.addAll( this.getIDs() ); + toReturn.sort( null ); + + return toReturn; + } + public Set getIDs(){ return this.map.keySet(); } @@ -136,93 +141,67 @@ public class FlightConfigurationSet> im public void set(FlightConfigurationID fcid, E nextValue) { if (null == fcid) { throw new NullPointerException("id is null"); + }else if( !fcid.isValid()){ + throw new IllegalStateException(" Attempt to reset the default value on with an invalid key: "+fcid.toString()); } - if (nextValue == null) { + if ( nextValue == null) { // null value means to delete this fcid - this.remove(fcid); + if ( DEFAULT_VALUE_FCID == fcid ) { + // NEVER delete the default value.... + return; + } + + E previousValue = map.remove(fcid); + removeListener(previousValue); }else{ E previousValue = map.put(fcid, nextValue); - remove(previousValue); - if (previousValue == this.defaultValue) { - this.defaultValue = nextValue; - } - add(nextValue); + removeListener(previousValue); + addListener(nextValue); } fireEvent(); } - public boolean isDefault(E _value) { - return (Utils.equals(this.defaultValue, _value)); + public boolean isDefault(E testVal) { + return (Utils.equals( this.getDefault(), testVal)); } @Override - public boolean isDefault(FlightConfigurationID id) { - return (this.defaultValue == map.get(id)); + public boolean isDefault( FlightConfigurationID fcid) { + return (getDefault() == map.get(fcid)); } @Override - public void resetDefault(FlightConfigurationID id) { - if( null == id){ - this.resetDefault(); - }else if( !id.isValid()){ - throw new IllegalStateException(" Attempt to reset the default value on with an invalid key: "+id.toString()); + public void reset( FlightConfigurationID fcid) { + // enforce at least one value in the set + if( 1 < this.map.size() ){ + set( fcid, null); + }else{ + log.warn(" attempted to remove last element from the FlightConfigurationSet<"+this.getDefault().getClass().getSimpleName()+"> attached to: "+component.getName()+". Ignoring. "); + return; } - - E previous = map.get(id); - remove(previous); - - if ( previous == this.defaultValue ) { - this.defaultValue = null; - resetDefault(); - } - fireEvent(); - } - - private void resetDefault(){ - if( 0 == this.map.keySet().size()){ - throw new IllegalStateException(" Attempt to reset the default value on an empty configurationSet."); - } - - FlightConfigurationID firstFCID = map.keySet().iterator().next(); - this.defaultValue = map.get( firstFCID); } private void fireEvent() { component.fireComponentChangeEvent(eventType); } - + @Override public void cloneFlightConfiguration(FlightConfigurationID oldConfigId, FlightConfigurationID newConfigId) { - if (isDefault(oldConfigId)) { - this.resetDefault(newConfigId); - } else { - E original = this.get(oldConfigId); - this.set(newConfigId, original.clone()); - } + // clones the ENTRIES for the given fcid's. + E oldValue = this.get(oldConfigId); + this.set(newConfigId, oldValue.clone()); + fireEvent(); } - private void add(E value) { + private void addListener(E value) { if (value != null) { value.addChangeListener(listener); } } - public void remove(FlightConfigurationID fcid) { - // enforce at least one value in the set - if( 1 < this.map.size() ){ - this.map.remove(fcid); - if( this.isDefault(fcid)){ - this.defaultValue = map.values().iterator().next(); - } - }else{ - log.warn(" attempted to remove last element from the FlightConfigurationSet<"+this.defaultValue.getClass().getSimpleName()+">. Action not allowed. "); - return; - } - } - - private void remove(E value) { + private void removeListener(E value) { if (value != null) { value.removeChangeListener(listener); } @@ -236,4 +215,28 @@ public class FlightConfigurationSet> im } } + public void printDebug(){ + System.err.println("====== Dumping ConfigurationSet for comp: '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======"); + System.err.println(" >> FlightConfigurationSet ("+this.size()+ " configurations)"); + + for( FlightConfigurationID loopFCID : this.map.keySet()){ + String shortKey = loopFCID.toShortKey(); + + + E inst = this.map.get(loopFCID); + if( this.isDefault(inst)){ + shortKey = "*"+shortKey+"*"; + } + String designation; + if( inst instanceof FlightConfiguration){ + FlightConfiguration fc = (FlightConfiguration) inst; + designation = fc.getName(); + }else{ + designation = inst.toString(); + } + System.err.println(" >> ["+shortKey+"]= "+designation); + } + + } + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/IgnitionEvent.java b/core/src/net/sf/openrocket/rocketcomponent/IgnitionEvent.java index c8ff4efe8..e4e9c3f10 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/IgnitionEvent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/IgnitionEvent.java @@ -6,35 +6,29 @@ import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.startup.Application; -public class IgnitionEvent { +public enum IgnitionEvent { - private static final Translator trans = Application.getTranslator(); - public final String name; - private final String key; - protected String description=null; - - public static final IgnitionEvent AUTOMATIC = new IgnitionEvent( "AUTOMATIC", "MotorMount.IgnitionEvent.AUTOMATIC"){ + //// Automatic (launch or ejection charge) + AUTOMATIC( "AUTOMATIC", "MotorMount.IgnitionEvent.AUTOMATIC"){ @Override - public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { int count = source.getRocket().getStageCount(); int stage = source.getStageNumber(); if (stage == count - 1) { - return LAUNCH.isActivationEvent( fe, source); - } else { - return EJECTION_CHARGE.isActivationEvent( fe, source); - } - } - }; - - public static final IgnitionEvent LAUNCH = new IgnitionEvent( "LAUNCH", "MotorMount.IgnitionEvent.LAUNCH"){ + return LAUNCH.isActivationEvent(e, source); + } else { + return EJECTION_CHARGE.isActivationEvent(e, source); + } + } + }, + LAUNCH ( "LAUNCH", "MotorMount.IgnitionEvent.LAUNCH"){ @Override public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ return (fe.getType() == FlightEvent.Type.LAUNCH); } - }; - - public static final IgnitionEvent EJECTION_CHARGE= new IgnitionEvent("EJECTION_CHARGE", "MotorMount.IgnitionEvent.EJECTION_CHARGE"){ + }, + EJECTION_CHARGE ("EJECTION_CHARGE", "MotorMount.IgnitionEvent.EJECTION_CHARGE"){ @Override public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ if (fe.getType() != FlightEvent.Type.EJECTION_CHARGE){ @@ -44,9 +38,8 @@ public class IgnitionEvent { int mount = source.getStageNumber(); return (mount + 1 == charge); } - }; - - public static final IgnitionEvent BURNOUT = new IgnitionEvent("BURNOUT", "MotorMount.IgnitionEvent.BURNOUT"){ + }, + BURNOUT ("BURNOUT", "MotorMount.IgnitionEvent.BURNOUT"){ @Override public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ if (fe.getType() != FlightEvent.Type.BURNOUT) @@ -56,30 +49,33 @@ public class IgnitionEvent { int mount = source.getStageNumber(); return (mount + 1 == charge); } - }; - - public static final IgnitionEvent NEVER= new IgnitionEvent("NEVER", "MotorMount.IgnitionEvent.NEVER"); + }, + NEVER("NEVER", "MotorMount.IgnitionEvent.NEVER") + ; - public static final IgnitionEvent[] events = {AUTOMATIC, LAUNCH, EJECTION_CHARGE, BURNOUT, NEVER}; + private static final Translator trans = Application.getTranslator(); + public final String name; + private final String key; + protected String description=null; + + //public static final IgnitionEvent[] events = {AUTOMATIC, LAUNCH, EJECTION_CHARGE, BURNOUT, NEVER}; public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ // default behavior. Also for the NEVER case. return false; } - public IgnitionEvent(final String _name, final String _key) { + private IgnitionEvent(final String _name, final String _key) { this.name = _name; this.key = _key; - this.description = trans.get(this.key); } public boolean equals( final String content){ String comparator = this.name.toLowerCase(Locale.ENGLISH).replaceAll("_", ""); - return comparator.equals(content); } - public String name(){ + public String getName(){ return this.name; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 784b41537..feadc25e1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -33,7 +33,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra private double overhang = 0; private boolean isActing; - private FlightConfigurationSet motors; + private MotorConfigurationSet motors; /** * Main constructor. @@ -248,7 +248,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra @Override public boolean isDefaultMotorInstance( final MotorInstance testInstance){ - return this.motors.getDefault() == testInstance; + return this.motors.isDefault( testInstance); } @Override @@ -343,7 +343,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra @Override protected RocketComponent copyWithOriginalID() { InnerTube copy = (InnerTube) super.copyWithOriginalID(); - copy.motors = new FlightConfigurationSet(motors, copy, ComponentChangeEvent.MOTOR_CHANGE); + copy.motors = new MotorConfigurationSet(motors, copy, ComponentChangeEvent.MOTOR_CHANGE); return copy; } @@ -368,6 +368,9 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra return copy; } + public void printMotorDebug( FlightConfigurationID fcid ){ + this.motors.printDebug(); + } } \ No newline at end of file diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java b/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java index a7df5cdea..642e450c5 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java @@ -27,8 +27,46 @@ public class MotorConfigurationSet extends FlightConfigurationSet @Override - public void setDefault(MotorInstance value) { + public void setDefault( MotorInstance value) { throw new UnsupportedOperationException("Cannot change default value of motor configuration"); } + @Override + public void printDebug(){ + System.err.println("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======"); + System.err.println(" >> motorSet ("+this.size()+ " motors)"); + + for( FlightConfigurationID loopFCID : this.map.keySet()){ + String shortKey = loopFCID.toShortKey(); + + MotorInstance curInstance = this.map.get(loopFCID); + String designation; + if( MotorInstance.EMPTY_INSTANCE == curInstance){ + designation = "EMPTY_INSTANCE"; + }else{ + designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay()); + } + System.err.println(" >> ["+shortKey+"]= "+designation); + + } + } + +// public void printDebug(FlightConfigurationID curFCID){ +// if( this.map.containsKey(curFCID)){ +// // no-op +// }else{ +// String shortKey = curFCID.toShortKey(); +// MotorInstance curInstance= this.get(curFCID); +// +// String designation; +// if( MotorInstance.EMPTY_INSTANCE == curInstance){ +// designation = "EMPTY_INSTANCE"; +// }else{ +// designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay()); +// } +// System.err.println(" Queried FCID:"); +// System.err.println(" >> ["+shortKey+"]= "+designation); +// } +// } + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 10a7af932..c4662bff9 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Vector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +67,6 @@ public class Rocket extends RocketComponent { // Flight configuration list private FlightConfigurationSet configurations; - private final Vector ids = new Vector(); // Does the rocket have a perfect finish (a notable amount of laminar flow) private boolean perfectFinish = false; @@ -85,7 +83,7 @@ public class Rocket extends RocketComponent { treeModID = modID; functionalModID = modID; - FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_ID; + FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_FCID; FlightConfiguration defaultConfiguration = new FlightConfiguration( defaultFCID, this); this.configurations = new FlightConfigurationSet(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration); } @@ -528,22 +526,9 @@ public class Rocket extends RocketComponent { checkState(); return this.configurations; } - - public FlightConfiguration getFlightConfig( final FlightConfigurationID fcid ){ - checkState(); - return this.configurations.get(fcid); - } - public Vector getSortedConfigurationIDs(){ - // if the configuration list has changed, refresh it. - if( configurations.size() != ids.size()){ - this.ids.clear(); - //this.ids = new Vector( idSet ); - this.ids.addAll( this.configurations.getIDs() ); - this.ids .sort( null ); - } - - return this.ids; + public List getSortedConfigurationIDs(){ + return configurations.getSortedConfigurationIDs(); } @@ -613,7 +598,7 @@ public class Rocket extends RocketComponent { */ public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) { checkState(); - return configurations.get(id); + return this.configurations.get(id); } diff --git a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java index cb584ebc5..90b13b30f 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java @@ -2,6 +2,7 @@ package net.sf.openrocket.gui.adaptors; import java.util.EventObject; +import java.util.List; import java.util.Vector; import javax.swing.ComboBoxModel; @@ -29,7 +30,7 @@ public class FlightConfigurationModel implements ComboBoxModel ids= new Vector(); + List ids= new Vector(); public FlightConfigurationModel(FlightConfiguration config) { this.config = config; @@ -43,9 +44,9 @@ public class FlightConfigurationModel implements ComboBoxModel= this.ids.size()){ - return FlightConfigurationID.ERROR_CONFIGURATION_ID; + return FlightConfigurationID.ERROR_CONFIGURATION_FCID; } return this.ids.get(index); diff --git a/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java index 1a3f0c80c..27606c264 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java @@ -16,6 +16,7 @@ import net.miginfocom.swing.MigLayout; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.BooleanModel; import net.sf.openrocket.gui.adaptors.DoubleModel; +import net.sf.openrocket.gui.adaptors.EnumModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.UnitSelector; @@ -70,9 +71,9 @@ public class MotorConfig extends JPanel { MotorInstance motorInstance = mount.getDefaultMotorInstance(); - - JComboBox combo = new JComboBox( IgnitionEvent.events ); - panel.add(combo, "growx, wrap"); + final EnumModel igEvModel = new EnumModel(motorMount, "IgnitionEvent", IgnitionEvent.values()); + final JComboBox eventBox = new JComboBox( igEvModel); + panel.add(eventBox , "growx, wrap"); // ... and delay //// plus diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java index 24f987bb0..3361d7eae 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java @@ -4,6 +4,7 @@ import java.awt.Dialog; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Iterator; import javax.swing.ButtonGroup; import javax.swing.JButton; @@ -15,14 +16,18 @@ import javax.swing.JRadioButton; import javax.swing.JSpinner; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.DoubleModel; +import net.sf.openrocket.gui.adaptors.EnumModel; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; @@ -31,31 +36,31 @@ public class IgnitionSelectionDialog extends JDialog { private static final Translator trans = Application.getTranslator(); - //private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); + private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); private MotorMount curMount; - private MotorInstance destMotorInstance; + private MotorInstance curMotorInstance; - private IgnitionEvent startIgnEvent; - private double ignitionDelay; + private IgnitionEvent startIgnitionEvent; + private double startIgnitionDelay; public IgnitionSelectionDialog(Window parent, final FlightConfigurationID curFCID, MotorMount _mount) { super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL); curMount = _mount; - destMotorInstance = curMount.getMotorInstance(curFCID); - startIgnEvent = destMotorInstance.getIgnitionEvent(); - ignitionDelay = destMotorInstance.getIgnitionDelay(); - final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); - + curMotorInstance = curMount.getMotorInstance(curFCID); + startIgnitionEvent = curMotorInstance.getIgnitionEvent(); + startIgnitionDelay = curMotorInstance.getIgnitionDelay(); JPanel panel = new JPanel(new MigLayout("fill")); // Edit default or override option - boolean isDefault = curMount.isDefaultMotorInstance( destMotorInstance ); + boolean isDefault = curMount.isDefaultMotorInstance( curMotorInstance ); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel"); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); panel.add(defaultButton, "span, gapleft para, wrap rel"); String str = trans.get("IgnitionSelectionDialog.opt.override"); - //str = str.replace("{0}", descriptor.format(rocket, id)); + Rocket rkt = ((RocketComponent)_mount).getRocket(); + str = str.replace("{0}", descriptor.format(rkt, curFCID)); + final JRadioButton overrideButton = new JRadioButton(str, !isDefault); panel.add(overrideButton, "span, gapleft para, wrap para"); @@ -71,18 +76,16 @@ public class IgnitionSelectionDialog extends JDialog { } // Select ignition event - //// Ignition at: panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), ""); - - final JComboBox eventBox = new JComboBox(IgnitionEvent.events); - //eventBox.setTit + final EnumModel igEvModel = new EnumModel(curMotorInstance, "IgnitionEvent", IgnitionEvent.values()); + final JComboBox eventBox = new JComboBox( igEvModel); panel.add(eventBox, "growx, wrap"); - // ... and delay + // ... and delay //// plus panel.add(new JLabel(trans.get("MotorCfg.lbl.plus")), "gap indent, skip 1, span, split"); - DoubleModel delay = new DoubleModel(destMotorInstance, "IgnitionDelay", UnitGroup.UNITS_SHORT_TIME, 0); + DoubleModel delay = new DoubleModel(curMotorInstance, "IgnitionDelay", UnitGroup.UNITS_SHORT_TIME, 0); JSpinner spin = new JSpinner(delay.getSpinnerModel()); spin.setEditor(new SpinnerEditor(spin, 3)); panel.add(spin, "gap rel rel"); @@ -98,14 +101,29 @@ public class IgnitionSelectionDialog extends JDialog { public void actionPerformed(ActionEvent e) { if (defaultButton.isSelected()) { - System.err.println("setting motor ignition to.... default values"); + // change the default... + IgnitionEvent cie = curMotorInstance.getIgnitionEvent(); + double cid = curMotorInstance.getIgnitionDelay(); + + // and change all remaining configs? + // this seems like odd behavior to me, but it matches the text on the UI dialog popup. -teyrana (equipoise@gmail.com) + Iterator iter = curMount.getMotorIterator(); + while( iter.hasNext() ){ + MotorInstance next = iter.next(); + next.setIgnitionDelay( cid); + next.setIgnitionEvent( cie); + } + + final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); + System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: "); + System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent()+" w/delay: "+defaultMotorInstance.getIgnitionDelay()); - destMotorInstance.setIgnitionDelay( defaultMotorInstance.getIgnitionDelay()); - destMotorInstance.setIgnitionEvent( defaultMotorInstance.getIgnitionEvent()); - } else { - System.err.println("setting motor ignition to.... new values: "); - System.err.println(" "+destMotorInstance.getIgnitionEvent()+" w/ "+destMotorInstance.getIgnitionDelay()); } +// else { +// System.err.println("setting motor ignition to.... new values: "); +// //destMotorInstance.setIgnitionEvent((IgnitionEvent)eventBox.getSelectedItem()); +// System.err.println(" "+curMotorInstance.getIgnitionEvent()+" w/ "+curMotorInstance.getIgnitionDelay()); +// } IgnitionSelectionDialog.this.setVisible(false); } }); @@ -119,8 +137,8 @@ public class IgnitionSelectionDialog extends JDialog { public void actionPerformed(ActionEvent e) { IgnitionSelectionDialog.this.setVisible(false); // if cancelled, reset to starting values - destMotorInstance.setIgnitionEvent( startIgnEvent ); - destMotorInstance.setIgnitionDelay( ignitionDelay ); + curMotorInstance.setIgnitionEvent( startIgnitionEvent ); + curMotorInstance.setIgnitionDelay( startIgnitionDelay ); } }); 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 7b5e54a37..2e7542218 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -4,7 +4,6 @@ import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.util.EventObject; -import java.util.Vector; import javax.swing.JComponent; import javax.swing.JLabel; @@ -78,7 +77,8 @@ public abstract class FlightConfigurablePanel 1) ? 1 : 0; } - Vector ids = rocket.getSortedConfigurationIDs(); + + java.util.List ids = rocket.getSortedConfigurationIDs(); for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) { FlightConfigurationID rowFCID = ids.get(rowNum ); if ( rowFCID.equals(selectedFCID) ) { @@ -163,7 +163,7 @@ public abstract class FlightConfigurablePanel protected final Rocket rocket; protected final Class clazz; private final List components = new ArrayList(); - private Vector ids = new Vector(); + private List ids = new Vector(); public FlightConfigurableTableModel(Class clazz, Rocket rocket) { super(); @@ -66,7 +66,8 @@ public class FlightConfigurableTableModel @Override public int getRowCount() { - return rocket.getConfigurationSet().size(); + // the -1 removes the DEFAULT_VALUE row, which is hidden. + return (rocket.getConfigurationCount()-1); } @Override @@ -106,8 +107,9 @@ public class FlightConfigurableTableModel } private FlightConfigurationID getConfigurationID(int rowNum) { - if( rocket.getConfigurationCount() != ids.size()){ + if( rocket.getConfigurationCount() != (1+ ids.size() ) ){ this.ids = rocket.getSortedConfigurationIDs(); + this.ids.remove(FlightConfigurationID.DEFAULT_VALUE_FCID); } return this.ids.get(rowNum); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java index 4958a3845..e22b3f60b 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -127,6 +127,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe FlightConfiguration newConfig = new FlightConfiguration( newFCID, rocket ); rocket.setFlightConfiguration(newFCID, newConfig); + //System.err.println("Adding new config: "+newFCID.key+" called: "+newConfig.getName()+" (sz: "+newConfig?+")"); // Create a new simulation for this configuration. createSimulationForNewConfiguration(); @@ -139,15 +140,15 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe FlightConfiguration newConfig = oldConfig.clone(); FlightConfigurationID oldId = oldConfig.getFlightConfigurationID(); FlightConfigurationID newId = newConfig.getFlightConfigurationID(); - String oldName = oldConfig.getName(); for (RocketComponent c : rocket) { if (c instanceof FlightConfigurableComponent) { ((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId); } } - newConfig.setName( oldName+"2"); - + newConfig.setName( newId.key ); + rocket.setFlightConfiguration(newId, newConfig); + // Create a new simulation for this configuration. createSimulationForNewConfiguration(); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 4b3b8e054..cb54ab8d5 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -280,8 +280,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) { JLabel label = new JLabel(); label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS)); + MotorInstance curMotor = mount.getMotorInstance( configId); String motorString = getMotorSpecification( curMotor ); +// if( mount instanceof BodyTube ){ +// System.err.println("Formatting Cell: fcid="+configId.key.substring(0, 8)); +// ((BodyTube) mount).printMotorDebug(); +// } + JLabel motorDescriptionLabel = new JLabel(motorString); label.add(motorDescriptionLabel); label.add( Box.createRigidArea(new Dimension(10,0))); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index b130caf18..08cd6a814 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -103,7 +103,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel