VR-Vantage 3.2 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exampleCustomElementAttributePlugin

Table of Contents

Overview

Implements a custom entity element attribute.

Expected Result

StealthConsoleOutput.png
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':

VRForcesGuiObjectEdit.png
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/exampleCustomElementAttributePluginHLA1615e_stealth.bat (on Windows) or ./bin64/exampleCustomElementAttributePluginHLA1615e_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

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

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

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

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
, 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.
{
}
#endif
#ifdef DtDIS
{
}
#endif

[<< Examples] [Home] [Top of Page]



Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)