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);
157 FGTaxiNode * getEnd() {
160 FGTaxiNode * getStart() {
169 double getLatitude() {
170 return center.getLatitudeDeg();
172 double getLongitude() {
173 return center.getLongitudeDeg();
175 double getHeading() {
179 return isPushBackRoute;
182 int getPenalty(int nGates);
184 FGTaxiSegment *getAddress() {
188 bool operator<(const FGTaxiSegment &other) const {
189 return index < other.index;
191 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
192 FGTaxiSegment *opposite() {
193 return oppositeDirection;
195 void setCourseDiff(double crse);
205 typedef vector<int> intVec;
206 typedef vector<int>::iterator intVecIterator;
210 /***************************************************************************************
212 **************************************************************************************/
220 intVecIterator currNode;
221 intVecIterator currRoute;
226 currNode = nodes.begin();
227 currRoute = routes.begin();
229 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
233 currNode = nodes.begin();
234 currRoute = routes.begin();
238 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
240 routes = other.routes;
241 distance = other.distance;
242 // depth = other.depth;
243 currNode = nodes.begin();
244 currRoute = routes.begin();
248 FGTaxiRoute(const FGTaxiRoute& copy) :
251 distance(copy.distance),
252 // depth(copy.depth),
253 currNode(nodes.begin()),
254 currRoute(routes.begin())
257 bool operator< (const FGTaxiRoute &other) const {
258 return distance < other.distance;
261 return nodes.begin() == nodes.end();
264 bool next(int *nde, int *rte);
265 void rewind(int legNr);
268 currNode = nodes.begin();
269 currRoute = routes.begin();
275 return nodes.end() - currNode;
278 // int getDepth() { return depth; };
281 typedef vector<FGTaxiRoute> TaxiRouteVector;
282 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
284 /**************************************************************************************
285 * class FGGroundNetWork
286 *************************************************************************************/
287 class FGGroundNetwork : public FGATCController
291 bool networkInitialized;
296 FGTaxiNodeVector nodes;
297 FGTaxiNodeVector pushBackNodes;
298 FGTaxiSegmentVector segments;
301 //intVec routesStack;
302 TaxiRouteVector routes;
303 TrafficVector activeTraffic;
304 TrafficVectorIterator currTraffic;
307 double totalDistance, maxDistance;
308 FGTowerController *towerController;
312 //void printRoutingError(string);
314 void checkSpeedAdjustment(int id, double lat, double lon,
315 double heading, double speed, double alt);
316 void checkHoldPosition(int id, double lat, double lon,
317 double heading, double speed, double alt);
325 void addNode (const FGTaxiNode& node);
326 void addNodes (FGParkingVec *parkings);
327 void addSegment(const FGTaxiSegment& seg);
328 void setVersion (int v) { version = v;};
330 int getVersion() { return version; };
336 void setTowerController(FGTowerController *twrCtrlr) {
337 towerController = twrCtrlr;
340 int findNearestNode(double lat, double lon);
341 int findNearestNode(const SGGeod& aGeod);
342 int findNearestNodeOnRunway(const SGGeod& aGeod);
344 FGTaxiNode *findNode(unsigned idx);
345 FGTaxiSegment *findSegment(unsigned idx);
346 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
347 //void trace(FGTaxiNode *, int, int, double dist);
353 void setParent(FGAirport *par) {
357 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
358 double lat, double lon, double hdg, double spd, double alt,
359 double radius, int leg, FGAIAircraft *aircraft);
360 virtual void signOff(int id);
361 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
362 virtual bool hasInstruction(int id);
363 virtual FGATCInstruction getInstruction(int id);
365 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
367 bool checkForCircularWaits(int id);
368 virtual void render(bool);
369 virtual string getName();
370 virtual void update(double dt);
372 void saveElevationCache();
373 void addVersion(int v) {version = v; };