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(
Reflection.findMethod(FinSet.class, "setCantAngle", double.class), Math.PI / 180.0));
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(
Reflection.findMethod(FinSet.class, "setTabLength", double.class)));
Reflection.findMethod(FinSet.class, "setTabLengthNoValidate", double.class)));
setters.put("FinSet:tabposition", new FinTabPositionSetter());
setters.put("FinSet:filletradius", new DoubleSetter(
Reflection.findMethod(FinSet.class, "setFilletRadius", double.class)));

View File

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

View File

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

View File

@ -248,6 +248,24 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
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
* <code>height</code> deep, and the bottom edge of the tab will be parallel to the stage centerline. If the tab is located via TOP, the the front edge will have corresponding height/depth.
@ -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
*
*/
public void setTabHeight(final double newHeightRequest) {
if (MathUtil.equals(this.tabHeight, MathUtil.max(newHeightRequest, 0))){
private void setTabHeight(final double heightRequest, final boolean validate) {
if (MathUtil.equals(this.tabHeight, MathUtil.max(heightRequest, 0))){
return;
}
this.tabHeight = newHeightRequest;
tabHeight = heightRequest;
if (validate)
validateFinTab();
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -274,25 +294,73 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
return tabLength;
}
public void setTabLength(double length) {
length = MathUtil.max(length, 0);
if (MathUtil.equals(this.tabLength, length))
/**
* Wrapper to call setTabLength with no validation
* 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;
tabLength = length;
}
tabLength = lengthRequest;
if (validate) {
validateFinTab();
}
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
/**
* internally, set the internal
*
* @param newOffset new requested shift of tab -- from
* wrapper to call setTabOffset 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 setTabOffset( final double newOffset) {
this.tabOffset = newOffset;
this.tabPosition = this.tabOffsetMethod.getAsPosition( newOffset, this.tabLength, this.length);
public void setTabOffsetNoValidate(final double offsetRequest) {
setTabOffset(offsetRequest, false);
}
/**
* 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);
}

File diff suppressed because it is too large Load Diff