VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Class that will import from or export to a comma delimited file

Classes

Header

/*******************************************************************************
** Copyright (c) 2012 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
{
public:
virtual bool loadScenarioDescription(const DtFilename& file, const std::map<std::string, std::string>& importData,
virtual bool importFromSimulation(DtSimManager*, const std::map<std::string, std::string>& exportData,
virtual bool saveScenarioDescription(const DtFilename& file, const DtScenario&) const;
virtual std::string supportedExtensions();
virtual bool canImportFile(const DtFilename&);
protected:
struct ObjectInformation
{
DtEntityType type;
int force;
std::vector<DtVector> points;
std::vector<ObjectInformation*> children;
};
typedef std::map<DtString, ObjectInformation*> ObjectMap;
typedef std::map<DtString, std::vector<ObjectInformation*> > WaitingMap;
};

Class

/*******************************************************************************
** Copyright (c) 2012 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <matrix/vlMath.h>
#include <matrix/geodeticCoord.h>
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
{
}
{
ObjectMap::iterator iter = myObjectMap.begin();
while (iter != myObjectMap.end())
{
delete iter->second;
++iter;
}
}
const std::map<std::string, std::string>& importData,const DtMsdlHierarchyPropertyMappings&)
{
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(","));
ObjectInformation* information = new ObjectInformation;
information->name = results[0].c_str();
information->type = DtEntityType(results[1].c_str());
information->force = atoi(results[2].c_str());
information->parent = results[3].c_str();
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 + 4].c_str())));
geod.setLon(DtDeg2Rad(atof(results[i * 3 + 5].c_str())));
geod.setAlt(atof(results[i * 3 + 6].c_str()));
information->points.push_back(geod.geocentric());
}
WaitingMap::iterator waitingIter = myToBeParented.find(information->name);
if (waitingIter != myToBeParented.end())
{
information->children = waitingIter->second;
myToBeParented.erase(waitingIter);
}
myObjectMap[information->name] = information;
if (information->type.kind() < 16)
{
if (information->parent.length())
{
ObjectMap::const_iterator superiorIter = myObjectMap.find(information->parent);
if (superiorIter != myObjectMap.end())
{
superiorIter->second->children.push_back(information);
}
else
{
myToBeParented[information->parent].push_back(information);
}
}
}
}
}
return true;
}
{
}
{
return false;
}
const std::map<std::string, std::string>& exportData, const DtMsdlHierarchyPropertyMappings&)
{
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,FORCE,SUPERIOR OR OVERLAY,POINTS" << std::endl;
ObjectMap::const_iterator iter = myObjectMap.begin();
while (iter != myObjectMap.end())
{
ifs << iter->second->name.c_str() << ",";
ifs << iter->second->type.string() << ",";
ifs << iter->second->force << ",";
ifs << iter->second->parent.c_str() << ",";
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;
}

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)