VR-Vantage
Loading...
Searching...
No Matches
exampleCustomMenu

Overview

This example shows how to build a custom Menu and menu items using the VR-Vantage application framework and existing parts and pieces.

Expected Result

Custom Menu Application Result

Example details

Say you want to use the existing VR-Vantage application but create your own menus, menu items and sub menu items. The example shows the simplest possible way to achieve this by registering custom menus with VR-Vantage. Once the menus are created, one can add their own logic to the GUI items.

The basic strategy here is let the DtVrvApplication do its thing, then just customize the way it looks. Let it load plug-ins, settings, data, etc. and then just what GUI elements are assembled right before the code that assembles the GUI executes. In this way, you get all the benefits of the plug-in architecture, but all the control of programatically created GUI.

The trick to doing that is to install an application transform, which is really just a function that gets called at a certain point. In this example we are going to install a function that gets called right after the plug-ins are loaded and before the GUI is assembled.

Here is the function we want to install. It's signature has to be the same as the DtVrvApplication::ApplicationTransform funtor:

void postPluginTransform(DtDeInitializer& initializer, DtDe& de, DtVrvApplicationConfiguration& appConfig)
{
// Register the Menu and Menu item so they can be added to the gui.
DtQtMenuAssembler::instance(de).registerMenu(new DtCustomMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(new CustomMenuItem(de));
// Create menu configuration with our custom menu
DtMenuConfiguration myMenu;
myMenu.addMenuPath(DtMenuPath::mainMenu("DtCustomMenu"));
myMenu.addMenuPath(DtMenuPath::mainMenu("DtCustomMenu").item("CustomMenuItem"));
// Minimal UI - Just our custom menu (no pages or toolbars)
appConfig.setMasterModePageConfiguration(DtPageConfiguration());
appConfig.setMasterModeMenuConfiguration(myMenu);
appConfig.setMasterModeToolbarConfiguration(DtToolbarConfiguration());
appConfig.masterModeUIConfiguration().myShowStartupScreen = false;
}
The item for bringing up a Custom dialog. This DtMenuItem is added to the DtCustomMenu menu.
Definition CustomMenu.h:45
A builder for the Custom menu. The menu string is "DtCustomMenu".
Definition CustomMenu.h:24

We install the functor into the DtVrvApplication in main before the applications initialize method is called.

Building the Example

VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running vrvStealth.exe –plugin ../examples/plugins/release/exampleCustomMenu.dll (on Windows) or vrvStealth.exe –plugin ../examples/plugins/release/libexampleCustomMenu.so (on Linux) from the command prompt. Once the application is started, click on the "Customize" menu to see the popup. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleCustomMenu.cxx

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include "CustomMenu.h"
#include <vrvCore/DtDe.h>
using namespace makVrv;
void postPluginTransform(DtDeInitializer& initializer, DtDe& de, DtVrvApplicationConfiguration& appConfig)
{
// Register the Menu and Menu item so they can be added to the gui.
DtQtMenuAssembler::instance(de).registerMenu(new DtCustomMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(new CustomMenuItem(de));
// Create menu configuration with our custom menu
myMenu.addMenuPath(DtMenuPath::mainMenu("DtCustomMenu"));
myMenu.addMenuPath(DtMenuPath::mainMenu("DtCustomMenu").item("CustomMenuItem"));
// Minimal UI - Just our custom menu (no pages or toolbars)
appConfig.setMasterModeMenuConfiguration(myMenu);
}
void init(DtDe& de)
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
if (de.isInMasterMode())
{
// Add example menu
if (app)
{
DtVrvApplication::ApplicationTransform functor = boost::bind(&postPluginTransform, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3);
app->installPostPluginTransform(functor, "SetupGUIPostPluginTransform");
}
}
}
bool initDeModule(DtDe* de)
{
init(*de);
return true;
}
Contains the DtCustomMenu class declaration.
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtMenuPath class.
Contains makVrv::DtQtMenuAssembler class.
Contains makVrv::DtVrvApplication implementation.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
The initialization configuration for the makVrv::DtDe.
Definition DtDeInitializer.h:40
A configuration of a menu layout. A menu configuration manages an ordered collection of menu paths th...
Definition DtMenuConfiguration.h:44
void addMenuPath(const DtMenuPath &, const MenuSortFlags &sortFlagsIfMenu=(MenuSortFlags)(SortAllAlphabetically|SortWithinSubmenus|SortBetweenSeparators))
Adds the menu path (as well as its entire family).
static MenuPathBuilder mainMenu(const std::string &name)
A configuration of the pages in the gui.
Definition DtPageConfiguration.h:26
static DtQtMenuAssembler & instance(DtDe &de)
Get an instance of the assembler.
A configuration of the toolbar layout.
Definition DtToolbarConfiguration.h:26
This owns a list of display engine configurations.
Definition DtVrvApplicationConfiguration.h:33
const UIConfiguration & masterModeUIConfiguration() const
void setMasterModePageConfiguration(const DtPageConfiguration &pageConfig)
void setMasterModeToolbarConfiguration(const DtToolbarConfiguration &toolbarConfig)
void setMasterModeMenuConfiguration(const DtMenuConfiguration &menuConfig)
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
static DtVrvApplication * findFromDe(DtDe &)
virtual void installPostPluginTransform(const ApplicationTransform &transform, const std::string &id)
Add a transformer that runs after plug-ins are loaded.
boost::function< void(DtDeInitializer &, DtDe &, DtVrvApplicationConfiguration &)> ApplicationTransform
Definition DtVrvApplication.h:147
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains DLL export macros.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
bool myShowStartupScreen
Definition DtVrvApplicationConfiguration.h:42