package com.billkuker.rocketry.motorsim;\r
\r
+import java.text.DecimalFormat;\r
import java.util.HashSet;\r
import java.util.Set;\r
\r
import javax.measure.unit.Unit;\r
import javax.measure.unit.UnitFormat;\r
\r
+import org.jscience.physics.amount.Amount;\r
+\r
public class RocketScience {\r
public static Unit<Pressure> PSI = new ProductUnit<Pressure>(NonSI.POUND_FORCE.divide(NonSI.INCH.pow(2)));\r
public static Unit<Impulse> NEWTON_SECOND = new ProductUnit<Impulse>(SI.NEWTON.times(SI.SECOND));\r
}\r
}\r
\r
+ @SuppressWarnings("unchecked")\r
+ public static <T extends Quantity> String approx(Amount<T> a) {\r
+ Unit<T> u = RocketScience.UnitPreference.preference.getPreferredUnit(a\r
+ .getUnit());\r
+ double d = a.doubleValue(u);\r
+\r
+ DecimalFormat df;\r
+ if (Math.abs(d) < 10.0) {\r
+ df = new DecimalFormat("#.##");\r
+ } else if (Math.abs(d) < 10.0) {\r
+ df = new DecimalFormat("#.#");\r
+ } else {\r
+ df = new DecimalFormat("#");\r
+ }\r
+\r
+ return df.format(d) + " " + u.toString();\r
+ }\r
+\r
}\r
import javax.measure.quantity.Pressure;\r
import javax.measure.quantity.Velocity;\r
import javax.measure.unit.SI;\r
-import javax.measure.unit.Unit;\r
import javax.swing.JFrame;\r
import javax.swing.JLabel;\r
import javax.swing.JPanel;\r
text.add(new JLabel("Max Pressure"));\r
\r
text.add(new JLabel(percent + "% " + new String(new char[]{cl}) + "-" +Math.round(averageThrust.doubleValue(SI.NEWTON))));\r
- text.add(new JLabel(approx(ns)));\r
- text.add(new JLabel(approx(isp))); \r
- text.add(new JLabel(approx(maxThrust)));\r
- text.add(new JLabel(approx(averageThrust)));\r
- text.add(new JLabel(approx(maxPressure)));\r
+ text.add(new JLabel(RocketScience.approx(ns)));\r
+ text.add(new JLabel(RocketScience.approx(isp))); \r
+ text.add(new JLabel(RocketScience.approx(maxThrust)));\r
+ text.add(new JLabel(RocketScience.approx(averageThrust)));\r
+ text.add(new JLabel(RocketScience.approx(maxPressure)));\r
\r
add(text, BorderLayout.NORTH);\r
\r
\r
}\r
\r
- @SuppressWarnings("unchecked")\r
- private String approx(Amount a){\r
- Unit u = RocketScience.UnitPreference.preference.getPreferredUnit(a.getUnit());\r
- double d = a.doubleValue(u);\r
- long i = Math.round(d);\r
- return i + " " + u.toString();\r
- }\r
- \r
private class SL extends JSlider implements ChangeListener{\r
private static final long serialVersionUID = 1L;\r
private static final int STEPS = 80;\r
import java.util.Map;\r
import java.util.Vector;\r
\r
+import javax.measure.quantity.Length;\r
import javax.measure.unit.SI;\r
import javax.swing.BoxLayout;\r
import javax.swing.ComboBoxModel;\r
import com.billkuker.rocketry.motorsim.Grain;\r
import com.billkuker.rocketry.motorsim.Motor;\r
import com.billkuker.rocketry.motorsim.Nozzle;\r
+import com.billkuker.rocketry.motorsim.RocketScience;\r
import com.billkuker.rocketry.motorsim.fuel.KNSU;\r
import com.billkuker.rocketry.motorsim.grain.CSlot;\r
import com.billkuker.rocketry.motorsim.grain.CoredCylindricalGrain;\r
final Thread me = this;\r
final JProgressBar bar = new JProgressBar(0, 100);\r
add(bar, BorderLayout.NORTH);\r
+ final JLabel progress = new JLabel();\r
+ add(progress, BorderLayout.CENTER);\r
try {\r
final Burn b = new Burn(motor,\r
new Burn.BurnProgressListener() {\r
@Override\r
public void setProgress(float f) {\r
- bar.setValue((int) (f * 100));\r
+ int pct = (int)(f*100);\r
+ bar.setValue(pct);\r
+ Amount<Length> web = motor.getGrain().webThickness();\r
+ Amount<Length> remaining = web.times(1.0 - f);\r
+ \r
+ progress.setText("Progress: " + pct + "% (" + RocketScience.approx(remaining) + " web thickness remaining)");\r
if ( currentThread != me ){\r
throw new BurnCanceled();\r
}\r