1 package net.sf.openrocket.database;
4 import java.io.IOException;
5 import java.util.ArrayList;
7 import net.sf.openrocket.file.MotorLoader;
8 import net.sf.openrocket.material.Material;
9 import net.sf.openrocket.rocketcomponent.Motor;
10 import net.sf.openrocket.util.MathUtil;
14 * A class that contains single instances of {@link Database} for specific purposes.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
18 public class Databases {
20 /* Static implementations of specific databases: */
24 public static final Database<Motor> MOTOR = new Database<Motor>(new MotorLoader());
28 * A database of bulk materials (with bulk densities).
30 public static final Database<Material> BULK_MATERIAL = new Database<Material>();
32 * A database of surface materials (with surface densities).
34 public static final Database<Material> SURFACE_MATERIAL = new Database<Material>();
36 * A database of linear material (with length densities).
38 public static final Database<Material> LINE_MATERIAL = new Database<Material>();
42 // TODO: HIGH: loading the thrust curves and other databases
46 MOTOR.loadJarDirectory("datafiles/thrustcurves/", ".*\\.[eE][nN][gG]$");
47 } catch (IOException e) {
48 System.out.println("Could not read thrust curves from JAR: "+e.getMessage());
51 MOTOR.loadDirectory(new File("datafiles/thrustcurves/"),".*\\.[eE][nN][gG]$");
52 } catch (IOException e1) {
53 System.out.println("Could not read thrust curves from directory either.");
54 throw new RuntimeException(e1);
59 // TODO: HIGH: Move materials into data files
62 BULK_MATERIAL.add(new Material.Bulk("Acrylic", 1190));
63 BULK_MATERIAL.add(new Material.Bulk("Balsa", 170));
64 BULK_MATERIAL.add(new Material.Bulk("Birch", 670));
65 BULK_MATERIAL.add(new Material.Bulk("Cardboard", 680));
66 BULK_MATERIAL.add(new Material.Bulk("Carbon fiber", 1780));
67 BULK_MATERIAL.add(new Material.Bulk("Cork", 240));
68 BULK_MATERIAL.add(new Material.Bulk("Fiberglass", 1850));
69 BULK_MATERIAL.add(new Material.Bulk("Kraft phenolic",950));
70 BULK_MATERIAL.add(new Material.Bulk("Maple", 755));
71 BULK_MATERIAL.add(new Material.Bulk("Paper (office)",820));
72 BULK_MATERIAL.add(new Material.Bulk("Pine", 530));
73 BULK_MATERIAL.add(new Material.Bulk("Plywood (birch)",630));
74 BULK_MATERIAL.add(new Material.Bulk("Polycarbonate (Lexan)",1200));
75 BULK_MATERIAL.add(new Material.Bulk("Polystyrene", 1050));
76 BULK_MATERIAL.add(new Material.Bulk("PVC", 1390));
77 BULK_MATERIAL.add(new Material.Bulk("Spruce", 450));
78 BULK_MATERIAL.add(new Material.Bulk("Quantum tubing",1050));
80 SURFACE_MATERIAL.add(new Material.Surface("Ripstop nylon", 0.067));
81 SURFACE_MATERIAL.add(new Material.Surface("Mylar", 0.021));
82 SURFACE_MATERIAL.add(new Material.Surface("Polyethylene (thin)", 0.015));
83 SURFACE_MATERIAL.add(new Material.Surface("Polyethylene (heavy)", 0.040));
84 SURFACE_MATERIAL.add(new Material.Surface("Silk", 0.060));
85 SURFACE_MATERIAL.add(new Material.Surface("Paper (office)", 0.080));
86 SURFACE_MATERIAL.add(new Material.Surface("Cellophane", 0.018));
87 SURFACE_MATERIAL.add(new Material.Surface("Cr\u00eape paper", 0.025));
89 LINE_MATERIAL.add(new Material.Line("Thread (heavy-duty)", 0.0003));
90 LINE_MATERIAL.add(new Material.Line("Elastic cord (round 2mm, 1/16 in)",0.0018));
91 LINE_MATERIAL.add(new Material.Line("Elastic cord (flat 6mm, 1/4 in)", 0.0043));
92 LINE_MATERIAL.add(new Material.Line("Elastic cord (flat 12mm, 1/2 in)", 0.008));
93 LINE_MATERIAL.add(new Material.Line("Elastic cord (flat 19mm, 3/4 in)", 0.0012));
94 LINE_MATERIAL.add(new Material.Line("Elastic cord (flat 25mm, 1 in)", 0.0016));
95 LINE_MATERIAL.add(new Material.Line("Braided nylon (2 mm, 1/16 in)", 0.001));
96 LINE_MATERIAL.add(new Material.Line("Braided nylon (3 mm, 1/8 in)", 0.0035));
97 LINE_MATERIAL.add(new Material.Line("Tubular nylon (11 mm, 7/16 in)", 0.013));
98 LINE_MATERIAL.add(new Material.Line("Tubular nylon (14 mm, 9/16 in)", 0.016));
99 LINE_MATERIAL.add(new Material.Line("Tubular nylon (25 mm, 1 in)", 0.029));
104 * Find a material from the database with the specified type and name. Returns
105 * <code>null</code> if the specified material could not be found.
107 * @param type the material type.
108 * @param name the material name in the database.
109 * @return the material, or <code>null</code> if not found.
111 public static Material findMaterial(Material.Type type, String name) {
112 Database<Material> db;
118 db = SURFACE_MATERIAL;
124 throw new IllegalArgumentException("Illegal material type: "+type);
127 for (Material m: db) {
128 if (m.getName().equalsIgnoreCase(name)) {
137 * Find a material from the database or return a new material if the specified
138 * material with the specified density is not found.
140 * @param type the material type.
141 * @param name the material name.
142 * @param density the density of the material.
143 * @return the material object from the database or a new material.
145 public static Material findMaterial(Material.Type type, String name, double density) {
146 Database<Material> db;
152 db = SURFACE_MATERIAL;
158 throw new IllegalArgumentException("Illegal material type: "+type);
161 for (Material m: db) {
162 if (m.getName().equalsIgnoreCase(name) && MathUtil.equals(m.getDensity(), density)) {
166 return Material.newMaterial(type, name, density);
172 * Return all motor in the database matching a search criteria. Any search criteria that
173 * is null or NaN is ignored.
175 * @param type the motor type, or null.
176 * @param manufacturer the manufacturer, or null.
177 * @param designation the designation, or null.
178 * @param diameter the diameter, or NaN.
179 * @param length the length, or NaN.
180 * @return an array of all the matching motors.
182 public static Motor[] findMotors(Motor.Type type, String manufacturer, String designation, double diameter, double length) {
183 ArrayList<Motor> results = new ArrayList<Motor>();
185 for (Motor m: MOTOR) {
186 boolean match = true;
187 if (type != null && type != m.getMotorType())
189 else if (manufacturer != null && !manufacturer.equalsIgnoreCase(m.getManufacturer()))
191 else if (designation != null && !designation.equalsIgnoreCase(m.getDesignation()))
193 else if (!Double.isNaN(diameter) && (Math.abs(diameter - m.getDiameter()) > 0.0015))
195 else if (!Double.isNaN(length) && (Math.abs(length - m.getLength()) > 0.0015))
202 return results.toArray(new Motor[0]);