From 58c721d1cbbdf8677f92f62abf9663dd63879ee7 Mon Sep 17 00:00:00 2001 From: Raketenolli Date: Sat, 15 May 2021 15:31:52 +0200 Subject: [PATCH 1/4] Allow rocket info to show stability margin as percentage of length * create a new class PercentageOfLengthUnit * add new unit to stability units --- .../unit/PercentageOfLengthUnit.java | 99 +++++++++++++++++++ .../src/net/sf/openrocket/unit/UnitGroup.java | 19 ++-- 2 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 core/src/net/sf/openrocket/unit/PercentageOfLengthUnit.java diff --git a/core/src/net/sf/openrocket/unit/PercentageOfLengthUnit.java b/core/src/net/sf/openrocket/unit/PercentageOfLengthUnit.java new file mode 100644 index 000000000..5cafe6520 --- /dev/null +++ b/core/src/net/sf/openrocket/unit/PercentageOfLengthUnit.java @@ -0,0 +1,99 @@ +package net.sf.openrocket.unit; + +import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.util.BugException; + +public class PercentageOfLengthUnit extends GeneralUnit { + + private final FlightConfiguration configuration; + private final Rocket rocket; + + private int rocketModId = -1; + private int configurationModId = -1; + + private double referenceLength = -1; + + public PercentageOfLengthUnit(FlightConfiguration configuration) { + super(0.01, "%"); + this.configuration = configuration; + + if (configuration == null) { + this.rocket = null; + } else { + this.rocket = configuration.getRocket(); + } + } + + public PercentageOfLengthUnit(Rocket rocket) { + super(0.01, "%"); + this.configuration = null; + this.rocket = rocket; + } + + public PercentageOfLengthUnit(double reference) { + super(0.01, "%"); + this.configuration = null; + this.rocket = null; + this.referenceLength = reference; + + if (reference <= 0) { + throw new IllegalArgumentException("Illegal reference = " + reference); + } + } + + @Override + public double fromUnit(double value) { + checkLength(); + + return value * referenceLength * multiplier; + } + + @Override + public double toUnit(double value) { + checkLength(); + + return value / referenceLength / multiplier; + } + + private void checkLength() { + if (configuration != null && configuration.getModID() != configurationModId) { + referenceLength = -1; + configurationModId = configuration.getModID(); + } + if (rocket != null && rocket.getModID() != rocketModId) { + referenceLength = -1; + rocketModId = rocket.getModID(); + } + if (referenceLength < 0) { + if (configuration != null) { + referenceLength = getReferenceLength(configuration); + } else if (rocket != null) { + referenceLength = getReferenceLength(rocket); + } else { + throw new BugException("Both rocket and configuration are null"); + } + } + } + + /** + * Get the reference length of a rocket configuration. + * + * @param config the rocket configuration + * @return the reference length of the rocket + */ + public static double getReferenceLength(FlightConfiguration config) { + return config.getLength(); + } + + /** + * Get the reference length of a rocket. + * + * @param rocket the rocket + * @return the reference length of the rocket + */ + public static double getReferenceLength(Rocket rocket) { + return getReferenceLength(rocket.getSelectedConfiguration()); + } + +} \ No newline at end of file diff --git a/core/src/net/sf/openrocket/unit/UnitGroup.java b/core/src/net/sf/openrocket/unit/UnitGroup.java index 4905329c0..99d6c1a58 100644 --- a/core/src/net/sf/openrocket/unit/UnitGroup.java +++ b/core/src/net/sf/openrocket/unit/UnitGroup.java @@ -177,13 +177,13 @@ public class UnitGroup { 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_STABILITY.setDefaultUnit(4); UNITS_STABILITY_CALIBERS = new UnitGroup(); UNITS_STABILITY_CALIBERS.addUnit(new GeneralUnit(1, "cal")); UNITS_STABILITY_CALIBERS.setDefaultUnit(0); - - + UNITS_VELOCITY = new UnitGroup(); UNITS_VELOCITY.addUnit(new GeneralUnit(1, "m/s")); UNITS_VELOCITY.addUnit(new GeneralUnit(1 / 3.6, "km/h")); @@ -708,25 +708,24 @@ public class UnitGroup { */ private static class StabilityUnitGroup extends UnitGroup { - public StabilityUnitGroup(double ref) { - this(new CaliberUnit(ref)); - } + public StabilityUnitGroup(double ref) { this(new CaliberUnit(ref), new PercentageOfLengthUnit(ref)); } public StabilityUnitGroup(Rocket rocket) { - this(new CaliberUnit(rocket)); + this(new CaliberUnit(rocket), new PercentageOfLengthUnit(rocket)); } - public StabilityUnitGroup(FlightConfiguration config) { - this(new CaliberUnit(config)); - } + public StabilityUnitGroup(FlightConfiguration config) { this(new CaliberUnit(config), new PercentageOfLengthUnit(config)); } - private StabilityUnitGroup(CaliberUnit caliberUnit) { + private StabilityUnitGroup(CaliberUnit caliberUnit, PercentageOfLengthUnit percentageOfLengthUnit) { this.units.addAll(UnitGroup.UNITS_STABILITY.units); this.defaultUnit = UnitGroup.UNITS_STABILITY.defaultUnit; for (int i = 0; i < units.size(); i++) { if (units.get(i) instanceof CaliberUnit) { units.set(i, caliberUnit); } + if (units.get(i) instanceof PercentageOfLengthUnit) { + units.set(i, percentageOfLengthUnit); + } } } From 1b5094553a321479c9d12cfcd6d628f18c3e98a6 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Wed, 23 Jun 2021 14:39:25 +0200 Subject: [PATCH 2/4] Fix inside color tube --- .../net/sf/openrocket/gui/figure3d/RealisticRenderer.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RealisticRenderer.java b/swing/src/net/sf/openrocket/gui/figure3d/RealisticRenderer.java index d3c94b006..e584db68f 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RealisticRenderer.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RealisticRenderer.java @@ -91,12 +91,7 @@ public class RealisticRenderer extends RocketRenderer { @Override public void renderComponent(final GL2 gl, Geometry geom, final float alpha) { Appearance app = getAppearance( geom.getComponent() ); - if (app.getPaint().getAlpha()<255){ - // if transparent, draw inside the same as the outside so we dont get a cardboard interior on a clear payload bay - render(gl, geom, Surface.INSIDE, app, true, alpha); - }else{ - render(gl, geom, Surface.INSIDE, DefaultAppearance.getDefaultAppearance(geom.getComponent()), true, 1.0f); - } + render(gl, geom, Surface.INSIDE, app, true, alpha); render(gl, geom, Surface.OUTSIDE, app, true, alpha); render(gl, geom, Surface.EDGES, app, false, alpha); } From a3e5d949d0dc154f2cf3c742d69f3db404362746 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Thu, 1 Jul 2021 02:49:24 +0200 Subject: [PATCH 3/4] [fixes #651] Fix shine wrong init value --- .../net/sf/openrocket/gui/configdialog/AppearancePanel.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index b2d00a6b8..4f8a99004 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -389,6 +389,9 @@ public class AppearancePanel extends JPanel { add(new JLabel(trans.get("AppearanceCfg.lbl.shine"))); DoubleModel shineModel = new DoubleModel(ab, "Shine", UnitGroup.UNITS_RELATIVE); + // Set the initial value to the reset state, not the shine value of the default appearance of this component + if (mDefault.getValue() && previousUserSelectedAppearance != null) + shineModel.setValue(previousUserSelectedAppearance.getShine()); JSpinner spin = new JSpinner(shineModel.getSpinnerModel()); spin.setEditor(new SpinnerEditor(spin)); JSlider slide = new JSlider(shineModel.getSliderModel(0, 1)); From dcacc40d887df48818adfe0bf4eed163142d5f87 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Thu, 1 Jul 2021 14:15:07 +0200 Subject: [PATCH 4/4] [fixes #971] Fix default appearance unchecking --- .../src/net/sf/openrocket/gui/configdialog/AppearancePanel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 4f8a99004..33fd7cac2 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -315,6 +315,7 @@ public class AppearancePanel extends JPanel { previousUserSelectedAppearance = (ab == null) ? null : ab.getAppearance(); ab.setAppearance(defaultAppearance); + c.setAppearance(null); } else { ab.setAppearance(previousUserSelectedAppearance); }