From 8e268a9a25d093fa864fedb4a607ba8fb623948e Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Mon, 22 Jun 2015 16:10:13 -0400 Subject: [PATCH] added gui and model elements for stage multiplicity --- core/resources/l10n/messages.properties | 1 + .../rocketcomponent/OutsideComponent.java | 17 +++++++- .../sf/openrocket/rocketcomponent/Stage.java | 40 ++++++++++++++++--- .../gui/configdialog/StageConfig.java | 25 ++++++------ 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index cffcc0834..14bd5061d 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -828,6 +828,7 @@ RocketCompCfg.tab.ParallelComment = Options for locating stages parallel to othe RocketCompCfg.outside.stage = Make this Stage Parallel RocketCompCfg.outside.radius = Radial Distance RocketCompCfg.outside.angle = Angle +RocketCompCfg.outside.count = Number of Boosters RocketCompCfg.outside.rotation = Rotation RocketCompCfg.outside.componentname = Name of parent component RocketCompCfg.tab.Figure = Figure diff --git a/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java index 2b7bd2130..f17562c69 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java @@ -32,10 +32,25 @@ public interface OutsideComponent { */ public void setAngularPosition(final double phi); + /** + * Number of instances this stage represents + * + * @return number of instances this stage currently represents + */ + public int getCount(); + + /** + * Set the multiplicity of this component + * + * @param number of instances this component should represent + */ + public void setCount(final int phi); + + /** * Get the position of this component in polar coordinates * - * @return Radial position in radians (m) + * @return Radial position in radians (m) */ public double getRadialPosition(); diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index 079ea9497..04c16ead2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -3,17 +3,25 @@ package net.sf.openrocket.rocketcomponent; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class Stage extends ComponentAssembly implements FlightConfigurableComponent, OutsideComponent { static final Translator trans = Application.getTranslator(); + private static final Logger log = LoggerFactory.getLogger(Stage.class); private FlightConfigurationImpl separationConfigurations; private boolean outside = false; - private double position_angular_rad = 0; - private double position_radial_m = 0; + private double angularPosition_rad = 0; + private double radialPosition_m = 0; private double rotation_rad = 0; + private int count = 2; + private double separationAngle = Math.PI; + + public Stage() { this.separationConfigurations = new FlightConfigurationImpl(this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration()); } @@ -72,6 +80,26 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setOutside(final boolean _outside) { this.outside = _outside; + if (Position.AFTER == this.relativePosition) { + this.relativePosition = Position.BOTTOM; + this.position = 0; + } + if (this.outside) { + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); + } + } + + @Override + public int getCount() { + return this.count; + } + + @Override + public void setCount(final int _count) { + mutex.verify(); + this.count = _count; + this.separationAngle = Math.PI * 2 / this.count; + if (this.outside) { fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } @@ -80,7 +108,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public double getAngularPosition() { if (this.outside) { - return this.position_angular_rad; + return this.angularPosition_rad; } else { return 0.; } @@ -89,7 +117,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setAngularPosition(final double angle_rad) { - this.position_angular_rad = angle_rad; + this.angularPosition_rad = angle_rad; if (this.outside) { fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } @@ -98,7 +126,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public double getRadialPosition() { if (this.outside) { - return this.position_radial_m; + return this.radialPosition_m; } else { return 0.; } @@ -106,7 +134,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setRadialPosition(final double radius) { - this.position_radial_m = radius; + this.radialPosition_m = radius; if (this.outside) { fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } diff --git a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java index a60eddea0..38058a789 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java @@ -20,6 +20,7 @@ import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.BooleanModel; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.EnumModel; +import net.sf.openrocket.gui.adaptors.IntegerModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.UnitSelector; @@ -106,6 +107,17 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add( rotationUnitSelector, "growx 1, wrap"); parallelEnabledModel.addEnableComponent( rotationUnitSelector , true); + // set multiplicity + JLabel countLabel = new JLabel(trans.get("RocketCompCfg.outside.count")); + motherPanel.add( countLabel, "align left"); + parallelEnabledModel.addEnableComponent( countLabel, true); + + IntegerModel countModel = new IntegerModel( stage, "Count", 1 ); + JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel()); + countSpinner.setEditor(new SpinnerEditor(countSpinner)); + motherPanel.add(countSpinner, "growx 1, wrap"); + parallelEnabledModel.addEnableComponent( countSpinner, true); + // setPositions relative to parent component JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")); motherPanel.add( positionLabel); @@ -136,18 +148,7 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add( relToCombo , "growx, wrap"); parallelEnabledModel.addEnableComponent( relToCombo ); -// // EnumModel(ChangeSource source, String valueName, Enum[] values) { -// ComboBoxModel posRelModel = new EnumModel(component, "RelativePosition", -// new RocketComponent.Position[] { -// RocketComponent.Position.TOP, -// RocketComponent.Position.MIDDLE, -// RocketComponent.Position.BOTTOM, -// RocketComponent.Position.ABSOLUTE -// }); -// JComboBox combo = new JComboBox( posRelModel ); -// motherPanel.add(combo, "spanx, growx, wrap"); -// parallelEnabledModel.addEnableComponent( positionLabel); -// + // plus JLabel positionPlusLabel = new JLabel(trans.get("LaunchLugCfg.lbl.plus")); motherPanel.add( positionPlusLabel );