Skip to content

Commit 2dcee5d

Browse files
Marco Bernasocchipka
Marco Bernasocchi
authored andcommitted
reworked gui added new handlers //TODO use GlobePlugin::syncExtent instead of duplicating code
1 parent f84567d commit 2dcee5d

File tree

6 files changed

+112
-50
lines changed

6 files changed

+112
-50
lines changed

src/plugins/globe/globe_plugin.cpp

+110-50
Original file line numberDiff line numberDiff line change
@@ -256,29 +256,12 @@ void GlobePlugin::setupMap()
256256
#endif
257257
}
258258

259-
struct MyClickHandler : public ControlEventHandler
260-
{
261-
void onClick ( Control* control, int mouseButtonMask )
262-
{
263-
OE_NOTICE << "Thank you for clicking on " << typeid ( control ).name()
264-
<< std::endl;
265-
}
266-
};
267-
268259
struct PanControlHandler : public NavigationControlHandler
269260
{
270261
PanControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip ( manip ), _dx ( dx ), _dy ( dy ) { }
271262
virtual void onMouseDown ( Control* control, int mouseButtonMask )
272263
{
273-
if ( 0 == _dx && 0 == _dy)
274-
{
275-
//TODO
276-
OE_NOTICE << "ZOOM reset" << _manip->getDistance();
277-
}
278-
else
279-
{
280-
_manip->pan ( _dx, _dy );
281-
}
264+
_manip->pan ( _dx, _dy );
282265
}
283266
private:
284267
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
@@ -328,37 +311,88 @@ struct ZoomControlHandler : public NavigationControlHandler
328311
double _dx;
329312
double _dy;
330313
};
314+
315+
struct RefreshControlHandler : public NavigationControlHandler
316+
{
317+
RefreshControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
318+
virtual void onMouseDown ( Control* control, int mouseButtonMask )
319+
{
320+
//TODO
321+
OE_NOTICE << "refresh layers" << std::endl;
322+
}
323+
private:
324+
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
325+
QgisInterface* _mQGisIface;
326+
};
327+
328+
struct SyncExtentControlHandler : public NavigationControlHandler
329+
{
330+
SyncExtentControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
331+
virtual void onMouseDown ( Control* control, int mouseButtonMask )
332+
{
333+
//TODO use GlobePlugin::syncExtent instead of duplicating code
334+
_manip->setRotation(osg::Quat());
335+
QgsRectangle extent = _mQGisIface->mapCanvas()->extent();
336+
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
337+
QgsCoordinateTransform* trans = new QgsCoordinateTransform( _mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
338+
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );
339+
double viewAngle = 30;
340+
double height = projectedExtent.height();
341+
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
342+
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
343+
_manip->setViewpoint ( viewpoint, 4.0 );
344+
}
345+
private:
346+
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
347+
QgisInterface* _mQGisIface;
348+
};
331349

332350
bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
333351
{
334352
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' )
335353
{
354+
//TODO use GlobePlugin::syncExtent instead of duplicating code
336355
_manip->setRotation(osg::Quat());
337-
338-
//get actual mapCanvas->extent().height in meters
339356
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
340357
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
341358
QgsCoordinateTransform* trans = new QgsCoordinateTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
342359
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );
343-
344-
const double PI = 3.141592;
345360
double viewAngle = 30;
346361
double height = projectedExtent.height();
347-
double distance = height / tan( viewAngle*PI/180 ); //c = b*cotan(B)
348-
349-
QString md, me;
350-
md.setNum(height);
351-
me.setNum(distance);
352-
QMessageBox msgBox;
353-
msgBox.setText(md + " " + me );
354-
msgBox.exec();
355-
362+
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
356363
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
357364
_manip->setViewpoint ( viewpoint, 4.0 );
358365
}
359366
return false;
360367
}
361368

369+
void GlobePlugin::syncExtent( osgEarthUtil::EarthManipulator* manip )
370+
{
371+
//rotate earth to north and perpendicular to camera
372+
manip->setRotation(osg::Quat());
373+
374+
//get actual mapCanvas->extent().height in meters
375+
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
376+
//TODO: implement a stronger solution ev look at http://www.uwgb.edu/dutchs/usefuldata/utmformulas.htm
377+
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem(31254, QgsCoordinateReferenceSystem::EpsgCrsId );
378+
QgsCoordinateTransform* trans = new QgsCoordinateTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs);
379+
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );
380+
381+
double viewAngle = 30;
382+
double height = projectedExtent.height();
383+
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
384+
385+
// QString md, me;
386+
// md.setNum(height);
387+
// me.setNum(distance);
388+
// QMessageBox msgBox;
389+
// msgBox.setText(md + " " + me );
390+
// msgBox.exec();
391+
392+
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
393+
manip->setViewpoint ( viewpoint, 4.0 );
394+
}
395+
362396
void GlobePlugin::setupControls()
363397
{
364398

@@ -370,10 +404,11 @@ void GlobePlugin::setupControls()
370404
moveHControls->setFrame ( new RoundedFrame() );
371405
//moveHControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
372406
moveHControls->setMargin ( 10 );
373-
moveHControls->setSpacing ( 10 );
407+
moveHControls->setSpacing ( 15 );
374408
moveHControls->setVertAlign ( Control::ALIGN_CENTER );
375409
moveHControls->setHorizAlign ( Control::ALIGN_CENTER );
376-
moveHControls->setPosition ( 5, 35 );
410+
moveHControls->setPosition ( 20, 26 );
411+
moveHControls->setPadding(3);
377412

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

389-
//Move Reset
390-
osg::Image* moveResetImg = osgDB::readImageFile ( imgDir + "/move-reset.png" );
391-
ImageControl* moveReset = new NavigationControl ( moveResetImg );
392-
moveReset->addEventHandler ( new PanControlHandler ( manip, 0, 0 ) );
393-
394-
395424
//Vertical container
396425
VBox* moveVControls = new VBox();
397426
moveVControls->setFrame ( new RoundedFrame() );
398427
//moveVControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
399428
moveVControls->setMargin ( 10 );
400-
moveVControls->setSpacing ( 30 );
429+
moveVControls->setSpacing ( 20 );
401430
moveVControls->setVertAlign ( Control::ALIGN_CENTER );
402431
moveVControls->setHorizAlign ( Control::ALIGN_CENTER );
403432
moveVControls->setPosition ( 40, 5 );
433+
moveVControls->setPadding(3);
404434

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

415445
//add controls to moveControls group
416446
moveHControls->addControl ( moveLeft );
417-
moveHControls->addControl ( moveReset );
418447
moveHControls->addControl ( moveRight );
419448
moveVControls->addControl ( moveUp );
420449
moveVControls->addControl ( moveDown );
@@ -431,6 +460,7 @@ void GlobePlugin::setupControls()
431460
rotateControls->setVertAlign ( Control::ALIGN_CENTER );
432461
rotateControls->setHorizAlign ( Control::ALIGN_CENTER );
433462
rotateControls->setPosition ( 5, 120 );
463+
rotateControls->setPadding(3);
434464

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

450-
//add controls to moveControls group
480+
//add controls to rotateControls group
451481
rotateControls->addControl ( rotateCCW );
452482
rotateControls->addControl ( rotateReset );
453483
rotateControls->addControl ( rotateCW );
@@ -464,6 +494,7 @@ void GlobePlugin::setupControls()
464494
tiltControls->setVertAlign ( Control::ALIGN_CENTER );
465495
tiltControls->setHorizAlign ( Control::ALIGN_CENTER );
466496
tiltControls->setPosition ( 40, 90 );
497+
tiltControls->setPadding(3);
467498

468499
//tilt Up
469500
osg::Image* tiltUpImg = osgDB::readImageFile ( imgDir + "/tilt-up.png" );
@@ -487,10 +518,11 @@ void GlobePlugin::setupControls()
487518
zoomControls->setFrame ( new RoundedFrame() );
488519
//zoomControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
489520
zoomControls->setMargin ( 10 );
490-
zoomControls->setSpacing ( 5 );
521+
zoomControls->setSpacing ( 0 );
491522
zoomControls->setVertAlign ( Control::ALIGN_CENTER );
492523
zoomControls->setHorizAlign ( Control::ALIGN_CENTER );
493524
zoomControls->setPosition ( 40, 180 );
525+
zoomControls->setPadding(3);
494526

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

505-
//Zoom Reset
506-
osg::Image* zoomResetImg = osgDB::readImageFile ( imgDir + "/zoom-reset.png" );
507-
ImageControl* zoomReset = new NavigationControl ( zoomResetImg );
508-
zoomReset->addEventHandler ( new ZoomControlHandler ( manip, 0, 0 ) );
509-
510537
//add controls to zoomControls group
511538
zoomControls->addControl ( zoomIn );
512-
zoomControls->addControl ( zoomReset );
513539
zoomControls->addControl ( zoomOut );
514540

515541
//END ZOOM CONTROLS
542+
543+
//EXTRA CONTROLS
544+
//Horizontal container
545+
HBox* extraControls = new HBox();
546+
extraControls->setFrame ( new RoundedFrame() );
547+
//extraControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
548+
extraControls->setMargin ( 10 );
549+
extraControls->setSpacing ( 10 );
550+
extraControls->setVertAlign ( Control::ALIGN_CENTER );
551+
extraControls->setHorizAlign ( Control::ALIGN_CENTER );
552+
extraControls->setPosition ( 5, 240 );
553+
extraControls->setPadding(3);
554+
555+
//Zoom Reset
556+
osg::Image* extraHomeImg = osgDB::readImageFile ( imgDir + "/zoom-home.png" );
557+
ImageControl* extraHome = new NavigationControl ( extraHomeImg );
558+
extraHome->addEventHandler ( new ZoomControlHandler ( manip, 0, 0 ) );
559+
560+
//Sync Extent
561+
osg::Image* extraSyncImg = osgDB::readImageFile ( imgDir + "/sync-extent.png" );
562+
ImageControl* extraSync = new NavigationControl ( extraSyncImg );
563+
extraSync->addEventHandler ( new SyncExtentControlHandler ( manip, mQGisIface ) );
564+
565+
//refresh layers
566+
osg::Image* extraRefreshImg = osgDB::readImageFile ( imgDir + "/refresh-view.png" );
567+
ImageControl* extraRefresh = new NavigationControl ( extraRefreshImg );
568+
extraRefresh->addEventHandler ( new RefreshControlHandler ( manip, mQGisIface ) );
569+
570+
//add controls to extraControls group
571+
extraControls->addControl ( extraSync );
572+
extraControls->addControl ( extraHome );
573+
extraControls->addControl ( extraRefresh );
574+
575+
//END EXTRA CONTROLS
516576

517577
//add controls groups to canavas
518578
mControlCanvas->addControl ( moveVControls );
519579
mControlCanvas->addControl ( moveHControls );
520580
mControlCanvas->addControl ( rotateControls );
521581
mControlCanvas->addControl ( tiltControls );
522582
mControlCanvas->addControl ( zoomControls );
583+
mControlCanvas->addControl ( extraControls );
523584

524585
}
525586

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

668729
bool KeyboardControlHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
669730
{
670-
float deg = 3.14159 / 180;
671731
/*
672732
osgEarthUtil::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
673733
_manip->getSettings()->bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);

src/plugins/globe/globe_plugin.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class GlobePlugin : public QObject, public QgisPlugin
6565
void layersChanged();
6666
//! Called when the extents of the map change
6767
void extentsChanged();
68+
//! Sync globe extent to mapCanavas
69+
void syncExtent( osgEarthUtil::EarthManipulator* manip );
6870

6971
//! Place an OSG model on the globe
7072
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );
942 Bytes
Loading
1.26 KB
Loading
-3.62 KB
Binary file not shown.

0 commit comments

Comments
 (0)