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 FGGroundNetXMLLoader;
183 bool networkInitialized;
187 FGTaxiSegmentVector segments;
191 FGParkingList m_parkings;
192 FGTaxiNodeVector m_nodes;
194 FGTaxiNodeRef findNodeByIndex(int index) const;
196 //void printRoutingError(string);
198 void checkSpeedAdjustment(int id, double lat, double lon,
199 double heading, double speed, double alt);
200 void checkHoldPosition(int id, double lat, double lon,
201 double heading, double speed, double alt);
204 void addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to);
205 void addParking(const FGParkingRef& park);
207 FGTaxiNodeVector segmentsFrom(const FGTaxiNodeRef& from) const;
209 void addAwosFreq (int val) {
210 freqAwos.push_back(val);
212 void addUnicomFreq (int val) {
213 freqUnicom.push_back(val);
215 void addClearanceFreq(int val) {
216 freqClearance.push_back(val);
218 void addGroundFreq (int val) {
219 freqGround.push_back(val);
221 void addTowerFreq (int val) {
222 freqTower.push_back(val);
224 void addApproachFreq (int val) {
225 freqApproach.push_back(val);
228 intVec freqAwos; // </AWOS>
229 intVec freqUnicom; // </UNICOM>
230 intVec freqClearance;// </CLEARANCE>
231 intVec freqGround; // </GROUND>
232 intVec freqTower; // </TOWER>
233 intVec freqApproach; // </APPROACH>
235 FGGroundNetwork(FGAirport* pr);
238 void setVersion (int v) { version = v;};
239 int getVersion() { return version; };
246 FGAirport* airport() const
249 FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const;
250 FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
252 FGTaxiSegment *findSegment(unsigned int idx) const;
254 FGTaxiSegment* findOppositeSegment(unsigned int index) const;
256 const FGParkingList& allParkings() const;
259 * Find the taxiway segment joining two (ground-net) nodes. Returns
260 * NULL if no such segment exists.
261 * It is permitted to pass HULL for the 'to' indicating that any
262 * segment originating at 'from' is acceptable.
264 FGTaxiSegment *findSegment(const FGTaxiNode* from, const FGTaxiNode* to) const;
266 FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch=true);
269 void blockSegmentsEndingAt(FGTaxiSegment* seg, int blockId,
270 time_t blockTime, time_t now);
272 void addVersion(int v) {version = v; };
273 void unblockAllSegments(time_t now);
275 const intVec& getTowerFrequencies() const;
276 const intVec& getGroundFrequencies() const;