From 90cceecd6506c1384eb27a0453957173d51c26ef Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 4 Nov 2022 00:38:32 +0100 Subject: [PATCH] [#106] Fix SubAssembly importing in RockSim --- .../file/rocksim/importt/RockSimHandler.java | 3 +++ .../rocksim/importt/SubAssemblyHandler.java | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/RockSimHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/RockSimHandler.java index 52f0c8fe7..1aef79cd3 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/RockSimHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/RockSimHandler.java @@ -350,6 +350,9 @@ class StageHandler extends AbstractElementHandler { if (RockSimCommonConstants.TRANSITION.equals(element)) { return new TransitionHandler(context, component, warnings); } + if (RockSimCommonConstants.SUBASSEMBLY.equals(element)) { + return new SubAssemblyHandler(context, component); + } return null; } } diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/SubAssemblyHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/SubAssemblyHandler.java index 476696a03..a80f3034d 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/SubAssemblyHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/SubAssemblyHandler.java @@ -10,18 +10,21 @@ import net.sf.openrocket.rocketcomponent.RocketComponent; import java.util.HashMap; /** - * This class handles Rocksim 'SubAssembly' elements. They are similar to 'AttachedParts' (which is why this class is subclassed from - * AttachedPartsHandler) with some key differences. In Rocksim, AttachedParts elements can contain SubAssembly elements, which can in turn + * This class handles RockSim 'SubAssembly' elements. They are similar to 'AttachedParts' (which is why this class is subclassed from + * AttachedPartsHandler) with some key differences. In RockSim, AttachedParts elements can contain SubAssembly elements, which can in turn * contain AttachedParts elements. To represent them in OR, SubAssembly elements are treated as children of the stage - much like a nose cone or * external body tube. */ public class SubAssemblyHandler extends AttachedPartsHandler { + /** + * Constructor + * @param c the parent component + * @throws IllegalArgumentException + */ public SubAssemblyHandler(final DocumentLoadingContext context, final RocketComponent c) throws IllegalArgumentException { - //A bit of a risk here, but assign the subassembly to the stage, not to the component. This is because typically the - //first component within the subassembly will be an external component. - super(context, c.getStage()); + super(context, c); } @Override @@ -33,9 +36,14 @@ public class SubAssemblyHandler extends AttachedPartsHandler { if (RockSimCommonConstants.ATTACHED_PARTS.equals(element)) { return this; } - // The key override of this class - treat body tubes as external body tubes. + // The key override of this class - treat body tubes, transitions, and nose cones as external components. + // note: this will only work if the parent component is a stage. else if (RockSimCommonConstants.BODY_TUBE.equals(element)) { return new BodyTubeHandler(getContext(), getComponent(), warnings); + } else if (RockSimCommonConstants.TRANSITION.equals(element)) { + return new TransitionHandler(getContext(), getComponent(), warnings); + } else if (RockSimCommonConstants.NOSE_CONE.equals(element)) { + return new NoseConeHandler(getContext(), getComponent(), warnings); } return super.openElement(element, attributes, warnings); }