The first time a TubeFinSet is added to a rocket, inherit the thickness from

the parent BodyTube.

The two rockets I was using to test my code both turned out to have the thickness of their tube fins set to the default, so the need for a user to do this is clearly easy to miss (I created one of those rockets myself!).
This commit is contained in:
JoePfeiffer 2023-06-30 15:13:08 -06:00
parent d5291d7b52
commit a3dfb8ecd4
2 changed files with 20 additions and 3 deletions

View File

@ -550,4 +550,19 @@ public class BodyTube extends SymmetricComponent implements BoxBounded, MotorMou
// The motor config also has listeners, so clear them as well // The motor config also has listeners, so clear them as well
getDefaultMotorConfig().clearConfigListeners(); getDefaultMotorConfig().clearConfigListeners();
} }
/**
* The first time we add a TubeFinSet to the component tree, inherit the tube thickness from
* the parent body tube
*/
@Override
public final void addChild(RocketComponent component, int index, boolean trackStage) {
super.addChild(component, index, trackStage);
if (component instanceof TubeFinSet) {
TubeFinSet finset = (TubeFinSet) component;
if (Double.isNaN(finset.getThickness())) {
finset.setThickness(getThickness());
}
}
}
} }

View File

@ -24,7 +24,7 @@ public class TubeFinSet extends Tube implements AxialPositionable, BoxBounded, R
private boolean autoRadius = true; // Radius chosen automatically based on parent component private boolean autoRadius = true; // Radius chosen automatically based on parent component
private double outerRadius = DEFAULT_RADIUS; private double outerRadius = DEFAULT_RADIUS;
protected double thickness = 0.002; protected double thickness = Double.NaN;
private AngleMethod angleMethod = AngleMethod.FIXED; private AngleMethod angleMethod = AngleMethod.FIXED;
protected RadiusMethod radiusMethod = RadiusMethod.RELATIVE; protected RadiusMethod radiusMethod = RadiusMethod.RELATIVE;
@ -49,7 +49,7 @@ public class TubeFinSet extends Tube implements AxialPositionable, BoxBounded, R
/** /**
* New FinSet with given number of fins and given base rotation angle. * New TubeFinSet with default values
* Sets the component relative position to POSITION_RELATIVE_BOTTOM, * Sets the component relative position to POSITION_RELATIVE_BOTTOM,
* i.e. fins are positioned at the bottom of the parent component. * i.e. fins are positioned at the bottom of the parent component.
*/ */
@ -146,6 +146,7 @@ public class TubeFinSet extends Tube implements AxialPositionable, BoxBounded, R
* Sets whether the radius is selected automatically or not. * Sets whether the radius is selected automatically or not.
*/ */
public void setOuterRadiusAutomatic(boolean auto) { public void setOuterRadiusAutomatic(boolean auto) {
for (RocketComponent listener : configListeners) { for (RocketComponent listener : configListeners) {
if (listener instanceof TubeFinSet) { if (listener instanceof TubeFinSet) {
((TubeFinSet) listener).setOuterRadiusAutomatic(auto); ((TubeFinSet) listener).setOuterRadiusAutomatic(auto);
@ -195,8 +196,9 @@ public class TubeFinSet extends Tube implements AxialPositionable, BoxBounded, R
if ((this.thickness == thickness)) if ((this.thickness == thickness))
return; return;
this.thickness = MathUtil.clamp(thickness, 0, getOuterRadius()); this.thickness = MathUtil.clamp(thickness, 0, getOuterRadius());
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
clearPreset(); clearPreset();
} }