VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Menu Manipulation (menuManipulation)

Table of Contents

The Menu Manipulation example demonstrates the following:

Modifying the Menus

The Menu Manipulation example demonstrates how to manipulate the menu, changing it from the system default.

This example shows you how to modify the following menus:

How to Run the Example

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. Load an existing scneario - e.g. HawaiiGround.scnx.
  3. Right click on an entity - e.g. CH-47 1. From the context meny select Task -> Embarkation. The Embark and Disembark sub-menu items are removed.
  4. The Embark and Disembark sub-menu items have been moved in the new Task -> Task Example menu.
  5. Select the Create manu item from the GUI main menu. A new menu item Example -> M1A2 has been added.
  6. In a similar way - you can observe the other menu modifiactions listed in the previous section.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file menuManipulationPlugin.cxx
//This file defines the generic DT_DLL_VRF_PLUGIN_EXPORT_MACRO. Use that macro when
//you want to export symbols.
//Include for task menu modifications
//Include for set menu modifications
//Include for create menu modifications
//Include for menu bar modifications that are not one of the above 3
//Include for right click menu modifications
//Included for this example to show direct entity mapping addition to menus
//Included for removing items from the create menu and palette
using namespace makVrf;
// Filter to filter out friendly M1A2 from entity create palette
class DtMenuManipulationPaletteFilter : public DtPaletteFilter
{
public:
DtMenuManipulationPaletteFilter() {};
DtMenuManipulationPaletteFilter(const DtMenuManipulationPaletteFilter& orig) : DtPaletteFilter(orig) {};
virtual bool shouldAddCreationItem(const DtEntityPaletteItem& item, const std::set<std::string>& categories, const std::string& deployedCountry, int force) const
{
if ((force == DtForceFriendly) && (item.myMapperKey == DtEntityType(1, 1, 225, 1, 1, 3, 0)))
{
return false;
}
return true;
}
DtPaletteFilter* clone() const
{
return new DtMenuManipulationPaletteFilter(*this);
}
};
// Because the create menu is recreated with each new scenario, need to manipulate the menu here after it
// has been loaded
void DtCreateMenuConfigurationLoaded(makVrv::DtDe* de)
{
//Now remove all fixed wings from the model set (which is used for the create menu and the create
//palette) so they can no longer be added
DtModelSet copySet(*mgr.modelSet());
DtListItem* item = copySet.first();
while (item)
{
DtModelSetEntry* entry = static_cast<DtModelSetEntry*>(item->data());
if (entry->categories().containsValue("Fixed Wing"))
{
}
else if (entry->label() == "Route")
{
}
item = item->next();
}
}
//This method will modify the information section of the entity section to remove
//the altitude item and add the heading item
void modifyInformationSection(makVrv::DtDe& de)
{
removeInformationItemFromSection("DtEntityInformation", "DtEntityCompactData", "DtEntityAltitude");
addInformationItemToSection("DtEntityInformation", "DtEntityCompactData", "DtEntityHeadingPitchRoll", 1, 3, 1, 1, 128);
}
//This method (called from below) will remove menu items from the configuration.
//The task, set, command, entity and conditional menus are each handled separately
//from the rest of the menu bar, however, all are touched on in this method
void removeMenuItems(makVrv::DtDe& de)
{
//Do not allow the user to save any terrains from the file menu. This is an
//example of how to remove an individual menu item.
//Another example of removing a menu from this same menu
//This is an example of how to remove an entire menu from the configuration
//Because the create menu is now populated by a settings file that is part of
//each simulation model set, setup a signal connection to be made to remove
//the create menu item from the model set as it is loaded
(boost::bind(&DtCreateMenuConfigurationLoaded, &de));
//Add a palette filter to the palette logic to filter out some items for creation
DtMenuManipulationPaletteFilter filter;
}
//Complete removal of existing task menu items
void DtTaskMenuConfigurationLoaded(makVrv::DtDe* de)
{
}
//This function will take existing menu items and reorganize them. Specifically putting some items on the task
//menu in sub-menu. This function only shows reorganization in the task menu, but you could apply this to
//many other menus. You can even move it across other menus entirely, but you will need to be sure to register
//those items to the menu class assuming it doesn't already have it.
void reorganizeTaskMenuItems(makVrv::DtDe& de)
{
//To add a new sub-menu with text "Embark" that will be referenced as DtEmbarkSubmenu from now on.
//This function at the base menu level creates and registers a simple menu with your choice
//of text and your choice of a key to reference this menu in paths. It creates the menu, registers it
//for use and then adds it to the path you specify all at once making it really simple to create
//a series of sub-menus.
makVrv::DtMenuPath::mainMenu(DtTaskMenuId).menu("DtEmbarkSubmenu"));
//Because the task menu is now populated by a settings file that is part of
//each simulation model set, setup a signal connection to be made to remove
//the task menu item from the initial task configuration
//Now, remove these menu items from their current location
(boost::bind(&DtTaskMenuConfigurationLoaded, &de));
//And now re-add them to the new sub-menu we created earlier in this function
}
//This function will be used in our next function addToCreateMenu(). This function will be called
//when you click the newly created menu item. You can do whatever you like in this function but
//this sample just pops up a simple dialog. This function must be structured like this in terms of the
//function signature. The usr arg is an optional argument you would set to be your class object
//incase you wanted to register a class specific function and access real data members. You would need
//to cast the void* to your class pointer.
void exampleMenuItemTrigger(makVrv::DtDe& de, void* usr)
{
QMessageBox::information(NULL, QObject::tr("Example Menu Item Pressed"), QObject::tr("Your menu item works!"));
}
//This function will add some new items to the create menu. Will add an example menu item,
//a menu item to create the removed M1A2, and a new sub-menu which contains a few items
void addToCreateMenu(makVrv::DtDe& de)
{
//This is an example of creating a simple menu item and adding it to a specific location
//in the menus. This also gives the menu an action which we defined in the function before this
//called exampleMenuItemTrigger(). Notice that function gets called whenever you click this
//menu item which is called "Example Menu Item..." in your menus but reference as "DtExampleMenuItem".
//This works with any main menu (task, set, mainmenu, right click), but it is shown here in the create menu
makVrv::DtMenuPath::mainMenu(DtCreateMenuId).item("DtExampleMenuItem"),
makVrv::DtMenuPath::mainMenu(DtCreateMenuId).item("Waypoint"), &exampleMenuItemTrigger);
//Now, add a sub-menu called example again. Similar to what we did in the task menu,
//but with a different text and different string reference name.
//Finally, we add the M1A2 creation option to that sub-menu. The create menu has this specialized
//function that allows you to directly reference what entity mapper key you wish to make with the
//string you wish to appear in the menu.
makVrv::DtMenuPath::menu("DtExampleMenu").item("M1A2"),
DtEntityMapperKey(1, 1, 1, 225, 1, 1, 3, 0));
}
//Complete removal of existing set menu items
void DtSetMenuConfigurationLoaded(makVrv::DtDe* de)
{
}
//This example will take existing menu items and reorganize them. Specifically putting some items
//from the set menu in to a sub-menu in the set menu. Similar to what we did with the task menu earlier.
void reorganizeSetMenuItems(makVrv::DtDe& de)
{
//To add a new sub-menu, the text is "Positioning" and the reference is "DtPositioningSetSubmenu".
//Again we are using this simple menu creation. It is very useful for creating submenus with no
//real special functionality.
makVrv::DtMenuPath::mainMenu(DtSetMenuId).menu("DtPositioningSetSubmenu"),
//Because the set menu is now populated by a settings file that is part of
//each simulation model set, setup a signal connection to be made to remove
//the set menu item from the initial set configuration
//Now, remove these menu items from their current location
(boost::bind(&DtSetMenuConfigurationLoaded, &de));
//And add them to the new sub menu in the set menu
makVrv::DtMenuPath::mainMenu(DtSetMenuId).menu("DtPositioningSetSubmenu").item(DtVrfSetLocationActionId));
makVrv::DtMenuPath::mainMenu(DtSetMenuId).menu("DtPositioningSetSubmenu").item(DtVrfSetHeadingActionId));
}
//Adds a new menu called "Example" by using the simple menu creation and adds
//new menu items to it.
void addMenu(makVrv::DtDe& de)
{
//Here we are using the simple menu creation to create a top level menu in the menu bar.
//Notice the accessor is via DtVrfMainMenu which will reference any menu in the menu bar.
//It's also important to notice that if you want to directly affect a specialized menu that
//is in the menu bar, such as the task,set, or create menus, you need to use their accessors
//as we have shown in previous functions. Here you are adding this new example menu before the
//task menu in the menu bar.
makVrv::DtMenuPath::mainMenu("DtExampleMenu"),
//Now we are creating a simple menu item in this example menu. Notice that even though
//we created a similar menu in the create menu, each main menu has its own set of menus
//that it keeps track of. This means that we had to recreate the simple menu for the main
//menu in order for us to add it. We will reuse the same function we used for the create
//menu where it pops up a dialog when you click this menu item.
DtVrfMainMenu::instance(de).createSimpleMenuItem("Example Menu Item...",
makVrv::DtMenuPath::mainMenu("DtExampleMenu").item("DtExampleMenuItem"),
&exampleMenuItemTrigger);
}
//This function will modify the right click menu. Unlike other menus, the right click menu
//has a special "context sensitivity". What this means is that modifying the right click menu
//changes depending on what is being selected in the GUI. The right click menu allows you
//to specify a "context", which some are predefined and usable, or you can define contexts
//yourself, in which the selection meets your criteria and then you apply those changes.
//This example uses the built in "Entity" context. Here we make changes to the right click
//menu only when an entity is selected. All changes follow the context set so the right
//click menu knows what changes to apply to that context. If you wanted to make changes to
//other contexts, you would set the current context, current as in "working", and make
//modifications to that context.
void modifyRightClick(makVrv::DtDe& de)
{
//First set the context where you want your changes to apply to. It's a boolean evaluated
//function based on parameters supplied.
//Context options include "Entity", "Aggregate", "Terrain", and "Global".
//Now any changes I make to the right click will ONLY apply to the "Entity" context and use
//that context name's evaluation function. Here I am adding the example menu item we created
//in the main menu. Items registered in the main menu do not need to be re-registers in the
//right click menu before you start adding/removing them from the menuConfig.
//Add a menu separator. This can be done in any main menu. The name supplied is how you reference it
//if you want to put other menu items before/after it.
makVrv::DtMenuPath::popupMenu(DtVrfRightClickContextMenuId).separator("DtExampleMenuSeparator"));
//Adds the previously created example menu
//Adds the same menu item we already added to this sub-menu as well
makVrv::DtMenuPath::popupMenu(DtVrfRightClickContextMenuId).menu("DtExampleMenu").item("DtExampleMenuItem"));
}
//This function is called by our plugin structure to make changes to the front end. It goes through
//each function (as you may have already done) and makes modifications to each area of the menus in the GUI.
//Only return true if you are sure you want to continue. In this case, we are set to go once all the changes
//are made.
{
removeMenuItems(*de);
reorganizeTaskMenuItems(*de);
reorganizeSetMenuItems(*de);
addToCreateMenu(*de);
addMenu(*de);
modifyRightClick(*de);
modifyInformationSection(*de);
return true;
}
//This function is also called by our plugin structure and prints out information about this plugin
//to the logs. It's a good indicator that the plugin loaded if you are looking at the logs.
{
info.pluginName = "Menu Manipulation";
info.pluginDescription = "This example shows how to manipulate menu items.";
info.pluginVersion = "1.00";
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 Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)