Refactor component analysis parameters to dedicated class

This commit is contained in:
SiboVG 2024-08-17 22:30:31 +02:00
parent 621ee57cc2
commit 74777df2d6
3 changed files with 117 additions and 20 deletions

View File

@ -1,11 +1,10 @@
package info.openrocket.swing.gui.dialogs; package info.openrocket.swing.gui.dialogs.componentanalysis;
import static info.openrocket.core.unit.Unit.NOUNIT; import static info.openrocket.core.unit.Unit.NOUNIT;
import static info.openrocket.core.util.Chars.ALPHA; import static info.openrocket.core.util.Chars.ALPHA;
import info.openrocket.core.aerodynamics.AerodynamicCalculator; import info.openrocket.core.aerodynamics.AerodynamicCalculator;
import info.openrocket.core.aerodynamics.AerodynamicForces; import info.openrocket.core.aerodynamics.AerodynamicForces;
import info.openrocket.core.aerodynamics.FlightConditions; import info.openrocket.core.aerodynamics.FlightConditions;
import info.openrocket.core.logging.Warning;
import info.openrocket.core.logging.WarningSet; import info.openrocket.core.logging.WarningSet;
import info.openrocket.core.l10n.Translator; import info.openrocket.core.l10n.Translator;
import info.openrocket.core.masscalc.CMAnalysisEntry; import info.openrocket.core.masscalc.CMAnalysisEntry;
@ -88,7 +87,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
private final JToggleButton worstToggle; private final JToggleButton worstToggle;
private boolean fakeChange = false; private boolean fakeChange = false;
private AerodynamicCalculator aerodynamicCalculator; private AerodynamicCalculator aerodynamicCalculator;
private double initTheta; private ComponentAnalysisParameters parameters;
private final ColumnTableModel longitudeStabilityTableModel; private final ColumnTableModel longitudeStabilityTableModel;
private final ColumnTableModel dragTableModel; private final ColumnTableModel dragTableModel;
@ -115,18 +114,15 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
rkt = rocketPanel.getDocument().getRocket(); rkt = rocketPanel.getDocument().getRocket();
this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance(); this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance();
conditions = new FlightConditions(rkt.getSelectedConfiguration()); conditions = new FlightConditions(rkt.getSelectedConfiguration());
rocketPanel.setCPAOA(0); // Create ComponentAnalysisParameters
aoa = new DoubleModel(rocketPanel, "CPAOA", UnitGroup.UNITS_ANGLE, 0, Math.PI); parameters = new ComponentAnalysisParameters(rkt, rocketPanel);
rocketPanel.setCPMach(Application.getPreferences().getDefaultMach());
mach = new DoubleModel(rocketPanel, "CPMach", UnitGroup.UNITS_COEFFICIENT, 0); aoa = new DoubleModel(parameters, "AOA", UnitGroup.UNITS_ANGLE, 0, Math.PI);
initTheta = rocketPanel.getFigure().getRotation(); mach = new DoubleModel(parameters, "Mach", UnitGroup.UNITS_COEFFICIENT, 0);
rocketPanel.setCPTheta(rocketPanel.getFigure().getRotation()); theta = new DoubleModel(parameters, "Theta", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
theta = new DoubleModel(rocketPanel, "CPTheta", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI); roll = new DoubleModel(parameters, "RollRate", UnitGroup.UNITS_ROLL);
rocketPanel.setCPRoll(0);
roll = new DoubleModel(rocketPanel, "CPRoll", UnitGroup.UNITS_ROLL);
//// Wind direction: //// Wind direction:
panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.winddir"))); panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.winddir")));
@ -435,7 +431,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosed(WindowEvent e) { public void windowClosed(WindowEvent e) {
theta.setValue(initTheta); theta.setValue(parameters.getInitialTheta());
//System.out.println("Closing method called: " + this); //System.out.println("Closing method called: " + this);
rkt.removeChangeListener(ComponentAnalysisDialog.this); rkt.removeChangeListener(ComponentAnalysisDialog.this);
@ -470,7 +466,13 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
// Buttons // Buttons
JButton button; JButton plotExportBtn = new JButton(trans.get("simpanel.but.plotexport"));
plotExportBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO: open plot/export dialog
}
});
// TODO: LOW: printing // TODO: LOW: printing
// button = new JButton("Print"); // button = new JButton("Print");
@ -487,16 +489,15 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
// }); // });
// panel.add(button,"tag ok"); // panel.add(button,"tag ok");
//button = new JButton("Close");
//Close button //Close button
button = new JButton(trans.get("dlg.but.close")); JButton closeBtn = new JButton(trans.get("dlg.but.close"));
button.addActionListener(new ActionListener() { closeBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ComponentAnalysisDialog.this.dispose(); ComponentAnalysisDialog.this.dispose();
} }
}); });
panel.add(button, "span, tag cancel"); panel.add(closeBtn, "span, tag cancel");
this.setLocationByPlatform(true); this.setLocationByPlatform(true);

View File

@ -0,0 +1,96 @@
package info.openrocket.swing.gui.dialogs.componentanalysis;
import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.startup.Application;
import info.openrocket.core.util.Mutable;
import info.openrocket.swing.gui.scalefigure.RocketPanel;
public class ComponentAnalysisParameters implements Cloneable {
private final Mutable mutable = new Mutable();
private final Rocket rocket;
private final RocketPanel rocketPanel;
private double theta;
private final double initialTheta;
private double aoa;
private double mach;
private double rollRate;
public ComponentAnalysisParameters(Rocket rocket, RocketPanel rocketPanel) {
this.rocket = rocket;
this.rocketPanel = rocketPanel;
setTheta(rocketPanel.getFigure().getRotation());
this.initialTheta = this.theta;
setAOA(0);
setMach(Application.getPreferences().getDefaultMach());
setRollRate(0);
}
public double getTheta() {
return theta;
}
public void setTheta(double theta) {
mutable.check();
this.theta = theta;
this.rocketPanel.setCPTheta(theta);
}
public double getInitialTheta() {
return initialTheta;
}
public double getAOA() {
return aoa;
}
public void setAOA(double aoa) {
mutable.check();
this.aoa = aoa;
this.rocketPanel.setCPAOA(aoa);
}
public double getMach() {
return mach;
}
public void setMach(double mach) {
mutable.check();
this.mach = mach;
this.rocketPanel.setCPMach(mach);
}
public double getRollRate() {
return rollRate;
}
public void setRollRate(double rollRate) {
mutable.check();
this.rollRate = rollRate;
this.rocketPanel.setCPRoll(rollRate);
}
public FlightConfiguration getSelectedConfiguration() {
return rocket.getSelectedConfiguration();
}
public void immute() {
mutable.immute();
}
public boolean isMutable() {
return mutable.isMutable();
}
@Override
public ComponentAnalysisParameters clone() {
try {
return (ComponentAnalysisParameters) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -89,7 +89,7 @@ import info.openrocket.swing.gui.configdialog.ComponentConfigDialog;
import info.openrocket.swing.gui.customexpression.CustomExpressionDialog; import info.openrocket.swing.gui.customexpression.CustomExpressionDialog;
import info.openrocket.swing.gui.dialogs.AboutDialog; import info.openrocket.swing.gui.dialogs.AboutDialog;
import info.openrocket.swing.gui.dialogs.BugReportDialog; import info.openrocket.swing.gui.dialogs.BugReportDialog;
import info.openrocket.swing.gui.dialogs.ComponentAnalysisDialog; import info.openrocket.swing.gui.dialogs.componentanalysis.ComponentAnalysisDialog;
import info.openrocket.swing.gui.dialogs.DebugLogDialog; import info.openrocket.swing.gui.dialogs.DebugLogDialog;
import info.openrocket.swing.gui.dialogs.DecalNotFoundDialog; import info.openrocket.swing.gui.dialogs.DecalNotFoundDialog;
import info.openrocket.swing.gui.dialogs.DetailDialog; import info.openrocket.swing.gui.dialogs.DetailDialog;