VR-Forces 4.0.4 Class Documentation
Add Set Front-End Example

The Add Set example creates a new "Set" command that allows a user to set an entity's current speed and heading. When the command is selected from the Set menu, a dialog box that allows entry of desired speed/ heading is created. The larger architecture of GUI and Menus in the VR Forces Front End is described in more detail in section 3.1 in the VRF Front End Developers Guide.

The front-end example demonstrates the following:

Adding an Item to the Set Menu

Most of the work in placing, registering and associating a menu item in this example is done in addSet/addSetGui/addSetPlugin.cxx. Adding an item to the set menu involves establishing a menu item object derived from the makVrf::DtVrfTaskSetMenuItem class. This example creates a menu item called vrfAddSetExample::DtSetSpeedAndHeadingMenuItem. A string called the menuItemIdName linking this entry to its menu item object must be inserted into the makVrf::DtSetMenu relative to another menuItemIdName:

   //Inserts the DtSetSpeedAndHeadingMenuItem object name as the menu item into a specific point of the Set Menu with the masterModeMenuConfiguration
   //The set entry is placed after the menu entry corresponding to the "DtVrfSetResponsibilityAction" object
   setMenu.menuConfiguration().addMenuPathAfter(makVrv::DtMenuPath::mainMenu(DtSetMenuId).item(DtSetSpeedAndHeadingMenuItemIdName),
      makVrv::DtMenuPath::mainMenu(DtSetMenuId).item(DtVrfSetResponsibilityActionId));

Now the actual menu item object vrfAddSetExample::DtSetSpeedAndHeadingMenuItem must be instantiated and registered with the set menu assembler:

The menu item inserted in the first quoted bit of code is associated in the Set Menu by the common text string vrfAddSetExample::DtSetSpeedAndHeadingMenuItemIdName. A string like this one is central to the identification of all menu items and our vrfAddSetExample::DtSetSpeedAndHeadingMenuItem object is initialized with this string.

Creating and Linking a GUI Dialog Box

In this example, the dialog box object is derived from DtSetSpeedAndHeadingDialog - a Qt object ultimately derived from QWidget. The actual layout and definition of the interface is entirely specified in the contents() method, and the accessors and mutators are also contained in this object. There is an associated creator object deriving from DtVrfTaskSetDialogCreator - in our case, DtSetSpeedAndHeadingDialogCreator - that is registered with the DtVrfTaskSetDialogManager in the constructor of the menu item (DtSetSpeedAndHeadingMenuItem).

Sending the Set Command From the Front-end to the Back-end

The back-end set-creator function, DtSetSpeedAndHeadingRequest.creator(), is registered with the DtVrfSimMessager in the front-end plugin initialization, initDeModule. It links the back-end creator with the front-end via the common string DtSetSpeedAndHeadingString. In the back-end, the creator function is registered with the factory in DtInitializeVrfPlugin in addSetSim\plugin.cxx. The message sent through the DtSetSpeedAndHeadingRequest is passed on to the entity-specific controllers generated in the back-end.

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

How to Run

This example demonstrates how to add a new kind of set data request (set heading and ordered speed).

To view the new behavior:

  1. Open a database or create a new scenario.
  2. Create a lifeform entity (e.g. 'Friendly Dismounted Infantry). Any ground vehicle, air vehicle, and/or lifeform will work with this example.
  3. Right-click on entity and select the new entry 'Set->Speed and Heading...".
  4. In the 'Set Heading and Speed' dialog, select the desired heading and ordered speed for the entity.
  5. Click OK to exit the dialog. The entity will snap to the new heading.
  6. Give the entity a movement task. It will move at the speed specified in the 'Set Heading and Speed' request.

Classes

DtSetSpeedAndHeadingMenuItemThe menu item that will register the dialog to be shown when this set is requested.
DtSetSpeedAndHeadingDialogThe Qt widget that generates the dialog box used to enter the speed and heading information.
DtSetSpeedAndHeadingRequestThe subclass of DtSetDataRequest that is used to communicate the new set request between the front-end and the back-end.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/

//\file addSetPlugin.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 <vrfGuiCore/vrfGuiExportPlugin.h>

#include "DtSetSpeedAndHeadingMenuItem.h"
#include "../addSetSim/setSpeedAndHeading.h"

#include <vrfGuiCoreQt/DtSetMenu.h>
#include <vrfGuiCore/DtGuiThreadVrfRemoteController.h>
#include <vrfGuiConstants/vrfMenuIds.h>

#include <vrvCore/DtDe.h>
#include <vrvCoreQt/DtQtMenuAssembler.h>

using namespace vrfAddSetExample;
using namespace makVrf;

bool initDeModule(makVrv::DtDe* de)
{
   DtSetMenu& setMenu = makVrf::DtSetMenu::instance(*de);

   //[insert menu item string into set menu]
   //Inserts the DtSetSpeedAndHeadingMenuItem object name as the menu item into a specific point of the Set Menu with the masterModeMenuConfiguration
   //The set entry is placed after the menu entry corresponding to the "DtVrfSetResponsibilityAction" object
   setMenu.menuConfiguration().addMenuPathAfter(makVrv::DtMenuPath::mainMenu(DtSetMenuId).item(DtSetSpeedAndHeadingMenuItemIdName),
      makVrv::DtMenuPath::mainMenu(DtSetMenuId).item(DtVrfSetResponsibilityActionId));
   //[insert menu item string into set menu]

   //[register menu item with set menu]
   //Registers the DtSSetSpeedAndHeadingMenuItem object with the makVrf::DtSetMenu assembler
   setMenu.registerMenuItem(new DtSetSpeedAndHeadingMenuItem(*de));
   //[register menu item with set menu assembler]

   //Registers the set creator in the back-end, linking it with the front-end by the common string DtSetSpeedAndHeadingString
   DtGuiThreadVrfRemoteController::instance(*de).addSetCreatorFcn(
      DtSetSpeedAndHeadingString, DtSetSpeedAndHeadingRequestType, DtSetSpeedAndHeadingRequest::creator);

   return true;
}

void DtPluginInformation(DtVrfPluginInformation& info)
{
   info.pluginName = "Add Set Gui";
   info.pluginVersion = "1.00";
   info.pluginDescription = "Front-end plugin addition to add new Set Speed and Heading... command";
   info.pluginCreator = "MAK Technologies";
   info.pluginCreatorEmail = "sales@mak.com";
   info.pluginContactWebPage = "www.mak.com";
   info.pluginContactMailingAddress = "68 Moulton Street - Cambridge, MA 02138";
   info.pluginContactPhone = "(617) 876 8085";
}

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)