00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _ROUTE_HXX
00028 #define _ROUTE_HXX
00029
00030
00031 #ifndef __cplusplus
00032 # error This library requires C++
00033 #endif
00034
00035 #include <simgear/compiler.h>
00036
00037 #include <vector>
00038
00039 using std::vector;
00040
00041 #include <simgear/route/waypoint.hxx>
00042
00047 class SGRoute {
00048
00049 private:
00050
00051 typedef vector < SGWayPoint > route_list;
00052 route_list route;
00053 int current_wp;
00054
00055 void update_distance_and_track(int index);
00056
00057 public:
00058
00060 SGRoute();
00061
00063 ~SGRoute();
00064
00066 inline void clear() {
00067 route.clear();
00068 current_wp = 0;
00069 }
00070
00075 void add_waypoint( const SGWayPoint &wp, int n = -1 );
00080 inline int size() const { return route.size(); }
00081
00086 inline SGWayPoint get_first() const {
00087 if ( route.size() ) {
00088 return route[0];
00089 } else {
00090 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
00091 }
00092 }
00093
00098 inline SGWayPoint get_current() const {
00099 if ( current_wp < (int)route.size() ) {
00100 return route[current_wp];
00101 } else {
00102 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
00103 }
00104 }
00105
00106 inline SGWayPoint get_previous() const {
00107 if ( (current_wp > 0) && (current_wp < (int)route.size()) ) {
00108 return route[current_wp - 1];
00109 } else {
00110 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
00111 }
00112 }
00113
00114 inline SGWayPoint get_next() const {
00115 if ( (current_wp + 1) < (int)route.size() ) {
00116 return route[current_wp+1];
00117 } else {
00118 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
00119 }
00120 }
00121
00126 inline void set_current( int n ) {
00127 if ( n >= 0 && n < (int)route.size() ) {
00128 current_wp = n;
00129 }
00130 }
00131
00132 inline int current_index() const {
00133 return current_wp;
00134 }
00135
00137 inline void increment_current() {
00138 if ( current_wp < (int)route.size() - 1 ) {
00139 ++current_wp;
00140 }
00141 }
00142
00148 inline SGWayPoint get_waypoint( const int n ) const {
00149 if ( n < (int)route.size() ) {
00150 return route[n];
00151 } else {
00152 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
00153 }
00154 }
00155
00157 inline void delete_first() { delete_waypoint(0); }
00158
00160 void delete_waypoint( int n = 0 );
00161
00165 double total_distance() const;
00166 };
00167
00168
00169 #endif // _ROUTE_HXX