Only write back through version 1.6. Added test motor to support

OpenRocketSaverTest.
This commit is contained in:
Kevin Ruland 2015-12-14 21:40:51 -06:00
parent b998bd30c5
commit d840f302ba
2 changed files with 12 additions and 195 deletions

View File

@ -282,127 +282,13 @@ public class OpenRocketSaver extends RocketSaver {
}
}
/////////////////
// Version 1.6 //
/////////////////
// OpenRocket only writes back to 1.6 now.
return FILE_VERSION_DIVISOR + 6;
// Search the rocket for any Appearances or non-motor flight configurations (version 1.6)
for (RocketComponent c : document.getRocket()) {
if (c.getAppearance() != null) {
return FILE_VERSION_DIVISOR + 6;
}
if (c instanceof FlightConfigurableComponent) {
if (c instanceof MotorMount) {
MotorMount mmt = (MotorMount) c;
if (mmt.getMotorCount() > 0) {
return FILE_VERSION_DIVISOR + 6;
}
}
if (c instanceof RecoveryDevice) {
RecoveryDevice recovery = (RecoveryDevice) c;
if (recovery.getDeploymentConfigurations().size() > 0) {
return FILE_VERSION_DIVISOR + 6;
}
}
if (c instanceof AxialStage) {
AxialStage stage = (AxialStage) c;
if (stage.getSeparationConfigurations().size() > 0) {
return FILE_VERSION_DIVISOR + 6;
}
}
}
}
/////////////////
// Version 1.5 //
/////////////////
// Search the rocket for any ComponentPresets (version 1.5)
for (RocketComponent c : document.getRocket()) {
if (c.getPresetComponent() != null) {
return FILE_VERSION_DIVISOR + 5;
}
}
// Search for recovery device deployment type LOWER_STAGE_SEPARATION (version 1.5)
for (RocketComponent c : document.getRocket()) {
if (c instanceof RecoveryDevice) {
if (((RecoveryDevice) c).getDeploymentConfigurations().getDefault().getDeployEvent() == DeployEvent.LOWER_STAGE_SEPARATION) {
return FILE_VERSION_DIVISOR + 5;
}
}
}
// Check for custom expressions (version 1.5)
if (!document.getCustomExpressions().isEmpty()) {
return FILE_VERSION_DIVISOR + 5;
}
/////////////////
// Version 1.4 //
/////////////////
// Check if design has simulations defined (version 1.4)
if (document.getSimulationCount() > 0) {
return FILE_VERSION_DIVISOR + 4;
}
// Check for motor definitions (version 1.4)
for (RocketComponent c : document.getRocket()) {
if (!(c instanceof MotorMount))
continue;
MotorMount mount = (MotorMount) c;
for( FlightConfiguration config : document.getRocket().getConfigSet()) {
FlightConfigurationID fcid = config.getFlightConfigurationID();
if (mount.getMotorInstance(fcid) != null) {
return FILE_VERSION_DIVISOR + 4;
}
}
}
/////////////////
// Version 1.3 //
/////////////////
// no version 1.3 file type exists
/////////////////
// Version 1.2 //
/////////////////
// no version 1.2 file type exists
/////////////////
// Version 1.1 //
/////////////////
// Check for fin tabs or tube coupler children (version 1.1)
for (RocketComponent c : document.getRocket()) {
// Check for fin tabs
if (c instanceof FinSet) {
FinSet fin = (FinSet) c;
if (!MathUtil.equals(fin.getTabHeight(), 0) &&
!MathUtil.equals(fin.getTabLength(), 0)) {
return FILE_VERSION_DIVISOR + 1;
}
}
// Check for components attached to tube coupler
if (c instanceof TubeCoupler) {
if (c.getChildCount() > 0) {
return FILE_VERSION_DIVISOR + 1;
}
}
}
/////////////////
// Version 1.0 //
/////////////////
// Default (version 1.0)
return FILE_VERSION_DIVISOR + 0;
}

View File

@ -25,12 +25,14 @@ import net.sf.openrocket.file.RocketLoadException;
import net.sf.openrocket.file.motor.GeneralMotorLoader;
import net.sf.openrocket.l10n.DebugTranslator;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.plugin.PluginModule;
import net.sf.openrocket.simulation.extension.impl.ScriptingExtension;
import net.sf.openrocket.simulation.extension.impl.ScriptingUtil;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.TestRockets;
import org.junit.After;
@ -190,82 +192,6 @@ public class OpenRocketSaverTest {
}
////////////////////////////////
// Tests for File Version 1.0 //
////////////////////////////////
@Test
public void testFileVersion100() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v100();
assertEquals(100, getCalculatedFileVersion(rocketDoc));
}
////////////////////////////////
// Tests for File Version 1.1 //
////////////////////////////////
@Test
public void testFileVersion101_withFinTabs() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v101_withFinTabs();
assertEquals(101, getCalculatedFileVersion(rocketDoc));
}
@Test
public void testFileVersion101_withTubeCouplerChild() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v101_withTubeCouplerChild();
assertEquals(101, getCalculatedFileVersion(rocketDoc));
}
////////////////////////////////
// Tests for File Version 1.2 //
////////////////////////////////
// no version 1.2 file type exists
////////////////////////////////
// Tests for File Version 1.3 //
////////////////////////////////
// no version 1.3 file type exists
////////////////////////////////
// Tests for File Version 1.4 //
////////////////////////////////
@Test
public void testFileVersion104_withSimulationData() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v104_withSimulationData();
assertEquals(104, getCalculatedFileVersion(rocketDoc));
}
@Test
public void testFileVersion104_withMotor() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v104_withMotor();
assertEquals(104, getCalculatedFileVersion(rocketDoc));
}
////////////////////////////////
// Tests for File Version 1.5 //
////////////////////////////////
@Test
public void testFileVersion105_withComponentPresets() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v105_withComponentPreset();
assertEquals(105, getCalculatedFileVersion(rocketDoc));
}
@Test
public void testFileVersion105_withCustomExpressions() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v105_withCustomExpression();
assertEquals(105, getCalculatedFileVersion(rocketDoc));
}
@Test
public void testFileVersion105_withLowerStageRecoveryDevice() {
OpenRocketDocument rocketDoc = TestRockets.makeTestRocket_v105_withLowerStageRecoveryDevice();
assertEquals(105, getCalculatedFileVersion(rocketDoc));
}
////////////////////////////////
// Tests for File Version 1.6 //
////////////////////////////////
@ -384,8 +310,13 @@ public class OpenRocketSaverTest {
public MotorDbProvider() {
db.addMotor(readMotor());
assertEquals(1, db.getMotorSets().size());
db.addMotor( new ThrustCurveMotor(
Manufacturer.getManufacturer("A"),
"F12X", "Desc", Motor.Type.UNKNOWN, new double[] {},
0.024, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 },
new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL }, "digestA"));
assertEquals(2, db.getMotorSets().size());
}
@Override