Add Dave Cook's parts database as a git submodule, in a directory called swing/swing/resources-src/datafiles/components/

Move old rocksim-based database from .../presets to .../legacy_components
Move rocksim .csv files from .../rocksim_components to .../rocksim_src
Modify BaseComponentDTO to process units
Modify SerializePresets to take a set of directories containing .orc files
as command-line arguments, and process all of them.
Modify swing/build.xml to specify both legacy and new databases for import
This commit is contained in:
JoePfeiffer 2022-01-18 14:50:30 -07:00
parent 7fdd0ed5c7
commit 71202abfdc
80 changed files with 44 additions and 22 deletions

View File

@ -228,14 +228,16 @@ public abstract class BaseComponentDTO {
static class AnnotatedLengthDTO {
@XmlAttribute(name = "Unit", required = false)
private final String unitName = "m";
private final String unitName;
@XmlValue
private double length;
AnnotatedLengthDTO() {
this.unitName = "m";
}
AnnotatedLengthDTO(double length) {
this.unitName = "m";
this.length = length;
}
@ -246,14 +248,16 @@ public abstract class BaseComponentDTO {
static class AnnotatedMassDTO {
@XmlAttribute(name = "Unit", required = false)
private final String unitName = "kg";
private final String unitName;
@XmlValue
private double mass;
AnnotatedMassDTO() {
unitName = "kg";
}
AnnotatedMassDTO(double mass) {
unitName = "kg";
this.mass = mass;
}

View File

@ -125,11 +125,13 @@
</target>
<target name="serialize-presets" depends="build" description="Preprocess the orc preset files into serialized form">
<java classname="net.sf.openrocket.utils.SerializePresets"
fork="true"
classpathref="run-classpath"
failonerror="true">
</java>
<java classname="net.sf.openrocket.utils.SerializePresets"
fork="true"
classpathref="run-classpath"
failonerror="true">
<arg value="resources-src/datafiles/legacy_components"/>
<arg value="resources-src/datafiles/components/orc"/>
</java>
</target>
<!-- CONVERT vendor csv to ORC files -->
@ -138,7 +140,7 @@
<attribute name="vendor"/>
<sequential>
<echo>Generating ORC file for vendor @{vendor}</echo>
<java classname="net.sf.openrocket.preset.loader.RocksimComponentFileTranslator"
<java classname="net.sf.openrocket.utils.RocksimComponentFileTranslator"
fork="true"
classpathref="run-classpath"
failonerror="true">

View File

@ -17,6 +17,11 @@ import net.sf.openrocket.preset.xml.OpenRocketComponentLoader;
import net.sf.openrocket.util.Pair;
public class SerializePresets extends BasicApplication {
private static void printUsage() {
System.err.println("SerializePresets <dir> ... ");
System.err.println("<dir> (may be repeated) is base directory for a set of .orc preset files");
}
/**
* @param args
@ -26,25 +31,36 @@ public class SerializePresets extends BasicApplication {
SerializePresets app = new SerializePresets();
app.initializeApplication();
if (args.length < 1) {
printUsage();
throw new IllegalArgumentException("Invalid Command Line Params");
}
Locale.setDefault(Locale.ENGLISH);
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase();
FileIterator iterator = DirectoryIterator.findDirectory("resources-src/datafiles/presets", new SimpleFileFilter("", false, "orc"));
if (iterator == null) {
throw new RuntimeException("Can't find resources-src/presets directory");
}
while (iterator.hasNext()) {
Pair<String, InputStream> f = iterator.next();
String fileName = f.getU();
InputStream is = f.getV();
for (int i = 0; i < args.length; i++) {
System.err.println("Processing .orc files in directory " + args[i]);
OpenRocketComponentLoader loader = new OpenRocketComponentLoader();
Collection<ComponentPreset> presets = loader.load(is, fileName);
componentPresetDao.addAll(presets);
FileIterator iterator = DirectoryIterator.findDirectory(args[i], new SimpleFileFilter("", false, "orc"));
if (iterator == null) {
throw new RuntimeException("Can't find " + args[i] + " directory");
}
while (iterator.hasNext()) {
Pair<String, InputStream> f = iterator.next();
String fileName = f.getU();
InputStream is = f.getV();
OpenRocketComponentLoader loader = new OpenRocketComponentLoader();
Collection<ComponentPreset> presets = loader.load(is, fileName);
componentPresetDao.addAll(presets);
}
}
List<ComponentPreset> list = componentPresetDao.listAll();