]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
4c8bdb2eb6d1a504fd4d53e5e872b7009fb9c1ae
[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 STL_STRING
30 #include <vector>
31
32 SG_USING_STD(string);
33 SG_USING_STD(vector);
34
35 #include "parking.hxx"
36
37 class FGTaxiSegment; // forward reference
38
39 typedef vector<FGTaxiSegment>  FGTaxiSegmentVector;
40 typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
41 typedef vector<FGTaxiSegment>::iterator FGTaxiSegmentVectorIterator;
42 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
43
44 /**************************************************************************************
45  * class FGTaxiNode
46  *************************************************************************************/
47 class FGTaxiNode 
48 {
49 private:
50   double lat;
51   double lon;
52   int index;
53   FGTaxiSegmentPointerVector next; // a vector to all the segments leaving from this node
54   
55 public:
56   FGTaxiNode();
57   FGTaxiNode(double, double, int);
58
59   void setIndex(int idx)                  { index = idx;};
60   void setLatitude (double val)           { lat = val;};
61   void setLongitude(double val)           { lon = val;};
62   void setLatitude (const string& val)           { lat = processPosition(val);  };
63   void setLongitude(const string& val)           { lon = processPosition(val);  };
64   void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
65   
66   double getLatitude() { return lat;};
67   double getLongitude(){ return lon;};
68
69   int getIndex() { return index; };
70   FGTaxiNode *getAddress() { return this;};
71   FGTaxiSegmentPointerVectorIterator getBeginRoute() { return next.begin(); };
72   FGTaxiSegmentPointerVectorIterator getEndRoute()   { return next.end();   }; 
73 };
74
75 typedef vector<FGTaxiNode> FGTaxiNodeVector;
76 typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
77
78 /***************************************************************************************
79  * class FGTaxiSegment
80  **************************************************************************************/
81 class FGTaxiSegment
82 {
83 private:
84   int startNode;
85   int endNode;
86   double length;
87   FGTaxiNode *start;
88   FGTaxiNode *end;
89   int index;
90
91 public:
92   FGTaxiSegment();
93   FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
94
95   void setIndex        (int val) { index     = val; };
96   void setStartNodeRef (int val) { startNode = val; };
97   void setEndNodeRef   (int val) { endNode   = val; };
98
99   void setStart(FGTaxiNodeVector *nodes);
100   void setEnd  (FGTaxiNodeVector *nodes);
101   void setTrackDistance();
102
103   FGTaxiNode * getEnd() { return end;};
104   double getLength() { return length; };
105   int getIndex() { return index; };
106
107  FGTaxiSegment *getAddress() { return this;};
108
109   
110 };
111
112
113 typedef vector<int> intVec;
114 typedef vector<int>::iterator intVecIterator;
115
116 /***************************************************************************************
117  * class FGTaxiRoute
118  **************************************************************************************/
119 class FGTaxiRoute
120 {
121 private:
122   intVec nodes;
123   intVec routes;
124   double distance;
125   intVecIterator currNode;
126   intVecIterator currRoute;
127
128 public:
129   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
130   FGTaxiRoute(intVec nds, intVec rts, double dist) { 
131     nodes = nds; 
132     routes = rts;
133     distance = dist; 
134     currNode = nodes.begin();
135   };
136   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
137   bool empty () { return nodes.begin() == nodes.end(); };
138   bool next(int *nde); 
139   bool next(int *nde, int *rte);
140   
141   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
142   int size() { return nodes.size(); };
143 };
144
145 typedef vector<FGTaxiRoute> TaxiRouteVector;
146 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
147
148 /**************************************************************************************
149  * class FGGroundNetWork
150  *************************************************************************************/
151 class FGGroundNetwork
152 {
153 private:
154   bool hasNetwork;
155   FGTaxiNodeVector    nodes;
156   FGTaxiSegmentVector segments;
157   //intVec route;
158   intVec nodesStack;
159   intVec routesStack;
160   TaxiRouteVector routes;
161   
162   bool foundRoute;
163   double totalDistance, maxDistance;
164
165   void printRoutingError(string);
166   
167 public:
168   FGGroundNetwork();
169
170   void addNode   (const FGTaxiNode& node);
171   void addNodes  (FGParkingVec *parkings);
172   void addSegment(const FGTaxiSegment& seg); 
173
174   void init();
175   bool exists() { return hasNetwork; };
176   int findNearestNode(double lat, double lon);
177   FGTaxiNode *findNode(int idx);
178   FGTaxiSegment *findSegment(int idx);
179   FGTaxiRoute findShortestRoute(int start, int end);
180   void trace(FGTaxiNode *, int, int, double dist);
181  
182 };
183
184 #endif