From 9cda82cf204863a88e3f925b1dcadf2cf6df56dd Mon Sep 17 00:00:00 2001 From: Nabos <9805355+nab-os@users.noreply.github.com> Date: Tue, 20 Dec 2022 03:21:46 +0100 Subject: [PATCH] Gui: Added FreeTurntable orbit style (#8048) * Added FreeTurntable orbit style --- src/Gui/DlgSettingsNavigation.ui | 10 ++++- src/Gui/NavigationStyle.cpp | 60 +++++++++++++++++---------- src/Gui/NavigationStyle.h | 3 +- src/Mod/Tux/NavigationIndicatorGui.py | 18 ++++++-- 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/Gui/DlgSettingsNavigation.ui b/src/Gui/DlgSettingsNavigation.ui index 76132d0422..87ebc2db47 100644 --- a/src/Gui/DlgSettingsNavigation.ui +++ b/src/Gui/DlgSettingsNavigation.ui @@ -279,10 +279,11 @@ Select a set and then press the button to view said configurations. Rotation orbit style. Trackball: moving the mouse horizontally will rotate the part around the y-axis -Turntable: the part will be rotated around the z-axis. +Turntable: the part will be rotated around the z-axis (with constrained axes). +Free Turntable: the part will be rotated around the z-axis. - 1 + 0 @@ -294,6 +295,11 @@ Turntable: the part will be rotated around the z-axis. Trackball + + + Free Turntable + + diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 6abef059fc..b34ee7682b 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -85,7 +85,8 @@ class FCSphereSheetProjector : public SbSphereSheetProjector { public: enum OrbitStyle { Turntable, - Trackball + Trackball, + FreeTurntable }; FCSphereSheetProjector(const SbSphere & sph, const SbBool orienttoeye = true) @@ -114,33 +115,46 @@ public: SbRotation rot = inherited::getRotation(point1, point2); if (orbit == Trackball) return rot; - - // 0000333: Turntable camera rotation - SbVec3f axis; - float angle; - rot.getValue(axis, angle); - SbVec3f dif = point1 - point2; - if (fabs(dif[1]) > fabs(dif[0])) { - SbVec3f xaxis(1,0,0); - if (dif[1] < 0) - angle = -angle; - rot.setValue(xaxis, angle); - } - else { - SbVec3f zaxis(0,0,1); - this->worldToScreen.multDirMatrix(zaxis, zaxis); - if (zaxis[1] < 0) { - if (dif[0] < 0) + else if (orbit == Turntable) { + SbVec3f axis; + float angle; + rot.getValue(axis, angle); + SbVec3f dif = point1 - point2; + if (fabs(dif[1]) > fabs(dif[0])) { + SbVec3f xaxis(1,0,0); + if (dif[1] < 0) angle = -angle; + rot.setValue(xaxis, angle); } else { - if (dif[0] > 0) - angle = -angle; + SbVec3f zaxis(0,0,1); + this->worldToScreen.multDirMatrix(zaxis, zaxis); + if (zaxis[1] < 0) { + if (dif[0] < 0) + angle = -angle; + } + else { + if (dif[0] > 0) + angle = -angle; + } + rot.setValue(zaxis, angle); } - rot.setValue(zaxis, angle); - } - return rot; + return rot; + } else { + // Turntable without constraints + SbRotation zrot, xrot; + SbVec3f dif = point1 - point2; + + SbVec3f zaxis(1,0,0); + zrot.setValue(zaxis, dif[1]); + + SbVec3f xaxis(0,0,1); + this->worldToScreen.multDirMatrix(xaxis, xaxis); + xrot.setValue(xaxis, -dif[0]); + + return zrot * xrot; + } } void setOrbitStyle(OrbitStyle style) diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 902f571c18..59a3b39cf3 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -99,7 +99,8 @@ public: enum OrbitStyle { Turntable, - Trackball + Trackball, + FreeTurntable }; enum class RotationCenterMode { diff --git a/src/Mod/Tux/NavigationIndicatorGui.py b/src/Mod/Tux/NavigationIndicatorGui.py index cd90c1920e..2ae617aa3b 100644 --- a/src/Mod/Tux/NavigationIndicatorGui.py +++ b/src/Mod/Tux/NavigationIndicatorGui.py @@ -333,6 +333,7 @@ def retranslateUi(): aCompact.setText(translate("NavigationIndicator", "Compact")) aTooltip.setText(translate("NavigationIndicator", "Tooltip")) aTurntable.setText(translate("NavigationIndicator", "Turntable")) + aFreeTurntable.setText(translate("NavigationIndicator", "FreeTurntable")) aTrackball.setText(translate("NavigationIndicator", "Trackball")) a0.setText(translate("NavigationIndicator", "Undefined")) @@ -358,13 +359,18 @@ gOrbit = QtGui.QActionGroup(menuSettings) aTurntable = QtGui.QAction(gOrbit) aTurntable.setObjectName("NavigationIndicator_Turntable") aTurntable.setCheckable(True) +aFreeTurntable = QtGui.QAction(gOrbit) +aFreeTurntable.setObjectName("NavigationIndicator_FreeTurntable") +aFreeTurntable.setCheckable(True) aTrackball = QtGui.QAction(gOrbit) aTrackball.setObjectName("NavigationIndicator_Trackball") aTrackball.setCheckable(True) +menuOrbit.addAction(aFreeTurntable) menuOrbit.addAction(aTurntable) menuOrbit.addAction(aTrackball) + menuSettings.addMenu(menuOrbit) menuSettings.addSeparator() menuSettings.addAction(aCompact) @@ -504,18 +510,22 @@ def onOrbit(): if aTurntable.isChecked(): pView.SetInt("OrbitStyle", 0) - else: + elif aTrackball.isChecked(): pView.SetInt("OrbitStyle", 1) + elif aFreeTurntable.isChecked(): + pView.SetInt("OrbitStyle", 2) def onOrbitShow(): """Set turntable or trackball orbit style.""" gOrbit.blockSignals(True) - if pView.GetInt("OrbitStyle", 1): - aTrackball.setChecked(True) - else: + if pView.GetInt("OrbitStyle", 0): aTurntable.setChecked(True) + elif pView.GetInt("OrbitStyle", 1): + aTrackball.setChecked(True) + elif pView.GetInt("OrbitStyle", 2): + aFreeTurntable.setChecked(True) gOrbit.blockSignals(False)