diff --git a/src/Gui/DemoMode.cpp b/src/Gui/DemoMode.cpp index ce7b07f4d4..e1185b1d21 100644 --- a/src/Gui/DemoMode.cpp +++ b/src/Gui/DemoMode.cpp @@ -180,7 +180,7 @@ void DemoMode::onAngleSliderValueChanged(int v) SbRotation rot(SbVec3f(-1, 0, 0), angle); reorientCamera(cam ,rot); this->oldvalue = v; - if (view->getViewer()->isAnimating()) { + if (view->getViewer()->isSpinning()) { startAnimation(view); } } @@ -206,7 +206,7 @@ void DemoMode::onSpeedSliderValueChanged(int v) { Q_UNUSED(v); Gui::View3DInventor* view = activeView(); - if (view && view->getViewer()->isAnimating()) { + if (view && view->getViewer()->isSpinning()) { startAnimation(view); } } @@ -216,7 +216,7 @@ void DemoMode::onPlayButtonToggled(bool pressed) Gui::View3DInventor* view = activeView(); if (view) { if (pressed) { - if (!view->getViewer()->isAnimating()) { + if (!view->getViewer()->isSpinning()) { SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera(); if (cam) { SbRotation rot = cam->orientation.getValue(); @@ -263,7 +263,7 @@ void DemoMode::onTimeoutValueChanged(int v) void DemoMode::onAutoPlay() { Gui::View3DInventor* view = activeView(); - if (view && !view->getViewer()->isAnimating()) { + if (view && !view->getViewer()->isSpinning()) { ui->playButton->setChecked(true); startAnimation(view); } @@ -271,9 +271,6 @@ void DemoMode::onAutoPlay() void DemoMode::startAnimation(Gui::View3DInventor* view) { - if (!view->getViewer()->isAnimationEnabled()) - view->getViewer()->setAnimationEnabled(true); - view->getViewer()->startSpinningAnimation(getDirection(view), getSpeed(ui->speedSlider->value())); } diff --git a/src/Gui/NavigationAnimator.cpp b/src/Gui/NavigationAnimator.cpp index 4f3a73eff4..6794c64b3a 100644 --- a/src/Gui/NavigationAnimator.cpp +++ b/src/Gui/NavigationAnimator.cpp @@ -90,3 +90,15 @@ void NavigationAnimator::stop() activeAnimation.reset(); } } + +/** + * @return Whether or not an animation is active + */ +bool NavigationAnimator::isAnimating() const +{ + if (activeAnimation != nullptr) { + return activeAnimation->state() == QAbstractAnimation::State::Running; + } + + return false; +} diff --git a/src/Gui/NavigationAnimator.h b/src/Gui/NavigationAnimator.h index e2f7290a1e..8b206acd71 100644 --- a/src/Gui/NavigationAnimator.h +++ b/src/Gui/NavigationAnimator.h @@ -42,6 +42,7 @@ public: void start(const std::shared_ptr& animation); bool startAndWait(const std::shared_ptr& animation); void stop(); + bool isAnimating() const; private: std::shared_ptr activeAnimation; diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 9618b78fa7..bc2bb8a7da 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -176,7 +176,8 @@ NavigationStyle& NavigationStyle::operator = (const NavigationStyle& ns) { this->panningplane = ns.panningplane; this->menuenabled = ns.menuenabled; - this->spinanimatingallowed = ns.spinanimatingallowed; + this->animationEnabled = ns.animationEnabled; + this->spinningAnimationEnabled = ns.spinningAnimationEnabled; static_cast(this->spinprojector)->setOrbitStyle (static_cast(ns.spinprojector)->getOrbitStyle()); return *this; @@ -194,7 +195,8 @@ void NavigationStyle::initialize() this->sensitivity = 2.0f; this->resetcursorpos = false; this->currentmode = NavigationStyle::IDLE; - this->spinanimatingallowed = true; + this->animationEnabled = true; + this->spinningAnimationEnabled = false; this->spinsamplecounter = 0; this->spinincrement = SbRotation::identity(); this->rotationCenterFound = false; @@ -916,7 +918,7 @@ SbBool NavigationStyle::doSpin() { if (this->log.historysize >= 3) { SbTime stoptime = (SbTime::getTimeOfDay() - this->log.time[0]); - if (this->spinanimatingallowed && stoptime.getValue() < 0.100) { + if (isSpinningAnimationEnabled() && stoptime.getValue() < 0.100) { const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); const SbVec2s glsize(vp.getViewportSizePixels()); SbVec3f from = this->spinprojector->project(SbVec2f(float(this->log.position[2][0]) / float(std::max(glsize[0]-1, 1)), @@ -1061,38 +1063,62 @@ SbBool NavigationStyle::handleEventInForeground(const SoEvent* const e) return action.isHandled(); } -/*! - Decide if it should be possible to start a spin animation of the - model in the viewer by releasing the mouse button while dragging. - - If the \a enable flag is \c false and we're currently animating, the - spin will be stopped. -*/ -void -NavigationStyle::setAnimationEnabled(const SbBool enable) +/** + * @brief Decide if it should be possible to start any animation + * + * If the enable flag is false and we're currently animating, the animation will be stopped + */ +void NavigationStyle::setAnimationEnabled(const SbBool enable) { - this->spinanimatingallowed = enable; - if (!enable && this->isAnimating()) { animator->stop(); } + animationEnabled = enable; + if (!enable && isAnimating()) { + animator->stop(); + } } -/*! - Query whether or not it is possible to start a spinning animation by - releasing the left mouse button while dragging the mouse. -*/ - -SbBool -NavigationStyle::isAnimationEnabled() const +/** + * @brief Decide if it should be possible to start a spin animation of the model in the viewer by releasing the mouse button while dragging + * + * If the enable flag is false and we're currently animating, the spin animation will be stopped + */ +void NavigationStyle::setSpinningAnimationEnabled(const SbBool enable) { - return this->spinanimatingallowed; + spinningAnimationEnabled = enable; + if (!enable && isSpinning()) { + animator->stop(); + } } -/*! - Query if the model in the viewer is currently in spinning mode after - a user drag. -*/ +/** + * @return Whether or not it is possible to start any animation + */ +SbBool NavigationStyle::isAnimationEnabled() const +{ + return animationEnabled; +} + +/** + * @return Whether or not it is possible to start a spinning animation e.g. after dragging + */ +SbBool NavigationStyle::isSpinningAnimationEnabled() const +{ + return animationEnabled && spinningAnimationEnabled; +} + +/** + * @return Whether or not any animation is currently active + */ SbBool NavigationStyle::isAnimating() const { - return this->currentmode == NavigationStyle::SPINNING; + return animator->isAnimating(); +} + +/** + * @return Whether or not a spinning animation is currently active e.g. after a user drag + */ +SbBool NavigationStyle::isSpinning() const +{ + return currentmode == NavigationStyle::SPINNING; } void NavigationStyle::startAnimating(const std::shared_ptr& animation, bool wait) const diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 12c5e4a00d..e3e22e4761 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -123,9 +123,11 @@ public: void setViewer(View3DInventorViewer*); void setAnimationEnabled(const SbBool enable); + void setSpinningAnimationEnabled(const SbBool enable); SbBool isAnimationEnabled() const; - + SbBool isSpinningAnimationEnabled() const; SbBool isAnimating() const; + SbBool isSpinning() const; void startAnimating(const std::shared_ptr& animation, bool wait = false) const; void stopAnimating() const; @@ -242,6 +244,7 @@ protected: View3DInventorViewer* viewer{nullptr}; NavigationAnimator* animator; + SbBool animationEnabled; ViewerMode currentmode; SoMouseButtonEvent mouseDownConsumedEvent; SbVec2f lastmouseposition; @@ -266,7 +269,7 @@ protected: /** @name Spinning data */ //@{ - SbBool spinanimatingallowed; + SbBool spinningAnimationEnabled; int spinsamplecounter; SbRotation spinincrement; SbSphereSheetProjector * spinprojector; diff --git a/src/Gui/PreferencePackTemplates/View.cfg b/src/Gui/PreferencePackTemplates/View.cfg index 708b9b9498..d0837eb5de 100644 --- a/src/Gui/PreferencePackTemplates/View.cfg +++ b/src/Gui/PreferencePackTemplates/View.cfg @@ -33,6 +33,7 @@ + diff --git a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp index 9e307a8816..5ad22a869c 100644 --- a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp +++ b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp @@ -88,8 +88,8 @@ void DlgSettingsNavigation::saveSettings() ui->rotationCenterSize->onSave(); ui->rotationCenterColor->onSave(); ui->spinBoxZoomStep->onSave(); - ui->checkBoxNavigationAnimations->onSave(); ui->spinBoxAnimationDuration->onSave(); + ui->checkBoxSpinningAnimations->onSave(); ui->qspinNewDocScale->onSave(); ui->prefStepByTurn->onSave(); ui->naviCubeCorner->onSave(); @@ -103,6 +103,9 @@ void DlgSettingsNavigation::saveSettings() bool showRotationCenter = ui->groupBoxRotationCenter->isChecked(); hGrp->SetBool("ShowRotationCenter", showRotationCenter); + bool useNavigationAnimations = ui->groupBoxAnimations->isChecked(); + hGrp->SetBool("UseNavigationAnimations", useNavigationAnimations); + QVariant camera = ui->comboNewDocView->itemData(ui->comboNewDocView->currentIndex(), Qt::UserRole); hGrp->SetASCII("NewDocumentCameraOrientation", (const char*)camera.toByteArray()); @@ -130,8 +133,8 @@ void DlgSettingsNavigation::loadSettings() ui->rotationCenterSize->onRestore(); ui->rotationCenterColor->onRestore(); ui->spinBoxZoomStep->onRestore(); - ui->checkBoxNavigationAnimations->onRestore(); ui->spinBoxAnimationDuration->onRestore(); + ui->checkBoxSpinningAnimations->onRestore(); ui->qspinNewDocScale->onRestore(); ui->prefStepByTurn->onRestore(); ui->naviCubeCorner->onRestore(); @@ -158,6 +161,9 @@ void DlgSettingsNavigation::loadSettings() bool showRotationCenter = hGrp->GetBool("ShowRotationCenter", true); ui->groupBoxRotationCenter->setChecked(showRotationCenter); + bool useNavigationAnimations = hGrp->GetBool("UseNavigationAnimations", true); + ui->groupBoxAnimations->setChecked(useNavigationAnimations); + ui->comboNewDocView->addItem(tr("Isometric"), QByteArray("Isometric")); ui->comboNewDocView->addItem(tr("Dimetric"), QByteArray("Dimetric")); ui->comboNewDocView->addItem(tr("Trimetric"), QByteArray("Trimetric")); diff --git a/src/Gui/PreferencePages/DlgSettingsNavigation.ui b/src/Gui/PreferencePages/DlgSettingsNavigation.ui index 3902e04e7a..b7ffc27c6b 100644 --- a/src/Gui/PreferencePages/DlgSettingsNavigation.ui +++ b/src/Gui/PreferencePages/DlgSettingsNavigation.ui @@ -6,8 +6,8 @@ 0 0 - 484 - 586 + 516 + 687 @@ -565,92 +565,6 @@ The value is the diameter of the sphere to fit on the screen. - - - - true - - - Enable navigation animations - - - Enable navigation animations - - - true - - - UseNavigationAnimations - - - View - - - - - - - Duration of navigation animations that have a fixed duration - - - Animation duration - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - 60 - 16777215 - - - - The duration of navigation animations in milliseconds - - - 100 - - - 10000 - - - 50 - - - 250 - - - AnimationDuration - - - View - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 10 - 20 - - - - - - @@ -775,6 +689,94 @@ Mouse tilting is not disabled by this setting. + + + + Animations + + + true + + + + + + Duration of navigation animations that have a fixed duration + + + Animation duration + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 60 + 16777215 + + + + The duration of navigation animations in milliseconds + + + 100 + + + 10000 + + + 50 + + + 250 + + + AnimationDuration + + + View + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Enable spinning animations that are used in some navigation styles after dragging + + + Enable spinning animations + + + false + + + UseSpinningAnimations + + + View + + + + + + diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 734a4f51fe..d0ebdd14c8 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2397,7 +2397,7 @@ void View3DInventorViewer::renderScene() glDepthRange(0.1,1.0); #endif - // Immediately reschedule to get continuous spin animation. + // Immediately reschedule to get continuous animation. if (this->isAnimating()) { this->getSoRenderManager()->scheduleRedraw(); } @@ -3233,39 +3233,58 @@ void View3DInventorViewer::viewSelection() } } -/*! - Decide if it should be possible to start a spin animation of the - model in the viewer by releasing the mouse button while dragging. - - If the \a enable flag is \c false and we're currently animating, the - spin will be stopped. -*/ -void -View3DInventorViewer::setAnimationEnabled(bool enable) +/** + * @brief Decide if it should be possible to start any animation + * + * If the enable flag is false and we're currently animating, the animation will be stopped + */ +void View3DInventorViewer::setAnimationEnabled(bool enable) { navigation->setAnimationEnabled(enable); } -/*! - Query whether or not it is possible to start a spinning animation by - releasing the left mouse button while dragging the mouse. -*/ +/** + * @brief Decide if it should be possible to start a spin animation of the model in the viewer by releasing the mouse button while dragging + * + * If the enable flag is false and we're currently animating, the spin animation will be stopped + */ +void View3DInventorViewer::setSpinningAnimationEnabled(bool enable) +{ + navigation->setSpinningAnimationEnabled(enable); +} -bool -View3DInventorViewer::isAnimationEnabled() const +/** + * @return Whether or not it is possible to start any animation + */ +bool View3DInventorViewer::isAnimationEnabled() const { return navigation->isAnimationEnabled(); } -/*! - Query if the model in the viewer is currently in spinning mode after - a user drag. -*/ +/** + * @return Whether or not it is possible to start a spinning animation e.g. after dragging + */ +bool View3DInventorViewer::isSpinningAnimationEnabled() const +{ + return navigation->isSpinningAnimationEnabled(); +} + +/** + * @return Whether or not any animation is currently active + */ bool View3DInventorViewer::isAnimating() const { return navigation->isAnimating(); } +/** + * @return Whether or not a spinning animation is currently active e.g. after a user drag + */ +bool View3DInventorViewer::isSpinning() const +{ + return navigation->isSpinning(); +} + /** * @brief Change the camera pose with an animation * diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 5d30e65523..58e23fdef0 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -159,16 +159,18 @@ public: bool searchNode(SoNode*) const; void setAnimationEnabled(bool enable); + void setSpinningAnimationEnabled(bool enable); bool isAnimationEnabled() const; - - void setPopupMenuEnabled(bool on); - bool isPopupMenuEnabled() const; - + bool isSpinningAnimationEnabled() const; + bool isAnimating() const; + bool isSpinning() const; void startAnimation(const SbRotation& orientation, const SbVec3f& rotationCenter, const SbVec3f& translation, int duration = -1, bool wait = false); void startSpinningAnimation(const SbVec3f& axis, float velocity); void stopAnimating(); - bool isAnimating() const; + + void setPopupMenuEnabled(bool on); + bool isPopupMenuEnabled() const; void setFeedbackVisibility(bool enable); bool isFeedbackVisible() const; diff --git a/src/Gui/View3DSettings.cpp b/src/Gui/View3DSettings.cpp index f97b32e120..2d0eb0839c 100644 --- a/src/Gui/View3DSettings.cpp +++ b/src/Gui/View3DSettings.cpp @@ -75,6 +75,7 @@ void View3DSettings::applySettings() OnChange(*hGrp,"CornerCoordSystemSize"); OnChange(*hGrp,"ShowAxisCross"); OnChange(*hGrp,"UseNavigationAnimations"); + OnChange(*hGrp,"UseSpinningAnimations"); OnChange(*hGrp,"Gradient"); OnChange(*hGrp,"RadialGradient"); OnChange(*hGrp,"BackgroundColor"); @@ -299,6 +300,11 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M _viewer->setAnimationEnabled(rGrp.GetBool("UseNavigationAnimations", true)); } } + else if (strcmp(Reason,"UseSpinningAnimations") == 0) { + for (auto _viewer : _viewers) { + _viewer->setSpinningAnimationEnabled(rGrp.GetBool("UseSpinningAnimations", false)); + } + } else if (strcmp(Reason,"Gradient") == 0 || strcmp(Reason,"RadialGradient") == 0) { View3DInventorViewer::Background background = View3DInventorViewer::Background::NoGradient; if (rGrp.GetBool("Gradient", true)) {