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