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