Gui: Revert breaking Python interface change for viewPosition()

This commit is contained in:
Rexbas
2023-10-24 20:32:47 +02:00
committed by wwmayer
parent 3a4fdbb3fd
commit a2c2bf5a4b
3 changed files with 18 additions and 8 deletions

View File

@@ -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<FixedTimeAnimation>(
navigation, orientation, rotationCenter, translation, duration);

View File

@@ -165,7 +165,7 @@ public:
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 @@ public:
*/
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.
*/

View File

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