[#1687] Save stage activeness to design file
This commit is contained in:
parent
3d3c32b3c9
commit
1f826ed141
@ -20,6 +20,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
private final Rocket rocket;
|
||||
private String name = null;
|
||||
private boolean inNameElement = false;
|
||||
private HashMap<Integer, Boolean> stageActiveness = new HashMap<>();
|
||||
|
||||
public MotorConfigurationHandler(Rocket rocket, DocumentLoadingContext context) {
|
||||
this.rocket = rocket;
|
||||
@ -30,11 +31,13 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
||||
WarningSet warnings) {
|
||||
|
||||
if (inNameElement || !element.equals("name")) {
|
||||
if ((inNameElement && element.equals("name")) || !(element.equals("name") || element.equals("stage"))) {
|
||||
warnings.add(Warning.FILE_INVALID_PARAMETER);
|
||||
return null;
|
||||
}
|
||||
inNameElement = true;
|
||||
if (element.equals("name")) {
|
||||
inNameElement = true;
|
||||
}
|
||||
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
@ -42,7 +45,13 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
@Override
|
||||
public void closeElement(String element, HashMap<String, String> attributes,
|
||||
String content, WarningSet warnings) {
|
||||
name = content;
|
||||
if (element.equals("name")) {
|
||||
name = content;
|
||||
} else if (element.equals("stage")) {
|
||||
int stageNr = Integer.parseInt(attributes.get("number"));
|
||||
boolean isActive = Boolean.parseBoolean(attributes.get("active"));
|
||||
stageActiveness.put(stageNr, isActive);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,7 +69,11 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
if (name != null && name.trim().length() > 0) {
|
||||
rocket.getFlightConfiguration(fcid).setName(name);
|
||||
}
|
||||
|
||||
|
||||
for (int stageNr : stageActiveness.keySet()) {
|
||||
rocket.getFlightConfiguration(fcid).preloadStageActiveness(stageNr, stageActiveness.get(stageNr));
|
||||
}
|
||||
|
||||
if ("true".equals(attributes.remove("default"))) {
|
||||
rocket.setSelectedConfiguration( fcid);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.InputSource;
|
||||
@ -53,7 +54,10 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
throw new RocketLoadException("Malformed XML in input.", e);
|
||||
}
|
||||
|
||||
doc.getSelectedConfiguration().setAllStages();
|
||||
// load the stage activeness
|
||||
for (FlightConfiguration config : doc.getRocket().getFlightConfigurations()) {
|
||||
config.applyPreloadedStageActiveness();
|
||||
}
|
||||
|
||||
// Deduce suitable time skip
|
||||
double timeSkip = StorageOptions.SIMULATION_DATA_NONE;
|
||||
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.file.openrocket.OpenRocketSaver;
|
||||
import net.sf.openrocket.rocketcomponent.AxialStage;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
||||
@ -53,15 +55,23 @@ public class RocketSaver extends RocketComponentSaver {
|
||||
if ( rocket.getSelectedConfiguration().equals( flightConfig )){
|
||||
str += " default=\"true\"";
|
||||
}
|
||||
|
||||
|
||||
// close motorconfiguration opening tag
|
||||
str += ">";
|
||||
elements.add(str);
|
||||
|
||||
// flight configuration name
|
||||
if (flightConfig.isNameOverridden()){
|
||||
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getNameRaw())
|
||||
+ "</name></motorconfiguration>";
|
||||
} else {
|
||||
str += "/>";
|
||||
elements.add(OpenRocketSaver.INDENT + "<name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getNameRaw())
|
||||
+ "</name>");
|
||||
}
|
||||
// stage activeness
|
||||
for (AxialStage stage : rocket.getStageList()) {
|
||||
elements.add(OpenRocketSaver.INDENT + "<stage number=\"" + stage.getStageNumber() + "\"" +
|
||||
" active=\"" + flightConfig.isStageActive(stage.getStageNumber()) + "\"/>");
|
||||
}
|
||||
|
||||
elements.add(str);
|
||||
elements.add("</motorconfiguration>");
|
||||
}
|
||||
|
||||
// Reference diameter
|
||||
|
@ -64,6 +64,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
/* Cached data */
|
||||
final protected Map<Integer, StageFlags> stages = new HashMap<>(); // Map of stage number to StageFlags of the corresponding stage
|
||||
final protected Map<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
|
||||
private Map<Integer, Boolean> preloadStageActiveness = null;
|
||||
final private Collection<MotorConfiguration> activeMotors = new ConcurrentLinkedQueue<MotorConfiguration>();
|
||||
final private InstanceMap activeInstances = new InstanceMap();
|
||||
|
||||
@ -276,6 +277,34 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
stages.get(stageNumber) != null && stages.get(stageNumber).active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload the stage activeness of a certain stage.
|
||||
* This method is to be used during the import and readout of an OpenRocket design file.
|
||||
* @param stageNumber stage number to preload the stage activeness for
|
||||
* @param isActive whether the stage should be active or not
|
||||
*/
|
||||
public void preloadStageActiveness(int stageNumber, boolean isActive) {
|
||||
if (this.preloadStageActiveness == null) {
|
||||
preloadStageActiveness = new HashMap<>();
|
||||
}
|
||||
this.preloadStageActiveness.put(stageNumber, isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies preloaded stage activeness.
|
||||
* This method should be called after the rocket has been loaded from a file.
|
||||
*/
|
||||
public void applyPreloadedStageActiveness() {
|
||||
if (preloadStageActiveness == null) {
|
||||
return;
|
||||
}
|
||||
for (int stageNumber : preloadStageActiveness.keySet()) {
|
||||
_setStageActive(stageNumber, preloadStageActiveness.get(stageNumber), false);
|
||||
}
|
||||
preloadStageActiveness.clear();
|
||||
preloadStageActiveness = null;
|
||||
}
|
||||
|
||||
public Collection<RocketComponent> getAllComponents() {
|
||||
List<RocketComponent> traversalOrder = new ArrayList<RocketComponent>();
|
||||
recurseAllComponentsDepthFirst(this.rocket,traversalOrder);
|
||||
@ -795,6 +824,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
// Note the stages are updated in the constructor call.
|
||||
FlightConfiguration clone = new FlightConfiguration( this.rocket, this.fcid );
|
||||
clone.setName(configurationName);
|
||||
clone.preloadStageActiveness = this.preloadStageActiveness == null ? null : new HashMap<>(this.preloadStageActiveness);
|
||||
|
||||
clone.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone();
|
||||
clone.cachedBounds = this.cachedBounds.clone();
|
||||
@ -824,6 +854,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
cloneMotor.getMount().setMotorConfig(cloneMotor, copyId);
|
||||
}
|
||||
|
||||
copy.preloadStageActiveness = this.preloadStageActiveness == null ? null : new HashMap<>(this.preloadStageActiveness);
|
||||
copy.cachedBoundsAerodynamic = this.cachedBoundsAerodynamic.clone();
|
||||
copy.cachedBounds = this.cachedBounds.clone();
|
||||
copy.modID = this.modID;
|
||||
|
@ -57,6 +57,7 @@ The following file format versions exist:
|
||||
Transitions, Inner Tubes, Launch Lugs, and Fins.
|
||||
Added PhotoStudio settings saving (<photostudio>)
|
||||
Added override CD parameter (<overridecd>)
|
||||
Added stage activeness remembrance (<stage> under <motorconfiguration>)
|
||||
Separated <overridesubcomponents> into individual parameters for mass, CG, and CD.
|
||||
Rename <fincount> to <instancecount> (<fincount> remains for backward compatibility)
|
||||
Rename <position> to <axialoffset> (<position> remains for backward compatibility)
|
||||
|
@ -154,7 +154,6 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
this.document = document;
|
||||
this.rocket = document.getRocket();
|
||||
this.rocket.getSelectedConfiguration().setAllStages();
|
||||
BasicFrame.lastFrameInstance = this;
|
||||
|
||||
// Create the component tree selection model that will be used
|
||||
|
Loading…
x
Reference in New Issue
Block a user