Debian Codegraph @

src/Navaids/route.hxx

raw symbols SCIP
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 // Copyright (C) 2009 James Turner
8 // SPDX-License-Identifier: GPL-2.0-or-later
9
10 #pragma once
11
12 // std
13 #include <vector>
14 #include <map>
15 #include <iosfwd>
16 #include <optional>
17
18 // Simgear
19 #include <simgear/structure/SGReferenced.hxx>
20 #include <simgear/structure/SGSharedPtr.hxx>
21 #include <simgear/props/props.hxx>
22
23 // forward decls
24 class FGPositioned;
25 class SGPath;
26 class FGAirport;
27
28 namespace flightgear
29 {
30
31 // forward decls
32 class RouteBase;
33 class Waypt;
34 class NavdataVisitor;
35 class Airway;
36
37 using AirwayRef = SGSharedPtr<Airway>;
38 typedef SGSharedPtr<Waypt> WayptRef;
39
40 typedef enum {
41 WPT_MAP = 1 << 0, ///< missed approach point
42 WPT_IAF = 1 << 1, ///< initial approach fix
43 WPT_FAF = 1 << 2, ///< final approach fix
44 WPT_OVERFLIGHT = 1 << 3, ///< must overfly the point directly
45 WPT_TRANSITION = 1 << 4, ///< transition to/from enroute structure
46 WPT_MISS = 1 << 5, ///< segment is part of missed approach
47 /// waypoint position is dynamic, i.e moves based on other criteria,
48 /// such as altitude, inbound course, or so on.
49 WPT_DYNAMIC = 1 << 6,
50 /// waypoint was created automatically (not manually entered/loaded)
51 /// for example waypoints from airway routing or a procedure
52 WPT_GENERATED = 1 << 7,
53
54 WPT_DEPARTURE = 1 << 8,
55 WPT_ARRIVAL = 1 << 9,
56
57 /// waypoint generated by VNAV / speed management profile,
58 /// for step climbs or top of descent
59 WPT_PSEUDO = 1 << 10,
60 WPT_APPROACH = 1 << 11,
61
62 /// waypoint prodcued by expanding a VIA segment
63 WPT_VIA = 1 << 12,
64
65 /// waypoint should not be shown in UI displays, etc
66 /// this is used to implement FMSs which delete waypoints after passing them
67 WPT_HIDDEN = 1 << 13
68 } WayptFlag;
69
70 typedef enum {
71 RESTRICT_NONE,
72 RESTRICT_AT,
73 RESTRICT_ABOVE,
74 RESTRICT_BELOW,
75 RESTRICT_BETWEEN,
76 SPEED_RESTRICT_MACH, ///< encode an 'AT' restriction in Mach, not IAS
77 RESTRICT_DELETE, ///< ignore underlying restriction (on a leg)
78 RESTRICT_COMPUTED, ///< data is computed, not a real restriction
79 SPEED_COMPUTED_MACH ///< variant on above to encode a Mach value
80 } RouteRestriction;
81
82 typedef enum {
83 DEFAULT_UNITS = 0,
84 ALTITUDE_FEET,
85 ALTITUDE_METER,
86 ALTITUDE_FLIGHTLEVEL,
87 SPEED_KNOTS,
88 SPEED_MACH,
89 SPEED_KPH
90 } RouteUnits;
91
92 RouteRestriction restrictionFromString(const std::string& t);
93
94 bool isMachRestrict(RouteRestriction rr);
95
96 double convertSpeedUnits(RouteUnits aSrc, RouteUnits aDest, double aAltitudeFt, double aValue);
97 double convertAltitudeUnits(RouteUnits aSrc, RouteUnits aDest, double aValue);
98
99 /**
100 * Abstract base class for waypoints (and things that are treated similarly
101 * by navigation systems). More precisely this is route path elements,
102 * including their terminator.
103 */
104 class Waypt : public SGReferenced
105 {
106 public:
107 virtual ~Waypt();
108
109 RouteBase* owner() const
110 { return const_cast<RouteBase*>(_owner); }
111
112 virtual SGGeod position() const = 0;
113
114 /**
115 * The Positioned associated with this element, if one exists
116 */
117 virtual FGPositioned* source() const
118 { return nullptr; }
119
120 double altitudeFt() const;
121
122 double speed(RouteUnits aUnits = DEFAULT_UNITS) const;
123
124 double altitude(RouteUnits aUnits = DEFAULT_UNITS) const;
125
126 double constraintAltitude(RouteUnits aUnits = DEFAULT_UNITS) const;
127
128 // wrapper - asserts if restriction type is _MACH
129 double speedKts() const;
130
131 // wrapper - asserts if restriction type is not _MACH
132 double speedMach() const;
133
134 virtual RouteRestriction altitudeRestriction() const
135 { return _altRestrict; }
136
137 virtual RouteRestriction speedRestriction() const
138 { return _speedRestrict; }
139
140 void setAltitude(double aAlt, RouteRestriction aRestrict, RouteUnits aUnits = DEFAULT_UNITS);
141 void setSpeed(double aSpeed, RouteRestriction aRestrict, RouteUnits aUnits = DEFAULT_UNITS);
142
143 void setConstraintAltitude(double aAlt);
144
145 /**
146 * Identifier assoicated with the waypoint. Human-readable, but
147 * possibly quite terse, and definitiely not unique.
148 */
149 virtual std::string ident() const;
150
151 /**
152 * Test if the specified flag is set for this element
153 */
154 virtual bool flag(WayptFlag aFlag) const;
155
156 virtual unsigned int flags() const
157 { return _flags; }
158
159 void setFlag(WayptFlag aFlag, bool aV = true);
160
161 /**
162 * Factory method
163 */
164 static WayptRef createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp);
165
166 /**
167 Create a waypoint from the route manager's standard string format:
168 * - simple identifier
169 * - decimal-lon,decimal-lat
170 * - airport-id/runway-id
171 * - navaid/radial-deg/offset-nm
172 */
173 static WayptRef createFromString(RouteBase* aOwner, const std::string& s, const SGGeod& vicinity);
174
175 static WayptRef fromLatLonString(RouteBase* aOwner, const std::string& target);
176
177
178 void saveAsNode(SGPropertyNode* node) const;
179
180 /**
181 * Test if this element and another are 'the same', i.e matching
182 * ident and lat/lon are approximately equal
183 */
184 bool matches(Waypt* aOther) const;
185
186 /**
187 * Test if this element and positioned are the same, i.e matching
188 * ident and lat/lon are approximately equal
189 */
190 bool matches(FGPositioned* aPos) const;
191
192 /**
193 * Test if this element and a position 'the same'
194 * this can be defined by either position, ident or both
195 */
196 bool matches(const SGGeod& aPos) const;
197
198 virtual std::string type() const = 0;
199
200 /**
201 * Magentic variation at/in the vicinity of the waypoint.
202 * For some waypoint types this will always return 0.
203 */
204 virtual double magvarDeg() const;
205
206 /**
207 * return the assoicated heading or radial for this waypoint.
208 * The exact meaning varies by type - for a hold it's the inbound radial,
209 * for a DME intercept it's the heading to hold, and so on.
210 */
211 virtual double headingRadialDeg() const;
212
213 /**
214 * @brief icaoDescription - description of the waypoint in ICAO route plan format
215 * @return
216 */
217 virtual std::string icaoDescription() const;
218
219 protected:
220 friend class NavdataVisitor;
221
222 Waypt(RouteBase* aOwner);
223
224 /**
225 * Persistence helper - read node properties from a file
226 */
227 virtual bool initFromProperties(SGPropertyNode_ptr aProp);
228
229 /**
230 * Persistence helper - save this element to a node
231 */
232 virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
233
234 typedef Waypt*(FactoryFunction)(RouteBase* aOwner);
235 static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
236
237 double _altitude = 0.0;
238 /// some restriction types specify two altitudes, in which case this is the second value, corresponding to
239 /// AltitudeCons in the level-D XML procedures format.
240 std::optional<double> _constraintAltitude;
241
242 RouteUnits _altitudeUnits = ALTITUDE_FEET;
243
244 double _speed = 0.0;
245 RouteUnits _speedUnits = SPEED_KNOTS;
246
247 RouteRestriction _altRestrict = RESTRICT_NONE;
248 RouteRestriction _speedRestrict = RESTRICT_NONE;
249 private:
250
251 /**
252 * Create an instance of a concrete subclass, or throw an exception
253 */
254 static WayptRef createInstance(RouteBase* aOwner, const std::string& aTypeName);
255
256 const RouteBase* _owner = nullptr;
257 unsigned short _flags = 0;
258 mutable double _magVarDeg = 0.0; ///< cached mag var at this location
259 };
260
261 typedef std::vector<WayptRef> WayptVec;
262
263 class RouteBase : public SGReferenced
264 {
265 public:
266 virtual ~RouteBase();
267
268 /**
269 *
270 */
271 virtual std::string ident() const = 0;
272
273 static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
274
275 static void dumpRouteToKML(const WayptVec& aRoute, const std::string& aName);
276
277 static void dumpRouteToKMLLineString(const std::string& aIdent,
278 const WayptVec& aRoute, std::ostream& aStream);
279 private:
280
281 };
282
283 } // of namespace flightgear