diff --git a/src/main.cpp b/src/main.cpp index 8ef35d34..5d13ebaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -373,26 +373,25 @@ protected: int main(int argc, char* argv[]) { SpdLogger logger("logs/log.txt", 5); // - // Application::setAttribute(Qt::AA_EnableHighDpiScaling); + Application::setAttribute(Qt::AA_EnableHighDpiScaling); // - // Application app(argc, argv); - // app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + Application app(argc, argv); + app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); // InstallCrashHandler(); // - // RecourceHelper::ChangeSkin("default"); + RecourceHelper::ChangeSkin("default"); + + MainFrame mainWindow; + mainWindow.showMaximized(); // - // MainFrame mainWindow; - // mainWindow.showMaximized(); - // - // int ret = app.exec(); - // return ret; + int ret = app.exec(); + return ret; osg::ArgumentParser arguments(&argc, argv); // Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4 osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded; - QApplication app(argc, argv); OsgWidget* viewWidget = new OsgWidget(nullptr, Qt::Widget); // ViewerWidget* viewWidget = new ViewerWidget(nullptr, Qt::Widget, threadingModel); viewWidget->setGeometry( 100, 100, 800, 600 ); diff --git a/src/scene/ui/CompositeHandle.cpp b/src/scene/ui/CompositeHandle.cpp index 3a62fca5..94cce511 100644 --- a/src/scene/ui/CompositeHandle.cpp +++ b/src/scene/ui/CompositeHandle.cpp @@ -1,8 +1,31 @@ #include "CompositeHandle.h" +#include #include "CompositeWidgetManager.h" #include +#define M_PI 3.14159265358979323846 /* mathematical constant pi */ + +///Radian to degree conversion factor +static const double RAD2DEG = 180.0 / M_PI; +///Degree to radian conversion factor +static const double DEG2RAD = M_PI / 180.0; + +inline double angFix360(double in) { + in -= 45.0; + if ((in < 0.0) || (in >= 360.0)) { + in = fmod(in, 360.0); + + if (in < 0.0) + in += 360.0; + } + return in; +} + +inline bool areEqual(double a, double b, double t = 1.0e-6) { + return fabs(a - b) < t; +} + CompositeHandle::CompositeHandle(CompositeWidgetManager* cw) : _cw(cw), _operate(cw->GetcanvasO()), @@ -17,7 +40,32 @@ CompositeHandle::CompositeHandle(CompositeWidgetManager* cw) bool CompositeHandle::handle(const osgGA::GUIEventAdapter&ea, osgGA::GUIActionAdapter& aa) { if (ea.getEventType() == osgGA::GUIEventAdapter::FRAME) { - + constexpr double TWO_DECIMAL_PLACES = 1e-02; + double heading = 0.0; + osgViewer::View* activeView = static_cast(aa.asView()); + const osgEarth::Util::EarthManipulator* manip = dynamic_cast(activeView->getCameraManipulator()); + if (manip != NULL) + { + manip->getCompositeEulerAngles(&heading); + // Convert to degrees + heading = angFix360(heading * RAD2DEG); + } + else + { + // Fall back to the viewpoint's heading + heading = angFix360(manip->getViewpoint().heading()->as(osgEarth::Units::DEGREES)); + } + + // make sure that anything equivalent to 0.00 is displayed as 0.00 + if (areEqual(heading, 0.0, TWO_DECIMAL_PLACES) || areEqual(heading, 360.0, TWO_DECIMAL_PLACES)) { + heading = 0.0; + } + + if (!areEqual(_N->getRotate(), -heading, TWO_DECIMAL_PLACES)) + { + _N->setRotate(-heading); + _N->update(); + } } // compass_->update_(); diff --git a/src/scene/ui/OESceneUI.cpp b/src/scene/ui/OESceneUI.cpp index 25957f5f..227f3c5f 100644 --- a/src/scene/ui/OESceneUI.cpp +++ b/src/scene/ui/OESceneUI.cpp @@ -29,13 +29,13 @@ void OESceneUI::InitUI(OsgViewUI* ui) { compositeWidgetManager_ = new CompositeWidgetManager(); compositeWidgetManager_->AttachViewUI(ui); - zoomManager_ = new ZoomManager(oeScene_); - zoomManager_->AttachViewUI(ui); + //zoomManager_ = new ZoomManager(oeScene_); + //zoomManager_->AttachViewUI(ui); queryElevationWidget_ = new QueryElevationWidget(oeScene_); queryElevationWidget_->AttachViewUI(ui); - ui->getView()->addEventHandler(new ZoomHandle(zoomManager_, compositeWidgetManager_)); + //ui->getView()->addEventHandler(new ZoomHandle(zoomManager_, compositeWidgetManager_)); ui->getView()->addEventHandler(new CompositeHandle(compositeWidgetManager_)); isInit_ = true; @@ -44,9 +44,9 @@ void OESceneUI::InitUI(OsgViewUI* ui) { void OESceneUI::OnResize(double width, double height) { dyt_check(compositeWidgetManager_); - dyt_check(zoomManager_); + //dyt_check(zoomManager_); compositeWidgetManager_->ResetCanvasPosition(width, height); - zoomManager_->ResetCanvasPosition(width, height); + //zoomManager_->ResetCanvasPosition(width, height); queryElevationWidget_->ResetCanvasPosition(width, height); } diff --git a/src/scene/ui/OESceneUI.h b/src/scene/ui/OESceneUI.h index 4197d2c4..f0c3d4fe 100644 --- a/src/scene/ui/OESceneUI.h +++ b/src/scene/ui/OESceneUI.h @@ -22,6 +22,6 @@ private: class OEScene* oeScene_; bool isInit_{ false }; osg::ref_ptr compositeWidgetManager_{ nullptr }; - osg::ref_ptr zoomManager_{ nullptr }; + //osg::ref_ptr zoomManager_{ nullptr }; osg::ref_ptr queryElevationWidget_{ nullptr }; }; diff --git a/src/scene/ui/ZoomManager.cpp b/src/scene/ui/ZoomManager.cpp index 8c11ea14..64b1b807 100644 --- a/src/scene/ui/ZoomManager.cpp +++ b/src/scene/ui/ZoomManager.cpp @@ -82,6 +82,8 @@ void ZoomManager::slotZoom() { double dx = val*(-1.0)*(0.0005);// dx不起作用 double dy = val*(-1.0)*(0.0005); + return; + // dx *= getSettings()->getMouseSensitivity(); // dy *= getSettings()->getMouseSensitivity(); diff --git a/src/scene/ui/ZoomManager.h b/src/scene/ui/ZoomManager.h index 5f2d5acd..02516237 100644 --- a/src/scene/ui/ZoomManager.h +++ b/src/scene/ui/ZoomManager.h @@ -21,6 +21,9 @@ public: osgWidget::Canvas* GetCanvasZoom() { return _canvasZoom; } + osgWidget::Widget* GetBar() const { + return _bar; + } void AttachViewUI(class OsgViewUI* ui); // diff --git a/src/scene/ui/ZoomWidget.cpp b/src/scene/ui/ZoomWidget.cpp index 3b314078..6bd9f78d 100644 --- a/src/scene/ui/ZoomWidget.cpp +++ b/src/scene/ui/ZoomWidget.cpp @@ -38,11 +38,14 @@ bool ZoomWidget::mousePush(double x, double y, const osgWidget::WindowManager* if ("lessen" == _order) { _pZoomManager->zoom = -43; + UpdateBarPosition(_pZoomManager->zoom); } else if ("enlargement" == _order) { _pZoomManager->zoom = 43; + UpdateBarPosition(_pZoomManager->zoom); } + setColor(1, 1, 1, 1); return false; } @@ -51,48 +54,55 @@ bool ZoomWidget::mouseRelease(double x, double y, const osgWidget::WindowManager { _pZoomManager->state = ZoomManager::MOUSE_RELEASE; - if ("bar" == _order) - { - setOrigin(0, 67); - getParent()->getByName("bar_")->setOrigin(0, 66); - getParent()->resize(); - } + //if ("bar" == _order) + //{ + // setOrigin(0, 67); + // getParent()->getByName("bar_")->setOrigin(0, 66); + // getParent()->resize(); + //} _pZoomManager->zoom = 0.0; + UpdateBarPosition(_pZoomManager->zoom); setColor(1, 1, 1, 0); return false; } +// +//bool ZoomWidget::mouseDrag(double x, double y, const osgWidget::WindowManager* wm) +//{ +// if (_order == "bar") +// { +// _pointX += x; +// _pointY += y; +// +// while (_pZoomManager->zoom > 43) +// _pZoomManager->zoom = 43; +// while (_pZoomManager->zoom < -43) +// _pZoomManager->zoom = -43; +// +// if (y > 43 - _pZoomManager->zoom) +// { +// y = 43 - _pZoomManager->zoom; +// } +// if (y < -43 - _pZoomManager->zoom) +// { +// y = -43 - _pZoomManager->zoom; +// } +// +// if (_pZoomManager->zoom >= -43 && _pZoomManager->zoom <= 43) +// { +// /*addOrigin(0, y); +// getParent()->getByName("bar_")->addOrigin(0, y);*/ +// double y1 = _pZoomManager->GetBar()->getOrigin().y(); +// UpdateBarPosition(y + y1); +// _pZoomManager->zoom += y; +// } +// else { +// _pZoomManager->zoom += y; +// } +// } +// return true; +//} -bool ZoomWidget::mouseDrag(double x, double y, const osgWidget::WindowManager* wm) -{ - if (_order == "bar") - { - _pointX += x; - _pointY += y; - - while (_pZoomManager->zoom > 43) - _pZoomManager->zoom = 43; - while (_pZoomManager->zoom < -43) - _pZoomManager->zoom = -43; - - if (y > 43 - _pZoomManager->zoom) - { - y = 43 - _pZoomManager->zoom; - } - if (y < -43 - _pZoomManager->zoom) - { - y = -43 - _pZoomManager->zoom; - } - - if (_pZoomManager->zoom >= -43 && _pZoomManager->zoom <= 43) - { - addOrigin(0, y); - getParent()->getByName("bar_")->addOrigin(0, y); - _pZoomManager->zoom += y; - } - else { - _pZoomManager->zoom += y; - } - getParent()->resize(); - } - return true; -} \ No newline at end of file +void ZoomWidget::UpdateBarPosition(double y) { + _pZoomManager->GetBar()->setOrigin(0, 67 + y * 0.5); + _pZoomManager->GetCanvasZoom()->update(); +} diff --git a/src/scene/ui/ZoomWidget.h b/src/scene/ui/ZoomWidget.h index e4af9b3d..de11dc9b 100644 --- a/src/scene/ui/ZoomWidget.h +++ b/src/scene/ui/ZoomWidget.h @@ -25,11 +25,12 @@ public: bool mousePush(double, double, const osgWidget::WindowManager*); bool mouseRelease(double, double, const osgWidget::WindowManager*); - bool mouseDrag(double, double, const osgWidget::WindowManager*); + //bool mouseDrag(double, double, const osgWidget::WindowManager*); std::string GetOrder() { return _order; } double GetPointerX() { return _pointX; } double GetpointerY() { return _pointY; } + void UpdateBarPosition(double y); private: double _pointX;