0031984: Modeling Algorithms - Sweep crashes if Bi-normal is given
[occt.git] / src / AIS / AIS_ViewController.hxx
1 // Copyright (c) 2016-2019 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _AIS_ViewController_HeaderFile
15 #define _AIS_ViewController_HeaderFile
16
17 #include <Aspect_VKeySet.hxx>
18 #include <Aspect_TouchMap.hxx>
19 #include <Aspect_XRHapticActionData.hxx>
20 #include <Aspect_XRTrackedDeviceRole.hxx>
21 #include <AIS_DragAction.hxx>
22 #include <AIS_MouseGesture.hxx>
23 #include <AIS_NavigationMode.hxx>
24 #include <AIS_ViewInputBuffer.hxx>
25 #include <AIS_RotationMode.hxx>
26 #include <AIS_WalkDelta.hxx>
27
28 #include <gp_Pnt.hxx>
29 #include <Graphic3d_Vec3.hxx>
30 #include <NCollection_Array1.hxx>
31 #include <OSD_Timer.hxx>
32 #include <Precision.hxx>
33 #include <Quantity_ColorRGBA.hxx>
34 #include <Standard_Mutex.hxx>
35
36 class AIS_AnimationCamera;
37 class AIS_InteractiveObject;
38 class AIS_InteractiveContext;
39 class AIS_Point;
40 class AIS_RubberBand;
41 class AIS_XRTrackedDevice;
42 class Graphic3d_Camera;
43 class SelectMgr_EntityOwner;
44 class V3d_View;
45 class WNT_HIDSpaceMouse;
46
47 //! Auxiliary structure for handling viewer events between GUI and Rendering threads.
48 //!
49 //! Class implements the following features:
50 //! - Buffers storing the state of user input (mouse, touches and keyboard).
51 //! - Mapping mouse/multi-touch input to View camera manipulations (panning/rotating/zooming).
52 //! - Input events are not applied immediately but queued for separate processing from two working threads
53 //!   UI thread receiving user input and Rendering thread for OCCT 3D Viewer drawing.
54 class AIS_ViewController
55 {
56 public:
57
58   //! Empty constructor.
59   Standard_EXPORT AIS_ViewController();
60
61   //! Destructor.
62   Standard_EXPORT virtual ~AIS_ViewController();
63
64   //! Return input buffer.
65   const AIS_ViewInputBuffer& InputBuffer (AIS_ViewInputBufferType theType) const { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
66
67   //! Return input buffer.
68   AIS_ViewInputBuffer& ChangeInputBuffer (AIS_ViewInputBufferType theType)       { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
69
70   //! Return view animation; empty (but not NULL) animation by default.
71   const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; }
72
73   //! Set view animation to be handled within handleViewRedraw().
74   void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; }
75
76   //! Interrupt active view animation.
77   Standard_EXPORT void AbortViewAnimation();
78
79 public: //! @name global parameters
80
81   //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default.
82   AIS_RotationMode RotationMode() const { return myRotationMode; }
83
84   //! Set camera rotation mode.
85   void SetRotationMode (AIS_RotationMode theMode) { myRotationMode = theMode; }
86
87   //! Return camera navigation mode; AIS_NavigationMode_Orbit by default.
88   AIS_NavigationMode NavigationMode() const { return myNavigationMode; }
89
90   //! Set camera navigation mode.
91   Standard_EXPORT void SetNavigationMode (AIS_NavigationMode theMode);
92
93   //! Return mouse input acceleration ratio in First Person mode; 1.0 by default.
94   float MouseAcceleration() const { return myMouseAccel; }
95
96   //! Set mouse input acceleration ratio.
97   void SetMouseAcceleration (float theRatio) { myMouseAccel = theRatio; }
98
99   //! Return orbit rotation acceleration ratio; 1.0 by default.
100   float OrbitAcceleration() const { return myOrbitAccel; }
101
102   //! Set orbit rotation acceleration ratio.
103   void SetOrbitAcceleration (float theRatio) { myOrbitAccel = theRatio; }
104
105   //! Return TRUE if panning anchor point within perspective projection should be displayed in 3D Viewer; TRUE by default.
106   bool ToShowPanAnchorPoint() const { return myToShowPanAnchorPoint; }
107
108   //! Set if panning anchor point within perspective projection should be displayed in 3D Viewer.
109   void SetShowPanAnchorPoint (bool theToShow) { myToShowPanAnchorPoint = theToShow; }
110
111   //! Return TRUE if rotation point should be displayed in 3D Viewer; TRUE by default.
112   bool ToShowRotateCenter() const { return myToShowRotateCenter; }
113
114   //! Set if rotation point should be displayed in 3D Viewer.
115   void SetShowRotateCenter (bool theToShow) { myToShowRotateCenter = theToShow; }
116
117   //! Return TRUE if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up; FALSE by default.
118   bool ToLockOrbitZUp() const { return myToLockOrbitZUp; }
119
120   //! Set if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up.
121   void SetLockOrbitZUp (bool theToForceUp) { myToLockOrbitZUp = theToForceUp; }
122
123   //! Return TRUE if z-rotation via two-touches gesture is enabled; FALSE by default.
124   bool ToAllowTouchZRotation() const { return myToAllowTouchZRotation; }
125
126   //! Set if z-rotation via two-touches gesture is enabled.
127   void SetAllowTouchZRotation (bool theToEnable) { myToAllowTouchZRotation = theToEnable; }
128
129   //! Return TRUE if camera rotation is allowed; TRUE by default.
130   bool ToAllowRotation() const { return myToAllowRotation; }
131
132   //! Set if camera rotation is allowed.
133   void SetAllowRotation (bool theToEnable) { myToAllowRotation = theToEnable; }
134
135   //! Return TRUE if panning is allowed; TRUE by default.
136   bool ToAllowPanning() const { return myToAllowPanning; }
137
138   //! Set if panning is allowed.
139   void SetAllowPanning (bool theToEnable) { myToAllowPanning = theToEnable; }
140
141   //! Return TRUE if zooming is allowed; TRUE by default.
142   bool ToAllowZooming() const { return myToAllowZooming; }
143
144   //! Set if zooming is allowed.
145   void SetAllowZooming (bool theToEnable) { myToAllowZooming = theToEnable; }
146
147   //! Return TRUE if ZFocus change is allowed; TRUE by default.
148   bool ToAllowZFocus() const { return myToAllowZFocus; }
149
150   //! Set if ZFocus change is allowed.
151   void SetAllowZFocus (bool theToEnable) { myToAllowZFocus = theToEnable; }
152
153   //! Return TRUE if dynamic highlight on mouse move is allowed; TRUE by default.
154   bool ToAllowHighlight() const { return myToAllowHighlight; }
155
156   //! Set if dragging object is allowed.
157   void SetAllowHighlight (bool theToEnable) { myToAllowHighlight = theToEnable; }
158
159   //! Return TRUE if dragging object is allowed; TRUE by default.
160   bool ToAllowDragging() const { return myToAllowDragging; }
161
162   //! Set if dynamic highlight on mouse move is allowed.
163   void SetAllowDragging (bool theToEnable) { myToAllowDragging = theToEnable; }
164
165   //! Return TRUE if picked point should be projected to picking ray on zooming at point; TRUE by default.
166   bool ToStickToRayOnZoom() const { return myToStickToRayOnZoom; }
167
168   //! Set if picked point should be projected to picking ray on zooming at point.
169   void SetStickToRayOnZoom (bool theToEnable) { myToStickToRayOnZoom = theToEnable; }
170
171   //! Return TRUE if picked point should be projected to picking ray on rotating around point; TRUE by default.
172   bool ToStickToRayOnRotation() const { return myToStickToRayOnRotation; }
173
174   //! Set if picked point should be projected to picking ray on rotating around point.
175   void SetStickToRayOnRotation (bool theToEnable) { myToStickToRayOnRotation = theToEnable; }
176
177   //! Return TRUE if pitch direction should be inverted while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown; FALSE by default.
178   bool ToInvertPitch() const { return myToInvertPitch; }
179
180   //! Set flag inverting pitch direction.
181   void SetInvertPitch (bool theToInvert) { myToInvertPitch = theToInvert; }
182
183   //! Return normal walking speed, in m/s; 1.5 by default.
184   float WalkSpeedAbsolute() const { return myWalkSpeedAbsolute; }
185
186   //! Set normal walking speed, in m/s; 1.5 by default.
187   void SetWalkSpeedAbsolute (float theSpeed) { myWalkSpeedAbsolute = theSpeed; }
188
189   //! Return walking speed relative to scene bounding box; 0.1 by default.
190   float WalkSpeedRelative() const { return myWalkSpeedRelative; }
191
192   //! Set walking speed relative to scene bounding box.
193   void SetWalkSpeedRelative (float theFactor) { myWalkSpeedRelative = theFactor; }
194
195   //! Return active thrust value; 0.0f by default.
196   float ThrustSpeed() const { return myThrustSpeed; }
197
198   //! Set active thrust value.
199   void SetThrustSpeed (float theSpeed) { myThrustSpeed = theSpeed; }
200
201   //! Return TRUE if previous position of MoveTo has been defined.
202   bool HasPreviousMoveTo() const { return myPrevMoveTo != Graphic3d_Vec2i (-1); }
203
204   //! Return previous position of MoveTo event in 3D viewer.
205   const Graphic3d_Vec2i& PreviousMoveTo() const { return myPrevMoveTo; }
206
207   //! Reset previous position of MoveTo.
208   void ResetPreviousMoveTo() { myPrevMoveTo = Graphic3d_Vec2i (-1); }
209
210   //! Return TRUE to display auxiliary tracked XR devices (like tracking stations).
211   bool ToDisplayXRAuxDevices() const { return myToDisplayXRAuxDevices; }
212
213   //! Set if auxiliary tracked XR devices should be displayed.
214   void SetDisplayXRAuxDevices (bool theToDisplay) { myToDisplayXRAuxDevices = theToDisplay; }
215
216   //! Return TRUE to display XR hand controllers.
217   bool ToDisplayXRHands() const { return myToDisplayXRHands; }
218
219   //! Set if tracked XR hand controllers should be displayed.
220   void SetDisplayXRHands (bool theToDisplay) { myToDisplayXRHands = theToDisplay; }
221
222 public: //! @name keyboard input
223
224   //! Return keyboard state.
225   const Aspect_VKeySet& Keys() const { return myKeys; }
226
227   //! Return keyboard state.
228   Aspect_VKeySet& ChangeKeys() { return myKeys; }
229
230   //! Press key.
231   //! @param theKey key pressed
232   //! @param theTime event timestamp
233   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
234                                         double theTime,
235                                         double thePressure = 1.0);
236
237   //! Release key.
238   //! @param theKey key pressed
239   //! @param theTime event timestamp
240   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
241                                       double theTime);
242
243   //! Simulate key up/down events from axis value.
244   Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
245                                             Aspect_VKey thePositive,
246                                             double theTime,
247                                             double thePressure);
248
249   //! Fetch active navigation actions.
250   Standard_EXPORT AIS_WalkDelta FetchNavigationKeys (Standard_Real theCrouchRatio,
251                                                      Standard_Real theRunRatio);
252
253 public: //! @name mouse input
254
255   //! Return map defining mouse gestures.
256   const AIS_MouseGestureMap& MouseGestureMap() const { return myMouseGestureMap; }
257
258   //! Return map defining mouse gestures.
259   AIS_MouseGestureMap& ChangeMouseGestureMap() { return myMouseGestureMap; }
260
261   //! Return map defining mouse selection schemes.
262   const AIS_MouseSelectionSchemeMap& MouseSelectionSchemes() const { return myMouseSelectionSchemes; }
263
264   //! Return map defining mouse gestures.
265   AIS_MouseSelectionSchemeMap& ChangeMouseSelectionSchemes() { return myMouseSelectionSchemes; }
266
267   //! Return double click interval in seconds; 0.4 by default.
268   double MouseDoubleClickInterval() const { return myMouseDoubleClickInt; }
269
270   //! Set double click interval in seconds.
271   void SetMouseDoubleClickInterval (double theSeconds) { myMouseDoubleClickInt = theSeconds; }
272
273   //! Perform selection in 3D viewer.
274   //! This method is expected to be called from UI thread.
275   //! @param thePnt picking point
276   //! @param theScheme selection scheme
277   Standard_EXPORT virtual void SelectInViewer (const Graphic3d_Vec2i& thePnt,
278                                                const AIS_SelectionScheme theScheme = AIS_SelectionScheme_Replace);
279
280   //! Perform selection in 3D viewer.
281   //! This method is expected to be called from UI thread.
282   //! @param thePnts picking point
283   //! @param theScheme selection scheme
284   Standard_EXPORT virtual void SelectInViewer (const NCollection_Sequence<Graphic3d_Vec2i>& thePnts,
285                                                const AIS_SelectionScheme theScheme = AIS_SelectionScheme_Replace);
286
287   //! Update rectangle selection tool.
288   //! This method is expected to be called from UI thread.
289   //! @param thePntFrom rectangle first   corner
290   //! @param thePntTo   rectangle another corner
291   Standard_EXPORT virtual void UpdateRubberBand (const Graphic3d_Vec2i& thePntFrom,
292                                                  const Graphic3d_Vec2i& thePntTo);
293
294   //! Update polygonal selection tool.
295   //! This method is expected to be called from UI thread.
296   //! @param thePnt new point to add to polygon
297   //! @param theToAppend append new point or update the last point
298   Standard_EXPORT virtual void UpdatePolySelection (const Graphic3d_Vec2i& thePnt,
299                                                     bool theToAppend);
300
301   //! Update zoom event (e.g. from mouse scroll).
302   //! This method is expected to be called from UI thread.
303   //! @param theDelta mouse cursor position to zoom at and zoom delta
304   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
305   Standard_EXPORT virtual bool UpdateZoom (const Aspect_ScrollDelta& theDelta);
306
307   //! Update Z rotation event.
308   //! @param theAngle rotation angle, in radians.
309   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
310   Standard_EXPORT virtual bool UpdateZRotation (double theAngle);
311
312   //! Update mouse scroll event; redirects to UpdateZoom by default.
313   //! This method is expected to be called from UI thread.
314   //! @param theDelta mouse cursor position and delta
315   //! @return TRUE if new event has been created or FALSE if existing one has been updated
316   Standard_EXPORT virtual bool UpdateMouseScroll (const Aspect_ScrollDelta& theDelta);
317
318   //! Handle mouse button press/release event.
319   //! This method is expected to be called from UI thread.
320   //! @param thePoint      mouse cursor position
321   //! @param theButtons    pressed buttons
322   //! @param theModifiers  key modifiers
323   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
324   //!                      but emulated from non-precise input like touch on screen
325   //! @return TRUE if View should be redrawn
326   Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
327                                                    Aspect_VKeyMouse theButtons,
328                                                    Aspect_VKeyFlags theModifiers,
329                                                    bool theIsEmulated);
330
331   //! Handle mouse cursor movement event.
332   //! This method is expected to be called from UI thread.
333   //! @param thePoint      mouse cursor position
334   //! @param theButtons    pressed buttons
335   //! @param theModifiers  key modifiers
336   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
337   //!                      but emulated from non-precise input like touch on screen
338   //! @return TRUE if View should be redrawn
339   Standard_EXPORT virtual bool UpdateMousePosition (const Graphic3d_Vec2i& thePoint,
340                                                     Aspect_VKeyMouse theButtons,
341                                                     Aspect_VKeyFlags theModifiers,
342                                                     bool theIsEmulated);
343
344   //! Handle mouse button press event.
345   //! This method is expected to be called from UI thread.
346   //! @param thePoint      mouse cursor position
347   //! @param theButton     pressed button
348   //! @param theModifiers  key modifiers
349   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
350   //!                      but emulated from non-precise input like touch on screen
351   //! @return TRUE if View should be redrawn
352   bool PressMouseButton (const Graphic3d_Vec2i& thePoint,
353                          Aspect_VKeyMouse theButton,
354                          Aspect_VKeyFlags theModifiers,
355                          bool theIsEmulated)
356   {
357     return UpdateMouseButtons (thePoint, myMousePressed | theButton, theModifiers, theIsEmulated);
358   }
359
360   //! Handle mouse button release event.
361   //! This method is expected to be called from UI thread.
362   //! @param thePoint      mouse cursor position
363   //! @param theButton     released button
364   //! @param theModifiers  key modifiers
365   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
366   //!                      but emulated from non-precise input like touch on screen
367   //! @return TRUE if View should be redrawn
368   bool ReleaseMouseButton (const Graphic3d_Vec2i& thePoint,
369                            Aspect_VKeyMouse theButton,
370                            Aspect_VKeyFlags theModifiers,
371                            bool theIsEmulated)
372   {
373     Aspect_VKeyMouse aButtons = myMousePressed & (~theButton);
374     return UpdateMouseButtons (thePoint, aButtons, theModifiers, theIsEmulated);
375   }
376
377   //! Handle mouse button click event (emulated by UpdateMouseButtons() while releasing single button).
378   //! Note that as this method is called by UpdateMouseButtons(), it should be executed from UI thread.
379   //! Default implementation redirects to SelectInViewer().
380   //! This method is expected to be called from UI thread.
381   //! @param thePoint      mouse cursor position
382   //! @param theButton     clicked button
383   //! @param theModifiers  key modifiers
384   //! @param theIsDoubleClick flag indicating double mouse click
385   //! @return TRUE if View should be redrawn
386   Standard_EXPORT virtual bool UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
387                                                  Aspect_VKeyMouse theButton,
388                                                  Aspect_VKeyFlags theModifiers,
389                                                  bool theIsDoubleClick);
390
391   //! Return currently pressed mouse buttons.
392   Aspect_VKeyMouse PressedMouseButtons() const { return myMousePressed; }
393
394   //! Return active key modifiers passed with last mouse event.
395   Aspect_VKeyFlags LastMouseFlags() const { return myMouseModifiers; }
396
397   //! Return last mouse position.
398   const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
399
400 public: //! @name multi-touch input
401
402   //! Return scale factor for adjusting tolerances for starting multi-touch gestures; 1.0 by default
403   //! This scale factor is expected to be computed from touch screen resolution.
404   float TouchToleranceScale() const { return myTouchToleranceScale; }
405
406   //! Set scale factor for adjusting tolerances for starting multi-touch gestures.
407   void SetTouchToleranceScale (float theTolerance) { myTouchToleranceScale = theTolerance; }
408
409   //! Return TRUE if touches map is not empty.
410   bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
411
412   //! Add touch point with the given ID.
413   //! This method is expected to be called from UI thread.
414   //! @param theId touch unique identifier
415   //! @param thePnt touch coordinates
416   //! @param theClearBefore if TRUE previously registered touches will be removed
417   Standard_EXPORT virtual void AddTouchPoint (Standard_Size theId,
418                                               const Graphic3d_Vec2d& thePnt,
419                                               Standard_Boolean theClearBefore = false);
420
421   //! Remove touch point with the given ID.
422   //! This method is expected to be called from UI thread.
423   //! @param theId touch unique identifier
424   //! @param theClearSelectPnts if TRUE will initiate clearing of selection points
425   //! @return TRUE if point has been removed
426   Standard_EXPORT virtual bool RemoveTouchPoint (Standard_Size theId,
427                                                  Standard_Boolean theClearSelectPnts = false);
428
429   //! Update touch point with the given ID.
430   //! If point with specified ID was not registered before, it will be added.
431   //! This method is expected to be called from UI thread.
432   //! @param theId touch unique identifier
433   //! @param thePnt touch coordinates
434   Standard_EXPORT virtual void UpdateTouchPoint (Standard_Size theId,
435                                                  const Graphic3d_Vec2d& thePnt);
436
437 public: //! @name 3d mouse input
438
439   //! Return acceleration ratio for translation event; 2.0 by default.
440   float Get3dMouseTranslationScale() const { return my3dMouseAccelTrans; }
441
442   //! Set acceleration ratio for translation event.
443   void Set3dMouseTranslationScale (float theScale) { my3dMouseAccelTrans = theScale; }
444
445   //! Return acceleration ratio for rotation event; 4.0 by default.
446   float Get3dMouseRotationScale() const { return my3dMouseAccelRotate; }
447
448   //! Set acceleration ratio for rotation event.
449   void Set3dMouseRotationScale (float theScale) { my3dMouseAccelRotate = theScale; }
450
451   //! Return quadric acceleration flag; TRUE by default.
452   bool To3dMousePreciseInput() const { return my3dMouseIsQuadric; }
453
454   //! Set quadric acceleration flag.
455   void Set3dMousePreciseInput (bool theIsQuadric) { my3dMouseIsQuadric = theIsQuadric; }
456
457   //! Return 3d mouse rotation axes (tilt/roll/spin) ignore flag; (FALSE, FALSE, FALSE) by default.
458   const NCollection_Vec3<bool>& Get3dMouseIsNoRotate() const { return my3dMouseNoRotate; }
459
460   //! Return 3d mouse rotation axes (tilt/roll/spin) ignore flag; (FALSE, FALSE, FALSE) by default.
461   NCollection_Vec3<bool>& Change3dMouseIsNoRotate() { return my3dMouseNoRotate; }
462
463   //! Return 3d mouse rotation axes (tilt/roll/spin) reverse flag; (TRUE, FALSE, FALSE) by default.
464   const NCollection_Vec3<bool>& Get3dMouseToReverse() const { return my3dMouseToReverse; }
465
466   //! Return 3d mouse rotation axes (tilt/roll/spin) reverse flag; (TRUE, FALSE, FALSE) by default.
467   NCollection_Vec3<bool>& Change3dMouseToReverse() { return my3dMouseToReverse; }
468
469   //! Process 3d mouse input event (redirects to translation, rotation and keys).
470   Standard_EXPORT virtual bool Update3dMouse (const WNT_HIDSpaceMouse& theEvent);
471
472   //! Process 3d mouse input translation event.
473   Standard_EXPORT virtual bool update3dMouseTranslation (const WNT_HIDSpaceMouse& theEvent);
474
475   //! Process 3d mouse input rotation event.
476   Standard_EXPORT virtual bool update3dMouseRotation (const WNT_HIDSpaceMouse& theEvent);
477
478   //! Process 3d mouse input keys event.
479   Standard_EXPORT virtual bool update3dMouseKeys (const WNT_HIDSpaceMouse& theEvent);
480
481 public:
482
483   //! Return event time (e.g. current time).
484   double EventTime() const { return myEventTimer.ElapsedTime(); }
485
486   //! Reset input state (pressed keys, mouse buttons, etc.) e.g. on window focus loss.
487   //! This method is expected to be called from UI thread.
488   Standard_EXPORT virtual void ResetViewInput();
489
490   //! Reset view orientation.
491   //! This method is expected to be called from UI thread.
492   Standard_EXPORT virtual void UpdateViewOrientation (V3d_TypeOfOrientation theOrientation,
493                                                       bool theToFitAll);
494
495   //! Update buffer for rendering thread.
496   //! This method is expected to be called within synchronization barrier between GUI
497   //! and Rendering threads (e.g. GUI thread should be locked beforehand to avoid data races).
498   //! @param theCtx interactive context
499   //! @param theView active view
500   //! @param theToHandle if TRUE, the HandleViewEvents() will be called
501   Standard_EXPORT virtual void FlushViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
502                                                 const Handle(V3d_View)& theView,
503                                                 Standard_Boolean theToHandle = Standard_False);
504
505   //! Process events within rendering thread.
506   Standard_EXPORT virtual void HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
507                                                  const Handle(V3d_View)& theView);
508
509 public:
510
511   //! Callback called by handleMoveTo() on Selection in 3D Viewer.
512   //! This method is expected to be called from rendering thread.
513   Standard_EXPORT virtual void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
514                                                    const Handle(V3d_View)& theView);
515
516   //! Callback called by handleMoveTo() on dragging object in 3D Viewer.
517   //! This method is expected to be called from rendering thread.
518   Standard_EXPORT virtual void OnObjectDragged (const Handle(AIS_InteractiveContext)& theCtx,
519                                                 const Handle(V3d_View)& theView,
520                                                 AIS_DragAction theAction);
521
522   //! Pick closest point under mouse cursor.
523   //! This method is expected to be called from rendering thread.
524   //! @param thePnt   [out] result point
525   //! @param theCtx    [in] interactive context
526   //! @param theView   [in] active view
527   //! @param theCursor [in] mouse cursor
528   //! @param theToStickToPickRay [in] when TRUE, the result point will lie on picking ray
529   //! @return TRUE if result has been found
530   Standard_EXPORT virtual bool PickPoint (gp_Pnt& thePnt,
531                                           const Handle(AIS_InteractiveContext)& theCtx,
532                                           const Handle(V3d_View)& theView,
533                                           const Graphic3d_Vec2i& theCursor,
534                                           bool theToStickToPickRay);
535
536   //! Compute rotation gravity center point depending on rotation mode.
537   //! This method is expected to be called from rendering thread.
538   Standard_EXPORT virtual gp_Pnt GravityPoint (const Handle(AIS_InteractiveContext)& theCtx,
539                                                const Handle(V3d_View)& theView);
540
541   //! Modify view camera to fit all objects.
542   //! Default implementation fits either all visible and all selected objects (swapped on each call).
543   Standard_EXPORT virtual void FitAllAuto (const Handle(AIS_InteractiveContext)& theCtx,
544                                            const Handle(V3d_View)& theView);
545
546 public:
547
548   //! Handle hot-keys defining new camera orientation (Aspect_VKey_ViewTop and similar keys).
549   //! Default implementation starts an animated transaction from the current to the target camera orientation, when specific action key was pressed.
550   //! This method is expected to be called from rendering thread.
551   Standard_EXPORT virtual void handleViewOrientationKeys (const Handle(AIS_InteractiveContext)& theCtx,
552                                                           const Handle(V3d_View)& theView);
553
554   //! Perform navigation (Aspect_VKey_NavForward and similar keys).
555   //! This method is expected to be called from rendering thread.
556   Standard_EXPORT virtual AIS_WalkDelta handleNavigationKeys (const Handle(AIS_InteractiveContext)& theCtx,
557                                                               const Handle(V3d_View)& theView);
558
559   //! Perform immediate camera actions (rotate/zoom/pan) on gesture progress.
560   //! This method is expected to be called from rendering thread.
561   Standard_EXPORT virtual void handleCameraActions (const Handle(AIS_InteractiveContext)& theCtx,
562                                                     const Handle(V3d_View)& theView,
563                                                     const AIS_WalkDelta& theWalk);
564
565   //! Perform moveto/selection/dragging.
566   //! This method is expected to be called from rendering thread.
567   Standard_EXPORT virtual void handleMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
568                                              const Handle(V3d_View)& theView);
569
570   //! Return TRUE if another frame should be drawn right after this one.
571   bool toAskNextFrame() const { return myToAskNextFrame; }
572
573   //! Set if another frame should be drawn right after this one.
574   void setAskNextFrame (bool theToDraw = true) { myToAskNextFrame = theToDraw; }
575
576   //! Return if panning anchor point has been defined.
577   bool hasPanningAnchorPoint() const { return !Precision::IsInfinite (myPanPnt3d.X()); }
578
579   //! Return active panning anchor point.
580   const gp_Pnt& panningAnchorPoint() const { return myPanPnt3d; }
581
582   //! Set active panning anchor point.
583   void setPanningAnchorPoint (const gp_Pnt& thePnt) { myPanPnt3d = thePnt; }
584
585   //! Handle panning event myGL.Panning.
586   Standard_EXPORT virtual void handlePanning (const Handle(V3d_View)& theView);
587
588   //! Handle Z rotation event myGL.ZRotate.
589   Standard_EXPORT virtual void handleZRotate (const Handle(V3d_View)& theView);
590
591   //! Return minimal camera distance for zoom operation.
592   double MinZoomDistance() const { return myMinCamDistance; }
593
594   //! Set minimal camera distance for zoom operation.
595   void SetMinZoomDistance (double theDist) { myMinCamDistance = theDist; }
596
597   //! Handle zoom event myGL.ZoomActions.
598   //! This method is expected to be called from rendering thread.
599   Standard_EXPORT virtual void handleZoom (const Handle(V3d_View)& theView,
600                                            const Aspect_ScrollDelta& theParams,
601                                            const gp_Pnt* thePnt);
602
603   //! Handle ZScroll event myGL.ZoomActions.
604   //! This method is expected to be called from rendering thread.
605   Standard_EXPORT virtual void handleZFocusScroll (const Handle(V3d_View)& theView,
606                                                    const Aspect_ScrollDelta& theParams);
607
608   //! Handle orbital rotation events myGL.OrbitRotation.
609   //! @param theView view to modify
610   //! @param thePnt 3D point to rotate around
611   //! @param theToLockZUp amend camera to exclude roll angle (put camera Up vector to plane containing global Z and view direction)
612   Standard_EXPORT virtual void handleOrbitRotation (const Handle(V3d_View)& theView,
613                                                     const gp_Pnt& thePnt,
614                                                     bool theToLockZUp);
615
616   //! Handle view direction rotation events myGL.ViewRotation.
617   //! This method is expected to be called from rendering thread.
618   //! @param theView       camera to modify
619   //! @param theYawExtra   extra yaw increment
620   //! @param thePitchExtra extra pitch increment
621   //! @param theRoll       roll value
622   //! @param theToRestartOnIncrement flag indicating flight mode
623   Standard_EXPORT virtual void handleViewRotation (const Handle(V3d_View)& theView,
624                                                    double theYawExtra,
625                                                    double thePitchExtra,
626                                                    double theRoll,
627                                                    bool theToRestartOnIncrement);
628
629   //! Handle view redraw.
630   //! This method is expected to be called from rendering thread.
631   Standard_EXPORT virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
632                                                  const Handle(V3d_View)& theView);
633
634 public:
635
636   //! Perform XR input.
637   //! This method is expected to be called from rendering thread.
638   Standard_EXPORT virtual void handleXRInput (const Handle(AIS_InteractiveContext)& theCtx,
639                                               const Handle(V3d_View)& theView,
640                                               const AIS_WalkDelta& theWalk);
641
642   //! Handle trackpad view turn action.
643   Standard_EXPORT virtual void handleXRTurnPad (const Handle(AIS_InteractiveContext)& theCtx,
644                                                 const Handle(V3d_View)& theView);
645
646   //! Handle trackpad teleportation action.
647   Standard_EXPORT virtual void handleXRTeleport (const Handle(AIS_InteractiveContext)& theCtx,
648                                                  const Handle(V3d_View)& theView);
649
650   //! Handle picking on trigger click.
651   Standard_EXPORT virtual void handleXRPicking (const Handle(AIS_InteractiveContext)& theCtx,
652                                                 const Handle(V3d_View)& theView);
653
654   //! Perform dynamic highlighting for active hand.
655   Standard_EXPORT virtual void handleXRHighlight (const Handle(AIS_InteractiveContext)& theCtx,
656                                                   const Handle(V3d_View)& theView);
657
658   //! Display auxiliary XR presentations.
659   Standard_EXPORT virtual void handleXRPresentations (const Handle(AIS_InteractiveContext)& theCtx,
660                                                       const Handle(V3d_View)& theView);
661
662   //! Perform picking with/without dynamic highlighting for XR pose.
663   Standard_EXPORT virtual Standard_Integer handleXRMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
664                                                            const Handle(V3d_View)& theView,
665                                                            const gp_Trsf& thePose,
666                                                            const Standard_Boolean theToHighlight);
667
668 protected:
669
670   //! Flush buffers.
671   Standard_EXPORT virtual void flushBuffers (const Handle(AIS_InteractiveContext)& theCtx,
672                                              const Handle(V3d_View)& theView);
673
674   //! Flush touch gestures.
675   Standard_EXPORT virtual void flushGestures (const Handle(AIS_InteractiveContext)& theCtx,
676                                               const Handle(V3d_View)& theView);
677
678   //! Return current and previously fetched event times.
679   //! This callback is intended to compute delta between sequentially processed events.
680   //! @param thePrevTime [out] events time fetched previous time by this method
681   //! @param theCurrTime [out] actual events time
682   void updateEventsTime (double& thePrevTime,
683                          double& theCurrTime)
684   {
685     thePrevTime = myLastEventsTime;
686     myLastEventsTime = EventTime();
687     theCurrTime = myLastEventsTime;
688   }
689
690   //! Perform selection via mouse click.
691   //! This method is expected to be called from rendering thread.
692   Standard_EXPORT virtual void handleSelectionPick (const Handle(AIS_InteractiveContext)& theCtx,
693                                                     const Handle(V3d_View)& theView);
694
695   //! Perform dynamic highlight on mouse move.
696   //! This method is expected to be called from rendering thread.
697   Standard_EXPORT virtual void handleDynamicHighlight (const Handle(AIS_InteractiveContext)& theCtx,
698                                                        const Handle(V3d_View)& theView);
699
700   //! Perform rubber-band selection.
701   //! This method is expected to be called from rendering thread.
702   Standard_EXPORT virtual void handleSelectionPoly (const Handle(AIS_InteractiveContext)& theCtx,
703                                                     const Handle(V3d_View)& theView);
704
705   //! Lazy AIS_InteractiveContext::MoveTo() with myPrevMoveTo check.
706   Standard_EXPORT virtual void contextLazyMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
707                                                   const Handle(V3d_View)& theView,
708                                                   const Graphic3d_Vec2i& thePnt);
709
710 protected:
711
712   AIS_ViewInputBuffer myUI;                       //!< buffer for UI thread
713   AIS_ViewInputBuffer myGL;                       //!< buffer for rendering thread
714
715   OSD_Timer           myEventTimer;               //!< timer for timestamping events
716   Standard_Real       myLastEventsTime;           //!< last fetched events timer value for computing delta/progress
717   Standard_Boolean    myToAskNextFrame;           //!< flag indicating that another frame should be drawn right after this one
718
719   Standard_Real       myMinCamDistance;           //!< minimal camera distance for zoom operation
720   AIS_RotationMode    myRotationMode;             //!< rotation mode
721   AIS_NavigationMode  myNavigationMode;           //!< navigation mode (orbit rotation / first person)
722   Standard_ShortReal  myMouseAccel;               //!< mouse input acceleration ratio in First Person mode
723   Standard_ShortReal  myOrbitAccel;               //!< Orbit rotation acceleration ratio
724   Standard_Boolean    myToShowPanAnchorPoint;     //!< option displaying panning  anchor point
725   Standard_Boolean    myToShowRotateCenter;       //!< option displaying rotation center point
726   Standard_Boolean    myToLockOrbitZUp;           //!< force camera up orientation within AIS_NavigationMode_Orbit rotation mode
727   Standard_Boolean    myToInvertPitch;            //!< flag inverting pitch direction while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown
728   Standard_Boolean    myToAllowTouchZRotation;    //!< enable z-rotation two-touches gesture; FALSE by default
729   Standard_Boolean    myToAllowRotation;          //!< enable rotation; TRUE by default
730   Standard_Boolean    myToAllowPanning;           //!< enable panning; TRUE by default
731   Standard_Boolean    myToAllowZooming;           //!< enable zooming; TRUE by default
732   Standard_Boolean    myToAllowZFocus;            //!< enable ZFocus change; TRUE by default
733   Standard_Boolean    myToAllowHighlight;         //!< enable dynamic highlight on mouse move; TRUE by default
734   Standard_Boolean    myToAllowDragging;          //!< enable dragging object; TRUE by default
735   Standard_Boolean    myToStickToRayOnZoom;       //!< project picked point to ray while zooming at point, TRUE by default
736   Standard_Boolean    myToStickToRayOnRotation;   //!< project picked point to ray while rotating around point; TRUE by default
737
738   Standard_ShortReal  myWalkSpeedAbsolute;        //!< normal walking speed, in m/s; 1.5 by default
739   Standard_ShortReal  myWalkSpeedRelative;        //!< walking speed relative to scene bounding box; 0.1 by default
740   Standard_ShortReal  myThrustSpeed;              //!< active thrust value
741   Standard_Boolean    myHasThrust;                //!< flag indicating active thrust
742
743   Handle(AIS_AnimationCamera) myViewAnimation;    //!< view animation
744   Handle(AIS_RubberBand) myRubberBand;            //!< Rubber-band presentation
745   Handle(SelectMgr_EntityOwner) myDragOwner;      //!< detected owner of currently dragged object
746   Handle(AIS_InteractiveObject) myDragObject;     //!< currently dragged object
747   Graphic3d_Vec2i     myPrevMoveTo;               //!< previous position of MoveTo event in 3D viewer
748   Standard_Boolean    myHasHlrOnBeforeRotation;   //!< flag for restoring Computed mode after rotation
749
750 protected: //! @name XR input variables
751
752   NCollection_Array1<Handle(AIS_XRTrackedDevice)> myXRPrsDevices; //!< array of XR tracked devices presentations
753   Handle(Graphic3d_Camera)   myXRCameraTmp;       //!< temporary camera
754   Quantity_Color             myXRLaserTeleColor;  //!< color of teleport laser
755   Quantity_Color             myXRLaserPickColor;  //!< color of picking  laser
756   Aspect_XRTrackedDeviceRole myXRLastTeleportHand;//!< active hand for teleport
757   Aspect_XRTrackedDeviceRole myXRLastPickingHand; //!< active hand for picking objects
758   Aspect_XRHapticActionData  myXRTeleportHaptic;  //!< vibration on picking teleport destination
759   Aspect_XRHapticActionData  myXRPickingHaptic;   //!< vibration on dynamic highlighting
760   Aspect_XRHapticActionData  myXRSelectHaptic;    //!< vibration on selection
761   Standard_Real       myXRLastPickDepthLeft;      //!< last picking depth for left  hand
762   Standard_Real       myXRLastPickDepthRight;     //!< last picking depth for right hand
763   Standard_Real       myXRTurnAngle;              //!< discrete turn angle for XR trackpad
764   Standard_Boolean    myToDisplayXRAuxDevices;    //!< flag to display auxiliary tracked XR devices
765   Standard_Boolean    myToDisplayXRHands;         //!< flag to display XR hands
766
767 protected: //! @name keyboard input variables
768
769   Aspect_VKeySet      myKeys;                     //!< keyboard state
770
771 protected: //! @name mouse input variables
772
773   Standard_Real       myMouseClickThreshold;      //!< mouse click threshold in pixels; 3 by default
774   Standard_Real       myMouseDoubleClickInt;      //!< double click interval in seconds; 0.4 by default
775   Standard_ShortReal  myScrollZoomRatio;          //!< distance ratio for mapping mouse scroll event to zoom; 15.0 by default
776
777   AIS_MouseGestureMap myMouseGestureMap;          //!< map defining mouse gestures
778   AIS_MouseGesture    myMouseActiveGesture;       //!< initiated mouse gesture (by pressing mouse button)
779   AIS_MouseSelectionSchemeMap
780                       myMouseSelectionSchemes;    //!< map defining selection schemes bound to mouse + modifiers
781   Standard_Boolean    myMouseActiveIdleRotation;  //!< flag indicating view idle rotation state
782   Graphic3d_Vec2i     myMousePositionLast;        //!< last mouse position
783   Graphic3d_Vec2i     myMousePressPoint;          //!< mouse position where active gesture was been initiated
784   Graphic3d_Vec2i     myMouseProgressPoint;       //!< gesture progress
785   OSD_Timer           myMouseClickTimer;          //!< timer for handling double-click event
786   Standard_Integer    myMouseClickCounter;        //!< counter for handling double-click event
787   Aspect_VKeyMouse    myMousePressed;             //!< active mouse buttons
788   Aspect_VKeyFlags    myMouseModifiers;           //!< active key modifiers passed with last mouse event
789   Standard_Integer    myMouseSingleButton;        //!< index of mouse button pressed alone (>0)
790   Standard_Boolean    myMouseStopDragOnUnclick;   //!< queue stop dragging even with at next mouse unclick
791
792 protected: //! @name multi-touch input variables
793
794   Standard_ShortReal  myTouchToleranceScale;      //!< tolerance scale factor; 1.0 by default
795   Standard_ShortReal  myTouchRotationThresholdPx; //!< threshold for starting one-touch rotation     gesture in pixels;  6 by default
796   Standard_ShortReal  myTouchZRotationThreshold;  //!< threshold for starting two-touch Z-rotation   gesture in radians; 2 degrees by default
797   Standard_ShortReal  myTouchPanThresholdPx;      //!< threshold for starting two-touch panning      gesture in pixels;  4 by default
798   Standard_ShortReal  myTouchZoomThresholdPx;     //!< threshold for starting two-touch zoom (pitch) gesture in pixels;  6 by default
799   Standard_ShortReal  myTouchZoomRatio;           //!< distance ratio for mapping two-touch zoom (pitch) gesture from pixels to zoom; 0.13 by default
800
801   Aspect_TouchMap     myTouchPoints;              //!< map of active touches
802   Graphic3d_Vec2d     myStartPanCoord;            //!< touch coordinates at the moment of starting panning  gesture
803   Graphic3d_Vec2d     myStartRotCoord;            //!< touch coordinates at the moment of starting rotating gesture
804   Standard_Integer    myNbTouchesLast;            //!< number of touches within previous gesture flush to track gesture changes
805   Standard_Boolean    myUpdateStartPointPan;      //!< flag indicating that new anchor  point should be picked for starting panning    gesture
806   Standard_Boolean    myUpdateStartPointRot;      //!< flag indicating that new gravity point should be picked for starting rotation   gesture
807   Standard_Boolean    myUpdateStartPointZRot;     //!< flag indicating that new gravity point should be picked for starting Z-rotation gesture
808
809 protected: //! @name 3d mouse input variables
810
811   bool                   my3dMouseButtonState[32];//!< cached button state
812   NCollection_Vec3<bool> my3dMouseNoRotate;       //!< ignore  3d mouse rotation axes
813   NCollection_Vec3<bool> my3dMouseToReverse;      //!< reverse 3d mouse rotation axes
814   float                  my3dMouseAccelTrans;     //!< acceleration ratio for translation event
815   float                  my3dMouseAccelRotate;    //!< acceleration ratio for rotation event
816   bool                   my3dMouseIsQuadric;      //!< quadric acceleration
817
818 protected: //! @name rotation/panning transient state variables
819
820   Handle(AIS_Point)   myAnchorPointPrs1;          //!< anchor point presentation (Graphic3d_ZLayerId_Top)
821   Handle(AIS_Point)   myAnchorPointPrs2;          //!< anchor point presentation (Graphic3d_ZLayerId_Topmost)
822   gp_Pnt              myPanPnt3d;                 //!< active panning anchor point
823   gp_Pnt              myRotatePnt3d;              //!< active rotation center of gravity
824   gp_Dir              myCamStartOpUp;             //!< camera Up    direction at the beginning of rotation
825   gp_Dir              myCamStartOpDir;            //!< camera View  direction at the beginning of rotation
826   gp_Pnt              myCamStartOpEye;            //!< camera Eye    position at the beginning of rotation
827   gp_Pnt              myCamStartOpCenter;         //!< camera Center position at the beginning of rotation
828   gp_Vec              myCamStartOpToCenter;       //!< vector from rotation gravity point to camera Center at the beginning of rotation
829   gp_Vec              myCamStartOpToEye;          //!< vector from rotation gravity point to camera Eye    at the beginning of rotation
830   Graphic3d_Vec3d     myRotateStartYawPitchRoll;  //!< camera yaw pitch roll at the beginning of rotation
831
832 };
833
834 #endif // _AIS_ViewController_HeaderFile