From 4bd50af6739b922de56e6112956cf4ddf54f3822 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Tue, 1 Mar 2022 11:38:09 -0700 Subject: [PATCH] Make motor database search more robust, especially when loading files: Instead of requiring motor "designation" to match either the actual designation or the common name, require it to be a substring of the actual designation or that the common name be a substring of the actual designation. Many motors in stored rocket files have "designations" that resemble, but do not match, actual designations and common names. Don't match on diameter or length when loading files. Motors with errors in the old database (eg M1850) would fail to be recognized. --- .../database/motor/ThrustCurveMotorSetDatabase.java | 6 +++--- .../sf/openrocket/file/openrocket/importt/MotorHandler.java | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSetDatabase.java b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSetDatabase.java index 60b3256b4..6ff4b4ab5 100644 --- a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSetDatabase.java +++ b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSetDatabase.java @@ -34,7 +34,7 @@ public class ThrustCurveMotorSetDatabase implements MotorDatabase { for (ThrustCurveMotor m : set.getMotors()) { boolean matchDescription = true; boolean matchDigest = true; - + // unlike the description, digest must be present in search criteria to get a match if (digest == null || digest != m.getDigest()) matchDigest = false; @@ -45,8 +45,8 @@ public class ThrustCurveMotorSetDatabase implements MotorDatabase { else if (manufacturer != null && !m.getManufacturer().matches(manufacturer)) matchDescription = false; else if (designation != null && - !designation.equalsIgnoreCase(m.getDesignation()) && - !designation.equalsIgnoreCase(m.getCommonName())) + !m.getDesignation().toUpperCase().contains(designation.toUpperCase()) && + !designation.toUpperCase().contains(m.getCommonName().toUpperCase())) matchDescription = false; else if (!Double.isNaN(diameter) && (Math.abs(diameter - m.getDiameter()) > 0.005)) matchDescription = false; diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorHandler.java index e11247c3e..5e4258cb3 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorHandler.java @@ -1,5 +1,7 @@ package net.sf.openrocket.file.openrocket.importt; +import java.lang.Double; + import java.util.HashMap; import java.util.Locale; @@ -42,7 +44,7 @@ class MotorHandler extends AbstractElementHandler { * Return the motor to use, or null. */ public Motor getMotor(WarningSet warnings) { - return context.getMotorFinder().findMotor(type, manufacturer, designation, diameter, length, digest, warnings); + return context.getMotorFinder().findMotor(type, manufacturer, designation, Double.NaN, Double.NaN, digest, warnings); } /** @@ -142,4 +144,4 @@ class MotorHandler extends AbstractElementHandler { } } -} \ No newline at end of file +}