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 **************************************************************************************/
73 FGTaxiSegment *oppositeDirection;
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),
103 oppositeDirection (other.oppositeDirection)
107 FGTaxiSegment& operator=(const FGTaxiSegment &other)
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;
119 oppositeDirection = other.oppositeDirection;
123 void setIndex (int val) { index = val; };
124 void setStartNodeRef (int val) { startNode = val; };
125 void setEndNodeRef (int val) { endNode = val; };
127 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
129 void setStart(FGTaxiNodeVector *nodes);
130 void setEnd (FGTaxiNodeVector *nodes);
131 void setPushBackType(bool val) { isPushBackRoute = val; };
132 void setDimensions(double elevation);
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; };
143 int getPenalty(int nGates);
145 FGTaxiSegment *getAddress() { return this;};
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);
160 typedef vector<int> intVec;
161 typedef vector<int>::iterator intVecIterator;
165 /***************************************************************************************
167 **************************************************************************************/
175 intVecIterator currNode;
176 intVecIterator currRoute;
179 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
180 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
184 currNode = nodes.begin();
185 currRoute = routes.begin();
189 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
191 routes = other.routes;
192 distance = other.distance;
193 // depth = other.depth;
194 currNode = nodes.begin();
195 currRoute = routes.begin();
199 FGTaxiRoute(const FGTaxiRoute& copy) :
202 distance(copy.distance),
203 // depth(copy.depth),
204 currNode(nodes.begin()),
205 currRoute(routes.begin())
208 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
209 bool empty () { return nodes.begin() == nodes.end(); };
211 bool next(int *nde, int *rte);
212 void rewind(int legNr);
214 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
215 int size() { return nodes.size(); };
216 int nodesLeft() { return nodes.end() - currNode; };
218 // int getDepth() { return depth; };
221 typedef vector<FGTaxiRoute> TaxiRouteVector;
222 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
224 /**************************************************************************************
225 * class FGGroundNetWork
226 *************************************************************************************/
227 class FGGroundNetwork : public FGATCController
231 bool networkInitialized;
235 FGTaxiNodeVector nodes;
236 FGTaxiNodeVector pushBackNodes;
237 FGTaxiSegmentVector segments;
240 //intVec routesStack;
241 TaxiRouteVector routes;
242 TrafficVector activeTraffic;
243 TrafficVectorIterator currTraffic;
246 double totalDistance, maxDistance;
247 FGTowerController *towerController;
251 //void printRoutingError(string);
253 void checkSpeedAdjustment(int id, double lat, double lon,
254 double heading, double speed, double alt);
255 void checkHoldPosition(int id, double lat, double lon,
256 double heading, double speed, double alt);
264 void addNode (const FGTaxiNode& node);
265 void addNodes (FGParkingVec *parkings);
266 void addSegment(const FGTaxiSegment& seg);
269 bool exists() { return hasNetwork; };
270 void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
272 int findNearestNode(double lat, double lon);
273 int findNearestNode(const SGGeod& aGeod);
275 FGTaxiNode *findNode(unsigned idx);
276 FGTaxiSegment *findSegment(unsigned idx);
277 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
278 //void trace(FGTaxiNode *, int, int, double dist);
280 int getNrOfNodes() { return nodes.size(); };
282 void setParent(FGAirport *par) { parent = par; };
284 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
285 double lat, double lon, double hdg, double spd, double alt,
286 double radius, int leg, FGAIAircraft *aircraft);
287 virtual void signOff(int id);
288 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
289 virtual bool hasInstruction(int id);
290 virtual FGATCInstruction getInstruction(int id);
292 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
294 bool checkForCircularWaits(int id);
295 virtual void render(bool);
296 virtual string getName();
298 void saveElevationCache();