1617709007569657ecf5c6b254a4eee737d7ce56
[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 modID = 0;
61         private int modIDadd = 0;
62         
63         
64
65
66         public AerodynamicCalculator getAerodynamicCalculator() {
67                 return aerodynamicCalculator;
68         }
69         
70         
71         public void setAerodynamicCalculator(AerodynamicCalculator aerodynamicCalculator) {
72                 if (this.aerodynamicCalculator != null)
73                         this.modIDadd += this.aerodynamicCalculator.getModID();
74                 this.modID++;
75                 this.aerodynamicCalculator = aerodynamicCalculator;
76         }
77         
78         
79         public MassCalculator getMassCalculator() {
80                 return massCalculator;
81         }
82         
83         
84         public void setMassCalculator(MassCalculator massCalculator) {
85                 if (this.massCalculator != null)
86                         this.modIDadd += this.massCalculator.getModID();
87                 this.modID++;
88                 this.massCalculator = massCalculator;
89         }
90         
91         
92         public Rocket getRocket() {
93                 return rocket;
94         }
95         
96         
97         public void setRocket(Rocket rocket) {
98                 if (this.rocket != null)
99                         this.modIDadd += this.rocket.getModID();
100                 this.modID++;
101                 this.rocket = rocket;
102         }
103         
104         
105         public String getMotorConfigurationID() {
106                 return motorID;
107         }
108         
109         
110         public void setMotorConfigurationID(String motorID) {
111                 this.motorID = motorID;
112                 this.modID++;
113         }
114         
115         
116         public double getLaunchRodLength() {
117                 return launchRodLength;
118         }
119         
120         
121         public void setLaunchRodLength(double launchRodLength) {
122                 this.launchRodLength = launchRodLength;
123                 this.modID++;
124         }
125         
126         
127         public double getLaunchRodAngle() {
128                 return launchRodAngle;
129         }
130         
131         
132         public void setLaunchRodAngle(double launchRodAngle) {
133                 this.launchRodAngle = launchRodAngle;
134                 this.modID++;
135         }
136         
137         
138         public double getLaunchRodDirection() {
139                 return launchRodDirection;
140         }
141         
142         
143         public void setLaunchRodDirection(double launchRodDirection) {
144                 this.launchRodDirection = launchRodDirection;
145                 this.modID++;
146         }
147         
148         
149         public double getLaunchAltitude() {
150                 return launchAltitude;
151         }
152         
153         
154         public void setLaunchAltitude(double launchAltitude) {
155                 this.launchAltitude = launchAltitude;
156                 this.modID++;
157         }
158         
159         
160         public double getLaunchLatitude() {
161                 return launchLatitude;
162         }
163         
164         
165         public void setLaunchLatitude(double launchLatitude) {
166                 this.launchLatitude = launchLatitude;
167                 this.modID++;
168         }
169         
170         
171         public WindModel getWindModel() {
172                 return windModel;
173         }
174         
175         
176         public void setWindModel(WindModel windModel) {
177                 if (this.windModel != null)
178                         this.modIDadd += this.windModel.getModID();
179                 this.modID++;
180                 this.windModel = windModel;
181         }
182         
183         
184         public AtmosphericModel getAtmosphericModel() {
185                 return atmosphericModel;
186         }
187         
188         
189         public void setAtmosphericModel(AtmosphericModel atmosphericModel) {
190                 if (this.atmosphericModel != null)
191                         this.modIDadd += this.atmosphericModel.getModID();
192                 this.modID++;
193                 this.atmosphericModel = atmosphericModel;
194         }
195         
196         
197         public GravityModel getGravityModel() {
198                 return gravityModel;
199         }
200         
201         
202         public void setGravityModel(GravityModel gravityModel) {
203                 if (this.gravityModel != null)
204                         this.modIDadd += this.gravityModel.getModID();
205                 this.modID++;
206                 this.gravityModel = gravityModel;
207         }
208         
209         
210         public double getTimeStep() {
211                 return timeStep;
212         }
213         
214         
215         public void setTimeStep(double timeStep) {
216                 this.timeStep = timeStep;
217                 this.modID++;
218         }
219         
220         
221         public double getMaximumAngleStep() {
222                 return maximumAngleStep;
223         }
224         
225         
226         public void setMaximumAngleStep(double maximumAngle) {
227                 this.maximumAngleStep = maximumAngle;
228                 this.modID++;
229         }
230         
231         
232         public boolean isCalculateExtras() {
233                 return calculateExtras;
234         }
235         
236         
237         public void setCalculateExtras(boolean calculateExtras) {
238                 this.calculateExtras = calculateExtras;
239                 this.modID++;
240         }
241         
242         
243         // TODO: HIGH: Make cleaner
244         public List<SimulationListener> getSimulationListenerList() {
245                 return simulationListeners;
246         }
247         
248         
249         @Override
250         public int getModID() {
251                 return (modID + modIDadd + rocket.getModID() + windModel.getModID() + atmosphericModel.getModID() +
252                                 gravityModel.getModID() + aerodynamicCalculator.getModID() + massCalculator.getModID());
253         }
254         
255         
256         @Override
257         public SimulationConditions clone() {
258                 try {
259                         // TODO: HIGH: Deep clone models
260                         return (SimulationConditions) super.clone();
261                 } catch (CloneNotSupportedException e) {
262                         throw new BugException(e);
263                 }
264         }
265         
266 }