[Bugfix] Cleaning up FlightConfigurationID handling. Multiple Fixes.

-Fixed Motor Choosing UI Function
-Fixed Motor Remove UI Function
-Fixed UI display bug:  pass FlightConfigIDs instead of naked Strings.
-FlightConfigurationIDs now filter out keytext only. (spurious "key: " appended)
-Fixed extra de-select when navigating MotorSelection / FlightConfig selection tables
    - code no longer sets selected cell / config as the default item
This commit is contained in:
Daniel_M_Williams 2015-10-12 12:20:45 -04:00
parent 059c9cf0db
commit b3c1c5fac1
32 changed files with 362 additions and 211 deletions

View File

@ -502,7 +502,7 @@ public class OpenRocketSaver extends RocketSaver {
writeln("<conditions>"); writeln("<conditions>");
indent++; indent++;
writeElement("configid", cond.getConfigID()); writeElement("configid", cond.getConfigID().key);
writeElement("launchrodlength", cond.getLaunchRodLength()); writeElement("launchrodlength", cond.getLaunchRodLength());
writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI); writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI);
writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI)); writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI));

View File

@ -57,8 +57,11 @@ 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
// System.err.println("closing MotorMount element: "+ element);
if (element.equals("motor")) { if (element.equals("motor")) {
// yes, this is confirmed to be the FLIGHT config id, instead of the motor inastance id.
FlightConfigurationID fcid = new FlightConfigurationID(attributes.get("configid")); FlightConfigurationID fcid = new FlightConfigurationID(attributes.get("configid"));
if (!fcid.isValid()) { if (!fcid.isValid()) {
warnings.add(Warning.fromString("Illegal motor specification, ignoring.")); warnings.add(Warning.fromString("Illegal motor specification, ignoring."));
@ -69,6 +72,20 @@ 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);
// // vvvvvvv DEBUG vvvvvvv
// System.err.println(" processing <motor> 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();
// }
// 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; return;
} }

View File

@ -64,7 +64,7 @@ public class AxialStageSaver extends ComponentAssemblySaver {
} }
StageSeparationConfiguration separationConfig = stage.getSeparationConfigurations().get(fcid); StageSeparationConfiguration separationConfig = stage.getSeparationConfigurations().get(fcid);
elements.add("<separationconfiguration configid=\"" + fcid + "\">"); elements.add("<separationconfiguration configid=\"" + fcid.key + "\">");
elements.addAll(separationConfig(separationConfig, true)); elements.addAll(separationConfig(separationConfig, true));
elements.add("</separationconfiguration>"); elements.add("</separationconfiguration>");

View File

@ -47,7 +47,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
} }
DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid); DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid);
elements.add("<deploymentconfiguration configid=\"" + fcid + "\">"); elements.add("<deploymentconfiguration configid=\"" + fcid.key + "\">");
elements.addAll(deploymentConfiguration(deployConfig, true)); elements.addAll(deploymentConfiguration(deployConfig, true));
elements.add("</deploymentconfiguration>"); elements.add("</deploymentconfiguration>");
} }

View File

@ -164,13 +164,15 @@ public class RocketComponentSaver {
for (FlightConfiguration curConfig : configs) { for (FlightConfiguration curConfig : configs) {
FlightConfigurationID fcid = curConfig.getFlightConfigurationID(); FlightConfigurationID fcid = curConfig.getFlightConfigurationID();
MotorInstance motorInstance = mount.getMotorInstance(fcid);
Motor motor = motorInstance.getMotor();
// Nothing is stored if no motor loaded
if (motor == null)
continue;
elements.add(" <motor configid=\"" + fcid + "\">"); MotorInstance motorInstance = mount.getMotorInstance(fcid);
// Nothing is stored if no motor loaded
if( motorInstance.isEmpty()){
continue;
}
Motor motor = motorInstance.getMotor();
elements.add(" <motor configid=\"" + fcid.key + "\">");
if (motor.getMotorType() != Motor.Type.UNKNOWN) { if (motor.getMotorType() != Motor.Type.UNKNOWN) {
elements.add(" <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>"); elements.add(" <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>");
} }

View File

@ -48,7 +48,7 @@ public class RocketSaver extends RocketComponentSaver {
if (fcid == null) if (fcid == null)
continue; continue;
String str = "<motorconfiguration configid=\"" + fcid + "\""; String str = "<motorconfiguration configid=\"" + fcid.key + "\"";
if (fcid.equals(defId)) if (fcid.equals(defId))
str += " default=\"true\""; str += " default=\"true\"";

View File

@ -122,8 +122,8 @@ public class MassCalculator implements Monitorable {
if (motors != null) { if (motors != null) {
for (MotorInstance inst : config.getActiveMotors()) { for (MotorInstance inst : config.getActiveMotors()) {
// DEVEL // DEVEL
if(MotorInstanceId.EMPTY_ID == inst.getID()){ if(MotorInstanceId.EMPTY_ID == inst.getMotorID()){
throw new IllegalArgumentException(" detected empty motor"); throw new IllegalArgumentException(" detected empty motor from <FlightConfiguration>.getActiveMotors()");
} }
MotorMount mount = inst.getMount(); MotorMount mount = inst.getMount();
if( null == mount ){ if( null == mount ){

View File

@ -18,8 +18,9 @@ import net.sf.openrocket.util.StateChangeListener;
public class MotorInstance implements FlightConfigurableParameter<MotorInstance> { public class MotorInstance implements FlightConfigurableParameter<MotorInstance> {
protected MotorInstanceId id = null; protected MotorInstanceId id = null;
protected MotorMount mount = null; // deferred to subclasses
//protected Motor motor = null; // deferred to subclasses //protected MotorMount mount = null;
//protected Motor motor = null;
protected double ejectionDelay = 0.0; protected double ejectionDelay = 0.0;
protected double ignitionDelay = 0.0; protected double ignitionDelay = 0.0;
protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER; protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER;
@ -27,7 +28,7 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
protected double ignitionTime = 0.0; protected double ignitionTime = 0.0;
// comparison threshold // comparison threshold
private static final double EPSILON = 0.01; //private static final double EPSILON = 0.01;
protected int modID = 0; protected int modID = 0;
private final List<StateChangeListener> listeners = new ArrayList<StateChangeListener>(); private final List<StateChangeListener> listeners = new ArrayList<StateChangeListener>();
@ -40,7 +41,7 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
modID++; modID++;
} }
public MotorInstanceId getID() { public MotorInstanceId getMotorID() {
return this.id; return this.id;
} }
@ -65,11 +66,11 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
}; };
public MotorMount getMount() { public MotorMount getMount() {
return this.mount; throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance");
} }
public void setMount(final MotorMount _mount) { public void setMount(final MotorMount _mount) {
this.mount = _mount; throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance");
} }
public Coordinate getPosition() { public Coordinate getPosition() {
@ -165,7 +166,11 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
} }
public boolean isEmpty(){ public boolean isEmpty(){
return this == MotorInstance.EMPTY_INSTANCE; return true;
}
public boolean hasMotor(){
return ! this.isEmpty();
} }
@Override @Override
@ -176,19 +181,20 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
MotorInstance omi = (MotorInstance)other; MotorInstance omi = (MotorInstance)other;
if( this.id.equals( omi.id)){ if( this.id.equals( omi.id)){
return true; return true;
}else if( this.mount != omi.mount ){
return false;
}else if( this.ignitionEvent == omi.ignitionEvent ){
return false;
}else if( EPSILON < Math.abs(this.ignitionDelay - omi.ignitionDelay )){
return false;
}else if( EPSILON < Math.abs( this.ejectionDelay - omi.ejectionDelay )){
return false;
}else if( ! this.position.equals( omi.position )){
return false;
}else if( EPSILON < Math.abs( this.ignitionTime - omi.ignitionTime )){
return false;
} }
// }else if( this.mount != omi.mount ){
// return false;
// }else if( this.ignitionEvent == omi.ignitionEvent ){
// return false;
// }else if( EPSILON < Math.abs(this.ignitionDelay - omi.ignitionDelay )){
// return false;
// }else if( EPSILON < Math.abs( this.ejectionDelay - omi.ejectionDelay )){
// return false;
// }else if( ! this.position.equals( omi.position )){
// return false;
// }else if( EPSILON < Math.abs( this.ignitionTime - omi.ignitionTime )){
// return false;
// }
return true; return true;
} }

View File

@ -7,9 +7,6 @@ import java.util.Set;
import net.sf.openrocket.models.atmosphere.AtmosphericConditions; import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Monitorable; import net.sf.openrocket.util.Monitorable;
/** /**
@ -34,16 +31,16 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable<MotorInst
*/ */
public MotorInstanceConfiguration(FlightConfiguration configuration) { public MotorInstanceConfiguration(FlightConfiguration configuration) {
// motors == this // motors == this
final FlightConfigurationID fcid = configuration.getFlightConfigurationID(); // final FlightConfigurationID fcid = configuration.getFlightConfigurationID();
Iterator<RocketComponent> iterator = configuration.getRocket().iterator(false); // Iterator<RocketComponent> iterator = configuration.getRocket().iterator(false);
while (iterator.hasNext()) { // while (iterator.hasNext()) {
RocketComponent component = iterator.next(); // RocketComponent component = iterator.next();
if (component instanceof MotorMount) { // if (component instanceof MotorMount) {
MotorMount mount = (MotorMount) component; // MotorMount mount = (MotorMount) component;
//
// MotorInstance motorInst = mount.getMotorInstance(flightConfigId); // // MotorInstance motorInst = mount.getMotorInstance(flightConfigId);
// IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(flightConfigId); // // IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(flightConfigId);
// //
// Iterator<MotorInstance> iter = mount.getMotorIterator(); // Iterator<MotorInstance> iter = mount.getMotorIterator();
// //
@ -65,10 +62,9 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable<MotorInst
// MotorId curID = curMotorInstance.getID(); // MotorId curID = curMotorInstance.getID();
// motors.put(curID, curMotorInstance); // motors.put(curID, curMotorInstance);
// } // }
//
} // }
} // }
} }
@ -109,7 +105,7 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable<MotorInst
* @throws IllegalArgumentException if a motor with the specified ID already exists. * @throws IllegalArgumentException if a motor with the specified ID already exists.
*/ */
public void addMotor(MotorInstance motor) { public void addMotor(MotorInstance motor) {
MotorInstanceId id = motor.getID(); MotorInstanceId id = motor.getMotorID();
if (this.motors.containsKey(id)) { if (this.motors.containsKey(id)) {
throw new IllegalArgumentException("MotorInstanceConfiguration already " + throw new IllegalArgumentException("MotorInstanceConfiguration already " +
"contains a motor with id " + id); "contains a motor with id " + id);
@ -170,7 +166,7 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable<MotorInst
public MotorInstanceConfiguration clone() { public MotorInstanceConfiguration clone() {
MotorInstanceConfiguration clone = new MotorInstanceConfiguration(); MotorInstanceConfiguration clone = new MotorInstanceConfiguration();
for (MotorInstance motor : this.motors.values()) { for (MotorInstance motor : this.motors.values()) {
clone.motors.put(motor.getID(), motor.clone()); clone.motors.put(motor.getMotorID(), motor.clone());
} }
clone.modID = this.modID; clone.modID = this.modID;
return clone; return clone;

View File

@ -69,5 +69,8 @@ public final class MotorInstanceId {
return componentId.hashCode() + (number << 12); return componentId.hashCode() + (number << 12);
} }
// TODO: toString() @Override
public String toString(){
return Integer.toString( this.hashCode());
}
} }

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.motor; package net.sf.openrocket.motor;
import net.sf.openrocket.models.atmosphere.AtmosphericConditions; import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Inertia; import net.sf.openrocket.util.Inertia;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -11,6 +12,7 @@ public class ThrustCurveMotorInstance extends MotorInstance {
private int timeIndex = -1; private int timeIndex = -1;
protected MotorMount mount = null;
protected ThrustCurveMotor motor = null; protected ThrustCurveMotor motor = null;
// Previous time step value // Previous time step value
@ -100,6 +102,21 @@ public class ThrustCurveMotorInstance extends MotorInstance {
return this.motor; return this.motor;
} }
@Override
public boolean isEmpty(){
return false;
}
@Override
public MotorMount getMount() {
return this.mount;
}
@Override
public void setMount(final MotorMount _mount) {
this.mount = _mount;
}
@Override @Override
public void setEjectionDelay(double delay) { public void setEjectionDelay(double delay) {
if (MathUtil.equals(ejectionDelay, delay)) { if (MathUtil.equals(ejectionDelay, delay)) {

View File

@ -7,9 +7,9 @@ import java.util.Iterator;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -28,7 +28,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
// When changing the inner radius, thickness is modified // When changing the inner radius, thickness is modified
private double overhang = 0; private double overhang = 0;
private boolean isActing = false; private boolean isActingMount = false;
private MotorConfigurationSet motors; private MotorConfigurationSet motors;
@ -378,15 +378,25 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
@Override @Override
public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){
if( null == fcid){
throw new NullPointerException(" null FCID passed passed to 'setMotorInstance(...)': bug ");
}
if( null == newMotorInstance){
throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug ");
}
this.motors.set(fcid,newMotorInstance); this.motors.set(fcid,newMotorInstance);
if( null != newMotorInstance ){
if( newMotorInstance.isEmpty() ){
return;
}else if( null == newMotorInstance.getMount()){
newMotorInstance.setMount(this); newMotorInstance.setMount(this);
if( MotorInstanceId.EMPTY_ID != newMotorInstance.getID()){ }else if( !this.equals( newMotorInstance.getMount())){
this.setMotorMount(true); throw new BugException(" adding a MotorInstance to a mount that it isn't owned by... ");
}
} }
} }
@Override @Override
public Iterator<MotorInstance> getMotorIterator(){ public Iterator<MotorInstance> getMotorIterator(){
return this.motors.iterator(); return this.motors.iterator();
@ -399,15 +409,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
@Override @Override
public void setMotorMount(boolean _active){ public void setMotorMount(boolean _active){
if (this.isActing == _active) if (this.isActingMount == _active)
return; return;
this.isActing = _active; this.isActingMount = _active;
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
} }
@Override @Override
public boolean isMotorMount(){ public boolean isMotorMount(){
return this.isActing; return this.isActingMount;
} }
@Override @Override

View File

@ -26,8 +26,8 @@ public class ComponentChangeEvent extends EventObject {
/** A change to the 3D texture assigned to a component*/ /** A change to the 3D texture assigned to a component*/
public static final int TEXTURE_CHANGE = 128; public static final int TEXTURE_CHANGE = 128;
/** A bit-field that contains all possible change types. */ /** A bit-field that contains all possible change types. Will output as -1 */
public static final int ALL_CHANGE = 0xFFFFFFFF; public static final int ALL_CHANGE = 0xFFFFFFFF; // =-1; // because int is a signed type.
private final int type; private final int type;

View File

@ -41,6 +41,16 @@ public interface FlightConfigurable<E extends ChangeSource> extends FlightConfig
*/ */
public E get(FlightConfigurationID id); public E get(FlightConfigurationID id);
/**
* Return the parameter value for the provided flight configuration ID.
* This returns either the value specified for this flight config ID,
* or the default value.
*
* @param value the parameter to find
* @return the flight configuration ID
*/
public FlightConfigurationID get(E value);
/** /**
* Set the parameter value for the provided flight configuration ID. * Set the parameter value for the provided flight configuration ID.
* This sets the override for this flight configuration ID. * This sets the override for this flight configuration ID.

View File

@ -205,9 +205,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
//List<MotorInstance> instanceList = mount.getMotorInstance(this.fcid); //List<MotorInstance> instanceList = mount.getMotorInstance(this.fcid);
MotorInstance inst = mount.getMotorInstance(this.fcid); MotorInstance inst = mount.getMotorInstance(this.fcid);
if( MotorInstance.EMPTY_INSTANCE == inst){ if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){
// DEVEL // DEVEL
log.error("Detected 'Empty' Motor Instance in configuration: "+this.getName()+" / "+comp.getName()+" / (#)"); log.error("Detected 'Empty' Motor Instance on Activated MotorMount: "+this.getName()+" / "+comp.getName()+" / (#)");
continue; continue;
} }

View File

@ -26,7 +26,17 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
}else if (5 >_val.length()){ }else if (5 >_val.length()){
this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY; this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY;
} else { } else {
this.key = _val; // vv temp vv
String temp_val = _val;
final String extra = "key: ";
if( _val.contains(extra)){
int index = temp_val.lastIndexOf(extra);
temp_val = _val.substring(index+extra.length());
System.err.println(" correcting FCID from \""+_val+"\" to \""+temp_val+"\".");
}
// ^^ temp ^^
this.key = temp_val;
} }
} }
@ -63,7 +73,7 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
@Override @Override
public String toString() { public String toString() {
return ("key: "+this.key); return this.key;
} }
@Override @Override

View File

@ -3,6 +3,7 @@ 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.Map.Entry;
import java.util.Set; import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -99,6 +100,22 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
return map.size(); return map.size();
} }
@Override
public FlightConfigurationID get(E testValue) {
if( null == testValue ){
return null;
}
for( Entry<FlightConfigurationID, E> curEntry : this.map.entrySet()){
FlightConfigurationID curKey = curEntry.getKey();
E curValue = curEntry.getValue();
if( testValue.equals(curValue)){
return curKey;
}
}
return null;
}
@Override @Override
public E get(FlightConfigurationID id) { public E get(FlightConfigurationID id) {

View File

@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.BugException;
@ -259,12 +258,21 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
@Override @Override
public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){
this.motors.set(fcid,newMotorInstance); if( null == fcid){
if( null != newMotorInstance ){ throw new NullPointerException(" null FCID passed passed to 'setMotorInstance(...)': bug ");
newMotorInstance.setMount( this);
if( MotorInstanceId.EMPTY_ID != newMotorInstance.getID()){
this.setMotorMount(true);
} }
if( null == newMotorInstance){
throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug ");
}
this.motors.set(fcid,newMotorInstance);
if( newMotorInstance.isEmpty() ){
return;
}else if( null == newMotorInstance.getMount()){
newMotorInstance.setMount(this);
}else if( !this.equals( newMotorInstance.getMount())){
throw new BugException(" adding a MotorInstance to a mount that it isn't owned by... ");
} }
} }

View File

@ -401,6 +401,9 @@ public class Rocket extends RocketComponent {
return; return;
} }
if( -1 == e.getType()){
log.debug(">>fireComponentChangeEvent()>> . . .");
}
// Notify all components first // Notify all components first
Iterator<RocketComponent> iterator = this.iterator(true); Iterator<RocketComponent> iterator = this.iterator(true);
while (iterator.hasNext()) { while (iterator.hasNext()) {
@ -513,15 +516,24 @@ public class Rocket extends RocketComponent {
} }
this.setFlightConfiguration( fcid, nextConfig ); this.setFlightConfiguration( fcid, nextConfig );
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
return nextConfig; return nextConfig;
} }
public int getConfigurationCount(){
return this.configurations.size();
}
public FlightConfigurationSet<FlightConfiguration> getConfigurationSet(){ public FlightConfigurationSet<FlightConfiguration> getConfigurationSet(){
checkState(); checkState();
return this.configurations; return this.configurations;
} }
public FlightConfiguration getFlightConfig( final FlightConfigurationID fcid ){
checkState();
return this.configurations.get(fcid);
}
public Vector<FlightConfigurationID> getSortedConfigurationIDs(){ public Vector<FlightConfigurationID> getSortedConfigurationIDs(){
// if the configuration list has changed, refresh it. // if the configuration list has changed, refresh it.
if( configurations.size() != ids.size()){ if( configurations.size() != ids.size()){

View File

@ -448,7 +448,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
// Check whether any motor in the active stages is active anymore // Check whether any motor in the active stages is active anymore
List<MotorInstance> activeMotors = status.getConfiguration().getActiveMotors(); List<MotorInstance> activeMotors = status.getConfiguration().getActiveMotors();
for (MotorInstance curInstance : activeMotors) { for (MotorInstance curInstance : activeMotors) {
MotorInstanceId curID = curInstance.getID(); MotorInstanceId curID = curInstance.getMotorID();
RocketComponent comp = ((RocketComponent) curInstance.getMount()); RocketComponent comp = ((RocketComponent) curInstance.getMount());
int stage = comp.getStageNumber(); int stage = comp.getStageNumber();
if (!status.getConfiguration().isStageActive(stage)) if (!status.getConfiguration().isStageActive(stage))

View File

@ -28,7 +28,7 @@ import net.sf.openrocket.util.WorldCoordinate;
public class SimulationConditions implements Monitorable, Cloneable { public class SimulationConditions implements Monitorable, Cloneable {
private Rocket rocket; private Rocket rocket;
private FlightConfigurationID motorID = null; private FlightConfigurationID configID= null;
private Simulation simulation; // The parent simulation private Simulation simulation; // The parent simulation
@ -116,12 +116,11 @@ public class SimulationConditions implements Monitorable, Cloneable {
public FlightConfigurationID getMotorConfigurationID() { public FlightConfigurationID getMotorConfigurationID() {
return motorID; return configID;
} }
public void setFlightConfigurationID(FlightConfigurationID _fcid) {
public void setMotorConfigurationID(FlightConfigurationID motorID) { this.configID = _fcid;
this.motorID = motorID;
this.modID++; this.modID++;
} }

View File

@ -621,7 +621,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
SimulationConditions conditions = new SimulationConditions(); SimulationConditions conditions = new SimulationConditions();
conditions.setRocket((Rocket) getRocket().copy()); conditions.setRocket((Rocket) getRocket().copy());
conditions.setMotorConfigurationID(this.getConfigID()); conditions.setFlightConfigurationID(this.getConfigID());
conditions.setLaunchRodLength(getLaunchRodLength()); conditions.setLaunchRodLength(getLaunchRodLength());
conditions.setLaunchRodAngle(getLaunchRodAngle()); conditions.setLaunchRodAngle(getLaunchRodAngle());
conditions.setLaunchRodDirection(getLaunchRodDirection()); conditions.setLaunchRodDirection(getLaunchRodDirection());

View File

@ -72,10 +72,9 @@ public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurati
} }
FlightConfigurationID fcid= (FlightConfigurationID) item; FlightConfigurationID fcid= (FlightConfigurationID) item;
FlightConfigurationSet<FlightConfiguration> configs= rocket.getConfigurationSet(); FlightConfigurationSet<FlightConfiguration> configSet = rocket.getConfigurationSet();
configs.setDefault( configs.get(fcid)); this.config = configSet.get(fcid);
this.config = rocket.getDefaultConfiguration();
} }

View File

@ -15,7 +15,6 @@ 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.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
@ -24,35 +23,39 @@ 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.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
public class IgnitionSelectionDialog extends JDialog { public class IgnitionSelectionDialog extends JDialog {
private static final long serialVersionUID = -3399966098520607837L;
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 MotorInstance curMotor; private MotorMount curMount;
//private IgnitionConfiguration newConfiguration; private MotorInstance destMotorInstance;
public IgnitionSelectionDialog(Window parent, final Rocket rocket, final MotorMount component) { private IgnitionEvent startIgnEvent;
private double ignitionDelay;
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);
final FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); curMount = _mount;
destMotorInstance = curMount.getMotorInstance(curFCID);
curMotor = component.getMotorInstance(id); startIgnEvent = destMotorInstance.getIgnitionEvent();
MotorInstance defMotor = component.getDefaultMotorInstance(); ignitionDelay = destMotorInstance.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 = (defMotor.equals( curMotor)); boolean isDefault = curMount.isDefaultMotorInstance( destMotorInstance );
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)); //str = str.replace("{0}", descriptor.format(rocket, id));
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");
@ -79,7 +82,7 @@ public class IgnitionSelectionDialog extends JDialog {
//// 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(curMotor, "IgnitionDelay", UnitGroup.UNITS_SHORT_TIME, 0); DoubleModel delay = new DoubleModel(destMotorInstance, "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");
@ -93,12 +96,15 @@ public class IgnitionSelectionDialog extends JDialog {
okButton.addActionListener(new ActionListener() { okButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
MotorInstance defMotor = component.getDefaultMotorInstance();
if (defaultButton.isSelected()) { if (defaultButton.isSelected()) {
component.setMotorInstance(id, defMotor); System.err.println("setting motor ignition to.... default values");
destMotorInstance.setIgnitionDelay( defaultMotorInstance.getIgnitionDelay());
destMotorInstance.setIgnitionEvent( defaultMotorInstance.getIgnitionEvent());
} else { } else {
component.setMotorInstance(id, curMotor); System.err.println("setting motor ignition to.... new values: ");
System.err.println(" "+destMotorInstance.getIgnitionEvent()+" w/ "+destMotorInstance.getIgnitionDelay());
} }
IgnitionSelectionDialog.this.setVisible(false); IgnitionSelectionDialog.this.setVisible(false);
} }
@ -112,6 +118,9 @@ public class IgnitionSelectionDialog extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
IgnitionSelectionDialog.this.setVisible(false); IgnitionSelectionDialog.this.setVisible(false);
// if cancelled, reset to starting values
destMotorInstance.setIgnitionEvent( startIgnEvent );
destMotorInstance.setIgnitionDelay( ignitionDelay );
} }
}); });

View File

@ -23,7 +23,6 @@ import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent;
@ -94,9 +93,9 @@ public class SeparationSelectionDialog extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (defaultButton.isSelected()) { if (defaultButton.isSelected()) {
FlightConfigurationSet<StageSeparationConfiguration> sepConfigSet = component.getSeparationConfigurations(); // FlightConfigurationSet<StageSeparationConfiguration> sepConfigSet = component.getSeparationConfigurations();
StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID); // StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID);
component.getSeparationConfigurations().setDefault( sepConfig); // component.getSeparationConfigurations().setDefault( sepConfig);
// old version // old version
//component.getSeparationConfigurations().setDefault( fcid?, newConfiguration); //component.getSeparationConfigurations().setDefault( fcid?, newConfiguration);
} else { } else {

View File

@ -23,6 +23,8 @@ import net.sf.openrocket.startup.Application;
public class MotorChooserDialog extends JDialog implements CloseableDialog { public class MotorChooserDialog extends JDialog implements CloseableDialog {
private static final long serialVersionUID = 6903386330489783515L;
private final ThrustCurveMotorSelectionPanel selectionPanel; private final ThrustCurveMotorSelectionPanel selectionPanel;
private boolean okClicked = false; private boolean okClicked = false;
@ -30,7 +32,7 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
public MotorChooserDialog(MotorMount mount, FlightConfigurationID currentConfigID, Window owner) { public MotorChooserDialog(MotorMount mount, FlightConfigurationID currentConfigID, Window owner) {
this(owner); this(owner);
setMotorMountAndConfig(mount, currentConfigID); setMotorMountAndConfig( currentConfigID, mount);
} }
public MotorChooserDialog(Window owner) { public MotorChooserDialog(Window owner) {
@ -82,8 +84,8 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
selectionPanel.setCloseableDialog(this); selectionPanel.setCloseableDialog(this);
} }
public void setMotorMountAndConfig( MotorMount mount, FlightConfigurationID currentConfig ) { public void setMotorMountAndConfig( FlightConfigurationID _fcid, MotorMount _mount ) {
selectionPanel.setMotorMountAndConfig(mount, currentConfig); selectionPanel.setMotorMountAndConfig( _fcid, _mount );
} }
/** /**

View File

@ -67,10 +67,12 @@ public class MotorRowFilter extends RowFilter<TableModel, Integer> implements Ch
Iterator<MotorInstance> iter = mount.getMotorIterator(); Iterator<MotorInstance> iter = mount.getMotorIterator();
while( iter.hasNext()){ while( iter.hasNext()){
MotorInstance mi = iter.next(); MotorInstance mi = iter.next();
if( !mi.isEmpty()){
this.usedMotors.add((ThrustCurveMotor) mi.getMotor()); this.usedMotors.add((ThrustCurveMotor) mi.getMotor());
} }
} }
} }
}
public void setSearchTerms(final List<String> searchTerms) { public void setSearchTerms(final List<String> searchTerms) {
this.searchTerms = new ArrayList<String>(); this.searchTerms = new ArrayList<String>();

View File

@ -98,11 +98,12 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
private ThrustCurveMotorSet selectedMotorSet; private ThrustCurveMotorSet selectedMotorSet;
private double selectedDelay; private double selectedDelay;
public ThrustCurveMotorSelectionPanel(MotorMount mount, FlightConfigurationID currentConfig) { public ThrustCurveMotorSelectionPanel( final FlightConfigurationID fcid, MotorMount mount ) {
this(); this();
setMotorMountAndConfig( mount, currentConfig ); setMotorMountAndConfig( fcid, mount );
} }
/** /**
* Sole constructor. * Sole constructor.
* *
@ -310,16 +311,37 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
} }
public void setMotorMountAndConfig( MotorMount mount, FlightConfigurationID currentConfigId ) { public void setMotorMountAndConfig( final FlightConfigurationID _fcid, MotorMount _mount ) {
if ( null == _fcid ){
throw new NullPointerException(" attempted to set mount with a null FCID. bug. ");
}else if ( null == _mount ){
throw new NullPointerException(" attempted to set mount with a null mount. bug. ");
}
// DEBUG
MotorInstance curMotorInstance = _mount.getMotorInstance(_fcid);
System.err.println("(A) motor ID: "+ curMotorInstance.getMotorID().hashCode());
if( curMotorInstance.isEmpty()){
System.err.println("(B) MotorInstance: Motor: Empty.");
System.err.println("(C) MotorInstance: mount: Empty.");
}else{
System.err.println("(B) MotorInstance: has motor: "+curMotorInstance.getMotor() );
System.err.println("(C) MotorInstance: set mount: "+curMotorInstance.getMount());
}
System.err.println("(D) MotorInstance: parent mount: "+_mount);
System.err.println("(F) FCID: "+ _fcid.key);
System.err.println("(K) MotorInstance: IgnitionEvent: "+curMotorInstance.getIgnitionEvent().name);
System.err.println("(I) MotorInstance: Ign delay: "+curMotorInstance.getIgnitionDelay());
// DEBUG
selectedMotor = null; selectedMotor = null;
selectedMotorSet = null; selectedMotorSet = null;
selectedDelay = 0; selectedDelay = 0;
ThrustCurveMotor motorToSelect = null; ThrustCurveMotor motorToSelect = null;
if (currentConfigId != null && mount != null) { if ( curMotorInstance.hasMotor()){
MotorInstance motorConf = mount.getMotorInstance( currentConfigId); motorToSelect = (ThrustCurveMotor) curMotorInstance.getMotor();
motorToSelect = (ThrustCurveMotor) motorConf.getMotor(); selectedDelay = curMotorInstance.getEjectionDelay();
selectedDelay = motorConf.getEjectionDelay();
} }
// If current motor is not found in db, add a new ThrustCurveMotorSet containing it // If current motor is not found in db, add a new ThrustCurveMotorSet containing it
@ -333,13 +355,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
database.add(extra); database.add(extra);
Collections.sort(database); Collections.sort(database);
} }
}
select(motorToSelect); select(motorToSelect);
MotorMount mount = curMotorInstance.getMount();
//? have we added this motor to the given mount?
motorFilterPanel.setMotorMount(mount); motorFilterPanel.setMotorMount(mount);
}
scrollSelectionVisible(); scrollSelectionVisible();
} }
@Override @Override

View File

@ -10,7 +10,6 @@ import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
@ -24,7 +23,6 @@ import net.sf.openrocket.formatting.RocketDescriptor;
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.rocketcomponent.FlightConfigurableComponent; import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
@ -70,9 +68,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
FlightConfigurationID defaultFCID = rocket.getDefaultConfiguration().getFlightConfigurationID(); FlightConfigurationID defaultFCID = rocket.getDefaultConfiguration().getFlightConfigurationID();
FlightConfigurationID selectedFCID = getSelectedConfigurationId(); FlightConfigurationID selectedFCID = getSelectedConfigurationId();
if ( defaultFCID == null && selectedFCID == null ) { if ( selectedFCID == null ) {
// Nothing to do
} else if ( selectedFCID == null ) {
// need to unselect // need to unselect
table.clearSelection(); table.clearSelection();
} else if ( !defaultFCID.equals(selectedFCID)){ } else if ( !defaultFCID.equals(selectedFCID)){
@ -85,7 +81,6 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
Vector<FlightConfigurationID> ids = rocket.getSortedConfigurationIDs(); Vector<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) ) {
table.changeSelection(rowNum, col, true, false); table.changeSelection(rowNum, col, true, false);
break; break;
@ -114,17 +109,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
if ( e.getValueIsAdjusting() ) { if ( e.getValueIsAdjusting() ) {
return; return;
} }
int firstrow = e.getFirstIndex(); // int firstrow = e.getFirstIndex();
int lastrow = e.getLastIndex(); // int lastrow = e.getLastIndex();
ListSelectionModel model = (ListSelectionModel) e.getSource(); // ListSelectionModel model = (ListSelectionModel) e.getSource();
for( int row = firstrow; row <= lastrow; row ++) { // for( int row = firstrow; row <= lastrow; row ++) {
if ( model.isSelectedIndex(row) ) { // if ( model.isSelectedIndex(row) ) {
FlightConfigurationID fcid = (FlightConfigurationID) table.getValueAt(row, table.convertColumnIndexToView(0)); // FlightConfigurationID fcid = (FlightConfigurationID) table.getValueAt(row, table.convertColumnIndexToView(0));
FlightConfiguration config = rocket.getConfigurationSet().get(fcid); // FlightConfiguration config = rocket.getConfigurationSet().get(fcid);
rocket.getConfigurationSet().setDefault(config); // return;
return; // }
} // }
}
} }
}); });
@ -160,12 +154,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
} }
Object tableValue = table.getModel().getValueAt(row, col); Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) { if ( tableValue instanceof Pair ) {
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue; Pair<FlightConfigurationID,T> selectedComponent = (Pair<FlightConfigurationID,T>) tableValue;
return new FlightConfigurationID( selectedComponent.getU() ); return selectedComponent.getU();
} else if ( tableValue instanceof String ){ } else if ( tableValue instanceof String ){
return new FlightConfigurationID((String) tableValue); // DEPRECATED
System.err.println(" found String instance where expected a Pair....Bug!");
throw new IllegalStateException("!!Found String instance where expected a Pair....Bug!");
// this really should be un-implemented.
//return new FlightConfigurationID((String) tableValue);
} }
return null; return FlightConfigurationID.ERROR_CONFIGURATION_ID;
} }
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer { protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
@ -183,9 +181,11 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
return label; return label;
} }
default: { default: {
Pair<String, T> v = (Pair<String, T>) value; @SuppressWarnings("unchecked")
Pair<FlightConfigurationID, T> v = (Pair<FlightConfigurationID, T>) value;
if(v!=null){ if(v!=null){
FlightConfigurationID fcid = new FlightConfigurationID (v.getU()); FlightConfigurationID fcid = v.getU();
T component = v.getV(); T component = v.getV();
label = format(component, fcid, label ); label = format(component, fcid, label );
} }

View File

@ -37,8 +37,8 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
} }
@Override @Override
public void componentChanged(ComponentChangeEvent e) { public void componentChanged(ComponentChangeEvent cce) {
if ( e.isMotorChange() || e.isTreeChange() ) { if ( cce.isMotorChange() || cce.isTreeChange() ) {
initialize(); initialize();
fireTableStructureChanged(); fireTableStructureChanged();
} }
@ -66,7 +66,7 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
@Override @Override
public int getRowCount() { public int getRowCount() {
return rocket.getConfigurationSet().size() - 1; return rocket.getConfigurationSet().size();
} }
@Override @Override
@ -76,15 +76,16 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
@Override @Override
public Object getValueAt(int row, int column) { public Object getValueAt(int row, int column) {
FlightConfigurationID id = getConfiguration(row); FlightConfigurationID fcid = getConfigurationID(row);
switch (column) { switch (column) {
case 0: { case 0: {
return id; return fcid;
} }
default: { default: {
int index = column - 1; int index = column - 1;
T d = components.get(index); T d = components.get(index);
return new Pair<String, T>(id.toString(), d); return new Pair<FlightConfigurationID, T>(fcid, d);
} }
} }
} }
@ -104,11 +105,12 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
} }
} }
private FlightConfigurationID getConfiguration(int rowNum) { private FlightConfigurationID getConfigurationID(int rowNum) {
if( rocket.getConfigurationCount() != ids.size()){
this.ids = rocket.getSortedConfigurationIDs(); this.ids = rocket.getSortedConfigurationIDs();
}
FlightConfigurationID id = this.ids.get(rowNum + 1); return this.ids.get(rowNum);
return id;
} }
} }

View File

@ -146,8 +146,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId); ((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId);
} }
} }
newConfig.setName( oldName); newConfig.setName( oldName+"2");
rocket.getConfigurationSet().setDefault(newConfig);
// Create a new simulation for this configuration. // Create a new simulation for this configuration.
createSimulationForNewConfiguration(); createSimulationForNewConfiguration();

View File

@ -66,7 +66,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
@Override @Override
public void onDataChanged() { public void onDataChanged() {
MotorConfigurationPanel.this.fireTableDataChanged(); MotorConfigurationPanel.this.fireTableDataChanged();
} }
}; };
subpanel.add(mountConfigPanel, "grow"); subpanel.add(mountConfigPanel, "grow");
@ -147,18 +146,19 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected boolean includeComponent(MotorMount component) { protected boolean includeComponent(MotorMount component) {
return component.isMotorMount(); return component.isMotorMount();
} }
}; };
// Listen to changes to the table so we can disable the help text when a // Listen to changes to the table so we can disable the help text when a
// motor mount is added through the edit body tube dialog. // motor mount is added through the edit body tube dialog.
configurationTableModel.addTableModelListener( new TableModelListener() { configurationTableModel.addTableModelListener( new TableModelListener() {
@Override @Override
public void tableChanged(TableModelEvent e) { public void tableChanged(TableModelEvent tme) {
MotorConfigurationPanel.this.updateButtonState(); MotorConfigurationPanel.this.updateButtonState();
} }
}); });
JTable configurationTable = new JTable(configurationTableModel); JTable configurationTable = new JTable(configurationTableModel);
configurationTable.getTableHeader().setReorderingAllowed(false); configurationTable.getTableHeader().setReorderingAllowed(false);
configurationTable.setCellSelectionEnabled(true); configurationTable.setCellSelectionEnabled(true);
@ -168,7 +168,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
configurationTable.addMouseListener(new MouseAdapter() { configurationTable.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
updateButtonState(); MotorConfigurationPanel.this.updateButtonState();
int selectedColumn = table.getSelectedColumn(); int selectedColumn = table.getSelectedColumn();
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
if (selectedColumn > 0) { if (selectedColumn > 0) {
@ -184,12 +184,12 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected void updateButtonState() { protected void updateButtonState() {
if( configurationTableModel.getColumnCount() > 1 ) { if( configurationTableModel.getColumnCount() > 1 ) {
showContent(); showContent();
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount currentMount = getSelectedComponent(); boolean haveSelection = (null != getSelectedComponent());
selectMotorButton.setEnabled(currentMount != null && currentID != null); selectMotorButton.setEnabled( haveSelection );
removeMotorButton.setEnabled(currentMount != null && currentID != null); removeMotorButton.setEnabled( haveSelection );
selectIgnitionButton.setEnabled(currentMount != null && currentID != null); selectIgnitionButton.setEnabled( haveSelection );
resetIgnitionButton.setEnabled(currentMount != null && currentID != null); resetIgnitionButton.setEnabled( haveSelection );
} else { } else {
showEmptyText(); showEmptyText();
selectMotorButton.setEnabled(false); selectMotorButton.setEnabled(false);
@ -201,65 +201,71 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private void selectMotor() { private void selectMotor() {
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); MotorMount curMount = getSelectedComponent();
MotorMount mount = getSelectedComponent(); FlightConfigurationID fcid= getSelectedConfigurationId();
if (id == null || mount == null) if ( (null == fcid )||( null == curMount )){
return;
MotorInstance inst = mount.getMotorInstance(id);
if( inst.isEmpty() )
return; return;
}
System.err.println("?? selected FCID: "+ fcid.key);
motorChooserDialog.setMotorMountAndConfig(mount, id); motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
motorChooserDialog.setVisible(true); motorChooserDialog.setVisible(true);
Motor m = motorChooserDialog.getSelectedMotor(); Motor m = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay(); double d = motorChooserDialog.getSelectedDelay();
MotorInstance curInstance = curMount.getMotorInstance(fcid);
if (m != null) { if (m != null) {
inst = m.getNewInstance(); curInstance = m.getNewInstance();
inst.setEjectionDelay(d); curInstance.setEjectionDelay(d);
mount.setMotorInstance(id, inst); curMount.setMotorInstance( fcid, curInstance);
} }
fireTableDataChanged(); fireTableDataChanged();
} }
private void removeMotor() { private void removeMotor() {
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); MotorMount curMount = getSelectedComponent();
MotorMount mount = getSelectedComponent(); FlightConfigurationID fcid= getSelectedConfigurationId();
if (id == null || mount == null) if ( (null == fcid )||( null == curMount )){
return; return;
}
mount.setMotorInstance( id, null);
MotorInstance curInstance = MotorInstance.EMPTY_INSTANCE;
curMount.setMotorInstance( fcid, curInstance);
fireTableDataChanged(); fireTableDataChanged();
} }
private void selectIgnition() { private void selectIgnition() {
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); MotorMount curMount = getSelectedComponent();
MotorMount currentMount = getSelectedComponent(); FlightConfigurationID fcid= getSelectedConfigurationId();
if (currentID == null || currentMount == null) if ( (null == fcid )||( null == curMount )){
return; return;
}
IgnitionSelectionDialog dialog = new IgnitionSelectionDialog( IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog(
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel), SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
rocket, fcid,
currentMount); curMount);
dialog.setVisible(true); ignitionDialog.setVisible(true);
// changes performed automatically within "new IgnitionSelectionDialog(...)"
fireTableDataChanged(); fireTableDataChanged();
} }
private void resetIgnition() { private void resetIgnition() {
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); MotorMount curMount = getSelectedComponent();
MotorMount currentMount = getSelectedComponent(); FlightConfigurationID fcid= getSelectedConfigurationId();
if (currentID == null || currentMount == null) if ( (null == fcid )||( null == curMount )){
return; return;
}
MotorInstance curInstance = curMount.getMotorInstance(fcid);
MotorInstance curInstance = currentMount.getMotorInstance(currentID); MotorInstance defInstance = curInstance.getMount().getDefaultMotorInstance();
MotorInstance defInstance = currentMount.getDefaultMotorInstance();
curInstance.setIgnitionDelay( defInstance.getIgnitionDelay()); curInstance.setIgnitionDelay( defInstance.getIgnitionDelay());
curInstance.setIgnitionEvent( defInstance.getIgnitionEvent()); curInstance.setIgnitionEvent( defInstance.getIgnitionEvent());
@ -292,6 +298,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
MotorMount mount = curMotorInstance.getMount(); MotorMount mount = curMotorInstance.getMount();
Motor motor = curMotorInstance.getMotor(); Motor motor = curMotorInstance.getMotor();
if( null == mount){
throw new NullPointerException("Motor has a null mount... this should never happen: "+curMotorInstance.getMotorID());
}
String str = motor.getDesignation(curMotorInstance.getEjectionDelay()); String str = motor.getDesignation(curMotorInstance.getEjectionDelay());
int count = mount.getInstanceCount(); int count = mount.getInstanceCount();