[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:
parent
6b322a610f
commit
3ae4b0d277
@ -62,7 +62,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
private static boolean undoErrorReported = false;
|
||||
|
||||
private final Rocket rocket;
|
||||
private final FlightConfiguration configuration;
|
||||
|
||||
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
|
||||
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
|
||||
@ -104,7 +103,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
private final List<DocumentChangeListener> listeners = new ArrayList<DocumentChangeListener>();
|
||||
|
||||
OpenRocketDocument(Rocket rocket) {
|
||||
this.configuration = rocket.getDefaultConfiguration();
|
||||
this.rocket = rocket;
|
||||
init();
|
||||
}
|
||||
@ -166,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
|
||||
|
||||
public FlightConfiguration getDefaultConfiguration() {
|
||||
return configuration;
|
||||
return rocket.getDefaultConfiguration();
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
||||
@ -12,7 +12,7 @@ import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet;
|
||||
import net.sf.openrocket.rocketcomponent.ParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
@ -64,7 +64,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
|
||||
if ("true".equals(attributes.remove("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);
|
||||
fcs.setDefault(fc);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.Locale;
|
||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
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.Rocket;
|
||||
|
||||
@ -37,7 +37,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
|
||||
//dev.getDeploymentConfigurations().printDebug();
|
||||
// DEBUG
|
||||
|
||||
FlightConfigurationSet<FlightConfiguration> configList = rocket.getConfigurationSet();
|
||||
ParameterSet<FlightConfiguration> configList = rocket.getConfigurationSet();
|
||||
for (FlightConfigurationID fcid : configList.getSortedConfigurationIDs()) {
|
||||
//System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?");
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import net.sf.openrocket.preset.ComponentPreset;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
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.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
@ -148,7 +148,7 @@ public class RocketComponentSaver {
|
||||
return Collections.emptyList();
|
||||
|
||||
//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>();
|
||||
|
||||
MotorInstance defaultInstance = mount.getDefaultMotorInstance();
|
||||
|
||||
@ -6,7 +6,7 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
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.Rocket;
|
||||
|
||||
@ -43,7 +43,7 @@ public class RocketSaver extends RocketComponentSaver {
|
||||
|
||||
|
||||
// Motor configurations
|
||||
FlightConfigurationSet<FlightConfiguration> allConfigs = rocket.getConfigurationSet();
|
||||
ParameterSet<FlightConfiguration> allConfigs = rocket.getConfigurationSet();
|
||||
for (FlightConfigurationID fcid : allConfigs.getSortedConfigurationIDs()) {
|
||||
FlightConfiguration flightConfig = allConfigs.get(fcid);
|
||||
if (fcid == null)
|
||||
|
||||
@ -12,12 +12,12 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
//private static final Logger log = LoggerFactory.getLogger(AxialStage.class);
|
||||
|
||||
protected FlightConfigurationSet<StageSeparationConfiguration> separationConfigurations;
|
||||
protected ParameterSet<StageSeparationConfiguration> separationConfigurations;
|
||||
|
||||
protected int stageNumber;
|
||||
|
||||
public AxialStage(){
|
||||
this.separationConfigurations = new FlightConfigurationSet<StageSeparationConfiguration>(
|
||||
this.separationConfigurations = new ParameterSet<StageSeparationConfiguration>(
|
||||
this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration());
|
||||
this.relativePosition = Position.AFTER;
|
||||
this.stageNumber = 0;
|
||||
@ -34,7 +34,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
return trans.get("Stage.Stage");
|
||||
}
|
||||
|
||||
public FlightConfigurationSet<StageSeparationConfiguration> getSeparationConfigurations() {
|
||||
public ParameterSet<StageSeparationConfiguration> getSeparationConfigurations() {
|
||||
return separationConfigurations;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
@Override
|
||||
protected RocketComponent copyWithOriginalID() {
|
||||
AxialStage copy = (AxialStage) super.copyWithOriginalID();
|
||||
copy.separationConfigurations = new FlightConfigurationSet<StageSeparationConfiguration>(separationConfigurations,
|
||||
copy.separationConfigurations = new ParameterSet<StageSeparationConfiguration>(separationConfigurations,
|
||||
copy, ComponentChangeEvent.EVENT_CHANGE);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -462,8 +462,8 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
||||
return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang());
|
||||
}
|
||||
|
||||
public void printMotorDebug(){
|
||||
this.motors.printDebug();
|
||||
public String toMotorDebug(){
|
||||
return this.motors.toDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -114,7 +114,7 @@ public class BoosterSet extends AxialStage implements FlightConfigurableComponen
|
||||
// there must be at least one instance....
|
||||
return;
|
||||
}
|
||||
System.err.println("?! Setting BoosterSet instance count to: "+newCount );
|
||||
|
||||
this.count = newCount;
|
||||
this.angularSeparation = Math.PI * 2 / this.count;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
|
||||
@ -184,14 +184,10 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public List<MotorInstance> getActiveMotors() {
|
||||
ArrayList<MotorInstance> toReturn = new ArrayList<MotorInstance>();
|
||||
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...
|
||||
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;
|
||||
}
|
||||
|
||||
@ -368,7 +365,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
|
||||
// DEBUG / DEVEL
|
||||
public String toDebugDetail() {
|
||||
public String toStageListDetail() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("\nDumping stage config: \n"));
|
||||
for (StageFlags flags : this.stageMap.values()) {
|
||||
@ -492,5 +489,4 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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 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 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() {
|
||||
this(UUID.randomUUID().toString());
|
||||
|
||||
@ -1,35 +1,12 @@
|
||||
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 FlightConfigurationSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> {
|
||||
|
||||
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();
|
||||
|
||||
public class FlightConfigurationSet extends ParameterSet<FlightConfiguration> {
|
||||
|
||||
/**
|
||||
* 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 eventType the event type that will be fired on changes
|
||||
*/
|
||||
public FlightConfigurationSet(RocketComponent component, int eventType, E _defaultValue) {
|
||||
this.component = component;
|
||||
this.eventType = eventType;
|
||||
|
||||
this.defaultValue= _defaultValue;
|
||||
|
||||
addListener(_defaultValue);
|
||||
public FlightConfigurationSet( RocketComponent component, int eventType, FlightConfiguration _defaultValue) {
|
||||
super( component, eventType, _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 eventType the event type that will be fired on changes
|
||||
*/
|
||||
public FlightConfigurationSet(FlightConfigurationSet<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 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);
|
||||
}
|
||||
|
||||
public FlightConfigurationSet(FlightConfigurationSet configSet, RocketComponent component, int eventType) {
|
||||
super( configSet, component, eventType );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
||||
}
|
||||
|
||||
public void printMotorDebug( FlightConfigurationID fcid ){
|
||||
this.motors.printDebug();
|
||||
System.err.println(this.motors.toDebug());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -393,26 +393,29 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
||||
|
||||
Coordinate[] relCoords = this.shiftCoordinates(new Coordinate[] { Coordinate.ZERO });
|
||||
Coordinate[] absCoords = this.getLocations();
|
||||
FlightConfigurationID curId = this.getRocket().getDefaultConfiguration().getFlightConfigurationID();
|
||||
int count = this.getInstanceCount();
|
||||
for (int instanceNumber = 0; instanceNumber < count; instanceNumber++) {
|
||||
Coordinate instanceRelativePosition = relCoords[instanceNumber];
|
||||
Coordinate instanceAbsolutePosition = absCoords[instanceNumber];
|
||||
buffer.append(String.format("%s [instance %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()));
|
||||
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++) {
|
||||
Coordinate instanceRelativePosition = relCoords[instanceNumber];
|
||||
Coordinate instanceAbsolutePosition = absCoords[instanceNumber];
|
||||
buffer.append(String.format("%s [MotorInstance %2d / %2d] %28s %28s\n", prefix, instanceNumber, count,
|
||||
buffer.append(String.format("%s [%2d / %2d] %28s %28s\n", prefix, instanceNumber, count,
|
||||
instanceRelativePosition, instanceAbsolutePosition));
|
||||
}
|
||||
}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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import net.sf.openrocket.motor.MotorInstance;
|
||||
* FlightConfigurationSet for motors.
|
||||
* 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;
|
||||
|
||||
@ -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 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);
|
||||
}
|
||||
|
||||
@ -32,9 +32,10 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDebug(){
|
||||
System.err.println("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======");
|
||||
System.err.println(" >> motorSet ("+this.size()+ " motors)");
|
||||
public String toDebug(){
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
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()){
|
||||
String shortKey = loopFCID.getShortKey();
|
||||
@ -46,9 +47,9 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
|
||||
}else{
|
||||
designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay());
|
||||
}
|
||||
System.err.println(" >> ["+shortKey+"]= "+designation);
|
||||
|
||||
buffer.append(" >> ["+shortKey+"]= "+designation);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
// public void printDebug(FlightConfigurationID curFCID){
|
||||
|
||||
233
core/src/net/sf/openrocket/rocketcomponent/ParameterSet.java
Normal file
233
core/src/net/sf/openrocket/rocketcomponent/ParameterSet.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,10 +25,10 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
|
||||
private Material.Surface material;
|
||||
|
||||
private FlightConfigurationSet<DeploymentConfiguration> deploymentConfigurations;
|
||||
private ParameterSet<DeploymentConfiguration> deploymentConfigurations;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
}
|
||||
|
||||
public FlightConfigurationSet<DeploymentConfiguration> getDeploymentConfigurations() {
|
||||
public ParameterSet<DeploymentConfiguration> getDeploymentConfigurations() {
|
||||
return deploymentConfigurations;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
@Override
|
||||
protected RocketComponent copyWithOriginalID() {
|
||||
RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID();
|
||||
copy.deploymentConfigurations = new FlightConfigurationSet<DeploymentConfiguration>(deploymentConfigurations,
|
||||
copy.deploymentConfigurations = new ParameterSet<DeploymentConfiguration>(deploymentConfigurations,
|
||||
copy, ComponentChangeEvent.EVENT_CHANGE);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
|
||||
// Flight configuration list
|
||||
private FlightConfigurationSet<FlightConfiguration> configurations;
|
||||
private FlightConfigurationSet configSet;
|
||||
|
||||
// Does the rocket have a perfect finish (a notable amount of laminar flow)
|
||||
private boolean perfectFinish = false;
|
||||
@ -84,7 +84,7 @@ public class Rocket extends RocketComponent {
|
||||
functionalModID = modID;
|
||||
|
||||
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() {
|
||||
@ -281,8 +281,8 @@ public class Rocket extends RocketComponent {
|
||||
@Override
|
||||
public Rocket copyWithOriginalID() {
|
||||
Rocket copy = (Rocket) super.copyWithOriginalID();
|
||||
copy.configurations = new FlightConfigurationSet<FlightConfiguration>(
|
||||
this.configurations, copy, ComponentChangeEvent.ALL_CHANGE);
|
||||
copy.configSet = new FlightConfigurationSet(
|
||||
this.configSet, copy, ComponentChangeEvent.ALL_CHANGE);
|
||||
copy.resetListeners();
|
||||
|
||||
return copy;
|
||||
@ -319,8 +319,8 @@ public class Rocket extends RocketComponent {
|
||||
this.refType = r.refType;
|
||||
this.customReferenceLength = r.customReferenceLength;
|
||||
|
||||
this.configurations = new FlightConfigurationSet<FlightConfiguration>(
|
||||
r.configurations, this, ComponentChangeEvent.ALL_CHANGE);
|
||||
this.configSet = new FlightConfigurationSet(
|
||||
r.configSet, this, ComponentChangeEvent.ALL_CHANGE);
|
||||
this.perfectFinish = r.perfectFinish;
|
||||
|
||||
this.checkComponentStructure();
|
||||
@ -499,17 +499,17 @@ public class Rocket extends RocketComponent {
|
||||
*/
|
||||
public FlightConfiguration getDefaultConfiguration() {
|
||||
checkState();
|
||||
return this.configurations.getDefault();
|
||||
return this.configSet.getDefault();
|
||||
}
|
||||
|
||||
public FlightConfiguration createFlightConfiguration( final FlightConfigurationID fcid) {
|
||||
checkState();
|
||||
FlightConfiguration nextConfig = null;
|
||||
if( configurations.containsKey(fcid)){
|
||||
nextConfig = this.configurations.get(fcid);
|
||||
if( configSet.containsKey(fcid)){
|
||||
nextConfig = this.configSet.get(fcid);
|
||||
}else{
|
||||
nextConfig = new FlightConfiguration(fcid, this);
|
||||
this.configurations.set(fcid, nextConfig);
|
||||
this.configSet.set(fcid, nextConfig);
|
||||
}
|
||||
|
||||
this.setFlightConfiguration( fcid, nextConfig );
|
||||
@ -518,16 +518,16 @@ public class Rocket extends RocketComponent {
|
||||
}
|
||||
|
||||
public int getConfigurationCount(){
|
||||
return this.configurations.size();
|
||||
return this.configSet.size();
|
||||
}
|
||||
|
||||
public FlightConfigurationSet<FlightConfiguration> getConfigurationSet(){
|
||||
public ParameterSet<FlightConfiguration> getConfigurationSet(){
|
||||
checkState();
|
||||
return this.configurations;
|
||||
return this.configSet;
|
||||
}
|
||||
|
||||
public List<FlightConfigurationID> getSortedConfigurationIDs(){
|
||||
return configurations.getSortedConfigurationIDs();
|
||||
return configSet.getSortedConfigurationIDs();
|
||||
}
|
||||
|
||||
|
||||
@ -543,7 +543,7 @@ public class Rocket extends RocketComponent {
|
||||
return;
|
||||
|
||||
// Get current configuration:
|
||||
this.configurations.set(fcid, null);
|
||||
this.configSet.set(fcid, null);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
@ -556,7 +556,7 @@ public class Rocket extends RocketComponent {
|
||||
*/
|
||||
public boolean containsFlightConfigurationID(FlightConfigurationID id) {
|
||||
checkState();
|
||||
FlightConfiguration config = configurations.get( id);
|
||||
FlightConfiguration config = configSet.get( id);
|
||||
return (null != config);
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ public class Rocket extends RocketComponent {
|
||||
*/
|
||||
public FlightConfiguration getFlightConfiguration(final FlightConfigurationID id) {
|
||||
checkState();
|
||||
return this.configurations.get(id);
|
||||
return this.configSet.get(id);
|
||||
}
|
||||
|
||||
|
||||
@ -614,7 +614,7 @@ public class Rocket extends RocketComponent {
|
||||
// silently ignore
|
||||
return;
|
||||
}else{
|
||||
configurations.set(fcid, newConfig);
|
||||
configSet.set(fcid, newConfig);
|
||||
}
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
@ -1358,25 +1358,15 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
|
||||
/**
|
||||
* Removes a child from the rocket component tree.
|
||||
* (redirect to the removed-by-component
|
||||
*
|
||||
* @param n remove the n'th child.
|
||||
* @throws IndexOutOfBoundsException if n is out of bounds
|
||||
*/
|
||||
public final void removeChild(int n) {
|
||||
checkState();
|
||||
RocketComponent component = children.remove(n);
|
||||
component.parent = null;
|
||||
|
||||
if (component instanceof AxialStage) {
|
||||
AxialStage nStage = (AxialStage) component;
|
||||
this.getRocket().forgetStage(nStage);
|
||||
}
|
||||
|
||||
this.checkComponentStructure();
|
||||
component.checkComponentStructure();
|
||||
|
||||
updateBounds();
|
||||
fireAddRemoveEvent(component);
|
||||
RocketComponent component = this.getChild(n);
|
||||
this.removeChild(component);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1391,9 +1381,15 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
|
||||
component.checkComponentStructure();
|
||||
|
||||
|
||||
if (children.remove(component)) {
|
||||
component.parent = null;
|
||||
|
||||
if (component instanceof AxialStage) {
|
||||
AxialStage stage = (AxialStage) component;
|
||||
this.getRocket().forgetStage(stage);
|
||||
}
|
||||
|
||||
this.checkComponentStructure();
|
||||
component.checkComponentStructure();
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
|
||||
// test explicitly setting all stages up to second stage active
|
||||
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);
|
||||
assertThat(" deactivate stage #0: ", config.isStageActive(0), equalTo(false));
|
||||
|
||||
@ -7,8 +7,6 @@ import javax.swing.AbstractListModel;
|
||||
import javax.swing.ComboBoxModel;
|
||||
import javax.swing.MutableComboBoxModel;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
|
||||
import net.sf.openrocket.util.ChangeSource;
|
||||
import net.sf.openrocket.util.Reflection;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
@ -132,8 +130,6 @@ public class EnumModel<T extends Enum<T>> extends AbstractListModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EnumModel["+source.getClass().getCanonicalName()+":"+valueName+"]";
|
||||
|
||||
@ -11,55 +11,54 @@ import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
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.FlightConfigurationSet;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.ParameterSet;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
/**
|
||||
* A ComboBoxModel that contains a list of flight configurations. The list can
|
||||
* 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 RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
private EventListenerList listenerList = new EventListenerList();
|
||||
|
||||
private FlightConfiguration config;
|
||||
private final Rocket rocket;
|
||||
List<FlightConfigurationID> ids= new Vector<FlightConfigurationID>();
|
||||
private T selected;
|
||||
private final ParameterSet<T> sourceSet;
|
||||
List<FlightConfigurationID> idList= new Vector<FlightConfigurationID>();
|
||||
|
||||
public FlightConfigurationModel(FlightConfiguration config) {
|
||||
this.config = config;
|
||||
this.rocket = config.getRocket();
|
||||
config.addChangeListener(this);
|
||||
public ParameterSetModel(ParameterSet<T> set ) {
|
||||
this.sourceSet = set;
|
||||
this.selected = this.sourceSet.getDefault();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FlightConfigurationID getElementAt(int index) {
|
||||
this.ids = rocket.getSortedConfigurationIDs();
|
||||
|
||||
this.idList = this.sourceSet.getSortedConfigurationIDs();
|
||||
|
||||
if (index < 0){
|
||||
return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
|
||||
}else if ( index >= this.ids.size()){
|
||||
}else if ( index >= this.idList.size()){
|
||||
return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
|
||||
}
|
||||
|
||||
return this.ids.get(index);
|
||||
return this.idList.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return this.ids.size();
|
||||
this.idList = this.sourceSet.getSortedConfigurationIDs();
|
||||
return this.idList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
return config.getFlightConfigurationID();
|
||||
return selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,14 +67,13 @@ public class FlightConfigurationModel implements ComboBoxModel<FlightConfigurati
|
||||
// Clear selection - huh?
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item instanceof FlightConfigurationID)) {
|
||||
throw new IllegalArgumentException("MotorConfigurationModel item=" + item);
|
||||
}
|
||||
|
||||
FlightConfigurationID fcid= (FlightConfigurationID) item;
|
||||
FlightConfigurationSet<FlightConfiguration> configSet = rocket.getConfigurationSet();
|
||||
|
||||
this.config = configSet.get(fcid);
|
||||
this.selected = sourceSet.get(fcid);
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ import net.sf.openrocket.gui.adaptors.Column;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTable;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
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.StageSelector;
|
||||
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.masscalc.MassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
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.RocketComponent;
|
||||
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"));
|
||||
label.setHorizontalAlignment(JLabel.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
|
||||
|
||||
@ -40,7 +40,7 @@ public class RenameConfigDialog extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newName = textbox.getText();
|
||||
rocket.getFlightConfiguration(fcid).setName( newName);
|
||||
rocket.getConfigurationSet().printDebug();
|
||||
System.err.println(rocket.getConfigurationSet().toDebug());
|
||||
RenameConfigDialog.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
@ -345,33 +345,21 @@ public class RocketFigure extends AbstractScaleFigure {
|
||||
Motor motor = curInstance.getMotor();
|
||||
double motorLength = motor.getLength();
|
||||
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);
|
||||
|
||||
// <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();
|
||||
|
||||
double mountLength = mountComponent.getLength();
|
||||
for ( Coordinate curInstanceLocation : mountLocations ){
|
||||
Coordinate[] motorPositions;
|
||||
Coordinate[] clusterCenterTop = new Coordinate[]{ curInstanceLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0)};
|
||||
|
||||
// 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]);
|
||||
}
|
||||
System.err.println("motors are drawing wrong... from here?");
|
||||
for ( Coordinate curMountLocation : mountLocations ){
|
||||
Coordinate curMotorLocation = curMountLocation.add( mountLength - motorLength + mount.getMotorOverhang(), 0, 0);
|
||||
System.err.println("Translating from mount at "+curMountLocation+" to motor at "+curMotorLocation);
|
||||
|
||||
|
||||
for (Coordinate coord : motorPositions) {
|
||||
Coordinate coord = curMotorLocation;
|
||||
{
|
||||
Shape s;
|
||||
if (currentViewType == RocketPanel.VIEW_TYPE.SideView) {
|
||||
s = new Rectangle2D.Double(EXTRA_SCALE * coord.x,
|
||||
|
||||
@ -37,7 +37,7 @@ import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
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.StageSelector;
|
||||
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"));
|
||||
label.setHorizontalAlignment(JLabel.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
|
||||
|
||||
|
||||
@ -21,10 +21,11 @@ import javax.swing.event.DocumentListener;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
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.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.simulation.SimulationOptions;
|
||||
import net.sf.openrocket.simulation.extension.SimulationExtension;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
@ -150,7 +151,9 @@ public class SimulationEditDialog extends JDialog {
|
||||
label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg"));
|
||||
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.
|
||||
combo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||
combo.addActionListener(new ActionListener() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user