]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Mark's dynamic sun color changes.
[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   
108 };
109
110
111 typedef vector<int> intVec;
112 typedef vector<int>::iterator intVecIterator;
113
114 class FGTaxiRoute
115 {
116 private:
117   intVec nodes;
118   double distance;
119   intVecIterator currNode;
120
121 public:
122   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); };
123   FGTaxiRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
124   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
125   bool empty () { return nodes.begin() == nodes.end(); };
126   bool next(int *val); 
127   
128   void first() { currNode = nodes.begin(); };
129   int size() { return nodes.size(); };
130 };
131
132 typedef vector<FGTaxiRoute> TaxiRouteVector;
133 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
134
135 /**************************************************************************************
136  * class FGGroundNetWork
137  *************************************************************************************/
138 class FGGroundNetwork
139 {
140 private:
141   bool hasNetwork;
142   FGTaxiNodeVector    nodes;
143   FGTaxiSegmentVector segments;
144   //intVec route;
145   intVec traceStack;
146   TaxiRouteVector routes;
147   
148   bool foundRoute;
149   double totalDistance, maxDistance;
150   
151 public:
152   FGGroundNetwork();
153
154   void addNode   (const FGTaxiNode& node);
155   void addNodes  (FGParkingVec *parkings);
156   void addSegment(const FGTaxiSegment& seg); 
157
158   void init();
159   bool exists() { return hasNetwork; };
160   int findNearestNode(double lat, double lon);
161   FGTaxiNode *findNode(int idx);
162   FGTaxiRoute findShortestRoute(int start, int end);
163   void trace(FGTaxiNode *, int, int, double dist);
164  
165 };
166
167 #endif