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