]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/route_mgr.hxx
Route-manager: remove any interaction with the autopilot, or internal sequencing...
[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 // forward decls
32 class SGRoute;
33 class SGPath;
34
35 /**
36  * Top level route manager class
37  * 
38  */
39
40 class FGRouteMgr : public SGSubsystem
41 {
42
43 private:
44     SGRoute* _route;
45     time_t _takeoffTime;
46     time_t _touchdownTime;
47  
48     // automatic inputs
49     SGPropertyNode_ptr lon;
50     SGPropertyNode_ptr lat;
51     SGPropertyNode_ptr alt;
52     SGPropertyNode_ptr magvar;
53     
54     // automatic outputs    
55     SGPropertyNode_ptr departure; ///< departure airport information
56     SGPropertyNode_ptr destination; ///< destination airport information
57     SGPropertyNode_ptr alternate; ///< alternate airport information
58     SGPropertyNode_ptr cruise; ///< cruise information
59     
60     SGPropertyNode_ptr totalDistance;
61     SGPropertyNode_ptr ete;
62     SGPropertyNode_ptr elapsedFlightTime;
63     
64     SGPropertyNode_ptr active;
65     SGPropertyNode_ptr airborne;
66     SGPropertyNode_ptr currentWp;
67     
68     SGPropertyNode_ptr wp0;
69     SGPropertyNode_ptr wp1;
70     SGPropertyNode_ptr wpn;
71     
72     
73     SGPropertyNode_ptr _pathNode;
74     
75     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
76     
77     class InputListener : public SGPropertyChangeListener {
78     public:
79         InputListener(FGRouteMgr *m) : mgr(m) {}
80         virtual void valueChanged (SGPropertyNode * prop);
81     private:
82         FGRouteMgr *mgr;
83     };
84
85     SGPropertyNode_ptr input;
86     SGPropertyNode_ptr weightOnWheels;
87     
88     InputListener *listener;
89     SGPropertyNode_ptr mirror;
90
91     /**
92      * Create a SGWayPoint from a string in the following format:
93      *  - simple identifier
94      *  - decimal-lon,decimal-lat
95      *  - airport-id/runway-id
96      *  - navaid/radial-deg/offset-nm
97      */
98     SGWayPoint* make_waypoint(const string& target);
99     
100     
101     void update_mirror();
102     bool near_ground();
103     
104     void currentWaypointChanged();
105     
106     /**
107      * Parse a route/wp node (from a saved, property-lsit formatted route)
108      */
109     void parseRouteWaypoint(SGPropertyNode* aWP);
110 public:
111
112     FGRouteMgr();
113     ~FGRouteMgr();
114
115     void init ();
116     void postinit ();
117     void bind ();
118     void unbind ();
119     void update (double dt);
120
121     bool build ();
122
123     void new_waypoint( const string& tgt_alt, int n = -1 );
124     void add_waypoint( const SGWayPoint& wp, int n = -1 );
125     SGWayPoint pop_waypoint( int i = 0 );
126
127     SGWayPoint get_waypoint( int i ) const;
128     int size() const;
129         
130     bool isRouteActive() const;
131         
132     int currentWaypoint() const;
133        
134     /**
135      * Find a waypoint in the route, by position, and return its index, or
136      * -1 if no matching waypoint was found in the route.
137      */
138     int findWaypoint(const SGGeod& aPos) const;
139           
140     /**
141      * Activate a built route. This checks for various mandatory pieces of
142      * data, such as departure and destination airports, and creates waypoints
143      * for them on the route structure.
144      *
145      * returns true if the route was activated successfully, or false if the
146      * route could not be activated for some reason
147      */
148     bool activate();
149
150     /**
151      * Step to the next waypoint on the active route
152      */
153     void sequence();
154     
155     /**
156      *
157      */
158     void jumpToIndex(int index);
159     
160     void saveRoute();
161     void loadRoute();
162 };
163
164
165 #endif // _ROUTE_MGR_HXX