#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;
bool headerContainsProjected = false;
if (getline(ifs, s))
{
std::vector<std::string> headerColumns;
boost::algorithm::split(headerColumns, s, boost::algorithm::is_any_of(","));
std::vector<std::string>::iterator headerIter = headerColumns.begin();
while (headerIter != headerColumns.end())
{
boost::algorithm::trim(*headerIter);
if (boost::algorithm::iequals(*headerIter, "PROJECTED"))
{
headerContainsProjected = true;
break;
}
++headerIter;
}
}
while (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();
if (headerContainsProjected && (results.size() > 5))
{
std::string projectedValue = results[5];
boost::algorithm::trim(projectedValue);
information->projected =
boost::algorithm::iequals(projectedValue, "true") ||
boost::algorithm::iequals(projectedValue, "t") ||
boost::algorithm::iequals(projectedValue, "yes") ||
(projectedValue == "1");
}
else
{
information->projected = false;
}
int lastFixedColumn = headerContainsProjected ? 6 : 5;
int size = results.size();
int i;
for (i = size - 1; i > -1; --i)
{
{
break;
}
}
int lastCell = i;
int numPoints = 0;
if ((lastCell + 1) > lastFixedColumn)
{
numPoints = ((lastCell + 1) - lastFixedColumn) / 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,PROJECTED,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 << ",";
ifs << (iter->second->projected ? "True" : "False") << ",";
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 "examples-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;
}