Outdated simulations will now run when the simulations tab is selected.
This commit is contained in:
parent
05242d4f81
commit
6110e0f5cd
@ -2,6 +2,7 @@ package net.sf.openrocket.document;
|
|||||||
|
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
|
import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
|
||||||
@ -10,8 +11,14 @@ import net.sf.openrocket.aerodynamics.WarningSet;
|
|||||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||||
import net.sf.openrocket.masscalc.BasicMassCalculator;
|
import net.sf.openrocket.masscalc.BasicMassCalculator;
|
||||||
import net.sf.openrocket.masscalc.MassCalculator;
|
import net.sf.openrocket.masscalc.MassCalculator;
|
||||||
|
import net.sf.openrocket.motor.Motor;
|
||||||
|
import net.sf.openrocket.motor.MotorInstanceConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||||
|
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.simulation.BasicEventSimulationEngine;
|
import net.sf.openrocket.simulation.BasicEventSimulationEngine;
|
||||||
import net.sf.openrocket.simulation.DefaultSimulationOptionFactory;
|
import net.sf.openrocket.simulation.DefaultSimulationOptionFactory;
|
||||||
import net.sf.openrocket.simulation.FlightData;
|
import net.sf.openrocket.simulation.FlightData;
|
||||||
@ -58,7 +65,10 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
EXTERNAL,
|
EXTERNAL,
|
||||||
|
|
||||||
/** Not yet simulated */
|
/** Not yet simulated */
|
||||||
NOT_SIMULATED
|
NOT_SIMULATED,
|
||||||
|
|
||||||
|
/** Can't be simulated, NO_MOTORS **/
|
||||||
|
CANT_RUN
|
||||||
}
|
}
|
||||||
|
|
||||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||||
@ -250,12 +260,34 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
*/
|
*/
|
||||||
public Status getStatus() {
|
public Status getStatus() {
|
||||||
mutex.verify();
|
mutex.verify();
|
||||||
|
|
||||||
if (status == Status.UPTODATE || status == Status.LOADED) {
|
if (status == Status.UPTODATE || status == Status.LOADED) {
|
||||||
if (rocket.getFunctionalModID() != simulatedRocketID ||
|
if (rocket.getFunctionalModID() != simulatedRocketID || !options.equals(simulatedConditions)) {
|
||||||
!options.equals(simulatedConditions))
|
status = Status.OUTDATED;
|
||||||
return Status.OUTDATED;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Make sure this simulation has motors.
|
||||||
|
Configuration c = new Configuration(this.getRocket());
|
||||||
|
MotorInstanceConfiguration motors = new MotorInstanceConfiguration();
|
||||||
|
c.setFlightConfigurationID(options.getMotorConfigurationID());
|
||||||
|
final String flightConfigId = c.getFlightConfigurationID();
|
||||||
|
|
||||||
|
Iterator<MotorMount> iterator = c.motorIterator();
|
||||||
|
boolean no_motors = true;
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
MotorMount mount = iterator.next();
|
||||||
|
RocketComponent component = (RocketComponent) mount;
|
||||||
|
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(flightConfigId);
|
||||||
|
IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(flightConfigId);
|
||||||
|
Motor motor = motorConfig.getMotor();
|
||||||
|
if (motor != null)
|
||||||
|
no_motors = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (no_motors)
|
||||||
|
status = Status.CANT_RUN;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
private SimulationStepper landingStepper = new BasicLandingStepper();
|
private SimulationStepper landingStepper = new BasicLandingStepper();
|
||||||
private SimulationStepper tumbleStepper = new BasicTumbleStepper();
|
private SimulationStepper tumbleStepper = new BasicTumbleStepper();
|
||||||
|
|
||||||
// Constant holding 20 degress in radians. This is the AOA condition
|
// Constant holding 20 degrees in radians. This is the AOA condition
|
||||||
// necessary to transistion to tumbling.
|
// necessary to transition to tumbling.
|
||||||
private final static double AOA_TUMBLE_CONDITION = Math.PI / 9.0;
|
private final static double AOA_TUMBLE_CONDITION = Math.PI / 9.0;
|
||||||
|
|
||||||
// The thrust must be below this value for the transition to tumbling.
|
// The thrust must be below this value for the transition to tumbling.
|
||||||
|
@ -334,7 +334,7 @@ public class PreferencesDialog extends JDialog {
|
|||||||
});
|
});
|
||||||
panel.add(automaticallyRunSimsBox, "wrap, growx, sg combos ");
|
panel.add(automaticallyRunSimsBox, "wrap, growx, sg combos ");
|
||||||
|
|
||||||
//// Automatically run all simulation out-dated by design changes.
|
//// Update flight estimates in the design window
|
||||||
final JCheckBox updateEstimates =
|
final JCheckBox updateEstimates =
|
||||||
new JCheckBox(trans.get("pref.dlg.checkbox.Updateestimates"));
|
new JCheckBox(trans.get("pref.dlg.checkbox.Updateestimates"));
|
||||||
updateEstimates.setSelected(preferences.computeFlightInBackground());
|
updateEstimates.setSelected(preferences.computeFlightInBackground());
|
||||||
|
@ -54,6 +54,7 @@ import javax.swing.border.BevelBorder;
|
|||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.event.TreeSelectionListener;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.tree.DefaultTreeSelectionModel;
|
import javax.swing.tree.DefaultTreeSelectionModel;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
import javax.swing.tree.TreeSelectionModel;
|
import javax.swing.tree.TreeSelectionModel;
|
||||||
@ -153,7 +154,7 @@ public class BasicFrame extends JFrame {
|
|||||||
/** Actions available for rocket modifications */
|
/** Actions available for rocket modifications */
|
||||||
private final RocketActions actions;
|
private final RocketActions actions;
|
||||||
|
|
||||||
|
private SimulationPanel simulationPanel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,7 +175,7 @@ public class BasicFrame extends JFrame {
|
|||||||
componentSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
componentSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
|
|
||||||
// Obtain the simulation selection model that will be used
|
// Obtain the simulation selection model that will be used
|
||||||
SimulationPanel simulationPanel = new SimulationPanel(document);
|
simulationPanel = new SimulationPanel(document);
|
||||||
simulationSelectionModel = simulationPanel.getSimulationListSelectionModel();
|
simulationSelectionModel = simulationPanel.getSimulationListSelectionModel();
|
||||||
|
|
||||||
// Combine into a DocumentSelectionModel
|
// Combine into a DocumentSelectionModel
|
||||||
@ -203,6 +204,11 @@ public class BasicFrame extends JFrame {
|
|||||||
//// Flight simulations
|
//// Flight simulations
|
||||||
tabbedPane.addTab(trans.get("BasicFrame.tab.Flightsim"), null, simulationPanel);
|
tabbedPane.addTab(trans.get("BasicFrame.tab.Flightsim"), null, simulationPanel);
|
||||||
|
|
||||||
|
// Add change listener to catch when the tabs are changed. This is to run simulations
|
||||||
|
// automagically when the simulation tab is selected.
|
||||||
|
tabbedPane.addChangeListener(new BasicFrame_changeAdapter(this));
|
||||||
|
|
||||||
|
|
||||||
vertical.setTopComponent(tabbedPane);
|
vertical.setTopComponent(tabbedPane);
|
||||||
|
|
||||||
|
|
||||||
@ -1553,4 +1559,24 @@ public class BasicFrame extends JFrame {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
JTabbedPane tabSource = (JTabbedPane) e.getSource();
|
||||||
|
String tab = tabSource.getTitleAt(tabSource.getSelectedIndex());
|
||||||
|
if (tab.equals(trans.get("BasicFrame.tab.Flightsim"))) {
|
||||||
|
simulationPanel.activating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BasicFrame_changeAdapter implements javax.swing.event.ChangeListener {
|
||||||
|
BasicFrame adaptee;
|
||||||
|
|
||||||
|
BasicFrame_changeAdapter(BasicFrame adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
adaptee.stateChanged(e);
|
||||||
|
}
|
||||||
}
|
}
|
@ -44,6 +44,7 @@ import net.sf.openrocket.gui.simulation.SimulationEditDialog;
|
|||||||
import net.sf.openrocket.gui.simulation.SimulationRunDialog;
|
import net.sf.openrocket.gui.simulation.SimulationRunDialog;
|
||||||
import net.sf.openrocket.gui.simulation.SimulationWarningDialog;
|
import net.sf.openrocket.gui.simulation.SimulationWarningDialog;
|
||||||
import net.sf.openrocket.gui.util.Icons;
|
import net.sf.openrocket.gui.util.Icons;
|
||||||
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||||
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||||
@ -586,6 +587,44 @@ public class SimulationPanel extends JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// when the simulation tab is selected this run outdated simulated if appropriate.
|
||||||
|
public void activating(){
|
||||||
|
if( ((Preferences) Application.getPreferences()).getAutoRunSimulations()){
|
||||||
|
int nSims = simulationTable.getRowCount();
|
||||||
|
int outdated = 0;
|
||||||
|
if (nSims == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < nSims; i++) {
|
||||||
|
Simulation.Status s = document.getSimulation(simulationTable.convertRowIndexToModel(i)).getStatus();
|
||||||
|
if((s==Simulation.Status.NOT_SIMULATED) ||
|
||||||
|
(s==Simulation.Status.OUTDATED)){
|
||||||
|
outdated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(outdated>0){
|
||||||
|
Simulation[] sims = new Simulation[outdated];
|
||||||
|
|
||||||
|
int index=0;
|
||||||
|
for (int i = 0; i < nSims; i++) {
|
||||||
|
int t = simulationTable.convertRowIndexToModel(i);
|
||||||
|
Simulation s = document.getSimulation(t);
|
||||||
|
if((s.getStatus()==Status.NOT_SIMULATED)||(s.getStatus()==Status.OUTDATED)){
|
||||||
|
sims[index] = s;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
new SimulationRunDialog(SwingUtilities.getWindowAncestor(
|
||||||
|
SimulationPanel.this), document, sims).setVisible(true);
|
||||||
|
log.info("Running simulations took " + (System.currentTimeMillis() - t) + " ms");
|
||||||
|
fireMaintainSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ListSelectionModel getSimulationListSelectionModel() {
|
public ListSelectionModel getSimulationListSelectionModel() {
|
||||||
return simulationTable.getSelectionModel();
|
return simulationTable.getSelectionModel();
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class Icons {
|
|||||||
static {
|
static {
|
||||||
HashMap<Simulation.Status, Icon> map = new HashMap<Simulation.Status, Icon>();
|
HashMap<Simulation.Status, Icon> map = new HashMap<Simulation.Status, Icon>();
|
||||||
map.put(Simulation.Status.NOT_SIMULATED, loadImageIcon("pix/spheres/gray-16x16.png", "Not simulated"));
|
map.put(Simulation.Status.NOT_SIMULATED, loadImageIcon("pix/spheres/gray-16x16.png", "Not simulated"));
|
||||||
|
map.put(Simulation.Status.CANT_RUN, loadImageIcon("pix/spheres/yellow-16x16.png", "Can't run, no motors assigned."));
|
||||||
map.put(Simulation.Status.UPTODATE, loadImageIcon("pix/spheres/green-16x16.png", "Up to date"));
|
map.put(Simulation.Status.UPTODATE, loadImageIcon("pix/spheres/green-16x16.png", "Up to date"));
|
||||||
map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/yellow-16x16.png", "Loaded from file"));
|
map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/yellow-16x16.png", "Loaded from file"));
|
||||||
map.put(Simulation.Status.OUTDATED, loadImageIcon("pix/spheres/red-16x16.png", "Out-of-date"));
|
map.put(Simulation.Status.OUTDATED, loadImageIcon("pix/spheres/red-16x16.png", "Out-of-date"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user