Refactoring or rocket configuration description

This commit is contained in:
Sampo Niskanen 2013-03-22 18:12:58 +02:00
parent dd5a16802b
commit 525869c3e7
25 changed files with 255 additions and 355 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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))

View File

@ -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;
}

View 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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
@ -22,9 +23,11 @@ import net.sf.openrocket.util.StateChangeListener;
public class FlightConfigurationModel implements ComboBoxModel, StateChangeListener {
private static final Translator trans = Application.getTranslator();
private static final String EDIT = trans.get("MotorCfgModel.Editcfg");
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
private EventListenerList listenerList = new EventListenerList();
@ -33,7 +36,7 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
private Map<String, ID> map = new HashMap<String, ID>();
public FlightConfigurationModel(Configuration config) {
this.config = config;
this.rocket = config.getRocket();
@ -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)
@ -53,17 +56,17 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
return get(ids[index]);
}
@Override
public int getSize() {
return rocket.getFlightConfigurationIDs().length + 1;
}
@Override
public Object getSelectedItem() {
return get(config.getFlightConfigurationID());
}
@Override
public void setSelectedItem(Object item) {
if (item == null) {
@ -77,21 +80,21 @@ 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;
config.setFlightConfigurationID(idObject.getID());
}
//////////////// Event/listener handling ////////////////
@ -100,31 +103,31 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe
public void addListDataListener(ListDataListener l) {
listenerList.add(ListDataListener.class, l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listenerList.remove(ListDataListener.class, l);
}
protected void fireListDataEvent() {
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);
}
}
}
@Override
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);
}
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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");

View File

@ -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));

View File

@ -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;
@ -47,7 +49,7 @@ import net.sf.openrocket.unit.UnitGroup;
public class SimulationPanel extends JPanel {
private static final LogHelper log = Application.getLogger();
private static final Translator trans = Application.getTranslator();
private static final Color WARNING_COLOR = Color.RED;
private static final String WARNING_TEXT = "\uFF01"; // Fullwidth exclamation mark
@ -55,8 +57,10 @@ public class SimulationPanel extends JPanel {
private static final Color OK_COLOR = new Color(60, 150, 0);
private static final String OK_TEXT = "\u2714"; // Heavy check mark
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
private final OpenRocketDocument document;
private final ColumnTableModel simulationTableModel;
@ -68,11 +72,11 @@ public class SimulationPanel extends JPanel {
JButton button;
this.document = doc;
//////// The simulation action buttons
//// New simulation button
@ -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;
@ -216,14 +220,13 @@ public class SimulationPanel extends JPanel {
});
this.add(button, "wrap para");
//////// The simulation table
simulationTableModel = new ColumnTableModel(
//// Status and warning column
//// Status and warning column
new Column("") {
private JLabel label = null;
@ -243,7 +246,7 @@ public class SimulationPanel extends JPanel {
Simulation.Status status = document.getSimulation(row).getStatus();
label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status));
// Set warning marker
if (status == Simulation.Status.NOT_SIMULATED ||
status == Simulation.Status.EXTERNAL) {
@ -277,7 +280,7 @@ public class SimulationPanel extends JPanel {
return JLabel.class;
}
},
//// Simulation name
//// Name
new Column(trans.get("simpanel.col.Name")) {
@ -293,16 +296,15 @@ public class SimulationPanel extends JPanel {
return 125;
}
},
//// 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
@ -310,7 +312,7 @@ public class SimulationPanel extends JPanel {
return 125;
}
},
//// Launch rod velocity
new Column(trans.get("simpanel.col.Velocityoffrod")) {
@Override
@ -326,7 +328,7 @@ public class SimulationPanel extends JPanel {
data.getLaunchRodVelocity());
}
},
//// Apogee
new Column(trans.get("simpanel.col.Apogee")) {
@Override
@ -342,7 +344,7 @@ public class SimulationPanel extends JPanel {
data.getMaxAltitude());
}
},
//// Velocity at deployment
new Column(trans.get("simpanel.col.Velocityatdeploy")) {
@Override
@ -358,7 +360,7 @@ public class SimulationPanel extends JPanel {
data.getDeploymentVelocity());
}
},
//// Maximum velocity
new Column(trans.get("simpanel.col.Maxvelocity")) {
@Override
@ -374,7 +376,7 @@ public class SimulationPanel extends JPanel {
data.getMaxVelocity());
}
},
//// Maximum acceleration
new Column(trans.get("simpanel.col.Maxacceleration")) {
@Override
@ -390,7 +392,7 @@ public class SimulationPanel extends JPanel {
data.getMaxAcceleration());
}
},
//// Time to apogee
new Column(trans.get("simpanel.col.Timetoapogee")) {
@Override
@ -406,7 +408,7 @@ public class SimulationPanel extends JPanel {
data.getTimeToApogee());
}
},
//// Flight time
new Column(trans.get("simpanel.col.Flighttime")) {
@Override
@ -422,7 +424,7 @@ public class SimulationPanel extends JPanel {
data.getFlightTime());
}
},
//// Ground hit velocity
new Column(trans.get("simpanel.col.Groundhitvelocity")) {
@Override
@ -438,13 +440,13 @@ public class SimulationPanel extends JPanel {
data.getGroundHitVelocity());
}
}
) {
@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
@ -461,7 +463,7 @@ public class SimulationPanel extends JPanel {
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
// Mouse listener to act on double-clicks
simulationTable.addMouseListener(new MouseAdapter() {
@Override
@ -490,9 +492,9 @@ public class SimulationPanel extends JPanel {
}
});
// Fire table change event when the rocket changes
document.getRocket().addComponentChangeListener(new ComponentChangeListener() {
@Override
@ -501,11 +503,11 @@ public class SimulationPanel extends JPanel {
}
});
JScrollPane scrollpane = new JScrollPane(simulationTable);
this.add(scrollpane, "spanx, grow, wrap rel");
}
@ -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();
}

View File

@ -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;
@ -74,33 +75,36 @@ import com.itextpdf.text.pdf.PdfWriter;
* </pre>
*/
public class DesignReport {
/**
* The logger.
*/
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.
*/
private OpenRocketDocument rocketDocument;
/**
* A panel used for rendering of the design diagram.
*/
final RocketPanel panel;
/**
* The iText document.
*/
protected Document document;
/**
* The figure rotation.
*/
private double rotation = 0d;
/** The displayed strings. */
private static final String STAGES = "Stages: ";
private static final String MASS_WITH_MOTORS = "Mass (with motors): ";
@ -126,7 +130,7 @@ public class DesignReport {
private static final String LANDING_VELOCITY = "Landing Velocity";
private static final String ROCKET_DESIGN = "Rocket Design";
private static final double GRAVITY_CONSTANT = 9.80665d;
/**
* Constructor.
*
@ -140,7 +144,7 @@ public class DesignReport {
panel = new RocketPanel(rocketDocument);
rotation = figureRotation;
}
/**
* Main entry point. Prints the rocket drawing and design data.
*
@ -153,23 +157,23 @@ public class DesignReport {
com.itextpdf.text.Rectangle pageSize = document.getPageSize();
int pageImageableWidth = (int) pageSize.getWidth() - (int) pageSize.getBorderWidth() * 2;
int pageImageableHeight = (int) pageSize.getHeight() / 2 - (int) pageSize.getBorderWidthTop();
PrintUtilities.addText(document, PrintUtilities.BIG_BOLD, ROCKET_DESIGN);
Rocket rocket = rocketDocument.getRocket();
final Configuration configuration = rocket.getDefaultConfiguration().clone();
configuration.setAllStages();
PdfContentByte canvas = writer.getDirectContent();
final PrintFigure figure = new PrintFigure(configuration);
figure.setRotation(rotation);
FigureElement cp = panel.getExtraCP();
FigureElement cg = panel.getExtraCG();
RocketInfo text = panel.getExtraText();
double scale = paintRocketDiagram(pageImageableWidth, pageImageableHeight, canvas, figure, cp, cg);
canvas.beginText();
canvas.setFontAndSize(ITextHelper.getBaseFont(), PrintUtilities.NORMAL_FONT_SIZE);
int figHeightPts = (int) (PrintUnit.METERS.toPoints(figure.getFigureHeight()) * 0.4 * (scale / PrintUnit.METERS
@ -177,15 +181,15 @@ public class DesignReport {
final int diagramHeight = pageImageableHeight * 2 - 70 - (figHeightPts);
canvas.moveText(document.leftMargin() + pageSize.getBorderWidthLeft(), diagramHeight);
canvas.moveTextWithLeading(0, -16);
float initialY = canvas.getYTLM();
canvas.showText(rocketDocument.getRocket().getName());
canvas.newlineShowText(STAGES);
canvas.showText("" + rocket.getStageCount());
if (configuration.hasMotors()) {
if (configuration.getStageCount() > 1) {
canvas.newlineShowText(MASS_WITH_MOTORS);
@ -196,29 +200,29 @@ public class DesignReport {
canvas.newlineShowText(MASS_EMPTY);
}
canvas.showText(text.getMass(UnitGroup.UNITS_MASS.getDefaultUnit()));
canvas.newlineShowText(STABILITY);
canvas.showText(text.getStability());
canvas.newlineShowText(CG);
canvas.showText(text.getCg());
canvas.newlineShowText(CP);
canvas.showText(text.getCp());
canvas.endText();
try {
//Move the internal pointer of the document below that of what was just written using the direct byte buffer.
Paragraph paragraph = new Paragraph();
float finalY = canvas.getYTLM();
int heightOfDiagramAndText = (int) (pageSize.getHeight() - (finalY - initialY + diagramHeight));
paragraph.setSpacingAfter(heightOfDiagramAndText);
document.add(paragraph);
String[] motorIds = rocket.getFlightConfigurationIDs();
List<Simulation> simulations = rocketDocument.getSimulations();
for (int j = 0; j < motorIds.length; j++) {
String motorId = motorIds[j];
if (motorId != null) {
@ -242,8 +246,8 @@ public class DesignReport {
log.error("Could not modify document.", e);
}
}
/**
* Paint a diagram of the rocket into the PDF document.
*
@ -264,7 +268,7 @@ public class DesignReport {
theFigure.addRelativeExtra(theCp);
theFigure.addRelativeExtra(theCg);
theFigure.updateFigure();
double scale =
(thePageImageableWidth * 2.2) / theFigure.getFigureWidth();
theFigure.setScale(scale);
@ -273,7 +277,7 @@ public class DesignReport {
*/
theFigure.setSize(thePageImageableWidth, thePageImageableHeight);
theFigure.updateFigure();
final DefaultFontMapper mapper = new DefaultFontMapper();
Graphics2D g2d = theCanvas.createGraphics(thePageImageableWidth, thePageImageableHeight * 2, mapper);
final double halfFigureHeight = SCALE_FUDGE_FACTOR * theFigure.getFigureHeightPx() / 2;
@ -284,13 +288,13 @@ public class DesignReport {
y += (int) halfFigureHeight;
}
g2d.translate(20, y);
g2d.scale(SCALE_FUDGE_FACTOR, SCALE_FUDGE_FACTOR);
theFigure.paint(g2d);
g2d.dispose();
return scale;
}
/**
* Add the motor data for a motor configuration to the table.
*
@ -299,11 +303,11 @@ public class DesignReport {
* @param parent the parent to which the motor data will be added
*/
private void addMotorData(Rocket rocket, String motorId, final PdfPTable parent) {
PdfPTable motorTable = new PdfPTable(8);
motorTable.setWidthPercentage(68);
motorTable.setHorizontalAlignment(Element.ALIGN_LEFT);
final PdfPCell motorCell = ITextHelper.createCell(MOTOR, PdfPCell.BOTTOM, PrintUtilities.SMALL);
final int mPad = 10;
motorCell.setPaddingLeft(mPad);
@ -315,25 +319,25 @@ public class DesignReport {
motorTable.addCell(ITextHelper.createCell(THRUST_TO_WT, PdfPCell.BOTTOM, PrintUtilities.SMALL));
motorTable.addCell(ITextHelper.createCell(PROPELLANT_WT, PdfPCell.BOTTOM, PrintUtilities.SMALL));
motorTable.addCell(ITextHelper.createCell(SIZE, PdfPCell.BOTTOM, PrintUtilities.SMALL));
DecimalFormat ttwFormat = new DecimalFormat("0.00");
MassCalculator massCalc = new BasicMassCalculator();
Configuration config = new Configuration(rocket);
config.setFlightConfigurationID(motorId);
int totalMotorCount = 0;
double totalPropMass = 0;
double totalImpulse = 0;
double totalTTW = 0;
int stage = 0;
double stageMass = 0;
boolean topBorder = false;
for (RocketComponent c : rocket) {
if (c instanceof Stage) {
config.setToStage(stage);
stage++;
@ -342,26 +346,26 @@ public class DesignReport {
totalTTW = 0;
topBorder = true;
}
if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) {
MotorMount mount = (MotorMount) c;
if (mount.isMotorMount() && mount.getMotor(motorId) != null) {
Motor motor = mount.getMotor(motorId);
int motorCount = c.toAbsolute(Coordinate.NUL).length;
int border = Rectangle.NO_BORDER;
if (topBorder) {
border = Rectangle.TOP;
topBorder = false;
}
String name = motor.getDesignation();
if (motorCount > 1) {
name += " (" + Chars.TIMES + motorCount + ")";
}
final PdfPCell motorVCell = ITextHelper.createCell(name, border);
motorVCell.setPaddingLeft(mPad);
motorTable.addCell(motorVCell);
@ -373,21 +377,21 @@ public class DesignReport {
UnitGroup.UNITS_FORCE.getDefaultUnit().toStringUnit(motor.getMaxThrustEstimate()), border));
motorTable.addCell(ITextHelper.createCell(
UnitGroup.UNITS_IMPULSE.getDefaultUnit().toStringUnit(motor.getTotalImpulseEstimate()), border));
double ttw = motor.getAverageThrustEstimate() / (stageMass * GRAVITY_CONSTANT);
motorTable.addCell(ITextHelper.createCell(
ttwFormat.format(ttw) + ":1", border));
double propMass = (motor.getLaunchCG().weight - motor.getEmptyCG().weight);
motorTable.addCell(ITextHelper.createCell(
UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(propMass), border));
final Unit motorUnit = UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit();
motorTable.addCell(ITextHelper.createCell(motorUnit.toString(motor.getDiameter()) +
"/" +
motorUnit.toString(motor.getLength()) + " " +
motorUnit.toString(), border));
// Sum up total count
totalMotorCount += motorCount;
totalPropMass += propMass * motorCount;
@ -396,7 +400,7 @@ public class DesignReport {
}
}
}
if (totalMotorCount > 1) {
int border = Rectangle.TOP;
final PdfPCell motorVCell = ITextHelper.createCell("Total:", border);
@ -412,17 +416,17 @@ public class DesignReport {
motorTable.addCell(ITextHelper.createCell(
UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(totalPropMass), border));
motorTable.addCell(ITextHelper.createCell("", border));
}
PdfPCell c = new PdfPCell(motorTable);
c.setBorder(PdfPCell.LEFT);
c.setBorderWidthTop(0f);
parent.addCell(c);
config.release();
config.release();
}
/**
* Add the flight data for a simulation configuration to the table.
*
@ -433,47 +437,47 @@ public class DesignReport {
* @param leading the number of points for the leading
*/
private void addFlightData(final FlightData flight, final Rocket theRocket, final String motorId, final PdfPTable parent, int leading) {
// Output the flight data
if (flight != null) {
try {
final Unit distanceUnit = UnitGroup.UNITS_DISTANCE.getDefaultUnit();
final Unit velocityUnit = UnitGroup.UNITS_VELOCITY.getDefaultUnit();
final Unit flightTimeUnit = UnitGroup.UNITS_FLIGHT_TIME.getDefaultUnit();
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);
document.add(chunk);
final PdfPCell cell = ITextHelper.createCell(ALTITUDE, 2, 2);
cell.setUseBorderPadding(false);
cell.setBorderWidthTop(0f);
labelTable.addCell(cell);
labelTable.addCell(ITextHelper.createCell(distanceUnit.toStringUnit(flight.getMaxAltitude()), 2, 2));
labelTable.addCell(ITextHelper.createCell(FLIGHT_TIME, 2, 2));
labelTable.addCell(ITextHelper.createCell(flightTimeUnit.toStringUnit(flight.getFlightTime()), 2, 2));
labelTable.addCell(ITextHelper.createCell(TIME_TO_APOGEE, 2, 2));
labelTable.addCell(ITextHelper.createCell(flightTimeUnit.toStringUnit(flight.getTimeToApogee()), 2, 2));
labelTable.addCell(ITextHelper.createCell(VELOCITY_OFF_PAD, 2, 2));
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getLaunchRodVelocity()), 2, 2));
labelTable.addCell(ITextHelper.createCell(MAX_VELOCITY, 2, 2));
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getMaxVelocity()), 2, 2));
labelTable.addCell(ITextHelper.createCell(DEPLOYMENT_VELOCITY, 2, 2));
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getDeploymentVelocity()), 2, 2));
labelTable.addCell(ITextHelper.createCell(LANDING_VELOCITY, 2, 2));
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getGroundHitVelocity()), 2, 2));
//Add the table to the parent; have to wrap it in a cell
PdfPCell c = new PdfPCell(labelTable);
c.setBorder(PdfPCell.RIGHT);
@ -485,7 +489,7 @@ public class DesignReport {
}
}
}
/**
* Locate the simulation based on the motor id. Copy the simulation and execute it, then return the resulting
* flight data.
@ -513,7 +517,7 @@ public class DesignReport {
}
return flight;
}
/**
* Strip [] brackets from a string.
*
@ -524,7 +528,7 @@ public class DesignReport {
private String stripBrackets(String target) {
return stripLeftBracket(stripRightBracket(target));
}
/**
* Strip [ from a string.
*
@ -535,7 +539,7 @@ public class DesignReport {
private String stripLeftBracket(String target) {
return target.replace("[", "");
}
/**
* Strip ] from a string.
*
@ -546,5 +550,5 @@ public class DesignReport {
private String stripRightBracket(String target) {
return target.replace("]", "");
}
}

View File

@ -181,12 +181,6 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
fireChangeEvent();
}
public String getFlightConfigurationDescription() {
return rocket.getFlightConfigurationNameOrDescription(flightConfigurationId);
}
/**

View File

@ -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

View File

@ -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;

View File

@ -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);
}
}