Skip to content

Commit 481e0ea

Browse files
mbernasocchipka
authored andcommitted
- added support for globe coordinates, they are now shown in the status bar. - added modkey support
1 parent 9bca3a7 commit 481e0ea

File tree

4 files changed

+121
-12
lines changed

4 files changed

+121
-12
lines changed

src/plugins/globe/globe_plugin.cpp

+80-10
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ void GlobePlugin::initGui()
117117
SLOT( blankProjectReady() ) );
118118
connect( &mQDockWidget, SIGNAL( globeClosed() ), this,
119119
SLOT( setGlobeNotRunning() ) );
120+
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
121+
mQGisIface->mainWindow(), SLOT( showMouseCoordinate( const QgsPoint & ) ) );
122+
// connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
123+
// this, SLOT( showSelectedCoordinates() ) );
124+
120125
}
121126

122127
void GlobePlugin::run()
@@ -351,16 +356,80 @@ bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct
351356

352357
bool QueryCoordinatesHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
353358
{
354-
if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH )
359+
if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
360+
{
361+
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
362+
osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view );
363+
mGlobe->showCurrentCoordinates( coords.x(), coords.y() );
364+
}
365+
if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH
366+
&& ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
355367
{
356368
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
357-
getCoords( ea.getX(), ea.getY(), view );
369+
osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view );
370+
371+
OE_NOTICE << "Lon: " << coords.x() << " Lat: " << coords.y()
372+
<< " Ele: " << coords.z() << std::endl;
373+
374+
mGlobe->setSelectedCoordinates( coords );
375+
376+
if (ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL)
377+
{
378+
mGlobe->showSelectedCoordinates();
379+
}
358380
}
359381

360382
return false;
361383
}
362384

363-
void QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view )
385+
void GlobePlugin::showCurrentCoordinates(double lon, double lat)
386+
{
387+
// show x y on status bar
388+
OE_NOTICE << "lon: " << lon << " lat: " << lat <<std::endl;
389+
QgsPoint coord = QgsPoint( lon, lat );
390+
emit xyCoordinates( coord );
391+
}
392+
393+
void GlobePlugin::setSelectedCoordinates( osg::Vec3d coords)
394+
{
395+
mSelectedLon = coords.x();
396+
mSelectedLat = coords.y();
397+
mSelectedElevation = coords.z();
398+
}
399+
400+
osg::Vec3d GlobePlugin::getSelectedCoordinates()
401+
{
402+
osg::Vec3d coords = osg::Vec3d(mSelectedLon, mSelectedLat, mSelectedElevation);
403+
return coords;
404+
}
405+
406+
void GlobePlugin::showSelectedCoordinates()
407+
{
408+
QString lon, lat, elevation;
409+
lon.setNum(mSelectedLon);
410+
lat.setNum(mSelectedLat);
411+
elevation.setNum(mSelectedElevation);
412+
QMessageBox m;
413+
m.setText("selected coordinates are:\nlon: " + lon + "\nlat: " + lat + "\nelevation: " + elevation);
414+
m.exec();
415+
}
416+
417+
double GlobePlugin::getSelectedLon()
418+
{
419+
return mSelectedLon;
420+
}
421+
422+
double GlobePlugin::getSelectedLat()
423+
{
424+
return mSelectedLat;
425+
}
426+
427+
double GlobePlugin::getSelectedElevation()
428+
{
429+
return mSelectedElevation;
430+
}
431+
432+
osg::Vec3d QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view )
364433
{
365434
osgUtil::LineSegmentIntersector::Intersections results;
366435
if ( view->computeIntersections( x, y, results, 0x01 ) )
@@ -374,30 +443,31 @@ void QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view
374443
_mapSRS->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height );
375444

376445
// query the elevation at the map point:
377-
double lat_deg = osg::RadiansToDegrees( lat_rad );
378446
double lon_deg = osg::RadiansToDegrees( lon_rad );
447+
double lat_deg = osg::RadiansToDegrees( lat_rad );
448+
double elevation = 0.0;
379449

380-
OE_NOTICE << "coords at " << lat_deg << ", " << lon_deg << std::endl ;
381-
382-
/* osg::Matrixd out_mat;
450+
/*TODO IMPLEMENT ELEVATION
451+
osg::Matrixd out_mat;
383452
double query_resolution = 0.1; // 1/10th of a degree
384-
double out_elevation = 0.0;
385453
double out_resolution = 0.0;
386454
387455
if ( _elevMan->getPlacementMatrix(
388456
lon_deg, lat_deg, 0,
389457
query_resolution, NULL,
390-
out_mat, out_elevation, out_resolution ) )
458+
out_mat, elevation, out_resolution ) )
391459
{
392460
OE_NOTICE << "Elevation at " << lat_deg << ", " << lon_deg
393-
<< " is " << out_elevation << std::endl;
461+
<< " is " << elevation << std::endl;
394462
}
395463
else
396464
{
397465
OE_NOTICE
398466
<< "getElevation FAILED! at (" << lat_deg << ", " << lon_deg << ")" << std::endl;
399467
}
400468
*/
469+
osg::Vec3d coords = osg::Vec3d(lon_deg, lat_deg, elevation);
470+
return coords;
401471
}
402472
}
403473

src/plugins/globe/globe_plugin.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class GlobePlugin : public QObject, public QgisPlugin
5656
//! show the help document
5757
void help();
5858

59-
6059
//! Called when the main canvas is about to be rendered
6160
void renderStarting();
6261
//! Called when the main canvas has rendered.
@@ -68,9 +67,27 @@ class GlobePlugin : public QObject, public QgisPlugin
6867
//! Sync globe extent to mapCanavas
6968
void syncExtent();
7069

70+
//! called when a project has been read succesfully
7171
void projectReady();
72+
//! called when a new project has been created succesfully
7273
void blankProjectReady();
74+
//! called when the globe window is closed
7375
void setGlobeNotRunning();
76+
//! set the globe coordinates of a user right-click on the globe
77+
void setSelectedCoordinates( osg::Vec3d coords );
78+
//! get a coordinates vector
79+
osg::Vec3d getSelectedCoordinates();
80+
//! prints the ccordinates in a QMessageBox
81+
void showSelectedCoordinates();
82+
//! emits signal with current mouse coordinates
83+
void showCurrentCoordinates(double lon, double lat);
84+
//! get longitude of user right click
85+
double getSelectedLon();
86+
//! get latitude of user right click
87+
double getSelectedLat();
88+
//! get elevation of user right click
89+
double getSelectedElevation();
90+
7491

7592
//! Place an OSG model on the globe
7693
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );
@@ -116,6 +133,13 @@ class GlobePlugin : public QObject, public QgisPlugin
116133
osgEarthUtil::ObjectPlacer* mObjectPlacer;
117134
//! tracks if the globe is open
118135
bool mIsGlobeRunning;
136+
//! coordinates of the right-clicked point on the globe
137+
double mSelectedLat, mSelectedLon, mSelectedElevation;
138+
139+
signals:
140+
//! emits current mouse position
141+
//TODO connect to this signal at qgisapp.cpp:1952
142+
void xyCoordinates( const QgsPoint & p );
119143
};
120144

121145
class FlyToExtentHandler : public osgGA::GUIEventHandler
@@ -138,7 +162,7 @@ class QueryCoordinatesHandler : public osgGA::GUIEventHandler
138162

139163
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
140164

141-
virtual void getCoords( float x, float y, osgViewer::View* view );
165+
virtual osg::Vec3d getCoords( float x, float y, osgViewer::View* view );
142166

143167
private:
144168
GlobePlugin* mGlobe;

src/plugins/globe/qgsosgviewer.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void QgsGLWidgetAdapter::keyReleaseEvent( QKeyEvent* event )
6666

6767
void QgsGLWidgetAdapter::mousePressEvent( QMouseEvent* event )
6868
{
69+
adaptModifiers( event );
6970
int button = 0;
7071
switch(event->button())
7172
{
@@ -78,6 +79,18 @@ void QgsGLWidgetAdapter::mousePressEvent( QMouseEvent* event )
7879
_gw->getEventQueue()->mouseButtonPress(event->x(), event->y(), button);
7980
}
8081

82+
void QgsGLWidgetAdapter::adaptModifiers( QInputEvent* event )
83+
{
84+
int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier);
85+
86+
unsigned int modkeyosg = 0;
87+
if (modkey & Qt::ShiftModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_SHIFT;
88+
if (modkey & Qt::ControlModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_CTRL;
89+
if (modkey & Qt::AltModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_ALT;
90+
91+
_gw->getEventQueue()->getCurrentEventState()->setModKeyMask( modkeyosg );
92+
}
93+
8194
void QgsGLWidgetAdapter::mouseReleaseEvent( QMouseEvent* event )
8295
{
8396
int button = 0;

src/plugins/globe/qgsosgviewer.h

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class QgsGLWidgetAdapter : public QGLWidget
6464
virtual void resizeGL( int width, int height );
6565
virtual void keyPressEvent( QKeyEvent* event );
6666
virtual void keyReleaseEvent( QKeyEvent* event );
67+
//! converts QT modifiers key to OSG modifiers key
68+
virtual void adaptModifiers( QInputEvent* event );
6769
virtual void mousePressEvent( QMouseEvent* event );
6870
virtual void mouseReleaseEvent( QMouseEvent* event );
6971
virtual void mouseMoveEvent( QMouseEvent* event );

0 commit comments

Comments
 (0)