[Bugfix] Merge with commit 4c00a206531968aab2e048ea4f9ef7e27e12dd52

This commit is contained in:
Daniel_M_Williams 2015-12-22 21:17:35 -05:00
commit 612f64fa4c
5 changed files with 73 additions and 92 deletions

View File

@ -40,7 +40,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
protected static int instanceCount=0; protected static int instanceCount=0;
public final int instanceNumber; public final int instanceNumber;
protected class StageFlags implements Cloneable { protected class StageFlags implements Cloneable {
public boolean active = true; public boolean active = true;
public int prev = -1; public int prev = -1;
@ -91,8 +91,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.rocket = rocket; this.rocket = rocket;
this.isNamed = false; this.isNamed = false;
this.configurationName = "<WARN: attempt to access unset configurationName. WARN!> "; this.configurationName = "<WARN: attempt to access unset configurationName. WARN!> ";
instanceNumber = FlightConfiguration.instanceCount; this.instanceNumber = instanceCount++;
++FlightConfiguration.instanceCount;
updateStages(); updateStages();
updateMotors(); updateMotors();
@ -361,36 +360,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
updateMotors(); updateMotors();
} }
/**
* Add a motor instance to this configuration. The motor is placed at
* the specified position and with an infinite ignition time (never ignited).
*
* @param id the ID of this motor instance.
* @param motor the motor instance.
* @param mount the motor mount containing this motor
* @param ignitionEvent the ignition event for the motor
* @param ignitionDelay the ignition delay for the motor
* @param position the position of the motor in absolute coordinates.
* @throws IllegalArgumentException if a motor with the specified ID already exists.
*/
// public void addMotor(MotorId _id, Motor _motor, double _ejectionDelay, MotorMount _mount,
// IgnitionEvent _ignitionEvent, double _ignitionDelay, Coordinate _position) {
//
// MotorInstance instanceToAdd = new MotorInstance(_id, _motor, _mount, _ejectionDelay,
// _ignitionEvent, _ignitionDelay, _position);
//
//
// // this.ids.add(id);
// // this.motors.add(motor);
// // this.ejectionDelays.add(ejectionDelay);
// // this.mounts.add(mount);
// // this.ignitionEvents.add(ignitionEvent);
// // this.ignitionDelays.add(ignitionDelay);
// // this.positions.add(position);
// // this.ignitionTimes.add(Double.POSITIVE_INFINITY);
// }
/** /**
* Add a motor instance to this configuration. * Add a motor instance to this configuration.
* *
@ -508,14 +477,13 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
*/ */
@Override @Override
public FlightConfiguration clone() { public FlightConfiguration clone() {
// Note the motors and stages are updated in the constructor call.
FlightConfiguration clone = new FlightConfiguration( this.getRocket(), this.fcid ); FlightConfiguration clone = new FlightConfiguration( this.getRocket(), this.fcid );
clone.setName("clone - "+this.fcid.toShortKey()); clone.setName("clone - "+this.fcid.toShortKey());
for( StageFlags flags : this.stages.values()){
clone.stages.put( flags.stage.getStageNumber(), flags.clone()); // DO NOT UPDATE:
} // this.stages and this.motors are updated correctly on their own.
for( MotorConfiguration mi : this.motors.values()){
clone.motors.put( mi.getID(), mi.clone());
}
clone.cachedBounds = this.cachedBounds.clone(); clone.cachedBounds = this.cachedBounds.clone();
clone.modID = this.modID; clone.modID = this.modID;
clone.boundsModID = -1; clone.boundsModID = -1;

View File

@ -1,34 +0,0 @@
package net.sf.openrocket.rocketcomponent;
/**
* An implementation of FlightConfiguration that fires off events
* to the rocket components when the parameter value is changed.
*
* @param <E> the parameter type
*/
public class FlightConfigurationSet extends FlightConfigurableParameterSet<FlightConfiguration> {
/**
* Construct a FlightConfiguration that has no overrides.
*
* @param component the rocket component on which events are fired when the parameter values are changed
* @param eventType the event type that will be fired on changes
*/
public FlightConfigurationSet( RocketComponent component, int eventType, FlightConfiguration _defaultValue) {
super( component, eventType, _defaultValue);
}
/**
* Construct a copy of an existing FlightConfigurationSet
*
* @param component the rocket component on which events are fired when the parameter values are changed
* @param eventType the event type that will be fired on changes
*/
public FlightConfigurationSet(FlightConfigurationSet configSet, RocketComponent component, int eventType) {
super( configSet, component, eventType );
}
}

View File

@ -67,7 +67,7 @@ public class Rocket extends RocketComponent {
// Flight configuration list // Flight configuration list
private FlightConfigurationSet configSet; private FlightConfigurableParameterSet<FlightConfiguration> configSet;
// Does the rocket have a perfect finish (a notable amount of laminar flow) // Does the rocket have a perfect finish (a notable amount of laminar flow)
private boolean perfectFinish = false; private boolean perfectFinish = false;
@ -85,7 +85,7 @@ public class Rocket extends RocketComponent {
functionalModID = modID; functionalModID = modID;
FlightConfiguration defaultConfiguration = new FlightConfiguration( this, null); FlightConfiguration defaultConfiguration = new FlightConfiguration( this, null);
this.configSet = new FlightConfigurationSet(this, ComponentChangeEvent.CONFIG_CHANGE, defaultConfiguration); this.configSet = new FlightConfigurableParameterSet<FlightConfiguration>(this, ComponentChangeEvent.CONFIG_CHANGE, defaultConfiguration);
} }
public String getDesigner() { public String getDesigner() {
@ -301,7 +301,7 @@ public class Rocket extends RocketComponent {
@Override @Override
public Rocket copyWithOriginalID() { public Rocket copyWithOriginalID() {
Rocket copy = (Rocket) super.copyWithOriginalID(); Rocket copy = (Rocket) super.copyWithOriginalID();
copy.configSet = new FlightConfigurationSet( copy.configSet = new FlightConfigurableParameterSet<FlightConfiguration>(
this.configSet, copy, ComponentChangeEvent.CONFIG_CHANGE); this.configSet, copy, ComponentChangeEvent.CONFIG_CHANGE);
copy.resetListeners(); copy.resetListeners();
@ -339,7 +339,7 @@ public class Rocket extends RocketComponent {
this.refType = r.refType; this.refType = r.refType;
this.customReferenceLength = r.customReferenceLength; this.customReferenceLength = r.customReferenceLength;
this.configSet = new FlightConfigurationSet( r.configSet, this, ComponentChangeEvent.CONFIG_CHANGE); this.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( r.configSet, this, ComponentChangeEvent.CONFIG_CHANGE);
this.perfectFinish = r.perfectFinish; this.perfectFinish = r.perfectFinish;
this.checkComponentStructure(); this.checkComponentStructure();

View File

@ -1247,21 +1247,21 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* *
* @return Sum of the lengths. * @return Sum of the lengths.
*/ */
private final double getTotalLength() { // private final double getTotalLength() {
checkState(); // checkState();
this.checkComponentStructure(); // this.checkComponentStructure();
mutex.lock("getTotalLength"); // mutex.lock("getTotalLength");
try { // try {
double l = 0; // double l = 0;
if (relativePosition == Position.AFTER) // if (relativePosition == Position.AFTER)
l = length; // l = length;
for (int i = 0; i < children.size(); i++) // for (int i = 0; i < children.size(); i++)
l += children.get(i).getTotalLength(); // l += children.get(i).getTotalLength();
return l; // return l;
} finally { // } finally {
mutex.unlock("getTotalLength"); // mutex.unlock("getTotalLength");
} // }
} // }
/////////// Total mass and CG calculation //////////// /////////// Total mass and CG calculation ////////////

View File

@ -0,0 +1,47 @@
package net.sf.openrocket.rocketcomponent;
//import static org.hamcrest.CoreMatchers.equalTo;
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertThat;
//import static org.junit.Assert.assertTrue;
import org.junit.Test;
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.StateChangeListener;
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
public class ParameterSetTest extends BaseTestCase {
private final static double EPSILON = MathUtil.EPSILON*1E3;
private class Parameter implements FlightConfigurableParameter<Parameter> {
public Parameter(){}
@Override
public Parameter clone(){ return null; }
@Override
public void update(){}
@Override
public void addChangeListener(StateChangeListener listener){}
@Override
public void removeChangeListener(StateChangeListener listener){}
};
@Test
public void testEmptyRocket() {
//FlightConfigurableParameterSet<Parameter> testSet = new FlightConfigurableParameterSet<Parameter>();
}
}