package com.billkuker.rocketry.motorsim.visual;\r
\r
import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.awt.GridLayout;\r
import java.text.NumberFormat;\r
\r
import javax.measure.quantity.Duration;\r
import javax.measure.unit.NonSI;\r
import javax.measure.unit.SI;\r
import javax.swing.JFrame;\r
+import javax.swing.JLabel;\r
import javax.swing.JPanel;\r
import javax.swing.JSlider;\r
import javax.swing.JSplitPane;\r
import org.jscience.physics.amount.Amount;\r
\r
import com.billkuker.rocketry.motorsim.Burn;\r
+import com.billkuker.rocketry.motorsim.RocketScience;\r
+import com.billkuker.rocketry.motorsim.Burn.Interval;\r
\r
public class BurnPanel extends JPanel {\r
private static final long serialVersionUID = 1L;\r
grains.setResizeWeight(.5);\r
\r
JSplitPane main = new JSplitPane(JSplitPane.VERTICAL_SPLIT, grains, tp);\r
+ Dimension minimumSize = new Dimension(800, 200);\r
+ grains.setMinimumSize(minimumSize);\r
+ tp.setMinimumSize(minimumSize);\r
main.setDividerLocation(.5);\r
main.setResizeWeight(.5);\r
\r
\r
add( new SL(), BorderLayout.SOUTH);\r
\r
+ \r
+\r
+ Amount<RocketScience.Impulse> ns = Amount.valueOf(0, RocketScience.NEWTON_SECOND);\r
+ Amount<Force> averageThrust = Amount.valueOf(0, SI.NEWTON);\r
+ Amount<Force> maxThrust = Amount.valueOf(0, SI.NEWTON);\r
+ Amount<Pressure> maxPressure = Amount.valueOf(0, SI.MEGA(SI.PASCAL));\r
+ int thrustCount = 0;\r
+ \r
+ for( Interval i: burn.getData().values() ){\r
+ ns = ns.plus(i.dt.times(i.thrust));\r
+ if ( i.thrust.isGreaterThan(Amount.valueOf(0.01, SI.NEWTON))){\r
+ thrustCount++;\r
+ averageThrust = averageThrust.plus(i.thrust);\r
+ }\r
+ if ( i.thrust.isGreaterThan(maxThrust))\r
+ maxThrust = i.thrust;\r
+ if ( i.chamberPressure.isGreaterThan(maxPressure))\r
+ maxPressure = i.chamberPressure;\r
+ }\r
+ averageThrust = averageThrust.divide(thrustCount);\r
+\r
+ int cn = (int)(Math.log(ns.doubleValue(RocketScience.NEWTON_SECOND)/1.25) / Math.log(2));\r
+ char cl = (char)((int)'A' + cn);\r
+\r
+ \r
+ JPanel text = new JPanel(new GridLayout(2,5));\r
+\r
+ text.add(new JLabel("Rating"));\r
+ text.add(new JLabel("Total Impulse"));\r
+ text.add(new JLabel("Max Thrust"));\r
+ text.add(new JLabel("Average Thust"));\r
+ text.add(new JLabel("Max Pressure"));\r
+ \r
+ text.add(new JLabel(new String(new char[]{cl}) + "-" +Math.round(averageThrust.doubleValue(SI.NEWTON))));\r
+ text.add(new JLabel(approx(ns)));\r
+ text.add(new JLabel(approx(maxThrust)));\r
+ text.add(new JLabel(approx(averageThrust)));\r
+ text.add(new JLabel(approx(maxPressure)));\r
+ \r
+ add(text, BorderLayout.NORTH);\r
+ \r
+ \r
} catch (NoSuchMethodException e){\r
throw new Error(e);\r
}\r
\r
}\r
\r
+ private String approx(Amount a){\r
+ double d = a.doubleValue(a.getUnit());\r
+ long i = Math.round(d);\r
+ return i + " " + a.getUnit().toString();\r
+ }\r
+ \r
private class SL extends JSlider implements ChangeListener{\r
private static final long serialVersionUID = 1L;\r
- private static final int STEPS = 300;\r
+ private static final int STEPS = 80;\r
public SL(){\r
addChangeListener(this);\r
setMinimum(0);\r