Merge pull request #1612 from SiboVG/issue-1603

[#1603] Fix fin set tab height validation + dynamic max slider value
This commit is contained in:
SiboVG 2022-08-25 16:37:06 +02:00 committed by GitHub
commit 22281b3f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View File

@ -309,7 +309,8 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
}
tabHeight = newTabHeight;
validateFinTabHeight();
double maxTabHeight = getMaxTabHeight();
this.tabHeight = Math.min(this.tabHeight, maxTabHeight);
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -425,19 +426,23 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
//System.err.println(String.format(" << Fin Tab Length: %.6f @ %.6f", tabLength, tabOffset));
}
public void validateFinTabHeight(){
/**
* Calculates the maximum height that the fin tabs can be, depending on the parent shape.
* @return maximum tab height value
*/
public double getMaxTabHeight() {
// check tab height
if( null != getParent() ){
if (null != getParent() ){
final Coordinate finFront = this.getFinFront();
// pulls the parent-body radius at the fin-tab reference point.
final double xLead = this.getTabFrontEdge();
final double xTrail = this.getTabTrailingEdge();
final SymmetricComponent sym = (SymmetricComponent)this.parent;
final double bodyRadius = MathUtil.min(sym.getRadius( xLead), sym.getRadius( xTrail));
// limit the new heights to be no greater than the current body radius.
this.tabHeight = Math.min( this.tabHeight, bodyRadius );
return MathUtil.min(sym.getRadius(finFront.x + xLead), sym.getRadius(finFront.x + xTrail));
}
return Double.MAX_VALUE;
}
/////////// Calculation methods //////////

View File

@ -34,7 +34,6 @@ import net.sf.openrocket.rocketcomponent.CenteringRing;
import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.FreeformFinSet;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
@ -156,16 +155,19 @@ public abstract class FinSetConfig extends RocketComponentConfig {
JLabel label;
DoubleModel length;
DoubleModel length2;
DoubleModel maxTabHeight;
DoubleModel length_2;
JSpinner spin;
JButton autoCalc;
length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
maxTabHeight = new DoubleModel(component, "MaxTabHeight", 1, UnitGroup.UNITS_LENGTH, 0);
length2 = new DoubleModel(component, "Length", 0.5, UnitGroup.UNITS_LENGTH, 0);
length_2 = new DoubleModel(component, "Length", -0.5, UnitGroup.UNITS_LENGTH, 0);
register(length);
register(length2);
register(maxTabHeight);
register(length_2);
//// Tab length
@ -192,14 +194,14 @@ public abstract class FinSetConfig extends RocketComponentConfig {
label.setToolTipText(trans.get("FinSetConfig.ttip.Tabheight"));
panel.add(label, "gapleft para");
final DoubleModel tabHeightModel = new DoubleModel(component, "TabHeight", UnitGroup.UNITS_LENGTH, 0);
final DoubleModel tabHeightModel = new DoubleModel(component, "TabHeight", UnitGroup.UNITS_LENGTH, 0, ((FinSet)component).getMaxTabHeight());
component.addChangeListener( tabHeightModel );
spin = new JSpinner(tabHeightModel.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx");
panel.add(new UnitSelector(tabHeightModel), "growx");
panel.add(new BasicSlider(tabHeightModel.getSliderModel(DoubleModel.ZERO, length2)),
panel.add(new BasicSlider(tabHeightModel.getSliderModel(DoubleModel.ZERO, maxTabHeight)),
"w 100lp, growx 5, wrap");
//// Tab position: