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

Table of Contents

The Add Conditional example adds a new plan conditional which trigger when an entity is facing north (heading of 0 degrees).

The example is intended to demonstrate the following:

Adding a New Menu Item to the Conditional Menu

Registering a new conditional menu item in the conditional menu requires deriving a new class from makVrf::DtVrfConditionalExpressionCreator, configuring its key methods, and then registering the creator function in the conditional menu. Our conditional creator class is called vrfAddConditionalExample::DtNorthConditionalCreator. The key methods of makVrf::DtVrfConditionalExpressionCreator are:

makVrf::DtVrfConditionalExpressionCreator::create() Adds a new dialog object to the heap (vrfAddConditionalExample::DtNorthConditional in this example) and returns its pointer
makVrf::DtVrfConditionalExpressionCreator::title() Returns the menu item string ("Facing North").
makVrf::DtVrfConditionalExpressionCreator::canEditType() Checks the conditional type() int with that of the conditional expression class.

The makVrf::DtVrfConditionalExpressionCreator class must be then registered with the dialog manager makVrf::DtVrfConditionalDialogManager. In our example, we register it in /examples/addConditional/addConditionalGui/addConditionPlugin.cxx.

this particular implementation inserts our menu item just before a menu item in the conditional combo box called "RANDOM"

Adding and Registering a Conditional Dialog

The Add Conditional example makes use of extant dialog classes associated with conditionals with minor customization. The interaction of important classes is structured around the Humble Dialog pattern. As such, we have a templated interaction of a logic class which interacts with a generalized interface class. The particular dialog class is then derived at some level from the interface class. Finally, the dialog creator class is tied to the dialog class. The following table describes our particular implementation:

Class Role Template class Example class Description
Logic makVrf::DtBaseEntityConditionalExpressionLogic vrfAddConditionalExample::DtNorthConditionalLogic populates dialog, communicates between dialog and back-end via interface calls
Interface makVrf::DtConditionalExpressionInterface (not instantiated) provides framework for Logic-Dialog interaction
Dialog makVrf::DtBaseEntityConditionalExpressionDialog vrfAddConditionalExample::DtNorthConditional provides GUI definition; instantiates logic class
Dialog Creator makVrf::DtVrfConditionalExpressionCreator vrfAddConditionalExample::DtNorthConditionalCreator used by conditional dialog manager to inantiate dialog object

As mentioned in the previous section, the dialog creator object, vrfAddConditionalExample::DtNorthConditionalCreator, is registered with the dialog manager in addConditional/addConditionalGui/addConditionPlugin.cxx. Additionally, the conditional expression creator function from the back-end, vrfAddConditionalExample::MyConditionalExpression::creator(), is also registered with the sim messager, makVrf::DtVrfSimMessager along with its unique string name and integer, in the same plugin file:

In this example, the dialog class, vrfAddConditionalExample::DtNorthConditional, is nearly identical to its parent class, as the default makVrf::DtBaseEntityConditionalExpressionDialog is fully appropriate for this particular conditional. Its only real points of customization involves overriding the constructor in order to instantiate its own distinct logic class vrfAddConditionalExample::DtNorthConditionalLogic, and to override the pure virtual setupConditional() method of the interface class with vrfAddConditionalExample::DtNorthConditional::setupConditional(), passing the setupConditional() call on through its logic class.

Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces 3D application.

How to Run the Example

This example demonstrates how to add a new kind of conditional test that can be used within a conditional expression.

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Create a new EntityLevel scneario (any terrain can be used - e.g. Ground_DB II).
  3. Create a new M1A2. By default, it will be facing north.
  4. Create a second M1A2.
  5. Set the heading of the second M1A2 to 90 degrees (facing east).
  6. Create a new plan for the first entity. Add an 'If' expression with the new 'Facing North' condition.
  7. In the 'Then' clause, give the entity a move-to-location task.
  8. Create a similar new plan for the second entity (same 'If/Then' statement).
  9. View the plan windows for each entity.
  10. Hit play.
  11. Observe that the first M1A2 (that was facing north by default) moves, while the second entity (not facing north) remains stationary.

Classes

vrfAddConditionalExample::DtNorthConditionalThe widget that is used to select the entity that will be tested.
vrfAddConditionalExample::MyConditionalExpressionThe subclass of DtSimCondExpr that is used to communicate the new conditional.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file addConditionalPlugin.cxx
//\brief Contains plugin function
//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 "../addConditionalSim/conditionalExpression.h"
#include <vrvCore/DtDe.h>
using namespace makVrf;
using namespace vrfAddConditionalExample;
{
//[registering a conditional menu item]
//[registering a conditional menu item]
//[registering a conditional with the sim messager]
//[registering a conditional with the sim messager]
return true;
}
//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
{
info.pluginName = "Add Conditional Gui";
info.pluginVersion = "1.00";
info.pluginDescription = "Front-end plugin addition to add new Conditional command";
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";
}

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)