]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/awynet.hxx
Directly associate runways objects with their ILS navrecord (if one exists)
[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   SGGeod geod;
54   int index;
55   FGAirwayPointerVector next; // a vector to all the segments leaving from this node
56
57 public:
58   FGNode();
59   FGNode(double lt, double ln, int idx, std::string id);
60
61   void setIndex(int idx)                  { index = idx;};
62   void addAirway(FGAirway *segment) { next.push_back(segment); };
63
64   double getLatitude() { return geod.getLatitudeDeg();};
65   double getLongitude(){ return geod.getLongitudeDeg();};
66
67   const SGGeod& getPosition() {return geod;}
68
69   int getIndex() { return index; };
70   std::string getIdent() { return ident; };
71   FGNode *getAddress() { return this;};
72   FGAirwayPointerVectorIterator getBeginRoute() { return next.begin(); };
73   FGAirwayPointerVectorIterator getEndRoute()   { return next.end();   };
74
75   bool matches(std::string ident, double lat, double lon);
76 };
77
78 typedef std::vector<FGNode *> FGNodeVector;
79 typedef std::vector<FGNode *>::iterator FGNodeVectorIterator;
80
81
82 typedef std::map < std::string, FGNode *> node_map;
83 typedef node_map::iterator node_map_iterator;
84 typedef node_map::const_iterator const_node_map_iterator;
85
86
87 /***************************************************************************************
88  * class FGAirway
89  **************************************************************************************/
90 class FGAirway
91 {
92 private:
93   std::string startNode;
94   std::string endNode;
95   double length;
96   FGNode *start;
97   FGNode *end;
98   int index;
99   int type; // 1=low altitude; 2=high altitude airway
100   int base; // base altitude
101   int top;  // top altitude
102   std::string name;
103
104 public:
105   FGAirway();
106   FGAirway(FGNode *, FGNode *, int);
107
108   void setIndex        (int val) { index     = val; };
109   void setStartNodeRef (std::string val) { startNode = val; };
110   void setEndNodeRef   (std::string val) { endNode   = val; };
111
112   void setStart(node_map *nodes);
113   void setEnd  (node_map *nodes);
114   void setType (int tp) { type = tp;};
115   void setBase (int val) { base = val;};
116   void setTop  (int val) { top  = val;};
117   void setName (std::string val) { name = val;};
118
119   void setTrackDistance();
120
121   FGNode * getEnd() { return end;};
122   double getLength() { if (length == 0) setTrackDistance(); return length; };
123   int getIndex() { return index; };
124   std::string getName() { return name; };
125
126
127 };
128
129
130 typedef std::vector<int> intVec;
131 typedef std::vector<int>::iterator intVecIterator;
132 typedef std::vector<int>::const_iterator constIntVecIterator;
133
134 class FGAirRoute
135 {
136 private:
137   intVec nodes;
138   double distance;
139   intVecIterator currNode;
140
141 public:
142   FGAirRoute() { distance = 0; currNode = nodes.begin(); };
143   FGAirRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
144   bool operator< (const FGAirRoute &other) const {return distance < other.distance; };
145   bool empty () { return nodes.begin() == nodes.end(); };
146   bool next(int *val);
147
148   void first() { currNode = nodes.begin(); };
149   void add(const FGAirRoute &other);
150   void add(int node) {nodes.push_back(node);};
151
152   friend std::istream& operator >> (std::istream& in, FGAirRoute& r);
153 };
154
155 inline std::istream& operator >> ( std::istream& in, FGAirRoute& r )
156 {
157   int node;
158   in >> node;
159   r.nodes.push_back(node);
160   //getline( in, n.name );
161   return in;
162 }
163
164 typedef std::vector<FGAirRoute> AirRouteVector;
165 typedef std::vector<FGAirRoute>::iterator AirRouteVectorIterator;
166
167 /**************************************************************************************
168  * class FGAirwayNetwork
169  *************************************************************************************/
170 class FGAirwayNetwork
171 {
172 private:
173   bool hasNetwork;
174   node_map        nodesMap;
175   FGNodeVector    nodes;
176   FGAirwayVector segments;
177   //intVec route;
178   intVec traceStack;
179   AirRouteVector routes;
180
181   bool foundRoute;
182   double totalDistance, maxDistance;
183
184 public:
185   FGAirwayNetwork();
186   ~FGAirwayNetwork();
187
188   //void addNode   (const FGNode& node);
189   //void addNodes  (FGParkingVec *parkings);
190   void addAirway(const FGAirway& seg);
191
192   void init();
193   bool exists() { return hasNetwork; };
194   int findNearestNode(double lat, double lon);
195   FGNode *findNode(int idx);
196   FGAirRoute findShortestRoute(int start, int end);
197   void trace(FGNode *, int, int, double dist);
198
199   void load(SGPath path);
200 };
201
202 #endif