- Implemented copying of custom expressions to other simulations in expression builder dialog. Note the small changes to various files are to allow simulations access to parent document.

- Switched to unicode char escapes
- Removed dynamic setting of flightdatatype priority
- Now hiding up down arrows in custom expression pane when unusable
- Localized custom expression operator discriptions.
This commit is contained in:
Richard Graham 2012-06-11 04:47:49 +00:00
parent 225d502896
commit 71b36bc481
13 changed files with 158 additions and 77 deletions

View File

@ -469,6 +469,8 @@ ExpressionBuilderDialog.InsertOperator = Insert Operator
ExpressionBuilderDialog.led.ttip.Name = Name must not have already been used
ExpressionBuilderDialog.led.ttip.Symbol = Symbol must not have already been used
ExpressionBuilderDialog.led.ttip.Expression = Expression must use only known symbols and operators
ExpressionBuilderDialog.CopyToOtherSimulations = Copy to other simulations
ExpressionBuilderDialog.CopyToOtherSimulations.ttip = <html>Make a copy of this expression in other simulations in this document.<br>Will not overwrite or modify any existing expressions in other simulations.
! Custom expression variable selector
CustomVariableSelector.title = Variable Selector
@ -476,6 +478,30 @@ CustomVariableSelector.title = Variable Selector
! Custom operator selector
CustomOperatorSelector.title = Operator Selector
! Operators
Operator.plus = Addition
Operator.minus = Subtraction
Operator.star = Multiplication
Operator.div = Divison
Operator.mod = Modulo
Operator.pow = Exponentiation
Operator.abs = Absolute value
Operator.ceil = Ceiling (next integer value
Operator.floor = Floor (previous integer value
Operator.sqrt = Square root
Operator.cbrt = Cubic root
Operator.exp = Euler\'s number raised to the value (e^x)
Operator.ln = Natural logarithm
Operator.sin = Sine
Operator.cos = Cosine
Operator.tan = Tangent
Operator.asin = Arc sine
Operator.acos = Arc cosine
Operator.atan = Arc tangent
Operator.hsin = Hyerbolic sine
Operator.hcos = Hyperbolic cosine
Operator.htan = Hyperbolic tangent
! MotorPlot
MotorPlot.title.Motorplot = Motor plot
MotorPlot.but.Select = Select

View File

@ -61,6 +61,7 @@ public class Simulation implements ChangeSource, Cloneable {
private SafetyMutex mutex = SafetyMutex.newInstance();
private final Rocket rocket;
private final OpenRocketDocument document;
private String name = "";
@ -90,12 +91,16 @@ public class Simulation implements ChangeSource, Cloneable {
/**
* Create a new simulation for the rocket. The initial motor configuration is
* taken from the default rocket configuration.
* Create a new simulation for the rocket. Parent document should also be provided.
* The initial motor configuration is taken from the default rocket configuration.
*
* @param rocket the rocket associated with the simulation.
*/
public Simulation(Rocket rocket) {
public Simulation(OpenRocketDocument doc, Rocket rocket) {
// It may seem silly to pass in the document and rocket, since usually when called we
// use doc.getRocket, but I guess there is some reason; when cloning a simulation + rocket we don't need
// to make a duplicate of the undo data etc stored in the document. --Richard
this.document = doc;
this.rocket = rocket;
this.status = Status.NOT_SIMULATED;
@ -106,7 +111,7 @@ public class Simulation implements ChangeSource, Cloneable {
}
public Simulation(Rocket rocket, Status status, String name, SimulationOptions options,
public Simulation(OpenRocketDocument doc, Rocket rocket, Status status, String name, SimulationOptions options,
List<String> listeners, FlightData data) {
if (rocket == null)
@ -119,6 +124,7 @@ public class Simulation implements ChangeSource, Cloneable {
throw new IllegalArgumentException("options cannot be null");
this.rocket = rocket;
this.document = doc;
if (status == Status.UPTODATE) {
this.status = Status.LOADED;
@ -148,6 +154,13 @@ public class Simulation implements ChangeSource, Cloneable {
}
/*
* Return the parent document for this simulation
*/
public OpenRocketDocument getDocument(){
return document;
}
public void addCustomExpression(CustomExpression expression){
this.status = Simulation.Status.OUTDATED;
log.debug("Simulation must be run again to update custom expression.");
@ -427,7 +440,7 @@ public class Simulation implements ChangeSource, Cloneable {
public Simulation duplicateSimulation(Rocket newRocket) {
mutex.lock("duplicateSimulation");
try {
Simulation copy = new Simulation(newRocket);
Simulation copy = new Simulation(document, newRocket);
copy.name = this.name;
copy.options.copyFrom(this.options);

View File

@ -1299,7 +1299,7 @@ class SingleSimulationHandler extends AbstractElementHandler {
else
data = dataHandler.getFlightData();
Simulation simulation = new Simulation(doc.getRocket(), status, name,
Simulation simulation = new Simulation(doc, doc.getRocket(), status, name,
conditions, listeners, data);
// Note : arraylist implementation in simulation different from standard one
@ -1704,7 +1704,15 @@ class FlightDataBranchHandler extends AbstractElementHandler {
}
}
// Look in custom expressions
for (CustomExpression exp : simHandler.getCustomExpressions()){
if (exp.getName().equals(name) ){
return exp.getType();
}
}
// Look in custom expressions, meanwhile set priority based on order in file
/*
int totalExpressions = simHandler.getCustomExpressions().size();
for (int i=0; i<totalExpressions; i++){
CustomExpression exp = simHandler.getCustomExpressions().get(i);
@ -1714,6 +1722,7 @@ class FlightDataBranchHandler extends AbstractElementHandler {
return exp.getType();
}
}
*/
log.warn("Could not find the flight data type '"+name+"' used in the XML file. Substituted type with unknown symbol and units.");
return FlightDataType.getType(name, "Unknown", UnitGroup.UNITS_NONE);

View File

@ -69,16 +69,15 @@ public class CustomExpressionPanel extends JPanel {
private void updateExpressions(){
expressionSelectorPanel.removeAll();
for (CustomExpression expression : simulation.getCustomExpressions()){
SingleExpression se = new SingleExpression(expression);
int totalExpressions = simulation.getCustomExpressions().size();
for (int i=0; i<totalExpressions; i++){
SingleExpression se = new SingleExpression(simulation.getCustomExpressions().get(i), i != 0, i != totalExpressions-1);
expressionSelectorPanel.add(se, "wrap");
}
//TODO: High : Find out why repaint method not working properly here.
//expressionSelectorPanel.repaint();
expressionSelectorPanel.updateUI(); // Not the correct method to use but works
}
private void deleteExpression(CustomExpression expression){
@ -114,7 +113,7 @@ public class CustomExpressionPanel extends JPanel {
return l;
}
private SingleExpression(final CustomExpression expression) {
private SingleExpression(final CustomExpression expression, boolean showUp, boolean showDown) {
super(new MigLayout("ins 0"));
// name: aName symbol: a Unit: m/s
//super(new MigLayout("","[::100][:200:400][::100][:100:200][::100][:100:200]",""));
@ -145,6 +144,7 @@ public class CustomExpressionPanel extends JPanel {
JButton upButton = new JButton(Icons.UP);
upButton.setToolTipText(trans.get("customExpression.Units.but.ttip.MoveUp"));
upButton.setBorderPainted(false);
upButton.setVisible(showUp);
upButton.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -156,6 +156,7 @@ public class CustomExpressionPanel extends JPanel {
JButton downButton = new JButton(Icons.DOWN);
downButton.setToolTipText(trans.get("customExpression.Units.but.ttip.MoveDown"));
downButton.setBorderPainted(false);
downButton.setVisible(showDown);
downButton.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

View File

@ -10,10 +10,12 @@ import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
@ -172,13 +174,23 @@ public class ExpressionBuilderDialog extends JDialog {
}
});
//// Copy expression check box
final JCheckBox copyCheckBox = new JCheckBox(trans.get("ExpressionBuilderDialog.CopyToOtherSimulations"));
copyCheckBox.setHorizontalTextPosition(SwingConstants.LEFT);
copyCheckBox.setToolTipText(trans.get("ExpressionBuilderDialog.CopyToOtherSimulations.ttip"));
//// OK Button
okButton.setEnabled(false);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// add to this simulation
expression.addToSimulation();
if (copyCheckBox.isSelected()){
expression.copyToOtherSimulations();
}
// close window
ExpressionBuilderDialog.this.dispose();
}
});
@ -214,6 +226,7 @@ public class ExpressionBuilderDialog extends JDialog {
mainPanel.add(expressionCheck, "wrap, center");
mainPanel.add(insertOperatorButton, "span 2, right, split 2");
mainPanel.add(insertVariableButton, "right, wrap");
mainPanel.add(copyCheckBox, "span 2, right, wrap");
mainPanel.add(cancelButton, "span 2, right, width :50:100");
mainPanel.add(okButton, "right, width :50:100, wrap");

View File

@ -1000,14 +1000,14 @@ public class GeneralOptimizationDialog extends JDialog {
if (id == null) {
continue;
}
Simulation sim = new Simulation(rocket);
Simulation sim = new Simulation(documentCopy, rocket);
sim.getConfiguration().setMotorConfigurationID(id);
String name = createSimulationName(trans.get("basicSimulationName"), rocket.getMotorConfigurationNameOrDescription(id));
simulations.add(new Named<Simulation>(sim, name));
}
Simulation sim = new Simulation(rocket);
Simulation sim = new Simulation(documentCopy, rocket);
sim.getConfiguration().setMotorConfigurationID(null);
String name = createSimulationName(trans.get("noSimulationName"), rocket.getMotorConfigurationNameOrDescription(null));
simulations.add(new Named<Simulation>(sim, name));

View File

@ -82,7 +82,7 @@ public class SimulationPanel extends JPanel {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Simulation sim = new Simulation(document.getRocket());
Simulation sim = new Simulation(document, document.getRocket());
sim.setName(document.getNextSimulationName());
int n = document.getSimulationCount();

View File

@ -15,6 +15,7 @@ import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import net.sf.openrocket.arch.SystemInfo;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.material.Material;
@ -398,7 +399,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
}
public Simulation getBackgroundSimulation(Rocket rocket) {
Simulation s = new Simulation(rocket);
Simulation s = new Simulation(new OpenRocketDocument(rocket), rocket);
SimulationOptions cond = s.getOptions();
cond.setTimeStep(RK4SimulationStepper.RECOMMENDED_TIME_STEP * 2);

View File

@ -126,7 +126,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
Rocket rocket = document.getRocket();
// Simulation is used to calculate default min/max values
Simulation simulation = new Simulation(rocket);
Simulation simulation = new Simulation(document, rocket);
simulation.getConfiguration().setMotorConfigurationID(null);
for (RocketComponent c : rocket) {

View File

@ -4,6 +4,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.FixedUnitGroup;
@ -21,6 +22,7 @@ import de.congrace.exp4j.ExpressionBuilder;
public class CustomExpression implements Cloneable{
private static final LogHelper log = Application.getLogger();
private static final Translator trans = Application.getTranslator();
private String name, symbol, unit, expression;
private ExpressionBuilder builder;
@ -28,31 +30,30 @@ public class CustomExpression implements Cloneable{
// A map of available operator strings (keys) and description of function (value)
public static final SortedMap<String, String> AVAILABLE_OPERATORS = new TreeMap<String, String>() {{
put("+" , "Addition");
put("-" , "Subtraction");
put("*" , "Multiplication");
put("/" , "Divison");
put("%" , "Modulo");
put("^" , "Exponentiation");
put("abs()" , "Absolute value");
put("ceil()" , "Ceiling (next integer value");
put("floor()" , "Floor (previous integer value");
put("sqrt()" , "Square root");
put("cbrt()" , "Cubic root");
put("exp()" , "Euler\'s number raised to the value (e^x)");
put("log()" , "Natural logarithm");
put("sin()" , "Sine");
put("cos()" , "Cosine");
put("tan()" , "Tangent");
put("asin()" , "Arc sine");
put("acos()" , "Arc cosine");
put("atan()" , "Arc tangent");
put("sinh()" , "Hyerbolic sine");
put("cosh()" , "Hyperbolic cosine");
put("tanh()" , "Hyperbolic tangent");
put("+" , trans.get("Operator.plus"));
put("-" , trans.get("Operator.minus"));
put("*" , trans.get("Operator.star"));
put("/" , trans.get("Operator.div"));
put("%" , trans.get("Operator.mod"));
put("^" , trans.get("Operator.pow"));
put("abs()" , trans.get("Operator.abs"));
put("ceil()" , trans.get("Operator.ceil"));
put("floor()" , trans.get("Operator.floor"));
put("sqrt()" , trans.get("Operator.sqrt"));
put("cbrt()" , trans.get("Operator.cbrt"));
put("exp()" , trans.get("Operator.exp"));
put("log()" , trans.get("Operator.ln"));
put("sin()" , trans.get("Operator.sin"));
put("cos()" , trans.get("Operator.cos"));
put("tan()" , trans.get("Operator.tan"));
put("asin()" , trans.get("Operator.asin"));
put("acos()" , trans.get("Operator.acos"));
put("atan()" , trans.get("Operator.atan"));
put("sinh()" , trans.get("Operator.hsin"));
put("cosh()" , trans.get("Operator.hcos"));
put("tanh()" , trans.get("Operator.htan"));
}};
public CustomExpression(){
setName("");
setSymbol("");
@ -94,7 +95,6 @@ public class CustomExpression implements Cloneable{
return new FlightDataBranch();
}
else {
System.out.println("Using existing branch");
return sim.getSimulatedData().getBranch(0);
}
}
@ -179,7 +179,7 @@ public class CustomExpression implements Cloneable{
ArrayList<String> names = getAllNames().clone();
if (names.contains(name.trim())){
int index = names.indexOf(name.trim());
log.user("Symbol "+symbol+" already exists, found "+names.get(index));
log.user("Name "+name+" already exists, found "+names.get(index));
return false;
}
@ -271,21 +271,22 @@ public class CustomExpression implements Cloneable{
FlightDataType type = FlightDataType.getType(name, symbol, ug);
// If in a simulation, figure out priority from order in array so that customs expressions are always at the top
if (sim != null && sim.getCustomExpressions().contains(this)){
int totalExpressions = sim.getCustomExpressions().size();
int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this));
type.setPriority(p);
}
//if (sim != null && sim.getCustomExpressions().contains(this)){
// int totalExpressions = sim.getCustomExpressions().size();
// int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this));
// type.setPriority(p);
//}
return type;
}
/*
* Add this expression to the simulation if not already added
* Add this expression to the simulation if valid and not already added
*/
public void addToSimulation(){
if (! sim.getCustomExpressions().contains(this))
sim.addCustomExpression( this );
// Abort if exact expression already in
if ( !sim.getCustomExpressions().contains(this) && this.checkAll() )
sim.addCustomExpression( this );
}
/*
@ -300,6 +301,18 @@ public class CustomExpression implements Cloneable{
}
}
/*
* Add a copy to other simulations in this document if possible
* Will not overwrite existing expressions
*/
public void copyToOtherSimulations(){
for (Simulation s : this.getSimulation().getDocument().getSimulations()){
CustomExpression newExpression = (CustomExpression) this.clone();
newExpression.setSimulation(s);
newExpression.addToSimulation();
}
}
@Override
public String toString(){
return "Custom expression : "+this.name.toString()+ " " + this.expression.toString();
@ -307,7 +320,8 @@ public class CustomExpression implements Cloneable{
@Override
/*
* Clone method makes a deep copy of everything except the simulation
* Clone method makes a deep copy of everything except the simulation.
* If you want to apply this to another simulation, set simulation manually after cloning.
* @see java.lang.Object#clone()
*/
public Object clone() {

View File

@ -59,25 +59,25 @@ public class FlightDataType implements Comparable<FlightDataType> {
//// Lateral distance
public static final FlightDataType TYPE_POSITION_XY = newType(trans.get("FlightDataType.TYPE_POSITION_XY"), "Pl", UnitGroup.UNITS_DISTANCE, 32);
//// Lateral direction
public static final FlightDataType TYPE_POSITION_DIRECTION = newType(trans.get("FlightDataType.TYPE_POSITION_DIRECTION"), "θl", UnitGroup.UNITS_ANGLE, 33);
public static final FlightDataType TYPE_POSITION_DIRECTION = newType(trans.get("FlightDataType.TYPE_POSITION_DIRECTION"), "\u03b8l", UnitGroup.UNITS_ANGLE, 33);
//// Lateral velocity
public static final FlightDataType TYPE_VELOCITY_XY = newType(trans.get("FlightDataType.TYPE_VELOCITY_XY"), "Vl", UnitGroup.UNITS_VELOCITY, 34);
//// Lateral acceleration
public static final FlightDataType TYPE_ACCELERATION_XY = newType(trans.get("FlightDataType.TYPE_ACCELERATION_XY"), "Al", UnitGroup.UNITS_ACCELERATION, 35);
//// Latitude
public static final FlightDataType TYPE_LATITUDE = newType(trans.get("FlightDataType.TYPE_LATITUDE"), "φ", UnitGroup.UNITS_ANGLE, 36);
public static final FlightDataType TYPE_LATITUDE = newType(trans.get("FlightDataType.TYPE_LATITUDE"), "\u03c6", UnitGroup.UNITS_ANGLE, 36);
//// Longitude
public static final FlightDataType TYPE_LONGITUDE = newType(trans.get("FlightDataType.TYPE_LONGITUDE"), "λ", UnitGroup.UNITS_ANGLE, 37);
public static final FlightDataType TYPE_LONGITUDE = newType(trans.get("FlightDataType.TYPE_LONGITUDE"), "\u03bb", UnitGroup.UNITS_ANGLE, 37);
//// Angular motion
//// Angle of attack
public static final FlightDataType TYPE_AOA = newType(trans.get("FlightDataType.TYPE_AOA"), "α", UnitGroup.UNITS_ANGLE, 40);
public static final FlightDataType TYPE_AOA = newType(trans.get("FlightDataType.TYPE_AOA"), "\u03b1", UnitGroup.UNITS_ANGLE, 40);
//// Roll rate
public static final FlightDataType TYPE_ROLL_RATE = newType(trans.get("FlightDataType.TYPE_ROLL_RATE"), "dΦ", UnitGroup.UNITS_ROLL, 41);
public static final FlightDataType TYPE_ROLL_RATE = newType(trans.get("FlightDataType.TYPE_ROLL_RATE"), "d\u03a6", UnitGroup.UNITS_ROLL, 41);
//// Pitch rate
public static final FlightDataType TYPE_PITCH_RATE = newType(trans.get("FlightDataType.TYPE_PITCH_RATE"), "dθ", UnitGroup.UNITS_ROLL, 42);
public static final FlightDataType TYPE_PITCH_RATE = newType(trans.get("FlightDataType.TYPE_PITCH_RATE"), "d\u03b8", UnitGroup.UNITS_ROLL, 42);
//// Yaw rate
public static final FlightDataType TYPE_YAW_RATE = newType(trans.get("FlightDataType.TYPE_YAW_RATE"), "dΨ", UnitGroup.UNITS_ROLL, 43);
public static final FlightDataType TYPE_YAW_RATE = newType(trans.get("FlightDataType.TYPE_YAW_RATE"), "d\u03a8", UnitGroup.UNITS_ROLL, 43);
//// Stability information
@ -126,22 +126,22 @@ public class FlightDataType implements Comparable<FlightDataType> {
//// Normal force coefficient
public static final FlightDataType TYPE_NORMAL_FORCE_COEFF = newType(trans.get("FlightDataType.TYPE_NORMAL_FORCE_COEFF"), "Cn", UnitGroup.UNITS_COEFFICIENT, 90);
//// Pitch moment coefficient
public static final FlightDataType TYPE_PITCH_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_PITCH_MOMENT_COEFF"), "Cθ", UnitGroup.UNITS_COEFFICIENT, 91);
public static final FlightDataType TYPE_PITCH_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_PITCH_MOMENT_COEFF"), "C\u03b8", UnitGroup.UNITS_COEFFICIENT, 91);
//// Yaw moment coefficient
public static final FlightDataType TYPE_YAW_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_YAW_MOMENT_COEFF"), "CτΨ", UnitGroup.UNITS_COEFFICIENT, 92);
public static final FlightDataType TYPE_YAW_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_YAW_MOMENT_COEFF"), "C\u03c4\u03a8", UnitGroup.UNITS_COEFFICIENT, 92);
//// Side force coefficient
public static final FlightDataType TYPE_SIDE_FORCE_COEFF = newType(trans.get("FlightDataType.TYPE_SIDE_FORCE_COEFF"), "Cτs", UnitGroup.UNITS_COEFFICIENT, 93);
public static final FlightDataType TYPE_SIDE_FORCE_COEFF = newType(trans.get("FlightDataType.TYPE_SIDE_FORCE_COEFF"), "C\u03c4s", UnitGroup.UNITS_COEFFICIENT, 93);
//// Roll moment coefficient
public static final FlightDataType TYPE_ROLL_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_MOMENT_COEFF"), "CτΦ", UnitGroup.UNITS_COEFFICIENT, 94);
public static final FlightDataType TYPE_ROLL_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_MOMENT_COEFF"), "C\u03c4\u03a6", UnitGroup.UNITS_COEFFICIENT, 94);
//// Roll forcing coefficient
public static final FlightDataType TYPE_ROLL_FORCING_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_FORCING_COEFF"), "CfΦ", UnitGroup.UNITS_COEFFICIENT, 95);
public static final FlightDataType TYPE_ROLL_FORCING_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_FORCING_COEFF"), "Cf\u03a6", UnitGroup.UNITS_COEFFICIENT, 95);
//// Roll damping coefficient
public static final FlightDataType TYPE_ROLL_DAMPING_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_DAMPING_COEFF"), "CζΦ", UnitGroup.UNITS_COEFFICIENT, 96);
public static final FlightDataType TYPE_ROLL_DAMPING_COEFF = newType(trans.get("FlightDataType.TYPE_ROLL_DAMPING_COEFF"), "C\u03b6\u03a6", UnitGroup.UNITS_COEFFICIENT, 96);
//// Pitch damping coefficient
public static final FlightDataType TYPE_PITCH_DAMPING_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_PITCH_DAMPING_MOMENT_COEFF"), "Cζθ", UnitGroup.UNITS_COEFFICIENT, 97);
public static final FlightDataType TYPE_PITCH_DAMPING_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_PITCH_DAMPING_MOMENT_COEFF"), "C\u03b6\u03b8", UnitGroup.UNITS_COEFFICIENT, 97);
//// Yaw damping coefficient
public static final FlightDataType TYPE_YAW_DAMPING_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_YAW_DAMPING_MOMENT_COEFF"), "CζΨ", UnitGroup.UNITS_COEFFICIENT, 98);
public static final FlightDataType TYPE_YAW_DAMPING_MOMENT_COEFF = newType(trans.get("FlightDataType.TYPE_YAW_DAMPING_MOMENT_COEFF"), "C\u03b6\u03a8", UnitGroup.UNITS_COEFFICIENT, 98);
//// Coriolis acceleration
public static final FlightDataType TYPE_CORIOLIS_ACCELERATION = newType(trans.get("FlightDataType.TYPE_CORIOLIS_ACCELERATION"), "Ac", UnitGroup.UNITS_ACCELERATION, 99);
@ -156,9 +156,9 @@ public class FlightDataType implements Comparable<FlightDataType> {
//// Orientation
//// Vertical orientation (zenith)
public static final FlightDataType TYPE_ORIENTATION_THETA = newType(trans.get("FlightDataType.TYPE_ORIENTATION_THETA"), "Θ", UnitGroup.UNITS_ANGLE, 106);
public static final FlightDataType TYPE_ORIENTATION_THETA = newType(trans.get("FlightDataType.TYPE_ORIENTATION_THETA"), "\u0398", UnitGroup.UNITS_ANGLE, 106);
//// Lateral orientation (azimuth)
public static final FlightDataType TYPE_ORIENTATION_PHI = newType(trans.get("FlightDataType.TYPE_ORIENTATION_PHI"), "Φ", UnitGroup.UNITS_ANGLE, 107);
public static final FlightDataType TYPE_ORIENTATION_PHI = newType(trans.get("FlightDataType.TYPE_ORIENTATION_PHI"), "\u03a6", UnitGroup.UNITS_ANGLE, 107);
//// Atmospheric conditions
@ -175,8 +175,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
//// Simulation time step
public static final FlightDataType TYPE_TIME_STEP = newType(trans.get("FlightDataType.TYPE_TIME_STEP"), "dt", UnitGroup.UNITS_TIME_STEP, 200);
//// Computation time
public static final FlightDataType TYPE_COMPUTATION_TIME = newType(trans.get("FlightDataType.TYPE_COMPUTATION_TIME"), "tc", UnitGroup.UNITS_SHORT_TIME, 201);
public static final FlightDataType TYPE_COMPUTATION_TIME = newType(trans.get("FlightDataType.TYPE_COMPUTATION_TIME"), "tc", UnitGroup.UNITS_SHORT_TIME, 201);
// An array of all the built in types
public static final FlightDataType[] ALL_TYPES = {
@ -273,7 +272,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
private final String name;
private final String symbol;
private final UnitGroup units;
private int priority;
private final int priority;
private final int hashCode;
@ -289,10 +288,11 @@ public class FlightDataType implements Comparable<FlightDataType> {
this.hashCode = this.name.toLowerCase(Locale.ENGLISH).hashCode();
}
/*
public void setPriority(int p){
this.priority = p;
}
*/
public String getName() {
return name;

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.optimization.rocketoptimization;
import static org.junit.Assert.*;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.optimization.general.OptimizationException;
import net.sf.openrocket.optimization.general.Point;
@ -39,7 +40,7 @@ public class TestRocketOptimizationFunction {
@Test
public void testNormalEvaluation() throws InterruptedException, OptimizationException {
final Rocket rocket = new Rocket();
final Simulation simulation = new Simulation(rocket);
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
final double p1 = 0.4;
final double p2 = 0.7;
@ -85,7 +86,7 @@ public class TestRocketOptimizationFunction {
@Test
public void testNaNValue() throws InterruptedException, OptimizationException {
final Rocket rocket = new Rocket();
final Simulation simulation = new Simulation(rocket);
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
final double p1 = 0.4;
final double p2 = 0.7;
@ -122,7 +123,7 @@ public class TestRocketOptimizationFunction {
@Test
public void testOutsideDomain() throws InterruptedException, OptimizationException {
final Rocket rocket = new Rocket();
final Simulation simulation = new Simulation(rocket);
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
final double p1 = 0.4;
final double p2 = 0.7;
@ -163,7 +164,7 @@ public class TestRocketOptimizationFunction {
@Test
public void testOutsideDomain2() throws InterruptedException, OptimizationException {
final Rocket rocket = new Rocket();
final Simulation simulation = new Simulation(rocket);
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
final double p1 = 0.4;
final double p2 = 0.7;
@ -196,7 +197,7 @@ public class TestRocketOptimizationFunction {
public void testNewSimulationInstance() {
final Rocket rocket = new Rocket();
rocket.setName("Foobar");
final Simulation simulation = new Simulation(rocket);
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
simulation.setName("MySim");
RocketOptimizationFunction function = new RocketOptimizationFunction(simulation,

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.optimization.rocketoptimization.modifiers;
import static net.sf.openrocket.util.MathUtil.EPSILON;
import static org.junit.Assert.assertEquals;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.optimization.general.OptimizationException;
import net.sf.openrocket.rocketcomponent.Rocket;
@ -20,7 +21,9 @@ public class TestGenericModifier {
@Before
public void setup() {
value = new TestValue();
sim = new Simulation(new Rocket());
Rocket rocket = new Rocket();
sim = new Simulation(new OpenRocketDocument(rocket), rocket);
Object related = new Object();