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_
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/misc/sgstream.hxx>
37 //#include "parking.hxx"
39 class FGAirway; // forward reference
41 typedef std::vector<FGAirway> FGAirwayVector;
42 typedef std::vector<FGAirway *> FGAirwayPointerVector;
43 typedef std::vector<FGAirway>::iterator FGAirwayVectorIterator;
44 typedef std::vector<FGAirway*>::iterator FGAirwayPointerVectorIterator;
46 /**************************************************************************************
48 *************************************************************************************/
56 FGAirwayPointerVector next; // a vector to all the segments leaving from this node
60 FGNode(double lt, double ln, int idx, std::string id) { lat = lt; lon = ln; index = idx; ident = id;};
62 void setIndex(int idx) { index = idx;};
63 void setLatitude (double val) { lat = val;};
64 void setLongitude(double val) { lon = val;};
65 //void setLatitude (const std::string& val) { lat = processPosition(val); };
66 //void setLongitude(const std::string& val) { lon = processPosition(val); };
67 void addAirway(FGAirway *segment) { next.push_back(segment); };
69 double getLatitude() { return lat;};
70 double getLongitude(){ return lon;};
72 int getIndex() { return index; };
73 std::string getIdent() { return ident; };
74 FGNode *getAddress() { return this;};
75 FGAirwayPointerVectorIterator getBeginRoute() { return next.begin(); };
76 FGAirwayPointerVectorIterator getEndRoute() { return next.end(); };
78 bool matches(std::string ident, double lat, double lon);
81 typedef std::vector<FGNode *> FGNodeVector;
82 typedef std::vector<FGNode *>::iterator FGNodeVectorIterator;
85 typedef std::map < std::string, FGNode *> node_map;
86 typedef node_map::iterator node_map_iterator;
87 typedef node_map::const_iterator const_node_map_iterator;
90 /***************************************************************************************
92 **************************************************************************************/
96 std::string startNode;
102 int type; // 1=low altitude; 2=high altitude airway
103 int base; // base altitude
104 int top; // top altitude
109 FGAirway(FGNode *, FGNode *, int);
111 void setIndex (int val) { index = val; };
112 void setStartNodeRef (std::string val) { startNode = val; };
113 void setEndNodeRef (std::string val) { endNode = val; };
115 void setStart(node_map *nodes);
116 void setEnd (node_map *nodes);
117 void setType (int tp) { type = tp;};
118 void setBase (int val) { base = val;};
119 void setTop (int val) { top = val;};
120 void setName (std::string val) { name = val;};
122 void setTrackDistance();
124 FGNode * getEnd() { return end;};
125 double getLength() { if (length == 0) setTrackDistance(); return length; };
126 int getIndex() { return index; };
127 std::string getName() { return name; };
133 typedef std::vector<int> intVec;
134 typedef std::vector<int>::iterator intVecIterator;
135 typedef std::vector<int>::const_iterator constIntVecIterator;
142 intVecIterator currNode;
145 FGAirRoute() { distance = 0; currNode = nodes.begin(); };
146 FGAirRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
147 bool operator< (const FGAirRoute &other) const {return distance < other.distance; };
148 bool empty () { return nodes.begin() == nodes.end(); };
151 void first() { currNode = nodes.begin(); };
152 void add(const FGAirRoute &other);
153 void add(int node) {nodes.push_back(node);};
155 friend std::istream& operator >> (std::istream& in, FGAirRoute& r);
158 inline std::istream& operator >> ( std::istream& in, FGAirRoute& r )
162 r.nodes.push_back(node);
163 //getline( in, n.name );
167 typedef std::vector<FGAirRoute> AirRouteVector;
168 typedef std::vector<FGAirRoute>::iterator AirRouteVectorIterator;
170 /**************************************************************************************
171 * class FGAirwayNetwork
172 *************************************************************************************/
173 class FGAirwayNetwork
179 FGAirwayVector segments;
182 AirRouteVector routes;
185 double totalDistance, maxDistance;
191 //void addNode (const FGNode& node);
192 //void addNodes (FGParkingVec *parkings);
193 void addAirway(const FGAirway& seg);
196 bool exists() { return hasNetwork; };
197 int findNearestNode(double lat, double lon);
198 FGNode *findNode(int idx);
199 FGAirRoute findShortestRoute(int start, int end);
200 void trace(FGNode *, int, int, double dist);
202 void load(SGPath path);