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/sgstream.hxx>
36 //#include "parking.hxx"
38 class FGAirway; // forward reference
42 typedef std::vector<FGAirway> FGAirwayVector;
43 typedef std::vector<FGAirway *> FGAirwayPointerVector;
44 typedef std::vector<FGAirway>::iterator FGAirwayVectorIterator;
45 typedef std::vector<FGAirway*>::iterator FGAirwayPointerVectorIterator;
47 /**************************************************************************************
49 *************************************************************************************/
55 SGVec3d cart; // cached cartesian position
57 FGAirwayPointerVector next; // a vector to all the segments leaving from this node
61 FGNode(const SGGeod& aPos, int idx, std::string id);
63 void setIndex(int idx) { index = idx;};
64 void addAirway(FGAirway *segment) { next.push_back(segment); };
66 const SGGeod& getPosition() {return geod;}
67 const SGVec3d& getCart() { return cart; }
68 int getIndex() { return index; };
69 std::string getIdent() { return ident; };
70 FGNode *getAddress() { return this;};
71 FGAirwayPointerVectorIterator getBeginRoute() { return next.begin(); };
72 FGAirwayPointerVectorIterator getEndRoute() { return next.end(); };
74 bool matches(std::string ident, const SGGeod& aPos);
77 typedef std::vector<FGNode *> FGNodeVector;
78 typedef std::vector<FGNode *>::iterator FGNodeVectorIterator;
81 typedef std::map < std::string, FGNode *> node_map;
82 typedef node_map::iterator node_map_iterator;
83 typedef node_map::const_iterator const_node_map_iterator;
86 /***************************************************************************************
88 **************************************************************************************/
92 std::string startNode;
98 int type; // 1=low altitude; 2=high altitude airway
99 int base; // base altitude
100 int top; // top altitude
105 FGAirway(FGNode *, FGNode *, int);
107 void setIndex (int val) { index = val; };
108 void setStartNodeRef (std::string val) { startNode = val; };
109 void setEndNodeRef (std::string val) { endNode = val; };
111 void setStart(node_map *nodes);
112 void setEnd (node_map *nodes);
113 void setType (int tp) { type = tp;};
114 void setBase (int val) { base = val;};
115 void setTop (int val) { top = val;};
116 void setName (std::string val) { name = val;};
118 void setTrackDistance();
120 FGNode * getEnd() { return end;};
121 double getLength() { if (length == 0) setTrackDistance(); return length; };
122 int getIndex() { return index; };
123 std::string getName() { return name; };
129 typedef std::vector<int> intVec;
130 typedef std::vector<int>::iterator intVecIterator;
131 typedef std::vector<int>::const_iterator constIntVecIterator;
138 intVecIterator currNode;
141 FGAirRoute() { distance = 0; currNode = nodes.begin(); };
142 FGAirRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
143 bool operator< (const FGAirRoute &other) const {return distance < other.distance; };
144 bool empty () { return nodes.begin() == nodes.end(); };
147 void first() { currNode = nodes.begin(); };
148 void add(const FGAirRoute &other);
149 void add(int node) {nodes.push_back(node);};
151 friend std::istream& operator >> (std::istream& in, FGAirRoute& r);
154 inline std::istream& operator >> ( std::istream& in, FGAirRoute& r )
158 r.nodes.push_back(node);
159 //getline( in, n.name );
163 typedef std::vector<FGAirRoute> AirRouteVector;
164 typedef std::vector<FGAirRoute>::iterator AirRouteVectorIterator;
166 /**************************************************************************************
167 * class FGAirwayNetwork
168 *************************************************************************************/
169 class FGAirwayNetwork
175 FGAirwayVector segments;
178 AirRouteVector routes;
181 double totalDistance, maxDistance;
187 //void addNode (const FGNode& node);
188 //void addNodes (FGParkingVec *parkings);
189 void addAirway(const FGAirway& seg);
192 bool exists() { return hasNetwork; };
193 int findNearestNode(const SGGeod& aPos);
194 FGNode *findNode(int idx);
195 FGAirRoute findShortestRoute(int start, int end);
196 void trace(FGNode *, int, int, double dist);
198 void load(const SGPath& path);