]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Make it optional whether a dialog can be dragged or not.
[flightgear.git] / src / Airports / simple.hxx
1 // simple.hxx -- a really simplistic class to manage airport ID,
2 //                 lat, lon of the center of one of it's runways, and 
3 //                 elevation in feet.
4 //
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25
26
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #ifdef HAVE_CONFIG_H
37 #  include <config.h>
38 #endif
39
40 #include <simgear/compiler.h>
41 #include <simgear/xml/easyxml.hxx>
42
43 #include STL_STRING
44 #include <map>
45 #include <vector>
46
47 SG_USING_STD(string);
48 SG_USING_STD(map);
49 SG_USING_STD(vector);
50
51 typedef vector<string> stringVec;
52 typedef vector<string>::iterator stringVecIterator;
53 typedef vector<string>::const_iterator stringVecConstIterator;
54
55 typedef vector<time_t> timeVec;
56 typedef vector<time_t>::const_iterator timeVecConstIterator;
57 /***************************************************************************/
58 class ScheduleTime {
59 private:
60   timeVec   start;
61   timeVec   end;
62   stringVec scheduleNames;
63   double tailWind;
64   double crssWind;
65 public:
66   ScheduleTime() {};
67   ScheduleTime(const ScheduleTime &other);
68   ScheduleTime &operator= (const ScheduleTime &other);
69   string getName(time_t dayStart);
70
71   void clear();
72   void addStartTime(time_t time)     { start.push_back(time);            };
73   void addEndTime  (time_t time)     { end.  push_back(time);            };
74   void addScheduleName(string sched) { scheduleNames.push_back(sched);   };
75   void setTailWind(double wnd)  { tailWind = wnd;                        };
76   void setCrossWind(double wnd) { tailWind = wnd;                        };
77
78   double getTailWind()  { return tailWind;                               };
79   double getCrossWind() { return crssWind;                               };
80 };
81
82 //typedef vector<ScheduleTime> ScheduleTimes;
83 /*****************************************************************************/
84
85 class RunwayList
86 {
87 private:
88   string type;
89   stringVec preferredRunways;
90 public:
91   RunwayList() {};
92   RunwayList(const RunwayList &other);
93   RunwayList& operator= (const RunwayList &other);
94
95   void set(string, string);
96   void clear();
97
98   string getType() { return type; };
99   stringVec *getRwyList() { return &preferredRunways;    };
100   string getRwyList(int j) { return preferredRunways[j]; };
101 };
102
103 typedef vector<RunwayList> RunwayListVec;
104 typedef vector<RunwayList>::iterator RunwayListVectorIterator;
105 typedef vector<RunwayList>::const_iterator RunwayListVecConstIterator;
106
107
108 /*****************************************************************************/
109
110 class RunwayGroup
111 {
112 private:
113   string name;
114   RunwayListVec rwyList;
115   int active;
116   //stringVec runwayNames;
117   int choice[2];
118   int nrActive;
119 public:
120   RunwayGroup() {};
121   RunwayGroup(const RunwayGroup &other);
122   RunwayGroup &operator= (const RunwayGroup &other);
123
124   void setName(string nm) { name = nm;                };
125   void add(RunwayList list) { rwyList.push_back(list);};
126   void setActive(string aptId, double windSpeed, double windHeading, double maxTail, double maxCross);
127
128   int getNrActiveRunways() { return nrActive;};
129   void getActive(int i, string *name, string *type);
130
131   string getName() { return name; };
132   void clear() { rwyList.clear(); }; 
133   //void add(string, string);
134 };
135
136 typedef vector<RunwayGroup> PreferenceList;
137 typedef vector<RunwayGroup>::iterator PreferenceListIterator;
138 typedef vector<RunwayGroup>::const_iterator PreferenceListConstIterator;
139 /******************************************************************************/
140
141 class FGRunwayPreference  : public XMLVisitor {
142 private:
143   string value;
144   string scheduleName;
145
146   ScheduleTime comTimes; // Commercial Traffic;
147   ScheduleTime genTimes; // General Aviation;
148   ScheduleTime milTimes; // Military Traffic;
149   ScheduleTime currTimes; // Needed for parsing;
150
151   RunwayList  rwyList;
152   RunwayGroup rwyGroup;
153   PreferenceList preferences;
154
155   time_t processTime(string);
156   bool initialized;
157
158 public:
159   FGRunwayPreference();
160   FGRunwayPreference(const FGRunwayPreference &other);
161   
162   FGRunwayPreference & operator= (const FGRunwayPreference &other);
163   ScheduleTime *getSchedule(const char *trafficType);
164   RunwayGroup *getGroup(const string groupName);
165   bool available() { return initialized; };
166
167  // Some overloaded virtual XMLVisitor members
168   virtual void startXML (); 
169   virtual void endXML   ();
170   virtual void startElement (const char * name, const XMLAttributes &atts);
171   virtual void endElement (const char * name);
172   virtual void data (const char * s, int len);
173   virtual void pi (const char * target, const char * data);
174   virtual void warning (const char * message, int line, int column);
175   virtual void error (const char * message, int line, int column);
176 };
177
178 class FGParking {
179 private:
180   double latitude;
181   double longitude;
182   double heading;
183   double radius;
184   int index;
185   string parkingName;
186   string type;
187   string airlineCodes;
188  
189
190   bool available;
191
192   double processPosition(string pos);
193
194 public:
195   FGParking() { available = true;};
196   //FGParking(FGParking &other);
197   FGParking(double lat,
198             double lon,
199             double hdg,
200             double rad,
201             int idx,
202             string name,
203             string tpe,
204             string codes);
205   void setLatitude (string lat)  { latitude    = processPosition(lat);  };
206   void setLongitude(string lon)  { longitude   = processPosition(lon);  };
207   void setHeading  (double hdg)  { heading     = hdg;  };
208   void setRadius   (double rad)  { radius      = rad;  };
209   void setIndex    (int    idx)  { index       = idx;  };
210   void setName     (string name) { parkingName = name; };
211   void setType     (string tpe)  { type        = tpe;  };
212   void setCodes    (string codes){ airlineCodes= codes;};
213
214   bool isAvailable ()         { return available;};
215   void setAvailable(bool val) { available = val; };
216   
217   double getLatitude () { return latitude;    };
218   double getLongitude() { return longitude;   };
219   double getHeading  () { return heading;     };
220   double getRadius   () { return radius;      };
221   int    getIndex    () { return index;       };
222   string getType     () { return type;        };
223   string getCodes    () { return airlineCodes;};
224   string getName     () { return parkingName; };
225
226   bool operator< (const FGParking &other) const {return radius < other.radius; };
227 };
228
229 typedef vector<FGParking> FGParkingVec;
230 typedef vector<FGParking>::iterator FGParkingVecIterator;
231 typedef vector<FGParking>::const_iterator FGParkingVecConstIterator;
232
233
234 class FGAirport : public XMLVisitor{
235 private:
236   string _id;
237   double _longitude;
238   double _latitude;
239   double _elevation;
240   string _code;               // depricated and can be removed
241   string _name;
242   bool _has_metar;
243   FGParkingVec parkings;
244   FGRunwayPreference rwyPrefs;
245
246  time_t lastUpdate;
247   string prevTrafficType;
248   stringVec landing;
249   stringVec takeoff;
250
251   // Experimental keep a running average of wind dir and speed to prevent
252   // Erratic runway changes. 
253   // Note: I should add these to the copy constructor and assigment operator to be
254   // constistent
255   double avWindHeading [10];
256   double avWindSpeed   [10];
257
258 public:
259   FGAirport();
260   FGAirport(const FGAirport &other);
261   //operator= (FGAirport &other);
262   FGAirport(string id, double lon, double lat, double elev, string name, bool has_metar);
263   void getActiveRunway(string trafficType, int action, string *runway);
264   void chooseRunwayFallback(string *runway);
265   bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, string fltype, 
266                            string acType, string airline);
267   void getParking         (int id, double *lat, double* lon, double *heading);
268   FGParking *getParking(int i); // { if (i < parkings.size()) return parkings[i]; else return 0;};
269   void releaseParking(int id);
270   string getParkingName(int i); 
271   const string getId() const { return _id;};
272   const string &getName() const { return _name;};
273   FGAirport *getAddress() { return this; };
274   double getLongitude() { return _longitude;};
275   double getLatitude()  { return _latitude; };
276   double getElevation() { return _elevation;};
277   bool   getMetar()     { return _has_metar;};
278   
279
280   void setId(string id) { _id = id;};
281   void setMetar(bool value) { _has_metar = value; };
282
283   void setRwyUse(FGRunwayPreference& ref);
284
285  // Some overloaded virtual XMLVisitor members
286   virtual void startXML (); 
287   virtual void endXML   ();
288   virtual void startElement (const char * name, const XMLAttributes &atts);
289   virtual void endElement (const char * name);
290   virtual void data (const char * s, int len);
291   virtual void pi (const char * target, const char * data);
292   virtual void warning (const char * message, int line, int column);
293   virtual void error (const char * message, int line, int column);
294 };
295
296 typedef map < string, FGAirport > airport_map;
297 typedef airport_map::iterator airport_map_iterator;
298 typedef airport_map::const_iterator const_airport_map_iterator;
299
300 typedef vector < FGAirport * > airport_list;
301
302
303 class FGAirportList {
304
305 private:
306
307     airport_map airports_by_id;
308     airport_list airports_array;
309
310 public:
311
312     // Constructor (new)
313     FGAirportList() {}
314
315     // Destructor
316     ~FGAirportList();
317
318     // add an entry to the list
319     void add( const string id, const double longitude, const double latitude,
320               const double elevation, const string name, const bool has_metar );
321
322     // search for the specified id.
323     // Returns true if successful, otherwise returns false.
324     // On success, airport data is returned thru "airport" pointer.
325     // "airport" is not changed if "apt" is not found.
326     FGAirport search( const string& id );
327
328     // search for the airport closest to the specified position
329     // (currently a linear inefficient search so it's probably not
330     // best to use this at runtime.)  If with_metar is true, then only
331     // return station id's marked as having metar data.
332     FGAirport search( double lon_deg, double lat_deg, bool with_metar );
333
334     // search and return a pointer;
335     FGAirport* search( const string& id, FGAirport *result);
336
337     /**
338      * Return the number of airports in the list.
339      */
340     int size() const;
341
342
343     /**
344      * Return a specific airport, by position.
345      */
346     const FGAirport *getAirport( int index ) const;
347
348
349     /**
350      * Mark the specified airport record as not having metar
351      */
352     void no_metar( const string &id );
353
354     /**
355      * Mark the specified airport record as (yes) having metar
356      */
357     void has_metar( const string &id );
358
359 };
360
361
362 #endif // _FG_SIMPLE_HXX
363
364