]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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     time_t 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(time_t time) {
148         if (isBlocked) {
149             if (time < isBlocked) {
150                 isBlocked = time;
151             }
152         } else {
153             isBlocked = time;
154         }
155     }
156     void unblock(time_t now) {
157         if ((now - isBlocked) > 60)
158             isBlocked = 0;
159     };
160     bool hasBlock(time_t now) {
161         return isBlocked ? (isBlocked < now) : 0;
162     };
163
164     FGTaxiNode * getEnd() {
165         return end;
166     };
167     FGTaxiNode * getStart() {
168         return start;
169     };
170     double getLength() {
171         return length;
172     };
173     int getIndex() {
174         return index;
175     };
176     double getLatitude()  {
177         return center.getLatitudeDeg();
178     };
179     double getLongitude() {
180         return center.getLongitudeDeg();
181     };
182     double getHeading()   {
183         return heading;
184     };
185     bool isPushBack() {
186         return isPushBackRoute;
187     };
188
189     int getPenalty(int nGates);
190
191     FGTaxiSegment *getAddress() {
192         return this;
193     };
194
195     bool operator<(const FGTaxiSegment &other) const {
196         return index < other.index;
197     };
198     //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
199     FGTaxiSegment *opposite() {
200         return oppositeDirection;
201     };
202     void setCourseDiff(double crse);
203
204
205
206
207 };
208
209
210
211
212 typedef vector<int> intVec;
213 typedef vector<int>::iterator intVecIterator;
214
215
216
217 /***************************************************************************************
218  * class FGTaxiRoute
219  **************************************************************************************/
220 class FGTaxiRoute
221 {
222 private:
223     intVec nodes;
224     intVec routes;
225     double distance;
226 //  int depth;
227     intVecIterator currNode;
228     intVecIterator currRoute;
229
230 public:
231     FGTaxiRoute() {
232         distance = 0;
233         currNode = nodes.begin();
234         currRoute = routes.begin();
235     };
236     FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
237         nodes = nds;
238         routes = rts;
239         distance = dist;
240         currNode = nodes.begin();
241         currRoute = routes.begin();
242 //    depth = dpth;
243     };
244
245     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
246         nodes = other.nodes;
247         routes = other.routes;
248         distance = other.distance;
249 //    depth = other.depth;
250         currNode = nodes.begin();
251         currRoute = routes.begin();
252         return *this;
253     };
254
255     FGTaxiRoute(const FGTaxiRoute& copy) :
256             nodes(copy.nodes),
257             routes(copy.routes),
258             distance(copy.distance),
259 //    depth(copy.depth),
260             currNode(nodes.begin()),
261             currRoute(routes.begin())
262     {};
263
264     bool operator< (const FGTaxiRoute &other) const {
265         return distance < other.distance;
266     };
267     bool empty () {
268         return nodes.begin() == nodes.end();
269     };
270     bool next(int *nde);
271     bool next(int *nde, int *rte);
272     void rewind(int legNr);
273
274     void first() {
275         currNode = nodes.begin();
276         currRoute = routes.begin();
277     };
278     int size() {
279         return nodes.size();
280     };
281     int nodesLeft() {
282         return nodes.end() - currNode;
283     };
284
285 //  int getDepth() { return depth; };
286 };
287
288 typedef vector<FGTaxiRoute> TaxiRouteVector;
289 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
290
291 /**************************************************************************************
292  * class FGGroundNetWork
293  *************************************************************************************/
294 class FGGroundNetwork : public FGATCController
295 {
296 private:
297     bool hasNetwork;
298     bool networkInitialized;
299     time_t nextSave;
300     //int maxDepth;
301     int count;
302     int version;
303     FGTaxiNodeVector    nodes;
304     FGTaxiNodeVector    pushBackNodes;
305     FGTaxiSegmentVector segments;
306     //intVec route;
307     //intVec nodesStack;
308     //intVec routesStack;
309     TaxiRouteVector routes;
310     TrafficVector activeTraffic;
311     TrafficVectorIterator currTraffic;
312
313     bool foundRoute;
314     double totalDistance, maxDistance;
315     FGTowerController *towerController;
316     FGAirport *parent;
317
318
319     //void printRoutingError(string);
320
321     void checkSpeedAdjustment(int id, double lat, double lon,
322                               double heading, double speed, double alt);
323     void checkHoldPosition(int id, double lat, double lon,
324                            double heading, double speed, double alt);
325
326
327
328 public:
329     FGGroundNetwork();
330     ~FGGroundNetwork();
331
332     void addNode   (const FGTaxiNode& node);
333     void addNodes  (FGParkingVec *parkings);
334     void addSegment(const FGTaxiSegment& seg);
335     void setVersion (int v) { version = v;};
336     
337     int getVersion() { return version; };
338
339     void init();
340     bool exists() {
341         return hasNetwork;
342     };
343     void setTowerController(FGTowerController *twrCtrlr) {
344         towerController = twrCtrlr;
345     };
346
347     int findNearestNode(double lat, double lon);
348     int findNearestNode(const SGGeod& aGeod);
349     int findNearestNodeOnRunway(const SGGeod& aGeod);
350
351     FGTaxiNode *findNode(unsigned idx);
352     FGTaxiSegment *findSegment(unsigned idx);
353     FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
354     //void trace(FGTaxiNode *, int, int, double dist);
355
356     int getNrOfNodes() {
357         return nodes.size();
358     };
359
360     void setParent(FGAirport *par) {
361         parent = par;
362     };
363
364     virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
365                                   double lat, double lon, double hdg, double spd, double alt,
366                                   double radius, int leg, FGAIAircraft *aircraft);
367     virtual void signOff(int id);
368     virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
369     virtual bool hasInstruction(int id);
370     virtual FGATCInstruction getInstruction(int id);
371
372     bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
373                                 AtcMsgDir msgDir);
374     bool checkForCircularWaits(int id);
375     virtual void render(bool);
376     virtual string getName();
377     virtual void update(double dt);
378
379     void saveElevationCache();
380     void addVersion(int v) {version = v; };
381 };
382
383
384 #endif