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.Pressure = Pressure:
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.effect1 = The effects will take place the next time you open a window.
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 DEFAULT_MACH_NUMBER = "DefaultMachNumber";
// Preferences related to units
public static final String DISPLAY_SECONDARY_STABILITY = "DisplaySecondaryStability";
// Preferences related to data export
public static final String EXPORT_FIELD_SEPARATOR = "ExportFieldSeparator";
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 SHOW_DISCARD_CONFIRMATION = "IgnoreDiscardEditingWarning";
private static final String SHOW_DISCARD_SIMULATION_CONFIRMATION = "IgnoreDiscardSimulationEditingWarning";
public static final String MARKER_STYLE_ICON = "MARKER_STYLE_ICON";
private static final String SHOW_MARKERS = "SHOW_MARKERS";
private static final String SHOW_RASAERO_FORMAT_WARNING = "SHOW_RASAERO_FORMAT_WARNING";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING";
public static final String MARKER_STYLE_ICON = "MarkerStyleIcon";
private static final String SHOW_MARKERS = "ShowMarkers";
private static final String SHOW_RASAERO_FORMAT_WARNING = "ShowRASAeroFormatWarning";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "ShowRockSimFormatWarning";
private static final String EXPORT_USER_DIRECTORIES = "ExportUserDirectories";
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_STABILITY;
public static final UnitGroup UNITS_SECONDARY_STABILITY;
/**
* 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.
@ -162,12 +164,10 @@ public class UnitGroup {
UNITS_STABILITY = new UnitGroup();
UNITS_STABILITY.addUnit(new GeneralUnit(0.001, "mm"));
UNITS_STABILITY.addUnit(new GeneralUnit(0.01, "cm"));
UNITS_STABILITY.addUnit(new GeneralUnit(1, "m"));
UNITS_STABILITY.addUnit(new GeneralUnit(0.0254, "in"));
UNITS_STABILITY.addUnit(new CaliberUnit((Rocket) null));
UNITS_STABILITY.addUnit(new PercentageOfLengthUnit((Rocket) null));
UNITS_SECONDARY_STABILITY = new UnitGroup();
addStabilityUnits(UNITS_STABILITY);
addStabilityUnits(UNITS_SECONDARY_STABILITY);
UNITS_STABILITY_CALIBERS = new UnitGroup();
UNITS_STABILITY_CALIBERS.addUnit(new GeneralUnit(1, "cal"));
@ -310,6 +310,7 @@ public class UnitGroup {
map.put("ACCELERATION", UNITS_ACCELERATION);
map.put("AREA", UNITS_AREA);
map.put("STABILITY", UNITS_STABILITY);
map.put("SECONDARY_STABILITY", UNITS_SECONDARY_STABILITY);
map.put("MASS", UNITS_MASS);
map.put("INERTIA", UNITS_INERTIA);
map.put("ANGLE", UNITS_ANGLE);
@ -366,6 +367,7 @@ public class UnitGroup {
UNITS_DISTANCE.setDefaultUnit("m");
UNITS_AREA.setDefaultUnit("cm" + SQUARED);
UNITS_STABILITY.setDefaultUnit("cal");
UNITS_SECONDARY_STABILITY.setDefaultUnit("%");
UNITS_VELOCITY.setDefaultUnit("m/s");
UNITS_ACCELERATION.setDefaultUnit("m/s" + SQUARED);
UNITS_MASS.setDefaultUnit("g");
@ -392,6 +394,7 @@ public class UnitGroup {
UNITS_DISTANCE.setDefaultUnit("ft");
UNITS_AREA.setDefaultUnit("in" + SQUARED);
UNITS_STABILITY.setDefaultUnit("cal");
UNITS_SECONDARY_STABILITY.setDefaultUnit("%");
UNITS_VELOCITY.setDefaultUnit("ft/s");
UNITS_ACCELERATION.setDefaultUnit("ft/s" + SQUARED);
UNITS_MASS.setDefaultUnit("oz");
@ -425,6 +428,7 @@ public class UnitGroup {
UNITS_ALL_LENGTHS.setDefaultUnit(2);
UNITS_AREA.setDefaultUnit(1);
UNITS_STABILITY.setDefaultUnit(4);
UNITS_SECONDARY_STABILITY.setDefaultUnit(5);
UNITS_STABILITY_CALIBERS.setDefaultUnit(0);
UNITS_VELOCITY.setDefaultUnit(0);
UNITS_WINDSPEED.setDefaultUnit(0);
@ -448,6 +452,15 @@ public class UnitGroup {
UNITS_COEFFICIENT.setDefaultUnit(0);
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));
}
/**
@ -456,8 +469,18 @@ public class UnitGroup {
* @param rocket the rocket from which to calculate the caliber
* @return the unit group
*/
public static UnitGroup stabilityUnits(Rocket rocket) {
return new StabilityUnitGroup(rocket);
public static StabilityUnitGroup stabilityUnits(Rocket 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
* @return the unit group
*/
public static UnitGroup stabilityUnits(FlightConfiguration config) {
return new StabilityUnitGroup(config);
public static StabilityUnitGroup stabilityUnits(FlightConfiguration 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
*/
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.
* 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(Rocket rocket) {
this(new CaliberUnit(rocket), new PercentageOfLengthUnit(rocket));
public StabilityUnitGroup(UnitGroup stabilityUnit, double ref) {
this(stabilityUnit, new CaliberUnit(ref), new PercentageOfLengthUnit(ref));
}
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) {
this.units.addAll(UnitGroup.UNITS_STABILITY.units);
this.defaultUnit = UnitGroup.UNITS_STABILITY.defaultUnit;
public StabilityUnitGroup(UnitGroup stabilityUnit, FlightConfiguration config) {
this(stabilityUnit, new CaliberUnit(config), new PercentageOfLengthUnit(config));
}
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++) {
if (units.get(i) instanceof CaliberUnit) {
units.set(i, caliberUnit);
@ -744,7 +795,15 @@ public class UnitGroup {
@Override
public void setDefaultUnit(int 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.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel;
@ -18,122 +22,146 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
public class UnitsPreferencesPanel extends PreferencesPanel {
public UnitsPreferencesPanel(JDialog parent) {
super(parent, new MigLayout("", "[][]40lp[][]"));
super(parent, new MigLayout("", "[]40lp[]"));
JComboBox<?> combo;
JPanel leftPanel = new JPanel(new MigLayout("ins 0"));
JPanel rightPanel = new JPanel(new MigLayout("ins 0"));
//// Select your preferred units:
this.add(new JLabel(trans.get("pref.dlg.lbl.Selectprefunits")), "span, wrap paragraph");
// -------------- LEFT PANEL
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// 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));
this.add(combo, "sizegroup boxes");
//// 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");
leftPanel.add(combo, "sizegroup boxes, wrap");
//// Stability:
this.add(new JLabel(trans.get("pref.dlg.lbl.Stability")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_STABILITY));
this.add(combo, "sizegroup boxes");
leftPanel.add(new JLabel(trans.get("pref.dlg.lbl.Stability")));
combo = new JComboBox<>(new DefaultUnitSelector(UnitGroup.UNITS_STABILITY));
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:
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));
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
@ -165,7 +193,7 @@ public class UnitsPreferencesPanel extends PreferencesPanel {
trans.get("pref.dlg.lbl.effect1"), -2, Style.ITALIC),
"spanx, wrap");
}
}
public UnitsPreferencesPanel(LayoutManager layout) {
super(layout);

View File

@ -11,6 +11,7 @@ import java.awt.Rectangle;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.logging.Warning;
import net.sf.openrocket.logging.WarningSet;
import net.sf.openrocket.l10n.Translator;
@ -31,6 +32,7 @@ import net.sf.openrocket.util.MathUtil;
public class RocketInfo implements FigureElement {
private static final Translator trans = Application.getTranslator();
private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
// Margin around the figure edges, pixels
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 cgCaret = new CGCaret(0,0);
private UnitGroup stabilityUnits;
private UnitGroup.StabilityUnitGroup stabilityUnits;
private UnitGroup.StabilityUnitGroup secondaryStabilityUnits;
private FlightConfiguration configuration;
private double cg = 0, cp = 0;
@ -66,6 +69,7 @@ public class RocketInfo implements FigureElement {
public RocketInfo(FlightConfiguration configuration) {
this.configuration = configuration;
this.stabilityUnits = UnitGroup.stabilityUnits(configuration);
this.secondaryStabilityUnits = UnitGroup.secondaryStabilityUnits(configuration);
}
@ -189,19 +193,9 @@ public class RocketInfo implements FigureElement {
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 cpValue = createText(getCp());
GlyphVector stabValue = createText(getStability());
GlyphVector stabValue = createText(getStabilityCombined());
//// CG:
GlyphVector cgText = createText(trans.get("RocketInfo.cgText"));
@ -209,6 +203,15 @@ public class RocketInfo implements FigureElement {
GlyphVector cpText = createText(trans.get("RocketInfo.cpText"));
//// Stability:
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 visual bounds drops the spaces, so we'll add them
@ -276,16 +279,52 @@ public class RocketInfo implements FigureElement {
public String getMassWithMotors(Unit u) {
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 () {
return stabilityUnits.getDefaultUnit().toStringUnit(cp-cg);
public String getStabilityCombined() {
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;
}
/**
* Get the center of pressure in default length units.
*
@ -478,5 +517,6 @@ public class RocketInfo implements FigureElement {
public void setCurrentConfig(FlightConfiguration newConfig) {
this.configuration = 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.newlineShowText(STABILITY);
canvas.showText(text.getStability());
canvas.showText(text.getStabilityCombined());
canvas.newlineShowText(CG);
canvas.showText(text.getCg());