Merge pull request #1805 from SiboVG/issue-1792
[#1792] Don't clamp SymmetricComponent thickness when importing
This commit is contained in:
commit
19ee2a83ac
@ -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)));
|
||||
|
@ -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.
|
||||
@ -53,14 +53,16 @@ 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,
|
||||
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) {
|
||||
|
@ -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;
|
||||
@ -95,6 +93,12 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -103,15 +107,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 <code>doClamping</code> 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 +124,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, getMaxRadius()) : 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.
|
||||
|
@ -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;
|
||||
@ -212,7 +230,6 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
|
||||
}
|
||||
|
||||
|
||||
|
||||
//// Radius automatics
|
||||
|
||||
@Override
|
||||
|
@ -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"));
|
||||
|
@ -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"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user