Refactoring or rocket configuration description
This commit is contained in:
parent
dd5a16802b
commit
525869c3e7
@ -405,6 +405,7 @@ simpanel.dlg.lbl.DeleteSim2 = <html><i>This operation cannot be undone.</i>
|
||||
simpanel.dlg.lbl.DeleteSim3 = Delete simulations
|
||||
simpanel.col.Name = Name
|
||||
simpanel.col.Motors = Motors
|
||||
simpanel.col.Configuration = Configuration
|
||||
simpanel.col.Velocityoffrod = Velocity off rod
|
||||
simpanel.col.Velocityatdeploy = Velocity at deployment
|
||||
simpanel.col.Apogee = Apogee
|
||||
@ -1313,7 +1314,8 @@ Streamer.Streamer = Streamer
|
||||
Sleeve.Sleeve = Sleeve
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [No motors]
|
||||
Rocket.motorCount.Nomotor = No motors
|
||||
Rocket.motorCount.noStageMotors = None
|
||||
Rocket.compname.Rocket = Rocket
|
||||
|
||||
!MotorMount
|
||||
@ -1856,3 +1858,4 @@ SeparationSelectionDialog.opt.override = Override for the {0} flight configurati
|
||||
|
||||
MotorConfigurationPanel.description = <b>Select the motors and motor ignition events of your rocket.</b><br> <em>Motor mounts:</em> Select which components function as motor mounts.<br> <em>Motor configurations:</em> Select the motor and ignition event for each motor mount.
|
||||
|
||||
MotorDescriptionSubstitutor.description = Motors in the configuration
|
||||
|
@ -1159,7 +1159,7 @@ ShockCord.ShockCord = Poutac
|
||||
Bulkhead.Bulkhead = Prepá\u017Eka
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [\u017Dádné motory]
|
||||
Rocket.motorCount.Nomotor = \u017Dádné motory
|
||||
Rocket.compname.Rocket = Raketa
|
||||
|
||||
!MotorMount
|
||||
|
@ -1216,7 +1216,7 @@ ShockCord.ShockCord = Gummiband
|
||||
Bulkhead.Bulkhead = Schott
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [Keine Motoren]
|
||||
Rocket.motorCount.Nomotor = Keine Motoren
|
||||
Rocket.compname.Rocket = Rakete
|
||||
|
||||
!MotorMount
|
||||
|
@ -1227,7 +1227,7 @@ ShockCord.ShockCord = Tirante de suspensi
|
||||
Bulkhead.Bulkhead = Disco de enganche
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [Sin motores]
|
||||
Rocket.motorCount.Nomotor = Sin motores
|
||||
Rocket.compname.Rocket = Cohete
|
||||
|
||||
!MotorMount
|
||||
|
@ -1269,7 +1269,7 @@ Streamer.Streamer = Streamer
|
||||
Sleeve.Sleeve = Sleeve
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [aucun moteurs]
|
||||
Rocket.motorCount.Nomotor = aucun moteurs
|
||||
Rocket.compname.Rocket = Fusée
|
||||
|
||||
!MotorMount
|
||||
|
@ -1220,7 +1220,7 @@ ShockCord.ShockCord = Shock cord
|
||||
Bulkhead.Bulkhead = Paratia
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [Nessun motore]
|
||||
Rocket.motorCount.Nomotor = Nessun motore
|
||||
Rocket.compname.Rocket = Razzo
|
||||
|
||||
!MotorMount
|
||||
|
@ -1161,7 +1161,7 @@
|
||||
Bulkhead.Bulkhead = Przegroda
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [bez silników]
|
||||
Rocket.motorCount.Nomotor = bez silników
|
||||
Rocket.compname.Rocket = Rakieta
|
||||
|
||||
!MotorMount
|
||||
|
@ -1274,7 +1274,7 @@ Streamer.Streamer = \u0422\u043e\u0440\u043c\u043e\u0437\u043d\u0430\u044f \u043
|
||||
Sleeve.Sleeve = \u0412\u0442\u0443\u043b\u043a\u0430
|
||||
|
||||
!Rocket
|
||||
Rocket.motorCount.Nomotor = [\u0411\u0435\u0437 \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u0435\u0439]
|
||||
Rocket.motorCount.Nomotor = \u0411\u0435\u0437 \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u0435\u0439
|
||||
Rocket.compname.Rocket = \u0420\u0430\u043a\u0435\u0442\u0430
|
||||
|
||||
!MotorMount
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
|
||||
import net.sf.openrocket.aerodynamics.BarrowmanCalculator;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.masscalc.BasicMassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator;
|
||||
@ -57,6 +58,9 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
NOT_SIMULATED
|
||||
}
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
private SafetyMutex mutex = SafetyMutex.newInstance();
|
||||
|
||||
private final Rocket rocket;
|
||||
@ -83,7 +87,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
|
||||
/** The conditions actually used in the previous simulation, or null */
|
||||
private SimulationOptions simulatedConditions = null;
|
||||
private String simulatedMotors = null;
|
||||
private String simulatedConfiguration = null;
|
||||
private FlightData simulatedData = null;
|
||||
private int simulatedRocketID = -1;
|
||||
|
||||
@ -305,7 +309,8 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
// Set simulated info after simulation, will not be set in case of exception
|
||||
simulatedConditions = options.clone();
|
||||
final Configuration configuration = getConfiguration();
|
||||
simulatedMotors = configuration.getFlightConfigurationDescription();
|
||||
|
||||
simulatedConfiguration = descriptor.format(configuration.getRocket(), configuration.getFlightConfigurationID());
|
||||
simulatedRocketID = rocket.getFunctionalModID();
|
||||
|
||||
status = Status.UPTODATE;
|
||||
@ -350,11 +355,10 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
*
|
||||
* @return a description of the motor configuration of the previous simulation, or
|
||||
* <code>null</code>.
|
||||
* @see Rocket#getFlightConfigurationNameOrDescription(String)
|
||||
*/
|
||||
public String getSimulatedMotorDescription() {
|
||||
public String getSimulatedConfigurationDescription() {
|
||||
mutex.verify();
|
||||
return simulatedMotors;
|
||||
return simulatedConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -389,7 +393,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
copy.simulationListeners = this.simulationListeners.clone();
|
||||
copy.listeners = new ArrayList<EventListener>();
|
||||
copy.simulatedConditions = null;
|
||||
copy.simulatedMotors = null;
|
||||
copy.simulatedConfiguration = null;
|
||||
copy.simulatedData = null;
|
||||
copy.simulatedRocketID = -1;
|
||||
|
||||
|
@ -49,7 +49,8 @@ public class RocketSaver extends RocketComponentSaver {
|
||||
if (id.equals(defId))
|
||||
str += " default=\"true\"";
|
||||
|
||||
if (rocket.getFlightConfigurationName(id) == "") {
|
||||
|
||||
if (rocket.getFlightConfigurationName(id).equals(Rocket.DEFAULT_NAME)) {
|
||||
str += "/>";
|
||||
} else {
|
||||
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(rocket.getFlightConfigurationName(id))
|
||||
|
@ -32,20 +32,20 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
|
||||
|
||||
@Override
|
||||
public String substitute(String str, Rocket rocket, String configId) {
|
||||
String description = getFlightConfigurationDescription(rocket, configId);
|
||||
String description = getMotorConfigurationDescription(rocket, configId);
|
||||
return str.replace(SUBSTITUTION, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDescriptions() {
|
||||
Map<String, String> desc = new HashMap<String, String>();
|
||||
desc.put(SUBSTITUTION, trans.get("description"));
|
||||
desc.put(SUBSTITUTION, trans.get("MotorDescriptionSubstitutor.description"));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getFlightConfigurationDescription(Rocket rocket, String id) {
|
||||
public String getMotorConfigurationDescription(Rocket rocket, String id) {
|
||||
String name;
|
||||
int motorCount = 0;
|
||||
|
||||
@ -82,7 +82,6 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
|
||||
}
|
||||
|
||||
if (motorCount == 0) {
|
||||
//// [No motors]
|
||||
return trans.get("Rocket.motorCount.Nomotor");
|
||||
}
|
||||
|
||||
@ -138,17 +137,16 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
|
||||
stages.add(stageName);
|
||||
}
|
||||
|
||||
name = "[";
|
||||
name = "";
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
String s = stages.get(i);
|
||||
if (s.equals(""))
|
||||
s = "None";
|
||||
s = trans.get("Rocket.motorCount.noStageMotors");
|
||||
if (i == 0)
|
||||
name = name + s;
|
||||
else
|
||||
name = name + "; " + s;
|
||||
}
|
||||
name += "]";
|
||||
return name;
|
||||
}
|
||||
|
||||
|
25
core/src/net/sf/openrocket/formatting/RocketDescriptor.java
Normal file
25
core/src/net/sf/openrocket/formatting/RocketDescriptor.java
Normal file
@ -0,0 +1,25 @@
|
||||
package net.sf.openrocket.formatting;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
/**
|
||||
* Interface for formatting a flight configuration into a
|
||||
* textual string.
|
||||
*/
|
||||
public interface RocketDescriptor {
|
||||
|
||||
/**
|
||||
* Return a string describing a particular flight configuration
|
||||
* of the rocket. This uses the default flight configuration name
|
||||
* as the basis.
|
||||
*/
|
||||
public String format(Rocket rocket, String configId);
|
||||
|
||||
|
||||
/**
|
||||
* Return a string describing a particular flight configuration
|
||||
* of the rocket. This uses a custom-provided name as the basis.
|
||||
*/
|
||||
public String format(String name, Rocket rocket, String configId);
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class RocketFormatterImpl implements RocketFormatter {
|
||||
public class RocketDescriptorImpl implements RocketDescriptor {
|
||||
|
||||
@Inject
|
||||
private Set<RocketSubstitutor> substitutors;
|
||||
@ -14,7 +14,11 @@ public class RocketFormatterImpl implements RocketFormatter {
|
||||
@Override
|
||||
public String format(Rocket rocket, String configId) {
|
||||
String name = rocket.getFlightConfigurationName(configId);
|
||||
return format(name, rocket, configId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String name, Rocket rocket, String configId) {
|
||||
for (RocketSubstitutor s : substitutors) {
|
||||
while (s.containsSubstitution(name)) {
|
||||
name = s.substitute(name, rocket, configId);
|
@ -1,17 +0,0 @@
|
||||
package net.sf.openrocket.formatting;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
/**
|
||||
* Interface for formatting a flight configuration into a
|
||||
* textual string.
|
||||
*/
|
||||
public interface RocketFormatter {
|
||||
|
||||
/**
|
||||
* Return a string describing a particular flight configuration
|
||||
* of the rocket.
|
||||
*/
|
||||
public String format(Rocket rocket, String configId);
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ import javax.swing.event.EventListenerList;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.dialogs.flightconfiguration.FlightConfigurationDialog;
|
||||
import net.sf.openrocket.gui.main.BasicFrame;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
@ -25,6 +26,8 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
|
||||
private static final String EDIT = trans.get("MotorCfgModel.Editcfg");
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
private EventListenerList listenerList = new EventListenerList();
|
||||
|
||||
@ -45,7 +48,7 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
@Override
|
||||
public Object getElementAt(int index) {
|
||||
String[] ids = rocket.getFlightConfigurationIDs();
|
||||
if (index < 0 || index > ids.length)
|
||||
if (index < 0 || index > ids.length)
|
||||
return null;
|
||||
|
||||
if (index == ids.length)
|
||||
@ -77,14 +80,14 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
@Override
|
||||
public void run() {
|
||||
new FlightConfigurationDialog(rocket, BasicFrame.findFrame(rocket))
|
||||
.setVisible(true);
|
||||
.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
if (!(item instanceof ID)) {
|
||||
throw new IllegalArgumentException("MotorConfigurationModel item="+item);
|
||||
throw new IllegalArgumentException("MotorConfigurationModel item=" + item);
|
||||
}
|
||||
|
||||
ID idObject = (ID) item;
|
||||
@ -110,11 +113,11 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
Object[] listeners = listenerList.getListenerList();
|
||||
ListDataEvent e = null;
|
||||
|
||||
for (int i = listeners.length-2; i>=0; i-=2) {
|
||||
for (int i = listeners.length - 2; i >= 0; i -= 2) {
|
||||
if (listeners[i] == ListDataListener.class) {
|
||||
if (e == null)
|
||||
e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize());
|
||||
((ListDataListener) listeners[i+1]).contentsChanged(e);
|
||||
((ListDataListener) listeners[i + 1]).contentsChanged(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,7 +127,7 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
public void stateChanged(EventObject e) {
|
||||
if (e instanceof ComponentChangeEvent) {
|
||||
// Ignore unnecessary changes
|
||||
if (!((ComponentChangeEvent)e).isMotorChange())
|
||||
if (!((ComponentChangeEvent) e).isMotorChange())
|
||||
return;
|
||||
}
|
||||
fireListDataEvent();
|
||||
@ -162,9 +165,8 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return rocket.getFlightConfigurationNameOrDescription(id);
|
||||
return descriptor.format(rocket, id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import javax.swing.JSlider;
|
||||
import javax.swing.JSpinner;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.SpinnerEditor;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.adaptors.EnumModel;
|
||||
@ -33,6 +34,8 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
private final DeploymentConfiguration newConfiguration;
|
||||
|
||||
private final JLabel altText;
|
||||
@ -53,7 +56,7 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
final JRadioButton defaultButton = new JRadioButton(trans.get("DeploymentSelectionDialog.opt.default"), true);
|
||||
panel.add(defaultButton, "span, gapleft para, wrap rel");
|
||||
String str = trans.get("DeploymentSelectionDialog.opt.override");
|
||||
str = str.replace("{0}", rocket.getFlightConfigurationNameOrDescription(id));
|
||||
str = str.replace("{0}", descriptor.format(rocket, id));
|
||||
final JRadioButton overrideButton = new JRadioButton(str, false);
|
||||
panel.add(overrideButton, "span, gapleft para, wrap para");
|
||||
|
||||
@ -134,7 +137,6 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
||||
}
|
||||
|
||||
|
||||
private void updateState() {
|
||||
boolean enabled = (newConfiguration.getDeployEvent() == DeployEvent.ALTITUDE);
|
||||
altText.setEnabled(enabled);
|
||||
|
@ -10,6 +10,8 @@ import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
|
||||
public class FlightConfigurationModelRemoveMe extends DefaultComboBoxModel {
|
||||
|
||||
// FIXME Remove this class
|
||||
|
||||
private final Configuration config;
|
||||
private final Rocket rocket;
|
||||
|
||||
@ -90,7 +92,7 @@ public class FlightConfigurationModelRemoveMe extends DefaultComboBoxModel {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return rocket.getFlightConfigurationNameOrDescription(id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import javax.swing.JRadioButton;
|
||||
import javax.swing.JSpinner;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.SpinnerEditor;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.adaptors.EnumModel;
|
||||
@ -30,6 +31,8 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
private IgnitionConfiguration newConfiguration;
|
||||
|
||||
@ -46,7 +49,7 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault);
|
||||
panel.add(defaultButton, "span, gapleft para, wrap rel");
|
||||
String str = trans.get("IgnitionSelectionDialog.opt.override");
|
||||
str = str.replace("{0}", rocket.getFlightConfigurationNameOrDescription(id));
|
||||
str = str.replace("{0}", descriptor.format(rocket, id));
|
||||
final JRadioButton overrideButton = new JRadioButton(str, !isDefault);
|
||||
panel.add(overrideButton, "span, gapleft para, wrap para");
|
||||
|
||||
|
@ -55,6 +55,7 @@ import javax.swing.tree.TreePath;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.SpinnerEditor;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.components.CsvOptionPanel;
|
||||
@ -115,6 +116,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
||||
private static final String START_TEXT = trans.get("btn.start");
|
||||
private static final String STOP_TEXT = trans.get("btn.stop");
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
private final List<OptimizableParameter> optimizationParameters = new ArrayList<OptimizableParameter>();
|
||||
private final Map<Object, List<SimulationModifier>> simulationModifiers =
|
||||
new HashMap<Object, List<SimulationModifier>>();
|
||||
@ -933,7 +937,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
||||
|
||||
for (Simulation s : documentCopy.getSimulations()) {
|
||||
String id = s.getConfiguration().getFlightConfigurationID();
|
||||
String name = createSimulationName(s.getName(), rocket.getFlightConfigurationNameOrDescription(id));
|
||||
String name = createSimulationName(s.getName(), descriptor.format(rocket, id));
|
||||
simulations.add(new Named<Simulation>(s, name));
|
||||
}
|
||||
|
||||
@ -943,13 +947,13 @@ public class GeneralOptimizationDialog extends JDialog {
|
||||
}
|
||||
Simulation sim = new Simulation(rocket);
|
||||
sim.getConfiguration().setFlightConfigurationID(id);
|
||||
String name = createSimulationName(trans.get("basicSimulationName"), rocket.getFlightConfigurationNameOrDescription(id));
|
||||
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, id));
|
||||
simulations.add(new Named<Simulation>(sim, name));
|
||||
}
|
||||
|
||||
Simulation sim = new Simulation(rocket);
|
||||
sim.getConfiguration().setFlightConfigurationID(null);
|
||||
String name = createSimulationName(trans.get("noSimulationName"), rocket.getFlightConfigurationNameOrDescription(null));
|
||||
String name = createSimulationName(trans.get("noSimulationName"), descriptor.format(rocket, null));
|
||||
simulations.add(new Named<Simulation>(sim, name));
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@ import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.document.events.DocumentChangeEvent;
|
||||
import net.sf.openrocket.document.events.DocumentChangeListener;
|
||||
import net.sf.openrocket.document.events.SimulationChangeEvent;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.adaptors.Column;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
import net.sf.openrocket.gui.components.StyledLabel;
|
||||
@ -39,6 +40,7 @@ import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||
import net.sf.openrocket.simulation.FlightData;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.startup.Preferences;
|
||||
@ -56,6 +58,8 @@ public class SimulationPanel extends JPanel {
|
||||
private static final String OK_TEXT = "\u2714"; // Heavy check mark
|
||||
|
||||
|
||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
private final OpenRocketDocument document;
|
||||
|
||||
@ -135,7 +139,7 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
new SimulationRunDialog(SwingUtilities.getWindowAncestor(
|
||||
SimulationPanel.this), document, sims).setVisible(true);
|
||||
SimulationPanel.this), document, sims).setVisible(true);
|
||||
log.info("Running simulations took " + (System.currentTimeMillis() - t) + " ms");
|
||||
fireMaintainSelection();
|
||||
}
|
||||
@ -165,17 +169,17 @@ public class SimulationPanel extends JPanel {
|
||||
panel.add(new StyledLabel(trans.get("simpanel.lbl.defpref"), -2));
|
||||
|
||||
int ret = JOptionPane.showConfirmDialog(SimulationPanel.this,
|
||||
new Object[] {
|
||||
//// Delete the selected simulations?
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim1"),
|
||||
//// <html><i>This operation cannot be undone.</i>
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim2"),
|
||||
"",
|
||||
panel },
|
||||
//// Delete simulations
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim3"),
|
||||
JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
new Object[] {
|
||||
//// Delete the selected simulations?
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim1"),
|
||||
//// <html><i>This operation cannot be undone.</i>
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim2"),
|
||||
"",
|
||||
panel },
|
||||
//// Delete simulations
|
||||
trans.get("simpanel.dlg.lbl.DeleteSim3"),
|
||||
JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
if (ret != JOptionPane.OK_OPTION)
|
||||
return;
|
||||
|
||||
@ -218,12 +222,11 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
|
||||
|
||||
|
||||
//////// The simulation table
|
||||
|
||||
simulationTableModel = new ColumnTableModel(
|
||||
|
||||
//// Status and warning column
|
||||
//// Status and warning column
|
||||
new Column("") {
|
||||
private JLabel label = null;
|
||||
|
||||
@ -294,15 +297,14 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
},
|
||||
|
||||
//// Simulation motors
|
||||
//// Motors
|
||||
new Column(trans.get("simpanel.col.Motors")) {
|
||||
//// Simulation configuration
|
||||
new Column(trans.get("simpanel.col.Configuration")) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
return document.getSimulation(row).getConfiguration()
|
||||
.getFlightConfigurationDescription();
|
||||
Configuration c = document.getSimulation(row).getConfiguration();
|
||||
return descriptor.format(c.getRocket(), c.getFlightConfigurationID());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -439,12 +441,12 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
) {
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return document.getSimulationCount();
|
||||
}
|
||||
};
|
||||
) {
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return document.getSimulationCount();
|
||||
}
|
||||
};
|
||||
|
||||
// Override processKeyBinding so that the JTable does not catch
|
||||
// key bindings used in menu accelerators
|
||||
@ -571,38 +573,38 @@ public class SimulationPanel extends JPanel {
|
||||
tip = "<html><b>" + sim.getName() + "</b><br>";
|
||||
switch (sim.getStatus()) {
|
||||
case UPTODATE:
|
||||
tip += trans.get ("simpanel.ttip.uptodate") + "<br>";
|
||||
tip += trans.get("simpanel.ttip.uptodate") + "<br>";
|
||||
break;
|
||||
|
||||
case LOADED:
|
||||
tip += trans.get ("simpanel.ttip.loaded") + "<br>";
|
||||
tip += trans.get("simpanel.ttip.loaded") + "<br>";
|
||||
break;
|
||||
|
||||
case OUTDATED:
|
||||
tip += trans.get ("simpanel.ttip.outdated") + "<br>";
|
||||
tip += trans.get("simpanel.ttip.outdated") + "<br>";
|
||||
break;
|
||||
|
||||
case EXTERNAL:
|
||||
tip += trans.get ("simpanel.ttip.external") + "<br>";
|
||||
tip += trans.get("simpanel.ttip.external") + "<br>";
|
||||
return tip;
|
||||
|
||||
case NOT_SIMULATED:
|
||||
tip += trans.get ("simpanel.ttip.notSimulated");
|
||||
tip += trans.get("simpanel.ttip.notSimulated");
|
||||
return tip;
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
tip += trans.get ("simpanel.ttip.noData");
|
||||
tip += trans.get("simpanel.ttip.noData");
|
||||
return tip;
|
||||
}
|
||||
WarningSet warnings = data.getWarningSet();
|
||||
|
||||
if (warnings.isEmpty()) {
|
||||
tip += trans.get ("simpanel.ttip.noWarnings");
|
||||
tip += trans.get("simpanel.ttip.noWarnings");
|
||||
return tip;
|
||||
}
|
||||
|
||||
tip += trans.get ("simpanel.ttip.warnings");
|
||||
tip += trans.get("simpanel.ttip.warnings");
|
||||
for (Warning w : warnings) {
|
||||
tip += "<br>" + w.toString();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.figureelements.FigureElement;
|
||||
import net.sf.openrocket.gui.figureelements.RocketInfo;
|
||||
import net.sf.openrocket.gui.scalefigure.RocketPanel;
|
||||
@ -81,6 +82,9 @@ public class DesignReport {
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
public static final double SCALE_FUDGE_FACTOR = 0.4d;
|
||||
|
||||
private static final RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||
|
||||
|
||||
/**
|
||||
* The OR Document.
|
||||
*/
|
||||
@ -419,7 +423,7 @@ public class DesignReport {
|
||||
c.setBorder(PdfPCell.LEFT);
|
||||
c.setBorderWidthTop(0f);
|
||||
parent.addCell(c);
|
||||
config.release();
|
||||
config.release();
|
||||
}
|
||||
|
||||
|
||||
@ -444,7 +448,7 @@ public class DesignReport {
|
||||
PdfPTable labelTable = new PdfPTable(2);
|
||||
labelTable.setWidths(new int[] { 3, 2 });
|
||||
final Paragraph chunk = ITextHelper.createParagraph(stripBrackets(
|
||||
theRocket.getFlightConfigurationNameOrDescription(motorId)), PrintUtilities.BOLD);
|
||||
descriptor.format(theRocket, motorId)), PrintUtilities.BOLD);
|
||||
chunk.setLeading(leading);
|
||||
chunk.setSpacingAfter(3f);
|
||||
|
||||
|
@ -181,12 +181,6 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
||||
fireChangeEvent();
|
||||
}
|
||||
|
||||
public String getFlightConfigurationDescription() {
|
||||
return rocket.getFlightConfigurationNameOrDescription(flightConfigurationId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,8 @@ import java.util.UUID;
|
||||
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.ArrayList;
|
||||
import net.sf.openrocket.util.Chars;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.MathUtil;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
@ -35,6 +33,7 @@ public class Rocket extends RocketComponent {
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
public static final String DEFAULT_NAME = "[{motors}]";
|
||||
public static final double DEFAULT_REFERENCE_LENGTH = 0.01;
|
||||
|
||||
|
||||
@ -583,7 +582,7 @@ public class Rocket extends RocketComponent {
|
||||
MotorMount mount = (MotorMount) c;
|
||||
if (!mount.isMotorMount())
|
||||
continue;
|
||||
if (mount.getMotor(id) != null) {
|
||||
if (mount.getMotorConfiguration().get(id).getMotor() != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -594,18 +593,19 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
/**
|
||||
* Return the user-set name of the flight configuration. If no name has been set,
|
||||
* returns an empty string (not null).
|
||||
* returns the default name ({@link #DEFAULT_NAME}).
|
||||
*
|
||||
* @param id the flight configuration id
|
||||
* @return the configuration name
|
||||
*/
|
||||
// FIXME: Check references to this method adhere to the new returning of DEFAULT_NAME
|
||||
public String getFlightConfigurationName(String id) {
|
||||
checkState();
|
||||
if (!isFlightConfigurationID(id))
|
||||
return "";
|
||||
return DEFAULT_NAME;
|
||||
String s = flightConfigurationNames.get(id);
|
||||
if (s == null)
|
||||
return "";
|
||||
return DEFAULT_NAME;
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -619,146 +619,15 @@ public class Rocket extends RocketComponent {
|
||||
*/
|
||||
public void setFlightConfigurationName(String id, String name) {
|
||||
checkState();
|
||||
flightConfigurationNames.put(id, name);
|
||||
if (name == null || name.equals("")) {
|
||||
flightConfigurationNames.remove(id);
|
||||
} else {
|
||||
flightConfigurationNames.put(id, name);
|
||||
}
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return either the flight configuration name (if set) or its description.
|
||||
*
|
||||
* @param id the flight configuration ID.
|
||||
* @return a textual representation of the configuration
|
||||
*/
|
||||
public String getFlightConfigurationNameOrDescription(String id) {
|
||||
checkState();
|
||||
String name;
|
||||
|
||||
name = getFlightConfigurationName(id);
|
||||
if (name != null && !name.equals(""))
|
||||
return name;
|
||||
|
||||
return getFlightConfigurationDescription(id);
|
||||
}
|
||||
|
||||
|
||||
// FIXME: Change to private
|
||||
/**
|
||||
* Return a description for the flight configuration, generated from the motor
|
||||
* designations of the components.
|
||||
*
|
||||
* @param id the flight configuration ID.
|
||||
* @return a textual representation of the configuration
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
private String getFlightConfigurationDescription(String id) {
|
||||
checkState();
|
||||
String name;
|
||||
int motorCount = 0;
|
||||
|
||||
// Generate the description
|
||||
|
||||
// First iterate over each stage and store the designations of each motor
|
||||
List<List<String>> list = new ArrayList<List<String>>();
|
||||
List<String> currentList = null;
|
||||
|
||||
Iterator<RocketComponent> iterator = this.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RocketComponent c = iterator.next();
|
||||
|
||||
if (c instanceof Stage) {
|
||||
|
||||
currentList = new ArrayList<String>();
|
||||
list.add(currentList);
|
||||
|
||||
} else if (c instanceof MotorMount) {
|
||||
|
||||
MotorMount mount = (MotorMount) c;
|
||||
Motor motor = mount.getMotor(id);
|
||||
|
||||
if (mount.isMotorMount() && motor != null) {
|
||||
String designation = motor.getDesignation(mount.getMotorDelay(id));
|
||||
|
||||
for (int i = 0; i < mount.getMotorCount(); i++) {
|
||||
currentList.add(designation);
|
||||
motorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (motorCount == 0) {
|
||||
//// [No motors]
|
||||
return trans.get("Rocket.motorCount.Nomotor");
|
||||
}
|
||||
|
||||
// Change multiple occurrences of a motor to n x motor
|
||||
List<String> stages = new ArrayList<String>();
|
||||
|
||||
for (List<String> stage : list) {
|
||||
String stageName = "";
|
||||
String previous = null;
|
||||
int count = 0;
|
||||
|
||||
Collections.sort(stage);
|
||||
for (String current : stage) {
|
||||
if (current.equals(previous)) {
|
||||
|
||||
count++;
|
||||
|
||||
} else {
|
||||
|
||||
if (previous != null) {
|
||||
String s = "";
|
||||
if (count > 1) {
|
||||
s = "" + count + Chars.TIMES + previous;
|
||||
} else {
|
||||
s = previous;
|
||||
}
|
||||
|
||||
if (stageName.equals(""))
|
||||
stageName = s;
|
||||
else
|
||||
stageName = stageName + "," + s;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
count = 1;
|
||||
|
||||
}
|
||||
}
|
||||
if (previous != null) {
|
||||
String s = "";
|
||||
if (count > 1) {
|
||||
s = "" + count + Chars.TIMES + previous;
|
||||
} else {
|
||||
s = previous;
|
||||
}
|
||||
|
||||
if (stageName.equals(""))
|
||||
stageName = s;
|
||||
else
|
||||
stageName = stageName + "," + s;
|
||||
}
|
||||
|
||||
stages.add(stageName);
|
||||
}
|
||||
|
||||
name = "[";
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
String s = stages.get(i);
|
||||
if (s.equals(""))
|
||||
s = "None";
|
||||
if (i == 0)
|
||||
name = name + s;
|
||||
else
|
||||
name = name + "; " + s;
|
||||
}
|
||||
name += "]";
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////// Obligatory component information
|
||||
|
@ -407,11 +407,11 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
// Try to find a closely matching motor ID
|
||||
MotorDescriptionSubstitutor formatter = Application.getInjector().getInstance(MotorDescriptionSubstitutor.class);
|
||||
|
||||
String motorDesc = formatter.substitute(MotorDescriptionSubstitutor.SUBSTITUTION, src.rocket, src.motorID);
|
||||
String motorDesc = formatter.getMotorConfigurationDescription(src.rocket, src.motorID);
|
||||
String matchID = null;
|
||||
|
||||
for (String id : this.rocket.getFlightConfigurationIDs()) {
|
||||
String motorDesc2 = formatter.substitute(MotorDescriptionSubstitutor.SUBSTITUTION, this.rocket, id);
|
||||
String motorDesc2 = formatter.getMotorConfigurationDescription(this.rocket, id);
|
||||
if (motorDesc.equals(motorDesc2)) {
|
||||
matchID = id;
|
||||
break;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.sf.openrocket.startup;
|
||||
|
||||
import net.sf.openrocket.formatting.RocketFormatter;
|
||||
import net.sf.openrocket.formatting.RocketFormatterImpl;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.formatting.RocketDescriptorImpl;
|
||||
import net.sf.openrocket.gui.watcher.WatchService;
|
||||
import net.sf.openrocket.gui.watcher.WatchServiceImpl;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
@ -17,7 +17,7 @@ public class ApplicationModule extends AbstractModule {
|
||||
bind(Preferences.class).toInstance(Application.getPreferences());
|
||||
bind(Translator.class).toInstance(Application.getTranslator());
|
||||
bind(WatchService.class).to(WatchServiceImpl.class);
|
||||
bind(RocketFormatter.class).to(RocketFormatterImpl.class);
|
||||
bind(RocketDescriptor.class).to(RocketDescriptorImpl.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user