[#2178] Add south/west unit group for latitude/longitude

This commit is contained in:
SiboVG 2023-04-06 02:21:03 +02:00
parent cae9c8957d
commit 485d0b5210
6 changed files with 235 additions and 274 deletions

View File

@ -356,6 +356,8 @@ pref.dlg.lbl.Momentofinertia = Moment of inertia:
pref.dlg.lbl.Pressure = Pressure:
pref.dlg.lbl.Stability = Stability:
pref.dlg.lbl.FlightTime = Flight time:
pref.dlg.lbl.Latitude = Latitude:
pref.dlg.lbl.Longitude = Longitude:
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.PrefChoiseSelector1 = Always ask

View File

@ -70,6 +70,10 @@ public abstract class Unit {
return true;
}
public double getMultiplier() {
return multiplier;
}
@Override
public String toString() {
return unit;

View File

@ -16,8 +16,11 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.StringUtils;
@ -46,6 +49,8 @@ public class UnitGroup {
public static final UnitGroup UNITS_STABILITY_CALIBERS;
public static final UnitGroup UNITS_VELOCITY;
public static final UnitGroup UNITS_WINDSPEED;
public static final UnitGroup UNITS_LATITUDE;
public static final UnitGroup UNITS_LONGITUDE;
public static final UnitGroup UNITS_ACCELERATION;
public static final UnitGroup UNITS_MASS;
public static final UnitGroup UNITS_INERTIA;
@ -83,6 +88,8 @@ public class UnitGroup {
public static final Map<String, UnitGroup> UNITS; // keys such as "LENGTH", "VELOCITY"
public static final Map<String, UnitGroup> SIUNITS; // keys such a "m", "m/s"
private static final Translator trans = Application.getTranslator();
/*
* Note: Units may not use HTML tags.
@ -186,6 +193,14 @@ public class UnitGroup {
UNITS_WINDSPEED.addUnit(new GeneralUnit(0.44704, "mph"));
UNITS_WINDSPEED.addUnit(new GeneralUnit(0.51444445, "kt"));
UNITS_LATITUDE = new UnitGroup();
UNITS_LATITUDE.addUnit(new GeneralUnit(1, DEGREE + " " + trans.get("CompassRose.lbl.north")));
UNITS_LATITUDE.addUnit(new GeneralUnit(-1, DEGREE + " " + trans.get("CompassRose.lbl.south")));
UNITS_LONGITUDE = new UnitGroup();
UNITS_LONGITUDE.addUnit(new GeneralUnit(1, DEGREE + " " + trans.get("CompassRose.lbl.east")));
UNITS_LONGITUDE.addUnit(new GeneralUnit(-1, DEGREE + " " + trans.get("CompassRose.lbl.west")));
UNITS_ACCELERATION = new UnitGroup();
UNITS_ACCELERATION.addUnit(new GeneralUnit(1, "m/s" + SQUARED));
UNITS_ACCELERATION.addUnit(new GeneralUnit(0.3048, "ft/s" + SQUARED));
@ -328,6 +343,8 @@ public class UnitGroup {
map.put("MOMENTUM", UNITS_MOMENTUM);
map.put("FREQUENCY", UNITS_FREQUENCY);
map.put("WINDSPEED", UNITS_WINDSPEED);
map.put("LATITUDE", UNITS_LATITUDE);
map.put("LONGITUDE", UNITS_LONGITUDE);
UNITS = Collections.unmodifiableMap(map);
@ -375,6 +392,8 @@ public class UnitGroup {
UNITS_ROLL.setDefaultUnit("r/s");
UNITS_TEMPERATURE.setDefaultUnit(DEGREE + "C");
UNITS_WINDSPEED.setDefaultUnit("m/s");
UNITS_LATITUDE.setDefaultUnit(DEGREE + " " + trans.get("CompassRose.lbl.north"));
UNITS_LONGITUDE.setDefaultUnit(DEGREE + " " + trans.get("CompassRose.lbl.east"));
UNITS_PRESSURE.setDefaultUnit("mbar");
UNITS_RELATIVE.setDefaultUnit("%");
UNITS_ROUGHNESS.setDefaultUnit(MICRO + "m");
@ -401,6 +420,8 @@ public class UnitGroup {
UNITS_ROLL.setDefaultUnit("r/s");
UNITS_TEMPERATURE.setDefaultUnit(DEGREE + "F");
UNITS_WINDSPEED.setDefaultUnit("mph");
UNITS_LATITUDE.setDefaultUnit(DEGREE + " " + trans.get("CompassRose.lbl.north"));
UNITS_LONGITUDE.setDefaultUnit(DEGREE + " " + trans.get("CompassRose.lbl.east"));
UNITS_PRESSURE.setDefaultUnit("mbar");
UNITS_RELATIVE.setDefaultUnit("%");
UNITS_ROUGHNESS.setDefaultUnit("mil");
@ -422,6 +443,8 @@ public class UnitGroup {
UNITS_STABILITY_CALIBERS.setDefaultUnit(0);
UNITS_VELOCITY.setDefaultUnit(0);
UNITS_WINDSPEED.setDefaultUnit(0);
UNITS_LATITUDE.setDefaultUnit(0);
UNITS_LONGITUDE.setDefaultUnit(0);
UNITS_ACCELERATION.setDefaultUnit(0);
UNITS_MASS.setDefaultUnit(0);
UNITS_INERTIA.setDefaultUnit(1);
@ -447,8 +470,8 @@ public class UnitGroup {
/**
* Return a UnitGroup for stability units based on the rocket.
*
* @param rocket the rocket from which to calculate the caliber
* @return the unit group
* @param rocket the rocket from which to calculate the caliber
* @return the unit group
*/
public static UnitGroup stabilityUnits(Rocket rocket) {
return new StabilityUnitGroup(rocket);
@ -458,8 +481,8 @@ public class UnitGroup {
/**
* 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
* @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);
@ -469,8 +492,8 @@ public class UnitGroup {
/**
* Return a UnitGroup for stability units based on a constant caliber.
*
* @param reference the constant reference length
* @return the unit group
* @param reference the constant reference length
* @return the unit group
*/
public static UnitGroup stabilityUnits(double reference) {
return new StabilityUnitGroup(reference);
@ -516,8 +539,8 @@ public class UnitGroup {
* considered in the matching. This method is mainly means for testing, allowing
* a simple means to obtain a particular unit.
*
* @param str the unit name.
* @return the corresponding unit, or <code>null</code> if not found.
* @param str the unit name.
* @return the corresponding unit, or <code>null</code> if not found.
*/
public Unit findApproximate(String str) {
str = str.replaceAll("\\W", "").trim();
@ -533,8 +556,8 @@ public class UnitGroup {
* Set the default unit based on the unit name. Throws an exception if a
* unit with the provided name is not available.
*
* @param name the unit name.
* @throws IllegalArgumentException if the corresponding unit is not found in the group.
* @param name the unit name.
* @throws IllegalArgumentException if the corresponding unit is not found in the group.
*/
public void setDefaultUnit(String name) throws IllegalArgumentException {
for (int i = 0; i < units.size(); i++) {
@ -591,9 +614,9 @@ public class UnitGroup {
* Return the value formatted by the default unit of this group.
* It is the same as calling <code>getDefaultUnit().toString(value)</code>.
*
* @param value the SI value to format.
* @return the formatted string.
* @see Unit#toString(double)
* @param value the SI value to format.
* @return the formatted string.
* @see Unit#toString(double)
*/
public String toString(double value) {
return this.getDefaultUnit().toString(value);
@ -604,23 +627,20 @@ public class UnitGroup {
* Return the value formatted by the default unit of this group including the unit.
* It is the same as calling <code>getDefaultUnit().toStringUnit(value)</code>.
*
* @param value the SI value to format.
* @return the formatted string.
* @see Unit#toStringUnit(double)
* @param value the SI value to format.
* @return the formatted string.
* @see Unit#toStringUnit(double)
*/
public String toStringUnit(double value) {
return this.getDefaultUnit().toStringUnit(value);
}
/**
* Creates a new Value object with the specified value and the default unit of this group.
*
* @param value the value to set.
* @return a new Value object.
* @param value the value to set.
* @return a new Value object.
*/
public Value toValue(double value) {
return this.getDefaultUnit().toValue(value);
@ -662,7 +682,7 @@ public class UnitGroup {
* This method is applicable only for simple units without e.g. powers.
*
* @param str the string to parse.
* @return the SI value.
* @return the SI value.
* @throws NumberFormatException if the string cannot be parsed.
*/
public double fromString(String str) {

View File

@ -291,18 +291,17 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
label.setToolTipText(tip);
sub.add(label);
m = new DoubleModel(preferences, "LaunchLatitude",
UnitGroup.UNITS_NONE, -90, 90);
m = new DoubleModel(preferences, "LaunchLatitude", UnitGroup.UNITS_LATITUDE, -90, 90);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
spin.setToolTipText(tip);
sub.add(spin, "growx");
label = new JLabel(Chars.DEGREE + " " + trans.get("CompassRose.lbl.north"));
label.setToolTipText(tip);
sub.add(label, "growx");
slider = new BasicSlider(m.getSliderModel(-90, 90));
unit = new UnitSelector(m);
unit.setToolTipText(tip);
sub.add(unit, "growx");
slider = new BasicSlider(m.getSliderModel());
slider.setToolTipText(tip);
sub.add(slider, "w 75lp, wrap");
@ -312,18 +311,17 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
label.setToolTipText(tip);
sub.add(label);
m = new DoubleModel(preferences, "LaunchLongitude",
UnitGroup.UNITS_NONE, -180, 180);
m = new DoubleModel(preferences, "LaunchLongitude", UnitGroup.UNITS_LONGITUDE, -180, 180);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
spin.setToolTipText(tip);
sub.add(spin, "growx");
label = new JLabel(Chars.DEGREE + " " + trans.get("CompassRose.lbl.east"));
label.setToolTipText(tip);
sub.add(label, "growx");
slider = new BasicSlider(m.getSliderModel(-180, 180));
unit = new UnitSelector(m);
unit.setToolTipText(tip);
sub.add(unit, "growx");
slider = new BasicSlider(m.getSliderModel());
slider.setToolTipText(tip);
sub.add(slider, "w 75lp, wrap");

View File

@ -8,6 +8,7 @@ import javax.swing.JButton;
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;
@ -21,119 +22,55 @@ public class UnitsPreferencesPanel extends PreferencesPanel {
super(parent, new MigLayout("", "[][]40lp[][]"));
JComboBox<?> combo;
// Create left and right panels
JPanel leftPanel = new JPanel(new MigLayout("", "[][]"));
JPanel rightPanel = new JPanel(new MigLayout("", "[][]"));
//// Select your preferred units:
this.add(new JLabel(trans.get("pref.dlg.lbl.Selectprefunits")), "span, wrap paragraph");
//// Rocket dimensions:
this.add(new JLabel(trans.get("pref.dlg.lbl.Rocketdimensions")));
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_LENGTH));
this.add(combo, "sizegroup boxes");
// Add widgets to the left panel
String[] leftLabels = {
"Rocketdimensions", "Motordimensions", "Distance", "Velocity",
"Acceleration", "Mass", "Force", "Totalimpulse",
"Momentofinertia", "Stability", "Linedensity"
};
UnitGroup[] leftUnitGroups = {
UnitGroup.UNITS_LENGTH, UnitGroup.UNITS_MOTOR_DIMENSIONS, UnitGroup.UNITS_DISTANCE,
UnitGroup.UNITS_VELOCITY, UnitGroup.UNITS_ACCELERATION, UnitGroup.UNITS_MASS,
UnitGroup.UNITS_FORCE, UnitGroup.UNITS_IMPULSE, UnitGroup.UNITS_INERTIA,
UnitGroup.UNITS_STABILITY, UnitGroup.UNITS_DENSITY_LINE
};
//// 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");
for (int i = 0; i < leftLabels.length; i++) {
leftPanel.add(new JLabel(trans.get("pref.dlg.lbl." + leftLabels[i])));
combo = new JComboBox<>(new DefaultUnitSelector(leftUnitGroups[i]));
leftPanel.add(combo, "sizegroup boxes, wrap");
}
// Add widgets to the right panel
String[] rightLabels = {
"Surfacedensity", "Bulkdensity", "Surfaceroughness",
"Area", "Angle", "Rollrate", "Temperature",
"Pressure", "Windspeed", "Latitude", "Longitude"
};
UnitGroup[] rightUnitGroups = {
UnitGroup.UNITS_DENSITY_SURFACE, UnitGroup.UNITS_DENSITY_BULK,
UnitGroup.UNITS_ROUGHNESS, UnitGroup.UNITS_AREA, UnitGroup.UNITS_ANGLE,
UnitGroup.UNITS_ROLL, UnitGroup.UNITS_TEMPERATURE, UnitGroup.UNITS_PRESSURE,
UnitGroup.UNITS_WINDSPEED, UnitGroup.UNITS_LATITUDE, UnitGroup.UNITS_LONGITUDE
};
//// Motor dimensions:
this.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");
//// Distance:
this.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");
//// Velocity:
this.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");
//// Acceleration:
this.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");
//// Mass:
this.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");
//// Force:
this.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");
//// Total impulse:
this.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");
//// Moment of inertia:
this.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");
//// 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");
//// Windspeed:
this.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");
for (int i = 0; i < rightLabels.length; i++) {
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl." + rightLabels[i])));
combo = new JComboBox<>(new DefaultUnitSelector(rightUnitGroups[i]));
rightPanel.add(combo, "sizegroup boxes, wrap");
}
// Add left and right panels to the UnitsPreferencesPanel
this.add(leftPanel);
this.add(rightPanel, "wrap para");
//// Default metric button

View File

@ -273,17 +273,17 @@ public class SimulationConditionsPanel extends JPanel {
label.setToolTipText(tip);
sub.add(label);
m = new DoubleModel(conditions, "LaunchLatitude", UnitGroup.UNITS_NONE, -90, 90);
m = new DoubleModel(conditions, "LaunchLatitude", UnitGroup.UNITS_LATITUDE, -90, 90);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
spin.setToolTipText(tip);
sub.add(spin, "w 65lp!");
label = new JLabel(Chars.DEGREE + " N");
label.setToolTipText(tip);
sub.add(label, "growx");
slider = new BasicSlider(m.getSliderModel(-90, 90));
unit = new UnitSelector(m);
unit.setToolTipText(tip);
sub.add(unit, "growx");
slider = new BasicSlider(m.getSliderModel());
slider.setToolTipText(tip);
sub.add(slider, "w 75lp, wrap");
@ -294,17 +294,17 @@ public class SimulationConditionsPanel extends JPanel {
label.setToolTipText(tip);
sub.add(label);
m = new DoubleModel(conditions, "LaunchLongitude", UnitGroup.UNITS_NONE, -180, 180);
m = new DoubleModel(conditions, "LaunchLongitude", UnitGroup.UNITS_LONGITUDE, -180, 180);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
spin.setToolTipText(tip);
sub.add(spin, "w 65lp!");
label = new JLabel(Chars.DEGREE + " E");
label.setToolTipText(tip);
sub.add(label, "growx");
slider = new BasicSlider(m.getSliderModel(-180, 180));
unit = new UnitSelector(m);
unit.setToolTipText(tip);
sub.add(unit, "growx");
slider = new BasicSlider(m.getSliderModel());
slider.setToolTipText(tip);
sub.add(slider, "w 75lp, wrap");