]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/route_mgr.hxx
Merge branch 'jmt/view' into next
[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 class FGAirport;
36 typedef SGSharedPtr<FGAirport> FGAirportRef;
37
38 /**
39  * Top level route manager class
40  * 
41  */
42
43 class FGRouteMgr : public SGSubsystem
44 {
45
46 private:
47     SGRoute* _route;
48     time_t _takeoffTime;
49     time_t _touchdownTime;
50     FGAirportRef _departure;
51     FGAirportRef _destination;
52     
53     // automatic inputs
54     SGPropertyNode_ptr lon;
55     SGPropertyNode_ptr lat;
56     SGPropertyNode_ptr alt;
57     SGPropertyNode_ptr magvar;
58     
59     // automatic outputs    
60     SGPropertyNode_ptr departure; ///< departure airport information
61     SGPropertyNode_ptr destination; ///< destination airport information
62     SGPropertyNode_ptr alternate; ///< alternate airport information
63     SGPropertyNode_ptr cruise; ///< cruise information
64     
65     SGPropertyNode_ptr totalDistance;
66     SGPropertyNode_ptr ete;
67     SGPropertyNode_ptr elapsedFlightTime;
68     
69     SGPropertyNode_ptr active;
70     SGPropertyNode_ptr airborne;
71     
72     SGPropertyNode_ptr wp0;
73     SGPropertyNode_ptr wp1;
74     SGPropertyNode_ptr wpn;
75     
76     
77     SGPropertyNode_ptr _pathNode;
78     SGPropertyNode_ptr _currentWpt;
79     
80     
81     /** 
82      * Signal property to notify people that the route was edited
83      */
84     SGPropertyNode_ptr _edited;
85     
86     /**
87      * Signal property to notify when the last waypoint is reached
88      */
89     SGPropertyNode_ptr _finished;
90     
91     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
92     
93     class InputListener : public SGPropertyChangeListener {
94     public:
95         InputListener(FGRouteMgr *m) : mgr(m) {}
96         virtual void valueChanged (SGPropertyNode * prop);
97     private:
98         FGRouteMgr *mgr;
99     };
100
101     SGPropertyNode_ptr input;
102     SGPropertyNode_ptr weightOnWheels;
103     
104     InputListener *listener;
105     SGPropertyNode_ptr mirror;
106
107     /**
108      * Create a SGWayPoint from a string in the following format:
109      *  - simple identifier
110      *  - decimal-lon,decimal-lat
111      *  - airport-id/runway-id
112      *  - navaid/radial-deg/offset-nm
113      */
114     SGWayPoint* make_waypoint(const string& target);
115     
116     /**
117      * Helper to keep various pieces of state in sync when the SGRoute is
118      * modified (waypoints added, inserted, removed). Notably, this fires the
119      * 'edited' signal.
120      */
121     void waypointsChanged();
122     
123     void update_mirror();
124     
125     void currentWaypointChanged();
126     
127     /**
128      * Parse a route/wp node (from a saved, property-lsit formatted route)
129      */
130     void parseRouteWaypoint(SGPropertyNode* aWP);
131     
132     /**
133      * Check if we've reached the final waypoint. 
134      * Returns true if we have.
135      */
136     bool checkFinished();
137     
138 // tied getters and setters
139     const char* getDepartureICAO() const;
140     const char* getDepartureName() const;
141     void setDepartureICAO(const char* aIdent);
142     
143     const char* getDestinationICAO() const;
144     const char* getDestinationName() const;
145     void setDestinationICAO(const char* aIdent);
146     
147 public:
148
149     FGRouteMgr();
150     ~FGRouteMgr();
151
152     void init ();
153     void postinit ();
154     void bind ();
155     void unbind ();
156     void update (double dt);
157
158     bool build ();
159
160     void new_waypoint( const string& tgt_alt, int n = -1 );
161     void add_waypoint( const SGWayPoint& wp, int n = -1 );
162     SGWayPoint pop_waypoint( int i = 0 );
163
164     SGWayPoint get_waypoint( int i ) const;
165     int size() const;
166         
167     bool isRouteActive() const;
168         
169     int currentWaypoint() const;
170        
171     /**
172      * Find a waypoint in the route, by position, and return its index, or
173      * -1 if no matching waypoint was found in the route.
174      */
175     int findWaypoint(const SGGeod& aPos) const;
176           
177     /**
178      * Activate a built route. This checks for various mandatory pieces of
179      * data, such as departure and destination airports, and creates waypoints
180      * for them on the route structure.
181      *
182      * returns true if the route was activated successfully, or false if the
183      * route could not be activated for some reason
184      */
185     bool activate();
186
187     /**
188      * Step to the next waypoint on the active route
189      */
190     void sequence();
191     
192     /**
193      *
194      */
195     void jumpToIndex(int index);
196     
197     /**
198      * 
199      */
200     void setWaypointTargetAltitudeFt(unsigned int index, int altFt);
201     
202     void saveRoute();
203     void loadRoute();
204 };
205
206
207 #endif // _ROUTE_MGR_HXX