Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:16:26

0001 // Copyright (c) 2019-2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _ViewerTest_ContinuousRedrawer_HeaderFile
0015 #define _ViewerTest_ContinuousRedrawer_HeaderFile
0016 
0017 #include <OSD_Thread.hxx>
0018 #include <Standard_Condition.hxx>
0019 #include <Standard_Type.hxx>
0020 
0021 #include <mutex>
0022 
0023 class V3d_View;
0024 
0025 //! Auxiliary tool performing continuous redraws of specified window.
0026 //! Tool creates an extra working thread pushing content invalidation messages to specific window
0027 //! using Aspect_Window::InvalidateContent() method. Normally, GUI application should done
0028 //! continuous rendering in simple fashion - just by drawing next frame without waiting for new
0029 //! events from windowing system; however, implementation of this approach is problematic in context
0030 //! of ViewerTest due to message loop binding mechanism implied by Tcl/Tk.
0031 class ViewerTest_ContinuousRedrawer
0032 {
0033 public:
0034   //! Return global instance.
0035   Standard_EXPORT static ViewerTest_ContinuousRedrawer& Instance();
0036 
0037 public:
0038   //! Destructor.
0039   Standard_EXPORT ~ViewerTest_ContinuousRedrawer();
0040 
0041   //! Return TRUE if redrawer thread is started.
0042   bool IsStarted() const { return myThread.GetId() != 0; }
0043 
0044   //! Start thread.
0045   Standard_EXPORT void Start(const occ::handle<V3d_View>& theView, double theTargetFps);
0046 
0047   //! Stop thread.
0048   Standard_EXPORT void Stop(const occ::handle<V3d_View>& theView = nullptr);
0049 
0050   //! Return TRUE if redrawer thread is in paused state.
0051   bool IsPaused() const { return myToPause; }
0052 
0053   //! Pause working thread, but does not terminate it.
0054   Standard_EXPORT void Pause();
0055 
0056 private:
0057   //! Thread loop.
0058   void doThreadLoop();
0059 
0060   //! Thread creation callback.
0061   static void* doThreadWrapper(void* theData)
0062   {
0063     ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer*)theData;
0064     aThis->doThreadLoop();
0065     return nullptr;
0066   }
0067 
0068   //! Empty constructor.
0069   ViewerTest_ContinuousRedrawer();
0070 
0071 private:
0072   occ::handle<V3d_View> myView;      //!< view to invalidate
0073   OSD_Thread            myThread;    //!< working thread
0074   std::mutex            myMutex;     //!< mutex for accessing common variables
0075   Standard_Condition    myWakeEvent; //!< event to wake up working thread
0076   double                myTargetFps; //!< desired update framerate
0077   volatile bool         myToStop;    //!< flag to stop working thread
0078   volatile bool         myToPause;   //!< flag to put  working thread asleep without stopping
0079 };
0080 
0081 #endif // _ViewerTest_ContinuousRedrawer_HeaderFile