Merge pull request #268 from teyrana/configfix

Multiple Configuration Fixes
This commit is contained in:
kruland2607 2016-04-26 09:30:13 -05:00
commit 1a3b5efb74
43 changed files with 675 additions and 466 deletions

View File

@ -25,5 +25,7 @@
<classpathentry kind="lib" path="/OpenRocket Test Libraries/junit-dep-4.8.2.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/test-plugin.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/uispec4j-2.3-jdk16.jar"/>
<classpathentry kind="lib" path="/OpenRocket Swing/lib/logback-classic-1.0.12.jar"/>
<classpathentry kind="lib" path="/OpenRocket Swing/lib/logback-core-1.0.12.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -164,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
}
public FlightConfiguration getDefaultConfiguration() {
public FlightConfiguration getSelectedConfiguration() {
return rocket.getSelectedConfiguration();
}
@ -286,7 +286,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
removeSimulation(s);
}
}
rocket.removeFlightConfigurationID(configId);
rocket.removeFlightConfiguration(configId);
}

View File

@ -62,9 +62,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
}
if ("true".equals(attributes.remove("default"))) {
// also associate this configuration with the default.
FlightConfiguration fc = rocket.getFlightConfiguration(fcid);
rocket.setSelectedConfiguration( fc);
rocket.setSelectedConfiguration( fcid);
}
super.closeElement(element, attributes, content, warnings);

View File

@ -53,7 +53,7 @@ public class OpenRocketLoader extends AbstractRocketLoader {
throw new RocketLoadException("Malformed XML in input.", e);
}
doc.getDefaultConfiguration().setAllStages();
doc.getSelectedConfiguration().setAllStages();
// Deduce suitable time skip
double timeSkip = StorageOptions.SIMULATION_DATA_NONE;

View File

@ -16,19 +16,18 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public static final String EMPTY_DESCRIPTION = "Empty Motor Configuration".intern();
protected final MotorMount mount;
protected final FlightConfigurationId fcid;
protected final MotorConfigurationId id;
private final MotorMount mount;
private final FlightConfigurationId fcid;
private final MotorConfigurationId mid;
protected String name = "";
protected Motor motor = null;
protected double ejectionDelay = 0.0;
private Motor motor = null;
private double ejectionDelay = 0.0;
protected boolean ignitionOveride = false;
protected double ignitionDelay = 0.0;
protected IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
private boolean ignitionOveride = false;
private double ignitionDelay = 0.0;
private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
protected int modID = 0;
private int modID = 0;
public MotorConfiguration( final MotorMount _mount, final FlightConfigurationId _fcid ) {
if (null == _mount ) {
@ -40,7 +39,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.mount = _mount;
this.fcid = _fcid;
this.id = new MotorConfigurationId( _mount, _fcid );
this.mid = new MotorConfigurationId( _mount, _fcid );
modID++;
}
@ -68,7 +67,15 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
}
public MotorConfigurationId getID() {
return this.id;
return this.mid;
}
public FlightConfigurationId getFCID() {
return fcid;
}
public MotorConfigurationId getMID() {
return mid;
}
public void setMotor(Motor motor){
@ -175,7 +182,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
return false;
}else if( other instanceof MotorConfiguration ){
MotorConfiguration omi = (MotorConfiguration)other;
if( this.id.equals( omi.id)){
if( this.mid.equals( omi.mid)){
return true;
}
}
@ -184,25 +191,38 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
@Override
public int hashCode() {
return this.id.hashCode();
return this.mid.hashCode();
}
/**
* Create a new instance of this motor instance. The state of the motor is
* identical to this instance and can be used independently from this one.
*/
@Override
public MotorConfiguration clone( ) {
MotorConfiguration clone = new MotorConfiguration( this.mount, this.fcid);
clone.motor = this.motor;
clone.ejectionDelay = this.ejectionDelay;
clone.ignitionOveride = this.ignitionOveride;
clone.ignitionDelay = this.ignitionDelay;
clone.ignitionEvent = this.ignitionEvent;
return clone;
}
public int getModID() {
/**
* Create a new instance of this motor instance. The state of the motor is
* identical to this instance and can be used independently from this one.
*/
@Override
public MotorConfiguration clone( ) {
MotorConfiguration clone = new MotorConfiguration( this.mount, this.fcid);
clone.motor = this.motor;
clone.ejectionDelay = this.ejectionDelay;
clone.ignitionOveride = this.ignitionOveride;
clone.ignitionDelay = this.ignitionDelay;
clone.ignitionEvent = this.ignitionEvent;
return clone;
}
@Override
public MotorConfiguration copy( final FlightConfigurationId copyId){
MotorConfiguration clone = new MotorConfiguration( this.mount, copyId);
clone.motor = this.motor;
clone.ejectionDelay = this.ejectionDelay;
clone.ignitionOveride = this.ignitionOveride;
clone.ignitionDelay = this.ignitionDelay;
clone.ignitionEvent = this.ignitionEvent;
return clone;
}
public int getModID() {
return modID;
}
@ -223,14 +243,15 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public String toDebugDetail( ) {
StringBuilder buf = new StringBuilder();
buf.append(String.format(">> in: %28s::%10s %8s ign@: %12s ",
buf.append(String.format("[in: %28s][fcid %10s][mid %10s][ %8s ign@: %12s]",
mount.getDebugName(),
fcid.toShortKey(),
mid.toDebug(),
toMotorDescription(),
toIgnitionDescription() ));
return buf.toString();
}
}

View File

@ -18,17 +18,12 @@ public final class MotorConfigurationId {
private final static String ERROR_ID_TEXT = "MotorInstance Error Id".intern();
private final static UUID ERROR_KEY = new UUID( 62274413, 56768908);
public final static MotorConfigurationId ERROR_ID = new MotorConfigurationId();
private MotorConfigurationId( ) {
this.key = MotorConfigurationId.ERROR_KEY;
}
/**
* Sole constructor.
*
* @param componentName the component ID, must not be null
* @param number a positive motor number
* @param _mount the component ID, must not be null
* @param _fcid the key for a
*/
public MotorConfigurationId(final MotorMount _mount, final FlightConfigurationId _fcid) {
if (null == _mount ) {
@ -38,12 +33,10 @@ public final class MotorConfigurationId {
throw new NullPointerException("Provided FlightConfigurationId was null");
}
// Use intern so comparison can be done using == instead of equals()
final long upper = ((long)_mount.getID().hashCode()) << 32;
final long lower = _fcid.key.getLeastSignificantBits();
this.key = new UUID( upper, lower);
final long mountHash= ((long)_mount.getID().hashCode()) << 32;
final long fcidLower = _fcid.key.getMostSignificantBits();
this.key = new UUID( mountHash, fcidLower);
}
@Override
public boolean equals(Object other) {
@ -62,6 +55,10 @@ public final class MotorConfigurationId {
return key.hashCode();
}
public String toDebug(){
return toShortKey();
}
@Override
public String toString(){
if( this.key == MotorConfigurationId.ERROR_KEY){
@ -70,4 +67,13 @@ public final class MotorConfigurationId {
return key.toString();
}
}
public String toShortKey() {
final String keyString = key.toString();
final int lastIndex = -1 + keyString.length();
final int chunkLen = 4;
// return the head + tail of the full 64-character id
return (keyString.substring(0,chunkLen)+"/"+keyString.substring(lastIndex - chunkLen,lastIndex));
}
}

View File

@ -4,7 +4,6 @@ import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
/**
* FlightConfigurationSet for motors.
@ -24,8 +23,15 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
* @param component the rocket component on which events are fired when the parameter values are changed
* @param eventType the event type that will be fired on changes
*/
public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> configSet, RocketComponent component) {
super(configSet);
public MotorConfigurationSet(FlightConfigurableParameterSet<MotorConfiguration> sourceSet, final MotorMount newMount) {
// creates a new empty config w/ default value
super( new MotorConfiguration( newMount, FlightConfigurationId.DEFAULT_VALUE_FCID ));
for( MotorConfiguration sourceConfig : sourceSet ){
FlightConfigurationId nextFCID = sourceConfig.getFCID();
MotorConfiguration nextValue = new MotorConfiguration( newMount, nextFCID, sourceConfig);
set( nextFCID, nextValue );
}
}
@Override
@ -37,15 +43,24 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
public String toDebug(){
StringBuilder buffer = new StringBuilder();
final MotorMount mnt = this.getDefault().getMount();
buffer.append("====== Dumping MotorConfigurationSet: "+this.size()+ " motors in "+mnt.getDebugName()+" \n");
buffer.append(String.format(" ====== Dumping MotorConfigurationSet: %d motors in %s ====== ",
this.size(), mnt.getDebugName() ));
for( FlightConfigurationId loopFCID : this.map.keySet()){
MotorConfiguration curConfig = this.map.get(loopFCID);
if( this.isDefault(loopFCID)){
buffer.append( " [DEFAULT] "+curConfig.toDebugDetail()+"\n");
buffer.append( " [DEF]");
}else{
buffer.append( " "+curConfig.toDebugDetail() +"\n");
buffer.append( " ");
}
buffer.append(String.format("@%10s=[fcid//%8s][mid//%8s][ %8s ign@: %12s]\n",
loopFCID.toShortKey(),
curConfig.getFCID().toShortKey(),
curConfig.getMID().toShortKey(),
curConfig.toMotorDescription(),
curConfig.toIgnitionDescription() ));
}
return buffer.toString();
}

View File

@ -37,6 +37,11 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
return separations;
}
@Override
public void reset( final FlightConfigurationId fcid){
separations.reset(fcid);
}
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size
@Override
public Collection<Coordinate> getComponentBounds() {
@ -72,8 +77,8 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
}
@Override
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
separations.cloneFlightConfiguration(oldConfigId, newConfigId);
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
separations.copyFlightConfiguration(oldConfigId, newConfigId);
}
@Override

View File

@ -92,7 +92,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return outerRadius;
}
/**
* Set the outer radius of the body tube. If the radius is less than the wall thickness,
* the wall thickness is decreased accordingly of the value of the radius.
@ -395,10 +394,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
public Iterator<MotorConfiguration> getMotorIterator(){
return this.motors.iterator();
}
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
motors.cloneFlightConfiguration(oldConfigId, newConfigId);
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
motors.copyFlightConfiguration(oldConfigId, newConfigId);
}
@Override

View File

@ -141,6 +141,9 @@ public class DeploymentConfiguration implements FlightConfigurableParameter<Depl
@Override
public DeploymentConfiguration clone() {
return copy(null);
}
public DeploymentConfiguration copy( final FlightConfigurationId copyId) {
DeploymentConfiguration that = new DeploymentConfiguration();
that.deployAltitude = this.deployAltitude;
that.deployDelay = this.deployDelay;

View File

@ -14,6 +14,13 @@ public interface FlightConfigurableComponent {
* @param oldConfigId the old configuration ID
* @param newConfigId the new configuration ID
*/
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId);
void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId);
/**
* Reset a specific flight configuration ID to use the default parameter value.
*
* @param fcid the flight configuration ID
*/
void reset( final FlightConfigurationId fcid);
}

View File

@ -10,11 +10,18 @@ package net.sf.openrocket.rocketcomponent;
public interface FlightConfigurableParameter<E> {
/**
* Return a copy of this object. The listeners must not be copied
* to the new object.
* return an exact copy of this object
*/
public E clone();
public void update();
E clone();
/**
* return a copy of this object, corresponding to the specified Id
*
* @param fcid id to attach the new object to
* @return the desired copy
*/
E copy( final FlightConfigurationId fcid );
void update();
}

View File

@ -22,23 +22,20 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
//private static final Logger log = LoggerFactory.getLogger(ParameterSet.class);
protected final HashMap<FlightConfigurationId, E> map = new HashMap<FlightConfigurationId, E>();
protected static final FlightConfigurationId defaultValueId = FlightConfigurationId.DEFAULT_VALUE_FCID;
/**
* 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
* @param _defaultValue the first default value
*/
public FlightConfigurableParameterSet(E _defaultValue) {
this.map.put( defaultValueId, _defaultValue);
this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, _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
* @param configSet the FlightConfigurableParameterSet to copy
*/
public FlightConfigurableParameterSet(FlightConfigurableParameterSet<E> configSet ){
for (FlightConfigurationId key : configSet.map.keySet()) {
@ -55,7 +52,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* @return the default parameter value (never null)
*/
public E getDefault(){
return this.map.get( defaultValueId);
return this.map.get( FlightConfigurationId.DEFAULT_VALUE_FCID );
}
/**
@ -63,7 +60,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
*This is used in case a per-flight configuration override
* has not been defined.
*
* @param value the parameter value (null not allowed)
* @param nextDefaultValue the parameter value (null not allowed)
*/
public void setDefault(E nextDefaultValue) {
if (nextDefaultValue == null) {
@ -72,9 +69,14 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
if( this.isDefault(nextDefaultValue)){
return;
}
this.map.put( defaultValueId, nextDefaultValue);
this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, nextDefaultValue);
}
public boolean containsId( final FlightConfigurationId fcid){
return this.map.containsKey(fcid);
}
@Override
public Iterator<E> iterator() {
return map.values().iterator();
@ -93,7 +95,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* This returns either the value specified for this flight config ID,
* or the default value.
*
* @param value the parameter to find
* @param testValue the parameter to find
* @return the flight configuration ID
*/
public FlightConfigurationId getId(E testValue) {
@ -121,7 +123,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
+" than the stored values: "+index+"/"+this.map.size());
}
List<FlightConfigurationId> ids = this.getSortedConfigurationIDs();
List<FlightConfigurationId> ids = this.getIds();
FlightConfigurationId selectedId = ids.get(index);
return this.map.get(selectedId);
}
@ -135,9 +137,6 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* @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!");
}
E toReturn;
if (map.containsKey(id)) {
toReturn = map.get(id);
@ -147,38 +146,38 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
return toReturn;
}
/**
* @return a sorted list of all the contained FlightConfigurationIDs
*/
public List<FlightConfigurationId> getSortedConfigurationIDs(){
ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>();
toReturn.addAll( this.map.keySet() );
toReturn.remove( defaultValueId );
// Java 1.8:
//toReturn.sort( null );
// Java 1.7:
Collections.sort(toReturn);
return toReturn;
}
public List<FlightConfigurationId> getIds(){
return this.getSortedConfigurationIDs();
/**
* @return a sorted list of all the contained FlightConfigurationIDs
*/
public List<FlightConfigurationId> getIds(){
ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>();
toReturn.addAll( this.map.keySet() );
toReturn.remove( FlightConfigurationId.DEFAULT_VALUE_FCID );
// Java 1.8:
//toReturn.sort( null );
// Java 1.7:
Collections.sort(toReturn);
return toReturn;
}
/**
* 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)
* @param fcid the flight configuration ID
* @param nextValue the parameter value (null not allowed)
*/
public void set(FlightConfigurationId fcid, E nextValue) {
public void set( final FlightConfigurationId fcid, E nextValue) {
if ( nextValue == null) {
// null value means to delete this fcid
this.map.remove(fcid);
// null value means to delete this fcid
this.map.remove(fcid);
}else if( FlightConfigurationId.DEFAULT_VALUE_FCID == fcid ){
// if a user wants to set the default value, make them do it explicitly with .setDefaultValue(...)
return;
}else{
this.map.put(fcid, nextValue);
}
@ -187,7 +186,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
}
public boolean isDefault(E testVal) {
public boolean isDefault( final E testVal) {
return (Utils.equals( this.getDefault(), testVal));
}
@ -195,25 +194,25 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* Return whether a specific flight configuration ID is using the
* default value.
*
* @param id the flight configuration ID
* @param fcid the flight configuration ID
* @return whether the default is being used
*/
public boolean isDefault( FlightConfigurationId fcid) {
return ( this.getDefault() == this.map.get(fcid));
public boolean isDefault( final FlightConfigurationId fcid) {
return ( this.getDefault() == this.map.get(fcid));
}
/**
* Reset a specific flight configuration ID to use the default parameter value.
*
* @param id the flight configuration ID
* @param fcid the flight configuration ID
*/
public void reset( FlightConfigurationId fcid) {
public void reset( final 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() {
@ -222,10 +221,11 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
setDefault(tempValue);
}
public FlightConfigurationId cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
public FlightConfigurationId copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
// clones the ENTRIES for the given fcid's.
E oldValue = this.get(oldConfigId);
this.set(newConfigId, oldValue.clone());
E newValue = oldValue.copy( newConfigId);
this.set(newConfigId, newValue );
update();
return newConfigId;
}
@ -235,7 +235,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
StringBuilder buf = new StringBuilder();
buf.append(String.format("====== Dumping ConfigurationSet<%s> (%d configurations)\n", this.getDefault().getClass().getSimpleName(), this.size() ));
final String fmt = " [%-12s]: %s\n";
for( FlightConfigurationId loopFCID : this.getSortedConfigurationIDs()){
for( FlightConfigurationId loopFCID : getIds()){
String shortKey = loopFCID.toShortKey();
E inst = this.map.get(loopFCID);
if( this.isDefault(inst)){
@ -246,12 +246,14 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
return buf.toString();
}
public void update(){
for( E curValue: this.map.values() ){
curValue.update();
}
}
public FlightConfiguration[] toArray() {
return map.values().toArray( new FlightConfiguration[0]);
}
}

View File

@ -6,7 +6,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,18 +28,19 @@ import net.sf.openrocket.util.Monitorable;
public class FlightConfiguration implements FlightConfigurableParameter<FlightConfiguration>, Monitorable {
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
public final static String DEFAULT_CONFIGURATION_NAME = "Default Configuration".intern();
public final static String NO_MOTORS_TEXT = "[No Motors Defined]".intern();
protected String configurationName=null;
private final static String NO_MOTORS_NAME = "[No Motors Defined]";
private final static String DEFAULT_CONFIGURATION_NAME = NO_MOTORS_NAME;
private String configurationName=null;
protected final Rocket rocket;
protected final FlightConfigurationId fcid;
protected static int instanceCount=0;
private static int instanceCount=0;
// made public for testing.... there is probably a better way
public final int instanceNumber;
protected class StageFlags implements Cloneable {
private class StageFlags implements Cloneable {
public boolean active = true;
public int prev = -1;
public AxialStage stage = null;
@ -51,15 +51,10 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.active = _active;
}
public int getKey(){
return this.stage.getStageNumber();
}
@Override
public StageFlags clone(){
return new StageFlags( this.stage, this.prev, true);
}
}
/* Cached data */
@ -119,7 +114,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
/**
* This method flags a stage inactive. Other stages are unaffected.
*
* @param stageNumber stage number to inactivate
* @param stageNumber stage number to turn off
*/
public void clearStage(final int stageNumber) {
_setStageActive( stageNumber, false );
@ -175,16 +170,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public Collection<RocketComponent> getActiveComponents() {
Queue<RocketComponent> toProcess = new ArrayDeque<RocketComponent>(this.getActiveStages());
ArrayList<RocketComponent> toReturn = new ArrayList<RocketComponent>();
ArrayList<RocketComponent> toReturn = new ArrayList<>();
while (!toProcess.isEmpty()) {
RocketComponent comp = toProcess.poll();
toReturn.add(comp);
for (RocketComponent child : comp.getChildren()) {
if (child instanceof AxialStage) {
continue;
} else {
if (!(child instanceof AxialStage)) {
toProcess.offer(child);
}
}
@ -194,7 +187,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
}
public List<AxialStage> getActiveStages() {
List<AxialStage> activeStages = new ArrayList<AxialStage>();
List<AxialStage> activeStages = new ArrayList<>();
for (StageFlags flags : this.stages.values()) {
if (flags.active) {
@ -215,9 +208,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return activeCount;
}
/**
* Retrieve the bottom-most active stage.
* @return
/**
* @return the component for the bottom-most center, active stage.
*/
public AxialStage getBottomStage() {
AxialStage bottomStage = null;
@ -251,12 +243,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return Math.PI * MathUtil.pow2(getReferenceLength() / 2);
}
public FlightConfigurationId getFlightConfigurationID() {
return fcid;
}
public FlightConfigurationId getFlightConfigurationID() {
return fcid;
}
public FlightConfigurationId getId() {
return getFlightConfigurationID();
return fcid;
}
//////////////// Listeners ////////////////
@ -271,7 +263,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
updateMotors();
}
protected void updateStages() {
private void updateStages() {
if (this.rocket.getStageCount() == this.stages.size()) {
// no changes needed
return;
@ -322,17 +314,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
}
}
if( 0 == activeMotorCount ){
return NO_MOTORS_TEXT;
return DEFAULT_CONFIGURATION_NAME;
}
buff.append("]");
return buff.toString();
}
@Override
public String toString() {
return this.getName();
}
public String toString() { return this.getName(); }
/**
* Add a motor instance to this configuration.
@ -344,24 +333,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
if( motorConfig.isEmpty() ){
throw new IllegalArgumentException("MotorInstance is empty.");
}
MotorConfigurationId id = motorConfig.getID();
if (this.motors.containsKey(id)) {
throw new IllegalArgumentException("FlightConfiguration already " +
"contains a motor with id " + id);
}
this.motors.put(id, motorConfig);
this.motors.put( motorConfig.getID(), motorConfig);
modID++;
}
public Set<MotorConfigurationId> getMotorIDs() {
return motors.keySet();
}
public MotorConfiguration getMotorInstance(MotorConfigurationId id) {
return motors.get(id);
}
public boolean hasMotors() {
return (0 < motors.size());
}
@ -381,7 +358,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return activeMotors;
}
protected void updateMotors() {
private void updateMotors() {
this.motors.clear();
Iterator<RocketComponent> iter = rocket.iterator(false);
@ -394,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
continue;
}
this.motors.put( motorConfig.getID(), motorConfig);
this.motors.put( motorConfig.getMID(), motorConfig);
}
}
@ -471,22 +448,44 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
*/
@Override
public FlightConfiguration clone() {
// Note the motors and stages are updated in the constructor call.
FlightConfiguration clone = new FlightConfiguration( this.getRocket(), this.fcid );
clone.setName("clone[#"+clone.instanceNumber+"]"+clone.fcid.toShortKey());
// log.error(">> Why am I being cloned!?", new IllegalStateException(this.toDebug()+" >to> "+clone.toDebug()));
// DO NOT UPDATE this.stages or this.motors;
// these are are updated correctly on their own.
clone.cachedBounds = this.cachedBounds.clone();
// Note the stages are updated in the constructor call.
FlightConfiguration clone = new FlightConfiguration( this.rocket, this.fcid );
clone.setName("clone[#"+clone.instanceNumber+"]"+clone.fcid.toShortKey());
clone.cachedBounds = this.cachedBounds.clone();
clone.modID = this.modID;
clone.boundsModID = -1;
clone.refLengthModID = -1;
return clone;
}
/**
* Copy all available information attached to this, and attached copies to the
* new configuration
*
* @param copyId attached the new configuration to this Id
* @return the new configuration
*/
@Override
public FlightConfiguration copy( final FlightConfigurationId copyId ) {
// Note the stages are updated in the constructor call.
FlightConfiguration copy= new FlightConfiguration( this.rocket, copyId );
// copy motor instances.
for( final MotorConfiguration sourceMotor: motors.values() ){
MotorConfiguration cloneMotor = sourceMotor.copy( copyId);
copy.addMotor( cloneMotor);
cloneMotor.getMount().setMotorConfig(cloneMotor, copyId);
}
copy.cachedBounds = this.cachedBounds.clone();
copy.modID = this.modID;
copy.boundsModID = -1;
copy.refLengthModID = -1;
return copy;
}
@Override
public int getModID() {
// TODO: this doesn't seem consistent...
@ -502,7 +501,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
if(( null == newName ) ||( "".equals(newName))){
this.configurationName = null;
return;
}else if( ! this.getFlightConfigurationID().isValid()){
}else if( ! this.getId().isValid()){
return;
}else if( newName.equals(this.configurationName)){
return;
@ -512,10 +511,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
@Override
public boolean equals(Object other){
if( other instanceof FlightConfiguration ){
return this.fcid.equals( ((FlightConfiguration)other).fcid);
}
return false;
return (( other instanceof FlightConfiguration ) &&
this.fcid.equals( ((FlightConfiguration)other).fcid));
}
@Override
@ -530,10 +527,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
// 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));
buf.append(String.format("\nDumping %d stages for config: %s: (%s)(#: %d)\n",
stages.size(), getName(), getId().toShortKey(), instanceNumber));
final String fmt = " [%-2s][%4s]: %6s \n";
buf.append(String.format(fmt, "#", "?actv", "Name"));
for (StageFlags flags : this.stages.values()) {
for (StageFlags flags : stages.values()) {
AxialStage curStage = flags.stage;
buf.append(String.format(fmt, curStage.getStageNumber(), (flags.active?" on": "off"), curStage.getName()));
}
@ -545,7 +543,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public String toMotorDetail(){
StringBuilder buf = new StringBuilder();
buf.append(String.format("\nDumping %2d Motors for configuration %s (%s)(#: %s)\n",
this.motors.size(), this.getName(), this.getFlightConfigurationID().toFullKey(), this.instanceNumber));
motors.size(), getName(), getId().toShortKey(), this.instanceNumber));
for( MotorConfiguration curConfig : this.motors.values() ){
buf.append(" "+curConfig.toDebugDetail()+"\n");

View File

@ -73,11 +73,7 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
public int hashCode() {
return this.key.hashCode();
}
public UUID intern() {
return this.key;
}
public boolean hasError(){
return (ERROR_UUID == this.key);
}

View File

@ -34,13 +34,16 @@ public class IgnitionConfiguration implements FlightConfigurableParameter<Igniti
@Override
public IgnitionConfiguration clone() {
IgnitionConfiguration clone = new IgnitionConfiguration();
return this.copy(null);
}
public IgnitionConfiguration copy( final FlightConfigurationId copyId) {
IgnitionConfiguration clone = new IgnitionConfiguration();
clone.ignitionDelay = this.ignitionDelay;
clone.ignitionEvent = this.ignitionEvent;
clone.ignitionTime = this.ignitionTime;
return clone;
}
}
@Override
public void update(){

View File

@ -304,10 +304,14 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
}
@Override
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
motors.cloneFlightConfiguration(oldConfigId, newConfigId);
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
motors.copyFlightConfiguration(oldConfigId, newConfigId);
}
@Override
public void reset( final FlightConfigurationId fcid){
this.motors.reset(fcid);
}
@Override
public void setMotorMount(boolean _active){

View File

@ -81,8 +81,8 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
}
@Override
public void cloneFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
this.separations.cloneFlightConfiguration(oldConfigId, newConfigId);
public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
this.separations.copyFlightConfiguration(oldConfigId, newConfigId);
}
@Override

View File

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

View File

@ -34,14 +34,12 @@ public class Rocket extends RocketComponent {
private static final Logger log = LoggerFactory.getLogger(Rocket.class);
private static final Translator trans = Application.getTranslator();
public static final String DEFAULT_NAME = "[{motors}]";
public static final double DEFAULT_REFERENCE_LENGTH = 0.01;
protected static final double DEFAULT_REFERENCE_LENGTH = 0.01;
/**
* List of component change listeners.
*/
private List<EventListener> listenerList = new ArrayList<EventListener>();
private List<EventListener> listenerList = new ArrayList<>();
/**
* When freezeList != null, events are not dispatched but stored in the list.
@ -68,8 +66,8 @@ public class Rocket extends RocketComponent {
// Flight configuration list
private FlightConfiguration selectedConfiguration;
private HashMap<FlightConfigurationId, FlightConfiguration> configSet = new HashMap<FlightConfigurationId, FlightConfiguration>();
private HashMap<Integer, AxialStage> stageMap = new HashMap<Integer, AxialStage>();
private FlightConfigurableParameterSet<FlightConfiguration> configSet;
private HashMap<Integer, AxialStage> stageMap = new HashMap<>();
// Does the rocket have a perfect finish (a notable amount of laminar flow)
private boolean perfectFinish = false;
@ -84,11 +82,11 @@ public class Rocket extends RocketComponent {
aeroModID = modID;
treeModID = modID;
functionalModID = modID;
// must be after the hashmaps :P
this.selectedConfiguration = new FlightConfiguration( this, null);
FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID);
configSet = new FlightConfigurableParameterSet<>( defaultConfig );
this.selectedConfiguration = defaultConfig;
}
public String getDesigner() {
@ -210,7 +208,7 @@ public class Rocket extends RocketComponent {
*
* @Return a reference to the topmost stage
*/
public AxialStage getBottomCoreStage(){
/*package-local*/ AxialStage getBottomCoreStage(){
// get last stage that's a direct child of the rocket.
return (AxialStage) children.get( children.size()-1 );
}
@ -222,8 +220,8 @@ public class Rocket extends RocketComponent {
}
return guess;
}
public void trackStage(final AxialStage newStage) {
/*package-local*/ void trackStage(final AxialStage newStage) {
int stageNumber = newStage.getStageNumber();
AxialStage value = stageMap.get(stageNumber);
@ -235,8 +233,8 @@ public class Rocket extends RocketComponent {
this.stageMap.put(stageNumber, newStage);
}
}
public void forgetStage(final AxialStage oldStage) {
/*package-local*/ void forgetStage(final AxialStage oldStage) {
this.stageMap.remove(oldStage.getStageNumber());
}
@ -311,7 +309,8 @@ public class Rocket extends RocketComponent {
// Rocket copy is cloned, so non-trivial members must be cloned as well:
copy.stageMap = new HashMap<Integer, AxialStage>();
copy.configSet = new HashMap<FlightConfigurationId, FlightConfiguration>();
copy.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( this.configSet );
new HashMap<FlightConfigurationId, FlightConfiguration>();
if( 0 < this.configSet.size() ){
Rocket.cloneConfigs( this, copy);
}
@ -324,8 +323,8 @@ public class Rocket extends RocketComponent {
source.checkState();
dest.checkState();
dest.selectedConfiguration = source.selectedConfiguration.clone();
for( final FlightConfiguration config : source.configSet.values() ){
dest.configSet.put( config.getId(), config.clone() );
for( final FlightConfiguration config : source.configSet ){
dest.configSet.set( config.getId(), config.clone() );
}
}
@ -473,7 +472,7 @@ public class Rocket extends RocketComponent {
private void updateConfigurations(){
this.selectedConfiguration.update();
for( FlightConfiguration config : configSet.values() ){
for( FlightConfiguration config : configSet ){
config.update();
}
}
@ -483,7 +482,12 @@ public class Rocket extends RocketComponent {
// Copy the list before iterating to prevent concurrent modification exceptions.
EventListener[] list = listenerList.toArray(new EventListener[0]);
for (EventListener l : list) {
if (l instanceof ComponentChangeListener) {
{ // vvvv DEVEL vvvv
//System.err.println("notifying listener. (type= "+l.getClass().getSimpleName()+")");
//System.err.println(" (type= "+l.getClass().getName()+")");
} // ^^^^ DEVEL ^^^^
if (l instanceof ComponentChangeListener) {
((ComponentChangeListener) l).componentChanged(cce);
} else if (l instanceof StateChangeListener) {
((StateChangeListener) l).stateChanged(cce);
@ -512,7 +516,7 @@ public class Rocket extends RocketComponent {
public void freeze() {
checkState();
if (freezeList == null) {
freezeList = new LinkedList<ComponentChangeEvent>();
freezeList = new LinkedList<>();
log.debug("Freezing Rocket");
} else {
Application.getExceptionHandler().handleErrorCondition("Attempting to freeze Rocket when it is already frozen, " +
@ -567,24 +571,7 @@ public class Rocket extends RocketComponent {
*/
public FlightConfiguration getSelectedConfiguration() {
checkState();
return this.selectedConfiguration;
}
public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) {
checkState();
if( null == fcid ){
throw new NullPointerException("Attempted to create a flightConfiguration from a null key!");
}else if( fcid.hasError() ){
throw new NullPointerException("Attempted to create a flightConfiguration from an error key!");
}else if( configSet.containsKey(fcid)){
return this.configSet.get(fcid);
}else{
FlightConfiguration nextConfig = new FlightConfiguration(this, fcid);
this.configSet.put(fcid, nextConfig);
this.selectedConfiguration = nextConfig;
fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE);
return nextConfig;
}
return selectedConfiguration;
}
public int getConfigurationCount(){
@ -592,42 +579,40 @@ public class Rocket extends RocketComponent {
}
public List<FlightConfigurationId> getIds(){
ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>(this.configSet.keySet());
// Java 1.8:
//toReturn.sort( null );
// Java 1.7:
Collections.sort(toReturn);
return toReturn;
return configSet.getIds();
}
/**
* Primarily for use with UI elements
*
* @return list of attached flight configurations (unordered)
*/
public FlightConfiguration[] toConfigArray(){
return this.configSet.values().toArray( new FlightConfiguration[0]);
}
/**
* Remove a flight configuration ID from the configuration IDs. The <code>null</code>
* ID cannot be removed, and an attempt to remove it will be silently ignored.
* Remove a flight configuration ID from the configuration IDs. The
* <code>FlightConfigurationId.DEFAULT_VALUE_FCID</code> ID cannot be removed,
* and an attempt to remove it will be silently ignored.
*
* @param id the flight configuration ID to remove
* @param fcid the flight configuration ID to remove
*/
public void removeFlightConfigurationID(FlightConfigurationId fcid) {
public void removeFlightConfiguration(final FlightConfigurationId fcid) {
checkState();
if( fcid.hasError() ){
return;
}
if( selectedConfiguration.getId().equals( fcid)){
selectedConfiguration = configSet.getDefault();
}
// removed any component configuration tied to this FCID
Iterator<RocketComponent> iterator = this.iterator();
while (iterator.hasNext()) {
RocketComponent comp = iterator.next();
if (comp instanceof FlightConfigurableComponent){
FlightConfigurableComponent confbl = (FlightConfigurableComponent)comp;
confbl.reset( fcid);
}
}
// Get current configuration:
this.configSet.remove( fcid);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
this.configSet.reset( fcid);
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -637,19 +622,19 @@ public class Rocket extends RocketComponent {
* @param id the configuration ID.
* @return whether a motor configuration with that ID exists.
*/
public boolean containsFlightConfigurationID(FlightConfigurationId id) {
public boolean containsFlightConfigurationID(final FlightConfigurationId id) {
checkState();
if( id.hasError() ){
return false;
}
return configSet.containsKey( id);
return configSet.containsId( id);
}
/**
* Check whether the given motor configuration ID has motors defined for it.
*
* @param id the FlightConfigurationID containing the motor (may be invalid).
* @param fcid the FlightConfigurationID containing the motor (may be invalid).
* @return whether any motors are defined for it.
*/
public boolean hasMotors(FlightConfigurationId fcid) {
@ -673,58 +658,88 @@ public class Rocket extends RocketComponent {
}
return false;
}
/**
* Return a flight configuration. If the supplied id does not have a specific instance, the default is returned.
*
* @param fcid the flight configuration id
* @return FlightConfiguration instance
*/
public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) {
checkState();
if( null == fcid ){
// fall-through to the default case...
// creating a FlightConfiguration( null ) just allocates a fresh new FCID
}else if( fcid.hasError() ){
return configSet.getDefault();
}else if( configSet.containsId(fcid)){
return this.getFlightConfiguration(fcid);
}
FlightConfiguration nextConfig = new FlightConfiguration(this, fcid);
this.configSet.set(nextConfig.getId(), nextConfig);
fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE);
return nextConfig;
}
/**
* Return a flight configuration. If the supplied id does not have a specific instance, the default is returned.
*
* @param id the flight configuration id
* @param fcid the flight configuration id
* @return a FlightConfiguration instance
*/
public FlightConfiguration getFlightConfiguration(final FlightConfigurationId fcid) {
checkState();
return this.createFlightConfiguration(fcid);
return this.configSet.get(fcid);
}
public FlightConfiguration getFlightConfigurationByIndex(final int configIndex) {
return getFlightConfigurationByIndex( configIndex, false);
}
/**
* Return a flight configuration. If the supplied index is out of bounds, an exception is thrown.
* Return a flight configuration. If the supplied index is out of bounds, an exception is thrown.
* If the default instance is allowed, the default will be at index 0.
*
* @param id the flight configuration index number
* @return a FlightConfiguration instance
* @param includeDefault Whether to allow returning the default instance
* @param configIndex The flight configuration index number
* @return a FlightConfiguration instance
*/
public FlightConfiguration getFlightConfiguration(final int configIndex) {
public FlightConfiguration getFlightConfigurationByIndex( int configIndex, final boolean allowDefault ) {
if( allowDefault ){
if( 0 == configIndex ){
return configSet.getDefault();
}
--configIndex;
}
return this.configSet.get( this.getId(configIndex));
}
public FlightConfigurationId getId( final int configIndex) {
List<FlightConfigurationId> idList = this.getIds();
List<FlightConfigurationId> idList = configSet.getIds();
return idList.get(configIndex);
}
public void setSelectedConfiguration(final FlightConfiguration config) {
checkState();
this.selectedConfiguration = config;
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
public void setDefaultConfiguration(final FlightConfigurationId fcid) {
public void setSelectedConfiguration(final FlightConfigurationId selectId) {
checkState();
if( fcid.hasError() ){
log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid));
if( selectId.equals( selectedConfiguration.getFlightConfigurationID())){
// if desired configuration is already selected, skip the event
return;
}else if( this.configSet.containsKey(fcid)){
this.selectedConfiguration = configSet.get(fcid);
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
}
this.selectedConfiguration = this.configSet.get( selectId );
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
/**
* Associate the given ID and flight configuration.
* <code>null</code> or an empty string.
*
* @param id the flight configuration id
* @param name the name for the flight configuration
* @param fcid the flight configuration id
* @param newConfig new FlightConfiguration to store
*/
public void setFlightConfiguration(final FlightConfigurationId fcid, FlightConfiguration newConfig) {
checkState();
@ -734,13 +749,16 @@ public class Rocket extends RocketComponent {
}
if (null == newConfig){
newConfig = createFlightConfiguration(fcid);
configSet.reset( fcid);
}else if( fcid.equals( configSet.get(fcid).getFlightConfigurationID())){
// this mapping already exists; skip the event
return;
}else{
configSet.set(fcid, newConfig);
}
configSet.put(fcid, newConfig);
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
//////// Obligatory component information
@Override
public String getComponentName() {
@ -820,9 +838,10 @@ public class Rocket extends RocketComponent {
public String toDebugConfigs(){
StringBuilder buf = new StringBuilder();
buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName()));
buf.append(String.format("====== Dumping %d Configurations from rocket: %s ======\n",
this.getConfigurationCount(), this.getName()));
final String fmt = " [%12s]: %s\n";
for( FlightConfiguration config : this.configSet.values() ){
for( FlightConfiguration config : this.configSet ){
String shortKey = config.getId().toShortKey();
if( this.selectedConfiguration.equals( config)){
shortKey = "=>" + shortKey;

View File

@ -135,6 +135,10 @@ public class StageSeparationConfiguration implements FlightConfigurableParameter
@Override
public StageSeparationConfiguration clone() {
return copy(null);
}
public StageSeparationConfiguration copy( final FlightConfigurationId copyId){
StageSeparationConfiguration clone = new StageSeparationConfiguration();
clone.separationEvent = this.separationEvent;
clone.separationDelay = this.separationDelay;

View File

@ -1,31 +0,0 @@
package net.sf.openrocket.rocketvisitors;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.RocketComponent;
public class CopyFlightConfigurationVisitor extends DepthFirstRecusiveVisitor<Void> {
private final FlightConfigurationId oldConfigId;
private final FlightConfigurationId newConfigId;
public CopyFlightConfigurationVisitor(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) {
super();
this.oldConfigId = oldConfigId;
this.newConfigId = newConfigId;
}
@Override
public void doAction(RocketComponent visitable) {
if (visitable instanceof FlightConfigurableComponent) {
((FlightConfigurableComponent) visitable).cloneFlightConfiguration(oldConfigId, newConfigId);
}
}
@Override
public Void getResult() {
return null;
}
}

View File

@ -101,14 +101,13 @@ public class TestRockets {
// Motor.Type type, double[] delays, double diameter, double length,
// double[] time, double[] thrust,
// Coordinate[] cg, String digest);
ThrustCurveMotor mtr = new ThrustCurveMotor(
Manufacturer.getManufacturer("Estes"),"A8", " SU Black Powder",
return new ThrustCurveMotor(
Manufacturer.getManufacturer("Estes"),"A8", " SU Black Powder",
Motor.Type.SINGLE, new double[] {0,3,5}, 0.018, 0.070,
new double[] { 0, 1, 2 }, new double[] { 0, 9, 0 },
new Coordinate[] {
new Coordinate(0.035, 0, 0, 0.0164),new Coordinate(.035, 0, 0, 0.0145),new Coordinate(.035, 0, 0, 0.0131)},
new Coordinate(0.035, 0, 0, 0.0164),new Coordinate(.035, 0, 0, 0.0145),new Coordinate(.035, 0, 0, 0.0131)},
"digest A8 test");
return mtr;
}
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
@ -117,14 +116,13 @@ public class TestRockets {
// Motor.Type type, double[] delays, double diameter, double length,
// double[] time, double[] thrust,
// Coordinate[] cg, String digest);
ThrustCurveMotor mtr = new ThrustCurveMotor(
return new ThrustCurveMotor(
Manufacturer.getManufacturer("Estes"),"B4", " SU Black Powder",
Motor.Type.SINGLE, new double[] {0,3,5}, 0.018, 0.070,
new double[] { 0, 1, 2 }, new double[] { 0, 11.4, 0 },
new Coordinate[] {
new Coordinate(0.035, 0, 0, 0.0195),new Coordinate(.035, 0, 0, 0.0155),new Coordinate(.035, 0, 0, 0.013)},
"digest B4 test");
return mtr;
}
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
@ -133,26 +131,24 @@ public class TestRockets {
// Motor.Type type, double[] delays, double diameter, double length,
// double[] time, double[] thrust,
// Coordinate[] cg, String digest);
ThrustCurveMotor mtr = new ThrustCurveMotor(
return new ThrustCurveMotor(
Manufacturer.getManufacturer("Estes"),"C6", " SU Black Powder",
Motor.Type.SINGLE, new double[] {0,3,5,7}, 0.018, 0.070,
new double[] { 0, 1, 2 }, new double[] { 0, 6, 0 },
new Coordinate[] {
new Coordinate(0.035, 0, 0, 0.0227),new Coordinate(.035, 0, 0, 0.0165),new Coordinate(.035, 0, 0, 0.012)},
"digest C6 test");
return mtr;
}
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
private static Motor generateMotor_D21_18mm(){
ThrustCurveMotor mtr = new ThrustCurveMotor(
return new ThrustCurveMotor(
Manufacturer.getManufacturer("AeroTech"),"D21", "Desc",
Motor.Type.SINGLE, new double[] {}, 0.018, 0.07,
new double[] { 0, 1, 2 }, new double[] { 0, 32, 0 },
new Coordinate[] {
new Coordinate(.035, 0, 0, 0.025),new Coordinate(.035, 0, 0, .020),new Coordinate(.035, 0, 0, 0.0154)},
"digest D21 test");
return mtr;
}
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
@ -161,14 +157,13 @@ public class TestRockets {
// Motor.Type type, double[] delays, double diameter, double length,
// double[] time, double[] thrust,
// Coordinate[] cg, String digest);
ThrustCurveMotor mtr = new ThrustCurveMotor(
return new ThrustCurveMotor(
Manufacturer.getManufacturer("AeroTech"),"M1350", "Desc",
Motor.Type.SINGLE, new double[] {}, 0.075, 0.622,
new double[] { 0, 1, 2 }, new double[] { 0, 1357, 0 },
new Coordinate[] {
new Coordinate(.311, 0, 0, 4.808),new Coordinate(.311, 0, 0, 3.389),new Coordinate(.311, 0, 0, 1.970)},
"digest M1350 test");
return mtr;
}
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
@ -177,14 +172,13 @@ public class TestRockets {
// Motor.Type type, double[] delays, double diameter, double length,
// double[] time, double[] thrust,
// Coordinate[] cg, String digest);
ThrustCurveMotor mtr = new ThrustCurveMotor(
return new ThrustCurveMotor(
Manufacturer.getManufacturer("AeroTech"),"G77", "Desc",
Motor.Type.SINGLE, new double[] {4,7,10},0.029, 0.124,
new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 },
new Coordinate[] {
new Coordinate(.062, 0, 0, 0.123),new Coordinate(.062, 0, 0, .0935),new Coordinate(.062, 0, 0, 0.064)},
"digest G77 test");
return mtr;
}
//
@ -384,7 +378,7 @@ public class TestRockets {
public static final Rocket makeEstesAlphaIII(){
Rocket rocket = new Rocket();
FlightConfigurationId fcid[] = new FlightConfigurationId[5];
fcid[0] = rocket.getSelectedConfiguration().getFlightConfigurationID();
fcid[0] = new FlightConfigurationId();
rocket.createFlightConfiguration(fcid[0]);
fcid[1] = new FlightConfigurationId();
rocket.createFlightConfiguration(fcid[1]);
@ -521,7 +515,7 @@ public class TestRockets {
bodytube.setMaterial(material);
finset.setMaterial(material);
rocket.setSelectedConfiguration( rocket.getFlightConfiguration( fcid[0]));
rocket.setSelectedConfiguration( fcid[0] );
rocket.getSelectedConfiguration().setAllStages();
rocket.enableEvents();
return rocket;
@ -541,8 +535,7 @@ public class TestRockets {
fcid[i] = new FlightConfigurationId();
rocket.createFlightConfiguration(fcid[i]);
}
FlightConfiguration selectedConfiguration = rocket.getFlightConfiguration(fcid[0]);
double noseconeLength = 0.07;
double noseconeRadius = 0.012;
NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius);
@ -714,7 +707,7 @@ public class TestRockets {
}
rocket.getSelectedConfiguration().setAllStages();
rocket.setSelectedConfiguration( selectedConfiguration );
rocket.setSelectedConfiguration( fcid[0] );
rocket.enableEvents();
return rocket;
}
@ -1029,9 +1022,11 @@ public class TestRockets {
public static Rocket makeFalcon9Heavy() {
Rocket rocket = new Rocket();
rocket.setName("Falcon9H Scale Rocket");
FlightConfiguration selConfig = rocket.getSelectedConfiguration();
FlightConfigurationId selFCID = selConfig.getFlightConfigurationID();
FlightConfiguration selConfig = rocket.createFlightConfiguration(null);
FlightConfigurationId selFCID = selConfig.getFlightConfigurationID();
rocket.setSelectedConfiguration(selFCID);
// ====== Payload Stage ======
// ====== ====== ====== ======
AxialStage payloadStage = new AxialStage();
@ -1178,7 +1173,7 @@ public class TestRockets {
}
rocket.enableEvents();
rocket.setSelectedConfiguration(selConfig);
rocket.setSelectedConfiguration( selFCID);
selConfig.setAllStages();
return rocket;

View File

@ -131,6 +131,7 @@ public class OpenRocketSaverTest {
rocketDocs.add(TestRockets.makeTestRocket_v106_withRecoveryDeviceDeploymentConfig());
rocketDocs.add(TestRockets.makeTestRocket_v106_withStageSeparationConfig());
rocketDocs.add(TestRockets.makeTestRocket_v107_withSimulationExtension(SIMULATION_EXTENSION_SCRIPT));
rocketDocs.add(TestRockets.makeTestRocket_v108_withBoosters());
rocketDocs.add(TestRockets.makeTestRocket_for_estimateFileSize());
StorageOptions options = new StorageOptions();

View File

@ -142,12 +142,27 @@ public class FlightConfigurationTest extends BaseTestCase {
config.setAllStages();
}
/**
* Single stage rocket specific configuration tests
*/
@Test
public void testConfigurationSwitching() {
@Test
public void testCreateConfigurationNullId() {
/* Setup */
Rocket rkt = TestRockets.makeEstesAlphaIII();
// PRE-CONDITION:
// test that all configurations correctly loaded:
int expectedConfigCount = 5;
int actualConfigCount = rkt.getConfigurationCount();
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
// create with
rkt.createFlightConfiguration(null);
expectedConfigCount = 6;
actualConfigCount = rkt.getConfigurationCount();
assertThat("createFlightConfiguration with null: doesn't actually work.", actualConfigCount, equalTo(expectedConfigCount));
}
@Test
public void testMotorConfigurations() {
/* Setup */
Rocket rkt = TestRockets.makeEstesAlphaIII();
@ -156,14 +171,42 @@ public class FlightConfigurationTest extends BaseTestCase {
int expectedMotorCount = 5;
int actualMotorCount = smmt.getMotorCount();
assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount));
}
@Test
public void testFlightConfigurationGetters(){
Rocket rkt = TestRockets.makeEstesAlphaIII();
// test that all configurations correctly loaded:
int expectedConfigCount = 5;
int actualConfigCount = rkt.getConfigurationCount();
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
}
actualConfigCount = rkt.getIds().size();
assertThat("number of configuration array ids doesn't actually match.",
actualConfigCount, equalTo(expectedConfigCount));
// upon success, these silently complete.
// upon failure, they'll throw exceptions:
rkt.getFlightConfigurationByIndex(4);
rkt.getFlightConfigurationByIndex(5, true);
}
@Test(expected=java.lang.IndexOutOfBoundsException.class)
public void testGetFlightConfigurationOutOfBounds(){
Rocket rkt = TestRockets.makeEstesAlphaIII();
// test that all configurations correctly loaded:
int expectedConfigCount = 5;
int actualConfigCount = rkt.getConfigurationCount();
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
// this SHOULD throw an exception --
// it's out of bounds on, and no configuration exists at index 5.
rkt.getFlightConfigurationByIndex(5);
}
/**
* Multi stage rocket specific configuration tests

View File

@ -51,11 +51,16 @@ public class ParameterSetTest extends BaseTestCase {
public String toString(){
return "tp#:"+id;
}
@Override
public TestParameter clone(){
return new TestParameter();
}
@Override
public TestParameter clone(){
return new TestParameter();
}
@Override
public TestParameter copy( final FlightConfigurationId copyId){
return new TestParameter();
}
};
@Before
@ -138,7 +143,7 @@ public class ParameterSetTest extends BaseTestCase {
// testSet.getSortedConfigurationIDs()
// >> this function should ONLY return ids for the overrides
assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.size()));
assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getSortedConfigurationIDs().size(), equalTo( testSet.getIds().size() ) );
assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.getIds().size() ) );
}
@Test
@ -230,7 +235,7 @@ public class ParameterSetTest extends BaseTestCase {
assertThat("set stores default value correctly: ", testSet.get(fcid2), equalTo( tp2 ));
FlightConfigurationId fcid3 = new FlightConfigurationId();
testSet.cloneFlightConfiguration(fcid2, fcid3);
testSet.copyFlightConfiguration(fcid2, fcid3);
// fcid <=> tp2 should be stored....
assertThat("set should contain zero overrides: ", testSet.size(), equalTo( 2 ));
assertThat("set stores default value correctly: ", testSet.get(fcid3), not( testSet.getDefault() ));

View File

@ -39,7 +39,6 @@ public class RocketTest extends BaseTestCase {
FlightConfigurationId fcid5 = config5.getId();
assertThat("fcids should match: ", config2.getId(), equalTo(fcid5));
assertThat("Configurations should bef different match: "+config2.toDebug()+"=?="+config5.toDebug(), config2.instanceNumber, not( config5.instanceNumber));
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jogl/jogl-all.jar"/>
<classpathentry kind="lib" path="lib/iText-5.0.2.jar"/>
@ -22,5 +23,12 @@
<classpathentry kind="lib" path="/OpenRocket Core/lib/annotation-detector-3.0.2.jar"/>
<classpathentry kind="lib" path="lib/miglayout-4.0-swing.jar" sourcepath="reference/miglayout-4.0-sources.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.5.6.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/hamcrest-core-1.3.0RC1.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/hamcrest-library-1.3.0RC1.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/jmock-2.6.0-RC2.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/jmock-junit4-2.6.0-RC2.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/junit-dep-4.8.2.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/test-plugin.jar"/>
<classpathentry kind="lib" path="/OpenRocket Test Libraries/uispec4j-2.3-jdk16.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -4,7 +4,7 @@ import java.util.Comparator;
import javax.swing.table.TableRowSorter;
public class ColumnTableRowSorter extends TableRowSorter {
public class ColumnTableRowSorter extends TableRowSorter<ColumnTableModel> {
private final ColumnTableModel columnTableModel;
@ -14,8 +14,8 @@ public class ColumnTableRowSorter extends TableRowSorter {
}
@Override
public Comparator getComparator(int column) {
Comparator c = columnTableModel.getColumn(column).getComparator();
public Comparator<?> getComparator(int column) {
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
return (c!= null) ? c : super.getComparator(column);
}
@ -30,7 +30,7 @@ public class ColumnTableRowSorter extends TableRowSorter {
*/
@Override
protected boolean useToString(int column) {
Comparator c = columnTableModel.getColumn(column).getComparator();
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
return ( c != null ) ? false : super.useToString(column);
}

View File

@ -47,7 +47,7 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
@Override
public int getSize() {
this.idList = this.sourceSet.getSortedConfigurationIDs();
this.idList = this.sourceSet.getIds();
return this.idList.size();
}
@ -109,7 +109,7 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
return;
}
fireListDataEvent();
this.idList = this.sourceSet.getSortedConfigurationIDs();
this.idList = this.sourceSet.getIds();
}
}

View File

@ -0,0 +1,86 @@
package net.sf.openrocket.gui.components;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.util.StateChangeListener;
import javax.swing.*;
import javax.swing.event.ListDataListener;
import java.util.EventObject;
public class ConfigurationModel implements MutableComboBoxModel<FlightConfiguration>, StateChangeListener {
private final Rocket rkt;
private final JComboBox<FlightConfiguration> combo;
public ConfigurationModel( final Rocket _rkt, final JComboBox<FlightConfiguration> _combo) {
this.rkt = _rkt;
this.combo = _combo;
}
@Override
public void stateChanged(EventObject eo) {
combo.revalidate();
combo.repaint();
}
@Override
public Object getSelectedItem() {
return rkt.getSelectedConfiguration();
}
@Override
public void setSelectedItem(Object nextItem) {
if( nextItem instanceof FlightConfiguration ){
FlightConfigurationId selectedId = ((FlightConfiguration)nextItem).getId();
rkt.setSelectedConfiguration(selectedId);
}
}
@Override
public void addListDataListener(ListDataListener l) {
// let the rocket send events, if necessary
// ignore any listen requests here...
}
public FlightConfiguration getElementAt( final int configIndex) {
return rkt.getFlightConfigurationByIndex(configIndex, true);
}
@Override
public int getSize() {
// plus the default config
return rkt.getConfigurationCount()+1;
}
@Override
public void removeListDataListener(ListDataListener l) {
// delegate event handling to the rocket
// ignore any listen requests here...
}
// ====== MutableComboBoxModel Functions ======
// these functions don't need to do anything, just being a 'mutable' version of the combo box
// is enough to allow updating the UI
@Override
public void addElement(FlightConfiguration arg0) {}
@Override
public void insertElementAt(FlightConfiguration arg0, int arg1) {}
@Override
public void removeElement(Object arg0) {}
@Override
public void removeElementAt(int arg0) {}
}

View File

@ -12,6 +12,7 @@ import javax.swing.JButton;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
@SuppressWarnings("serial")
public class FlatButton extends JButton {
public FlatButton() {

View File

@ -11,6 +11,7 @@ import javax.swing.JLabel;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
@SuppressWarnings("serial")
public class HtmlLabel extends JLabel {
public HtmlLabel() {

View File

@ -47,6 +47,7 @@ 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.components.BasicSlider;
import net.sf.openrocket.gui.components.ConfigurationModel;
import net.sf.openrocket.gui.components.StageSelector;
import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.UnitSelector;
@ -75,7 +76,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
private final FlightConditions conditions;
private final FlightConfiguration configuration;
private final Rocket rkt;
private final DoubleModel theta, aoa, mach, roll;
private final JToggleButton worstToggle;
private boolean fakeChange = false;
@ -105,11 +106,11 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
JPanel panel = new JPanel(new MigLayout("fill"));
add(panel);
this.configuration = rocketPanel.getConfiguration();
rkt = rocketPanel.getDocument().getRocket();
this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance();
conditions = new FlightConditions(configuration);
conditions = new FlightConditions(rkt.getSelectedConfiguration());
rocketPanel.setCPAOA(0);
aoa = new DoubleModel(rocketPanel, "CPAOA", UnitGroup.UNITS_ANGLE, 0, Math.PI);
@ -169,7 +170,6 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
// Stage and motor selection:
//// Active stages:
panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.activestages")), "spanx, split, gapafter rel");
Rocket rkt = rocketPanel.getDocument().getRocket();
panel.add(new StageSelector( rkt), "gapafter paragraph");
//// Motor configuration:
@ -177,9 +177,10 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
label.setHorizontalAlignment(JLabel.RIGHT);
panel.add(label, "growx, right");
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>( configuration.getRocket().toConfigArray());
panel.add(combo, "wrap");
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
configComboBox.setModel( configModel);
panel.add( configComboBox, "wrap");
// Tabbed pane
@ -517,6 +518,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
*/
@Override
public void stateChanged(EventObject e) {
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
AerodynamicForces forces;
WarningSet set = new WarningSet();
conditions.setAOA(aoa.getValue());
@ -580,12 +582,12 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
data[1] = MassCalcType.LAUNCH_MASS.getCG(motorConfig);
}
forces = aeroData.get(configuration.getRocket());
forces = aeroData.get(rkt);
if (forces != null) {
Object[] data = new Object[3];
cgData.add(data);
data[0] = configuration.getRocket();
data[1] = massData.get(configuration.getRocket());
data[0] = rkt;
data[1] = massData.get(rkt);
data[2] = forces;
dragData.add(forces);
rollData.add(forces);

View File

@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application;
@SuppressWarnings("serial")
public class EditDecalDialog extends JDialog {
private static final Translator trans = Application.getTranslator();

View File

@ -1165,11 +1165,7 @@ public class GeneralOptimizationDialog extends JDialog {
} else {
selectedModifierDescription.setText("");
}
// Update the active configuration
FlightConfigurationId fcid = getSelectedSimulation().getId();
getSelectedSimulation().getRocket().setDefaultConfiguration(fcid);
updating = false;
}

View File

@ -91,7 +91,7 @@ public class PhotoPanel extends JPanel implements GLEventListener {
((GLAutoDrawable) canvas).invoke(false, new GLRunnable() {
@Override
public boolean run(final GLAutoDrawable drawable) {
PhotoPanel.this.configuration = doc.getDefaultConfiguration();
PhotoPanel.this.configuration = doc.getSelectedConfiguration();
cachedBounds = null;
rr = new RealisticRenderer(doc);
rr.init(drawable);

View File

@ -29,9 +29,10 @@ import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Pair;
@SuppressWarnings("serial")
public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel {
private static final long serialVersionUID = 3359871704879603700L;
protected static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class);
protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
@ -136,6 +137,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
return selectedComponent.getV();
}
@ -150,6 +152,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
return fcid;
@ -160,7 +163,6 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 2026945220957913776L;
@Override
public Component getTableCellRendererComponent(JTable table, Object newValue, boolean isSelected, boolean hasFocus, int row, int column) {

View File

@ -26,9 +26,8 @@ import net.sf.openrocket.rocketvisitors.ListMotorMounts;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.StateChangeListener;
@SuppressWarnings("serial")
public class FlightConfigurationPanel extends JPanel implements StateChangeListener {
private static final long serialVersionUID = -5467500312467789009L;
//private static final Logger log = LoggerFactory.getLogger(FlightConfigurationPanel.class);
private static final Translator trans = Application.getTranslator();
private final OpenRocketDocument document;
@ -117,36 +116,36 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
updateButtonState();
this.add(tabs, "spanx, grow, wrap rel");
}
private void addConfiguration() {
FlightConfigurationId newFCID = new FlightConfigurationId();
FlightConfiguration newConfig = new FlightConfiguration( rocket, newFCID );
rocket.setFlightConfiguration(newFCID, newConfig);
FlightConfigurationId newId = new FlightConfigurationId();
FlightConfiguration newConfig = new FlightConfiguration( rocket, newId );
rocket.setFlightConfiguration( newId, newConfig);
// Create a new simulation for this configuration.
createSimulationForNewConfiguration();
createSimulationForNewConfiguration( newId );
configurationChanged();
}
private void copyConfiguration() {
FlightConfiguration oldConfig = rocket.getSelectedConfiguration();
FlightConfiguration newConfig = oldConfig.clone();
FlightConfigurationId oldId = oldConfig.getFlightConfigurationID();
FlightConfigurationId newId = newConfig.getFlightConfigurationID();
FlightConfigurationId oldId = this.motorConfigurationPanel.getSelectedConfigurationId();
FlightConfiguration oldConfig = rocket.getFlightConfiguration(oldId);
FlightConfigurationId newId = new FlightConfigurationId();
FlightConfiguration newConfig = oldConfig.copy( newId);
for (RocketComponent c : rocket) {
if (c instanceof FlightConfigurableComponent) {
((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId);
((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId);
}
}
rocket.setFlightConfiguration(newId, newConfig);
// Create a new simulation for this configuration.
createSimulationForNewConfiguration();
rocket.setFlightConfiguration( newId, newConfig);
// Create a new simulation for this configuration.
createSimulationForNewConfiguration( newId);
configurationChanged();
}
@ -160,6 +159,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
FlightConfigurationId currentId = this.motorConfigurationPanel.getSelectedConfigurationId();
if (currentId == null)
return;
System.err.println(this.rocket.toDebugConfigs());
document.removeFlightConfigurationAndSimulations(currentId);
configurationChanged();
}
@ -167,11 +167,13 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
/**
* prereq - assumes that the new configuration has been set as the default configuration.
*/
private void createSimulationForNewConfiguration() {
private void createSimulationForNewConfiguration( final FlightConfigurationId fcid ) {
Simulation newSim = new Simulation(rocket);
OpenRocketDocument doc = BasicFrame.findDocument(rocket);
newSim.setName(doc.getNextSimulationName());
doc.addSimulation(newSim);
if (doc != null) {
newSim.setName(doc.getNextSimulationName());
doc.addSimulation(newSim);
}
}
private void configurationChanged() {
@ -192,7 +194,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
int motorMountCount = rocket.accept(new ListMotorMounts()).size();
// Count the number of recovery devices
int recoveryDeviceCount = rocket.accept(new ListComponents<RecoveryDevice>(RecoveryDevice.class)).size();
int recoveryDeviceCount = rocket.accept(new ListComponents<>(RecoveryDevice.class)).size();
// Count the number of stages
int stageCount = rocket.getStageCount();

View File

@ -28,14 +28,15 @@ import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
@SuppressWarnings("serial")
public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount> {
private static final long serialVersionUID = -5046535300435793744L;
private static final String NONE = trans.get("edtmotorconfdlg.tbl.None");
@ -60,7 +61,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
subpanel.add(label, "wrap");
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) {
private static final long serialVersionUID = -238261338962282816L;
@Override
public void onDataChanged() {
@ -138,8 +138,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
protected JTable initializeTable() {
//// Motor selection table.
configurationTableModel = new FlightConfigurableTableModel<MotorMount>(MotorMount.class,rocket) {
private static final long serialVersionUID = -1210899988369000567L;
@Override
protected boolean includeComponent(MotorMount component) {
return component.isMotorMount();
@ -203,23 +201,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
if ( (null == fcid )||( null == curMount )){
return;
}
//MotorInstance curInstance = curMount.getMotorInstance( fcid );
// curInstance may be empty here...
//String mountName = ((RocketComponent)curMount).getName();
//System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey());
if( fcid.equals( FlightConfigurationId.DEFAULT_VALUE_FCID)){
throw new IllegalStateException("Attempting to set a motor on the default FCID.");
}
motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
motorChooserDialog.setVisible(true);
Motor mtr = motorChooserDialog.getSelectedMotor();
Motor mtr = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay();
if (mtr != null) {
MotorConfiguration curConfig = curMount.getMotorConfig(fcid);
curConfig.setMotor(mtr);
curConfig.setEjectionDelay(d);
curConfig.setIgnitionEvent( IgnitionEvent.NEVER);
curMount.setMotorConfig( curConfig, fcid);
final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid);
final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig);
newConfig.setMotor(mtr);
newConfig.setEjectionDelay(d);
curMount.setMotorConfig( newConfig, fcid);
}
fireTableDataChanged();
@ -270,7 +267,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
private static final long serialVersionUID = -7462331042920067984L;
@Override
protected JLabel format( MotorMount mount, FlightConfigurationId configId, JLabel l ) {

View File

@ -49,9 +49,9 @@ import net.sf.openrocket.util.Transformation;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
@SuppressWarnings("serial")
public class RocketFigure extends AbstractScaleFigure {
private static final long serialVersionUID = 45884403769043138L;
private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class);
private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure";

View File

@ -5,8 +5,6 @@ import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
@ -42,6 +40,7 @@ import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.StageSelector;
import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.components.ConfigurationModel;
import net.sf.openrocket.gui.configdialog.ComponentConfigDialog;
import net.sf.openrocket.gui.figure3d.RocketFigure3d;
import net.sf.openrocket.gui.figureelements.CGCaret;
@ -75,18 +74,19 @@ import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.StateChangeListener;
/**
* A JPanel that contains a RocketFigure and buttons to manipulate the figure.
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
* @author Bill Kuker <bkuker@billkuker.com>
*/
@SuppressWarnings("serial")
public class RocketPanel extends JPanel implements TreeSelectionListener, ChangeSource {
private static final long serialVersionUID = 1L;
private static final Translator trans = Application.getTranslator();
public static enum VIEW_TYPE {
public enum VIEW_TYPE {
SideView(false, RocketFigure.VIEW_SIDE),
BackView(false, RocketFigure.VIEW_BACK),
Figure3D(true, RocketFigure3d.TYPE_FIGURE),
@ -96,7 +96,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
public final boolean is3d;
private final int type;
private VIEW_TYPE(final boolean is3d, final int type) {
VIEW_TYPE(final boolean is3d, final int type) {
this.is3d = is3d;
this.type = type;
};
@ -140,7 +140,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
// The functional ID of the rocket that was simulated
private int flightDataFunctionalID = -1;
private FlightConfigurationId flightDataMotorID = null;
private FlightConfigurationId flightDataMotorID = null;
private SimulationWorker backgroundSimulationWorker = null;
@ -271,12 +271,21 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
* Creates the layout and components of the panel.
*/
private void createPanel() {
final Rocket rkt = document.getRocket();
rkt.addChangeListener(new StateChangeListener(){
@Override
public void stateChanged(EventObject eo) {
updateExtras();
updateFigures();
}
});
setLayout(new MigLayout("", "[shrink][grow]", "[shrink][shrink][grow][shrink]"));
setPreferredSize(new Dimension(800, 300));
// View Type Dropdown
@SuppressWarnings("serial") // because java throws a warning without this.
// View Type drop-down
ComboBoxModel<VIEW_TYPE> cm = new DefaultComboBoxModel<VIEW_TYPE>(VIEW_TYPE.values()) {
@Override
@ -301,7 +310,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
add(scaleSelector);
// Stage selector
final Rocket rkt = document.getRocket();
StageSelector stageSelector = new StageSelector( rkt );
rkt.addChangeListener(stageSelector);
add(stageSelector);
@ -311,21 +319,13 @@ 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");
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
rkt.addChangeListener( configModel );
configComboBox.setModel(configModel);
add(configComboBox, "wrap, width 16%, wmin 100");
configComboBox.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem();
document.getRocket().setSelectedConfiguration( newConfig);
updateExtras();
updateFigures();
}
});
// Create slider and scroll pane
DoubleModel theta = new DoubleModel(figure, "Rotation",
@ -361,8 +361,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
return aerodynamicCalculator;
}
public FlightConfiguration getConfiguration() {
return document.getDefaultConfiguration();
public FlightConfiguration getSelectedConfiguration() {
return document.getSelectedConfiguration();
}
/**
@ -565,7 +565,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
Coordinate cp, cg;
double cpx, cgx;
FlightConfiguration curConfig = document.getDefaultConfiguration();
FlightConfiguration curConfig = document.getSelectedConfiguration();
// TODO: MEDIUM: User-definable conditions
FlightConditions conditions = new FlightConditions(curConfig);
warnings.clear();
@ -644,7 +644,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
extraText.setLength(length);
extraText.setDiameter(diameter);
extraText.setMass(cg.weight);
extraText.setMassWithoutMotors( massCalculator.getCG( getConfiguration(), MassCalcType.NO_MOTORS ).weight );
extraText.setMassWithoutMotors( massCalculator.getCG( getSelectedConfiguration(), MassCalcType.NO_MOTORS ).weight );
extraText.setWarnings(warnings);
if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {
@ -672,12 +672,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
// Check whether data is already up to date
if (flightDataFunctionalID == curConfig.getRocket().getFunctionalModID() &&
flightDataMotorID == curConfig.getFlightConfigurationID()) {
flightDataMotorID == curConfig.getId()) {
return;
}
flightDataFunctionalID = curConfig.getRocket().getFunctionalModID();
flightDataMotorID = curConfig.getFlightConfigurationID();
flightDataMotorID = curConfig.getId();
// Stop previous computation (if any)
stopBackgroundSimulation();
@ -695,7 +695,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
Rocket duplicate = (Rocket) document.getRocket().copy();
Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate);
simulation.setFlightConfigurationId( document.getDefaultConfiguration().getFlightConfigurationID());
simulation.setFlightConfigurationId( document.getSelectedConfiguration().getId());
backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation);
backgroundSimulationExecutor.execute(backgroundSimulationWorker);
@ -781,7 +781,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
* Adds the extra data to the figure. Currently this includes the CP and CG carets.
*/
private void addExtras() {
FlightConfiguration curConfig = document.getDefaultConfiguration();
FlightConfiguration curConfig = document.getSelectedConfiguration();
extraCG = new CGCaret(0, 0);
extraCP = new CPCaret(0, 0);
extraText = new RocketInfo(curConfig);

View File

@ -21,10 +21,12 @@ 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.components.ConfigurationModel;
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.rocketcomponent.Rocket;
import net.sf.openrocket.simulation.extension.SimulationExtension;
import net.sf.openrocket.startup.Application;
@ -145,8 +147,10 @@ public class SimulationEditDialog extends JDialog {
label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg"));
panel.add(label, "growx 0, gapright para");
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
configComboBox.setSelectedItem( document.getRocket().getSelectedConfiguration().getId() );
final Rocket rkt = document.getRocket();
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
configComboBox.setModel( configModel);
//// Select the motor configuration to use.
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));