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.
8 // Written by James Turner, started 2009.
10 // Copyright (C) 2009 Curtis L. Olson
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.
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.
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.
35 #include <simgear/structure/SGReferenced.hxx>
36 #include <simgear/structure/SGSharedPtr.hxx>
37 #include <simgear/props/props.hxx>
52 typedef SGSharedPtr<Waypt> WayptRef;
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.
64 /// waypoint was created automatically (not manually entered/loaded)
65 /// for example waypoints from airway routing or a procedure
66 WPT_GENERATED = 1 << 7,
68 WPT_DEPARTURE = 1 << 8,
71 /// waypoint generated by VNAV / speed management profile,
72 /// for step climbs or top of descent
74 WPT_APPROACH = 1 << 11
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
88 bool isMachRestrict(RouteRestriction rr);
91 * Abstract base class for waypoints (and things that are treated similarly
92 * by navigation systems)
94 class Waypt : public SGReferenced
99 RouteBase* owner() const
103 * Return true course (in degrees) and distance (in metres) from the provided
104 * position to this waypoint
106 virtual std::pair<double, double> courseAndDistanceFrom(const SGGeod& aPos) const;
108 virtual SGGeod position() const = 0;
111 * The Positioned associated with this element, if one exists
113 virtual FGPositioned* source() const
116 virtual double altitudeFt() const
117 { return _altitudeFt; }
119 virtual double speed() const
122 // wrapper - asserts if restriction type is _MACH
123 double speedKts() const;
125 // wrapper - asserts if restriction type is not _MACH
126 double speedMach() const;
128 virtual RouteRestriction altitudeRestriction() const
129 { return _altRestrict; }
131 virtual RouteRestriction speedRestriction() const
132 { return _speedRestrict; }
134 void setAltitude(double aAlt, RouteRestriction aRestrict);
135 void setSpeed(double aSpeed, RouteRestriction aRestrict);
138 * Identifier assoicated with the waypoint. Human-readable, but
139 * possibly quite terse, and definitiely not unique.
141 virtual std::string ident() const;
144 * Test if the specified flag is set for this element
146 virtual bool flag(WayptFlag aFlag) const;
148 virtual unsigned int flags() const
151 void setFlag(WayptFlag aFlag, bool aV = true);
156 static WayptRef createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp);
158 void saveAsNode(SGPropertyNode* node) const;
161 * Test if this element and another are 'the same', i.e matching
162 * ident and lat/lon are approximately equal
164 bool matches(Waypt* aOther) const;
167 * Test if this element and a position 'the same'
168 * this can be defined by either position, ident or both
170 bool matches(const SGGeod& aPos) const;
172 virtual std::string type() const = 0;
175 * Magentic variation at/in the vicinity of the waypoint.
176 * For some waypoint types this will always return 0.
178 virtual double magvarDeg() const;
181 * return the assoicated heading or radial for this waypoint.
182 * The exact meaning varies by type - for a hold it's the inbound radial,
183 * for a DME intercept it's the heading to hold, and so on.
185 virtual double headingRadialDeg() const;
187 friend class NavdataVisitor;
189 Waypt(RouteBase* aOwner);
192 * Persistence helper - read node properties from a file
194 virtual void initFromProperties(SGPropertyNode_ptr aProp);
197 * Persistence helper - save this element to a node
199 virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
201 typedef Waypt* (FactoryFunction)(RouteBase* aOwner) ;
202 static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
205 double _speed; // knots IAS or mach
206 RouteRestriction _altRestrict;
207 RouteRestriction _speedRestrict;
211 * Create an instance of a concrete subclass, or throw an exception
213 static Waypt* createInstance(RouteBase* aOwner, const std::string& aTypeName);
216 unsigned short _flags;
217 mutable double _magVarDeg;
220 typedef std::vector<WayptRef> WayptVec;
222 class RouteBase : public SGReferenced
228 virtual std::string ident() const = 0;
230 static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
232 static void dumpRouteToKML(const WayptVec& aRoute, const std::string& aName);
234 static void dumpRouteToKMLLineString(const std::string& aIdent,
235 const WayptVec& aRoute, std::ostream& aStream);
240 } // of namespace flightgear
242 #endif // of FG_ROUTE_HXX