Ok. Posted more of the code. Constructor create
MainWindow
::MainWindow( osgViewer
::ViewerBase::ThreadingModel threadingModel
) : QMainWindow(){
setThreadingModel(threadingModel);
//QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("/home/hallmw/Downloads/gwaldron-osgearth-6bc5b12/tests/boston.earth") );
// Read in the file and create our m_mapNode
osg::Node* node = osgDB::readNodeFile("Data/bmng.earth");
m_mapNode = MapNode::findMapNode(node);
// Create our widget to view our scene.
QWidget* widget1
= addViewWidget
( createCamera
(0,
0,
100,
100), node
);
infoLabel
= new QLabel("Right",
this);
infoLabel
->setFrameStyle
(QFrame::Panel|QFrame
::Sunken);
m_latlongStatus
= new QLabel("Middle",
this);
m_latlongStatus
->setFrameStyle
(QFrame::Panel|QFrame
::Sunken);
// Sets the central widget to the widget we created
setCentralWidget(widget1);
// Create our actions
createActions();
// Create our Menus
createMenus();
// Create the status bar
createStatusBar();
//updateStatusBar();
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}
QWidget* MainWindow
::addViewWidget( osg
::Camera* camera, osg
::Node* scene
) {
mouseUtil = new MouseCoordsUtility(m_mapNode, m_latlongStatus);
osgViewer::View* view = new osgViewer::View;
view->setCamera( camera );
addView(view);
view->setSceneData( scene );
view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler(mouseUtil);
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
return gw ? gw->getGLWidget() : NULL;
}
// Creates the status bar for the application.
void MainWindow::createStatusBar()
{
statusBar()->addWidget(infoLabel,1);
statusBar()->addWidget(m_latlongStatus,2);
}
MainWindow::MainWindow( osgViewer::ViewerBase::ThreadingModel threadingModel ) : QMainWindow()
{
setThreadingModel(threadingModel);
//QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("/home/hallmw/Downloads/gwaldron-osgearth-6bc5b12/tests/boston.earth") );
// Read in the file and create our m_mapNode
osg::Node* node = osgDB::readNodeFile("Data/bmng.earth");
m_mapNode = MapNode::findMapNode(node);
// Create our widget to view our scene.
QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), node);
infoLabel = new QLabel("Right", this);
infoLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
m_latlongStatus = new QLabel("Middle", this);
m_latlongStatus->setFrameStyle(QFrame::Panel|QFrame::Sunken);
// Sets the central widget to the widget we created
setCentralWidget(widget1);
// Create our actions
createActions();
// Create our Menus
createMenus();
// Create the status bar
createStatusBar();
//updateStatusBar();
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}
QWidget* MainWindow::addViewWidget( osg::Camera* camera, osg::Node* scene )
{
mouseUtil = new MouseCoordsUtility(m_mapNode, m_latlongStatus);
osgViewer::View* view = new osgViewer::View;
view->setCamera( camera );
addView(view);
view->setSceneData( scene );
view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler(mouseUtil);
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
return gw ? gw->getGLWidget() : NULL;
}
// Creates the status bar for the application.
void MainWindow::createStatusBar()
{
statusBar()->addWidget(infoLabel,1);
statusBar()->addWidget(m_latlongStatus,2);
}
To copy to clipboard, switch view to plain text mode
MouseCoordsUtilLabelCallback
::MouseCoordsUtilLabelCallback(QLabel* statusbar, Formatter
* formatter
){
m_label = statusbar;
m_formatter = formatter;
if(!formatter)
{
m_formatter = new LatLongFormatter(LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS);
}
}
bool
MouseCoordsUtility::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
{
osg::Vec3d world;
if ( m_mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world) )
{
GeoPoint map;
map.fromWorld( m_mapNode->getMapSRS(), world );
for( Callbacks::iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i )
i->get()->set( map, aa.asView(), m_mapNode );
}
else
{
for( Callbacks::iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i )
i->get()->reset( aa.asView(), m_mapNode );
}
}
return false;
}
void MouseCoordsUtilLabelCallback::set(const GeoPoint& mapCoords,osg::View* view, MapNode* mapNode)
{
if(m_label)
{
std::string result;
result = osgEarth::Stringify() << m_formatter->format(mapCoords) << ", " << mapCoords.z();
//result = "This is a test.";
//m_label->showMessage(QString(result.c_str()));
m_label
->setText
(QString(result.
c_str()));
}
}
MouseCoordsUtilLabelCallback::MouseCoordsUtilLabelCallback(QLabel* statusbar, Formatter* formatter)
{
m_label = statusbar;
m_formatter = formatter;
if(!formatter)
{
m_formatter = new LatLongFormatter(LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS);
}
}
bool
MouseCoordsUtility::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
{
osg::Vec3d world;
if ( m_mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world) )
{
GeoPoint map;
map.fromWorld( m_mapNode->getMapSRS(), world );
for( Callbacks::iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i )
i->get()->set( map, aa.asView(), m_mapNode );
}
else
{
for( Callbacks::iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i )
i->get()->reset( aa.asView(), m_mapNode );
}
}
return false;
}
void MouseCoordsUtilLabelCallback::set(const GeoPoint& mapCoords,osg::View* view, MapNode* mapNode)
{
if(m_label)
{
std::string result;
result = osgEarth::Stringify() << m_formatter->format(mapCoords) << ", " << mapCoords.z();
//result = "This is a test.";
//m_label->showMessage(QString(result.c_str()));
m_label->setText(QString(result.c_str()));
}
}
To copy to clipboard, switch view to plain text mode
The two labels are created in the constructor. They are added to the statusbar in createStatusBar.
Bookmarks