VR-Forces Developer's Guide
 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;
}
{
}
return true;
}

How to Run the Example

Usage

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

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Load the BombMission.scnx scenario file.
  3. Choose File → Export Scenario Laydown...
  4. Enter a filename and select “MSDL Scenario File (*.xml)” as the Save as type and then click Save.
  5. Choose File → Close Scenario and the entities and tactical overlays should disappear.
  6. Create a new entity-level scenario on Ala Moana.
  7. Choose File → Import Scenario Objects... and select “MSDL Scenario File (*.xml)” as the Files of Type option.
    If the File -> Import Scenario Objects menu option appears to be disabled, create a new blank scenario using the same (Ala Moana) terrain. The Import Scenario Objects menu option should be enabled to import the previously exported .csv scenario file.
  8. Select the scenario file that you just exported and then click Open.
  9. The objects that you 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 Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)