]> git.mxchange.org Git - simgear.git/blob - simgear/route/route.hxx
MacOS tweaks contributed by Darrell Walisser.
[simgear.git] / simgear / route / route.hxx
1 // route.hxx -- Class to manage a list of waypoints (route)
2 //
3 // Written by Curtis Olson, started October 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _ROUTE_HXX
25 #define _ROUTE_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <simgear/compiler.h>
38
39 #include STL_STRING
40 #include <vector>
41
42 FG_USING_STD(string);
43 FG_USING_STD(vector);
44
45 #include <simgear/route/waypoint.hxx>
46
47
48 class SGRoute {
49
50 private:
51
52     typedef vector < SGWayPoint > route_list;
53     route_list route;
54     int current_wp;
55
56 public:
57
58     SGRoute();
59     ~SGRoute();
60
61     // clear the entire route
62     inline void clear() {
63         route.clear();
64         current_wp = 0;
65     }
66
67     // add a waypoint
68     inline void add_waypoint( const SGWayPoint &wp ) {
69         route.push_back( wp );
70
71         int size = route.size();
72         if ( size > 1 ) {
73             SGWayPoint next_to_last = route[ size - 2 ];
74             double tmpd, tmpc;
75             wp.CourseAndDistance( next_to_last, &tmpc, &tmpd );
76             route[size - 1].set_distance( tmpd );
77         }
78     }
79
80     // get the number of waypoints
81     inline int size() const { return route.size(); }
82
83     // get the front waypoint
84     inline SGWayPoint get_first() const {
85         if ( route.size() ) {
86             return route[0];
87         } else {
88             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
89         }
90     }
91
92     // get the current waypoint
93     inline SGWayPoint get_current() const {
94         if ( current_wp < (int)route.size() ) {
95             return route[current_wp];
96         } else {
97             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
98         }
99     }
100
101     // set the current waypoint
102     inline void set_current( int n ) {
103         if ( n >= 0 && n < (int)route.size() ) {
104             current_wp = n;
105         }
106     }
107
108     // increment the current waypoint
109     inline void increment_current() {
110         if ( current_wp < (int)route.size() - 1 ) {
111             ++current_wp;
112         }
113     }
114
115     // get the nth waypoint
116     inline SGWayPoint get_waypoint( const int n ) const {
117         if ( n < (int)route.size() ) {
118             return route[n];
119         } else {
120             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
121         }
122     }
123
124     // delete the front waypoint
125     inline void delete_first() {
126         if ( route.size() ) {
127             route.erase( route.begin() );
128         }
129     }
130
131     // Calculate perpendicular distance from the current route segment
132     // This routine assumes all points are laying on a flat plane and
133     // ignores the altitude (or Z) dimension.  For best results, use
134     // with CARTESIAN way points.
135     double distance_off_route( double x, double y ) const;
136 };
137
138
139 #endif // _ROUTE_HXX