From 7fe3e1bd5da2f42280233c756f72a85cf692e28b Mon Sep 17 00:00:00 2001 From: Rexbas Date: Sat, 8 Jul 2023 22:48:56 +0200 Subject: [PATCH 1/3] Add visual indication for the rotation center --- src/Gui/NavigationStyle.cpp | 9 +++-- src/Gui/NavigationStyle.h | 3 +- src/Gui/View3DInventorViewer.cpp | 64 ++++++++++++++++++++++++++++++++ src/Gui/View3DInventorViewer.h | 4 ++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index a63abb399c..1072649939 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -862,10 +862,9 @@ void NavigationStyle::doRotate(SoCamera * camera, float angle, const SbVec2f& po } -SbVec3f NavigationStyle::getRotationCenter(SbBool* ok) const +SbVec3f NavigationStyle::getRotationCenter(SbBool& found) const { - if (ok) - *ok = PRIVATE(this)->rotationCenterFound; + found = PRIVATE(this)->rotationCenterFound; return PRIVATE(this)->rotationCenter; } @@ -1412,12 +1411,14 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode) case DRAGGING: // Set up initial projection point for the projector object when // first starting a drag operation. + viewer->showRotationCenter(true); this->spinprojector->project(this->lastmouseposition); this->interactiveCountInc(); this->clearLog(); break; case SPINNING: + viewer->showRotationCenter(true); this->interactiveCountInc(); viewer->getSoRenderManager()->scheduleRedraw(); break; @@ -1442,6 +1443,8 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode) switch (oldmode) { case SPINNING: case DRAGGING: + viewer->showRotationCenter(false); + [[fallthrough]]; case PANNING: case ZOOMING: case BOXZOOM: diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 59a3b39cf3..a6c6bf51e1 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -172,6 +172,8 @@ public: void setOrbitStyle(OrbitStyle style); OrbitStyle getOrbitStyle() const; + SbVec3f getRotationCenter(SbBool&) const; + protected: void initialize(); void finalize(); @@ -187,7 +189,6 @@ protected: SbBool seekToPoint(const SbVec2s screenpos); void seekToPoint(const SbVec3f& scenepos); SbBool lookAtPoint(const SbVec2s screenpos); - SbVec3f getRotationCenter(SbBool*) const; void reorientCamera(SoCamera * camera, const SbRotation & rot); void panCamera(SoCamera * camera, diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index a4ff65551c..4eac801515 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -52,6 +52,7 @@ # include # include # include +# include # include # include # include @@ -62,8 +63,10 @@ # include # include # include +# include # include # include +# include # include # include # include @@ -337,6 +340,7 @@ View3DInventorViewer::View3DInventorViewer(QWidget* parent, const QtGLWidget* sh , framebuffer(nullptr) , axisCross(nullptr) , axisGroup(nullptr) + , rotationCenterGroup(nullptr) , editing(false) , redirected(false) , allowredir(false) @@ -355,6 +359,7 @@ View3DInventorViewer::View3DInventorViewer(const QtGLFormat& format, QWidget* pa , framebuffer(nullptr) , axisCross(nullptr) , axisGroup(nullptr) + , rotationCenterGroup(nullptr) , editing(false) , redirected(false) , allowredir(false) @@ -1268,6 +1273,65 @@ bool View3DInventorViewer::hasAxisCross() return axisGroup; } +void View3DInventorViewer::showRotationCenter(bool show) +{ + SoNode* scene = getSceneGraph(); + auto sep = static_cast(scene); + + if (show) { + SbBool found; + SbVec3f center = navigation->getRotationCenter(found); + + if (!found) { + return; + } + + if (!rotationCenterGroup) { + rotationCenterGroup = new SoSkipBoundingGroup(); + + auto sphere = new SoSphere(); + + // There needs to be a non-transparent object to ensure the transparent sphere works when opening an new empty document + auto hidden = new SoSeparator(); + auto hiddenScale = new SoScale(); + hiddenScale->scaleFactor = SbVec3f(0, 0, 0); + hidden->addChild(hiddenScale); + hidden->addChild(sphere); + + auto complexity = new SoComplexity(); + complexity->value = 1; + + auto material = new SoMaterial(); + material->emissiveColor = SbColor(1, 0, 0); + material->transparency = 0.8; + + auto translation = new SoTranslation(); + translation->translation.setValue(center); + + auto annotation = new SoAnnotation(); + annotation->addChild(complexity); + annotation->addChild(material); + annotation->addChild(sphere); + + auto scaledSphere = new SoShapeScale(); + scaledSphere->setPart("shape", annotation); + scaledSphere->scaleFactor = 4.0; + + rotationCenterGroup->addChild(translation); + rotationCenterGroup->addChild(hidden); + rotationCenterGroup->addChild(scaledSphere); + + sep->addChild(rotationCenterGroup); + } + } + else { + if (rotationCenterGroup) { + sep->removeChild(rotationCenterGroup); + rotationCenterGroup = nullptr; + } + } +} + void View3DInventorViewer::setNavigationType(Base::Type t) { if (this->navigation && this->navigation->getTypeId() == t) diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 856a778252..43dd1e9bf6 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -413,6 +413,8 @@ public: void setAxisCross(bool b); bool hasAxisCross(); + void showRotationCenter(bool show); + void setEnabledFPSCounter(bool b); void setEnabledNaviCube(bool b); bool isEnabledNaviCube() const; @@ -509,6 +511,8 @@ private: SoShapeScale* axisCross; SoGroup* axisGroup; + SoGroup* rotationCenterGroup; + //stuff needed to draw the fps counter bool fpsEnabled; bool vboEnabled; From 625518c0ca572a14e3550320a7c968b1e4f80e28 Mon Sep 17 00:00:00 2001 From: Rexbas Date: Sun, 9 Jul 2023 13:45:39 +0200 Subject: [PATCH 2/3] Add option to disable rotation center indication --- src/Gui/DlgSettingsNavigation.cpp | 2 ++ src/Gui/DlgSettingsNavigation.ui | 19 +++++++++++++++++++ src/Gui/PreferencePackTemplates/View.cfg | 1 + src/Gui/View3DInventorViewer.cpp | 6 +++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Gui/DlgSettingsNavigation.cpp b/src/Gui/DlgSettingsNavigation.cpp index 2b148cc1ce..bd5df7e8ca 100644 --- a/src/Gui/DlgSettingsNavigation.cpp +++ b/src/Gui/DlgSettingsNavigation.cpp @@ -86,6 +86,7 @@ void DlgSettingsNavigation::saveSettings() ui->checkBoxZoomAtCursor->onSave(); ui->checkBoxInvertZoom->onSave(); ui->checkBoxDisableTilt->onSave(); + ui->checkBoxShowRotationCenter->onSave(); ui->spinBoxZoomStep->onSave(); ui->checkBoxUseAutoRotation->onSave(); ui->qspinNewDocScale->onSave(); @@ -122,6 +123,7 @@ void DlgSettingsNavigation::loadSettings() ui->checkBoxZoomAtCursor->onRestore(); ui->checkBoxInvertZoom->onRestore(); ui->checkBoxDisableTilt->onRestore(); + ui->checkBoxShowRotationCenter->onRestore(); ui->spinBoxZoomStep->onRestore(); ui->checkBoxUseAutoRotation->onRestore(); ui->qspinNewDocScale->onRestore(); diff --git a/src/Gui/DlgSettingsNavigation.ui b/src/Gui/DlgSettingsNavigation.ui index 711cc07975..c2c33a3370 100644 --- a/src/Gui/DlgSettingsNavigation.ui +++ b/src/Gui/DlgSettingsNavigation.ui @@ -615,6 +615,25 @@ Mouse tilting is not disabled by this setting. + + + + Show the rotation center when dragging. + + + Enable rotation center indication + + + true + + + ShowRotationCenter + + + View + + + diff --git a/src/Gui/PreferencePackTemplates/View.cfg b/src/Gui/PreferencePackTemplates/View.cfg index a0ef5b960d..6ad815c14c 100644 --- a/src/Gui/PreferencePackTemplates/View.cfg +++ b/src/Gui/PreferencePackTemplates/View.cfg @@ -18,6 +18,7 @@ + Gui::CADNavigationStyle diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 4eac801515..08592bc343 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1278,7 +1278,11 @@ void View3DInventorViewer::showRotationCenter(bool show) SoNode* scene = getSceneGraph(); auto sep = static_cast(scene); - if (show) { + bool showEnabled = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetBool("ShowRotationCenter", true); + + if (show && showEnabled) { SbBool found; SbVec3f center = navigation->getRotationCenter(found); From 579e2ee6eaeb8394485d8204310b1cf3925a7e8d Mon Sep 17 00:00:00 2001 From: Rexbas Date: Tue, 11 Jul 2023 21:35:19 +0200 Subject: [PATCH 3/3] Set rotation center for WindowCenter mode --- src/Gui/NavigationStyle.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 1072649939..33771881f5 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1031,6 +1031,11 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev) this->globalPos.setValue(QCursor::pos().x(), QCursor::pos().y()); this->localPos = ev->getPosition(); + // mode is WindowCenter + if (!PRIVATE(this)->rotationCenterMode) { + setRotationCenter(getFocalPoint()); + } + //Option to get point on model (slow) or always on focal plane (fast) // // mode is ScenePointAtCursor to get exact point if possible