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