0031459: Visualization, AIS_TextLabel - add missing getters
[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 <AIS_DragAction.hxx>
20 #include <AIS_MouseGesture.hxx>
21 #include <AIS_NavigationMode.hxx>
22 #include <AIS_ViewInputBuffer.hxx>
23 #include <AIS_RotationMode.hxx>
24 #include <AIS_WalkDelta.hxx>
25
26 #include <gp_Pnt.hxx>
27 #include <Graphic3d_Vec3.hxx>
28 #include <NCollection_Array1.hxx>
29 #include <OSD_Timer.hxx>
30 #include <Precision.hxx>
31 #include <Standard_Mutex.hxx>
32
33 class AIS_AnimationCamera;
34 class AIS_InteractiveObject;
35 class AIS_InteractiveContext;
36 class AIS_Point;
37 class AIS_RubberBand;
38 class V3d_View;
39
40 //! Auxiliary structure for handling viewer events between GUI and Rendering threads.
41 //!
42 //! Class implements the following features:
43 //! - Buffers storing the state of user input (mouse, touches and keyboard).
44 //! - Mapping mouse/multi-touch input to View camera manipulations (panning/rotating/zooming).
45 //! - Input events are not applied immediately but queued for separate processing from two working threads
46 //!   UI thread receiving user input and Rendering thread for OCCT 3D Viewer drawing.
47 class AIS_ViewController
48 {
49 public:
50
51   //! Empty constructor.
52   Standard_EXPORT AIS_ViewController();
53
54   //! Destructor.
55   Standard_EXPORT virtual ~AIS_ViewController();
56
57   //! Return input buffer.
58   const AIS_ViewInputBuffer& InputBuffer (AIS_ViewInputBufferType theType) const { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
59
60   //! Return input buffer.
61   AIS_ViewInputBuffer& ChangeInputBuffer (AIS_ViewInputBufferType theType)       { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
62
63   //! Return view animation; empty (but not NULL) animation by default.
64   const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; }
65
66   //! Set view animation to be handled within handleViewRedraw().
67   void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; }
68
69   //! Interrupt active view animation.
70   Standard_EXPORT void AbortViewAnimation();
71
72 public: //! @name global parameters
73
74   //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default.
75   AIS_RotationMode RotationMode() const { return myRotationMode; }
76
77   //! Set camera rotation mode.
78   void SetRotationMode (AIS_RotationMode theMode) { myRotationMode = theMode; }
79
80   //! Return camera navigation mode; AIS_NavigationMode_Orbit by default.
81   AIS_NavigationMode NavigationMode() const { return myNavigationMode; }
82
83   //! Set camera navigation mode.
84   Standard_EXPORT void SetNavigationMode (AIS_NavigationMode theMode);
85
86   //! Return mouse input acceleration ratio in First Person mode; 1.0 by default.
87   float MouseAcceleration() const { return myMouseAccel; }
88
89   //! Set mouse input acceleration ratio.
90   void SetMouseAcceleration (float theRatio) { myMouseAccel = theRatio; }
91
92   //! Return orbit rotation acceleration ratio; 1.0 by default.
93   float OrbitAcceleration() const { return myOrbitAccel; }
94
95   //! Set orbit rotation acceleration ratio.
96   void SetOrbitAcceleration (float theRatio) { myOrbitAccel = theRatio; }
97
98   //! Return TRUE if panning anchor point within perspective projection should be displayed in 3D Viewer; TRUE by default.
99   bool ToShowPanAnchorPoint() const { return myToShowPanAnchorPoint; }
100
101   //! Set if panning anchor point within perspective projection should be displayed in 3D Viewer.
102   void SetShowPanAnchorPoint (bool theToShow) { myToShowPanAnchorPoint = theToShow; }
103
104   //! Return TRUE if rotation point should be displayed in 3D Viewer; TRUE by default.
105   bool ToShowRotateCenter() const { return myToShowRotateCenter; }
106
107   //! Set if rotation point should be displayed in 3D Viewer.
108   void SetShowRotateCenter (bool theToShow) { myToShowRotateCenter = theToShow; }
109
110   //! Return TRUE if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up; FALSE by default.
111   bool ToLockOrbitZUp() const { return myToLockOrbitZUp; }
112
113   //! Set if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up.
114   void SetLockOrbitZUp (bool theToForceUp) { myToLockOrbitZUp = theToForceUp; }
115
116   //! Return TRUE if z-rotation via two-touches gesture is enabled; FALSE by default.
117   bool ToAllowTouchZRotation() const { return myToAllowTouchZRotation; }
118
119   //! Set if z-rotation via two-touches gesture is enabled.
120   void SetAllowTouchZRotation (bool theToEnable) { myToAllowTouchZRotation = theToEnable; }
121
122   //! Return TRUE if camera rotation is allowed; TRUE by default.
123   bool ToAllowRotation() const { return myToAllowRotation; }
124
125   //! Set if camera rotation is allowed.
126   void SetAllowRotation (bool theToEnable) { myToAllowRotation = theToEnable; }
127
128   //! Return TRUE if panning is allowed; TRUE by default.
129   bool ToAllowPanning() const { return myToAllowPanning; }
130
131   //! Set if panning is allowed.
132   void SetAllowPanning (bool theToEnable) { myToAllowPanning = theToEnable; }
133
134   //! Return TRUE if zooming is allowed; TRUE by default.
135   bool ToAllowZooming() const { return myToAllowZooming; }
136
137   //! Set if zooming is allowed.
138   void SetAllowZooming (bool theToEnable) { myToAllowZooming = theToEnable; }
139
140   //! Return TRUE if ZFocus change is allowed; TRUE by default.
141   bool ToAllowZFocus() const { return myToAllowZFocus; }
142
143   //! Set if ZFocus change is allowed.
144   void SetAllowZFocus (bool theToEnable) { myToAllowZFocus = theToEnable; }
145
146   //! Return TRUE if dynamic highlight on mouse move is allowed; TRUE by default.
147   bool ToAllowHighlight() const { return myToAllowHighlight; }
148
149   //! Set if dragging object is allowed.
150   void SetAllowHighlight (bool theToEnable) { myToAllowHighlight = theToEnable; }
151
152   //! Return TRUE if dragging object is allowed; TRUE by default.
153   bool ToAllowDragging() const { return myToAllowDragging; }
154
155   //! Set if dynamic highlight on mouse move is allowed.
156   void SetAllowDragging (bool theToEnable) { myToAllowDragging = theToEnable; }
157
158   //! Return TRUE if picked point should be projected to picking ray on zooming at point; TRUE by default.
159   bool ToStickToRayOnZoom() const { return myToStickToRayOnZoom; }
160
161   //! Set if picked point should be projected to picking ray on zooming at point.
162   void SetStickToRayOnZoom (bool theToEnable) { myToStickToRayOnZoom = theToEnable; }
163
164   //! Return TRUE if picked point should be projected to picking ray on rotating around point; TRUE by default.
165   bool ToStickToRayOnRotation() const { return myToStickToRayOnRotation; }
166
167   //! Set if picked point should be projected to picking ray on rotating around point.
168   void SetStickToRayOnRotation (bool theToEnable) { myToStickToRayOnRotation = theToEnable; }
169
170   //! Return TRUE if pitch direction should be inverted while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown; FALSE by default.
171   bool ToInvertPitch() const { return myToInvertPitch; }
172
173   //! Set flag inverting pitch direction.
174   void SetInvertPitch (bool theToInvert) { myToInvertPitch = theToInvert; }
175
176   //! Return normal walking speed, in m/s; 1.5 by default.
177   float WalkSpeedAbsolute() const { return myWalkSpeedAbsolute; }
178
179   //! Set normal walking speed, in m/s; 1.5 by default.
180   void SetWalkSpeedAbsolute (float theSpeed) { myWalkSpeedAbsolute = theSpeed; }
181
182   //! Return walking speed relative to scene bounding box; 0.1 by default.
183   float WalkSpeedRelative() const { return myWalkSpeedRelative; }
184
185   //! Set walking speed relative to scene bounding box.
186   void SetWalkSpeedRelative (float theFactor) { myWalkSpeedRelative = theFactor; }
187
188   //! Return active thrust value; 0.0f by default.
189   float ThrustSpeed() const { return myThrustSpeed; }
190
191   //! Set active thrust value.
192   void SetThrustSpeed (float theSpeed) { myThrustSpeed = theSpeed; }
193
194   //! Return TRUE if previous position of MoveTo has been defined.
195   bool HasPreviousMoveTo() const { return myPrevMoveTo != Graphic3d_Vec2i (-1); }
196
197   //! Return previous position of MoveTo event in 3D viewer.
198   const Graphic3d_Vec2i& PreviousMoveTo() const { return myPrevMoveTo; }
199
200   //! Reset previous position of MoveTo.
201   void ResetPreviousMoveTo() { myPrevMoveTo = Graphic3d_Vec2i (-1); }
202
203 public: //! @name keyboard input
204
205   //! Return keyboard state.
206   const Aspect_VKeySet& Keys() const { return myKeys; }
207
208   //! Return keyboard state.
209   Aspect_VKeySet& ChangeKeys() { return myKeys; }
210
211   //! Press key.
212   //! @param theKey key pressed
213   //! @param theTime event timestamp
214   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
215                                         double theTime,
216                                         double thePressure = 1.0);
217
218   //! Release key.
219   //! @param theKey key pressed
220   //! @param theTime event timestamp
221   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
222                                       double theTime);
223
224   //! Simulate key up/down events from axis value.
225   Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
226                                             Aspect_VKey thePositive,
227                                             double theTime,
228                                             double thePressure);
229
230   //! Fetch active navigation actions.
231   Standard_EXPORT AIS_WalkDelta FetchNavigationKeys (Standard_Real theCrouchRatio,
232                                                      Standard_Real theRunRatio);
233
234 public: //! @name mouse input
235
236   //! Return map defining mouse gestures.
237   const AIS_MouseGestureMap& MouseGestureMap() const { return myMouseGestureMap; }
238
239   //! Return map defining mouse gestures.
240   AIS_MouseGestureMap& ChangeMouseGestureMap() { return myMouseGestureMap; }
241
242   //! Return double click interval in seconds; 0.4 by default.
243   double MouseDoubleClickInterval() const { return myMouseDoubleClickInt; }
244
245   //! Set double click interval in seconds.
246   void SetMouseDoubleClickInterval (double theSeconds) { myMouseDoubleClickInt = theSeconds; }
247
248   //! Perform selection in 3D viewer.
249   //! This method is expected to be called from UI thread.
250   //! @param thePnt picking point
251   //! @param theIsXOR XOR selection flag
252   Standard_EXPORT virtual void SelectInViewer (const Graphic3d_Vec2i& thePnt,
253                                                const bool theIsXOR = false);
254
255   //! Perform selection in 3D viewer.
256   //! This method is expected to be called from UI thread.
257   //! @param thePnts picking point
258   //! @param theIsXOR XOR selection flag
259   Standard_EXPORT virtual void SelectInViewer (const NCollection_Sequence<Graphic3d_Vec2i>& thePnts,
260                                                const bool theIsXOR = false);
261
262   //! Update rectangle selection tool.
263   //! This method is expected to be called from UI thread.
264   //! @param thePntFrom rectangle first   corner
265   //! @param thePntTo   rectangle another corner
266   //! @param theIsXOR XOR selection flag
267   Standard_EXPORT virtual void UpdateRubberBand (const Graphic3d_Vec2i& thePntFrom,
268                                                  const Graphic3d_Vec2i& thePntTo,
269                                                  const bool theIsXOR = false);
270
271   //! Update polygonal selection tool.
272   //! This method is expected to be called from UI thread.
273   //! @param thePnt new point to add to polygon
274   //! @param theToAppend append new point or update the last point
275   Standard_EXPORT virtual void UpdatePolySelection (const Graphic3d_Vec2i& thePnt,
276                                                     bool theToAppend);
277
278   //! Update zoom event (e.g. from mouse scroll).
279   //! This method is expected to be called from UI thread.
280   //! @param theDelta mouse cursor position to zoom at and zoom delta
281   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
282   Standard_EXPORT virtual bool UpdateZoom (const Aspect_ScrollDelta& theDelta);
283
284   //! Update Z rotation event.
285   //! @param theAngle rotation angle, in radians.
286   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
287   Standard_EXPORT virtual bool UpdateZRotation (double theAngle);
288
289   //! Update mouse scroll event; redirects to UpdateZoom by default.
290   //! This method is expected to be called from UI thread.
291   //! @param theDelta mouse cursor position and delta
292   //! @return TRUE if new event has been created or FALSE if existing one has been updated
293   Standard_EXPORT virtual bool UpdateMouseScroll (const Aspect_ScrollDelta& theDelta);
294
295   //! Handle mouse button press/release event.
296   //! This method is expected to be called from UI thread.
297   //! @param thePoint      mouse cursor position
298   //! @param theButtons    pressed buttons
299   //! @param theModifiers  key modifiers
300   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
301   //!                      but emulated from non-precise input like touch on screen
302   //! @return TRUE if View should be redrawn
303   Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
304                                                    Aspect_VKeyMouse theButtons,
305                                                    Aspect_VKeyFlags theModifiers,
306                                                    bool theIsEmulated);
307
308   //! Handle mouse cursor movement event.
309   //! This method is expected to be called from UI thread.
310   //! @param thePoint      mouse cursor position
311   //! @param theButtons    pressed buttons
312   //! @param theModifiers  key modifiers
313   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
314   //!                      but emulated from non-precise input like touch on screen
315   //! @return TRUE if View should be redrawn
316   Standard_EXPORT virtual bool UpdateMousePosition (const Graphic3d_Vec2i& thePoint,
317                                                     Aspect_VKeyMouse theButtons,
318                                                     Aspect_VKeyFlags theModifiers,
319                                                     bool theIsEmulated);
320
321   //! Handle mouse button press event.
322   //! This method is expected to be called from UI thread.
323   //! @param thePoint      mouse cursor position
324   //! @param theButton     pressed button
325   //! @param theModifiers  key modifiers
326   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
327   //!                      but emulated from non-precise input like touch on screen
328   //! @return TRUE if View should be redrawn
329   bool PressMouseButton (const Graphic3d_Vec2i& thePoint,
330                          Aspect_VKeyMouse theButton,
331                          Aspect_VKeyFlags theModifiers,
332                          bool theIsEmulated)
333   {
334     return UpdateMouseButtons (thePoint, myMousePressed | theButton, theModifiers, theIsEmulated);
335   }
336
337   //! Handle mouse button release event.
338   //! This method is expected to be called from UI thread.
339   //! @param thePoint      mouse cursor position
340   //! @param theButton     released button
341   //! @param theModifiers  key modifiers
342   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
343   //!                      but emulated from non-precise input like touch on screen
344   //! @return TRUE if View should be redrawn
345   bool ReleaseMouseButton (const Graphic3d_Vec2i& thePoint,
346                            Aspect_VKeyMouse theButton,
347                            Aspect_VKeyFlags theModifiers,
348                            bool theIsEmulated)
349   {
350     Aspect_VKeyMouse aButtons = myMousePressed & (~theButton);
351     return UpdateMouseButtons (thePoint, aButtons, theModifiers, theIsEmulated);
352   }
353
354   //! Handle mouse button click event (emulated by UpdateMouseButtons() while releasing single button).
355   //! Note that as this method is called by UpdateMouseButtons(), it should be executed from UI thread.
356   //! Default implementation redirects to SelectInViewer().
357   //! This method is expected to be called from UI thread.
358   //! @param thePoint      mouse cursor position
359   //! @param theButton     clicked button
360   //! @param theModifiers  key modifiers
361   //! @param theIsDoubleClick flag indicating double mouse click
362   //! @return TRUE if View should be redrawn
363   Standard_EXPORT virtual bool UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
364                                                  Aspect_VKeyMouse theButton,
365                                                  Aspect_VKeyFlags theModifiers,
366                                                  bool theIsDoubleClick);
367
368   //! Return currently pressed mouse buttons.
369   Aspect_VKeyMouse PressedMouseButtons() const { return myMousePressed; }
370
371   //! Return active key modifiers passed with last mouse event.
372   Aspect_VKeyFlags LastMouseFlags() const { return myMouseModifiers; }
373
374   //! Return last mouse position.
375   const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
376
377 public: //! @name multi-touch input
378
379   //! Return scale factor for adjusting tolerances for starting multi-touch gestures; 1.0 by default
380   //! This scale factor is expected to be computed from touch screen resolution.
381   float TouchToleranceScale() const { return myTouchToleranceScale; }
382
383   //! Set scale factor for adjusting tolerances for starting multi-touch gestures.
384   void SetTouchToleranceScale (float theTolerance) { myTouchToleranceScale = theTolerance; }
385
386   //! Return TRUE if touches map is not empty.
387   bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
388
389   //! Add touch point with the given ID.
390   //! This method is expected to be called from UI thread.
391   //! @param theId touch unique identifier
392   //! @param thePnt touch coordinates
393   //! @param theClearBefore if TRUE previously registered touches will be removed
394   Standard_EXPORT virtual void AddTouchPoint (Standard_Size theId,
395                                               const Graphic3d_Vec2d& thePnt,
396                                               Standard_Boolean theClearBefore = false);
397
398   //! Remove touch point with the given ID.
399   //! This method is expected to be called from UI thread.
400   //! @param theId touch unique identifier
401   //! @param theClearSelectPnts if TRUE will initiate clearing of selection points
402   //! @return TRUE if point has been removed
403   Standard_EXPORT virtual bool RemoveTouchPoint (Standard_Size theId,
404                                                  Standard_Boolean theClearSelectPnts = false);
405
406   //! Update touch point with the given ID.
407   //! If point with specified ID was not registered before, it will be added.
408   //! This method is expected to be called from UI thread.
409   //! @param theId touch unique identifier
410   //! @param thePnt touch coordinates
411   Standard_EXPORT virtual void UpdateTouchPoint (Standard_Size theId,
412                                                  const Graphic3d_Vec2d& thePnt);
413
414 public:
415
416   //! Return event time (e.g. current time).
417   double EventTime() const { return myEventTimer.ElapsedTime(); }
418
419   //! Reset input state (pressed keys, mouse buttons, etc.) e.g. on window focus loss.
420   //! This method is expected to be called from UI thread.
421   Standard_EXPORT virtual void ResetViewInput();
422
423   //! Reset view orientation.
424   //! This method is expected to be called from UI thread.
425   Standard_EXPORT virtual void UpdateViewOrientation (V3d_TypeOfOrientation theOrientation,
426                                                       bool theToFitAll);
427
428   //! Update buffer for rendering thread.
429   //! This method is expected to be called within synchronization barrier between GUI
430   //! and Rendering threads (e.g. GUI thread should be locked beforehand to avoid data races).
431   //! @param theCtx interactive context
432   //! @param theView active view
433   //! @param theToHandle if TRUE, the HandleViewEvents() will be called
434   Standard_EXPORT virtual void FlushViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
435                                                 const Handle(V3d_View)& theView,
436                                                 Standard_Boolean theToHandle = Standard_False);
437
438   //! Process events within rendering thread.
439   Standard_EXPORT virtual void HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
440                                                  const Handle(V3d_View)& theView);
441
442 public:
443
444   //! Callback called by handleMoveTo() on Selection in 3D Viewer.
445   //! This method is expected to be called from rendering thread.
446   Standard_EXPORT virtual void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
447                                                    const Handle(V3d_View)& theView);
448
449   //! Callback called by handleMoveTo() on dragging object in 3D Viewer.
450   //! This method is expected to be called from rendering thread.
451   Standard_EXPORT virtual void OnObjectDragged (const Handle(AIS_InteractiveContext)& theCtx,
452                                                 const Handle(V3d_View)& theView,
453                                                 AIS_DragAction theAction);
454
455   //! Pick closest point under mouse cursor.
456   //! This method is expected to be called from rendering thread.
457   //! @param thePnt   [out] result point
458   //! @param theCtx    [in] interactive context
459   //! @param theView   [in] active view
460   //! @param theCursor [in] mouse cursor
461   //! @param theToStickToPickRay [in] when TRUE, the result point will lie on picking ray
462   //! @return TRUE if result has been found
463   Standard_EXPORT virtual bool PickPoint (gp_Pnt& thePnt,
464                                           const Handle(AIS_InteractiveContext)& theCtx,
465                                           const Handle(V3d_View)& theView,
466                                           const Graphic3d_Vec2i& theCursor,
467                                           bool theToStickToPickRay);
468
469   //! Compute rotation gravity center point depending on rotation mode.
470   //! This method is expected to be called from rendering thread.
471   Standard_EXPORT virtual gp_Pnt GravityPoint (const Handle(AIS_InteractiveContext)& theCtx,
472                                                const Handle(V3d_View)& theView);
473
474 public:
475
476   //! Perform camera actions.
477   //! This method is expected to be called from rendering thread.
478   Standard_EXPORT virtual void handleCameraActions (const Handle(AIS_InteractiveContext)& theCtx,
479                                                     const Handle(V3d_View)& theView,
480                                                     const AIS_WalkDelta& theWalk);
481
482   //! Perform moveto/selection/dragging.
483   //! This method is expected to be called from rendering thread.
484   Standard_EXPORT virtual void handleMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
485                                              const Handle(V3d_View)& theView);
486
487   //! Return TRUE if another frame should be drawn right after this one.
488   bool toAskNextFrame() const { return myToAskNextFrame; }
489
490   //! Set if another frame should be drawn right after this one.
491   void setAskNextFrame (bool theToDraw = true) { myToAskNextFrame = theToDraw; }
492
493   //! Return if panning anchor point has been defined.
494   bool hasPanningAnchorPoint() const { return !Precision::IsInfinite (myPanPnt3d.X()); }
495
496   //! Return active panning anchor point.
497   const gp_Pnt& panningAnchorPoint() const { return myPanPnt3d; }
498
499   //! Set active panning anchor point.
500   void setPanningAnchorPoint (const gp_Pnt& thePnt) { myPanPnt3d = thePnt; }
501
502   //! Handle panning event myGL.Panning.
503   Standard_EXPORT virtual void handlePanning (const Handle(V3d_View)& theView);
504
505   //! Handle Z rotation event myGL.ZRotate.
506   Standard_EXPORT virtual void handleZRotate (const Handle(V3d_View)& theView);
507
508   //! Return minimal camera distance for zoom operation.
509   double MinZoomDistance() const { return myMinCamDistance; }
510
511   //! Set minimal camera distance for zoom operation.
512   void SetMinZoomDistance (double theDist) { myMinCamDistance = theDist; }
513
514   //! Handle zoom event myGL.ZoomActions.
515   //! This method is expected to be called from rendering thread.
516   Standard_EXPORT virtual void handleZoom (const Handle(V3d_View)& theView,
517                                            const Aspect_ScrollDelta& theParams,
518                                            const gp_Pnt* thePnt);
519
520   //! Handle ZScroll event myGL.ZoomActions.
521   //! This method is expected to be called from rendering thread.
522   Standard_EXPORT virtual void handleZFocusScroll (const Handle(V3d_View)& theView,
523                                                    const Aspect_ScrollDelta& theParams);
524
525   //! Handle orbital rotation events myGL.OrbitRotation.
526   //! @param theView view to modify
527   //! @param thePnt 3D point to rotate around
528   //! @param theToLockZUp amend camera to exclude roll angle (put camera Up vector to plane containing global Z and view direction)
529   Standard_EXPORT virtual void handleOrbitRotation (const Handle(V3d_View)& theView,
530                                                     const gp_Pnt& thePnt,
531                                                     bool theToLockZUp);
532
533   //! Handle view direction rotation events myGL.ViewRotation.
534   //! This method is expected to be called from rendering thread.
535   //! @param theView       camera to modify
536   //! @param theYawExtra   extra yaw increment
537   //! @param thePitchExtra extra pitch increment
538   //! @param theRoll       roll value
539   //! @param theToRestartOnIncrement flag indicating flight mode
540   Standard_EXPORT virtual void handleViewRotation (const Handle(V3d_View)& theView,
541                                                    double theYawExtra,
542                                                    double thePitchExtra,
543                                                    double theRoll,
544                                                    bool theToRestartOnIncrement);
545
546   //! Handle view redraw.
547   //! This method is expected to be called from rendering thread.
548   Standard_EXPORT virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
549                                                  const Handle(V3d_View)& theView);
550
551 protected:
552
553   //! Flush buffers.
554   Standard_EXPORT virtual void flushBuffers (const Handle(AIS_InteractiveContext)& theCtx,
555                                              const Handle(V3d_View)& theView);
556
557   //! Flush touch gestures.
558   Standard_EXPORT virtual void flushGestures (const Handle(AIS_InteractiveContext)& theCtx,
559                                               const Handle(V3d_View)& theView);
560
561   //! Return current and previously fetched event times.
562   //! This callback is intended to compute delta between sequentially processed events.
563   //! @param thePrevTime [out] events time fetched previous time by this method
564   //! @param theCurrTime [out] actual events time
565   void updateEventsTime (double& thePrevTime,
566                          double& theCurrTime)
567   {
568     thePrevTime = myLastEventsTime;
569     myLastEventsTime = EventTime();
570     theCurrTime = myLastEventsTime;
571   }
572
573   //! Perform selection via mouse click.
574   //! This method is expected to be called from rendering thread.
575   Standard_EXPORT virtual void handleSelectionPick (const Handle(AIS_InteractiveContext)& theCtx,
576                                                     const Handle(V3d_View)& theView);
577
578   //! Perform dynamic highlight on mouse move.
579   //! This method is expected to be called from rendering thread.
580   Standard_EXPORT virtual void handleDynamicHighlight (const Handle(AIS_InteractiveContext)& theCtx,
581                                                        const Handle(V3d_View)& theView);
582
583   //! Perform rubber-band selection.
584   //! This method is expected to be called from rendering thread.
585   Standard_EXPORT virtual void handleSelectionPoly (const Handle(AIS_InteractiveContext)& theCtx,
586                                                     const Handle(V3d_View)& theView);
587
588   //! Lazy AIS_InteractiveContext::MoveTo() with myPrevMoveTo check.
589   Standard_EXPORT virtual void contextLazyMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
590                                                   const Handle(V3d_View)& theView,
591                                                   const Graphic3d_Vec2i& thePnt);
592
593 protected:
594
595   AIS_ViewInputBuffer myUI;                       //!< buffer for UI thread
596   AIS_ViewInputBuffer myGL;                       //!< buffer for rendering thread
597
598   OSD_Timer           myEventTimer;               //!< timer for timestamping events
599   Standard_Real       myLastEventsTime;           //!< last fetched events timer value for computing delta/progress
600   Standard_Boolean    myToAskNextFrame;           //!< flag indicating that another frame should be drawn right after this one
601
602   Standard_Real       myMinCamDistance;           //!< minimal camera distance for zoom operation
603   AIS_RotationMode    myRotationMode;             //!< rotation mode
604   AIS_NavigationMode  myNavigationMode;           //!< navigation mode (orbit rotation / first person)
605   Standard_ShortReal  myMouseAccel;               //!< mouse input acceleration ratio in First Person mode
606   Standard_ShortReal  myOrbitAccel;               //!< Orbit rotation acceleration ratio
607   Standard_Boolean    myToShowPanAnchorPoint;     //!< option displaying panning  anchor point
608   Standard_Boolean    myToShowRotateCenter;       //!< option displaying rotation center point
609   Standard_Boolean    myToLockOrbitZUp;           //!< force camera up orientation within AIS_NavigationMode_Orbit rotation mode
610   Standard_Boolean    myToInvertPitch;            //!< flag inverting pitch direction while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown
611   Standard_Boolean    myToAllowTouchZRotation;    //!< enable z-rotation two-touches gesture; FALSE by default
612   Standard_Boolean    myToAllowRotation;          //!< enable rotation; TRUE by default
613   Standard_Boolean    myToAllowPanning;           //!< enable panning; TRUE by default
614   Standard_Boolean    myToAllowZooming;           //!< enable zooming; TRUE by default
615   Standard_Boolean    myToAllowZFocus;            //!< enable ZFocus change; TRUE by default
616   Standard_Boolean    myToAllowHighlight;         //!< enable dynamic highlight on mouse move; TRUE by default
617   Standard_Boolean    myToAllowDragging;          //!< enable dragging object; TRUE by default
618   Standard_Boolean    myToStickToRayOnZoom;       //!< project picked point to ray while zooming at point, TRUE by default
619   Standard_Boolean    myToStickToRayOnRotation;   //!< project picked point to ray while rotating around point; TRUE by default
620
621   Standard_ShortReal  myWalkSpeedAbsolute;        //!< normal walking speed, in m/s; 1.5 by default
622   Standard_ShortReal  myWalkSpeedRelative;        //!< walking speed relative to scene bounding box; 0.1 by default
623   Standard_ShortReal  myThrustSpeed;              //!< active thrust value
624   Standard_Boolean    myHasThrust;                //!< flag indicating active thrust
625
626   Handle(AIS_AnimationCamera) myViewAnimation;    //!< view animation
627   Handle(AIS_RubberBand) myRubberBand;            //!< Rubber-band presentation
628   Handle(AIS_InteractiveObject) myDragObject;     //!< currently dragged object
629   Graphic3d_Vec2i     myPrevMoveTo;               //!< previous position of MoveTo event in 3D viewer
630   Standard_Boolean    myHasHlrOnBeforeRotation;   //!< flag for restoring Computed mode after rotation
631
632 protected: //! @name keyboard input variables
633
634   Aspect_VKeySet      myKeys;                     //!< keyboard state
635
636 protected: //! @name mouse input variables
637
638   Standard_Real       myMouseClickThreshold;      //!< mouse click threshold in pixels; 3 by default
639   Standard_Real       myMouseDoubleClickInt;      //!< double click interval in seconds; 0.4 by default
640   Standard_ShortReal  myScrollZoomRatio;          //!< distance ratio for mapping mouse scroll event to zoom; 15.0 by default
641
642   AIS_MouseGestureMap myMouseGestureMap;          //!< map defining mouse gestures
643   AIS_MouseGesture    myMouseActiveGesture;       //!< initiated mouse gesture (by pressing mouse button)
644   Standard_Boolean    myMouseActiveIdleRotation;  //!< flag indicating view idle rotation state
645   Graphic3d_Vec2i     myMousePositionLast;        //!< last mouse position
646   Graphic3d_Vec2i     myMousePressPoint;          //!< mouse position where active gesture was been initiated
647   Graphic3d_Vec2i     myMouseProgressPoint;       //!< gesture progress
648   OSD_Timer           myMouseClickTimer;          //!< timer for handling double-click event
649   Standard_Integer    myMouseClickCounter;        //!< counter for handling double-click event
650   Aspect_VKeyMouse    myMousePressed;             //!< active mouse buttons
651   Aspect_VKeyFlags    myMouseModifiers;           //!< active key modifiers passed with last mouse event
652   Standard_Integer    myMouseSingleButton;        //!< index of mouse button pressed alone (>0)
653   Standard_Boolean    myMouseStopDragOnUnclick;   //!< queue stop dragging even with at next mouse unclick
654
655 protected: //! @name multi-touch input variables
656
657   Standard_ShortReal  myTouchToleranceScale;      //!< tolerance scale factor; 1.0 by default
658   Standard_ShortReal  myTouchRotationThresholdPx; //!< threshold for starting one-touch rotation     gesture in pixels;  6 by default
659   Standard_ShortReal  myTouchZRotationThreshold;  //!< threshold for starting two-touch Z-rotation   gesture in radians; 2 degrees by default
660   Standard_ShortReal  myTouchPanThresholdPx;      //!< threshold for starting two-touch panning      gesture in pixels;  4 by default
661   Standard_ShortReal  myTouchZoomThresholdPx;     //!< threshold for starting two-touch zoom (pitch) gesture in pixels;  6 by default
662   Standard_ShortReal  myTouchZoomRatio;           //!< distance ratio for mapping two-touch zoom (pitch) gesture from pixels to zoom; 0.13 by default
663
664   Aspect_TouchMap     myTouchPoints;              //!< map of active touches
665   Graphic3d_Vec2d     myStartPanCoord;            //!< touch coordinates at the moment of starting panning  gesture
666   Graphic3d_Vec2d     myStartRotCoord;            //!< touch coordinates at the moment of starting rotating gesture
667   Standard_Integer    myNbTouchesLast;            //!< number of touches within previous gesture flush to track gesture changes
668   Standard_Boolean    myUpdateStartPointPan;      //!< flag indicating that new anchor  point should be picked for starting panning    gesture
669   Standard_Boolean    myUpdateStartPointRot;      //!< flag indicating that new gravity point should be picked for starting rotation   gesture
670   Standard_Boolean    myUpdateStartPointZRot;     //!< flag indicating that new gravity point should be picked for starting Z-rotation gesture
671
672 protected: //! @name rotation/panning transient state variables
673
674   Handle(AIS_Point)   myAnchorPointPrs1;          //!< anchor point presentation (Graphic3d_ZLayerId_Top)
675   Handle(AIS_Point)   myAnchorPointPrs2;          //!< anchor point presentation (Graphic3d_ZLayerId_Topmost)
676   gp_Pnt              myPanPnt3d;                 //!< active panning anchor point
677   gp_Pnt              myRotatePnt3d;              //!< active rotation center of gravity
678   gp_Dir              myCamStartOpUp;             //!< camera Up    direction at the beginning of rotation
679   gp_Dir              myCamStartOpDir;            //!< camera View  direction at the beginning of rotation
680   gp_Pnt              myCamStartOpEye;            //!< camera Eye    position at the beginning of rotation
681   gp_Pnt              myCamStartOpCenter;         //!< camera Center position at the beginning of rotation
682   gp_Vec              myCamStartOpToCenter;       //!< vector from rotation gravity point to camera Center at the beginning of rotation
683   gp_Vec              myCamStartOpToEye;          //!< vector from rotation gravity point to camera Eye    at the beginning of rotation
684   Graphic3d_Vec3d     myRotateStartYawPitchRoll;  //!< camera yaw pitch roll at the beginning of rotation
685
686 };
687
688 #endif // _AIS_ViewController_HeaderFile