[bugfix] Fixed several FlightConfiguration bugs

- adjusted some class member names to be more descriptive
- When a component lacks an entry for the currently selected FC
  -- Code would sometimes fail to create a new motor entry
- removing a flight configuration from a rocket
  -- removes all component configurations tied to that configuration Id
This commit is contained in:
Daniel_M_Williams 2016-04-23 18:36:31 -04:00
parent f7090afd79
commit 3362c03279
13 changed files with 112 additions and 43 deletions

View File

@ -286,7 +286,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
removeSimulation(s); removeSimulation(s);
} }
} }
rocket.removeFlightConfigurationID(configId); rocket.removeFlightConfiguration(configId);
} }

View File

@ -16,19 +16,18 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public static final String EMPTY_DESCRIPTION = "Empty Motor Configuration".intern(); public static final String EMPTY_DESCRIPTION = "Empty Motor Configuration".intern();
protected final MotorMount mount; private final MotorMount mount;
protected final FlightConfigurationId fcid; private final FlightConfigurationId fcid;
protected final MotorConfigurationId id; private final MotorConfigurationId mid;
protected String name = ""; private Motor motor = null;
protected Motor motor = null; private double ejectionDelay = 0.0;
protected double ejectionDelay = 0.0;
protected boolean ignitionOveride = false; private boolean ignitionOveride = false;
protected double ignitionDelay = 0.0; private double ignitionDelay = 0.0;
protected IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC; private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
protected int modID = 0; private int modID = 0;
public MotorConfiguration( final MotorMount _mount, final FlightConfigurationId _fcid ) { public MotorConfiguration( final MotorMount _mount, final FlightConfigurationId _fcid ) {
if (null == _mount ) { if (null == _mount ) {
@ -40,7 +39,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.mount = _mount; this.mount = _mount;
this.fcid = _fcid; this.fcid = _fcid;
this.id = new MotorConfigurationId( _mount, _fcid ); this.mid = new MotorConfigurationId( _mount, _fcid );
modID++; modID++;
} }
@ -68,7 +67,15 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
} }
public MotorConfigurationId getID() { public MotorConfigurationId getID() {
return this.id; return this.mid;
}
public FlightConfigurationId getFCID() {
return fcid;
}
public MotorConfigurationId getMID() {
return mid;
} }
public void setMotor(Motor motor){ public void setMotor(Motor motor){
@ -175,7 +182,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
return false; return false;
}else if( other instanceof MotorConfiguration ){ }else if( other instanceof MotorConfiguration ){
MotorConfiguration omi = (MotorConfiguration)other; MotorConfiguration omi = (MotorConfiguration)other;
if( this.id.equals( omi.id)){ if( this.mid.equals( omi.mid)){
return true; return true;
} }
} }
@ -184,7 +191,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
@Override @Override
public int hashCode() { public int hashCode() {
return this.id.hashCode(); return this.mid.hashCode();
} }
/** /**
@ -236,9 +243,10 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public String toDebugDetail( ) { public String toDebugDetail( ) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(String.format(">> in: %28s::%10s %8s ign@: %12s ", buf.append(String.format("[in: %28s][fcid %10s][mid %10s][ %8s ign@: %12s]",
mount.getDebugName(), mount.getDebugName(),
fcid.toShortKey(), fcid.toShortKey(),
mid.toDebug(),
toMotorDescription(), toMotorDescription(),
toIgnitionDescription() )); toIgnitionDescription() ));

View File

@ -33,10 +33,9 @@ public final class MotorConfigurationId {
throw new NullPointerException("Provided FlightConfigurationId was null"); throw new NullPointerException("Provided FlightConfigurationId was null");
} }
// Use intern so comparison can be done using == instead of equals() final long mountHash= ((long)_mount.getID().hashCode()) << 32;
final long upper = ((long)_mount.getID().hashCode()) << 32; final long fcidLower = _fcid.key.getMostSignificantBits();
final long lower = _fcid.key.getLeastSignificantBits(); this.key = new UUID( mountHash, fcidLower);
this.key = new UUID( upper, lower);
} }
@Override @Override
@ -56,6 +55,10 @@ public final class MotorConfigurationId {
return key.hashCode(); return key.hashCode();
} }
public String toDebug(){
return toShortKey();
}
@Override @Override
public String toString(){ public String toString(){
if( this.key == MotorConfigurationId.ERROR_KEY){ if( this.key == MotorConfigurationId.ERROR_KEY){
@ -64,4 +67,13 @@ public final class MotorConfigurationId {
return key.toString(); return key.toString();
} }
} }
public String toShortKey() {
final String keyString = key.toString();
final int lastIndex = -1 + keyString.length();
final int chunkLen = 4;
// return the head + tail of the full 64-character id
return (keyString.substring(0,chunkLen)+"/"+keyString.substring(lastIndex - chunkLen,lastIndex));
}
} }

View File

@ -4,7 +4,6 @@ import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
/** /**
* FlightConfigurationSet for motors. * FlightConfigurationSet for motors.
@ -24,8 +23,15 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
* @param component the rocket component on which events are fired when the parameter values are changed * @param component the rocket component on which events are fired when the parameter values are changed
* @param eventType the event type that will be fired on changes * @param eventType the event type that will be fired on changes
*/ */
public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> configSet, RocketComponent component) { public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> sourceSet, final MotorMount newMount) {
super(configSet); // creates a new empty config w/ default value
super( new MotorConfiguration( newMount, FlightConfigurationId.DEFAULT_VALUE_FCID ));
for( MotorConfiguration sourceConfig : sourceSet ){
FlightConfigurationId nextFCID = sourceConfig.getFCID();
MotorConfiguration nextValue = new MotorConfiguration( newMount, nextFCID, sourceConfig);
set( nextFCID, nextValue );
}
} }
@Override @Override
@ -42,10 +48,18 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
for( FlightConfigurationId loopFCID : this.map.keySet()){ for( FlightConfigurationId loopFCID : this.map.keySet()){
MotorConfiguration curConfig = this.map.get(loopFCID); MotorConfiguration curConfig = this.map.get(loopFCID);
if( this.isDefault(loopFCID)){ if( this.isDefault(loopFCID)){
buffer.append( " [DEFAULT] "+curConfig.toDebugDetail()+"\n"); buffer.append( " [DEF]");
}else{ }else{
buffer.append( " "+curConfig.toDebugDetail() +"\n"); buffer.append( " ");
} }
buffer.append(String.format("@%10s=[fcid//%8s][mid//%8s][ %8s ign@: %12s]\n",
loopFCID.toShortKey(),
curConfig.getFCID().toShortKey(),
curConfig.getMID().toShortKey(),
curConfig.toMotorDescription(),
curConfig.toIgnitionDescription() ));
} }
return buffer.toString(); return buffer.toString();
} }

View File

@ -37,6 +37,11 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
return separations; return separations;
} }
@Override
public void reset( final FlightConfigurationId fcid){
separations.reset(fcid);
}
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size // not strictly accurate, but this should provide an acceptable estimate for total vehicle size
@Override @Override
public Collection<Coordinate> getComponentBounds() { public Collection<Coordinate> getComponentBounds() {

View File

@ -92,7 +92,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return outerRadius; return outerRadius;
} }
/** /**
* Set the outer radius of the body tube. If the radius is less than the wall thickness, * Set the outer radius of the body tube. If the radius is less than the wall thickness,
* the wall thickness is decreased accordingly of the value of the radius. * the wall thickness is decreased accordingly of the value of the radius.
@ -396,6 +395,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return this.motors.iterator(); return this.motors.iterator();
} }
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override @Override
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) { public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
motors.copyFlightConfiguration(oldConfigId, newConfigId); motors.copyFlightConfiguration(oldConfigId, newConfigId);

View File

@ -16,4 +16,11 @@ public interface FlightConfigurableComponent {
*/ */
void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId); void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId);
/**
* Reset a specific flight configuration ID to use the default parameter value.
*
* @param fcid the flight configuration ID
*/
void reset( final FlightConfigurationId fcid);
} }

View File

@ -371,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
continue; continue;
} }
this.motors.put( motorConfig.getID(), motorConfig); this.motors.put( motorConfig.getMID(), motorConfig);
} }
} }

View File

@ -308,6 +308,10 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
motors.copyFlightConfiguration(oldConfigId, newConfigId); motors.copyFlightConfiguration(oldConfigId, newConfigId);
} }
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override @Override
public void setMotorMount(boolean _active){ public void setMotorMount(boolean _active){

View File

@ -94,6 +94,10 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
deploymentConfigurations.copyFlightConfiguration(oldConfigId, newConfigId); deploymentConfigurations.copyFlightConfiguration(oldConfigId, newConfigId);
} }
@Override
public void reset( final FlightConfigurationId fcid){
deploymentConfigurations.reset(fcid);
}
@Override @Override
public double getComponentMass() { public double getComponentMass() {

View File

@ -589,7 +589,7 @@ public class Rocket extends RocketComponent {
* *
* @param fcid the flight configuration ID to remove * @param fcid the flight configuration ID to remove
*/ */
public void removeFlightConfigurationID(FlightConfigurationId fcid) { public void removeFlightConfiguration(final FlightConfigurationId fcid) {
checkState(); checkState();
if( fcid.hasError() ){ if( fcid.hasError() ){
return; return;
@ -599,6 +599,17 @@ public class Rocket extends RocketComponent {
selectedConfiguration = configSet.getDefault(); selectedConfiguration = configSet.getDefault();
} }
// removed any component configuration tied to this FCID
Iterator<RocketComponent> iterator = this.iterator();
while (iterator.hasNext()) {
RocketComponent comp = iterator.next();
if (comp instanceof FlightConfigurableComponent){
FlightConfigurableComponent confbl = (FlightConfigurableComponent)comp;
confbl.reset( fcid);
}
}
// Get current configuration: // Get current configuration:
this.configSet.reset( fcid); this.configSet.reset( fcid);
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);

View File

@ -29,9 +29,10 @@ import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Pair; import net.sf.openrocket.util.Pair;
@SuppressWarnings("serial")
public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel { public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel {
private static final long serialVersionUID = 3359871704879603700L;
protected static final Translator trans = Application.getTranslator(); protected static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class); private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class);
protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
@ -160,7 +161,6 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
} }
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer { protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 2026945220957913776L;
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object newValue, boolean isSelected, boolean hasFocus, int row, int column) { public Component getTableCellRendererComponent(JTable table, Object newValue, boolean isSelected, boolean hasFocus, int row, int column) {

View File

@ -28,6 +28,7 @@ import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.motor.IgnitionEvent; import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -201,10 +202,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return; return;
} }
//MotorInstance curInstance = curMount.getMotorInstance( fcid ); if( fcid.equals( FlightConfigurationId.DEFAULT_VALUE_FCID)){
// curInstance may be empty here... throw new IllegalStateException("Attempting to set a motor on the default FCID.");
//String mountName = ((RocketComponent)curMount).getName(); }
//System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey());
motorChooserDialog.setMotorMountAndConfig( fcid, curMount ); motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
motorChooserDialog.setVisible(true); motorChooserDialog.setVisible(true);
@ -212,11 +212,11 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
Motor mtr = motorChooserDialog.getSelectedMotor(); Motor mtr = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay(); double d = motorChooserDialog.getSelectedDelay();
if (mtr != null) { if (mtr != null) {
MotorConfiguration curConfig = curMount.getMotorConfig(fcid); final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid);
curConfig.setMotor(mtr); final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig);
curConfig.setEjectionDelay(d); newConfig.setMotor(mtr);
curConfig.setIgnitionEvent( IgnitionEvent.NEVER); newConfig.setEjectionDelay(d);
curMount.setMotorConfig( curConfig, fcid); curMount.setMotorConfig( newConfig, fcid);
} }
fireTableDataChanged(); fireTableDataChanged();