VR-Vantage
Loading...
Searching...
No Matches
exampleElementAttributesPlugin

Overview

Builds an index of element ID's to (DIS/RPR FOM) marking text.

Expected Result

Element Attribute Monitor Result

Example details

The DtDataBank contains simulation-specific and element-specific data elements. However there is substantial overlap - VR-Link driver's Marking Text is an element (that comes from that driver) Display Name. Element Data is, for the most part, static, and created when the Element itself is created. Simulation Data, on the other hand, contains both static and dynamic data.

The element data is easier to work with and faster/cheaper to retrieve. In addition to the the already existing Display Name attribute, there is now a Connection ID attribute and a Connection Entity Type attribute. These are whatever a particular connection uses for an ID and entity type, in string form. For example, an element from a DIS connection might have a connection ID of "3001:1:1" and a connection entity type of "1:225:1:1:1:0:0". An element created by a CIGI connection, on the other hand, might have an connection ID of "5" and a connection Entity Type of "17".

It is common for users who are used to working in a DIS or HLA environment to want to look up elements by a connection ID or Marking Text, for example. Connection objects makes that much easier to do.

The exampleElementAttributesPlugin example shows the signal that is raised with all the elements whose attribute data has been received that frame; elements can be added to indices or sets based on attribute data at that time. It builds an index of element IDs to Marking Text (Display Name) and vice versa. The example can easily be extended to build similar indices using connection ID attributes.

Building the Example

VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running ./bin64/exampleElementAttributesPlugin_stealth.bat (on Windows) or ./bin64/exampleElementAttributesPlugin_stealth.sh (on Linux). Load the Ala Moana terrain, once Vantage is started, connect with DIS. Open MAK DIS Logger and load "HawaiiTour-2019-DIS.lgr". Hit Play and you will see the connection information printed in the console. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleElementAttributesPlugin.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
#ifdef _WIN32
#ifdef EXAMPLEELEMENTATTRIBUTESPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN
#endif
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN
// Declare & export the plugin initialization function (bool initDeModule(DtDe* de))
namespace makVrv
{
class DtDe;
}
// Work function for the plugin initialization
// Callback to create the attribute monitor and register it with the DtDe
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
#define DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN
Definition exampleElementAttributesPlugin.h:19
void createMonitor(makVrv::DtDe &de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16

exampleElementAttributesPlugin.cxx

/*****************************************************************************
* Copyright (c) 2024 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
using namespace makVrv;
static vrvSignalsLib::connection postInitializeConnection;
{
// We're done with the signal, so disconnect from it
postInitializeConnection.disconnect();
// By registering the instance with the DtDe, it will delete our monitor on exit
de.registerInstance("AttributeMonitor", monitor);
// Set up a key command to dump all named elements
DtInputDriver& inputDriver = de.driverManager().inputDriver();
keyMapManager.addKeyFunction("Dump Elements", boost::bind(
// Bind the above key function to the 'f' key in the default
// ("Observer Frame") key map
DtKeyMap* obsFrame = keyMapManager.findKeyMap("Observer Frame");
if (obsFrame)
{
inputDriver.addKeyBinding(obsFrame, DtKeyState::KEY_X, "Dump Elements");
}
}
void init(DtDe& de)
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// We only want to create the driver if we're running in master mode:
if (de.isInMasterMode())
{
// The driver must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(&createMonitor, std::ref(de)));
}
}
{
// Setup the plug-in. Normally, the init function and functionality
// should be in its own library.
init(*de);
return true;
}
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv:DtMasterScene class.
Contains the DtElementAttributesMonitor class declaration.
Contains makVrv::DtInputDriver class.
Contains makVrv::DtKeyMapManager class.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual void registerInstance(const std::string &instanceName, DtVirtualBaseClass *instance)
Register an instance with a given name for later retrieval. Once registered, the DtDe takes ownership...
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
Definition DtElementAttributesMonitor.h:28
virtual void dumpElements()
Dump all the named Elements to the console. This method dumps all of the entries in the element ID to...
This class's main responsibility is to handle keyboard and mouse events from OSG (Qt events are route...
Definition DtInputDriver.h:46
void addKeyBinding(DtKeyMap *map, DtKeyState::KeyType key, const std::string &functionName, DtKeyState::KeyModifier modifiers=DtKeyState::NO_MODIFIER, bool replace=false, DtKeyEvent::KeyEventType eventType=DtKeyEvent::KEY_DOWN)
bind a key down or key up event (possibly modified) to a function name
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Miscellaneous
Definition DtKeyMapManager.h:45
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_X
Definition DtKeyState.h:79
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)

DtElementAttributesMonitor.h

/*****************************************************************************
* Copyright (c) 2024 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
#include <string>
namespace makVrv
{
class DT_DLL_EXAMPLEELEMENTATTRIBUTESPLUGIN DtElementAttributesMonitor : public DtVirtualBaseClass
{
public:
DtElementAttributesMonitor(DtDe& de);
virtual ~DtElementAttributesMonitor();
virtual void processElementInitialized(makVrv::DtElementID entity);
virtual void processElementRemoved(makVrv::DtElementID entity);
virtual void dumpElements();
static std::string elementTypeToString(DtElementEntry::ElementType elementType);
static std::string elementSubTypeToString(DtElementAttributes::ElementSubtypes subType);
protected:
virtual void slot_elementsInitialized(const DtElementData::ElementIdList& elements);
virtual void slot_elementsRemoved(const DtElementData::ElementIdList& elements);
virtual void slot_attributesChanged(const DtElementAttributeManager::EntryAttributesList& entryAttributeList);
protected:
DtDe& myDe;
DtSignalConnectionManager mySignalConnections;
};
}
Contains makVrv::DtDataBank class.
Contains the DtElementAttributeManager class declaration.
Base class to provide boost signal/slot management.
Contains makVrv::DtVirtualBaseClass class.
DtUniqueID DtElementID
Definition DtUniqueID.h:23

DtElementAttributesMonitor.cxx

/*****************************************************************************
* Copyright (c) 2024 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
#include <iostream>
// Use the VR-Vantage namespace.
// All classes in VR-Vantage are in this namespace.
namespace makVrv
{
//
// Custom Element Attribute Definition
// This custom element attribute is reported by exampleCustomElementAttributePlugin{protocol} example
//
// enumeration of unique ids for custom element attributes
enum class CustomElementAttributeIds : unsigned short
{
};
// create a new type of string-based element attribute, called DtElementAttributeEntityLabel, assigned to the 'EntityLabel' id
typedef DtUniqueElementAttribute<std::string, (unsigned short)CustomElementAttributeIds::EntityLabel> DtElementAttributeEntityLabel;
//
// Simple example of using the type and attribute data in the ElementData class
//
, myDe(de)
{
DtElementData& elements = myDe.dataBank().elementData();
// By using the signal connection manager to hold our signal connections, we do not
// need to disconnect them in the destructor
mySignalConnections += elements.signal_elementsInitialized.connect(boost::bind(
&DtElementAttributesMonitor::slot_elementsInitialized, this, boost::placeholders::_1));
mySignalConnections += elements.signal_elementsToBeRemoved.connect(boost::bind(
&DtElementAttributesMonitor::slot_elementsRemoved, this, boost::placeholders::_1));
mySignalConnections += elements.attributeManager().signal_attributesChanged.connect(std::bind(
&DtElementAttributesMonitor::slot_attributesChanged, this, std::placeholders::_1));
}
{
// intentional noop
}
{
const DtElementAttributeManager& attrMgr = myDe.dataBank().elementData().attributeManager();
const DtElementEntry* entry = myDe.dataBank().elementData().findElement(entity);
if (!entry)
{
std::string displayName = "Unnamed";
attrMgr.getElementDisplayName(entity, displayName);
std::cout << "Invalid Element ID received: " << std::hex << entity << " - "
<< " not found" << std::endl;
return;
}
std::cout << "Added ";
std::string displayName;
if (attrMgr.getElementDisplayName(*entry, displayName))
{
std::cout << displayName;
}
else
{
std::cout << "Unnamed (" << std::hex << entity << ")";
}
std::string driverType;
if (attrMgr.getElementDriverType(*entry, driverType))
{
std::cout << " from " << driverType << std::endl;
}
else
{
std::cout << std::endl;
}
DtElementEntry::ElementType elementType = attrMgr.elementType(*entry);
std::string elementTypeStr = elementTypeToString(elementType);
std::cout << " Element Type " << elementTypeStr << std::endl;
std::string objectId;
if (attrMgr.getElementObjectId(*entry, objectId))
{
std::cout << " Connection ID " << objectId << std::endl;
}
std::string objectType;
if (attrMgr.getElementObjectType(*entry, objectType))
{
std::cout << " Connection Type " << objectType << std::endl;
}
if (attrMgr.getElementSubtype(*entry, subtype))
{
std::string subtypeStr = elementSubTypeToString(subtype);
std::cout << " Subtype " << subtypeStr << std::endl;
}
DtUnicode elementDefName;
if (attrMgr.getElementElementDefinitionName(*entry, elementDefName))
{
std::string elementDefStr;
elementDefName.toAscii(elementDefStr);
std::cout << " Element Definition " << elementDefStr << std::endl;
}
// Each frame the entity may be updated (either from the network, dead reckoning, or some other
// 'tickable' updater. If you want to access the entity in your driver AFTER these updates, you can
// listen for signal_postUpdate. Here is an example that would print out the entity's new position,
// but left commented out since this will generate a LOT of console output.
// myAgentManager.de().renderer().signal_postUpdate.connect(
// boost::bind( &DtConnectionObjectsDriver::slot_postUpdate, this, entity ) );
}
{
// Disconnect this entity from the postUpdate calls if you uncommented the code above to
// connect it...
// myAgentManager.de().renderer().signal_postUpdate.disconnect(
// boost::bind( &DtConnectionObjectsDriver::slot_postUpdate, this, entity ) );
const DtElementAttributeManager& attrMgr = myDe.dataBank().elementData().attributeManager();
// At this point, you might want to insert this information into a class that can look up
// everything else by marking text, by element ID, etc...
std::cout << "Removed " << std::hex << entity << " - ";
std::string displayName;
if (attrMgr.getElementDisplayName(entity, displayName))
{
std::cout << displayName << std::endl;
}
else
{
DtElementEntry::ElementType elementType = attrMgr.elementType(entity);
std::string elementTypeStr = elementTypeToString(elementType);
std::cout << "Unnamed " << elementTypeStr << " (" << entity << ")" << std::endl;
}
}
{
DtElementData::ElementIdList::const_iterator curIter = elements.begin();
DtElementData::ElementIdList::const_iterator endIter = elements.end();
for (; curIter != endIter; ++curIter)
{
processElementInitialized(*curIter);
}
}
{
DtElementData::ElementIdList::const_iterator curIter = elements.begin();
DtElementData::ElementIdList::const_iterator endIter = elements.end();
for (; curIter != endIter; ++curIter)
{
// signal before actually removing the entries from the maps so the
// maps are still usable to receivers of the signal
processElementRemoved(*curIter);
}
}
{
const DtElementAttributeManager& attrMgr = myDe.dataBank().elementData().attributeManager();
for (const DtElementAttributeManager::EntryAttributes& entryAttributes : entryAttributeList)
{
const DtElementID entryElementId = entryAttributes.first->elementID();
for (const DtElementAttribute* currentAttribute : entryAttributes.second)
{
const DtElementAttribute* attribute = currentAttribute;
if (attribute->attributeId() == (unsigned short)CustomElementAttributeIds::EntityLabel)
{
std::cout << "Modified ";
std::string displayName;
if (attrMgr.getElementDisplayName(entryElementId, displayName))
{
std::cout << displayName << std::endl;
}
else
{
DtElementEntry::ElementType elementType = attrMgr.elementType(entryElementId);
std::string elementTypeStr = elementTypeToString(elementType);
std::cout << "Unnamed " << elementTypeStr << " (" << entryElementId << ")" << std::endl;
}
const DtElementAttributeEntityLabel* entityLabelIdAttr =
dynamic_cast<const DtElementAttributeEntityLabel*>(entryAttributes.first->findAttribute((unsigned short)CustomElementAttributeIds::EntityLabel));
if (entityLabelIdAttr != nullptr)
{
std::cout << " Element Label " << entityLabelIdAttr->value() << std::endl;
}
}
}
}
}
{
const DtElementAttributeManager& attrMgr = myDe.dataBank().elementData().attributeManager();
DtElementID elementId;
std::string elementName;
while (attrMgr.getNextElementIdAndDisplayName(elementId, elementName))
{
std::cout << "ID: " << std::hex << elementId << " NAME: " << elementName << std::endl;
}
}
{
std::string elementTypeStr;
switch (elementType)
{
default:
elementTypeStr = "Unknown";
break;
elementTypeStr = "Entity";
break;
elementTypeStr = "Prop";
break;
elementTypeStr = "Terrain Patch";
break;
elementTypeStr = "Aggregate";
break;
elementTypeStr = "Observer";
break;
elementTypeStr = "Environmental";
break;
elementTypeStr = "Graphic Point";
break;
elementTypeStr = "Graphic Shape";
break;
elementTypeStr = "Graphic Vertex";
break;
elementTypeStr = "Remote Graphic";
break;
elementTypeStr = "Tactical Graphic";
break;
elementTypeStr = "Intervisibility";
break;
elementTypeStr = "Feature";
break;
elementTypeStr = "Tactical Smoke";
break;
elementTypeStr = "Bouy Or Beacon";
break;
elementTypeStr = "Dynamic Terrain";
break;
}
return elementTypeStr;
}
{
std::string subtypeStr;
switch (subType)
{
subtypeStr = "Munitions";
break;
subtypeStr = "Friendly";
break;
subtypeStr = "Opposing";
break;
subtypeStr = "Other";
break;
subtypeStr = "Neutral";
break;
default:
subtypeStr = "Unrecognized!";
break;
}
return subtypeStr;
}
}
Contains makVrv::DtElementAttributes class.
Contains makVrv::DtUniqueID type.
DtElementAttribute is a common base class used for all element attributes, such as those found in a D...
Definition DtElementAttribute.h:21
unsigned short attributeId() const
Definition DtElementAttribute.h:34
The element attribute manager is used to provide access to element attribute data....
Definition DtElementAttributeManager.h:37
virtual bool getNextElementIdAndDisplayName(DtElementID &id, std::string &displayName) const
virtual bool getElementObjectType(const DtElementEntry &entry, std::string &value) const
Get the 'object type' from an element entry. Returns false if no connection object type attribute is ...
std::vector< EntryAttributes > EntryAttributesList
Definition DtElementAttributeManager.h:44
virtual bool getElementDriverType(const DtElementEntry &entry, std::string &value) const
Get the Driver type from an element entry. Returns false if no Driver type attribute is found for the...
virtual DtElementEntry::ElementType elementType(DtElementID elementId) const
Get the element type from given an element id or element entry.
virtual bool getElementElementDefinitionName(const DtElementEntry &entry, DtUnicode &value) const
Get the Element Definition name from an element entry. Returns false if no Element Definition name at...
virtual bool getElementObjectId(const DtElementEntry &entry, std::string &value) const
Get the 'object id' from an element entry. Returns false if no connection object id attribute is foun...
virtual bool getElementSubtype(const DtElementEntry &entry, DtElementAttributes::ElementSubtypes &value) const
Get the 'element subtype' from an element entry Returns false if no subtype attribute is found for th...
virtual bool getElementDisplayName(DtElementID elementId, std::string &value) const
Optional Attributes.
virtual void startNamedElementIteration() const
Iterate through element ID / displayName pairs These methods provide a mechanism to inspect all of th...
std::pair< DtElementEntry *, AttributeList > EntryAttributes
Definition DtElementAttributeManager.h:43
virtual void slot_elementsRemoved(const DtElementData::ElementIdList &elements)
Slot connected to DtElementData's signal_elementsToBeRemoved signal.
virtual ~DtElementAttributesMonitor()
Virtual DTOR.
static std::string elementSubTypeToString(DtElementAttributes::ElementSubtypes subType)
GEt a readable form of an ElementSubtypes enumeration value.
static std::string elementTypeToString(DtElementEntry::ElementType elementType)
Get a readable form of an elementType enumeration value.
virtual void processElementRemoved(makVrv::DtElementID entity)
Print the element id and name (if it exists) for an element. This method is called by.
virtual void processElementInitialized(makVrv::DtElementID entity)
Print the attribute information for an initialized element entry. This method is called by.
virtual void slot_elementsInitialized(const DtElementData::ElementIdList &elements)
Slot connected to DtElementData's signal_signal_elementsInitialized signal.
virtual void slot_attributesChanged(const DtElementAttributeManager::EntryAttributesList &entryAttributeList)
Slot connected to DtElementAttributeManager's signal_attributesChanged signal.
The element data is all the information about all elements in the scene.
Definition DtElementData.h:31
std::vector< DtElementID > ElementIdList
Definition DtElementData.h:54
boost::signalslib::signal< void(const ElementIdList &) > signal_elementsToBeRemoved
Signal elements to be removed.
Definition DtElementData.h:154
boost::signalslib::signal< void(const ElementIdList &) > signal_elementsInitialized
Definition DtElementData.h:151
virtual const DtElementAttributeManager & attributeManager() const
Get a const reference to the.
DtElementEntry holds the non-simulation-specific data about an element, including its element type an...
Definition DtElementEntry.h:23
ElementType
Definition DtElementEntry.h:27
@ GraphicShape
Definition DtElementEntry.h:36
@ TerrainPatch
Definition DtElementEntry.h:31
@ Unknown
Definition DtElementEntry.h:28
@ Aggregate
Definition DtElementEntry.h:32
@ Environmental
Definition DtElementEntry.h:34
@ TacticalSmoke
Definition DtElementEntry.h:42
@ TacticalGraphic
Definition DtElementEntry.h:39
@ Observer
Definition DtElementEntry.h:33
@ RemoteGraphic
Definition DtElementEntry.h:38
@ BuoyOrBeacon
Definition DtElementEntry.h:43
@ Intervisibility
Definition DtElementEntry.h:40
@ GraphicVertex
Definition DtElementEntry.h:37
@ Feature
Definition DtElementEntry.h:41
@ Prop
Definition DtElementEntry.h:30
@ GraphicPoint
Definition DtElementEntry.h:35
@ DynamicTerrain
Definition DtElementEntry.h:44
@ Entity
Definition DtElementEntry.h:29
Definition DtUnicode.h:34
void toAscii(std::string &str) const
Decode via specifying encoding.
Definition DtUnicode.inl:364
Definition DtUniqueElementAttribute.h:82
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators,...
Definition DtVirtualBaseClass.h:20
ElementSubtypes
Definition DtElementAttributes.h:60
@ Friendly
Definition DtElementAttributes.h:62
@ Opposing
Definition DtElementAttributes.h:63
@ FriendlyMunitions
Definition DtElementAttributes.h:66
@ Neutral
Definition DtElementAttributes.h:65
@ OpposingMunitions
Definition DtElementAttributes.h:67
@ NeutralMunitions
Definition DtElementAttributes.h:69
@ Other
Definition DtElementAttributes.h:64
@ OtherMunitions
Definition DtElementAttributes.h:68
@ AttributeIdUserStart
Definition DtElementAttributes.h:53