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