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>
32 #include "parking.hxx"
34 class FGAirportDynamicsXMLLoader;
36 typedef std::vector<int> intVec;
37 typedef std::vector<int>::iterator intVecIterator;
46 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
48 int getId() { return id; };
49 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
50 const time_t getBlockTime() const { return blocktime; };
51 time_t getTimeStamp() { return touch; };
52 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
55 /***************************************************************************************
57 **************************************************************************************/
61 // weak (non-owning) pointers deliberately here:
62 // the ground-network owns the nodes
63 const FGTaxiNode* startNode;
64 const FGTaxiNode* endNode;
70 FGTaxiSegment *oppositeDirection; // also deliberatley weak
72 friend class FGGroundNetwork;
74 FGTaxiSegment(FGTaxiNode* start, FGTaxiNode* end);
76 void setIndex (int val) {
80 void setDimensions(double elevation);
81 void block(int id, time_t blockTime, time_t now);
82 void unblock(time_t now);
83 bool hasBlock(time_t now);
85 FGTaxiNodeRef getEnd() const;
86 FGTaxiNodeRef getStart() const;
88 double getLength() const;
90 // compute the center of the arc
91 SGGeod getCenter() const;
93 double getHeading() const;
99 int getPenalty(int nGates);
101 bool operator<(const FGTaxiSegment &other) const {
102 return index < other.index;
105 FGTaxiSegment *opposite() {
106 return oppositeDirection;
110 /***************************************************************************************
112 **************************************************************************************/
116 FGTaxiNodeVector nodes;
119 FGTaxiNodeVector::iterator currNode;
120 intVec::iterator currRoute;
125 currNode = nodes.begin();
126 currRoute = routes.begin();
129 FGTaxiRoute(const FGTaxiNodeVector& nds, intVec rts, double dist, int dpth) {
133 currNode = nodes.begin();
134 currRoute = routes.begin();
137 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
139 routes = other.routes;
140 distance = other.distance;
141 currNode = nodes.begin();
142 currRoute = routes.begin();
146 FGTaxiRoute(const FGTaxiRoute& copy) :
149 distance(copy.distance),
150 currNode(nodes.begin()),
151 currRoute(routes.begin())
154 bool operator< (const FGTaxiRoute &other) const {
155 return distance < other.distance;
158 return nodes.empty();
160 bool next(FGTaxiNodeRef& nde, int *rte);
163 currNode = nodes.begin();
164 currRoute = routes.begin();
170 return nodes.end() - currNode;
174 /**************************************************************************************
175 * class FGGroundNetWork
176 *************************************************************************************/
177 class FGGroundNetwork
180 friend class FGAirportDynamicsXMLLoader;
182 FGAirportDynamics* dynamics; // weak back-pointer to our owner
184 bool networkInitialized;
188 FGTaxiSegmentVector segments;
192 FGParkingList m_parkings;
193 FGTaxiNodeVector m_nodes;
195 FGTaxiNodeRef findNodeByIndex(int index) const;
197 //void printRoutingError(string);
199 void checkSpeedAdjustment(int id, double lat, double lon,
200 double heading, double speed, double alt);
201 void checkHoldPosition(int id, double lat, double lon,
202 double heading, double speed, double alt);
205 void addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to);
206 void addParking(const FGParkingRef& park);
208 FGTaxiNodeVector segmentsFrom(const FGTaxiNodeRef& from) const;
214 void setVersion (int v) { version = v;};
215 int getVersion() { return version; };
217 void init(FGAirportDynamics* pr);
222 FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const;
223 FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
225 FGTaxiSegment *findSegment(unsigned int idx) const;
227 FGTaxiSegment* findOppositeSegment(unsigned int index) const;
229 const FGParkingList& allParkings() const;
232 * Find the taxiway segment joining two (ground-net) nodes. Returns
233 * NULL if no such segment exists.
234 * It is permitted to pass HULL for the 'to' indicating that any
235 * segment originating at 'from' is acceptable.
237 FGTaxiSegment *findSegment(const FGTaxiNode* from, const FGTaxiNode* to) const;
239 FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch=true);
242 void blockSegmentsEndingAt(FGTaxiSegment* seg, int blockId,
243 time_t blockTime, time_t now);
245 void addVersion(int v) {version = v; };
246 void unblockAllSegments(time_t now);