]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/awynet.hxx
92ca9c36812877bcab0c5fa5f463d196a993aebc
[flightgear.git] / src / Navaids / awynet.hxx
1 // airwaynet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma. Based upon the ground netword code, started June 2005.
5 //
6 // Copyright (C) 2004 Durk Talsma.
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23
24 #ifndef _AIRWAYNETWORK_HXX_
25 #define _AIRWAYNETWORK_HXX_
26
27 #include <string>
28 #include <istream>
29 #include <set>
30 #include <map>
31 #include <vector>
32
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/misc/sgstream.hxx>
35
36
37 //#include "parking.hxx"
38
39 class FGAirway; // forward reference
40
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;
45
46 /**************************************************************************************
47  * class FGNode
48  *************************************************************************************/
49 class FGNode
50 {
51 private:
52   std::string ident;
53   double lat;
54   double lon;
55   int index;
56   FGAirwayPointerVector next; // a vector to all the segments leaving from this node
57
58 public:
59   FGNode();
60   FGNode(double lt, double ln, int idx, std::string id) { lat = lt; lon = ln; index = idx; ident = id;};
61
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); };
68
69   double getLatitude() { return lat;};
70   double getLongitude(){ return lon;};
71
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();   };
77
78   bool matches(std::string ident, double lat, double lon);
79 };
80
81 typedef std::vector<FGNode *> FGNodeVector;
82 typedef std::vector<FGNode *>::iterator FGNodeVectorIterator;
83
84
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;
88
89
90 /***************************************************************************************
91  * class FGAirway
92  **************************************************************************************/
93 class FGAirway
94 {
95 private:
96   std::string startNode;
97   std::string endNode;
98   double length;
99   FGNode *start;
100   FGNode *end;
101   int index;
102   int type; // 1=low altitude; 2=high altitude airway
103   int base; // base altitude
104   int top;  // top altitude
105   std::string name;
106
107 public:
108   FGAirway();
109   FGAirway(FGNode *, FGNode *, int);
110
111   void setIndex        (int val) { index     = val; };
112   void setStartNodeRef (std::string val) { startNode = val; };
113   void setEndNodeRef   (std::string val) { endNode   = val; };
114
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;};
121
122   void setTrackDistance();
123
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; };
128
129
130 };
131
132
133 typedef std::vector<int> intVec;
134 typedef std::vector<int>::iterator intVecIterator;
135 typedef std::vector<int>::const_iterator constIntVecIterator;
136
137 class FGAirRoute
138 {
139 private:
140   intVec nodes;
141   double distance;
142   intVecIterator currNode;
143
144 public:
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(); };
149   bool next(int *val);
150
151   void first() { currNode = nodes.begin(); };
152   void add(const FGAirRoute &other);
153   void add(int node) {nodes.push_back(node);};
154
155   friend std::istream& operator >> (std::istream& in, FGAirRoute& r);
156 };
157
158 inline std::istream& operator >> ( std::istream& in, FGAirRoute& r )
159 {
160   int node;
161   in >> node;
162   r.nodes.push_back(node);
163   //getline( in, n.name );
164   return in;
165 }
166
167 typedef std::vector<FGAirRoute> AirRouteVector;
168 typedef std::vector<FGAirRoute>::iterator AirRouteVectorIterator;
169
170 /**************************************************************************************
171  * class FGAirwayNetwork
172  *************************************************************************************/
173 class FGAirwayNetwork
174 {
175 private:
176   bool hasNetwork;
177   node_map        nodesMap;
178   FGNodeVector    nodes;
179   FGAirwayVector segments;
180   //intVec route;
181   intVec traceStack;
182   AirRouteVector routes;
183
184   bool foundRoute;
185   double totalDistance, maxDistance;
186
187 public:
188   FGAirwayNetwork();
189   ~FGAirwayNetwork();
190
191   //void addNode   (const FGNode& node);
192   //void addNodes  (FGParkingVec *parkings);
193   void addAirway(const FGAirway& seg);
194
195   void init();
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);
201
202   void load(SGPath path);
203 };
204
205 #endif