Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
reworked gui added new handlers //TODO use GlobePlugin::syncExtent in…
…stead of duplicating code
  • Loading branch information
Marco Bernasocchi authored and pka committed Jul 5, 2011
1 parent f84567d commit 2dcee5d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 50 deletions.
160 changes: 110 additions & 50 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -256,29 +256,12 @@ void GlobePlugin::setupMap()
#endif
}

struct MyClickHandler : public ControlEventHandler
{
void onClick ( Control* control, int mouseButtonMask )
{
OE_NOTICE << "Thank you for clicking on " << typeid ( control ).name()
<< std::endl;
}
};

struct PanControlHandler : public NavigationControlHandler
{
PanControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip ( manip ), _dx ( dx ), _dy ( dy ) { }
virtual void onMouseDown ( Control* control, int mouseButtonMask )
{
if ( 0 == _dx && 0 == _dy)
{
//TODO
OE_NOTICE << "ZOOM reset" << _manip->getDistance();
}
else
{
_manip->pan ( _dx, _dy );
}
_manip->pan ( _dx, _dy );
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
Expand Down Expand Up @@ -328,37 +311,88 @@ struct ZoomControlHandler : public NavigationControlHandler
double _dx;
double _dy;
};

struct RefreshControlHandler : public NavigationControlHandler
{
RefreshControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
virtual void onMouseDown ( Control* control, int mouseButtonMask )
{
//TODO
OE_NOTICE << "refresh layers" << std::endl;
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
QgisInterface* _mQGisIface;
};

struct SyncExtentControlHandler : public NavigationControlHandler
{
SyncExtentControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
virtual void onMouseDown ( Control* control, int mouseButtonMask )
{
//TODO use GlobePlugin::syncExtent instead of duplicating code
_manip->setRotation(osg::Quat());
QgsRectangle extent = _mQGisIface->mapCanvas()->extent();
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateTransform* trans = new QgsCoordinateTransform( _mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );
double viewAngle = 30;
double height = projectedExtent.height();
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
_manip->setViewpoint ( viewpoint, 4.0 );
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
QgisInterface* _mQGisIface;
};

bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' )
{
//TODO use GlobePlugin::syncExtent instead of duplicating code
_manip->setRotation(osg::Quat());

//get actual mapCanvas->extent().height in meters
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateTransform* trans = new QgsCoordinateTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );

const double PI = 3.141592;
double viewAngle = 30;
double height = projectedExtent.height();
double distance = height / tan( viewAngle*PI/180 ); //c = b*cotan(B)

QString md, me;
md.setNum(height);
me.setNum(distance);
QMessageBox msgBox;
msgBox.setText(md + " " + me );
msgBox.exec();

double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
_manip->setViewpoint ( viewpoint, 4.0 );
}
return false;
}

void GlobePlugin::syncExtent( osgEarthUtil::EarthManipulator* manip )
{
//rotate earth to north and perpendicular to camera
manip->setRotation(osg::Quat());

//get actual mapCanvas->extent().height in meters
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
//TODO: implement a stronger solution ev look at http://www.uwgb.edu/dutchs/usefuldata/utmformulas.htm
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateTransform* trans = new QgsCoordinateTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );

double viewAngle = 30;
double height = projectedExtent.height();
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))

// QString md, me;
// md.setNum(height);
// me.setNum(distance);
// QMessageBox msgBox;
// msgBox.setText(md + " " + me );
// msgBox.exec();

osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
manip->setViewpoint ( viewpoint, 4.0 );
}

void GlobePlugin::setupControls()
{

Expand All @@ -370,10 +404,11 @@ void GlobePlugin::setupControls()
moveHControls->setFrame ( new RoundedFrame() );
//moveHControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
moveHControls->setMargin ( 10 );
moveHControls->setSpacing ( 10 );
moveHControls->setSpacing ( 15 );
moveHControls->setVertAlign ( Control::ALIGN_CENTER );
moveHControls->setHorizAlign ( Control::ALIGN_CENTER );
moveHControls->setPosition ( 5, 35 );
moveHControls->setPosition ( 20, 26 );
moveHControls->setPadding(3);

osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*> ( viewer.getCameraManipulator() );
//Move Left
Expand All @@ -386,21 +421,16 @@ void GlobePlugin::setupControls()
ImageControl* moveRight = new NavigationControl ( moveRightImg );
moveRight->addEventHandler ( new PanControlHandler ( manip, MOVE_OFFSET, 0 ) );

//Move Reset
osg::Image* moveResetImg = osgDB::readImageFile ( imgDir + "/move-reset.png" );
ImageControl* moveReset = new NavigationControl ( moveResetImg );
moveReset->addEventHandler ( new PanControlHandler ( manip, 0, 0 ) );


//Vertical container
VBox* moveVControls = new VBox();
moveVControls->setFrame ( new RoundedFrame() );
//moveVControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
moveVControls->setMargin ( 10 );
moveVControls->setSpacing ( 30 );
moveVControls->setSpacing ( 20 );
moveVControls->setVertAlign ( Control::ALIGN_CENTER );
moveVControls->setHorizAlign ( Control::ALIGN_CENTER );
moveVControls->setPosition ( 40, 5 );
moveVControls->setPadding(3);

//Move Up
osg::Image* moveUpImg = osgDB::readImageFile ( imgDir + "/move-up.png" );
Expand All @@ -414,7 +444,6 @@ void GlobePlugin::setupControls()

//add controls to moveControls group
moveHControls->addControl ( moveLeft );
moveHControls->addControl ( moveReset );
moveHControls->addControl ( moveRight );
moveVControls->addControl ( moveUp );
moveVControls->addControl ( moveDown );
Expand All @@ -431,6 +460,7 @@ void GlobePlugin::setupControls()
rotateControls->setVertAlign ( Control::ALIGN_CENTER );
rotateControls->setHorizAlign ( Control::ALIGN_CENTER );
rotateControls->setPosition ( 5, 120 );
rotateControls->setPadding(3);

//Rotate CCW
osg::Image* rotateCCWImg = osgDB::readImageFile ( imgDir + "/rotate-ccw.png" );
Expand All @@ -447,7 +477,7 @@ void GlobePlugin::setupControls()
ImageControl* rotateReset = new NavigationControl ( rotateResetImg );
rotateReset->addEventHandler ( new RotateControlHandler ( manip, 0, 0 ) );

//add controls to moveControls group
//add controls to rotateControls group
rotateControls->addControl ( rotateCCW );
rotateControls->addControl ( rotateReset );
rotateControls->addControl ( rotateCW );
Expand All @@ -464,6 +494,7 @@ void GlobePlugin::setupControls()
tiltControls->setVertAlign ( Control::ALIGN_CENTER );
tiltControls->setHorizAlign ( Control::ALIGN_CENTER );
tiltControls->setPosition ( 40, 90 );
tiltControls->setPadding(3);

//tilt Up
osg::Image* tiltUpImg = osgDB::readImageFile ( imgDir + "/tilt-up.png" );
Expand All @@ -487,10 +518,11 @@ void GlobePlugin::setupControls()
zoomControls->setFrame ( new RoundedFrame() );
//zoomControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
zoomControls->setMargin ( 10 );
zoomControls->setSpacing ( 5 );
zoomControls->setSpacing ( 0 );
zoomControls->setVertAlign ( Control::ALIGN_CENTER );
zoomControls->setHorizAlign ( Control::ALIGN_CENTER );
zoomControls->setPosition ( 40, 180 );
zoomControls->setPadding(3);

//Zoom In
osg::Image* zoomInImg = osgDB::readImageFile ( imgDir + "/zoom-in.png" );
Expand All @@ -502,24 +534,53 @@ void GlobePlugin::setupControls()
ImageControl* zoomOut = new NavigationControl ( zoomOutImg );
zoomOut->addEventHandler ( new ZoomControlHandler ( manip, 0, MOVE_OFFSET ) );

//Zoom Reset
osg::Image* zoomResetImg = osgDB::readImageFile ( imgDir + "/zoom-reset.png" );
ImageControl* zoomReset = new NavigationControl ( zoomResetImg );
zoomReset->addEventHandler ( new ZoomControlHandler ( manip, 0, 0 ) );

//add controls to zoomControls group
zoomControls->addControl ( zoomIn );
zoomControls->addControl ( zoomReset );
zoomControls->addControl ( zoomOut );

//END ZOOM CONTROLS

//EXTRA CONTROLS
//Horizontal container
HBox* extraControls = new HBox();
extraControls->setFrame ( new RoundedFrame() );
//extraControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
extraControls->setMargin ( 10 );
extraControls->setSpacing ( 10 );
extraControls->setVertAlign ( Control::ALIGN_CENTER );
extraControls->setHorizAlign ( Control::ALIGN_CENTER );
extraControls->setPosition ( 5, 240 );
extraControls->setPadding(3);

//Zoom Reset
osg::Image* extraHomeImg = osgDB::readImageFile ( imgDir + "/zoom-home.png" );
ImageControl* extraHome = new NavigationControl ( extraHomeImg );
extraHome->addEventHandler ( new ZoomControlHandler ( manip, 0, 0 ) );

//Sync Extent
osg::Image* extraSyncImg = osgDB::readImageFile ( imgDir + "/sync-extent.png" );
ImageControl* extraSync = new NavigationControl ( extraSyncImg );
extraSync->addEventHandler ( new SyncExtentControlHandler ( manip, mQGisIface ) );

//refresh layers
osg::Image* extraRefreshImg = osgDB::readImageFile ( imgDir + "/refresh-view.png" );
ImageControl* extraRefresh = new NavigationControl ( extraRefreshImg );
extraRefresh->addEventHandler ( new RefreshControlHandler ( manip, mQGisIface ) );

//add controls to extraControls group
extraControls->addControl ( extraSync );
extraControls->addControl ( extraHome );
extraControls->addControl ( extraRefresh );

//END EXTRA CONTROLS

//add controls groups to canavas
mControlCanvas->addControl ( moveVControls );
mControlCanvas->addControl ( moveHControls );
mControlCanvas->addControl ( rotateControls );
mControlCanvas->addControl ( tiltControls );
mControlCanvas->addControl ( zoomControls );
mControlCanvas->addControl ( extraControls );

}

Expand Down Expand Up @@ -667,7 +728,6 @@ bool NavigationControl::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct

bool KeyboardControlHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
float deg = 3.14159 / 180;
/*
osgEarthUtil::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
_manip->getSettings()->bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -65,6 +65,8 @@ class GlobePlugin : public QObject, public QgisPlugin
void layersChanged();
//! Called when the extents of the map change
void extentsChanged();
//! Sync globe extent to mapCanavas
void syncExtent( osgEarthUtil::EarthManipulator* manip );

//! Place an OSG model on the globe
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );
Expand Down
Binary file added src/plugins/globe/images/gui/refresh-view.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/plugins/globe/images/gui/sync-extent.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file removed src/plugins/globe/images/gui/zoom-reset.png
Binary file not shown.

0 comments on commit 2dcee5d

Please sign in to comment.