1 // airwaynet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
4 // Written by Durk Talsma. Based upon the ground netword code, started June 2005.
6 // Copyright (C) 2004 Durk Talsma.
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifndef _AIRWAYNETWORK_HXX_
25 #define _AIRWAYNETWORK_HXX_
37 SG_USING_STD(fstream);
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/misc/sgstream.hxx>
43 //#include "parking.hxx"
45 class FGAirway; // forward reference
47 typedef vector<FGAirway> FGAirwayVector;
48 typedef vector<FGAirway *> FGAirwayPointerVector;
49 typedef vector<FGAirway>::iterator FGAirwayVectorIterator;
50 typedef vector<FGAirway*>::iterator FGAirwayPointerVectorIterator;
52 /**************************************************************************************
54 *************************************************************************************/
62 FGAirwayPointerVector next; // a vector to all the segments leaving from this node
66 FGNode(double lt, double ln, int idx, string id) { lat = lt; lon = ln; index = idx; ident = id;};
68 void setIndex(int idx) { index = idx;};
69 void setLatitude (double val) { lat = val;};
70 void setLongitude(double val) { lon = val;};
71 //void setLatitude (const string& val) { lat = processPosition(val); };
72 //void setLongitude(const string& val) { lon = processPosition(val); };
73 void addAirway(FGAirway *segment) { next.push_back(segment); };
75 double getLatitude() { return lat;};
76 double getLongitude(){ return lon;};
78 int getIndex() { return index; };
79 string getIdent() { return ident; };
80 FGNode *getAddress() { return this;};
81 FGAirwayPointerVectorIterator getBeginRoute() { return next.begin(); };
82 FGAirwayPointerVectorIterator getEndRoute() { return next.end(); };
84 bool matches(string ident, double lat, double lon);
87 typedef vector<FGNode *> FGNodeVector;
88 typedef vector<FGNode *>::iterator FGNodeVectorIterator;
91 typedef map < string, FGNode *> node_map;
92 typedef node_map::iterator node_map_iterator;
93 typedef node_map::const_iterator const_node_map_iterator;
96 /***************************************************************************************
98 **************************************************************************************/
108 int type; // 1=low altitude; 2=high altitude airway
109 int base; // base altitude
110 int top; // top altitude
115 FGAirway(FGNode *, FGNode *, int);
117 void setIndex (int val) { index = val; };
118 void setStartNodeRef (string val) { startNode = val; };
119 void setEndNodeRef (string val) { endNode = val; };
121 void setStart(node_map *nodes);
122 void setEnd (node_map *nodes);
123 void setType (int tp) { type = tp;};
124 void setBase (int val) { base = val;};
125 void setTop (int val) { top = val;};
126 void setName (string val) { name = val;};
128 void setTrackDistance();
130 FGNode * getEnd() { return end;};
131 double getLength() { if (length == 0) setTrackDistance(); return length; };
132 int getIndex() { return index; };
133 string getName() { return name; };
139 typedef vector<int> intVec;
140 typedef vector<int>::iterator intVecIterator;
141 typedef vector<int>::const_iterator constIntVecIterator;
148 intVecIterator currNode;
151 FGAirRoute() { distance = 0; currNode = nodes.begin(); };
152 FGAirRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
153 bool operator< (const FGAirRoute &other) const {return distance < other.distance; };
154 bool empty () { return nodes.begin() == nodes.end(); };
157 void first() { currNode = nodes.begin(); };
158 void add(const FGAirRoute &other);
159 void add(int node) {nodes.push_back(node);};
161 friend istream& operator >> (istream& in, FGAirRoute& r);
164 inline istream& operator >> ( istream& in, FGAirRoute& r )
168 r.nodes.push_back(node);
169 //getline( in, n.name );
173 typedef vector<FGAirRoute> AirRouteVector;
174 typedef vector<FGAirRoute>::iterator AirRouteVectorIterator;
176 /**************************************************************************************
177 * class FGAirwayNetwork
178 *************************************************************************************/
179 class FGAirwayNetwork
185 FGAirwayVector segments;
188 AirRouteVector routes;
191 double totalDistance, maxDistance;
196 //void addNode (const FGNode& node);
197 //void addNodes (FGParkingVec *parkings);
198 void addAirway(const FGAirway& seg);
201 bool exists() { return hasNetwork; };
202 int findNearestNode(double lat, double lon);
203 FGNode *findNode(int idx);
204 FGAirRoute findShortestRoute(int start, int end);
205 void trace(FGNode *, int, int, double dist);
207 void load(SGPath path);