From 61e419b88ffac8cdb9f874363270327a0ab3ed3c Mon Sep 17 00:00:00 2001 From: Rexbas Date: Tue, 24 Oct 2023 20:32:47 +0200 Subject: [PATCH] Gui: Revert breaking Python interface change for viewPosition() --- src/Gui/View3DInventorViewer.cpp | 16 ++++++++++++---- src/Gui/View3DInventorViewer.h | 4 ++-- src/Gui/View3DPy.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 73e33c6b325d..6e4606da759d 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2788,7 +2788,7 @@ void View3DInventorViewer::setCameraType(SoType t) } } -void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbVec3f& position) +void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbVec3f& position, int duration) { SoCamera* camera = getCamera(); if (!camera) @@ -2796,7 +2796,7 @@ void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbV if (isAnimationEnabled()) { startAnimation( - orientation, camera->position.getValue(), position - camera->position.getValue(), true); + orientation, camera->position.getValue(), position - camera->position.getValue(), duration, true); } camera->orientation.setValue(orientation); @@ -3088,16 +3088,24 @@ SbBool View3DInventorViewer::isAnimating() const * @param orientation The new orientation * @param rotationCenter The rotation center * @param translation An additional translation on top of the translation caused by the rotation around the rotation center + * @param duration The duration in milliseconds + * @param wait When false, start the animation and continue (asynchronous). When true, start the animation and wait for the animation to finish (synchronous) */ void View3DInventorViewer::startAnimation(const SbRotation& orientation, - const SbVec3f& rotationCenter, const SbVec3f& translation, bool wait) + const SbVec3f& rotationCenter, + const SbVec3f& translation, + int duration, + bool wait) { // Currently starts a FixedTimeAnimation. If there is going to be an additional animation like // FixedVelocityAnimation, check the animation type from a parameter and start the right animation - int duration = App::GetApplication() + // Duration was not set or is invalid so use the AnimationDuration parameter as default + if (duration < 0) { + duration = App::GetApplication() .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") ->GetInt("AnimationDuration", 250); + } auto animation = std::make_shared( navigation, orientation, rotationCenter, translation, duration); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 85441f11b836..11c3346d6377 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -165,7 +165,7 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi SbBool isPopupMenuEnabled() const; void startAnimation(const SbRotation& orientation, const SbVec3f& rotationCenter, - const SbVec3f& translation, bool wait = false); + const SbVec3f& translation, int duration = -1, bool wait = false); void startSpinningAnimation(const SbVec3f& axis, float velocity); void stopAnimating(); SbBool isAnimating() const; @@ -377,7 +377,7 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi */ void setCameraOrientation(const SbRotation& orientation, SbBool moveToCenter = false); void setCameraType(SoType t) override; - void moveCameraTo(const SbRotation& orientation, const SbVec3f& position); + void moveCameraTo(const SbRotation& orientation, const SbVec3f& position, int duration = -1); /** * Zooms the viewport to the size of the bounding box. */ diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 7e36f8b4a32b..b15f2c180393 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -778,7 +778,9 @@ Py::Object View3DInventorPy::getCameraOrientation() Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) { PyObject* p = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "|O!", &Base::PlacementPy::Type, &p)) + int steps; // Unused but kept as parameter to not break the Python interface + int duration = -1; // Duration in ms, will be replaced with User parameter:BaseApp/Preferences/View/AnimationDuration when not explicitly provided + if (!PyArg_ParseTuple(args.ptr(), "|O!ii", &Base::PlacementPy::Type, &p, &steps, &duration)) throw Py::Exception(); if (p) { @@ -789,7 +791,7 @@ Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) rot.getValue(q0,q1,q2,q3); getView3DIventorPtr()->getViewer()->moveCameraTo( SbRotation((float)q0, (float)q1, (float)q2, (float)q3), - SbVec3f((float)pos.x, (float)pos.y, (float)pos.z)); + SbVec3f((float)pos.x, (float)pos.y, (float)pos.z), duration); } SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();