]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/route_mgr.hxx
Continuous replay: use correct replay duration
[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 typedef SGSharedPtr<FGAirport> FGAirportRef;
39
40 /**
41  * Top level route manager class
42  * 
43  */
44
45 class FGRouteMgr : public SGSubsystem
46 {
47 public:
48   FGRouteMgr();
49   ~FGRouteMgr();
50
51   void init ();
52   void postinit ();
53   void bind ();
54   void unbind ();
55   void update (double dt);
56
57   void insertWayptAtIndex(flightgear::Waypt* aWpt, int aIndex);
58   flightgear::WayptRef removeWayptAtIndex(int index);
59   
60   void clearRoute();
61   
62   typedef enum {
63     ROUTE_HIGH_AIRWAYS, ///< high-level airways routing
64     ROUTE_LOW_AIRWAYS, ///< low-level airways routing
65     ROUTE_VOR ///< VOR-VOR routing
66   } RouteType;
67   
68   /**
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.
73    */
74   bool routeToIndex(int index, RouteType aRouteType);
75
76   void autoRoute();
77         
78   bool isRouteActive() const;
79          
80   int currentIndex() const
81     { return _currentIndex; }
82     
83   flightgear::Waypt* currentWaypt() const;
84   flightgear::Waypt* nextWaypt() const;
85   flightgear::Waypt* previousWaypt() const;
86   
87   const flightgear::WayptVec& waypts() const
88     { return _route; }
89   
90   int numWaypts() const
91     { return _route.size(); }
92     
93   flightgear::Waypt* wayptAtIndex(int index) const;
94              
95   /**
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.
98    */
99   int findWayptIndex(const SGGeod& aPos) const;
100         
101   /**
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.
105    *
106    * returns true if the route was activated successfully, or false if the
107    * route could not be activated for some reason
108    */
109   bool activate();
110
111   /**
112    * Step to the next waypoint on the active route
113    */
114   void sequence();
115   
116   /**
117    * Set the current waypoint to the specified index.
118    */
119   void jumpToIndex(int index);
120   
121   void saveRoute();
122   void loadRoute();
123   
124   /**
125    * Helper command to setup current airport/runway if necessary
126    */
127   void initAtPosition();
128 private:
129   flightgear::WayptVec _route;
130   int _currentIndex;
131   
132     time_t _takeoffTime;
133     time_t _touchdownTime;
134     FGAirportRef _departure;
135     FGAirportRef _destination;
136     
137     // automatic inputs
138     SGPropertyNode_ptr lon;
139     SGPropertyNode_ptr lat;
140     SGPropertyNode_ptr alt;
141     SGPropertyNode_ptr magvar;
142     
143     // automatic outputs    
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
148     
149     SGPropertyNode_ptr totalDistance;
150     SGPropertyNode_ptr ete;
151     SGPropertyNode_ptr elapsedFlightTime;
152     
153     SGPropertyNode_ptr active;
154     SGPropertyNode_ptr airborne;
155     
156     SGPropertyNode_ptr wp0;
157     SGPropertyNode_ptr wp1;
158     SGPropertyNode_ptr wpn;
159     
160     
161     SGPropertyNode_ptr _pathNode;
162     SGPropertyNode_ptr _currentWpt;
163     
164     /// integer property corresponding to the RouteType enum
165     SGPropertyNode_ptr _routingType;
166     
167     /** 
168      * Signal property to notify people that the route was edited
169      */
170     SGPropertyNode_ptr _edited;
171     
172     /**
173      * Signal property to notify when the last waypoint is reached
174      */
175     SGPropertyNode_ptr _finished;
176     
177     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
178     
179     class InputListener : public SGPropertyChangeListener {
180     public:
181         InputListener(FGRouteMgr *m) : mgr(m) {}
182         virtual void valueChanged (SGPropertyNode * prop);
183     private:
184         FGRouteMgr *mgr;
185     };
186
187     SGPropertyNode_ptr input;
188     SGPropertyNode_ptr weightOnWheels;
189     
190     InputListener *listener;
191     SGPropertyNode_ptr mirror;
192
193     /**
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
199      */
200     flightgear::WayptRef waypointFromString(const std::string& target);
201     
202     
203     void departureChanged();
204     void buildDeparture(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
205     
206     void arrivalChanged();
207     void buildArrival(flightgear::WayptRef enroute, flightgear::WayptVec& wps);
208     
209     /**
210      * Helper to keep various pieces of state in sync when the route is
211      * modified (waypoints added, inserted, removed). Notably, this fires the
212      * 'edited' signal.
213      */
214     void waypointsChanged();
215     
216     void update_mirror();
217     
218     void currentWaypointChanged();
219     
220     /**
221      * Parse a route/wp node (from a saved, property-lsit formatted route)
222      */
223     void parseRouteWaypoint(SGPropertyNode* aWP);
224     
225     /**
226      * Check if we've reached the final waypoint. 
227      * Returns true if we have.
228      */
229     bool checkFinished();
230     
231     
232     void loadPlainTextRoute(const SGPath& path);
233     
234     void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
235     void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
236     void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
237     flightgear::WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
238     
239     /**
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)
242      */
243     bool haveUserWaypoints() const;
244     
245 // tied getters and setters
246     const char* getDepartureICAO() const;
247     const char* getDepartureName() const;
248     void setDepartureICAO(const char* aIdent);
249     
250     const char* getDestinationICAO() const;
251     const char* getDestinationName() const;
252     void setDestinationICAO(const char* aIdent);
253
254     PropertyWatcher* _departureWatcher;
255     PropertyWatcher* _arrivalWatcher;
256 };
257
258
259 #endif // _ROUTE_MGR_HXX