#include "csvScenarioDescriptionImporterExporter.h"
#include <matrix/vlMath.h>
#include <matrix/geodeticCoord.h>
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
{
}
{
{
delete iter->second;
++iter;
}
}
const std::map<std::string, std::string>& importData)
{
std::ifstream ifs(file.c_str());
if(!ifs.is_open())
{
myError = std::string(
"Could not open file for reading ") + std::string(file.c_str());
return false;
}
std::string s;
getline(ifs, s);
while (!ifs.eof())
{
getline(ifs, s);
if (s.length())
{
std::vector<std::string> results;
boost::algorithm::split(results, s, boost::algorithm::is_any_of(","));
information->
name = results[0].c_str();
information->
type = DtEntityType(results[1].c_str());
information->uuid =
DtUUID(results[2].c_str());
information->
force = atoi(results[3].c_str());
information->
parent = results[4].c_str();
int lastFixedColumn = 5;
int size = results.size();
int i;
for (i = size - 1; i > -1; --i)
{
if (results[i].length())
{
break;
}
}
int lastCell = i;
int numPoints = ((lastCell + 1) - 4) / 3;
for (i = 0; i < numPoints; i++)
{
DtGeodeticCoord geod;
geod.setLat(DtDeg2Rad(atof(results[i * 3 + lastFixedColumn].c_str())));
geod.setLon(DtDeg2Rad(atof(results[i * 3 + lastFixedColumn + 1].c_str())));
geod.setAlt(atof(results[i * 3 + lastFixedColumn + 2].c_str()));
information->
points.push_back(geod.geocentric());
}
WaitingMap::iterator waitingIter =
myToBeParented.find(information->uuid);
{
information->children = waitingIter->second;
}
if (information->
type.kind() < 16)
{
if (parentUUID.isValid())
{
ObjectMap::const_iterator superiorIter =
myObjectMap.find(parentUUID);
{
superiorIter->second->children.push_back(information);
}
else
{
}
}
}
}
}
return true;
}
{
}
{
return false;
}
{
return false;
}
{
std::ofstream ifs(file.c_str());
if(!ifs.is_open())
{
myError = std::string(
"Could not open file for writing ") + std::string(file.c_str());
return false;
}
ifs.precision(9);
ifs << "NAME,ENUMERATION,UUID,FORCE,SUPERIOR OR OVERLAY,POINTS" << std::endl;
{
ifs << iter->second->name.c_str() << ",";
ifs << iter->second->type.string() << ",";
ifs << iter->second->uuid.uuidString() << ",";
ifs << iter->second->force << ",";
ifs << iter->second->parent << ",";
std::vector<DtVector>::const_iterator pointIter = iter->second->points.begin();
while (pointIter != iter->second->points.end())
{
DtGeodeticCoord geod;
geod.setGeocentric(*pointIter);
ifs << DtRad2Deg(geod.lat()) << ",";
ifs << DtRad2Deg(geod.lon()) << ",";
ifs << geod.alt();
++pointIter;
if (pointIter != iter->second->points.end())
{
ifs << ",";
}
}
ifs << std::endl;
++iter;
}
return true;
}
{
return "csv txt";
}
{
if (f.exists())
{
std::ifstream ifs(f.c_str());
if(!ifs.is_open())
{
return false;
}
std::string s;
getline(ifs, s);
if (s.find("NAME,") == 0)
{
return true;
}
}
return false;
}
{
return 0;
}