Merge pull request #9909 from Rexbas/rotationcenter

Gui: Add rotation center indicator
This commit is contained in:
Yorik van Havre
2023-08-07 17:57:13 +02:00
committed by GitHub
7 changed files with 107 additions and 4 deletions

View File

@@ -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();

View File

@@ -615,6 +615,25 @@ Mouse tilting is not disabled by this setting.</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxShowRotationCenter">
<property name="toolTip">
<string>Show the rotation center when dragging.</string>
</property>
<property name="text">
<string>Enable rotation center indication</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowRotationCenter</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -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;
}
@@ -1032,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
@@ -1412,12 +1416,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 +1448,8 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode)
switch (oldmode) {
case SPINNING:
case DRAGGING:
viewer->showRotationCenter(false);
[[fallthrough]];
case PANNING:
case ZOOMING:
case BOXZOOM:

View File

@@ -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,

View File

@@ -18,6 +18,7 @@
<FCInt Name="CornerCoordSystemSize" Value="10"/>
<FCBool Name="CheckBoxSelectionCheckBoxes" Value="1"/>
<FCBool Name="InvertZoom" Value="1"/>
<FCBool Name="ShowRotationCenter" Value="1"/>
<FCInt Name="NaviStepByTurn" Value="8"/>
<FCText Name="NavigationStyle">Gui::CADNavigationStyle</FCText>
<FCInt Name="OrbitStyle" Value="1"/>

View File

@@ -52,6 +52,7 @@
# include <Inventor/events/SoKeyboardEvent.h>
# include <Inventor/events/SoMotion3Event.h>
# include <Inventor/manips/SoClipPlaneManip.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoCallback.h>
# include <Inventor/nodes/SoCube.h>
@@ -62,8 +63,10 @@
# include <Inventor/nodes/SoOrthographicCamera.h>
# include <Inventor/nodes/SoPerspectiveCamera.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoScale.h>
# include <Inventor/nodes/SoSelection.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoSphere.h>
# include <Inventor/nodes/SoSwitch.h>
# include <Inventor/nodes/SoTransform.h>
# include <Inventor/nodes/SoTranslation.h>
@@ -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,69 @@ bool View3DInventorViewer::hasAxisCross()
return axisGroup;
}
void View3DInventorViewer::showRotationCenter(bool show)
{
SoNode* scene = getSceneGraph();
auto sep = static_cast<SoSeparator*>(scene);
bool showEnabled = App::GetApplication()
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
->GetBool("ShowRotationCenter", true);
if (show && showEnabled) {
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)

View File

@@ -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;