[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>");
indent++;
writeElement("configid", cond.getConfigID());
writeElement("configid", cond.getConfigID().key);
writeElement("launchrodlength", cond.getLaunchRodLength());
writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI);
writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI));

View File

@ -57,8 +57,11 @@ class MotorMountHandler extends AbstractElementHandler {
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
// DEBUG ONLY
// System.err.println("closing MotorMount element: "+ element);
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"));
if (!fcid.isValid()) {
warnings.add(Warning.fromString("Illegal motor specification, ignoring."));
@ -69,6 +72,20 @@ class MotorMountHandler extends AbstractElementHandler {
MotorInstance motorInstance = motor.getNewInstance();
motorInstance.setEjectionDelay(motorHandler.getDelay(warnings));
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;
}

View File

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

View File

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

View File

@ -164,13 +164,15 @@ public class RocketComponentSaver {
for (FlightConfiguration curConfig : configs) {
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) {
elements.add(" <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -69,5 +69,8 @@ public final class MotorInstanceId {
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;
import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Inertia;
import net.sf.openrocket.util.MathUtil;
@ -11,6 +12,7 @@ public class ThrustCurveMotorInstance extends MotorInstance {
private int timeIndex = -1;
protected MotorMount mount = null;
protected ThrustCurveMotor motor = null;
// Previous time step value
@ -99,6 +101,21 @@ public class ThrustCurveMotorInstance extends MotorInstance {
public Motor getMotor(){
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
public void setEjectionDelay(double delay) {

View File

@ -7,9 +7,9 @@ import java.util.Iterator;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
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
private double overhang = 0;
private boolean isActing = false;
private boolean isActingMount = false;
private MotorConfigurationSet motors;
@ -370,7 +370,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
public boolean isDefaultMotorInstance( final MotorInstance testInstance){
return this.motors.getDefault() == testInstance;
}
@Override
public MotorInstance getMotorInstance( final FlightConfigurationID fcid){
return this.motors.get(fcid);
@ -378,15 +378,25 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
@Override
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);
if( null != newMotorInstance ){
newMotorInstance.setMount( this);
if( MotorInstanceId.EMPTY_ID != newMotorInstance.getID()){
this.setMotorMount(true);
}
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... ");
}
}
@Override
public Iterator<MotorInstance> getMotorIterator(){
return this.motors.iterator();
@ -399,15 +409,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
@Override
public void setMotorMount(boolean _active){
if (this.isActing == _active)
if (this.isActingMount == _active)
return;
this.isActing = _active;
this.isActingMount = _active;
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
}
@Override
public boolean isMotorMount(){
return this.isActing;
return this.isActingMount;
}
@Override

View File

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

View File

@ -41,6 +41,16 @@ public interface FlightConfigurable<E extends ChangeSource> extends FlightConfig
*/
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.
* 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);
MotorInstance inst = mount.getMotorInstance(this.fcid);
if( MotorInstance.EMPTY_INSTANCE == inst){
if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){
// 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;
}

View File

@ -26,7 +26,17 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
}else if (5 >_val.length()){
this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY;
} 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
public String toString() {
return ("key: "+this.key);
return this.key;
}
@Override

View File

@ -3,6 +3,7 @@ package net.sf.openrocket.rocketcomponent;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import org.slf4j.Logger;
@ -99,7 +100,23 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
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
public E get(FlightConfigurationID id) {
E toReturn;

View File

@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
@ -259,12 +258,21 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
@Override
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);
if( null != newMotorInstance ){
newMotorInstance.setMount( this);
if( MotorInstanceId.EMPTY_ID != newMotorInstance.getID()){
this.setMotorMount(true);
}
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;
}
if( -1 == e.getType()){
log.debug(">>fireComponentChangeEvent()>> . . .");
}
// Notify all components first
Iterator<RocketComponent> iterator = this.iterator(true);
while (iterator.hasNext()) {
@ -513,14 +516,23 @@ public class Rocket extends RocketComponent {
}
this.setFlightConfiguration( fcid, nextConfig );
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
return nextConfig;
}
public int getConfigurationCount(){
return this.configurations.size();
}
public FlightConfigurationSet<FlightConfiguration> getConfigurationSet(){
checkState();
return this.configurations;
}
public FlightConfiguration getFlightConfig( final FlightConfigurationID fcid ){
checkState();
return this.configurations.get(fcid);
}
public Vector<FlightConfigurationID> getSortedConfigurationIDs(){
// if the configuration list has changed, refresh it.

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@ import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.util.GUIUtil;
@ -24,35 +23,39 @@ import net.sf.openrocket.motor.MotorInstance;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
public class IgnitionSelectionDialog extends JDialog {
private static final long serialVersionUID = -3399966098520607837L;
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 IgnitionConfiguration newConfiguration;
private MotorMount curMount;
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);
final FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID();
curMotor = component.getMotorInstance(id);
MotorInstance defMotor = component.getDefaultMotorInstance();
curMount = _mount;
destMotorInstance = curMount.getMotorInstance(curFCID);
startIgnEvent = destMotorInstance.getIgnitionEvent();
ignitionDelay = destMotorInstance.getIgnitionDelay();
final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance();
JPanel panel = new JPanel(new MigLayout("fill"));
// 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");
final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault);
panel.add(defaultButton, "span, gapleft para, wrap rel");
String str = trans.get("IgnitionSelectionDialog.opt.override");
str = str.replace("{0}", descriptor.format(rocket, id));
//str = str.replace("{0}", descriptor.format(rocket, id));
final JRadioButton overrideButton = new JRadioButton(str, !isDefault);
panel.add(overrideButton, "span, gapleft para, wrap para");
@ -79,7 +82,7 @@ public class IgnitionSelectionDialog extends JDialog {
//// plus
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());
spin.setEditor(new SpinnerEditor(spin, 3));
panel.add(spin, "gap rel rel");
@ -93,12 +96,15 @@ public class IgnitionSelectionDialog extends JDialog {
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MotorInstance defMotor = component.getDefaultMotorInstance();
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 {
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);
}
@ -112,6 +118,9 @@ public class IgnitionSelectionDialog extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
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.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent;
@ -94,9 +93,9 @@ public class SeparationSelectionDialog extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
if (defaultButton.isSelected()) {
FlightConfigurationSet<StageSeparationConfiguration> sepConfigSet = component.getSeparationConfigurations();
StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID);
component.getSeparationConfigurations().setDefault( sepConfig);
// FlightConfigurationSet<StageSeparationConfiguration> sepConfigSet = component.getSeparationConfigurations();
// StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID);
// component.getSeparationConfigurations().setDefault( sepConfig);
// old version
//component.getSeparationConfigurations().setDefault( fcid?, newConfiguration);
} else {

View File

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

View File

@ -67,7 +67,9 @@ public class MotorRowFilter extends RowFilter<TableModel, Integer> implements Ch
Iterator<MotorInstance> iter = mount.getMotorIterator();
while( iter.hasNext()){
MotorInstance mi = iter.next();
this.usedMotors.add((ThrustCurveMotor) mi.getMotor());
if( !mi.isEmpty()){
this.usedMotors.add((ThrustCurveMotor) mi.getMotor());
}
}
}
}

View File

@ -98,11 +98,12 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
private ThrustCurveMotorSet selectedMotorSet;
private double selectedDelay;
public ThrustCurveMotorSelectionPanel(MotorMount mount, FlightConfigurationID currentConfig) {
public ThrustCurveMotorSelectionPanel( final FlightConfigurationID fcid, MotorMount mount ) {
this();
setMotorMountAndConfig( mount, currentConfig );
setMotorMountAndConfig( fcid, mount );
}
/**
* Sole constructor.
*
@ -310,18 +311,39 @@ 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;
selectedMotorSet = null;
selectedDelay = 0;
ThrustCurveMotor motorToSelect = null;
if (currentConfigId != null && mount != null) {
MotorInstance motorConf = mount.getMotorInstance( currentConfigId);
motorToSelect = (ThrustCurveMotor) motorConf.getMotor();
selectedDelay = motorConf.getEjectionDelay();
if ( curMotorInstance.hasMotor()){
motorToSelect = (ThrustCurveMotor) curMotorInstance.getMotor();
selectedDelay = curMotorInstance.getEjectionDelay();
}
// If current motor is not found in db, add a new ThrustCurveMotorSet containing it
if (motorToSelect != null) {
ThrustCurveMotorSet motorSetToSelect = null;
@ -333,13 +355,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
database.add(extra);
Collections.sort(database);
}
select(motorToSelect);
MotorMount mount = curMotorInstance.getMount();
//? have we added this motor to the given mount?
motorFilterPanel.setMotorMount(mount);
}
select(motorToSelect);
motorFilterPanel.setMotorMount(mount);
scrollSelectionVisible();
}
@Override

View File

@ -10,7 +10,6 @@ import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.Border;
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.l10n.Translator;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
@ -58,7 +56,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
public void fireTableDataChanged() {
int selectedRow = table.getSelectedRow();
int selectedColumn = table.getSelectedColumn();
int selectedColumn = table.getSelectedColumn();
((AbstractTableModel)table.getModel()).fireTableDataChanged();
restoreSelection(selectedRow,selectedColumn);
updateButtonState();
@ -70,9 +68,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
FlightConfigurationID defaultFCID = rocket.getDefaultConfiguration().getFlightConfigurationID();
FlightConfigurationID selectedFCID = getSelectedConfigurationId();
if ( defaultFCID == null && selectedFCID == null ) {
// Nothing to do
} else if ( selectedFCID == null ) {
if ( selectedFCID == null ) {
// need to unselect
table.clearSelection();
} else if ( !defaultFCID.equals(selectedFCID)){
@ -85,7 +81,6 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
Vector<FlightConfigurationID> ids = rocket.getSortedConfigurationIDs();
for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) {
FlightConfigurationID rowFCID = ids.get(rowNum );
if ( rowFCID.equals(selectedFCID) ) {
table.changeSelection(rowNum, col, true, false);
break;
@ -114,17 +109,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
if ( e.getValueIsAdjusting() ) {
return;
}
int firstrow = e.getFirstIndex();
int lastrow = e.getLastIndex();
ListSelectionModel model = (ListSelectionModel) e.getSource();
for( int row = firstrow; row <= lastrow; row ++) {
if ( model.isSelectedIndex(row) ) {
FlightConfigurationID fcid = (FlightConfigurationID) table.getValueAt(row, table.convertColumnIndexToView(0));
FlightConfiguration config = rocket.getConfigurationSet().get(fcid);
rocket.getConfigurationSet().setDefault(config);
return;
}
}
// int firstrow = e.getFirstIndex();
// int lastrow = e.getLastIndex();
// ListSelectionModel model = (ListSelectionModel) e.getSource();
// for( int row = firstrow; row <= lastrow; row ++) {
// if ( model.isSelectedIndex(row) ) {
// FlightConfigurationID fcid = (FlightConfigurationID) table.getValueAt(row, table.convertColumnIndexToView(0));
// FlightConfiguration config = rocket.getConfigurationSet().get(fcid);
// return;
// }
// }
}
});
@ -160,12 +154,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
return new FlightConfigurationID( selectedComponent.getU() );
Pair<FlightConfigurationID,T> selectedComponent = (Pair<FlightConfigurationID,T>) tableValue;
return selectedComponent.getU();
} 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 {
@ -183,9 +181,11 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
return label;
}
default: {
Pair<String, T> v = (Pair<String, T>) value;
@SuppressWarnings("unchecked")
Pair<FlightConfigurationID, T> v = (Pair<FlightConfigurationID, T>) value;
if(v!=null){
FlightConfigurationID fcid = new FlightConfigurationID (v.getU());
FlightConfigurationID fcid = v.getU();
T component = v.getV();
label = format(component, fcid, label );
}

View File

@ -17,7 +17,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Pair;
public class FlightConfigurableTableModel<T extends FlightConfigurableComponent> extends AbstractTableModel implements ComponentChangeListener{
public class FlightConfigurableTableModel<T extends FlightConfigurableComponent> extends AbstractTableModel implements ComponentChangeListener{
private static final long serialVersionUID = 3168465083803936363L;
private static final Translator trans = Application.getTranslator();
@ -37,8 +37,8 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
}
@Override
public void componentChanged(ComponentChangeEvent e) {
if ( e.isMotorChange() || e.isTreeChange() ) {
public void componentChanged(ComponentChangeEvent cce) {
if ( cce.isMotorChange() || cce.isTreeChange() ) {
initialize();
fireTableStructureChanged();
}
@ -66,7 +66,7 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
@Override
public int getRowCount() {
return rocket.getConfigurationSet().size() - 1;
return rocket.getConfigurationSet().size();
}
@Override
@ -76,15 +76,16 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
@Override
public Object getValueAt(int row, int column) {
FlightConfigurationID id = getConfiguration(row);
FlightConfigurationID fcid = getConfigurationID(row);
switch (column) {
case 0: {
return id;
return fcid;
}
default: {
int index = column - 1;
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) {
this.ids = rocket.getSortedConfigurationIDs();
private FlightConfigurationID getConfigurationID(int rowNum) {
if( rocket.getConfigurationCount() != ids.size()){
this.ids = rocket.getSortedConfigurationIDs();
}
FlightConfigurationID id = this.ids.get(rowNum + 1);
return id;
return this.ids.get(rowNum);
}
}

View File

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

View File

@ -66,7 +66,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
@Override
public void onDataChanged() {
MotorConfigurationPanel.this.fireTableDataChanged();
}
};
subpanel.add(mountConfigPanel, "grow");
@ -147,18 +146,19 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected boolean includeComponent(MotorMount component) {
return component.isMotorMount();
}
};
// 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.
configurationTableModel.addTableModelListener( new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
public void tableChanged(TableModelEvent tme) {
MotorConfigurationPanel.this.updateButtonState();
}
});
JTable configurationTable = new JTable(configurationTableModel);
configurationTable.getTableHeader().setReorderingAllowed(false);
configurationTable.setCellSelectionEnabled(true);
@ -168,7 +168,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
configurationTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
updateButtonState();
MotorConfigurationPanel.this.updateButtonState();
int selectedColumn = table.getSelectedColumn();
if (e.getClickCount() == 2) {
if (selectedColumn > 0) {
@ -184,12 +184,12 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected void updateButtonState() {
if( configurationTableModel.getColumnCount() > 1 ) {
showContent();
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount currentMount = getSelectedComponent();
selectMotorButton.setEnabled(currentMount != null && currentID != null);
removeMotorButton.setEnabled(currentMount != null && currentID != null);
selectIgnitionButton.setEnabled(currentMount != null && currentID != null);
resetIgnitionButton.setEnabled(currentMount != null && currentID != null);
boolean haveSelection = (null != getSelectedComponent());
selectMotorButton.setEnabled( haveSelection );
removeMotorButton.setEnabled( haveSelection );
selectIgnitionButton.setEnabled( haveSelection );
resetIgnitionButton.setEnabled( haveSelection );
} else {
showEmptyText();
selectMotorButton.setEnabled(false);
@ -201,65 +201,71 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private void selectMotor() {
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount mount = getSelectedComponent();
if (id == null || mount == null)
return;
MotorInstance inst = mount.getMotorInstance(id);
if( inst.isEmpty() )
return;
motorChooserDialog.setMotorMountAndConfig(mount, id);
MotorMount curMount = getSelectedComponent();
FlightConfigurationID fcid= getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){
return;
}
System.err.println("?? selected FCID: "+ fcid.key);
motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
motorChooserDialog.setVisible(true);
Motor m = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay();
MotorInstance curInstance = curMount.getMotorInstance(fcid);
if (m != null) {
inst = m.getNewInstance();
inst.setEjectionDelay(d);
mount.setMotorInstance(id, inst);
curInstance = m.getNewInstance();
curInstance.setEjectionDelay(d);
curMount.setMotorInstance( fcid, curInstance);
}
fireTableDataChanged();
}
private void removeMotor() {
FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount mount = getSelectedComponent();
if (id == null || mount == null)
return;
mount.setMotorInstance( id, null);
MotorMount curMount = getSelectedComponent();
FlightConfigurationID fcid= getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){
return;
}
MotorInstance curInstance = MotorInstance.EMPTY_INSTANCE;
curMount.setMotorInstance( fcid, curInstance);
fireTableDataChanged();
}
private void selectIgnition() {
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount currentMount = getSelectedComponent();
if (currentID == null || currentMount == null)
return;
IgnitionSelectionDialog dialog = new IgnitionSelectionDialog(
MotorMount curMount = getSelectedComponent();
FlightConfigurationID fcid= getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){
return;
}
IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog(
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
rocket,
currentMount);
dialog.setVisible(true);
fcid,
curMount);
ignitionDialog.setVisible(true);
// changes performed automatically within "new IgnitionSelectionDialog(...)"
fireTableDataChanged();
}
private void resetIgnition() {
FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount currentMount = getSelectedComponent();
if (currentID == null || currentMount == null)
return;
MotorInstance curInstance = currentMount.getMotorInstance(currentID);
MotorInstance defInstance = currentMount.getDefaultMotorInstance();
MotorMount curMount = getSelectedComponent();
FlightConfigurationID fcid= getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){
return;
}
MotorInstance curInstance = curMount.getMotorInstance(fcid);
MotorInstance defInstance = curInstance.getMount().getDefaultMotorInstance();
curInstance.setIgnitionDelay( defInstance.getIgnitionDelay());
curInstance.setIgnitionEvent( defInstance.getIgnitionEvent());
@ -271,7 +277,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private static final long serialVersionUID = -7462331042920067984L;
@Override
protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) {
protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) {
JLabel label = new JLabel();
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
MotorInstance curMotor = mount.getMotorInstance( configId);
@ -292,6 +298,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
MotorMount mount = curMotorInstance.getMount();
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());
int count = mount.getInstanceCount();