]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/awynet.hxx
make attribute strings lowercase with hyphen instead of underscore;
[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 STL_STRING
28 #include <fstream>
29 #include <set>
30 #include <map>
31 #include <vector>
32
33 SG_USING_STD(string);
34 SG_USING_STD(map);
35 SG_USING_STD(set);
36 SG_USING_STD(vector);
37 SG_USING_STD(fstream);
38
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/misc/sgstream.hxx>
41
42
43 //#include "parking.hxx"
44
45 class FGAirway; // forward reference
46
47 typedef vector<FGAirway>  FGAirwayVector;
48 typedef vector<FGAirway *> FGAirwayPointerVector;
49 typedef vector<FGAirway>::iterator FGAirwayVectorIterator;
50 typedef vector<FGAirway*>::iterator FGAirwayPointerVectorIterator;
51
52 /**************************************************************************************
53  * class FGNode
54  *************************************************************************************/
55 class FGNode
56 {
57 private:
58   string ident;
59   double lat;
60   double lon;
61   int index;
62   FGAirwayPointerVector next; // a vector to all the segments leaving from this node
63
64 public:
65   FGNode();
66   FGNode(double lt, double ln, int idx, string id) { lat = lt; lon = ln; index = idx; ident = id;};
67
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); };
74
75   double getLatitude() { return lat;};
76   double getLongitude(){ return lon;};
77
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();   };
83
84   bool matches(string ident, double lat, double lon);
85 };
86
87 typedef vector<FGNode *> FGNodeVector;
88 typedef vector<FGNode *>::iterator FGNodeVectorIterator;
89
90
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;
94
95
96 /***************************************************************************************
97  * class FGAirway
98  **************************************************************************************/
99 class FGAirway
100 {
101 private:
102   string startNode;
103   string endNode;
104   double length;
105   FGNode *start;
106   FGNode *end;
107   int index;
108   int type; // 1=low altitude; 2=high altitude airway
109   int base; // base altitude
110   int top;  // top altitude
111   string name;
112
113 public:
114   FGAirway();
115   FGAirway(FGNode *, FGNode *, int);
116
117   void setIndex        (int val) { index     = val; };
118   void setStartNodeRef (string val) { startNode = val; };
119   void setEndNodeRef   (string val) { endNode   = val; };
120
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;};
127
128   void setTrackDistance();
129
130   FGNode * getEnd() { return end;};
131   double getLength() { if (length == 0) setTrackDistance(); return length; };
132   int getIndex() { return index; };
133   string getName() { return name; };
134
135
136 };
137
138
139 typedef vector<int> intVec;
140 typedef vector<int>::iterator intVecIterator;
141 typedef vector<int>::const_iterator constIntVecIterator;
142
143 class FGAirRoute
144 {
145 private:
146   intVec nodes;
147   double distance;
148   intVecIterator currNode;
149
150 public:
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(); };
155   bool next(int *val);
156
157   void first() { currNode = nodes.begin(); };
158   void add(const FGAirRoute &other);
159   void add(int node) {nodes.push_back(node);};
160
161   friend istream& operator >> (istream& in, FGAirRoute& r);
162 };
163
164 inline istream& operator >> ( istream& in, FGAirRoute& r )
165 {
166   int node;
167   in >> node;
168   r.nodes.push_back(node);
169   //getline( in, n.name );
170   return in;
171 }
172
173 typedef vector<FGAirRoute> AirRouteVector;
174 typedef vector<FGAirRoute>::iterator AirRouteVectorIterator;
175
176 /**************************************************************************************
177  * class FGAirwayNetwork
178  *************************************************************************************/
179 class FGAirwayNetwork
180 {
181 private:
182   bool hasNetwork;
183   node_map        nodesMap;
184   FGNodeVector    nodes;
185   FGAirwayVector segments;
186   //intVec route;
187   intVec traceStack;
188   AirRouteVector routes;
189
190   bool foundRoute;
191   double totalDistance, maxDistance;
192
193 public:
194   FGAirwayNetwork();
195
196   //void addNode   (const FGNode& node);
197   //void addNodes  (FGParkingVec *parkings);
198   void addAirway(const FGAirway& seg);
199
200   void init();
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);
206
207   void load(SGPath path);
208 };
209
210 #endif