Skip to content

Commit

Permalink
Gui: Revert breaking Python interface change for viewPosition()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexbas committed Oct 24, 2023
1 parent 9c629bb commit 61e419b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/Gui/View3DInventorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2788,15 +2788,15 @@ 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)
return;

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);
Expand Down Expand Up @@ -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<FixedTimeAnimation>(
navigation, orientation, rotationCenter, translation, duration);
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/View3DInventorViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Gui/View3DPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit 61e419b

Please sign in to comment.