create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / loader / RocksimComponentFileType.java
1 package net.sf.openrocket.preset.loader;
2
3 import java.util.Arrays;
4
5 /**
6  * Definition of the typical Rocksim component files and their formats.
7  */
8 public enum RocksimComponentFileType {
9     BODY_TUBE("BTDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material", "Engine"),
10     BULKHEAD("BHDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material", "Engine", "Engine",
11             "Engine", "Engine", "Engine", "Engine", "Engine", "Engine", "Engine", "Engine", "Engine"),
12     CENTERING_RING("CRDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material", "AutoSize"),
13     CUSTOM_FIN("CSDATA.CSV"),
14     ENGINE_BLOCK("EBDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material", "CG", "Mass Units", "Mass", "AutoSize"),
15     FIN("FSDATA.CSV"),
16     LAUNCH_LUG("LLDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material"),
17     MASS_OBJECT("MODATA.CSV", "Mfg.", "Part no", "Desc", "Units", "Name", "Type", "Length", "Material", "Mass units", "Mass"),
18     MATERIAL("MATERIAL.CSV", "Material Name", "Units", "Density", "Low", "High", "Class", "Rocketry Use", "Body Tubes",
19             "Fin Sets", "Launch Lugs", "Cords", "Nose", "Chute", "Stream", "Trans", "Ring", "Bulkhead", "Engine Block", "Sleeve",
20             "Tube Coupler", "spare", "spare", "spare", "spare", "spare", "spare", "spare", "Known Dim type", "Known Dim Units", "Known Dim Value"),
21     NOSE_CONE("NCDATA.CSV", "Mfg.","Part No.","Desc.","Units","Length","Outer Dia","L/D Ratio","Insert Length","Insert OD",
22             "Thickness","Shape","Config","Material","CG Loc","Mass Units","Mass","Base Ext. Len"),
23     PARACHUTE("PCDATA.CSV"),
24     SLEEVE("SLDATA.CSV"),
25     STREAMER("STDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "Length", "Width", "Thickness", "Count", "Material"),
26     TUBE_COUPLER("TCDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "ID", "OD", "Length", "Material", "Mass Units", "CG", "Mass", "AutoSize"),
27     TRANSITION("TRDATA.CSV", "Mfg.", "Part No.", "Desc.", "Units", "Front Insert Len", "Front Insert OD", "Front OD", "Length",
28             "Rear OD", "Core Dia.", "Rear Insert Len", "Rear Insert OD", "Thickness", "Config", "Material", "CG Loc",
29             "Mass Units", "Mass", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape", "Shape");
30
31     /**
32      * The default filename for the type of data.
33      */
34     private final String defaultFileName;
35
36     /**
37      * The column names.
38      */
39     private final String[] columns;
40
41     /**
42      * Constructor.
43      *
44      * @param theDefaultFileName  the default filename
45      * @param theColumns the array of column names in the file
46      */
47     private RocksimComponentFileType(final String theDefaultFileName, String... theColumns) {
48         defaultFileName = theDefaultFileName;
49         columns = theColumns;
50     }
51
52     /**
53      * Get the typical file name used for this type of component data.
54      *
55      * @return a filename
56      */
57     public String getDefaultFileName() {
58         return defaultFileName;
59     }
60
61     /**
62      * Try to be omniscient and figure out what kind of data file it is given an array of header (column) names.
63      *
64      * @param headers an array of column names
65      * @return the data type of the file, or null if unable to match the header names
66      */
67     public static RocksimComponentFileType determineType(String[] headers) {
68         RocksimComponentFileType[] types = values();
69         for (int i = 0; i < types.length; i++) {
70             RocksimComponentFileType type = types[i];
71             if (Arrays.equals(headers, type.columns)) {
72                 return type;
73             }
74         }
75         return null;
76     }
77 }