]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/route.hxx
Remove /sim/paths/use-custom-scenery-data.
[flightgear.git] / src / Navaids / route.hxx
1 /**
2  * route.hxx - defines basic route and route-element classes. Route elements
3  * are specialised into waypoints and related things. Routes are any class tha
4  * owns a collection (list, tree, graph) of route elements - such as airways,
5  * procedures or a flight plan.
6  */
7  
8 // Written by James Turner, started 2009.
9 //
10 // Copyright (C) 2009  Curtis L. Olson
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of the
15 // License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 // General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
25
26 #ifndef FG_ROUTE_HXX
27 #define FG_ROUTE_HXX
28
29 // std
30 #include <vector>
31 #include <map>
32 #include <iosfwd>
33
34 // Simgear
35 #include <simgear/math/SGMath.hxx>
36 #include <simgear/structure/SGReferenced.hxx>
37 #include <simgear/structure/SGSharedPtr.hxx>
38 #include <simgear/props/props.hxx>
39
40 // forward decls
41 class FGPositioned;
42 class SGPath;
43 class FGAirport;
44
45 namespace flightgear
46 {
47
48 // forward decls
49 class Route;
50 class Waypt;
51 class NavdataVisitor;
52
53 typedef SGSharedPtr<Waypt> WayptRef;
54
55 typedef enum {
56         WPT_MAP           = 1 << 0, ///< missed approach point
57         WPT_IAF           = 1 << 1, ///< initial approach fix
58         WPT_FAF           = 1 << 2, ///< final approach fix
59         WPT_OVERFLIGHT    = 1 << 3, ///< must overfly the point directly
60         WPT_TRANSITION    = 1 << 4, ///< transition to/from enroute structure
61         WPT_MISS          = 1 << 5, ///< segment is part of missed approach
62   /// waypoint position is dynamic, i.e moves based on other criteria,
63   /// such as altitude, inbound course, or so on.
64   WPT_DYNAMIC       = 1 << 6,
65   /// waypoint was created automatically (not manually entered/loaded)
66   /// for example waypoints from airway routing or a procedure  
67   WPT_GENERATED     = 1 << 7,
68   
69   WPT_DEPARTURE     = 1 << 8,
70   WPT_ARRIVAL       = 1 << 9
71 } WayptFlag;
72
73 typedef enum {
74         RESTRICT_NONE,
75         RESTRICT_AT,
76         RESTRICT_ABOVE,
77         RESTRICT_BELOW,
78   SPEED_RESTRICT_MACH
79 } RouteRestriction;
80
81 /**
82  * Abstract base class for waypoints (and things that are treated similarly
83  * by navigation systems)
84  */
85 class Waypt : public SGReferenced
86 {
87 public:
88   virtual ~Waypt();
89   
90         Route* owner() const 
91                 { return _owner; }
92   
93   /**
94    * Return true course (in degrees) and distance (in metres) from the provided
95    * position to this waypoint
96    */
97   virtual std::pair<double, double> courseAndDistanceFrom(const SGGeod& aPos) const;
98                         
99         virtual SGGeod position() const = 0;
100         
101         /**
102          * The Positioned associated with this element, if one exists
103          */
104         virtual FGPositioned* source() const
105                 { return NULL; }
106         
107         virtual double altitudeFt() const 
108                 { return _altitudeFt; }
109                 
110   virtual double speed() const
111     { return _speed; }
112   
113 // wrapper - asserts if restriction type is _MACH
114   double speedKts() const;
115   
116 // wrapper - asserts if restriction type is not _MACH
117   double speedMach() const;
118   
119         virtual RouteRestriction altitudeRestriction() const
120                 { return _altRestrict; }
121         
122         virtual RouteRestriction speedRestriction() const
123                 { return _speedRestrict; }
124         
125   void setAltitude(double aAlt, RouteRestriction aRestrict);
126   void setSpeed(double aSpeed, RouteRestriction aRestrict);
127   
128   /**
129    * Identifier assoicated with the waypoint. Human-readable, but
130    * possibly quite terse, and definitiely not unique.
131    */
132         virtual std::string ident() const;
133         
134         /**
135          * Test if the specified flag is set for this element
136          */
137         virtual bool flag(WayptFlag aFlag) const;
138         
139   void setFlag(WayptFlag aFlag, bool aV = true);
140   
141   /**
142    * Factory method
143    */
144   static WayptRef createFromProperties(Route* aOwner, SGPropertyNode_ptr aProp);
145   
146   void saveAsNode(SGPropertyNode* node) const;
147   
148   /**
149    * Test if this element and another are 'the same', i.e matching
150    * ident and lat/lon are approximately equal
151    */
152   bool matches(Waypt* aOther) const;
153
154   /**
155    * Test if this element and a position 'the same'
156    * this can be defined by either position, ident or both
157    */
158   bool matches(const SGGeod& aPos) const;
159   
160   virtual std::string type() const = 0;
161   
162   /**
163    * Magentic variation at/in the vicinity of the waypoint.
164    * For some waypoint types this will always return 0.
165    */
166   virtual double magvarDeg() const;
167 protected:
168   friend class NavdataVisitor;
169   
170         Waypt(Route* aOwner);
171   
172   /**
173    * Persistence helper - read node properties from a file
174    */
175   virtual void initFromProperties(SGPropertyNode_ptr aProp);
176   
177   /**
178    * Persistence helper - save this element to a node
179    */
180   virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
181   
182   typedef Waypt* (FactoryFunction)(Route* aOwner) ;
183   static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
184   
185   double _altitudeFt;
186         double _speed; // knots IAS or mach
187         RouteRestriction _altRestrict;
188         RouteRestriction _speedRestrict;
189 private:
190
191   /**
192    * Create an instance of a concrete subclass, or throw an exception
193    */
194   static Waypt* createInstance(Route* aOwner, const std::string& aTypeName);
195
196         Route* _owner;
197         unsigned short _flags;
198   mutable double _magVarDeg; 
199 };
200
201 typedef std::vector<WayptRef> WayptVec;
202   
203 class Route
204 {
205 public:
206   /**
207    *
208    */
209   virtual std::string ident() const = 0;
210   
211   static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
212   
213   static void dumpRouteToFile(const WayptVec& aRoute, const std::string& aName);
214   
215   static void dumpRouteToLineString(const std::string& aIdent,
216     const WayptVec& aRoute, std::ostream& aStream);
217 private:
218
219 };
220
221 } // of namespace flightgear
222
223 #endif // of FG_ROUTE_HXX