Skip to content

Commit

Permalink
- added support for globe coordinates, they are now shown in the stat…
Browse files Browse the repository at this point in the history
…us bar. - added modkey support
  • Loading branch information
mbernasocchi authored and pka committed Jul 5, 2011
1 parent 9bca3a7 commit 481e0ea
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 12 deletions.
90 changes: 80 additions & 10 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -117,6 +117,11 @@ void GlobePlugin::initGui()
SLOT( blankProjectReady() ) );
connect( &mQDockWidget, SIGNAL( globeClosed() ), this,
SLOT( setGlobeNotRunning() ) );
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
mQGisIface->mainWindow(), SLOT( showMouseCoordinate( const QgsPoint & ) ) );
// connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
// this, SLOT( showSelectedCoordinates() ) );

}

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

bool QueryCoordinatesHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH )
if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
{
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view );
mGlobe->showCurrentCoordinates( coords.x(), coords.y() );
}
if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH
&& ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
{
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
getCoords( ea.getX(), ea.getY(), view );
osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view );

OE_NOTICE << "Lon: " << coords.x() << " Lat: " << coords.y()
<< " Ele: " << coords.z() << std::endl;

mGlobe->setSelectedCoordinates( coords );

if (ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL)
{
mGlobe->showSelectedCoordinates();
}
}

return false;
}

void QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view )
void GlobePlugin::showCurrentCoordinates(double lon, double lat)
{
// show x y on status bar
OE_NOTICE << "lon: " << lon << " lat: " << lat <<std::endl;
QgsPoint coord = QgsPoint( lon, lat );
emit xyCoordinates( coord );
}

void GlobePlugin::setSelectedCoordinates( osg::Vec3d coords)
{
mSelectedLon = coords.x();
mSelectedLat = coords.y();
mSelectedElevation = coords.z();
}

osg::Vec3d GlobePlugin::getSelectedCoordinates()
{
osg::Vec3d coords = osg::Vec3d(mSelectedLon, mSelectedLat, mSelectedElevation);
return coords;
}

void GlobePlugin::showSelectedCoordinates()
{
QString lon, lat, elevation;
lon.setNum(mSelectedLon);
lat.setNum(mSelectedLat);
elevation.setNum(mSelectedElevation);
QMessageBox m;
m.setText("selected coordinates are:\nlon: " + lon + "\nlat: " + lat + "\nelevation: " + elevation);
m.exec();
}

double GlobePlugin::getSelectedLon()
{
return mSelectedLon;
}

double GlobePlugin::getSelectedLat()
{
return mSelectedLat;
}

double GlobePlugin::getSelectedElevation()
{
return mSelectedElevation;
}

osg::Vec3d QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view )
{
osgUtil::LineSegmentIntersector::Intersections results;
if ( view->computeIntersections( x, y, results, 0x01 ) )
Expand All @@ -374,30 +443,31 @@ void QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view
_mapSRS->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height );

// query the elevation at the map point:
double lat_deg = osg::RadiansToDegrees( lat_rad );
double lon_deg = osg::RadiansToDegrees( lon_rad );
double lat_deg = osg::RadiansToDegrees( lat_rad );
double elevation = 0.0;

OE_NOTICE << "coords at " << lat_deg << ", " << lon_deg << std::endl ;

/* osg::Matrixd out_mat;
/*TODO IMPLEMENT ELEVATION
osg::Matrixd out_mat;
double query_resolution = 0.1; // 1/10th of a degree
double out_elevation = 0.0;
double out_resolution = 0.0;
if ( _elevMan->getPlacementMatrix(
lon_deg, lat_deg, 0,
query_resolution, NULL,
out_mat, out_elevation, out_resolution ) )
out_mat, elevation, out_resolution ) )
{
OE_NOTICE << "Elevation at " << lat_deg << ", " << lon_deg
<< " is " << out_elevation << std::endl;
<< " is " << elevation << std::endl;
}
else
{
OE_NOTICE
<< "getElevation FAILED! at (" << lat_deg << ", " << lon_deg << ")" << std::endl;
}
*/
osg::Vec3d coords = osg::Vec3d(lon_deg, lat_deg, elevation);
return coords;
}
}

Expand Down
28 changes: 26 additions & 2 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -56,7 +56,6 @@ class GlobePlugin : public QObject, public QgisPlugin
//! show the help document
void help();


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

//! called when a project has been read succesfully
void projectReady();
//! called when a new project has been created succesfully
void blankProjectReady();
//! called when the globe window is closed
void setGlobeNotRunning();
//! set the globe coordinates of a user right-click on the globe
void setSelectedCoordinates( osg::Vec3d coords );
//! get a coordinates vector
osg::Vec3d getSelectedCoordinates();
//! prints the ccordinates in a QMessageBox
void showSelectedCoordinates();
//! emits signal with current mouse coordinates
void showCurrentCoordinates(double lon, double lat);
//! get longitude of user right click
double getSelectedLon();
//! get latitude of user right click
double getSelectedLat();
//! get elevation of user right click
double getSelectedElevation();


//! Place an OSG model on the globe
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );
Expand Down Expand Up @@ -116,6 +133,13 @@ class GlobePlugin : public QObject, public QgisPlugin
osgEarthUtil::ObjectPlacer* mObjectPlacer;
//! tracks if the globe is open
bool mIsGlobeRunning;
//! coordinates of the right-clicked point on the globe
double mSelectedLat, mSelectedLon, mSelectedElevation;

signals:
//! emits current mouse position
//TODO connect to this signal at qgisapp.cpp:1952
void xyCoordinates( const QgsPoint & p );
};

class FlyToExtentHandler : public osgGA::GUIEventHandler
Expand All @@ -138,7 +162,7 @@ class QueryCoordinatesHandler : public osgGA::GUIEventHandler

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

virtual void getCoords( float x, float y, osgViewer::View* view );
virtual osg::Vec3d getCoords( float x, float y, osgViewer::View* view );

private:
GlobePlugin* mGlobe;
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/globe/qgsosgviewer.cpp
Expand Up @@ -66,6 +66,7 @@ void QgsGLWidgetAdapter::keyReleaseEvent( QKeyEvent* event )

void QgsGLWidgetAdapter::mousePressEvent( QMouseEvent* event )
{
adaptModifiers( event );
int button = 0;
switch(event->button())
{
Expand All @@ -78,6 +79,18 @@ void QgsGLWidgetAdapter::mousePressEvent( QMouseEvent* event )
_gw->getEventQueue()->mouseButtonPress(event->x(), event->y(), button);
}

void QgsGLWidgetAdapter::adaptModifiers( QInputEvent* event )
{
int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier);

unsigned int modkeyosg = 0;
if (modkey & Qt::ShiftModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_SHIFT;
if (modkey & Qt::ControlModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_CTRL;
if (modkey & Qt::AltModifier) modkeyosg |= osgGA::GUIEventAdapter::MODKEY_ALT;

_gw->getEventQueue()->getCurrentEventState()->setModKeyMask( modkeyosg );
}

void QgsGLWidgetAdapter::mouseReleaseEvent( QMouseEvent* event )
{
int button = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/globe/qgsosgviewer.h
Expand Up @@ -64,6 +64,8 @@ class QgsGLWidgetAdapter : public QGLWidget
virtual void resizeGL( int width, int height );
virtual void keyPressEvent( QKeyEvent* event );
virtual void keyReleaseEvent( QKeyEvent* event );
//! converts QT modifiers key to OSG modifiers key
virtual void adaptModifiers( QInputEvent* event );
virtual void mousePressEvent( QMouseEvent* event );
virtual void mouseReleaseEvent( QMouseEvent* event );
virtual void mouseMoveEvent( QMouseEvent* event );
Expand Down

0 comments on commit 481e0ea

Please sign in to comment.