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 <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>
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>
36 class AIS_AnimationCamera;
37 class AIS_InteractiveObject;
38 class AIS_InteractiveContext;
41 class AIS_XRTrackedDevice;
42 class Graphic3d_Camera;
43 class SelectMgr_EntityOwner;
45 class WNT_HIDSpaceMouse;
47 //! Auxiliary structure for handling viewer events between GUI and Rendering threads.
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
58 //! Empty constructor.
59 Standard_EXPORT AIS_ViewController();
62 Standard_EXPORT virtual ~AIS_ViewController();
64 //! Return input buffer.
65 const AIS_ViewInputBuffer& InputBuffer (AIS_ViewInputBufferType theType) const { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
67 //! Return input buffer.
68 AIS_ViewInputBuffer& ChangeInputBuffer (AIS_ViewInputBufferType theType) { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
70 //! Return view animation; empty (but not NULL) animation by default.
71 const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; }
73 //! Set view animation to be handled within handleViewRedraw().
74 void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; }
76 //! Interrupt active view animation.
77 Standard_EXPORT void AbortViewAnimation();
79 public: //! @name global parameters
81 //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default.
82 AIS_RotationMode RotationMode() const { return myRotationMode; }
84 //! Set camera rotation mode.
85 void SetRotationMode (AIS_RotationMode theMode) { myRotationMode = theMode; }
87 //! Return camera navigation mode; AIS_NavigationMode_Orbit by default.
88 AIS_NavigationMode NavigationMode() const { return myNavigationMode; }
90 //! Set camera navigation mode.
91 Standard_EXPORT void SetNavigationMode (AIS_NavigationMode theMode);
93 //! Return mouse input acceleration ratio in First Person mode; 1.0 by default.
94 float MouseAcceleration() const { return myMouseAccel; }
96 //! Set mouse input acceleration ratio.
97 void SetMouseAcceleration (float theRatio) { myMouseAccel = theRatio; }
99 //! Return orbit rotation acceleration ratio; 1.0 by default.
100 float OrbitAcceleration() const { return myOrbitAccel; }
102 //! Set orbit rotation acceleration ratio.
103 void SetOrbitAcceleration (float theRatio) { myOrbitAccel = theRatio; }
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; }
108 //! Set if panning anchor point within perspective projection should be displayed in 3D Viewer.
109 void SetShowPanAnchorPoint (bool theToShow) { myToShowPanAnchorPoint = theToShow; }
111 //! Return TRUE if rotation point should be displayed in 3D Viewer; TRUE by default.
112 bool ToShowRotateCenter() const { return myToShowRotateCenter; }
114 //! Set if rotation point should be displayed in 3D Viewer.
115 void SetShowRotateCenter (bool theToShow) { myToShowRotateCenter = theToShow; }
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; }
120 //! Set if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up.
121 void SetLockOrbitZUp (bool theToForceUp) { myToLockOrbitZUp = theToForceUp; }
123 //! Return TRUE if z-rotation via two-touches gesture is enabled; FALSE by default.
124 bool ToAllowTouchZRotation() const { return myToAllowTouchZRotation; }
126 //! Set if z-rotation via two-touches gesture is enabled.
127 void SetAllowTouchZRotation (bool theToEnable) { myToAllowTouchZRotation = theToEnable; }
129 //! Return TRUE if camera rotation is allowed; TRUE by default.
130 bool ToAllowRotation() const { return myToAllowRotation; }
132 //! Set if camera rotation is allowed.
133 void SetAllowRotation (bool theToEnable) { myToAllowRotation = theToEnable; }
135 //! Return TRUE if panning is allowed; TRUE by default.
136 bool ToAllowPanning() const { return myToAllowPanning; }
138 //! Set if panning is allowed.
139 void SetAllowPanning (bool theToEnable) { myToAllowPanning = theToEnable; }
141 //! Return TRUE if zooming is allowed; TRUE by default.
142 bool ToAllowZooming() const { return myToAllowZooming; }
144 //! Set if zooming is allowed.
145 void SetAllowZooming (bool theToEnable) { myToAllowZooming = theToEnable; }
147 //! Return TRUE if ZFocus change is allowed; TRUE by default.
148 bool ToAllowZFocus() const { return myToAllowZFocus; }
150 //! Set if ZFocus change is allowed.
151 void SetAllowZFocus (bool theToEnable) { myToAllowZFocus = theToEnable; }
153 //! Return TRUE if dynamic highlight on mouse move is allowed; TRUE by default.
154 bool ToAllowHighlight() const { return myToAllowHighlight; }
156 //! Set if dragging object is allowed.
157 void SetAllowHighlight (bool theToEnable) { myToAllowHighlight = theToEnable; }
159 //! Return TRUE if dragging object is allowed; TRUE by default.
160 bool ToAllowDragging() const { return myToAllowDragging; }
162 //! Set if dynamic highlight on mouse move is allowed.
163 void SetAllowDragging (bool theToEnable) { myToAllowDragging = theToEnable; }
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; }
168 //! Set if picked point should be projected to picking ray on zooming at point.
169 void SetStickToRayOnZoom (bool theToEnable) { myToStickToRayOnZoom = theToEnable; }
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; }
174 //! Set if picked point should be projected to picking ray on rotating around point.
175 void SetStickToRayOnRotation (bool theToEnable) { myToStickToRayOnRotation = theToEnable; }
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; }
180 //! Set flag inverting pitch direction.
181 void SetInvertPitch (bool theToInvert) { myToInvertPitch = theToInvert; }
183 //! Return normal walking speed, in m/s; 1.5 by default.
184 float WalkSpeedAbsolute() const { return myWalkSpeedAbsolute; }
186 //! Set normal walking speed, in m/s; 1.5 by default.
187 void SetWalkSpeedAbsolute (float theSpeed) { myWalkSpeedAbsolute = theSpeed; }
189 //! Return walking speed relative to scene bounding box; 0.1 by default.
190 float WalkSpeedRelative() const { return myWalkSpeedRelative; }
192 //! Set walking speed relative to scene bounding box.
193 void SetWalkSpeedRelative (float theFactor) { myWalkSpeedRelative = theFactor; }
195 //! Return active thrust value; 0.0f by default.
196 float ThrustSpeed() const { return myThrustSpeed; }
198 //! Set active thrust value.
199 void SetThrustSpeed (float theSpeed) { myThrustSpeed = theSpeed; }
201 //! Return TRUE if previous position of MoveTo has been defined.
202 bool HasPreviousMoveTo() const { return myPrevMoveTo != Graphic3d_Vec2i (-1); }
204 //! Return previous position of MoveTo event in 3D viewer.
205 const Graphic3d_Vec2i& PreviousMoveTo() const { return myPrevMoveTo; }
207 //! Reset previous position of MoveTo.
208 void ResetPreviousMoveTo() { myPrevMoveTo = Graphic3d_Vec2i (-1); }
210 //! Return TRUE to display auxiliary tracked XR devices (like tracking stations).
211 bool ToDisplayXRAuxDevices() const { return myToDisplayXRAuxDevices; }
213 //! Set if auxiliary tracked XR devices should be displayed.
214 void SetDisplayXRAuxDevices (bool theToDisplay) { myToDisplayXRAuxDevices = theToDisplay; }
216 //! Return TRUE to display XR hand controllers.
217 bool ToDisplayXRHands() const { return myToDisplayXRHands; }
219 //! Set if tracked XR hand controllers should be displayed.
220 void SetDisplayXRHands (bool theToDisplay) { myToDisplayXRHands = theToDisplay; }
222 public: //! @name keyboard input
224 //! Return keyboard state.
225 const Aspect_VKeySet& Keys() const { return myKeys; }
227 //! Return keyboard state.
228 Aspect_VKeySet& ChangeKeys() { return myKeys; }
231 //! @param theKey key pressed
232 //! @param theTime event timestamp
233 Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
235 double thePressure = 1.0);
238 //! @param theKey key pressed
239 //! @param theTime event timestamp
240 Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
243 //! Simulate key up/down events from axis value.
244 Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
245 Aspect_VKey thePositive,
249 //! Fetch active navigation actions.
250 Standard_EXPORT AIS_WalkDelta FetchNavigationKeys (Standard_Real theCrouchRatio,
251 Standard_Real theRunRatio);
253 public: //! @name mouse input
255 //! Return map defining mouse gestures.
256 const AIS_MouseGestureMap& MouseGestureMap() const { return myMouseGestureMap; }
258 //! Return map defining mouse gestures.
259 AIS_MouseGestureMap& ChangeMouseGestureMap() { return myMouseGestureMap; }
261 //! Return map defining mouse selection schemes.
262 const AIS_MouseSelectionSchemeMap& MouseSelectionSchemes() const { return myMouseSelectionSchemes; }
264 //! Return map defining mouse gestures.
265 AIS_MouseSelectionSchemeMap& ChangeMouseSelectionSchemes() { return myMouseSelectionSchemes; }
267 //! Return double click interval in seconds; 0.4 by default.
268 double MouseDoubleClickInterval() const { return myMouseDoubleClickInt; }
270 //! Set double click interval in seconds.
271 void SetMouseDoubleClickInterval (double theSeconds) { myMouseDoubleClickInt = theSeconds; }
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);
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);
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);
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,
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);
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);
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);
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,
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,
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,
357 return UpdateMouseButtons (thePoint, myMousePressed | theButton, theModifiers, theIsEmulated);
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,
373 Aspect_VKeyMouse aButtons = myMousePressed & (~theButton);
374 return UpdateMouseButtons (thePoint, aButtons, theModifiers, theIsEmulated);
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);
391 //! Return currently pressed mouse buttons.
392 Aspect_VKeyMouse PressedMouseButtons() const { return myMousePressed; }
394 //! Return active key modifiers passed with last mouse event.
395 Aspect_VKeyFlags LastMouseFlags() const { return myMouseModifiers; }
397 //! Return last mouse position.
398 const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
400 public: //! @name multi-touch input
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; }
406 //! Set scale factor for adjusting tolerances for starting multi-touch gestures.
407 void SetTouchToleranceScale (float theTolerance) { myTouchToleranceScale = theTolerance; }
409 //! Return TRUE if touches map is not empty.
410 bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
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);
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);
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);
437 public: //! @name 3d mouse input
439 //! Return acceleration ratio for translation event; 2.0 by default.
440 float Get3dMouseTranslationScale() const { return my3dMouseAccelTrans; }
442 //! Set acceleration ratio for translation event.
443 void Set3dMouseTranslationScale (float theScale) { my3dMouseAccelTrans = theScale; }
445 //! Return acceleration ratio for rotation event; 4.0 by default.
446 float Get3dMouseRotationScale() const { return my3dMouseAccelRotate; }
448 //! Set acceleration ratio for rotation event.
449 void Set3dMouseRotationScale (float theScale) { my3dMouseAccelRotate = theScale; }
451 //! Return quadric acceleration flag; TRUE by default.
452 bool To3dMousePreciseInput() const { return my3dMouseIsQuadric; }
454 //! Set quadric acceleration flag.
455 void Set3dMousePreciseInput (bool theIsQuadric) { my3dMouseIsQuadric = theIsQuadric; }
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; }
460 //! Return 3d mouse rotation axes (tilt/roll/spin) ignore flag; (FALSE, FALSE, FALSE) by default.
461 NCollection_Vec3<bool>& Change3dMouseIsNoRotate() { return my3dMouseNoRotate; }
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; }
466 //! Return 3d mouse rotation axes (tilt/roll/spin) reverse flag; (TRUE, FALSE, FALSE) by default.
467 NCollection_Vec3<bool>& Change3dMouseToReverse() { return my3dMouseToReverse; }
469 //! Process 3d mouse input event (redirects to translation, rotation and keys).
470 Standard_EXPORT virtual bool Update3dMouse (const WNT_HIDSpaceMouse& theEvent);
472 //! Process 3d mouse input translation event.
473 Standard_EXPORT virtual bool update3dMouseTranslation (const WNT_HIDSpaceMouse& theEvent);
475 //! Process 3d mouse input rotation event.
476 Standard_EXPORT virtual bool update3dMouseRotation (const WNT_HIDSpaceMouse& theEvent);
478 //! Process 3d mouse input keys event.
479 Standard_EXPORT virtual bool update3dMouseKeys (const WNT_HIDSpaceMouse& theEvent);
483 //! Return event time (e.g. current time).
484 double EventTime() const { return myEventTimer.ElapsedTime(); }
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();
490 //! Reset view orientation.
491 //! This method is expected to be called from UI thread.
492 Standard_EXPORT virtual void UpdateViewOrientation (V3d_TypeOfOrientation theOrientation,
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);
505 //! Process events within rendering thread.
506 Standard_EXPORT virtual void HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
507 const Handle(V3d_View)& theView);
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);
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);
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);
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);
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);
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);
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);
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);
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);
570 //! Return TRUE if another frame should be drawn right after this one.
571 bool toAskNextFrame() const { return myToAskNextFrame; }
573 //! Set if another frame should be drawn right after this one.
574 void setAskNextFrame (bool theToDraw = true) { myToAskNextFrame = theToDraw; }
576 //! Return if panning anchor point has been defined.
577 bool hasPanningAnchorPoint() const { return !Precision::IsInfinite (myPanPnt3d.X()); }
579 //! Return active panning anchor point.
580 const gp_Pnt& panningAnchorPoint() const { return myPanPnt3d; }
582 //! Set active panning anchor point.
583 void setPanningAnchorPoint (const gp_Pnt& thePnt) { myPanPnt3d = thePnt; }
585 //! Handle panning event myGL.Panning.
586 Standard_EXPORT virtual void handlePanning (const Handle(V3d_View)& theView);
588 //! Handle Z rotation event myGL.ZRotate.
589 Standard_EXPORT virtual void handleZRotate (const Handle(V3d_View)& theView);
591 //! Return minimal camera distance for zoom operation.
592 double MinZoomDistance() const { return myMinCamDistance; }
594 //! Set minimal camera distance for zoom operation.
595 void SetMinZoomDistance (double theDist) { myMinCamDistance = theDist; }
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);
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);
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,
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,
625 double thePitchExtra,
627 bool theToRestartOnIncrement);
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);
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);
642 //! Handle trackpad view turn action.
643 Standard_EXPORT virtual void handleXRTurnPad (const Handle(AIS_InteractiveContext)& theCtx,
644 const Handle(V3d_View)& theView);
646 //! Handle trackpad teleportation action.
647 Standard_EXPORT virtual void handleXRTeleport (const Handle(AIS_InteractiveContext)& theCtx,
648 const Handle(V3d_View)& theView);
650 //! Handle picking on trigger click.
651 Standard_EXPORT virtual void handleXRPicking (const Handle(AIS_InteractiveContext)& theCtx,
652 const Handle(V3d_View)& theView);
654 //! Perform dynamic highlighting for active hand.
655 Standard_EXPORT virtual void handleXRHighlight (const Handle(AIS_InteractiveContext)& theCtx,
656 const Handle(V3d_View)& theView);
658 //! Display auxiliary XR presentations.
659 Standard_EXPORT virtual void handleXRPresentations (const Handle(AIS_InteractiveContext)& theCtx,
660 const Handle(V3d_View)& theView);
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);
671 Standard_EXPORT virtual void flushBuffers (const Handle(AIS_InteractiveContext)& theCtx,
672 const Handle(V3d_View)& theView);
674 //! Flush touch gestures.
675 Standard_EXPORT virtual void flushGestures (const Handle(AIS_InteractiveContext)& theCtx,
676 const Handle(V3d_View)& theView);
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,
685 thePrevTime = myLastEventsTime;
686 myLastEventsTime = EventTime();
687 theCurrTime = myLastEventsTime;
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);
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);
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);
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);
712 AIS_ViewInputBuffer myUI; //!< buffer for UI thread
713 AIS_ViewInputBuffer myGL; //!< buffer for rendering thread
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
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
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
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
750 protected: //! @name XR input variables
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
767 protected: //! @name keyboard input variables
769 Aspect_VKeySet myKeys; //!< keyboard state
771 protected: //! @name mouse input variables
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
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
792 protected: //! @name multi-touch input variables
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
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
809 protected: //! @name 3d mouse input variables
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
818 protected: //! @name rotation/panning transient state variables
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
834 #endif // _AIS_ViewController_HeaderFile