Modified setTabHeight, setTabLength, and setTabOffset to take a second

parameter, determining whether to validate fin tab, and made them
private.

Created two public wrappers for each, one calling for validation
(which has the same signature as the original three methods), and the
other not.

Called NoValidate versions of the three in file loading functions so
validation doesn't interfere with tab length when tab is read before
fin.

Tried to make the coding of the three more consistent with each
other.
This commit is contained in:
JoePfeiffer 2019-03-13 14:45:30 -06:00
parent 6efc7e42a1
commit 18ce41d9e7
5 changed files with 1727 additions and 26 deletions

View File

@ -253,9 +253,9 @@ class DocumentConfig {
setters.put("FinSet:cant", new DoubleSetter( setters.put("FinSet:cant", new DoubleSetter(
Reflection.findMethod(FinSet.class, "setCantAngle", double.class), Math.PI / 180.0)); Reflection.findMethod(FinSet.class, "setCantAngle", double.class), Math.PI / 180.0));
setters.put("FinSet:tabheight", new DoubleSetter( setters.put("FinSet:tabheight", new DoubleSetter(
Reflection.findMethod(FinSet.class, "setTabHeight", double.class))); Reflection.findMethod(FinSet.class, "setTabHeightNoValidate", double.class)));
setters.put("FinSet:tablength", new DoubleSetter( setters.put("FinSet:tablength", new DoubleSetter(
Reflection.findMethod(FinSet.class, "setTabLength", double.class))); Reflection.findMethod(FinSet.class, "setTabLengthNoValidate", double.class)));
setters.put("FinSet:tabposition", new FinTabPositionSetter()); setters.put("FinSet:tabposition", new FinTabPositionSetter());
setters.put("FinSet:filletradius", new DoubleSetter( setters.put("FinSet:filletradius", new DoubleSetter(
Reflection.findMethod(FinSet.class, "setFilletRadius", double.class))); Reflection.findMethod(FinSet.class, "setFilletRadius", double.class)));

View File

@ -11,7 +11,7 @@ import net.sf.openrocket.util.Reflection;
class FinTabPositionSetter extends DoubleSetter { class FinTabPositionSetter extends DoubleSetter {
public FinTabPositionSetter() { public FinTabPositionSetter() {
super(Reflection.findMethod(FinSet.class, "setTabOffset", double.class)); super(Reflection.findMethod(FinSet.class, "setTabOffsetNoValidate", double.class));
} }
@Override @Override
@ -50,4 +50,4 @@ class FinTabPositionSetter extends DoubleSetter {
} }
} }

View File

@ -315,9 +315,9 @@ class FinSetHandler extends AbstractElementHandler {
result.setFinish(finish); result.setFinish(finish);
//All TTW tabs in Rocksim are relative to the front of the fin. //All TTW tabs in Rocksim are relative to the front of the fin.
result.setTabOffsetMethod( AxialMethod.TOP); result.setTabOffsetMethod( AxialMethod.TOP);
result.setTabHeight(tabDepth); result.setTabHeightNoValidate(tabDepth);
result.setTabLength(tabLength); result.setTabLengthNoValidate(tabLength);
result.setTabOffset(taboffset); result.setTabOffsetNoValidate(taboffset);
result.setBaseRotation(radialAngle); result.setBaseRotation(radialAngle);
result.setCrossSection(convertTipShapeCode(tipShapeCode)); result.setCrossSection(convertTipShapeCode(tipShapeCode));
result.setAxialMethod(axialMethod); result.setAxialMethod(axialMethod);

View File

@ -247,6 +247,24 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
public double getTabHeight() { public double getTabHeight() {
return tabHeight; return tabHeight;
} }
/**
* wrapper to call setTabHeight without validating tab.
* This is intended to be used when reading a rocket from a file,
* since if the fin tab is read before the fin, validation will
* reduce the tab length to the default fin length
*/
public void setTabHeightNoValidate(final double heightRequest) {
setTabHeight(heightRequest, false);
}
/**
* wrapper to call setTabHeight and validate tab.
* This is intended to be used from the GUI
*/
public void setTabHeight(final double heightRequest) {
setTabHeight(heightRequest, true);
}
/** /**
* Set the height from the fin's base at the reference point -- i.e. where the tab is located from. If the tab is located via BOTTOM, then the back edge will be * Set the height from the fin's base at the reference point -- i.e. where the tab is located from. If the tab is located via BOTTOM, then the back edge will be
@ -258,14 +276,16 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
* @param newHeightRequest how deep the fin tab should project from the fin root, at the reference point * @param newHeightRequest how deep the fin tab should project from the fin root, at the reference point
* *
*/ */
public void setTabHeight(final double newHeightRequest) { private void setTabHeight(final double heightRequest, final boolean validate) {
if (MathUtil.equals(this.tabHeight, MathUtil.max(newHeightRequest, 0))){ if (MathUtil.equals(this.tabHeight, MathUtil.max(heightRequest, 0))){
return; return;
} }
this.tabHeight = newHeightRequest; tabHeight = heightRequest;
validateFinTab(); if (validate)
validateFinTab();
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }
@ -273,26 +293,74 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
public double getTabLength() { public double getTabLength() {
return tabLength; return tabLength;
} }
public void setTabLength(double length) { /**
length = MathUtil.max(length, 0); * Wrapper to call setTabLength with no validation
if (MathUtil.equals(this.tabLength, length)) * This is only intended to be used when reading a
* rocket from a file. If the fin tab is read before
* the fin, validation will reduce the length of the tab
* to the default length of the fin
*/
public void setTabLengthNoValidate(final double lengthRequest) {
setTabLength(lengthRequest, false);
}
/**
* Wrapper to call full setTabLength function, and validate
* tab length
*/
public void setTabLength(final double lengthRequest) {
setTabLength(lengthRequest, true);
}
/**
* set tab length and optionally validate parameters
*/
private void setTabLength(final double lengthRequest, final boolean validate) {
if (MathUtil.equals(tabLength, MathUtil.max(lengthRequest, 0))) {
return; return;
tabLength = length; }
validateFinTab();
tabLength = lengthRequest;
if (validate) {
validateFinTab();
}
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }
/** /**
* internally, set the internal * wrapper to call setTabOffset without validating tab.
* * This is intended to be used when reading a rocket from a file,
* @param newOffset new requested shift of tab -- from * since if the fin tab is read before the fin, validation will
* reduce the tab length to the default fin length
*/ */
public void setTabOffset( final double newOffset) { public void setTabOffsetNoValidate(final double offsetRequest) {
this.tabOffset = newOffset; setTabOffset(offsetRequest, false);
this.tabPosition = this.tabOffsetMethod.getAsPosition( newOffset, this.tabLength, this.length); }
validateFinTab(); /**
* wrapper to call setTabOffset and validate tab.
* This is intended to be used in the gui
*/
public void setTabOffset(final double offsetRequest) {
setTabOffset(offsetRequest, true);
}
/**
* internally, set the internal offset and optionally validate tab
*
* @param offsetRequest new requested shift of tab -- from
* @param validate wehther or not to validate
*/
private void setTabOffset( final double offsetRequest, final boolean validate) {
tabOffset = offsetRequest;
tabPosition = tabOffsetMethod.getAsPosition( tabOffset, tabLength, length);
if (validate) {
validateFinTab();
}
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }

File diff suppressed because it is too large Load Diff