Rework the CustomExpression evaluation to use SimulationListeners. Removed the OpenRocketDocument member variable from the Simulation object.
This commit is contained in:
parent
2b802c2f7d
commit
a5c3c1ac76
@ -75,8 +75,7 @@ public class CurrentRocket {
|
|||||||
public synchronized void addNewSimulation( Context context ) {
|
public synchronized void addNewSimulation( Context context ) {
|
||||||
isModified = true;
|
isModified = true;
|
||||||
Rocket rocket = rocketDocument.getRocket();
|
Rocket rocket = rocketDocument.getRocket();
|
||||||
// FIXME - hopefully the change to the Simulation object will be reverted soon.
|
Simulation newSim = new Simulation(rocket);
|
||||||
Simulation newSim = new Simulation(rocketDocument, rocket);
|
|
||||||
newSim.setName(rocketDocument.getNextSimulationName());
|
newSim.setName(rocketDocument.getNextSimulationName());
|
||||||
rocketDocument.addSimulation(newSim);
|
rocketDocument.addSimulation(newSim);
|
||||||
notifySimsChanged(context);
|
notifySimsChanged(context);
|
||||||
|
@ -117,7 +117,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
|||||||
customExpressions.remove(expression);
|
customExpressions.remove(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<CustomExpression> getCustomExpressions(){
|
public List<CustomExpression> getCustomExpressions(){
|
||||||
return customExpressions;
|
return customExpressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
private SafetyMutex mutex = SafetyMutex.newInstance();
|
private SafetyMutex mutex = SafetyMutex.newInstance();
|
||||||
|
|
||||||
private final Rocket rocket;
|
private final Rocket rocket;
|
||||||
private final OpenRocketDocument document;
|
|
||||||
|
|
||||||
private String name = "";
|
private String name = "";
|
||||||
|
|
||||||
@ -94,11 +93,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
*
|
*
|
||||||
* @param rocket the rocket associated with the simulation.
|
* @param rocket the rocket associated with the simulation.
|
||||||
*/
|
*/
|
||||||
public Simulation(OpenRocketDocument doc, Rocket rocket) {
|
public Simulation(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.rocket = rocket;
|
||||||
this.status = Status.NOT_SIMULATED;
|
this.status = Status.NOT_SIMULATED;
|
||||||
|
|
||||||
@ -109,7 +104,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Simulation(OpenRocketDocument doc, Rocket rocket, Status status, String name, SimulationOptions options,
|
public Simulation(Rocket rocket, Status status, String name, SimulationOptions options,
|
||||||
List<String> listeners, FlightData data) {
|
List<String> listeners, FlightData data) {
|
||||||
|
|
||||||
if (rocket == null)
|
if (rocket == null)
|
||||||
@ -122,7 +117,6 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
throw new IllegalArgumentException("options cannot be null");
|
throw new IllegalArgumentException("options cannot be null");
|
||||||
|
|
||||||
this.rocket = rocket;
|
this.rocket = rocket;
|
||||||
this.document = doc;
|
|
||||||
|
|
||||||
if (status == Status.UPTODATE) {
|
if (status == Status.UPTODATE) {
|
||||||
this.status = Status.LOADED;
|
this.status = Status.LOADED;
|
||||||
@ -152,13 +146,6 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the parent document for this simulation
|
|
||||||
*/
|
|
||||||
public OpenRocketDocument getDocument(){
|
|
||||||
return document;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the rocket associated with this simulation.
|
* Return the rocket associated with this simulation.
|
||||||
*
|
*
|
||||||
@ -423,7 +410,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
public Simulation duplicateSimulation(Rocket newRocket) {
|
public Simulation duplicateSimulation(Rocket newRocket) {
|
||||||
mutex.lock("duplicateSimulation");
|
mutex.lock("duplicateSimulation");
|
||||||
try {
|
try {
|
||||||
Simulation copy = new Simulation(document, newRocket);
|
Simulation copy = new Simulation(newRocket);
|
||||||
|
|
||||||
copy.name = this.name;
|
copy.name = this.name;
|
||||||
copy.options.copyFrom(this.options);
|
copy.options.copyFrom(this.options);
|
||||||
|
@ -1383,7 +1383,7 @@ class SingleSimulationHandler extends AbstractElementHandler {
|
|||||||
else
|
else
|
||||||
data = dataHandler.getFlightData();
|
data = dataHandler.getFlightData();
|
||||||
|
|
||||||
Simulation simulation = new Simulation(doc, doc.getRocket(), status, name,
|
Simulation simulation = new Simulation(doc.getRocket(), status, name,
|
||||||
conditions, listeners, data);
|
conditions, listeners, data);
|
||||||
|
|
||||||
doc.addSimulation(simulation);
|
doc.addSimulation(simulation);
|
||||||
|
@ -5,8 +5,8 @@ import java.awt.Window;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -17,23 +17,17 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.filechooser.FileFilter;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
import net.sf.openrocket.file.DatabaseMotorFinder;
|
||||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||||
import net.sf.openrocket.file.MotorFinder;
|
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
import net.sf.openrocket.document.Simulation;
|
|
||||||
import net.sf.openrocket.gui.components.DescriptionArea;
|
|
||||||
import net.sf.openrocket.gui.components.UnitSelector;
|
import net.sf.openrocket.gui.components.UnitSelector;
|
||||||
import net.sf.openrocket.gui.customexpression.ExpressionBuilderDialog;
|
|
||||||
import net.sf.openrocket.gui.util.Icons;
|
import net.sf.openrocket.gui.util.Icons;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
|
||||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
@ -158,7 +152,7 @@ public class CustomExpressionPanel extends JPanel {
|
|||||||
* @param move integer - +1 to move down, -1 to move up
|
* @param move integer - +1 to move down, -1 to move up
|
||||||
*/
|
*/
|
||||||
private void moveExpression(CustomExpression expression, int move){
|
private void moveExpression(CustomExpression expression, int move){
|
||||||
ArrayList<CustomExpression> expressions = doc.getCustomExpressions();
|
List<CustomExpression> expressions = doc.getCustomExpressions();
|
||||||
int i = expressions.indexOf(expression);
|
int i = expressions.indexOf(expression);
|
||||||
if (i+move == expressions.size() || i+move < 0)
|
if (i+move == expressions.size() || i+move < 0)
|
||||||
return;
|
return;
|
||||||
|
@ -1000,14 +1000,14 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
if (id == null) {
|
if (id == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Simulation sim = new Simulation(documentCopy, rocket);
|
Simulation sim = new Simulation(rocket);
|
||||||
sim.getConfiguration().setMotorConfigurationID(id);
|
sim.getConfiguration().setMotorConfigurationID(id);
|
||||||
String name = createSimulationName(trans.get("basicSimulationName"), rocket.getMotorConfigurationNameOrDescription(id));
|
String name = createSimulationName(trans.get("basicSimulationName"), rocket.getMotorConfigurationNameOrDescription(id));
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<Simulation>(sim, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Simulation sim = new Simulation(documentCopy, rocket);
|
Simulation sim = new Simulation(rocket);
|
||||||
sim.getConfiguration().setMotorConfigurationID(null);
|
sim.getConfiguration().setMotorConfigurationID(null);
|
||||||
String name = createSimulationName(trans.get("noSimulationName"), rocket.getMotorConfigurationNameOrDescription(null));
|
String name = createSimulationName(trans.get("noSimulationName"), rocket.getMotorConfigurationNameOrDescription(null));
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<Simulation>(sim, name));
|
||||||
|
@ -30,6 +30,7 @@ import javax.swing.event.DocumentEvent;
|
|||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.gui.SpinnerEditor;
|
import net.sf.openrocket.gui.SpinnerEditor;
|
||||||
import net.sf.openrocket.gui.adaptors.BooleanModel;
|
import net.sf.openrocket.gui.adaptors.BooleanModel;
|
||||||
@ -41,7 +42,6 @@ import net.sf.openrocket.gui.components.DescriptionArea;
|
|||||||
import net.sf.openrocket.gui.components.SimulationExportPanel;
|
import net.sf.openrocket.gui.components.SimulationExportPanel;
|
||||||
import net.sf.openrocket.gui.components.UnitSelector;
|
import net.sf.openrocket.gui.components.UnitSelector;
|
||||||
import net.sf.openrocket.gui.plot.Axis;
|
import net.sf.openrocket.gui.plot.Axis;
|
||||||
import net.sf.openrocket.gui.customexpression.CustomExpressionPanel;
|
|
||||||
import net.sf.openrocket.gui.plot.PlotConfiguration;
|
import net.sf.openrocket.gui.plot.PlotConfiguration;
|
||||||
import net.sf.openrocket.gui.plot.SimulationPlotPanel;
|
import net.sf.openrocket.gui.plot.SimulationPlotPanel;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
@ -83,19 +83,20 @@ public class SimulationEditDialog extends JDialog {
|
|||||||
|
|
||||||
private final Window parentWindow;
|
private final Window parentWindow;
|
||||||
private final Simulation simulation;
|
private final Simulation simulation;
|
||||||
|
private final OpenRocketDocument document;
|
||||||
private final SimulationOptions conditions;
|
private final SimulationOptions conditions;
|
||||||
private final Configuration configuration;
|
private final Configuration configuration;
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
|
||||||
public SimulationEditDialog(Window parent, Simulation s) {
|
public SimulationEditDialog(Window parent, OpenRocketDocument document, Simulation s) {
|
||||||
this(parent, s, 0);
|
this(parent, document, s, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimulationEditDialog(Window parent, Simulation s, int tab) {
|
public SimulationEditDialog(Window parent, OpenRocketDocument document, Simulation s, int tab) {
|
||||||
//// Edit simulation
|
//// Edit simulation
|
||||||
super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL);
|
super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL);
|
||||||
|
this.document = document;
|
||||||
this.parentWindow = parent;
|
this.parentWindow = parent;
|
||||||
this.simulation = s;
|
this.simulation = s;
|
||||||
this.conditions = simulation.getOptions();
|
this.conditions = simulation.getOptions();
|
||||||
@ -170,7 +171,7 @@ public class SimulationEditDialog extends JDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
SimulationEditDialog.this.dispose();
|
SimulationEditDialog.this.dispose();
|
||||||
SimulationRunDialog.runSimulations(parentWindow, simulation);
|
SimulationRunDialog.runSimulations(parentWindow, SimulationEditDialog.this.document, simulation);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mainPanel.add(button, "gapright para");
|
mainPanel.add(button, "gapright para");
|
||||||
|
@ -82,7 +82,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Simulation sim = new Simulation(document, document.getRocket());
|
Simulation sim = new Simulation(document.getRocket());
|
||||||
sim.setName(document.getNextSimulationName());
|
sim.setName(document.getNextSimulationName());
|
||||||
|
|
||||||
int n = document.getSimulationCount();
|
int n = document.getSimulationCount();
|
||||||
@ -135,7 +135,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
|
|
||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
new SimulationRunDialog(SwingUtilities.getWindowAncestor(
|
new SimulationRunDialog(SwingUtilities.getWindowAncestor(
|
||||||
SimulationPanel.this), sims).setVisible(true);
|
SimulationPanel.this), document, sims).setVisible(true);
|
||||||
log.info("Running simulations took " + (System.currentTimeMillis() - t) + " ms");
|
log.info("Running simulations took " + (System.currentTimeMillis() - t) + " ms");
|
||||||
fireMaintainSelection();
|
fireMaintainSelection();
|
||||||
}
|
}
|
||||||
@ -514,7 +514,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openDialog(final Simulation sim, int position) {
|
private void openDialog(final Simulation sim, int position) {
|
||||||
new SimulationEditDialog(SwingUtilities.getWindowAncestor(this), sim, position)
|
new SimulationEditDialog(SwingUtilities.getWindowAncestor(this), document, sim, position)
|
||||||
.setVisible(true);
|
.setVisible(true);
|
||||||
fireMaintainSelection();
|
fireMaintainSelection();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.gui.dialogs.DetailDialog;
|
import net.sf.openrocket.gui.dialogs.DetailDialog;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
@ -35,6 +36,8 @@ import net.sf.openrocket.rocketcomponent.MotorMount;
|
|||||||
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
|
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
|
||||||
import net.sf.openrocket.simulation.FlightEvent;
|
import net.sf.openrocket.simulation.FlightEvent;
|
||||||
import net.sf.openrocket.simulation.SimulationStatus;
|
import net.sf.openrocket.simulation.SimulationStatus;
|
||||||
|
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||||
|
import net.sf.openrocket.simulation.customexpression.CustomExpressionSimulationListener;
|
||||||
import net.sf.openrocket.simulation.exception.SimulationCancelledException;
|
import net.sf.openrocket.simulation.exception.SimulationCancelledException;
|
||||||
import net.sf.openrocket.simulation.exception.SimulationException;
|
import net.sf.openrocket.simulation.exception.SimulationException;
|
||||||
import net.sf.openrocket.simulation.exception.SimulationLaunchException;
|
import net.sf.openrocket.simulation.exception.SimulationLaunchException;
|
||||||
@ -95,6 +98,7 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
* will result in an exception being thrown!
|
* will result in an exception being thrown!
|
||||||
*/
|
*/
|
||||||
private final Simulation[] simulations;
|
private final Simulation[] simulations;
|
||||||
|
private final OpenRocketDocument document;
|
||||||
private final String[] simulationNames;
|
private final String[] simulationNames;
|
||||||
private final SimulationWorker[] simulationWorkers;
|
private final SimulationWorker[] simulationWorkers;
|
||||||
private final SimulationStatus[] simulationStatuses;
|
private final SimulationStatus[] simulationStatuses;
|
||||||
@ -102,9 +106,10 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
private final double[] simulationMaxVelocity;
|
private final double[] simulationMaxVelocity;
|
||||||
private final boolean[] simulationDone;
|
private final boolean[] simulationDone;
|
||||||
|
|
||||||
public SimulationRunDialog(Window window, Simulation... simulations) {
|
public SimulationRunDialog(Window window, OpenRocketDocument document, Simulation... simulations) {
|
||||||
//// Running simulations...
|
//// Running simulations...
|
||||||
super(window, trans.get("SimuRunDlg.title.RunSim"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(window, trans.get("SimuRunDlg.title.RunSim"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
this.document = document;
|
||||||
|
|
||||||
if (simulations.length == 0) {
|
if (simulations.length == 0) {
|
||||||
throw new IllegalArgumentException("Called with no simulations to run");
|
throw new IllegalArgumentException("Called with no simulations to run");
|
||||||
@ -129,7 +134,7 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
simulationNames[i] = simulations[i].getName();
|
simulationNames[i] = simulations[i].getName();
|
||||||
simulationWorkers[i] = new InteractiveSimulationWorker(simulations[i], i);
|
simulationWorkers[i] = new InteractiveSimulationWorker(document, simulations[i], i);
|
||||||
executor.execute(simulationWorkers[i]);
|
executor.execute(simulationWorkers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +213,8 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
* @param parent the parent Window of the dialog to use.
|
* @param parent the parent Window of the dialog to use.
|
||||||
* @param simulations the simulations to run.
|
* @param simulations the simulations to run.
|
||||||
*/
|
*/
|
||||||
public static void runSimulations(Window parent, Simulation... simulations) {
|
public static void runSimulations(Window parent, OpenRocketDocument document, Simulation... simulations) {
|
||||||
new SimulationRunDialog(parent, simulations).setVisible(true);
|
new SimulationRunDialog(parent, document, simulations).setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,6 +282,8 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
private volatile double burnoutVelocity;
|
private volatile double burnoutVelocity;
|
||||||
private volatile double apogeeAltitude;
|
private volatile double apogeeAltitude;
|
||||||
|
|
||||||
|
private final CustomExpressionSimulationListener exprListener;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -2 = time from 0 ... burnoutTimeEstimate
|
* -2 = time from 0 ... burnoutTimeEstimate
|
||||||
* -1 = velocity from v(burnoutTimeEstimate) ... 0
|
* -1 = velocity from v(burnoutTimeEstimate) ... 0
|
||||||
@ -287,8 +294,10 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
private int progress = 0;
|
private int progress = 0;
|
||||||
|
|
||||||
|
|
||||||
public InteractiveSimulationWorker(Simulation sim, int index) {
|
public InteractiveSimulationWorker(OpenRocketDocument doc, Simulation sim, int index) {
|
||||||
super(sim);
|
super(sim);
|
||||||
|
List<CustomExpression> exprs = doc.getCustomExpressions();
|
||||||
|
exprListener = new CustomExpressionSimulationListener(exprs);
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
|
||||||
// Calculate estimate of motor burn time
|
// Calculate estimate of motor burn time
|
||||||
@ -314,7 +323,7 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected SimulationListener[] getExtraListeners() {
|
protected SimulationListener[] getExtraListeners() {
|
||||||
return new SimulationListener[] { new SimulationProgressListener() };
|
return new SimulationListener[] { new SimulationProgressListener(), exprListener };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ import net.sf.openrocket.rocketcomponent.Rocket;
|
|||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
||||||
import net.sf.openrocket.simulation.FlightData;
|
import net.sf.openrocket.simulation.FlightData;
|
||||||
|
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||||
|
import net.sf.openrocket.simulation.customexpression.CustomExpressionSimulationListener;
|
||||||
import net.sf.openrocket.simulation.listeners.SimulationListener;
|
import net.sf.openrocket.simulation.listeners.SimulationListener;
|
||||||
import net.sf.openrocket.simulation.listeners.system.ApogeeEndListener;
|
import net.sf.openrocket.simulation.listeners.system.ApogeeEndListener;
|
||||||
import net.sf.openrocket.simulation.listeners.system.InterruptListener;
|
import net.sf.openrocket.simulation.listeners.system.InterruptListener;
|
||||||
@ -138,16 +140,16 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
static {
|
static {
|
||||||
backgroundSimulationExecutor = Executors.newFixedThreadPool(SwingPreferences.getMaxThreadCount(),
|
backgroundSimulationExecutor = Executors.newFixedThreadPool(SwingPreferences.getMaxThreadCount(),
|
||||||
new ThreadFactory() {
|
new ThreadFactory() {
|
||||||
private ThreadFactory factory = Executors.defaultThreadFactory();
|
private ThreadFactory factory = Executors.defaultThreadFactory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread t = factory.newThread(r);
|
Thread t = factory.newThread(r);
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
t.setPriority(Thread.MIN_PRIORITY);
|
t.setPriority(Thread.MIN_PRIORITY);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -693,7 +695,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
simulation.getOptions().setMotorConfigurationID(
|
simulation.getOptions().setMotorConfigurationID(
|
||||||
configuration.getMotorConfigurationID());
|
configuration.getMotorConfigurationID());
|
||||||
|
|
||||||
backgroundSimulationWorker = new BackgroundSimulationWorker(simulation);
|
backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation);
|
||||||
backgroundSimulationExecutor.execute(backgroundSimulationWorker);
|
backgroundSimulationExecutor.execute(backgroundSimulationWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,8 +717,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
*/
|
*/
|
||||||
private class BackgroundSimulationWorker extends SimulationWorker {
|
private class BackgroundSimulationWorker extends SimulationWorker {
|
||||||
|
|
||||||
public BackgroundSimulationWorker(Simulation sim) {
|
private final CustomExpressionSimulationListener exprListener;
|
||||||
|
|
||||||
|
public BackgroundSimulationWorker(OpenRocketDocument doc, Simulation sim) {
|
||||||
super(sim);
|
super(sim);
|
||||||
|
List<CustomExpression> exprs = doc.getCustomExpressions();
|
||||||
|
exprListener = new CustomExpressionSimulationListener(exprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -750,7 +756,9 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
protected SimulationListener[] getExtraListeners() {
|
protected SimulationListener[] getExtraListeners() {
|
||||||
return new SimulationListener[] {
|
return new SimulationListener[] {
|
||||||
InterruptListener.INSTANCE,
|
InterruptListener.INSTANCE,
|
||||||
ApogeeEndListener.INSTANCE };
|
ApogeeEndListener.INSTANCE,
|
||||||
|
exprListener};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,6 @@ import java.util.prefs.BackingStoreException;
|
|||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
import net.sf.openrocket.arch.SystemInfo;
|
import net.sf.openrocket.arch.SystemInfo;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
@ -399,7 +398,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Simulation getBackgroundSimulation(Rocket rocket) {
|
public Simulation getBackgroundSimulation(Rocket rocket) {
|
||||||
Simulation s = new Simulation(new OpenRocketDocument(rocket), rocket);
|
Simulation s = new Simulation(rocket);
|
||||||
SimulationOptions cond = s.getOptions();
|
SimulationOptions cond = s.getOptions();
|
||||||
|
|
||||||
cond.setTimeStep(RK4SimulationStepper.RECOMMENDED_TIME_STEP * 2);
|
cond.setTimeStep(RK4SimulationStepper.RECOMMENDED_TIME_STEP * 2);
|
||||||
|
@ -126,7 +126,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
Rocket rocket = document.getRocket();
|
Rocket rocket = document.getRocket();
|
||||||
|
|
||||||
// Simulation is used to calculate default min/max values
|
// Simulation is used to calculate default min/max values
|
||||||
Simulation simulation = new Simulation(document, rocket);
|
Simulation simulation = new Simulation(rocket);
|
||||||
simulation.getConfiguration().setMotorConfigurationID(null);
|
simulation.getConfiguration().setMotorConfigurationID(null);
|
||||||
|
|
||||||
for (RocketComponent c : rocket) {
|
for (RocketComponent c : rocket) {
|
||||||
|
@ -90,12 +90,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
}
|
}
|
||||||
SimulationListenerHelper.firePostStep(status);
|
SimulationListenerHelper.firePostStep(status);
|
||||||
|
|
||||||
// Calculate values for custom expressions
|
|
||||||
FlightDataBranch data = status.getFlightData();
|
|
||||||
ArrayList<CustomExpression> allExpressions = status.getSimulationConditions().getSimulation().getDocument().getCustomExpressions();
|
|
||||||
for (CustomExpression expression : allExpressions ) {
|
|
||||||
data.setValue(expression.getType(), expression.evaluateDouble(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for NaN values in the simulation status
|
// Check for NaN values in the simulation status
|
||||||
checkNaN();
|
checkNaN();
|
||||||
|
@ -175,7 +175,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
names.add(type.getName());
|
names.add(type.getName());
|
||||||
|
|
||||||
if (doc != null){
|
if (doc != null){
|
||||||
ArrayList<CustomExpression> expressions = doc.getCustomExpressions();
|
List<CustomExpression> expressions = doc.getCustomExpressions();
|
||||||
for (CustomExpression exp : expressions ){
|
for (CustomExpression exp : expressions ){
|
||||||
if (exp != this)
|
if (exp != this)
|
||||||
names.add(exp.getName());
|
names.add(exp.getName());
|
||||||
@ -412,7 +412,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
*/
|
*/
|
||||||
public void addToDocument(){
|
public void addToDocument(){
|
||||||
// Abort if exact expression already in
|
// Abort if exact expression already in
|
||||||
ArrayList<CustomExpression> expressions = doc.getCustomExpressions();
|
List<CustomExpression> expressions = doc.getCustomExpressions();
|
||||||
if ( !expressions.isEmpty() ) {
|
if ( !expressions.isEmpty() ) {
|
||||||
// check if expression already exists
|
// check if expression already exists
|
||||||
if ( expressions.contains(this) ){
|
if ( expressions.contains(this) ){
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package net.sf.openrocket.simulation.customexpression;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.openrocket.simulation.FlightDataBranch;
|
||||||
|
import net.sf.openrocket.simulation.SimulationStatus;
|
||||||
|
import net.sf.openrocket.simulation.exception.SimulationException;
|
||||||
|
import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
|
||||||
|
|
||||||
|
public class CustomExpressionSimulationListener extends AbstractSimulationListener {
|
||||||
|
|
||||||
|
private final List<CustomExpression> expressions;
|
||||||
|
|
||||||
|
public CustomExpressionSimulationListener(List<CustomExpression> expressions) {
|
||||||
|
super();
|
||||||
|
this.expressions = expressions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postStep(SimulationStatus status) throws SimulationException {
|
||||||
|
if ( expressions == null || expressions.size() == 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Calculate values for custom expressions
|
||||||
|
FlightDataBranch data = status.getFlightData();
|
||||||
|
for (CustomExpression expression : expressions ) {
|
||||||
|
data.setValue(expression.getType(), expression.evaluateDouble(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package net.sf.openrocket.optimization.rocketoptimization;
|
package net.sf.openrocket.optimization.rocketoptimization;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.optimization.general.OptimizationException;
|
import net.sf.openrocket.optimization.general.OptimizationException;
|
||||||
import net.sf.openrocket.optimization.general.Point;
|
import net.sf.openrocket.optimization.general.Point;
|
||||||
@ -40,7 +39,7 @@ public class TestRocketOptimizationFunction {
|
|||||||
@Test
|
@Test
|
||||||
public void testNormalEvaluation() throws InterruptedException, OptimizationException {
|
public void testNormalEvaluation() throws InterruptedException, OptimizationException {
|
||||||
final Rocket rocket = new Rocket();
|
final Rocket rocket = new Rocket();
|
||||||
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
|
final Simulation simulation = new Simulation(rocket);
|
||||||
|
|
||||||
final double p1 = 0.4;
|
final double p1 = 0.4;
|
||||||
final double p2 = 0.7;
|
final double p2 = 0.7;
|
||||||
@ -86,7 +85,7 @@ public class TestRocketOptimizationFunction {
|
|||||||
@Test
|
@Test
|
||||||
public void testNaNValue() throws InterruptedException, OptimizationException {
|
public void testNaNValue() throws InterruptedException, OptimizationException {
|
||||||
final Rocket rocket = new Rocket();
|
final Rocket rocket = new Rocket();
|
||||||
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
|
final Simulation simulation = new Simulation(rocket);
|
||||||
|
|
||||||
final double p1 = 0.4;
|
final double p1 = 0.4;
|
||||||
final double p2 = 0.7;
|
final double p2 = 0.7;
|
||||||
@ -123,7 +122,7 @@ public class TestRocketOptimizationFunction {
|
|||||||
@Test
|
@Test
|
||||||
public void testOutsideDomain() throws InterruptedException, OptimizationException {
|
public void testOutsideDomain() throws InterruptedException, OptimizationException {
|
||||||
final Rocket rocket = new Rocket();
|
final Rocket rocket = new Rocket();
|
||||||
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
|
final Simulation simulation = new Simulation(rocket);
|
||||||
|
|
||||||
final double p1 = 0.4;
|
final double p1 = 0.4;
|
||||||
final double p2 = 0.7;
|
final double p2 = 0.7;
|
||||||
@ -164,7 +163,7 @@ public class TestRocketOptimizationFunction {
|
|||||||
@Test
|
@Test
|
||||||
public void testOutsideDomain2() throws InterruptedException, OptimizationException {
|
public void testOutsideDomain2() throws InterruptedException, OptimizationException {
|
||||||
final Rocket rocket = new Rocket();
|
final Rocket rocket = new Rocket();
|
||||||
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
|
final Simulation simulation = new Simulation(rocket);
|
||||||
|
|
||||||
final double p1 = 0.4;
|
final double p1 = 0.4;
|
||||||
final double p2 = 0.7;
|
final double p2 = 0.7;
|
||||||
@ -197,7 +196,7 @@ public class TestRocketOptimizationFunction {
|
|||||||
public void testNewSimulationInstance() {
|
public void testNewSimulationInstance() {
|
||||||
final Rocket rocket = new Rocket();
|
final Rocket rocket = new Rocket();
|
||||||
rocket.setName("Foobar");
|
rocket.setName("Foobar");
|
||||||
final Simulation simulation = new Simulation(new OpenRocketDocument(rocket), rocket);
|
final Simulation simulation = new Simulation(rocket);
|
||||||
simulation.setName("MySim");
|
simulation.setName("MySim");
|
||||||
|
|
||||||
RocketOptimizationFunction function = new RocketOptimizationFunction(simulation,
|
RocketOptimizationFunction function = new RocketOptimizationFunction(simulation,
|
||||||
|
@ -2,7 +2,6 @@ package net.sf.openrocket.optimization.rocketoptimization.modifiers;
|
|||||||
|
|
||||||
import static net.sf.openrocket.util.MathUtil.EPSILON;
|
import static net.sf.openrocket.util.MathUtil.EPSILON;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.optimization.general.OptimizationException;
|
import net.sf.openrocket.optimization.general.OptimizationException;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
@ -21,9 +20,7 @@ public class TestGenericModifier {
|
|||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
value = new TestValue();
|
value = new TestValue();
|
||||||
Rocket rocket = new Rocket();
|
sim = new Simulation(new Rocket());
|
||||||
|
|
||||||
sim = new Simulation(new OpenRocketDocument(rocket), rocket);
|
|
||||||
|
|
||||||
Object related = new Object();
|
Object related = new Object();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user