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;
38 typedef SGSharedPtr<FGAirport> FGAirportRef;
41 * Top level route manager class
45 class FGRouteMgr : public SGSubsystem
55 void update (double dt);
57 void insertWayptAtIndex(flightgear::Waypt* aWpt, int aIndex);
58 flightgear::WayptRef removeWayptAtIndex(int index);
63 ROUTE_HIGH_AIRWAYS, ///< high-level airways routing
64 ROUTE_LOW_AIRWAYS, ///< low-level airways routing
65 ROUTE_VOR ///< VOR-VOR routing
69 * Insert waypoints from index-1 to index. In practice this means you can
70 * 'fill in the gaps' between defined waypoints. If index=0, the departure
71 * airport is used as index-1; if index is -1, the destination airport is
72 * used as the final waypoint.
74 bool routeToIndex(int index, RouteType aRouteType);
78 bool isRouteActive() const;
80 int currentIndex() const
81 { return _currentIndex; }
83 flightgear::Waypt* currentWaypt() const;
84 flightgear::Waypt* nextWaypt() const;
85 flightgear::Waypt* previousWaypt() const;
87 const flightgear::WayptVec& waypts() const
91 { return _route.size(); }
93 flightgear::Waypt* wayptAtIndex(int index) const;
96 * Find a waypoint in the route, by position, and return its index, or
97 * -1 if no matching waypoint was found in the route.
99 int findWayptIndex(const SGGeod& aPos) const;
102 * Activate a built route. This checks for various mandatory pieces of
103 * data, such as departure and destination airports, and creates waypoints
104 * for them on the route structure.
106 * returns true if the route was activated successfully, or false if the
107 * route could not be activated for some reason
112 * Step to the next waypoint on the active route
117 * Set the current waypoint to the specified index.
119 void jumpToIndex(int index);
125 * Helper command to setup current airport/runway if necessary
127 void initAtPosition();
129 flightgear::WayptVec _route;
133 time_t _touchdownTime;
134 FGAirportRef _departure;
135 FGAirportRef _destination;
138 SGPropertyNode_ptr lon;
139 SGPropertyNode_ptr lat;
140 SGPropertyNode_ptr alt;
141 SGPropertyNode_ptr magvar;
144 SGPropertyNode_ptr departure; ///< departure airport information
145 SGPropertyNode_ptr destination; ///< destination airport information
146 SGPropertyNode_ptr alternate; ///< alternate airport information
147 SGPropertyNode_ptr cruise; ///< cruise information
149 SGPropertyNode_ptr totalDistance;
150 SGPropertyNode_ptr ete;
151 SGPropertyNode_ptr elapsedFlightTime;
153 SGPropertyNode_ptr active;
154 SGPropertyNode_ptr airborne;
156 SGPropertyNode_ptr wp0;
157 SGPropertyNode_ptr wp1;
158 SGPropertyNode_ptr wpn;
161 SGPropertyNode_ptr _pathNode;
162 SGPropertyNode_ptr _currentWpt;
164 /// integer property corresponding to the RouteType enum
165 SGPropertyNode_ptr _routingType;
168 * Signal property to notify people that the route was edited
170 SGPropertyNode_ptr _edited;
173 * Signal property to notify when the last waypoint is reached
175 SGPropertyNode_ptr _finished;
177 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
179 class InputListener : public SGPropertyChangeListener {
181 InputListener(FGRouteMgr *m) : mgr(m) {}
182 virtual void valueChanged (SGPropertyNode * prop);
187 SGPropertyNode_ptr input;
188 SGPropertyNode_ptr weightOnWheels;
190 InputListener *listener;
191 SGPropertyNode_ptr mirror;
194 * Create a SGWayPoint from a string in the following format:
195 * - simple identifier
196 * - decimal-lon,decimal-lat
197 * - airport-id/runway-id
198 * - navaid/radial-deg/offset-nm
200 flightgear::WayptRef waypointFromString(const std::string& target);
203 void departureChanged();
204 void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
206 void arrivalChanged();
207 void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
210 * Helper to keep various pieces of state in sync when the route is
211 * modified (waypoints added, inserted, removed). Notably, this fires the
214 void waypointsChanged();
216 void update_mirror();
218 void currentWaypointChanged();
221 * Parse a route/wp node (from a saved, property-lsit formatted route)
223 void parseRouteWaypoint(SGPropertyNode* aWP);
226 * Check if we've reached the final waypoint.
227 * Returns true if we have.
229 bool checkFinished();
232 void loadPlainTextRoute(const SGPath& path);
234 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
235 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
236 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
237 flightgear::WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
240 * Predicate for helping the UI - test if at least one waypoint was
241 * entered by the user (as opposed to being generated by the route-manager)
243 bool haveUserWaypoints() const;
245 // tied getters and setters
246 const char* getDepartureICAO() const;
247 const char* getDepartureName() const;
248 void setDepartureICAO(const char* aIdent);
250 const char* getDestinationICAO() const;
251 const char* getDestinationName() const;
252 void setDestinationICAO(const char* aIdent);
254 PropertyWatcher* _departureWatcher;
255 PropertyWatcher* _arrivalWatcher;
259 #endif // _ROUTE_MGR_HXX