[Bugfix] Test Patch which replaces event-passing in FlightConfiguration with a simple 'update()'
- listener lists removed from FlightConfiguration - listener lists removed from MotorConfiguration - added update() calles to Rocket FlightConfigurationSet, other configs - merged FlightConfigurable into FlightConfigurableParameterSet - Fixed ParallelStageTest - updated some function calls in/to FlightConfiguration
This commit is contained in:
parent
8e2d4f1b95
commit
3f4cf696c1
@ -4,7 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurable;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.util.Reflection;
|
||||
import net.sf.openrocket.util.Reflection.Method;
|
||||
@ -94,7 +94,7 @@ class DoubleSetter implements Setter {
|
||||
if (configGetter == null) {
|
||||
setMethod.invoke(c, d * multiplier);
|
||||
} else {
|
||||
FlightConfigurable<?> config = (FlightConfigurable<?>) configGetter.invoke(c);
|
||||
FlightConfigurableParameterSet<?> config = (FlightConfigurableParameterSet<?>) configGetter.invoke(c);
|
||||
Object obj = config.getDefault();
|
||||
setMethod.invoke(obj, d * multiplier);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurable;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.util.Reflection;
|
||||
import net.sf.openrocket.util.Reflection.Method;
|
||||
@ -38,7 +38,7 @@ class EnumSetter<T extends Enum<T>> implements Setter {
|
||||
if (configurationGetter == null) {
|
||||
setter.invoke(c, setEnum);
|
||||
} else {
|
||||
FlightConfigurable<?> config = (FlightConfigurable<?>) configurationGetter.invoke(c);
|
||||
FlightConfigurableParameterSet<?> config = (FlightConfigurableParameterSet<?>) configurationGetter.invoke(c);
|
||||
Object obj = config.getDefault();
|
||||
setter.invoke(obj, setEnum);
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ public class MassCalculator implements Monitorable {
|
||||
private void calculateStageCache(FlightConfiguration config) {
|
||||
int stageCount = config.getActiveStageCount();
|
||||
if(debug){
|
||||
System.err.println(">> Calculating massData cache for config: "+config.toShort()+" with "+stageCount+" stages");
|
||||
System.err.println(">> Calculating massData cache for config: "+config.toDebug()+" with "+stageCount+" stages");
|
||||
}
|
||||
if( 0 < stageCount ){
|
||||
for( AxialStage curStage : config.getActiveStages()){
|
||||
|
@ -32,7 +32,6 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
|
||||
protected double ignitionTime = 0.0;
|
||||
|
||||
protected int modID = 0;
|
||||
private final List<StateChangeListener> listeners = new ArrayList<StateChangeListener>();
|
||||
|
||||
public MotorConfiguration( Motor motor ) {
|
||||
this();
|
||||
@ -231,24 +230,20 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
|
||||
|
||||
@Override
|
||||
public void addChangeListener(StateChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChangeListener(StateChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
protected void fireChangeEvent() {
|
||||
EventObject event = new EventObject(this);
|
||||
Object[] list = listeners.toArray();
|
||||
for (Object l : list) {
|
||||
((StateChangeListener) l).stateChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
public int getModID() {
|
||||
return modID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import java.util.Locale;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.optimization.general.OptimizationException;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameter;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurable;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
@ -70,7 +70,7 @@ public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E
|
||||
+ " with correct ID");
|
||||
}
|
||||
|
||||
FlightConfigurable<E> configs = (FlightConfigurable<E>) configGetter.invoke(c);
|
||||
FlightConfigurableParameterSet<E> configs = (FlightConfigurableParameterSet<E>) configGetter.invoke(c);
|
||||
return configs.get(simulation.getRocket().getDefaultConfiguration().getFlightConfigurationID());
|
||||
}
|
||||
|
||||
|
@ -180,5 +180,8 @@ public class DeploymentConfiguration implements FlightConfigurableParameter<Depl
|
||||
return that;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
}
|
||||
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.util.ChangeSource;
|
||||
|
||||
/**
|
||||
* Represents a value or parameter that can vary based on the
|
||||
* flight configuration ID.
|
||||
* <p>
|
||||
* The parameter value is always defined, and null is not a valid
|
||||
* parameter value.
|
||||
*
|
||||
* @param <E> the parameter type
|
||||
*/
|
||||
public interface FlightConfigurable<E extends ChangeSource> extends FlightConfigurableComponent, Iterable<E> {
|
||||
|
||||
/**
|
||||
* Return the default parameter value for this FlightConfiguration.
|
||||
* This is used in case a per-flight configuration override
|
||||
* has not been defined.
|
||||
*
|
||||
* @return the default parameter value (never null)
|
||||
*/
|
||||
public E getDefault();
|
||||
|
||||
/**
|
||||
* Set the default parameter value for this FlightConfiguration.
|
||||
*This is used in case a per-flight configuration override
|
||||
* has not been defined.
|
||||
*
|
||||
* @param value the parameter value (null not allowed)
|
||||
*/
|
||||
public void setDefault(E value);
|
||||
|
||||
/**
|
||||
* Return the parameter value for the provided flight configuration ID.
|
||||
* This returns either the value specified for this flight config ID,
|
||||
* or the default value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @return the parameter to use (never null)
|
||||
*/
|
||||
public E get(FlightConfigurationId id);
|
||||
|
||||
/**
|
||||
* Return the parameter value for the provided flight configuration ID.
|
||||
* This returns either the value specified for this flight config ID,
|
||||
* or the default value.
|
||||
*
|
||||
* @param value the parameter to find
|
||||
* @return the flight configuration ID
|
||||
*/
|
||||
public FlightConfigurationId get(E value);
|
||||
|
||||
/**
|
||||
* Set the parameter value for the provided flight configuration ID.
|
||||
* This sets the override for this flight configuration ID.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @param value the parameter value (null not allowed)
|
||||
*/
|
||||
public void set(FlightConfigurationId id, E value);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a sorted list of all the contained FlightConfigurationIDs
|
||||
*/
|
||||
public List<FlightConfigurationId> getSortedConfigurationIDs();
|
||||
|
||||
/**
|
||||
* Return whether a specific flight configuration ID is using the
|
||||
* default value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @return whether the default is being used
|
||||
*/
|
||||
public boolean isDefault(FlightConfigurationId id);
|
||||
|
||||
/**
|
||||
* Reset a specific flight configuration ID to use the default parameter value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
*/
|
||||
public void reset(FlightConfigurationId id);
|
||||
|
||||
/**
|
||||
* Return the number of specific flight configurations other than the default.
|
||||
* @return
|
||||
*/
|
||||
public int size();
|
||||
}
|
@ -16,4 +16,6 @@ public interface FlightConfigurableParameter<E> extends ChangeSource {
|
||||
*/
|
||||
public E clone();
|
||||
|
||||
public void update();
|
||||
|
||||
}
|
||||
|
@ -12,12 +12,15 @@ 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.
|
||||
* Represents a value or parameter that can vary based on the
|
||||
* flight configuration ID.
|
||||
* <p>
|
||||
* The parameter value is always defined, and null is not a valid
|
||||
* parameter value.
|
||||
*
|
||||
* @param <E> the parameter type
|
||||
*/
|
||||
public class FlightConfigurableParameterSet<E extends FlightConfigurableParameter<E>> implements FlightConfigurable<E> {
|
||||
public class FlightConfigurableParameterSet<E extends FlightConfigurableParameter<E>> implements Iterable<E> {
|
||||
|
||||
//private static final Logger log = LoggerFactory.getLogger(ParameterSet.class);
|
||||
protected final HashMap<FlightConfigurationId, E> map = new HashMap<FlightConfigurationId, E>();
|
||||
@ -66,12 +69,24 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
return this.map.containsKey(fcid);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Return the default parameter value for this FlightConfiguration.
|
||||
* This is used in case a per-flight configuration override
|
||||
* has not been defined.
|
||||
*
|
||||
* @return the default parameter value (never null)
|
||||
*/
|
||||
public E getDefault(){
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Set the default parameter value for this FlightConfiguration.
|
||||
*This is used in case a per-flight configuration override
|
||||
* has not been defined.
|
||||
*
|
||||
* @param value the parameter value (null not allowed)
|
||||
*/
|
||||
public void setDefault(E nextDefaultValue) {
|
||||
if (nextDefaultValue == null) {
|
||||
throw new NullPointerException("new Default Value is null");
|
||||
@ -88,12 +103,22 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Return the number of specific flight configurations other than the default.
|
||||
* @return
|
||||
*/
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Return the parameter value for the provided flight configuration ID.
|
||||
* This returns either the value specified for this flight config ID,
|
||||
* or the default value.
|
||||
*
|
||||
* @param value the parameter to find
|
||||
* @return the flight configuration ID
|
||||
*/
|
||||
public FlightConfigurationId get(E testValue) {
|
||||
if( null == testValue ){
|
||||
return null;
|
||||
@ -124,7 +149,14 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
return this.map.get(selectedId);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Return the parameter value for the provided flight configuration ID.
|
||||
* This returns either the value specified for this flight config ID,
|
||||
* or the default value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @return the parameter to use (never null)
|
||||
*/
|
||||
public E get(FlightConfigurationId id) {
|
||||
if( id.hasError() ){
|
||||
throw new NullPointerException("Attempted to retrieve a parameter with an error key!");
|
||||
@ -138,7 +170,10 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
*
|
||||
* @return a sorted list of all the contained FlightConfigurationIDs
|
||||
*/
|
||||
public List<FlightConfigurationId> getSortedConfigurationIDs(){
|
||||
ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>();
|
||||
|
||||
@ -156,7 +191,13 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
return this.getSortedConfigurationIDs();
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Set the parameter value for the provided flight configuration ID.
|
||||
* This sets the override for this flight configuration ID.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @param value the parameter value (null not allowed)
|
||||
*/
|
||||
public void set(FlightConfigurationId fcid, E nextValue) {
|
||||
if ( nextValue == null) {
|
||||
// null value means to delete this fcid
|
||||
@ -171,33 +212,54 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
fireEvent();
|
||||
}
|
||||
|
||||
|
||||
public boolean isDefault(E testVal) {
|
||||
return (Utils.equals( this.getDefault(), testVal));
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Return whether a specific flight configuration ID is using the
|
||||
* default value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
* @return whether the default is being used
|
||||
*/
|
||||
public boolean isDefault( FlightConfigurationId fcid) {
|
||||
return ( this.getDefault() == this.map.get(fcid));
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Reset a specific flight configuration ID to use the default parameter value.
|
||||
*
|
||||
* @param id the flight configuration ID
|
||||
*/
|
||||
public void reset( FlightConfigurationId fcid) {
|
||||
if( fcid.isValid() ){
|
||||
set( fcid, null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Clears all configuration-specific settings -- meaning querying the parameter for any configuration will return the default value.
|
||||
*
|
||||
*/
|
||||
public void reset() {
|
||||
E tempValue = this.getDefault();
|
||||
this.map.clear();
|
||||
setDefault(tempValue);
|
||||
}
|
||||
|
||||
|
||||
private void fireEvent() {
|
||||
component.fireComponentChangeEvent(eventType);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
|
||||
public FlightConfigurationId cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
|
||||
// clones the ENTRIES for the given fcid's.
|
||||
E oldValue = this.get(oldConfigId);
|
||||
this.set(newConfigId, oldValue.clone());
|
||||
fireEvent();
|
||||
return newConfigId;
|
||||
}
|
||||
|
||||
private void addListener(E value) {
|
||||
@ -238,12 +300,13 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Clears all configuration-specific settings -- meaning querying the parameter for any configuration will return the default value.
|
||||
*
|
||||
*/
|
||||
public void clear() {
|
||||
this.map.clear();
|
||||
|
||||
public void update(){
|
||||
this.defaultValue.update();
|
||||
for( E curValue: this.map.values() ){
|
||||
curValue.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.EventListener;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
@ -27,6 +25,7 @@ import net.sf.openrocket.util.StateChangeListener;
|
||||
*
|
||||
*
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
* @author Daniel Williams <equipoise@gmail.com>
|
||||
*/
|
||||
public class FlightConfiguration implements FlightConfigurableParameter<FlightConfiguration>, ChangeSource, ComponentChangeListener, Monitorable {
|
||||
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
|
||||
@ -42,8 +41,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
protected static int instanceCount=0;
|
||||
public final int instanceNumber;
|
||||
|
||||
private List<EventListener> listenerList = new ArrayList<EventListener>();
|
||||
|
||||
protected class StageFlags implements Cloneable {
|
||||
public boolean active = true;
|
||||
public int prev = -1;
|
||||
@ -99,7 +96,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
|
||||
updateStages();
|
||||
updateMotors();
|
||||
rocket.addComponentChangeListener(this);
|
||||
}
|
||||
|
||||
public Rocket getRocket() {
|
||||
@ -115,16 +111,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.setAllStages(true, true);
|
||||
}
|
||||
|
||||
public void setAllStages(final boolean _active) {
|
||||
this.setAllStages(_active, true);
|
||||
}
|
||||
|
||||
private void setAllStages(final boolean _active, final boolean fireEvent) {
|
||||
private void setAllStages(final boolean _active, final boolean updateRequired ) {
|
||||
for (StageFlags cur : stages.values()) {
|
||||
cur.active = _active;
|
||||
}
|
||||
if( fireEvent ){
|
||||
fireChangeEvent();
|
||||
if( updateRequired ){
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,11 +149,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.setStageActive(stageNumber, _active, true );
|
||||
}
|
||||
|
||||
private void setStageActive(final int stageNumber, final boolean _active, final boolean fireEvent) {
|
||||
private void setStageActive(final int stageNumber, final boolean _active, final boolean updateRequired ) {
|
||||
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
|
||||
stages.get(stageNumber).active = _active;
|
||||
if( fireEvent ){
|
||||
fireChangeEvent();
|
||||
if( updateRequired ){
|
||||
update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -173,7 +165,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
|
||||
StageFlags flags = stages.get(stageNumber);
|
||||
flags.active = !flags.active;
|
||||
fireChangeEvent();
|
||||
return;
|
||||
}
|
||||
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
|
||||
@ -282,38 +273,24 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
* This configuration may not be used after a call to this method!
|
||||
*/
|
||||
public void release() {
|
||||
rocket.removeComponentChangeListener(this);
|
||||
listenerList = new ArrayList<EventListener>();
|
||||
}
|
||||
|
||||
//////////////// Listeners ////////////////
|
||||
|
||||
@Override
|
||||
public void addChangeListener(StateChangeListener listener) {
|
||||
listenerList.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChangeListener(StateChangeListener listener) {
|
||||
listenerList.remove(listener);
|
||||
}
|
||||
|
||||
// for outgoing events only
|
||||
protected void fireChangeEvent() {
|
||||
EventObject e = new EventObject(this);
|
||||
|
||||
this.modID++;
|
||||
boundsModID = -1;
|
||||
refLengthModID = -1;
|
||||
|
||||
// Copy the list before iterating to prevent concurrent modification exceptions.
|
||||
EventListener[] listeners = listenerList.toArray(new EventListener[0]);
|
||||
for (EventListener l : listeners) {
|
||||
if (l instanceof StateChangeListener) {
|
||||
((StateChangeListener) l).stateChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
updateStages();
|
||||
updateMotors();
|
||||
}
|
||||
@ -344,18 +321,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
return configurationName;
|
||||
}else{
|
||||
if( this.hasMotors()){
|
||||
return fcid.toShortKey()+" - "+this.getMotorsOneline();
|
||||
return fcid.toDebug()+" - "+this.getOnelineMotorDescription();
|
||||
}else{
|
||||
return fcid.getFullKeyText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toShort() {
|
||||
return this.fcid.toShortKey();
|
||||
}
|
||||
|
||||
public String getMotorsOneline(){
|
||||
public String getOnelineMotorDescription(){
|
||||
StringBuilder buff = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
int activeMotorCount = 0;
|
||||
@ -497,6 +470,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
updateStages();
|
||||
updateMotors();
|
||||
}
|
||||
/////////////// Helper methods ///////////////
|
||||
|
||||
/**
|
||||
@ -559,7 +537,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
public FlightConfiguration clone() {
|
||||
FlightConfiguration clone = new FlightConfiguration( this.getRocket(), this.fcid );
|
||||
clone.setName("clone - "+this.fcid.toShortKey());
|
||||
clone.listenerList = new ArrayList<EventListener>();
|
||||
for( StageFlags flags : this.stages.values()){
|
||||
clone.stages.put( flags.stage.getStageNumber(), flags.clone());
|
||||
}
|
||||
@ -596,4 +573,63 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.isNamed = true;
|
||||
this.configurationName = newName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other){
|
||||
if( other instanceof FlightConfiguration ){
|
||||
return this.fcid.equals( ((FlightConfiguration)other).fcid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return this.fcid.hashCode();
|
||||
}
|
||||
|
||||
|
||||
public String toDebug() {
|
||||
return this.fcid.toDebug()+" #"+instanceNumber;
|
||||
}
|
||||
|
||||
// DEBUG / DEVEL
|
||||
public String toStageListDetail() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("\nDumping %d stages for config: %s: (#: %d)\n", this.stages.size(), this.getName(), this.instanceNumber));
|
||||
final String fmt = " [%-2s][%4s]: %6s \n";
|
||||
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
||||
for (StageFlags flags : this.stages.values()) {
|
||||
AxialStage curStage = flags.stage;
|
||||
buf.append(String.format(fmt, curStage.getStageNumber(), (flags.active?" on": "off"), curStage.getName()));
|
||||
}
|
||||
buf.append("\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
// DEBUG / DEVEL
|
||||
public String toMotorDetail(){
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("\nDumping %2d Motors for configuration %s: (#: %s)\n", this.motors.size(), this, this.instanceNumber));
|
||||
final String fmt = " ..[%-8s] <%6s> %-12s %-20s\n";
|
||||
buf.append(String.format(fmt, "Motor Id", "?active", "Mtr Desig","Mount"));
|
||||
for( MotorConfiguration curConfig : this.motors.values() ){
|
||||
MotorMount mount = curConfig.getMount();
|
||||
|
||||
String motorId = curConfig.getID().toShortKey();
|
||||
String activeDescr = (curConfig.isActive()? "active": "inactv");
|
||||
String motorDesig;
|
||||
if( curConfig.isEmpty() ){
|
||||
motorDesig = "(empty)";
|
||||
}else{
|
||||
motorDesig = curConfig.getMotor().getDesignation();
|
||||
}
|
||||
String mountName = ((RocketComponent)mount).getName();
|
||||
|
||||
buf.append(String.format( fmt, motorId, activeDescr, motorDesig, mountName));
|
||||
}
|
||||
buf.append("\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,11 +11,12 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
|
||||
final public UUID key;
|
||||
|
||||
private final static long DEFAULT_MOST_SIG_BITS = 0xF4F2F1F0;
|
||||
private final static UUID ERROR_CONFIGURATION_UUID = new UUID( DEFAULT_MOST_SIG_BITS, 2489);
|
||||
private final static String ERROR_KEY_NAME = "<Error_Key>";
|
||||
private final static UUID ERROR_UUID = new UUID( DEFAULT_MOST_SIG_BITS, 2489);
|
||||
private final static String ERROR_KEY_NAME = "ErrorKey";
|
||||
private final static UUID DEFAULT_VALUE_UUID = new UUID( DEFAULT_MOST_SIG_BITS, 5676);
|
||||
private final static String DEFAULT_VALUE_NAME = "DefaultKey";
|
||||
|
||||
public final static FlightConfigurationId ERROR_CONFIGURATION_FCID = new FlightConfigurationId( FlightConfigurationId.ERROR_CONFIGURATION_UUID);
|
||||
public final static FlightConfigurationId ERROR_FCID = new FlightConfigurationId( FlightConfigurationId.ERROR_UUID);
|
||||
public final static FlightConfigurationId DEFAULT_VALUE_FCID = new FlightConfigurationId( FlightConfigurationId.DEFAULT_VALUE_UUID );
|
||||
|
||||
public FlightConfigurationId() {
|
||||
@ -38,7 +39,7 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
|
||||
|
||||
public FlightConfigurationId(final UUID _val) {
|
||||
if (null == _val){
|
||||
this.key = FlightConfigurationId.ERROR_CONFIGURATION_UUID;
|
||||
this.key = FlightConfigurationId.ERROR_UUID;
|
||||
} else {
|
||||
this.key = _val;
|
||||
}
|
||||
@ -55,10 +56,12 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
|
||||
}
|
||||
|
||||
public String toShortKey(){
|
||||
if( isValid()){
|
||||
return this.key.toString().substring(0,8);
|
||||
if( hasError() ){
|
||||
return FlightConfigurationId.ERROR_KEY_NAME;
|
||||
}else if( this.key == FlightConfigurationId.DEFAULT_VALUE_UUID){
|
||||
return FlightConfigurationId.DEFAULT_VALUE_NAME;
|
||||
}else{
|
||||
return ERROR_KEY_NAME;
|
||||
return this.key.toString().substring(0,8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +79,7 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
|
||||
}
|
||||
|
||||
public boolean hasError(){
|
||||
return (ERROR_CONFIGURATION_UUID == this.key);
|
||||
return (ERROR_UUID == this.key);
|
||||
}
|
||||
public boolean isValid() {
|
||||
return !hasError();
|
||||
@ -89,7 +92,12 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
|
||||
|
||||
@Override
|
||||
public int compareTo(FlightConfigurationId other) {
|
||||
return (this.key.compareTo( other.key));
|
||||
return this.key.compareTo( other.key);
|
||||
}
|
||||
|
||||
public String toDebug(){
|
||||
return this.toShortKey();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,4 +29,6 @@ public class FlightConfigurationSet extends FlightConfigurableParameterSet<Fligh
|
||||
super( configSet, component, eventType );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -69,4 +69,9 @@ public class IgnitionConfiguration implements FlightConfigurableParameter<Igniti
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -439,6 +439,9 @@ public class Rocket extends RocketComponent {
|
||||
iterator.next().componentChanged(cce);
|
||||
}
|
||||
|
||||
// notify all configurations
|
||||
this.configSet.update();
|
||||
|
||||
// Notify all listeners
|
||||
// Copy the list before iterating to prevent concurrent modification exceptions.
|
||||
EventListener[] list = listenerList.toArray(new EventListener[0]);
|
||||
@ -454,7 +457,6 @@ public class Rocket extends RocketComponent {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Freezes the rocket structure from firing any events. This may be performed to
|
||||
* combine several actions on the structure into a single large action.
|
||||
|
@ -165,4 +165,9 @@ public class StageSeparationConfiguration implements FlightConfigurableParameter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -878,7 +878,7 @@ public class TestRockets {
|
||||
}
|
||||
|
||||
rocket.enableEvents();
|
||||
config.setAllStages(true);
|
||||
config.setAllStages();
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().clearAllStages();
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
// String treeDump = rocket.toDebugTree();
|
||||
// System.err.println( treeDump);
|
||||
@ -295,7 +295,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
rocket.getDefaultConfiguration().setAllStages(false);
|
||||
//rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
|
||||
//String treeDump = rocket.toDebugTree();
|
||||
@ -342,7 +342,6 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
// String treeDump = rocket.toDebugTree();
|
||||
// System.err.println( treeDump);
|
||||
@ -368,7 +367,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages(false);
|
||||
//rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
//String treeDump = rocket.toDebugTree();
|
||||
//System.err.println( treeDump);
|
||||
@ -395,7 +394,6 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
config.setAllStages(false);
|
||||
config.setOnlyStage( boostNum);
|
||||
|
||||
// String treeDump = rocket.toDebugTree();
|
||||
@ -446,7 +444,6 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
config.setAllStages(false);
|
||||
config.setOnlyStage( boostNum);
|
||||
|
||||
//String treeDump = rocket.toDebugTree();
|
||||
|
@ -748,8 +748,7 @@ public class ParallelStageTest extends BaseTestCase {
|
||||
actualStageNumber = boosterB.getStageNumber();
|
||||
assertEquals(" init order error: Booster B: resultant positions: ", expectedStageNumber, actualStageNumber);
|
||||
|
||||
//rocket.getDefaultConfiguration().dumpConfig();
|
||||
|
||||
// remove Booster A
|
||||
core.removeChild(2);
|
||||
|
||||
String treedump = rocket.toDebugTree();
|
||||
|
@ -101,7 +101,7 @@ public class SeparationSelectionDialog extends JDialog {
|
||||
newConfiguration.setSeparationDelay(0);
|
||||
}
|
||||
if (defaultButton.isSelected()) {
|
||||
stage.getSeparationConfigurations().clear();
|
||||
stage.getSeparationConfigurations().reset();
|
||||
stage.getSeparationConfigurations().setDefault( newConfiguration);
|
||||
} else {
|
||||
stage.getSeparationConfigurations().set(id, newConfiguration);
|
||||
|
@ -160,7 +160,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
} else if ( tableValue instanceof FlightConfigurationId ){
|
||||
return (FlightConfigurationId) tableValue;
|
||||
}
|
||||
return FlightConfigurationId.ERROR_CONFIGURATION_FCID;
|
||||
return FlightConfigurationId.ERROR_FCID;
|
||||
}
|
||||
|
||||
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user