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