23dfe7dceeb2c03ba56a7fae10e6c031c91ccc26
[occt.git] / src / ViewerTest / ViewerTest_EventManager.hxx
1 // Created on: 1998-08-27
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _ViewerTest_EventManager_HeaderFile
18 #define _ViewerTest_EventManager_HeaderFile
19
20 #include <AIS_ViewController.hxx>
21 #include <TColgp_Array1OfPnt2d.hxx>
22 #include <TCollection_AsciiString.hxx>
23
24 class AIS_InteractiveContext;
25 class Aspect_Window;
26 class V3d_View;
27
28 DEFINE_STANDARD_HANDLE(ViewerTest_EventManager, Standard_Transient)
29
30 //! used to manage mouse event (move,select)
31 //! By default the events are transmitted to interactive context.
32 class ViewerTest_EventManager : public Standard_Transient, public AIS_ViewController
33 {
34   DEFINE_STANDARD_RTTIEXT(ViewerTest_EventManager, Standard_Transient)
35 public:
36
37   //! Return TRUE if View should be closed on escape.
38   static Standard_Boolean& ToCloseViewOnEscape()
39   {
40     static Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
41     return Draw_ToCloseViewOnEsc;
42   }
43
44   //! Return TRUE if Draw Harness should exit on closing View.
45   static Standard_Boolean& ToExitOnCloseView()
46   {
47     static Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
48     return Draw_ToExitOnCloseView;
49   }
50
51   //! Use global camera animation object shared across all Views in ViewerTest.
52   Standard_EXPORT static const Handle(AIS_AnimationCamera)& GlobalViewAnimation();
53
54 public:
55
56   //! Main constructor.
57   Standard_EXPORT ViewerTest_EventManager(const Handle(V3d_View)& aView, const Handle(AIS_InteractiveContext)& aCtx);
58
59   //! Destructor.
60   Standard_EXPORT virtual ~ViewerTest_EventManager();
61
62   //! Setup or adjust window callbacks.
63   Standard_EXPORT static void SetupWindowCallbacks (const Handle(Aspect_Window)& theWin);
64
65   //! Return interactive context.
66   const Handle(AIS_InteractiveContext)& Context() const { return myCtx; }
67
68   //! Returns TRUE if picking point mode has been enabled (for VPick command).
69   Standard_Boolean ToPickPoint() const { return myToPickPnt; }
70
71   //! Start picking point for VPick command.
72   void StartPickPoint (const char* theArgX,
73                        const char* theArgY,
74                        const char* theArgZ)
75   {
76     myToPickPnt = Standard_True;
77     myPickPntArgVec[0] = theArgX;
78     myPickPntArgVec[1] = theArgY;
79     myPickPntArgVec[2] = theArgZ;
80   }
81
82   //! Handle mouse button click event.
83   Standard_EXPORT virtual bool UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
84                                                   Aspect_VKeyMouse theButton,
85                                                   Aspect_VKeyFlags theModifiers,
86                                                   bool theIsDoubleClick) Standard_OVERRIDE;
87
88   //! Handle mouse button press/release event.
89   Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
90                                                    Aspect_VKeyMouse theButtons,
91                                                    Aspect_VKeyFlags theModifiers,
92                                                    bool theIsEmulated) Standard_OVERRIDE;
93
94   //! Release key.
95   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
96                                         double theTime,
97                                         double thePressure = 1.0) Standard_OVERRIDE;
98
99   //! Release key.
100   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
101                                       double theTime) Standard_OVERRIDE;
102
103   //! Redraw the View on an Expose Event
104   Standard_EXPORT virtual void ProcessExpose() Standard_OVERRIDE;
105
106   //! Handle redraw.
107   Standard_EXPORT virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
108                                                  const Handle(V3d_View)& theView) Standard_OVERRIDE;
109
110   //! Resize View.
111   Standard_EXPORT virtual void ProcessConfigure (bool theIsResized = true) Standard_OVERRIDE;
112
113   //! Handle window input event immediately (flush input buffer).
114   Standard_EXPORT virtual void ProcessInput() Standard_OVERRIDE;
115
116   //! Handle KeyPress event.
117   Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey);
118
119 protected:
120
121   //! Register hot-keys for specified Action.
122   void addActionHotKeys (Aspect_VKey theAction,
123                          unsigned int theHotKey1 = 0,
124                          unsigned int theHotKey2 = 0,
125                          unsigned int theHotKey3 = 0,
126                          unsigned int theHotKey4 = 0,
127                          unsigned int theHotKey5 = 0)
128   {
129     if (theHotKey1 != 0) { myNavKeyMap.Bind (theHotKey1, theAction); }
130     if (theHotKey2 != 0) { myNavKeyMap.Bind (theHotKey2, theAction); }
131     if (theHotKey3 != 0) { myNavKeyMap.Bind (theHotKey3, theAction); }
132     if (theHotKey4 != 0) { myNavKeyMap.Bind (theHotKey4, theAction); }
133     if (theHotKey5 != 0) { myNavKeyMap.Bind (theHotKey5, theAction); }
134   }
135
136   //! Handle modifier key changes.
137   Standard_EXPORT bool navigationKeyModifierSwitch (unsigned int theModifOld,
138                                                     unsigned int theModifNew,
139                                                     double       theTimeStamp);
140
141 private:
142
143   Handle(AIS_InteractiveContext) myCtx;
144   Handle(V3d_View) myView;
145   NCollection_DataMap<unsigned int, Aspect_VKey> myNavKeyMap; //!< map of Hot-Key (key+modifiers) to Action
146
147   TCollection_AsciiString myPickPntArgVec[3];
148   Standard_Boolean myToPickPnt;
149   Standard_Boolean myIsTmpContRedraw;
150
151   unsigned int     myUpdateRequests; //!< counter for unhandled update requests
152
153 };
154
155 #endif // _ViewerTest_EventManager_HeaderFile