Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:31

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 DEFINE_STANDARD_HANDLE(ViewerTest_EventManager, Standard_Transient)
0028 
0029 //! used to manage mouse event (move,select)
0030 //! By default the events are transmitted to interactive context.
0031 class ViewerTest_EventManager : public Standard_Transient, public AIS_ViewController
0032 {
0033   DEFINE_STANDARD_RTTIEXT(ViewerTest_EventManager, Standard_Transient)
0034 public:
0035 
0036   //! Return TRUE if View should be closed on escape.
0037   static Standard_Boolean& ToCloseViewOnEscape()
0038   {
0039     static Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
0040     return Draw_ToCloseViewOnEsc;
0041   }
0042 
0043   //! Return TRUE if Draw Harness should exit on closing View.
0044   static Standard_Boolean& ToExitOnCloseView()
0045   {
0046     static Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
0047     return Draw_ToExitOnCloseView;
0048   }
0049 
0050   //! Use global camera animation object shared across all Views in ViewerTest.
0051   Standard_EXPORT static const Handle(AIS_AnimationCamera)& GlobalViewAnimation();
0052 
0053 public:
0054 
0055   //! Main constructor.
0056   Standard_EXPORT ViewerTest_EventManager(const Handle(V3d_View)& aView, const Handle(AIS_InteractiveContext)& aCtx);
0057 
0058   //! Destructor.
0059   Standard_EXPORT virtual ~ViewerTest_EventManager();
0060 
0061   //! Setup or adjust window callbacks.
0062   Standard_EXPORT static void SetupWindowCallbacks (const Handle(Aspect_Window)& theWin);
0063 
0064   //! Return interactive context.
0065   const Handle(AIS_InteractiveContext)& Context() const { return myCtx; }
0066 
0067   //! Returns TRUE if picking point mode has been enabled (for VPick command).
0068   Standard_Boolean ToPickPoint() const { return myToPickPnt; }
0069 
0070   //! Start picking point for VPick command.
0071   void StartPickPoint (const char* theArgX,
0072                        const char* theArgY,
0073                        const char* theArgZ)
0074   {
0075     myToPickPnt = Standard_True;
0076     myPickPntArgVec[0] = theArgX;
0077     myPickPntArgVec[1] = theArgY;
0078     myPickPntArgVec[2] = theArgZ;
0079   }
0080 
0081   //! Update mouse scroll event.
0082   Standard_EXPORT virtual bool UpdateMouseScroll (const Aspect_ScrollDelta& theDelta) Standard_OVERRIDE;
0083 
0084   //! Handle mouse button click event.
0085   Standard_EXPORT virtual bool UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
0086                                                   Aspect_VKeyMouse theButton,
0087                                                   Aspect_VKeyFlags theModifiers,
0088                                                   bool theIsDoubleClick) Standard_OVERRIDE;
0089 
0090   //! Handle mouse button press/release event.
0091   Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
0092                                                    Aspect_VKeyMouse theButtons,
0093                                                    Aspect_VKeyFlags theModifiers,
0094                                                    bool theIsEmulated) Standard_OVERRIDE;
0095 
0096   //! Release key.
0097   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
0098                                         double theTime,
0099                                         double thePressure = 1.0) Standard_OVERRIDE;
0100 
0101   //! Release key.
0102   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
0103                                       double theTime) Standard_OVERRIDE;
0104 
0105   //! Redraw the View on an Expose Event
0106   Standard_EXPORT virtual void ProcessExpose() Standard_OVERRIDE;
0107 
0108   //! Handle redraw.
0109   Standard_EXPORT virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
0110                                                  const Handle(V3d_View)& theView) Standard_OVERRIDE;
0111 
0112   //! Resize View.
0113   Standard_EXPORT virtual void ProcessConfigure (bool theIsResized = true) Standard_OVERRIDE;
0114 
0115   //! Handle window input event immediately (flush input buffer).
0116   Standard_EXPORT virtual void ProcessInput() Standard_OVERRIDE;
0117 
0118   //! Handle KeyPress event.
0119   Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey);
0120 
0121   //! Callback called on Selection of another (sub)view.
0122   //! This method is expected to be called from rendering thread.
0123   Standard_EXPORT virtual void OnSubviewChanged (const Handle(AIS_InteractiveContext)& theCtx,
0124                                                  const Handle(V3d_View)& theOldView,
0125                                                  const Handle(V3d_View)& theNewView) Standard_OVERRIDE;
0126 
0127 protected:
0128 
0129   //! Register hot-keys for specified Action.
0130   void addActionHotKeys (Aspect_VKey theAction,
0131                          unsigned int theHotKey1 = 0,
0132                          unsigned int theHotKey2 = 0,
0133                          unsigned int theHotKey3 = 0,
0134                          unsigned int theHotKey4 = 0,
0135                          unsigned int theHotKey5 = 0)
0136   {
0137     if (theHotKey1 != 0) { myNavKeyMap.Bind (theHotKey1, theAction); }
0138     if (theHotKey2 != 0) { myNavKeyMap.Bind (theHotKey2, theAction); }
0139     if (theHotKey3 != 0) { myNavKeyMap.Bind (theHotKey3, theAction); }
0140     if (theHotKey4 != 0) { myNavKeyMap.Bind (theHotKey4, theAction); }
0141     if (theHotKey5 != 0) { myNavKeyMap.Bind (theHotKey5, theAction); }
0142   }
0143 
0144   //! Handle modifier key changes.
0145   Standard_EXPORT bool navigationKeyModifierSwitch (unsigned int theModifOld,
0146                                                     unsigned int theModifNew,
0147                                                     double       theTimeStamp);
0148 
0149 private:
0150 
0151 #if defined(__EMSCRIPTEN__)
0152   //! Callback flushing events and redrawing the WebGL canvas.
0153   static void onWasmRedrawView (void* );
0154 #endif
0155 
0156 private:
0157 
0158   Handle(AIS_InteractiveContext) myCtx;
0159   Handle(V3d_View) myView;
0160   NCollection_DataMap<unsigned int, Aspect_VKey> myNavKeyMap; //!< map of Hot-Key (key+modifiers) to Action
0161 
0162   TCollection_AsciiString myPickPntArgVec[3];
0163   Standard_Boolean myToPickPnt;
0164   Standard_Boolean myIsTmpContRedraw;
0165 
0166   unsigned int     myNbUpdateRequests; //!< counter for unhandled update requests
0167 
0168 };
0169 
0170 #endif // _ViewerTest_EventManager_HeaderFile