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>
42 #include "parking.hxx"
43 #include <ATC/trafficcontrol.hxx>
46 class FGTaxiSegment; // forward reference
47 class FGAIFlightPlan; // forward reference
48 class FGAirport; // forward reference
50 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
51 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
53 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
54 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
63 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
65 int getId() { return id; };
66 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
67 const time_t getBlockTime() const { return blocktime; };
68 time_t getTimeStamp() { return touch; };
69 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
72 typedef vector<Block> BlockList;
73 typedef BlockList::iterator BlockListIterator;
75 /***************************************************************************************
77 **************************************************************************************/
92 FGTaxiSegment *oppositeDirection;
111 FGTaxiSegment (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 blockTimes (other.blockTimes),
123 oppositeDirection (other.oppositeDirection)
127 FGTaxiSegment& operator=(const FGTaxiSegment &other)
129 startNode = other.startNode;
130 endNode = other.endNode;
131 length = other.length;
132 heading = other.heading;
133 center = other.center;
134 isActive = other.isActive;
135 isPushBackRoute = other.isPushBackRoute;
136 blockTimes = other.blockTimes;
140 oppositeDirection = other.oppositeDirection;
144 void setIndex (int val) {
147 void setStartNodeRef (int val) {
150 void setEndNodeRef (int val) {
154 void setOpposite(FGTaxiSegment *opp) {
155 oppositeDirection = opp;
158 void setStart(FGTaxiNodeVector *nodes);
159 void setEnd (FGTaxiNodeVector *nodes);
160 void setPushBackType(bool val) {
161 isPushBackRoute = val;
163 void setDimensions(double elevation);
164 void block(int id, time_t blockTime, time_t now);
165 void unblock(time_t now);
166 bool hasBlock(time_t now);
168 FGTaxiNode * getEnd() {
171 FGTaxiNode * getStart() {
180 double getLatitude() {
181 return center.getLatitudeDeg();
183 double getLongitude() {
184 return center.getLongitudeDeg();
186 double getHeading() {
190 return isPushBackRoute;
193 int getPenalty(int nGates);
195 FGTaxiSegment *getAddress() {
199 bool operator<(const FGTaxiSegment &other) const {
200 return index < other.index;
202 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
203 FGTaxiSegment *opposite() {
204 return oppositeDirection;
206 void setCourseDiff(double crse);
216 typedef vector<int> intVec;
217 typedef vector<int>::iterator intVecIterator;
221 /***************************************************************************************
223 **************************************************************************************/
231 intVecIterator currNode;
232 intVecIterator currRoute;
237 currNode = nodes.begin();
238 currRoute = routes.begin();
240 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
244 currNode = nodes.begin();
245 currRoute = routes.begin();
249 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
251 routes = other.routes;
252 distance = other.distance;
253 // depth = other.depth;
254 currNode = nodes.begin();
255 currRoute = routes.begin();
259 FGTaxiRoute(const FGTaxiRoute& copy) :
262 distance(copy.distance),
263 // depth(copy.depth),
264 currNode(nodes.begin()),
265 currRoute(routes.begin())
268 bool operator< (const FGTaxiRoute &other) const {
269 return distance < other.distance;
272 return nodes.begin() == nodes.end();
275 bool next(int *nde, int *rte);
276 void rewind(int legNr);
279 currNode = nodes.begin();
280 currRoute = routes.begin();
286 return nodes.end() - currNode;
289 // int getDepth() { return depth; };
292 typedef vector<FGTaxiRoute> TaxiRouteVector;
293 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
295 /**************************************************************************************
296 * class FGGroundNetWork
297 *************************************************************************************/
298 class FGGroundNetwork : public FGATCController
302 bool networkInitialized;
307 FGTaxiNodeVector nodes;
308 FGTaxiNodeVector pushBackNodes;
309 FGTaxiSegmentVector segments;
312 //intVec routesStack;
313 TaxiRouteVector routes;
314 TrafficVector activeTraffic;
315 TrafficVectorIterator currTraffic;
318 double totalDistance, maxDistance;
319 FGTowerController *towerController;
323 //void printRoutingError(string);
325 void checkSpeedAdjustment(int id, double lat, double lon,
326 double heading, double speed, double alt);
327 void checkHoldPosition(int id, double lat, double lon,
328 double heading, double speed, double alt);
336 void addNode (const FGTaxiNode& node);
337 void addNodes (FGParkingVec *parkings);
338 void addSegment(const FGTaxiSegment& seg);
339 void setVersion (int v) { version = v;};
341 int getVersion() { return version; };
347 void setTowerController(FGTowerController *twrCtrlr) {
348 towerController = twrCtrlr;
351 int findNearestNode(double lat, double lon);
352 int findNearestNode(const SGGeod& aGeod);
353 int findNearestNodeOnRunway(const SGGeod& aGeod);
355 FGTaxiNode *findNode(unsigned idx);
356 FGTaxiSegment *findSegment(unsigned idx);
357 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
358 //void trace(FGTaxiNode *, int, int, double dist);
364 void setParent(FGAirport *par) {
368 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
369 double lat, double lon, double hdg, double spd, double alt,
370 double radius, int leg, FGAIAircraft *aircraft);
371 virtual void signOff(int id);
372 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
373 virtual bool hasInstruction(int id);
374 virtual FGATCInstruction getInstruction(int id);
376 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
378 bool checkForCircularWaits(int id);
379 virtual void render(bool);
380 virtual string getName();
381 virtual void update(double dt);
383 void saveElevationCache();
384 void addVersion(int v) {version = v; };