From 4f716b40afb1375480327fada58444229b7d65cb Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 13 Jun 2015 22:47:19 -0400 Subject: [PATCH] Updated GUI with axial stage position elements --- core/resources/l10n/messages.properties | 11 +-- .../rocketcomponent/RocketComponent.java | 23 ++++- .../sf/openrocket/rocketcomponent/Stage.java | 44 +++++++-- .../gui/configdialog/StageConfig.java | 99 +++++++++++++------ .../gui/scalefigure/RocketFigure.java | 4 +- 5 files changed, 124 insertions(+), 57 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 708ba5629..e55e442e5 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -823,15 +823,12 @@ RocketCompCfg.lbl.Componentname = Component name: RocketCompCfg.ttip.Thecomponentname = The component name. RocketCompCfg.tab.Override = Override RocketCompCfg.tab.MassandCGoverride = Mass and CG override options -RocketCompCfg.tab.Pod = Pod -RocketCompCfg.tab.PodComment = Options for locating ExteriorComponents outside the Rocket RocketCompCfg.tab.Parallel = Parallel -RocketCompCfg.tab.ParallelComment = Options for locating Stages parallel to other stages +RocketCompCfg.tab.ParallelComment = Options for locating stages parallel to other stages RocketCompCfg.outside.stage = Make this Stage Parallel -RocketCompCfg.outside.pod = Move this Component Outside -RocketCompCfg.outside.radius = Radial Distance (meters) -RocketCompCfg.outside.angle = Angle (Radians) -RocketCompCfg.outside.rotation = Rotation (Radians) +RocketCompCfg.outside.radius = Radial Distance +RocketCompCfg.outside.angle = Angle +RocketCompCfg.outside.rotation = Rotation RocketCompCfg.tab.Figure = Figure RocketCompCfg.tab.Figstyleopt = Figure style options RocketCompCfg.tab.Comment = Comment diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 8edda664b..906bfc3dd 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1000,11 +1000,22 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab mutex.lock("toRelative"); try { double absoluteX = Double.NaN; + double relativeY = 0; + double relativeZ = 0; RocketComponent search = dest; Coordinate[] array = new Coordinate[1]; array[0] = c; RocketComponent component = this; + if (component instanceof OutsideComponent) { + OutsideComponent ext = (OutsideComponent) component; + double phi = ext.getAngularPosition(); + double r = ext.getRadialPosition(); + relativeY = r * Math.cos(phi); + relativeZ = r * Math.sin(phi); + array[0].setY(relativeY); + array[0].setZ(relativeZ); + } while ((component != search) && (component.parent != null)) { array = component.shiftCoordinates(array); @@ -1012,21 +1023,21 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab switch (component.relativePosition) { case TOP: for (int i = 0; i < array.length; i++) { - array[i] = array[i].add(component.position, 0, 0); + array[i] = array[i].add(component.position, relativeY, relativeZ); } break; case MIDDLE: for (int i = 0; i < array.length; i++) { array[i] = array[i].add(component.position + - (component.parent.length - component.length) / 2, 0, 0); + (component.parent.length - component.length) / 2, relativeY, relativeZ); } break; case BOTTOM: for (int i = 0; i < array.length; i++) { array[i] = array[i].add(component.position + - (component.parent.length - component.length), 0, 0); + (component.parent.length - component.length), relativeY, relativeZ); } break; @@ -1038,17 +1049,18 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab RocketComponent comp = component.parent.children.get(index); double componentLength = comp.getTotalLength(); for (int i = 0; i < array.length; i++) { - array[i] = array[i].add(componentLength, 0, 0); + array[i] = array[i].add(componentLength, relativeY, relativeZ); } } for (int i = 0; i < array.length; i++) { - array[i] = array[i].add(component.position + component.parent.length, 0, 0); + array[i] = array[i].add(component.position + component.parent.length, relativeY, relativeZ); } break; case ABSOLUTE: search = null; // Requires back-search if dest!=null if (Double.isNaN(absoluteX)) { + // TODO: requires debugging if thsi component is an External Pods or stage absoluteX = component.position; } break; @@ -1063,6 +1075,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab if (!Double.isNaN(absoluteX)) { for (int i = 0; i < array.length; i++) { + // TODO: requires debugging if thsi component is an External Pods or stage array[i] = array[i].setX(absoluteX + c.x); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index 6fc9ca3e1..f568b5d27 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -14,8 +14,6 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon private double position_radial_m = 0; private double rotation_rad = 0; - // ParallelStagingConfiguration parallelConfiguration = null; - public Stage() { this.separationConfigurations = new FlightConfigurationImpl(this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration()); } @@ -31,11 +29,6 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return separationConfigurations; } - // public ParallelStagingConfiguration getParallelStageConfiguration() { - // return parallelConfiguration; - // } - - @Override public boolean allowsChildren() { return true; @@ -54,8 +47,6 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return BodyComponent.class.isAssignableFrom(type); } - - @Override public void cloneFlightConfiguration(String oldConfigId, String newConfigId) { separationConfigurations.cloneFlightConfiguration(oldConfigId, newConfigId); @@ -74,7 +65,6 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return this.outside; } - public boolean isInline() { return !this.outside; } @@ -82,6 +72,9 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setOutside(final boolean _outside) { this.outside = _outside; + if (this.outside) { + fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); + } } @Override @@ -95,6 +88,9 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setAngularPosition(final double angle_rad) { this.position_angular_rad = angle_rad; + if (this.outside) { + fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); + } } @Override @@ -108,6 +104,10 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setRadialPosition(final double radius) { this.position_radial_m = radius; + if (this.outside) { + fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); + } + } @Override @@ -121,6 +121,30 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon @Override public void setRotation(final double rotation) { this.rotation_rad = rotation; + if (this.outside) { + fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); + } + } + public RocketComponent.Position getRelativePositionMethod() { + return this.relativePosition; + } + + @Override + public void setRelativePosition(final Position position) { + super.setRelativePosition(position); + } + + public double getAxialPosition() { + return super.getPositionValue(); + } + + public void setAxialPosition(final double _pos) { + super.setPositionValue(_pos); + } + + + + } diff --git a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java index 50840ab96..0586654f4 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java @@ -3,6 +3,7 @@ package net.sf.openrocket.gui.configdialog; import java.awt.Component; import java.awt.Container; +import javax.swing.ComboBoxModel; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -19,7 +20,9 @@ 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.components.BasicSlider; import net.sf.openrocket.gui.components.StyledLabel; +import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.StyledLabel.Style; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.OutsideComponent; @@ -28,12 +31,11 @@ import net.sf.openrocket.rocketcomponent.Stage; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; +import net.sf.openrocket.util.ChangeSource; public class StageConfig extends RocketComponentConfig { private static final Translator trans = Application.getTranslator(); - - private BooleanModel parallelEnabledModel = null; - private JPanel parallelEnabledPanel = null; + public StageConfig(OpenRocketDocument document, RocketComponent component) { super(document, component); @@ -54,51 +56,84 @@ public class StageConfig extends RocketComponentConfig { private JPanel parallelTab( final Stage stage ){ // enable parallel staging JPanel motherPanel = new JPanel( new MigLayout("fill")); - parallelEnabledModel = new BooleanModel( component, "Outside"); + BooleanModel parallelEnabledModel = new BooleanModel( component, "Outside"); parallelEnabledModel.setValue( stage.getOutside()); JCheckBox parallelEnabled = new JCheckBox( parallelEnabledModel); parallelEnabled.setText(trans.get("RocketCompCfg.outside.stage")); motherPanel.add(parallelEnabled, "wrap"); - JPanel enabledPanel = new JPanel( new MigLayout("fill")); - this.parallelEnabledPanel = enabledPanel; - - enabledPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "growx,wrap"); + motherPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "spanx 3, growx, wrap"); - // set radial distance - enabledPanel.add(new JLabel(trans.get("RocketCompCfg.outside.radius")), "align left"); - DoubleModel radiusModel = new DoubleModel( stage, "RadialPosition", 0.0); - radiusModel.setCurrentUnit( UnitGroup.UNITS_DISTANCE.getSIUnit() ); + // set radial distance + JLabel radiusLabel = new JLabel(trans.get("RocketCompCfg.outside.radius")); + motherPanel.add( radiusLabel , "align left"); + parallelEnabledModel.addEnableComponent( radiusLabel, true); + DoubleModel radiusModel = new DoubleModel( stage, "RadialPosition", UnitGroup.UNITS_LENGTH, 0); + //radiusModel.setCurrentUnit( UnitGroup.UNITS_LENGTH.getUnit("cm")); JSpinner radiusSpinner = new JSpinner( radiusModel.getSpinnerModel()); radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner )); - enabledPanel.add(radiusSpinner , "growx, wrap, align right"); - - // set angle around the primary stage - enabledPanel.add(new JLabel(trans.get("RocketCompCfg.outside.angle")), "align left"); - DoubleModel angleModel = new DoubleModel( stage, "AngularPosition", 0.0, Math.PI*2); + motherPanel.add(radiusSpinner , "growx 1, align right"); + parallelEnabledModel.addEnableComponent( radiusSpinner, true); + UnitSelector radiusUnitSelector = new UnitSelector(radiusModel); + motherPanel.add(radiusUnitSelector, "growx 1, wrap"); + parallelEnabledModel.addEnableComponent( radiusUnitSelector , true); + + // set location angle around the primary stage + JLabel angleLabel = new JLabel(trans.get("RocketCompCfg.outside.angle")); + motherPanel.add( angleLabel, "align left"); + parallelEnabledModel.addEnableComponent( angleLabel, true); + DoubleModel angleModel = new DoubleModel( stage, "AngularPosition", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2); angleModel.setCurrentUnit( UnitGroup.UNITS_ANGLE.getUnit("rad")); JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel()); angleSpinner.setEditor(new SpinnerEditor(angleSpinner)); - enabledPanel.add(angleSpinner, "growx, wrap"); + motherPanel.add(angleSpinner, "growx 1"); + parallelEnabledModel.addEnableComponent( angleSpinner, true); + UnitSelector angleUnitSelector = new UnitSelector(angleModel); + motherPanel.add( angleUnitSelector, "growx 1, wrap"); + parallelEnabledModel.addEnableComponent( angleUnitSelector , true); - enabledPanel.add(new JLabel(trans.get("RocketCompCfg.outside.rotation")), "align left"); - DoubleModel rotationModel = new DoubleModel( stage, "Rotation", 0.0, Math.PI*2); + // set rotation angle of the stage. Does not affect the location + JLabel rotationLabel = new JLabel(trans.get("RocketCompCfg.outside.rotation")); + motherPanel.add( rotationLabel, "align left"); + parallelEnabledModel.addEnableComponent( rotationLabel, true); + DoubleModel rotationModel = new DoubleModel( stage, "Rotation", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2); rotationModel.setCurrentUnit( UnitGroup.UNITS_ANGLE.getUnit("rad") ); JSpinner rotationSpinner = new JSpinner(rotationModel.getSpinnerModel()); rotationSpinner.setEditor(new SpinnerEditor(rotationSpinner)); - enabledPanel.add(rotationSpinner, "growx, wrap"); - - - parallelEnabled.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - setDeepEnabled( parallelEnabledPanel, parallelEnabledModel.getValue()); - } - }); - setDeepEnabled( parallelEnabledPanel, parallelEnabledModel.getValue()); + motherPanel.add(rotationSpinner, "growx 1"); + parallelEnabledModel.addEnableComponent( rotationSpinner, true); + UnitSelector rotationUnitSelector = new UnitSelector( rotationModel); + motherPanel.add( rotationUnitSelector, "growx 1, wrap"); + parallelEnabledModel.addEnableComponent( rotationUnitSelector , true); - motherPanel.add( enabledPanel , "growx, wrap"); - + // setPositions relative to parent component + JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")); + motherPanel.add( positionLabel); + parallelEnabledModel.addEnableComponent( positionLabel); + + // 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 ); + parallelEnabledModel.addEnableComponent( positionPlusLabel ); + + DoubleModel axialPositionModel = new DoubleModel(component, "AxialPosition", UnitGroup.UNITS_LENGTH); + JSpinner axPosSpin= new JSpinner( axialPositionModel.getSpinnerModel()); + axPosSpin.setEditor(new SpinnerEditor(axPosSpin)); + motherPanel.add(axPosSpin, "growx"); + parallelEnabledModel.addEnableComponent( positionPlusLabel ); + return motherPanel; } diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index b864de545..cf9852bd0 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -173,9 +173,6 @@ public class RocketFigure extends AbstractScaleFigure { } - - - /** * Updates the figure shapes and figure size. */ @@ -195,6 +192,7 @@ public class RocketFigure extends AbstractScaleFigure { } } + System.err.println(" updating the RocketFigure."); repaint(); fireChangeEvent(); }