[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);
}
}
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();
protected final MotorMount mount;
protected final FlightConfigurationId fcid;
protected final MotorConfigurationId id;
private final MotorMount mount;
private final FlightConfigurationId fcid;
private final MotorConfigurationId mid;
protected String name = "";
protected Motor motor = null;
protected double ejectionDelay = 0.0;
private Motor motor = null;
private double ejectionDelay = 0.0;
protected boolean ignitionOveride = false;
protected double ignitionDelay = 0.0;
protected IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
private boolean ignitionOveride = false;
private double ignitionDelay = 0.0;
private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
protected int modID = 0;
private int modID = 0;
public MotorConfiguration( final MotorMount _mount, final FlightConfigurationId _fcid ) {
if (null == _mount ) {
@ -40,7 +39,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.mount = _mount;
this.fcid = _fcid;
this.id = new MotorConfigurationId( _mount, _fcid );
this.mid = new MotorConfigurationId( _mount, _fcid );
modID++;
}
@ -68,7 +67,15 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
}
public MotorConfigurationId getID() {
return this.id;
return this.mid;
}
public FlightConfigurationId getFCID() {
return fcid;
}
public MotorConfigurationId getMID() {
return mid;
}
public void setMotor(Motor motor){
@ -175,7 +182,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
return false;
}else if( other instanceof MotorConfiguration ){
MotorConfiguration omi = (MotorConfiguration)other;
if( this.id.equals( omi.id)){
if( this.mid.equals( omi.mid)){
return true;
}
}
@ -184,7 +191,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
@Override
public int hashCode() {
return this.id.hashCode();
return this.mid.hashCode();
}
/**
@ -236,14 +243,15 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public String toDebugDetail( ) {
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(),
fcid.toShortKey(),
mid.toDebug(),
toMotorDescription(),
toIgnitionDescription() ));
return buf.toString();
}
}

View File

@ -33,10 +33,9 @@ public final class MotorConfigurationId {
throw new NullPointerException("Provided FlightConfigurationId was null");
}
// Use intern so comparison can be done using == instead of equals()
final long upper = ((long)_mount.getID().hashCode()) << 32;
final long lower = _fcid.key.getLeastSignificantBits();
this.key = new UUID( upper, lower);
final long mountHash= ((long)_mount.getID().hashCode()) << 32;
final long fcidLower = _fcid.key.getMostSignificantBits();
this.key = new UUID( mountHash, fcidLower);
}
@Override
@ -56,6 +55,10 @@ public final class MotorConfigurationId {
return key.hashCode();
}
public String toDebug(){
return toShortKey();
}
@Override
public String toString(){
if( this.key == MotorConfigurationId.ERROR_KEY){
@ -64,4 +67,13 @@ public final class MotorConfigurationId {
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.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
/**
* 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 eventType the event type that will be fired on changes
*/
public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> configSet, RocketComponent component) {
super(configSet);
public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> sourceSet, final MotorMount newMount) {
// 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
@ -42,10 +48,18 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
for( FlightConfigurationId loopFCID : this.map.keySet()){
MotorConfiguration curConfig = this.map.get(loopFCID);
if( this.isDefault(loopFCID)){
buffer.append( " [DEFAULT] "+curConfig.toDebugDetail()+"\n");
buffer.append( " [DEF]");
}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();
}

View File

@ -37,6 +37,11 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
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
@Override
public Collection<Coordinate> getComponentBounds() {

View File

@ -92,7 +92,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return outerRadius;
}
/**
* 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.
@ -395,6 +394,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
public Iterator<MotorConfiguration> getMotorIterator(){
return this.motors.iterator();
}
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {

View File

@ -16,4 +16,11 @@ public interface FlightConfigurableComponent {
*/
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;
}
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);
}
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override
public void setMotorMount(boolean _active){

View File

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

View File

@ -589,7 +589,7 @@ public class Rocket extends RocketComponent {
*
* @param fcid the flight configuration ID to remove
*/
public void removeFlightConfigurationID(FlightConfigurationId fcid) {
public void removeFlightConfiguration(final FlightConfigurationId fcid) {
checkState();
if( fcid.hasError() ){
return;
@ -599,6 +599,17 @@ public class Rocket extends RocketComponent {
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:
this.configSet.reset( fcid);
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.util.Pair;
@SuppressWarnings("serial")
public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel {
private static final long serialVersionUID = 3359871704879603700L;
protected static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.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 {
private static final long serialVersionUID = 2026945220957913776L;
@Override
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.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
@ -200,23 +201,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
if ( (null == fcid )||( null == curMount )){
return;
}
//MotorInstance curInstance = curMount.getMotorInstance( fcid );
// curInstance may be empty here...
//String mountName = ((RocketComponent)curMount).getName();
//System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey());
if( fcid.equals( FlightConfigurationId.DEFAULT_VALUE_FCID)){
throw new IllegalStateException("Attempting to set a motor on the default FCID.");
}
motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
motorChooserDialog.setVisible(true);
Motor mtr = motorChooserDialog.getSelectedMotor();
Motor mtr = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay();
if (mtr != null) {
MotorConfiguration curConfig = curMount.getMotorConfig(fcid);
curConfig.setMotor(mtr);
curConfig.setEjectionDelay(d);
curConfig.setIgnitionEvent( IgnitionEvent.NEVER);
curMount.setMotorConfig( curConfig, fcid);
final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid);
final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig);
newConfig.setMotor(mtr);
newConfig.setEjectionDelay(d);
curMount.setMotorConfig( newConfig, fcid);
}
fireTableDataChanged();