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