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