Merge pull request #1180 from SiboVG/issue-1166

[fixes #1166] Use [{motors}] for flight config motors placeholder
This commit is contained in:
Joe Pfeiffer 2022-02-28 10:27:19 -07:00 committed by GitHub
commit 804d9bad0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 15 deletions

View File

@ -55,7 +55,7 @@ public class RocketSaver extends RocketComponentSaver {
} }
if (flightConfig.isNameOverridden()){ if (flightConfig.isNameOverridden()){
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getName()) str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getNameRaw())
+ "</name></motorconfiguration>"; + "</name></motorconfiguration>";
} else { } else {
str += "/>"; str += "/>";

View File

@ -34,7 +34,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class); private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private String configurationName=null; private String configurationName;
public static String DEFAULT_CONFIG_NAME = "[{motors}]";
protected final Rocket rocket; protected final Rocket rocket;
protected final FlightConfigurationId fcid; protected final FlightConfigurationId fcid;
@ -94,7 +95,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.fcid = _fcid; this.fcid = _fcid;
} }
this.rocket = rocket; this.rocket = rocket;
this.configurationName = null; this.configurationName = DEFAULT_CONFIG_NAME;
this.configurationInstanceId = configurationInstanceCount++; this.configurationInstanceId = configurationInstanceCount++;
updateStages(); updateStages();
@ -414,15 +415,31 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
public boolean isNameOverridden(){ public boolean isNameOverridden(){
return (null != this.configurationName ); return (!DEFAULT_CONFIG_NAME.equals(this.configurationName));
} }
/**
* Return the name of this configuration, with DEFAULT_CONFIG_NAME replaced by a one line motor description.
* If configurationName is null, the one line motor description is returned.
* @return the flight configuration name
*/
public String getName() { public String getName() {
if( null == configurationName){ if (configurationName == null) {
return this.getOneLineMotorDescription(); return getOneLineMotorDescription();
}else{
return configurationName;
} }
return configurationName.replace(DEFAULT_CONFIG_NAME, getOneLineMotorDescription());
}
/**
* Return the raw configuration name, without replacing DEFAULT_CONFIG_NAME.
* If the configurationName is null, DEFAULT_CONFIG_NAME is returned.
* @return raw flight configuration name
*/
public String getNameRaw() {
if (configurationName == null) {
return DEFAULT_CONFIG_NAME;
}
return configurationName;
} }
private String getOneLineMotorDescription(){ private String getOneLineMotorDescription(){
@ -699,6 +716,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
copy.modID = this.modID; copy.modID = this.modID;
copy.boundsModID = -1; copy.boundsModID = -1;
copy.refLengthModID = -1; copy.refLengthModID = -1;
copy.configurationName = configurationName;
return copy; return copy;
} }
@ -714,8 +732,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
public void setName(final String newName) { public void setName(final String newName) {
if(( null == newName ) ||( "".equals(newName))){ if ((newName == null) || ("".equals(newName))) {
this.configurationName = null; this.configurationName = DEFAULT_CONFIG_NAME;
return; return;
}else if( ! this.getId().isValid()){ }else if( ! this.getId().isValid()){
return; return;

View File

@ -861,7 +861,7 @@ public class Rocket extends ComponentAssembly {
if( this.selectedConfiguration.equals( config)){ if( this.selectedConfiguration.equals( config)){
shortKey = "=>" + shortKey; shortKey = "=>" + shortKey;
} }
buf.append(String.format(fmt, shortKey, config.getName() )); buf.append(String.format(fmt, shortKey, config.getNameRaw() ));
} }
return buf.toString(); return buf.toString();
} }

View File

@ -30,7 +30,7 @@ public class RenameConfigDialog extends JDialog {
panel.add(new JLabel(trans.get("RenameConfigDialog.lbl.name")), "span, wrap rel"); panel.add(new JLabel(trans.get("RenameConfigDialog.lbl.name")), "span, wrap rel");
final JTextField textbox = new JTextField(rocket.getFlightConfiguration(fcid).getName()); final JTextField textbox = new JTextField(rocket.getFlightConfiguration(fcid).getNameRaw());
panel.add(textbox, "span, w 200lp, growx, wrap para"); panel.add(textbox, "span, w 200lp, growx, wrap para");
panel.add(new JPanel(), "growx"); panel.add(new JPanel(), "growx");

View File

@ -220,7 +220,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
if (fcIds == null) return; if (fcIds == null) return;
FlightConfigurationId initFcId = fcIds.get(0); FlightConfigurationId initFcId = fcIds.get(0);
new RenameConfigDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId).setVisible(true); new RenameConfigDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId).setVisible(true);
String newName = rocket.getFlightConfiguration(initFcId).getName(); String newName = rocket.getFlightConfiguration(initFcId).getNameRaw();
for (int i = 1; i < fcIds.size(); i++) { for (int i = 1; i < fcIds.size(); i++) {
rocket.getFlightConfiguration(fcIds.get(i)).setName(newName); rocket.getFlightConfiguration(fcIds.get(i)).setName(newName);
} }