]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
apt.dat parser: various little improvements
[flightgear.git] / src / Airports / groundnetwork.hxx
1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma, started June 2005.
5 //
6 // Copyright (C) 2004 Durk Talsma.
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
26
27 #include <simgear/compiler.h>
28
29 #include <string>
30
31 #include "gnnode.hxx"
32 #include "parking.hxx"
33
34 class FGAirportDynamicsXMLLoader;
35
36 typedef std::vector<int> intVec;
37 typedef std::vector<int>::iterator intVecIterator;
38
39 class Block
40 {
41 private:
42     int id;
43     time_t blocktime;
44     time_t touch;
45 public:
46     Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
47     ~Block() {};
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; };
53 };
54
55 /***************************************************************************************
56  * class FGTaxiSegment
57  **************************************************************************************/
58 class FGTaxiSegment
59 {
60 private:
61     // weak (non-owning) pointers deliberately here:
62     // the ground-network owns the nodes
63     const FGTaxiNode* startNode;
64     const FGTaxiNode* endNode;
65     
66     bool isActive;
67     BlockList blockTimes;
68
69     int index;
70     FGTaxiSegment *oppositeDirection; // also deliberatley weak
71
72     friend class FGGroundNetwork;
73 public:
74     FGTaxiSegment(FGTaxiNode* start, FGTaxiNode* end);
75   
76     void setIndex        (int val) {
77         index     = val;
78     };
79   
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);
84
85     FGTaxiNodeRef getEnd() const;
86     FGTaxiNodeRef getStart() const;
87   
88     double getLength() const;
89   
90     // compute the center of the arc
91     SGGeod getCenter() const;
92   
93     double getHeading() const;
94     
95     int getIndex() {
96       return index;
97     };
98
99     int getPenalty(int nGates);
100
101     bool operator<(const FGTaxiSegment &other) const {
102         return index < other.index;
103     };
104
105     FGTaxiSegment *opposite() {
106         return oppositeDirection;
107     };
108 };
109
110 /***************************************************************************************
111  * class FGTaxiRoute
112  **************************************************************************************/
113 class FGTaxiRoute
114 {
115 private:
116     FGTaxiNodeVector nodes;
117     intVec routes;
118     double distance;
119     FGTaxiNodeVector::iterator currNode;
120     intVec::iterator currRoute;
121
122 public:
123     FGTaxiRoute() {
124         distance = 0;
125         currNode = nodes.begin();
126         currRoute = routes.begin();
127     };
128   
129     FGTaxiRoute(const FGTaxiNodeVector& nds, intVec rts,  double dist, int dpth) {
130         nodes = nds;
131         routes = rts;
132         distance = dist;
133         currNode = nodes.begin();
134         currRoute = routes.begin();
135     };
136
137     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
138         nodes = other.nodes;
139         routes = other.routes;
140         distance = other.distance;
141         currNode = nodes.begin();
142         currRoute = routes.begin();
143         return *this;
144     };
145
146     FGTaxiRoute(const FGTaxiRoute& copy) :
147             nodes(copy.nodes),
148             routes(copy.routes),
149             distance(copy.distance),
150             currNode(nodes.begin()),
151             currRoute(routes.begin())
152     {};
153
154     bool operator< (const FGTaxiRoute &other) const {
155         return distance < other.distance;
156     };
157     bool empty () {
158         return nodes.empty();
159     };
160     bool next(FGTaxiNodeRef& nde, int *rte);
161   
162     void first() {
163         currNode = nodes.begin();
164         currRoute = routes.begin();
165     };
166     int size() {
167         return nodes.size();
168     };
169     int nodesLeft() {
170         return nodes.end() - currNode;
171     };
172 };
173
174 /**************************************************************************************
175  * class FGGroundNetWork
176  *************************************************************************************/
177 class FGGroundNetwork
178 {
179 private:
180     friend class FGGroundNetXMLLoader;
181
182     bool hasNetwork;
183     bool networkInitialized;
184
185     int version;
186   
187     FGTaxiSegmentVector segments;
188
189     FGAirport *parent;
190
191     FGParkingList m_parkings;
192     FGTaxiNodeVector m_nodes;
193
194     FGTaxiNodeRef findNodeByIndex(int index) const;
195
196     //void printRoutingError(string);
197
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);
202
203
204     void addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to);
205     void addParking(const FGParkingRef& park);
206
207     FGTaxiNodeVector segmentsFrom(const FGTaxiNodeRef& from) const;
208
209     void addAwosFreq     (int val) {
210         freqAwos.push_back(val);
211     };
212     void addUnicomFreq   (int val) {
213         freqUnicom.push_back(val);
214     };
215     void addClearanceFreq(int val) {
216         freqClearance.push_back(val);
217     };
218     void addGroundFreq   (int val) {
219         freqGround.push_back(val);
220     };
221     void addTowerFreq    (int val) {
222         freqTower.push_back(val);
223     };
224     void addApproachFreq (int val) {
225         freqApproach.push_back(val);
226     };
227
228     intVec freqAwos;     // </AWOS>
229     intVec freqUnicom;   // </UNICOM>
230     intVec freqClearance;// </CLEARANCE>
231     intVec freqGround;   // </GROUND>
232     intVec freqTower;    // </TOWER>
233     intVec freqApproach; // </APPROACH>
234 public:
235     FGGroundNetwork(FGAirport* pr);
236     ~FGGroundNetwork();
237     
238     void setVersion (int v) { version = v;};
239     int getVersion() { return version; };
240
241     void init();
242     bool exists() {
243         return hasNetwork;
244     };
245
246     FGAirport* airport() const
247     { return parent; }
248
249     FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const;
250     FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
251
252     FGTaxiSegment *findSegment(unsigned int idx) const;
253
254     FGTaxiSegment* findOppositeSegment(unsigned int index) const;
255
256     const FGParkingList& allParkings() const;
257
258     /**
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.
263      */
264     FGTaxiSegment *findSegment(const FGTaxiNode* from, const FGTaxiNode* to) const;
265   
266     FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch=true);
267
268
269     void blockSegmentsEndingAt(FGTaxiSegment* seg, int blockId,
270                                time_t blockTime, time_t now);
271
272     void addVersion(int v) {version = v; };
273     void unblockAllSegments(time_t now);
274
275     const intVec& getTowerFrequencies() const;
276     const intVec& getGroundFrequencies() const;
277     
278 };
279
280
281 #endif