diff --git a/src/Gui/DlgSettings3DView.ui b/src/Gui/DlgSettings3DView.ui
index 56faa96d88..5b690eee5d 100644
--- a/src/Gui/DlgSettings3DView.ui
+++ b/src/Gui/DlgSettings3DView.ui
@@ -49,6 +49,22 @@
+ -
+
+
+ Show navigation cube
+
+
+ true
+
+
+ ShowNaviCube
+
+
+ View
+
+
+
-
@@ -528,6 +544,7 @@
CheckBox_CornerCoordSystem
CheckBox_ShowFPS
+ CheckBox_NaviCube
CheckBox_useVBO
CheckBox_UseAutoRotation
comboNavigationStyle
diff --git a/src/Gui/DlgSettings3DViewImp.cpp b/src/Gui/DlgSettings3DViewImp.cpp
index 2d5d44606b..b1664666c4 100644
--- a/src/Gui/DlgSettings3DViewImp.cpp
+++ b/src/Gui/DlgSettings3DViewImp.cpp
@@ -86,6 +86,7 @@ void DlgSettings3DViewImp::saveSettings()
CheckBox_CornerCoordSystem->onSave();
CheckBox_ShowFPS->onSave();
CheckBox_useVBO->onSave();
+ CheckBox_NaviCube->onSave();
CheckBox_UseAutoRotation->onSave();
FloatSpinBox_EyeDistance->onSave();
checkBoxBacklight->onSave();
@@ -103,6 +104,7 @@ void DlgSettings3DViewImp::loadSettings()
CheckBox_CornerCoordSystem->onRestore();
CheckBox_ShowFPS->onRestore();
CheckBox_useVBO->onRestore();
+ CheckBox_NaviCube->onRestore();
CheckBox_UseAutoRotation->onRestore();
FloatSpinBox_EyeDistance->onRestore();
checkBoxBacklight->onRestore();
diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp
index 22a2a857ae..8eb41b6ce9 100644
--- a/src/Gui/NaviCube.cpp
+++ b/src/Gui/NaviCube.cpp
@@ -253,6 +253,7 @@ public:
bool m_MouseDown = false;
bool m_Dragging = false;
bool m_MightDrag = false;
+ NaviCube::Corner m_Corner = NaviCube::TopRightCorner;
QtGLFramebufferObject* m_PickingFramebuffer;
@@ -287,6 +288,9 @@ bool NaviCube::processSoEvent(const SoEvent* ev) {
return m_NaviCubeImplementation->processSoEvent(ev);
}
+void NaviCube::setCorner(Corner c) {
+ m_NaviCubeImplementation->m_Corner = c;
+}
NaviCubeImplementation::NaviCubeImplementation(
Gui::View3DInventorViewer* viewer) {
@@ -748,8 +752,24 @@ void NaviCubeImplementation::handleResize() {
m_CubeWidgetPosY = view[1] - (m_PrevHeight - m_CubeWidgetPosY);
}
else { // initial position
- m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
- m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
+ switch (m_Corner) {
+ case NaviCube::TopLeftCorner:
+ m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
+ m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
+ break;
+ case NaviCube::TopRightCorner:
+ m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
+ m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
+ break;
+ case NaviCube::BottomLeftCorner:
+ m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
+ m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
+ break;
+ case NaviCube::BottomRightCorner:
+ m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
+ m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
+ break;
+ }
}
m_PrevWidth = view[0];
m_PrevHeight = view[1];
diff --git a/src/Gui/NaviCube.h b/src/Gui/NaviCube.h
index f520210ee0..3af12fc0f1 100644
--- a/src/Gui/NaviCube.h
+++ b/src/Gui/NaviCube.h
@@ -35,10 +35,17 @@ class NaviCubeImplementation;
class NaviCube {
public:
+ enum Corner {
+ TopLeftCorner,
+ TopRightCorner,
+ BottomLeftCorner,
+ BottomRightCorner
+ };
NaviCube(Gui::View3DInventorViewer* viewer) ;
virtual ~NaviCube();
void drawNaviCube();
bool processSoEvent(const SoEvent* ev);
+ void setCorner(Corner);
private:
NaviCubeImplementation* m_NaviCubeImplementation;
};
diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp
index 2f383f16f1..c3aac3f0af 100644
--- a/src/Gui/Quarter/QuarterWidget.cpp
+++ b/src/Gui/Quarter/QuarterWidget.cpp
@@ -98,6 +98,7 @@
#if QT_VERSION >= 0x050000
#include
#include
+#include
#endif
@@ -168,8 +169,8 @@ public:
}
void initializeGL()
{
-#if defined (_DEBUG) && 0
QOpenGLContext *context = QOpenGLContext::currentContext();
+#if defined (_DEBUG) && 0
if (context && context->hasExtension(QByteArrayLiteral("GL_KHR_debug"))) {
QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
connect(logger, &QOpenGLDebugLogger::messageLogged, this, &CustomGLWidget::handleLoggedMessage);
@@ -178,8 +179,18 @@ public:
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
#endif
+ if (context) {
+ connect(context, &QOpenGLContext::aboutToBeDestroyed,
+ this, &CustomGLWidget::aboutToDestroyGLContext, Qt::DirectConnection);
+ }
connect(this, &CustomGLWidget::resized, this, &CustomGLWidget::slotResized);
}
+ void aboutToDestroyGLContext()
+ {
+ QMetaObject::invokeMethod(parent(), "aboutToDestroyGLContext",
+ Qt::DirectConnection,
+ QGenericReturnArgument());
+ }
bool event(QEvent *e)
{
// If a debug logger is activated then Qt's default implementation
@@ -315,6 +326,11 @@ QuarterWidget::replaceViewport()
#endif
}
+void
+QuarterWidget::aboutToDestroyGLContext()
+{
+}
+
/*! destructor */
QuarterWidget::~QuarterWidget()
{
diff --git a/src/Gui/Quarter/QuarterWidget.h b/src/Gui/Quarter/QuarterWidget.h
index 260fb68112..dc8c47a208 100644
--- a/src/Gui/Quarter/QuarterWidget.h
+++ b/src/Gui/Quarter/QuarterWidget.h
@@ -191,6 +191,7 @@ Q_SIGNALS:
private Q_SLOTS:
void replaceViewport();
+ virtual void aboutToDestroyGLContext();
protected:
virtual void paintEvent(QPaintEvent*);
diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp
index 2f87e4b158..9f92c3ab56 100644
--- a/src/Gui/View3DInventor.cpp
+++ b/src/Gui/View3DInventor.cpp
@@ -168,6 +168,7 @@ View3DInventor::View3DInventor(Gui::Document* pcDocument, QWidget* parent,
OnChange(*hGrp,"BackgroundColor4");
OnChange(*hGrp,"UseBackgroundColorMid");
OnChange(*hGrp,"ShowFPS");
+ OnChange(*hGrp,"ShowNaviCube");
OnChange(*hGrp,"UseVBO");
OnChange(*hGrp,"Orthographic");
OnChange(*hGrp,"HeadlightColor");
@@ -361,6 +362,9 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
else if (strcmp(Reason,"ShowFPS") == 0) {
_viewer->setEnabledFPSCounter(rGrp.GetBool("ShowFPS",false));
}
+ else if (strcmp(Reason,"ShowNaviCube") == 0) {
+ _viewer->setEnabledNaviCube(rGrp.GetBool("ShowNaviCube",true));
+ }
else if (strcmp(Reason,"UseVBO") == 0) {
_viewer->setEnabledVBO(rGrp.GetBool("UseVBO",false));
}
diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp
index cb1c7d9740..72cf36f04a 100644
--- a/src/Gui/View3DInventorViewer.cpp
+++ b/src/Gui/View3DInventorViewer.cpp
@@ -120,6 +120,7 @@
#include
#include
#include "View3DViewerPy.h"
+#include
#include
#include
@@ -533,11 +534,14 @@ void View3DInventorViewer::init()
mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap);
panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y);
naviCube = new NaviCube(this);
+ naviCubeEnabled = true;
}
View3DInventorViewer::~View3DInventorViewer()
{
- delete naviCube;
+ // to prevent following OpenGL error message: "Texture is not valid in the current context. Texture has not been destroyed"
+ aboutToDestroyGLContext();
+
// cleanup
this->backgroundroot->unref();
this->backgroundroot = 0;
@@ -571,6 +575,18 @@ View3DInventorViewer::~View3DInventorViewer()
}
}
+void View3DInventorViewer::aboutToDestroyGLContext()
+{
+ if (naviCube) {
+ QtGLWidget* gl = qobject_cast(this->viewport());
+ if (gl)
+ gl->makeCurrent();
+ delete naviCube;
+ naviCube = 0;
+ naviCubeEnabled = false;
+ }
+}
+
void View3DInventorViewer::setDocument(Gui::Document* pcDocument)
{
// write the document the viewer belongs to to the selection node
@@ -823,6 +839,16 @@ bool View3DInventorViewer::isEnabledVBO() const
return vboEnabled;
}
+void View3DInventorViewer::setEnabledNaviCube(bool on)
+{
+ naviCubeEnabled = on;
+}
+
+bool View3DInventorViewer::isEnabledNaviCube(void) const
+{
+ return naviCubeEnabled;
+}
+
void View3DInventorViewer::setAxisCross(bool on)
{
SoNode* scene = getSceneGraph();
@@ -1733,7 +1759,8 @@ void View3DInventorViewer::renderScene(void)
draw2DString(stream.str().c_str(), SbVec2s(10,10), SbVec2f(0.1f,0.1f));
}
- naviCube->drawNaviCube();
+ if (naviCubeEnabled)
+ naviCube->drawNaviCube();
#if 0 // this breaks highlighting of edges
glEnable(GL_LIGHTING);
@@ -1816,7 +1843,7 @@ void View3DInventorViewer::selectAll()
bool View3DInventorViewer::processSoEvent(const SoEvent* ev)
{
- if (naviCube->processSoEvent(ev))
+ if (naviCubeEnabled && naviCube->processSoEvent(ev))
return true;
if (isRedirectedToSceneGraph()) {
SbBool processed = inherited::processSoEvent(ev);
diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h
index 17d9b810a5..f3866f584a 100644
--- a/src/Gui/View3DInventorViewer.h
+++ b/src/Gui/View3DInventorViewer.h
@@ -38,7 +38,6 @@
#include
#include
-#include
class SoTranslation;
class SoTransform;
@@ -55,6 +54,7 @@ class SbBox2s;
class SoVectorizeAction;
class QImage;
class SoGroup;
+class NaviCube;
namespace Gui {
@@ -344,6 +344,8 @@ public:
bool hasAxisCross(void);
void setEnabledFPSCounter(bool b);
+ void setEnabledNaviCube(bool b);
+ bool isEnabledNaviCube(void) const;
void setEnabledVBO(bool b);
bool isEnabledVBO() const;
@@ -395,6 +397,7 @@ private:
void drawAxisCross(void);
static void drawArrow(void);
void setCursorRepresentation(int mode);
+ void aboutToDestroyGLContext();
private:
NaviCube* naviCube;
@@ -428,6 +431,7 @@ private:
//stuff needed to draw the fps counter
bool fpsEnabled;
bool vboEnabled;
+ SbBool naviCubeEnabled;
SbBool editing;
QCursor editCursor, zoomCursor, panCursor, spinCursor;