00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <fstream>
00020 #include <string>
00021 #include <iomanip>
00022 #include <vector>
00023
00024 #include "uvsim/guidance/FlightPlan.h"
00025 #include "uvsim/guidance/GeoCoord.h"
00026
00027 namespace uvsim
00028 {
00029
00030 FlightPlan::FlightPlan()
00031 {
00032 }
00033
00034 FlightPlan::~FlightPlan()
00035 {
00036 }
00037
00038 void FlightPlan::open(std::string filename)
00039 {
00040 std::ifstream in_stream;
00041 int pos;
00042 int counter = 0;
00043 GeoCoord geocoord;
00044
00045 in_stream.open(filename.c_str());
00046
00047
00048 do
00049 {
00050 in_stream >> pos;
00051
00052 if (!in_stream.eof() && pos > -1 && pos <= this->size() + 1)
00053 {
00054 counter++;
00055 in_stream >> geocoord.m_Latitude;
00056 in_stream >> geocoord.m_Longitude;
00057 in_stream >> geocoord.m_Altitude;
00058
00059 if (counter == 1)
00060 {
00061 this->push_back(geocoord);
00062 }
00063 else
00064 {
00065 this->insert(this->begin() + pos, geocoord);
00066 }
00067
00068 }
00069
00070 }
00071 while (!in_stream.eof() && pos > -1 && pos < this->size() + 1);
00072
00073 in_stream.close();
00074
00075
00076 std::cout <<"\n---------------------Data From File--------------------\n";
00077 std::cout << "Waypoint#" << std::setw(15) <<" Latitude" << std::setw(16) << "Longitude" << std::setw(17) << "Altitude \n";
00078 for (counter = 0; counter < this->size(); counter++)
00079 {
00080 std::cout << counter << std::setw(23);
00081 (*this)[counter].print();
00082 }
00083 std::cout << "\n";
00084
00085 }
00086
00087 void FlightPlan::save(std::string filename)
00088 {
00089 int counter;
00090 std::ofstream out_stream;
00091
00092 out_stream.open(filename.c_str());
00093
00094
00095 for (counter = 0; counter < this->size(); counter++)
00096 {
00097 out_stream << counter << " " << (*this)[counter].m_Latitude
00098 << " " << (*this)[counter].m_Longitude << " " << (*this)[counter].m_Altitude << "\n";
00099 }
00100
00101 out_stream.close();
00102 }
00103
00104 void FlightPlan::display()
00105 {
00106 int counter;
00107
00108
00109 std::cout <<"\n-------------------------Summary-----------------------\n";
00110 std::cout << "Waypoint#" << std::setw(15) <<" Latitude" << std::setw(16) << "Longitude" << std::setw(17) << "Altitude \n";
00111 for (counter = 0; counter < this->size(); counter++)
00112 {
00113 std::cout << counter << std::setw(23);
00114 (*this)[counter].print();
00115 }
00116 std::cout << "\n";
00117 }
00118
00119 std::ostream& operator<< (std::ostream &out, FlightPlan &flightPlan)
00120 {
00121
00122 for (int i=0; i< flightPlan.size(); i++)
00123 {
00124 out << std::fixed << std::setprecision(3) << std::showbase << flightPlan[i];
00125 }
00126 return out;
00127 }
00128
00129 }
00130