Implement auto radius for all mass objects
This commit is contained in:
parent
3166dee81c
commit
c6788c9594
@ -22,6 +22,7 @@ import net.sf.openrocket.util.MathUtil;
|
||||
public abstract class MassObject extends InternalComponent {
|
||||
|
||||
protected double radius;
|
||||
private boolean autoRadius = false;
|
||||
|
||||
private double radialPosition;
|
||||
private double radialDirection;
|
||||
@ -67,6 +68,22 @@ public abstract class MassObject extends InternalComponent {
|
||||
|
||||
|
||||
public double getRadius() {
|
||||
if (autoRadius) {
|
||||
if (parent == null) {
|
||||
return radius;
|
||||
}
|
||||
if (parent instanceof NoseCone) {
|
||||
return ((NoseCone) parent).getAftRadius();
|
||||
} else if (parent instanceof Transition) {
|
||||
double foreRadius = ((Transition) parent).getForeRadius();
|
||||
double aftRadius = ((Transition) parent).getAftRadius();
|
||||
return (Math.max(foreRadius, aftRadius));
|
||||
} else if (parent instanceof BodyComponent) {
|
||||
return ((BodyComponent) parent).getInnerRadius();
|
||||
} else if (parent instanceof RingComponent) {
|
||||
return ((RingComponent) parent).getInnerRadius();
|
||||
}
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
@ -80,14 +97,32 @@ public abstract class MassObject extends InternalComponent {
|
||||
}
|
||||
}
|
||||
|
||||
if (MathUtil.equals(this.radius, radius)) {
|
||||
if (MathUtil.equals(this.radius, radius) && (!autoRadius))
|
||||
return;
|
||||
}
|
||||
|
||||
this.autoRadius = false;
|
||||
this.radius = radius;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isRadiusAutomatic() {
|
||||
return autoRadius;
|
||||
}
|
||||
|
||||
public void setRadiusAutomatic(boolean auto) {
|
||||
for (RocketComponent listener : configListeners) {
|
||||
if (listener instanceof Parachute) {
|
||||
((Parachute) listener).setRadiusAutomatic(auto);
|
||||
}
|
||||
}
|
||||
|
||||
if (autoRadius == auto)
|
||||
return;
|
||||
|
||||
autoRadius = auto;
|
||||
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
public final double getRadialPosition() {
|
||||
return radialPosition;
|
||||
|
@ -15,7 +15,6 @@ public class Parachute extends RecoveryDevice {
|
||||
private double diameter;
|
||||
private final double InitialPackedLength = this.length;
|
||||
private final double InitialPackedRadius = this.radius;
|
||||
private boolean autoRadius;
|
||||
|
||||
private Material lineMaterial;
|
||||
private int lineCount = 6;
|
||||
@ -146,64 +145,6 @@ public class Parachute extends RecoveryDevice {
|
||||
//// Parachute
|
||||
return trans.get("Parachute.Parachute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRadius(double radius) {
|
||||
radius = Math.max(radius, 0);
|
||||
|
||||
for (RocketComponent listener : configListeners) {
|
||||
if (listener instanceof MassObject) {
|
||||
((MassObject) listener).setRadius(radius);
|
||||
}
|
||||
}
|
||||
|
||||
if (MathUtil.equals(this.radius, radius) && (!autoRadius))
|
||||
return;
|
||||
|
||||
this.autoRadius = false;
|
||||
this.radius = radius;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRadius() {
|
||||
if (autoRadius) {
|
||||
if (parent == null) {
|
||||
return radius;
|
||||
}
|
||||
if (parent instanceof NoseCone) {
|
||||
return ((NoseCone) parent).getAftRadius();
|
||||
} else if (parent instanceof Transition) {
|
||||
double foreRadius = ((Transition) parent).getForeRadius();
|
||||
double aftRadius = ((Transition) parent).getAftRadius();
|
||||
return (Math.max(foreRadius, aftRadius));
|
||||
} else if (parent instanceof BodyComponent) {
|
||||
return ((BodyComponent) parent).getInnerRadius();
|
||||
} else if (parent instanceof RingComponent) {
|
||||
return ((RingComponent) parent).getInnerRadius();
|
||||
}
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
public boolean isRadiusAutomatic() {
|
||||
return autoRadius;
|
||||
}
|
||||
|
||||
public void setRadiusAutomatic(boolean auto) {
|
||||
for (RocketComponent listener : configListeners) {
|
||||
if (listener instanceof Parachute) {
|
||||
((Parachute) listener).setRadiusAutomatic(auto);
|
||||
}
|
||||
}
|
||||
|
||||
if (autoRadius == auto)
|
||||
return;
|
||||
|
||||
autoRadius = auto;
|
||||
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsChildren() {
|
||||
|
@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
@ -105,7 +106,12 @@ public class MassComponentConfig extends RocketComponentConfig {
|
||||
|
||||
panel.add(new UnitSelector(od), "growx");
|
||||
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
||||
|
||||
|
||||
////// Automatic
|
||||
JCheckBox checkAutoPackedRadius = new JCheckBox(od.getAutomaticAction());
|
||||
checkAutoPackedRadius.setText(trans.get("TransitionCfg.checkbox.Automatic"));
|
||||
panel.add(checkAutoPackedRadius, "skip, span 2, wrap 30lp");
|
||||
|
||||
|
||||
//// Position
|
||||
//// Position relative to:
|
||||
|
@ -112,8 +112,11 @@ public class ShockCordConfig extends RocketComponentConfig {
|
||||
|
||||
panel2.add(new UnitSelector(od), "growx");
|
||||
panel2.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
||||
|
||||
|
||||
////// Automatic
|
||||
JCheckBox checkAutoPackedRadius = new JCheckBox(od.getAutomaticAction());
|
||||
checkAutoPackedRadius.setText(trans.get("TransitionCfg.checkbox.Automatic"));
|
||||
panel2.add(checkAutoPackedRadius, "skip, span 2, wrap");
|
||||
|
||||
//// General and General properties
|
||||
tabbedPane.insertTab(trans.get("ShockCordCfg.tab.General"), null, panel,
|
||||
|
@ -185,8 +185,13 @@ public class StreamerConfig extends RecoveryDeviceConfig {
|
||||
panel.add(spin, "growx");
|
||||
|
||||
panel.add(new UnitSelector(od), "growx");
|
||||
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap 30lp");
|
||||
|
||||
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
||||
|
||||
////// Automatic
|
||||
JCheckBox checkAutoPackedRadius = new JCheckBox(od.getAutomaticAction());
|
||||
checkAutoPackedRadius.setText(trans.get("TransitionCfg.checkbox.Automatic"));
|
||||
panel.add(checkAutoPackedRadius, "skip, span 2, wrap 30lp");
|
||||
|
||||
|
||||
//// Deployment
|
||||
//// Deploys at:
|
||||
|
Loading…
x
Reference in New Issue
Block a user