diff --git a/android/src/net/sf/openrocket/android/db/ConversionUtils.java b/android/src/net/sf/openrocket/android/db/ConversionUtils.java index a5695a1d8..a66fc28cf 100644 --- a/android/src/net/sf/openrocket/android/db/ConversionUtils.java +++ b/android/src/net/sf/openrocket/android/db/ConversionUtils.java @@ -5,10 +5,47 @@ import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import net.sf.openrocket.motor.Motor; import net.sf.openrocket.util.Coordinate; abstract class ConversionUtils { + static double[] stringToDelays( String value ) { + if (value == null || "".equals(value) ) { + return new double[0]; + } + String[] parts = value.split(","); + double[] values = new double[parts.length]; + for( int i =0; i { // Check whether to add as new motor or overwrite existing - final String digest = MotorDigest.digestMotor(motor); + final String digest = motor.getDigest(); for (int index = 0; index < motors.size(); index++) { Motor m = motors.get(index); diff --git a/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java b/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java index ae653e666..cbe517e74 100644 --- a/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java @@ -196,15 +196,13 @@ public class RASPMotorLoader extends AbstractMotorLoader { motorDigest.update(DataType.TIME_ARRAY, timeArray); motorDigest.update(DataType.MASS_SPECIFIC, totalW, totalW - propW); motorDigest.update(DataType.FORCE_PER_TIME, thrustArray); - // TODO: HIGH: Motor digest? - // final String digest = motorDigest.getDigest(); - + final String digest = motorDigest.getDigest(); try { Manufacturer m = Manufacturer.getManufacturer(manufacturer); return new ThrustCurveMotor(m, designation, comment, m.getMotorType(), - delays, diameter, length, timeArray, thrustArray, cgArray); + delays, diameter, length, timeArray, thrustArray, cgArray, digest); } catch (IllegalArgumentException e) { diff --git a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java index 5b0743e14..5e04c98c5 100644 --- a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java @@ -353,8 +353,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { motorDigest.update(DataType.CG_PER_TIME, toArray(cg)); } motorDigest.update(DataType.FORCE_PER_TIME, thrustArray); - // TODO: HIGH: Motor digest? - // final String digest = motorDigest.getDigest(); + final String digest = motorDigest.getDigest(); try { @@ -372,7 +371,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { } return new ThrustCurveMotor(m, designation, description, t, - delays, diameter, length, timeArray, thrustArray, cgArray); + delays, diameter, length, timeArray, thrustArray, cgArray, digest); } catch (IllegalArgumentException e) { throw new SAXException("Illegal motor data", e); } diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketLoader.java index c4fc7d737..518f1e44c 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketLoader.java @@ -23,8 +23,6 @@ import net.sf.openrocket.file.simplesax.SimpleSAX; import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.motor.MotorDigest; -import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.rocketcomponent.BodyComponent; import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.Bulkhead; @@ -1015,7 +1013,7 @@ class MotorHandler extends ElementHandler { // One motor if (motors.size() == 1) { Motor m = motors.get(0); - if (digest != null && !MotorDigest.digestMotor(m).equals(digest)) { + if (digest != null && !digest.equals(m.getDigest())) { String str = "Motor with designation '" + designation + "'"; if (manufacturer != null) str += " for manufacturer '" + manufacturer + "'"; @@ -1030,7 +1028,7 @@ class MotorHandler extends ElementHandler { // Check for motor with correct digest for (Motor m : motors) { - if (MotorDigest.digestMotor(m).equals(digest)) { + if (digest.equals(m.getDigest())) { return m; } } @@ -1045,7 +1043,7 @@ class MotorHandler extends ElementHandler { // No digest, check for preferred digest (OpenRocket <= 1.1.0) // TODO: MEDIUM: This should only be done for document versions 1.1 and below for (Motor m : motors) { - if (PreferredMotorDigests.DIGESTS.contains(MotorDigest.digestMotor(m))) { + if (PreferredMotorDigests.DIGESTS.contains(m.getDigest())) { return m; } } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index 44e71e4b9..3cd29acb1 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -7,7 +7,6 @@ import java.util.List; import net.sf.openrocket.file.RocketSaver; import net.sf.openrocket.material.Material; import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.motor.MotorDigest; import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.MotorMount; @@ -128,7 +127,7 @@ public class RocketComponentSaver { ThrustCurveMotor m = (ThrustCurveMotor) motor; elements.add(" " + RocketSaver.escapeXML(m.getManufacturer().getSimpleName()) + ""); - elements.add(" " + MotorDigest.digestMotor(m) + ""); + elements.add(" " + m.getDigest() + ""); } elements.add(" " + RocketSaver.escapeXML(motor.getDesignation()) + ""); elements.add(" " + motor.getDiameter() + ""); diff --git a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index e4c222294..d49e58f56 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -589,7 +589,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec // Store selected motor in preferences node, set all others to false Preferences prefs = ((SwingPreferences) Application.getPreferences()).getNode(net.sf.openrocket.startup.Preferences.PREFERRED_THRUST_CURVE_MOTOR_NODE); for (ThrustCurveMotor m : set.getMotors()) { - String digest = MotorDigest.digestMotor(m); + String digest = m.getDigest(); prefs.putBoolean(digest, m == motor); } } @@ -689,7 +689,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec selectedMotor.getEmptyCG().weight)); dataPointsLabel.setText("" + (selectedMotor.getTimePoints().length - 1)); if (digestLabel != null) { - digestLabel.setText(MotorDigest.digestMotor(selectedMotor)); + digestLabel.setText(selectedMotor.getDigest()); } setComment(selectedMotor.getDescription()); @@ -819,7 +819,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec List list = set.getMotors(); Preferences prefs = ((SwingPreferences) Application.getPreferences()).getNode(net.sf.openrocket.startup.Preferences.PREFERRED_THRUST_CURVE_MOTOR_NODE); for (ThrustCurveMotor m : list) { - String digest = MotorDigest.digestMotor(m); + String digest = m.getDigest(); if (prefs.getBoolean(digest, false)) { return m; } diff --git a/core/src/net/sf/openrocket/motor/Motor.java b/core/src/net/sf/openrocket/motor/Motor.java index afe062126..21104f0d6 100644 --- a/core/src/net/sf/openrocket/motor/Motor.java +++ b/core/src/net/sf/openrocket/motor/Motor.java @@ -128,6 +128,7 @@ public interface Motor { */ public double getLength(); + public String getDigest(); public MotorInstance getInstance(); diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index 1f8acd2aa..e1ba1d77c 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -1,6 +1,5 @@ package net.sf.openrocket.motor; -import java.io.Serializable; import java.text.Collator; import java.util.Arrays; import java.util.Locale; @@ -26,7 +25,7 @@ public class ThrustCurveMotor implements Motor, Comparable { } private static final DesignationComparator DESIGNATION_COMPARATOR = new DesignationComparator(); - + private final String digest; private final Manufacturer manufacturer; private final String designation; @@ -61,8 +60,8 @@ public class ThrustCurveMotor implements Motor, Comparable { */ public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description, Motor.Type type, double[] delays, double diameter, double length, - double[] time, double[] thrust, Coordinate[] cg) { - + double[] time, double[] thrust, Coordinate[] cg, String digest) { + this.digest = digest; // Check argument validity if ((time.length != thrust.length) || (time.length != cg.length)) { throw new IllegalArgumentException("Array lengths do not match, " + @@ -253,6 +252,10 @@ public class ThrustCurveMotor implements Motor, Comparable { return totalImpulse; } + @Override + public String getDigest() { + return digest; + } /** diff --git a/core/src/net/sf/openrocket/utils/MotorCorrelation.java b/core/src/net/sf/openrocket/utils/MotorCorrelation.java index 3394a59e0..e978b0cf4 100644 --- a/core/src/net/sf/openrocket/utils/MotorCorrelation.java +++ b/core/src/net/sf/openrocket/utils/MotorCorrelation.java @@ -129,7 +129,7 @@ public class MotorCorrelation { // Output motor digests final int count = motors.size(); for (int i = 0; i < count; i++) { - System.out.println(files.get(i) + ": " + MotorDigest.digestMotor((ThrustCurveMotor) motors.get(i))); + System.out.println(files.get(i) + ": " + ((ThrustCurveMotor) motors.get(i)).getDigest()); } // Cross-correlate every pair diff --git a/core/src/net/sf/openrocket/utils/MotorDigester.java b/core/src/net/sf/openrocket/utils/MotorDigester.java index 754d4075a..27b6d23f6 100644 --- a/core/src/net/sf/openrocket/utils/MotorDigester.java +++ b/core/src/net/sf/openrocket/utils/MotorDigester.java @@ -47,7 +47,7 @@ public class MotorDigester { continue; } - String digest = MotorDigest.digestMotor((ThrustCurveMotor) m); + String digest = ((ThrustCurveMotor) m).getDigest(); if (printFileNames) { System.out.print(file + ": "); } diff --git a/core/src/net/sf/openrocket/utils/MotorPrinter.java b/core/src/net/sf/openrocket/utils/MotorPrinter.java index 0ca4e9871..0f6b7b786 100644 --- a/core/src/net/sf/openrocket/utils/MotorPrinter.java +++ b/core/src/net/sf/openrocket/utils/MotorPrinter.java @@ -39,7 +39,7 @@ public class MotorPrinter { System.out.printf(" Total impulse: %.2f Ns\n", m.getTotalImpulseEstimate()); System.out.println(" Diameter: " + m.getDiameter() * 1000 + " mm"); System.out.println(" Length: " + m.getLength() * 1000 + " mm"); - System.out.println(" Digest: " + MotorDigest.digestMotor(m)); + System.out.println(" Digest: " + m.getDigest()); if (m instanceof ThrustCurveMotor) { ThrustCurveMotor tc = (ThrustCurveMotor) m; diff --git a/core/test/net/sf/openrocket/database/MotorSetDatabaseTest.java b/core/test/net/sf/openrocket/database/MotorSetDatabaseTest.java index 33ced0c8e..06e8d835e 100644 --- a/core/test/net/sf/openrocket/database/MotorSetDatabaseTest.java +++ b/core/test/net/sf/openrocket/database/MotorSetDatabaseTest.java @@ -28,15 +28,15 @@ public class MotorSetDatabaseTest { this.addMotor(new ThrustCurveMotor(Manufacturer.getManufacturer("A"), "Foo", "Desc", Motor.Type.SINGLE, new double[] { 0 }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL})); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestA")); this.addMotor(new ThrustCurveMotor(Manufacturer.getManufacturer("A"), "Bar", "Desc", Motor.Type.SINGLE, new double[] { 0 }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL})); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestB")); this.addMotor(new ThrustCurveMotor(Manufacturer.getManufacturer("A"), "Foo", "Desc", Motor.Type.UNKNOWN, new double[] { 0 }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL})); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestA")); } }; diff --git a/core/test/net/sf/openrocket/database/ThrustCurveMotorSetTest.java b/core/test/net/sf/openrocket/database/ThrustCurveMotorSetTest.java index 56e30b2dd..2432f279a 100644 --- a/core/test/net/sf/openrocket/database/ThrustCurveMotorSetTest.java +++ b/core/test/net/sf/openrocket/database/ThrustCurveMotorSetTest.java @@ -19,25 +19,25 @@ public class ThrustCurveMotorSetTest { Manufacturer.getManufacturer("A"), "F12X", "Desc", Motor.Type.UNKNOWN, new double[] { }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestA"); private static final ThrustCurveMotor motor2 = new ThrustCurveMotor( Manufacturer.getManufacturer("A"), "F12H", "Desc", Motor.Type.SINGLE, new double[] { 5 }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestB"); private static final ThrustCurveMotor motor3 = new ThrustCurveMotor( Manufacturer.getManufacturer("A"), "F12", "Desc", Motor.Type.UNKNOWN, new double[] { 0, Motor.PLUGGED }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 2, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestC"); private static final ThrustCurveMotor motor4 = new ThrustCurveMotor( Manufacturer.getManufacturer("A"), "F12", "Desc", Motor.Type.HYBRID, new double[] { 0 }, 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 2, 0}, - new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}); + new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL}, "digestD"); @Test diff --git a/core/test/net/sf/openrocket/file/motor/TestMotorLoader.java b/core/test/net/sf/openrocket/file/motor/TestMotorLoader.java index 8200310a0..74391bdc5 100644 --- a/core/test/net/sf/openrocket/file/motor/TestMotorLoader.java +++ b/core/test/net/sf/openrocket/file/motor/TestMotorLoader.java @@ -1,6 +1,8 @@ package net.sf.openrocket.file.motor; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -8,7 +10,6 @@ import java.util.Arrays; import java.util.List; import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.motor.MotorDigest; import net.sf.openrocket.motor.ThrustCurveMotor; import org.junit.Test; @@ -52,12 +53,12 @@ public class TestMotorLoader { String[] d = new String[digests.length]; for (int i = 0; i < motors.size(); i++) { - d[i] = MotorDigest.digestMotor((ThrustCurveMotor) motors.get(i)); + d[i] = ((ThrustCurveMotor) motors.get(i)).getDigest(); } Arrays.sort(digests); Arrays.sort(d); - assertTrue(Arrays.equals(d, digests)); + assertTrue("d = " + Arrays.toString(d) + " digests = " + Arrays.toString(digests), Arrays.equals(d, digests)); } } diff --git a/core/test/net/sf/openrocket/motor/ThrustCurveMotorTest.java b/core/test/net/sf/openrocket/motor/ThrustCurveMotorTest.java index 7ca43d716..327ec375e 100644 --- a/core/test/net/sf/openrocket/motor/ThrustCurveMotorTest.java +++ b/core/test/net/sf/openrocket/motor/ThrustCurveMotorTest.java @@ -26,7 +26,7 @@ public class ThrustCurveMotorTest { new Coordinate(0.02,0,0,0.05), new Coordinate(0.02,0,0,0.05), new Coordinate(0.03,0,0,0.03) - }); + }, "digestA"); @Test public void testMotorData() {