Added persistence of RecoveryDevice DeploymentConfiguration in ork

files.
This commit is contained in:
kruland2607 2012-10-17 15:29:19 -05:00
parent e364c10026
commit dfd36f5374
2 changed files with 97 additions and 11 deletions

View File

@ -35,6 +35,7 @@ import net.sf.openrocket.rocketcomponent.Bulkhead;
import net.sf.openrocket.rocketcomponent.CenteringRing;
import net.sf.openrocket.rocketcomponent.ClusterConfiguration;
import net.sf.openrocket.rocketcomponent.Clusterable;
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
import net.sf.openrocket.rocketcomponent.EngineBlock;
@ -876,6 +877,13 @@ class ComponentParameterHandler extends AbstractElementHandler {
}
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;
}
@ -885,7 +893,8 @@ class ComponentParameterHandler extends AbstractElementHandler {
String content, WarningSet warnings) {
if (element.equals("subcomponents") || element.equals("motormount") ||
element.equals("finpoints") || element.equals("motorconfiguration")) {
element.equals("finpoints") || element.equals("motorconfiguration") ||
element.equals("deploymentconfiguration")) {
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 {
private final DocumentLoadingContext context;

View File

@ -1,30 +1,58 @@
package net.sf.openrocket.file.openrocket.savers;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.Rocket;
public class RecoveryDeviceSaver extends MassObjectSaver {
@Override
protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> elements) {
super.addParams(c, elements);
RecoveryDevice dev = (RecoveryDevice) c;
if (dev.isCDAutomatic())
elements.add("<cd>auto</cd>");
else
elements.add("<cd>" + dev.getCD() + "</cd>");
elements.add("<deployevent>" + dev.getDefaultDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</deployevent>");
elements.add("<deployaltitude>" + dev.getDefaultDeployAltitude() + "</deployaltitude>");
elements.add("<deploydelay>" + dev.getDefaultDeployDelay() + "</deploydelay>");
DeploymentConfiguration defaultConfig = dev.getDefaultFlightConfiguration();
elements.addAll( deploymentConfiguration(defaultConfig, false));
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;
}
}