]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/route.hxx
Nasal: use SG_LOG for security error messages to avoid truncation
[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 RouteBase;
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   
71   /// waypoint generated by VNAV / speed management profile,
72   /// for step climbs or top of descent
73   WPT_PSEUDO        = 1 << 10,
74   WPT_APPROACH      = 1 << 11
75 } WayptFlag;
76
77 typedef enum {
78         RESTRICT_NONE,
79         RESTRICT_AT,
80         RESTRICT_ABOVE,
81         RESTRICT_BELOW,
82   SPEED_RESTRICT_MACH,  ///< encode an 'AT' restriction in Mach, not IAS
83   RESTRICT_DELETE,      ///< ignore underlying restriction (on a leg)
84   RESTRICT_COMPUTED,    ///< data is computed, not a real restriction
85   SPEED_COMPUTED_MACH   ///< variant on above to encode a Mach value
86 } RouteRestriction;
87
88 bool isMachRestrict(RouteRestriction rr);
89   
90 /**
91  * Abstract base class for waypoints (and things that are treated similarly
92  * by navigation systems)
93  */
94 class Waypt : public SGReferenced
95 {
96 public:
97   virtual ~Waypt();
98   
99         RouteBase* owner() const 
100                 { return _owner; }
101                 
102         virtual SGGeod position() const = 0;
103         
104         /**
105          * The Positioned associated with this element, if one exists
106          */
107         virtual FGPositioned* source() const
108                 { return NULL; }
109         
110         virtual double altitudeFt() const 
111                 { return _altitudeFt; }
112                 
113   virtual double speed() const
114     { return _speed; }
115   
116 // wrapper - asserts if restriction type is _MACH
117   double speedKts() const;
118   
119 // wrapper - asserts if restriction type is not _MACH
120   double speedMach() const;
121   
122         virtual RouteRestriction altitudeRestriction() const
123                 { return _altRestrict; }
124         
125         virtual RouteRestriction speedRestriction() const
126                 { return _speedRestrict; }
127         
128   void setAltitude(double aAlt, RouteRestriction aRestrict);
129   void setSpeed(double aSpeed, RouteRestriction aRestrict);
130   
131   /**
132    * Identifier assoicated with the waypoint. Human-readable, but
133    * possibly quite terse, and definitiely not unique.
134    */
135         virtual std::string ident() const;
136         
137         /**
138          * Test if the specified flag is set for this element
139          */
140         virtual bool flag(WayptFlag aFlag) const;
141         
142   virtual unsigned int flags() const
143   { return _flags; }
144   
145   void setFlag(WayptFlag aFlag, bool aV = true);
146   
147   /**
148    * Factory method
149    */
150   static WayptRef createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp);
151   
152   void saveAsNode(SGPropertyNode* node) const;
153   
154   /**
155    * Test if this element and another are 'the same', i.e matching
156    * ident and lat/lon are approximately equal
157    */
158   bool matches(Waypt* aOther) const;
159
160   /**
161    * Test if this element and a position 'the same'
162    * this can be defined by either position, ident or both
163    */
164   bool matches(const SGGeod& aPos) const;
165   
166   virtual std::string type() const = 0;
167   
168   /**
169    * Magentic variation at/in the vicinity of the waypoint.
170    * For some waypoint types this will always return 0.
171    */
172   virtual double magvarDeg() const;
173   
174   /**
175    * return the assoicated heading  or radial for this waypoint.
176    * The exact meaning varies by type - for a hold it's the inbound radial,
177    * for a DME intercept it's the heading to hold, and so on. 
178    */
179   virtual double headingRadialDeg() const;
180 protected:
181   friend class NavdataVisitor;
182   
183         Waypt(RouteBase* aOwner);
184   
185   /**
186    * Persistence helper - read node properties from a file
187    */
188   virtual void initFromProperties(SGPropertyNode_ptr aProp);
189   
190   /**
191    * Persistence helper - save this element to a node
192    */
193   virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
194   
195   typedef Waypt* (FactoryFunction)(RouteBase* aOwner) ;
196   static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
197   
198   double _altitudeFt;
199         double _speed; // knots IAS or mach
200         RouteRestriction _altRestrict;
201         RouteRestriction _speedRestrict;
202 private:
203
204   /**
205    * Create an instance of a concrete subclass, or throw an exception
206    */
207   static Waypt* createInstance(RouteBase* aOwner, const std::string& aTypeName);
208
209         RouteBase* _owner;
210         unsigned short _flags;
211   mutable double _magVarDeg; 
212 };
213
214 typedef std::vector<WayptRef> WayptVec;
215   
216 class RouteBase : public SGReferenced
217 {
218 public:
219   /**
220    *
221    */
222   virtual std::string ident() const = 0;
223   
224   static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
225   
226   static void dumpRouteToKML(const WayptVec& aRoute, const std::string& aName);
227   
228   static void dumpRouteToKMLLineString(const std::string& aIdent,
229     const WayptVec& aRoute, std::ostream& aStream);
230 private:
231
232 };
233
234 } // of namespace flightgear
235
236 #endif // of FG_ROUTE_HXX