VR-Vantage API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleCustom

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

What if you wanted to build your own application that looked different that any of the existing VR-Vantage applications, yet also use all of the existing widgets, pages and other parts? The easist way to do that is to build a custom VR-Vantage application and add only the things you want to it.

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)
{
// Setup the pages
appConfig.setMasterModePageConfiguration(createCustomPages());
// Setup the menus
appConfig.setMasterModeMenuConfiguration(createCustomMenu());
// Setup the toolbars
appConfig.setMasterModeToolbarConfiguration(createCustomToolbar());
}

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

int main(int argc,char** argv)
{
// Create a custom configuration for your GUI.
DtCustomConfiguration config;
// A DtVrvApplication wraps up all the components required to build a complete
// VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
// DtVrvApplicationConfiguration).
DtVrvApplication vrvApp(config);
// Create a functor to install into the application.
DtVrvApplication::ApplicationTransform functor = boost::bind(&postPluginTransform, _1, _2, _3);
// Install our application transform after the plug-ins are loaded and before the GUI is assembled.
vrvApp.installPostPluginTransform(functor, "postPluginTransform");
// Use the stealth's command line processor or create your own.
DtStealthCommandLineProcessor cmdLineProcessor;
vrvApp.installCommandLineProcessor(&cmdLineProcessor);
// This causes the plug-in manager to load plug-ins, cause a Display Configuration
// to be realized, creates the default environment, etc.
vrvApp.initialize(argc, argv);
// Creates an event loop and begins running it, causing the creation of frames.
vrvApp.run();
}

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 an application. You can run it by running ./bin/exampleCustom.exe (on Windows) or ./bin/exampleCustom (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleCustom.cxx

// /******************************************************************************
// ** Copyright (c) 2008 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
// /******************************************************************************
// ** $RCSfile: exampleCustom.cxx,v $ $Revision: 1.13 $ $State: Exp $
// ******************************************************************************/
#include <list>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/foreach.hpp>
// Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace.
using namespace makVrv;
class DtCustomConfiguration : public DtVrvApplicationConfiguration
{
public:
DtCustomConfiguration()
{
this->setLogFileName("exampleCustom.log");
deName += " 1";
this->setDisplayEngineName(deName);
this->setDeMode(DtDeInitializer::MasterMode);
this->setAutoLoadDrivers(true);
this->setAssembleUserInterfaceComponents(true);
DtObserverConfiguration observerConfig("Observer 1");
inputConfig.observerConfigurations().add(observerConfig);
inputConfig.setOptionalParameter( "windowDependent", "true" );
this->setInputDriverConfiguration( inputConfig );
this->pathConfiguration().setFactoryPath(
"../factory/settings/stealth");
// However, give this application our own application settings directory to mess with.
std::string settingsPath = this->pathConfiguration().appPath();
settingsPath += "/settings/exampleCustom";
this->pathConfiguration().setSettingsPath(settingsPath);
this->setApplicationName("VR-Vantage Custom Application");
this->setShowQuitDialogOnClose(true);
}
virtual ~DtCustomConfiguration()
{
}
};
DtPageConfiguration createCustomPages()
{
pages.addPageCollection("DtObjectsListPanel",DtUnicode::fromAscii("Objects List"),DtPageConfiguration::DockLeft,true,"DtOverlaysPage");
pages.addPagePath(DtPagePath::collection("DtObjectsListPanel").page("DtObjectsListPage"));
pages.addPagePath(DtPagePath::collection("DtObjectsListPanel").page("DtOverlaysPage"));
pages.addPageCollection("DtAttachmentPanel",DtUnicode::fromAscii("Attachments"),DtPageConfiguration::DockLeft,true,"DtAttachWidget");
pages.addPagePath(DtPagePath::collection("DtAttachmentPanel").page("DtAttachWidget"));
return pages;
}
DtMenuConfiguration createCustomMenu()
{
//*********************************************************************
//The File Menu.
//*********************************************************************
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").menu("DtNewMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").menu("DtOpenMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").separator("1"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").menu("DtAddMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").separator("2"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").menu("DtCloseMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtFileMenu").item("DtExitItem"));
menus.addMenuPathBefore(DtMenuPath::mainMenu("DtFileMenu").separator("ExitSeparator"),
DtMenuPath::mainMenu("DtFileMenu").item("DtExitItem"));
//Relative menus
menus.addMenuPath(DtMenuPath::menu("DtNewMenu").item("DtNewSceneItem"));
menus.addMenuPath(DtMenuPath::menu("DtNewMenu").item("DtNewTerrainItem"));
menus.addMenuPath(DtMenuPath::menu("DtOpenMenu").item("DtOpenSceneItem"));
menus.addMenuPath(DtMenuPath::menu("DtOpenMenu").item("DtOpenTerrainItem"));
menus.addMenuPath(DtMenuPath::menu("DtAddMenu").item("DtAddTerrainPatchMenuItem"));
menus.addMenuPath(DtMenuPath::menu("DtAddMenu").item("DtAddFeatureLayerItem"));
menus.addMenuPath(DtMenuPath::menu("DtCloseMenu").item("DtCloseTerrainItem"));
//*********************************************************************
//The Window Menu.
//*********************************************************************
menus.addMenuPath(DtMenuPath::mainMenu("DtViewMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtViewMenu").item("DtAttachmentPanel"));
menus.addMenuPath(DtMenuPath::mainMenu("DtViewMenu").item("DtObjectsListPanel"));
//Add a separator after the DtObjectsListPanel.
menus.addMenuPathAfter(DtMenuPath::mainMenu("DtViewMenu").separator("1"),
DtMenuPath::mainMenu("DtViewMenu").item("DtObjectsListPanel"));
menus.addMenuPathAfter(DtMenuPath::mainMenu("DtViewMenu").item("DtSceneToolbar"),
DtMenuPath::mainMenu("DtViewMenu").separator("1"));
menus.addMenuPathAfter(DtMenuPath::mainMenu("DtViewMenu").item("DtTerrainToolbar"),
DtMenuPath::mainMenu("DtViewMenu").item("DtSceneToolbar"));
menus.addMenuPathAfter(DtMenuPath::mainMenu("DtViewMenu").item("DtSimulationConnectionsToolbar"),
DtMenuPath::mainMenu("DtViewMenu").item("DtDisplaySettingsToolbar"));
menus.addMenuPathAfter(DtMenuPath::mainMenu("DtViewMenu").separator("2"),
DtMenuPath::mainMenu("DtViewMenu").item("DtSimulationConnectionsToolbar"));
menus.addMenuPath(DtMenuPath::mainMenu("DtViewMenu").item("DtFullScreenItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtSettingsMenu"));
menus.addMenuPath(DtMenuPath::mainMenu("DtSettingsMenu").item("DtConnectionsMenuItem"));
//*********************************************************************
//The Help Menu.
//*********************************************************************
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtHelpItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").separator("1"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtAboutItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").separator("2"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtProductsWebSiteMenuItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtForumWebSiteMenuItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtVersionWebSiteMenuItem"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").separator("3"));
menus.addMenuPath(DtMenuPath::mainMenu("DtHelpMenu").item("DtErrorMessagesPage"));
//*********************************************************************
//The right object context menu.
//*********************************************************************
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtObjectInfoItem"));
menus.addMenuPathAfter(DtMenuPath::popupMenu("DtObjectContextMenu").separator("1"),
DtMenuPath::popupMenu("DtObjectContextMenu").item("DtObjectInfoItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtTransparencyToggleItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachTetherItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachFollowItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachMimicItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachTrackItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachTetherTrackItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachMimicTrackItem"));
menus.addMenuPathAfter(DtMenuPath::popupMenu("DtObjectContextMenu").separator("2"),
DtMenuPath::popupMenu("DtObjectContextMenu").item("DtAttachMimicTrackItem"));
menus.addMenuPath(DtMenuPath::popupMenu("DtObjectContextMenu").item("DtCreateInsetViewItem"));
return menus;
}
DtToolbarConfiguration createCustomToolbar()
{
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtSceneToolbar").item("DtNewSceneItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtSceneToolbar").item("DtOpenSceneItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").item("DtNewTerrainItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").item("DtOpenTerrainItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").item("DtCloseTerrainItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").separator("DtTerrainToolbarSeparator"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").item("DtAddTerrainPatchMenuItem"));
toolbars.addToolbarPath(DtToolbarPath::toolbar("DtTerrainToolbar").item("DtAddFeatureLayerItem"));
return toolbars;
}
void postPluginTransform(DtDeInitializer& initializer, DtDe& de, DtVrvApplicationConfiguration& appConfig)
{
// Setup the pages
appConfig.setMasterModePageConfiguration(createCustomPages());
// Setup the menus
appConfig.setMasterModeMenuConfiguration(createCustomMenu());
// Setup the toolbars
appConfig.setMasterModeToolbarConfiguration(createCustomToolbar());
}
int main(int argc,char** argv)
{
// Create a custom configuration for your GUI.
DtCustomConfiguration config;
// A DtVrvApplication wraps up all the components required to build a complete
// VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
// DtVrvApplicationConfiguration).
DtVrvApplication vrvApp(config);
// Create a functor to install into the application.
DtVrvApplication::ApplicationTransform functor = boost::bind(&postPluginTransform, _1, _2, _3);
// Install our application transform after the plug-ins are loaded and before the GUI is assembled.
vrvApp.installPostPluginTransform(functor, "postPluginTransform");
// Use the stealth's command line processor or create your own.
vrvApp.installCommandLineProcessor(&cmdLineProcessor);
// This causes the plug-in manager to load plug-ins, cause a Display Configuration
// to be realized, creates the default environment, etc.
vrvApp.initialize(argc, argv);
// Creates an event loop and begins running it, causing the creation of frames.
vrvApp.run();
}


Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)