1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
4 // Written by Durk Talsma, started June 2005.
6 // Copyright (C) 2004 Durk Talsma.
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.
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.
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.
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
28 #include <osg/Geometry>
29 #include <osg/MatrixTransform>
33 #include <simgear/compiler.h>
34 #include <simgear/route/waypoint.hxx>
43 #include "parking.hxx"
44 #include <ATC/trafficcontrol.hxx>
47 class FGTaxiSegment; // forward reference
48 class FGAIFlightPlan; // forward reference
49 class FGAirport; // forward reference
51 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
52 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
54 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
55 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
57 /***************************************************************************************
59 **************************************************************************************/
74 FGTaxiSegment *oppositeDirection;
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),
106 oppositeDirection (other.oppositeDirection)
110 FGTaxiSegment& operator=(const FGTaxiSegment &other)
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;
123 oppositeDirection = other.oppositeDirection;
127 void setIndex (int val) {
130 void setStartNodeRef (int val) {
133 void setEndNodeRef (int val) {
137 void setOpposite(FGTaxiSegment *opp) {
138 oppositeDirection = opp;
141 void setStart(FGTaxiNodeVector *nodes);
142 void setEnd (FGTaxiNodeVector *nodes);
143 void setPushBackType(bool val) {
144 isPushBackRoute = val;
146 void setDimensions(double elevation);
147 void block(time_t time) {
149 if (time < isBlocked) {
156 void unblock(time_t now) {
157 if ((now - isBlocked) > 60)
160 bool hasBlock(time_t now) {
161 return isBlocked ? (isBlocked < now) : 0;
164 FGTaxiNode * getEnd() {
167 FGTaxiNode * getStart() {
176 double getLatitude() {
177 return center.getLatitudeDeg();
179 double getLongitude() {
180 return center.getLongitudeDeg();
182 double getHeading() {
186 return isPushBackRoute;
189 int getPenalty(int nGates);
191 FGTaxiSegment *getAddress() {
195 bool operator<(const FGTaxiSegment &other) const {
196 return index < other.index;
198 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
199 FGTaxiSegment *opposite() {
200 return oppositeDirection;
202 void setCourseDiff(double crse);
212 typedef vector<int> intVec;
213 typedef vector<int>::iterator intVecIterator;
217 /***************************************************************************************
219 **************************************************************************************/
227 intVecIterator currNode;
228 intVecIterator currRoute;
233 currNode = nodes.begin();
234 currRoute = routes.begin();
236 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
240 currNode = nodes.begin();
241 currRoute = routes.begin();
245 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
247 routes = other.routes;
248 distance = other.distance;
249 // depth = other.depth;
250 currNode = nodes.begin();
251 currRoute = routes.begin();
255 FGTaxiRoute(const FGTaxiRoute& copy) :
258 distance(copy.distance),
259 // depth(copy.depth),
260 currNode(nodes.begin()),
261 currRoute(routes.begin())
264 bool operator< (const FGTaxiRoute &other) const {
265 return distance < other.distance;
268 return nodes.begin() == nodes.end();
271 bool next(int *nde, int *rte);
272 void rewind(int legNr);
275 currNode = nodes.begin();
276 currRoute = routes.begin();
282 return nodes.end() - currNode;
285 // int getDepth() { return depth; };
288 typedef vector<FGTaxiRoute> TaxiRouteVector;
289 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
291 /**************************************************************************************
292 * class FGGroundNetWork
293 *************************************************************************************/
294 class FGGroundNetwork : public FGATCController
298 bool networkInitialized;
303 FGTaxiNodeVector nodes;
304 FGTaxiNodeVector pushBackNodes;
305 FGTaxiSegmentVector segments;
308 //intVec routesStack;
309 TaxiRouteVector routes;
310 TrafficVector activeTraffic;
311 TrafficVectorIterator currTraffic;
314 double totalDistance, maxDistance;
315 FGTowerController *towerController;
319 //void printRoutingError(string);
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);
332 void addNode (const FGTaxiNode& node);
333 void addNodes (FGParkingVec *parkings);
334 void addSegment(const FGTaxiSegment& seg);
335 void setVersion (int v) { version = v;};
337 int getVersion() { return version; };
343 void setTowerController(FGTowerController *twrCtrlr) {
344 towerController = twrCtrlr;
347 int findNearestNode(double lat, double lon);
348 int findNearestNode(const SGGeod& aGeod);
349 int findNearestNodeOnRunway(const SGGeod& aGeod);
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);
360 void setParent(FGAirport *par) {
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);
372 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
374 bool checkForCircularWaits(int id);
375 virtual void render(bool);
376 virtual string getName();
377 virtual void update(double dt);
379 void saveElevationCache();
380 void addVersion(int v) {version = v; };