1 // route_mgr.hxx - manage a route (i.e. a collection of waypoints)
3 // Written by Curtis Olson, started January 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef _ROUTE_MGR_HXX
25 #define _ROUTE_MGR_HXX 1
27 #include <simgear/props/props.hxx>
28 #include <simgear/route/waypoint.hxx>
29 #include <simgear/structure/subsystem_mgr.hxx>
31 #include <Navaids/route.hxx>
35 class PropertyWatcher;
40 typedef SGSharedPtr<FGAirport> FGAirportRef;
43 * Top level route manager class
47 class FGRouteMgr : public SGSubsystem
57 void update (double dt);
59 void insertWayptAtIndex(flightgear::Waypt* aWpt, int aIndex);
60 flightgear::WayptRef removeWayptAtIndex(int index);
65 ROUTE_HIGH_AIRWAYS, ///< high-level airways routing
66 ROUTE_LOW_AIRWAYS, ///< low-level airways routing
67 ROUTE_VOR ///< VOR-VOR routing
71 * Insert waypoints from index-1 to index. In practice this means you can
72 * 'fill in the gaps' between defined waypoints. If index=0, the departure
73 * airport is used as index-1; if index is -1, the destination airport is
74 * used as the final waypoint.
76 bool routeToIndex(int index, RouteType aRouteType);
80 bool isRouteActive() const;
82 int currentIndex() const
83 { return _currentIndex; }
85 flightgear::Waypt* currentWaypt() const;
86 flightgear::Waypt* nextWaypt() const;
87 flightgear::Waypt* previousWaypt() const;
89 const flightgear::WayptVec& waypts() const
93 { return _route.size(); }
95 flightgear::Waypt* wayptAtIndex(int index) const;
98 * Find a waypoint in the route, by position, and return its index, or
99 * -1 if no matching waypoint was found in the route.
101 int findWayptIndex(const SGGeod& aPos) const;
104 * Activate a built route. This checks for various mandatory pieces of
105 * data, such as departure and destination airports, and creates waypoints
106 * for them on the route structure.
108 * returns true if the route was activated successfully, or false if the
109 * route could not be activated for some reason
114 * Step to the next waypoint on the active route
119 * Set the current waypoint to the specified index.
121 void jumpToIndex(int index);
123 bool saveRoute(const SGPath& p);
124 bool loadRoute(const SGPath& p);
127 * Helper command to setup current airport/runway if necessary
129 void initAtPosition();
132 * Create a WayPoint from a string in the following format:
133 * - simple identifier
134 * - decimal-lon,decimal-lat
135 * - airport-id/runway-id
136 * - navaid/radial-deg/offset-nm
138 flightgear::WayptRef waypointFromString(const std::string& target);
140 FGAirportRef departureAirport() const;
141 FGAirportRef destinationAirport() const;
143 FGRunway* departureRunway() const;
144 FGRunway* destinationRunway() const;
146 flightgear::WayptVec _route;
150 time_t _touchdownTime;
151 FGAirportRef _departure;
152 FGAirportRef _destination;
155 SGPropertyNode_ptr lon;
156 SGPropertyNode_ptr lat;
157 SGPropertyNode_ptr alt;
158 SGPropertyNode_ptr magvar;
161 SGPropertyNode_ptr departure; ///< departure airport information
162 SGPropertyNode_ptr destination; ///< destination airport information
163 SGPropertyNode_ptr alternate; ///< alternate airport information
164 SGPropertyNode_ptr cruise; ///< cruise information
166 SGPropertyNode_ptr totalDistance;
167 SGPropertyNode_ptr ete;
168 SGPropertyNode_ptr elapsedFlightTime;
170 SGPropertyNode_ptr active;
171 SGPropertyNode_ptr airborne;
173 SGPropertyNode_ptr wp0;
174 SGPropertyNode_ptr wp1;
175 SGPropertyNode_ptr wpn;
178 SGPropertyNode_ptr _pathNode;
179 SGPropertyNode_ptr _currentWpt;
181 /// integer property corresponding to the RouteType enum
182 SGPropertyNode_ptr _routingType;
185 * Signal property to notify people that the route was edited
187 SGPropertyNode_ptr _edited;
190 * Signal property to notify when the last waypoint is reached
192 SGPropertyNode_ptr _finished;
194 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
196 class InputListener : public SGPropertyChangeListener {
198 InputListener(FGRouteMgr *m) : mgr(m) {}
199 virtual void valueChanged (SGPropertyNode * prop);
204 SGPropertyNode_ptr input;
205 SGPropertyNode_ptr weightOnWheels;
207 InputListener *listener;
208 SGPropertyNode_ptr mirror;
210 void departureChanged();
211 void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
213 void arrivalChanged();
214 void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
217 * Helper to keep various pieces of state in sync when the route is
218 * modified (waypoints added, inserted, removed). Notably, this fires the
221 void waypointsChanged();
223 void update_mirror();
225 void currentWaypointChanged();
228 * Parse a route/wp node (from a saved, property-lsit formatted route)
230 void parseRouteWaypoint(SGPropertyNode* aWP);
233 * Check if we've reached the final waypoint.
234 * Returns true if we have.
236 bool checkFinished();
239 bool loadPlainTextRoute(const SGPath& path);
241 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
242 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
243 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
244 flightgear::WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
247 * Predicate for helping the UI - test if at least one waypoint was
248 * entered by the user (as opposed to being generated by the route-manager)
250 bool haveUserWaypoints() const;
252 // tied getters and setters
253 const char* getDepartureICAO() const;
254 const char* getDepartureName() const;
255 void setDepartureICAO(const char* aIdent);
257 const char* getDestinationICAO() const;
258 const char* getDestinationName() const;
259 void setDestinationICAO(const char* aIdent);
261 PropertyWatcher* _departureWatcher;
262 PropertyWatcher* _arrivalWatcher;
266 #endif // _ROUTE_MGR_HXX