]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
f4a8dd41fd583cb554fb5fa35474b155b2ee9078
[flightgear.git] / src / Airports / groundnetwork.hxx
1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma, 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
26
27 #include <simgear/compiler.h>
28
29
30 #include STL_STRING
31 #include <vector>
32
33 SG_USING_STD(string);
34 SG_USING_STD(vector);
35
36
37 #include "parking.hxx"
38 //#include <AIModel/AIBase.hxx>
39
40
41
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
44
45 typedef vector<FGTaxiSegment>  FGTaxiSegmentVector;
46 typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
47 typedef vector<FGTaxiSegment>::iterator FGTaxiSegmentVectorIterator;
48 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
49
50 /**************************************************************************************
51  * class FGTaxiNode
52  *************************************************************************************/
53 class FGTaxiNode 
54 {
55 private:
56   double lat;
57   double lon;
58   int index;
59   FGTaxiSegmentPointerVector next; // a vector to all the segments leaving from this node
60   
61 public:
62   FGTaxiNode();
63   FGTaxiNode(double, double, int);
64
65   void setIndex(int idx)                  { index = idx;};
66   void setLatitude (double val)           { lat = val;};
67   void setLongitude(double val)           { lon = val;};
68   void setLatitude (const string& val)           { lat = processPosition(val);  };
69   void setLongitude(const string& val)           { lon = processPosition(val);  };
70   void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
71   
72   double getLatitude() { return lat;};
73   double getLongitude(){ return lon;};
74
75   int getIndex() { return index; };
76   FGTaxiNode *getAddress() { return this;};
77   FGTaxiSegmentPointerVectorIterator getBeginRoute() { return next.begin(); };
78   FGTaxiSegmentPointerVectorIterator getEndRoute()   { return next.end();   }; 
79 };
80
81 typedef vector<FGTaxiNode> FGTaxiNodeVector;
82 typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
83
84 /***************************************************************************************
85  * class FGTaxiSegment
86  **************************************************************************************/
87 class FGTaxiSegment
88 {
89 private:
90   int startNode;
91   int endNode;
92   double length;
93   FGTaxiNode *start;
94   FGTaxiNode *end;
95   int index;
96
97 public:
98   FGTaxiSegment();
99   FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
100
101   void setIndex        (int val) { index     = val; };
102   void setStartNodeRef (int val) { startNode = val; };
103   void setEndNodeRef   (int val) { endNode   = val; };
104
105   void setStart(FGTaxiNodeVector *nodes);
106   void setEnd  (FGTaxiNodeVector *nodes);
107   void setTrackDistance();
108
109   FGTaxiNode * getEnd() { return end;};
110   double getLength() { return length; };
111   int getIndex() { return index; };
112
113  FGTaxiSegment *getAddress() { return this;};
114
115   
116 };
117
118
119 typedef vector<int> intVec;
120 typedef vector<int>::iterator intVecIterator;
121
122 /***************************************************************************************
123  * class FGTaxiRoute
124  **************************************************************************************/
125 class FGTaxiRoute
126 {
127 private:
128   intVec nodes;
129   intVec routes;
130   double distance;
131   intVecIterator currNode;
132   intVecIterator currRoute;
133
134 public:
135   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
136   FGTaxiRoute(intVec nds, intVec rts, double dist) { 
137     nodes = nds; 
138     routes = rts;
139     distance = dist; 
140     currNode = nodes.begin();
141   };
142   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
143   bool empty () { return nodes.begin() == nodes.end(); };
144   bool next(int *nde); 
145   bool next(int *nde, int *rte);
146   void rewind(int legNr);
147   
148   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
149   int size() { return nodes.size(); };
150 };
151
152 typedef vector<FGTaxiRoute> TaxiRouteVector;
153 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
154
155 /**************************************************************************************
156  * class FGATCInstruction
157  * like class FGATC Controller, this class definition should go into its own file
158  * and or directory... For now, just testing this stuff out though...
159  *************************************************************************************/
160 class FGATCInstruction
161 {
162 private:
163   bool holdPattern;
164   bool holdPosition;
165   bool changeSpeed;
166   bool changeHeading;
167   bool changeAltitude;
168
169   double speed;
170   double heading;
171   double alt;
172 public:
173
174   FGATCInstruction();
175   bool hasInstruction   ();
176   bool getHoldPattern   () { return holdPattern;    };
177   bool getHoldPosition  () { return holdPosition;   };
178   bool getChangeSpeed   () { return changeSpeed;    };
179   bool getChangeHeading () { return changeHeading;  };
180   bool getChangeAltitude() { return changeAltitude; };
181
182   double getSpeed       () { return speed; };
183   double getHeading     () { return heading; };
184   double getAlt         () { return alt; };
185
186   void setHoldPattern   (bool val) { holdPattern    = val; };
187   void setHoldPosition  (bool val) { holdPosition   = val; };
188   void setChangeSpeed   (bool val) { changeSpeed    = val; };
189   void setChangeHeading (bool val) { changeHeading  = val; };
190   void setChangeAltitude(bool val) { changeAltitude = val; };
191
192   void setSpeed       (double val) { speed   = val; };
193   void setHeading     (double val) { heading = val; };
194   void setAlt         (double val) { alt     = val; };
195 };
196
197
198 /**************************************************************************************
199  * class FGTrafficRecord
200  *************************************************************************************/
201 class FGTrafficRecord
202 {
203 private:
204   int id, waitsForId;
205   int currentPos;
206   intVec intentions;
207   FGATCInstruction instruction;
208   double latitude, longitude, heading, speed, altitude, radius;
209   
210   
211 public:
212   FGTrafficRecord() {};
213   
214   void setId(int val)  { id = val; };
215   void setRadius(double rad) { radius = rad;};
216   void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
217   int getId() { return id;};
218   FGATCInstruction getInstruction() { return instruction;};
219   bool hasInstruction() { return instruction.hasInstruction(); };
220   void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
221   bool checkPositionAndIntentions(FGTrafficRecord &other);
222   
223   double getLatitude () { return latitude ; };
224   double getLongitude() { return longitude; };
225   double getHeading  () { return heading  ; };
226   double getSpeed    () { return speed    ; };
227   double getAltitude () { return altitude ; };
228   double getRadius   () { return radius   ; };
229
230   int getWaitsForId  () { return waitsForId; };
231
232   void setSpeedAdjustment(double spd) { instruction.setChangeSpeed(true); 
233                                         instruction.setSpeed(spd); };
234   void setHeadingAdjustment(double heading) { instruction.setChangeHeading(true);
235                                               instruction.setHeading(heading); };
236   void clearSpeedAdjustment  () { instruction.setChangeSpeed  (false); };
237   void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
238
239   bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
240
241   void setWaitsForId(int id) { waitsForId = id; };
242
243 };
244
245 typedef vector<FGTrafficRecord> TrafficVector;
246 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
247
248
249
250
251 /**************************************************************************************
252  * class FGATCController
253  * NOTE: this class serves as an abstraction layer for all sorts of ATC controller,
254  * Ground and air, so eventually it should move to its own file / directory. 
255  *************************************************************************************/
256 class FGATCController
257 {
258 private:
259   double dt_count;
260 public:
261   FGATCController() { dt_count = 0;};
262   virtual ~FGATCController() {};
263   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
264                                 double lat, double lon,
265                                 double hdg, double spd, double alt, double radius) = 0;
266   virtual void             signOff(int id) = 0;
267   virtual void             update(int id, double lat, double lon, 
268                                   double heading, double speed, double alt) = 0;
269   virtual bool             hasInstruction(int id) = 0;
270   virtual FGATCInstruction getInstruction(int id) = 0;
271
272   double getDt() { return dt_count; };
273   void   setDt(double dt) { dt_count = dt;};
274 };
275
276
277
278 /**************************************************************************************
279  * class FGGroundNetWork
280  *************************************************************************************/
281 class FGGroundNetwork : public FGATCController
282 {
283 private:
284   bool hasNetwork;
285   FGTaxiNodeVector    nodes;
286   FGTaxiSegmentVector segments;
287   //intVec route;
288   intVec nodesStack;
289   intVec routesStack;
290   TaxiRouteVector routes;
291   TrafficVector activeTraffic;
292   TrafficVectorIterator currTraffic;
293   
294   bool foundRoute;
295   double totalDistance, maxDistance;
296
297   void printRoutingError(string);
298   
299 public:
300   FGGroundNetwork();
301
302   void addNode   (const FGTaxiNode& node);
303   void addNodes  (FGParkingVec *parkings);
304   void addSegment(const FGTaxiSegment& seg); 
305
306   void init();
307   bool exists() { return hasNetwork; };
308   int findNearestNode(double lat, double lon);
309   FGTaxiNode *findNode(int idx);
310   FGTaxiSegment *findSegment(int idx);
311   FGTaxiRoute findShortestRoute(int start, int end);
312   void trace(FGTaxiNode *, int, int, double dist);
313
314   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
315                                 double lat, double lon, double hdg, double spd, double alt, double radius);
316   virtual void signOff(int id);
317   virtual void update(int id, double lat, double lon, double heading, double speed, double alt);
318   virtual bool hasInstruction(int id);
319   virtual FGATCInstruction getInstruction(int id);
320 };
321
322
323 #endif