Fix issue in boattail axial offset importing

This commit is contained in:
SiboVG 2023-02-23 21:56:08 +01:00
parent dfac4c6e56
commit c009b23e47
2 changed files with 17 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package net.sf.openrocket.file.rasaero.importt;
import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.file.DocumentLoadingContext; import net.sf.openrocket.file.DocumentLoadingContext;
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
import net.sf.openrocket.file.simplesax.ElementHandler; import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.PodSet;
@ -15,15 +14,15 @@ import org.xml.sax.SAXException;
import java.util.HashMap; import java.util.HashMap;
/** /**
* A handler for the boat tail element RASAero. * A handler for the boattail element RASAero.
* A boat tail is just an OpenRocket transition, but because it can be recessed in next symmetric components * A boattail is just an OpenRocket transition, but because it can be recessed in next symmetric components
* (e.g. a body tube), we will add the boat tail using an inline pod set to the previous component. * (e.g. a body tube), we will add the boattail using an inline pod set to the previous component.
* In case the previous component is a nose cone, we will first add a phantom body tube and then add the pod to * In case the previous component is a nose cone, we will first add a phantom body tube and then add the pod to
* that body tube. I know, not the most elegant solution, but it grants us the best cross-compatibility with RASAero. * that body tube. I know, not the most elegant solution, but it grants us the best cross-compatibility with RASAero.
* *
* @author Sibo Van Gool <sibo.vangool@hotmail.com> * @author Sibo Van Gool <sibo.vangool@hotmail.com>
*/ */
public class BoatTailHandler extends TransitionHandler { public class BoattailHandler extends TransitionHandler {
/** /**
* Constructor * Constructor
@ -33,47 +32,47 @@ public class BoatTailHandler extends TransitionHandler {
* @param warnings warning set to add import warnings to * @param warnings warning set to add import warnings to
* @throws IllegalArgumentException if the parent component is null * @throws IllegalArgumentException if the parent component is null
*/ */
public BoatTailHandler(DocumentLoadingContext context, RocketComponent parent, WarningSet warnings) throws IllegalArgumentException { public BoattailHandler(DocumentLoadingContext context, RocketComponent parent, WarningSet warnings) throws IllegalArgumentException {
super(context); super(context);
if (parent == null) { if (parent == null) {
throw new IllegalArgumentException("The parent component of a boat tail may not be null."); throw new IllegalArgumentException("The parent component of a boattail may not be null.");
} }
if (parent.getChildCount() == 0) { if (parent.getChildCount() == 0) {
throw new IllegalArgumentException("The parent component of a boat tail must have at least one child."); throw new IllegalArgumentException("The parent component of a boattail must have at least one child.");
} }
// Pod to add the boat tail to // Pod to add the boattail to
PodSet pod = new PodSet(); PodSet pod = new PodSet();
pod.setInstanceCount(1); pod.setInstanceCount(1);
pod.setRadius(RadiusMethod.FREE, 0); pod.setRadius(RadiusMethod.FREE, 0);
pod.setName("Boat tail pod"); pod.setName("Boattail pod");
pod.setComment("Because boat tails in RASAero can be recessed, we will add the boat tail using an inline pod set to the previous component."); pod.setComment("Because boattails in RASAero can be recessed, we will add the boattail using an inline pod set to the previous component.");
// Add the pod to the parent's last child, or to a phantom tube if the last child is a nose cone/transition // Add the pod to the parent's last child, or to a phantom tube if the last child is a nose cone/transition
RocketComponent lastChild = parent.getChild(parent.getChildCount() - 1); RocketComponent lastChild = parent.getChild(parent.getChildCount() - 1);
if (lastChild instanceof BodyTube) { if (lastChild instanceof BodyTube) {
lastChild.addChild(pod); lastChild.addChild(pod);
pod.setAxialMethod(AxialMethod.BOTTOM); pod.setAxialMethod(AxialMethod.TOP);
pod.setAxialOffset(0); pod.setAxialOffset(lastChild.getLength());
} else if (lastChild instanceof Transition) { } else if (lastChild instanceof Transition) {
BodyTube phantomBodyTube = new BodyTube(); BodyTube phantomBodyTube = new BodyTube();
phantomBodyTube.setLength(0); phantomBodyTube.setLength(0);
phantomBodyTube.setOuterRadiusAutomatic(true); phantomBodyTube.setOuterRadiusAutomatic(true);
phantomBodyTube.setName("Boat tail phantom tube"); phantomBodyTube.setName("Boattail phantom tube");
ColorHandler.applyRASAeroColor(phantomBodyTube, null); // Set the color to the default RASAero color ColorHandler.applyRASAeroColor(phantomBodyTube, null); // Set the color to the default RASAero color
parent.addChild(phantomBodyTube); parent.addChild(phantomBodyTube);
phantomBodyTube.addChild(pod); phantomBodyTube.addChild(pod);
pod.setAxialMethod(AxialMethod.TOP); pod.setAxialMethod(AxialMethod.TOP);
pod.setAxialOffset(0); pod.setAxialOffset(0);
} else { } else {
throw new IllegalArgumentException("Cannot add boat tail after component of type " + parent.getClass().getName()); throw new IllegalArgumentException("Cannot add boattail after component of type " + parent.getClass().getName());
} }
pod.addChild(this.transition); pod.addChild(this.transition);
this.transition.setAftRadiusAutomatic(false); this.transition.setAftRadiusAutomatic(false);
this.transition.setShapeType(Transition.Shape.CONICAL); // RASAero only supports conical boat tails this.transition.setShapeType(Transition.Shape.CONICAL); // RASAero only supports conical boattails
this.transition.setName("Boat tail"); this.transition.setName("Boattail");
} }
@Override @Override

View File

@ -179,7 +179,7 @@ public class RASAeroHandler extends AbstractElementHandler {
} }
// BoatTail // BoatTail
else if (RASAeroCommonConstants.BOATTAIL.equals(element)) { else if (RASAeroCommonConstants.BOATTAIL.equals(element)) {
return new BoatTailHandler(context, component, warnings); return new BoattailHandler(context, component, warnings);
} }
// Surface finish // Surface finish