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/structure/subsystem_mgr.hxx>
30 #include <Navaids/FlightPlan.hxx>
34 class PropertyWatcher;
37 * Top level route manager class
41 class FGRouteMgr : public SGSubsystem,
42 public flightgear::FlightPlan::Delegate
52 void update (double dt);
54 bool isRouteActive() const;
56 int currentIndex() const;
58 void setFlightPlan(flightgear::FlightPlan* plan);
59 flightgear::FlightPlan* flightPlan() const;
63 flightgear::Waypt* currentWaypt() const;
72 flightgear::Waypt* wayptAtIndex(int index) const;
74 SGPropertyNode_ptr wayptNodeAtIndex(int index) const;
76 void removeLegAtIndex(int aIndex);
79 * Activate a built route. This checks for various mandatory pieces of
80 * data, such as departure and destination airports, and creates waypoints
81 * for them on the route structure.
83 * returns true if the route was activated successfully, or false if the
84 * route could not be activated for some reason
89 * Step to the next waypoint on the active route
94 * Set the current waypoint to the specified index.
96 void jumpToIndex(int index);
98 bool saveRoute(const SGPath& p);
99 bool loadRoute(const SGPath& p);
101 flightgear::WayptRef waypointFromString(const std::string& target);
104 * Helper command to setup current airport/runway if necessary
106 void initAtPosition();
109 flightgear::FlightPlan* _plan;
112 time_t _touchdownTime;
115 SGPropertyNode_ptr magvar;
118 SGPropertyNode_ptr departure; ///< departure airport information
119 SGPropertyNode_ptr destination; ///< destination airport information
120 SGPropertyNode_ptr alternate; ///< alternate airport information
121 SGPropertyNode_ptr cruise; ///< cruise information
123 SGPropertyNode_ptr totalDistance;
124 SGPropertyNode_ptr distanceToGo;
125 SGPropertyNode_ptr ete;
126 SGPropertyNode_ptr elapsedFlightTime;
128 SGPropertyNode_ptr active;
129 SGPropertyNode_ptr airborne;
131 SGPropertyNode_ptr wp0;
132 SGPropertyNode_ptr wp1;
133 SGPropertyNode_ptr wpn;
136 SGPropertyNode_ptr _pathNode;
137 SGPropertyNode_ptr _currentWpt;
141 * Signal property to notify people that the route was edited
143 SGPropertyNode_ptr _edited;
146 * Signal property to notify when the last waypoint is reached
148 SGPropertyNode_ptr _finished;
150 SGPropertyNode_ptr _flightplanChanged;
152 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
155 * retrieve the cached path distance along a leg
157 double cachedLegPathDistanceM(int index) const;
158 double cachedWaypointPathTotalDistance(int index) const;
160 class InputListener : public SGPropertyChangeListener {
162 InputListener(FGRouteMgr *m) : mgr(m) {}
163 virtual void valueChanged (SGPropertyNode * prop);
168 SGPropertyNode_ptr input;
169 SGPropertyNode_ptr weightOnWheels;
170 SGPropertyNode_ptr groundSpeed;
172 InputListener *listener;
173 SGPropertyNode_ptr mirror;
175 virtual void departureChanged();
176 void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
178 virtual void arrivalChanged();
179 void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
182 * Helper to keep various pieces of state in sync when the route is
183 * modified (waypoints added, inserted, removed). Notably, this fires the
186 virtual void waypointsChanged();
188 void update_mirror();
190 virtual void currentWaypointChanged();
193 * Check if we've reached the final waypoint.
194 * Returns true if we have.
196 bool checkFinished();
199 * Predicate for helping the UI - test if at least one waypoint was
200 * entered by the user (as opposed to being generated by the route-manager)
202 bool haveUserWaypoints() const;
204 // tied getters and setters
205 const char* getDepartureICAO() const;
206 const char* getDepartureName() const;
207 void setDepartureICAO(const char* aIdent);
209 const char* getDepartureRunway() const;
210 void setDepartureRunway(const char* aIdent);
212 const char* getSID() const;
213 void setSID(const char* aIdent);
215 const char* getDestinationICAO() const;
216 const char* getDestinationName() const;
217 void setDestinationICAO(const char* aIdent);
219 const char* getDestinationRunway() const;
220 void setDestinationRunway(const char* aIdent);
222 const char* getApproach() const;
223 void setApproach(const char* aIdent);
225 const char* getSTAR() const;
226 void setSTAR(const char* aIdent);
228 double getDepartureFieldElevation() const;
229 double getDestinationFieldElevation() const;
233 #endif // _ROUTE_MGR_HXX