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

This example builds on the symbol facade and driver created in exampleSymbolFacade1 , and shows additional steps that are necessary for created symbols to be selected and show a context menu when right-clicked.

In order for the symbols to accept mouse input, the facade's widget label must have events enabled.

// Enable events processing so symbols accept mouse input.
// In example 1, symbols could only be selected by clicking on them
// in the objects list pane. Enabling events for the widget label agent
// allows mouse click events on the symbol to select them, as well as
// allowing for the context menu to be shown on right-click.
myWidgetLabelAgent->setEventsEnabled( true );

Enabling events makes the symbol selectable and shows a context menu when the symbol is right-clicked, but the symbols themselves don't indicate that they've been selected. In order to listen for selection changes and keep the symbols up to date, the driver connects to the selection manager's 'selection changed' signal. The driver also disconnects from the signal when the driver stops.

// Listen for selection changes.
DtSelectionManager& selectionManager =
DtSelectionManager::instance( myAgentManager.de() );
selectionManager.signal_currentSelectionChanged.connect( boost::bind(
&DtExampleSymbolDriver::slot_currentSelectionChanged,
this, _1, _2, _3, _4 ) );

The slot slot_currentSelectionChanged makes newly selected symbols bigger and brighter, and sets deselected symbols back to the default color and size.

void DtExampleSymbolDriver::slot_currentSelectionChanged(
const DtSelectionManager::IdSet& selected,
const DtSelectionManager::IdSet& deselected,
DtSelectionManager::SelectionType newType,
DtSelectionManager::SelectionType oldType )
{
DtSelectionManager::IdSet::const_iterator i, e;
// Update selected symbols to indicate they're selected.
e = selected.end();
i = selected.begin();
for ( ; i != e; ++i )
{
SymbolFacadeMap::iterator itr = mySymbolFacades.find( *i );
if ( itr != mySymbolFacades.end() )
{
DtWidgetLabelAgent& label = itr->second->widgetLabelAgent();
label.setColor( 1.0f, 1.0f, 1.0f, 1.0f );
label.setSize( 36, 36 );
}
}
// Revert deselected symbols to the default (unselected) look.
e = deselected.end();
i = deselected.begin();
for ( ; i != e; ++i )
{
SymbolFacadeMap::iterator itr = mySymbolFacades.find( *i );
if ( itr != mySymbolFacades.end() )
{
DtWidgetLabelAgent& label = itr->second->widgetLabelAgent();
label.setColor( 0.8f, 0.8f, 0.8f, 1.0f );
label.setSize( 32, 32 );
}
}
}

[<< exampleSymbolFacade1] [Home] [Top of Page] [exampleSymbolFacade3 >>]


DtSymbolDriverToolbar2.h

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
namespace makVrv
{
class DtDe;
}
namespace makVrv
{
namespace exampleSymbolFacade2
{
class DT_DLL_EXAMPLESYMBOLFACADE2 DtSymbolDriverToolbar
{
public:
DtSymbolDriverToolbar( makVrv::DtDe& );
virtual ~DtSymbolDriverToolbar();
virtual QToolBar* createToolbar( makVrv::DtDe&, QWidget* parent );
};
class DT_DLL_EXAMPLESYMBOLFACADE2 DtAddSymbolItem : public makVrv::DtMenuItem
{
public:
DtAddSymbolItem( makVrv::DtDe& de );
virtual ~DtAddSymbolItem();
virtual QAction* createAction( makVrv::DtDe&, QWidget* parent );
virtual void on_triggered();
protected:
makVrv::DtDe& myDe;
};
}
}

DtSymbolDriverToolbar2.cxx

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
#include <QtGui/QToolBar>
#include <QtGui/QAction>
#include <matrix/vlVector.h>
#include <time.h>
#include <math.h>
namespace makVrv
{
namespace exampleSymbolFacade2
{
: DtToolbar( de, "DtSymbolDriverToolbar" )
{
}
DtSymbolDriverToolbar::~DtSymbolDriverToolbar()
{
}
QToolBar* DtSymbolDriverToolbar::createToolbar( DtDe&, QWidget* parent )
{
QToolBar* bar = new QToolBar( parent );
bar->setWindowTitle( QObject::tr("Symbol Driver Toolbar") );
bar->setObjectName( QObject::tr("Symbol Driver Toolbar") );
return bar;
}
DtAddSymbolItem::DtAddSymbolItem( DtDe& de )
: DtMenuItem( "DtAddSymbolItem" )
, myDe( de )
{
// Seed the random number generator.
srand( time(NULL ) );
}
DtAddSymbolItem::~DtAddSymbolItem()
{
}
QAction* DtAddSymbolItem::createAction( DtDe&, QWidget* parent )
{
QAction* act = new QAction( parent );
act->setText( DtMenuItem::tr("&Add new symbol...") );
act->setToolTip( DtMenuItem::tr("Create a new symbol...") );
act->setIcon( QIcon(QObject::tr("../data/Icons/UtilityAdd.svg")) );
return act;
}
void DtAddSymbolItem::on_triggered()
{
// Keep track of how many symbols have been created.
static int numSymbolsCreated = 0;
// Give the symbol a unique name.
DtString symbolName( "Symbol #" );
symbolName += DtString(numSymbolsCreated);
// Put the symbol somewhere random on the makland terrain.
double rand_x = 4000.0*((double)rand())/RAND_MAX;
double rand_y = 4000.0*((double)rand())/RAND_MAX;
double rand_z = 4000.0*((double)rand())/RAND_MAX;
DtVector location( rand_x, rand_y, rand_z );
// Get the driver and create the symbol
DtExampleSymbolDriver* symbolDriver = (DtExampleSymbolDriver*)
myDe.driverManager().findDriver( "DtExampleSymbolDriver" );
symbolDriver->createSymbol( symbolName.string(), location );
++numSymbolsCreated;
}
}
}

DtSymbolFacade2.h

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
#include <boost/signal.hpp>
class DtVector;
namespace makVrv
{
class DtSceneObjectAgent;
class DtWidgetLabelAgent;
class DtAgentManagerInterface;
class DtProjectedWidgetModelAgent;
}
namespace makVrv
{
namespace exampleSymbolFacade2
{
class DT_DLL_EXAMPLESYMBOLFACADE2 DtSymbolFacade
{
public:
DtSymbolFacade( makVrv::DtAgentManagerInterface& sceneInterface,
virtual ~DtSymbolFacade();
virtual makVrv::DtElementID elementId() const;
virtual makVrv::DtWidgetLabelAgent& widgetLabelAgent();
virtual void setPosition( const DtVector& pos );
protected:
// Sets up the sceneobject and widget agents.
// Non-virtual (Called from CTOR).
void initialize();
protected:
makVrv::DtElementID myElementId;
makVrv::DtSceneObjectAgent* mySceneObjectAgent;
makVrv::DtProjectedWidgetModelAgent* myProjectedWidgetModelAgent;
makVrv::DtWidgetLabelAgent* myWidgetLabelAgent;
};
}
}

DtSymbolFacade2.cxx

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vlutil/vlUtil.h>
namespace makVrv
{
namespace exampleSymbolFacade2
{
DtAgentManagerInterface& sceneInterface, DtElementID id )
: myElementId( id )
, mySceneObjectAgent( DtSceneObjectAgent::create(sceneInterface) )
, myProjectedWidgetModelAgent( DtProjectedWidgetModelAgent::create(sceneInterface) )
, myWidgetLabelAgent( DtWidgetLabelAgent::create(sceneInterface) )
{
initialize();
}
DtSymbolFacade::~DtSymbolFacade()
{
// Remove the widget label agent from the PWMA and delete it.
myProjectedWidgetModelAgent->removeWidget( myWidgetLabelAgent );
DtDELETE( myWidgetLabelAgent );
// Remove the PWMA from the scene object and delete it.
mySceneObjectAgent->removeModel( myProjectedWidgetModelAgent );
DtDELETE( myProjectedWidgetModelAgent );
// Delete the scene object now that everything's been removed from it.
DtDELETE( mySceneObjectAgent );
}
void DtSymbolFacade::initialize()
{
// Make sure the agents were fully created.
if ( ! mySceneObjectAgent ) DtTHROW_NEW( DtCorruptedState, "Unable to create scene object agent." );
if ( ! myProjectedWidgetModelAgent ) DtTHROW_NEW( DtCorruptedState, "Unable to create projected widget model agent." );
if ( ! myWidgetLabelAgent ) DtTHROW_NEW( DtCorruptedState, "Unable to create widget label agent." );
// Initialize the scene object
mySceneObjectAgent->setModelSet( 5 ); // PVD
mySceneObjectAgent->setElementID( myElementId );
mySceneObjectAgent->addModel( myProjectedWidgetModelAgent, DtStateVisualizer::EntityVisualizerType );
// Initialize the label
myWidgetLabelAgent->setOverlay( DtOverlayManager::ModelSet_2D_Icons_Overlay );
myWidgetLabelAgent->setBackgroundImage( "$(DATA_DIR)/images/ArrowCircle.png" );
myWidgetLabelAgent->setColor( 0.8f, 0.8f, 0.8f, 1.0f );
myWidgetLabelAgent->setSize( 32, 32 );
// Add the label to the projected widget model.
myProjectedWidgetModelAgent->addWidget( myWidgetLabelAgent );
// Enable events processing so symbols accept mouse input.
// In example 1, symbols could only be selected by clicking on them
// in the objects list pane. Enabling events for the widget label agent
// allows mouse click events on the symbol to select them, as well as
// allowing for the context menu to be shown on right-click.
myWidgetLabelAgent->setEventsEnabled( true );
}
DtUniqueID DtSymbolFacade::elementId() const
{
return myElementId;
}
DtWidgetLabelAgent& DtSymbolFacade::widgetLabelAgent()
{
return *myWidgetLabelAgent;
}
void DtSymbolFacade::setPosition( const DtVector& pos )
{
mySceneObjectAgent->setPosition( 0, pos );
}
// This is a static method that can be used to query what type of element
// DtSymbolFacades are. The returned value indicates whether the symbol
// is an entity, a prop, or a terrain (among other things).
// For this example we'll consider the symbol to be an entity.
DtElementEntry::ElementType DtSymbolFacade::elementType()
{
return DtElementEntry::Entity;
}
}
}

DtExampleSymbolDriver2.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
#include <boost/unordered_set.hpp>
class DtVector;
namespace makVrv
{
namespace exampleSymbolFacade2
{
class DtSymbolFacade;
class DT_DLL_EXAMPLESYMBOLFACADE2 DtExampleSymbolDriver
{
public:
DtExampleSymbolDriver( makVrv::DtAgentManager& am );
virtual ~DtExampleSymbolDriver();
virtual const std::string& className() const;
virtual bool onStart();
virtual bool onStop();
virtual bool onTick();
virtual DtSymbolFacade* createSymbol( const std::string& name,
const DtVector& pos );
virtual DtSymbolFacade* findSymbol( makVrv::DtElementID id );
protected:
virtual void positionSymbol( DtSymbolFacade* symbol, const DtVector& pos );
virtual void slot_currentSelectionChanged(
virtual void slot_displayEngineAdded( const makVrv::DtDeRecord& igRecord );
protected:
typedef boost::unordered_map<makVrv::DtElementID,DtSymbolFacade*> SymbolFacadeMap;
SymbolFacadeMap mySymbolFacades;
};
}
}

DtExampleSymbolDriver2.cxx

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
#include <matrix/vlVector.h>
namespace makVrv
{
namespace exampleSymbolFacade2
{
: makVrv::DtDriver( am, "DtExampleSymbolDriver" )
{
}
DtExampleSymbolDriver::~DtExampleSymbolDriver()
{
DtExampleSymbolDriver::onStop();
}
const std::string& DtExampleSymbolDriver::className() const
{
static std::string name = "DtExampleSymbolDriver";
return name;
}
bool DtExampleSymbolDriver::onStart()
{
// Load the Makland programatically.
DtScene& sceneDriver = myAgentManager.de().scene();
std::string maklandPath = myAgentManager.de().dePathConfiguration().userPath();
maklandPath += "/terrains/Makland.mtf";
sceneDriver.loadTerrain( maklandPath );
// Listen for selection changes.
DtSelectionManager& selectionManager =
DtSelectionManager::instance( myAgentManager.de() );
selectionManager.signal_currentSelectionChanged.connect( boost::bind(
&DtExampleSymbolDriver::slot_currentSelectionChanged,
this, _1, _2, _3, _4 ) );
return true;
}
bool DtExampleSymbolDriver::onStop()
{
// Stop listening for selection changes.
DtSelectionManager& selectionManager =
DtSelectionManager::instance( myAgentManager.de() );
selectionManager.signal_currentSelectionChanged.disconnect(
boost::bind( &DtExampleSymbolDriver::slot_currentSelectionChanged,
this, _1, _2, _3, _4 ) );
// Delete all created facades.
SymbolFacadeMap::iterator i = mySymbolFacades.begin();
SymbolFacadeMap::iterator e = mySymbolFacades.end();
for ( ; i != e; ++i )
{
delete i->second;
}
// Clear the list of facades.
mySymbolFacades.clear();
return true;
}
bool DtExampleSymbolDriver::onTick()
{
return true;
}
DtSymbolFacade* DtExampleSymbolDriver::createSymbol(
const std::string& name, const DtVector& pos )
{
// Create symbol.
DtElementID elementId = myAgentManager.createNewUniqueId();
DtSymbolFacade* symbol = new DtSymbolFacade( myAgentManager, elementId );
symbol->widgetLabelAgent().setColor( 0.8f, 0.8f, 0.8f, 1.0f );
symbol->widgetLabelAgent().setSize( 32, 32 );
// Store the symbol in the driver's symbol map.
mySymbolFacades.insert( std::make_pair(elementId,symbol) );
// Report that the symbol was created and report its name.
// These commands report to VR-Vantage that a new object has been created
// and that it should be managed as an object that may be visualized in various ways.
reportElementCreated( elementId, 0, DtSymbolFacade::elementType() );
reportElementAttribute( elementId, new DtElementAttributeDisplayName(name) );
// Position the symbol.
positionSymbol( symbol, pos );
return symbol;
}
DtSymbolFacade* DtExampleSymbolDriver::findSymbol( DtElementID symbolId )
{
SymbolFacadeMap::iterator itr = mySymbolFacades.find( symbolId );
if ( itr != mySymbolFacades.end() )
return itr->second;
return NULL;
}
void DtExampleSymbolDriver::positionSymbol(
DtSymbolFacade* symbol, const DtVector& pos )
{
// Initialize the coordinate converter with the position.
DtCoordinateConverter* coordConverter =
myAgentManager.de().sharedState().coordinateSystem().converter();
coordConverter->setupTopoFrame( pos );
// Convert the position (from ENU) to our local database (CIG) coordinate system.
DtVector position;
coordConverter->enuToCig_coordTrans( pos, position );
symbol->setPosition( position );
}
void DtExampleSymbolDriver::slot_currentSelectionChanged(
const DtSelectionManager::IdSet& selected,
const DtSelectionManager::IdSet& deselected,
DtSelectionManager::SelectionType newType,
DtSelectionManager::SelectionType oldType )
{
DtSelectionManager::IdSet::const_iterator i, e;
// Update selected symbols to indicate they're selected.
e = selected.end();
i = selected.begin();
for ( ; i != e; ++i )
{
SymbolFacadeMap::iterator itr = mySymbolFacades.find( *i );
if ( itr != mySymbolFacades.end() )
{
DtWidgetLabelAgent& label = itr->second->widgetLabelAgent();
label.setColor( 1.0f, 1.0f, 1.0f, 1.0f );
label.setSize( 36, 36 );
}
}
// Revert deselected symbols to the default (unselected) look.
e = deselected.end();
i = deselected.begin();
for ( ; i != e; ++i )
{
SymbolFacadeMap::iterator itr = mySymbolFacades.find( *i );
if ( itr != mySymbolFacades.end() )
{
DtWidgetLabelAgent& label = itr->second->widgetLabelAgent();
label.setColor( 0.8f, 0.8f, 0.8f, 1.0f );
label.setSize( 32, 32 );
}
}
}
void DtExampleSymbolDriver::slot_displayEngineAdded( const DtDeRecord& igRecord )
{
// When a new display engine is connected to our driver, the driver
// must be re-started in order to ensure the terrain and all symbols
// are properly loaded on all connected De's.
stop();
start();
}
}
}

exampleSymbolFacade2.cxx

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
// Use the VR-Vantage namespace.
// All classes in VR-Vantage are in this namespace.
using namespace makVrv;
using namespace makVrv::exampleSymbolFacade2;
bool initDeModule( DtDe* de )
{
// Setup the plug-in.
init( *de );
return true;
}
void init( DtDe& de )
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// Make sure that the vrvCoreQt and vrvOsgEarthQt module are init'ed.
// Don't show the startup dialog for selecting a terrain.
//Add example menu and example page item.
if ( igApp )
{
// Register the toolbar and MenuItems so they can be created where they're placed.
// Add the button to the toolbar.
DtToolbarPath::toolbar("DtSymbolDriverToolbar").item("DtAddSymbolItem") );
}
// We only want to create the driver if we are running in master mode.
if ( de.isInMasterMode() )
{
// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
}
}
void installDriver( DtDe& de )
{
// Create DtExampleDriver.
// The driver is now owned by the display engine. Do not delete it.
de.driverManager().addDriver( driver );
// Start the driver, creating the agent.
de.driverManager().startDriver( driver );
}

exampleSymbolFacade2.h

/*****************************************************************************
* Copyright (c) 2011 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
// Plugin export macro.
#ifdef _WIN32
# ifdef EXAMPLESYMBOLFACADE2_EXPORTS
# define DT_DLL_EXAMPLESYMBOLFACADE2 __declspec ( dllexport )
# else
# define DT_DLL_EXAMPLESYMBOLFACADE2 __declspec ( dllimport )
# endif
#else
# define DT_DLL_EXAMPLESYMBOLFACADE2
#endif
// Declare & export the plugin initialization function (bool initDeModule(DtDe* de))
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLESYMBOLFACADE2
// Plugin initialization methods.


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