From a43fbe79bc60fb98e9be39bc64149b7d3108acaf Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Thu, 26 Nov 2015 09:05:08 -0500 Subject: [PATCH] [bugfix] 'remove motor' button now works correctly --- .../MotorConfigurationSet.java | 7 +++-- .../openrocket/rocketcomponent/BodyTube.java | 5 ++-- .../openrocket/rocketcomponent/InnerTube.java | 29 ++----------------- .../MotorConfigurationPanel.java | 4 +-- 4 files changed, 12 insertions(+), 33 deletions(-) rename core/src/net/sf/openrocket/{rocketcomponent => motor}/MotorConfigurationSet.java (91%) diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java similarity index 91% rename from core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java rename to core/src/net/sf/openrocket/motor/MotorConfigurationSet.java index 3d12176e4..0ff5a53f9 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java @@ -1,6 +1,9 @@ -package net.sf.openrocket.rocketcomponent; +package net.sf.openrocket.motor; -import net.sf.openrocket.motor.MotorInstance; +import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; +import net.sf.openrocket.rocketcomponent.FlightConfigurationID; +import net.sf.openrocket.rocketcomponent.ParameterSet; +import net.sf.openrocket.rocketcomponent.RocketComponent; /** * FlightConfigurationSet for motors. diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 2b054abd2..59cf000a3 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -6,6 +6,7 @@ import java.util.Iterator; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Motor; +import net.sf.openrocket.motor.MotorConfigurationSet; import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.startup.Application; @@ -373,8 +374,8 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ - if( null == newMotorInstance){ - throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug "); + if((null == newMotorInstance)||(newMotorInstance.equals( MotorInstance.EMPTY_INSTANCE ))){ + this.motors.set( fcid, null); }else{ if( null == newMotorInstance.getMount()){ newMotorInstance.setMount(this); diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 63dac0898..c5e828188 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Motor; +import net.sf.openrocket.motor.MotorConfigurationSet; import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.startup.Application; @@ -237,30 +238,6 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra return newArray; } -// @Override -// public Coordinate[] getLocations(){ -// if (null == this.parent) { -// throw new BugException(" Attempted to get absolute position Vector of a Stage without a parent. "); -// } -// -// final Coordinate center = parentInstances[0].add( this.position); -// Coordinate[] instanceLocations = this.getInstanceOffsets(); -// Coordinate[] toReturn = new Coordinate[ instanceLocations.length]; -// for( int i = 0; i < toReturn.length; i++){ -// toReturn[i] = center.add( instanceLocations[i]); -// } -// -// return toReturn; -// -// Coordinate[] parentInstances = this.parent.getLocations(); -// for( int i=0; i< parentInstances.length; i++){ -// parentInstances[i] = parentInstances[i].add( this.position ); -// } -// Coordinate[] toReturn = this.shiftCoordinates(parentInstances); -// -// return toReturn; -// } - // @Override // protected Coordinate[] shiftCoordinates(Coordinate[] array) { // array = super.shiftCoordinates(array); @@ -298,8 +275,8 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra @Override public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ - if( null == newMotorInstance){ - throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug "); + if((null == newMotorInstance)||(newMotorInstance.equals( MotorInstance.EMPTY_INSTANCE ))){ + this.motors.set( fcid, null); }else{ if( null == newMotorInstance.getMount()){ newMotorInstance.setMount(this); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 15e1c3b5f..027d9185b 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -236,9 +236,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel return; } - - MotorInstance curInstance = MotorInstance.EMPTY_INSTANCE; - curMount.setMotorInstance( fcid, curInstance); + curMount.setMotorInstance( fcid, null); fireTableDataChanged(); }