Refactor PlotConfiguration to SimulationPlotConfiguration

This commit is contained in:
SiboVG 2024-08-13 21:49:57 +02:00
parent 8a0a12cd94
commit c3a2bb8d29
4 changed files with 52 additions and 53 deletions

View File

@ -15,7 +15,6 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
@ -89,9 +88,9 @@ public class SimulationPlot {
private final JFreeChart chart;
private final PlotConfiguration config;
private final SimulationPlotConfiguration config;
private final Simulation simulation;
private final PlotConfiguration filled;
private final SimulationPlotConfiguration filled;
private final List<EventDisplayInfo> eventList;
private final List<ModifiedXYItemRenderer> renderers = new ArrayList<>();
@ -129,7 +128,7 @@ public class SimulationPlot {
errorAnnotations.setCurrent(branch);
}
SimulationPlot(Simulation simulation, PlotConfiguration config, boolean initialShowPoints) {
SimulationPlot(Simulation simulation, SimulationPlotConfiguration config, boolean initialShowPoints) {
this.simulation = simulation;
this.config = config;
this.branchCount = simulation.getSimulatedData().getBranchCount();
@ -163,7 +162,7 @@ public class SimulationPlot {
this.filled = config.fillAutoAxes(mainBranch);
// Compute the axes based on the min and max value of all branches
PlotConfiguration plotConfig = filled.clone();
SimulationPlotConfiguration plotConfig = filled.clone();
plotConfig.fitAxes(simulation.getSimulatedData().getBranches());
List<Axis> minMaxAxes = plotConfig.getAllAxes();

View File

@ -17,17 +17,17 @@ import info.openrocket.core.util.MathUtil;
import info.openrocket.core.util.Pair;
public class PlotConfiguration implements Cloneable {
public class SimulationPlotConfiguration implements Cloneable {
private static final Translator trans = Application.getTranslator();
public static final PlotConfiguration[] DEFAULT_CONFIGURATIONS;
public static final SimulationPlotConfiguration[] DEFAULT_CONFIGURATIONS;
static {
ArrayList<PlotConfiguration> configs = new ArrayList<>();
PlotConfiguration config;
ArrayList<SimulationPlotConfiguration> configs = new ArrayList<>();
SimulationPlotConfiguration config;
//// Vertical motion vs. time
config = new PlotConfiguration(trans.get("PlotConfiguration.Verticalmotion"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Verticalmotion"));
config.addPlotDataType(FlightDataType.TYPE_ALTITUDE, 0);
config.addPlotDataType(FlightDataType.TYPE_VELOCITY_Z);
config.addPlotDataType(FlightDataType.TYPE_ACCELERATION_Z);
@ -43,7 +43,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Total motion vs. time
config = new PlotConfiguration(trans.get("PlotConfiguration.Totalmotion"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Totalmotion"));
config.addPlotDataType(FlightDataType.TYPE_ALTITUDE, 0);
config.addPlotDataType(FlightDataType.TYPE_VELOCITY_TOTAL);
config.addPlotDataType(FlightDataType.TYPE_ACCELERATION_TOTAL);
@ -59,7 +59,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Flight side profile
config = new PlotConfiguration(trans.get("PlotConfiguration.Flightside"), FlightDataType.TYPE_POSITION_X);
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Flightside"), FlightDataType.TYPE_POSITION_X);
config.addPlotDataType(FlightDataType.TYPE_ALTITUDE);
config.setEvent(FlightEvent.Type.IGNITION, true);
config.setEvent(FlightEvent.Type.BURNOUT, true);
@ -74,7 +74,7 @@ public class PlotConfiguration implements Cloneable {
//// Ground track
config = new PlotConfiguration(trans.get("PlotConfiguration.Groundtrack"), FlightDataType.TYPE_POSITION_X);
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Groundtrack"), FlightDataType.TYPE_POSITION_X);
config.addPlotDataType(FlightDataType.TYPE_POSITION_Y, 0);
config.addPlotDataType(FlightDataType.TYPE_ALTITUDE, 1);
config.setEvent(FlightEvent.Type.IGNITION, true);
@ -87,7 +87,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Stability vs. time
config = new PlotConfiguration(trans.get("PlotConfiguration.Stability"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Stability"));
config.addPlotDataType(FlightDataType.TYPE_STABILITY, 0);
config.addPlotDataType(FlightDataType.TYPE_CP_LOCATION, 1);
config.addPlotDataType(FlightDataType.TYPE_CG_LOCATION, 1);
@ -102,7 +102,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Drag coefficients vs. Mach number
config = new PlotConfiguration(trans.get("PlotConfiguration.Dragcoef"),
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Dragcoef"),
FlightDataType.TYPE_MACH_NUMBER);
config.addPlotDataType(FlightDataType.TYPE_DRAG_COEFF, 0);
config.addPlotDataType(FlightDataType.TYPE_FRICTION_DRAG_COEFF, 0);
@ -113,7 +113,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Roll characteristics
config = new PlotConfiguration(trans.get("PlotConfiguration.Rollcharacteristics"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Rollcharacteristics"));
config.addPlotDataType(FlightDataType.TYPE_ROLL_RATE, 0);
config.addPlotDataType(FlightDataType.TYPE_ROLL_MOMENT_COEFF, 1);
config.addPlotDataType(FlightDataType.TYPE_ROLL_FORCING_COEFF, 1);
@ -131,7 +131,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Angle of attack and orientation vs. time
config = new PlotConfiguration(trans.get("PlotConfiguration.Angleofattack"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Angleofattack"));
config.addPlotDataType(FlightDataType.TYPE_AOA, 0);
config.addPlotDataType(FlightDataType.TYPE_ORIENTATION_PHI);
config.addPlotDataType(FlightDataType.TYPE_ORIENTATION_THETA);
@ -147,7 +147,7 @@ public class PlotConfiguration implements Cloneable {
configs.add(config);
//// Simulation time step and computation time
config = new PlotConfiguration(trans.get("PlotConfiguration.Simulationtime"));
config = new SimulationPlotConfiguration(trans.get("PlotConfiguration.Simulationtime"));
config.addPlotDataType(FlightDataType.TYPE_TIME_STEP);
config.addPlotDataType(FlightDataType.TYPE_COMPUTATION_TIME);
config.setEvent(FlightEvent.Type.IGNITION, true);
@ -161,7 +161,7 @@ public class PlotConfiguration implements Cloneable {
config.setEvent(FlightEvent.Type.SIM_ABORT, true);
configs.add(config);
DEFAULT_CONFIGURATIONS = configs.toArray(new PlotConfiguration[0]);
DEFAULT_CONFIGURATIONS = configs.toArray(new SimulationPlotConfiguration[0]);
}
@ -208,15 +208,15 @@ public class PlotConfiguration implements Cloneable {
private String name = null;
public PlotConfiguration() {
public SimulationPlotConfiguration() {
this(null, FlightDataType.TYPE_TIME);
}
public PlotConfiguration(String name) {
public SimulationPlotConfiguration(String name) {
this(name, FlightDataType.TYPE_TIME);
}
public PlotConfiguration(String name, FlightDataType domainType) {
public SimulationPlotConfiguration(String name, FlightDataType domainType) {
this.name = name;
// Two axes
allAxes.add(new Axis());
@ -370,7 +370,7 @@ public class PlotConfiguration implements Cloneable {
}
/**
* Returns the name of this PlotConfiguration.
* Returns the name of this SimulationPlotConfiguration.
*/
@Override
public String toString() {
@ -382,11 +382,11 @@ public class PlotConfiguration implements Cloneable {
/**
* Find the best combination of the auto-selectable axes.
*
* @return a new PlotConfiguration with the best fitting auto-selected axes and
* @return a new SimulationPlotConfiguration with the best fitting auto-selected axes and
* axes ranges selected.
*/
public PlotConfiguration fillAutoAxes(FlightDataBranch data) {
PlotConfiguration config = recursiveFillAutoAxes(data).getU();
public SimulationPlotConfiguration fillAutoAxes(FlightDataBranch data) {
SimulationPlotConfiguration config = recursiveFillAutoAxes(data).getU();
//System.out.println("BEST FOUND, fitting");
config.fitAxes(data);
return config;
@ -399,13 +399,13 @@ public class PlotConfiguration implements Cloneable {
* Recursively search for the best combination of the auto-selectable axes.
* This is a brute-force search method.
*
* @return a new PlotConfiguration with the best fitting auto-selected axes and
* @return a new SimulationPlotConfiguration with the best fitting auto-selected axes and
* axes ranges selected, and the goodness value
*/
private Pair<PlotConfiguration, Double> recursiveFillAutoAxes(FlightDataBranch data) {
private Pair<SimulationPlotConfiguration, Double> recursiveFillAutoAxes(FlightDataBranch data) {
// Create copy to fill in
PlotConfiguration copy = this.clone();
SimulationPlotConfiguration copy = this.clone();
int autoindex;
for (autoindex = 0; autoindex < plotDataAxes.size(); autoindex++) {
@ -421,11 +421,11 @@ public class PlotConfiguration implements Cloneable {
// Set the auto-selected index one at a time and choose the best one
PlotConfiguration best = null;
SimulationPlotConfiguration best = null;
double bestValue = Double.NEGATIVE_INFINITY;
for (int i = 0; i < axesCount; i++) {
copy.plotDataAxes.set(autoindex, i);
Pair<PlotConfiguration, Double> result = copy.recursiveFillAutoAxes(data);
Pair<SimulationPlotConfiguration, Double> result = copy.recursiveFillAutoAxes(data);
if (result.getV() > bestValue) {
best = result.getU();
bestValue = result.getV();
@ -690,11 +690,11 @@ public class PlotConfiguration implements Cloneable {
/**
* Reset the units of this configuration to the default units. Returns this
* PlotConfiguration.
* SimulationPlotConfiguration.
*
* @return this PlotConfiguration.
* @return this SimulationPlotConfiguration.
*/
public PlotConfiguration resetUnits() {
public SimulationPlotConfiguration resetUnits() {
for (int i = 0; i < plotDataTypes.size(); i++) {
plotDataUnits.set(i, plotDataTypes.get(i).getUnitGroup().getDefaultUnit());
}
@ -705,10 +705,10 @@ public class PlotConfiguration implements Cloneable {
@Override
public PlotConfiguration clone() {
public SimulationPlotConfiguration clone() {
try {
PlotConfiguration copy = (PlotConfiguration) super.clone();
SimulationPlotConfiguration copy = (SimulationPlotConfiguration) super.clone();
// Shallow-clone all immutable lists
copy.plotDataTypes = this.plotDataTypes.clone();

View File

@ -52,7 +52,7 @@ public class SimulationPlotDialog extends JDialog {
initColors();
}
private SimulationPlotDialog(Window parent, Simulation simulation, PlotConfiguration config) {
private SimulationPlotDialog(Window parent, Simulation simulation, SimulationPlotConfiguration config) {
//// Flight data plot
super(parent, simulation.getName());
this.setModalityType(ModalityType.DOCUMENT_MODAL);
@ -247,7 +247,7 @@ public class SimulationPlotDialog extends JDialog {
* @param simulation the simulation to plot.
* @param config the configuration of the plot.
*/
public static SimulationPlotDialog getPlot(Window parent, Simulation simulation, PlotConfiguration config) {
public static SimulationPlotDialog getPlot(Window parent, Simulation simulation, SimulationPlotConfiguration config) {
return new SimulationPlotDialog(parent, simulation, config);
}

View File

@ -35,11 +35,11 @@ import info.openrocket.core.preferences.ApplicationPreferences;
import info.openrocket.core.unit.Unit;
import info.openrocket.core.util.Utils;
import info.openrocket.swing.gui.plot.SimulationPlotConfiguration;
import info.openrocket.swing.gui.widgets.GroupableAndSearchableComboBox;
import net.miginfocom.swing.MigLayout;
import info.openrocket.swing.gui.components.DescriptionArea;
import info.openrocket.swing.gui.components.UnitSelector;
import info.openrocket.swing.gui.plot.PlotConfiguration;
import info.openrocket.swing.gui.plot.SimulationPlotDialog;
import info.openrocket.swing.gui.util.GUIUtil;
import info.openrocket.swing.gui.util.Icons;
@ -74,32 +74,32 @@ public class SimulationPlotPanel extends JPanel {
private static final String CUSTOM = trans.get("simplotpanel.CUSTOM");
/** The "Custom" configuration - not to be used for anything other than the title. */
private static final PlotConfiguration CUSTOM_CONFIGURATION;
private static final SimulationPlotConfiguration CUSTOM_CONFIGURATION;
static {
CUSTOM_CONFIGURATION = new PlotConfiguration(CUSTOM);
CUSTOM_CONFIGURATION = new SimulationPlotConfiguration(CUSTOM);
}
/** The array of presets for the combo box. */
private static final PlotConfiguration[] PRESET_ARRAY;
private static final SimulationPlotConfiguration[] PRESET_ARRAY;
static {
PRESET_ARRAY = Arrays.copyOf(PlotConfiguration.DEFAULT_CONFIGURATIONS,
PlotConfiguration.DEFAULT_CONFIGURATIONS.length + 1);
PRESET_ARRAY = Arrays.copyOf(SimulationPlotConfiguration.DEFAULT_CONFIGURATIONS,
SimulationPlotConfiguration.DEFAULT_CONFIGURATIONS.length + 1);
PRESET_ARRAY[PRESET_ARRAY.length - 1] = CUSTOM_CONFIGURATION;
}
/** The current default configuration, set each time a plot is made. */
private static PlotConfiguration defaultConfiguration =
PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
private static SimulationPlotConfiguration defaultConfiguration =
SimulationPlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
private final Simulation simulation;
private final FlightDataType[] types;
private PlotConfiguration configuration;
private SimulationPlotConfiguration configuration;
private JComboBox<PlotConfiguration> configurationSelector;
private JComboBox<SimulationPlotConfiguration> configurationSelector;
private GroupableAndSearchableComboBox<FlightDataTypeGroup, FlightDataType> domainTypeSelector;
private UnitSelector domainUnitSelector;
@ -135,7 +135,7 @@ public class SimulationPlotPanel extends JPanel {
// Setup the combo box
configurationSelector = new JComboBox<>(PRESET_ARRAY);
for (PlotConfiguration config : PRESET_ARRAY) {
for (SimulationPlotConfiguration config : PRESET_ARRAY) {
if (config.getName().equals(configuration.getName())) {
configurationSelector.setSelectedItem(config);
}
@ -154,7 +154,7 @@ public class SimulationPlotPanel extends JPanel {
}
if (modifying > 0)
return;
PlotConfiguration conf = (PlotConfiguration) configurationSelector.getSelectedItem();
SimulationPlotConfiguration conf = (SimulationPlotConfiguration) configurationSelector.getSelectedItem();
if (conf == CUSTOM_CONFIGURATION)
return;
modifying++;
@ -421,7 +421,7 @@ public class SimulationPlotPanel extends JPanel {
return SimulationPlotDialog.getPlot(parent, simulation, configuration);
}
private void setConfiguration(PlotConfiguration conf) {
private void setConfiguration(SimulationPlotConfiguration conf) {
boolean modified = false;
@ -479,7 +479,7 @@ public class SimulationPlotPanel extends JPanel {
/**
* A JPanel which configures a single plot of a PlotConfiguration.
* A JPanel which configures a single plot of a SimulationPlotConfiguration.
*/
private class PlotTypeSelector extends JPanel {
private static final long serialVersionUID = 9056324972817542570L;
@ -565,7 +565,7 @@ public class SimulationPlotPanel extends JPanel {
this.add(button, "gapright 0");
}
}
private class FlightEventTableModel extends AbstractTableModel {