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

Overview

Implements a custom entity element attribute.

Expected Result

Custom Element Attribute Result

Example details

VR-Forces publishes various properties for entities and other simulation objects. For entities, one such property is the 'entity label':

VR-Forces GUI - Setting an Entity Label

By default, VR-Vantage does not make use of this entity label property but a toolkit user can write a plugin which extracts this property from the entity state repository and makes it available throughout the application as an element attribute.

This example, implements a custom Entity State Listener class and maintains an entity's label that is published by VR-Forces for all entities and, if defined for an entity, reports it to the rest of the system as a custom element attribute. This custom element attribute can be queried throughout the system for visualization to the console, Qt user interface, or as part of the scene.

This example, when used with the exampleElementAttributesPlugin example, visualizes entity labels to the console.

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/exampleCustomElementAttributePluginDIS_stealth.bat (on Windows) or ./bin64/exampleCustomElementAttributePluginDIS_stealth.sh (on Linux). Once Vantage is started, connect with DIS. Open MAK DIS Logger and load "ExampleCustomElementAttributePluginDIS.lgr". Hit Play and you will see information printed in the console. There are startup scripts for HLA1516e: ./bin64/exampleCustomElementAttributePluginHLA1516e_stealth.bat (on Windows) or ./bin64/exampleCustomElementAttributePluginHLA1516e_stealth.sh (on Linux). There is no MAK Logger tape provided for the HLA1516e version of this example. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleCustomElementAttributePlugin.h

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
#ifdef _WIN32
#ifdef EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN_EXPORTS
#define DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN
#endif
#ifdef DtDIS
# include <vrvDis/vrvDis.h>
# define DT_PROTOCOL_NAMESPACE vrvDis
#else
# ifdef DtHLA_4
# include <vrvHla4/vrvHla4.h>
# define DT_PROTOCOL_NAMESPACE vrvHla4
# elif DtHLA_1516_EVOLVED
# define DT_PROTOCOL_NAMESPACE vrvHla1516e
# else
# ifdef DtHLA_1516
# include <vrvHla1516/vrvHla1516.h>
# define DT_PROTOCOL_NAMESPACE vrvHla1516
# else
# ifdef DtHLA
# define DT_PROTOCOL_NAMESPACE vrvHla13
# define DL_DLL_IGCONVRLINK DT_DLL_VRVHLA13
# else
# error "Protocol not specified or unsupported."
# endif
# endif
# endif
#endif
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN
// 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)
void slot_postInitialize(makVrv::DtDe &de)
#define DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN
Definition exampleCustomElementAttributePlugin.h:20
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
Contains DLL export macros.
Contains DLL export macros.
Contains DLL export macros.
Contains DLL export macros.

exampleCustomElementAttributePlugin.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();
// Add the custom element attribute accessory to the accessory
// manager. It will get the optionto install itself into any
// DtDriver objects that are created.
DtAccessoryManager::instance(de).addAccessory(
}
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(
std::bind(&slot_postInitialize, 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::DtAccessoryManager class.
Contains declaration for DtCustomElementAttributeAccessory.
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
This class defines an accessory that will install itself into DtVrlinkDriver objects and print out th...
Definition DtCustomElementAttributeAccessory.h:24
static DtAccessoryManager & instance(DtDe &de)
Lazily create singleton.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)

DtCustomElementAttributeAccessory.h

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
namespace makVrv
{
class DtVrlinkBaseConnection;
{
class DT_DLL_EXAMPLECUSTOMELEMENTATTRIBUTEPLUGIN DtCustomElementAttributeAccessory : public DtBaseAccessory
{
public:
DtCustomElementAttributeAccessory();
virtual ~DtCustomElementAttributeAccessory();
virtual void install(DtDriver* driver);
virtual void uninstall(DtDriver* baseConn);
virtual bool isCompatible(DtDriver* driver);
protected:
virtual void slot_onConnectionCreated(DtVrlinkBaseConnection* connection);
};
}
}
Contains makVrv::DtBaseAccessory class.
Contains implementation for DtCustomElementAttributeAccessory.
#define DT_PROTOCOL_NAMESPACE
Definition vrvAudioShared/dllExport.h:43

DtCustomElementAttributeAccessory.cxx

DtCustomElementAttributeVrlinkEntityStateListener.h

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
{
public:
public:
virtual void reflectedEntityPostUpdate() override;
protected:
std::string myEntityLabel;
};
{
public:
#ifdef DtHLA
DtHlaObject* object);
#endif
#ifdef DtDIS
const DtEntityIdentifier& id, const DtEntityType& type);
#endif
};
Contains makVrv::DtUniqueID type.
unsigned long long DtUniqueID
Definition DtUniqueID.h:19

DtCustomElementAttributeVrlinkEntityStateListener.cxx

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrfExtObjects/extEntityStateRepository.h>
using namespace makVrv;
// 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;
, myEntityLabel("")
{
// intentional noop
}
{
// intentional noop
}
{
// call base class implementation
// get the extended entity state repository
const DtExtEntityStateRepository& extEsr = dynamic_cast<const DtExtEntityStateRepository&>(esr());
if (myEntityLabel != extEsr.vrfObjectLabel().stdString())
{
// if changed, report the VR-Forces Object Label as the Entity Label element attribute
myEntityLabel = extEsr.vrfObjectLabel().stdString();
myVrlinkConnection->reportElementAttribute(myElementId, new DtElementAttributeEntityLabel(myEntityLabel));
}
}
{
// intentional noop
}
{
// intentional noop
}
#ifdef DtHLA
//functionality.
{
return new DtCustomElementAttributeVrlinkEntityStateListener(mySim.sceneInterface().createNewUniqueId(), mySim);
}
#endif
#ifdef DtDIS
{
return new DtCustomElementAttributeVrlinkEntityStateListener(mySim.sceneInterface().createNewUniqueId(), mySim);
}
#endif
Contains makVrv::DtAgentManagerInterface class.
void reportElementAttribute(DtElementID id, DtElementAttribute *attribute)
DtElementID myElementId
Definition DtStateListener.h:90
Definition DtUniqueElementAttribute.h:82
Definition DtAudioInit.h:25
@ AttributeIdUserStart
Definition DtElementAttributes.h:53