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_
27 #include <simgear/compiler.h>
37 #include "parking.hxx"
38 //#include <AIModel/AIBase.hxx>
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
45 typedef vector<FGTaxiSegment> FGTaxiSegmentVector;
46 typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
47 typedef vector<FGTaxiSegment>::iterator FGTaxiSegmentVectorIterator;
48 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
50 /**************************************************************************************
52 *************************************************************************************/
59 FGTaxiSegmentPointerVector next; // a vector to all the segments leaving from this node
63 FGTaxiNode(double, double, int);
65 void setIndex(int idx) { index = idx;};
66 void setLatitude (double val) { lat = val;};
67 void setLongitude(double val) { lon = val;};
68 void setLatitude (const string& val) { lat = processPosition(val); };
69 void setLongitude(const string& val) { lon = processPosition(val); };
70 void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
72 double getLatitude() { return lat;};
73 double getLongitude(){ return lon;};
75 int getIndex() { return index; };
76 FGTaxiNode *getAddress() { return this;};
77 FGTaxiSegmentPointerVectorIterator getBeginRoute() { return next.begin(); };
78 FGTaxiSegmentPointerVectorIterator getEndRoute() { return next.end(); };
81 typedef vector<FGTaxiNode> FGTaxiNodeVector;
82 typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
84 /***************************************************************************************
86 **************************************************************************************/
99 FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
101 void setIndex (int val) { index = val; };
102 void setStartNodeRef (int val) { startNode = val; };
103 void setEndNodeRef (int val) { endNode = val; };
105 void setStart(FGTaxiNodeVector *nodes);
106 void setEnd (FGTaxiNodeVector *nodes);
107 void setTrackDistance();
109 FGTaxiNode * getEnd() { return end;};
110 double getLength() { return length; };
111 int getIndex() { return index; };
113 FGTaxiSegment *getAddress() { return this;};
119 typedef vector<int> intVec;
120 typedef vector<int>::iterator intVecIterator;
122 /***************************************************************************************
124 **************************************************************************************/
131 intVecIterator currNode;
132 intVecIterator currRoute;
135 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
136 FGTaxiRoute(intVec nds, intVec rts, double dist) {
140 currNode = nodes.begin();
142 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
143 bool empty () { return nodes.begin() == nodes.end(); };
145 bool next(int *nde, int *rte);
146 void rewind(int legNr);
148 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
149 int size() { return nodes.size(); };
152 typedef vector<FGTaxiRoute> TaxiRouteVector;
153 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
155 /**************************************************************************************
156 * class FGATCInstruction
157 * like class FGATC Controller, this class definition should go into its own file
158 * and or directory... For now, just testing this stuff out though...
159 *************************************************************************************/
160 class FGATCInstruction
175 bool hasInstruction ();
176 bool getHoldPattern () { return holdPattern; };
177 bool getHoldPosition () { return holdPosition; };
178 bool getChangeSpeed () { return changeSpeed; };
179 bool getChangeHeading () { return changeHeading; };
180 bool getChangeAltitude() { return changeAltitude; };
182 double getSpeed () { return speed; };
183 double getHeading () { return heading; };
184 double getAlt () { return alt; };
186 void setHoldPattern (bool val) { holdPattern = val; };
187 void setHoldPosition (bool val) { holdPosition = val; };
188 void setChangeSpeed (bool val) { changeSpeed = val; };
189 void setChangeHeading (bool val) { changeHeading = val; };
190 void setChangeAltitude(bool val) { changeAltitude = val; };
192 void setSpeed (double val) { speed = val; };
193 void setHeading (double val) { heading = val; };
194 void setAlt (double val) { alt = val; };
198 /**************************************************************************************
199 * class FGTrafficRecord
200 *************************************************************************************/
201 class FGTrafficRecord
207 FGATCInstruction instruction;
208 double latitude, longitude, heading, speed, altitude, radius;
212 FGTrafficRecord() {};
214 void setId(int val) { id = val; };
215 void setRadius(double rad) { radius = rad;};
216 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
217 int getId() { return id;};
218 FGATCInstruction getInstruction() { return instruction;};
219 bool hasInstruction() { return instruction.hasInstruction(); };
220 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
221 bool checkPositionAndIntentions(FGTrafficRecord &other);
223 double getLatitude () { return latitude ; };
224 double getLongitude() { return longitude; };
225 double getHeading () { return heading ; };
226 double getSpeed () { return speed ; };
227 double getAltitude () { return altitude ; };
228 double getRadius () { return radius ; };
230 int getWaitsForId () { return waitsForId; };
232 void setSpeedAdjustment(double spd) { instruction.setChangeSpeed(true);
233 instruction.setSpeed(spd); };
234 void setHeadingAdjustment(double heading) { instruction.setChangeHeading(true);
235 instruction.setHeading(heading); };
236 void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
237 void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
239 bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
241 void setWaitsForId(int id) { waitsForId = id; };
245 typedef vector<FGTrafficRecord> TrafficVector;
246 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
251 /**************************************************************************************
252 * class FGATCController
253 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller,
254 * Ground and air, so eventually it should move to its own file / directory.
255 *************************************************************************************/
256 class FGATCController
261 FGATCController() { dt_count = 0;};
262 virtual ~FGATCController() {};
263 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
264 double lat, double lon,
265 double hdg, double spd, double alt, double radius) = 0;
266 virtual void signOff(int id) = 0;
267 virtual void update(int id, double lat, double lon,
268 double heading, double speed, double alt) = 0;
269 virtual bool hasInstruction(int id) = 0;
270 virtual FGATCInstruction getInstruction(int id) = 0;
272 double getDt() { return dt_count; };
273 void setDt(double dt) { dt_count = dt;};
278 /**************************************************************************************
279 * class FGGroundNetWork
280 *************************************************************************************/
281 class FGGroundNetwork : public FGATCController
285 FGTaxiNodeVector nodes;
286 FGTaxiSegmentVector segments;
290 TaxiRouteVector routes;
291 TrafficVector activeTraffic;
292 TrafficVectorIterator currTraffic;
295 double totalDistance, maxDistance;
297 void printRoutingError(string);
302 void addNode (const FGTaxiNode& node);
303 void addNodes (FGParkingVec *parkings);
304 void addSegment(const FGTaxiSegment& seg);
307 bool exists() { return hasNetwork; };
308 int findNearestNode(double lat, double lon);
309 FGTaxiNode *findNode(int idx);
310 FGTaxiSegment *findSegment(int idx);
311 FGTaxiRoute findShortestRoute(int start, int end);
312 void trace(FGTaxiNode *, int, int, double dist);
314 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
315 double lat, double lon, double hdg, double spd, double alt, double radius);
316 virtual void signOff(int id);
317 virtual void update(int id, double lat, double lon, double heading, double speed, double alt);
318 virtual bool hasInstruction(int id);
319 virtual FGATCInstruction getInstruction(int id);