]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/airways.hxx
Fix a couple of 64-bit warnings identified by GCC.
[flightgear.git] / src / Navaids / airways.hxx
1 // airways.hxx - storage of airways network, and routing between nodes
2 // Written by James Turner, started 2009.
3 //
4 // Copyright (C) 2009  Curtis L. Olson
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef FG_AIRWAYS_HXX
21 #define FG_AIRWAYS_HXX
22
23 #include <map>
24 #include <vector>
25
26 #include <Navaids/route.hxx>
27 #include <Navaids/positioned.hxx>
28
29 class SGPath;
30 typedef SGSharedPtr<FGPositioned> FGPositionedRef; 
31
32 namespace flightgear {
33
34 // forward declare some helpers
35 struct SearchContext;
36 class AdjacentWaypoint;
37 class InAirwayFilter;
38
39 class Airway
40 {
41 public:
42   virtual std::string ident() const
43   { return _ident; }
44   
45   static void load(const SGPath& path);
46   
47   /**
48    * Track a network of airways
49    *
50    */
51   class Network
52   {
53   public:
54     friend class Airway;
55     friend class InAirwayFilter;
56     
57   
58     /**
59      * Principal routing algorithm. Attempts to find the best route beween
60      * two points. If either point is part of the airway network (e.g, a SID
61      * or STAR transition), it will <em>not</em> be duplicated in the result
62      * path.
63      *
64      * Returns true if a route could be found, or false otherwise.
65      */
66     bool route(WayptRef aFrom, WayptRef aTo, WayptVec& aPath);
67   private:    
68     void addEdge(int aWay, const SGGeod& aStartPos,
69                 const std::string& aStartIdent, 
70                 const SGGeod& aEndPos, const std::string& aEndIdent);
71   
72     int findAirway(const std::string& aName, double aTop, double aBase);
73
74     bool search2(FGPositionedRef aStart, FGPositionedRef aDest, WayptVec& aRoute);
75   
76     /**
77      * Test if a positioned item is part of this airway network or not.
78      */
79     bool inNetwork(PositionedID pos) const;
80     
81     /**
82      * Find the closest node on the network, to the specified waypoint
83      *
84      * May return NULL,false if no match could be found; the search is
85      * internally limited to avoid very poor performance; for example, 
86      * in the middle of an ocean.
87      *
88      * The second return value indicates if the returned value is
89      * equal (true) or distinct (false) to the input waypoint.
90      * Equality here means being physically within a close tolerance,
91      * on the order of a hundred metres.
92      */
93     std::pair<FGPositionedRef, bool> findClosestNode(WayptRef aRef);
94     
95     /**
96      * Overloaded version working with a raw SGGeod
97      */
98   
99     std::pair<FGPositionedRef, bool> findClosestNode(const SGGeod& aGeod);
100     
101     /**
102      * cache which positioned items are in this network
103      */
104     typedef std::map<PositionedID, bool> NetworkMembershipDict;
105     mutable NetworkMembershipDict _inNetworkCache;
106     
107     int _networkID;
108   };
109
110
111   static Network* highLevel();
112   static Network* lowLevel();
113   
114 private:
115   Airway(const std::string& aIdent, double aTop, double aBottom);
116
117   friend class Network;
118   
119   std::string _ident;
120   double _topAltitudeFt;
121   double _bottomAltitudeFt;
122   
123   WayptVec _elements;
124 };
125
126 } // of namespace flightgear
127
128
129 #endif //of FG_AIRWAYS_HXX