1 package net.sf.openrocket.database;
3 import net.sf.openrocket.logging.LogHelper;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.material.MaterialStorage;
6 import net.sf.openrocket.startup.Application;
7 import net.sf.openrocket.util.MathUtil;
11 * A class that contains single instances of {@link Database} for specific purposes.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public class Databases {
16 private static final LogHelper log = Application.getLogger();
18 /* Static implementations of specific databases: */
21 * A database of bulk materials (with bulk densities).
23 public static final Database<Material> BULK_MATERIAL = new Database<Material>();
25 * A database of surface materials (with surface densities).
27 public static final Database<Material> SURFACE_MATERIAL = new Database<Material>();
29 * A database of linear material (with length densities).
31 public static final Database<Material> LINE_MATERIAL = new Database<Material>();
37 // Add default materials
38 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Acrylic", 1190));
39 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Aluminum", 2700));
40 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Balsa", 170));
41 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Basswood", 500));
42 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Birch", 670));
43 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Brass", 8600));
44 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cardboard", 680));
45 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Carbonfiber", 1780));
46 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cork", 240));
47 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"DepronXPS", 40));
48 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Fiberglass", 1850));
49 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Kraftphenolic", 950));
50 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Maple", 755));
51 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Paperoffice", 820));
52 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Pine", 530));
53 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Plywoodbirch", 630));
54 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PolycarbonateLexan", 1200));
55 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Polystyrene", 1050));
56 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PVC", 1390));
57 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Spruce", 450));
58 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Steel", 7850));
59 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamgenericEPS", 20));
60 // BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Styrofoam (Blue foam, XPS)", 32));
61 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamBluefoamXPS", 32));
62 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Titanium", 4500));
63 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Quantumtubing", 1050));
64 BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"BlueTube", 1300));
66 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Ripstopnylon", 0.067));
67 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Mylar", 0.021));
68 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethylenethin", 0.015));
69 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethyleneheavy", 0.040));
70 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Silk", 0.060));
71 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Paperoffice", 0.080));
72 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Cellophane", 0.018));
73 SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Crepepaper", 0.025));
75 //// Thread (heavy-duty)
76 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Threadheavy-duty", 0.0003));
77 //// Elastic cord (round 2mm, 1/16 in)
78 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordround2mm", 0.0018));
79 //// Elastic cord (flat 6mm, 1/4 in)
80 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat6mm", 0.0043));
81 //// Elastic cord (flat 12mm, 1/2 in)
82 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat12mm", 0.008));
83 //// Elastic cord (flat 19mm, 3/4 in)
84 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat19mm", 0.0012));
85 //// Elastic cord (flat 25mm, 1 in)
86 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat25mm", 0.0016));
87 //// Braided nylon (2 mm, 1/16 in)
88 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon2mm", 0.001));
89 //// Braided nylon (3 mm, 1/8 in)
90 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon3mm", 0.0035));
91 //// Tubular nylon (11 mm, 7/16 in)
92 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon11mm", 0.013));
93 //// Tubular nylon (14 mm, 9/16 in)
94 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon14mm", 0.016));
95 //// Tubular nylon (25 mm, 1 in)
96 LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon25mm", 0.029));
99 // Add user-defined materials
100 for (Material m : Application.getPreferences().getUserMaterials()) {
101 switch (m.getType()) {
103 LINE_MATERIAL.add(m);
107 SURFACE_MATERIAL.add(m);
111 BULK_MATERIAL.add(m);
115 log.warn("ERROR: Unknown material type " + m);
119 // Add database storage listener
120 MaterialStorage listener = new MaterialStorage();
121 LINE_MATERIAL.addDatabaseListener(listener);
122 SURFACE_MATERIAL.addDatabaseListener(listener);
123 BULK_MATERIAL.addDatabaseListener(listener);
128 * Used just for ensuring initialization of the class.
130 public static void fakeMethod() {
136 * Find a material from the database with the specified type and name. Returns
137 * <code>null</code> if the specified material could not be found.
139 * @param type the material type.
140 * @param name the material name in the database.
141 * @return the material, or <code>null</code> if not found.
143 public static Material findMaterial(Material.Type type, String name) {
144 Database<Material> db;
150 db = SURFACE_MATERIAL;
156 throw new IllegalArgumentException("Illegal material type: " + type);
159 for (Material m : db) {
160 if (m.getName().equalsIgnoreCase(name)) {
169 * Find a material from the database or return a new user defined material if the specified
170 * material with the specified density is not found.
172 * @param type the material type.
173 * @param name the material name.
174 * @param density the density of the material.
175 * @return the material object from the database or a new material.
177 public static Material findMaterial(Material.Type type, String key, String name, double density) {
178 Database<Material> db;
184 db = SURFACE_MATERIAL;
190 throw new IllegalArgumentException("Illegal material type: " + type);
193 Material bestMatch = null;
195 // Alter the search mechanism to handle older specifications.
196 // If a key is specified, then we match on key, if one is found.
197 // Otherwise we return the material which matches on name.
198 // this requires us to loop through the entire db at least once to look for the key.
199 for (Material m : db) {
200 // perfect match based on key.
201 if ( key != null && m.getKey().equals(key) && MathUtil.equals(m.getDensity(), density) ) {
204 if (m.getName().equalsIgnoreCase(name) && MathUtil.equals(m.getDensity(), density)) {
208 if ( bestMatch != null ) {
211 return Material.newUserMaterial(type, name, density);