Added CaseInfo enum and compatible case information to

MotorInformationPanl.
This commit is contained in:
Kevin Ruland 2015-12-13 10:58:47 -06:00
parent 17540d160c
commit 4c56c53135
5 changed files with 143 additions and 9 deletions

View File

@ -1185,6 +1185,7 @@ TCMotorSelPan.lbl.Launchmass = Launch mass:
TCMotorSelPan.lbl.Emptymass = Empty mass:
TCMotorSelPan.lbl.Caseinfo = Case info:
TCMotorSelPan.lbl.Propinfo = Propellant:
TCMotorSelPan.lbl.CompatibleCases = Compatible Cases
TCMotorSelPan.lbl.Datapoints = Data points:
TCMotorSelPan.lbl.Digest = Digest:
TCMotorSelPan.title.Thrustcurve = Thrust curve:

View File

@ -0,0 +1,94 @@
package net.sf.openrocket.motor;
import java.util.HashMap;
import java.util.Map;
/**
* Enumeration of reloadable hardware which OpenRocket supports for substitution.
*
*/
public enum CaseInfo {
RMS29_100("RMS-29/100"), RMS29_120("RMS-29/120"), RMS29_180("RMS-29/180"), RMS29_240("RMS-29/240"), RMS29_360("RMS-29/360"),
RMS38_120("RMS-38/120"), RMS38_240("RMS-38/240"), RMS38_360("RMS-38/360"), RMS38_480("RMS-38/480"), RMS38_600("RMS-38/600"), RMS38_720("RMS-38/720"),
RMS54_426("RMS-54/426"), RMS54_852("RMS-54/852"), RMS54_1280("RMS-54/1280"), RMS54_1706("RMS-54/1706"), RMS54_2560("RMS-54/2560"), RMS54_2800("RMS-54/2800"),
PRO29_1("Pro29-1G"), PRO29_2("Pro29-2G"), PRO29_3("Pro29-3G"), PRO29_4("Pro29-4G"), PRO29_5("Pro29-5G"), PRO29_6("Pro29-6G"), PRO29_6XL("Pro29-6GXL"),
PRO38_1("Pro38-1G"), PRO38_2("Pro38-2G"), PRO38_3("Pro38-4G"), PRO38_4("Pro38-4G"), PRO38_5("Pro38-5G"), PRO38_6("Pro38-6G"), PRO38_6XL("Pro38-6GXL"),
PRO54_1("Pro54-1G"), PRO54_2("Pro54-2G"), PRO54_3("Pro54-3G"), PRO54_4("Pro54-4G"), PRO54_5("Pro54-5G"), PRO54_6("Pro54-6G"), PRO54_6XL("Pro54-6GXL");
private String label;
private CaseInfo(String label) {
this.label = label;
}
public static CaseInfo parse(String label) {
return labelMapping.get(label);
}
@Override
public String toString() {
return label;
}
public CaseInfo[] getCompatibleCases() {
return compatibleCases.get(this);
}
private static Map<String, CaseInfo> labelMapping;
private static Map<CaseInfo, CaseInfo[]> compatibleCases;
static {
labelMapping = new HashMap<>();
for (CaseInfo ci : CaseInfo.values()) {
labelMapping.put(ci.label, ci);
}
compatibleCases = new HashMap<>();
compatibleCases.put(RMS29_100, new CaseInfo[] { RMS29_100, RMS29_120, RMS29_180 });
compatibleCases.put(RMS29_120, new CaseInfo[] { RMS29_120, RMS29_180, RMS29_240 });
compatibleCases.put(RMS29_180, new CaseInfo[] { RMS29_180, RMS29_240, RMS29_360 });
compatibleCases.put(RMS29_240, new CaseInfo[] { RMS29_240, RMS29_360 });
compatibleCases.put(RMS29_360, new CaseInfo[] { RMS29_360 });
compatibleCases.put(RMS38_120, new CaseInfo[] { RMS38_120, RMS38_240, RMS38_360 });
compatibleCases.put(RMS38_240, new CaseInfo[] { RMS38_240, RMS38_360, RMS38_480 });
compatibleCases.put(RMS38_360, new CaseInfo[] { RMS38_360, RMS38_480, RMS38_600 });
compatibleCases.put(RMS38_480, new CaseInfo[] { RMS38_480, RMS38_600, RMS38_720 });
compatibleCases.put(RMS38_600, new CaseInfo[] { RMS38_600, RMS38_720 });
compatibleCases.put(RMS38_720, new CaseInfo[] { RMS38_720 });
compatibleCases.put(RMS54_426, new CaseInfo[] { RMS54_426, RMS54_852, RMS54_1280 });
compatibleCases.put(RMS54_852, new CaseInfo[] { RMS54_852, RMS54_1280, RMS54_1706 });
compatibleCases.put(RMS54_1280, new CaseInfo[] { RMS54_1280, RMS54_1706, RMS54_2560 });
compatibleCases.put(RMS54_1706, new CaseInfo[] { RMS54_1706, RMS54_2560, RMS54_2800 });
compatibleCases.put(RMS54_2560, new CaseInfo[] { RMS54_2560, RMS54_2800 });
compatibleCases.put(RMS54_2800, new CaseInfo[] { RMS54_2800 });
compatibleCases.put(PRO29_1, new CaseInfo[] { PRO29_1, PRO29_2, PRO29_3 });
compatibleCases.put(PRO29_2, new CaseInfo[] { PRO29_2, PRO29_3, PRO29_4 });
compatibleCases.put(PRO29_3, new CaseInfo[] { PRO29_3, PRO29_4, PRO29_5 });
compatibleCases.put(PRO29_4, new CaseInfo[] { PRO29_4, PRO29_5, PRO29_6 });
compatibleCases.put(PRO29_5, new CaseInfo[] { PRO29_5, PRO29_6, PRO29_6XL });
compatibleCases.put(PRO29_6, new CaseInfo[] { PRO29_6, PRO29_6XL });
compatibleCases.put(PRO29_6XL, new CaseInfo[] { PRO29_6XL });
compatibleCases.put(PRO38_1, new CaseInfo[] { PRO38_1, PRO38_2, PRO38_3 });
compatibleCases.put(PRO38_2, new CaseInfo[] { PRO38_2, PRO38_3, PRO38_4 });
compatibleCases.put(PRO38_3, new CaseInfo[] { PRO38_3, PRO38_4, PRO38_5 });
compatibleCases.put(PRO38_4, new CaseInfo[] { PRO38_4, PRO38_5, PRO38_6 });
compatibleCases.put(PRO38_5, new CaseInfo[] { PRO38_5, PRO38_6, PRO38_6XL });
compatibleCases.put(PRO38_6, new CaseInfo[] { PRO38_6, PRO38_6XL });
compatibleCases.put(PRO38_6XL, new CaseInfo[] { PRO38_6XL });
compatibleCases.put(PRO54_1, new CaseInfo[] { PRO54_1, PRO54_2, PRO54_3 });
compatibleCases.put(PRO54_2, new CaseInfo[] { PRO54_2, PRO54_3, PRO54_4 });
compatibleCases.put(PRO54_3, new CaseInfo[] { PRO54_3, PRO54_4, PRO54_5 });
compatibleCases.put(PRO54_4, new CaseInfo[] { PRO54_4, PRO54_5, PRO54_6 });
compatibleCases.put(PRO54_5, new CaseInfo[] { PRO54_5, PRO54_6, PRO54_6XL });
compatibleCases.put(PRO54_6, new CaseInfo[] { PRO54_6, PRO54_6XL });
compatibleCases.put(PRO54_6XL, new CaseInfo[] { PRO54_6XL });
}
}

View File

@ -248,6 +248,17 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
return caseInfo;
}
public CaseInfo getCaseInfoEnum() {
return CaseInfo.parse(caseInfo);
}
public CaseInfo[] getCompatibleCases() {
CaseInfo myCase = getCaseInfoEnum();
if (myCase == null) {
return new CaseInfo[] {};
}
return myCase.getCompatibleCases();
}
public String getPropellantInfo() {
return propellantInfo;

View File

@ -16,14 +16,6 @@ import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
@ -34,6 +26,15 @@ import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.utils.StringUtils;
class MotorInformationPanel extends JPanel {
private static final int ZOOM_ICON_POSITION_NEGATIVE_X = 50;
@ -56,9 +57,10 @@ class MotorInformationPanel extends JPanel {
private final JLabel burnTimeLabel;
private final JLabel launchMassLabel;
private final JLabel emptyMassLabel;
private final JLabel dataPointsLabel;
private final JLabel caseInfoLabel;
private final JLabel propInfoLabel;
private final JLabel dataPointsLabel;
private final JLabel compatibleCasesLabel;
private final JLabel digestLabel;
private final JTextArea comment;
@ -118,6 +120,11 @@ class MotorInformationPanel extends JPanel {
propInfoLabel = new JLabel();
this.add(propInfoLabel, "wrap");
//// compatible cases:
this.add(new JLabel(trans.get("TCMotorSelPan.lbl.CompatibleCases")));
compatibleCasesLabel = new JLabel();
this.add(compatibleCasesLabel, "wrap");
//// Data points:
this.add(new JLabel(trans.get("TCMotorSelPan.lbl.Datapoints")));
dataPointsLabel = new JLabel();
@ -226,6 +233,7 @@ class MotorInformationPanel extends JPanel {
emptyMassLabel.setText("");
caseInfoLabel.setText("");
propInfoLabel.setText("");
compatibleCasesLabel.setText("");
dataPointsLabel.setText("");
if (digestLabel != null) {
digestLabel.setText("");
@ -264,6 +272,7 @@ class MotorInformationPanel extends JPanel {
selectedMotor.getEmptyCG().weight));
caseInfoLabel.setText(selectedMotor.getCaseInfo());
propInfoLabel.setText(selectedMotor.getPropellantInfo());
compatibleCasesLabel.setText( StringUtils.join(",",selectedMotor.getCompatibleCases()));
dataPointsLabel.setText("" + (selectedMotor.getTimePoints().length - 1));
if (digestLabel != null) {
digestLabel.setText(selectedMotor.getDigest());

View File

@ -0,0 +1,19 @@
package net.sf.openrocket.utils;
public class StringUtils {
public static String join(String sep, Object[] values) {
if ( values == null || values.length == 0 ) {
return "";
}
StringBuilder value = new StringBuilder();
for( Object v : values ) {
if( value.length() > 0 ) {
value.append(sep);
}
value.append(String.valueOf(v));
}
return value.toString();
}
}