35
36
#ifdef HAVE_CONFIG_H
36
37
# include <config.h>
39
#include <simgear/math/point3d.hxx>
40
#include <simgear/route/waypoint.hxx>
39
41
#include <simgear/compiler.h>
42
#include <simgear/xml/easyxml.hxx>
41
44
#include STL_STRING
45
49
SG_USING_STD(string);
47
52
SG_USING_STD(vector);
55
string _code; // depricated and can be removed
60
typedef map < string, FGAirport > airport_map;
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(const 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(const string&, const 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(const 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(const 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(const string& pos);
201
FGParking() { available = true;};
202
//FGParking(FGParking &other);
203
FGParking(double lat,
210
const string& codes);
211
void setLatitude (const string& lat) { latitude = processPosition(lat); };
212
void setLongitude(const 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 (const string& name) { parkingName = name; };
217
void setType (const string& tpe) { type = tpe; };
218
void setCodes (const 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 (const string& val) { lat = processPosition(val); };
265
void setLongitude(const 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 (const FGTaxiNode& node);
356
void addNodes (FGParkingVec *parkings);
357
void addSegment(const 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];
396
string chooseRunwayFallback();
400
FGAirport(const FGAirport &other);
401
//operator= (FGAirport &other);
402
FGAirport(const string& id, double lon, double lat, double elev, const string& name, bool has_metar);
405
void getActiveRunway(const string& trafficType, int action, string& runway);
406
bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, const string& fltype,
407
const string& acType, const string& airline);
408
void getParking (int id, double *lat, double* lon, double *heading);
409
FGParking *getParking(int i); // { if (i < parkings.size()) return parkings[i]; else return 0;};
410
void releaseParking(int id);
411
string getParkingName(int i);
412
string getId() const { return _id;};
413
const string &getName() const { return _name;};
414
//FGAirport *getAddress() { return this; };
415
//const string &getName() const { return _name;};
417
double getLongitude() const { return _longitude;};
419
double getLatitude() const { return _latitude; };
421
double getElevation() const { return _elevation;};
422
bool getMetar() const { return _has_metar;};
423
FGGroundNetwork* getGroundNetwork() { return &groundNetwork; };
426
void setId(const string& id) { _id = id;};
427
void setMetar(bool value) { _has_metar = value; };
429
void setRwyUse(const FGRunwayPreference& ref);
431
// Some overloaded virtual XMLVisitor members
432
virtual void startXML ();
433
virtual void endXML ();
434
virtual void startElement (const char * name, const XMLAttributes &atts);
435
virtual void endElement (const char * name);
436
virtual void data (const char * s, int len);
437
virtual void pi (const char * target, const char * data);
438
virtual void warning (const char * message, int line, int column);
439
virtual void error (const char * message, int line, int column);
442
typedef map < string, FGAirport* > airport_map;
61
443
typedef airport_map::iterator airport_map_iterator;
62
444
typedef airport_map::const_iterator const_airport_map_iterator;
71
453
airport_map airports_by_id;
72
454
airport_list airports_array;
455
set < string > ai_dirs;
76
459
// Constructor (new)
82
465
// add an entry to the list
83
void add( const string id, const double longitude, const double latitude,
84
const double elevation, const string name, const bool has_metar );
466
void add( const string& id, const double longitude, const double latitude,
467
const double elevation, const string& name, const bool has_metar );
86
469
// search for the specified id.
87
// Returns true if successful, otherwise returns false.
88
// On success, airport data is returned thru "airport" pointer.
89
// "airport" is not changed if "apt" is not found.
90
FGAirport search( const string& id );
470
// Returns NULL if unsucessfull.
471
FGAirport* search( const string& id );
473
// Search for the next airport in ASCII sequence to the supplied id.
474
// eg. id = "KDC" or "KDCA" would both return "KDCA".
475
// If exact = true then only exact matches are returned.
476
// NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
477
// Implementation assumes airport codes are unique.
478
// Returns NULL if unsucessfull.
479
const FGAirport* findFirstById( const string& id, bool exact = false );
92
481
// search for the airport closest to the specified position
93
482
// (currently a linear inefficient search so it's probably not
94
483
// best to use this at runtime.) If with_metar is true, then only
95
484
// return station id's marked as having metar data.
96
FGAirport search( double lon_deg, double lat_deg, bool with_metar );
485
// Returns NULL if fails (unlikely unless none have metar and with_metar spec'd!)
486
FGAirport* search( double lon_deg, double lat_deg, bool with_metar );
100
489
* Return the number of airports in the list.
102
491
int size() const;
106
494
* Return a specific airport, by position.
108
const FGAirport *getAirport( int index ) const;
496
const FGAirport *getAirport( unsigned int index ) const;
112
499
* Mark the specified airport record as not having metar