From 39420ddfc08bb12034d9181ce19749017a4e0970 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Tue, 19 Jan 2016 00:03:25 -0500 Subject: [PATCH] [Bugfix] Cleaned up simulation and configuration Ids loading - Simulations now load the configuration ids corresponding to it's file entry. - involved removing redundand flightconfig id fields - FROM simulation conditions and simulation options - TO "Simulation" - Distilled some unit tests to use all rockets from the TestRocket class. - Fixed a few warnings --- .../document/OpenRocketDocument.java | 4 +- .../sf/openrocket/document/Simulation.java | 49 ++- .../file/openrocket/OpenRocketSaver.java | 2 +- .../importt/SimulationConditionsHandler.java | 35 +- .../importt/SingleSimulationHandler.java | 12 +- .../motor/MotorConfigurationSet.java | 9 +- .../rocketcomponent/FlightConfiguration.java | 5 +- .../sf/openrocket/rocketcomponent/Rocket.java | 3 +- .../rocketcomponent/RocketComponent.java | 2 +- .../DefaultSimulationOptionFactory.java | 2 +- .../simulation/SimulationConditions.java | 28 +- .../simulation/SimulationOptions.java | 86 +---- .../net/sf/openrocket/util/TestRockets.java | 309 +++++++++++++++-- .../FlightConfigurationTest.java | 310 +++--------------- .../examples/Booster Stage Example.ork | Bin 2426 -> 0 bytes .../examples/Parallel_Staging_Example.ork | Bin 0 -> 2476 bytes .../GeneralOptimizationDialog.java | 2 +- .../openrocket/gui/main/SimulationPanel.java | 3 +- .../FlightConfigurableTableModel.java | 3 +- .../sf/openrocket/gui/print/DesignReport.java | 2 +- .../gui/scalefigure/RocketPanel.java | 3 +- .../gui/simulation/SimulationEditDialog.java | 46 ++- 22 files changed, 444 insertions(+), 471 deletions(-) delete mode 100644 swing/resources/datafiles/examples/Booster Stage Example.ork create mode 100644 swing/resources/datafiles/examples/Parallel_Staging_Example.ork diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index fca963520..a68390bb3 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -281,7 +281,7 @@ public class OpenRocketDocument implements ComponentChangeListener { } for (Simulation s : getSimulations()) { // Assumes modifiable collection - which it is - if (configId.equals(s.getOptions().getId())) { + if (configId.equals(s.getId())) { removeSimulation(s); } } @@ -637,7 +637,7 @@ public class OpenRocketDocument implements ComponentChangeListener { str.append(">> Dumping simulation list:\n"); int simNum = 0; for( Simulation s : this.simulations ){ - str.append(String.format(" [%d] %s (%s) \n", simNum, s.getName(), s.getOptions().getId().toShortKey() )); + str.append(String.format(" [%d] %s (%s) \n", simNum, s.getName(), s.getId().toShortKey() )); simNum++; } diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index 85a2ad7db..30b4d02c7 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -70,6 +70,7 @@ public class Simulation implements ChangeSource, Cloneable { private SafetyMutex mutex = SafetyMutex.newInstance(); private final Rocket rocket; + FlightConfigurationId configId = FlightConfigurationId.ERROR_FCID; private String name = ""; @@ -77,7 +78,7 @@ public class Simulation implements ChangeSource, Cloneable { /** The conditions to use */ // TODO: HIGH: Change to use actual conditions class?? - private SimulationOptions options; + private SimulationOptions options = new SimulationOptions(); private ArrayList simulationExtensions = new ArrayList(); @@ -109,13 +110,12 @@ public class Simulation implements ChangeSource, Cloneable { this.rocket = rocket; this.status = Status.NOT_SIMULATED; - options = new SimulationOptions(rocket); - DefaultSimulationOptionFactory f = Application.getInjector().getInstance(DefaultSimulationOptionFactory.class); options.copyConditionsFrom(f.getDefault()); FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID(); - options.setFlightConfigurationId(fcid); + setFlightConfigurationId(fcid); + options.addChangeListener(new ConditionListener()); } @@ -146,9 +146,8 @@ public class Simulation implements ChangeSource, Cloneable { this.options = options; - FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID(); - options.setFlightConfigurationId(fcid); - + this.setFlightConfigurationId( rocket.getSelectedConfiguration().getFlightConfigurationID()); + options.addChangeListener(new ConditionListener()); if (extensions != null) { @@ -176,9 +175,35 @@ public class Simulation implements ChangeSource, Cloneable { return rocket; } - public FlightConfigurationId getId(){ - return this.options.getFlightConfigurationId(); + public FlightConfigurationId getFlightConfigurationId(){ + return this.configId; } + public FlightConfigurationId getId(){ + return this.getFlightConfigurationId(); + } + + /** + * Set the motor configuration ID. If this id does not yet exist, it will be created. + * + * @param id the configuration to set. + */ + public void setFlightConfigurationId(FlightConfigurationId fcid) { + if ( null == fcid ){ + throw new NullPointerException("Attempted to set a null Config id in simulation options. Not allowed!"); + }else if ( fcid.hasError() ){ + throw new IllegalArgumentException("Attempted to set the configuration to an error id. Not Allowed!"); + }else if (!rocket.containsFlightConfigurationID(fcid)){ + rocket.createFlightConfiguration(fcid); + } + + if( fcid.equals(this.configId)){ + return; + } + + this.configId = fcid; + fireChangeEvent(); + } + // /** // * Return a newly created Configuration for this simulation. The configuration @@ -284,13 +309,13 @@ public class Simulation implements ChangeSource, Cloneable { } // if the id hasn't been set yet, skip. - if ( options.getId().hasError() ){ + if ( getId().hasError() ){ log.warn(" simulationOptions lacks a valid id. Skipping."); status = Status.CANT_RUN; return status; } - FlightConfiguration config = rocket.getFlightConfiguration(options.getId()); + FlightConfiguration config = rocket.getFlightConfiguration( this.getId()).clone(); //Make sure this simulation has motors. if ( ! config.hasMotors() ){ @@ -346,7 +371,7 @@ public class Simulation implements ChangeSource, Cloneable { // Set simulated info after simulation, will not be set in case of exception simulatedConditions = options.clone(); - simulatedConfigurationDescription = descriptor.format( this.rocket, options.getId()); + simulatedConfigurationDescription = descriptor.format( this.rocket, getId()); simulatedRocketID = rocket.getFunctionalModID(); status = Status.UPTODATE; diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index d9e3f27a3..bad0a5a9c 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -380,7 +380,7 @@ public class OpenRocketSaver extends RocketSaver { writeln(""); indent++; - writeElement("configid", cond.getId().key); + writeElement("configid", simulation.getId().key); writeElement("launchrodlength", cond.getLaunchRodLength()); writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI); writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI)); diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java index b85d2aca0..27b72c8db 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java @@ -14,18 +14,19 @@ import net.sf.openrocket.util.GeodeticComputationStrategy; class SimulationConditionsHandler extends AbstractElementHandler { private final DocumentLoadingContext context; - private SimulationOptions conditions; + public FlightConfigurationId idToSet = FlightConfigurationId.ERROR_FCID; + private SimulationOptions options; private AtmosphereHandler atmosphereHandler; public SimulationConditionsHandler(Rocket rocket, DocumentLoadingContext context) { this.context = context; - conditions = new SimulationOptions(rocket); + options = new SimulationOptions(); // Set up default loading settings (which may differ from the new defaults) - conditions.setGeodeticComputation(GeodeticComputationStrategy.FLAT); + options.setGeodeticComputation(GeodeticComputationStrategy.FLAT); } public SimulationOptions getConditions() { - return conditions; + return options; } @Override @@ -50,72 +51,70 @@ class SimulationConditionsHandler extends AbstractElementHandler { if (element.equals("configid")) { - // the ID constructor is designed to always return a valid value - FlightConfigurationId idToSet= new FlightConfigurationId(content); - conditions.setFlightConfigurationId(idToSet); + this.idToSet= new FlightConfigurationId(content); } else if (element.equals("launchrodlength")) { if (Double.isNaN(d)) { warnings.add("Illegal launch rod length defined, ignoring."); } else { - conditions.setLaunchRodLength(d); + options.setLaunchRodLength(d); } } else if (element.equals("launchrodangle")) { if (Double.isNaN(d)) { warnings.add("Illegal launch rod angle defined, ignoring."); } else { - conditions.setLaunchRodAngle(d * Math.PI / 180); + options.setLaunchRodAngle(d * Math.PI / 180); } } else if (element.equals("launchroddirection")) { if (Double.isNaN(d)) { warnings.add("Illegal launch rod direction defined, ignoring."); } else { - conditions.setLaunchRodDirection(d * 2.0 * Math.PI / 360); + options.setLaunchRodDirection(d * 2.0 * Math.PI / 360); } } else if (element.equals("windaverage")) { if (Double.isNaN(d)) { warnings.add("Illegal average windspeed defined, ignoring."); } else { - conditions.setWindSpeedAverage(d); + options.setWindSpeedAverage(d); } } else if (element.equals("windturbulence")) { if (Double.isNaN(d)) { warnings.add("Illegal wind turbulence intensity defined, ignoring."); } else { - conditions.setWindTurbulenceIntensity(d); + options.setWindTurbulenceIntensity(d); } } else if (element.equals("launchaltitude")) { if (Double.isNaN(d)) { warnings.add("Illegal launch altitude defined, ignoring."); } else { - conditions.setLaunchAltitude(d); + options.setLaunchAltitude(d); } } else if (element.equals("launchlatitude")) { if (Double.isNaN(d)) { warnings.add("Illegal launch latitude defined, ignoring."); } else { - conditions.setLaunchLatitude(d); + options.setLaunchLatitude(d); } } else if (element.equals("launchlongitude")) { if (Double.isNaN(d)) { warnings.add("Illegal launch longitude."); } else { - conditions.setLaunchLongitude(d); + options.setLaunchLongitude(d); } } else if (element.equals("geodeticmethod")) { GeodeticComputationStrategy gcs = (GeodeticComputationStrategy) DocumentConfig.findEnum(content, GeodeticComputationStrategy.class); if (gcs != null) { - conditions.setGeodeticComputation(gcs); + options.setGeodeticComputation(gcs); } else { warnings.add("Unknown geodetic computation method '" + content + "'"); } } else if (element.equals("atmosphere")) { - atmosphereHandler.storeSettings(conditions, warnings); + atmosphereHandler.storeSettings(options, warnings); } else if (element.equals("timestep")) { if (Double.isNaN(d) || d <= 0) { warnings.add("Illegal time step defined, ignoring."); } else { - conditions.setTimeStep(d); + options.setTimeStep(d); } } } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java index a1d402ffb..7834c285e 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java @@ -13,6 +13,7 @@ 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.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.simulation.FlightData; import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.extension.SimulationExtension; @@ -115,12 +116,14 @@ class SingleSimulationHandler extends AbstractElementHandler { status = Simulation.Status.OUTDATED; } - SimulationOptions conditions; + SimulationOptions options; + FlightConfigurationId idToSet= FlightConfigurationId.ERROR_FCID; if (conditionHandler != null) { - conditions = conditionHandler.getConditions(); + options = conditionHandler.getConditions(); + idToSet = conditionHandler.idToSet; } else { warnings.add("Simulation conditions not defined, using defaults."); - conditions = new SimulationOptions(doc.getRocket()); + options = new SimulationOptions(); } if (name == null) @@ -133,7 +136,8 @@ class SingleSimulationHandler extends AbstractElementHandler { data = dataHandler.getFlightData(); Simulation simulation = new Simulation(doc.getRocket(), status, name, - conditions, extensions, data); + options, extensions, data); + simulation.setFlightConfigurationId( idToSet ); doc.addSimulation(simulation); } diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java index cedfe0085..d3fb571f3 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java @@ -36,8 +36,8 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet> (["+emptyInstance.toString()+"]= @ "+ emptyInstance.getIgnitionEvent().name +" +"+emptyInstance.getIgnitionDelay()+"sec )\n"); + MotorConfiguration defaultConfig = this.getDefault(); + buffer.append(" (Ignition@ "+ defaultConfig.getIgnitionEvent().name +" +"+defaultConfig.getIgnitionDelay()+"sec )\n"); for( FlightConfigurationId loopFCID : this.map.keySet()){ String shortKey = loopFCID.toShortKey(); @@ -45,7 +45,7 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet> ["+shortKey+"]= "+designation+" @ "+ignition+"\n"); + buffer.append(String.format(" >> [%10s]= %6s @ %4s\n", + shortKey, designation, ignition )); } return buffer.toString(); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index eabf07ca0..984f45de6 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -420,10 +420,11 @@ public class FlightConfiguration implements FlightConfigurableParameter maxX) + }else if (coord.x > maxX){ maxX = coord.x; + } } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 8fa36cbf7..6c7456f12 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -818,11 +818,10 @@ public class Rocket extends RocketComponent { StringBuilder buf = new StringBuilder(); buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName())); final String fmt = " [%-12s]: %s\n"; - buf.append(String.format(fmt, " *SELECTED* ", selectedConfiguration.getName() )); for( FlightConfiguration config : this.configSet.values() ){ String shortKey = config.getId().toShortKey(); if( this.selectedConfiguration.equals( config)){ - shortKey = "*"+shortKey+"*"; + shortKey = shortKey+"<="; } buf.append(String.format(fmt, shortKey, config.getName() )); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 633552048..d73f6f518 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -2114,7 +2114,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab public String toDebugTree() { StringBuilder buffer = new StringBuilder(); buffer.append("\n ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ======\n"); - buffer.append(" [Name] [Length] [Rel Pos] [Abs Pos] \n"); + buffer.append(" [Name] [Length] [Rel Pos] [Abs Pos] \n"); this.dumpTreeHelper(buffer, ""); return buffer.toString(); } diff --git a/core/src/net/sf/openrocket/simulation/DefaultSimulationOptionFactory.java b/core/src/net/sf/openrocket/simulation/DefaultSimulationOptionFactory.java index 785598c59..23a2f82f0 100644 --- a/core/src/net/sf/openrocket/simulation/DefaultSimulationOptionFactory.java +++ b/core/src/net/sf/openrocket/simulation/DefaultSimulationOptionFactory.java @@ -33,7 +33,7 @@ public class DefaultSimulationOptionFactory { } public SimulationOptions getDefault() { - SimulationOptions defaults = new SimulationOptions(null); + SimulationOptions defaults = new SimulationOptions(); if (prefs != null) { defaults.setWindSpeedAverage(prefs.getDouble(SIMCONDITION_WIND_SPEED, defaults.getWindSpeedAverage())); diff --git a/core/src/net/sf/openrocket/simulation/SimulationConditions.java b/core/src/net/sf/openrocket/simulation/SimulationConditions.java index 01b455ded..66fd5cb97 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationConditions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationConditions.java @@ -27,9 +27,6 @@ import net.sf.openrocket.util.WorldCoordinate; */ public class SimulationConditions implements Monitorable, Cloneable { - private Rocket rocket; - private FlightConfigurationId configId= null; - private Simulation simulation; // The parent simulation private double launchRodLength = 1; @@ -103,29 +100,16 @@ public class SimulationConditions implements Monitorable, Cloneable { public Rocket getRocket() { - return rocket; + return simulation.getRocket(); } - - - public void setRocket(Rocket rocket) { - if (this.rocket != null) - this.modIDadd += this.rocket.getModID(); - this.modID++; - this.rocket = rocket; - } - + public FlightConfigurationId getMotorConfigurationID() { - return configId; + return simulation.getId(); } public FlightConfigurationId getFlightConfigurationID() { - return configId; - } - - public void setFlightConfigurationID(FlightConfigurationId _fcid) { - this.configId = _fcid; - this.modID++; + return simulation.getId(); } @@ -313,7 +297,7 @@ public class SimulationConditions implements Monitorable, Cloneable { public int getModID() { //return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() + // gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID()); - return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() + + return (modID + modIDadd + simulation.getRocket().getModID() + windModel.getModID() + atmosphericModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID()); } @@ -327,8 +311,6 @@ public class SimulationConditions implements Monitorable, Cloneable { for (SimulationListener listener : this.simulationListeners) { clone.simulationListeners.add(listener.clone()); } - clone.rocket = this.rocket; // the rocket should be read-only from this point - clone.configId = this.configId; // configIds are read-only return clone; } catch (CloneNotSupportedException e) { diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index fd2eabd5f..5aa4d534b 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -10,15 +10,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.sf.openrocket.aerodynamics.BarrowmanCalculator; -import net.sf.openrocket.formatting.MotorDescriptionSubstitutor; import net.sf.openrocket.masscalc.MassCalculator; import net.sf.openrocket.models.atmosphere.AtmosphericModel; import net.sf.openrocket.models.atmosphere.ExtendedISAModel; import net.sf.openrocket.models.gravity.GravityModel; import net.sf.openrocket.models.gravity.WGSGravityModel; import net.sf.openrocket.models.wind.PinkNoiseWindModel; -import net.sf.openrocket.rocketcomponent.FlightConfigurationId; -import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.util.BugException; @@ -26,7 +23,6 @@ import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.GeodeticComputationStrategy; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.StateChangeListener; -import net.sf.openrocket.util.Utils; import net.sf.openrocket.util.WorldCoordinate; /** @@ -50,9 +46,6 @@ public class SimulationOptions implements ChangeSource, Cloneable { protected final Preferences preferences = Application.getPreferences(); - private final Rocket rocket; - private FlightConfigurationId configId = FlightConfigurationId.ERROR_FCID; - /* * NOTE: When adding/modifying parameters, they must also be added to the * equals and copyFrom methods!! @@ -92,45 +85,9 @@ public class SimulationOptions implements ChangeSource, Cloneable { private List listeners = new ArrayList(); - public SimulationOptions(Rocket rocket) { - this.rocket = rocket; + public SimulationOptions() { } - public Rocket getRocket() { - return rocket; - } - - public FlightConfigurationId getFlightConfigurationId() { - return getId(); - } - - public FlightConfigurationId getId() { - return this.configId; - } - - /** - * Set the motor configuration ID. If this id does not yet exist, it will be created. - * - * @param id the configuration to set. - */ - public void setFlightConfigurationId(FlightConfigurationId fcid) { - if ( null == fcid ){ - throw new NullPointerException("Attempted to set a null Config id in simulation options. Not allowed!"); - }else if ( fcid.hasError() ){ - throw new IllegalArgumentException("Attempted to set the configuration to an error id. Not Allowed!"); - }else if (!rocket.containsFlightConfigurationID(fcid)){ - rocket.createFlightConfiguration(fcid); - } - - if( fcid.equals(this.configId)){ - return; - } - - this.configId = fcid; - fireChangeEvent(); - } - - public double getLaunchRodLength() { return launchRodLength; } @@ -436,35 +393,6 @@ public class SimulationOptions implements ChangeSource, Cloneable { public void copyFrom(SimulationOptions src) { - if (this.rocket == src.rocket) { - this.configId = src.configId; - } else { - if (src.rocket.hasMotors(src.configId)) { - // First check for exact match: - if (this.rocket.containsFlightConfigurationID(src.configId)) { - this.configId = src.configId; - } else { - // Try to find a closely matching motor ID - MotorDescriptionSubstitutor formatter = Application.getInjector().getInstance(MotorDescriptionSubstitutor.class); - - String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.configId); - FlightConfigurationId matchID = null; - - for (FlightConfigurationId fcid : rocket.getIds()){ - String motorDesc2 = formatter.getMotorConfigurationDescription(this.rocket, fcid); - if (motorDesc.equals(motorDesc2)) { - matchID = fcid; - break; - } - } - - this.configId = matchID; - } - } else { - this.configId = FlightConfigurationId.ERROR_FCID; - } - } - this.launchAltitude = src.launchAltitude; this.launchLatitude = src.launchLatitude; this.launchLongitude = src.launchLongitude; @@ -564,9 +492,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { if (!(other instanceof SimulationOptions)) return false; SimulationOptions o = (SimulationOptions) other; - return ((this.rocket == o.rocket) && - Utils.equals(this.configId, o.configId) && - MathUtil.equals(this.launchAltitude, o.launchAltitude) && + return (MathUtil.equals(this.launchAltitude, o.launchAltitude) && MathUtil.equals(this.launchLatitude, o.launchLatitude) && MathUtil.equals(this.launchLongitude, o.launchLongitude) && MathUtil.equals(this.launchPressure, o.launchPressure) && @@ -587,9 +513,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { */ @Override public int hashCode() { - if (configId.hasError()) - return rocket.hashCode(); - return rocket.hashCode() + configId.hashCode(); + return 0; } @Override @@ -619,9 +543,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { // TODO: HIGH: Clean up public SimulationConditions toSimulationConditions() { SimulationConditions conditions = new SimulationConditions(); - - conditions.setRocket((Rocket) getRocket().copy()); - conditions.setFlightConfigurationID(this.getId()); + conditions.setLaunchRodLength(getLaunchRodLength()); conditions.setLaunchRodAngle(getLaunchRodAngle()); conditions.setLaunchRodDirection(getLaunchRodDirection()); diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 8e0021cee..b2ce4801f 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -51,7 +51,6 @@ import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.Transition.Shape; import net.sf.openrocket.rocketcomponent.TrapezoidFinSet; import net.sf.openrocket.rocketcomponent.TubeCoupler; -import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.customexpression.CustomExpression; import net.sf.openrocket.simulation.exception.SimulationException; import net.sf.openrocket.simulation.extension.impl.ScriptingExtension; @@ -87,7 +86,48 @@ public class TestRockets { this.rnd = new Random(key.hashCode()); } - + + // Minimal motor without any useful numbers data + private static ThrustCurveMotor getTestMotor() { + return new ThrustCurveMotor( + Manufacturer.getManufacturer("A"), + "F12X", "Desc", Motor.Type.UNKNOWN, new double[] {}, + 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 }, + new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL }, "digestA"); + } + + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + private static MotorConfiguration generateMotorInstance_A8_18mm(){ + // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, + // 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", + 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)}, + "digest A8 test"); + return new MotorConfiguration(mtr); + } + + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + private static MotorConfiguration generateMotorInstance_B4_18mm(){ + // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, + // Motor.Type type, double[] delays, double diameter, double length, + // double[] time, double[] thrust, + // Coordinate[] cg, String digest); + ThrustCurveMotor mtr = 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 new MotorConfiguration(mtr); + } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). private static MotorConfiguration generateMotorInstance_C6_18mm(){ // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, @@ -99,11 +139,23 @@ public class TestRockets { 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.0102)}, + 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 new MotorConfiguration(mtr); } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + private static MotorConfiguration generateMotorInstance_D21_18mm(){ + ThrustCurveMotor mtr = 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 new MotorConfiguration(mtr); + } + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). private static MotorConfiguration generateMotorInstance_M1350_75mm(){ // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, @@ -332,6 +384,18 @@ public class TestRockets { // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). public static final Rocket makeEstesAlphaIII(){ Rocket rocket = new Rocket(); + FlightConfigurationId fcid[] = new FlightConfigurationId[5]; + fcid[0] = rocket.getSelectedConfiguration().getFlightConfigurationID(); + rocket.createFlightConfiguration(fcid[0]); + fcid[1] = new FlightConfigurationId(); + rocket.createFlightConfiguration(fcid[1]); + fcid[2] = new FlightConfigurationId(); + rocket.createFlightConfiguration(fcid[2]); + fcid[3] = new FlightConfigurationId(); + rocket.createFlightConfiguration(fcid[3]); + fcid[4] = new FlightConfigurationId(); + rocket.createFlightConfiguration(fcid[4]); + rocket.setName("Estes Alpha III / Code Verification Rocket"); AxialStage stage = new AxialStage(); stage.setName("Stage"); @@ -394,12 +458,38 @@ public class TestRockets { thrustBlock.setThickness(0.0008); thrustBlock.setName("Engine Block"); inner.addChild(thrustBlock); - - MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); - motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); inner.setMotorMount( true); - FlightConfigurationId motorConfigId = rocket.getSelectedConfiguration().getFlightConfigurationID(); - inner.setMotorInstance( motorConfigId, motorConfig); + + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_A8_18mm(); + motorConfig.setEjectionDelay(0.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + inner.setMotorInstance( fcid[0], motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_B4_18mm(); + motorConfig.setEjectionDelay(3.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + inner.setMotorInstance( fcid[1], motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(3.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + inner.setMotorInstance( fcid[2], motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(5.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + inner.setMotorInstance( fcid[3], motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(7.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + inner.setMotorInstance( fcid[4], motorConfig); + } } // parachute @@ -432,6 +522,192 @@ public class TestRockets { return rocket; } + // This is an extra stage tacked onto the end of an Estes Alpha III + // http://www.rocketreviews.com/alpha-iii---estes-221256.html + // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + public static final Rocket makeBeta(){ + Rocket rocket = new Rocket(); + rocket.setName("Kit-bash Beta"); + AxialStage sustainerStage = new AxialStage(); + sustainerStage.setName("Sustainer Stage"); + rocket.addChild(sustainerStage); + + double noseconeLength = 0.07; + double noseconeRadius = 0.012; + NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius); + nosecone.setAftShoulderLength(0.025); + nosecone.setAftShoulderRadius(0.012); + nosecone.setName("Nose Cone"); + sustainerStage.addChild(nosecone); + + double bodytubeLength = 0.20; + double bodytubeRadius = 0.012; + double bodyTubeThickness = 0.0003; + BodyTube bodytube = new BodyTube(bodytubeLength, bodytubeRadius, bodyTubeThickness); + bodytube.setName("Body Tube"); + sustainerStage.addChild(bodytube); + + TrapezoidFinSet finset; + { + int finCount = 3; + double finRootChord = .05; + double finTipChord = .03; + double finSweep = 0.02; + double finHeight = 0.05; + finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); + finset.setThickness( 0.0032); + finset.setRelativePosition(Position.BOTTOM); + finset.setName("3 Fin Set"); + bodytube.addChild(finset); + + LaunchLug lug = new LaunchLug(); + lug.setName("Launch Lugs"); + lug.setRelativePosition(Position.TOP); + lug.setAxialOffset(0.111); + lug.setLength(0.050); + lug.setOuterRadius(0.0022); + lug.setInnerRadius(0.0020); + bodytube.addChild(lug); + + InnerTube inner = new InnerTube(); + inner.setRelativePosition(Position.TOP); + inner.setAxialOffset(0.133); + inner.setLength(0.07); + inner.setOuterRadius(0.009); + inner.setThickness(0.0003); + inner.setMotorMount(true); + inner.setName("Motor Mount Tube"); + bodytube.addChild(inner); + + { + // MotorBlock + EngineBlock thrustBlock= new EngineBlock(); + thrustBlock.setRelativePosition(Position.TOP); + thrustBlock.setAxialOffset(0.0); + thrustBlock.setLength(0.005); + thrustBlock.setOuterRadius(0.009); + thrustBlock.setThickness(0.0008); + thrustBlock.setName("Engine Block"); + inner.addChild(thrustBlock); + inner.setMotorMount( true); + + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_A8_18mm(); + motorConfig.setEjectionDelay(0.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + FlightConfigurationId motorConfigId = rocket.getSelectedConfiguration().getFlightConfigurationID(); + inner.setMotorInstance( motorConfigId, motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_B4_18mm(); + motorConfig.setEjectionDelay(3.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + FlightConfigurationId motorConfigId = new FlightConfigurationId(); + inner.setMotorInstance( motorConfigId, motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(3.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + FlightConfigurationId motorConfigId = new FlightConfigurationId(); + inner.setMotorInstance( motorConfigId, motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(5.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + FlightConfigurationId motorConfigId = new FlightConfigurationId(); + inner.setMotorInstance( motorConfigId, motorConfig); + } + { + MotorConfiguration motorConfig = TestRockets.generateMotorInstance_C6_18mm(); + motorConfig.setEjectionDelay(7.0); + motorConfig.setID( new MotorInstanceId( inner.getName(), 1) ); + FlightConfigurationId motorConfigId = new FlightConfigurationId(); + inner.setMotorInstance( motorConfigId, motorConfig); + } + } + + // parachute + Parachute chute = new Parachute(); + chute.setRelativePosition(Position.TOP); + chute.setName("Parachute"); + chute.setAxialOffset(0.028); + chute.setOverrideMass(0.002); + chute.setMassOverridden(true); + bodytube.addChild(chute); + + // bulkhead x2 + CenteringRing centerings = new CenteringRing(); + centerings.setName("Centering Rings"); + centerings.setRelativePosition(Position.TOP); + centerings.setAxialOffset(0.14); + centerings.setLength(0.006); + centerings.setInstanceCount(2); + centerings.setInstanceSeparation(0.035); + bodytube.addChild(centerings); + } + + Material material = Application.getPreferences().getDefaultComponentMaterial(null, Material.Type.BULK); + nosecone.setMaterial(material); + bodytube.setMaterial(material); + finset.setMaterial(material); + + { + AxialStage boosterStage = new AxialStage(); + boosterStage.setName("Booster"); + + BodyTube boosterTube = new BodyTube(0.06, bodytubeRadius, bodyTubeThickness); + boosterStage.addChild(boosterTube); + + TubeCoupler coupler = new TubeCoupler(); + coupler.setName("Interstage"); + coupler.setOuterRadiusAutomatic(true); + coupler.setThickness( bodyTubeThickness); + coupler.setLength(0.03); + coupler.setRelativePosition(Position.TOP); + coupler.setPositionValue(-1.5); + boosterTube.addChild(coupler); + + int finCount = 3; + double finRootChord = .05; + double finTipChord = .03; + double finSweep = 0.02; + double finHeight = 0.05; + finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); + finset.setThickness( 0.0032); + finset.setRelativePosition(Position.BOTTOM); + finset.setPositionValue(1); + finset.setName("Booster Fins"); + boosterTube.addChild(finset); + + // Motor mount + InnerTube boosterMMT = new InnerTube(); + boosterMMT.setName("Booster MMT"); + boosterMMT.setPositionValue(0.005); + boosterMMT.setRelativePosition(Position.BOTTOM); + boosterMMT.setOuterRadius(0.019 / 2); + boosterMMT.setInnerRadius(0.018 / 2); + boosterMMT.setLength(0.075); + boosterTube.addChild(boosterMMT); + + rocket.addChild(boosterStage); + + boosterMMT.setMotorMount(true); + { + FlightConfigurationId mcid = rocket.getSelectedConfiguration().getFlightConfigurationID(); + MotorConfiguration motorConfig= generateMotorInstance_D21_18mm(); + motorConfig.setID( new MotorInstanceId( boosterMMT.getName(), 1) ); + boosterMMT.setMotorInstance( mcid, motorConfig); + } + + } + rocket.getSelectedConfiguration().setAllStages(); + rocket.enableEvents(); + return rocket; + } + + public static Rocket makeSmallFlyable() { double noseconeLength = 0.10, noseconeRadius = 0.01; double bodytubeLength = 0.20, bodytubeRadius = 0.01, bodytubeThickness = 0.001; @@ -553,6 +829,8 @@ public class TestRockets { } + + public static Rocket makeIsoHaisu() { Rocket rocket; AxialStage stage; @@ -1036,9 +1314,8 @@ public class TestRockets { OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket); // create simulation data - SimulationOptions options = new SimulationOptions(rocket); - options.setFlightConfigurationId(fcid); Simulation simulation1 = new Simulation(rocket); + simulation1.setFlightConfigurationId(fcid); rocketDoc.addSimulation(simulation1); Simulation simulation2 = new Simulation(rocket); @@ -1358,16 +1635,6 @@ public class TestRockets { return rocketDoc; } - - - - private static ThrustCurveMotor getTestMotor() { - return new ThrustCurveMotor( - Manufacturer.getManufacturer("A"), - "F12X", "Desc", Motor.Type.UNKNOWN, new double[] {}, - 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 }, - new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL }, "digestA"); - } - + } diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index 5e7fa2d74..6caeb0d97 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -11,9 +11,11 @@ import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.ThrustCurveMotor; +import net.sf.openrocket.optimization.rocketoptimization.TestRocketOptimizationFunction; import net.sf.openrocket.rocketcomponent.RocketComponent.Position; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; +import net.sf.openrocket.util.TestRockets; import net.sf.openrocket.util.BaseTestCase.BaseTestCase; public class FlightConfigurationTest extends BaseTestCase { @@ -25,7 +27,7 @@ public class FlightConfigurationTest extends BaseTestCase { */ @Test public void testEmptyRocket() { - Rocket r1 = makeEmptyRocket(); + Rocket r1 = TestRockets.makeSmallFlyable(); FlightConfiguration config = r1.getSelectedConfiguration(); FlightConfiguration configClone = config.clone(); @@ -38,9 +40,12 @@ public class FlightConfigurationTest extends BaseTestCase { */ @Test public void testCloneBasic() { - Rocket rkt1 = makeTwoStageMotorRocket(); + Rocket rkt1 = TestRockets.makeBeta(); FlightConfiguration config1 = rkt1.getSelectedConfiguration(); +// final String treedump = rkt1.toDebugTree(); +// System.err.println("treedump: \n" + treedump); + // preconditions config1.setAllStages(); int expectedStageCount = 2; @@ -49,13 +54,13 @@ public class FlightConfigurationTest extends BaseTestCase { int expectedMotorCount = 2; int actualMotorCount = config1.getActiveMotors().size(); assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount)); - double expectedLength = 176.8698848; + double expectedLength = 0.33; double actualLength = config1.getLength(); assertEquals("source config length doesn't match: ", expectedLength, actualLength, EPSILON); - double expectedReferenceLength = 2.5; + double expectedReferenceLength = 0.024; double actualReferenceLength = config1.getReferenceLength(); assertEquals("source config reference length doesn't match: ", expectedReferenceLength, actualReferenceLength, EPSILON); - double expectedReferenceArea = 4.9087385212; + double expectedReferenceArea = Math.pow(expectedReferenceLength/2,2)*Math.PI; double actualReferenceArea = config1.getReferenceArea(); assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON); @@ -84,7 +89,7 @@ public class FlightConfigurationTest extends BaseTestCase { */ @Test public void testCloneIndependence() { - Rocket rkt1 = makeTwoStageMotorRocket(); + Rocket rkt1 = TestRockets.makeBeta(); FlightConfiguration config1 = rkt1.getSelectedConfiguration(); int expectedStageCount; int actualStageCount; @@ -121,18 +126,13 @@ public class FlightConfigurationTest extends BaseTestCase { */ @Test public void testSingleStageRocket() { - - /* Setup */ - Rocket r1 = makeSingleStageTestRocket(); + Rocket r1 = TestRockets.makeEstesAlphaIII(); FlightConfiguration config = r1.getSelectedConfiguration(); // test explicitly setting only first stage active config.clearAllStages(); config.setOnlyStage(0); - //config.dumpConfig(); - //System.err.println("treedump: \n" + treedump); - // test that getStageCount() returns correct value int expectedStageCount = 1; int stageCount = config.getStageCount(); @@ -150,6 +150,35 @@ public class FlightConfigurationTest extends BaseTestCase { } + /** + * Single stage rocket specific configuration tests + */ + @Test + public void testConfigurationSwitching() { + /* Setup */ + Rocket rkt = TestRockets.makeEstesAlphaIII(); + //FlightConfiguration config = rkt.getSelectedConfiguration(); + + InnerTube smmt = (InnerTube)rkt.getChild(0).getChild(1).getChild(2); + System.err.println( smmt.toMotorDebug()); + + final String configDump= rkt.toDebugConfigs(); + System.err.println("configs:\n" +configDump); +// final String treedump = rkt.toDebugTree(); +// System.err.println("treedump: \n" + treedump); + + + //int actualMotorCount = smmt.getM + //assertThat("number of motor configurations doesn't actually match.", actualMotorCount, equalTo(expectedMotorCount)); + + // 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)); + + + } + /** * Multi stage rocket specific configuration tests */ @@ -157,8 +186,8 @@ public class FlightConfigurationTest extends BaseTestCase { public void testMultiStageRocket() { /* Setup */ - Rocket r1 = makeTwoStageTestRocket(); - FlightConfiguration config = r1.getSelectedConfiguration(); + Rocket rkt = TestRockets.makeBeta(); + FlightConfiguration config = rkt.getSelectedConfiguration(); int expectedStageCount; int stageCount; @@ -214,7 +243,7 @@ public class FlightConfigurationTest extends BaseTestCase { public void testMotorClusters() { /* Setup */ - Rocket rkt = makeTwoStageMotorRocket(); + Rocket rkt = TestRockets.makeBeta(); FlightConfiguration config = rkt.getSelectedConfiguration(); @@ -239,256 +268,5 @@ public class FlightConfigurationTest extends BaseTestCase { assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount)); } - //////////////////// Test Rocket Creation Methods ///////////////////////// - - public static Rocket makeEmptyRocket() { - Rocket rocket = new Rocket(); - rocket.enableEvents(); - return rocket; - } - - public static Rocket makeSingleStageTestRocket() { - - // TODO: get units correct, these units are prob wrong, are lengths are CM, mass are grams - - Rocket rocket; - AxialStage stage; - NoseCone nosecone; - BodyTube tube1; - TrapezoidFinSet finset; - - // body tube constants - final double R = 2.5 / 2; // cm - final double BT_T = 0.1; - - // nose cone constants - final double NC_T = 0.2; - final double R2 = 2.3 / 2; - - rocket = new Rocket(); - stage = new AxialStage(); - stage.setName("Stage1"); - - nosecone = new NoseCone(Transition.Shape.OGIVE, 10.0, R); - nosecone.setThickness(NC_T); - nosecone.setAftShoulderLength(2.0); - nosecone.setAftShoulderRadius(R2); - nosecone.setAftShoulderThickness(NC_T); - nosecone.setAftShoulderCapped(true); - nosecone.setFilled(false); - stage.addChild(nosecone); - - tube1 = new BodyTube(30, R, BT_T); - stage.addChild(tube1); - - LaunchLug lug = new LaunchLug(); - lug.setLength(3.5); - tube1.addChild(lug); - - /* - TubeCoupler coupler = new TubeCoupler(); - coupler.setOuterRadiusAutomatic(true); - coupler.setThickness(0.005); - coupler.setLength(0.28); - coupler.setMassOverridden(true); - coupler.setOverrideMass(0.360); - coupler.setRelativePosition(Position.BOTTOM); - coupler.setPositionValue(-0.14); - tube1.addChild(coupler); - */ - - // Parachute - MassComponent mass = new MassComponent(4.5, R2, 8.0); - mass.setRelativePosition(Position.TOP); - mass.setPositionValue(3.0); - tube1.addChild(mass); - - // Cord - mass = new MassComponent(40.0, R2, 72); - mass.setRelativePosition(Position.TOP); - mass.setPositionValue(2.0); - tube1.addChild(mass); - - // Motor mount - InnerTube inner = new InnerTube(); - inner.setName("Sustainer MMT"); - inner.setPositionValue(0.5); - inner.setRelativePosition(Position.BOTTOM); - inner.setOuterRadius(1.9 / 2); - inner.setInnerRadius(1.8 / 2); - inner.setLength(7.5); - tube1.addChild(inner); - - // Motor - - // Centering rings for motor mount - CenteringRing center = new CenteringRing(); - center.setInnerRadiusAutomatic(true); - center.setOuterRadiusAutomatic(true); - center.setLength(0.005); - center.setMassOverridden(true); - center.setOverrideMass(0.038); - center.setRelativePosition(Position.BOTTOM); - center.setPositionValue(0.25); - tube1.addChild(center); - - center = new CenteringRing(); - center.setInnerRadiusAutomatic(true); - center.setOuterRadiusAutomatic(true); - center.setLength(0.005); - center.setMassOverridden(true); - center.setOverrideMass(0.038); - center.setRelativePosition(Position.BOTTOM); - center.setPositionValue(-6.0); - tube1.addChild(center); - - - center = new CenteringRing(); - center.setInnerRadiusAutomatic(true); - center.setOuterRadiusAutomatic(true); - center.setLength(0.005); - center.setMassOverridden(true); - center.setOverrideMass(0.038); - center.setRelativePosition(Position.TOP); - center.setPositionValue(0.83); - tube1.addChild(center); - - // Fins - finset = new TrapezoidFinSet(); - finset.setFinCount(3); - finset.setRootChord(5.0); - finset.setTipChord(5.0); - finset.setHeight(3.0); - finset.setThickness(0.005); - finset.setSweepAngle(40.0); - finset.setRelativePosition(Position.BOTTOM); - finset.setPositionValue(-0.5); - finset.setBaseRotation(Math.PI / 2); - tube1.addChild(finset); - - // Stage construction - rocket.addChild(stage); - rocket.setPerfectFinish(false); - rocket.enableEvents(); - - final int expectedStageCount = 1; - assertThat(" rocket has incorrect stage count: ", rocket.getStageCount(), equalTo(expectedStageCount)); - - int expectedConfigurationCount = 0; - 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.getFlightConfigurationCount(), equalTo(expectedConfigurationCount)); - - rocket.update(); - rocket.enableEvents(); - return rocket; - } - - - public static Rocket makeTwoStageTestRocket() { - - // TODO: get units correct, these units are prob wrong, are lengths are CM, mass are grams - - final double R = 2.5 / 2; // cm - final double BT_T = 0.1; - - Rocket rocket = makeSingleStageTestRocket(); - - AxialStage stage = new AxialStage(); - stage.setName("Booster"); - - BodyTube boosterTube = new BodyTube(9.0, R, BT_T); - stage.addChild(boosterTube); - - TubeCoupler coupler = new TubeCoupler(); - coupler.setOuterRadiusAutomatic(true); - coupler.setThickness(BT_T); - coupler.setLength(3.0); - coupler.setRelativePosition(Position.TOP); - coupler.setPositionValue(-1.5); - boosterTube.addChild(coupler); - - TrapezoidFinSet finset = new TrapezoidFinSet(); - finset.setFinCount(3); - finset.setRootChord(5.0); - finset.setTipChord(5.0); - finset.setHeight(3.0); - finset.setThickness(0.005); - finset.setSweepAngle(40.0); - finset.setRelativePosition(Position.BOTTOM); - finset.setPositionValue(-0.25); - finset.setBaseRotation(Math.PI / 2); - boosterTube.addChild(finset); - - // Motor mount - InnerTube inner = new InnerTube(); - inner.setName("Booster MMT"); - inner.setPositionValue(0.5); - inner.setRelativePosition(Position.BOTTOM); - inner.setOuterRadius(1.9 / 2); - inner.setInnerRadius(1.8 / 2); - inner.setLength(7.5); - boosterTube.addChild(inner); - - rocket.addChild(stage); - - // already set in "makeSingleStageTestRocket()" above... -// rocket.enableEvents(); -// 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.getSelectedConfiguration().getId(); - - { - // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, - // Motor.Type type, double[] delays, double diameter, double length, - // double[] time, double[] thrust, - // Coordinate[] cg, String digest); - ThrustCurveMotor sustainerMotor = new ThrustCurveMotor( - Manufacturer.getManufacturer("AeroTech"),"D10", "Desc", - Motor.Type.SINGLE, new double[] {3,5,7},0.018, 0.07, - new double[] { 0, 1, 2 }, new double[] { 0, 25, 0 }, - new Coordinate[] { - new Coordinate(.035, 0, 0, 0.026),new Coordinate(.035, 0, 0, .021),new Coordinate(.035, 0, 0, 0.016)}, - "digest D10 test"); - - InnerTube sustainerMount = (InnerTube) rocket.getChild(0).getChild(1).getChild(3); - sustainerMount.setMotorMount(true); - sustainerMount.setMotorInstance(fcid, new MotorConfiguration(sustainerMotor)); - } - - { - // public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, - // Motor.Type type, double[] delays, double diameter, double length, - // double[] time, double[] thrust, - // Coordinate[] cg, String digest); - ThrustCurveMotor boosterMotor = 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"); - InnerTube boosterMount = (InnerTube) rocket.getChild(1).getChild(0).getChild(2); - boosterMount.setMotorMount(true); - boosterMount.setMotorInstance(fcid, new MotorConfiguration(boosterMotor)); - boosterMount.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[1]); // double-mount - } - rocket.update(); - rocket.enableEvents(); - return rocket; - } } diff --git a/swing/resources/datafiles/examples/Booster Stage Example.ork b/swing/resources/datafiles/examples/Booster Stage Example.ork deleted file mode 100644 index e0369348b85b86723a8b85b0fdf01996dd279d90..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2426 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 diff --git a/swing/resources/datafiles/examples/Parallel_Staging_Example.ork b/swing/resources/datafiles/examples/Parallel_Staging_Example.ork new file mode 100644 index 0000000000000000000000000000000000000000..6aa38087be1bdc63c0bcecee81cb92bb9e141007 GIT binary patch literal 2476 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 literal 0 HcmV?d00001 diff --git a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java index 2bf821a23..e8c42a5cd 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -1167,7 +1167,7 @@ public class GeneralOptimizationDialog extends JDialog { } // Update the active configuration - FlightConfigurationId fcid = getSelectedSimulation().getOptions().getId(); + FlightConfigurationId fcid = getSelectedSimulation().getId(); getSelectedSimulation().getRocket().setDefaultConfiguration(fcid); updating = false; diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index a756c2651..87bad26db 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -612,7 +612,7 @@ public class SimulationPanel extends JPanel { if((s==Simulation.Status.NOT_SIMULATED) || (s==Simulation.Status.OUTDATED)){ outdated++; - } + } } if(outdated>0){ Simulation[] sims = new Simulation[outdated]; @@ -668,7 +668,6 @@ public class SimulationPanel extends JPanel { } private class JLabelRenderer extends DefaultTableCellRenderer { - private static final long serialVersionUID = 5487619660216145843L; @Override public Component getTableCellRendererComponent(JTable table, diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java index 32ef7c863..71541494a 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java @@ -3,7 +3,6 @@ package net.sf.openrocket.gui.main.flightconfigpanel; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Vector; import javax.swing.table.AbstractTableModel; @@ -25,7 +24,6 @@ public class FlightConfigurableTableModel protected final Rocket rocket; protected final Class clazz; private final List components = new ArrayList(); - private List ids = new Vector(); public FlightConfigurableTableModel(Class clazz, Rocket rocket) { super(); @@ -52,6 +50,7 @@ public class FlightConfigurableTableModel return true; } + @SuppressWarnings("unchecked") protected void initialize() { components.clear(); Iterator it = rocket.iterator(); diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index 223dd302c..1b1dc79c6 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -513,7 +513,7 @@ public class DesignReport { try { for (int i = 0; i < simulations.size(); i++) { Simulation simulation = simulations.get(i); - if (Utils.equals(simulation.getOptions().getId(), motorId)) { + if (Utils.equals(simulation.getId(), motorId)) { simulation = simulation.copy(); simulation.simulate(); flight = simulation.getSimulatedData(); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 7073d4243..124e6eca8 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -687,8 +687,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change Rocket duplicate = (Rocket) document.getRocket().copy(); Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); - simulation.getOptions().setFlightConfigurationId( - document.getDefaultConfiguration().getFlightConfigurationID()); + simulation.setFlightConfigurationId( document.getDefaultConfiguration().getFlightConfigurationID()); backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation); backgroundSimulationExecutor.execute(backgroundSimulationWorker); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index bb487d747..18dad4a30 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -25,7 +25,6 @@ import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; -import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.extension.SimulationExtension; import net.sf.openrocket.startup.Application; @@ -33,9 +32,8 @@ import net.sf.openrocket.startup.Application; public class SimulationEditDialog extends JDialog { private static final long serialVersionUID = -4468157685542912715L; private final Window parentWindow; - private final Simulation[] simulation; + private final Simulation[] simulationList; private final OpenRocketDocument document; - private final SimulationOptions conditions; private static final Translator trans = Application.getTranslator(); JPanel cards; @@ -47,8 +45,7 @@ public class SimulationEditDialog extends JDialog { super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL); this.document = document; this.parentWindow = parent; - this.simulation = sims; - this.conditions = simulation[0].getOptions(); + this.simulationList = sims; this.cards = new JPanel(new CardLayout()); this.add(cards); @@ -64,11 +61,11 @@ public class SimulationEditDialog extends JDialog { } private boolean isSingleEdit() { - return simulation.length == 1; + return simulationList.length == 1; } private boolean allowsPlotMode() { - return simulation.length == 1 && simulation[0].hasSimulationData(); + return simulationList.length == 1 && simulationList[0].hasSimulationData(); } public void setEditMode() { @@ -87,12 +84,12 @@ public class SimulationEditDialog extends JDialog { } private void copyChangesToAllSims() { - if (simulation.length > 1) { - for (int i = 1; i < simulation.length; i++) { - simulation[i].getOptions().copyConditionsFrom(simulation[0].getOptions()); - simulation[i].getSimulationExtensions().clear(); - for (SimulationExtension c : simulation[0].getSimulationExtensions()) { - simulation[i].getSimulationExtensions().add(c.clone()); + if (simulationList.length > 1) { + for (int i = 1; i < simulationList.length; i++) { + simulationList[i].getOptions().copyConditionsFrom(simulationList[0].getOptions()); + simulationList[i].getSimulationExtensions().clear(); + for (SimulationExtension c : simulationList[0].getSimulationExtensions()) { + simulationList[i].getSimulationExtensions().add(c.clone()); } } } @@ -113,7 +110,7 @@ public class SimulationEditDialog extends JDialog { //// Simulation name: panel.add(new JLabel(trans.get("simedtdlg.lbl.Simname") + " "), "growx 0, gapright para"); - final JTextField field = new JTextField(simulation[0].getName()); + final JTextField field = new JTextField(simulationList[0].getName()); field.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { @@ -135,7 +132,7 @@ public class SimulationEditDialog extends JDialog { if (name == null || name.equals("")) return; //System.out.println("Setting name:" + name); - simulation[0].setName(name); + simulationList[0].setName(name); } }); @@ -158,7 +155,8 @@ public class SimulationEditDialog extends JDialog { public void actionPerformed(ActionEvent e) { FlightConfiguration config = (FlightConfiguration)configComboBox.getSelectedItem(); FlightConfigurationId id = config.getId(); - conditions.setFlightConfigurationId( id ); + + simulationList[0].setFlightConfigurationId( id ); } }); panel.add(configComboBox, "span"); @@ -170,9 +168,9 @@ public class SimulationEditDialog extends JDialog { JTabbedPane tabbedPane = new JTabbedPane(); //// Launch conditions - tabbedPane.addTab(trans.get("simedtdlg.tab.Launchcond"), new SimulationConditionsPanel(simulation[0])); + tabbedPane.addTab(trans.get("simedtdlg.tab.Launchcond"), new SimulationConditionsPanel(simulationList[0])); //// Simulation options - tabbedPane.addTab(trans.get("simedtdlg.tab.Simopt"), new SimulationOptionsPanel(document, simulation[0])); + tabbedPane.addTab(trans.get("simedtdlg.tab.Simopt"), new SimulationOptionsPanel(document, simulationList[0])); tabbedPane.setSelectedIndex(0); @@ -205,7 +203,7 @@ public class SimulationEditDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { copyChangesToAllSims(); - SimulationRunDialog.runSimulations(parentWindow, SimulationEditDialog.this.document, simulation); + SimulationRunDialog.runSimulations(parentWindow, SimulationEditDialog.this.document, simulationList); refreshView(); if (allowsPlotMode()) { setPlotMode(); @@ -236,17 +234,17 @@ public class SimulationEditDialog extends JDialog { //// Simulation name: plotExportPanel.add(new JLabel(trans.get("simedtdlg.lbl.Simname") + " "), "span, split 2, shrink"); - final JTextField field = new JTextField(simulation[0].getName()); + final JTextField field = new JTextField(simulationList[0].getName()); field.setEditable(false); plotExportPanel.add(field, "shrinky, growx, wrap"); final JTabbedPane tabbedPane = new JTabbedPane(); //// Plot data - final SimulationPlotPanel plotTab = new SimulationPlotPanel(simulation[0]); + final SimulationPlotPanel plotTab = new SimulationPlotPanel(simulationList[0]); tabbedPane.addTab(trans.get("simedtdlg.tab.Plotdata"), plotTab); //// Export data - final SimulationExportPanel exportTab = new SimulationExportPanel(simulation[0]); + final SimulationExportPanel exportTab = new SimulationExportPanel(simulationList[0]); tabbedPane.addTab(trans.get("simedtdlg.tab.Exportdata"), exportTab); plotExportPanel.add(tabbedPane, "grow, wrap"); @@ -286,8 +284,8 @@ public class SimulationEditDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { // If the simulation is out of date, run the simulation. - if (simulation[0].getStatus() != Simulation.Status.UPTODATE) { - new SimulationRunDialog(SimulationEditDialog.this.parentWindow, document, simulation[0]).setVisible(true); + if (simulationList[0].getStatus() != Simulation.Status.UPTODATE) { + new SimulationRunDialog(SimulationEditDialog.this.parentWindow, document, simulationList[0]).setVisible(true); } if (tabbedPane.getSelectedIndex() == 0) {