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>
45 #include "parking.hxx"
46 #include <ATC/trafficcontrol.hxx>
49 class FGTaxiSegment; // forward reference
50 class FGAIFlightPlan; // forward reference
51 class FGAirport; // forward reference
53 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
54 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
56 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
57 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
66 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
68 int getId() { return id; };
69 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
70 const time_t getBlockTime() const { return blocktime; };
71 time_t getTimeStamp() { return touch; };
72 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
75 typedef vector<Block> BlockList;
76 typedef BlockList::iterator BlockListIterator;
78 /***************************************************************************************
80 **************************************************************************************/
95 FGTaxiSegment *oppositeDirection;
114 FGTaxiSegment (const FGTaxiSegment &other) :
115 startNode (other.startNode),
116 endNode (other.endNode),
117 length (other.length),
118 heading (other.heading),
119 center (other.center),
120 isActive (other.isActive),
121 isPushBackRoute (other.isPushBackRoute),
122 blockTimes (other.blockTimes),
126 oppositeDirection (other.oppositeDirection)
130 FGTaxiSegment& operator=(const FGTaxiSegment &other)
132 startNode = other.startNode;
133 endNode = other.endNode;
134 length = other.length;
135 heading = other.heading;
136 center = other.center;
137 isActive = other.isActive;
138 isPushBackRoute = other.isPushBackRoute;
139 blockTimes = other.blockTimes;
143 oppositeDirection = other.oppositeDirection;
147 void setIndex (int val) {
150 void setStartNodeRef (int val) {
153 void setEndNodeRef (int val) {
157 void setOpposite(FGTaxiSegment *opp) {
158 oppositeDirection = opp;
161 void setStart(FGTaxiNodeVector *nodes);
162 void setEnd (FGTaxiNodeVector *nodes);
163 void setPushBackType(bool val) {
164 isPushBackRoute = val;
166 void setDimensions(double elevation);
167 void block(int id, time_t blockTime, time_t now);
168 void unblock(time_t now);
169 bool hasBlock(time_t now);
171 FGTaxiNode * getEnd() {
174 FGTaxiNode * getStart() {
183 double getLatitude() {
184 return center.getLatitudeDeg();
186 double getLongitude() {
187 return center.getLongitudeDeg();
189 double getHeading() {
193 return isPushBackRoute;
196 int getPenalty(int nGates);
198 FGTaxiSegment *getAddress() {
202 bool operator<(const FGTaxiSegment &other) const {
203 return index < other.index;
205 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
206 FGTaxiSegment *opposite() {
207 return oppositeDirection;
209 void setCourseDiff(double crse);
219 typedef vector<int> intVec;
220 typedef vector<int>::iterator intVecIterator;
224 /***************************************************************************************
226 **************************************************************************************/
234 intVecIterator currNode;
235 intVecIterator currRoute;
240 currNode = nodes.begin();
241 currRoute = routes.begin();
243 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
247 currNode = nodes.begin();
248 currRoute = routes.begin();
252 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
254 routes = other.routes;
255 distance = other.distance;
256 // depth = other.depth;
257 currNode = nodes.begin();
258 currRoute = routes.begin();
262 FGTaxiRoute(const FGTaxiRoute& copy) :
265 distance(copy.distance),
266 // depth(copy.depth),
267 currNode(nodes.begin()),
268 currRoute(routes.begin())
271 bool operator< (const FGTaxiRoute &other) const {
272 return distance < other.distance;
275 return nodes.begin() == nodes.end();
278 bool next(int *nde, int *rte);
279 void rewind(int legNr);
282 currNode = nodes.begin();
283 currRoute = routes.begin();
289 return nodes.end() - currNode;
292 // int getDepth() { return depth; };
295 typedef vector<FGTaxiRoute> TaxiRouteVector;
296 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
298 /**************************************************************************************
299 * class FGGroundNetWork
300 *************************************************************************************/
301 class FGGroundNetwork : public FGATCController
305 bool networkInitialized;
310 FGTaxiNodeVector nodes;
311 FGTaxiNodeVector pushBackNodes;
312 FGTaxiSegmentVector segments;
315 //intVec routesStack;
316 TaxiRouteVector routes;
317 TrafficVector activeTraffic;
318 TrafficVectorIterator currTraffic;
321 double totalDistance, maxDistance;
322 FGTowerController *towerController;
326 //void printRoutingError(string);
328 void checkSpeedAdjustment(int id, double lat, double lon,
329 double heading, double speed, double alt);
330 void checkHoldPosition(int id, double lat, double lon,
331 double heading, double speed, double alt);
339 void addNode (const FGTaxiNode& node);
340 void addNodes (FGParkingVec *parkings);
341 void addSegment(const FGTaxiSegment& seg);
342 void setVersion (int v) { version = v;};
344 int getVersion() { return version; };
350 void setTowerController(FGTowerController *twrCtrlr) {
351 towerController = twrCtrlr;
354 int findNearestNode(double lat, double lon);
355 int findNearestNode(const SGGeod& aGeod);
356 int findNearestNodeOnRunway(const SGGeod& aGeod);
358 FGTaxiNode *findNode(unsigned idx);
359 FGTaxiSegment *findSegment(unsigned idx);
360 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
361 //void trace(FGTaxiNode *, int, int, double dist);
367 void setParent(FGAirport *par) {
371 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
372 double lat, double lon, double hdg, double spd, double alt,
373 double radius, int leg, FGAIAircraft *aircraft);
374 virtual void signOff(int id);
375 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
376 virtual bool hasInstruction(int id);
377 virtual FGATCInstruction getInstruction(int id);
379 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
381 bool checkForCircularWaits(int id);
382 virtual void render(bool);
383 virtual string getName();
384 virtual void update(double dt);
386 void saveElevationCache();
387 void addVersion(int v) {version = v; };