1 // simple.hxx -- a really simplistic class to manage airport ID,
2 // lat, lon of the center of one of it's runways, and
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
8 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
32 # error This library requires C++
39 #include <simgear/math/point3d.hxx>
40 #include <simgear/route/waypoint.hxx>
41 #include <simgear/compiler.h>
42 #include <simgear/xml/easyxml.hxx>
54 typedef vector<string> stringVec;
55 typedef vector<string>::iterator stringVecIterator;
56 typedef vector<string>::const_iterator stringVecConstIterator;
58 typedef vector<time_t> timeVec;
59 typedef vector<time_t>::const_iterator timeVecConstIterator;
62 /***************************************************************************/
67 stringVec scheduleNames;
72 ScheduleTime(const ScheduleTime &other);
73 ScheduleTime &operator= (const ScheduleTime &other);
74 string getName(time_t dayStart);
77 void addStartTime(time_t time) { start.push_back(time); };
78 void addEndTime (time_t time) { end. push_back(time); };
79 void addScheduleName(string sched) { scheduleNames.push_back(sched); };
80 void setTailWind(double wnd) { tailWind = wnd; };
81 void setCrossWind(double wnd) { tailWind = wnd; };
83 double getTailWind() { return tailWind; };
84 double getCrossWind() { return crssWind; };
87 //typedef vector<ScheduleTime> ScheduleTimes;
88 /*****************************************************************************/
94 stringVec preferredRunways;
97 RunwayList(const RunwayList &other);
98 RunwayList& operator= (const RunwayList &other);
100 void set(string, string);
103 string getType() { return type; };
104 stringVec *getRwyList() { return &preferredRunways; };
105 string getRwyList(int j) { return preferredRunways[j]; };
108 typedef vector<RunwayList> RunwayListVec;
109 typedef vector<RunwayList>::iterator RunwayListVectorIterator;
110 typedef vector<RunwayList>::const_iterator RunwayListVecConstIterator;
113 /*****************************************************************************/
119 RunwayListVec rwyList;
121 //stringVec runwayNames;
126 RunwayGroup(const RunwayGroup &other);
127 RunwayGroup &operator= (const RunwayGroup &other);
129 void setName(string nm) { name = nm; };
130 void add(RunwayList list) { rwyList.push_back(list);};
131 void setActive(string aptId, double windSpeed, double windHeading, double maxTail, double maxCross);
133 int getNrActiveRunways() { return nrActive;};
134 void getActive(int i, string *name, string *type);
136 string getName() { return name; };
137 void clear() { rwyList.clear(); };
138 //void add(string, string);
141 typedef vector<RunwayGroup> PreferenceList;
142 typedef vector<RunwayGroup>::iterator PreferenceListIterator;
143 typedef vector<RunwayGroup>::const_iterator PreferenceListConstIterator;
144 /******************************************************************************/
146 class FGRunwayPreference : public XMLVisitor {
151 ScheduleTime comTimes; // Commercial Traffic;
152 ScheduleTime genTimes; // General Aviation;
153 ScheduleTime milTimes; // Military Traffic;
154 ScheduleTime currTimes; // Needed for parsing;
157 RunwayGroup rwyGroup;
158 PreferenceList preferences;
160 time_t processTime(string);
164 FGRunwayPreference();
165 FGRunwayPreference(const FGRunwayPreference &other);
167 FGRunwayPreference & operator= (const FGRunwayPreference &other);
168 ScheduleTime *getSchedule(const char *trafficType);
169 RunwayGroup *getGroup(const string groupName);
170 bool available() { return initialized; };
172 // Some overloaded virtual XMLVisitor members
173 virtual void startXML ();
174 virtual void endXML ();
175 virtual void startElement (const char * name, const XMLAttributes &atts);
176 virtual void endElement (const char * name);
177 virtual void data (const char * s, int len);
178 virtual void pi (const char * target, const char * data);
179 virtual void warning (const char * message, int line, int column);
180 virtual void error (const char * message, int line, int column);
183 double processPosition(string pos);
201 FGParking() { available = true;};
202 //FGParking(FGParking &other);
203 FGParking(double lat,
211 void setLatitude (string lat) { latitude = processPosition(lat); };
212 void setLongitude(string lon) { longitude = processPosition(lon); };
213 void setHeading (double hdg) { heading = hdg; };
214 void setRadius (double rad) { radius = rad; };
215 void setIndex (int idx) { index = idx; };
216 void setName (string name) { parkingName = name; };
217 void setType (string tpe) { type = tpe; };
218 void setCodes (string codes){ airlineCodes= codes;};
220 bool isAvailable () { return available;};
221 void setAvailable(bool val) { available = val; };
223 double getLatitude () { return latitude; };
224 double getLongitude() { return longitude; };
225 double getHeading () { return heading; };
226 double getRadius () { return radius; };
227 int getIndex () { return index; };
228 string getType () { return type; };
229 string getCodes () { return airlineCodes;};
230 string getName () { return parkingName; };
232 bool operator< (const FGParking &other) const {return radius < other.radius; };
235 typedef vector<FGParking> FGParkingVec;
236 typedef vector<FGParking>::iterator FGParkingVecIterator;
237 typedef vector<FGParking>::const_iterator FGParkingVecConstIterator;
239 class FGTaxiSegment; // forward reference
241 typedef vector<FGTaxiSegment> FGTaxiSegmentVector;
242 typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
243 typedef vector<FGTaxiSegment>::iterator FGTaxiSegmentVectorIterator;
244 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
246 /**************************************************************************************
248 *************************************************************************************/
255 FGTaxiSegmentPointerVector next; // a vector to all the segments leaving from this node
259 FGTaxiNode(double, double, int);
261 void setIndex(int idx) { index = idx;};
262 void setLatitude (double val) { lat = val;};
263 void setLongitude(double val) { lon = val;};
264 void setLatitude (string val) { lat = processPosition(val); };
265 void setLongitude(string val) { lon = processPosition(val); };
266 void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
268 double getLatitude() { return lat;};
269 double getLongitude(){ return lon;};
271 int getIndex() { return index; };
272 FGTaxiNode *getAddress() { return this;};
273 FGTaxiSegmentPointerVectorIterator getBeginRoute() { return next.begin(); };
274 FGTaxiSegmentPointerVectorIterator getEndRoute() { return next.end(); };
277 typedef vector<FGTaxiNode> FGTaxiNodeVector;
278 typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
280 /***************************************************************************************
281 * class FGTaxiSegment
282 **************************************************************************************/
295 FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
297 void setIndex (int val) { index = val; };
298 void setStartNodeRef (int val) { startNode = val; };
299 void setEndNodeRef (int val) { endNode = val; };
301 void setStart(FGTaxiNodeVector *nodes);
302 void setEnd (FGTaxiNodeVector *nodes);
303 void setTrackDistance();
305 FGTaxiNode * getEnd() { return end;};
306 double getLength() { return length; };
307 int getIndex() { return index; };
313 typedef vector<int> intVec;
314 typedef vector<int>::iterator intVecIterator;
321 intVecIterator currNode;
324 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); };
325 FGTaxiRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
326 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
327 bool empty () { return nodes.begin() == nodes.end(); };
330 void first() { currNode = nodes.begin(); };
333 typedef vector<FGTaxiRoute> TaxiRouteVector;
334 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
336 /**************************************************************************************
337 * class FGGroundNetWork
338 *************************************************************************************/
339 class FGGroundNetwork
343 FGTaxiNodeVector nodes;
344 FGTaxiSegmentVector segments;
347 TaxiRouteVector routes;
350 double totalDistance, maxDistance;
355 void addNode (FGTaxiNode node);
356 void addNodes (FGParkingVec *parkings);
357 void addSegment(FGTaxiSegment seg);
360 bool exists() { return hasNetwork; };
361 int findNearestNode(double lat, double lon);
362 FGTaxiNode *findNode(int idx);
363 FGTaxiRoute findShortestRoute(int start, int end);
364 void trace(FGTaxiNode *, int, int, double dist);
368 /***************************************************************************************
370 **************************************************************************************/
371 class FGAirport : public XMLVisitor{
374 double _longitude; // degrees
375 double _latitude; // degrees
376 double _elevation; // ft
377 string _code; // depricated and can be removed
380 FGParkingVec parkings;
381 FGRunwayPreference rwyPrefs;
382 FGGroundNetwork groundNetwork;
385 string prevTrafficType;
389 // Experimental keep a running average of wind dir and speed to prevent
390 // Erratic runway changes.
391 // Note: I should add these to the copy constructor and assigment operator to be
393 double avWindHeading [10];
394 double avWindSpeed [10];
398 FGAirport(const FGAirport &other);
399 //operator= (FGAirport &other);
400 FGAirport(string id, double lon, double lat, double elev, string name, bool has_metar);
403 void getActiveRunway(string trafficType, int action, string *runway);
404 void chooseRunwayFallback(string *runway);
405 bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, string fltype,
406 string acType, string airline);
407 void getParking (int id, double *lat, double* lon, double *heading);
408 FGParking *getParking(int i); // { if (i < parkings.size()) return parkings[i]; else return 0;};
409 void releaseParking(int id);
410 string getParkingName(int i);
411 string getId() const { return _id;};
412 const string &getName() const { return _name;};
413 //FGAirport *getAddress() { return this; };
414 //const string &getName() const { return _name;};
416 double getLongitude() const { return _longitude;};
418 double getLatitude() const { return _latitude; };
420 double getElevation() const { return _elevation;};
421 bool getMetar() const { return _has_metar;};
422 FGGroundNetwork* getGroundNetwork() { return &groundNetwork; };
425 void setId(string id) { _id = id;};
426 void setMetar(bool value) { _has_metar = value; };
428 void setRwyUse(FGRunwayPreference& ref);
430 // Some overloaded virtual XMLVisitor members
431 virtual void startXML ();
432 virtual void endXML ();
433 virtual void startElement (const char * name, const XMLAttributes &atts);
434 virtual void endElement (const char * name);
435 virtual void data (const char * s, int len);
436 virtual void pi (const char * target, const char * data);
437 virtual void warning (const char * message, int line, int column);
438 virtual void error (const char * message, int line, int column);
441 typedef map < string, FGAirport* > airport_map;
442 typedef airport_map::iterator airport_map_iterator;
443 typedef airport_map::const_iterator const_airport_map_iterator;
445 typedef vector < FGAirport * > airport_list;
448 class FGAirportList {
452 airport_map airports_by_id;
453 airport_list airports_array;
454 set < string > ai_dirs;
464 // add an entry to the list
465 void add( const string id, const double longitude, const double latitude,
466 const double elevation, const string name, const bool has_metar );
468 // search for the specified id.
469 // Returns NULL if unsucessfull.
470 FGAirport* search( const string& id );
472 // Search for the next airport in ASCII sequence to the supplied id.
473 // eg. id = "KDC" or "KDCA" would both return "KDCA".
474 // If exact = true then only exact matches are returned.
475 // NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
476 // Implementation assumes airport codes are unique.
477 // Returns NULL if unsucessfull.
478 const FGAirport* findFirstById( const string& id, bool exact = false );
480 // search for the airport closest to the specified position
481 // (currently a linear inefficient search so it's probably not
482 // best to use this at runtime.) If with_metar is true, then only
483 // return station id's marked as having metar data.
484 // Returns NULL if fails (unlikely unless none have metar and with_metar spec'd!)
485 FGAirport* search( double lon_deg, double lat_deg, bool with_metar );
488 * Return the number of airports in the list.
493 * Return a specific airport, by position.
495 const FGAirport *getAirport( unsigned int index ) const;
498 * Mark the specified airport record as not having metar
500 void no_metar( const string &id );
503 * Mark the specified airport record as (yes) having metar
505 void has_metar( const string &id );
510 #endif // _FG_SIMPLE_HXX