This example shows how to create a your own QT application with a Main Window that has a VR-Vantage view embedded into it. It also adds a dockable widget with a second embedded view (and its own independent observer). Finally, it adds some standard VR-Vantage GUI elements, including a File Menu, and File Toolbar.
The main window class owns some key VR-Vantage objects. It owns a DtDe (display engine) which is the core component for adding visualization to any application. It also owns a DtPluginManager which is responsible for loading all the VR-Vantage plug-ins.
The OpenGL graphics context needs to be owned and managed by the QT main window. We connect it the VR-Vantage display engine (and consequently OSG) via the DtOsgAdapterQtWidget. We use a second DtOsgAdapterWidget to embed the display engine into the dock widget.
The main window also owns some QT widgets for menus and toolbars.
The real work begins in the constructor of the main window.
First, set up the display engine configuration and initializer.
Create observer configurations for the main window and docked window and include them in the input driver configuration, and add the input driver configuration to the display engine initializer.
Create a window configuration for each window, specifying the observer for each.
Create, intialize, and provide the display configuration to the display engine.
Finally, create a plug-in manager, and then initialize and load the plug-ins.
Now we create the GUI. The interesting thing here is the DtQtIgTickerProvider. This provides us with a "ticker" that ticks the display engine as fast as the QT GUI will go. The rest of the function just sets up menus, toolbars, and the other things that would be part of this application.
During the call to preDisplayEngineInitialize(), we override the functionality set up by plug-ins. We want to create a DtEmbeddedOsgWindow that uses a DtOsgAdapterQtWidget for its graphic context and we do that by installing a new creator with the DtWindowFactory.
This example is an application. You can run it by running ./bin64/exampleEmbedded.exe (on Windows) or ./bin64/exampleEmbedded (on Linux). For more information about running examples, please see Running Applications and Examples.
#include <QtWidgets/QApplication>
#include <QtWidgets/QtWidgets>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <vlutil/vlLogFileInfo.h>
, myPluginManager(0)
, myDe(0)
, myMainOSGWidget(0)
, myMiniOsgWidget(0)
{
createDisplayEngine(argc, argv);
buildGui();
preDisplayEngineInitialize();
initializeDisplayEngine();
postDisplayEngineInitialize();
}
{
{
}
{
}
}
{
}
{
DtDeConfiguration deConfig;
DtStealthCommandLineProcessor commandLineProcessor;
DtDePathConfiguration pathConfiguration;
pathConfiguration.
setFactoryPath(
"$(FACTORY_ROOT_DIR)/settings/stealth");
init.setPathConfiguration(pathConfiguration);
std::string displayName = DtDisplayConfiguration::DefaultDisplayString;
displayName += " 1";
init.setDeMode(DtDeInitializer::MasterMode);
init.setDisplayEngineName(displayName);
makVrv::DtObserverConfiguration observerConfig("Observer 1");
makVrv::DtObserverConfiguration observerConfig2("Observer 2");
makVrv::DtInputDriverConfiguration inputConfig;
init.setInputDriverConfiguration(inputConfig);
wName += " 1";
DtWindowConfiguration wc(wName);
cName += " 1";
DtChannelConfiguration cc(cName);
cc.setObserverName("Observer 1");
DtDisplayConfiguration dec(displayName);
wc.setWindowType(DtWindowConfiguration::EmbeddedWindow);
wc.channelConfigurations().add(cc);
wName2 += " 2";
DtWindowConfiguration wc2(wName2);
cName2 += " 2";
DtChannelConfiguration cc2(cName2);
cc2.setObserverName("Observer 2");
wc2.setWindowType(DtWindowConfiguration::EmbeddedWindow);
wc2.channelConfigurations().add(cc2);
dec.windowConfigurations().add(wc);
dec.windowConfigurations().add(wc2);
DtLogFileInfo::instance().setAppName( "ExampleEmbeddedMainWindow" );
DtLogFileInfo::instance().setProtocol( DT_PROTOCOL_SHORT_NAME );
DtLogFileInfo::instance().setSvnRev(
SVN_REV );
init.setLogFileName( DtLogFileInfo::instance().getLogFileName() );
init.setDeConfiguration(deConfig);
myDe->createDebugLog(
init.logFileName(),
init.notifyLevel());
#ifndef _WIN32
myConfiguration.excludePluginFile(
"../plugins64/release/libvrvDiGuyPlugin.so");
#endif
myConfiguration.addPluginFile(
"..\\examples\\plugins\\exampleDisConnection.dll");
}
{
DtWindowFactory::instance(*myDe).setCreator(
DtWindowConfiguration::EmbeddedWindow,
new ExampleEmbeddedMainWindowViewCreator(this));
DtQApplicationProvider::instance(*myDe).setQAppInstance(qApp);
DtDeMainWindowProvider::registerInstance(*
myDe, NULL);
}
{
DtQtDeTickerProvider& tickerProvider = DtQtDeTickerProvider::instance(*
myDe);
setWindowTitle(tr("Embedded Example"));
setWindowIcon(QIcon(":/images/Mak-de.png"));
}
{
}
{
DtSelectionManager& selectMgr = DtSelectionManager::instance(*
myDe);
}
{
if (!selected.empty())
{
DtSelectionManager::IdSet::const_iterator idIter = selected.begin();
std::string nameStr;
if (
myDe->dataBank().elementData().attributeManager().elementType(selId) == DtElementEntry::Entity)
{
myDe->dataBank().elementData().attributeManager().getElementDisplayName(selId, nameStr);
DtSensorFieldOfViewManager& fovMgr = DtSensorFieldOfViewManager::instance(*
myDe);
const DtSensorFieldOfViewManager::SensorFieldOfViewDataMap* fieldsOfView =
if (fieldsOfView)
{
std::cout << nameStr << " has " << fieldsOfView->size() << " sensor(s)" << std::endl;
}
else
{
std::cout << nameStr << " has no sensors" << std::endl;
}
}
}
}
{
event->accept();
}
{
DtEmbeddedOsgWindow* pWindow = 0;
DtOsgAdapterQtWidget* pAdapter = 0;
osg::GraphicsContext* sharedContext = 0;
{
if (windows.size() > 0)
{
DtOsgWindow* osgView = dynamic_cast<DtOsgWindow*>(windows.front());
if (osgView)
{
}
}
}
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
traits->sharedContext = sharedContext;
traits->vsync = deInit.
vsync();
if (level == 2 || level == 4 || level == 8 || level == 16 || level == 32)
{
traits->sampleBuffers = 1;
}
else
{
traits->sampleBuffers = 0;
traits->samples = 0;
}
if (wc.
name() ==
"Window 1")
{
DtOsgAdapterQtWidgetCreator::instance(de).create(de, traits.get(),
DtOsgAdapterQtWidget::createFormatFromTraits(traits.get()),
myWindow, 0);
}
else if (wc.
name() ==
"Window 2")
{
DtOsgAdapterQtWidgetCreator::instance(de).create(de, traits.get(),
DtOsgAdapterQtWidget::createFormatFromTraits(traits.get()),
myWindow, 0);
QDockWidget* dockMini =
new QDockWidget(
"Mini Widget",
myWindow);
dockMini->setWidget(
myWindow->myMiniOsgWidget);
myWindow->addDockWidget(Qt::LeftDockWidgetArea, dockMini, Qt::Vertical);
}
if (pAdapter)
{
pWindow = new DtEmbeddedOsgWindow(de, wc, pAdapter);
if (pWindow)
{
}
}
return pWindow;
}
{
QString terrainDir =
myDe->dePathConfiguration().dataPath().c_str();
terrainDir += "//Terrain";
QString filename =
DtStaticFileDialog::getOpenFileName(*
myDe,
this, tr(
"Open File"), terrainDir,
tr(
"All Readable Data Types (*medf *.dt0 *.dt1 *.dt2 *.dted *.flt *.3ds *.osg *.lwo *.obj *.txp);;" \
"MAK Terrain Database (*.mtf);;" \
"MAK Encrypted Data Format (*.medf);;" \
"DTED (*.dt0 *.dt1 *.dt2 *.dted);;" \
"OpenFlight (*.flt);;" \
"Terrapage (*.txp);;" \
"Other 3D Formats (*.3ds *.osg *.lwo *.obj);;" \
"All (*.*);;"
));
if (!filename.isEmpty())
{
QDir dir;
QString relativePath = dir.relativeFilePath(filename);
std::string modelPath = relativePath.toStdString();
DtModelDefinition modelDef(modelPath);
modelDef.setParameter("filename", modelPath);
myDe->sharedState().addModelDefinition(modelDef);
myDe->scene().terrain().addTerrainPatch(modelDef.name());
}
}
{
myDe->scene().resetScene();
}
{
myOpenAction =
new QAction(QIcon(
":/images/open.png"), tr(
"&Open..."),
this);
myCloseAction =
new QAction(QIcon(
":/images/close.png"), tr(
"&Close"),
this);
myExitAction =
new QAction(QIcon(
":/images/exit.png"), tr(
"E&xit"),
this);
connect(
myExitAction, SIGNAL(triggered()),
this, SLOT(close()));
}
{
myFileMenu = this->menuBar()->addMenu(tr(
"&File"));
}
{
}
{
this->statusBar()->showMessage(tr("Ready"));
}
Contains makVrv::DtDataBank class.
Contains makVrv::DtDeSharedState class.
Contains the DtElementAttributeManager class declaration.
Contains makVrv::DtElementData class.
Contains makVrv::DtEmbeddedOsgWindow class.
Contains makVrv::DtEventLoop class.
Interaction makVrv::DtModelDefinition class.
Contains makVrv::DtQApplicationProvider class.
Contains makVrv::DtQtDeMainWindow class.
Contains makVrv::DtQtDeTicker class.
Contains makVrv::DtScene class.
Contains makVrv::DtSceneDriver class.
Contains makVrv::DtSensorFieldOfViewManager class.
Contains makVrv::DtStaticFileDialog class.
Contains makVrv::DtStealthCommandLineProcessor class.
Contains makVrv::DtTerrain class.
Contains makVrv::DtTerrainPatch class.
Contains makVrv::DtViewFactory class.
Contains makVrv::DtWindowManager class.
static const char * DefaultChannelString
Definition DtChannelConfiguration.h:31
virtual ConfigurationType & add(const ConfigurationType &orig)
Add a Channel configuration.
Definition DtConfigurationCollection.h:68
virtual void setOptionalParameter(const std::string &name, const std::string &value)
Set an optional parameter.
virtual const std::string & name() const
Get the configuration name.
virtual DT_DECLARE_serialize_FUNCTIONS DtDisplayConfigurations & displayConfigurations()
Declare serialize functions Call via serialize(Archive ar, unsigned int version); Where Archive can b...
virtual DtDisplay * display()
DtDisplay accessor. The returned pointer will be NULL before initialize is called,...
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
unsigned short numStencilBits() const
unsigned short numDepthBits() const
bool doubleBuffer() const
@ Features_Stealth
Definition DtDeInitializer.h:59
unsigned short antiAliasingLevel() const
virtual void setSettingsPath(const std::string &path)
Setters.
virtual void setFactoryPath(const std::string &path)
Setters.
virtual DtWindowManager & windowManager()
DtWindowManager accessor.
virtual osg::GraphicsContext * graphicsContext()
Get the OSG Graphics Context for the window.
virtual DtQtDeTicker * ticker(QObject *parent)
boost::signalslib::signal< void(const IdSet &selected, const IdSet &deselected, SelectionType newType, SelectionType oldType)> signal_currentSelectionChanged
Emited when the current selection changes.
Definition DtSelectionManager.h:182
const SensorFieldOfViewDataMap * fieldsOfViewForEntity(DtElementID entity) const
Returns data for all sensor fields of view hosted by the specified entity.
virtual void processCommandLine(DtVrvApplicationConfiguration &appConfig, int argc, char **argv)
Parse the command line and modify the appConfig accordingly.
Definition DtStealthCommandLineProcessor.inl:558
static const char * DefaultWindowString
Definition DtWindowConfiguration.h:31
virtual WindowList & windows()
Get the window list.
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains necessary ig version information.
#define VANTAGE_VERSION_STRING
Definition igVersion.h:12
DT_DLL_VRVCORE DtTaitBryan level(const DtCoordinateSystem &cs, const DtVector &localOrigin, double topoHeading)
Returns a level orientation with the topographic heading.
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtUniqueID DtElementID
Definition DtUniqueID.h:23
#define SVN_REV
Definition svnRev.h:1
Contains DLL export macros.
Contains DLL export macros.