From b9dcc908b66c2431a37b6899204d95aafdf168ab Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 10 Nov 2022 00:08:27 +0100 Subject: [PATCH 1/2] [#1792] Don't clamp the transition thickness upon import --- .../openrocket/importt/DocumentConfig.java | 15 ++++++---- .../file/openrocket/importt/DoubleSetter.java | 28 +++++++++++++------ .../rocketcomponent/SymmetricComponent.java | 23 ++++++++++----- .../rocketcomponent/Transition.java | 26 ++++++++++++++--- 4 files changed, 66 insertions(+), 26 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java b/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java index 3fe4093e6..775c1c47f 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java @@ -171,9 +171,10 @@ class DocumentConfig { // SymmetricComponent setters.put("SymmetricComponent:thickness", new DoubleSetter( - Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class), + Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class, boolean.class), "filled", - Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class))); + Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class), + false)); // LaunchLug setters.put("LaunchLug:instancecount", new IntSetter( @@ -218,13 +219,15 @@ class DocumentConfig { Reflection.findMethod(Transition.class, "setShapeParameter", double.class))); setters.put("Transition:foreradius", new DoubleSetter( - Reflection.findMethod(Transition.class, "setForeRadius", double.class), + Reflection.findMethod(Transition.class, "setForeRadius", double.class, boolean.class), "auto", " ", - Reflection.findMethod(Transition.class, "setForeRadiusAutomatic", boolean.class))); + Reflection.findMethod(Transition.class, "setForeRadiusAutomatic", boolean.class), + false)); setters.put("Transition:aftradius", new DoubleSetter( - Reflection.findMethod(Transition.class, "setAftRadius", double.class), + Reflection.findMethod(Transition.class, "setAftRadius", double.class, boolean.class), "auto", " ", - Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class))); + Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class), + false)); setters.put("Transition:foreshoulderradius", new DoubleSetter( Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class))); diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java b/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java index 5525f8086..b12263666 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java @@ -2,7 +2,6 @@ package net.sf.openrocket.file.openrocket.importt; import java.util.Arrays; import java.util.HashMap; -import java.util.Objects; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.WarningSet; @@ -20,6 +19,7 @@ class DoubleSetter implements Setter { private final Reflection.Method specialMethod; private final double multiplier; private String separator; + private Object[] extraParameters = null; /** * Set only the double value. @@ -45,22 +45,24 @@ class DoubleSetter implements Setter { this.specialMethod = null; this.multiplier = mul; } - + /** * Set the double value, or if the value equals the special string, use the * special setter and set it to true. - * + * * @param set double setter. * @param special special string * @param specialMethod boolean setter. + * @param parameters (optional) extra parameter set to use for the setter method. */ public DoubleSetter(Reflection.Method set, String special, - Reflection.Method specialMethod) { + Reflection.Method specialMethod, Object... parameters) { this.setMethod = set; this.configGetter = null; this.specialString = special; this.specialMethod = specialMethod; this.multiplier = 1.0; + this.extraParameters = parameters; } /** @@ -73,11 +75,13 @@ class DoubleSetter implements Setter { * @param set double setter. * @param special special string * @param specialMethod boolean setter. + * @param parameters (optional) extra parameter set to use for the setter method. */ public DoubleSetter(Reflection.Method set, String special, String separator, - Reflection.Method specialMethod) { + Reflection.Method specialMethod, Object... parameters) { this(set, special, specialMethod); this.separator = separator; + this.extraParameters = parameters; } @@ -118,11 +122,17 @@ class DoubleSetter implements Setter { try { double d = Double.parseDouble(data); - if (configGetter == null) { - setMethod.invoke(c, d * multiplier); - } else { + Object obj = c; + if (configGetter != null) { FlightConfigurableParameterSet config = (FlightConfigurableParameterSet) configGetter.invoke(c); - Object obj = config.getDefault(); + obj = config.getDefault(); + } + if (extraParameters != null) { + Object[] parameters = new Object[extraParameters.length + 1]; + parameters[0] = d * multiplier; + System.arraycopy(extraParameters, 0, parameters, 1, extraParameters.length); + setMethod.invoke(obj, parameters); + } else { setMethod.invoke(obj, d * multiplier); } } catch (NumberFormatException e) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index 0427ea927..322a6245b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -103,15 +103,15 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou public double getThickness() { if (filled) return Math.max(getForeRadius(), getAftRadius()); - return Math.min(thickness, Math.max(getForeRadius(), getAftRadius())); + return thickness; } - - + /** - * Set the component wall thickness. Values greater than the maximum radius are not - * allowed, and will result in setting the thickness to the maximum radius. + * Set the component wall thickness. If doClamping is true, values greater than + * the maximum radius will be clamped the thickness to the maximum radius. + * @param doClamping If true, the thickness will be clamped to the maximum radius. */ - public void setThickness(double thickness) { + public void setThickness(double thickness, boolean doClamping) { for (RocketComponent listener : configListeners) { if (listener instanceof SymmetricComponent) { ((SymmetricComponent) listener).setThickness(thickness); @@ -120,13 +120,22 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou if ((this.thickness == thickness) && !filled) return; - this.thickness = MathUtil.clamp(thickness, 0, Math.max(getForeRadius(), getAftRadius())); + this.thickness = doClamping ? MathUtil.clamp(thickness, 0, Math.max(getForeRadius(), getAftRadius())) : thickness; filled = false; fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); clearPreset(); } + /** + * Set the component wall thickness. Values greater than the maximum radius are not + * allowed, and will result in setting the thickness to the maximum radius. + */ + public void setThickness(double thickness) { + setThickness(thickness, true); + } + + /** * Returns whether the component is set as filled. If it is set filled, then the * wall thickness will have no effect. diff --git a/core/src/net/sf/openrocket/rocketcomponent/Transition.java b/core/src/net/sf/openrocket/rocketcomponent/Transition.java index c63dff741..83d18081f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Transition.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Transition.java @@ -102,7 +102,12 @@ public class Transition extends SymmetricComponent implements InsideColorCompone return foreRadius; } - public void setForeRadius(double radius) { + /** + * Set the new fore radius, with option to clamp the thickness to the new radius if it's too large. + * @param radius new radius + * @param doClamping whether to clamp the thickness + */ + public void setForeRadius(double radius, boolean doClamping) { for (RocketComponent listener : configListeners) { if (listener instanceof Transition) { ((Transition) listener).setForeRadius(radius); @@ -115,13 +120,17 @@ public class Transition extends SymmetricComponent implements InsideColorCompone this.autoForeRadius = false; this.foreRadius = Math.max(radius, 0); - if (this.thickness > this.foreRadius && this.thickness > this.aftRadius) + if (doClamping && this.thickness > this.foreRadius && this.thickness > this.aftRadius) this.thickness = Math.max(this.foreRadius, this.aftRadius); clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } + public void setForeRadius(double radius) { + setForeRadius(radius, true); + } + @Override public boolean isForeRadiusAutomatic() { return autoForeRadius; @@ -170,7 +179,12 @@ public class Transition extends SymmetricComponent implements InsideColorCompone return aftRadius; } - public void setAftRadius(double radius) { + /** + * Set the new aft radius, with option to clamp the thickness to the new radius if it's too large. + * @param radius new radius + * @param doClamping whether to clamp the thickness + */ + public void setAftRadius(double radius, boolean doClamping) { for (RocketComponent listener : configListeners) { if (listener instanceof Transition) { ((Transition) listener).setAftRadius(radius); @@ -183,13 +197,17 @@ public class Transition extends SymmetricComponent implements InsideColorCompone this.autoAftRadius2 = false; this.aftRadius = Math.max(radius, 0); - if (this.thickness > this.foreRadius && this.thickness > this.aftRadius) + if (doClamping && this.thickness > this.foreRadius && this.thickness > this.aftRadius) this.thickness = Math.max(this.foreRadius, this.aftRadius); clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } + public void setAftRadius(double radius) { + setAftRadius(radius, true); + } + @Override public boolean isAftRadiusAutomatic() { return autoAftRadius2; From d400947e1fe75105142805c40fd89830179f777d Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 10 Nov 2022 00:18:56 +0100 Subject: [PATCH 2/2] Fix max slider value of thickness --- .../rocketcomponent/SymmetricComponent.java | 14 +++++++++----- .../sf/openrocket/rocketcomponent/Transition.java | 1 - .../gui/configdialog/NoseConeConfig.java | 4 +++- .../gui/configdialog/TransitionConfig.java | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index 322a6245b..bb76e77ce 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -7,8 +7,6 @@ import java.util.Collection; import java.util.List; import net.sf.openrocket.preset.ComponentPreset; -import net.sf.openrocket.rocketcomponent.PodSet; -import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -94,8 +92,14 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou public final double getInnerRadius(double x, double theta) { return getInnerRadius(x); } - - + + /** + * Returns the largest radius of the component (either the aft radius, or the fore radius). + */ + public double getMaxRadius() { + return MathUtil.max(getForeRadius(), getAftRadius()); + } + /** * Return the component wall thickness. @@ -120,7 +124,7 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou if ((this.thickness == thickness) && !filled) return; - this.thickness = doClamping ? MathUtil.clamp(thickness, 0, Math.max(getForeRadius(), getAftRadius())) : thickness; + this.thickness = doClamping ? MathUtil.clamp(thickness, 0, getMaxRadius()) : thickness; filled = false; fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); clearPreset(); diff --git a/core/src/net/sf/openrocket/rocketcomponent/Transition.java b/core/src/net/sf/openrocket/rocketcomponent/Transition.java index 83d18081f..9fd78a378 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Transition.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Transition.java @@ -230,7 +230,6 @@ public class Transition extends SymmetricComponent implements InsideColorCompone } - //// Radius automatics @Override diff --git a/swing/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java index 06e711b85..9587d4760 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java @@ -133,7 +133,9 @@ public class NoseConeConfig extends RocketComponentConfig { order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField()); panel.add(new UnitSelector(thicknessModel), "growx"); - panel.add(new BasicSlider(thicknessModel.getSliderModel(0, 0.01)), "w 100lp, wrap 0px"); + panel.add(new BasicSlider(thicknessModel.getSliderModel(0, + new DoubleModel(component, "MaxRadius", UnitGroup.UNITS_LENGTH))), + "w 100lp, wrap 0px"); final JCheckBox filledCheckbox = new JCheckBox(new BooleanModel(component, "Filled")); diff --git a/swing/src/net/sf/openrocket/gui/configdialog/TransitionConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/TransitionConfig.java index 3b3c3f0ea..6487e5059 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/TransitionConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/TransitionConfig.java @@ -170,7 +170,9 @@ public class TransitionConfig extends RocketComponentConfig { order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField()); panel.add(new UnitSelector(thicknessModel), "growx"); - panel.add(new BasicSlider(thicknessModel.getSliderModel(0, 0.01)), "w 100lp, wrap 0px"); + panel.add(new BasicSlider(thicknessModel.getSliderModel(0, + new DoubleModel(component, "MaxRadius", UnitGroup.UNITS_LENGTH))), + "w 100lp, wrap 0px"); //// Filled final JCheckBox thicknessCheckbox = new JCheckBox(new BooleanModel(component, "Filled"));