1 // airways.hxx - storage of airways network, and routing between nodes
2 // Written by James Turner, started 2009.
4 // Copyright (C) 2009 Curtis L. Olson
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.
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.
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.
20 #ifndef FG_AIRWAYS_HXX
21 #define FG_AIRWAYS_HXX
26 #include <Navaids/route.hxx>
27 #include <Navaids/positioned.hxx>
30 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
32 namespace flightgear {
34 // forward declare some helpers
36 class AdjacentWaypoint;
42 virtual std::string ident() const
45 static void load(const SGPath& path);
47 double topAltitudeFt() const
48 { return _topAltitudeFt; }
50 double bottomAltitudeFt() const
51 { return _bottomAltitudeFt; }
53 static Airway* findByIdent(const std::string& aIdent);
55 WayptRef findEnroute(const std::string& aIdent) const;
57 bool canVia(const WayptRef& from, const WayptRef& to) const;
59 WayptVec via(const WayptRef& from, const WayptRef& to) const;
61 bool containsNavaid(const FGPositionedRef& navaid) const;
64 * Track a network of airways
71 friend class InAirwayFilter;
75 * Principal routing algorithm. Attempts to find the best route beween
76 * two points. If either point is part of the airway network (e.g, a SID
77 * or STAR transition), it will <em>not</em> be duplicated in the result
80 * Returns true if a route could be found, or false otherwise.
82 bool route(WayptRef aFrom, WayptRef aTo, WayptVec& aPath);
86 void addEdge(int aWay, const SGGeod& aStartPos,
87 const std::string& aStartIdent,
88 const SGGeod& aEndPos, const std::string& aEndIdent);
90 int findAirway(const std::string& aName, double aTop, double aBase);
92 bool cleanGeneratedPath(WayptRef aFrom, WayptRef aTo, WayptVec& aPath,
93 bool exactTo, bool exactFrom);
95 bool search2(FGPositionedRef aStart, FGPositionedRef aDest, WayptVec& aRoute);
98 * Test if a positioned item is part of this airway network or not.
100 bool inNetwork(PositionedID pos) const;
103 * Find the closest node on the network, to the specified waypoint
105 * May return NULL,false if no match could be found; the search is
106 * internally limited to avoid very poor performance; for example,
107 * in the middle of an ocean.
109 * The second return value indicates if the returned value is
110 * equal (true) or distinct (false) to the input waypoint.
111 * Equality here means being physically within a close tolerance,
112 * on the order of a hundred metres.
114 std::pair<FGPositionedRef, bool> findClosestNode(WayptRef aRef);
117 * Overloaded version working with a raw SGGeod
120 std::pair<FGPositionedRef, bool> findClosestNode(const SGGeod& aGeod);
123 * cache which positioned items are in this network
125 typedef std::map<PositionedID, bool> NetworkMembershipDict;
126 mutable NetworkMembershipDict _inNetworkCache;
132 static Network* highLevel();
133 static Network* lowLevel();
136 Airway(const std::string& aIdent, double aTop, double aBottom);
138 WayptVec::const_iterator find(WayptRef wpt) const;
140 friend class Network;
143 double _topAltitudeFt;
144 double _bottomAltitudeFt;
149 } // of namespace flightgear
152 #endif //of FG_AIRWAYS_HXX