Merge pull request #1805 from SiboVG/issue-1792

[#1792] Don't clamp SymmetricComponent thickness when importing
This commit is contained in:
Sibo Van Gool 2022-11-11 19:19:44 +01:00 committed by GitHub
commit 19ee2a83ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 33 deletions

View File

@ -171,9 +171,10 @@ class DocumentConfig {
// SymmetricComponent // SymmetricComponent
setters.put("SymmetricComponent:thickness", new DoubleSetter( setters.put("SymmetricComponent:thickness", new DoubleSetter(
Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class), Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class, boolean.class),
"filled", "filled",
Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class))); Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class),
false));
// LaunchLug // LaunchLug
setters.put("LaunchLug:instancecount", new IntSetter( setters.put("LaunchLug:instancecount", new IntSetter(
@ -218,13 +219,15 @@ class DocumentConfig {
Reflection.findMethod(Transition.class, "setShapeParameter", double.class))); Reflection.findMethod(Transition.class, "setShapeParameter", double.class)));
setters.put("Transition:foreradius", new DoubleSetter( setters.put("Transition:foreradius", new DoubleSetter(
Reflection.findMethod(Transition.class, "setForeRadius", double.class), Reflection.findMethod(Transition.class, "setForeRadius", double.class, boolean.class),
"auto", " ", "auto", " ",
Reflection.findMethod(Transition.class, "setForeRadiusAutomatic", boolean.class))); Reflection.findMethod(Transition.class, "setForeRadiusAutomatic", boolean.class),
false));
setters.put("Transition:aftradius", new DoubleSetter( setters.put("Transition:aftradius", new DoubleSetter(
Reflection.findMethod(Transition.class, "setAftRadius", double.class), Reflection.findMethod(Transition.class, "setAftRadius", double.class, boolean.class),
"auto", " ", "auto", " ",
Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class))); Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class),
false));
setters.put("Transition:foreshoulderradius", new DoubleSetter( setters.put("Transition:foreshoulderradius", new DoubleSetter(
Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class))); Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class)));

View File

@ -2,7 +2,6 @@ package net.sf.openrocket.file.openrocket.importt;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.Warning;
import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.aerodynamics.WarningSet;
@ -20,6 +19,7 @@ class DoubleSetter implements Setter {
private final Reflection.Method specialMethod; private final Reflection.Method specialMethod;
private final double multiplier; private final double multiplier;
private String separator; private String separator;
private Object[] extraParameters = null;
/** /**
* Set only the double value. * Set only the double value.
@ -45,22 +45,24 @@ class DoubleSetter implements Setter {
this.specialMethod = null; this.specialMethod = null;
this.multiplier = mul; this.multiplier = mul;
} }
/** /**
* Set the double value, or if the value equals the special string, use the * Set the double value, or if the value equals the special string, use the
* special setter and set it to true. * special setter and set it to true.
* *
* @param set double setter. * @param set double setter.
* @param special special string * @param special special string
* @param specialMethod boolean setter. * @param specialMethod boolean setter.
* @param parameters (optional) extra parameter set to use for the setter method.
*/ */
public DoubleSetter(Reflection.Method set, String special, public DoubleSetter(Reflection.Method set, String special,
Reflection.Method specialMethod) { Reflection.Method specialMethod, Object... parameters) {
this.setMethod = set; this.setMethod = set;
this.configGetter = null; this.configGetter = null;
this.specialString = special; this.specialString = special;
this.specialMethod = specialMethod; this.specialMethod = specialMethod;
this.multiplier = 1.0; this.multiplier = 1.0;
this.extraParameters = parameters;
} }
/** /**
@ -73,11 +75,13 @@ class DoubleSetter implements Setter {
* @param set double setter. * @param set double setter.
* @param special special string * @param special special string
* @param specialMethod boolean setter. * @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, public DoubleSetter(Reflection.Method set, String special, String separator,
Reflection.Method specialMethod) { Reflection.Method specialMethod, Object... parameters) {
this(set, special, specialMethod); this(set, special, specialMethod);
this.separator = separator; this.separator = separator;
this.extraParameters = parameters;
} }
@ -118,11 +122,17 @@ class DoubleSetter implements Setter {
try { try {
double d = Double.parseDouble(data); double d = Double.parseDouble(data);
if (configGetter == null) { Object obj = c;
setMethod.invoke(c, d * multiplier); if (configGetter != null) {
} else {
FlightConfigurableParameterSet<?> config = (FlightConfigurableParameterSet<?>) configGetter.invoke(c); 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); setMethod.invoke(obj, d * multiplier);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -7,8 +7,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import net.sf.openrocket.preset.ComponentPreset; 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.BoundingBox;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; 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) { public final double getInnerRadius(double x, double theta) {
return getInnerRadius(x); 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. * Return the component wall thickness.
@ -103,15 +107,15 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
public double getThickness() { public double getThickness() {
if (filled) if (filled)
return Math.max(getForeRadius(), getAftRadius()); 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 * Set the component wall thickness. If <code>doClamping</code> is true, values greater than
* allowed, and will result in setting the thickness to the maximum radius. * 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) { for (RocketComponent listener : configListeners) {
if (listener instanceof SymmetricComponent) { if (listener instanceof SymmetricComponent) {
((SymmetricComponent) listener).setThickness(thickness); ((SymmetricComponent) listener).setThickness(thickness);
@ -120,13 +124,22 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
if ((this.thickness == thickness) && !filled) if ((this.thickness == thickness) && !filled)
return; return;
this.thickness = MathUtil.clamp(thickness, 0, Math.max(getForeRadius(), getAftRadius())); this.thickness = doClamping ? MathUtil.clamp(thickness, 0, getMaxRadius()) : thickness;
filled = false; filled = false;
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
clearPreset(); 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 * Returns whether the component is set as filled. If it is set filled, then the
* wall thickness will have no effect. * wall thickness will have no effect.

View File

@ -102,7 +102,12 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
return foreRadius; 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) { for (RocketComponent listener : configListeners) {
if (listener instanceof Transition) { if (listener instanceof Transition) {
((Transition) listener).setForeRadius(radius); ((Transition) listener).setForeRadius(radius);
@ -115,13 +120,17 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
this.autoForeRadius = false; this.autoForeRadius = false;
this.foreRadius = Math.max(radius, 0); 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); this.thickness = Math.max(this.foreRadius, this.aftRadius);
clearPreset(); clearPreset();
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
public void setForeRadius(double radius) {
setForeRadius(radius, true);
}
@Override @Override
public boolean isForeRadiusAutomatic() { public boolean isForeRadiusAutomatic() {
return autoForeRadius; return autoForeRadius;
@ -170,7 +179,12 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
return aftRadius; 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) { for (RocketComponent listener : configListeners) {
if (listener instanceof Transition) { if (listener instanceof Transition) {
((Transition) listener).setAftRadius(radius); ((Transition) listener).setAftRadius(radius);
@ -183,13 +197,17 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
this.autoAftRadius2 = false; this.autoAftRadius2 = false;
this.aftRadius = Math.max(radius, 0); 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); this.thickness = Math.max(this.foreRadius, this.aftRadius);
clearPreset(); clearPreset();
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
public void setAftRadius(double radius) {
setAftRadius(radius, true);
}
@Override @Override
public boolean isAftRadiusAutomatic() { public boolean isAftRadiusAutomatic() {
return autoAftRadius2; return autoAftRadius2;
@ -212,7 +230,6 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
} }
//// Radius automatics //// Radius automatics
@Override @Override

View File

@ -133,7 +133,9 @@ public class NoseConeConfig extends RocketComponentConfig {
order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField()); order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField());
panel.add(new UnitSelector(thicknessModel), "growx"); 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")); final JCheckBox filledCheckbox = new JCheckBox(new BooleanModel(component, "Filled"));

View File

@ -170,7 +170,9 @@ public class TransitionConfig extends RocketComponentConfig {
order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField()); order.add(((SpinnerEditor) thicknessSpinner.getEditor()).getTextField());
panel.add(new UnitSelector(thicknessModel), "growx"); 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 //// Filled
final JCheckBox thicknessCheckbox = new JCheckBox(new BooleanModel(component, "Filled")); final JCheckBox thicknessCheckbox = new JCheckBox(new BooleanModel(component, "Filled"));