added gui and model elements for stage multiplicity

This commit is contained in:
Daniel_M_Williams 2015-06-22 16:10:13 -04:00
parent c5d47cf806
commit 8e268a9a25
4 changed files with 64 additions and 19 deletions

View File

@ -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

View File

@ -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();

View File

@ -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<StageSeparationConfiguration> 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<StageSeparationConfiguration>(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);
}

View File

@ -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<T>[] values) {
// ComboBoxModel<RocketComponent.Position> posRelModel = new EnumModel<RocketComponent.Position>(component, "RelativePosition",
// new RocketComponent.Position[] {
// RocketComponent.Position.TOP,
// RocketComponent.Position.MIDDLE,
// RocketComponent.Position.BOTTOM,
// RocketComponent.Position.ABSOLUTE
// });
// JComboBox<?> combo = new JComboBox<RocketComponent.Position>( posRelModel );
// motherPanel.add(combo, "spanx, growx, wrap");
// parallelEnabledModel.addEnableComponent( positionLabel);
//
// plus
JLabel positionPlusLabel = new JLabel(trans.get("LaunchLugCfg.lbl.plus"));
motherPanel.add( positionPlusLabel );