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 {
|
public abstract class MassObject extends InternalComponent {
|
||||||
|
|
||||||
protected double radius;
|
protected double radius;
|
||||||
|
private boolean autoRadius = false;
|
||||||
|
|
||||||
private double radialPosition;
|
private double radialPosition;
|
||||||
private double radialDirection;
|
private double radialDirection;
|
||||||
@ -67,6 +68,22 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
|
|
||||||
|
|
||||||
public double getRadius() {
|
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;
|
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;
|
return;
|
||||||
}
|
|
||||||
|
this.autoRadius = false;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
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() {
|
public final double getRadialPosition() {
|
||||||
return radialPosition;
|
return radialPosition;
|
||||||
|
@ -15,7 +15,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
private double diameter;
|
private double diameter;
|
||||||
private final double InitialPackedLength = this.length;
|
private final double InitialPackedLength = this.length;
|
||||||
private final double InitialPackedRadius = this.radius;
|
private final double InitialPackedRadius = this.radius;
|
||||||
private boolean autoRadius;
|
|
||||||
|
|
||||||
private Material lineMaterial;
|
private Material lineMaterial;
|
||||||
private int lineCount = 6;
|
private int lineCount = 6;
|
||||||
@ -146,64 +145,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
//// Parachute
|
//// Parachute
|
||||||
return trans.get("Parachute.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
|
@Override
|
||||||
public boolean allowsChildren() {
|
public boolean allowsChildren() {
|
||||||
|
@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@ -105,7 +106,12 @@ public class MassComponentConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
panel.add(new UnitSelector(od), "growx");
|
panel.add(new UnitSelector(od), "growx");
|
||||||
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
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
|
||||||
//// Position relative to:
|
//// Position relative to:
|
||||||
|
@ -112,8 +112,11 @@ public class ShockCordConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
panel2.add(new UnitSelector(od), "growx");
|
panel2.add(new UnitSelector(od), "growx");
|
||||||
panel2.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
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
|
//// General and General properties
|
||||||
tabbedPane.insertTab(trans.get("ShockCordCfg.tab.General"), null, panel,
|
tabbedPane.insertTab(trans.get("ShockCordCfg.tab.General"), null, panel,
|
||||||
|
@ -185,8 +185,13 @@ public class StreamerConfig extends RecoveryDeviceConfig {
|
|||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(od), "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
|
//// Deployment
|
||||||
//// Deploys at:
|
//// Deploys at:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user