Updated French translations
[debian/openrocket] / src / net / sf / openrocket / simulation / SimulationStatus.java
1 package net.sf.openrocket.simulation;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Set;
6
7 import net.sf.openrocket.aerodynamics.WarningSet;
8 import net.sf.openrocket.motor.MotorInstanceConfiguration;
9 import net.sf.openrocket.rocketcomponent.Configuration;
10 import net.sf.openrocket.rocketcomponent.RecoveryDevice;
11 import net.sf.openrocket.util.BugException;
12 import net.sf.openrocket.util.Coordinate;
13 import net.sf.openrocket.util.Monitorable;
14 import net.sf.openrocket.util.MonitorableSet;
15 import net.sf.openrocket.util.Quaternion;
16
17 /**
18  * A holder class for the dynamic status during the rocket's flight.
19  * 
20  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
21  */
22 public class SimulationStatus implements Cloneable, Monitorable {
23         
24         /*
25          * NOTE!  All fields must be added to copyFrom() method!!
26          */
27
28         private SimulationConditions simulationConditions;
29         private Configuration configuration;
30         private MotorInstanceConfiguration motorConfiguration;
31         private FlightDataBranch flightData;
32         
33         private double time;
34         
35         private double previousTimeStep;
36         
37         private Coordinate position;
38         private Coordinate velocity;
39         
40         private Quaternion orientation;
41         private Coordinate rotationVelocity;
42         
43         private double effectiveLaunchRodLength;
44         
45
46         /** Nanosecond time when the simulation was started. */
47         private long simulationStartWallTime = Long.MIN_VALUE;
48         
49
50         /** Set to true when a motor has ignited. */
51         private boolean motorIgnited = false;
52         
53         /** Set to true when the rocket has risen from the ground. */
54         private boolean liftoff = false;
55         
56         /** Set to true when the launch rod has been cleared. */
57         private boolean launchRodCleared = false;
58         
59         /** Set to true when apogee has been detected. */
60         private boolean apogeeReached = false;
61         
62         /** Contains a list of deployed recovery devices. */
63         private MonitorableSet<RecoveryDevice> deployedRecoveryDevices = new MonitorableSet<RecoveryDevice>();
64         
65         /** The flight event queue */
66         private final EventQueue eventQueue = new EventQueue();
67         
68         private WarningSet warnings;
69         
70         /** Available for special purposes by the listeners. */
71         private final Map<String, Object> extraData = new HashMap<String, Object>();
72         
73
74         private int modID = 0;
75         private int modIDadd = 0;
76         
77         
78         public void setSimulationTime(double time) {
79                 this.time = time;
80                 this.modID++;
81         }
82         
83         
84         public double getSimulationTime() {
85                 return time;
86         }
87         
88         
89         public void setConfiguration(Configuration configuration) {
90                 if (this.configuration != null)
91                         this.modIDadd += this.configuration.getModID();
92                 this.modID++;
93                 this.configuration = configuration;
94         }
95         
96         
97         public Configuration getConfiguration() {
98                 return configuration;
99         }
100         
101         
102         public void setMotorConfiguration(MotorInstanceConfiguration motorConfiguration) {
103                 if (this.motorConfiguration != null)
104                         this.modIDadd += this.motorConfiguration.getModID();
105                 this.modID++;
106                 this.motorConfiguration = motorConfiguration;
107         }
108         
109         
110         public MotorInstanceConfiguration getMotorConfiguration() {
111                 return motorConfiguration;
112         }
113         
114         
115         public void setFlightData(FlightDataBranch flightData) {
116                 if (this.flightData != null)
117                         this.modIDadd += this.flightData.getModID();
118                 this.modID++;
119                 this.flightData = flightData;
120         }
121         
122         
123         public FlightDataBranch getFlightData() {
124                 return flightData;
125         }
126         
127         
128         public double getPreviousTimeStep() {
129                 return previousTimeStep;
130         }
131         
132         
133         public void setPreviousTimeStep(double previousTimeStep) {
134                 this.previousTimeStep = previousTimeStep;
135                 this.modID++;
136         }
137         
138         
139         public void setRocketPosition(Coordinate position) {
140                 this.position = position;
141                 this.modID++;
142         }
143         
144         
145         public Coordinate getRocketPosition() {
146                 return position;
147         }
148         
149         
150         public void setRocketVelocity(Coordinate velocity) {
151                 this.velocity = velocity;
152                 this.modID++;
153         }
154         
155         
156         public Coordinate getRocketVelocity() {
157                 return velocity;
158         }
159         
160         
161
162
163
164         public Quaternion getRocketOrientationQuaternion() {
165                 return orientation;
166         }
167         
168         
169         public void setRocketOrientationQuaternion(Quaternion orientation) {
170                 this.orientation = orientation;
171                 this.modID++;
172         }
173         
174         
175         public Coordinate getRocketRotationVelocity() {
176                 return rotationVelocity;
177         }
178         
179         
180         public void setRocketRotationVelocity(Coordinate rotation) {
181                 this.rotationVelocity = rotation;
182         }
183         
184         
185         public void setEffectiveLaunchRodLength(double effectiveLaunchRodLength) {
186                 this.effectiveLaunchRodLength = effectiveLaunchRodLength;
187                 this.modID++;
188         }
189         
190         
191         public double getEffectiveLaunchRodLength() {
192                 return effectiveLaunchRodLength;
193         }
194         
195         
196         public void setSimulationStartWallTime(long simulationStartWallTime) {
197                 this.simulationStartWallTime = simulationStartWallTime;
198                 this.modID++;
199         }
200         
201         
202         public long getSimulationStartWallTime() {
203                 return simulationStartWallTime;
204         }
205         
206         
207         public void setMotorIgnited(boolean motorIgnited) {
208                 this.motorIgnited = motorIgnited;
209                 this.modID++;
210         }
211         
212         
213         public boolean isMotorIgnited() {
214                 return motorIgnited;
215         }
216         
217         
218         public void setLiftoff(boolean liftoff) {
219                 this.liftoff = liftoff;
220                 this.modID++;
221         }
222         
223         
224         public boolean isLiftoff() {
225                 return liftoff;
226         }
227         
228         
229         public void setLaunchRodCleared(boolean launchRod) {
230                 this.launchRodCleared = launchRod;
231                 this.modID++;
232         }
233         
234         
235         public boolean isLaunchRodCleared() {
236                 return launchRodCleared;
237         }
238         
239         
240         public void setApogeeReached(boolean apogeeReached) {
241                 this.apogeeReached = apogeeReached;
242                 this.modID++;
243         }
244         
245         
246         public boolean isApogeeReached() {
247                 return apogeeReached;
248         }
249         
250         
251         public Set<RecoveryDevice> getDeployedRecoveryDevices() {
252                 return deployedRecoveryDevices;
253         }
254         
255         
256         public void setWarnings(WarningSet warnings) {
257                 if (this.warnings != null)
258                         this.modIDadd += this.warnings.getModID();
259                 this.modID++;
260                 this.warnings = warnings;
261         }
262         
263         
264         public WarningSet getWarnings() {
265                 return warnings;
266         }
267         
268         
269         public EventQueue getEventQueue() {
270                 return eventQueue;
271         }
272         
273         
274         public void setSimulationConditions(SimulationConditions simulationConditions) {
275                 if (this.simulationConditions != null)
276                         this.modIDadd += this.simulationConditions.getModID();
277                 this.modID++;
278                 this.simulationConditions = simulationConditions;
279         }
280         
281         
282         public SimulationConditions getSimulationConditions() {
283                 return simulationConditions;
284         }
285         
286         
287         /**
288          * Store extra data available for use by simulation listeners.  The data can be retrieved
289          * using {@link #getExtraData(String)}.
290          * 
291          * @param key           the data key
292          * @param value         the value to store
293          */
294         public void putExtraData(String key, Object value) {
295                 extraData.put(key, value);
296         }
297         
298         /**
299          * Retrieve extra data stored by simulation listeners.  This data map is initially empty.
300          * Data can be stored using {@link #putExtraData(String, Object)}.
301          * 
302          * @param key           the data key to retrieve
303          * @return                      the data, or <code>null</code> if nothing has been set for the key
304          */
305         public Object getExtraData(String key) {
306                 return extraData.get(key);
307         }
308         
309         
310         /**
311          * Returns a copy of this object.  The general purpose is that the conditions,
312          * rocket configuration, flight data etc. point to the same objects.  However,
313          * subclasses are allowed to deep-clone specific objects, such as those pertaining
314          * to the current orientation of the rocket.  The purpose is to allow creating intermediate
315          * copies of this object used during step computation.
316          * 
317          * TODO: HIGH: Deep cloning required for branch saving.
318          */
319         @Override
320         public SimulationStatus clone() {
321                 try {
322                         SimulationStatus clone = (SimulationStatus) super.clone();
323                         return clone;
324                 } catch (CloneNotSupportedException e) {
325                         throw new BugException("CloneNotSupportedException?!?", e);
326                 }
327         }
328         
329         
330         /**
331          * Copies the data from the provided object to this object.  Most included object are
332          * deep-cloned, except for the flight data object.
333          * 
334          * @param orig  the object from which to copy
335          */
336         public void copyFrom(SimulationStatus orig) {
337                 this.simulationConditions = orig.simulationConditions.clone();
338                 this.configuration = orig.configuration.clone();
339                 this.motorConfiguration = orig.motorConfiguration.clone();
340                 this.flightData = orig.flightData;
341                 this.time = orig.time;
342                 this.previousTimeStep = orig.previousTimeStep;
343                 this.position = orig.position;
344                 this.velocity = orig.velocity;
345                 this.orientation = orig.orientation;
346                 this.rotationVelocity = orig.rotationVelocity;
347                 this.effectiveLaunchRodLength = orig.effectiveLaunchRodLength;
348                 this.simulationStartWallTime = orig.simulationStartWallTime;
349                 this.motorIgnited = orig.motorIgnited;
350                 this.liftoff = orig.liftoff;
351                 this.launchRodCleared = orig.launchRodCleared;
352                 this.apogeeReached = orig.apogeeReached;
353                 
354                 this.deployedRecoveryDevices.clear();
355                 this.deployedRecoveryDevices.addAll(orig.deployedRecoveryDevices);
356                 
357                 this.eventQueue.clear();
358                 this.eventQueue.addAll(orig.eventQueue);
359                 
360                 this.warnings = orig.warnings;
361                 
362                 this.extraData.clear();
363                 this.extraData.putAll(orig.extraData);
364                 
365                 this.modID = orig.modID;
366                 this.modIDadd = orig.modIDadd;
367         }
368         
369         
370         @Override
371         public int getModID() {
372                 return (modID + modIDadd + simulationConditions.getModID() + configuration.getModID() +
373                                 motorConfiguration.getModID() + flightData.getModID() + deployedRecoveryDevices.getModID() +
374                                 eventQueue.getModID() + warnings.getModID());
375         }
376         
377
378 }