VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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(DtSimulationServices*, 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&);
virtual DtObjectParser * parser();
protected:
{
DtEntityType type;
int force;
std::vector<DtVector> points;
std::vector<ObjectInformation*> children;
};
typedef std::map<DtUUID, ObjectInformation*> ObjectMap;
typedef std::map<DtUUID, std::vector<ObjectInformation*> > WaitingMap;
};

Class

/*******************************************************************************
** Copyright (c) 2012 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "csvScenarioDescriptionImporterExporter.h"
#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;
}
}
//[The loadScenarioDescription function]
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);
if (waitingIter != myToBeParented.end())
{
information->children = waitingIter->second;
myToBeParented.erase(waitingIter);
}
myObjectMap[information->uuid] = information;
if (information->type.kind() < 16)
{
DtUUID parentUUID(information->parent, 0, true);
if (parentUUID.isValid())
{
ObjectMap::const_iterator superiorIter = myObjectMap.find(parentUUID);
if (superiorIter != myObjectMap.end())
{
superiorIter->second->children.push_back(information);
}
else
{
myToBeParented[parentUUID].push_back(information);
}
}
}
}
}
return true;
}
//[The loadScenarioDescription function]
{
}
{
return false;
}
const std::map<std::string, std::string>& exportData, const DtMsdlHierarchyPropertyMappings&)
{
return false;
}
//[The saveScenarioDescription function]
{
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;
ObjectMap::const_iterator iter = myObjectMap.begin();
while (iter != myObjectMap.end())
{
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;
}
//[The saveScenarioDescription function]
//[The supportedExtensions function]
{
return "csv txt";
}
//[The supportedExtensions function]
{
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;
}
{
//Not using a seperate parser in this example.
return 0;
}

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)