Merge pull request #731 from teyrana/fix/726-positioning

[Fixes #726] Fixes multiple issues when changing Fin-Offset-Methods
This commit is contained in:
Daniel Williams 2020-08-08 11:25:26 -04:00 committed by GitHub
commit b17d03138a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 218 additions and 118 deletions

View File

@ -934,11 +934,14 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
// no change.
return;
}
// this variable does not change the internal representation
// this variable changes the internal representation, but not the physical position
// the relativePosition (method) is just the lens through which external code may view this component's position.
this.axialMethod = newAxialMethod;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
this.axialOffset = getAxialOffset(newAxialMethod);
// // this doesn't cause any physical change-- just how it's described.
// fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
/**

View File

@ -55,8 +55,8 @@ public class FreeformFinSetTest extends BaseTestCase {
sourceSet.setOverrideCGX(0.012);
sourceSet.setOverrideMass(0.0123);
sourceSet.setOverrideSubcomponents(true);
sourceSet.setAxialOffset(0.1);
sourceSet.setAxialMethod(AxialMethod.ABSOLUTE);
sourceSet.setAxialOffset(0.1);
sourceSet.setTabHeight(0.01);
sourceSet.setTabLength(0.02);
sourceSet.setTabOffsetMethod(AxialMethod.BOTTOM);

View File

@ -2,15 +2,18 @@ package net.sf.openrocket.rocketcomponent;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.closeTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.ArrayList;
import org.junit.Test;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.AngleMethod;
import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.TestRockets;
@ -147,6 +150,63 @@ public class RocketTest extends BaseTestCase {
assertEquals( 0.062000000, bounds.max.y, EPSILON);
assertEquals( 0.052893575, bounds.max.z, EPSILON);
}
@Test
public void testChangeAxialMethod(){
class AxialPositionTestCase {
final public AxialMethod beginMethod;
final public double beginOffset;
final public AxialMethod endMethod;
final public double endOffset;
final public double endPosition;
public AxialPositionTestCase( AxialMethod _begMeth, double _begOffs, AxialMethod _endMeth, double _endOffs, double _endPos){
beginMethod = _begMeth; beginOffset = _begOffs; endMethod = _endMeth; endOffset = _endOffs; endPosition = _endPos;
}
}
final Rocket rocket = TestRockets.makeEstesAlphaIII();
final AxialStage stage= (AxialStage)rocket.getChild(0);
final BodyTube body = (BodyTube)stage.getChild(1);
final FinSet fins = (FinSet) body.getChild(0);
{ // verify construction:
assertEquals("incorrect body length:", 0.20, body.getLength(), EPSILON);
assertEquals("incorrect fin length:", 0.05, fins.getLength(), EPSILON);
{ // fin #1
final Coordinate expLoc = new Coordinate(0.22, 0.012, 0);
final Coordinate actLocs[] = fins.getComponentLocations();
assertThat(fins.getName() + " not positioned correctly: ", actLocs[0], equalTo(expLoc));
}
}
final ArrayList<AxialPositionTestCase> allTestCases = new ArrayList<>(10);
allTestCases.add(0, new AxialPositionTestCase(AxialMethod.BOTTOM, 0.0, AxialMethod.TOP, 0.15, 0.15));
allTestCases.add(1, new AxialPositionTestCase(AxialMethod.TOP, 0.0, AxialMethod.BOTTOM, -0.15, 0.0));
allTestCases.add(2, new AxialPositionTestCase(AxialMethod.BOTTOM, -0.03, AxialMethod.TOP, 0.12, 0.12));
allTestCases.add(3, new AxialPositionTestCase(AxialMethod.BOTTOM, 0.03, AxialMethod.TOP, 0.18, 0.18));
allTestCases.add(4, new AxialPositionTestCase(AxialMethod.BOTTOM, 0.03, AxialMethod.MIDDLE, 0.105, 0.18));
allTestCases.add(5, new AxialPositionTestCase(AxialMethod.MIDDLE, 0.0, AxialMethod.TOP, 0.075, 0.075));
allTestCases.add(6, new AxialPositionTestCase(AxialMethod.MIDDLE, 0.0, AxialMethod.BOTTOM, -0.075, 0.075));
allTestCases.add(7, new AxialPositionTestCase(AxialMethod.MIDDLE, 0.005, AxialMethod.TOP, 0.08, 0.08));
for( int caseIndex=0; caseIndex < allTestCases.size(); ++caseIndex ){
final AxialPositionTestCase cur = allTestCases.get(caseIndex);
// test repositioning
fins.setAxialOffset(cur.beginMethod, cur.beginOffset);
assertEquals(fins.getName() + " incorrect start axial-position-method: ", fins.getAxialMethod(), cur.beginMethod);
assertEquals(fins.getName() + " incorrect start axial-position-value: ", cur.beginOffset, fins.getAxialOffset(), EPSILON);
{
// System.err.println(String.format("## Running Test case # %d :", caseIndex));
fins.setAxialMethod(cur.endMethod);
assertEquals(String.format(" Test Case # %d // offset doesn't match!", caseIndex), cur.endOffset, fins.getAxialOffset(), EPSILON);
assertEquals(String.format(" Test Case # %d // position doesn't match!", caseIndex), cur.endPosition, fins.getPosition().x, EPSILON);
}
}
}
@Test
public void testRemoveReadjustLocation() {

View File

@ -1,6 +1,9 @@
package net.sf.openrocket.gui.configdialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
@ -110,25 +113,32 @@ public class EllipticalFinSetConfig extends FinSetConfig {
//// Position
//// Position relative to:
panel.add(new JLabel(trans.get("EllipticalFinSetCfg.Positionrelativeto")));
JComboBox<AxialMethod> positionCombo= new JComboBox<AxialMethod>( new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods ));
panel.add(positionCombo, "spanx, growx, wrap");
final EnumModel<AxialMethod> axialMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );
final JComboBox<AxialMethod> axialMethodCombo = new JComboBox<AxialMethod>( axialMethodModel );
panel.add(axialMethodCombo, "spanx, growx, wrap");
//// plus
panel.add(new JLabel(trans.get("EllipticalFinSetCfg.plus")), "right");
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
spin = new JSpinner(m.getSpinnerModel());
final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
spin = new JSpinner(axialOffsetModel.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(
axialMethodCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
axialOffsetModel.stateChanged(new EventObject(e));
}
});
panel.add(new UnitSelector(axialOffsetModel), "growx");
panel.add(new BasicSlider(axialOffsetModel.getSliderModel(
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
new DoubleModel(component.getParent(), "Length"))),
"w 100lp, wrap");
//// Right portion
mainPanel.add(panel, "aligny 20%");

View File

@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;
import javax.swing.JButton;
@ -93,106 +94,111 @@ public class FreeformFinSetConfig extends FinSetConfig {
private JPanel generalPane() {
DoubleModel m;
JSpinner spin;
JPanel mainPanel = new JPanel(new MigLayout("fill"));
JPanel panel = new JPanel(new MigLayout("fill, gap rel unrel", "[][65lp::][30lp::]", ""));
//// Number of fins:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Numberoffins")));
IntegerModel im = new IntegerModel(component, "FinCount", 1, 8);
spin = new JSpinner(im.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx, wrap");
//// Base rotation
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Finrotation")));
m = new DoubleModel(component, "BaseRotation", UnitGroup.UNITS_ANGLE);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(-Math.PI, Math.PI)), "w 100lp, wrap");
//// Fin cant
JLabel label = new JLabel(trans.get("FreeformFinSetCfg.lbl.Fincant"));
//// The angle that the fins are canted with respect to the rocket body.
label.setToolTipText(trans.get("FreeformFinSetCfg.lbl.ttip.Fincant"));
panel.add(label);
m = new DoubleModel(component, "CantAngle", UnitGroup.UNITS_ANGLE, -FinSet.MAX_CANT_RADIANS, FinSet.MAX_CANT_RADIANS);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(-FinSet.MAX_CANT_RADIANS, FinSet.MAX_CANT_RADIANS)), "w 100lp, wrap 40lp");
//// Position
//// Position relative to:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Posrelativeto")));
JComboBox<AxialMethod> positionCombo = new JComboBox<>( new EnumModel<>(component, "AxialMethod", AxialMethod.axialOffsetMethods ));
panel.add(positionCombo, "spanx 3, growx, wrap");
//// plus
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.plus")), "right");
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE), new DoubleModel(component.getParent(), "Length"))), "w 100lp, wrap");
{ //// Number of fins:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Numberoffins")));
final IntegerModel finCountModel = new IntegerModel(component, "FinCount", 1, 8);
JSpinner spin = new JSpinner(finCountModel.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx, wrap");
}
{ //// Base rotation
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Finrotation")));
DoubleModel m = new DoubleModel(component, "BaseRotation", UnitGroup.UNITS_ANGLE);
JSpinner spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(-Math.PI, Math.PI)), "w 100lp, wrap");
}
{ //// Fin cant
JLabel label = new JLabel(trans.get("FreeformFinSetCfg.lbl.Fincant"));
//// The angle that the fins are canted with respect to the rocket body.
label.setToolTipText(trans.get("FreeformFinSetCfg.lbl.ttip.Fincant"));
panel.add(label);
final DoubleModel cantAngleModel = new DoubleModel(component, "CantAngle", UnitGroup.UNITS_ANGLE, -FinSet.MAX_CANT_RADIANS, FinSet.MAX_CANT_RADIANS);
final JSpinner cantAngleSpinner = new JSpinner(cantAngleModel.getSpinnerModel());
cantAngleSpinner.setEditor(new SpinnerEditor(cantAngleSpinner));
panel.add(cantAngleSpinner, "growx");
panel.add(new UnitSelector(cantAngleModel), "growx");
panel.add(new BasicSlider(cantAngleModel.getSliderModel(-FinSet.MAX_CANT_RADIANS, FinSet.MAX_CANT_RADIANS)), "w 100lp, wrap 40lp");
}
{ //// Position
//// Position relative to:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Posrelativeto")));
final EnumModel<AxialMethod> axialMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods);
final JComboBox<AxialMethod> axialMethodCombo = new JComboBox<AxialMethod>(axialMethodModel);
panel.add(axialMethodCombo, "spanx 3, growx, wrap");
//// plus
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.plus")), "right");
final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
final JSpinner axialOffsetSpinner = new JSpinner(axialOffsetModel.getSpinnerModel());
axialOffsetSpinner.setEditor(new SpinnerEditor(axialOffsetSpinner));
panel.add(axialOffsetSpinner, "growx");
panel.add(new UnitSelector(axialOffsetModel), "growx");
panel.add(new BasicSlider(axialOffsetModel.getSliderModel(new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE), new DoubleModel(component.getParent(), "Length"))), "w 100lp, wrap");
axialMethodCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
axialOffsetModel.stateChanged(new EventObject(e));
}
});
}
mainPanel.add(panel, "aligny 20%");
mainPanel.add(new JSeparator(SwingConstants.VERTICAL), "growy, height 150lp");
panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
//// Cross section
//// Fin cross section:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.FincrossSection")), "span, split");
JComboBox<FinSet.CrossSection> sectionCombo = new JComboBox<>(new EnumModel<FinSet.CrossSection>(component, "CrossSection"));
panel.add(sectionCombo, "growx, wrap unrel");
//// Thickness:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Thickness")));
m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap 30lp");
//// Material
panel.add(materialPanel(Material.Type.BULK), "span, wrap");
panel.add(filletMaterialPanel(), "span, wrap");
{ //// Cross section
//// Fin cross section:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.FincrossSection")), "span, split");
JComboBox<FinSet.CrossSection> sectionCombo = new JComboBox<>(new EnumModel<FinSet.CrossSection>(component, "CrossSection"));
panel.add(sectionCombo, "growx, wrap unrel");
//// Thickness:
panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Thickness")));
final DoubleModel m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
final JSpinner spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap 30lp");
}
{ //// Material
panel.add(materialPanel(Material.Type.BULK), "span, wrap");
panel.add(filletMaterialPanel(), "span, wrap");
}
mainPanel.add(panel, "aligny 20%");

View File

@ -1,6 +1,9 @@
package net.sf.openrocket.gui.configdialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
@ -161,18 +164,26 @@ public class TrapezoidFinSetConfig extends FinSetConfig {
{//// Position relative to:
panel.add(new JLabel(trans.get("TrapezoidFinSetCfg.lbl.Posrelativeto")));
final EnumModel<AxialMethod> methodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods);
final JComboBox<AxialMethod> positionCombo = new JComboBox<AxialMethod>(methodModel);
final EnumModel<AxialMethod> axialMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );
final JComboBox<AxialMethod> axialMethodCombo = new JComboBox<AxialMethod>( axialMethodModel );
panel.add(axialMethodCombo, "spanx, growx, wrap");
panel.add(positionCombo, "spanx, growx, wrap");
//// plus
panel.add(new JLabel(trans.get("TrapezoidFinSetCfg.lbl.plus")), "right");
final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
final JSpinner axialOffsetSpinner = new JSpinner(axialOffsetModel.getSpinnerModel());
axialOffsetSpinner.setEditor(new SpinnerEditor(axialOffsetSpinner));
panel.add(axialOffsetSpinner, "growx");
axialMethodCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
axialOffsetModel.stateChanged(new EventObject(e));
}
});
panel.add(new UnitSelector(axialOffsetModel), "growx");
panel.add(new BasicSlider(axialOffsetModel.getSliderModel(
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),

View File

@ -1,6 +1,9 @@
package net.sf.openrocket.gui.configdialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
@ -123,20 +126,27 @@ public class TubeFinSetConfig extends RocketComponentConfig {
panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::][]", ""));
//// Position relative to:
panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")));
final EnumModel<AxialMethod> methodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );
final JComboBox<AxialMethod> methodCombo = new JComboBox<AxialMethod>( methodModel );
panel.add(methodCombo, "spanx, growx, wrap");
panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto"))); // (note re-uses the label from LaunchLug, because they're the same
final EnumModel<AxialMethod> axialMethodModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );
final JComboBox<AxialMethod> axialMethodCombo = new JComboBox<AxialMethod>( axialMethodModel );
panel.add(axialMethodCombo, "spanx, growx, wrap");
//// plus
panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.plus")), "right");
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
spin = new JSpinner(m.getSpinnerModel());
final DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
spin = new JSpinner(axialOffsetModel.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
axialMethodCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
axialOffsetModel.stateChanged(new EventObject(e));
}
});
panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),