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,
48 public flightgear::FlightPlan::Delegate
58 void update (double dt);
60 bool isRouteActive() const;
62 int currentIndex() const;
64 void setFlightPlan(flightgear::FlightPlan* plan);
65 flightgear::FlightPlan* flightPlan() const;
69 flightgear::Waypt* currentWaypt() const;
78 flightgear::Waypt* wayptAtIndex(int index) const;
80 SGPropertyNode_ptr wayptNodeAtIndex(int index) const;
82 void removeLegAtIndex(int aIndex);
85 * Activate a built route. This checks for various mandatory pieces of
86 * data, such as departure and destination airports, and creates waypoints
87 * for them on the route structure.
89 * returns true if the route was activated successfully, or false if the
90 * route could not be activated for some reason
95 * Step to the next waypoint on the active route
100 * Set the current waypoint to the specified index.
102 void jumpToIndex(int index);
104 bool saveRoute(const SGPath& p);
105 bool loadRoute(const SGPath& p);
107 flightgear::WayptRef waypointFromString(const std::string& target);
110 * Helper command to setup current airport/runway if necessary
112 void initAtPosition();
115 flightgear::FlightPlan* _plan;
118 time_t _touchdownTime;
121 SGPropertyNode_ptr magvar;
124 SGPropertyNode_ptr departure; ///< departure airport information
125 SGPropertyNode_ptr destination; ///< destination airport information
126 SGPropertyNode_ptr alternate; ///< alternate airport information
127 SGPropertyNode_ptr cruise; ///< cruise information
129 SGPropertyNode_ptr totalDistance;
130 SGPropertyNode_ptr distanceToGo;
131 SGPropertyNode_ptr ete;
132 SGPropertyNode_ptr elapsedFlightTime;
134 SGPropertyNode_ptr active;
135 SGPropertyNode_ptr airborne;
137 SGPropertyNode_ptr wp0;
138 SGPropertyNode_ptr wp1;
139 SGPropertyNode_ptr wpn;
142 SGPropertyNode_ptr _pathNode;
143 SGPropertyNode_ptr _currentWpt;
147 * Signal property to notify people that the route was edited
149 SGPropertyNode_ptr _edited;
152 * Signal property to notify when the last waypoint is reached
154 SGPropertyNode_ptr _finished;
156 SGPropertyNode_ptr _flightplanChanged;
158 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
161 * retrieve the cached path distance along a leg
163 double cachedLegPathDistanceM(int index) const;
164 double cachedWaypointPathTotalDistance(int index) const;
166 class InputListener : public SGPropertyChangeListener {
168 InputListener(FGRouteMgr *m) : mgr(m) {}
169 virtual void valueChanged (SGPropertyNode * prop);
174 SGPropertyNode_ptr input;
175 SGPropertyNode_ptr weightOnWheels;
176 SGPropertyNode_ptr groundSpeed;
178 InputListener *listener;
179 SGPropertyNode_ptr mirror;
181 virtual void departureChanged();
182 void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
184 virtual void arrivalChanged();
185 void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
188 * Helper to keep various pieces of state in sync when the route is
189 * modified (waypoints added, inserted, removed). Notably, this fires the
192 virtual void waypointsChanged();
194 void update_mirror();
196 virtual void currentWaypointChanged();
199 * Check if we've reached the final waypoint.
200 * Returns true if we have.
202 bool checkFinished();
205 * Predicate for helping the UI - test if at least one waypoint was
206 * entered by the user (as opposed to being generated by the route-manager)
208 bool haveUserWaypoints() const;
210 // tied getters and setters
211 const char* getDepartureICAO() const;
212 const char* getDepartureName() const;
213 void setDepartureICAO(const char* aIdent);
215 const char* getDepartureRunway() const;
216 void setDepartureRunway(const char* aIdent);
218 const char* getSID() const;
219 void setSID(const char* aIdent);
221 const char* getDestinationICAO() const;
222 const char* getDestinationName() const;
223 void setDestinationICAO(const char* aIdent);
225 const char* getDestinationRunway() const;
226 void setDestinationRunway(const char* aIdent);
228 const char* getApproach() const;
229 void setApproach(const char* aIdent);
231 const char* getSTAR() const;
232 void setSTAR(const char* aIdent);
234 double getDepartureFieldElevation() const;
235 double getDestinationFieldElevation() const;
239 #endif // _ROUTE_MGR_HXX