Fix fin set tab length/offset scaling

This commit is contained in:
SiboVG 2024-09-26 17:12:50 +02:00
parent 31fd57131e
commit fdf130b982
3 changed files with 88 additions and 46 deletions

View File

@ -311,6 +311,10 @@ public abstract class FinSet extends ExternalComponent
*
*/
public void setTabHeight(final double newTabHeight) {
setTabHeight(newTabHeight, true);
}
public void setTabHeight(double newTabHeight, boolean validateTabHeight) {
for (RocketComponent listener : configListeners) {
if (listener instanceof FinSet) {
((FinSet) listener).setTabHeight(newTabHeight);
@ -322,8 +326,11 @@ public abstract class FinSet extends ExternalComponent
}
tabHeight = newTabHeight;
if (validateTabHeight) {
double maxTabHeight = getMaxTabHeight();
this.tabHeight = Math.min(this.tabHeight, maxTabHeight);
}
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -336,6 +343,10 @@ public abstract class FinSet extends ExternalComponent
* set tab length
*/
public void setTabLength(final double lengthRequest) {
setTabLength(lengthRequest, true);
}
public void setTabLength(final double lengthRequest, boolean updateTabPosition) {
for (RocketComponent listener : configListeners) {
if (listener instanceof FinSet) {
((FinSet) listener).setTabLength(lengthRequest);
@ -348,7 +359,9 @@ public abstract class FinSet extends ExternalComponent
tabLength = lengthRequest;
if (updateTabPosition) {
updateTabPosition();
}
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -375,6 +388,18 @@ public abstract class FinSet extends ExternalComponent
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
public double getTabOffset(AxialMethod method) {
return method.getAsOffset(tabPosition, tabLength, length);
}
public double getTabOffset() {
return getTabOffset(this.tabOffsetMethod);
}
public double getTabPosition(AxialMethod method) {
return method.getAsPosition(tabOffset, tabLength, length);
}
public AxialMethod getTabOffsetMethod() {
return tabOffsetMethod;
}
@ -403,18 +428,6 @@ public abstract class FinSet extends ExternalComponent
return tabPosition;
}
public double getTabOffset(AxialMethod method){
return method.getAsOffset(tabPosition, tabLength, length);
}
public double getTabOffset(){
return getTabOffset(this.tabOffsetMethod);
}
public double getTabPosition(AxialMethod method) {
return method.getAsPosition(tabOffset, tabLength, length);
}
/**
* Return the tab trailing edge position *from the front of the fin*.
*/
@ -435,16 +448,12 @@ public abstract class FinSet extends ExternalComponent
}
public void validateFinTabLength() {
//System.err.println(String.format(" >> Fin Tab Length: %.6f @ %.6f", tabLength, tabOffset));
final double xTabBack = getTabTrailingEdge();
if (this.length < xTabBack) {
this.tabLength -= (xTabBack - this.length);
}
tabLength = Math.max(0, tabLength);
//System.err.println(String.format(" << Fin Tab Length: %.6f @ %.6f", tabLength, tabOffset));
}
/**

View File

@ -242,13 +242,17 @@ public class FreeformFinSet extends FinSet {
/** maintained just for backwards compatibility:
*/
public void setPoints(Coordinate[] newPoints) {
setPoints(newPoints, true);
}
public void setPoints(Coordinate[] newPoints, boolean validateFinTab) {
for (RocketComponent listener : configListeners) {
if (listener instanceof FreeformFinSet) {
((FreeformFinSet) listener).setPoints(newPoints);
}
}
setPoints(new ArrayList<>(Arrays.asList(newPoints)));
setPoints(new ArrayList<>(Arrays.asList(newPoints)), validateFinTab);
}
/**
@ -257,6 +261,10 @@ public class FreeformFinSet extends FinSet {
* @param newPoints New points to set as the exposed edges of the fin
*/
public void setPoints(ArrayList<Coordinate> newPoints) {
setPoints(newPoints, true);
}
public void setPoints( ArrayList<Coordinate> newPoints, boolean validateFinTab) {
for (RocketComponent listener : configListeners) {
if (listener instanceof FreeformFinSet) {
((FreeformFinSet) listener).setPoints(newPoints);
@ -284,7 +292,7 @@ public class FreeformFinSet extends FinSet {
this.points = newPoints;
update();
update(validateFinTab);
if (intersects()) {
// on error, reset to the old points
@ -432,11 +440,15 @@ public class FreeformFinSet extends FinSet {
@Override
public void update() {
update(true);
}
public void update(boolean validateFinTab) {
final double oldLength = this.length;
this.length = points.get(points.size() -1).x - points.get(0).x;
this.setAxialOffset(this.axialMethod, this.axialOffset);
if(null != this.getParent()) {
if (this.getParent() != null) {
clampFirstPoint();
for (int i=1; i < points.size()-1; i++) {
@ -445,10 +457,11 @@ public class FreeformFinSet extends FinSet {
clampLastPoint();
if (oldLength != this.length)
if (oldLength != this.length && validateFinTab) {
validateFinTabLength();
}
}
}
private void clampFirstPoint() {
final SymmetricComponent body = (SymmetricComponent) getParent();

View File

@ -47,6 +47,7 @@ import info.openrocket.core.rocketcomponent.SymmetricComponent;
import info.openrocket.core.rocketcomponent.ThicknessRingComponent;
import info.openrocket.core.rocketcomponent.Transition;
import info.openrocket.core.rocketcomponent.TrapezoidFinSet;
import info.openrocket.core.rocketcomponent.position.AxialMethod;
import org.apache.commons.lang3.ClassUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -139,10 +140,9 @@ public class ScaleDialog extends JDialog {
addScaler(LaunchLug.class, "Length", SCALERS_NO_OFFSET);
// FinSet
addScaler(FinSet.class, "Thickness", SCALERS_NO_OFFSET);
addScaler(FinSet.class, "TabHeight", SCALERS_NO_OFFSET);
addScaler(FinSet.class, "TabLength", SCALERS_NO_OFFSET);
addScaler(FinSet.class, "TabOffset", SCALERS_NO_OFFSET);
list = new ArrayList<>(1);
list.add(new FinSetScaler());
SCALERS_NO_OFFSET.put(FinSet.class, list);
// TrapezoidFinSet
addScaler(TrapezoidFinSet.class, "Sweep", SCALERS_NO_OFFSET);
@ -807,8 +807,30 @@ public class ScaleDialog extends JDialog {
}
private static class FreeformFinSetScaler implements Scaler {
private static class FinSetScaler implements Scaler {
@Override
public void scale(RocketComponent component, double multiplier, boolean scaleMass) {
final Map<Class<? extends RocketComponent>, List<Scaler>> scalers = new HashMap<>();
FinSet finset = (FinSet) component;
AxialMethod originalTabOffsetMethod = finset.getTabOffsetMethod();
finset.setTabOffsetMethod(AxialMethod.ABSOLUTE);
double tabOffset = finset.getTabOffset();
tabOffset = tabOffset * multiplier;
addScaler(FinSet.class, "Thickness", scalers);
addScaler(FinSet.class, "TabHeight", scalers);
addScaler(FinSet.class, "TabLength", scalers);
performIterativeScaling(scalers, component, multiplier, scaleMass);
finset.setTabOffset(tabOffset);
finset.setTabOffsetMethod(originalTabOffsetMethod);
}
}
private static class FreeformFinSetScaler implements Scaler {
@Override
public void scale(RocketComponent component, double multiplier, boolean scaleMass) {
FreeformFinSet finset = (FreeformFinSet) component;
@ -817,10 +839,8 @@ public class ScaleDialog extends JDialog {
points[i] = points[i].multiply(multiplier);
}
finset.setPoints(points);
finset.setPoints(points, false);
}
}
private static class RadiusRingComponentScaler implements Scaler {