Merge pull request #2416 from SiboVG/issue-2178
[#2178] Add South/West unit for latitude/longitude
This commit is contained in:
commit
c136436284
@ -374,6 +374,8 @@ pref.dlg.lbl.SecondaryStability.ttip = Select the stability unit that will be di
|
||||
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.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
|
||||
|
@ -79,10 +79,10 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
||||
public static final FlightDataType TYPE_ACCELERATION_XY = newType(trans.get("FlightDataType.TYPE_ACCELERATION_XY"), "Al", UnitGroup.UNITS_ACCELERATION,
|
||||
FlightDataTypeGroup.POSITION_AND_MOTION, 5);
|
||||
//// Latitude
|
||||
public static final FlightDataType TYPE_LATITUDE = newType(trans.get("FlightDataType.TYPE_LATITUDE"), "\u03c6", UnitGroup.UNITS_ANGLE,
|
||||
public static final FlightDataType TYPE_LATITUDE = newType(trans.get("FlightDataType.TYPE_LATITUDE"), "\u03c6", UnitGroup.UNITS_LATITUDE,
|
||||
FlightDataTypeGroup.POSITION_AND_MOTION, 6);
|
||||
//// Longitude
|
||||
public static final FlightDataType TYPE_LONGITUDE = newType(trans.get("FlightDataType.TYPE_LONGITUDE"), "\u03bb", UnitGroup.UNITS_ANGLE,
|
||||
public static final FlightDataType TYPE_LONGITUDE = newType(trans.get("FlightDataType.TYPE_LONGITUDE"), "\u03bb", UnitGroup.UNITS_LONGITUDE,
|
||||
FlightDataTypeGroup.POSITION_AND_MOTION, 7);
|
||||
|
||||
|
||||
|
@ -70,6 +70,10 @@ public abstract class Unit {
|
||||
return true;
|
||||
}
|
||||
|
||||
public double getMultiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return unit;
|
||||
|
@ -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;
|
||||
|
||||
|
||||
@ -49,6 +52,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;
|
||||
@ -88,6 +93,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.
|
||||
@ -192,6 +199,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));
|
||||
@ -346,6 +361,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);
|
||||
|
||||
@ -394,6 +411,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");
|
||||
@ -421,6 +440,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");
|
||||
@ -443,6 +464,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);
|
||||
@ -674,9 +697,6 @@ public class UnitGroup {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Value object with the specified value and the default unit of this group.
|
||||
*
|
||||
|
@ -123,7 +123,8 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
||||
@Override
|
||||
public Object getNextValue() {
|
||||
double d = currentUnit.toUnit(DoubleModel.this.getValue());
|
||||
double max = currentUnit.toUnit(maxValue);
|
||||
boolean inverted = DoubleModel.this.currentUnit.getMultiplier() < 0;
|
||||
double max = inverted ? currentUnit.toUnit(minValue) : currentUnit.toUnit(maxValue);
|
||||
if (MathUtil.equals(d, max))
|
||||
return null;
|
||||
d = currentUnit.getNextValue(d);
|
||||
@ -135,7 +136,8 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
||||
@Override
|
||||
public Object getPreviousValue() {
|
||||
double d = currentUnit.toUnit(DoubleModel.this.getValue());
|
||||
double min = currentUnit.toUnit(minValue);
|
||||
boolean inverted = DoubleModel.this.currentUnit.getMultiplier() < 0;
|
||||
double min = inverted ? currentUnit.toUnit(maxValue) : currentUnit.toUnit(minValue);
|
||||
if (MathUtil.equals(d, min))
|
||||
return null;
|
||||
d = currentUnit.getPreviousValue(d);
|
||||
@ -315,10 +317,11 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
||||
@Override
|
||||
public int getValue() {
|
||||
double value = DoubleModel.this.getValue();
|
||||
boolean inverted = DoubleModel.this.getCurrentUnit().getMultiplier() < 0;
|
||||
if (value <= min.getValue())
|
||||
return 0;
|
||||
return inverted ? MAX : 0;
|
||||
if (value >= max.getValue())
|
||||
return MAX;
|
||||
return inverted ? 0 : MAX;
|
||||
|
||||
double x;
|
||||
if ((value <= mid.getValue()) || (quad2 == 0)) { // If quad 2 is 0, the midpoint is perfectly in center
|
||||
@ -333,6 +336,9 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
||||
// a*x^2 + b*x + c-value == 0
|
||||
x = (MathUtil.safeSqrt(quad1 * quad1 - 4 * quad2 * (quad0 - value)) - quad1) / (2 * quad2);
|
||||
}
|
||||
if (inverted) {
|
||||
x = 1 - x;
|
||||
}
|
||||
return (int) (x * MAX);
|
||||
}
|
||||
|
||||
@ -346,7 +352,11 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
||||
return;
|
||||
}
|
||||
|
||||
boolean inverted = DoubleModel.this.getCurrentUnit().getMultiplier() < 0;
|
||||
double x = (double) newValue / MAX;
|
||||
if (inverted) {
|
||||
x = 1 - x;
|
||||
}
|
||||
double scaledValue;
|
||||
|
||||
if (x <= linearPosition) {
|
||||
|
@ -160,6 +160,17 @@ public class UnitsPreferencesPanel extends PreferencesPanel {
|
||||
combo = new JComboBox<Object>(new DefaultUnitSelector(UnitGroup.UNITS_WINDSPEED));
|
||||
rightPanel.add(combo, "sizegroup boxes, wrap");
|
||||
|
||||
//// Latitude
|
||||
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Latitude")));
|
||||
combo = new JComboBox<>(new DefaultUnitSelector(UnitGroup.UNITS_LATITUDE));
|
||||
rightPanel.add(combo, "sizegroup boxes, wrap");
|
||||
|
||||
//// Longitude
|
||||
rightPanel.add(new JLabel(trans.get("pref.dlg.lbl.Longitude")));
|
||||
combo = new JComboBox<>(new DefaultUnitSelector(UnitGroup.UNITS_LONGITUDE));
|
||||
rightPanel.add(combo, "sizegroup boxes, wrap");
|
||||
|
||||
|
||||
this.add(leftPanel, "top");
|
||||
this.add(rightPanel, "top, wrap para");
|
||||
|
||||
|
@ -327,17 +327,17 @@ public class SimulationConditionsPanel extends JPanel {
|
||||
label.setToolTipText(tip);
|
||||
sub.add(label);
|
||||
|
||||
m = new DoubleModel(target, "LaunchLatitude", UnitGroup.UNITS_NONE, -90, 90);
|
||||
m = new DoubleModel(target, "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");
|
||||
|
||||
@ -348,17 +348,17 @@ public class SimulationConditionsPanel extends JPanel {
|
||||
label.setToolTipText(tip);
|
||||
sub.add(label);
|
||||
|
||||
m = new DoubleModel(target, "LaunchLongitude", UnitGroup.UNITS_NONE, -180, 180);
|
||||
m = new DoubleModel(target, "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");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user