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(); };
79 bool operator<(const FGTaxiNode &other) const { return index < other.index; };
82 typedef vector<FGTaxiNode> FGTaxiNodeVector;
83 typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
85 /***************************************************************************************
87 **************************************************************************************/
97 FGTaxiSegment *oppositeDirection;
101 //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
103 void setIndex (int val) { index = val; };
104 void setStartNodeRef (int val) { startNode = val; };
105 void setEndNodeRef (int val) { endNode = val; };
107 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
109 void setStart(FGTaxiNodeVector *nodes);
110 void setEnd (FGTaxiNodeVector *nodes);
111 void setTrackDistance();
113 FGTaxiNode * getEnd() { return end;};
114 FGTaxiNode * getStart() { return start; };
115 double getLength() { return length; };
116 int getIndex() { return index; };
118 FGTaxiSegment *getAddress() { return this;};
120 bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
121 FGTaxiSegment *opposite() { return oppositeDirection; };
127 typedef vector<int> intVec;
128 typedef vector<int>::iterator intVecIterator;
130 /***************************************************************************************
132 **************************************************************************************/
139 intVecIterator currNode;
140 intVecIterator currRoute;
143 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
144 FGTaxiRoute(intVec nds, intVec rts, double dist) {
148 currNode = nodes.begin();
150 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
151 bool empty () { return nodes.begin() == nodes.end(); };
153 bool next(int *nde, int *rte);
154 void rewind(int legNr);
156 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
157 int size() { return nodes.size(); };
160 typedef vector<FGTaxiRoute> TaxiRouteVector;
161 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
163 /**************************************************************************************
164 * class FGATCInstruction
165 * like class FGATC Controller, this class definition should go into its own file
166 * and or directory... For now, just testing this stuff out though...
167 *************************************************************************************/
168 class FGATCInstruction
183 bool hasInstruction ();
184 bool getHoldPattern () { return holdPattern; };
185 bool getHoldPosition () { return holdPosition; };
186 bool getChangeSpeed () { return changeSpeed; };
187 bool getChangeHeading () { return changeHeading; };
188 bool getChangeAltitude() { return changeAltitude; };
190 double getSpeed () { return speed; };
191 double getHeading () { return heading; };
192 double getAlt () { return alt; };
194 void setHoldPattern (bool val) { holdPattern = val; };
195 void setHoldPosition (bool val) { holdPosition = val; };
196 void setChangeSpeed (bool val) { changeSpeed = val; };
197 void setChangeHeading (bool val) { changeHeading = val; };
198 void setChangeAltitude(bool val) { changeAltitude = val; };
200 void setSpeed (double val) { speed = val; };
201 void setHeading (double val) { heading = val; };
202 void setAlt (double val) { alt = val; };
205 class FGGroundNetwork;
207 /**************************************************************************************
208 * class FGTrafficRecord
209 *************************************************************************************/
210 class FGTrafficRecord
216 FGATCInstruction instruction;
217 double latitude, longitude, heading, speed, altitude, radius;
221 FGTrafficRecord() {};
223 void setId(int val) { id = val; };
224 void setRadius(double rad) { radius = rad;};
225 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
226 int getId() { return id;};
227 FGATCInstruction getInstruction() { return instruction;};
228 bool hasInstruction() { return instruction.hasInstruction(); };
229 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
230 bool checkPositionAndIntentions(FGTrafficRecord &other);
231 int crosses (FGGroundNetwork *, FGTrafficRecord &other);
232 bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
234 bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
236 double getLatitude () { return latitude ; };
237 double getLongitude() { return longitude; };
238 double getHeading () { return heading ; };
239 double getSpeed () { return speed ; };
240 double getAltitude () { return altitude ; };
241 double getRadius () { return radius ; };
243 int getWaitsForId () { return waitsForId; };
245 void setSpeedAdjustment(double spd) { instruction.setChangeSpeed(true);
246 instruction.setSpeed(spd); };
247 void setHeadingAdjustment(double heading) { instruction.setChangeHeading(true);
248 instruction.setHeading(heading); };
249 void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
250 void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
252 bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
253 bool hasHoldPosition() { return instruction.getHoldPosition(); };
254 void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
256 void setWaitsForId(int id) { waitsForId = id; };
260 typedef vector<FGTrafficRecord> TrafficVector;
261 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
266 /**************************************************************************************
267 * class FGATCController
268 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller,
269 * Ground and air, so eventually it should move to its own file / directory.
270 *************************************************************************************/
271 class FGATCController
276 FGATCController() { dt_count = 0;};
277 virtual ~FGATCController() {};
278 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
279 double lat, double lon,
280 double hdg, double spd, double alt, double radius) = 0;
281 virtual void signOff(int id) = 0;
282 virtual void update(int id, double lat, double lon,
283 double heading, double speed, double alt, double dt) = 0;
284 virtual bool hasInstruction(int id) = 0;
285 virtual FGATCInstruction getInstruction(int id) = 0;
287 double getDt() { return dt_count; };
288 void setDt(double dt) { dt_count = dt;};
293 /**************************************************************************************
294 * class FGGroundNetWork
295 *************************************************************************************/
296 class FGGroundNetwork : public FGATCController
300 FGTaxiNodeVector nodes;
301 FGTaxiSegmentVector segments;
305 TaxiRouteVector routes;
306 TrafficVector activeTraffic;
307 TrafficVectorIterator currTraffic;
310 double totalDistance, maxDistance;
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);
322 void addNode (const FGTaxiNode& node);
323 void addNodes (FGParkingVec *parkings);
324 void addSegment(const FGTaxiSegment& seg);
327 bool exists() { return hasNetwork; };
328 int findNearestNode(double lat, double lon);
329 FGTaxiNode *findNode(int idx);
330 FGTaxiSegment *findSegment(int idx);
331 FGTaxiRoute findShortestRoute(int start, int end);
332 void trace(FGTaxiNode *, int, int, double dist);
334 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
335 double lat, double lon, double hdg, double spd, double alt, double radius);
336 virtual void signOff(int id);
337 virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
338 virtual bool hasInstruction(int id);
339 virtual FGATCInstruction getInstruction(int id);