Display computer motor class in motor selection dialog
This commit is contained in:
parent
02fbe90a32
commit
216ba1dd00
@ -1,3 +1,7 @@
|
|||||||
|
2012-02-19 Sampo Niskanen
|
||||||
|
|
||||||
|
* Display computed motor class
|
||||||
|
|
||||||
2012-02-16 Sampo Niskanen
|
2012-02-16 Sampo Niskanen
|
||||||
|
|
||||||
* [BUG] Freeze when dropping component on child component
|
* [BUG] Freeze when dropping component on child component
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
||||||
|
|
||||||
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
import net.sf.openrocket.util.BugException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NAR approved motor classes (http://www.nar.org/NARmotors.html).
|
||||||
|
*
|
||||||
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
|
*/
|
||||||
|
public enum MotorClass {
|
||||||
|
|
||||||
|
A18("1/8A", 0, 0.3125),
|
||||||
|
A14("1/4A", 0.3125, 0.625),
|
||||||
|
A12("1/2A", 0.625, 1.25),
|
||||||
|
A("A", 1.25, 2.5),
|
||||||
|
B("B", 2.5, 5),
|
||||||
|
C("C", 5, 10),
|
||||||
|
D("D", 10, 20),
|
||||||
|
E("E", 20, 40),
|
||||||
|
F("F", 40, 80),
|
||||||
|
G("G", 80, 160),
|
||||||
|
H("H", 160, 320),
|
||||||
|
I("I", 320, 640),
|
||||||
|
J("J", 640, 1280),
|
||||||
|
K("K", 1280, 2560),
|
||||||
|
L("L", 2560, 5120),
|
||||||
|
M("M", 5120, 10240),
|
||||||
|
N("N", 10240, 20480),
|
||||||
|
O("O", 20480, 40960),
|
||||||
|
OVER("> O", 40960, Double.MAX_VALUE) {
|
||||||
|
@Override
|
||||||
|
public String getDescription(double impulse) {
|
||||||
|
return "Over O";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassDescription() {
|
||||||
|
return "Over O-class (over " + UnitGroup.UNITS_IMPULSE.toStringUnit(40960) + ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private final String className;
|
||||||
|
private final double min;
|
||||||
|
private final double max;
|
||||||
|
|
||||||
|
|
||||||
|
private MotorClass(String className, double min, double max) {
|
||||||
|
this.className = className;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getDescription(double impulse) {
|
||||||
|
double percent = (impulse - min) / (max - min) * 100;
|
||||||
|
if (percent < 1) {
|
||||||
|
// 0% looks stupid
|
||||||
|
percent = 1;
|
||||||
|
}
|
||||||
|
return String.format("%d%% %s", Math.round(percent), className);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassDescription() {
|
||||||
|
return "Class " + className + " (" + UnitGroup.UNITS_IMPULSE.toStringUnit(min) + " - " + UnitGroup.UNITS_IMPULSE.toStringUnit(max) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the appropriate motor class for the provided impulse.
|
||||||
|
*/
|
||||||
|
public static MotorClass getMotorClass(double impulse) {
|
||||||
|
double epsilon = 0.0000001;
|
||||||
|
|
||||||
|
// Round large values so 640.1 Ns (which is displayed as 640 Ns) is counted as I-class
|
||||||
|
if (impulse >= 100) {
|
||||||
|
impulse = Math.rint(impulse);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MotorClass m : MotorClass.values()) {
|
||||||
|
if (impulse <= m.max + epsilon) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new BugException("Could not find motor class for impulse " + impulse);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -54,7 +54,6 @@ import net.sf.openrocket.gui.util.SwingPreferences;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
import net.sf.openrocket.motor.MotorDigest;
|
|
||||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
@ -124,6 +123,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
private final DefaultComboBoxModel curveSelectionModel;
|
private final DefaultComboBoxModel curveSelectionModel;
|
||||||
|
|
||||||
private final JLabel totalImpulseLabel;
|
private final JLabel totalImpulseLabel;
|
||||||
|
private final JLabel classificationLabel;
|
||||||
private final JLabel avgThrustLabel;
|
private final JLabel avgThrustLabel;
|
||||||
private final JLabel maxThrustLabel;
|
private final JLabel maxThrustLabel;
|
||||||
private final JLabel burnTimeLabel;
|
private final JLabel burnTimeLabel;
|
||||||
@ -300,7 +300,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
// Motor mount diameter label
|
// Motor mount diameter label
|
||||||
//// Motor mount diameter:
|
//// Motor mount diameter:
|
||||||
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Motormountdia")+ " " +
|
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Motormountdia") + " " +
|
||||||
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter));
|
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter));
|
||||||
panel.add(label, "gapright 30lp, spanx, split");
|
panel.add(label, "gapright 30lp, spanx, split");
|
||||||
|
|
||||||
@ -413,7 +413,11 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
//// Total impulse:
|
//// Total impulse:
|
||||||
panel.add(new JLabel(trans.get("TCMotorSelPan.lbl.Totalimpulse")));
|
panel.add(new JLabel(trans.get("TCMotorSelPan.lbl.Totalimpulse")));
|
||||||
totalImpulseLabel = new JLabel();
|
totalImpulseLabel = new JLabel();
|
||||||
panel.add(totalImpulseLabel, "wrap");
|
panel.add(totalImpulseLabel, "split");
|
||||||
|
classificationLabel = new JLabel();
|
||||||
|
classificationLabel.setEnabled(false); // Gray
|
||||||
|
// classificationLabel.setForeground(Color.GRAY);
|
||||||
|
panel.add(classificationLabel, "gapleft unrel, wrap");
|
||||||
|
|
||||||
//// Avg. thrust:
|
//// Avg. thrust:
|
||||||
panel.add(new JLabel(trans.get("TCMotorSelPan.lbl.Avgthrust")));
|
panel.add(new JLabel(trans.get("TCMotorSelPan.lbl.Avgthrust")));
|
||||||
@ -638,6 +642,9 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
curveSelectionBox.setEnabled(false);
|
curveSelectionBox.setEnabled(false);
|
||||||
curveSelectionLabel.setEnabled(false);
|
curveSelectionLabel.setEnabled(false);
|
||||||
totalImpulseLabel.setText("");
|
totalImpulseLabel.setText("");
|
||||||
|
totalImpulseLabel.setToolTipText(null);
|
||||||
|
classificationLabel.setText("");
|
||||||
|
classificationLabel.setToolTipText(null);
|
||||||
avgThrustLabel.setText("");
|
avgThrustLabel.setText("");
|
||||||
maxThrustLabel.setText("");
|
maxThrustLabel.setText("");
|
||||||
burnTimeLabel.setText("");
|
burnTimeLabel.setText("");
|
||||||
@ -675,8 +682,13 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
|
|
||||||
// Update thrust curve data
|
// Update thrust curve data
|
||||||
totalImpulseLabel.setText(UnitGroup.UNITS_IMPULSE.getDefaultUnit().toStringUnit(
|
double impulse = selectedMotor.getTotalImpulseEstimate();
|
||||||
selectedMotor.getTotalImpulseEstimate()));
|
MotorClass mc = MotorClass.getMotorClass(impulse);
|
||||||
|
totalImpulseLabel.setText(UnitGroup.UNITS_IMPULSE.getDefaultUnit().toStringUnit(impulse));
|
||||||
|
classificationLabel.setText("(" + mc.getDescription(impulse) + ")");
|
||||||
|
totalImpulseLabel.setToolTipText(mc.getClassDescription());
|
||||||
|
classificationLabel.setToolTipText(mc.getClassDescription());
|
||||||
|
|
||||||
avgThrustLabel.setText(UnitGroup.UNITS_FORCE.getDefaultUnit().toStringUnit(
|
avgThrustLabel.setText(UnitGroup.UNITS_FORCE.getDefaultUnit().toStringUnit(
|
||||||
selectedMotor.getAverageThrustEstimate()));
|
selectedMotor.getAverageThrustEstimate()));
|
||||||
maxThrustLabel.setText(UnitGroup.UNITS_FORCE.getDefaultUnit().toStringUnit(
|
maxThrustLabel.setText(UnitGroup.UNITS_FORCE.getDefaultUnit().toStringUnit(
|
||||||
@ -721,7 +733,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
plot.setDataset(dataset);
|
plot.setDataset(dataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<ThrustCurveMotor> getFilteredCurves() {
|
private List<ThrustCurveMotor> getFilteredCurves() {
|
||||||
List<ThrustCurveMotor> motors = selectedMotorSet.getMotors();
|
List<ThrustCurveMotor> motors = selectedMotorSet.getMotors();
|
||||||
if (hideSimilarBox.isSelected()) {
|
if (hideSimilarBox.isSelected()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user