[Bugfix] .ORK I/O Bugfixes...
- Corrected FlightConfiguration, MotorConfiguration ID issues - output code no longer outputs extra FlightConfigurations - recovery Devices no longer print out FlightConfigurations w/o specific settings - Reverted Default Value for FlightConfigurationSet is just a member field - creates extraneous code when included in the map. - fixed corresponding display issues.
This commit is contained in:
parent
9551ddc0cb
commit
1719351a63
@ -10,7 +10,9 @@ import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
@ -61,7 +63,10 @@ class MotorConfigurationHandler extends AbstractElementHandler {
|
||||
}
|
||||
|
||||
if ("true".equals(attributes.remove("default"))) {
|
||||
rocket.getConfigurationSet().reset(fcid);
|
||||
// associate this configuration with both this FCID and the default.
|
||||
FlightConfigurationSet<FlightConfiguration> fcs = rocket.getConfigurationSet();
|
||||
FlightConfiguration fc = fcs.get(fcid);
|
||||
fcs.setDefault(fc);
|
||||
}
|
||||
|
||||
super.closeElement(element, attributes, content, warnings);
|
||||
|
@ -31,21 +31,22 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
|
||||
elements.addAll(deploymentConfiguration(defaultConfig, false));
|
||||
|
||||
Rocket rocket = c.getRocket();
|
||||
// Note - getFlightConfigurationIDs returns at least one element. The first element
|
||||
// is null and means "default".
|
||||
FlightConfigurationSet<FlightConfiguration> configList = rocket.getConfigurationSet();
|
||||
|
||||
if (configList.size() > 1) {
|
||||
// DEBUG
|
||||
//System.err.println("printing deployment info for: "+dev.getName());
|
||||
//dev.getDeploymentConfigurations().printDebug();
|
||||
// DEBUG
|
||||
|
||||
FlightConfigurationSet<FlightConfiguration> configList = rocket.getConfigurationSet();
|
||||
for (FlightConfigurationID fcid : configList.getSortedConfigurationIDs()) {
|
||||
//System.err.println("checking FlightConfiguration:"+fcid.getShortKey()+ " save?");
|
||||
|
||||
for (FlightConfiguration config : configList) {
|
||||
FlightConfigurationID fcid = config.getFlightConfigurationID();
|
||||
if (fcid == null) {
|
||||
continue;
|
||||
}
|
||||
if (dev.getDeploymentConfigurations().isDefault(fcid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dev.getDeploymentConfigurations().isDefault(fcid)) {
|
||||
//System.err.println(" >> skipping: fcid="+fcid.getShortKey());
|
||||
continue;
|
||||
}else if( dev.getDeploymentConfigurations().containsKey(fcid)){
|
||||
// only print configurations which override the default.
|
||||
//System.err.println(" >> printing data.");
|
||||
DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid);
|
||||
elements.add("<deploymentconfiguration configid=\"" + fcid.key + "\">");
|
||||
elements.addAll(deploymentConfiguration(deployConfig, true));
|
||||
|
@ -6,6 +6,7 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationSet;
|
||||
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
@ -42,23 +43,25 @@ public class RocketSaver extends RocketComponentSaver {
|
||||
|
||||
|
||||
// Motor configurations
|
||||
FlightConfigurationID defId = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||
for (FlightConfiguration flightConfig : rocket.getConfigurationSet()) {
|
||||
FlightConfigurationID fcid = flightConfig.getFlightConfigurationID();
|
||||
FlightConfigurationSet<FlightConfiguration> allConfigs = rocket.getConfigurationSet();
|
||||
for (FlightConfigurationID fcid : allConfigs.getSortedConfigurationIDs()) {
|
||||
FlightConfiguration flightConfig = allConfigs.get(fcid);
|
||||
if (fcid == null)
|
||||
continue;
|
||||
|
||||
String str = "<motorconfiguration configid=\"" + fcid.key + "\"";
|
||||
if (fcid.equals(defId))
|
||||
// if the configuration is the default, add the tag
|
||||
if ( allConfigs.isDefault( flightConfig )){
|
||||
str += " default=\"true\"";
|
||||
}
|
||||
|
||||
|
||||
if (rocket.getConfigurationSet().isDefault(flightConfig)) {
|
||||
str += "/>";
|
||||
} else {
|
||||
if (flightConfig.isNameOverridden()){
|
||||
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getName())
|
||||
+ "</name></motorconfiguration>";
|
||||
} else {
|
||||
str += "/>";
|
||||
}
|
||||
|
||||
elements.add(str);
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.fcid = _fcid;
|
||||
}
|
||||
this.rocket = rocket;
|
||||
this.setName( fcid.key);
|
||||
|
||||
this.overrideName = false;
|
||||
this.configurationName = "<WARN: attempt to access unset configurationName. WARN!> ";
|
||||
|
||||
updateStageMap();
|
||||
rocket.addComponentChangeListener(this);
|
||||
}
|
||||
@ -461,10 +462,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
|
||||
public void setName( final String newName) {
|
||||
if( this.getFlightConfigurationID().equals( FlightConfigurationID.DEFAULT_CONFIGURATION_FCID)){
|
||||
this.configurationName = FlightConfiguration.DEFAULT_CONFIGURATION_NAME;
|
||||
return;
|
||||
}else if( null == newName ){
|
||||
if( null == newName ){
|
||||
this.overrideName = false;
|
||||
}else if( "".equals(newName)){
|
||||
return;
|
||||
@ -477,11 +475,15 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.configurationName = newName;
|
||||
}
|
||||
|
||||
public boolean isNameOverridden(){
|
||||
return this.overrideName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if( overrideName ){
|
||||
return this.configurationName;
|
||||
}else{
|
||||
return " NYI - motor digest string";
|
||||
return fcid.key;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,12 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
|
||||
final public String key;
|
||||
|
||||
private final static String ERROR_CONFIGURATION_KEYTEXT = "error_key_2489";
|
||||
private final static String DEFAULT_CONFIGURATION_KEYTEXT = "default_configuration_6602";
|
||||
private final static String DEFAULT_VALUE_KEYTEXT = "default_value_5676";
|
||||
// private final static String DEFAULT_CONFIGURATION_KEYTEXT = "default_configuration_6602";
|
||||
// private final static String DEFAULT_VALUE_KEYTEXT = "default_value_5676";
|
||||
|
||||
public final static FlightConfigurationID ERROR_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.ERROR_CONFIGURATION_KEYTEXT);
|
||||
public final static FlightConfigurationID DEFAULT_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEYTEXT );
|
||||
public final static FlightConfigurationID DEFAULT_VALUE_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_VALUE_KEYTEXT );
|
||||
// public final static FlightConfigurationID DEFAULT_CONFIGURATION_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_CONFIGURATION_KEYTEXT );
|
||||
// public final static FlightConfigurationID DEFAULT_VALUE_FCID = new FlightConfigurationID( FlightConfigurationID.DEFAULT_VALUE_KEYTEXT );
|
||||
|
||||
public FlightConfigurationID() {
|
||||
this(UUID.randomUUID().toString());
|
||||
@ -52,6 +52,10 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
|
||||
return this.key.equals(otherFCID.key);
|
||||
}
|
||||
|
||||
public String getShortKey(){
|
||||
return this.key.substring(0,8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.key.hashCode();
|
||||
@ -72,15 +76,6 @@ public final class FlightConfigurationID implements Comparable<FlightConfigurati
|
||||
public int length() {
|
||||
return this.key.length();
|
||||
}
|
||||
|
||||
public String toShortKey(){
|
||||
if( this == DEFAULT_VALUE_FCID ){
|
||||
return "DEFVAL";
|
||||
}else if( this == FlightConfigurationID.DEFAULT_CONFIGURATION_FCID){
|
||||
return "DEFCONFIG";
|
||||
}
|
||||
return this.key.substring(0,8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -24,8 +23,8 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FlightConfigurationSet.class);
|
||||
protected final HashMap<FlightConfigurationID, E> map = new HashMap<FlightConfigurationID, E>();
|
||||
protected final static FlightConfigurationID DEFAULT_VALUE_FCID = FlightConfigurationID.DEFAULT_VALUE_FCID;
|
||||
|
||||
protected E defaultValue;
|
||||
protected final RocketComponent component;
|
||||
protected final int eventType;
|
||||
|
||||
@ -42,7 +41,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
this.component = component;
|
||||
this.eventType = eventType;
|
||||
|
||||
this.map.put( DEFAULT_VALUE_FCID, _defaultValue );
|
||||
this.defaultValue= _defaultValue;
|
||||
|
||||
addListener(_defaultValue);
|
||||
}
|
||||
@ -58,7 +57,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
this.component = component;
|
||||
this.eventType = eventType;
|
||||
|
||||
this.map.put( DEFAULT_VALUE_FCID, flightConfiguration.getDefault().clone());
|
||||
this.defaultValue= flightConfiguration.getDefault().clone();
|
||||
for (FlightConfigurationID key : flightConfiguration.map.keySet()) {
|
||||
this.map.put(key, flightConfiguration.map.get(key).clone());
|
||||
}
|
||||
@ -70,7 +69,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
|
||||
@Override
|
||||
public E getDefault(){
|
||||
return this.map.get(DEFAULT_VALUE_FCID);
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +80,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
if( this.isDefault(nextDefaultValue)){
|
||||
return;
|
||||
}
|
||||
this.set( DEFAULT_VALUE_FCID, nextDefaultValue);
|
||||
this.defaultValue = nextDefaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -127,16 +126,16 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
public List<FlightConfigurationID> getSortedConfigurationIDs(){
|
||||
Vector<FlightConfigurationID> toReturn = new Vector<FlightConfigurationID>();
|
||||
|
||||
toReturn.addAll( this.getIDs() );
|
||||
toReturn.addAll( this.map.keySet() );
|
||||
toReturn.sort( null );
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public Set<FlightConfigurationID> getIDs(){
|
||||
return this.map.keySet();
|
||||
public List<FlightConfigurationID> getIDs(){
|
||||
return this.getSortedConfigurationIDs();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void set(FlightConfigurationID fcid, E nextValue) {
|
||||
if (null == fcid) {
|
||||
@ -146,11 +145,6 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
}
|
||||
if ( nextValue == null) {
|
||||
// null value means to delete this fcid
|
||||
if ( DEFAULT_VALUE_FCID == fcid ) {
|
||||
// NEVER delete the default value....
|
||||
return;
|
||||
}
|
||||
|
||||
E previousValue = map.remove(fcid);
|
||||
removeListener(previousValue);
|
||||
}else{
|
||||
@ -168,7 +162,7 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
|
||||
@Override
|
||||
public boolean isDefault( FlightConfigurationID fcid) {
|
||||
return (getDefault() == map.get(fcid));
|
||||
return ( this.getDefault() == this.map.get(fcid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -219,17 +213,33 @@ public class FlightConfigurationSet<E extends FlightConfigurableParameter<E>> im
|
||||
System.err.println("====== Dumping ConfigurationSet for comp: '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======");
|
||||
System.err.println(" >> FlightConfigurationSet ("+this.size()+ " configurations)");
|
||||
|
||||
for( FlightConfigurationID loopFCID : this.getSortedConfigurationIDs()){
|
||||
String shortKey = loopFCID.toShortKey();
|
||||
if( 0 == this.size() ){
|
||||
String designation = "";
|
||||
E inst = this.getDefault();
|
||||
|
||||
E inst = this.map.get(loopFCID);
|
||||
String designation;
|
||||
if( inst instanceof FlightConfiguration){
|
||||
FlightConfiguration fc = (FlightConfiguration) inst;
|
||||
designation = fc.getName();
|
||||
designation = ((FlightConfiguration) inst).getFlightConfigurationID().getShortKey();
|
||||
}else{
|
||||
designation = inst.toString();
|
||||
}
|
||||
|
||||
System.err.println(" ( DEFAULT_VALUE = "+designation + ")");
|
||||
}
|
||||
|
||||
for( FlightConfigurationID loopFCID : this.getSortedConfigurationIDs()){
|
||||
String shortKey = loopFCID.getShortKey();
|
||||
String designation = "";
|
||||
|
||||
E inst = this.map.get(loopFCID);
|
||||
if( inst instanceof FlightConfiguration){
|
||||
FlightConfiguration fc = (FlightConfiguration) inst;
|
||||
designation = ( fc.isNameOverridden() ? "" : fc.getName());
|
||||
}else{
|
||||
designation = inst.toString();
|
||||
}
|
||||
if( this.isDefault(inst)){
|
||||
shortKey = "*"+shortKey+"*";
|
||||
}
|
||||
System.err.println(" >> ["+shortKey+"]= "+designation);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class MotorConfigurationSet extends FlightConfigurationSet<MotorInstance>
|
||||
System.err.println(" >> motorSet ("+this.size()+ " motors)");
|
||||
|
||||
for( FlightConfigurationID loopFCID : this.map.keySet()){
|
||||
String shortKey = loopFCID.toShortKey();
|
||||
String shortKey = loopFCID.getShortKey();
|
||||
|
||||
MotorInstance curInstance = this.map.get(loopFCID);
|
||||
String designation;
|
||||
|
@ -83,8 +83,7 @@ public class Rocket extends RocketComponent {
|
||||
treeModID = modID;
|
||||
functionalModID = modID;
|
||||
|
||||
FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_FCID;
|
||||
FlightConfiguration defaultConfiguration = new FlightConfiguration( defaultFCID, this);
|
||||
FlightConfiguration defaultConfiguration = new FlightConfiguration( null, this);
|
||||
this.configurations = new FlightConfigurationSet<FlightConfiguration>(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class RenameConfigDialog extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newName = textbox.getText();
|
||||
rocket.getFlightConfiguration(fcid).setName( newName);
|
||||
System.err.println(" << just renamed: "+fcid.toShortKey()+" with: "+newName+" to: "+ rocket.getFlightConfiguration(fcid).getName());
|
||||
System.err.println(" << just renamed: "+fcid.getShortKey()+" with: "+newName+" to: "+ rocket.getFlightConfiguration(fcid).getName());
|
||||
rocket.getConfigurationSet().printDebug();
|
||||
RenameConfigDialog.this.setVisible(false);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Pair;
|
||||
|
||||
public class FlightConfigurableTableModel<T extends FlightConfigurableComponent> extends AbstractTableModel implements ComponentChangeListener{
|
||||
|
||||
private static final long serialVersionUID = 3168465083803936363L;
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
private static final String CONFIGURATION = trans.get("edtmotorconfdlg.col.configuration");
|
||||
@ -66,8 +65,7 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
// the -1 removes the DEFAULT_VALUE row, which is hidden.
|
||||
return (rocket.getConfigurationCount()-1);
|
||||
return rocket.getConfigurationCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,9 +105,8 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
|
||||
}
|
||||
|
||||
private FlightConfigurationID getConfigurationID(int rowNum) {
|
||||
if( rocket.getConfigurationCount() != (1+ ids.size() ) ){
|
||||
if( rocket.getConfigurationCount() != (ids.size() ) ){
|
||||
this.ids = rocket.getSortedConfigurationIDs();
|
||||
this.ids.remove(FlightConfigurationID.DEFAULT_VALUE_FCID);
|
||||
}
|
||||
|
||||
return this.ids.get(rowNum);
|
||||
|
@ -127,7 +127,6 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
FlightConfiguration newConfig = new FlightConfiguration( newFCID, rocket );
|
||||
|
||||
rocket.setFlightConfiguration(newFCID, newConfig);
|
||||
//System.err.println("Adding new config: "+newFCID.key+" called: "+newConfig.getName()+" (sz: "+newConfig?+")");
|
||||
|
||||
// Create a new simulation for this configuration.
|
||||
createSimulationForNewConfiguration();
|
||||
|
@ -139,7 +139,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
protected JTable initializeTable() {
|
||||
//// Motor selection table.
|
||||
configurationTableModel = new FlightConfigurableTableModel<MotorMount>(MotorMount.class,rocket) {
|
||||
|
||||
private static final long serialVersionUID = -1210899988369000567L;
|
||||
|
||||
@Override
|
||||
@ -206,7 +205,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
if ( (null == fcid )||( null == curMount )){
|
||||
return;
|
||||
}
|
||||
System.err.println("?? selected FCID: "+ fcid.key);
|
||||
|
||||
motorChooserDialog.setMotorMountAndConfig( fcid, curMount );
|
||||
motorChooserDialog.setVisible(true);
|
||||
@ -286,6 +284,11 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
// if( mount instanceof BodyTube ){
|
||||
// System.err.println("Formatting Cell: fcid="+configId.key.substring(0, 8));
|
||||
// ((BodyTube) mount).printMotorDebug();
|
||||
// }
|
||||
// System.err.println("rendering "+configId.getShortKey()+" cell: " );
|
||||
// if( rocket.getConfigurationSet().isDefault( configId) ){
|
||||
// String newText = label.getText() + " (default)";
|
||||
// System.err.println(" "+label.getText()+" >> "+newText);
|
||||
// }
|
||||
|
||||
JLabel motorDescriptionLabel = new JLabel(motorString);
|
||||
|
Loading…
x
Reference in New Issue
Block a user