]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/route_mgr.hxx
a small cleanup and make Windows simple_mmap function return the proper value if...
[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/route.hxx>
29 #include <simgear/structure/subsystem_mgr.hxx>
30
31
32 /**
33  * Top level route manager class
34  * 
35  */
36
37 class FGRouteMgr : public SGSubsystem
38 {
39
40 private:
41
42     SGRoute *route;
43
44     // automatic inputs
45     SGPropertyNode_ptr lon;
46     SGPropertyNode_ptr lat;
47     SGPropertyNode_ptr alt;
48
49     // automatic outputs
50     SGPropertyNode_ptr true_hdg_deg;
51     SGPropertyNode_ptr target_altitude_ft;
52     SGPropertyNode_ptr altitude_lock;
53
54     SGPropertyNode_ptr wp0_id;
55     SGPropertyNode_ptr wp0_dist;
56     SGPropertyNode_ptr wp0_eta;
57
58     SGPropertyNode_ptr wp1_id;
59     SGPropertyNode_ptr wp1_dist;
60     SGPropertyNode_ptr wp1_eta;
61
62     SGPropertyNode_ptr wpn_id;
63     SGPropertyNode_ptr wpn_dist;
64     SGPropertyNode_ptr wpn_eta;
65
66
67     class Listener : public SGPropertyChangeListener {
68     public:
69         Listener(FGRouteMgr *m) : mgr(m) {}
70         virtual void valueChanged (SGPropertyNode * prop);
71     private:
72         FGRouteMgr *mgr;
73     };
74
75     SGPropertyNode_ptr input;
76     Listener *listener;
77     SGPropertyNode_ptr mirror;
78     bool altitude_set;
79
80     SGWayPoint* make_waypoint(const string& target);
81     void update_mirror();
82     bool near_ground();
83
84     /**
85      * Helper to set a string property to the estimated arrival time (ETA),
86      * formatted as either hours:minutes or minutes:seconds, based on a distance
87      * and the current groundspeed.
88      */
89     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
90     
91     /**
92      * Helper to update the target_altitude_ft and altitude_set flag when wp0
93      * changes
94      */
95     void updateTargetAltitude();
96 public:
97
98     FGRouteMgr();
99     ~FGRouteMgr();
100
101     void init ();
102     void postinit ();
103     void bind ();
104     void unbind ();
105     void update (double dt);
106
107     bool build ();
108
109     void new_waypoint( const string& tgt_alt, int n = -1 );
110     void add_waypoint( const SGWayPoint& wp, int n = -1 );
111     SGWayPoint pop_waypoint( int i = 0 );
112
113     SGWayPoint get_waypoint( int i ) const {
114         return route->get_waypoint(i);
115     }
116
117     int size() const {
118         return route->size();
119     }
120
121 };
122
123
124 #endif // _ROUTE_MGR_HXX