![]() |
VR-Forces 5.0.1 Developer's Guide
|
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:
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"
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.
This example demonstrates how to add a new kind of conditional test that can be used within a conditional expression.
In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.
To view the new behavior:
| vrfAddConditionalExample::DtNorthConditional | The widget that is used to select the entity that will be tested. |
| vrfAddConditionalExample::MyConditionalExpression | The subclass of DtSimCondExpr that is used to communicate the new conditional. |