Merge pull request #2220 from SiboVG/issue-2079

[#2079] Display secondary stability unit
This commit is contained in:
Sibo Van Gool 2023-05-29 22:42:30 +02:00 committed by GitHub
commit 2fc2c6427b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 281 additions and 125 deletions

View File

@ -366,6 +366,10 @@ pref.dlg.lbl.Temperature = Temperature:
pref.dlg.lbl.Momentofinertia = Moment of inertia: pref.dlg.lbl.Momentofinertia = Moment of inertia:
pref.dlg.lbl.Pressure = Pressure: pref.dlg.lbl.Pressure = Pressure:
pref.dlg.lbl.Stability = Stability: pref.dlg.lbl.Stability = Stability:
pref.dlg.lbl.SecondaryStability = Secondary Stability:
pref.dlg.lbl.SecondaryStability.ttip = Select the stability unit that will be displayed alongside the main stability unit in the design view.
pref.dlg.checkbox.DisplaySecondaryStability = Display secondary stability unit
pref.dlg.checkbox.DisplaySecondaryStability.ttip = If checked, a secondary stability unit will be displayed in the rocket design view.
pref.dlg.lbl.FlightTime = Flight time: pref.dlg.lbl.FlightTime = Flight time:
pref.dlg.lbl.effect1 = The effects will take place the next time you open a window. pref.dlg.lbl.effect1 = The effects will take place the next time you open a window.
pref.dlg.lbl.Checkingupdates = Checking for updates\u2026 pref.dlg.lbl.Checkingupdates = Checking for updates\u2026

View File

@ -44,6 +44,10 @@ public abstract class Preferences implements ChangeSource {
public static final String USER_THRUST_CURVES_KEY = "UserThrustCurves"; public static final String USER_THRUST_CURVES_KEY = "UserThrustCurves";
public static final String DEFAULT_MACH_NUMBER = "DefaultMachNumber"; public static final String DEFAULT_MACH_NUMBER = "DefaultMachNumber";
// Preferences related to units
public static final String DISPLAY_SECONDARY_STABILITY = "DisplaySecondaryStability";
// Preferences related to data export // Preferences related to data export
public static final String EXPORT_FIELD_SEPARATOR = "ExportFieldSeparator"; public static final String EXPORT_FIELD_SEPARATOR = "ExportFieldSeparator";
public static final String EXPORT_DECIMAL_PLACES = "ExportDecimalPlaces"; public static final String EXPORT_DECIMAL_PLACES = "ExportDecimalPlaces";
@ -79,10 +83,10 @@ public abstract class Preferences implements ChangeSource {
private static final String OPEN_LEFTMOST_DESIGN_TAB = "OpenLeftmostDesignTab"; private static final String OPEN_LEFTMOST_DESIGN_TAB = "OpenLeftmostDesignTab";
private static final String SHOW_DISCARD_CONFIRMATION = "IgnoreDiscardEditingWarning"; private static final String SHOW_DISCARD_CONFIRMATION = "IgnoreDiscardEditingWarning";
private static final String SHOW_DISCARD_SIMULATION_CONFIRMATION = "IgnoreDiscardSimulationEditingWarning"; private static final String SHOW_DISCARD_SIMULATION_CONFIRMATION = "IgnoreDiscardSimulationEditingWarning";
public static final String MARKER_STYLE_ICON = "MARKER_STYLE_ICON"; public static final String MARKER_STYLE_ICON = "MarkerStyleIcon";
private static final String SHOW_MARKERS = "SHOW_MARKERS"; private static final String SHOW_MARKERS = "ShowMarkers";
private static final String SHOW_RASAERO_FORMAT_WARNING = "SHOW_RASAERO_FORMAT_WARNING"; private static final String SHOW_RASAERO_FORMAT_WARNING = "ShowRASAeroFormatWarning";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING"; private static final String SHOW_ROCKSIM_FORMAT_WARNING = "ShowRockSimFormatWarning";
private static final String EXPORT_USER_DIRECTORIES = "ExportUserDirectories"; private static final String EXPORT_USER_DIRECTORIES = "ExportUserDirectories";
private static final String EXPORT_WINDOW_INFORMATION = "ExportWindowInformation"; private static final String EXPORT_WINDOW_INFORMATION = "ExportWindowInformation";
@ -201,6 +205,27 @@ public abstract class Preferences implements ChangeSource {
} }
/*
* *********************** Unit Preferences *******************************************
*/
/**
* Return whether to display a secondary stability unit in the rocket design view.
* @return true if the secondary unit should be displayed, false if not.
*/
public final boolean isDisplaySecondaryStability() {
return this.getBoolean(DISPLAY_SECONDARY_STABILITY, true);
}
/**
* Set whether to display a secondary stability unit in the rocket design view.
* @param check if true, display the secondary unit, if false not.
*/
public final void setDisplaySecondaryStability(boolean check) {
this.putBoolean(DISPLAY_SECONDARY_STABILITY, check);
}
/* /*
* ****************************************************************************************** * ******************************************************************************************
*/ */

View File

@ -39,6 +39,8 @@ public class UnitGroup {
public static final UnitGroup UNITS_AREA; public static final UnitGroup UNITS_AREA;
public static final UnitGroup UNITS_STABILITY; public static final UnitGroup UNITS_STABILITY;
public static final UnitGroup UNITS_SECONDARY_STABILITY;
/** /**
* This unit group contains only the caliber unit that never scales the originating "SI" value. * This unit group contains only the caliber unit that never scales the originating "SI" value.
* It can be used in cases where the originating value is already in calibers to obtains the correct unit. * It can be used in cases where the originating value is already in calibers to obtains the correct unit.
@ -162,12 +164,10 @@ public class UnitGroup {
UNITS_STABILITY = new UnitGroup(); UNITS_STABILITY = new UnitGroup();
UNITS_STABILITY.addUnit(new GeneralUnit(0.001, "mm")); UNITS_SECONDARY_STABILITY = new UnitGroup();
UNITS_STABILITY.addUnit(new GeneralUnit(0.01, "cm")); addStabilityUnits(UNITS_STABILITY);
UNITS_STABILITY.addUnit(new GeneralUnit(1, "m")); addStabilityUnits(UNITS_SECONDARY_STABILITY);
UNITS_STABILITY.addUnit(new GeneralUnit(0.0254, "in"));
UNITS_STABILITY.addUnit(new CaliberUnit((Rocket) null));
UNITS_STABILITY.addUnit(new PercentageOfLengthUnit((Rocket) null));
UNITS_STABILITY_CALIBERS = new UnitGroup(); UNITS_STABILITY_CALIBERS = new UnitGroup();
UNITS_STABILITY_CALIBERS.addUnit(new GeneralUnit(1, "cal")); UNITS_STABILITY_CALIBERS.addUnit(new GeneralUnit(1, "cal"));
@ -310,6 +310,7 @@ public class UnitGroup {
map.put("ACCELERATION", UNITS_ACCELERATION); map.put("ACCELERATION", UNITS_ACCELERATION);
map.put("AREA", UNITS_AREA); map.put("AREA", UNITS_AREA);
map.put("STABILITY", UNITS_STABILITY); map.put("STABILITY", UNITS_STABILITY);
map.put("SECONDARY_STABILITY", UNITS_SECONDARY_STABILITY);
map.put("MASS", UNITS_MASS); map.put("MASS", UNITS_MASS);
map.put("INERTIA", UNITS_INERTIA); map.put("INERTIA", UNITS_INERTIA);
map.put("ANGLE", UNITS_ANGLE); map.put("ANGLE", UNITS_ANGLE);
@ -366,6 +367,7 @@ public class UnitGroup {
UNITS_DISTANCE.setDefaultUnit("m"); UNITS_DISTANCE.setDefaultUnit("m");
UNITS_AREA.setDefaultUnit("cm" + SQUARED); UNITS_AREA.setDefaultUnit("cm" + SQUARED);
UNITS_STABILITY.setDefaultUnit("cal"); UNITS_STABILITY.setDefaultUnit("cal");
UNITS_SECONDARY_STABILITY.setDefaultUnit("%");
UNITS_VELOCITY.setDefaultUnit("m/s"); UNITS_VELOCITY.setDefaultUnit("m/s");
UNITS_ACCELERATION.setDefaultUnit("m/s" + SQUARED); UNITS_ACCELERATION.setDefaultUnit("m/s" + SQUARED);
UNITS_MASS.setDefaultUnit("g"); UNITS_MASS.setDefaultUnit("g");
@ -392,6 +394,7 @@ public class UnitGroup {
UNITS_DISTANCE.setDefaultUnit("ft"); UNITS_DISTANCE.setDefaultUnit("ft");
UNITS_AREA.setDefaultUnit("in" + SQUARED); UNITS_AREA.setDefaultUnit("in" + SQUARED);
UNITS_STABILITY.setDefaultUnit("cal"); UNITS_STABILITY.setDefaultUnit("cal");
UNITS_SECONDARY_STABILITY.setDefaultUnit("%");
UNITS_VELOCITY.setDefaultUnit("ft/s"); UNITS_VELOCITY.setDefaultUnit("ft/s");
UNITS_ACCELERATION.setDefaultUnit("ft/s" + SQUARED); UNITS_ACCELERATION.setDefaultUnit("ft/s" + SQUARED);
UNITS_MASS.setDefaultUnit("oz"); UNITS_MASS.setDefaultUnit("oz");
@ -425,6 +428,7 @@ public class UnitGroup {
UNITS_ALL_LENGTHS.setDefaultUnit(2); UNITS_ALL_LENGTHS.setDefaultUnit(2);
UNITS_AREA.setDefaultUnit(1); UNITS_AREA.setDefaultUnit(1);
UNITS_STABILITY.setDefaultUnit(4); UNITS_STABILITY.setDefaultUnit(4);
UNITS_SECONDARY_STABILITY.setDefaultUnit(5);
UNITS_STABILITY_CALIBERS.setDefaultUnit(0); UNITS_STABILITY_CALIBERS.setDefaultUnit(0);
UNITS_VELOCITY.setDefaultUnit(0); UNITS_VELOCITY.setDefaultUnit(0);
UNITS_WINDSPEED.setDefaultUnit(0); UNITS_WINDSPEED.setDefaultUnit(0);
@ -449,6 +453,15 @@ public class UnitGroup {
UNITS_FREQUENCY.setDefaultUnit(1); UNITS_FREQUENCY.setDefaultUnit(1);
} }
private static void addStabilityUnits(UnitGroup stabilityUnit) {
stabilityUnit.addUnit(new GeneralUnit(0.001, "mm"));
stabilityUnit.addUnit(new GeneralUnit(0.01, "cm"));
stabilityUnit.addUnit(new GeneralUnit(1, "m"));
stabilityUnit.addUnit(new GeneralUnit(0.0254, "in"));
stabilityUnit.addUnit(new CaliberUnit((Rocket) null));
stabilityUnit.addUnit(new PercentageOfLengthUnit((Rocket) null));
}
/** /**
* Return a UnitGroup for stability units based on the rocket. * Return a UnitGroup for stability units based on the rocket.
@ -456,8 +469,18 @@ public class UnitGroup {
* @param rocket the rocket from which to calculate the caliber * @param rocket the rocket from which to calculate the caliber
* @return the unit group * @return the unit group
*/ */
public static UnitGroup stabilityUnits(Rocket rocket) { public static StabilityUnitGroup stabilityUnits(Rocket rocket) {
return new StabilityUnitGroup(rocket); return new StabilityUnitGroup(UnitGroup.UNITS_STABILITY, rocket);
}
/**
* Return a UnitGroup for secondary stability units based on the rocket.
*
* @param rocket the rocket from which to calculate the caliber
* @return the unit group
*/
public static StabilityUnitGroup secondaryStabilityUnits(Rocket rocket) {
return new StabilityUnitGroup(UnitGroup.UNITS_SECONDARY_STABILITY, rocket);
} }
@ -467,8 +490,18 @@ public class UnitGroup {
* @param config the rocket configuration from which to calculate the caliber * @param config the rocket configuration from which to calculate the caliber
* @return the unit group * @return the unit group
*/ */
public static UnitGroup stabilityUnits(FlightConfiguration config) { public static StabilityUnitGroup stabilityUnits(FlightConfiguration config) {
return new StabilityUnitGroup(config); return new StabilityUnitGroup(UnitGroup.UNITS_STABILITY, config);
}
/**
* Return a UnitGroup for stability units based on the rocket configuration.
*
* @param config the rocket configuration from which to calculate the caliber
* @return the unit group
*/
public static StabilityUnitGroup secondaryStabilityUnits(FlightConfiguration config) {
return new StabilityUnitGroup(UnitGroup.UNITS_SECONDARY_STABILITY, config);
} }
@ -479,7 +512,17 @@ public class UnitGroup {
* @return the unit group * @return the unit group
*/ */
public static UnitGroup stabilityUnits(double reference) { public static UnitGroup stabilityUnits(double reference) {
return new StabilityUnitGroup(reference); return new StabilityUnitGroup(UnitGroup.UNITS_STABILITY, reference);
}
/**
* Return a UnitGroup for secondary stability units based on a constant caliber.
*
* @param reference the constant reference length
* @return the unit group
*/
public static UnitGroup secondaryStabilityUnits(double reference) {
return new StabilityUnitGroup(UnitGroup.UNITS_SECONDARY_STABILITY, reference);
} }
@ -717,19 +760,27 @@ public class UnitGroup {
* A private class that switches the CaliberUnit to a rocket-specific CaliberUnit. * A private class that switches the CaliberUnit to a rocket-specific CaliberUnit.
* All other methods are passed through to UNITS_STABILITY. * All other methods are passed through to UNITS_STABILITY.
*/ */
private static class StabilityUnitGroup extends UnitGroup { public static class StabilityUnitGroup extends UnitGroup {
private final PercentageOfLengthUnit percentageOfLengthUnit;
private final UnitGroup stabilityUnit;
public StabilityUnitGroup(double ref) { this(new CaliberUnit(ref), new PercentageOfLengthUnit(ref)); } public StabilityUnitGroup(UnitGroup stabilityUnit, double ref) {
this(stabilityUnit, new CaliberUnit(ref), new PercentageOfLengthUnit(ref));
public StabilityUnitGroup(Rocket rocket) {
this(new CaliberUnit(rocket), new PercentageOfLengthUnit(rocket));
} }
public StabilityUnitGroup(FlightConfiguration config) { this(new CaliberUnit(config), new PercentageOfLengthUnit(config)); } public StabilityUnitGroup(UnitGroup stabilityUnit, Rocket rocket) {
this(stabilityUnit, new CaliberUnit(rocket), new PercentageOfLengthUnit(rocket));
}
private StabilityUnitGroup(CaliberUnit caliberUnit, PercentageOfLengthUnit percentageOfLengthUnit) { public StabilityUnitGroup(UnitGroup stabilityUnit, FlightConfiguration config) {
this.units.addAll(UnitGroup.UNITS_STABILITY.units); this(stabilityUnit, new CaliberUnit(config), new PercentageOfLengthUnit(config));
this.defaultUnit = UnitGroup.UNITS_STABILITY.defaultUnit; }
private StabilityUnitGroup(UnitGroup stabilityUnit, CaliberUnit caliberUnit, PercentageOfLengthUnit percentageOfLengthUnit) {
this.percentageOfLengthUnit = percentageOfLengthUnit;
this.stabilityUnit = stabilityUnit;
this.units.addAll(stabilityUnit.units);
this.defaultUnit = stabilityUnit.defaultUnit;
for (int i = 0; i < units.size(); i++) { for (int i = 0; i < units.size(); i++) {
if (units.get(i) instanceof CaliberUnit) { if (units.get(i) instanceof CaliberUnit) {
units.set(i, caliberUnit); units.set(i, caliberUnit);
@ -744,7 +795,15 @@ public class UnitGroup {
@Override @Override
public void setDefaultUnit(int n) { public void setDefaultUnit(int n) {
super.setDefaultUnit(n); super.setDefaultUnit(n);
UNITS_STABILITY.setDefaultUnit(n); this.stabilityUnit.setDefaultUnit(n);
}
/**
* Returns the percentage of length unit. (Stability in %)
* @return the percentage of length unit.
*/
public Unit getPercentageOfLengthUnit() {
return this.percentageOfLengthUnit;
} }
} }
} }

View File

@ -3,11 +3,15 @@ package net.sf.openrocket.gui.dialogs.preferences;
import java.awt.LayoutManager; import java.awt.LayoutManager;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
@ -18,122 +22,146 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
public class UnitsPreferencesPanel extends PreferencesPanel { public class UnitsPreferencesPanel extends PreferencesPanel {
public UnitsPreferencesPanel(JDialog parent) { public UnitsPreferencesPanel(JDialog parent) {
super(parent, new MigLayout("", "[][]40lp[][]")); super(parent, new MigLayout("", "[]40lp[]"));
JComboBox<?> combo; JComboBox<?> combo;
JPanel leftPanel = new JPanel(new MigLayout("ins 0"));
JPanel rightPanel = new JPanel(new MigLayout("ins 0"));
//// Select your preferred units: //// Select your preferred units:
this.add(new JLabel(trans.get("pref.dlg.lbl.Selectprefunits")), "span, wrap paragraph"); this.add(new JLabel(trans.get("pref.dlg.lbl.Selectprefunits")), "span, wrap paragraph");
// -------------- LEFT PANEL
//// Rocket dimensions: //// Rocket dimensions:
this.add(new JLabel(trans.get("pref.dlg.lbl.Rocketdimensions"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Rocketdimensions")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_LENGTH)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_LENGTH));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Line density:
this.add(new JLabel(trans.get("pref.dlg.lbl.Linedensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_LINE));
this.add(combo, "sizegroup boxes, wrap");
//// Motor dimensions: //// Motor dimensions:
this.add(new JLabel(trans.get("pref.dlg.lbl.Motordimensions"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Motordimensions")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_MOTOR_DIMENSIONS)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_MOTOR_DIMENSIONS));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Surface density:
this.add(new JLabel(trans.get("pref.dlg.lbl.Surfacedensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_SURFACE));
this.add(combo, "sizegroup boxes, wrap");
//// Distance: //// Distance:
this.add(new JLabel(trans.get("pref.dlg.lbl.Distance"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Distance")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DISTANCE)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DISTANCE));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Bulk density::
this.add(new JLabel(trans.get("pref.dlg.lbl.Bulkdensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_BULK));
this.add(combo, "sizegroup boxes, wrap");
//// Velocity: //// Velocity:
this.add(new JLabel(trans.get("pref.dlg.lbl.Velocity"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Velocity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_VELOCITY)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_VELOCITY));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Surface roughness:
this.add(new JLabel(trans.get("pref.dlg.lbl.Surfaceroughness")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ROUGHNESS));
this.add(combo, "sizegroup boxes, wrap");
//// Acceleration: //// Acceleration:
this.add(new JLabel(trans.get("pref.dlg.lbl.Acceleration"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Acceleration")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ACCELERATION)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ACCELERATION));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Area:
this.add(new JLabel(trans.get("pref.dlg.lbl.Area")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_AREA));
this.add(combo, "sizegroup boxes, wrap");
//// Mass: //// Mass:
this.add(new JLabel(trans.get("pref.dlg.lbl.Mass"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Mass")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_MASS)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_MASS));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Angle:
this.add(new JLabel(trans.get("pref.dlg.lbl.Angle")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ANGLE));
this.add(combo, "sizegroup boxes, wrap");
//// Force: //// Force:
this.add(new JLabel(trans.get("pref.dlg.lbl.Force"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Force")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_FORCE)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_FORCE));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Roll rate:
this.add(new JLabel(trans.get("pref.dlg.lbl.Rollrate")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ROLL));
this.add(combo, "sizegroup boxes, wrap");
//// Total impulse: //// Total impulse:
this.add(new JLabel(trans.get("pref.dlg.lbl.Totalimpulse"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Totalimpulse")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_IMPULSE)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_IMPULSE));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Temperature:
this.add(new JLabel(trans.get("pref.dlg.lbl.Temperature")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_TEMPERATURE));
this.add(combo, "sizegroup boxes, wrap");
//// Moment of inertia: //// Moment of inertia:
this.add(new JLabel(trans.get("pref.dlg.lbl.Momentofinertia"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Momentofinertia")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_INERTIA)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_INERTIA));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Pressure:
this.add(new JLabel(trans.get("pref.dlg.lbl.Pressure")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_PRESSURE));
this.add(combo, "sizegroup boxes, wrap");
//// Stability: //// Stability:
this.add(new JLabel(trans.get("pref.dlg.lbl.Stability"))); leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Stability")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_STABILITY)); combo = new JComboBox<>(new DefaultUnitSelector(UnitGroup.UNITS_STABILITY));
this.add(combo, "sizegroup boxes"); leftPanel.add(combo, "sizegroup boxes, wrap");
//// Secondary stability:
final JLabel labelSecStab = new JLabel(trans.get("pref.dlg.lbl.SecondaryStability"));
labelSecStab.setToolTipText(trans.get("pref.dlg.lbl.SecondaryStability.ttip"));
labelSecStab.setEnabled(preferences.isDisplaySecondaryStability());
leftPanel.add(labelSecStab);
final JComboBox<?> comboSecStab = new JComboBox<>(new DefaultUnitSelector(UnitGroup.UNITS_SECONDARY_STABILITY));
comboSecStab.setToolTipText(trans.get("pref.dlg.lbl.SecondaryStability.ttip"));
comboSecStab.setEnabled(preferences.isDisplaySecondaryStability());
leftPanel.add(comboSecStab, "sizegroup boxes, wrap");
//// Display secondary stability unit:
JCheckBox displaySecondary = new JCheckBox(trans.get("pref.dlg.checkbox.DisplaySecondaryStability"));
displaySecondary.setToolTipText(trans.get("pref.dlg.checkbox.DisplaySecondaryStability.ttip"));
displaySecondary.setSelected(preferences.isDisplaySecondaryStability());
displaySecondary.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
preferences.setDisplaySecondaryStability(e.getStateChange() == ItemEvent.SELECTED);
labelSecStab.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
comboSecStab.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
}
});
leftPanel.add(displaySecondary, "spanx, wrap");
// -------------- RIGHT PANEL
//// Line density:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Linedensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_LINE));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Surface density:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Surfacedensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_SURFACE));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Bulk density::
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Bulkdensity")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_DENSITY_BULK));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Surface roughness:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Surfaceroughness")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ROUGHNESS));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Area:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Area")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_AREA));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Angle:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Angle")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ANGLE));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Roll rate:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Rollrate")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_ROLL));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Temperature:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Temperature")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_TEMPERATURE));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Pressure:
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Pressure")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_PRESSURE));
rightPanel.add(combo, "sizegroup boxes, wrap");
//// Windspeed: //// Windspeed:
this.add(new JLabel(trans.get("pref.dlg.lbl.Windspeed"))); rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Windspeed")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_WINDSPEED)); combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_WINDSPEED));
this.add(combo, "sizegroup boxes, wrap para"); rightPanel.add(combo, "sizegroup boxes, wrap");
this.add(leftPanel, "top");
this.add(rightPanel, "top, wrap para");
//// Default metric button //// Default metric button

View File

@ -11,6 +11,7 @@ import java.awt.Rectangle;
import java.awt.font.GlyphVector; import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.logging.Warning; import net.sf.openrocket.logging.Warning;
import net.sf.openrocket.logging.WarningSet; import net.sf.openrocket.logging.WarningSet;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
@ -31,6 +32,7 @@ import net.sf.openrocket.util.MathUtil;
public class RocketInfo implements FigureElement { public class RocketInfo implements FigureElement {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
// Margin around the figure edges, pixels // Margin around the figure edges, pixels
private static final int MARGIN = 8; private static final int MARGIN = 8;
@ -41,7 +43,8 @@ public class RocketInfo implements FigureElement {
private final Caret cpCaret = new CPCaret(0,0); private final Caret cpCaret = new CPCaret(0,0);
private final Caret cgCaret = new CGCaret(0,0); private final Caret cgCaret = new CGCaret(0,0);
private UnitGroup stabilityUnits; private UnitGroup.StabilityUnitGroup stabilityUnits;
private UnitGroup.StabilityUnitGroup secondaryStabilityUnits;
private FlightConfiguration configuration; private FlightConfiguration configuration;
private double cg = 0, cp = 0; private double cg = 0, cp = 0;
@ -66,6 +69,7 @@ public class RocketInfo implements FigureElement {
public RocketInfo(FlightConfiguration configuration) { public RocketInfo(FlightConfiguration configuration) {
this.configuration = configuration; this.configuration = configuration;
this.stabilityUnits = UnitGroup.stabilityUnits(configuration); this.stabilityUnits = UnitGroup.stabilityUnits(configuration);
this.secondaryStabilityUnits = UnitGroup.secondaryStabilityUnits(configuration);
} }
@ -189,19 +193,9 @@ public class RocketInfo implements FigureElement {
private void drawStabilityInfo() { private void drawStabilityInfo() {
String at;
//// at M=
at = trans.get("RocketInfo.at")+UnitGroup.UNITS_COEFFICIENT.getDefaultUnit().toStringUnit(this.mach);
if (!Double.isNaN(aoa)) {
at += " "+ALPHA+"=" + UnitGroup.UNITS_ANGLE.getDefaultUnit().toStringUnit(aoa);
}
if (!Double.isNaN(theta)) {
at += " "+THETA+"=" + UnitGroup.UNITS_ANGLE.getDefaultUnit().toStringUnit(theta);
}
GlyphVector cgValue = createText(getCg()); GlyphVector cgValue = createText(getCg());
GlyphVector cpValue = createText(getCp()); GlyphVector cpValue = createText(getCp());
GlyphVector stabValue = createText(getStability()); GlyphVector stabValue = createText(getStabilityCombined());
//// CG: //// CG:
GlyphVector cgText = createText(trans.get("RocketInfo.cgText")); GlyphVector cgText = createText(trans.get("RocketInfo.cgText"));
@ -209,6 +203,15 @@ public class RocketInfo implements FigureElement {
GlyphVector cpText = createText(trans.get("RocketInfo.cpText")); GlyphVector cpText = createText(trans.get("RocketInfo.cpText"));
//// Stability: //// Stability:
GlyphVector stabText = createText(trans.get("RocketInfo.stabText")); GlyphVector stabText = createText(trans.get("RocketInfo.stabText"));
//// at M=...
String at = trans.get("RocketInfo.at")+UnitGroup.UNITS_COEFFICIENT.getDefaultUnit().toStringUnit(this.mach);
if (!Double.isNaN(aoa)) {
at += " "+ALPHA+"=" + UnitGroup.UNITS_ANGLE.getDefaultUnit().toStringUnit(aoa);
}
if (!Double.isNaN(theta)) {
at += " "+THETA+"=" + UnitGroup.UNITS_ANGLE.getDefaultUnit().toStringUnit(theta);
}
GlyphVector atText = createSmallText(at); GlyphVector atText = createSmallText(at);
// GlyphVector visual bounds drops the spaces, so we'll add them // GlyphVector visual bounds drops the spaces, so we'll add them
@ -277,13 +280,49 @@ public class RocketInfo implements FigureElement {
return u.toStringUnit(massWithMotors); return u.toStringUnit(massWithMotors);
} }
/** /**
* Get the stability, in calibers. * Get the stability in both the selected stability unit and in percentage, e.g. "2.4 cal (14.1 %)".
* If the current unit is already the percentage length unit, only use that.
* *
* @return the current stability margin * @return the current stability margin in the currently selected stability unit and in percentage
*/ */
public String getStability () { public String getStabilityCombined() {
return stabilityUnits.getDefaultUnit().toStringUnit(cp-cg); Unit stabilityUnit = stabilityUnits.getDefaultUnit();
Unit secondaryStabilityUnit = secondaryStabilityUnits.getDefaultUnit();
String stabilityStr = getStability();
// Don't display secondary units if the stability is NaN, or if the secondary unit is the same as the primary unit,
// or if it is disabled in the preferences
if (Double.isNaN(getStabilityValue()) || secondaryStabilityUnit.equals(stabilityUnit) ||
!preferences.isDisplaySecondaryStability()) {
return stabilityStr;
}
String secondaryStabilityStr = getSecondaryStability();
return stabilityStr + " / " + secondaryStabilityStr;
}
/**
* Get the stability in the currently selected unit.
* @return the current stability margin in the currently selected stability unit
*/
private String getStability() {
return stabilityUnits.getDefaultUnit().toStringUnit(getStabilityValue());
}
/**
* Get the stability in the secondary stability unit.
* @return the current stability margin in the secondary stability unit
*/
private String getSecondaryStability() {
return secondaryStabilityUnits.getDefaultUnit().toStringUnit(getStabilityValue());
}
private double getStabilityValue() {
return cp - cg;
} }
/** /**
@ -478,5 +517,6 @@ public class RocketInfo implements FigureElement {
public void setCurrentConfig(FlightConfiguration newConfig) { public void setCurrentConfig(FlightConfiguration newConfig) {
this.configuration = newConfig; this.configuration = newConfig;
this.stabilityUnits = UnitGroup.stabilityUnits(newConfig); this.stabilityUnits = UnitGroup.stabilityUnits(newConfig);
this.secondaryStabilityUnits = UnitGroup.secondaryStabilityUnits(newConfig);
} }
} }

View File

@ -256,7 +256,7 @@ public class DesignReport {
canvas.showText(text.getMassWithMotors(UnitGroup.UNITS_MASS.getDefaultUnit())); canvas.showText(text.getMassWithMotors(UnitGroup.UNITS_MASS.getDefaultUnit()));
canvas.newlineShowText(STABILITY); canvas.newlineShowText(STABILITY);
canvas.showText(text.getStability()); canvas.showText(text.getStabilityCombined());
canvas.newlineShowText(CG); canvas.newlineShowText(CG);
canvas.showText(text.getCg()); canvas.showText(text.getCg());