diff --git a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java index 58adc3f39..69ecdc658 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java @@ -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; diff --git a/core/src/net/sf/openrocket/rocketcomponent/Parachute.java b/core/src/net/sf/openrocket/rocketcomponent/Parachute.java index e7b2a12c7..75a634266 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Parachute.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Parachute.java @@ -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() { diff --git a/swing/src/net/sf/openrocket/gui/configdialog/MassComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/MassComponentConfig.java index 4f510fc0f..d7177e998 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/MassComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/MassComponentConfig.java @@ -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: diff --git a/swing/src/net/sf/openrocket/gui/configdialog/ShockCordConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/ShockCordConfig.java index 745ddb649..4403f0049 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/ShockCordConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/ShockCordConfig.java @@ -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, diff --git a/swing/src/net/sf/openrocket/gui/configdialog/StreamerConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/StreamerConfig.java index c16ea1638..e05b2ad94 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/StreamerConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/StreamerConfig.java @@ -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: