public class OpenRocketSaver extends RocketSaver {
private static final LogHelper log = Application.getLogger();
-
+
/**
* Divisor used in converting an integer version to the point-represented version.
* The integer version divided by this value is the major version and the remainder is
*/
public static final int FILE_VERSION_DIVISOR = 100;
-
+
private static final String OPENROCKET_CHARSET = "UTF-8";
private static final String METHOD_PACKAGE = "net.sf.openrocket.file.openrocket.savers";
private static final String METHOD_SUFFIX = "Saver";
-
+
// Estimated storage used by different portions
// These have been hand-estimated from saved files
private static final int BYTES_PER_COMPONENT_UNCOMPRESSED = 590;
private static final int BYTES_PER_DATAPOINT_UNCOMPRESSED = 350;
private static final int BYTES_PER_DATAPOINT_COMPRESSED = 100;
-
+
private int indent;
private Writer dest;
(fileVersion / FILE_VERSION_DIVISOR) + "." + (fileVersion % FILE_VERSION_DIVISOR);
log.debug("Storing file version " + fileVersionString);
-
+
this.indent = 0;
-
+
writeln("<?xml version='1.0' encoding='utf-8'?>");
writeln("<openrocket version=\"" + fileVersionString + "\" creator=\"OpenRocket "
+ BuildProperties.getVersion() + "\">");
}
-
+
@Override
public long estimateFileSize(OpenRocketDocument doc, StorageOptions options) {
else
size += componentCount * BYTES_PER_COMPONENT_UNCOMPRESSED;
-
+
// Size per simulation
if (options.isCompressionEnabled())
size += doc.getSimulationCount() * BYTES_PER_SIMULATION_COMPRESSED;
else
size += doc.getSimulationCount() * BYTES_PER_SIMULATION_UNCOMPRESSED;
-
+
// Size per flight data point
int pointCount = 0;
double timeSkip = options.getSimulationTimeSkip();
*/
private int calculateNecessaryFileVersion(OpenRocketDocument document, StorageOptions opts) {
/*
- * File version 1.2 is required for:
+ * File version 1.4 is required for:
+ * - saving simulation data
* - saving motor data
*
* File version 1.1 is required for:
*
* Otherwise use version 1.0.
*/
-
- // Check if design has simulations defined (version 1.3)
+
+ // Check if design has simulations defined (version 1.4)
if (document.getSimulationCount() > 0) {
- return FILE_VERSION_DIVISOR + 3;
+ return FILE_VERSION_DIVISOR + 4;
}
- // Check for motor definitions (version 1.2)
+ // Check for motor definitions (version 1.4)
Iterator<RocketComponent> iterator = document.getRocket().iterator();
while (iterator.hasNext()) {
RocketComponent c = iterator.next();
MotorMount mount = (MotorMount) c;
for (String id : document.getRocket().getMotorConfigurationIDs()) {
if (mount.getMotor(id) != null) {
- return FILE_VERSION_DIVISOR + 2;
+ return FILE_VERSION_DIVISOR + 4;
}
}
}
}
-
+
@SuppressWarnings("unchecked")
private void saveComponent(RocketComponent component) throws IOException {
indent--;
writeln("</conditions>");
-
+
for (String s : simulation.getSimulationListeners()) {
writeElement("listener", escapeXML(s));
}
-
+
// Write basic simulation data
FlightData data = simulation.getSimulatedData();
}
-
+
private void saveFlightDataBranch(FlightDataBranch branch, double timeSkip)
throws IOException {
double previousTime = -100000;
}
-
+
/* TODO: LOW: This is largely duplicated from above! */
private int countFlightDataBranchPoints(FlightDataBranch branch, double timeSkip) {
int count = 0;
}
-
+
private void writeDataPointString(List<List<Double>> data, int index, StringBuilder sb)
throws IOException {
sb.setLength(0);
}
-
+
private void writeElement(String element, Object content) throws IOException {
if (content == null)
content = "";
}
-
+
private void writeln(String str) throws IOException {
if (str.length() == 0) {
dest.write("\n");
}
-
-
+
+
/**
* Return the XML equivalent of an enum name.
*