[Bugfix] Fixing Configuration Editing UI

- Default Parameter in FlightConfigurationSet<T> 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
This commit is contained in:
Daniel_M_Williams 2015-10-15 11:33:33 -04:00
parent b3c1c5fac1
commit 55acf6cebf
23 changed files with 320 additions and 212 deletions

View File

@ -51,7 +51,7 @@ class IgnitionConfigurationHandler extends AbstractElementHandler {
if (element.equals("ignitionevent")) { if (element.equals("ignitionevent")) {
for (IgnitionEvent ie : IgnitionEvent.events) { for (IgnitionEvent ie : IgnitionEvent.values()) {
if (ie.equals(content)) { if (ie.equals(content)) {
ignitionEvent = ie; ignitionEvent = ie;
break; break;

View File

@ -61,7 +61,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
} }
if ("true".equals(attributes.remove("default"))) { if ("true".equals(attributes.remove("default"))) {
rocket.getConfigurationSet().resetDefault(fcid); rocket.getConfigurationSet().reset(fcid);
} }
super.closeElement(element, attributes, content, warnings); super.closeElement(element, attributes, content, warnings);

View File

@ -15,6 +15,8 @@ import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
class MotorMountHandler extends AbstractElementHandler { class MotorMountHandler extends AbstractElementHandler {
private final DocumentLoadingContext context; private final DocumentLoadingContext context;
@ -57,6 +59,7 @@ class MotorMountHandler extends AbstractElementHandler {
@Override @Override
public void closeElement(String element, HashMap<String, String> attributes, public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException { String content, WarningSet warnings) throws SAXException {
// DEBUG ONLY // DEBUG ONLY
// System.err.println("closing MotorMount element: "+ element); // System.err.println("closing MotorMount element: "+ element);
@ -72,20 +75,32 @@ class MotorMountHandler extends AbstractElementHandler {
MotorInstance motorInstance = motor.getNewInstance(); MotorInstance motorInstance = motor.getNewInstance();
motorInstance.setEjectionDelay(motorHandler.getDelay(warnings)); motorInstance.setEjectionDelay(motorHandler.getDelay(warnings));
mount.setMotorInstance(fcid, motorInstance); mount.setMotorInstance(fcid, motorInstance);
Rocket rkt = ((RocketComponent)mount).getRocket();
rkt.createFlightConfiguration(fcid);
// // vvvvvvv DEBUG vvvvvvv // // vvvvvvv DEBUG vvvvvvv
// System.err.println(" processing <motor> element:"+fcid.key); // if( mount instanceof BodyTube ){
// System.err.println(" processing <"+element+"> element with mount: "+((RocketComponent)mount).getName()+" with content: "+content);
// MotorInstance justSet = mount.getMotorInstance(fcid); // MotorInstance justSet = mount.getMotorInstance(fcid);
// System.err.println(" just set Motor: "+motor.getDesignation()+" to Mount: "+((RocketComponent)mount).getName()+"."); // String shortKey = fcid.key.substring(0,8);
// String motorKey = justSet.getMotorID().toString().substring(0,8);
// String contains; // String contains;
// if( justSet.isEmpty()){ // if( justSet.isEmpty()){
// contains = "empty"; // contains = "empty";
// }else{ // }else{
// contains = justSet.getMotor().getDesignation(); // contains = justSet.getMotor().getDesignation();
// } // }
// System.err.println(" to Motor: "+justSet.getMotorID()+ " containing: "+contains); // System.err.println(" set( key:"+ shortKey + " to Motor: "+motorKey+ " containing: "+contains);
// System.err.println(" mount now contains "+mount.getMotorCount()+" motors."); //
// // ... well, we know it's at least 2 configurations now.... // // exhaustive part...
//
// ((BodyTube)mount).printMotorDebug( fcid );
//
// rkt.getConfigurationSet().printDebug();
// }
// // ^^^^^^^ DEBUG ^^^^^^^^ // // ^^^^^^^ DEBUG ^^^^^^^^
return; return;
} }
@ -106,7 +121,7 @@ class MotorMountHandler extends AbstractElementHandler {
if (element.equals("ignitionevent")) { if (element.equals("ignitionevent")) {
IgnitionEvent event = null; IgnitionEvent event = null;
for (IgnitionEvent ie : IgnitionEvent.events) { for (IgnitionEvent ie : IgnitionEvent.values()) {
if (ie.equals(content)) { if (ie.equals(content)) {
event = ie; event = ie;
break; break;

View File

@ -38,6 +38,9 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
protected MotorInstance() { protected MotorInstance() {
this.id = MotorInstanceId.EMPTY_ID; this.id = MotorInstanceId.EMPTY_ID;
ejectionDelay = 0.0;
ignitionEvent = IgnitionEvent.NEVER;
ignitionDelay = 0.0;
modID++; modID++;
} }

View File

@ -12,10 +12,10 @@ public final class MotorInstanceId {
private final String componentId; private final String componentId;
private final int number; 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; private final static int ERROR_NUMBER = -1;
public final static MotorInstanceId ERROR_ID = new MotorInstanceId(); 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; private final static int EMPTY_NUMBER = 1;
public final static MotorInstanceId EMPTY_ID = new MotorInstanceId(EMPTY_COMPONENT_TEXT, EMPTY_NUMBER); public final static MotorInstanceId EMPTY_ID = new MotorInstanceId(EMPTY_COMPONENT_TEXT, EMPTY_NUMBER);
@ -71,6 +71,12 @@ public final class MotorInstanceId {
@Override @Override
public String toString(){ public String toString(){
if( this == ERROR_ID){
return "ERROR_ID";
}else if( this == EMPTY_ID){
return "EMPTY_ID";
}else{
return Integer.toString( this.hashCode()); return Integer.toString( this.hashCode());
} }
}
} }

View File

@ -462,7 +462,9 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang()); return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang());
} }
public void printMotorDebug(){
this.motors.printDebug();
}
@Override @Override
protected RocketComponent copyWithOriginalID() { protected RocketComponent copyWithOriginalID() {

View File

@ -1,5 +1,7 @@
package net.sf.openrocket.rocketcomponent; package net.sf.openrocket.rocketcomponent;
import java.util.List;
import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.ChangeSource;
/** /**
@ -60,6 +62,11 @@ public interface FlightConfigurable<E extends ChangeSource> extends FlightConfig
*/ */
public void set(FlightConfigurationID id, E value); public void set(FlightConfigurationID id, E value);
/**
*
* @return a sorted list of all the contained FlightConfigurationIDs
*/
public List<FlightConfigurationID> getSortedConfigurationIDs();
/** /**
* Return whether a specific flight configuration ID is using the * Return whether a specific flight configuration ID is using the
@ -75,7 +82,7 @@ public interface FlightConfigurable<E extends ChangeSource> extends FlightConfig
* *
* @param id the flight configuration ID * @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. * Return the number of specific flight configurations other than the default.

View File

@ -63,7 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
private int modID = 0; private int modID = 0;
public FlightConfiguration( ){ public FlightConfiguration( ){
this.fcid = FlightConfigurationID.ERROR_CONFIGURATION_ID; this.fcid = FlightConfigurationID.ERROR_CONFIGURATION_FCID;
this.rocket = new Rocket(); this.rocket = new Rocket();
this.configurationName = "<ERROR: FlightConfiguration created without an id or rocket instance. ERROR!> "; this.configurationName = "<ERROR: FlightConfiguration created without an id or rocket instance. ERROR!> ";
} }
@ -194,22 +194,29 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
log.error( "Detected inactive component in list returned from <config>.getActiveComponents()"); log.error( "Detected inactive component in list returned from <config>.getActiveComponents()");
} }
// DEVEL // DEVEL
// see planning notes... // see planning notes...
if ( comp instanceof MotorMount ){ if ( comp instanceof MotorMount ){
MotorMount mount = (MotorMount)comp; MotorMount mount = (MotorMount)comp;
//if( mount.isActive() ){ MotorInstance inst = mount.getMotorInstance(this.fcid);
// if( mount instanceof Clusterable ){ // if( mount instanceof Clusterable ){
// if( 1 < comp.getInstanceCount() ){ // if( 1 < comp.getInstanceCount() ){
// if comp is clustered, it will be clustered from the innerTube, no? // if comp is clustered, it will be clustered from the innerTube, no?
//List<MotorInstance> instanceList = mount.getMotorInstance(this.fcid); //List<MotorInstance> instanceList = mount.getMotorInstance(this.fcid);
MotorInstance inst = mount.getMotorInstance(this.fcid); // // vvvv DEVEL vvvv
if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){ //
// DEVEL // if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){
log.error("Detected 'Empty' Motor Instance on Activated MotorMount: "+this.getName()+" / "+comp.getName()+" / (#)"); // if( mount instanceof BodyTube){
continue; // 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 // motors go inactive after burnout, so we
if (inst.isActive()){ if (inst.isActive()){
@ -457,7 +464,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return; return;
}else if( "".equals(newName)){ }else if( "".equals(newName)){
return; return;
}else if( this.getFlightConfigurationID().equals( FlightConfigurationID.DEFAULT_CONFIGURATION_ID)){ }else if( this.getFlightConfigurationID().equals( FlightConfigurationID.DEFAULT_CONFIGURATION_FCID)){
this.configurationName = FlightConfiguration.DEFAULT_CONFIGURATION_NAME; this.configurationName = FlightConfiguration.DEFAULT_CONFIGURATION_NAME;
return; return;
}else if( ! this.getFlightConfigurationID().isValid()){ }else if( ! this.getFlightConfigurationID().isValid()){

View File

@ -10,11 +10,13 @@ import java.util.UUID;
public final class FlightConfigurationID implements Comparable<FlightConfigurationID> { public final class FlightConfigurationID implements Comparable<FlightConfigurationID> {
final public String key; final public String key;
private final static String ERROR_CONFIGURATION_KEY = "j567uryk2489yfjbr8i1fi"; private final static String ERROR_CONFIGURATION_KEYTEXT = "j567uryk2489yfjbr8i1fi";
private final static String DEFAULT_CONFIGURATION_KEY = "default_configuration_662002"; 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 ERROR_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT);
public final static FlightConfigurationID DEFAULT_CONFIGURATION_ID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEY ); 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() { public FlightConfigurationID() {
this(UUID.randomUUID().toString()); this(UUID.randomUUID().toString());
@ -22,9 +24,9 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
public FlightConfigurationID(final String _val) { public FlightConfigurationID(final String _val) {
if (null == _val){ if (null == _val){
this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY; this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT;
}else if (5 >_val.length()){ }else if (5 >_val.length()){
this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY; this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT;
} else { } else {
// vv temp vv // vv temp vv
String temp_val = _val; String temp_val = _val;
@ -60,7 +62,7 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
} }
public boolean isValid() { public boolean isValid() {
if (this.key.intern() == FlightConfigurationID.ERROR_CONFIGURATION_KEY) { if (this.key.intern() == FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT) {
return false; return false;
} }
@ -71,6 +73,15 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
return this.key.length(); return this.key.length();
} }
public String toShortKey(){
if( this == DEFAULT_VALUE_FCID ){
return "DEFVAL";
}else if( this == FlightConfigurationID.DEFAULT_CONFIGURATION_FCID){
return "DEFCONFIG";
}
return this.key.substring(0,8);
}
@Override @Override
public String toString() { public String toString() {
return this.key; return this.key;

View File

@ -3,8 +3,10 @@ package net.sf.openrocket.rocketcomponent;
import java.util.EventObject; import java.util.EventObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.Vector;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,11 +23,11 @@ import net.sf.openrocket.util.Utils;
public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> { public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> {
private static final Logger log = LoggerFactory.getLogger(FlightConfigurationSet.class); private static final Logger log = LoggerFactory.getLogger(FlightConfigurationSet.class);
private final HashMap<FlightConfigurationID, E> map = new HashMap<FlightConfigurationID, E>(); protected final HashMap<FlightConfigurationID, E> map = new HashMap<FlightConfigurationID, E>();
private E defaultValue = null; protected final static FlightConfigurationID DEFAULT_VALUE_FCID = FlightConfigurationID.DEFAULT_VALUE_FCID;
private final RocketComponent component; protected final RocketComponent component;
private final int eventType; protected final int eventType;
private final Listener listener = new Listener(); private final Listener listener = new Listener();
@ -40,13 +42,9 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
this.component = component; this.component = component;
this.eventType = eventType; this.eventType = eventType;
this.defaultValue = _defaultValue; this.map.put( DEFAULT_VALUE_FCID, _defaultValue );
if ( null == defaultValue ) {
throw new NullPointerException("defaultValue is null");
}
this.map.put( FlightConfigurationID.DEFAULT_CONFIGURATION_ID, defaultValue );
add(defaultValue); addListener(_defaultValue);
} }
@ -60,7 +58,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
this.component = component; this.component = component;
this.eventType = eventType; this.eventType = eventType;
this.defaultValue = flightConfiguration.defaultValue.clone(); this.map.put( DEFAULT_VALUE_FCID, flightConfiguration.getDefault().clone());
for (FlightConfigurationID key : flightConfiguration.map.keySet()) { for (FlightConfigurationID key : flightConfiguration.map.keySet()) {
this.map.put(key, flightConfiguration.map.get(key).clone()); this.map.put(key, flightConfiguration.map.get(key).clone());
} }
@ -72,21 +70,18 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
@Override @Override
public E getDefault(){ public E getDefault(){
return defaultValue; return this.map.get(DEFAULT_VALUE_FCID);
} }
@Override @Override
public void setDefault(E value) { public void setDefault(E nextDefaultValue) {
if (value == null) { if (nextDefaultValue == null) {
throw new NullPointerException("value is null"); throw new NullPointerException("new Default Value is null");
} }
if( this.isDefault(value)){ if( this.isDefault(nextDefaultValue)){
return; return;
} }
remove(this.defaultValue); this.set( DEFAULT_VALUE_FCID, nextDefaultValue);
this.defaultValue = value;
add(value);
fireEvent();
} }
@Override @Override
@ -123,11 +118,21 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
if (map.containsKey(id)) { if (map.containsKey(id)) {
toReturn = map.get(id); toReturn = map.get(id);
} else { } else {
toReturn = defaultValue; toReturn = this.getDefault();
} }
return toReturn; return toReturn;
} }
@Override
public List<FlightConfigurationID> getSortedConfigurationIDs(){
Vector<FlightConfigurationID> toReturn = new Vector<FlightConfigurationID>();
toReturn.addAll( this.getIDs() );
toReturn.sort( null );
return toReturn;
}
public Set<FlightConfigurationID> getIDs(){ public Set<FlightConfigurationID> getIDs(){
return this.map.keySet(); return this.map.keySet();
} }
@ -136,56 +141,45 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
public void set(FlightConfigurationID fcid, E nextValue) { public void set(FlightConfigurationID fcid, E nextValue) {
if (null == fcid) { if (null == fcid) {
throw new NullPointerException("id is null"); 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 // 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{ }else{
E previousValue = map.put(fcid, nextValue); E previousValue = map.put(fcid, nextValue);
remove(previousValue); removeListener(previousValue);
if (previousValue == this.defaultValue) { addListener(nextValue);
this.defaultValue = nextValue;
}
add(nextValue);
} }
fireEvent(); fireEvent();
} }
public boolean isDefault(E _value) { public boolean isDefault(E testVal) {
return (Utils.equals(this.defaultValue, _value)); return (Utils.equals( this.getDefault(), testVal));
} }
@Override @Override
public boolean isDefault(FlightConfigurationID id) { public boolean isDefault( FlightConfigurationID fcid) {
return (this.defaultValue == map.get(id)); return (getDefault() == map.get(fcid));
} }
@Override @Override
public void resetDefault(FlightConfigurationID id) { public void reset( FlightConfigurationID fcid) {
if( null == id){ // enforce at least one value in the set
this.resetDefault(); if( 1 < this.map.size() ){
}else if( !id.isValid()){ set( fcid, null);
throw new IllegalStateException(" Attempt to reset the default value on with an invalid key: "+id.toString()); }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() { private void fireEvent() {
@ -195,34 +189,19 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
@Override @Override
public void cloneFlightConfiguration(FlightConfigurationID oldConfigId, FlightConfigurationID newConfigId) { public void cloneFlightConfiguration(FlightConfigurationID oldConfigId, FlightConfigurationID newConfigId) {
if (isDefault(oldConfigId)) { // clones the ENTRIES for the given fcid's.
this.resetDefault(newConfigId); E oldValue = this.get(oldConfigId);
} else { this.set(newConfigId, oldValue.clone());
E original = this.get(oldConfigId); fireEvent();
this.set(newConfigId, original.clone());
}
} }
private void add(E value) { private void addListener(E value) {
if (value != null) { if (value != null) {
value.addChangeListener(listener); value.addChangeListener(listener);
} }
} }
public void remove(FlightConfigurationID fcid) { private void removeListener(E value) {
// 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) {
if (value != null) { if (value != null) {
value.removeChangeListener(listener); value.removeChangeListener(listener);
} }
@ -236,4 +215,28 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> 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);
}
}
} }

View File

@ -6,35 +6,29 @@ import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
public class IgnitionEvent { public enum IgnitionEvent {
private static final Translator trans = Application.getTranslator(); //// Automatic (launch or ejection charge)
public final String name; AUTOMATIC( "AUTOMATIC", "MotorMount.IgnitionEvent.AUTOMATIC"){
private final String key;
protected String description=null;
public static final IgnitionEvent AUTOMATIC = new IgnitionEvent( "AUTOMATIC", "MotorMount.IgnitionEvent.AUTOMATIC"){
@Override @Override
public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
int count = source.getRocket().getStageCount(); int count = source.getRocket().getStageCount();
int stage = source.getStageNumber(); int stage = source.getStageNumber();
if (stage == count - 1) { if (stage == count - 1) {
return LAUNCH.isActivationEvent( fe, source); return LAUNCH.isActivationEvent(e, source);
} else { } else {
return EJECTION_CHARGE.isActivationEvent( fe, source); return EJECTION_CHARGE.isActivationEvent(e, source);
} }
} }
}; },
LAUNCH ( "LAUNCH", "MotorMount.IgnitionEvent.LAUNCH"){
public static final IgnitionEvent LAUNCH = new IgnitionEvent( "LAUNCH", "MotorMount.IgnitionEvent.LAUNCH"){
@Override @Override
public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ public boolean isActivationEvent( FlightEvent fe, RocketComponent source){
return (fe.getType() == FlightEvent.Type.LAUNCH); return (fe.getType() == FlightEvent.Type.LAUNCH);
} }
}; },
EJECTION_CHARGE ("EJECTION_CHARGE", "MotorMount.IgnitionEvent.EJECTION_CHARGE"){
public static final IgnitionEvent EJECTION_CHARGE= new IgnitionEvent("EJECTION_CHARGE", "MotorMount.IgnitionEvent.EJECTION_CHARGE"){
@Override @Override
public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ public boolean isActivationEvent( FlightEvent fe, RocketComponent source){
if (fe.getType() != FlightEvent.Type.EJECTION_CHARGE){ if (fe.getType() != FlightEvent.Type.EJECTION_CHARGE){
@ -44,9 +38,8 @@ public class IgnitionEvent {
int mount = source.getStageNumber(); int mount = source.getStageNumber();
return (mount + 1 == charge); return (mount + 1 == charge);
} }
}; },
BURNOUT ("BURNOUT", "MotorMount.IgnitionEvent.BURNOUT"){
public static final IgnitionEvent BURNOUT = new IgnitionEvent("BURNOUT", "MotorMount.IgnitionEvent.BURNOUT"){
@Override @Override
public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ public boolean isActivationEvent( FlightEvent fe, RocketComponent source){
if (fe.getType() != FlightEvent.Type.BURNOUT) if (fe.getType() != FlightEvent.Type.BURNOUT)
@ -56,30 +49,33 @@ public class IgnitionEvent {
int mount = source.getStageNumber(); int mount = source.getStageNumber();
return (mount + 1 == charge); return (mount + 1 == charge);
} }
}; },
NEVER("NEVER", "MotorMount.IgnitionEvent.NEVER")
;
public static final IgnitionEvent NEVER= new IgnitionEvent("NEVER", "MotorMount.IgnitionEvent.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 static final IgnitionEvent[] events = {AUTOMATIC, LAUNCH, EJECTION_CHARGE, BURNOUT, NEVER};
public boolean isActivationEvent( FlightEvent fe, RocketComponent source){ public boolean isActivationEvent( FlightEvent fe, RocketComponent source){
// default behavior. Also for the NEVER case. // default behavior. Also for the NEVER case.
return false; return false;
} }
public IgnitionEvent(final String _name, final String _key) { private IgnitionEvent(final String _name, final String _key) {
this.name = _name; this.name = _name;
this.key = _key; this.key = _key;
this.description = trans.get(this.key);
} }
public boolean equals( final String content){ public boolean equals( final String content){
String comparator = this.name.toLowerCase(Locale.ENGLISH).replaceAll("_", ""); String comparator = this.name.toLowerCase(Locale.ENGLISH).replaceAll("_", "");
return comparator.equals(content); return comparator.equals(content);
} }
public String name(){ public String getName(){
return this.name; return this.name;
} }

View File

@ -33,7 +33,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
private double overhang = 0; private double overhang = 0;
private boolean isActing; private boolean isActing;
private FlightConfigurationSet<MotorInstance> motors; private MotorConfigurationSet motors;
/** /**
* Main constructor. * Main constructor.
@ -248,7 +248,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
@Override @Override
public boolean isDefaultMotorInstance( final MotorInstance testInstance){ public boolean isDefaultMotorInstance( final MotorInstance testInstance){
return this.motors.getDefault() == testInstance; return this.motors.isDefault( testInstance);
} }
@Override @Override
@ -343,7 +343,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
@Override @Override
protected RocketComponent copyWithOriginalID() { protected RocketComponent copyWithOriginalID() {
InnerTube copy = (InnerTube) super.copyWithOriginalID(); InnerTube copy = (InnerTube) super.copyWithOriginalID();
copy.motors = new FlightConfigurationSet<MotorInstance>(motors, copy, ComponentChangeEvent.MOTOR_CHANGE); copy.motors = new MotorConfigurationSet(motors, copy, ComponentChangeEvent.MOTOR_CHANGE);
return copy; return copy;
} }
@ -368,6 +368,9 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
return copy; return copy;
} }
public void printMotorDebug( FlightConfigurationID fcid ){
this.motors.printDebug();
}
} }

View File

@ -27,8 +27,46 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
@Override @Override
public void setDefault(MotorInstance value) { public void setDefault( MotorInstance value) {
throw new UnsupportedOperationException("Cannot change default value of motor configuration"); 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);
// }
// }
} }

View File

@ -7,7 +7,6 @@ import java.util.HashMap;
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.Vector;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -68,7 +67,6 @@ public class Rocket extends RocketComponent {
// Flight configuration list // Flight configuration list
private FlightConfigurationSet<FlightConfiguration> configurations; private FlightConfigurationSet<FlightConfiguration> configurations;
private final Vector<FlightConfigurationID> ids = new Vector<FlightConfigurationID>();
// Does the rocket have a perfect finish (a notable amount of laminar flow) // Does the rocket have a perfect finish (a notable amount of laminar flow)
private boolean perfectFinish = false; private boolean perfectFinish = false;
@ -85,7 +83,7 @@ public class Rocket extends RocketComponent {
treeModID = modID; treeModID = modID;
functionalModID = modID; functionalModID = modID;
FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_ID; FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_FCID;
FlightConfiguration defaultConfiguration = new FlightConfiguration( defaultFCID, this); FlightConfiguration defaultConfiguration = new FlightConfiguration( defaultFCID, this);
this.configurations = new FlightConfigurationSet<FlightConfiguration>(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration); this.configurations = new FlightConfigurationSet<FlightConfiguration>(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration);
} }
@ -529,21 +527,8 @@ public class Rocket extends RocketComponent {
return this.configurations; return this.configurations;
} }
public FlightConfiguration getFlightConfig( final FlightConfigurationID fcid ){ public List<FlightConfigurationID> getSortedConfigurationIDs(){
checkState(); return configurations.getSortedConfigurationIDs();
return this.configurations.get(fcid);
}
public Vector<FlightConfigurationID> getSortedConfigurationIDs(){
// if the configuration list has changed, refresh it.
if( configurations.size() != ids.size()){
this.ids.clear();
//this.ids = new Vector<FlightConfigurationID>( idSet );
this.ids.addAll( this.configurations.getIDs() );
this.ids .sort( null );
}
return this.ids;
} }
@ -613,7 +598,7 @@ public class Rocket extends RocketComponent {
*/ */
public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) { public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) {
checkState(); checkState();
return configurations.get(id); return this.configurations.get(id);
} }

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.gui.adaptors;
import java.util.EventObject; import java.util.EventObject;
import java.util.List;
import java.util.Vector; import java.util.Vector;
import javax.swing.ComboBoxModel; import javax.swing.ComboBoxModel;
@ -29,7 +30,7 @@ public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurati
private FlightConfiguration config; private FlightConfiguration config;
private final Rocket rocket; private final Rocket rocket;
Vector<FlightConfigurationID> ids= new Vector<FlightConfigurationID>(); List<FlightConfigurationID> ids= new Vector<FlightConfigurationID>();
public FlightConfigurationModel(FlightConfiguration config) { public FlightConfigurationModel(FlightConfiguration config) {
this.config = config; this.config = config;
@ -43,9 +44,9 @@ public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurati
this.ids = rocket.getSortedConfigurationIDs(); this.ids = rocket.getSortedConfigurationIDs();
if (index < 0){ if (index < 0){
return FlightConfigurationID.ERROR_CONFIGURATION_ID; return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
}else if ( index >= this.ids.size()){ }else if ( index >= this.ids.size()){
return FlightConfigurationID.ERROR_CONFIGURATION_ID; return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
} }
return this.ids.get(index); return this.ids.get(index);

View File

@ -16,6 +16,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.BooleanModel; import net.sf.openrocket.gui.adaptors.BooleanModel;
import net.sf.openrocket.gui.adaptors.DoubleModel; 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.BasicSlider;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
@ -70,9 +71,9 @@ public class MotorConfig extends JPanel {
MotorInstance motorInstance = mount.getDefaultMotorInstance(); MotorInstance motorInstance = mount.getDefaultMotorInstance();
final EnumModel<IgnitionEvent> igEvModel = new EnumModel<IgnitionEvent>(motorMount, "IgnitionEvent", IgnitionEvent.values());
JComboBox<IgnitionEvent> combo = new JComboBox<IgnitionEvent>( IgnitionEvent.events ); final JComboBox<IgnitionEvent> eventBox = new JComboBox<IgnitionEvent>( igEvModel);
panel.add(combo, "growx, wrap"); panel.add(eventBox , "growx, wrap");
// ... and delay // ... and delay
//// plus //// plus

View File

@ -4,6 +4,7 @@ import java.awt.Dialog;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Iterator;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JButton; import javax.swing.JButton;
@ -15,14 +16,18 @@ import javax.swing.JRadioButton;
import javax.swing.JSpinner; import javax.swing.JSpinner;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel; 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.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount; 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.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
@ -31,31 +36,31 @@ public class IgnitionSelectionDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); 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 MotorMount curMount;
private MotorInstance destMotorInstance; private MotorInstance curMotorInstance;
private IgnitionEvent startIgnEvent; private IgnitionEvent startIgnitionEvent;
private double ignitionDelay; private double startIgnitionDelay;
public IgnitionSelectionDialog(Window parent, final FlightConfigurationID curFCID, MotorMount _mount) { public IgnitionSelectionDialog(Window parent, final FlightConfigurationID curFCID, MotorMount _mount) {
super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL); super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL);
curMount = _mount; curMount = _mount;
destMotorInstance = curMount.getMotorInstance(curFCID); curMotorInstance = curMount.getMotorInstance(curFCID);
startIgnEvent = destMotorInstance.getIgnitionEvent(); startIgnitionEvent = curMotorInstance.getIgnitionEvent();
ignitionDelay = destMotorInstance.getIgnitionDelay(); startIgnitionDelay = curMotorInstance.getIgnitionDelay();
final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance();
JPanel panel = new JPanel(new MigLayout("fill")); JPanel panel = new JPanel(new MigLayout("fill"));
// Edit default or override option // 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"); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel");
final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault);
panel.add(defaultButton, "span, gapleft para, wrap rel"); panel.add(defaultButton, "span, gapleft para, wrap rel");
String str = trans.get("IgnitionSelectionDialog.opt.override"); 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); final JRadioButton overrideButton = new JRadioButton(str, !isDefault);
panel.add(overrideButton, "span, gapleft para, wrap para"); panel.add(overrideButton, "span, gapleft para, wrap para");
@ -71,18 +76,16 @@ public class IgnitionSelectionDialog extends JDialog {
} }
// Select ignition event // Select ignition event
//// Ignition at:
panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), ""); panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), "");
final EnumModel<IgnitionEvent> igEvModel = new EnumModel<IgnitionEvent>(curMotorInstance, "IgnitionEvent", IgnitionEvent.values());
final JComboBox<IgnitionEvent> eventBox = new JComboBox<IgnitionEvent>(IgnitionEvent.events); final JComboBox<IgnitionEvent> eventBox = new JComboBox<IgnitionEvent>( igEvModel);
//eventBox.setTit
panel.add(eventBox, "growx, wrap"); panel.add(eventBox, "growx, wrap");
// ... and delay // ... and delay
//// plus //// plus
panel.add(new JLabel(trans.get("MotorCfg.lbl.plus")), "gap indent, skip 1, span, split"); 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()); JSpinner spin = new JSpinner(delay.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin, 3)); spin.setEditor(new SpinnerEditor(spin, 3));
panel.add(spin, "gap rel rel"); panel.add(spin, "gap rel rel");
@ -98,14 +101,29 @@ public class IgnitionSelectionDialog extends JDialog {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (defaultButton.isSelected()) { if (defaultButton.isSelected()) {
System.err.println("setting motor ignition to.... default values"); // change the default...
IgnitionEvent cie = curMotorInstance.getIgnitionEvent();
double cid = curMotorInstance.getIgnitionDelay();
destMotorInstance.setIgnitionDelay( defaultMotorInstance.getIgnitionDelay()); // and change all remaining configs?
destMotorInstance.setIgnitionEvent( defaultMotorInstance.getIgnitionEvent()); // this seems like odd behavior to me, but it matches the text on the UI dialog popup. -teyrana (equipoise@gmail.com)
} else { Iterator<MotorInstance> iter = curMount.getMotorIterator();
System.err.println("setting motor ignition to.... new values: "); while( iter.hasNext() ){
System.err.println(" "+destMotorInstance.getIgnitionEvent()+" w/ "+destMotorInstance.getIgnitionDelay()); 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());
}
// 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); IgnitionSelectionDialog.this.setVisible(false);
} }
}); });
@ -119,8 +137,8 @@ public class IgnitionSelectionDialog extends JDialog {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
IgnitionSelectionDialog.this.setVisible(false); IgnitionSelectionDialog.this.setVisible(false);
// if cancelled, reset to starting values // if cancelled, reset to starting values
destMotorInstance.setIgnitionEvent( startIgnEvent ); curMotorInstance.setIgnitionEvent( startIgnitionEvent );
destMotorInstance.setIgnitionDelay( ignitionDelay ); curMotorInstance.setIgnitionDelay( startIgnitionDelay );
} }
}); });

View File

@ -4,7 +4,6 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Font; import java.awt.Font;
import java.util.EventObject; import java.util.EventObject;
import java.util.Vector;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -78,7 +77,8 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
if ( col < 0 ) { if ( col < 0 ) {
col = (table.getColumnCount() > 1) ? 1 : 0; col = (table.getColumnCount() > 1) ? 1 : 0;
} }
Vector<FlightConfigurationID> ids = rocket.getSortedConfigurationIDs();
java.util.List<FlightConfigurationID> ids = rocket.getSortedConfigurationIDs();
for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) { for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) {
FlightConfigurationID rowFCID = ids.get(rowNum ); FlightConfigurationID rowFCID = ids.get(rowNum );
if ( rowFCID.equals(selectedFCID) ) { if ( rowFCID.equals(selectedFCID) ) {
@ -163,7 +163,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
// this really should be un-implemented. // this really should be un-implemented.
//return new FlightConfigurationID((String) tableValue); //return new FlightConfigurationID((String) tableValue);
} }
return FlightConfigurationID.ERROR_CONFIGURATION_ID; return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
} }
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer { protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {

View File

@ -26,7 +26,7 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
protected final Rocket rocket; protected final Rocket rocket;
protected final Class<T> clazz; protected final Class<T> clazz;
private final List<T> components = new ArrayList<T>(); private final List<T> components = new ArrayList<T>();
private Vector<FlightConfigurationID> ids = new Vector<FlightConfigurationID>(); private List<FlightConfigurationID> ids = new Vector<FlightConfigurationID>();
public FlightConfigurableTableModel(Class<T> clazz, Rocket rocket) { public FlightConfigurableTableModel(Class<T> clazz, Rocket rocket) {
super(); super();
@ -66,7 +66,8 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
@Override @Override
public int getRowCount() { public int getRowCount() {
return rocket.getConfigurationSet().size(); // the -1 removes the DEFAULT_VALUE row, which is hidden.
return (rocket.getConfigurationCount()-1);
} }
@Override @Override
@ -106,8 +107,9 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
} }
private FlightConfigurationID getConfigurationID(int rowNum) { private FlightConfigurationID getConfigurationID(int rowNum) {
if( rocket.getConfigurationCount() != ids.size()){ if( rocket.getConfigurationCount() != (1+ ids.size() ) ){
this.ids = rocket.getSortedConfigurationIDs(); this.ids = rocket.getSortedConfigurationIDs();
this.ids.remove(FlightConfigurationID.DEFAULT_VALUE_FCID);
} }
return this.ids.get(rowNum); return this.ids.get(rowNum);

View File

@ -127,6 +127,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
FlightConfiguration newConfig = new FlightConfiguration( newFCID, rocket ); FlightConfiguration newConfig = new FlightConfiguration( newFCID, rocket );
rocket.setFlightConfiguration(newFCID, newConfig); rocket.setFlightConfiguration(newFCID, newConfig);
//System.err.println("Adding new config: "+newFCID.key+" called: "+newConfig.getName()+" (sz: "+newConfig?+")");
// Create a new simulation for this configuration. // Create a new simulation for this configuration.
createSimulationForNewConfiguration(); createSimulationForNewConfiguration();
@ -139,14 +140,14 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
FlightConfiguration newConfig = oldConfig.clone(); FlightConfiguration newConfig = oldConfig.clone();
FlightConfigurationID oldId = oldConfig.getFlightConfigurationID(); FlightConfigurationID oldId = oldConfig.getFlightConfigurationID();
FlightConfigurationID newId = newConfig.getFlightConfigurationID(); FlightConfigurationID newId = newConfig.getFlightConfigurationID();
String oldName = oldConfig.getName();
for (RocketComponent c : rocket) { for (RocketComponent c : rocket) {
if (c instanceof FlightConfigurableComponent) { if (c instanceof FlightConfigurableComponent) {
((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId); ((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId);
} }
} }
newConfig.setName( oldName+"2"); newConfig.setName( newId.key );
rocket.setFlightConfiguration(newId, newConfig);
// Create a new simulation for this configuration. // Create a new simulation for this configuration.
createSimulationForNewConfiguration(); createSimulationForNewConfiguration();

View File

@ -280,8 +280,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) { protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) {
JLabel label = new JLabel(); JLabel label = new JLabel();
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS)); label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
MotorInstance curMotor = mount.getMotorInstance( configId); MotorInstance curMotor = mount.getMotorInstance( configId);
String motorString = getMotorSpecification( curMotor ); 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); JLabel motorDescriptionLabel = new JLabel(motorString);
label.add(motorDescriptionLabel); label.add(motorDescriptionLabel);
label.add( Box.createRigidArea(new Dimension(10,0))); label.add( Box.createRigidArea(new Dimension(10,0)));

View File

@ -103,7 +103,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
return; return;
} }
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID();
c.getDeploymentConfigurations().resetDefault(id); c.getDeploymentConfigurations().reset(id);
fireTableDataChanged(); fireTableDataChanged();
} }

View File

@ -107,8 +107,11 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
if (stage == null) { if (stage == null) {
return; return;
} }
// why?
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID();
stage.getSeparationConfigurations().resetDefault(id); stage.getSeparationConfigurations().reset(id);
fireTableDataChanged(); fireTableDataChanged();
} }
public void updateButtonState() { public void updateButtonState() {