Made burn ctor not start burn.
[sw/motorsim] / src / com / billkuker / rocketry / motorsim / Burn.java
index d863cd9db5a207a2be1995ecfd76e8f3ccb2eb21..0923394f68b4d3805d266833edeb62424ddb6ee1 100644 (file)
@@ -40,6 +40,9 @@ public class Burn {
        private static Logger log = Logger.getLogger(Burn.class);\r
        protected final Motor motor;\r
        \r
+       private boolean burning = false;\r
+       private boolean done = false;\r
+       \r
        public interface BurnProgressListener{\r
                public void setProgress(float p);\r
        }\r
@@ -64,6 +67,8 @@ public class Burn {
        protected SortedMap<Amount<Duration>,Interval> data = new TreeMap<Amount<Duration>, Interval>();\r
        \r
        public SortedMap<Amount<Duration>,Interval> getData(){\r
+               if ( !done )\r
+                       throw new IllegalStateException("Burn not complete!");\r
                return data;\r
        }\r
        \r
@@ -72,7 +77,7 @@ public class Burn {
        }\r
 \r
        public Amount<Duration> burnTime(){\r
-               return data.lastKey();\r
+               return getData().lastKey();\r
        }\r
        \r
        public Burn(Motor m){\r
@@ -82,21 +87,18 @@ public class Burn {
                        throw new IllegalArgumentException("Invalid Motor: " + e.getMessage());\r
                }\r
                motor = m;\r
-               burn();\r
        }\r
        \r
-       public Burn(Motor m, BurnProgressListener bpl){\r
-               try {\r
-                       m.validate();\r
-               } catch (ValidationException e) {\r
-                       throw new IllegalArgumentException("Invalid Motor: " + e.getMessage());\r
-               }\r
-               motor = m;\r
+       public void addBurnProgressListener( BurnProgressListener bpl ){\r
                bpls.add(bpl);\r
-               burn();\r
        }\r
        \r
-       private void burn(){\r
+       public void burn(){\r
+               synchronized(this){\r
+                       if ( burning )\r
+                               throw new IllegalStateException("Already burning!");\r
+                       burning = true;\r
+               }\r
                log.info("Starting burn...");\r
                int endPressureSteps = 0;\r
                long start = new Date().getTime();\r
@@ -238,6 +240,7 @@ public class Burn {
 \r
                long time = new Date().getTime() - start;\r
                log.info("Burn took " + time + " millis.");\r
+               done = true;\r
        }\r
        \r
        @SuppressWarnings("unchecked")\r
@@ -252,11 +255,11 @@ public class Burn {
        }\r
        \r
        public Amount<Pressure> pressure(Amount<Duration> time){\r
-               return data.get(time).chamberPressure;\r
+               return getData().get(time).chamberPressure;\r
        }\r
        \r
        public Amount<Force> thrust(Amount<Duration> time){\r
-               return data.get(time).thrust;\r
+               return getData().get(time).thrust;\r
        }\r
        \r
        public Amount<Dimensionless> kn(Amount<Length> regression){\r