]> git.mxchange.org Git - simgear.git/blob - simgear/route/route.hxx
Add project.* to MSVC project files
[simgear.git] / simgear / route / route.hxx
1 /**
2  * \file route.hxx
3  * Provides a class to manage a list of waypoints (i.e. a route).
4  */
5
6 // Written by Curtis Olson, started October 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _ROUTE_HXX
28 #define _ROUTE_HXX
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35 #include <simgear/compiler.h>
36
37 #include <vector>
38
39 using std::vector;
40
41 #include <simgear/route/waypoint.hxx>
42
43 /**
44  * A class to manage a list of waypoints (i.e. a route).
45  */
46
47 class SGRoute {
48
49 private:
50
51     typedef vector < SGWayPoint > route_list;
52     route_list route;
53     int current_wp;
54
55     void update_distance_and_track(int index);
56
57 public:
58
59     /** Constructor */
60     SGRoute();
61
62     /** Destructor */
63     ~SGRoute();
64
65     /** Clear the entire route */
66     inline void clear() {
67         route.clear();
68         current_wp = 0;
69     }
70
71     /**
72      * Add waypoint (default), or insert waypoint at position n.
73      * @param wp a waypoint
74      */
75     void add_waypoint( const SGWayPoint &wp, int n = -1 );
76     /**
77      * Get the number of waypoints (i.e. route length )
78      * @return route length
79      */
80     inline int size() const { return route.size(); }
81
82     /**
83      * Get the front waypoint.
84      * @return the first waypoint.
85      */
86     inline SGWayPoint get_first() const {
87         if ( route.size() ) {
88             return route[0];
89         } else {
90             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
91         }
92     }
93
94     /**
95      * Get the current waypoint
96      * @return the current waypoint
97      */
98     inline SGWayPoint get_current() const {
99         if ( current_wp < (int)route.size() ) {
100             return route[current_wp];
101         } else {
102             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
103         }
104     }
105     
106     inline SGWayPoint get_previous() const {
107         if ( (current_wp > 0) && (current_wp < (int)route.size()) ) {
108             return route[current_wp - 1];
109         } else {
110             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
111         }
112     }
113
114     inline SGWayPoint get_next() const {
115         if ( (current_wp + 1) < (int)route.size() ) {
116             return route[current_wp+1];
117         } else {
118             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
119         }
120     }
121
122     /**
123      * Set the current waypoint
124      * @param number of waypoint to make current.
125      */
126     inline void set_current( int n ) {
127         if ( n >= 0 && n < (int)route.size() ) {
128             current_wp = n;
129         }
130     }
131
132     inline int current_index() const {
133         return current_wp;
134     }
135
136     /** Increment the current waypoint pointer. */
137     inline void increment_current() {
138         if ( current_wp < (int)route.size() - 1 ) {
139             ++current_wp;
140         }
141     }
142
143     /**
144      * Get the nth waypoint
145      * @param n waypoint number
146      * @return the nth waypoint
147      */
148     inline SGWayPoint get_waypoint( const int n ) const {
149         if ( n < (int)route.size() ) {
150             return route[n];
151         } else {
152             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
153         }
154     }
155
156     /** Delete the front waypoint */
157     inline void delete_first() { delete_waypoint(0); }
158
159     /** Delete waypoint waypoint with index n  (last one if n < 0) */
160     void delete_waypoint( int n = 0 );
161     
162     /**
163      * Helper, sum the distance members of each waypoint
164      */
165     double total_distance() const;
166 };
167
168
169 #endif // _ROUTE_HXX