1 package net.sf.openrocket.file;
5 import net.sf.openrocket.aerodynamics.Warning;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.motor.Motor;
8 import net.sf.openrocket.motor.Motor.Type;
9 import net.sf.openrocket.startup.Application;
12 * A MotorFinder implementation that searches the thrust curve motor database
15 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17 public class DatabaseMotorFinder implements MotorFinder {
20 * Do something when a missing motor is found.
22 * This implementation adds a Warning.MissingMotor to the warning set and returns null.
24 * Override this function to change the behavior.
26 * @return The Motor which will be put in the Rocket.
28 protected Motor handleMissingMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
29 Warning.MissingMotor mmw = new Warning.MissingMotor();
30 mmw.setDesignation(designation);
31 mmw.setDigest(digest);
32 mmw.setDiameter(diameter);
33 mmw.setLength(length);
34 mmw.setManufacturer(manufacturer);
41 public Motor findMotor(Type type, String manufacturer, String designation, double diameter, double length, String digest, WarningSet warnings) {
43 if (designation == null) {
44 warnings.add(Warning.fromString("No motor specified, ignoring."));
48 List<? extends Motor> motors = Application.getMotorSetDatabase().findMotors(type, manufacturer, designation, diameter, length);
51 if (motors.size() == 0) {
52 return handleMissingMotor(type, manufacturer, designation, diameter, length, digest, warnings);
56 if (motors.size() == 1) {
57 Motor m = motors.get(0);
58 if (digest != null && !digest.equals(m.getDigest())) {
59 String str = "Motor with designation '" + designation + "'";
60 if (manufacturer != null)
61 str += " for manufacturer '" + manufacturer + "'";
62 str += " has differing thrust curve than the original.";
68 // Multiple motors, check digest for which one to use
71 // Check for motor with correct digest
72 for (Motor m : motors) {
73 if (digest.equals(m.getDigest())) {
77 String str = "Motor with designation '" + designation + "'";
78 if (manufacturer != null)
79 str += " for manufacturer '" + manufacturer + "'";
80 str += " has differing thrust curve than the original.";
85 String str = "Multiple motors with designation '" + designation + "'";
86 if (manufacturer != null)
87 str += " for manufacturer '" + manufacturer + "'";
88 str += " found, one chosen arbitrarily.";