]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Merge branch 'next' into durk-atc
[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 #include <simgear/route/waypoint.hxx>
29
30 #include <string>
31 #include <vector>
32
33 using std::string;
34 using std::vector;
35
36 #include "gnnode.hxx"
37 #include "parking.hxx"
38 #include <ATC/trafficcontrol.hxx>
39
40 class FGTaxiSegment; // forward reference
41 class FGAIFlightPlan; // forward reference
42 class FGAirport;      // forward reference
43
44 typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
45 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
46
47 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
48 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
49
50 /***************************************************************************************
51  * class FGTaxiSegment
52  **************************************************************************************/
53 class FGTaxiSegment
54 {
55 private:
56   int startNode;
57   int endNode;
58   double length;
59   double heading;
60   SGGeod center;
61   bool isActive;
62   bool isPushBackRoute;
63   FGTaxiNode *start;
64   FGTaxiNode *end;
65   int index;
66   FGTaxiSegment *oppositeDirection;
67
68  
69
70 public:
71   FGTaxiSegment() :
72       startNode(0),
73       endNode(0),
74       length(0),
75       heading(0),
76       isActive(0),
77       isPushBackRoute(0),
78       start(0),
79       end(0),
80       index(0),
81       oppositeDirection(0)
82   {
83   };
84
85   FGTaxiSegment         (const FGTaxiSegment &other) :
86       startNode         (other.startNode),
87       endNode           (other.endNode),
88       length            (other.length),
89       heading           (other.heading),
90       center            (other.center),
91       isActive          (other.isActive),
92       isPushBackRoute   (other.isPushBackRoute),
93       start             (other.start),
94       end               (other.end),
95       index             (other.index),
96       oppositeDirection (other.oppositeDirection)
97   {
98   };
99
100   FGTaxiSegment& operator=(const FGTaxiSegment &other)
101   {
102       startNode          = other.startNode;
103       endNode            = other.endNode;
104       length             = other.length;
105       heading            = other.heading;
106       center             = other.center;
107       isActive           = other.isActive;
108       isPushBackRoute    = other.isPushBackRoute;
109       start              = other.start;
110       end                = other.end;
111       index              = other.index;
112       oppositeDirection  = other.oppositeDirection;
113       return *this;
114   };
115
116   void setIndex        (int val) { index     = val; };
117   void setStartNodeRef (int val) { startNode = val; };
118   void setEndNodeRef   (int val) { endNode   = val; };
119
120   void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
121
122   void setStart(FGTaxiNodeVector *nodes);
123   void setEnd  (FGTaxiNodeVector *nodes);
124   void setPushBackType(bool val) { isPushBackRoute = val; };
125   void setDimensions(double elevation);
126
127   FGTaxiNode * getEnd() { return end;};
128   FGTaxiNode * getStart() { return start; };
129   double getLength() { return length; };
130   int getIndex() { return index; };
131   double getLatitude()  { return center.getLatitudeDeg();  };
132   double getLongitude() { return center.getLongitudeDeg(); };
133   double getHeading()   { return heading; }; 
134   bool isPushBack() { return isPushBackRoute; };
135
136   int getPenalty(int nGates);
137
138   FGTaxiSegment *getAddress() { return this;};
139
140   bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
141   //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
142   FGTaxiSegment *opposite() { return oppositeDirection; };
143   void setCourseDiff(double crse);
144
145
146   
147 };
148
149
150
151
152 typedef vector<int> intVec;
153 typedef vector<int>::iterator intVecIterator;
154
155
156
157 /***************************************************************************************
158  * class FGTaxiRoute
159  **************************************************************************************/
160 class FGTaxiRoute
161 {
162 private:
163   intVec nodes;
164   intVec routes;
165   double distance;
166 //  int depth;
167   intVecIterator currNode;
168   intVecIterator currRoute;
169
170 public:
171   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
172   FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { 
173     nodes = nds; 
174     routes = rts;
175     distance = dist; 
176     currNode = nodes.begin();
177 //    depth = dpth;
178   };
179
180   FGTaxiRoute& operator= (const FGTaxiRoute &other) {
181     nodes = other.nodes;
182     routes = other.routes;
183     distance = other.distance;
184 //    depth = other.depth;
185     currNode = nodes.begin();
186     currRoute = routes.begin();
187     return *this;
188   };
189
190   FGTaxiRoute(const FGTaxiRoute& copy) :
191     nodes(copy.nodes),
192     routes(copy.routes),
193     distance(copy.distance),
194 //    depth(copy.depth),
195     currNode(nodes.begin()),
196     currRoute(routes.begin())
197   {};
198
199   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
200   bool empty () { return nodes.begin() == nodes.end(); };
201   bool next(int *nde); 
202   bool next(int *nde, int *rte);
203   void rewind(int legNr);
204   
205   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
206   int size() { return nodes.size(); };
207 //  int getDepth() { return depth; };
208 };
209
210 typedef vector<FGTaxiRoute> TaxiRouteVector;
211 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
212
213 /**************************************************************************************
214  * class FGGroundNetWork
215  *************************************************************************************/
216 class FGGroundNetwork : public FGATCController
217 {
218 private:
219   bool hasNetwork;
220   //int maxDepth;
221   int count;
222   FGTaxiNodeVector    nodes;
223   FGTaxiNodeVector    pushBackNodes;
224   FGTaxiSegmentVector segments;
225   //intVec route;
226   //intVec nodesStack;
227   //intVec routesStack;
228   TaxiRouteVector routes;
229   TrafficVector activeTraffic;
230   TrafficVectorIterator currTraffic;
231
232   bool foundRoute;
233   double totalDistance, maxDistance;
234   FGTowerController *towerController;
235   FGAirport *parent;
236
237
238   //void printRoutingError(string);
239
240   void checkSpeedAdjustment(int id, double lat, double lon, 
241                             double heading, double speed, double alt);
242   void checkHoldPosition(int id, double lat, double lon, 
243                          double heading, double speed, double alt);
244
245 public:
246   FGGroundNetwork();
247   ~FGGroundNetwork();
248
249   void addNode   (const FGTaxiNode& node);
250   void addNodes  (FGParkingVec *parkings);
251   void addSegment(const FGTaxiSegment& seg); 
252
253   void init();
254   bool exists() { return hasNetwork; };
255   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
256
257   int findNearestNode(double lat, double lon);
258   int findNearestNode(const SGGeod& aGeod);
259
260   FGTaxiNode *findNode(unsigned idx);
261   FGTaxiSegment *findSegment(unsigned idx);
262   FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
263   //void trace(FGTaxiNode *, int, int, double dist);
264
265   int getNrOfNodes() { return nodes.size(); };
266
267   void setParent(FGAirport *par) { parent = par; };
268
269   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
270                                 double lat, double lon, double hdg, double spd, double alt, 
271                                 double radius, int leg, FGAIAircraft *aircraft);
272   virtual void signOff(int id);
273   virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
274   virtual bool hasInstruction(int id);
275   virtual FGATCInstruction getInstruction(int id);
276
277   bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
278                                AtcMsgDir msgDir);
279   bool checkForCircularWaits(int id);
280   osg::Node* getRenderNode();
281 };
282
283
284 #endif