]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/airways.hxx
fix trx and rx heights and improve calculations
[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
28 class FGPositioned;
29 typedef SGSharedPtr<FGPositioned> FGPositionedRef; 
30
31 namespace flightgear {
32
33 // forward declare some helpers
34 struct SearchContext;
35 class AdjacentWaypoint;
36 class InAirwayFilter;
37
38 class Airway : public Route
39 {
40 public:
41   virtual std::string ident() const
42   { return _ident; }
43   
44   static void load();
45   
46   /**
47    * Track a network of airways
48    *
49    */
50   class Network
51   {
52   public:
53     friend class Airway;
54     friend class InAirwayFilter;
55     
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(Airway* aWay, const SGGeod& aStartPos, 
69                 const std::string& aStartIdent, 
70                 const SGGeod& aEndPos, const std::string& aEndIdent);
71   
72     Airway* findAirway(const std::string& aName, double aTop, double aBase);
73     
74     typedef std::multimap<FGPositioned*, AdjacentWaypoint*> AdjacencyMap;
75     AdjacencyMap _graph;
76     
77     typedef std::vector<AdjacentWaypoint*> AdjacentWaypointVec;
78
79     typedef std::map<std::string, Airway*> AirwayDict;
80     AirwayDict _airways;
81
82     bool search2(FGPositionedRef aStart, FGPositionedRef aDest, WayptVec& aRoute);
83   
84     /**
85      * Test if a positioned item is part of this airway network or not.
86      */
87     bool inNetwork(const FGPositioned* aRef) const;
88     
89     /**
90      * Find the closest node on the network, to the specified waypoint
91      *
92      * May return NULL,false if no match could be found; the search is
93      * internally limited to avoid very poor performance; for example, 
94      * in the middle of an ocean.
95      *
96      * The second return value indicates if the returned value is
97      * equal (true) or distinct (false) to the input waypoint.
98      * Equality here means being physically within a close tolerance,
99      * on the order of a hundred metres.
100      */
101     std::pair<FGPositionedRef, bool> findClosestNode(WayptRef aRef);
102     
103     /**
104      * Overloaded version working with a raw SGGeod
105      */
106     std::pair<FGPositionedRef, bool> findClosestNode(const SGGeod& aGeod);
107   };
108
109
110   static Network* highLevel();
111   static Network* lowLevel();
112   
113 private:
114   Airway(const std::string& aIdent, double aTop, double aBottom);
115
116   friend class Network;
117   
118   static Network* static_highLevel;
119   static Network* static_lowLevel;
120   
121   std::string _ident;
122   double _topAltitudeFt;
123   double _bottomAltitudeFt;
124
125   // high-level vs low-level flag
126   // ... ?
127   
128   WayptVec _elements;
129 };
130
131 } // of namespace flightgear
132
133
134 #endif //of FG_AIRWAYS_HXX