VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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.

To view the new behavior:

  1. Create a new scenario.
  2. Create a new M1A2. By default, it will be facing north.
  3. Create a second M1A2.
  4. Set the heading of the second M1A2 to 90 degrees (facing east).
  5. Create a new plan for the first entity. Add a IF 'facing north' statement. In the 'then' clause, give the entity a move-to-location task.
  6. Create a similar new plan for the second entity (same IF/THEN statement).
  7. View the plan windows for each entity.
  8. Hit play.

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


Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)