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();
55 Standard_EXPORT virtual ~AIS_ViewController();
57 //! Return input buffer.
58 const AIS_ViewInputBuffer& InputBuffer (AIS_ViewInputBufferType theType) const { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
60 //! Return input buffer.
61 AIS_ViewInputBuffer& ChangeInputBuffer (AIS_ViewInputBufferType theType) { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
63 //! Return view animation; empty (but not NULL) animation by default.
64 const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; }
66 //! Set view animation to be handled within handleViewRedraw().
67 void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; }
69 //! Interrupt active view animation.
70 Standard_EXPORT void AbortViewAnimation();
72 public: //! @name global parameters
74 //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default.
75 AIS_RotationMode RotationMode() const { return myRotationMode; }
77 //! Set camera rotation mode.
78 void SetRotationMode (AIS_RotationMode theMode) { myRotationMode = theMode; }
80 //! Return camera navigation mode; AIS_NavigationMode_Orbit by default.
81 AIS_NavigationMode NavigationMode() const { return myNavigationMode; }
83 //! Set camera navigation mode.
84 Standard_EXPORT void SetNavigationMode (AIS_NavigationMode theMode);
86 //! Return mouse input acceleration ratio in First Person mode; 1.0 by default.
87 float MouseAcceleration() const { return myMouseAccel; }
89 //! Set mouse input acceleration ratio.
90 void SetMouseAcceleration (float theRatio) { myMouseAccel = theRatio; }
92 //! Return orbit rotation acceleration ratio; 1.0 by default.
93 float OrbitAcceleration() const { return myOrbitAccel; }
95 //! Set orbit rotation acceleration ratio.
96 void SetOrbitAcceleration (float theRatio) { myOrbitAccel = theRatio; }
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; }
101 //! Set if panning anchor point within perspective projection should be displayed in 3D Viewer.
102 void SetShowPanAnchorPoint (bool theToShow) { myToShowPanAnchorPoint = theToShow; }
104 //! Return TRUE if rotation point should be displayed in 3D Viewer; TRUE by default.
105 bool ToShowRotateCenter() const { return myToShowRotateCenter; }
107 //! Set if rotation point should be displayed in 3D Viewer.
108 void SetShowRotateCenter (bool theToShow) { myToShowRotateCenter = theToShow; }
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; }
113 //! Set if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up.
114 void SetLockOrbitZUp (bool theToForceUp) { myToLockOrbitZUp = theToForceUp; }
116 //! Return TRUE if z-rotation via two-touches gesture is enabled; FALSE by default.
117 bool ToAllowTouchZRotation() const { return myToAllowTouchZRotation; }
119 //! Set if z-rotation via two-touches gesture is enabled.
120 void SetAllowTouchZRotation (bool theToEnable) { myToAllowTouchZRotation = theToEnable; }
122 //! Return TRUE if camera rotation is allowed; TRUE by default.
123 bool ToAllowRotation() const { return myToAllowRotation; }
125 //! Set if camera rotation is allowed.
126 void SetAllowRotation (bool theToEnable) { myToAllowRotation = theToEnable; }
128 //! Return TRUE if panning is allowed; TRUE by default.
129 bool ToAllowPanning() const { return myToAllowPanning; }
131 //! Set if panning is allowed.
132 void SetAllowPanning (bool theToEnable) { myToAllowPanning = theToEnable; }
134 //! Return TRUE if zooming is allowed; TRUE by default.
135 bool ToAllowZooming() const { return myToAllowZooming; }
137 //! Set if zooming is allowed.
138 void SetAllowZooming (bool theToEnable) { myToAllowZooming = theToEnable; }
140 //! Return TRUE if ZFocus change is allowed; TRUE by default.
141 bool ToAllowZFocus() const { return myToAllowZFocus; }
143 //! Set if ZFocus change is allowed.
144 void SetAllowZFocus (bool theToEnable) { myToAllowZFocus = theToEnable; }
146 //! Return TRUE if dynamic highlight on mouse move is allowed; TRUE by default.
147 bool ToAllowHighlight() const { return myToAllowHighlight; }
149 //! Set if dragging object is allowed.
150 void SetAllowHighlight (bool theToEnable) { myToAllowHighlight = theToEnable; }
152 //! Return TRUE if dragging object is allowed; TRUE by default.
153 bool ToAllowDragging() const { return myToAllowDragging; }
155 //! Set if dynamic highlight on mouse move is allowed.
156 void SetAllowDragging (bool theToEnable) { myToAllowDragging = theToEnable; }
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; }
161 //! Set if picked point should be projected to picking ray on zooming at point.
162 void SetStickToRayOnZoom (bool theToEnable) { myToStickToRayOnZoom = theToEnable; }
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; }
167 //! Set if picked point should be projected to picking ray on rotating around point.
168 void SetStickToRayOnRotation (bool theToEnable) { myToStickToRayOnRotation = theToEnable; }
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; }
173 //! Set flag inverting pitch direction.
174 void SetInvertPitch (bool theToInvert) { myToInvertPitch = theToInvert; }
176 //! Return normal walking speed, in m/s; 1.5 by default.
177 float WalkSpeedAbsolute() const { return myWalkSpeedAbsolute; }
179 //! Set normal walking speed, in m/s; 1.5 by default.
180 void SetWalkSpeedAbsolute (float theSpeed) { myWalkSpeedAbsolute = theSpeed; }
182 //! Return walking speed relative to scene bounding box; 0.1 by default.
183 float WalkSpeedRelative() const { return myWalkSpeedRelative; }
185 //! Set walking speed relative to scene bounding box.
186 void SetWalkSpeedRelative (float theFactor) { myWalkSpeedRelative = theFactor; }
188 //! Return active thrust value; 0.0f by default.
189 float ThrustSpeed() const { return myThrustSpeed; }
191 //! Set active thrust value.
192 void SetThrustSpeed (float theSpeed) { myThrustSpeed = theSpeed; }
194 //! Return TRUE if previous position of MoveTo has been defined.
195 bool HasPreviousMoveTo() const { return myPrevMoveTo != Graphic3d_Vec2i (-1); }
197 //! Return previous position of MoveTo event in 3D viewer.
198 const Graphic3d_Vec2i& PreviousMoveTo() const { return myPrevMoveTo; }
200 //! Reset previous position of MoveTo.
201 void ResetPreviousMoveTo() { myPrevMoveTo = Graphic3d_Vec2i (-1); }
203 public: //! @name keyboard input
205 //! Return keyboard state.
206 const Aspect_VKeySet& Keys() const { return myKeys; }
208 //! Return keyboard state.
209 Aspect_VKeySet& ChangeKeys() { return myKeys; }
212 //! @param theKey key pressed
213 //! @param theTime event timestamp
214 Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
216 double thePressure = 1.0);
219 //! @param theKey key pressed
220 //! @param theTime event timestamp
221 Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
224 //! Simulate key up/down events from axis value.
225 Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
226 Aspect_VKey thePositive,
230 //! Fetch active navigation actions.
231 Standard_EXPORT AIS_WalkDelta FetchNavigationKeys (Standard_Real theCrouchRatio,
232 Standard_Real theRunRatio);
234 public: //! @name mouse input
236 //! Return map defining mouse gestures.
237 const AIS_MouseGestureMap& MouseGestureMap() const { return myMouseGestureMap; }
239 //! Return map defining mouse gestures.
240 AIS_MouseGestureMap& ChangeMouseGestureMap() { return myMouseGestureMap; }
242 //! Return double click interval in seconds; 0.4 by default.
243 double MouseDoubleClickInterval() const { return myMouseDoubleClickInt; }
245 //! Set double click interval in seconds.
246 void SetMouseDoubleClickInterval (double theSeconds) { myMouseDoubleClickInt = theSeconds; }
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);
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);
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);
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,
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);
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);
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);
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,
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,
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,
334 return UpdateMouseButtons (thePoint, myMousePressed | theButton, theModifiers, theIsEmulated);
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,
350 Aspect_VKeyMouse aButtons = myMousePressed & (~theButton);
351 return UpdateMouseButtons (thePoint, aButtons, theModifiers, theIsEmulated);
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);
368 //! Return currently pressed mouse buttons.
369 Aspect_VKeyMouse PressedMouseButtons() const { return myMousePressed; }
371 //! Return active key modifiers passed with last mouse event.
372 Aspect_VKeyFlags LastMouseFlags() const { return myMouseModifiers; }
374 //! Return last mouse position.
375 const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
377 public: //! @name multi-touch input
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; }
383 //! Set scale factor for adjusting tolerances for starting multi-touch gestures.
384 void SetTouchToleranceScale (float theTolerance) { myTouchToleranceScale = theTolerance; }
386 //! Return TRUE if touches map is not empty.
387 bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
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);
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);
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);
416 //! Return event time (e.g. current time).
417 double EventTime() const { return myEventTimer.ElapsedTime(); }
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();
423 //! Reset view orientation.
424 //! This method is expected to be called from UI thread.
425 Standard_EXPORT virtual void UpdateViewOrientation (V3d_TypeOfOrientation theOrientation,
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);
438 //! Process events within rendering thread.
439 Standard_EXPORT virtual void HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
440 const Handle(V3d_View)& theView);
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);
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);
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);
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);
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);
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);
487 //! Return TRUE if another frame should be drawn right after this one.
488 bool toAskNextFrame() const { return myToAskNextFrame; }
490 //! Set if another frame should be drawn right after this one.
491 void setAskNextFrame (bool theToDraw = true) { myToAskNextFrame = theToDraw; }
493 //! Return if panning anchor point has been defined.
494 bool hasPanningAnchorPoint() const { return !Precision::IsInfinite (myPanPnt3d.X()); }
496 //! Return active panning anchor point.
497 const gp_Pnt& panningAnchorPoint() const { return myPanPnt3d; }
499 //! Set active panning anchor point.
500 void setPanningAnchorPoint (const gp_Pnt& thePnt) { myPanPnt3d = thePnt; }
502 //! Handle panning event myGL.Panning.
503 Standard_EXPORT virtual void handlePanning (const Handle(V3d_View)& theView);
505 //! Handle Z rotation event myGL.ZRotate.
506 Standard_EXPORT virtual void handleZRotate (const Handle(V3d_View)& theView);
508 //! Return minimal camera distance for zoom operation.
509 double MinZoomDistance() const { return myMinCamDistance; }
511 //! Set minimal camera distance for zoom operation.
512 void SetMinZoomDistance (double theDist) { myMinCamDistance = theDist; }
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);
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);
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,
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,
542 double thePitchExtra,
544 bool theToRestartOnIncrement);
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);
554 Standard_EXPORT virtual void flushBuffers (const Handle(AIS_InteractiveContext)& theCtx,
555 const Handle(V3d_View)& theView);
557 //! Flush touch gestures.
558 Standard_EXPORT virtual void flushGestures (const Handle(AIS_InteractiveContext)& theCtx,
559 const Handle(V3d_View)& theView);
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,
568 thePrevTime = myLastEventsTime;
569 myLastEventsTime = EventTime();
570 theCurrTime = myLastEventsTime;
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);
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);
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);
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);
595 AIS_ViewInputBuffer myUI; //!< buffer for UI thread
596 AIS_ViewInputBuffer myGL; //!< buffer for rendering thread
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
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
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
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
632 protected: //! @name keyboard input variables
634 Aspect_VKeySet myKeys; //!< keyboard state
636 protected: //! @name mouse input variables
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
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
655 protected: //! @name multi-touch input variables
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
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
672 protected: //! @name rotation/panning transient state variables
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
688 #endif // _AIS_ViewController_HeaderFile