[#106] Fix SubAssembly importing in RockSim

This commit is contained in:
SiboVG 2022-11-04 00:38:32 +01:00
parent 3d3ad2486b
commit 90cceecd65
2 changed files with 17 additions and 6 deletions

View File

@ -350,6 +350,9 @@ class StageHandler extends AbstractElementHandler {
if (RockSimCommonConstants.TRANSITION.equals(element)) { if (RockSimCommonConstants.TRANSITION.equals(element)) {
return new TransitionHandler(context, component, warnings); return new TransitionHandler(context, component, warnings);
} }
if (RockSimCommonConstants.SUBASSEMBLY.equals(element)) {
return new SubAssemblyHandler(context, component);
}
return null; return null;
} }
} }

View File

@ -10,18 +10,21 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
import java.util.HashMap; import java.util.HashMap;
/** /**
* This class handles Rocksim 'SubAssembly' elements. They are similar to 'AttachedParts' (which is why this class is subclassed from * 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 * 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 * 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. * external body tube.
*/ */
public class SubAssemblyHandler extends AttachedPartsHandler { public class SubAssemblyHandler extends AttachedPartsHandler {
/**
* Constructor
* @param c the parent component
* @throws IllegalArgumentException
*/
public SubAssemblyHandler(final DocumentLoadingContext context, final RocketComponent c) public SubAssemblyHandler(final DocumentLoadingContext context, final RocketComponent c)
throws IllegalArgumentException { throws IllegalArgumentException {
//A bit of a risk here, but assign the subassembly to the stage, not to the component. This is because typically the super(context, c);
//first component within the subassembly will be an external component.
super(context, c.getStage());
} }
@Override @Override
@ -33,9 +36,14 @@ public class SubAssemblyHandler extends AttachedPartsHandler {
if (RockSimCommonConstants.ATTACHED_PARTS.equals(element)) { if (RockSimCommonConstants.ATTACHED_PARTS.equals(element)) {
return this; 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)) { else if (RockSimCommonConstants.BODY_TUBE.equals(element)) {
return new BodyTubeHandler(getContext(), getComponent(), warnings); 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); return super.openElement(element, attributes, warnings);
} }