Refactor component analysis parameters to dedicated class
This commit is contained in:
		
							parent
							
								
									621ee57cc2
								
							
						
					
					
						commit
						74777df2d6
					
				@ -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.util.Chars.ALPHA;
 | 
			
		||||
import info.openrocket.core.aerodynamics.AerodynamicCalculator;
 | 
			
		||||
import info.openrocket.core.aerodynamics.AerodynamicForces;
 | 
			
		||||
import info.openrocket.core.aerodynamics.FlightConditions;
 | 
			
		||||
import info.openrocket.core.logging.Warning;
 | 
			
		||||
import info.openrocket.core.logging.WarningSet;
 | 
			
		||||
import info.openrocket.core.l10n.Translator;
 | 
			
		||||
import info.openrocket.core.masscalc.CMAnalysisEntry;
 | 
			
		||||
@ -88,7 +87,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
 | 
			
		||||
	private final JToggleButton worstToggle;
 | 
			
		||||
	private boolean fakeChange = false;
 | 
			
		||||
	private AerodynamicCalculator aerodynamicCalculator;
 | 
			
		||||
	private double initTheta;
 | 
			
		||||
	private ComponentAnalysisParameters parameters;
 | 
			
		||||
 | 
			
		||||
	private final ColumnTableModel longitudeStabilityTableModel;
 | 
			
		||||
	private final ColumnTableModel dragTableModel;
 | 
			
		||||
@ -115,18 +114,15 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
 | 
			
		||||
		rkt = rocketPanel.getDocument().getRocket();
 | 
			
		||||
		this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		conditions = new FlightConditions(rkt.getSelectedConfiguration());
 | 
			
		||||
 | 
			
		||||
		rocketPanel.setCPAOA(0);
 | 
			
		||||
		aoa = new DoubleModel(rocketPanel, "CPAOA", UnitGroup.UNITS_ANGLE, 0, Math.PI);
 | 
			
		||||
		rocketPanel.setCPMach(Application.getPreferences().getDefaultMach());
 | 
			
		||||
		mach = new DoubleModel(rocketPanel, "CPMach", UnitGroup.UNITS_COEFFICIENT, 0);
 | 
			
		||||
		initTheta = rocketPanel.getFigure().getRotation();
 | 
			
		||||
		rocketPanel.setCPTheta(rocketPanel.getFigure().getRotation());
 | 
			
		||||
		theta = new DoubleModel(rocketPanel, "CPTheta", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
 | 
			
		||||
		rocketPanel.setCPRoll(0);
 | 
			
		||||
		roll = new DoubleModel(rocketPanel, "CPRoll", UnitGroup.UNITS_ROLL);
 | 
			
		||||
		// Create ComponentAnalysisParameters
 | 
			
		||||
		parameters = new ComponentAnalysisParameters(rkt, rocketPanel);
 | 
			
		||||
 | 
			
		||||
		aoa = new DoubleModel(parameters, "AOA", UnitGroup.UNITS_ANGLE, 0, Math.PI);
 | 
			
		||||
		mach = new DoubleModel(parameters, "Mach", UnitGroup.UNITS_COEFFICIENT, 0);
 | 
			
		||||
		theta = new DoubleModel(parameters, "Theta", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
 | 
			
		||||
		roll = new DoubleModel(parameters, "RollRate", UnitGroup.UNITS_ROLL);
 | 
			
		||||
 | 
			
		||||
		//// Wind direction:
 | 
			
		||||
		panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.winddir")));
 | 
			
		||||
@ -435,7 +431,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
 | 
			
		||||
		this.addWindowListener(new WindowAdapter() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void windowClosed(WindowEvent e) {
 | 
			
		||||
				theta.setValue(initTheta);
 | 
			
		||||
				theta.setValue(parameters.getInitialTheta());
 | 
			
		||||
 | 
			
		||||
				//System.out.println("Closing method called: " + this);
 | 
			
		||||
				rkt.removeChangeListener(ComponentAnalysisDialog.this);
 | 
			
		||||
@ -470,7 +466,13 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// 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
 | 
			
		||||
		//		button = new JButton("Print");
 | 
			
		||||
@ -487,16 +489,15 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
 | 
			
		||||
		//		});
 | 
			
		||||
		//		panel.add(button,"tag ok");
 | 
			
		||||
 | 
			
		||||
		//button = new JButton("Close");
 | 
			
		||||
		//Close button
 | 
			
		||||
		button = new JButton(trans.get("dlg.but.close"));
 | 
			
		||||
		button.addActionListener(new ActionListener() {
 | 
			
		||||
		JButton closeBtn = new JButton(trans.get("dlg.but.close"));
 | 
			
		||||
		closeBtn.addActionListener(new ActionListener() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void actionPerformed(ActionEvent e) {
 | 
			
		||||
				ComponentAnalysisDialog.this.dispose();
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		panel.add(button, "span, tag cancel");
 | 
			
		||||
		panel.add(closeBtn, "span, tag cancel");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		this.setLocationByPlatform(true);
 | 
			
		||||
@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -89,7 +89,7 @@ import info.openrocket.swing.gui.configdialog.ComponentConfigDialog;
 | 
			
		||||
import info.openrocket.swing.gui.customexpression.CustomExpressionDialog;
 | 
			
		||||
import info.openrocket.swing.gui.dialogs.AboutDialog;
 | 
			
		||||
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.DecalNotFoundDialog;
 | 
			
		||||
import info.openrocket.swing.gui.dialogs.DetailDialog;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user