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