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.plus = plus
StageConfig.separation.lbl.seconds = seconds
StageConfig.parallel.radius = Radial Distance
StageConfig.parallel.angle = Angle
StageConfig.parallel.count = Number of Copies
StageConfig.parallel.offset = Offset Value
StageConfig.parallel.radius = Radial Distance:
StageConfig.parallel.angle = Angle:
StageConfig.parallel.count = Number of Copies:
StageConfig.parallel.plus = plus
!EllipticalFinSetConfig
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.Position.Method.Axial.Label = Radius Positioning Method
RocketComponent.Position.Method.Axial.ABSOLUTE = Tip of the nose cone
RocketComponent.Position.Method.Axial.AFTER = After the sibling 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.TOP = Top of the parent component
RocketComponent.Position.Method.Radius.Label = Radius Positioning Method
RocketComponent.Position.Method.Radius.FREE = Position relative to the component's center
RocketComponent.Position.Method.Radius.SURFACE = Position on the target component surface (without offset)
RocketComponent.Position.Method.Radius.RELATIVE = Position relative to the component surface
RocketComponent.Position.Method.Radius.COAXIAL = Position on the same axis as the target component
RocketComponent.Position.Method.Radius.Label = Radius relative to:
RocketComponent.Position.Method.Radius.FREE = Center of the parent component
RocketComponent.Position.Method.Radius.SURFACE = Surface of the parent component (without offset)
RocketComponent.Position.Method.Radius.RELATIVE = Surface of the parent 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.FIXED = Angle is fixed.
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();
for (AxialStage curStage : this.rocket.getStageList()) {
if (curStage == null) continue;
StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true);
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
@ -229,16 +236,15 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
}
mutex.verify();
RadiusMethod newMethod = requestedMethod;
double newRadius = requestedRadius;
if( newMethod.clampToZero() ) {
if( requestedMethod.clampToZero() ) {
newRadius = 0.;
}
this.radiusMethod = newMethod;
this.radiusOffset_m = newRadius;
this.radiusMethod = requestedMethod;
this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
@ -267,14 +273,18 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
}
@Override
public void setRadiusMethod(RadiusMethod newRadiusMethod) {
public void setRadiusMethod(RadiusMethod newMethod) {
for (RocketComponent listener : configListeners) {
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

@ -26,7 +26,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
protected double angleSeparation = Math.PI;
// angle to the first pod
protected double angleOffset_rad = 0;
protected RadiusMethod radiusMethod = RadiusMethod.RELATIVE;
protected double radiusOffset_m = 0;
@ -225,19 +225,22 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
}
mutex.verify();
if( this.radiusMethod.clampToZero() ) {
if (radius_m == this.radiusOffset_m) return;
if (this.radiusMethod.clampToZero()) {
this.radiusOffset_m = 0.0;
}else {
} else {
this.radiusOffset_m = radius_m;
}
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
@Override
public RadiusMethod getRadiusMethod() {
return this.radiusMethod;
}
@Override
public void setRadiusMethod(RadiusMethod newMethod ) {
for (RocketComponent listener : configListeners) {
@ -246,11 +249,13 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
}
}
if (newMethod == this.radiusMethod) return;
mutex.verify();
this.radiusMethod = newMethod;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
double radius = this.radiusMethod.getRadius(getParent(), this, this.radiusOffset_m); // Radius from the parent's center
setRadius(newMethod, radius);
}
@Override
public void setRadius(RadiusMethod requestMethod, double requestRadius ) {
for (RocketComponent listener : configListeners) {
@ -260,16 +265,15 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
}
mutex.verify();
RadiusMethod newMethod = requestMethod;
double newRadius = requestRadius;
if( this.radiusMethod.clampToZero() ) {
newRadius = 0.;
}
this.radiusMethod = newMethod;
this.radiusOffset_m = newRadius;
this.radiusMethod = requestMethod;
this.radiusOffset_m = this.radiusMethod.getAsOffset(getParent(), this, newRadius);
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 ){
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") ){
@ -26,6 +31,11 @@ public enum RadiusMethod implements DistanceMethod {
public double getRadius( final RocketComponent parentComponent, final RocketComponent thisComponent, final double 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") ){
@ -43,6 +53,18 @@ public enum RadiusMethod implements DistanceMethod {
}
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
@ -60,10 +82,15 @@ public enum RadiusMethod implements DistanceMethod {
}
return radius;
}
@Override
public double getAsOffset(RocketComponent parentComponent, RocketComponent thisComponent, double radius) {
return 0;
}
};
public static final RadiusMethod[] choices(){
return new RadiusMethod[]{ RadiusMethod.FREE, RadiusMethod.RELATIVE };
return new RadiusMethod[]{ RadiusMethod.FREE, RadiusMethod.RELATIVE };
}
public final String description;
@ -82,5 +109,15 @@ public enum RadiusMethod implements DistanceMethod {
@Override
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
parallelBoosterStage.setAxialOffset( AxialMethod.BOTTOM, 0.0 );
final double targetRadiusOffset = 0.01;
parallelBoosterStage.setRadius( RadiusMethod.RELATIVE, targetRadiusOffset );
parallelBoosterStage.setRadius( RadiusMethod.RELATIVE, RadiusMethod.RELATIVE.getRadius(parallelBoosterStage.getParent(), parallelBoosterStage, targetRadiusOffset));
// ^^ function under test
assertFalse(RadiusMethod.RELATIVE.clampToZero());

View File

@ -207,6 +207,19 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
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
}
@ -426,6 +439,10 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
public BoundedRangeModel getSliderModel(double min, double 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) {
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.EnumModel;
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.l10n.Translator;
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.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")
public class ComponentAssemblyConfig extends RocketComponentConfig {
private static final Translator trans = Application.getTranslator();
private final RocketComponent component;
public ComponentAssemblyConfig(OpenRocketDocument document, RocketComponent component) {
super(document, component);
this.component = component;
// only stages which are actually off-centerline will get the dialog here:
if( ParallelStage.class.isAssignableFrom( component.getClass()) || PodSet.class.isAssignableFrom( component.getClass())){
@ -45,9 +54,9 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
// radial distance method
JLabel radiusMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Radius.Label"));
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 );
motherPanel.add( radiusMethodCombo, "align left, wrap");
motherPanel.add( radiusMethodCombo, "spanx 3, growx, wrap");
// set radial distance
JLabel radiusLabel = new JLabel(trans.get("StageConfig.parallel.radius"));
@ -55,31 +64,34 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
//radiusMethodModel.addEnableComponent(radiusLabel, false);
DoubleModel radiusModel = new DoubleModel( boosters, "RadiusOffset", UnitGroup.UNITS_LENGTH, 0);
JSpinner radiusSpinner = new JSpinner( radiusModel.getSpinnerModel());
radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner ));
motherPanel.add(radiusSpinner , "growx 1, align right");
JSpinner radiusSpinner = new JSpinner(radiusModel.getSpinnerModel());
radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner));
motherPanel.add(radiusSpinner , "wmin 65lp, growx 1, align right");
// autoRadOffsModel.addEnableComponent(radiusSpinner, false);
UnitSelector radiusUnitSelector = new UnitSelector(radiusModel);
motherPanel.add(radiusUnitSelector, "growx 1, wrap");
// autoRadOffsModel.addEnableComponent(radiusUnitSelector, false);
// // set location angle around the primary stage
// JLabel angleMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Angle.Label"));
// motherPanel.add( angleMethodLabel, "align left");
// EnumModel<AngleMethod> angleMethodModel = new EnumModel<AngleMethod>( boosters, "AngleMethod", AngleMethod.choices() );
// final JComboBox<AngleMethod> angleMethodCombo = new JComboBox<AngleMethod>( angleMethodModel );
// motherPanel.add( angleMethodCombo, "align left, wrap");
motherPanel.add(radiusUnitSelector, "growx 1");
motherPanel.add(new BasicSlider(radiusModel.getSliderModel(0, new DoubleModel(component.getParent(), "OuterRadius", 4.0, UnitGroup.UNITS_LENGTH))),
"gapleft para, growx 2, wrap");
radiusMethodCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
radiusModel.stateChanged(new EventObject(e));
}
});
// set angle
JLabel angleLabel = new JLabel(trans.get("StageConfig.parallel.angle"));
motherPanel.add( angleLabel, "align left");
DoubleModel angleModel = new DoubleModel( boosters, "AngleOffset", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2);
JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel());
angleSpinner.setEditor(new SpinnerEditor(angleSpinner));
motherPanel.add(angleSpinner, "growx 1");
motherPanel.add(angleSpinner, "wmin 65lp, growx 1");
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
JLabel countLabel = new JLabel(trans.get("StageConfig.parallel.count"));
motherPanel.add( countLabel, "align left");
@ -87,7 +99,7 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
IntegerModel countModel = new IntegerModel( boosters, "InstanceCount", 1);
JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel());
countSpinner.setEditor(new SpinnerEditor(countSpinner));
motherPanel.add(countSpinner, "growx 1, wrap");
motherPanel.add(countSpinner, "wmin 65lp, growx 1, wrap");
// setPositions relative to parent component
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 );
JComboBox<?> positionMethodCombo = new JComboBox<AxialMethod>( axialPositionMethodModel );
motherPanel.add(positionMethodCombo, "spanx 2, growx, wrap");
motherPanel.add(positionMethodCombo, "spanx 3, growx, wrap");
// relative offset labels
JLabel positionPlusLabel = new JLabel(trans.get("StageConfig.parallel.offset"));
motherPanel.add( positionPlusLabel );
DoubleModel axialOffsetModel = new DoubleModel( boosters, "AxialOffset", UnitGroup.UNITS_LENGTH);
// plus
motherPanel.add(new JLabel(trans.get("StageConfig.parallel.plus")), "right");
JSpinner axPosSpin= new JSpinner( axialOffsetModel.getSpinnerModel());
axPosSpin.setEditor(new SpinnerEditor(axPosSpin));
motherPanel.add(axPosSpin, "growx");
UnitSelector axialOffsetUnitSelector = new UnitSelector(axialOffsetModel);
motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap");
// For DEBUG purposes
//System.err.println(assembly.getRocket().toDebugTree());
final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
final JSpinner axialOffsetSpinner = new JSpinner(axialOffsetModel.getSpinnerModel());
axialOffsetSpinner.setEditor(new SpinnerEditor(axialOffsetSpinner));
motherPanel.add(axialOffsetSpinner, "wmin 65lp, growx 1");
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;
}