VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Importing/Exporting Scenarios from Different File Formats (csvScenarioImporterExporterSim)

Table of Contents

The Importing/Exporting Scenarios from Different File Formats example demonstrates the following:

The Importing/Exporting scenarios example installs a new scenario importer/exporter that will read a comma delimited file and restore entity/aggregate laydown as well as tactical graphic objects.

Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application. Make sure to enable the csvScenarioImporterExporter example from the launcher application

Adding a New Scenario Importer/Exporter

To create a new scenario importer/exporter it is necessary to inherit from the DtScenarioDescriptionImporterExporter class.

The new importer/exporter is registered using the extension it supports.

The supportedExtensions() Function

The supportedExtensions () method is used to define which file extensions are supported by the importer/exporter.

Exporting Scenarios

Exporting a scenario consists of two parts: first getting the objects from the simulation and then writing them out to disk.

DtExCSVScenarioDescriptionImporterExporter handles writing out the simulation data to disk through the saveScenarioDescription method:

{
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;
}

It obtains the simulation data from the importFromSimulation method that is implemented by the subclass DtVrfCSVScenarioDescriptionImporterExporter

const std::map<std::string, std::string>& exportData, const DtMsdlHierarchyPropertyMappings& m)
{
exportOrganization(mgr, exportData, m);
exportTacticalGraphics(mgr, exportData, m);
return true;
}

Importing Scenarios

Like exporting scenarios, importing scenarios is a two step process: first is loading the scenario data from disk and second is instantiating that data into the simulation.

DtExCSVScenarioDescriptionImporterExporter implements the method loadScenarioDescription to read in the simulation data stored in the CSV file.

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 subclass DtVrfCSVScenarioDescriptionImporterExporter converts the data read in from disk to simulation data through the importIntoSimulation method.

{
ObjectMap::iterator iter = myObjectMap.begin();
while (iter != myObjectMap.end())
{
if (!iter->second->parent.length() || (iter->second->type.kind() >= 16))
{
myOrganizedHierarchy.push_back(iter->second);
}
++iter;
}
mySimManager = mgr;
{
}
return true;
}

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin. Then launch VR-Forces.

To view the new behavior:

  1. Load the BombMission.scnx scenario file.
  2. Click on File → Export Scenario Laydown...
  3. Enter a filename and select “CSV Scenario File (*.csv *.txt)” as the Save as type and press the Save button.
  4. Click on File → Close Scenario and the entities and tactical overlays should disappear
  5. Click on File → Import Scenario Objects... and select “CSV Scenario File (*.csv *.txt)” as the Files of type option
  6. Select the scenario file that was just exported and press the Open button
  7. The objects that were exported should reload;verify that objects were exported correctly

Notes

Scenario Import/Export does not export VR Forces specific data, such as Plans and Tasks.

Classes

DtExCSVScenarioDescriptionImporterExporterThe subclass of DtScenarioDescriptionImporterExporter has the implementation to import/export information to/from the csv scenario file.
DtVrfCSVScenarioDescriptionImporterExporterThe subclass of DtExCSVScenarioDescriptionImporterExporter that will fill in internal structures with information from a comma delimited file or write the comma delimited file from scenario information.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//VR-Forces includes
#include "vrfcgf/cgf.h"
extern "C" {
{
info.pluginName = "csvScenarioImporterExporterSim";
info.pluginDescription = "An example of how to take a scenario imported from a file and incorporate it into an existing scenario";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
}
//[Registering Importer Exporter]
DT_VRF_DLL_PLUGIN bool DtPostInitializeVrfPlugin(DtCgf* cgf)
{
return true;
}
//[Registering Importer Exporter]
}

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)