Added persistence of RecoveryDevice DeploymentConfiguration in ork
files.
This commit is contained in:
parent
e364c10026
commit
dfd36f5374
@ -35,6 +35,7 @@ import net.sf.openrocket.rocketcomponent.Bulkhead;
|
|||||||
import net.sf.openrocket.rocketcomponent.CenteringRing;
|
import net.sf.openrocket.rocketcomponent.CenteringRing;
|
||||||
import net.sf.openrocket.rocketcomponent.ClusterConfiguration;
|
import net.sf.openrocket.rocketcomponent.ClusterConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.Clusterable;
|
import net.sf.openrocket.rocketcomponent.Clusterable;
|
||||||
|
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
|
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
|
||||||
import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
|
import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
|
||||||
import net.sf.openrocket.rocketcomponent.EngineBlock;
|
import net.sf.openrocket.rocketcomponent.EngineBlock;
|
||||||
@ -876,6 +877,13 @@ class ComponentParameterHandler extends AbstractElementHandler {
|
|||||||
}
|
}
|
||||||
return new MotorConfigurationHandler((Rocket) component, context);
|
return new MotorConfigurationHandler((Rocket) component, context);
|
||||||
}
|
}
|
||||||
|
if ( element.equals("deploymentconfiguration")) {
|
||||||
|
if ( !(component instanceof RecoveryDevice) ) {
|
||||||
|
warnings.add(Warning.fromString("Illegal component defined as recovery device."));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new DeploymentConfigurationHandler( (RecoveryDevice) component, context );
|
||||||
|
}
|
||||||
|
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
@ -885,7 +893,8 @@ class ComponentParameterHandler extends AbstractElementHandler {
|
|||||||
String content, WarningSet warnings) {
|
String content, WarningSet warnings) {
|
||||||
|
|
||||||
if (element.equals("subcomponents") || element.equals("motormount") ||
|
if (element.equals("subcomponents") || element.equals("motormount") ||
|
||||||
element.equals("finpoints") || element.equals("motorconfiguration")) {
|
element.equals("finpoints") || element.equals("motorconfiguration") ||
|
||||||
|
element.equals("deploymentconfiguration")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1257,7 +1266,56 @@ class MotorHandler extends AbstractElementHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeploymentConfigurationHandler extends AbstractElementHandler {
|
||||||
|
private final DocumentLoadingContext context;
|
||||||
|
private final RecoveryDevice recoveryDevice;
|
||||||
|
private DeploymentConfiguration config;
|
||||||
|
private String configId;
|
||||||
|
|
||||||
|
public DeploymentConfigurationHandler( RecoveryDevice recoveryDevice, DocumentLoadingContext context ) {
|
||||||
|
this.recoveryDevice = recoveryDevice;
|
||||||
|
this.context = context;
|
||||||
|
config = new DeploymentConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
|
||||||
|
throws SAXException {
|
||||||
|
return PlainTextHandler.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeElement(String element, HashMap<String, String> attributes, String content,
|
||||||
|
WarningSet warnings) throws SAXException {
|
||||||
|
|
||||||
|
content = content.trim();
|
||||||
|
|
||||||
|
if ( "deployevent".equals(element) ) {
|
||||||
|
DeployEvent type = (DeployEvent) DocumentConfig.findEnum(content, DeployEvent.class);
|
||||||
|
if ( type == null ) {
|
||||||
|
warnings.add(Warning.FILE_INVALID_PARAMETER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
config.setDeployEvent( type );
|
||||||
|
return;
|
||||||
|
} else if ( "deployaltitude".equals(element) ) {
|
||||||
|
config.setDeployAltitude( Double.parseDouble(content));
|
||||||
|
return;
|
||||||
|
} else if ( "deploydelay".equals(element) ) {
|
||||||
|
config.setDeployDelay( Double.parseDouble(content));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.closeElement(element, attributes, content, warnings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endHandler(String element, HashMap<String, String> attributes, String content, WarningSet warnings) throws SAXException {
|
||||||
|
String configId = attributes.get("configid");
|
||||||
|
recoveryDevice.setFlightConfiguration(configId, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class SimulationsHandler extends AbstractElementHandler {
|
class SimulationsHandler extends AbstractElementHandler {
|
||||||
private final DocumentLoadingContext context;
|
private final DocumentLoadingContext context;
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package net.sf.openrocket.file.openrocket.savers;
|
package net.sf.openrocket.file.openrocket.savers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
||||||
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
|
|
||||||
|
|
||||||
public class RecoveryDeviceSaver extends MassObjectSaver {
|
public class RecoveryDeviceSaver extends MassObjectSaver {
|
||||||
@ -19,12 +22,37 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
|
|||||||
else
|
else
|
||||||
elements.add("<cd>" + dev.getCD() + "</cd>");
|
elements.add("<cd>" + dev.getCD() + "</cd>");
|
||||||
|
|
||||||
elements.add("<deployevent>" + dev.getDefaultDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</deployevent>");
|
DeploymentConfiguration defaultConfig = dev.getDefaultFlightConfiguration();
|
||||||
elements.add("<deployaltitude>" + dev.getDefaultDeployAltitude() + "</deployaltitude>");
|
elements.addAll( deploymentConfiguration(defaultConfig, false));
|
||||||
elements.add("<deploydelay>" + dev.getDefaultDeployDelay() + "</deploydelay>");
|
|
||||||
elements.add(materialParam(dev.getMaterial()));
|
elements.add(materialParam(dev.getMaterial()));
|
||||||
|
|
||||||
// FIXME - add mapping.
|
Rocket rocket = c.getRocket();
|
||||||
|
// Note - getFlightConfigurationIDs returns at least one element. The first element
|
||||||
|
// is null and means "default".
|
||||||
|
String[] configs = rocket.getFlightConfigurationIDs();
|
||||||
|
if ( configs.length > 1 ) {
|
||||||
|
|
||||||
|
for( String id : configs ) {
|
||||||
|
if ( id == null ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DeploymentConfiguration config = dev.getFlightConfiguration(id);
|
||||||
|
if ( config == null ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
elements.add("<deploymentconfiguration configid=\"" + id + "\">");
|
||||||
|
elements.addAll( deploymentConfiguration(config, true) );
|
||||||
|
elements.add("</deploymentconfiguration>");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> deploymentConfiguration( DeploymentConfiguration config, boolean indent ) {
|
||||||
|
List<String> elements = new ArrayList<String>(3);
|
||||||
|
elements.add((indent?" ": "") + "<deployevent>" + config.getDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</deployevent>");
|
||||||
|
elements.add((indent?" ": "") + "<deployaltitude>" + config.getDeployAltitude() + "</deployaltitude>");
|
||||||
|
elements.add((indent?" ": "") + "<deploydelay>" + config.getDeployDelay() + "</deploydelay>");
|
||||||
|
return elements;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user