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