VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Add State Property (addStatePropertyGui)

Table of Contents

The Add State Property GUI example demonstrates the following:

Adding New State Properties

The Add State Property example shows how to add new state properties to entities, receive these properties in the GUI, and then display them in the Information dialog. For more details on state properties, please see the Add State Property Sim example plugin which publishes this data to the network.

In the GUI, this example registers new page data items to display the TargetsHit and TargetsMissed state properties. These page data items query the state view of the DtVrfObjectDataState to get the latest state property values.

How to Run the Example

  1. Copy VrfStateProperty.fed, VrfStateProperty.xml, and VrfStateProperty_evolved.xml from examples to the bin64 directory.
  2. Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application

Usage

In the Launcher:

  1. In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.
  2. Set Federation Name to "VrfStateProperty"
  3. Set the FED File Name to VrfStateProperty.fed if using HLA 1.3, VrfStateProperty.xml if using HLA 1516-2000, or VrfStateProperty_evolved.xml if using HLA Evolved. If using DIS, you must use DIS 7.
  4. Set the RPR FOM version to 2.0
  5. Start VR-Forces

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Load the addStateProperty.scnx scenario from the 'developer toolkit examples' directory.
  3. Right-click on entity R1 and select Information... to open its information window.
  4. Find the Hits and Misses entries on the State Data page.
  5. Play the scenario. As the entity shoots at the opposing entities, watch Hits and Misses increase depending on the result of the shot taken.
  6. Right-click on entity R1, go to the Set menu, and choose Clear Accuracy Stats. The Hits and Misses counts should return to 0.
  After the example run is completed - remove the previously copied FED File Name (e.g. AddStateComponent_evolved.xml) from the bin64 directory.
  Restore the previously set FED File Name within the Launcher dialog.

Plugin Code

/*******************************************************************************
** Copyright (c) 2017 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file examplePlugin.cxx
//\brief Loads the plugin and initializes menu items
// This file defines the generic DT_DLL_VRF_PLUGIN_EXPORT_MACRO. Use that macro when
// you want to export symbols. Also, in your CMakeLists.txt file, make sure to
// define the VRFPLUGIN_EXPORTS define to tell the compiler to define the macro as an
// export
#include "accuracyStats.h"
#include <vrvCore/DtDe.h>
using namespace makVrv;
using namespace makVrf;
// Entry point that must be defined by all plugins, this is called as part of the
// process that loads the plugin, before the de is fully initialized
bool initDeModule(DtDe* de)
{
// Add the new menu items into the state page path of the entity information page.
// Pages are now prefaced by the section they are in (if they are in a section)
// so must reference the page as <section name>.<page name>
makVrfGuiObjectInformationQt:: DtInformationDialogManager::instance(*de).informationPageConfiguration().
addPagePathBefore(DtInformationPagePath::page("DtEntityExpandedData.DtEntityInformationPage").informationItem("DtMissStats"),
DtInformationPagePath::page("DtEntityExpandedData.DtEntityInformationPage").informationItem("DtEntityAcceleration"));
makVrfGuiObjectInformationQt::DtInformationDialogManager::instance(*de).informationPageConfiguration().
addPagePathBefore(DtInformationPagePath::page("DtEntityExpandedData.DtEntityInformationPage").informationItem("DtHitStats"),
DtInformationPagePath::page("DtEntityExpandedData.DtEntityInformationPage").informationItem("DtMissStats"));
// And now add the information item creators to be created when these items want to be displayed
makVrfGuiObjectInformationQt::DtInformationDialogManager::instance(*de).informationPageAssembler().
registerPageDataItemCreator(new DtHitStatsCreator);
makVrfGuiObjectInformationQt::DtInformationDialogManager::instance(*de).informationPageAssembler().
registerPageDataItemCreator(new DtMissStatsCreator);
return true;
}
{
info.pluginName = "Add State Property Gui";
info.pluginDescription = "This is an example of how to add an attribute to an entity as a state property and publish that attribute to the network.";
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";
}
/******************************************************************************
** Copyright (c) 2017 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include "accuracyStats.h"
using namespace makVrf;
{
}
{
return "DtHitStats";
}
{
objectDataStateViewCollection()->findStateView(state->id());
if (objDataView)
{
boost::optional<int> numHits =
objDataView->state().myStateProperties.findPropertyValue<int>("TargetsHit");
if (numHits)
{
return QString::number(*numHits);
}
}
return "";
}
{
return QObject::tr("Hits");
}
{
}
{
return "DtMissStats";
}
{
objectDataStateViewCollection()->findStateView(state->id());
if (objDataView)
{
boost::optional<int> numMisses =
objDataView->state().myStateProperties.findPropertyValue<int>("TargetsMissed");
if (numMisses)
{
return QString::number(*numMisses);
}
}
return "";
}
{
return QObject::tr("Misses");
}

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)