[#1348] Add RockSim exporting of PodSet

This commit is contained in:
SiboVG 2022-11-06 17:02:04 +01:00
parent afbd989249
commit 92edca5923
4 changed files with 126 additions and 5 deletions

View File

@ -29,6 +29,8 @@ public class RockSimCommonConstants {
public static final String DENSITY_TYPE = "DensityType";
public static final String RADIAL_LOC = "RadialLoc";
public static final String RADIAL_ANGLE = "RadialAngle";
public static final String AUTO_CALC_RADIAL_DISTANCE = "AutoCalcRadialDistance";
public static final String AUTO_CALC_RADIAL_ANGLE = "AutoCalcRadialAngle";
public static final String LOCATION_MODE = "LocationMode";
public static final String FINISH_CODE = "FinishCode";
public static final String SERIAL_NUMBER = "SerialNo";

View File

@ -11,6 +11,7 @@ import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.Parachute;
import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Streamer;
import net.sf.openrocket.rocketcomponent.Transition;
@ -50,6 +51,7 @@ public class BodyTubeDTO extends BasePartDTO implements AttachableParts {
@XmlElementRefs({
@XmlElementRef(name = RockSimCommonConstants.BODY_TUBE, type = BodyTubeDTO.class),
@XmlElementRef(name = RockSimCommonConstants.BODY_TUBE, type = InnerBodyTubeDTO.class),
@XmlElementRef(name = RockSimCommonConstants.TRANSITION, type = TransitionDTO.class),
@XmlElementRef(name = RockSimCommonConstants.RING, type = CenteringRingDTO.class),
@XmlElementRef(name = RockSimCommonConstants.LAUNCH_LUG, type = LaunchLugDTO.class),
@XmlElementRef(name = RockSimCommonConstants.FIN_SET, type = FinSetDTO.class),
@ -57,7 +59,8 @@ public class BodyTubeDTO extends BasePartDTO implements AttachableParts {
@XmlElementRef(name = RockSimCommonConstants.TUBE_FIN_SET, type = TubeFinSetDTO.class),
@XmlElementRef(name = RockSimCommonConstants.STREAMER, type = StreamerDTO.class),
@XmlElementRef(name = RockSimCommonConstants.PARACHUTE, type = ParachuteDTO.class),
@XmlElementRef(name = RockSimCommonConstants.MASS_OBJECT, type = MassObjectDTO.class)})
@XmlElementRef(name = RockSimCommonConstants.MASS_OBJECT, type = MassObjectDTO.class),
@XmlElementRef(name = RockSimCommonConstants.EXTERNAL_POD, type = PodSetDTO.class)})
List<BasePartDTO> attachedParts = new ArrayList<BasePartDTO>();
/**
@ -125,6 +128,8 @@ public class BodyTubeDTO extends BasePartDTO implements AttachableParts {
addAttachedPart(new FinSetDTO((FinSet) rocketComponents));
} else if (rocketComponents instanceof TubeFinSet) {
addAttachedPart(new TubeFinSetDTO((TubeFinSet) rocketComponents));
} else if (rocketComponents instanceof PodSet) {
addAttachedPart(new PodSetDTO((PodSet) rocketComponents));
}
}
}

View File

@ -0,0 +1,110 @@
package net.sf.openrocket.file.rocksim.export;
import net.sf.openrocket.file.rocksim.RockSimCommonConstants;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.NoseCone;
import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Transition;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
/**
* Models the XML element for a RockSim pod.
*/
@XmlRootElement(name = RockSimCommonConstants.EXTERNAL_POD)
@XmlAccessorType(XmlAccessType.FIELD)
public class PodSetDTO extends BasePartDTO implements AttachableParts {
@XmlElement(name = RockSimCommonConstants.AUTO_CALC_RADIAL_DISTANCE)
private int autoCalcRadialDistance = 0;
@XmlElement(name = RockSimCommonConstants.AUTO_CALC_RADIAL_ANGLE)
private int autoCalcRadialAngle = 0;
@XmlElementWrapper(name = RockSimCommonConstants.ATTACHED_PARTS)
@XmlElementRefs({
@XmlElementRef(name = RockSimCommonConstants.BODY_TUBE, type = BodyTubeDTO.class),
@XmlElementRef(name = RockSimCommonConstants.NOSE_CONE, type = NoseConeDTO.class),
@XmlElementRef(name = RockSimCommonConstants.TRANSITION, type = TransitionDTO.class),
@XmlElementRef(name = RockSimCommonConstants.EXTERNAL_POD, type = PodSetDTO.class)})
List<BasePartDTO> attachedParts = new ArrayList<BasePartDTO>();
/**
* Default constructor.
*/
public PodSetDTO() {
}
/**
* Copy constructor. Fully populates this instance with values taken from the OR PodSet.
*
* @param theORPodSet
*/
public PodSetDTO(PodSet theORPodSet) {
super(theORPodSet);
// OR should always override the radial angle and distance
setAutoCalcRadialDistance(false);
setAutoCalcRadialAngle(false);
setRadialAngle(theORPodSet.getAngleOffset());
setRadialLoc(theORPodSet.getRadiusMethod().getRadius(
theORPodSet.getParent(), theORPodSet,
theORPodSet.getRadiusOffset()) * RockSimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
setXb(theORPodSet.getAxialOffset(AxialMethod.TOP) * RockSimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
for (RocketComponent child : theORPodSet.getChildren()) {
if (child instanceof PodSet) {
addAttachedPart(new PodSetDTO((PodSet) child));
} else if (child instanceof BodyTube) {
addAttachedPart(new BodyTubeDTO((BodyTube) child));
} else if (child instanceof NoseCone) {
addAttachedPart(new NoseConeDTO((NoseCone) child));
} else if (child instanceof Transition) {
addAttachedPart(new TransitionDTO((Transition) child));
}
}
}
public int getAutoCalcRadialDistance() {
return autoCalcRadialDistance;
}
public void setAutoCalcRadialDistance(boolean motorMount) {
if (motorMount) {
this.autoCalcRadialDistance = 1;
} else {
this.autoCalcRadialDistance = 0;
}
}
public int getAutoCalcRadialAngle() {
return autoCalcRadialAngle;
}
public void setAutoCalcRadialAngle(boolean motorMount) {
if (motorMount) {
this.autoCalcRadialAngle = 1;
} else {
this.autoCalcRadialAngle = 0;
}
}
@Override
public void addAttachedPart(BasePartDTO part) {
if (!attachedParts.contains(part)) {
attachedParts.add(part);
}
}
@Override
public void removeAttachedPart(BasePartDTO part) {
attachedParts.remove(part);
}
}

View File

@ -121,19 +121,23 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
@Override
public double getAxialOffset() {
return getAxialOffset(this.axialMethod);
}
@Override
public double getAxialOffset(AxialMethod method) {
double returnValue;
if (this.isAfter()){
// remember the implicit (this instanceof Stage)
throw new BugException("found a pod positioned via: AFTER, but is not on the centerline?!: " + this.getName() + " is " + this.getAxialMethod().name() );
} else {
returnValue = super.getAxialOffset(this.axialMethod);
returnValue = super.getAxialOffset(method);
}
if (MathUtil.EPSILON > Math.abs(returnValue)) {
returnValue = 0.0;
}
return returnValue;
}