]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/route.hxx
Remove redundant inclusion of math/SGMath.hxx
[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/structure/SGReferenced.hxx>
36 #include <simgear/structure/SGSharedPtr.hxx>
37 #include <simgear/props/props.hxx>
38
39 // forward decls
40 class FGPositioned;
41 class SGPath;
42 class FGAirport;
43
44 namespace flightgear
45 {
46
47 // forward decls
48 class Route;
49 class Waypt;
50 class NavdataVisitor;
51
52 typedef SGSharedPtr<Waypt> WayptRef;
53
54 typedef enum {
55         WPT_MAP           = 1 << 0, ///< missed approach point
56         WPT_IAF           = 1 << 1, ///< initial approach fix
57         WPT_FAF           = 1 << 2, ///< final approach fix
58         WPT_OVERFLIGHT    = 1 << 3, ///< must overfly the point directly
59         WPT_TRANSITION    = 1 << 4, ///< transition to/from enroute structure
60         WPT_MISS          = 1 << 5, ///< segment is part of missed approach
61   /// waypoint position is dynamic, i.e moves based on other criteria,
62   /// such as altitude, inbound course, or so on.
63   WPT_DYNAMIC       = 1 << 6,
64   /// waypoint was created automatically (not manually entered/loaded)
65   /// for example waypoints from airway routing or a procedure  
66   WPT_GENERATED     = 1 << 7,
67   
68   WPT_DEPARTURE     = 1 << 8,
69   WPT_ARRIVAL       = 1 << 9
70 } WayptFlag;
71
72 typedef enum {
73         RESTRICT_NONE,
74         RESTRICT_AT,
75         RESTRICT_ABOVE,
76         RESTRICT_BELOW,
77   SPEED_RESTRICT_MACH
78 } RouteRestriction;
79
80 /**
81  * Abstract base class for waypoints (and things that are treated similarly
82  * by navigation systems)
83  */
84 class Waypt : public SGReferenced
85 {
86 public:
87   virtual ~Waypt();
88   
89         Route* owner() const 
90                 { return _owner; }
91   
92   /**
93    * Return true course (in degrees) and distance (in metres) from the provided
94    * position to this waypoint
95    */
96   virtual std::pair<double, double> courseAndDistanceFrom(const SGGeod& aPos) const;
97                         
98         virtual SGGeod position() const = 0;
99         
100         /**
101          * The Positioned associated with this element, if one exists
102          */
103         virtual FGPositioned* source() const
104                 { return NULL; }
105         
106         virtual double altitudeFt() const 
107                 { return _altitudeFt; }
108                 
109   virtual double speed() const
110     { return _speed; }
111   
112 // wrapper - asserts if restriction type is _MACH
113   double speedKts() const;
114   
115 // wrapper - asserts if restriction type is not _MACH
116   double speedMach() const;
117   
118         virtual RouteRestriction altitudeRestriction() const
119                 { return _altRestrict; }
120         
121         virtual RouteRestriction speedRestriction() const
122                 { return _speedRestrict; }
123         
124   void setAltitude(double aAlt, RouteRestriction aRestrict);
125   void setSpeed(double aSpeed, RouteRestriction aRestrict);
126   
127   /**
128    * Identifier assoicated with the waypoint. Human-readable, but
129    * possibly quite terse, and definitiely not unique.
130    */
131         virtual std::string ident() const;
132         
133         /**
134          * Test if the specified flag is set for this element
135          */
136         virtual bool flag(WayptFlag aFlag) const;
137         
138   void setFlag(WayptFlag aFlag, bool aV = true);
139   
140   /**
141    * Factory method
142    */
143   static WayptRef createFromProperties(Route* aOwner, SGPropertyNode_ptr aProp);
144   
145   void saveAsNode(SGPropertyNode* node) const;
146   
147   /**
148    * Test if this element and another are 'the same', i.e matching
149    * ident and lat/lon are approximately equal
150    */
151   bool matches(Waypt* aOther) const;
152
153   /**
154    * Test if this element and a position 'the same'
155    * this can be defined by either position, ident or both
156    */
157   bool matches(const SGGeod& aPos) const;
158   
159   virtual std::string type() const = 0;
160   
161   /**
162    * Magentic variation at/in the vicinity of the waypoint.
163    * For some waypoint types this will always return 0.
164    */
165   virtual double magvarDeg() const;
166   
167   /**
168    * return the assoicated heading  or radial for this waypoint.
169    * The exact meaning varies by type - for a hold it's the inbound radial,
170    * for a DME intercept it's the heading to hold, and so on. 
171    */
172   virtual double headingRadialDeg() const;
173 protected:
174   friend class NavdataVisitor;
175   
176         Waypt(Route* aOwner);
177   
178   /**
179    * Persistence helper - read node properties from a file
180    */
181   virtual void initFromProperties(SGPropertyNode_ptr aProp);
182   
183   /**
184    * Persistence helper - save this element to a node
185    */
186   virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
187   
188   typedef Waypt* (FactoryFunction)(Route* aOwner) ;
189   static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
190   
191   double _altitudeFt;
192         double _speed; // knots IAS or mach
193         RouteRestriction _altRestrict;
194         RouteRestriction _speedRestrict;
195 private:
196
197   /**
198    * Create an instance of a concrete subclass, or throw an exception
199    */
200   static Waypt* createInstance(Route* aOwner, const std::string& aTypeName);
201
202         Route* _owner;
203         unsigned short _flags;
204   mutable double _magVarDeg; 
205 };
206
207 typedef std::vector<WayptRef> WayptVec;
208   
209 class Route
210 {
211 public:
212   /**
213    *
214    */
215   virtual std::string ident() const = 0;
216   
217   static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
218   
219   static void dumpRouteToFile(const WayptVec& aRoute, const std::string& aName);
220   
221   static void dumpRouteToLineString(const std::string& aIdent,
222     const WayptVec& aRoute, std::ostream& aStream);
223 private:
224
225 };
226
227 } // of namespace flightgear
228
229 #endif // of FG_ROUTE_HXX