Merge pull request #1425 from SiboVG/issue-1422

[Fixes #1422] Add sliders to pods/booster config + fix radius offset not updating with radius method
This commit is contained in:
SiboVG 2022-06-11 15:10:01 +02:00 committed by GitHub
commit 6bcf3e0362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 156 additions and 70 deletions

View File

@ -952,10 +952,10 @@ StageConfig.tab.Separation.ttip = Stage separation options
StageConfig.separation.lbl.title = Select when this stage separates: StageConfig.separation.lbl.title = Select when this stage separates:
StageConfig.separation.lbl.plus = plus StageConfig.separation.lbl.plus = plus
StageConfig.separation.lbl.seconds = seconds StageConfig.separation.lbl.seconds = seconds
StageConfig.parallel.radius = Radial Distance StageConfig.parallel.radius = Radial Distance:
StageConfig.parallel.angle = Angle StageConfig.parallel.angle = Angle:
StageConfig.parallel.count = Number of Copies StageConfig.parallel.count = Number of Copies:
StageConfig.parallel.offset = Offset Value StageConfig.parallel.plus = plus
!EllipticalFinSetConfig !EllipticalFinSetConfig
EllipticalFinSetCfg.Nbroffins = Number of fins: EllipticalFinSetCfg.Nbroffins = Number of fins:
@ -1481,20 +1481,18 @@ Shape.Haackseries.desc2 = The Haack series <i>nose cones</i> are designed to min
! RocketComponent ! RocketComponent
RocketComponent.Position.Method.Axial.Label = Radius Positioning Method
RocketComponent.Position.Method.Axial.ABSOLUTE = Tip of the nose cone RocketComponent.Position.Method.Axial.ABSOLUTE = Tip of the nose cone
RocketComponent.Position.Method.Axial.AFTER = After the sibling component RocketComponent.Position.Method.Axial.AFTER = After the sibling component
RocketComponent.Position.Method.Axial.BOTTOM = Bottom of the parent component RocketComponent.Position.Method.Axial.BOTTOM = Bottom of the parent component
RocketComponent.Position.Method.Axial.MIDDLE = Middle of the parent component RocketComponent.Position.Method.Axial.MIDDLE = Middle of the parent component
RocketComponent.Position.Method.Axial.TOP = Top of the parent component RocketComponent.Position.Method.Axial.TOP = Top of the parent component
RocketComponent.Position.Method.Radius.Label = Radius Positioning Method RocketComponent.Position.Method.Radius.Label = Radius relative to:
RocketComponent.Position.Method.Radius.FREE = Position relative to the component's center RocketComponent.Position.Method.Radius.FREE = Center of the parent component
RocketComponent.Position.Method.Radius.SURFACE = Position on the target component surface (without offset) RocketComponent.Position.Method.Radius.SURFACE = Surface of the parent component (without offset)
RocketComponent.Position.Method.Radius.RELATIVE = Position relative to the component surface RocketComponent.Position.Method.Radius.RELATIVE = Surface of the parent component
RocketComponent.Position.Method.Radius.COAXIAL = Position on the same axis as the target component RocketComponent.Position.Method.Radius.COAXIAL = Same axis as the target component
RocketComponent.Position.Method.Angle.Label = Angle Positioning Method
RocketComponent.Position.Method.Angle.RELATIVE = Relative to the parent component RocketComponent.Position.Method.Angle.RELATIVE = Relative to the parent component
RocketComponent.Position.Method.Angle.FIXED = Angle is fixed. RocketComponent.Position.Method.Angle.FIXED = Angle is fixed.
RocketComponent.Position.Method.Angle.MIRROR_XY = Mirror relative to the rocket's x-y plane RocketComponent.Position.Method.Angle.MIRROR_XY = Mirror relative to the rocket's x-y plane

View File

@ -424,7 +424,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.stages.clear(); this.stages.clear();
for (AxialStage curStage : this.rocket.getStageList()) { for (AxialStage curStage : this.rocket.getStageList()) {
if (curStage == null) continue;
StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true); StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true);
this.stages.put(curStage.getStageNumber(), flagsToAdd); this.stages.put(curStage.getStageNumber(), flagsToAdd);
} }

View File

@ -204,7 +204,14 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
} }
} }
setRadius( radiusMethod, radius_m ); if (radius_m == this.radiusOffset_m) return;
if (this.radiusMethod.clampToZero() ) {
this.radiusOffset_m = 0.0;
} else {
this.radiusOffset_m = radius_m;
}
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@Override @Override
@ -230,15 +237,14 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
mutex.verify(); mutex.verify();
RadiusMethod newMethod = requestedMethod;
double newRadius = requestedRadius; double newRadius = requestedRadius;
if( newMethod.clampToZero() ) { if( requestedMethod.clampToZero() ) {
newRadius = 0.; newRadius = 0.;
} }
this.radiusMethod = newMethod; this.radiusMethod = requestedMethod;
this.radiusOffset_m = newRadius; this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@ -267,14 +273,18 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
} }
@Override @Override
public void setRadiusMethod(RadiusMethod newRadiusMethod) { public void setRadiusMethod(RadiusMethod newMethod) {
for (RocketComponent listener : configListeners) { for (RocketComponent listener : configListeners) {
if (listener instanceof ParallelStage) { if (listener instanceof ParallelStage) {
((ParallelStage) listener).setRadiusMethod(newRadiusMethod); ((ParallelStage) listener).setRadiusMethod(newMethod);
} }
} }
setRadius( newRadiusMethod, this.radiusOffset_m ); if (newMethod == this.radiusMethod) return;
mutex.verify();
double radius = this.radiusMethod.getRadius(getParent(), this, this.radiusOffset_m); // Radius from the parent's center
setRadius(newMethod, radius);
} }

View File

@ -225,6 +225,9 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
} }
mutex.verify(); mutex.verify();
if (radius_m == this.radiusOffset_m) return;
if (this.radiusMethod.clampToZero()) { if (this.radiusMethod.clampToZero()) {
this.radiusOffset_m = 0.0; this.radiusOffset_m = 0.0;
} else { } else {
@ -246,9 +249,11 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
} }
} }
if (newMethod == this.radiusMethod) return;
mutex.verify(); mutex.verify();
this.radiusMethod = newMethod; double radius = this.radiusMethod.getRadius(getParent(), this, this.radiusOffset_m); // Radius from the parent's center
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); setRadius(newMethod, radius);
} }
@Override @Override
@ -261,15 +266,14 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
mutex.verify(); mutex.verify();
RadiusMethod newMethod = requestMethod;
double newRadius = requestRadius; double newRadius = requestRadius;
if( this.radiusMethod.clampToZero() ) { if( this.radiusMethod.clampToZero() ) {
newRadius = 0.; newRadius = 0.;
} }
this.radiusMethod = newMethod; this.radiusMethod = requestMethod;
this.radiusOffset_m = newRadius; this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }

View File

@ -16,6 +16,11 @@ public enum RadiusMethod implements DistanceMethod {
public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){ public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){
return 0.; return 0.;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
return 0;
}
}, },
FREE(Application.getTranslator().get("RocketComponent.Position.Method.Radius.FREE") ){ FREE(Application.getTranslator().get("RocketComponent.Position.Method.Radius.FREE") ){
@ -26,6 +31,11 @@ public enum RadiusMethod implements DistanceMethod {
public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){ public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){
return requestedOffset; return requestedOffset;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
return radius;
}
}, },
RELATIVE ( Application.getTranslator().get("RocketComponent.Position.Method.Radius.RELATIVE") ){ RELATIVE ( Application.getTranslator().get("RocketComponent.Position.Method.Radius.RELATIVE") ){
@ -43,6 +53,18 @@ public enum RadiusMethod implements DistanceMethod {
} }
return radius; return radius;
} }
@Override
public double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, double radius) {
double offset = radius;
if (parentComponent instanceof BodyTube) {
offset -= ((BodyTube)parentComponent).getOuterRadius();
}
if (thisComponent instanceof RadiusPositionable) {
offset -= ((RadiusPositionable)thisComponent).getBoundingRadius();
}
return offset;
}
}, },
// Defines placement relative to the outside of the target component // Defines placement relative to the outside of the target component
@ -60,6 +82,11 @@ public enum RadiusMethod implements DistanceMethod {
} }
return radius; return radius;
} }
@Override
public double getAsOffset(RocketComponent parentComponent, RocketComponent thisComponent, double radius) {
return 0;
}
}; };
public static final RadiusMethod[] choices(){ public static final RadiusMethod[] choices(){
@ -83,4 +110,14 @@ public enum RadiusMethod implements DistanceMethod {
public boolean clampToZero() { return true; } public boolean clampToZero() { return true; }
public abstract double getRadius(final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ); public abstract double getRadius(final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset );
/**
* Returns the radius offset argument (starting from the center of its parent) as an offset value for this
* RadiusMethod.
* @param parentComponent parent of this component
* @param thisComponent the component for which the offset is requested
* @param radius the radius offset argument
* @return the offset value of this RadiusMethod that yields the given radius
*/
public abstract double getAsOffset(final RocketComponent parentComponent, final RocketComponent thisComponent, final double radius);
} }

View File

@ -251,7 +251,7 @@ public class ParallelStageTest extends BaseTestCase {
// vv function under test // vv function under test
parallelBoosterStage.setAxialOffset( AxialMethod.BOTTOM, 0.0 ); parallelBoosterStage.setAxialOffset( AxialMethod.BOTTOM, 0.0 );
final double targetRadiusOffset = 0.01; final double targetRadiusOffset = 0.01;
parallelBoosterStage.setRadius( RadiusMethod.RELATIVE, targetRadiusOffset ); parallelBoosterStage.setRadius( RadiusMethod.RELATIVE, RadiusMethod.RELATIVE.getRadius(parallelBoosterStage.getParent(), parallelBoosterStage, targetRadiusOffset));
// ^^ function under test // ^^ function under test
assertFalse(RadiusMethod.RELATIVE.clampToZero()); assertFalse(RadiusMethod.RELATIVE.clampToZero());

View File

@ -208,6 +208,19 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
quad2 = quad1 = quad0 = 0; // Not used quad2 = quad1 = quad0 = 0; // Not used
} }
public ValueSliderModel(double min, DoubleModel max) {
this.islinear = true;
linearPosition = 1.0;
this.min = new DoubleModel(min);
this.mid = max; // Never use exponential scale
this.max = max;
max.addChangeListener(this);
quad2 = quad1 = quad0 = 0; // Not used
}
/** /**
@ -427,6 +440,10 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
return new ValueSliderModel(min, max); return new ValueSliderModel(min, max);
} }
public BoundedRangeModel getSliderModel(double min, DoubleModel max) {
return new ValueSliderModel(min, max);
}
public BoundedRangeModel getSliderModel(double min, double mid, double max) { public BoundedRangeModel getSliderModel(double min, double mid, double max) {
return new ValueSliderModel(min, mid, max); return new ValueSliderModel(min, mid, max);
} }

View File

@ -12,6 +12,7 @@ import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.adaptors.EnumModel; import net.sf.openrocket.gui.adaptors.EnumModel;
import net.sf.openrocket.gui.adaptors.IntegerModel; import net.sf.openrocket.gui.adaptors.IntegerModel;
import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ComponentAssembly;
@ -23,13 +24,21 @@ import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.EventObject;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ComponentAssemblyConfig extends RocketComponentConfig { public class ComponentAssemblyConfig extends RocketComponentConfig {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private final RocketComponent component;
public ComponentAssemblyConfig(OpenRocketDocument document, RocketComponent component) { public ComponentAssemblyConfig(OpenRocketDocument document, RocketComponent component) {
super(document, component); super(document, component);
this.component = component;
// only stages which are actually off-centerline will get the dialog here: // only stages which are actually off-centerline will get the dialog here:
if( ParallelStage.class.isAssignableFrom( component.getClass()) || PodSet.class.isAssignableFrom( component.getClass())){ if( ParallelStage.class.isAssignableFrom( component.getClass()) || PodSet.class.isAssignableFrom( component.getClass())){
@ -45,9 +54,9 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
// radial distance method // radial distance method
JLabel radiusMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Radius.Label")); JLabel radiusMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Radius.Label"));
motherPanel.add( radiusMethodLabel, "align left"); motherPanel.add( radiusMethodLabel, "align left");
final EnumModel<RadiusMethod> radiusMethodModel = new EnumModel<RadiusMethod>( boosters, "RadiusMethod", RadiusMethod.choices()); final ComboBoxModel<RadiusMethod> radiusMethodModel = new EnumModel<RadiusMethod>( boosters, "RadiusMethod", RadiusMethod.choices());
final JComboBox<RadiusMethod> radiusMethodCombo = new JComboBox<RadiusMethod>( radiusMethodModel ); final JComboBox<RadiusMethod> radiusMethodCombo = new JComboBox<RadiusMethod>( radiusMethodModel );
motherPanel.add( radiusMethodCombo, "align left, wrap"); motherPanel.add( radiusMethodCombo, "spanx 3, growx, wrap");
// set radial distance // set radial distance
JLabel radiusLabel = new JLabel(trans.get("StageConfig.parallel.radius")); JLabel radiusLabel = new JLabel(trans.get("StageConfig.parallel.radius"));
@ -57,28 +66,31 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
JSpinner radiusSpinner = new JSpinner(radiusModel.getSpinnerModel()); JSpinner radiusSpinner = new JSpinner(radiusModel.getSpinnerModel());
radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner)); radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner));
motherPanel.add(radiusSpinner , "growx 1, align right"); motherPanel.add(radiusSpinner , "wmin 65lp, growx 1, align right");
// autoRadOffsModel.addEnableComponent(radiusSpinner, false); // autoRadOffsModel.addEnableComponent(radiusSpinner, false);
UnitSelector radiusUnitSelector = new UnitSelector(radiusModel); UnitSelector radiusUnitSelector = new UnitSelector(radiusModel);
motherPanel.add(radiusUnitSelector, "growx 1, wrap"); motherPanel.add(radiusUnitSelector, "growx 1");
// autoRadOffsModel.addEnableComponent(radiusUnitSelector, false); motherPanel.add(new BasicSlider(radiusModel.getSliderModel(0, new DoubleModel(component.getParent(), "OuterRadius", 4.0, UnitGroup.UNITS_LENGTH))),
"gapleft para, growx 2, wrap");
// // set location angle around the primary stage radiusMethodCombo.addItemListener(new ItemListener() {
// JLabel angleMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Angle.Label")); @Override
// motherPanel.add( angleMethodLabel, "align left"); public void itemStateChanged(ItemEvent e) {
// EnumModel<AngleMethod> angleMethodModel = new EnumModel<AngleMethod>( boosters, "AngleMethod", AngleMethod.choices() ); radiusModel.stateChanged(new EventObject(e));
// final JComboBox<AngleMethod> angleMethodCombo = new JComboBox<AngleMethod>( angleMethodModel ); }
// motherPanel.add( angleMethodCombo, "align left, wrap"); });
// set angle
JLabel angleLabel = new JLabel(trans.get("StageConfig.parallel.angle")); JLabel angleLabel = new JLabel(trans.get("StageConfig.parallel.angle"));
motherPanel.add( angleLabel, "align left"); motherPanel.add( angleLabel, "align left");
DoubleModel angleModel = new DoubleModel( boosters, "AngleOffset", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2); DoubleModel angleModel = new DoubleModel( boosters, "AngleOffset", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2);
JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel()); JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel());
angleSpinner.setEditor(new SpinnerEditor(angleSpinner)); angleSpinner.setEditor(new SpinnerEditor(angleSpinner));
motherPanel.add(angleSpinner, "growx 1"); motherPanel.add(angleSpinner, "wmin 65lp, growx 1");
UnitSelector angleUnitSelector = new UnitSelector(angleModel); UnitSelector angleUnitSelector = new UnitSelector(angleModel);
motherPanel.add( angleUnitSelector, "growx 1, wrap"); motherPanel.add( angleUnitSelector, "growx 1");
motherPanel.add(new BasicSlider(angleModel.getSliderModel(-Math.PI, Math.PI)), "gapleft para, growx 2, wrap");
// set multiplicity // set multiplicity
JLabel countLabel = new JLabel(trans.get("StageConfig.parallel.count")); JLabel countLabel = new JLabel(trans.get("StageConfig.parallel.count"));
@ -87,7 +99,7 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
IntegerModel countModel = new IntegerModel( boosters, "InstanceCount", 1); IntegerModel countModel = new IntegerModel( boosters, "InstanceCount", 1);
JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel()); JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel());
countSpinner.setEditor(new SpinnerEditor(countSpinner)); countSpinner.setEditor(new SpinnerEditor(countSpinner));
motherPanel.add(countSpinner, "growx 1, wrap"); motherPanel.add(countSpinner, "wmin 65lp, growx 1, wrap");
// setPositions relative to parent component // setPositions relative to parent component
JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")); JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto"));
@ -95,21 +107,29 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
ComboBoxModel<AxialMethod> axialPositionMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods ); ComboBoxModel<AxialMethod> axialPositionMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );
JComboBox<?> positionMethodCombo = new JComboBox<AxialMethod>( axialPositionMethodModel ); JComboBox<?> positionMethodCombo = new JComboBox<AxialMethod>( axialPositionMethodModel );
motherPanel.add(positionMethodCombo, "spanx 2, growx, wrap"); motherPanel.add(positionMethodCombo, "spanx 3, growx, wrap");
// relative offset labels // plus
JLabel positionPlusLabel = new JLabel(trans.get("StageConfig.parallel.offset")); motherPanel.add(new JLabel(trans.get("StageConfig.parallel.plus")), "right");
motherPanel.add( positionPlusLabel );
DoubleModel axialOffsetModel = new DoubleModel( boosters, "AxialOffset", UnitGroup.UNITS_LENGTH);
JSpinner axPosSpin= new JSpinner( axialOffsetModel.getSpinnerModel()); final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
axPosSpin.setEditor(new SpinnerEditor(axPosSpin)); final JSpinner axialOffsetSpinner = new JSpinner(axialOffsetModel.getSpinnerModel());
motherPanel.add(axPosSpin, "growx"); axialOffsetSpinner.setEditor(new SpinnerEditor(axialOffsetSpinner));
UnitSelector axialOffsetUnitSelector = new UnitSelector(axialOffsetModel);
motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap");
// For DEBUG purposes motherPanel.add(axialOffsetSpinner, "wmin 65lp, growx 1");
//System.err.println(assembly.getRocket().toDebugTree());
positionMethodCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
axialOffsetModel.stateChanged(new EventObject(e));
}
});
motherPanel.add(new UnitSelector(axialOffsetModel), "growx");
motherPanel.add(new BasicSlider(axialOffsetModel.getSliderModel(
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
new DoubleModel(component.getParent(), "Length"))),
"gapleft para, growx 2, wrap");
return motherPanel; return motherPanel;
} }