[Bugfix] Improves FlightConfiguration selection, readability
-ParameterSetModel fixed - controlled configuration in the main window. et al. - now implements a generic ComboBoxModel<T>, instead of just a FlightConfigurationId.
This commit is contained in:
parent
c65fb80dbf
commit
040c451a3d
@ -277,7 +277,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
for (Simulation s : getSimulations()) {
|
||||
// Assumes modifiable collection - which it is
|
||||
if (configId.equals(s.getOptions().getConfigID())) {
|
||||
if (configId.equals(s.getOptions().getId())) {
|
||||
removeSimulation(s);
|
||||
}
|
||||
}
|
||||
@ -628,6 +628,17 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
public String getSimulationDetail(){
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(">> Dumping simulation list:\n");
|
||||
int simNum = 0;
|
||||
for( Simulation s : this.simulations ){
|
||||
str.append(String.format(" [%d] %s \n", simNum, s.getName(), s.getOptions().getId().toShortKey() ));
|
||||
simNum++;
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
DefaultSimulationOptionFactory f = Application.getInjector().getInstance(DefaultSimulationOptionFactory.class);
|
||||
options.copyConditionsFrom(f.getDefault());
|
||||
|
||||
options.setMotorConfigurationID(rocket.getDefaultConfiguration().getFlightConfigurationID());
|
||||
options.setFlightConfigurationId(rocket.getDefaultConfiguration().getFlightConfigurationID());
|
||||
options.addChangeListener(new ConditionListener());
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
FlightConfiguration config = rocket.getFlightConfiguration(options.getConfigID());
|
||||
FlightConfiguration config = rocket.getFlightConfiguration(options.getId());
|
||||
List<MotorInstance> motorList = config.getActiveMotors();
|
||||
|
||||
//Make sure this simulation has motors.
|
||||
@ -332,7 +332,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
|
||||
// Set simulated info after simulation, will not be set in case of exception
|
||||
simulatedConditions = options.clone();
|
||||
final FlightConfiguration configuration = new FlightConfiguration(options.getConfigID(), this.rocket);
|
||||
final FlightConfiguration configuration = this.rocket.getFlightConfiguration( options.getId());
|
||||
|
||||
simulatedConfigurationDescription = descriptor.format(configuration.getRocket(), configuration.getFlightConfigurationID());
|
||||
simulatedRocketID = rocket.getFunctionalModID();
|
||||
|
@ -504,7 +504,7 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
writeln("<conditions>");
|
||||
indent++;
|
||||
|
||||
writeElement("configid", cond.getConfigID().key);
|
||||
writeElement("configid", cond.getId().key);
|
||||
writeElement("launchrodlength", cond.getLaunchRodLength());
|
||||
writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI);
|
||||
writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI));
|
||||
|
@ -51,9 +51,9 @@ class SimulationConditionsHandler extends AbstractElementHandler {
|
||||
|
||||
if (element.equals("configid")) {
|
||||
if (content.equals("")) {
|
||||
conditions.setMotorConfigurationID(null);
|
||||
conditions.setFlightConfigurationId(null);
|
||||
} else {
|
||||
conditions.setMotorConfigurationID(new FlightConfigurationID(content));
|
||||
conditions.setFlightConfigurationId(new FlightConfigurationID(content));
|
||||
}
|
||||
} else if (element.equals("launchrodlength")) {
|
||||
if (Double.isNaN(d)) {
|
||||
|
@ -382,11 +382,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if( this.isNamed){
|
||||
return configurationName + "["+fcid.toShortKey()+"]";
|
||||
}else{
|
||||
return this.getName();
|
||||
}
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +51,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
protected final Preferences preferences = Application.getPreferences();
|
||||
|
||||
private final Rocket rocket;
|
||||
private FlightConfigurationID configID = null;
|
||||
private FlightConfigurationID configId = null;
|
||||
|
||||
/*
|
||||
* NOTE: When adding/modifying parameters, they must also be added to the
|
||||
@ -100,9 +100,12 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
return rocket;
|
||||
}
|
||||
|
||||
public FlightConfigurationID getFlightConfiguratioId() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
public FlightConfigurationID getConfigID() {
|
||||
return this.configID;
|
||||
public FlightConfigurationID getId() {
|
||||
return this.configId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,18 +114,18 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
*
|
||||
* @param id the configuration to set.
|
||||
*/
|
||||
public void setMotorConfigurationID(FlightConfigurationID fcid) {
|
||||
public void setFlightConfigurationId(FlightConfigurationID fcid) {
|
||||
if (! fcid.isValid() ){
|
||||
return; // error
|
||||
}else if (!rocket.containsFlightConfigurationID(fcid)){
|
||||
return;
|
||||
}
|
||||
|
||||
if( fcid.equals(this.configID)){
|
||||
if( fcid.equals(this.configId)){
|
||||
return;
|
||||
}
|
||||
|
||||
this.configID = fcid;
|
||||
this.configId = fcid;
|
||||
fireChangeEvent();
|
||||
}
|
||||
|
||||
@ -433,18 +436,18 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
public void copyFrom(SimulationOptions src) {
|
||||
|
||||
if (this.rocket == src.rocket) {
|
||||
this.configID = src.configID;
|
||||
this.configId = src.configId;
|
||||
} else {
|
||||
|
||||
if (src.rocket.hasMotors(src.configID)) {
|
||||
if (src.rocket.hasMotors(src.configId)) {
|
||||
// First check for exact match:
|
||||
if (this.rocket.containsFlightConfigurationID(src.configID)) {
|
||||
this.configID = src.configID;
|
||||
if (this.rocket.containsFlightConfigurationID(src.configId)) {
|
||||
this.configId = src.configId;
|
||||
} else {
|
||||
// Try to find a closely matching motor ID
|
||||
MotorDescriptionSubstitutor formatter = Application.getInjector().getInstance(MotorDescriptionSubstitutor.class);
|
||||
|
||||
String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.configID);
|
||||
String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.configId);
|
||||
FlightConfigurationID matchID = null;
|
||||
|
||||
for (FlightConfigurationID fcid : this.rocket.getSortedConfigurationIDs()){
|
||||
@ -455,10 +458,10 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
this.configID = matchID;
|
||||
this.configId = matchID;
|
||||
}
|
||||
} else {
|
||||
this.configID = null;
|
||||
this.configId = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,7 +565,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
return false;
|
||||
SimulationOptions o = (SimulationOptions) other;
|
||||
return ((this.rocket == o.rocket) &&
|
||||
Utils.equals(this.configID, o.configID) &&
|
||||
Utils.equals(this.configId, o.configId) &&
|
||||
MathUtil.equals(this.launchAltitude, o.launchAltitude) &&
|
||||
MathUtil.equals(this.launchLatitude, o.launchLatitude) &&
|
||||
MathUtil.equals(this.launchLongitude, o.launchLongitude) &&
|
||||
@ -584,9 +587,9 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (configID == null)
|
||||
if (configId == null)
|
||||
return rocket.hashCode();
|
||||
return rocket.hashCode() + configID.hashCode();
|
||||
return rocket.hashCode() + configId.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -618,7 +621,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
SimulationConditions conditions = new SimulationConditions();
|
||||
|
||||
conditions.setRocket((Rocket) getRocket().copy());
|
||||
conditions.setFlightConfigurationID(this.getConfigID());
|
||||
conditions.setFlightConfigurationID(this.getId());
|
||||
conditions.setLaunchRodLength(getLaunchRodLength());
|
||||
conditions.setLaunchRodAngle(getLaunchRodAngle());
|
||||
conditions.setLaunchRodDirection(getLaunchRodDirection());
|
||||
|
@ -14,7 +14,6 @@ import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.motor.MotorInstance;
|
||||
import net.sf.openrocket.motor.MotorInstanceId;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotorInstance;
|
||||
import net.sf.openrocket.preset.ComponentPreset;
|
||||
import net.sf.openrocket.preset.ComponentPresetFactory;
|
||||
import net.sf.openrocket.preset.InvalidComponentPresetException;
|
||||
@ -1028,7 +1027,7 @@ public class TestRockets {
|
||||
|
||||
// create simulation data
|
||||
SimulationOptions options = new SimulationOptions(rocket);
|
||||
options.setMotorConfigurationID(fcid);
|
||||
options.setFlightConfigurationId(fcid);
|
||||
Simulation simulation1 = new Simulation(rocket);
|
||||
|
||||
rocketDoc.addSimulation(simulation1);
|
||||
|
@ -10,9 +10,6 @@ import javax.swing.event.EventListenerList;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableParameter;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
@ -23,14 +20,14 @@ import net.sf.openrocket.util.StateChangeListener;
|
||||
* A ComboBoxModel that contains a list of flight configurations. The list can
|
||||
* optionally contain a last element that opens up the configuration edit dialog.
|
||||
*/
|
||||
public class ParameterSetModel<T extends FlightConfigurableParameter<T>> implements ComboBoxModel<FlightConfigurationID>, StateChangeListener {
|
||||
public class ParameterSetModel<T extends FlightConfigurableParameter<T>> implements ComboBoxModel<T>, StateChangeListener {
|
||||
//private static final Translator trans = Application.getTranslator();
|
||||
private static final Logger log = LoggerFactory.getLogger(ParameterSetModel.class);
|
||||
//private static final Logger log = LoggerFactory.getLogger(ParameterSetModel.class);
|
||||
//private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
private EventListenerList listenerList = new EventListenerList();
|
||||
|
||||
private T selected;
|
||||
private Object selected;
|
||||
private final ParameterSet<T> sourceSet;
|
||||
List<FlightConfigurationID> idList= new Vector<FlightConfigurationID>();
|
||||
|
||||
@ -40,17 +37,12 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlightConfigurationID getElementAt(int index) {
|
||||
|
||||
this.idList = this.sourceSet.getSortedConfigurationIDs();
|
||||
|
||||
if (index < 0){
|
||||
return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
|
||||
}else if ( index >= this.idList.size()){
|
||||
return FlightConfigurationID.ERROR_CONFIGURATION_FCID;
|
||||
public T getElementAt(int index) {
|
||||
if((index < 0)||( index >= this.idList.size())){
|
||||
return sourceSet.getDefault();
|
||||
}
|
||||
|
||||
return this.idList.get(index);
|
||||
FlightConfigurationID fcid = this.idList.get(index);
|
||||
return this.sourceSet.get( fcid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,7 +53,7 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
return selected;
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,13 +63,13 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item instanceof FlightConfigurationID)) {
|
||||
|
||||
throw new IllegalArgumentException("MotorConfigurationModel item=" + item);
|
||||
if( item.getClass().isAssignableFrom(this.selected.getClass())){
|
||||
this.selected = item;
|
||||
return;
|
||||
}else{
|
||||
throw new IllegalArgumentException("attempted to set selected item (oftype "+item.getClass().getSimpleName()
|
||||
+") when this generic contains a type: "+this.selected.getClass().getSimpleName());
|
||||
}
|
||||
FlightConfigurationID fcid= (FlightConfigurationID) item;
|
||||
|
||||
this.selected = sourceSet.get(fcid);
|
||||
}
|
||||
|
||||
|
||||
@ -117,6 +109,7 @@ public class ParameterSetModel<T extends FlightConfigurableParameter<T>> impleme
|
||||
return;
|
||||
}
|
||||
fireListDataEvent();
|
||||
this.idList = this.sourceSet.getSortedConfigurationIDs();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ import net.sf.openrocket.masscalc.MassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;
|
||||
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
@ -179,7 +178,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
panel.add(label, "growx, right");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
|
||||
JComboBox<FlightConfigurationID> combo = new JComboBox<FlightConfigurationID>(psm);
|
||||
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>(psm);
|
||||
panel.add(combo, "wrap");
|
||||
|
||||
|
||||
|
@ -1164,7 +1164,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
||||
}
|
||||
|
||||
// Update the active configuration
|
||||
FlightConfigurationID fcid = getSelectedSimulation().getOptions().getConfigID();
|
||||
FlightConfigurationID fcid = getSelectedSimulation().getOptions().getId();
|
||||
getSelectedSimulation().getRocket().setDefaultConfiguration(fcid);
|
||||
|
||||
updating = false;
|
||||
|
@ -58,6 +58,7 @@ import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.AlphanumComparator;
|
||||
|
||||
public class SimulationPanel extends JPanel {
|
||||
private static final long serialVersionUID = 1390060162192576924L;
|
||||
private static final Logger log = LoggerFactory.getLogger(SimulationPanel.class);
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
@ -323,7 +324,7 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
public Comparator<String> getComparator() {
|
||||
return new AlphanumComparator();
|
||||
}
|
||||
},
|
||||
@ -660,11 +661,8 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private enum SimulationTableColumns {
|
||||
|
||||
}
|
||||
|
||||
private class JLabelRenderer extends DefaultTableCellRenderer {
|
||||
private static final long serialVersionUID = 5487619660216145843L;
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table,
|
||||
@ -706,6 +704,9 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
tip = "<html><b>" + sim.getName() + "</b><br>";
|
||||
switch (sim.getStatus()) {
|
||||
case CANT_RUN:
|
||||
tip += trans.get("simpanel.ttip.noData")+"<br>";
|
||||
break;
|
||||
case UPTODATE:
|
||||
tip += trans.get("simpanel.ttip.uptodate") + "<br>";
|
||||
break;
|
||||
|
@ -515,7 +515,7 @@ public class DesignReport {
|
||||
try {
|
||||
for (int i = 0; i < simulations.size(); i++) {
|
||||
Simulation simulation = simulations.get(i);
|
||||
if (Utils.equals(simulation.getOptions().getConfigID(), motorId)) {
|
||||
if (Utils.equals(simulation.getOptions().getId(), motorId)) {
|
||||
simulation = simulation.copy();
|
||||
simulation.simulate();
|
||||
flight = simulation.getSimulatedData();
|
||||
|
@ -307,13 +307,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
add(label, "growx, right");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
|
||||
JComboBox<FlightConfigurationID> flightConfigurationComboBox = new JComboBox<FlightConfigurationID>(psm);
|
||||
add(flightConfigurationComboBox, "wrap");
|
||||
JComboBox<FlightConfiguration> flightConfigurationComboBox = new JComboBox<FlightConfiguration>(psm);
|
||||
add(flightConfigurationComboBox, "wrap, width 16%, wmin 100");
|
||||
flightConfigurationComboBox.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
Object source = ae.getSource();
|
||||
if( source instanceof JComboBox ){
|
||||
@SuppressWarnings("unchecked")
|
||||
JComboBox<FlightConfigurationID> box = (JComboBox<FlightConfigurationID>) source;
|
||||
FlightConfiguration newConfig = (FlightConfiguration)box.getSelectedItem();
|
||||
document.getRocket().getConfigurationSet().setDefault( newConfig);
|
||||
@ -695,7 +696,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
Rocket duplicate = (Rocket) document.getRocket().copy();
|
||||
Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate);
|
||||
simulation.getOptions().setMotorConfigurationID(
|
||||
simulation.getOptions().setFlightConfigurationId(
|
||||
document.getDefaultConfiguration().getFlightConfigurationID());
|
||||
|
||||
backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation);
|
||||
|
@ -25,14 +25,13 @@ import net.sf.openrocket.gui.adaptors.ParameterSetModel;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
|
||||
import net.sf.openrocket.simulation.SimulationOptions;
|
||||
import net.sf.openrocket.simulation.extension.SimulationExtension;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
|
||||
public class SimulationEditDialog extends JDialog {
|
||||
|
||||
private static final long serialVersionUID = -4468157685542912715L;
|
||||
private final Window parentWindow;
|
||||
private final Simulation[] simulation;
|
||||
private final OpenRocketDocument document;
|
||||
@ -152,14 +151,14 @@ public class SimulationEditDialog extends JDialog {
|
||||
panel.add(label, "growx 0, gapright para");
|
||||
|
||||
ParameterSetModel<FlightConfiguration> psm = new ParameterSetModel<FlightConfiguration>( configuration.getRocket().getConfigurationSet());
|
||||
JComboBox<?> combo = new JComboBox<FlightConfigurationID>(psm);
|
||||
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>(psm);
|
||||
|
||||
//// Select the motor configuration to use.
|
||||
combo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||
combo.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
conditions.setMotorConfigurationID(configuration.getFlightConfigurationID());
|
||||
conditions.setFlightConfigurationId(configuration.getFlightConfigurationID());
|
||||
}
|
||||
});
|
||||
panel.add(combo, "span");
|
||||
|
Loading…
x
Reference in New Issue
Block a user