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