Merge pull request #920 from neilbalch/RockSim_Import_Dist_Fix

Fix #881, #907 issues
This commit is contained in:
Joe Pfeiffer 2021-05-24 16:41:19 -06:00 committed by GitHub
commit de10d819bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 34 deletions

1
.gitignore vendored
View File

@ -92,3 +92,4 @@ openrocket.log
*.snap *.snap
prime/* prime/*
swing/resources/datafiles/presets/system.ser

View File

@ -39,7 +39,7 @@ class FinSetHandler extends AbstractElementHandler {
* The parent component. * The parent component.
*/ */
private final RocketComponent component; private final RocketComponent component;
/** /**
* The name of the fin. * The name of the fin.
*/ */
@ -68,13 +68,13 @@ class FinSetHandler extends AbstractElementHandler {
* The length of the tip chord. * The length of the tip chord.
*/ */
private double tipChord = 0.0d; private double tipChord = 0.0d;
/** /**
* The length of the mid-chord (aka height). * The length of the mid-chord (aka height).
*/ */
@SuppressWarnings("unused") // stored from file, but not used. @SuppressWarnings("unused") // stored from file, but not used.
private double midChordLen = 0.0d; private double midChordLen = 0.0d;
/** /**
* The distance of the leading edge from root to top. * The distance of the leading edge from root to top.
*/ */
@ -143,9 +143,9 @@ class FinSetHandler extends AbstractElementHandler {
* The Rocksim calculated cg. * The Rocksim calculated cg.
*/ */
private Double calcCg = 0d; private Double calcCg = 0d;
private final RockSimAppearanceBuilder appearanceBuilder; private final RockSimAppearanceBuilder appearanceBuilder;
/** /**
* Constructor. * Constructor.
* *
@ -160,12 +160,12 @@ class FinSetHandler extends AbstractElementHandler {
appearanceBuilder = new RockSimAppearanceBuilder(context); appearanceBuilder = new RockSimAppearanceBuilder(context);
component = c; component = c;
} }
@Override @Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) { public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
return PlainTextHandler.INSTANCE; return PlainTextHandler.INSTANCE;
} }
@Override @Override
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings) public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
throws SAXException { throws SAXException {
@ -180,7 +180,9 @@ class FinSetHandler extends AbstractElementHandler {
finish = RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket(); finish = RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket();
} }
if (RocksimCommonConstants.XB.equals(element)) { if (RocksimCommonConstants.XB.equals(element)) {
location = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; // Opposite value accounts for the different relative distance directions used
// Issue Ref: https://github.com/openrocket/openrocket/issues/881
location = -Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
} }
if (RocksimCommonConstants.LOCATION_MODE.equals(element)) { if (RocksimCommonConstants.LOCATION_MODE.equals(element)) {
axialMethod = RocksimLocationMode.fromCode(Integer.parseInt(content)).asOpenRocket(); axialMethod = RocksimLocationMode.fromCode(Integer.parseInt(content)).asOpenRocket();
@ -245,21 +247,21 @@ class FinSetHandler extends AbstractElementHandler {
if (RocksimCommonConstants.CALC_CG.equals(element)) { if (RocksimCommonConstants.CALC_CG.equals(element)) {
calcCg = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH; calcCg = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
} }
appearanceBuilder.processElement(element, content, warnings); appearanceBuilder.processElement(element, content, warnings);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number."); warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
} }
} }
@Override @Override
public void endHandler(String element, HashMap<String, String> attributes, public void endHandler(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException { String content, WarningSet warnings) throws SAXException {
//Create the fin set and correct for overrides and actual material densities //Create the fin set and correct for overrides and actual material densities
final FinSet finSet = asOpenRocket(warnings); final FinSet finSet = asOpenRocket(warnings);
finSet.setAppearance(appearanceBuilder.getAppearance()); finSet.setAppearance(appearanceBuilder.getAppearance());
if (component.isCompatible(finSet)) { if (component.isCompatible(finSet)) {
BaseHandler.setOverride(finSet, override, mass, cg); BaseHandler.setOverride(finSet, override, mass, cg);
if (!override && finSet.getCrossSection().equals(FinSet.CrossSection.AIRFOIL)) { if (!override && finSet.getCrossSection().equals(FinSet.CrossSection.AIRFOIL)) {
@ -277,8 +279,8 @@ class FinSetHandler extends AbstractElementHandler {
+ component.getComponentName() + ", ignoring component."); + component.getComponentName() + ", ignoring component.");
} }
} }
/** /**
* Convert the parsed Rocksim data values in this object to an instance of OpenRocket's FinSet. * Convert the parsed Rocksim data values in this object to an instance of OpenRocket's FinSet.
* *
@ -288,7 +290,7 @@ class FinSetHandler extends AbstractElementHandler {
*/ */
public FinSet asOpenRocket(WarningSet warnings) { public FinSet asOpenRocket(WarningSet warnings) {
FinSet result; FinSet result;
if (shapeCode == 0) { if (shapeCode == 0) {
//Trapezoidal //Trapezoidal
result = new TrapezoidFinSet(); result = new TrapezoidFinSet();
@ -301,10 +303,10 @@ class FinSetHandler extends AbstractElementHandler {
((EllipticalFinSet) result).setLength(rootChord); ((EllipticalFinSet) result).setLength(rootChord);
} }
else if (shapeCode == 2) { else if (shapeCode == 2) {
result = new FreeformFinSet(); result = new FreeformFinSet();
((FreeformFinSet) result).setPoints(toCoordinates(pointList, warnings)); ((FreeformFinSet) result).setPoints(toCoordinates(pointList, warnings));
} }
else { else {
return null; return null;
@ -324,9 +326,9 @@ class FinSetHandler extends AbstractElementHandler {
result.setAxialOffset(location); result.setAxialOffset(location);
return result; return result;
} }
/** /**
* Convert a Rocksim string that represents fin plan points into an array of OpenRocket coordinates. * Convert a Rocksim string that represents fin plan points into an array of OpenRocket coordinates.
* *
@ -368,8 +370,8 @@ class FinSetHandler extends AbstractElementHandler {
final Coordinate[] coords = new Coordinate[result.size()]; final Coordinate[] coords = new Coordinate[result.size()];
return result.toArray(coords); return result.toArray(coords);
} }
/** /**
* Convert a Rocksim tip shape to an OpenRocket CrossSection. * Convert a Rocksim tip shape to an OpenRocket CrossSection.
* *
@ -389,7 +391,7 @@ class FinSetHandler extends AbstractElementHandler {
return FinSet.CrossSection.SQUARE; return FinSet.CrossSection.SQUARE;
} }
} }
public static int convertTipShapeCode(FinSet.CrossSection cs) { public static int convertTipShapeCode(FinSet.CrossSection cs) {
if (FinSet.CrossSection.ROUNDED.equals(cs)) { if (FinSet.CrossSection.ROUNDED.equals(cs)) {
return 1; return 1;
@ -399,5 +401,5 @@ class FinSetHandler extends AbstractElementHandler {
} }
return 0; return 0;
} }
} }

View File

@ -3,7 +3,7 @@ package net.sf.openrocket.rocketcomponent.position;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
public enum AxialMethod implements DistanceMethod { public enum AxialMethod implements DistanceMethod {
// subject component is simply located absolutely, from the origin (tip-of-rocket) // subject component is simply located absolutely, from the origin (tip-of-rocket)
ABSOLUTE (Application.getTranslator().get("RocketComponent.Position.Method.Axial.ABSOLUTE")){ ABSOLUTE (Application.getTranslator().get("RocketComponent.Position.Method.Axial.ABSOLUTE")){
@Override @Override
public boolean clampToZero() { return false; } public boolean clampToZero() { return false; }
@ -18,8 +18,8 @@ public enum AxialMethod implements DistanceMethod {
return position; return position;
} }
}, },
// subject component will trail the target component, in the increasing coordinate direction // subject component will trail the target component, in the increasing coordinate direction
AFTER (Application.getTranslator().get("RocketComponent.Position.Method.Axial.AFTER")){ AFTER (Application.getTranslator().get("RocketComponent.Position.Method.Axial.AFTER")){
@Override @Override
public boolean clampToZero() { return false; } public boolean clampToZero() { return false; }
@ -51,7 +51,7 @@ public enum AxialMethod implements DistanceMethod {
return position; return position;
} }
}, },
// This coordinate is measured from the middle of the parent component to the middle of this component // This coordinate is measured from the middle of the parent component to the middle of this component
MIDDLE (Application.getTranslator().get("RocketComponent.Position.Method.Axial.MIDDLE")) { MIDDLE (Application.getTranslator().get("RocketComponent.Position.Method.Axial.MIDDLE")) {
@Override @Override
@ -70,7 +70,7 @@ public enum AxialMethod implements DistanceMethod {
return position + (innerLength - outerLength) / 2; return position + (innerLength - outerLength) / 2;
} }
}, },
// This coordinate is measured from the bottom of the parent component to the bottom of this component // This coordinate is measured from the bottom of the parent component to the bottom of this component
BOTTOM (Application.getTranslator().get("RocketComponent.Position.Method.Axial.BOTTOM")){ BOTTOM (Application.getTranslator().get("RocketComponent.Position.Method.Axial.BOTTOM")){
@Override @Override
@ -94,15 +94,15 @@ public enum AxialMethod implements DistanceMethod {
// just as a reminder: // just as a reminder:
// public T[] getEnumConstants() // public T[] getEnumConstants()
public static final AxialMethod[] axialOffsetMethods = { TOP, MIDDLE, BOTTOM }; public static final AxialMethod[] axialOffsetMethods = { ABSOLUTE, TOP, MIDDLE, BOTTOM };
public final String description; public final String description;
AxialMethod( final String newDescription ) { AxialMethod( final String newDescription ) {
this.description=newDescription; this.description=newDescription;
} }
public abstract boolean clampToZero(); public abstract boolean clampToZero();
public abstract double getAsOffset(double position, double innerLength, double outerLength); public abstract double getAsOffset(double position, double innerLength, double outerLength);
@ -113,5 +113,5 @@ public enum AxialMethod implements DistanceMethod {
public String toString() { public String toString() {
return description; return description;
} }
} }