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/math/SGMath.hxx>
36 #include <simgear/structure/SGReferenced.hxx>
37 #include <simgear/structure/SGSharedPtr.hxx>
38 #include <simgear/props/props.hxx>
53 typedef SGSharedPtr<Waypt> WayptRef;
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.
65 /// waypoint was created automatically (not manually entered/loaded)
66 /// for example waypoints from airway routing or a procedure
67 WPT_GENERATED = 1 << 7,
69 WPT_DEPARTURE = 1 << 8,
81 * Abstract base class for waypoints (and things that are treated similarly
82 * by navigation systems)
84 class Waypt : public SGReferenced
91 * Return true course (in degrees) and distance (in metres) from the provided
92 * position to this waypoint
94 virtual std::pair<double, double> courseAndDistanceFrom(const SGGeod& aPos) const;
96 virtual SGGeod position() const = 0;
99 * The Positioned associated with this element, if one exists
101 virtual FGPositioned* source() const
104 virtual double altitudeFt() const
105 { return _altitudeFt; }
107 virtual double speedKts() const
108 { return _speedKts; }
110 virtual RouteRestriction altitudeRestriction() const
111 { return _altRestrict; }
113 virtual RouteRestriction speedRestriction() const
114 { return _speedRestrict; }
116 void setAltitude(double aAlt, RouteRestriction aRestrict);
117 void setSpeed(double aSpeed, RouteRestriction aRestrict);
120 * Identifier assoicated with the waypoint. Human-readable, but
121 * possibly quite terse, and definitiely not unique.
123 virtual std::string ident() const;
126 * Test if the specified flag is set for this element
128 virtual bool flag(WayptFlag aFlag) const;
130 void setFlag(WayptFlag aFlag, bool aV = true);
135 static WayptRef createFromProperties(Route* aOwner, SGPropertyNode_ptr aProp);
137 void saveAsNode(SGPropertyNode* node) const;
140 * Test if this element and another are 'the same', i.e matching
141 * ident and lat/lon are approximately equal
143 bool matches(Waypt* aOther) const;
146 * Test if this element and a position 'the same'
147 * this can be defined by either position, ident or both
149 bool matches(const SGGeod& aPos) const;
151 virtual std::string type() const = 0;
153 friend class NavdataVisitor;
155 Waypt(Route* aOwner);
158 * Persistence helper - read node properties from a file
160 virtual void initFromProperties(SGPropertyNode_ptr aProp);
163 * Persistence helper - save this element to a node
165 virtual void writeToProperties(SGPropertyNode_ptr aProp) const;
167 typedef Waypt* (FactoryFunction)(Route* aOwner) ;
168 static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory);
172 RouteRestriction _altRestrict;
173 RouteRestriction _speedRestrict;
177 * Create an instance of a concrete subclass, or throw an exception
179 static Waypt* createInstance(Route* aOwner, const std::string& aTypeName);
182 unsigned short _flags;
186 typedef std::vector<WayptRef> WayptVec;
194 virtual std::string ident() const = 0;
196 static void loadAirportProcedures(const SGPath& aPath, FGAirport* aApt);
198 static void dumpRouteToFile(const WayptVec& aRoute, const std::string& aName);
200 static void dumpRouteToLineString(const std::string& aIdent,
201 const WayptVec& aRoute, std::ostream& aStream);
206 } // of namespace flightgear
208 #endif // of FG_ROUTE_HXX