create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / simulation / SimulationConditions.java
1 package net.sf.openrocket.simulation;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
7 import net.sf.openrocket.document.Simulation;
8 import net.sf.openrocket.masscalc.MassCalculator;
9 import net.sf.openrocket.models.atmosphere.AtmosphericModel;
10 import net.sf.openrocket.models.gravity.GravityModel;
11 import net.sf.openrocket.models.wind.WindModel;
12 import net.sf.openrocket.rocketcomponent.Rocket;
13 import net.sf.openrocket.simulation.listeners.SimulationListener;
14 import net.sf.openrocket.util.BugException;
15 import net.sf.openrocket.util.GeodeticComputationStrategy;
16 import net.sf.openrocket.util.Monitorable;
17 import net.sf.openrocket.util.WorldCoordinate;
18
19 /**
20  * A holder class for the simulation conditions.  These include conditions that do not change
21  * during the flight of a rocket, for example launch rod parameters, atmospheric models,
22  * aerodynamic calculators etc.
23  * 
24  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
25  */
26 public class SimulationConditions implements Monitorable, Cloneable {
27         
28         private Rocket rocket;
29         private String motorID = null;
30         
31         private Simulation simulation; // The parent simulation 
32
33         private double launchRodLength = 1;
34         
35         /** Launch rod angle >= 0, radians from vertical */
36         private double launchRodAngle = 0;
37         
38         /** Launch rod direction, 0 = upwind, PI = downwind. */
39         private double launchRodDirection = 0;
40         
41         // TODO: Depreciate these and use worldCoordinate only.
42         //private double launchAltitude = 0;
43         //private double launchLatitude = 45;
44         //private double launchLongitude = 0;
45         private WorldCoordinate launchSite = new WorldCoordinate(0, 0, 0);
46         private GeodeticComputationStrategy geodeticComputation = GeodeticComputationStrategy.SPHERICAL;
47         
48
49         private WindModel windModel;
50         private AtmosphericModel atmosphericModel;
51         private GravityModel gravityModel;
52         
53         private AerodynamicCalculator aerodynamicCalculator;
54         private MassCalculator massCalculator;
55         
56
57         private double timeStep = RK4SimulationStepper.RECOMMENDED_TIME_STEP;
58         private double maximumAngleStep = RK4SimulationStepper.RECOMMENDED_ANGLE_STEP;
59         
60         /* Whether to calculate additional data or only primary simulation figures */
61         private boolean calculateExtras = true;
62         
63
64         private List<SimulationListener> simulationListeners = new ArrayList<SimulationListener>();
65         
66
67         private int randomSeed = 0;
68         
69         private int modID = 0;
70         private int modIDadd = 0;
71         
72         
73
74
75         public AerodynamicCalculator getAerodynamicCalculator() {
76                 return aerodynamicCalculator;
77         }
78         
79         
80         public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) {
81                 if (this.aerodynamicCalculator != null)
82                         this.modIDadd += this.aerodynamicCalculator.getModID();
83                 this.modID++;
84                 this.aerodynamicCalculator = aerodynamicCalculator;
85         }
86         
87         public MassCalculator getMassCalculator() {
88                 return massCalculator;
89         }
90         
91         
92         public void setMassCalculator(MassCalculator massCalculator) {
93                 if (this.massCalculator != null)
94                         this.modIDadd += this.massCalculator.getModID();
95                 this.modID++;
96                 this.massCalculator = massCalculator;
97         }
98         
99         
100         public Rocket getRocket() {
101                 return rocket;
102         }
103         
104         
105         public void setRocket(Rocket rocket) {
106                 if (this.rocket != null)
107                         this.modIDadd += this.rocket.getModID();
108                 this.modID++;
109                 this.rocket = rocket;
110         }
111         
112         
113         public String getMotorConfigurationID() {
114                 return motorID;
115         }
116         
117         
118         public void setMotorConfigurationID(String motorID) {
119                 this.motorID = motorID;
120                 this.modID++;
121         }
122         
123         
124         public double getLaunchRodLength() {
125                 return launchRodLength;
126         }
127         
128         
129         public void setLaunchRodLength(double launchRodLength) {
130                 this.launchRodLength = launchRodLength;
131                 this.modID++;
132         }
133         
134         
135         public double getLaunchRodAngle() {
136                 return launchRodAngle;
137         }
138         
139         
140         public void setLaunchRodAngle(double launchRodAngle) {
141                 this.launchRodAngle = launchRodAngle;
142                 this.modID++;
143         }
144         
145         
146         public double getLaunchRodDirection() {
147                 return launchRodDirection;
148         }
149         
150         
151         public void setLaunchRodDirection(double launchRodDirection) {
152                 this.launchRodDirection = launchRodDirection;
153                 this.modID++;
154         }
155         
156         
157         public WorldCoordinate getLaunchSite() {
158                 return this.launchSite;
159         }
160         
161         public void setLaunchSite(WorldCoordinate site) {
162                 if (this.launchSite.equals(site))
163                         return;
164                 this.launchSite = site;
165                 this.modID++;
166         }
167         
168         
169         public GeodeticComputationStrategy getGeodeticComputation() {
170                 return geodeticComputation;
171         }
172         
173         public void setGeodeticComputation(GeodeticComputationStrategy geodeticComputation) {
174                 if (this.geodeticComputation == geodeticComputation)
175                         return;
176                 if (geodeticComputation == null) {
177                         throw new IllegalArgumentException("strategy cannot be null");
178                 }
179                 this.geodeticComputation = geodeticComputation;
180                 this.modID++;
181         }
182         
183         
184         public WindModel getWindModel() {
185                 return windModel;
186         }
187         
188         
189         public void setWindModel(WindModel windModel) {
190                 if (this.windModel != null)
191                         this.modIDadd += this.windModel.getModID();
192                 this.modID++;
193                 this.windModel = windModel;
194         }
195         
196         
197         public AtmosphericModel getAtmosphericModel() {
198                 return atmosphericModel;
199         }
200         
201         
202         public void setAtmosphericModel(AtmosphericModel atmosphericModel) {
203                 if (this.atmosphericModel != null)
204                         this.modIDadd += this.atmosphericModel.getModID();
205                 this.modID++;
206                 this.atmosphericModel = atmosphericModel;
207         }
208         
209         
210         public GravityModel getGravityModel() {
211                 return gravityModel;
212         }
213         
214         
215         public void setGravityModel(GravityModel gravityModel) {
216                 //if (this.gravityModel != null)
217                 //      this.modIDadd += this.gravityModel.getModID();
218                 this.modID++;
219                 this.gravityModel = gravityModel;
220         }
221         
222         
223         public double getTimeStep() {
224                 return timeStep;
225         }
226         
227         
228         public void setTimeStep(double timeStep) {
229                 this.timeStep = timeStep;
230                 this.modID++;
231         }
232         
233         
234         public double getMaximumAngleStep() {
235                 return maximumAngleStep;
236         }
237         
238         
239         public void setMaximumAngleStep(double maximumAngle) {
240                 this.maximumAngleStep = maximumAngle;
241                 this.modID++;
242         }
243         
244         
245         public boolean isCalculateExtras() {
246                 return calculateExtras;
247         }
248         
249         
250         public void setCalculateExtras(boolean calculateExtras) {
251                 this.calculateExtras = calculateExtras;
252                 this.modID++;
253         }
254         
255         
256
257         public int getRandomSeed() {
258                 return randomSeed;
259         }
260         
261         
262         public void setRandomSeed(int randomSeed) {
263                 this.randomSeed = randomSeed;
264                 this.modID++;
265         }
266         
267         public void setSimulation(Simulation sim) {
268                 this.simulation = sim;
269         }
270
271         public Simulation getSimulation(){
272                 return this.simulation;
273         }
274         
275         // TODO: HIGH: Make cleaner
276         public List<SimulationListener> getSimulationListenerList() {
277                 return simulationListeners;
278         }
279         
280         
281         @Override
282         public int getModID() {
283                 //return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
284                 //              gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID());
285                 return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
286                                 aerodynamicCalculator.getModID() + massCalculator.getModID());
287         }
288         
289         
290         @Override
291         public SimulationConditions clone() {
292                 try {
293                         // TODO: HIGH: Deep clone models
294                         return (SimulationConditions) super.clone();
295                 } catch (CloneNotSupportedException e) {
296                         throw new BugException(e);
297                 }
298         }
299         
300 }