[Bugfix] Fixed some FlightConfiguration-related UI elements

- Removed configuration from the document class -- please retrieve it from the rocket instead
- Refined debug code points, particularly in InnerTube
- Fixed <RocketComponent>.removeChild( component ) to function correctly
- fixed UI element: FlightConfiguration ComboBox chooser
    - Renamed FlightConfigurationSet -> ParameterSet
    - FlightConfigurationModel -> ParamaterSetModel
- fixed engine drawing (partially. Still needs Testing.
This commit is contained in:
Daniel_M_Williams 2015-10-22 20:13:36 -04:00
parent 6b322a610f
commit 3ae4b0d277
25 changed files with 365 additions and 361 deletions

View File

@ -62,7 +62,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
private static boolean undoErrorReported = false; private static boolean undoErrorReported = false;
private final Rocket rocket; private final Rocket rocket;
private final FlightConfiguration configuration;
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>(); private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>(); private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
@ -104,7 +103,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
private final List<DocumentChangeListener> listeners = new ArrayList<DocumentChangeListener>(); private final List<DocumentChangeListener> listeners = new ArrayList<DocumentChangeListener>();
OpenRocketDocument(Rocket rocket) { OpenRocketDocument(Rocket rocket) {
this.configuration = rocket.getDefaultConfiguration();
this.rocket = rocket; this.rocket = rocket;
init(); init();
} }
@ -166,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
public FlightConfiguration getDefaultConfiguration() { public FlightConfiguration getDefaultConfiguration() {
return configuration; return rocket.getDefaultConfiguration();
} }
public File getFile() { public File getFile() {

View File

@ -12,7 +12,7 @@ import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler; import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.ParameterSet;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
class MotorConfigurationHandler extends AbstractElementHandler { class MotorConfigurationHandler extends AbstractElementHandler {
@ -64,7 +64,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
if ("true".equals(attributes.remove("default"))) { if ("true".equals(attributes.remove("default"))) {
// associate this configuration with both this FCID and the default. // associate this configuration with both this FCID and the default.
FlightConfigurationSet<FlightConfiguration> fcs = rocket.getConfigurationSet(); ParameterSet<FlightConfiguration> fcs = rocket.getConfigurationSet();
FlightConfiguration fc = fcs.get(fcid); FlightConfiguration fc = fcs.get(fcid);
fcs.setDefault(fc); fcs.setDefault(fc);
} }

View File

@ -7,7 +7,7 @@ import java.util.Locale;
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.ParameterSet;
import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -37,7 +37,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
//dev.getDeploymentConfigurations().printDebug(); //dev.getDeploymentConfigurations().printDebug();
// DEBUG // DEBUG
FlightConfigurationSet<FlightConfiguration> configList = rocket.getConfigurationSet(); ParameterSet<FlightConfiguration> configList = rocket.getConfigurationSet();
for (FlightConfigurationID fcid : configList.getSortedConfigurationIDs()) { for (FlightConfigurationID fcid : configList.getSortedConfigurationIDs()) {
//System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?"); //System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?");

View File

@ -17,7 +17,7 @@ import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.ParameterSet;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -148,7 +148,7 @@ public class RocketComponentSaver {
return Collections.emptyList(); return Collections.emptyList();
//FlightConfigurationID[] motorConfigIDs = ((RocketComponent) mount).getRocket().getFlightConfigurationIDs(); //FlightConfigurationID[] motorConfigIDs = ((RocketComponent) mount).getRocket().getFlightConfigurationIDs();
FlightConfigurationSet<FlightConfiguration> configs = ((RocketComponent) mount).getRocket().getConfigurationSet(); ParameterSet<FlightConfiguration> configs = ((RocketComponent) mount).getRocket().getConfigurationSet();
List<String> elements = new ArrayList<String>(); List<String> elements = new ArrayList<String>();
MotorInstance defaultInstance = mount.getDefaultMotorInstance(); MotorInstance defaultInstance = mount.getDefaultMotorInstance();

View File

@ -6,7 +6,7 @@ import java.util.Locale;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.ParameterSet;
import net.sf.openrocket.rocketcomponent.ReferenceType; import net.sf.openrocket.rocketcomponent.ReferenceType;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -43,7 +43,7 @@ public class RocketSaver extends RocketComponentSaver {
// Motor configurations // Motor configurations
FlightConfigurationSet<FlightConfiguration> allConfigs = rocket.getConfigurationSet(); ParameterSet<FlightConfiguration> allConfigs = rocket.getConfigurationSet();
for (FlightConfigurationID fcid : allConfigs.getSortedConfigurationIDs()) { for (FlightConfigurationID fcid : allConfigs.getSortedConfigurationIDs()) {
FlightConfiguration flightConfig = allConfigs.get(fcid); FlightConfiguration flightConfig = allConfigs.get(fcid);
if (fcid == null) if (fcid == null)

View File

@ -12,12 +12,12 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
//private static final Logger log = LoggerFactory.getLogger(AxialStage.class); //private static final Logger log = LoggerFactory.getLogger(AxialStage.class);
protected FlightConfigurationSet<StageSeparationConfiguration> separationConfigurations; protected ParameterSet<StageSeparationConfiguration> separationConfigurations;
protected int stageNumber; protected int stageNumber;
public AxialStage(){ public AxialStage(){
this.separationConfigurations = new FlightConfigurationSet<StageSeparationConfiguration>( this.separationConfigurations = new ParameterSet<StageSeparationConfiguration>(
this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration()); this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration());
this.relativePosition = Position.AFTER; this.relativePosition = Position.AFTER;
this.stageNumber = 0; this.stageNumber = 0;
@ -34,7 +34,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
return trans.get("Stage.Stage"); return trans.get("Stage.Stage");
} }
public FlightConfigurationSet<StageSeparationConfiguration> getSeparationConfigurations() { public ParameterSet<StageSeparationConfiguration> getSeparationConfigurations() {
return separationConfigurations; return separationConfigurations;
} }
@ -80,7 +80,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
@Override @Override
protected RocketComponent copyWithOriginalID() { protected RocketComponent copyWithOriginalID() {
AxialStage copy = (AxialStage) super.copyWithOriginalID(); AxialStage copy = (AxialStage) super.copyWithOriginalID();
copy.separationConfigurations = new FlightConfigurationSet<StageSeparationConfiguration>(separationConfigurations, copy.separationConfigurations = new ParameterSet<StageSeparationConfiguration>(separationConfigurations,
copy, ComponentChangeEvent.EVENT_CHANGE); copy, ComponentChangeEvent.EVENT_CHANGE);
return copy; return copy;
} }

View File

@ -462,8 +462,8 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang()); return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang());
} }
public void printMotorDebug(){ public String toMotorDebug(){
this.motors.printDebug(); return this.motors.toDebug();
} }
@Override @Override

View File

@ -114,7 +114,7 @@ public class BoosterSet extends AxialStage implements FlightConfigurableComponen
// there must be at least one instance.... // there must be at least one instance....
return; return;
} }
System.err.println("?! Setting BoosterSet instance count to: "+newCount );
this.count = newCount; this.count = newCount;
this.angularSeparation = Math.PI * 2 / this.count; this.angularSeparation = Math.PI * 2 / this.count;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);

View File

@ -184,14 +184,10 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return toReturn; return toReturn;
} }
public List<MotorInstance> getActiveMotors() { public List<MotorInstance> getActiveMotors() {
ArrayList<MotorInstance> toReturn = new ArrayList<MotorInstance>(); ArrayList<MotorInstance> toReturn = new ArrayList<MotorInstance>();
for ( RocketComponent comp : this.getActiveComponents() ){ for ( RocketComponent comp : this.getActiveComponents() ){
// DEVEL
if (!this.isComponentActive(comp)){
log.error( "Detected inactive component in list returned from <config>.getActiveComponents()");
}
// DEVEL
// see planning notes... // see planning notes...
if ( comp instanceof MotorMount ){ if ( comp instanceof MotorMount ){
@ -223,7 +219,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
} }
System.err.println("returning "+toReturn.size()+" active motor instances for this configuration: "+this.fcid.getShortKey());
System.err.println(this.rocket.getConfigurationSet().toDebug());
return toReturn; return toReturn;
} }
@ -368,7 +365,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
// DEBUG / DEVEL // DEBUG / DEVEL
public String toDebugDetail() { public String toStageListDetail() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(String.format("\nDumping stage config: \n")); buf.append(String.format("\nDumping stage config: \n"));
for (StageFlags flags : this.stageMap.values()) { for (StageFlags flags : this.stageMap.values()) {
@ -492,5 +489,4 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
} }
} }

View File

@ -12,11 +12,11 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
private final static String ERROR_CONFIGURATION_KEYTEXT = "error_key_2489"; private final static String ERROR_CONFIGURATION_KEYTEXT = "error_key_2489";
// private final static String DEFAULT_CONFIGURATION_KEYTEXT = "default_configuration_6602"; // private final static String DEFAULT_CONFIGURATION_KEYTEXT = "default_configuration_6602";
// private final static String DEFAULT_VALUE_KEYTEXT = "default_value_5676"; private final static String DEFAULT_VALUE_KEYTEXT = "default_value_5676";
public final static FlightConfigurationID ERROR_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT); public final static FlightConfigurationID ERROR_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT);
// public final static FlightConfigurationID DEFAULT_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEYTEXT ); // public final static FlightConfigurationID DEFAULT_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEYTEXT );
// public final static FlightConfigurationID DEFAULT_VALUE_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_VALUE_KEYTEXT ); public final static FlightConfigurationID DEFAULT_VALUE_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_VALUE_KEYTEXT );
public FlightConfigurationID() { public FlightConfigurationID() {
this(UUID.randomUUID().toString()); this(UUID.randomUUID().toString());

View File

@ -1,35 +1,12 @@
package net.sf.openrocket.rocketcomponent; package net.sf.openrocket.rocketcomponent;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.util.StateChangeListener;
import net.sf.openrocket.util.Utils;
/** /**
* An implementation of FlightConfiguration that fires off events * An implementation of FlightConfiguration that fires off events
* to the rocket components when the parameter value is changed. * to the rocket components when the parameter value is changed.
* *
* @param <E> the parameter type * @param <E> the parameter type
*/ */
public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> { public class FlightConfigurationSet extends ParameterSet<FlightConfiguration> {
private static final Logger log = LoggerFactory.getLogger(FlightConfigurationSet.class);
protected final HashMap<FlightConfigurationID, E> map = new HashMap<FlightConfigurationID, E>();
protected E defaultValue;
protected final RocketComponent component;
protected final int eventType;
private final Listener listener = new Listener();
/** /**
* Construct a FlightConfiguration that has no overrides. * Construct a FlightConfiguration that has no overrides.
@ -37,212 +14,19 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
* @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 FlightConfigurationSet(RocketComponent component, int eventType, E _defaultValue) { public FlightConfigurationSet( RocketComponent component, int eventType, FlightConfiguration _defaultValue) {
this.component = component; super( component, eventType, _defaultValue);
this.eventType = eventType;
this.defaultValue= _defaultValue;
addListener(_defaultValue);
} }
/** /**
* Construct a copy of an existing FlightConfigurationImpl. * Construct a copy of an existing FlightConfigurationSet
* *
* @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 FlightConfigurationSet(FlightConfigurationSet<E> flightConfiguration, RocketComponent component, int eventType) { public FlightConfigurationSet(FlightConfigurationSet configSet, RocketComponent component, int eventType) {
this.component = component; super( configSet, component, eventType );
this.eventType = eventType;
this.defaultValue= flightConfiguration.getDefault().clone();
for (FlightConfigurationID key : flightConfiguration.map.keySet()) {
this.map.put(key, flightConfiguration.map.get(key).clone());
}
}
public boolean containsKey( final FlightConfigurationID fcid ){
return this.map.containsKey(fcid);
}
@Override
public E getDefault(){
return this.defaultValue;
}
@Override
public void setDefault(E nextDefaultValue) {
if (nextDefaultValue == null) {
throw new NullPointerException("new Default Value is null");
}
if( this.isDefault(nextDefaultValue)){
return;
}
this.defaultValue = nextDefaultValue;
}
@Override
public Iterator<E> iterator() {
return map.values().iterator();
}
@Override
public int 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
public E get(FlightConfigurationID id) {
E toReturn;
if (map.containsKey(id)) {
toReturn = map.get(id);
} else {
toReturn = this.getDefault();
}
return toReturn;
}
@Override
public List<FlightConfigurationID> getSortedConfigurationIDs(){
Vector<FlightConfigurationID> toReturn = new Vector<FlightConfigurationID>();
toReturn.addAll( this.map.keySet() );
toReturn.sort( null );
return toReturn;
}
public List<FlightConfigurationID> getIDs(){
return this.getSortedConfigurationIDs();
}
@Override
public void set(FlightConfigurationID fcid, E nextValue) {
if (null == fcid) {
throw new NullPointerException("id is null");
}else if( !fcid.isValid()){
throw new IllegalStateException(" Attempt to reset the default value on with an invalid key: "+fcid.toString());
}
if ( nextValue == null) {
// null value means to delete this fcid
E previousValue = map.remove(fcid);
removeListener(previousValue);
}else{
E previousValue = map.put(fcid, nextValue);
removeListener(previousValue);
addListener(nextValue);
}
fireEvent();
}
public boolean isDefault(E testVal) {
return (Utils.equals( this.getDefault(), testVal));
}
@Override
public boolean isDefault( FlightConfigurationID fcid) {
return ( this.getDefault() == this.map.get(fcid));
}
@Override
public void reset( FlightConfigurationID fcid) {
// enforce at least one value in the set
if( 1 < this.map.size() ){
set( fcid, null);
}else{
log.warn(" attempted to remove last element from the FlightConfigurationSet<"+this.getDefault().getClass().getSimpleName()+"> attached to: "+component.getName()+". Ignoring. ");
return;
}
}
private void fireEvent() {
component.fireComponentChangeEvent(eventType);
}
@Override
public void cloneFlightConfiguration(FlightConfigurationID oldConfigId, FlightConfigurationID newConfigId) {
// clones the ENTRIES for the given fcid's.
E oldValue = this.get(oldConfigId);
this.set(newConfigId, oldValue.clone());
fireEvent();
}
private void addListener(E value) {
if (value != null) {
value.addChangeListener(listener);
}
}
private void removeListener(E value) {
if (value != null) {
value.removeChangeListener(listener);
}
}
private class Listener implements StateChangeListener {
@Override
public void stateChanged(EventObject e) {
fireEvent();
}
}
public void printDebug(){
System.err.println("====== Dumping ConfigurationSet for comp: '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======");
System.err.println(" >> FlightConfigurationSet ("+this.size()+ " configurations)");
if( 0 == this.size() ){
String designation = "";
E inst = this.getDefault();
if( inst instanceof FlightConfiguration){
designation = ((FlightConfiguration) inst).getFlightConfigurationID().getShortKey();
}else{
designation = inst.toString();
}
System.err.println(" ( DEFAULT_VALUE = "+designation + ")");
}
for( FlightConfigurationID loopFCID : this.getSortedConfigurationIDs()){
String shortKey = loopFCID.getShortKey();
String designation = "";
E inst = this.map.get(loopFCID);
if( inst instanceof FlightConfiguration){
FlightConfiguration fc = (FlightConfiguration) inst;
designation = ( fc.isNameOverridden() ? "" : fc.getName());
}else{
designation = inst.toString();
}
if( this.isDefault(inst)){
shortKey = "*"+shortKey+"*";
}
System.err.println(" >> ["+shortKey+"]= "+designation);
}
} }
} }

View File

@ -383,7 +383,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
} }
public void printMotorDebug( FlightConfigurationID fcid ){ public void printMotorDebug( FlightConfigurationID fcid ){
this.motors.printDebug(); System.err.println(this.motors.toDebug());
} }
@Override @Override
@ -393,26 +393,29 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
Coordinate[] relCoords = this.shiftCoordinates(new Coordinate[] { Coordinate.ZERO }); Coordinate[] relCoords = this.shiftCoordinates(new Coordinate[] { Coordinate.ZERO });
Coordinate[] absCoords = this.getLocations(); Coordinate[] absCoords = this.getLocations();
FlightConfigurationID curId = this.getRocket().getDefaultConfiguration().getFlightConfigurationID();
int count = this.getInstanceCount(); int count = this.getInstanceCount();
MotorInstance curInstance = this.motors.get(curId);
if( curInstance.isEmpty() ){
// print just the tube locations
buffer.append(prefix+" [X] This Instance doesn't have any motors... showing mount tubes only\n");
for (int instanceNumber = 0; instanceNumber < count; instanceNumber++) { for (int instanceNumber = 0; instanceNumber < count; instanceNumber++) {
Coordinate instanceRelativePosition = relCoords[instanceNumber]; Coordinate instanceRelativePosition = relCoords[instanceNumber];
Coordinate instanceAbsolutePosition = absCoords[instanceNumber]; Coordinate instanceAbsolutePosition = absCoords[instanceNumber];
buffer.append(String.format("%s [instance %2d / %2d] %28s %28s\n", prefix, instanceNumber, count, buffer.append(String.format("%s [%2d / %2d] %28s %28s\n", prefix, instanceNumber, count,
instanceRelativePosition, instanceAbsolutePosition));
}
if( this.hasMotor()){
MotorInstance curInstance = this.getMotorInstance(null);
Motor curMotor = curInstance.getMotor();
buffer.append(String.format("%s %-24s (cluster: %s)", prefix, curMotor.getDesignation(), this.getPatternName()));
for (int instanceNumber = 0; instanceNumber < count; instanceNumber++) {
Coordinate instanceRelativePosition = relCoords[instanceNumber];
Coordinate instanceAbsolutePosition = absCoords[instanceNumber];
buffer.append(String.format("%s [MotorInstance %2d / %2d] %28s %28s\n", prefix, instanceNumber, count,
instanceRelativePosition, instanceAbsolutePosition)); instanceRelativePosition, instanceAbsolutePosition));
} }
}else{ }else{
buffer.append(prefix+" [X] This Instance doesn't have any motors.\n"); // curInstance has a motor ...
Motor curMotor = curInstance.getMotor();
buffer.append(String.format("%s %-24s (in cluster: %s)\n", prefix, curMotor.getDesignation(), this.getPatternName()));
for (int instanceNumber = 0; instanceNumber < count; instanceNumber++) {
Coordinate instanceRelativePosition = relCoords[instanceNumber];
Coordinate instanceAbsolutePosition = absCoords[instanceNumber];
buffer.append(String.format("%s [%2d / %2d] %28s %28s\n", prefix, instanceNumber, count,
instanceRelativePosition, instanceAbsolutePosition));
}
} }
} }

View File

@ -6,7 +6,7 @@ import net.sf.openrocket.motor.MotorInstance;
* FlightConfigurationSet for motors. * FlightConfigurationSet for motors.
* This is used for motors, where the default value is always no motor. * This is used for motors, where the default value is always no motor.
*/ */
public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance> { public class MotorConfigurationSet extends ParameterSet<MotorInstance> {
public static final int DEFAULT_EVENT_TYPE = ComponentChangeEvent.MOTOR_CHANGE | ComponentChangeEvent.EVENT_CHANGE; public static final int DEFAULT_EVENT_TYPE = ComponentChangeEvent.MOTOR_CHANGE | ComponentChangeEvent.EVENT_CHANGE;
@ -21,7 +21,7 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
* @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(FlightConfigurationSet<MotorInstance> flightConfiguration, RocketComponent component, int eventType) { public MotorConfigurationSet(ParameterSet<MotorInstance> flightConfiguration, RocketComponent component, int eventType) {
super(flightConfiguration, component, eventType); super(flightConfiguration, component, eventType);
} }
@ -32,9 +32,10 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
} }
@Override @Override
public void printDebug(){ public String toDebug(){
System.err.println("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======"); StringBuilder buffer = new StringBuilder();
System.err.println(" >> motorSet ("+this.size()+ " motors)"); buffer.append("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======");
buffer.append(" >> motorSet ("+this.size()+ " motors)");
for( FlightConfigurationID loopFCID : this.map.keySet()){ for( FlightConfigurationID loopFCID : this.map.keySet()){
String shortKey = loopFCID.getShortKey(); String shortKey = loopFCID.getShortKey();
@ -46,9 +47,9 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
}else{ }else{
designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay()); designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay());
} }
System.err.println(" >> ["+shortKey+"]= "+designation); buffer.append(" >> ["+shortKey+"]= "+designation);
} }
return buffer.toString();
} }
// public void printDebug(FlightConfigurationID curFCID){ // public void printDebug(FlightConfigurationID curFCID){

View File

@ -0,0 +1,233 @@
package net.sf.openrocket.rocketcomponent;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.util.StateChangeListener;
import net.sf.openrocket.util.Utils;
/**
* An implementation of FlightConfiguration that fires off events
* to the rocket components when the parameter value is changed.
*
* @param <E> the parameter type
*/
public class ParameterSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> {
private static final Logger log = LoggerFactory.getLogger(ParameterSet.class);
protected final HashMap<FlightConfigurationID, E> map = new HashMap<FlightConfigurationID, E>();
protected E defaultValue;
protected final RocketComponent component;
protected final int eventType;
private final Listener listener = new Listener();
/**
* Construct a FlightConfiguration that has no overrides.
*
* @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 ParameterSet(RocketComponent component, int eventType, E _defaultValue) {
this.component = component;
this.eventType = eventType;
this.defaultValue= _defaultValue;
addListener(_defaultValue);
}
/**
* Construct a copy of an existing FlightConfigurationImpl.
*
* @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 ParameterSet(ParameterSet<E> flightConfiguration, RocketComponent component, int eventType) {
this.component = component;
this.eventType = eventType;
this.defaultValue= flightConfiguration.getDefault().clone();
for (FlightConfigurationID key : flightConfiguration.map.keySet()) {
this.map.put(key, flightConfiguration.map.get(key).clone());
}
}
public boolean containsKey( final FlightConfigurationID fcid ){
return this.map.containsKey(fcid);
}
@Override
public E getDefault(){
return this.defaultValue;
}
@Override
public void setDefault(E nextDefaultValue) {
if (nextDefaultValue == null) {
throw new NullPointerException("new Default Value is null");
}
if( this.isDefault(nextDefaultValue)){
return;
}
this.defaultValue = nextDefaultValue;
}
@Override
public Iterator<E> iterator() {
return map.values().iterator();
}
@Override
public int 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
public E get(FlightConfigurationID id) {
E toReturn;
if (map.containsKey(id)) {
toReturn = map.get(id);
} else {
toReturn = this.getDefault();
}
return toReturn;
}
@Override
public List<FlightConfigurationID> getSortedConfigurationIDs(){
Vector<FlightConfigurationID> toReturn = new Vector<FlightConfigurationID>();
toReturn.addAll( this.map.keySet() );
toReturn.sort( null );
return toReturn;
}
public List<FlightConfigurationID> getIDs(){
return this.getSortedConfigurationIDs();
}
@Override
public void set(FlightConfigurationID fcid, E nextValue) {
if (null == fcid) {
throw new NullPointerException("id is null");
}else if( !fcid.isValid()){
throw new IllegalStateException(" Attempt to reset the default value on with an invalid key: "+fcid.toString());
}
if ( nextValue == null) {
// null value means to delete this fcid
E previousValue = map.remove(fcid);
removeListener(previousValue);
}else{
E previousValue = map.put(fcid, nextValue);
removeListener(previousValue);
addListener(nextValue);
}
fireEvent();
}
public boolean isDefault(E testVal) {
return (Utils.equals( this.getDefault(), testVal));
}
@Override
public boolean isDefault( FlightConfigurationID fcid) {
return ( this.getDefault() == this.map.get(fcid));
}
@Override
public void reset( FlightConfigurationID fcid) {
// enforce at least one value in the set
if( 1 < this.map.size() ){
set( fcid, null);
}else{
log.warn(" attempted to remove last element from the FlightConfigurationSet<"+this.getDefault().getClass().getSimpleName()+"> attached to: "+component.getName()+". Ignoring. ");
return;
}
}
private void fireEvent() {
component.fireComponentChangeEvent(eventType);
}
@Override
public void cloneFlightConfiguration(FlightConfigurationID oldConfigId, FlightConfigurationID newConfigId) {
// clones the ENTRIES for the given fcid's.
E oldValue = this.get(oldConfigId);
this.set(newConfigId, oldValue.clone());
fireEvent();
}
private void addListener(E value) {
if (value != null) {
value.addChangeListener(listener);
}
}
private void removeListener(E value) {
if (value != null) {
value.removeChangeListener(listener);
}
}
private class Listener implements StateChangeListener {
@Override
public void stateChanged(EventObject e) {
fireEvent();
}
}
public String toDebug(){
StringBuilder buf = new StringBuilder();
buf.append(String.format("====== Dumping ConfigurationSet for: '%s' of type: %s ======\n", this.component.getName(), this.component.getClass().getSimpleName() ));
buf.append(String.format(" >> FlightConfigurationSet (%d configurations)\n", this.size() ));
if( 0 == this.map.size() ){
buf.append(String.format(" >> [%s]= %s\n", "*DEFAULT*", this.getDefault().toString() ));
}else{
for( FlightConfigurationID loopFCID : this.getSortedConfigurationIDs()){
String shortKey = loopFCID.getShortKey();
E inst = this.map.get(loopFCID);
if( this.isDefault(inst)){
shortKey = "*"+shortKey+"*";
}
buf.append(String.format(" >> [%s]= %s\n", shortKey, inst.toString() ));
}
}
return buf.toString();
}
}

View File

@ -25,10 +25,10 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
private Material.Surface material; private Material.Surface material;
private FlightConfigurationSet<DeploymentConfiguration> deploymentConfigurations; private ParameterSet<DeploymentConfiguration> deploymentConfigurations;
public RecoveryDevice() { public RecoveryDevice() {
this.deploymentConfigurations = new FlightConfigurationSet<DeploymentConfiguration>(this, ComponentChangeEvent.EVENT_CHANGE, new DeploymentConfiguration()); this.deploymentConfigurations = new ParameterSet<DeploymentConfiguration>(this, ComponentChangeEvent.EVENT_CHANGE, new DeploymentConfiguration());
setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE)); setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE));
} }
@ -85,7 +85,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }
public FlightConfigurationSet<DeploymentConfiguration> getDeploymentConfigurations() { public ParameterSet<DeploymentConfiguration> getDeploymentConfigurations() {
return deploymentConfigurations; return deploymentConfigurations;
} }
@ -113,7 +113,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
@Override @Override
protected RocketComponent copyWithOriginalID() { protected RocketComponent copyWithOriginalID() {
RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID(); RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID();
copy.deploymentConfigurations = new FlightConfigurationSet<DeploymentConfiguration>(deploymentConfigurations, copy.deploymentConfigurations = new ParameterSet<DeploymentConfiguration>(deploymentConfigurations,
copy, ComponentChangeEvent.EVENT_CHANGE); copy, ComponentChangeEvent.EVENT_CHANGE);
return copy; return copy;
} }

View File

@ -66,7 +66,7 @@ public class Rocket extends RocketComponent {
// Flight configuration list // Flight configuration list
private FlightConfigurationSet<FlightConfiguration> configurations; private FlightConfigurationSet configSet;
// Does the rocket have a perfect finish (a notable amount of laminar flow) // Does the rocket have a perfect finish (a notable amount of laminar flow)
private boolean perfectFinish = false; private boolean perfectFinish = false;
@ -84,7 +84,7 @@ public class Rocket extends RocketComponent {
functionalModID = modID; functionalModID = modID;
FlightConfiguration defaultConfiguration = new FlightConfiguration( null, this); FlightConfiguration defaultConfiguration = new FlightConfiguration( null, this);
this.configurations = new FlightConfigurationSet<FlightConfiguration>(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration); this.configSet = new FlightConfigurationSet(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration);
} }
public String getDesigner() { public String getDesigner() {
@ -281,8 +281,8 @@ public class Rocket extends RocketComponent {
@Override @Override
public Rocket copyWithOriginalID() { public Rocket copyWithOriginalID() {
Rocket copy = (Rocket) super.copyWithOriginalID(); Rocket copy = (Rocket) super.copyWithOriginalID();
copy.configurations = new FlightConfigurationSet<FlightConfiguration>( copy.configSet = new FlightConfigurationSet(
this.configurations, copy, ComponentChangeEvent.ALL_CHANGE); this.configSet, copy, ComponentChangeEvent.ALL_CHANGE);
copy.resetListeners(); copy.resetListeners();
return copy; return copy;
@ -319,8 +319,8 @@ public class Rocket extends RocketComponent {
this.refType = r.refType; this.refType = r.refType;
this.customReferenceLength = r.customReferenceLength; this.customReferenceLength = r.customReferenceLength;
this.configurations = new FlightConfigurationSet<FlightConfiguration>( this.configSet = new FlightConfigurationSet(
r.configurations, this, ComponentChangeEvent.ALL_CHANGE); r.configSet, this, ComponentChangeEvent.ALL_CHANGE);
this.perfectFinish = r.perfectFinish; this.perfectFinish = r.perfectFinish;
this.checkComponentStructure(); this.checkComponentStructure();
@ -499,17 +499,17 @@ public class Rocket extends RocketComponent {
*/ */
public FlightConfiguration getDefaultConfiguration() { public FlightConfiguration getDefaultConfiguration() {
checkState(); checkState();
return this.configurations.getDefault(); return this.configSet.getDefault();
} }
public FlightConfiguration createFlightConfiguration( final FlightConfigurationID fcid) { public FlightConfiguration createFlightConfiguration( final FlightConfigurationID fcid) {
checkState(); checkState();
FlightConfiguration nextConfig = null; FlightConfiguration nextConfig = null;
if( configurations.containsKey(fcid)){ if( configSet.containsKey(fcid)){
nextConfig = this.configurations.get(fcid); nextConfig = this.configSet.get(fcid);
}else{ }else{
nextConfig = new FlightConfiguration(fcid, this); nextConfig = new FlightConfiguration(fcid, this);
this.configurations.set(fcid, nextConfig); this.configSet.set(fcid, nextConfig);
} }
this.setFlightConfiguration( fcid, nextConfig ); this.setFlightConfiguration( fcid, nextConfig );
@ -518,16 +518,16 @@ public class Rocket extends RocketComponent {
} }
public int getConfigurationCount(){ public int getConfigurationCount(){
return this.configurations.size(); return this.configSet.size();
} }
public FlightConfigurationSet<FlightConfiguration> getConfigurationSet(){ public ParameterSet<FlightConfiguration> getConfigurationSet(){
checkState(); checkState();
return this.configurations; return this.configSet;
} }
public List<FlightConfigurationID> getSortedConfigurationIDs(){ public List<FlightConfigurationID> getSortedConfigurationIDs(){
return configurations.getSortedConfigurationIDs(); return configSet.getSortedConfigurationIDs();
} }
@ -543,7 +543,7 @@ public class Rocket extends RocketComponent {
return; return;
// Get current configuration: // Get current configuration:
this.configurations.set(fcid, null); this.configSet.set(fcid, null);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@ -556,7 +556,7 @@ public class Rocket extends RocketComponent {
*/ */
public boolean containsFlightConfigurationID(FlightConfigurationID id) { public boolean containsFlightConfigurationID(FlightConfigurationID id) {
checkState(); checkState();
FlightConfiguration config = configurations.get( id); FlightConfiguration config = configSet.get( id);
return (null != config); return (null != config);
} }
@ -597,7 +597,7 @@ public class Rocket extends RocketComponent {
*/ */
public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) { public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) {
checkState(); checkState();
return this.configurations.get(id); return this.configSet.get(id);
} }
@ -614,7 +614,7 @@ public class Rocket extends RocketComponent {
// silently ignore // silently ignore
return; return;
}else{ }else{
configurations.set(fcid, newConfig); configSet.set(fcid, newConfig);
} }
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
} }

View File

@ -1358,25 +1358,15 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/** /**
* Removes a child from the rocket component tree. * Removes a child from the rocket component tree.
* (redirect to the removed-by-component
* *
* @param n remove the n'th child. * @param n remove the n'th child.
* @throws IndexOutOfBoundsException if n is out of bounds * @throws IndexOutOfBoundsException if n is out of bounds
*/ */
public final void removeChild(int n) { public final void removeChild(int n) {
checkState(); checkState();
RocketComponent component = children.remove(n); RocketComponent component = this.getChild(n);
component.parent = null; this.removeChild(component);
if (component instanceof AxialStage) {
AxialStage nStage = (AxialStage) component;
this.getRocket().forgetStage(nStage);
}
this.checkComponentStructure();
component.checkComponentStructure();
updateBounds();
fireAddRemoveEvent(component);
} }
/** /**
@ -1391,9 +1381,15 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
component.checkComponentStructure(); component.checkComponentStructure();
if (children.remove(component)) { if (children.remove(component)) {
component.parent = null; component.parent = null;
if (component instanceof AxialStage) {
AxialStage stage = (AxialStage) component;
this.getRocket().forgetStage(stage);
}
this.checkComponentStructure(); this.checkComponentStructure();
component.checkComponentStructure(); component.checkComponentStructure();

View File

@ -191,7 +191,7 @@ public class ConfigurationTest extends BaseTestCase {
// test explicitly setting all stages up to second stage active // test explicitly setting all stages up to second stage active
config.setOnlyStage(1); config.setOnlyStage(1);
assertThat(config.toDebugDetail() + "Setting single stage active: ", config.isStageActive(1), equalTo(true)); assertThat(config.toStageListDetail() + "Setting single stage active: ", config.isStageActive(1), equalTo(true));
config.clearOnlyStage(0); config.clearOnlyStage(0);
assertThat(" deactivate stage #0: ", config.isStageActive(0), equalTo(false)); assertThat(" deactivate stage #0: ", config.isStageActive(0), equalTo(false));

View File

@ -7,8 +7,6 @@ import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel; import javax.swing.ComboBoxModel;
import javax.swing.MutableComboBoxModel; import javax.swing.MutableComboBoxModel;
import org.jfree.util.Log;
import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.ChangeSource;
import net.sf.openrocket.util.Reflection; import net.sf.openrocket.util.Reflection;
import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.StateChangeListener;
@ -132,8 +130,6 @@ public class EnumModel<T extends Enum<T>> extends AbstractListModel
} }
} }
@Override @Override
public String toString() { public String toString() {
return "EnumModel["+source.getClass().getCanonicalName()+":"+valueName+"]"; return "EnumModel["+source.getClass().getCanonicalName()+":"+valueName+"]";

View File

@ -11,55 +11,54 @@ import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener; import javax.swing.event.ListDataListener;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameter;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.ParameterSet;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.StateChangeListener;
/** /**
* A ComboBoxModel that contains a list of flight configurations. The list can * A ComboBoxModel that contains a list of flight configurations. The list can
* optionally contain a last element that opens up the configuration edit dialog. * optionally contain a last element that opens up the configuration edit dialog.
*/ */
public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurationID>, StateChangeListener { public class ParameterSetModel<T extends FlightConfigurableParameter<T>> implements ComboBoxModel<FlightConfigurationID>, StateChangeListener {
//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 EventListenerList listenerList = new EventListenerList(); private EventListenerList listenerList = new EventListenerList();
private FlightConfiguration config; private T selected;
private final Rocket rocket; private final ParameterSet<T> sourceSet;
List<FlightConfigurationID> ids= new Vector<FlightConfigurationID>(); List<FlightConfigurationID> idList= new Vector<FlightConfigurationID>();
public FlightConfigurationModel(FlightConfiguration config) { public ParameterSetModel(ParameterSet<T> set ) {
this.config = config; this.sourceSet = set;
this.rocket = config.getRocket(); this.selected = this.sourceSet.getDefault();
config.addChangeListener(this);
} }
@Override @Override
public FlightConfigurationID getElementAt(int index) { public FlightConfigurationID getElementAt(int index) {
this.ids = rocket.getSortedConfigurationIDs();
this.idList = this.sourceSet.getSortedConfigurationIDs();
if (index < 0){ if (index < 0){
return FlightConfigurationID.ERROR_CONFIGURATION_FCID; return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
}else if ( index >= this.ids.size()){ }else if ( index >= this.idList.size()){
return FlightConfigurationID.ERROR_CONFIGURATION_FCID; return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
} }
return this.ids.get(index); return this.idList.get(index);
} }
@Override @Override
public int getSize() { public int getSize() {
return this.ids.size(); this.idList = this.sourceSet.getSortedConfigurationIDs();
return this.idList.size();
} }
@Override @Override
public Object getSelectedItem() { public Object getSelectedItem() {
return config.getFlightConfigurationID(); return selected;
} }
@Override @Override
@ -68,14 +67,13 @@ public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurati
// Clear selection - huh? // Clear selection - huh?
return; return;
} }
if (!(item instanceof FlightConfigurationID)) { if (!(item instanceof FlightConfigurationID)) {
throw new IllegalArgumentException("MotorConfigurationModel item=" + item); throw new IllegalArgumentException("MotorConfigurationModel item=" + item);
} }
FlightConfigurationID fcid= (FlightConfigurationID) item; FlightConfigurationID fcid= (FlightConfigurationID) item;
FlightConfigurationSet<FlightConfiguration> configSet = rocket.getConfigurationSet();
this.config = configSet.get(fcid); this.selected = sourceSet.get(fcid);
} }

View File

@ -46,7 +46,7 @@ import net.sf.openrocket.gui.adaptors.Column;
import net.sf.openrocket.gui.adaptors.ColumnTable; import net.sf.openrocket.gui.adaptors.ColumnTable;
import net.sf.openrocket.gui.adaptors.ColumnTableModel; import net.sf.openrocket.gui.adaptors.ColumnTableModel;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.adaptors.FlightConfigurationModel; import net.sf.openrocket.gui.adaptors.ParameterSetModel;
import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.StageSelector;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
@ -56,8 +56,9 @@ import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.masscalc.MassCalculator; import net.sf.openrocket.masscalc.MassCalculator;
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
@ -176,8 +177,10 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
JLabel label = new JLabel(trans.get("componentanalysisdlg.lbl.motorconf")); JLabel label = new JLabel(trans.get("componentanalysisdlg.lbl.motorconf"));
label.setHorizontalAlignment(JLabel.RIGHT); label.setHorizontalAlignment(JLabel.RIGHT);
panel.add(label, "growx, right"); panel.add(label, "growx, right");
panel.add(new JComboBox(new FlightConfigurationModel(configuration)), "wrap");
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
JComboBox<FlightConfigurationID> combo = new JComboBox<FlightConfigurationID>(psm);
panel.add(combo, "wrap");
// Tabbed pane // Tabbed pane

View File

@ -40,7 +40,7 @@ public class RenameConfigDialog extends JDialog {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String newName = textbox.getText(); String newName = textbox.getText();
rocket.getFlightConfiguration(fcid).setName( newName); rocket.getFlightConfiguration(fcid).setName( newName);
rocket.getConfigurationSet().printDebug(); System.err.println(rocket.getConfigurationSet().toDebug());
RenameConfigDialog.this.setVisible(false); RenameConfigDialog.this.setVisible(false);
} }
}); });

View File

@ -345,33 +345,21 @@ public class RocketFigure extends AbstractScaleFigure {
Motor motor = curInstance.getMotor(); Motor motor = curInstance.getMotor();
double motorLength = motor.getLength(); double motorLength = motor.getLength();
double motorRadius = motor.getDiameter() / 2; double motorRadius = motor.getDiameter() / 2;
// Steps for instancing:
// 1) mountComponent has an instanced ancestor:
// 2) which may be an arbitrary number of levels up, so calling mount.parent.getInstances is not enough.
// 3) therefore <component>.getLocation() will return all the instances of this owning component
// 4) Then, for each instance of the component, draw each cluster.
RocketComponent mountComponent = ((RocketComponent) mount); RocketComponent mountComponent = ((RocketComponent) mount);
// <component>.getLocation() will return all the parent instances of this owning component, AND all of it's own instances as well.
// so, just draw a motor once for each Coordinate returned...
Coordinate[] mountLocations = mountComponent.getLocations(); Coordinate[] mountLocations = mountComponent.getLocations();
double mountLength = mountComponent.getLength(); double mountLength = mountComponent.getLength();
for ( Coordinate curInstanceLocation : mountLocations ){ System.err.println("motors are drawing wrong... from here?");
Coordinate[] motorPositions; for ( Coordinate curMountLocation : mountLocations ){
Coordinate[] clusterCenterTop = new Coordinate[]{ curInstanceLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0)}; Coordinate curMotorLocation = curMountLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0);
System.err.println("Translating from mount at "+curMountLocation+" to motor at "+curMotorLocation);
// old code...
// motorPositions = mountComponent.shiftCoordinates(clusterCenterTop);
// new code
motorPositions = mountComponent.getLocations();
System.err.println("the motors are probably being drawn wrong, and its probably from here.... ");
for (int i = 0; i < motorPositions.length; i++) {
motorPositions[i] = transformation.transform(motorPositions[i]);
}
for (Coordinate coord : motorPositions) { Coordinate coord = curMotorLocation;
{
Shape s; Shape s;
if (currentViewType == RocketPanel.VIEW_TYPE.SideView) { if (currentViewType == RocketPanel.VIEW_TYPE.SideView) {
s = new Rectangle2D.Double(EXTRA_SCALE * coord.x, s = new Rectangle2D.Double(EXTRA_SCALE * coord.x,

View File

@ -37,7 +37,7 @@ import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.adaptors.FlightConfigurationModel; import net.sf.openrocket.gui.adaptors.ParameterSetModel;
import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.StageSelector;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
@ -304,7 +304,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg")); JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg"));
label.setHorizontalAlignment(JLabel.RIGHT); label.setHorizontalAlignment(JLabel.RIGHT);
add(label, "growx, right"); add(label, "growx, right");
add(new JComboBox(new FlightConfigurationModel(configuration)), "wrap");
// ?? this model should operate off of either: the rocket (or the FlightConfigurationSet contained in the rocket... )
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
JComboBox<FlightConfigurationID> flightConfigurationcomboBox = new JComboBox<FlightConfigurationID>(psm);
add(flightConfigurationcomboBox, "wrap");
// Create slider and scroll pane // Create slider and scroll pane

View File

@ -21,10 +21,11 @@ import javax.swing.event.DocumentListener;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.adaptors.FlightConfigurationModel; import net.sf.openrocket.gui.adaptors.ParameterSetModel;
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.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.SimulationOptions;
import net.sf.openrocket.simulation.extension.SimulationExtension; import net.sf.openrocket.simulation.extension.SimulationExtension;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
@ -150,7 +151,9 @@ public class SimulationEditDialog extends JDialog {
label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg")); label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg"));
panel.add(label, "growx 0, gapright para"); panel.add(label, "growx 0, gapright para");
JComboBox combo = new JComboBox(new FlightConfigurationModel(configuration)); ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
JComboBox<?> combo = new JComboBox<FlightConfigurationID>(psm);
//// Select the motor configuration to use. //// Select the motor configuration to use.
combo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); combo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
combo.addActionListener(new ActionListener() { combo.addActionListener(new ActionListener() {