diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index 009d7ce651..76b04e285b 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -37,6 +37,7 @@ AIS_ViewController::AIS_ViewController() : myLastEventsTime (0.0), myToAskNextFrame (false), + myIsContinuousRedraw(false), myMinCamDistance (1.0), myRotationMode (AIS_RotationMode_BndBoxActive), myNavigationMode (AIS_NavigationMode_Orbit), @@ -2943,6 +2944,10 @@ void AIS_ViewController::handleViewRedraw (const Handle(AIS_InteractiveContext)& setAskNextFrame(); } + if (myIsContinuousRedraw) + { + myToAskNextFrame = true; + } if (theView->View()->IsActiveXR()) { // VR requires continuous rendering diff --git a/src/AIS/AIS_ViewController.hxx b/src/AIS/AIS_ViewController.hxx index 8187275546..7d8e0fc50d 100644 --- a/src/AIS/AIS_ViewController.hxx +++ b/src/AIS/AIS_ViewController.hxx @@ -77,6 +77,13 @@ public: //! Interrupt active view animation. Standard_EXPORT void AbortViewAnimation(); + //! Return TRUE if continuous redrawing is enabled; FALSE by default. + //! This option would request a next viewer frame to be completely redrawn right after current frame is finished. + bool IsContinuousRedraw() const { return myIsContinuousRedraw; } + + //! Enable or disable continuous updates. + void SetContinuousRedraw (bool theToEnable) { myIsContinuousRedraw = theToEnable; } + public: //! @name global parameters //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default. @@ -679,6 +686,7 @@ protected: Standard_Real myLastEventsTime; //!< last fetched events timer value for computing delta/progress Standard_Boolean myToAskNextFrame; //!< flag indicating that another frame should be drawn right after this one + Standard_Boolean myIsContinuousRedraw; //!< continuous redrawing (without immediate rendering optimization) Standard_Real myMinCamDistance; //!< minimal camera distance for zoom operation AIS_RotationMode myRotationMode; //!< rotation mode diff --git a/src/ViewerTest/ViewerTest_ContinuousRedrawer.cxx b/src/ViewerTest/ViewerTest_ContinuousRedrawer.cxx index 40fe4feeb5..b134db5996 100644 --- a/src/ViewerTest/ViewerTest_ContinuousRedrawer.cxx +++ b/src/ViewerTest/ViewerTest_ContinuousRedrawer.cxx @@ -17,6 +17,7 @@ #include #include #include +#include // ======================================================================= // function : Instance @@ -55,14 +56,14 @@ ViewerTest_ContinuousRedrawer::~ViewerTest_ContinuousRedrawer() // function : Start // purpose : // ======================================================================= -void ViewerTest_ContinuousRedrawer::Start (const Handle(Aspect_Window)& theWindow, +void ViewerTest_ContinuousRedrawer::Start (const Handle(V3d_View)& theView, Standard_Real theTargetFps) { - if (myWindow != theWindow + if (myView != theView || myTargetFps != theTargetFps) { Stop(); - myWindow = theWindow; + myView = theView; myTargetFps = theTargetFps; } @@ -84,13 +85,13 @@ void ViewerTest_ContinuousRedrawer::Start (const Handle(Aspect_Window)& theWindo } // ======================================================================= -// function : Start +// function : Stop // purpose : // ======================================================================= -void ViewerTest_ContinuousRedrawer::Stop (const Handle(Aspect_Window)& theWindow) +void ViewerTest_ContinuousRedrawer::Stop (const Handle(V3d_View)& theView) { - if (!theWindow.IsNull() - && myWindow != theWindow) + if (!theView.IsNull() + && myView != theView) { return; } @@ -103,11 +104,11 @@ void ViewerTest_ContinuousRedrawer::Stop (const Handle(Aspect_Window)& theWindow myWakeEvent.Set(); myThread.Wait(); myToStop = false; - myWindow.Nullify(); + myView.Nullify(); } // ======================================================================= -// function : doThreadLoop +// function : Pause // purpose : // ======================================================================= void ViewerTest_ContinuousRedrawer::Pause() @@ -153,13 +154,15 @@ void ViewerTest_ContinuousRedrawer::doThreadLoop() const Standard_Real aDuration = aTimeNew - aTimeOld; if (aDuration >= aTargetDur) { - myWindow->InvalidateContent (aDisp); + myView->Invalidate(); + myView->Window()->InvalidateContent (aDisp); aTimeOld = aTimeNew; } } else { - myWindow->InvalidateContent (aDisp); + myView->Invalidate(); + myView->Window()->InvalidateContent (aDisp); } OSD::MilliSecSleep (1); diff --git a/src/ViewerTest/ViewerTest_ContinuousRedrawer.hxx b/src/ViewerTest/ViewerTest_ContinuousRedrawer.hxx index 5b15ed1ff2..4b2d2b7479 100644 --- a/src/ViewerTest/ViewerTest_ContinuousRedrawer.hxx +++ b/src/ViewerTest/ViewerTest_ContinuousRedrawer.hxx @@ -20,6 +20,7 @@ #include class Aspect_Window; +class V3d_View; //! Auxiliary tool performing continuous redraws of specified window. //! Tool creates an extra working thread pushing content invalidation messages to specific window using Aspect_Window::InvalidateContent() method. @@ -39,11 +40,11 @@ public: bool IsStarted() const { return myThread.GetId() != 0; } //! Start thread. - Standard_EXPORT void Start (const Handle(Aspect_Window)& theWindow, + Standard_EXPORT void Start (const Handle(V3d_View)& theView, Standard_Real theTargetFps); //! Stop thread. - Standard_EXPORT void Stop (const Handle(Aspect_Window)& theWindow = NULL); + Standard_EXPORT void Stop (const Handle(V3d_View)& theView = NULL); //! Return TRUE if redrawer thread is in paused state. bool IsPaused() const { return myToPause; } @@ -68,7 +69,7 @@ private: ViewerTest_ContinuousRedrawer(); private: - Handle(Aspect_Window) myWindow; //!< window to invalidate + Handle(V3d_View) myView; //!< view to invalidate OSD_Thread myThread; //!< working thread Standard_Mutex myMutex; //!< mutex for accessing common variables Standard_Condition myWakeEvent; //!< event to wake up working thread diff --git a/src/ViewerTest/ViewerTest_EventManager.cxx b/src/ViewerTest/ViewerTest_EventManager.cxx index 4e8673be5a..e22e72981b 100644 --- a/src/ViewerTest/ViewerTest_EventManager.cxx +++ b/src/ViewerTest/ViewerTest_EventManager.cxx @@ -197,7 +197,7 @@ void ViewerTest_EventManager::handleViewRedraw (const Handle(AIS_InteractiveCont { myIsTmpContRedraw = true; #if !defined(_WIN32) && !defined(__EMSCRIPTEN__) - aRedrawer.Start (theView->Window(), 60.0); + aRedrawer.Start (theView, 60.0); #endif } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 534f07e332..67870df603 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -2668,7 +2668,7 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); - aRedrawer.Stop (aView->Window()); + aRedrawer.Stop (aView); // Remove view resources ViewerTest_myViews.UnBind1(theViewName); @@ -2683,7 +2683,7 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S // unused empty contexts if (!aCurrentContext.IsNull()) { - // Check if there are more difined views in the viewer + // Check if there are more defined views in the viewer if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && aCurrentContext->CurrentViewer()->DefinedViews().IsEmpty()) { @@ -3703,9 +3703,21 @@ static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** } ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); - if (Abs (aFps) >= 1.0) + ViewerTest::CurrentEventManager()->SetContinuousRedraw (false); + if (aFps >= 1.0) { - aRedrawer.Start (aView->Window(), aFps); + aRedrawer.Start (aView, aFps); + } + else if (aFps < 0.0) + { + if (ViewerTest::GetViewerFromContext()->ActiveViews().Extent() == 1) + { + aRedrawer.Stop(); + ViewerTest::CurrentEventManager()->SetContinuousRedraw (true); + ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); + continue; + } + aRedrawer.Start (aView, aFps); } else {