Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:19:33

0001 // Created on: 1998-08-27
0002 // Created by: Robert COUBLANC
0003 // Copyright (c) 1998-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _ViewerTest_EventManager_HeaderFile
0018 #define _ViewerTest_EventManager_HeaderFile
0019 
0020 #include <AIS_ViewController.hxx>
0021 #include <TCollection_AsciiString.hxx>
0022 
0023 class AIS_InteractiveContext;
0024 class Aspect_Window;
0025 class V3d_View;
0026 
0027 //! used to manage mouse event (move,select)
0028 //! By default the events are transmitted to interactive context.
0029 class ViewerTest_EventManager : public Standard_Transient, public AIS_ViewController
0030 {
0031   DEFINE_STANDARD_RTTIEXT(ViewerTest_EventManager, Standard_Transient)
0032 public:
0033   //! Return TRUE if View should be closed on escape.
0034   static bool& ToCloseViewOnEscape()
0035   {
0036     static bool Draw_ToCloseViewOnEsc = false;
0037     return Draw_ToCloseViewOnEsc;
0038   }
0039 
0040   //! Return TRUE if Draw Harness should exit on closing View.
0041   static bool& ToExitOnCloseView()
0042   {
0043     static bool Draw_ToExitOnCloseView = false;
0044     return Draw_ToExitOnCloseView;
0045   }
0046 
0047   //! Use global camera animation object shared across all Views in ViewerTest.
0048   Standard_EXPORT static const occ::handle<AIS_AnimationCamera>& GlobalViewAnimation();
0049 
0050 public:
0051   //! Main constructor.
0052   Standard_EXPORT ViewerTest_EventManager(const occ::handle<V3d_View>&               aView,
0053                                           const occ::handle<AIS_InteractiveContext>& aCtx);
0054 
0055   //! Destructor.
0056   Standard_EXPORT ~ViewerTest_EventManager() override;
0057 
0058   //! Setup or adjust window callbacks.
0059   Standard_EXPORT static void SetupWindowCallbacks(const occ::handle<Aspect_Window>& theWin);
0060 
0061   //! Return interactive context.
0062   const occ::handle<AIS_InteractiveContext>& Context() const { return myCtx; }
0063 
0064   //! Returns TRUE if picking point mode has been enabled (for VPick command).
0065   bool ToPickPoint() const { return myToPickPnt; }
0066 
0067   //! Start picking point for VPick command.
0068   void StartPickPoint(const char* theArgX, const char* theArgY, const char* theArgZ)
0069   {
0070     myToPickPnt        = true;
0071     myPickPntArgVec[0] = theArgX;
0072     myPickPntArgVec[1] = theArgY;
0073     myPickPntArgVec[2] = theArgZ;
0074   }
0075 
0076   //! Update mouse scroll event.
0077   Standard_EXPORT bool UpdateMouseScroll(const Aspect_ScrollDelta& theDelta) override;
0078 
0079   //! Handle mouse button click event.
0080   Standard_EXPORT bool UpdateMouseClick(const NCollection_Vec2<int>& thePoint,
0081                                         Aspect_VKeyMouse             theButton,
0082                                         Aspect_VKeyFlags             theModifiers,
0083                                         bool                         theIsDoubleClick) override;
0084 
0085   //! Handle mouse button press/release event.
0086   Standard_EXPORT bool UpdateMouseButtons(const NCollection_Vec2<int>& thePoint,
0087                                           Aspect_VKeyMouse             theButtons,
0088                                           Aspect_VKeyFlags             theModifiers,
0089                                           bool                         theIsEmulated) override;
0090 
0091   //! Release key.
0092   Standard_EXPORT void KeyDown(Aspect_VKey theKey,
0093                                double      theTime,
0094                                double      thePressure = 1.0) override;
0095 
0096   //! Release key.
0097   Standard_EXPORT void KeyUp(Aspect_VKey theKey, double theTime) override;
0098 
0099   //! Redraw the View on an Expose Event
0100   Standard_EXPORT void ProcessExpose() override;
0101 
0102   //! Handle redraw.
0103   Standard_EXPORT void handleViewRedraw(const occ::handle<AIS_InteractiveContext>& theCtx,
0104                                         const occ::handle<V3d_View>& theView) override;
0105 
0106   //! Resize View.
0107   Standard_EXPORT void ProcessConfigure(bool theIsResized = true) override;
0108 
0109   //! Handle window input event immediately (flush input buffer).
0110   Standard_EXPORT void ProcessInput() override;
0111 
0112   //! Handle KeyPress event.
0113   Standard_EXPORT void ProcessKeyPress(Aspect_VKey theKey);
0114 
0115   //! Callback called on Selection of another (sub)view.
0116   //! This method is expected to be called from rendering thread.
0117   Standard_EXPORT void OnSubviewChanged(const occ::handle<AIS_InteractiveContext>& theCtx,
0118                                         const occ::handle<V3d_View>&               theOldView,
0119                                         const occ::handle<V3d_View>& theNewView) override;
0120 
0121 protected:
0122   //! Register hot-keys for specified Action.
0123   void addActionHotKeys(Aspect_VKey  theAction,
0124                         unsigned int theHotKey1 = 0,
0125                         unsigned int theHotKey2 = 0,
0126                         unsigned int theHotKey3 = 0,
0127                         unsigned int theHotKey4 = 0,
0128                         unsigned int theHotKey5 = 0)
0129   {
0130     if (theHotKey1 != 0)
0131     {
0132       myNavKeyMap.Bind(theHotKey1, theAction);
0133     }
0134     if (theHotKey2 != 0)
0135     {
0136       myNavKeyMap.Bind(theHotKey2, theAction);
0137     }
0138     if (theHotKey3 != 0)
0139     {
0140       myNavKeyMap.Bind(theHotKey3, theAction);
0141     }
0142     if (theHotKey4 != 0)
0143     {
0144       myNavKeyMap.Bind(theHotKey4, theAction);
0145     }
0146     if (theHotKey5 != 0)
0147     {
0148       myNavKeyMap.Bind(theHotKey5, theAction);
0149     }
0150   }
0151 
0152   //! Handle modifier key changes.
0153   Standard_EXPORT bool navigationKeyModifierSwitch(unsigned int theModifOld,
0154                                                    unsigned int theModifNew,
0155                                                    double       theTimeStamp);
0156 
0157 private:
0158 #if defined(__EMSCRIPTEN__)
0159   //! Callback flushing events and redrawing the WebGL canvas.
0160   static void onWasmRedrawView(void*);
0161 #endif
0162 
0163 private:
0164   occ::handle<AIS_InteractiveContext> myCtx;
0165   occ::handle<V3d_View>               myView;
0166   // clang-format off
0167   NCollection_DataMap<unsigned int, Aspect_VKey> myNavKeyMap; //!< map of Hot-Key (key+modifiers) to Action
0168   // clang-format on
0169 
0170   TCollection_AsciiString myPickPntArgVec[3];
0171   bool                    myToPickPnt;
0172   bool                    myIsTmpContRedraw;
0173 
0174   unsigned int myNbUpdateRequests; //!< counter for unhandled update requests
0175 };
0176 
0177 #endif // _ViewerTest_EventManager_HeaderFile