]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/route_mgr.hxx
Airways routing is driven via Nasal now.
[flightgear.git] / src / Autopilot / route_mgr.hxx
1 // route_mgr.hxx - manage a route (i.e. a collection of waypoints)
2 //
3 // Written by Curtis Olson, started January 2004.
4 //
5 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _ROUTE_MGR_HXX
25 #define _ROUTE_MGR_HXX 1
26
27 #include <simgear/props/props.hxx>
28 #include <simgear/route/waypoint.hxx>
29 #include <simgear/structure/subsystem_mgr.hxx>
30
31 #include <Navaids/route.hxx>
32
33 // forward decls
34 class SGPath;
35 class PropertyWatcher;
36
37 class FGAirport;
38 class FGRunway;
39
40 typedef SGSharedPtr<FGAirport> FGAirportRef;
41
42 /**
43  * Top level route manager class
44  * 
45  */
46
47 class FGRouteMgr : public SGSubsystem, 
48                    public flightgear::FlightPlan::Delegate
49 {
50 public:
51   FGRouteMgr();
52   ~FGRouteMgr();
53
54   void init ();
55   void postinit ();
56   void bind ();
57   void unbind ();
58   void update (double dt);
59   
60   bool isRouteActive() const;
61          
62   int currentIndex() const;
63   
64   void setFlightPlan(flightgear::FlightPlan* plan);
65   flightgear::FlightPlan* flightPlan() const;
66   
67   void clearRoute();
68   
69   flightgear::Waypt* currentWaypt() const;
70   
71   int numLegs() const;
72   
73 // deprecated
74   int numWaypts() const
75   { return numLegs(); }
76   
77 // deprecated
78   flightgear::Waypt* wayptAtIndex(int index) const;
79   
80   SGPropertyNode_ptr wayptNodeAtIndex(int index) const;
81   
82   void removeLegAtIndex(int aIndex);
83   
84   /**
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.
88    *
89    * returns true if the route was activated successfully, or false if the
90    * route could not be activated for some reason
91    */
92   bool activate();
93
94   /**
95    * Step to the next waypoint on the active route
96    */
97   void sequence();
98   
99   /**
100    * Set the current waypoint to the specified index.
101    */
102   void jumpToIndex(int index);
103   
104   bool saveRoute(const SGPath& p);
105   bool loadRoute(const SGPath& p);
106   
107   flightgear::WayptRef waypointFromString(const std::string& target);
108   
109   /**
110    * Helper command to setup current airport/runway if necessary
111    */
112   void initAtPosition();
113
114 private:
115     flightgear::FlightPlan* _plan;
116   
117     time_t _takeoffTime;
118     time_t _touchdownTime;
119
120     // automatic inputs
121     SGPropertyNode_ptr magvar;
122     
123     // automatic outputs    
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
128     
129     SGPropertyNode_ptr totalDistance;
130     SGPropertyNode_ptr distanceToGo;
131     SGPropertyNode_ptr ete;
132     SGPropertyNode_ptr elapsedFlightTime;
133     
134     SGPropertyNode_ptr active;
135     SGPropertyNode_ptr airborne;
136     
137     SGPropertyNode_ptr wp0;
138     SGPropertyNode_ptr wp1;
139     SGPropertyNode_ptr wpn;
140     
141     
142     SGPropertyNode_ptr _pathNode;
143     SGPropertyNode_ptr _currentWpt;
144     
145     
146     /** 
147      * Signal property to notify people that the route was edited
148      */
149     SGPropertyNode_ptr _edited;
150     
151     /**
152      * Signal property to notify when the last waypoint is reached
153      */
154     SGPropertyNode_ptr _finished;
155     
156     SGPropertyNode_ptr _flightplanChanged;
157   
158     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
159     
160     /**
161      * retrieve the cached path distance along a leg
162      */
163     double cachedLegPathDistanceM(int index) const;
164     double cachedWaypointPathTotalDistance(int index) const;
165   
166     class InputListener : public SGPropertyChangeListener {
167     public:
168         InputListener(FGRouteMgr *m) : mgr(m) {}
169         virtual void valueChanged (SGPropertyNode * prop);
170     private:
171         FGRouteMgr *mgr;
172     };
173
174     SGPropertyNode_ptr input;
175     SGPropertyNode_ptr weightOnWheels;
176     SGPropertyNode_ptr groundSpeed;
177   
178     InputListener *listener;
179     SGPropertyNode_ptr mirror;    
180   
181     virtual void departureChanged();
182     void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
183     
184     virtual void arrivalChanged();
185     void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
186     
187     /**
188      * Helper to keep various pieces of state in sync when the route is
189      * modified (waypoints added, inserted, removed). Notably, this fires the
190      * 'edited' signal.
191      */
192     virtual void waypointsChanged();
193     
194     void update_mirror();
195     
196     virtual void currentWaypointChanged();
197     
198     /**
199      * Check if we've reached the final waypoint. 
200      * Returns true if we have.
201      */
202     bool checkFinished();
203     
204     /**
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)
207      */
208     bool haveUserWaypoints() const;
209     
210 // tied getters and setters
211     const char* getDepartureICAO() const;
212     const char* getDepartureName() const;
213     void setDepartureICAO(const char* aIdent);
214     
215     const char* getDepartureRunway() const;
216     void setDepartureRunway(const char* aIdent);
217   
218     const char* getSID() const;
219     void setSID(const char* aIdent);
220   
221     const char* getDestinationICAO() const;
222     const char* getDestinationName() const;
223     void setDestinationICAO(const char* aIdent);
224
225     const char* getDestinationRunway() const;
226     void setDestinationRunway(const char* aIdent);
227   
228     const char* getApproach() const;
229     void setApproach(const char* aIdent);
230   
231     const char* getSTAR() const;
232     void setSTAR(const char* aIdent);
233   
234     double getDepartureFieldElevation() const;  
235     double getDestinationFieldElevation() const;  
236 };
237
238
239 #endif // _ROUTE_MGR_HXX