[Major] Re-Implemented Rocket configuration list
# FlightConfigurations behave differently than the ...ParameterSet instance - Rockets no longer have a defaultConfig, but have a selectedConfiguration - therefore these function were completely re-implemented native to the Rocket class - FlightConfigurationTest verifies this functionality - simplified several function calls through the code base - added convenience methods for getting the config[] to the UI # expanded RocketTest to verify Rocket.copyWithOriginalID(): - rocket is cloned, so non-trivial members must be cloned as well.
This commit is contained in:
parent
f59ebdd06e
commit
efd1656fc8
@ -164,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
|
||||
|
||||
public FlightConfiguration getDefaultConfiguration() {
|
||||
return rocket.getDefaultConfiguration();
|
||||
return rocket.getSelectedConfiguration();
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
@ -116,7 +116,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
DefaultSimulationOptionFactory f = Application.getInjector().getInstance(DefaultSimulationOptionFactory.class);
|
||||
options.copyConditionsFrom(f.getDefault());
|
||||
|
||||
FlightConfigurationId fcid = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
options.setFlightConfigurationId(fcid);
|
||||
options.addChangeListener(new ConditionListener());
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
import net.sf.openrocket.optimization.rocketoptimization.OptimizableParameter;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.util.Named;
|
||||
|
||||
class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
@SuppressWarnings("unused")
|
||||
@ -63,10 +65,9 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
}
|
||||
|
||||
if ("true".equals(attributes.remove("default"))) {
|
||||
// associate this configuration with both this FCID and the default.
|
||||
FlightConfigurableParameterSet<FlightConfiguration> fcs = rocket.getConfigSet();
|
||||
FlightConfiguration fc = fcs.get(fcid);
|
||||
fcs.setDefault(fc);
|
||||
// also associate this configuration with the default.
|
||||
FlightConfiguration fc = rocket.getFlightConfiguration(fcid);
|
||||
rocket.setSelectedConfiguration( fc);
|
||||
}
|
||||
|
||||
super.closeElement(element, attributes, content, warnings);
|
||||
|
@ -6,9 +6,7 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.AxialStage;
|
||||
import net.sf.openrocket.rocketcomponent.ParallelStage;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
|
||||
|
||||
@ -45,31 +43,27 @@ public class AxialStageSaver extends ComponentAssemblySaver {
|
||||
|
||||
if (stage.getStageNumber() > 0) {
|
||||
// NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on
|
||||
elements.addAll(separationConfig(stage.getSeparationConfigurations().getDefault(), false));
|
||||
elements.addAll(addSeparationConfigParams(stage.getSeparationConfigurations().getDefault(), false));
|
||||
|
||||
Rocket rocket = stage.getRocket();
|
||||
// Note - getFlightConfigurationIDs returns at least one element. The first element
|
||||
// is null and means "default".
|
||||
|
||||
for (FlightConfiguration curConfig : rocket.getConfigSet()){
|
||||
FlightConfigurationId fcid = curConfig.getFlightConfigurationID();
|
||||
for (FlightConfigurationId fcid: stage.getSeparationConfigurations().getIds() ){
|
||||
if (fcid == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StageSeparationConfiguration curSepCfg = stage.getSeparationConfigurations().get(fcid);
|
||||
if( stage.getSeparationConfigurations().isDefault( curSepCfg )){
|
||||
continue;
|
||||
}
|
||||
|
||||
// if( stage.getSeparationConfigurations().isDefault( curSepCfg )){
|
||||
// continue;
|
||||
// }
|
||||
|
||||
elements.add("<separationconfiguration configid=\"" + fcid.key + "\">");
|
||||
elements.addAll(separationConfig(curSepCfg, true));
|
||||
elements.addAll(addSeparationConfigParams(curSepCfg, true));
|
||||
elements.add("</separationconfiguration>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> separationConfig(StageSeparationConfiguration config, boolean indent) {
|
||||
private List<String> addSeparationConfigParams(StageSeparationConfiguration config, boolean indent) {
|
||||
List<String> elements = new ArrayList<String>(2);
|
||||
elements.add((indent ? " " : "") + "<separationevent>"
|
||||
+ config.getSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
|
||||
|
@ -5,11 +5,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
|
||||
public class RecoveryDeviceSaver extends MassObjectSaver {
|
||||
@ -27,35 +25,24 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
|
||||
elements.add(materialParam(dev.getMaterial()));
|
||||
|
||||
// NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on
|
||||
DeploymentConfiguration defaultConfig = dev.getDeploymentConfigurations().getDefault();
|
||||
elements.addAll(deploymentConfiguration(defaultConfig, false));
|
||||
FlightConfigurableParameterSet<DeploymentConfiguration> configSet = dev.getDeploymentConfigurations();
|
||||
DeploymentConfiguration defaultConfig = configSet.getDefault();
|
||||
elements.addAll(addDeploymentConfigurationParams(defaultConfig, false));
|
||||
|
||||
Rocket rocket = c.getRocket();
|
||||
|
||||
// DEBUG
|
||||
//System.err.println("printing deployment info for: "+dev.getName());
|
||||
//dev.getDeploymentConfigurations().printDebug();
|
||||
// DEBUG
|
||||
|
||||
FlightConfigurableParameterSet<FlightConfiguration> configList = rocket.getConfigSet();
|
||||
for (FlightConfigurationId fcid : configList.getSortedConfigurationIDs()) {
|
||||
//System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?");
|
||||
|
||||
for (FlightConfigurationId fcid : configSet.getIds()) {
|
||||
if (dev.getDeploymentConfigurations().isDefault(fcid)) {
|
||||
//System.err.println(" >> skipping: fcid="+fcid.getShortKey());
|
||||
continue;
|
||||
}else if( dev.getDeploymentConfigurations().containsKey(fcid)){
|
||||
}else{
|
||||
// only print configurations which override the default.
|
||||
//System.err.println(" >> printing data.");
|
||||
DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid);
|
||||
elements.add("<deploymentconfiguration configid=\"" + fcid.key + "\">");
|
||||
elements.addAll(deploymentConfiguration(deployConfig, true));
|
||||
elements.addAll(addDeploymentConfigurationParams(deployConfig, true));
|
||||
elements.add("</deploymentconfiguration>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> deploymentConfiguration(DeploymentConfiguration config, boolean indent) {
|
||||
private List<String> addDeploymentConfigurationParams(DeploymentConfiguration config, boolean indent) {
|
||||
List<String> elements = new ArrayList<String>(3);
|
||||
elements.add((indent ? " " : "") + "<deployevent>" + config.getDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</deployevent>");
|
||||
elements.add((indent ? " " : "") + "<deployaltitude>" + config.getDeployAltitude() + "</deployaltitude>");
|
||||
|
@ -190,7 +190,7 @@ public class RocketComponentSaver {
|
||||
elements.add(" <ignitiondelay>" + defaultInstance.getIgnitionDelay() + "</ignitiondelay>");
|
||||
elements.add(" <overhang>" + mount.getMotorOverhang() + "</overhang>");
|
||||
|
||||
for( FlightConfigurationId fcid : rkt.getSortedConfigurationIDs()){
|
||||
for( FlightConfigurationId fcid : rkt.getIds()){
|
||||
|
||||
MotorConfiguration motorInstance = mount.getMotorInstance(fcid);
|
||||
// Nothing is stored if no motor loaded
|
||||
|
@ -6,7 +6,6 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet;
|
||||
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
@ -43,15 +42,15 @@ public class RocketSaver extends RocketComponentSaver {
|
||||
|
||||
|
||||
// Motor configurations
|
||||
FlightConfigurableParameterSet<FlightConfiguration> allConfigs = rocket.getConfigSet();
|
||||
for (FlightConfigurationId fcid : allConfigs.getSortedConfigurationIDs()) {
|
||||
FlightConfiguration flightConfig = allConfigs.get(fcid);
|
||||
for (FlightConfigurationId fcid : rocket.getIds()) {
|
||||
FlightConfiguration flightConfig = rocket.getFlightConfiguration(fcid);
|
||||
if (fcid == null)
|
||||
continue;
|
||||
|
||||
// these are actually FlightConfigurationIds, buuuuuuuuuut backwards-compatible tags.
|
||||
String str = "<motorconfiguration configid=\"" + fcid.key + "\"";
|
||||
// if the configuration is the default, add the tag
|
||||
if ( allConfigs.isDefault( flightConfig )){
|
||||
if ( rocket.getSelectedConfiguration().equals( flightConfig )){
|
||||
str += " default=\"true\"";
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class RocksimSaver extends RocketSaver {
|
||||
|
||||
MassCalculator massCalc = new MassCalculator();
|
||||
|
||||
final FlightConfiguration configuration = rocket.getDefaultConfiguration();
|
||||
final FlightConfiguration configuration = rocket.getSelectedConfiguration();
|
||||
final double cg = massCalc.getCG(configuration, MassCalculator.MassCalcType.NO_MOTORS).x *
|
||||
RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class StabilityDomain implements SimulationDomain {
|
||||
MassCalculator massCalculator = new MassCalculator();
|
||||
|
||||
|
||||
FlightConfiguration configuration = simulation.getRocket().getDefaultConfiguration();
|
||||
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration();
|
||||
FlightConditions conditions = new FlightConditions(configuration);
|
||||
conditions.setMach(Application.getPreferences().getDefaultMach());
|
||||
conditions.setAOA(0);
|
||||
|
@ -71,7 +71,7 @@ public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E
|
||||
}
|
||||
|
||||
FlightConfigurableParameterSet<E> configs = (FlightConfigurableParameterSet<E>) configGetter.invoke(c);
|
||||
return configs.get(simulation.getRocket().getDefaultConfiguration().getFlightConfigurationID());
|
||||
return configs.get(simulation.getRocket().getSelectedConfiguration().getFlightConfigurationID());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class StabilityParameter implements OptimizableParameter {
|
||||
MassCalculator massCalculator = new MassCalculator();
|
||||
|
||||
|
||||
FlightConfiguration configuration = simulation.getRocket().getDefaultConfiguration();
|
||||
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration();
|
||||
FlightConditions conditions = new FlightConditions(configuration);
|
||||
conditions.setMach(Application.getPreferences().getDefaultMach());
|
||||
conditions.setAOA(0);
|
||||
|
@ -47,12 +47,6 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
// do we want to keep this? it shouldn't actually be called...
|
||||
public boolean containsKey( final FlightConfigurationId fcid ){
|
||||
return this.map.containsKey(fcid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default parameter value for this FlightConfiguration.
|
||||
* This is used in case a per-flight configuration override
|
||||
|
@ -479,11 +479,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
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 - "+this.fcid.toShortKey());
|
||||
|
||||
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 and this.motors are updated correctly on their own.
|
||||
|
||||
clone.cachedBounds = this.cachedBounds.clone();
|
||||
clone.modID = this.modID;
|
||||
clone.boundsModID = -1;
|
||||
|
@ -412,7 +412,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
||||
|
||||
Coordinate[] relCoords = this.getInstanceOffsets();
|
||||
Coordinate[] absCoords = this.getLocations();
|
||||
FlightConfigurationId curId = this.getRocket().getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId curId = this.getRocket().getSelectedConfiguration().getFlightConfigurationID();
|
||||
final int intanceCount = this.getInstanceCount();
|
||||
MotorConfiguration curInstance = this.motors.get(curId);
|
||||
if( curInstance.isEmpty() ){
|
||||
|
@ -67,12 +67,13 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
|
||||
// Flight configuration list
|
||||
private FlightConfigurableParameterSet<FlightConfiguration> configSet;
|
||||
private FlightConfiguration selectedConfiguration;
|
||||
private HashMap<FlightConfigurationId, FlightConfiguration> configSet = new HashMap<FlightConfigurationId, FlightConfiguration>();
|
||||
private HashMap<Integer, AxialStage> stageMap = new HashMap<Integer, AxialStage>();
|
||||
|
||||
// Does the rocket have a perfect finish (a notable amount of laminar flow)
|
||||
private boolean perfectFinish = false;
|
||||
|
||||
private final HashMap<Integer, AxialStage> stageMap = new HashMap<Integer, AxialStage>();
|
||||
|
||||
///////////// Constructor /////////////
|
||||
|
||||
@ -84,8 +85,10 @@ public class Rocket extends RocketComponent {
|
||||
treeModID = modID;
|
||||
functionalModID = modID;
|
||||
|
||||
FlightConfiguration defaultConfiguration = new FlightConfiguration( this, null);
|
||||
this.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( defaultConfiguration);
|
||||
|
||||
|
||||
// must be after the hashmaps :P
|
||||
this.selectedConfiguration = new FlightConfiguration( this, null);
|
||||
}
|
||||
|
||||
public String getDesigner() {
|
||||
@ -301,12 +304,32 @@ public class Rocket extends RocketComponent {
|
||||
@Override
|
||||
public Rocket copyWithOriginalID() {
|
||||
Rocket copy = (Rocket) super.copyWithOriginalID();
|
||||
copy.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( this.configSet);
|
||||
copy.resetListeners();
|
||||
|
||||
// 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>();
|
||||
if( 0 < this.configSet.size() ){
|
||||
Rocket.cloneConfigs( this, copy);
|
||||
}
|
||||
copy.listenerList = new ArrayList<EventListener>();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static void cloneConfigs( final Rocket source, Rocket dest ){
|
||||
source.checkState();
|
||||
dest.checkState();
|
||||
dest.selectedConfiguration = source.selectedConfiguration.clone();
|
||||
for( final FlightConfiguration config : source.configSet.values() ){
|
||||
dest.configSet.put( config.getId(), config.clone() );
|
||||
}
|
||||
}
|
||||
|
||||
public int getFlightConfigurationCount() {
|
||||
checkState();
|
||||
return this.configSet.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the rocket structure from the source. The method loads the fields of this
|
||||
* Rocket object and copies the references to siblings from the <code>source</code>.
|
||||
@ -337,8 +360,8 @@ public class Rocket extends RocketComponent {
|
||||
this.functionalModID = r.functionalModID;
|
||||
this.refType = r.refType;
|
||||
this.customReferenceLength = r.customReferenceLength;
|
||||
Rocket.cloneConfigs( r, this);
|
||||
|
||||
this.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( r.configSet );
|
||||
this.perfectFinish = r.perfectFinish;
|
||||
|
||||
this.checkComponentStructure();
|
||||
@ -458,7 +481,9 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
this.configSet.update();
|
||||
for( FlightConfiguration config : configSet.values() ){
|
||||
config.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -529,15 +554,15 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
|
||||
/**
|
||||
* Return the default configuration. This should be used in the user interface
|
||||
* Return the currently selected configuration. This should be used in the user interface
|
||||
* to ensure a consistent rocket configuration between dialogs. It should NOT
|
||||
* be used in simulations not relating to the UI.
|
||||
*
|
||||
* @return the default {@link FlightConfiguration}.
|
||||
* @return the current {@link FlightConfiguration}.
|
||||
*/
|
||||
public FlightConfiguration getDefaultConfiguration() {
|
||||
public FlightConfiguration getSelectedConfiguration() {
|
||||
checkState();
|
||||
return this.configSet.getDefault();
|
||||
return this.selectedConfiguration;
|
||||
}
|
||||
|
||||
public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) {
|
||||
@ -548,8 +573,8 @@ public class Rocket extends RocketComponent {
|
||||
return this.configSet.get(fcid);
|
||||
}else{
|
||||
FlightConfiguration nextConfig = new FlightConfiguration(this, fcid);
|
||||
this.configSet.set(fcid, nextConfig);
|
||||
this.configSet.setDefault( nextConfig);
|
||||
this.configSet.put(fcid, nextConfig);
|
||||
this.selectedConfiguration = nextConfig;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE);
|
||||
return nextConfig;
|
||||
}
|
||||
@ -559,16 +584,28 @@ public class Rocket extends RocketComponent {
|
||||
return this.configSet.size();
|
||||
}
|
||||
|
||||
public FlightConfigurableParameterSet<FlightConfiguration> getConfigSet(){
|
||||
checkState();
|
||||
return this.configSet;
|
||||
}
|
||||
|
||||
public List<FlightConfigurationId> getSortedConfigurationIDs(){
|
||||
return configSet.getSortedConfigurationIDs();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -582,7 +619,7 @@ public class Rocket extends RocketComponent {
|
||||
}
|
||||
|
||||
// Get current configuration:
|
||||
this.configSet.set(fcid, null);
|
||||
this.configSet.remove( fcid);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
@ -649,12 +686,17 @@ public class Rocket extends RocketComponent {
|
||||
* @return a FlightConfiguration instance
|
||||
*/
|
||||
public FlightConfiguration getFlightConfiguration(final int configIndex) {
|
||||
return this.configSet.get(configIndex);
|
||||
return this.configSet.get( this.getId(configIndex));
|
||||
}
|
||||
|
||||
public void setDefaultConfiguration(final FlightConfiguration config) {
|
||||
public FlightConfigurationId getId( final int configIndex) {
|
||||
List<FlightConfigurationId> idList = this.getIds();
|
||||
return idList.get(configIndex);
|
||||
}
|
||||
|
||||
public void setSelectedConfiguration(final FlightConfiguration config) {
|
||||
checkState();
|
||||
configSet.setDefault( config);
|
||||
this.selectedConfiguration = config;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
@ -665,7 +707,7 @@ public class Rocket extends RocketComponent {
|
||||
log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid));
|
||||
return;
|
||||
}else if( this.configSet.containsKey(fcid)){
|
||||
configSet.setDefault( configSet.get(fcid));
|
||||
this.selectedConfiguration = configSet.get(fcid);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
}
|
||||
@ -687,7 +729,7 @@ public class Rocket extends RocketComponent {
|
||||
if (null == newConfig){
|
||||
newConfig = createFlightConfiguration(fcid);
|
||||
}
|
||||
configSet.set(fcid, newConfig);
|
||||
configSet.put(fcid, newConfig);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
@ -768,4 +810,18 @@ 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()));
|
||||
final String fmt = " [%-12s]: %s\n";
|
||||
for( FlightConfiguration config : this.configSet.values() ){
|
||||
String shortKey = config.getId().toShortKey();
|
||||
if( this.selectedConfiguration.equals( config)){
|
||||
shortKey = "*"+shortKey+"*";
|
||||
}
|
||||
buf.append(String.format(fmt, shortKey, config.getName() ));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public abstract class RocketUtils {
|
||||
|
||||
public static double getLength(Rocket rocket) {
|
||||
double length = 0;
|
||||
Collection<Coordinate> bounds = rocket.getDefaultConfiguration().getBounds();
|
||||
Collection<Coordinate> bounds = rocket.getSelectedConfiguration().getBounds();
|
||||
if (!bounds.isEmpty()) {
|
||||
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
|
||||
for (Coordinate c : bounds) {
|
||||
@ -27,7 +27,7 @@ public abstract class RocketUtils {
|
||||
// get rid of this method.... we can sure come up with a better way to do this....
|
||||
public static Coordinate getCG(Rocket rocket, MassCalcType calcType) {
|
||||
MassCalculator massCalculator = new MassCalculator();
|
||||
Coordinate cg = massCalculator.getCG(rocket.getDefaultConfiguration(), calcType);
|
||||
Coordinate cg = massCalculator.getCG(rocket.getSelectedConfiguration(), calcType);
|
||||
return cg;
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.configId);
|
||||
FlightConfigurationId matchID = null;
|
||||
|
||||
for (FlightConfigurationId fcid : this.rocket.getSortedConfigurationIDs()){
|
||||
for (FlightConfigurationId fcid : rocket.getIds()){
|
||||
String motorDesc2 = formatter.getMotorConfigurationDescription(this.rocket, fcid);
|
||||
if (motorDesc.equals(motorDesc2)) {
|
||||
matchID = fcid;
|
||||
|
@ -464,7 +464,7 @@ public class TestRockets {
|
||||
bodytube.setMaterial(material);
|
||||
finset.setMaterial(material);
|
||||
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid = config.getFlightConfigurationID();
|
||||
|
||||
ThrustCurveMotor motor = getTestMotor();
|
||||
@ -715,7 +715,7 @@ public class TestRockets {
|
||||
rocket.addChild(stage);
|
||||
rocket.setPerfectFinish(false);
|
||||
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
// FlightConfigurationID fcid = config.getFlightConfigurationID();
|
||||
|
||||
// Motor m = Application.getMotorSetDatabase().findMotors(null, null, "L540", Double.NaN, Double.NaN).get(0);
|
||||
@ -733,7 +733,7 @@ public class TestRockets {
|
||||
public static Rocket makeFalcon9Heavy() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("Falcon9H Scale Rocket");
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
|
||||
// ====== Payload Stage ======
|
||||
// ====== ====== ====== ======
|
||||
@ -966,7 +966,7 @@ public class TestRockets {
|
||||
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v104_withMotorConfig");
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid = config.getFlightConfigurationID();
|
||||
config.setName("F12X");
|
||||
|
||||
@ -1002,7 +1002,7 @@ public class TestRockets {
|
||||
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v104_withSimulationData");
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid = config.getFlightConfigurationID();
|
||||
config.setName("F12X");
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class BarrowmanCalculatorTest {
|
||||
@Test
|
||||
public void testCPSimpleDry() {
|
||||
Rocket rocket = TestRockets.makeEstesAlphaIII();
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
AerodynamicCalculator calc = new BarrowmanCalculator();
|
||||
FlightConditions conditions = new FlightConditions(config);
|
||||
WarningSet warnings = new WarningSet();
|
||||
@ -63,7 +63,7 @@ public class BarrowmanCalculatorTest {
|
||||
@Test
|
||||
public void testCPSimpleWithMotor() {
|
||||
Rocket rkt = TestRockets.makeEstesAlphaIII();
|
||||
FlightConfiguration config = rkt.getDefaultConfiguration();
|
||||
FlightConfiguration config = rkt.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid = config.getFlightConfigurationID();
|
||||
AerodynamicCalculator calc = new BarrowmanCalculator();
|
||||
FlightConditions conditions = new FlightConditions(config);
|
||||
@ -90,7 +90,7 @@ public class BarrowmanCalculatorTest {
|
||||
@Test
|
||||
public void testCPDoubleStrapOn() {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
BarrowmanCalculator calc = new BarrowmanCalculator();
|
||||
FlightConditions conditions = new FlightConditions(config);
|
||||
WarningSet warnings = new WarningSet();
|
||||
|
@ -35,7 +35,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
// Validate Boosters
|
||||
MassCalculator mc = new MassCalculator();
|
||||
//mc.debug = true;
|
||||
Coordinate rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.NO_MOTORS);
|
||||
Coordinate rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.NO_MOTORS);
|
||||
|
||||
double expMass = 0.668984592;
|
||||
double expCMx = 0.558422219894;
|
||||
@ -47,9 +47,9 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
assertEquals(" Delta Heavy Booster CM.z is incorrect: ", expCM.z, rocketCM.z, EPSILON);
|
||||
assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM);
|
||||
|
||||
rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS);
|
||||
rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.LAUNCH_MASS);
|
||||
assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM);
|
||||
rocketCM = mc.getCM( rkt.getDefaultConfiguration(), MassCalcType.BURNOUT_MASS);
|
||||
rocketCM = mc.getCM( rkt.getSelectedConfiguration(), MassCalcType.BURNOUT_MASS);
|
||||
assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, rocketCM);
|
||||
}
|
||||
|
||||
@ -267,14 +267,14 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
rocket.getDefaultConfiguration().clearAllStages();
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
rocket.getSelectedConfiguration().clearAllStages();
|
||||
rocket.getSelectedConfiguration().setOnlyStage( boostNum);
|
||||
// String treeDump = rocket.toDebugTree();
|
||||
// System.err.println( treeDump);
|
||||
|
||||
// Validate Boosters
|
||||
MassCalculator mc = new MassCalculator();
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS);
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS);
|
||||
|
||||
double expMass = 0.23590802751203407;
|
||||
double expCMx = 0.9615865040919498;
|
||||
@ -296,14 +296,14 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
//rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
rocket.getSelectedConfiguration().setOnlyStage( boostNum);
|
||||
|
||||
//String treeDump = rocket.toDebugTree();
|
||||
//System.err.println( treeDump);
|
||||
{
|
||||
// Validate Booster Launch Mass
|
||||
MassCalculator mc = new MassCalculator();
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS);
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.LAUNCH_MASS);
|
||||
double calcTotalMass = boosterSetCM.weight;
|
||||
|
||||
double expTotalMass = 1.219908027512034;
|
||||
@ -318,7 +318,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
{
|
||||
// Validate Booster Burnout Mass
|
||||
MassCalculator mc = new MassCalculator();
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.BURNOUT_MASS);
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.BURNOUT_MASS);
|
||||
double calcTotalMass = boosterSetCM.weight;
|
||||
|
||||
double expTotalMass = 0.7479080275020341;
|
||||
@ -337,12 +337,12 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
public void testTestBoosterStructureMOI() {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||
FlightConfiguration defaultConfig = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration defaultConfig = rocket.getSelectedConfiguration();
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
rocket.getSelectedConfiguration().setOnlyStage( boostNum);
|
||||
// String treeDump = rocket.toDebugTree();
|
||||
// System.err.println( treeDump);
|
||||
|
||||
@ -361,14 +361,14 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testBoosterTotalMOI() {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
FlightConfiguration defaultConfig = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration defaultConfig = rocket.getSelectedConfiguration();
|
||||
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
int boostNum = boosters.getStageNumber();
|
||||
|
||||
//rocket.getDefaultConfiguration().setAllStages(false);
|
||||
rocket.getDefaultConfiguration().setOnlyStage( boostNum);
|
||||
rocket.getSelectedConfiguration().setOnlyStage( boostNum);
|
||||
//String treeDump = rocket.toDebugTree();
|
||||
//System.err.println( treeDump);
|
||||
|
||||
@ -389,7 +389,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testMassOverride() {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
@ -407,7 +407,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
// Validate Mass
|
||||
MassCalculator mc = new MassCalculator();
|
||||
//mc.debug = true;
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS);
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS);
|
||||
double calcTotalMass = boosterSetCM.weight;
|
||||
|
||||
double expTotalMass = overrideMass;
|
||||
@ -439,7 +439,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testCMOverride() {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||
|
||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||
@ -456,7 +456,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
// Validate Mass
|
||||
MassCalculator mc = new MassCalculator();
|
||||
//mc.debug = true;
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getDefaultConfiguration(), MassCalcType.NO_MOTORS);
|
||||
Coordinate boosterSetCM = mc.getCM( rocket.getSelectedConfiguration(), MassCalcType.NO_MOTORS);
|
||||
|
||||
double expMass = 0.23590802751203407;
|
||||
double calcTotalMass = boosterSetCM.weight;
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
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.motor.Manufacturer;
|
||||
@ -26,7 +28,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testEmptyRocket() {
|
||||
Rocket r1 = makeEmptyRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
FlightConfiguration config = r1.getSelectedConfiguration();
|
||||
|
||||
FlightConfiguration configClone = config.clone();
|
||||
|
||||
@ -39,7 +41,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testCloneBasic() {
|
||||
Rocket rkt1 = makeTwoStageMotorRocket();
|
||||
FlightConfiguration config1 = rkt1.getDefaultConfiguration();
|
||||
FlightConfiguration config1 = rkt1.getSelectedConfiguration();
|
||||
|
||||
// preconditions
|
||||
config1.setAllStages();
|
||||
@ -85,7 +87,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testCloneIndependence() {
|
||||
Rocket rkt1 = makeTwoStageMotorRocket();
|
||||
FlightConfiguration config1 = rkt1.getDefaultConfiguration();
|
||||
FlightConfiguration config1 = rkt1.getSelectedConfiguration();
|
||||
int expectedStageCount;
|
||||
int actualStageCount;
|
||||
int expectedMotorCount;
|
||||
@ -98,8 +100,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
FlightConfiguration config2 = config1.clone();
|
||||
// ^^^^ test target ^^^^
|
||||
config1.clearAllStages();
|
||||
|
||||
|
||||
|
||||
// postcondition: config #1
|
||||
expectedStageCount = 0;
|
||||
actualStageCount = config1.getActiveStageCount();
|
||||
@ -125,7 +126,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
|
||||
/* Setup */
|
||||
Rocket r1 = makeSingleStageTestRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
FlightConfiguration config = r1.getSelectedConfiguration();
|
||||
|
||||
// test explicitly setting only first stage active
|
||||
config.clearAllStages();
|
||||
@ -159,7 +160,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
|
||||
/* Setup */
|
||||
Rocket r1 = makeTwoStageTestRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
FlightConfiguration config = r1.getSelectedConfiguration();
|
||||
|
||||
int expectedStageCount;
|
||||
int stageCount;
|
||||
@ -216,7 +217,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
|
||||
/* Setup */
|
||||
Rocket rkt = makeTwoStageMotorRocket();
|
||||
FlightConfiguration config = rkt.getDefaultConfiguration();
|
||||
FlightConfiguration config = rkt.getSelectedConfiguration();
|
||||
|
||||
|
||||
config.clearAllStages();
|
||||
@ -376,15 +377,16 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
assertThat(" rocket has incorrect stage count: ", rocket.getStageCount(), equalTo(expectedStageCount));
|
||||
|
||||
int expectedConfigurationCount = 0;
|
||||
assertThat(" configuration list contains : ", rocket.getConfigSet().size(), equalTo(expectedConfigurationCount));
|
||||
assertThat(" configuration list contains : ", rocket.getFlightConfigurationCount(), equalTo(expectedConfigurationCount));
|
||||
|
||||
FlightConfiguration newConfig = new FlightConfiguration(rocket,null);
|
||||
rocket.setFlightConfiguration( newConfig.getId(), newConfig);
|
||||
rocket.setDefaultConfiguration( newConfig.getId());
|
||||
assertThat(" configuration updates stage Count correctly: ", newConfig.getActiveStageCount(), equalTo(expectedStageCount));
|
||||
expectedConfigurationCount = 1;
|
||||
assertThat(" configuration list contains : ", rocket.getConfigSet().size(), equalTo(expectedConfigurationCount));
|
||||
assertThat(" configuration list contains : ", rocket.getFlightConfigurationCount(), equalTo(expectedConfigurationCount));
|
||||
|
||||
rocket.update();
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
@ -442,13 +444,14 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
// FlightConfiguration newConfig = new FlightConfiguration(rocket,null);
|
||||
// rocket.setFlightConfiguration( newConfig.getId(), newConfig);
|
||||
|
||||
rocket.update();
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
||||
public static Rocket makeTwoStageMotorRocket() {
|
||||
Rocket rocket = makeTwoStageTestRocket();
|
||||
FlightConfigurationId fcid = rocket.getDefaultConfiguration().getId();
|
||||
FlightConfigurationId fcid = rocket.getSelectedConfiguration().getId();
|
||||
|
||||
{
|
||||
// public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description,
|
||||
@ -485,7 +488,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
boosterMount.setMotorInstance(fcid, new MotorConfiguration(boosterMotor));
|
||||
boosterMount.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[1]); // double-mount
|
||||
}
|
||||
rocket.getConfigSet().update();
|
||||
rocket.update();
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ public class ParallelStageTest extends BaseTestCase {
|
||||
int actualStageCount = rocket.getStageCount();
|
||||
|
||||
assertEquals(" Stage tracking error: removed booster A, but count not updated: " + treedump, expectedStageCount, actualStageCount);
|
||||
actualStageCount = rocket.getDefaultConfiguration().getStageCount();
|
||||
actualStageCount = rocket.getSelectedConfiguration().getStageCount();
|
||||
assertEquals(" Stage tracking error: removed booster A, but configuration not updated: " + treedump, expectedStageCount, actualStageCount);
|
||||
|
||||
ParallelStage boosterC = createBooster();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@ -14,17 +15,53 @@ import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||
public class RocketTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testCopyFrom() {
|
||||
Rocket r1 = net.sf.openrocket.util.TestRockets.makeIsoHaisu();
|
||||
Rocket r2 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
||||
public void testCopyRocket() {
|
||||
Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
||||
|
||||
Rocket copy = (Rocket) r2.copy();
|
||||
Rocket copy = (Rocket) r1.copy();
|
||||
|
||||
ComponentCompare.assertDeepEquality(r2, copy);
|
||||
//ComponentCompare.assertDeepEquality(r1, copy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyIndependence() {
|
||||
Rocket rkt1 = TestRockets.makeEstesAlphaIII();
|
||||
FlightConfiguration config1 = rkt1.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid1 = config1.getId();
|
||||
FlightConfiguration config2 = new FlightConfiguration(rkt1, null);
|
||||
rkt1.setFlightConfiguration( config2.getId(), config2);
|
||||
FlightConfiguration config3 = new FlightConfiguration(rkt1, null);
|
||||
rkt1.setFlightConfiguration( config3.getId(), config3);
|
||||
|
||||
r1.copyFrom(copy);
|
||||
//System.err.println("src: "+ rkt1.toDebugConfigs());
|
||||
// vvvv test target vvvv
|
||||
Rocket rkt2 = rkt1.copyWithOriginalID();
|
||||
// ^^^^ test target ^^^^
|
||||
//System.err.println("cpy: "+ rkt1.toDebugConfigs());
|
||||
|
||||
ComponentCompare.assertDeepEquality(r1, r2);
|
||||
FlightConfiguration config4 = rkt2.getSelectedConfiguration();
|
||||
FlightConfigurationId fcid4 = config4.getId();
|
||||
assertThat("fcids should match: ", fcid1.key, equalTo(fcid4.key));
|
||||
assertThat("Configurations should be different match: "+config1.toDebug()+"=?="+config4.toDebug(), config1.instanceNumber, not( config4.instanceNumber));
|
||||
|
||||
FlightConfiguration config5 = rkt2.getFlightConfiguration(config2.getId());
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCopyRocketFrom() {
|
||||
//Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
||||
//Rocket r2 = new Rocket();
|
||||
|
||||
// this method fails, but I'm not sure what this is testing, or why.
|
||||
// therefore, I'm not convinced it's valuable enough to keep around.
|
||||
//r2.copyFrom(r1);
|
||||
//ComponentCompare.assertDeepEquality(r1, r2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,7 +41,7 @@ public class AxialStageConfig extends ComponentAssemblyConfig {
|
||||
// Select separation event
|
||||
panel.add(new StyledLabel(trans.get("StageConfig.separation.lbl.title") + " " + CommonStrings.dagger, Style.BOLD), "spanx, wrap rel");
|
||||
|
||||
FlightConfiguration flConfig = stage.getRocket().getDefaultConfiguration();
|
||||
FlightConfiguration flConfig = stage.getRocket().getSelectedConfiguration();
|
||||
StageSeparationConfiguration sepConfig = stage.getSeparationConfigurations().get(flConfig.getId());
|
||||
// to ensure the configuration is distinct, and we're not modifying the default
|
||||
if( sepConfig == stage.getSeparationConfigurations().getDefault() ){
|
||||
|
@ -46,7 +46,6 @@ import net.sf.openrocket.gui.adaptors.Column;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTable;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.adaptors.ParameterSetModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.StageSelector;
|
||||
import net.sf.openrocket.gui.components.StyledLabel;
|
||||
@ -58,6 +57,7 @@ import net.sf.openrocket.masscalc.MassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;
|
||||
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
@ -177,8 +177,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||
panel.add(label, "growx, right");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigSet());
|
||||
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>(psm);
|
||||
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>( configuration.getRocket().toConfigArray());
|
||||
panel.add(combo, "wrap");
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
public DeploymentSelectionDialog(Window parent, final Rocket rocket, final RecoveryDevice component) {
|
||||
super(parent, trans.get("edtmotorconfdlg.title.Selectdeploymentconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
|
||||
final FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
final FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
|
||||
newConfiguration = component.getDeploymentConfigurations().get(id).clone();
|
||||
|
||||
|
@ -40,7 +40,6 @@ public class RenameConfigDialog extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newName = textbox.getText();
|
||||
rocket.getFlightConfiguration(fcid).setName( newName);
|
||||
System.err.println(rocket.getConfigSet().toDebug());
|
||||
RenameConfigDialog.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
@ -42,7 +42,7 @@ public class SeparationSelectionDialog extends JDialog {
|
||||
|
||||
public SeparationSelectionDialog(Window parent, final Rocket rocket, final AxialStage stage) {
|
||||
super(parent, trans.get("edtmotorconfdlg.title.Selectseparationconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
final FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
final FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
|
||||
newConfiguration = stage.getSeparationConfigurations().get(id);
|
||||
if( stage.getSeparationConfigurations().isDefault( newConfiguration )){
|
||||
|
@ -960,14 +960,14 @@ public class GeneralOptimizationDialog extends JDialog {
|
||||
simulations.add(new Named<Simulation>(s, name));
|
||||
}
|
||||
|
||||
for (FlightConfiguration config : rocket.getConfigSet()) {
|
||||
FlightConfigurationId fcid = config.getFlightConfigurationID();
|
||||
if ( fcid == null) {
|
||||
for (FlightConfigurationId curId: rocket.getIds() ){
|
||||
if ( curId== null) {
|
||||
// this is now *extremely* unlikely
|
||||
throw new NullPointerException(" flightconfiguration has a null id... bug.");
|
||||
}
|
||||
|
||||
Simulation sim = new Simulation(rocket);
|
||||
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, fcid));
|
||||
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, curId));
|
||||
simulations.add(new Named<Simulation>(sim, name));
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
|
||||
setupView(gl, glu);
|
||||
|
||||
final FlightConfiguration configuration = rkt.getDefaultConfiguration();
|
||||
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
|
||||
if (pickPoint != null) {
|
||||
gl.glDisable(GLLightingFunc.GL_LIGHTING);
|
||||
|
||||
@ -488,7 +488,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
return cachedBounds;
|
||||
} else {
|
||||
final Bounds b = new Bounds();
|
||||
final FlightConfiguration configuration = rkt.getDefaultConfiguration();
|
||||
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
|
||||
final Collection<Coordinate> bounds = configuration.getBounds();
|
||||
for (Coordinate c : bounds) {
|
||||
b.xMax = Math.max(b.xMax, c.x);
|
||||
|
@ -173,7 +173,7 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
this.document = document;
|
||||
this.rocket = document.getRocket();
|
||||
this.rocket.getDefaultConfiguration().setAllStages();
|
||||
this.rocket.getSelectedConfiguration().setAllStages();
|
||||
|
||||
// Create the component tree selection model that will be used
|
||||
componentSelectionModel = new DefaultTreeSelectionModel();
|
||||
|
@ -624,7 +624,7 @@ public class RocketActions {
|
||||
//// Add stage
|
||||
document.addUndoPosition("Add stage");
|
||||
rocket.addChild(stage);
|
||||
rocket.getDefaultConfiguration().setAllStages();
|
||||
rocket.getSelectedConfiguration().setAllStages();
|
||||
selectionModel.setSelectedComponent(stage);
|
||||
ComponentConfigDialog.showDialog(parentFrame, document, stage);
|
||||
|
||||
|
@ -43,7 +43,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
this.flightConfigurationPanel = flightConfigurationPanel;
|
||||
this.rocket = rocket;
|
||||
table = initializeTable();
|
||||
rocket.getDefaultConfiguration().addChangeListener( new StateChangeListener() {
|
||||
rocket.getSelectedConfiguration().addChangeListener( new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
FlightConfigurablePanel.this.synchronizeConfigurationSelection();
|
||||
@ -64,7 +64,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
protected abstract void updateButtonState();
|
||||
|
||||
protected final void synchronizeConfigurationSelection() {
|
||||
FlightConfigurationId defaultFCID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId defaultFCID = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId selectedFCID = getSelectedConfigurationId();
|
||||
|
||||
if ( selectedFCID == null ) {
|
||||
@ -78,9 +78,8 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
col = (table.getColumnCount() > 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
java.util.List<FlightConfigurationId> ids = rocket.getSortedConfigurationIDs();
|
||||
for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) {
|
||||
FlightConfigurationId rowFCID = ids.get(rowNum );
|
||||
FlightConfigurationId rowFCID = rocket.getId(rowNum );
|
||||
if ( rowFCID.equals(selectedFCID) ) {
|
||||
table.changeSelection(rowNum, col, true, false);
|
||||
break;
|
||||
|
@ -75,7 +75,7 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row, int column) {
|
||||
FlightConfigurationId fcid = getConfigurationID(row);
|
||||
FlightConfigurationId fcid = rocket.getId( row);
|
||||
|
||||
switch (column) {
|
||||
case 0: {
|
||||
@ -104,12 +104,4 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
|
||||
}
|
||||
}
|
||||
|
||||
private FlightConfigurationId getConfigurationID(int rowNum) {
|
||||
if( rocket.getConfigurationCount() != (ids.size() ) ){
|
||||
this.ids = rocket.getSortedConfigurationIDs();
|
||||
}
|
||||
|
||||
return this.ids.get(rowNum);
|
||||
}
|
||||
|
||||
}
|
@ -119,7 +119,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
this.add(tabs, "spanx, grow, wrap rel");
|
||||
|
||||
|
||||
this.rocket.getDefaultConfiguration().addChangeListener(this);
|
||||
this.rocket.getSelectedConfiguration().addChangeListener(this);
|
||||
}
|
||||
|
||||
private void addConfiguration() {
|
||||
@ -135,7 +135,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
}
|
||||
|
||||
private void copyConfiguration() {
|
||||
FlightConfiguration oldConfig = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration oldConfig = rocket.getSelectedConfiguration();
|
||||
FlightConfiguration newConfig = oldConfig.clone();
|
||||
FlightConfigurationId oldId = oldConfig.getFlightConfigurationID();
|
||||
FlightConfigurationId newId = newConfig.getFlightConfigurationID();
|
||||
@ -185,7 +185,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
}
|
||||
|
||||
private void updateButtonState() {
|
||||
FlightConfigurationId currentId = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId currentId = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
// Enable the remove/rename/copy buttons only when a configuration is selected.
|
||||
removeConfButton.setEnabled(currentId.isValid());
|
||||
renameConfButton.setEnabled(currentId.isValid());
|
||||
|
@ -102,7 +102,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
c.getDeploymentConfigurations().reset(id);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
|
||||
}
|
||||
|
||||
// why?
|
||||
FlightConfigurationId id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
stage.getSeparationConfigurations().reset(id);
|
||||
|
||||
fireTableDataChanged();
|
||||
|
@ -163,7 +163,7 @@ public class DesignReport {
|
||||
PrintUtilities.addText(document, PrintUtilities.BIG_BOLD, ROCKET_DESIGN);
|
||||
|
||||
Rocket rocket = rocketDocument.getRocket();
|
||||
final FlightConfiguration configuration = rocket.getDefaultConfiguration();//.clone();
|
||||
final FlightConfiguration configuration = rocket.getSelectedConfiguration();//.clone();
|
||||
configuration.setAllStages();
|
||||
PdfContentByte canvas = writer.getDirectContent();
|
||||
|
||||
@ -225,8 +225,7 @@ public class DesignReport {
|
||||
List<Simulation> simulations = rocketDocument.getSimulations();
|
||||
|
||||
int motorNumber = 0;
|
||||
for( FlightConfiguration curConfig : rocket.getConfigSet()){
|
||||
FlightConfigurationId fcid = curConfig.getFlightConfigurationID();
|
||||
for( FlightConfigurationId fcid : rocket.getIds()){
|
||||
|
||||
PdfPTable parent = new PdfPTable(2);
|
||||
parent.setWidthPercentage(100);
|
||||
|
@ -109,7 +109,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
||||
}
|
||||
|
||||
public FlightConfiguration getConfiguration() {
|
||||
return this.rocket.getDefaultConfiguration();
|
||||
return this.rocket.getSelectedConfiguration();
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
||||
figureShapes.clear();
|
||||
|
||||
calculateSize();
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
getShapes( figureShapes, config);
|
||||
|
||||
repaint();
|
||||
@ -337,7 +337,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
||||
Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor();
|
||||
Color borderColor = ((SwingPreferences)Application.getPreferences()).getMotorBorderColor();
|
||||
|
||||
FlightConfiguration config = rocket.getDefaultConfiguration();
|
||||
FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||
for( MotorConfiguration curInstance : config.getActiveMotors()){
|
||||
MotorMount mount = curInstance.getMount();
|
||||
Motor motor = curInstance.getMotor();
|
||||
@ -514,7 +514,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
||||
* The bounds are stored in the variables minX, maxX and maxR.
|
||||
*/
|
||||
private void calculateFigureBounds() {
|
||||
Collection<Coordinate> bounds = rocket.getDefaultConfiguration().getBounds();
|
||||
Collection<Coordinate> bounds = rocket.getSelectedConfiguration().getBounds();
|
||||
|
||||
if (bounds.isEmpty()) {
|
||||
minX = 0;
|
||||
|
@ -39,7 +39,6 @@ import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.adaptors.ParameterSetModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.StageSelector;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
@ -306,22 +305,17 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||
add(label, "growx, right");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigSet());
|
||||
JComboBox<FlightConfiguration> flightConfigurationComboBox = new JComboBox<FlightConfiguration>(psm);
|
||||
add(flightConfigurationComboBox, "wrap, width 16%, wmin 100");
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
|
||||
|
||||
add(configComboBox, "wrap, width 16%, wmin 100");
|
||||
|
||||
flightConfigurationComboBox.addActionListener(new ActionListener(){
|
||||
configComboBox.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
Object source = ae.getSource();
|
||||
if( source instanceof JComboBox ){
|
||||
@SuppressWarnings("unchecked")
|
||||
JComboBox<FlightConfigurationId> box = (JComboBox<FlightConfigurationId>) source;
|
||||
FlightConfiguration newConfig = (FlightConfiguration)box.getSelectedItem();
|
||||
document.getRocket().getConfigSet().setDefault( newConfig);
|
||||
updateExtras();
|
||||
updateFigures();
|
||||
}
|
||||
FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem();
|
||||
document.getRocket().setSelectedConfiguration( newConfig);
|
||||
updateExtras();
|
||||
updateFigures();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -149,22 +149,20 @@ public class SimulationEditDialog extends JDialog {
|
||||
label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg"));
|
||||
panel.add(label, "growx 0, gapright para");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( document.getRocket().getConfigSet());
|
||||
final JComboBox<FlightConfiguration> configCombo = new JComboBox<FlightConfiguration>(psm);
|
||||
FlightConfiguration config = document.getRocket().getFlightConfiguration(simulation[0].getId());
|
||||
configCombo.setSelectedItem( config );
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
|
||||
configComboBox.setSelectedItem( document.getRocket().getSelectedConfiguration().getId() );
|
||||
|
||||
//// Select the motor configuration to use.
|
||||
configCombo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||
configCombo.addActionListener(new ActionListener() {
|
||||
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||
configComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FlightConfiguration config = (FlightConfiguration) configCombo.getSelectedItem();
|
||||
FlightConfigurationId id = config.getFlightConfigurationID();
|
||||
FlightConfiguration config = (FlightConfiguration)configComboBox.getSelectedItem();
|
||||
FlightConfigurationId id = config.getId();
|
||||
conditions.setFlightConfigurationId( id );
|
||||
}
|
||||
});
|
||||
panel.add(configCombo, "span");
|
||||
panel.add(configComboBox, "span");
|
||||
|
||||
panel.add(new JPanel(), "growx, wrap");
|
||||
|
||||
|
@ -292,7 +292,7 @@ public class SimulationRunDialog extends JDialog {
|
||||
double otherBurn = 0;
|
||||
|
||||
|
||||
FlightConfiguration config = simulation.getRocket().getDefaultConfiguration();
|
||||
FlightConfiguration config = simulation.getRocket().getSelectedConfiguration();
|
||||
Collection<MotorConfiguration> activeMotors = config.getActiveMotors();
|
||||
|
||||
for (MotorConfiguration curInstance : activeMotors) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user