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

Table of Contents

The Add FOM Class example demonstrates the following:

Adding a New FOM Object Class

The Add FOM Class example shows how to add a new FOM object class that is not part of the RPR FOM and is therefore not typically supported by VR-Forces. It shows how to map this new object class to an existing RPR-based object, assuming the concepts being simulated are similar.

Note
Please note that if you use this technique in order to use an alternate FOM that does not contain one of the standard classes required by VR-Forces, you may need to edit the configuration file appData/settings/vrfSim/requiredFomClasses.mtl so that the initial validation check does not fail when the class is missing.

This example also uses an example SMS called addFomClass which can be found in data. This SMS includes a new OPE file called Alternate_Fixed_Wing.ope. This OPE makes two important additions to the standard EntityLevel Fixed Wing OPE file:

1) The hla-fom-class is set so that any entity that uses this OPE will be published with the new FOM object class.

(hla-fom-class "AlternateEntity")

2) A new state property is added in the state-data section. This state property is added to support the only attribute of the new FOM class that cannot be mapped to an existing RPR FOM entity attribute. All other attributes are mapped to existing RPR FOM attributes in the example code. This state property is a structure with two fields. This structure matches the attribute of the same name in the AlternateEntity FOM class. In order to properly encode and decode this attribute as a state property, it is important that the type defined in the OPE matches the datatype in the FOM.

(state-data (DtRwStructure SomeOtherAttribute (DtRwReal Field1 0.0) (DtRwInt Field2 0) publish ) )

For more details on state properties, please see the Add State Property Sim example.

The plug-in code configures the VR-Link FOM mapper so that instances of AlternateEntity can be encoded from and decoded to an entity state repository, which is based on the RPR FOM entity classes. It also adds the AlternateEntity FOM class as a supported class of the DtExtendedPropertiesEntityPublisher and DtExtendedPropertiesEntityList classes in order to process additional FOM attributes as state properties.

The example scenario also includes a Lua scripted set called Some Other Attribute that sets the two fields of the AlternateEntity attribute called SomeOtherAttribute.

How to Run the Example

  1. Copy the AlternateEntity_evolved.xml FOM module from examples to the bin64 directory. Note that this FOM module is for HLA Evolved. If you use another HLA version, you must edit your FOM to add in the new FOM class.
  2. Since this example is loaded as a plug-in, it can be used in conjunction with the released VR-Forces application.

Usage

In the Launcher:

  1. Choose an HLA 1516 Evolved protocol configuration.
  2. Set the addFomClass plug-in to load.
  3. Add AlternateEntity_evolved.xml to the list of FOM modules.
  4. Set the RPR FOM version to 2.0.
  5. Start VR-Forces.

To view the new behavior:

  1. Load the addFomClass developer toolkit example scenario
  2. Notice the entity that appears. It is published using AlternateEntity FOM class. This can be verified by running another application that subscribes to this class or using some inspection tool of your RTI.
  3. Right-click on the entity and then choose Information... to open its information window.
  4. Find the Some Other Attribute entry on the State Data page, which is updated via the SomeOtherAttribute state property.
  5. By default, after the very first scenario loads, the text should read "7 | 8".
  6. Select the entity and open the Set->Some Other Attribute dialog. Set the two fields to new values.
  7. The Some Other Attribute entry on the State Data page will update.

After the example run is completed:

Configure FOM Mapper Code

/*******************************************************************************
** Copyright (c) 2018 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#if DtHLA
#include "configFomMap.h"
#include "altEntityEnc.h"
#include "altEntityDec.h"
#include <vl/stateEncoderFactory.h>
#include <vl/stateDecoderFactory.h>
#include <vl/fom.h>
#include <vl/fomMapper.h>
const DtString theFomClass = "AlternateEntity";
void configFomMapper(DtExerciseConn* exConn, bool runExtPropInit)
{
DtFom* fom = exConn->fom();
DtFomMapper* mapper = exConn->fomMapper();
// Add our new class as one of the supported classes for extended attributes.
// This allows us to process any new attributes that cannot be directly mapped
// into RPR attributes by making them state properties. They must be defined in
// the OPE file in the SMS, but once there they will automatically be encoded and
// decoded as state properties.
init->addSupportedClass(theFomClass);
// Provide our new initializer to the publisher and reflected list classes prior
// to them their creation.
// Now add our encoder and decoder to map the relevant attributes to and from the new
// class and the corresponding RPR attributes.
DtObjClassDesc* objClass = fom->objClassByName(theFomClass);
if (objClass)
{
AlternateEntityEncoder* enc = new AlternateEntityEncoder(exConn, objClass);
mapper->stateEncoderFactory()->addEncoder(objClass->handle(), enc);
AlternateEntityDecoder* dec = new AlternateEntityDecoder(exConn, objClass);
mapper->stateDecoderFactory()->addDecoder(objClass->handle(), dec);
}
// Runs the initialization performed by the Extended Attributes Initializer. When
// using Extended Attributes publishers and reflected lists this is not necessary,
// but the GUI uses its own subclasses of the publishers and reflected lists, so
// this step is required for the GUI.
if (runExtPropInit)
{
init->initialize(exConn);
}
}
void unconfigFomMapper(DtExerciseConn* exConn)
{
DtFom* fom = exConn->fom();
DtFomMapper* mapper = exConn->fomMapper();
// Remove the object class encoder and decoder when the plugin is removed.
DtObjClassDesc* objClass = fom->objClassByName(theFomClass);
if (objClass)
{
DtHlaStateEncoder* enc = mapper->stateEncoderFactory()->addEncoder(
objClass->handle(), 0);
delete enc;
DtHlaStateDecoder* dec = mapper->stateDecoderFactory()->addDecoder(
objClass->handle(), 0);
delete dec;
}
// Remove the Extended Attributes Initializer when the plugin is removed.
}
#endif

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)