This example demonstrates how to add symbols to the scene in a PVD application.
The example creates a DtSymbolFacade for creating and modifying symbols and uses a driver for scene setup and management of the created symbols. A toolbar is also created to signal the creation of new symbols. For more information on creating a driver, see exampleDriver .
The DtSymbolFacade class encapsulates the model agents used to display the symbol and provides an interface for communicating with them.
The DtSymbolFacade's constructor creates the model agents the facade will use to display symbols.
DtSymbolFacade::DtSymbolFacade(
DtAgentManagerInterface& sceneInterface,
DtElementID id )
: myElementId( id )
, mySceneObjectAgent( DtSceneObjectAgent::create(sceneInterface) )
, myProjectedWidgetModelAgent( DtProjectedWidgetModelAgent::create(sceneInterface) )
, myWidgetLabelAgent( DtWidgetLabelAgent::create(sceneInterface) )
{
initialize();
}
The initialize method then configures the model agents.
void DtSymbolFacade::initialize()
{
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." );
mySceneObjectAgent->setModelSet( 5 );
mySceneObjectAgent->setElementID( myElementId );
mySceneObjectAgent->addModel( myProjectedWidgetModelAgent, DtStateVisualizer::EntityVisualizerType );
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 );
myProjectedWidgetModelAgent->addWidget( myWidgetLabelAgent );
}
The symbol facade provides accessors for the component model agents and a method for positioning the symbol. The facade also has a method that returns the symbol's element type. This 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()
{
}
Symbols are created using a button on the GUI's toolbar. This button (DtAddSymbolItem) picks a random spot on the terrain and tells the driver (DtExampleSymbolDriver) to create a symbol at that location.
void DtAddSymbolItem::on_triggered()
{
static int numSymbolsCreated = 0;
symbolName +=
DtString(numSymbolsCreated);
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 );
DtExampleSymbolDriver* symbolDriver = (DtExampleSymbolDriver*)
myDe.driverManager().findDriver( "DtExampleSymbolDriver" );
symbolDriver->createSymbol( symbolName.string(), location );
++numSymbolsCreated;
}
The driver creates the symbol by instantiating a new DtSymbolFacade, creating a unique ID for the symbol, and signaling that the new 'element' (the symbol) has been created. The driver also stores the symbol for later use and provides a default color and size. Once the symbol has been created, the driver associates the symbol's name with its elementId and positions it in the scene.
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 );
mySymbolFacades.insert( std::make_pair(elementId,symbol) );
reportElementCreated( elementId, 0, DtSymbolFacade::elementType() );
positionSymbol( symbol, pos );
[Home] [Top of Page] [exampleSymbolFacade2 >>]
DtSymbolDriverToolbar1.h
#pragma once
namespace makVrv
{
class DtDe;
}
namespace makVrv
{
namespace exampleSymbolFacade1
{
{
public:
virtual ~DtSymbolDriverToolbar();
};
{
public:
virtual ~DtAddSymbolItem();
virtual void on_triggered();
protected:
};
}
}
DtSymbolDriverToolbar1.cxx
#include <QtWidgets/QToolBar>
#include <QtWidgets/QAction>
#include <matrix/vlVector.h>
#include <time.h>
#include <math.h>
namespace makVrv
{
namespace exampleSymbolFacade1
{
: DtToolbar( de, "DtSymbolDriverToolbar" )
{
}
DtSymbolDriverToolbar::~DtSymbolDriverToolbar()
{
}
QToolBar* DtSymbolDriverToolbar::createToolbar( DtDe&, QWidget* 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 )
{
srand( time(NULL ) );
}
DtAddSymbolItem::~DtAddSymbolItem()
{
}
QAction* DtAddSymbolItem::createAction( DtDe&, QWidget* 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()
{
static int numSymbolsCreated = 0;
symbolName +=
DtString(numSymbolsCreated);
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 );
DtExampleSymbolDriver* symbolDriver = (DtExampleSymbolDriver*)
myDe.driverManager().findDriver( "DtExampleSymbolDriver" );
symbolDriver->createSymbol( symbolName.string(), location );
++numSymbolsCreated;
}
}
}
DtSymbolFacade1.h
#pragma once
#include <boost/signal.hpp>
#include <matrix/vlVector.h>
namespace makVrv
{
class DtSceneObjectAgent;
class DtWidgetLabelAgent;
class DtAgentManagerInterface;
class DtProjectedWidgetModelAgent;
}
namespace makVrv
{
namespace exampleSymbolFacade1
{
{
public:
virtual ~DtSymbolFacade();
virtual makVrv::DtWidgetLabelAgent& widgetLabelAgent();
virtual void setPosition(
const DtVector& pos );
protected:
void initialize();
protected:
makVrv::DtSceneObjectAgent* mySceneObjectAgent;
makVrv::DtProjectedWidgetModelAgent* myProjectedWidgetModelAgent;
makVrv::DtWidgetLabelAgent* myWidgetLabelAgent;
};
}
}
DtSymbolFacade1.cxx
#include <vrvCore/DtProjectedWidgetModelAgent.hpp>
#include <vrvCore/DtWidgetLabelAgent.hpp>
#include <vrvCore/DtSceneObjectAgent.hpp>
#include <vlutil/vlUtil.h>
namespace makVrv
{
namespace exampleSymbolFacade1
{
DtAgentManagerInterface& sceneInterface,
DtElementID id )
: myElementId( id )
, mySceneObjectAgent( DtSceneObjectAgent::create(sceneInterface) )
, myProjectedWidgetModelAgent( DtProjectedWidgetModelAgent::create(sceneInterface) )
, myWidgetLabelAgent( DtWidgetLabelAgent::create(sceneInterface) )
{
initialize();
}
DtSymbolFacade::~DtSymbolFacade()
{
myProjectedWidgetModelAgent->removeWidget( myWidgetLabelAgent );
DtDELETE( myWidgetLabelAgent );
mySceneObjectAgent->removeModel( myProjectedWidgetModelAgent );
DtDELETE( myProjectedWidgetModelAgent );
DtDELETE( mySceneObjectAgent );
}
void DtSymbolFacade::initialize()
{
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." );
mySceneObjectAgent->setModelSet( 5 );
mySceneObjectAgent->setElementID( myElementId );
mySceneObjectAgent->addModel( myProjectedWidgetModelAgent, DtStateVisualizer::EntityVisualizerType );
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 );
myProjectedWidgetModelAgent->addWidget( myWidgetLabelAgent );
}
{
return myElementId;
}
DtWidgetLabelAgent& DtSymbolFacade::widgetLabelAgent()
{
return *myWidgetLabelAgent;
}
void DtSymbolFacade::setPosition(
const DtVector& pos )
{
mySceneObjectAgent->setPosition( 0, pos );
}
DtElementEntry::ElementType DtSymbolFacade::elementType()
{
}
}
}
DtExampleSymbolDriver1.h
#pragma once
#include <boost/unordered_set.hpp>
#include <matrix/vlVector.h>
namespace makVrv
{
namespace exampleSymbolFacade1
{
class DtSymbolFacade;
{
public:
virtual ~DtExampleSymbolDriver();
virtual const std::string& className() const;
virtual bool onStart();
virtual bool onStop();
virtual bool onTick();
virtual DtSymbolFacade* createSymbol( const std::string& name,
protected:
virtual void positionSymbol( DtSymbolFacade* symbol,
const DtVector& pos );
protected:
typedef boost::unordered_map<makVrv::DtElementID,DtSymbolFacade*> SymbolFacadeMap;
SymbolFacadeMap mySymbolFacades;
};
}
}
DtExampleSymbolDriver1.cxx
#include <vrvCore/DtWidgetAgent.hpp>
#include <vrvCore/DtWidgetLabelAgent.hpp>
#include <vrvCore/DtSceneObjectAgent.hpp>
#include <vrvCore/DtProjectedWidgetModelAgent.hpp>
#include <matrix/vlVector.h>
namespace makVrv
{
namespace exampleSymbolFacade1
{
: makVrv::DtDriver( am, "DtExampleSymbolDriver" )
{
}
DtExampleSymbolDriver::~DtExampleSymbolDriver()
{
DtExampleSymbolDriver::onStop();
}
const std::string& DtExampleSymbolDriver::className() const
{
static std::string name = "DtExampleSymbolDriver";
return name;
}
bool DtExampleSymbolDriver::onStart()
{
DtScene& sceneDriver = myAgentManager.de().scene();
std::string maklandPath = myAgentManager.de().dePathConfiguration().userPath();
maklandPath += "/terrains/Makland.mtf";
return true;
}
bool DtExampleSymbolDriver::onStop()
{
SymbolFacadeMap::iterator i = mySymbolFacades.begin();
SymbolFacadeMap::iterator e = mySymbolFacades.end();
for ( ; i != e; ++i )
{
delete i->second;
}
mySymbolFacades.clear();
return true;
}
bool DtExampleSymbolDriver::onTick()
{
return true;
}
DtSymbolFacade* DtExampleSymbolDriver::createSymbol(
const std::string& name,
const DtVector& pos )
{
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 );
mySymbolFacades.insert( std::make_pair(elementId,symbol) );
reportElementCreated( elementId, 0, DtSymbolFacade::elementType() );
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 )
{
DtCoordinateConverter* coordConverter =
myAgentManager.de().sharedState().coordinateSystem().converter();
coordConverter->enuToCig_coordTrans( pos, position );
symbol->setPosition( position );
}
void DtExampleSymbolDriver::slot_displayEngineAdded( const DtDeRecord& igRecord )
{
stop();
start();
}
}
}
exampleSymbolFacade1.cxx
using namespace makVrv;
using namespace makVrv::exampleSymbolFacade1;
{
return true;
}
{
if ( igApp )
{
}
{
}
}
{
}
exampleSymbolFacade1.h
#pragma once
#ifdef _WIN32
# ifdef EXAMPLESYMBOLFACADE1_EXPORTS
# define DT_DLL_EXAMPLESYMBOLFACADE1 __declspec ( dllexport )
# else
# define DT_DLL_EXAMPLESYMBOLFACADE1 __declspec ( dllimport )
# endif
#else
# define DT_DLL_EXAMPLESYMBOLFACADE1
#endif
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLESYMBOLFACADE1