Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:56

0001 // Copyright (c) 2016-2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _AIS_ViewController_HeaderFile
0015 #define _AIS_ViewController_HeaderFile
0016 
0017 #include <Aspect_WindowInputListener.hxx>
0018 #include <Aspect_XRHapticActionData.hxx>
0019 #include <Aspect_XRTrackedDeviceRole.hxx>
0020 #include <AIS_DragAction.hxx>
0021 #include <AIS_MouseGesture.hxx>
0022 #include <AIS_NavigationMode.hxx>
0023 #include <AIS_ViewInputBuffer.hxx>
0024 #include <AIS_RotationMode.hxx>
0025 #include <AIS_WalkDelta.hxx>
0026 
0027 #include <gp_Pnt.hxx>
0028 #include <Graphic3d_Vec3.hxx>
0029 #include <NCollection_Array1.hxx>
0030 #include <OSD_Timer.hxx>
0031 #include <Precision.hxx>
0032 #include <Quantity_ColorRGBA.hxx>
0033 #include <Standard_Mutex.hxx>
0034 
0035 class AIS_Animation;
0036 class AIS_AnimationCamera;
0037 class AIS_InteractiveObject;
0038 class AIS_InteractiveContext;
0039 class AIS_Point;
0040 class AIS_RubberBand;
0041 class AIS_XRTrackedDevice;
0042 class SelectMgr_EntityOwner;
0043 class V3d_View;
0044 class WNT_HIDSpaceMouse;
0045 
0046 //! Auxiliary structure for handling viewer events between GUI and Rendering threads.
0047 //!
0048 //! Class implements the following features:
0049 //! - Buffers storing the state of user input (mouse, touches and keyboard).
0050 //! - Mapping mouse/multi-touch input to View camera manipulations (panning/rotating/zooming).
0051 //! - Input events are not applied immediately but queued for separate processing from two working threads
0052 //!   UI thread receiving user input and Rendering thread for OCCT 3D Viewer drawing.
0053 class AIS_ViewController : public Aspect_WindowInputListener
0054 {
0055 public:
0056 
0057   //! Empty constructor.
0058   Standard_EXPORT AIS_ViewController();
0059 
0060   //! Destructor.
0061   Standard_EXPORT virtual ~AIS_ViewController();
0062 
0063   //! Return input buffer.
0064   const AIS_ViewInputBuffer& InputBuffer (AIS_ViewInputBufferType theType) const { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
0065 
0066   //! Return input buffer.
0067   AIS_ViewInputBuffer& ChangeInputBuffer (AIS_ViewInputBufferType theType)       { return theType == AIS_ViewInputBufferType_UI ? myUI : myGL; }
0068 
0069   //! Return view animation; empty (but not NULL) animation by default.
0070   const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; }
0071 
0072   //! Set view animation to be handled within handleViewRedraw().
0073   void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; }
0074 
0075   //! Interrupt active view animation.
0076   Standard_EXPORT void AbortViewAnimation();
0077 
0078   //! Return objects animation; empty (but not NULL) animation by default.
0079   const Handle(AIS_Animation)& ObjectsAnimation() const { return myObjAnimation; }
0080 
0081   //! Set object animation to be handled within handleViewRedraw().
0082   void SetObjectsAnimation (const Handle(AIS_Animation)& theAnimation) { myObjAnimation = theAnimation; }
0083 
0084   //! Return TRUE if object animation should be paused on mouse click; FALSE by default.
0085   bool ToPauseObjectsAnimation() const { return myToPauseObjAnimation; }
0086 
0087   //! Set if object animation should be paused on mouse click.
0088   void SetPauseObjectsAnimation (bool theToPause) { myToPauseObjAnimation = theToPause; }
0089 
0090   //! Return TRUE if continuous redrawing is enabled; FALSE by default.
0091   //! This option would request a next viewer frame to be completely redrawn right after current frame is finished.
0092   bool IsContinuousRedraw() const { return myIsContinuousRedraw; }
0093 
0094   //! Enable or disable continuous updates.
0095   void SetContinuousRedraw (bool theToEnable) { myIsContinuousRedraw = theToEnable; }
0096 
0097 public: //! @name global parameters
0098 
0099   //! Return camera rotation mode, AIS_RotationMode_BndBoxActive by default.
0100   AIS_RotationMode RotationMode() const { return myRotationMode; }
0101 
0102   //! Set camera rotation mode.
0103   void SetRotationMode (AIS_RotationMode theMode) { myRotationMode = theMode; }
0104 
0105   //! Return camera navigation mode; AIS_NavigationMode_Orbit by default.
0106   AIS_NavigationMode NavigationMode() const { return myNavigationMode; }
0107 
0108   //! Set camera navigation mode.
0109   Standard_EXPORT void SetNavigationMode (AIS_NavigationMode theMode);
0110 
0111   //! Return mouse input acceleration ratio in First Person mode; 1.0 by default.
0112   float MouseAcceleration() const { return myMouseAccel; }
0113 
0114   //! Set mouse input acceleration ratio.
0115   void SetMouseAcceleration (float theRatio) { myMouseAccel = theRatio; }
0116 
0117   //! Return orbit rotation acceleration ratio; 1.0 by default.
0118   float OrbitAcceleration() const { return myOrbitAccel; }
0119 
0120   //! Set orbit rotation acceleration ratio.
0121   void SetOrbitAcceleration (float theRatio) { myOrbitAccel = theRatio; }
0122 
0123   //! Return TRUE if panning anchor point within perspective projection should be displayed in 3D Viewer; TRUE by default.
0124   bool ToShowPanAnchorPoint() const { return myToShowPanAnchorPoint; }
0125 
0126   //! Set if panning anchor point within perspective projection should be displayed in 3D Viewer.
0127   void SetShowPanAnchorPoint (bool theToShow) { myToShowPanAnchorPoint = theToShow; }
0128 
0129   //! Return TRUE if rotation point should be displayed in 3D Viewer; TRUE by default.
0130   bool ToShowRotateCenter() const { return myToShowRotateCenter; }
0131 
0132   //! Set if rotation point should be displayed in 3D Viewer.
0133   void SetShowRotateCenter (bool theToShow) { myToShowRotateCenter = theToShow; }
0134 
0135   //! Return TRUE if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up; FALSE by default.
0136   bool ToLockOrbitZUp() const { return myToLockOrbitZUp; }
0137 
0138   //! Set if camera up orientation within AIS_NavigationMode_Orbit rotation mode should be forced Z up.
0139   void SetLockOrbitZUp (bool theToForceUp) { myToLockOrbitZUp = theToForceUp; }
0140 
0141   //! Return TRUE if z-rotation via two-touches gesture is enabled; FALSE by default.
0142   bool ToAllowTouchZRotation() const { return myToAllowTouchZRotation; }
0143 
0144   //! Set if z-rotation via two-touches gesture is enabled.
0145   void SetAllowTouchZRotation (bool theToEnable) { myToAllowTouchZRotation = theToEnable; }
0146 
0147   //! Return TRUE if camera rotation is allowed; TRUE by default.
0148   bool ToAllowRotation() const { return myToAllowRotation; }
0149 
0150   //! Set if camera rotation is allowed.
0151   void SetAllowRotation (bool theToEnable) { myToAllowRotation = theToEnable; }
0152 
0153   //! Return TRUE if panning is allowed; TRUE by default.
0154   bool ToAllowPanning() const { return myToAllowPanning; }
0155 
0156   //! Set if panning is allowed.
0157   void SetAllowPanning (bool theToEnable) { myToAllowPanning = theToEnable; }
0158 
0159   //! Return TRUE if zooming is allowed; TRUE by default.
0160   bool ToAllowZooming() const { return myToAllowZooming; }
0161 
0162   //! Set if zooming is allowed.
0163   void SetAllowZooming (bool theToEnable) { myToAllowZooming = theToEnable; }
0164 
0165   //! Return TRUE if ZFocus change is allowed; TRUE by default.
0166   bool ToAllowZFocus() const { return myToAllowZFocus; }
0167 
0168   //! Set if ZFocus change is allowed.
0169   void SetAllowZFocus (bool theToEnable) { myToAllowZFocus = theToEnable; }
0170 
0171   //! Return TRUE if dynamic highlight on mouse move is allowed; TRUE by default.
0172   bool ToAllowHighlight() const { return myToAllowHighlight; }
0173 
0174   //! Set if dragging object is allowed.
0175   void SetAllowHighlight (bool theToEnable) { myToAllowHighlight = theToEnable; }
0176 
0177   //! Return TRUE if dragging object is allowed; TRUE by default.
0178   bool ToAllowDragging() const { return myToAllowDragging; }
0179 
0180   //! Set if dynamic highlight on mouse move is allowed.
0181   void SetAllowDragging (bool theToEnable) { myToAllowDragging = theToEnable; }
0182 
0183   //! Return TRUE if picked point should be projected to picking ray on zooming at point; TRUE by default.
0184   bool ToStickToRayOnZoom() const { return myToStickToRayOnZoom; }
0185 
0186   //! Set if picked point should be projected to picking ray on zooming at point.
0187   void SetStickToRayOnZoom (bool theToEnable) { myToStickToRayOnZoom = theToEnable; }
0188 
0189   //! Return TRUE if picked point should be projected to picking ray on rotating around point; TRUE by default.
0190   bool ToStickToRayOnRotation() const { return myToStickToRayOnRotation; }
0191 
0192   //! Set if picked point should be projected to picking ray on rotating around point.
0193   void SetStickToRayOnRotation (bool theToEnable) { myToStickToRayOnRotation = theToEnable; }
0194 
0195   //! Return TRUE if pitch direction should be inverted while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown; FALSE by default.
0196   bool ToInvertPitch() const { return myToInvertPitch; }
0197 
0198   //! Set flag inverting pitch direction.
0199   void SetInvertPitch (bool theToInvert) { myToInvertPitch = theToInvert; }
0200 
0201   //! Return normal walking speed, in m/s; 1.5 by default.
0202   float WalkSpeedAbsolute() const { return myWalkSpeedAbsolute; }
0203 
0204   //! Set normal walking speed, in m/s; 1.5 by default.
0205   void SetWalkSpeedAbsolute (float theSpeed) { myWalkSpeedAbsolute = theSpeed; }
0206 
0207   //! Return walking speed relative to scene bounding box; 0.1 by default.
0208   float WalkSpeedRelative() const { return myWalkSpeedRelative; }
0209 
0210   //! Set walking speed relative to scene bounding box.
0211   void SetWalkSpeedRelative (float theFactor) { myWalkSpeedRelative = theFactor; }
0212 
0213   //! Return active thrust value; 0.0f by default.
0214   float ThrustSpeed() const { return myThrustSpeed; }
0215 
0216   //! Set active thrust value.
0217   void SetThrustSpeed (float theSpeed) { myThrustSpeed = theSpeed; }
0218 
0219   //! Return TRUE if previous position of MoveTo has been defined.
0220   bool HasPreviousMoveTo() const { return myPrevMoveTo != Graphic3d_Vec2i (-1); }
0221 
0222   //! Return previous position of MoveTo event in 3D viewer.
0223   const Graphic3d_Vec2i& PreviousMoveTo() const { return myPrevMoveTo; }
0224 
0225   //! Reset previous position of MoveTo.
0226   void ResetPreviousMoveTo() { myPrevMoveTo = Graphic3d_Vec2i (-1); }
0227 
0228   //! Return TRUE to display auxiliary tracked XR devices (like tracking stations).
0229   bool ToDisplayXRAuxDevices() const { return myToDisplayXRAuxDevices; }
0230 
0231   //! Set if auxiliary tracked XR devices should be displayed.
0232   void SetDisplayXRAuxDevices (bool theToDisplay) { myToDisplayXRAuxDevices = theToDisplay; }
0233 
0234   //! Return TRUE to display XR hand controllers.
0235   bool ToDisplayXRHands() const { return myToDisplayXRHands; }
0236 
0237   //! Set if tracked XR hand controllers should be displayed.
0238   void SetDisplayXRHands (bool theToDisplay) { myToDisplayXRHands = theToDisplay; }
0239 
0240 public: //! @name keyboard input
0241 
0242   using Aspect_WindowInputListener::Keys;
0243   using Aspect_WindowInputListener::ChangeKeys;
0244 
0245   //! Press key.
0246   //! Default implementation updates internal cache.
0247   //! @param theKey key pressed
0248   //! @param theTime event timestamp
0249   Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
0250                                         double theTime,
0251                                         double thePressure = 1.0) Standard_OVERRIDE;
0252 
0253   //! Release key.
0254   //! Default implementation updates internal cache.
0255   //! @param theKey key pressed
0256   //! @param theTime event timestamp
0257   Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
0258                                       double theTime) Standard_OVERRIDE;
0259 
0260   //! Simulate key up/down events from axis value.
0261   //! Default implementation updates internal cache.
0262   Standard_EXPORT virtual void KeyFromAxis (Aspect_VKey theNegative,
0263                                             Aspect_VKey thePositive,
0264                                             double theTime,
0265                                             double thePressure) Standard_OVERRIDE;
0266 
0267   //! Fetch active navigation actions.
0268   Standard_EXPORT AIS_WalkDelta FetchNavigationKeys (Standard_Real theCrouchRatio,
0269                                                      Standard_Real theRunRatio);
0270 
0271 public: //! @name mouse input
0272 
0273   //! Return map defining mouse gestures.
0274   const AIS_MouseGestureMap& MouseGestureMap() const { return myMouseGestureMap; }
0275 
0276   //! Return map defining mouse gestures.
0277   AIS_MouseGestureMap& ChangeMouseGestureMap() { return myMouseGestureMap; }
0278 
0279   //! Return map defining mouse selection schemes.
0280   const AIS_MouseSelectionSchemeMap& MouseSelectionSchemes() const { return myMouseSelectionSchemes; }
0281 
0282   //! Return map defining mouse gestures.
0283   AIS_MouseSelectionSchemeMap& ChangeMouseSelectionSchemes() { return myMouseSelectionSchemes; }
0284 
0285   //! Return double click interval in seconds; 0.4 by default.
0286   double MouseDoubleClickInterval() const { return myMouseDoubleClickInt; }
0287 
0288   //! Set double click interval in seconds.
0289   void SetMouseDoubleClickInterval (double theSeconds) { myMouseDoubleClickInt = theSeconds; }
0290 
0291   //! Perform selection in 3D viewer.
0292   //! This method is expected to be called from UI thread.
0293   //! @param thePnt picking point
0294   //! @param theScheme selection scheme
0295   Standard_EXPORT virtual void SelectInViewer (const Graphic3d_Vec2i& thePnt,
0296                                                const AIS_SelectionScheme theScheme = AIS_SelectionScheme_Replace);
0297 
0298   //! Perform selection in 3D viewer.
0299   //! This method is expected to be called from UI thread.
0300   //! @param thePnts picking point
0301   //! @param theScheme selection scheme
0302   Standard_EXPORT virtual void SelectInViewer (const NCollection_Sequence<Graphic3d_Vec2i>& thePnts,
0303                                                const AIS_SelectionScheme theScheme = AIS_SelectionScheme_Replace);
0304 
0305   //! Update rectangle selection tool.
0306   //! This method is expected to be called from UI thread.
0307   //! @param thePntFrom rectangle first   corner
0308   //! @param thePntTo   rectangle another corner
0309   Standard_EXPORT virtual void UpdateRubberBand (const Graphic3d_Vec2i& thePntFrom,
0310                                                  const Graphic3d_Vec2i& thePntTo);
0311 
0312   //! Update polygonal selection tool.
0313   //! This method is expected to be called from UI thread.
0314   //! @param thePnt new point to add to polygon
0315   //! @param theToAppend append new point or update the last point
0316   Standard_EXPORT virtual void UpdatePolySelection (const Graphic3d_Vec2i& thePnt,
0317                                                     bool theToAppend);
0318 
0319   //! Update zoom event (e.g. from mouse scroll).
0320   //! This method is expected to be called from UI thread.
0321   //! @param theDelta mouse cursor position to zoom at and zoom delta
0322   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
0323   Standard_EXPORT virtual bool UpdateZoom (const Aspect_ScrollDelta& theDelta);
0324 
0325   //! Update Z rotation event.
0326   //! @param theAngle rotation angle, in radians.
0327   //! @return TRUE if new zoom event has been created or FALSE if existing one has been updated
0328   Standard_EXPORT virtual bool UpdateZRotation (double theAngle);
0329 
0330   //! Update mouse scroll event; redirects to UpdateZoom by default.
0331   //! This method is expected to be called from UI thread.
0332   //! @param theDelta mouse cursor position and delta
0333   //! @return TRUE if new event has been created or FALSE if existing one has been updated
0334   Standard_EXPORT virtual bool UpdateMouseScroll (const Aspect_ScrollDelta& theDelta) Standard_OVERRIDE;
0335 
0336   //! Handle mouse button press/release event.
0337   //! This method is expected to be called from UI thread.
0338   //! @param thePoint      mouse cursor position
0339   //! @param theButtons    pressed buttons
0340   //! @param theModifiers  key modifiers
0341   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0342   //!                      but emulated from non-precise input like touch on screen
0343   //! @return TRUE if View should be redrawn
0344   Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
0345                                                    Aspect_VKeyMouse theButtons,
0346                                                    Aspect_VKeyFlags theModifiers,
0347                                                    bool theIsEmulated) Standard_OVERRIDE;
0348 
0349   //! Handle mouse cursor movement event.
0350   //! This method is expected to be called from UI thread.
0351   //! @param thePoint      mouse cursor position
0352   //! @param theButtons    pressed buttons
0353   //! @param theModifiers  key modifiers
0354   //! @param theIsEmulated if TRUE then mouse event comes NOT from real mouse
0355   //!                      but emulated from non-precise input like touch on screen
0356   //! @return TRUE if View should be redrawn
0357   Standard_EXPORT virtual bool UpdateMousePosition (const Graphic3d_Vec2i& thePoint,
0358                                                     Aspect_VKeyMouse theButtons,
0359                                                     Aspect_VKeyFlags theModifiers,
0360                                                     bool theIsEmulated) Standard_OVERRIDE;
0361 
0362   //! Handle mouse button click event (emulated by UpdateMouseButtons() while releasing single button).
0363   //! Note that as this method is called by UpdateMouseButtons(), it should be executed from UI thread.
0364   //! Default implementation redirects to SelectInViewer().
0365   //! This method is expected to be called from UI thread.
0366   //! @param thePoint      mouse cursor position
0367   //! @param theButton     clicked button
0368   //! @param theModifiers  key modifiers
0369   //! @param theIsDoubleClick flag indicating double mouse click
0370   //! @return TRUE if View should be redrawn
0371   Standard_EXPORT virtual bool UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
0372                                                  Aspect_VKeyMouse theButton,
0373                                                  Aspect_VKeyFlags theModifiers,
0374                                                  bool theIsDoubleClick);
0375 
0376   using Aspect_WindowInputListener::PressMouseButton;
0377   using Aspect_WindowInputListener::ReleaseMouseButton;
0378 
0379   using Aspect_WindowInputListener::PressedMouseButtons;
0380   using Aspect_WindowInputListener::LastMouseFlags;
0381   using Aspect_WindowInputListener::LastMousePosition;
0382 
0383 public: //! @name multi-touch input
0384 
0385   //! Return scale factor for adjusting tolerances for starting multi-touch gestures; 1.0 by default
0386   //! This scale factor is expected to be computed from touch screen resolution.
0387   float TouchToleranceScale() const { return myTouchToleranceScale; }
0388 
0389   //! Set scale factor for adjusting tolerances for starting multi-touch gestures.
0390   void SetTouchToleranceScale (float theTolerance) { myTouchToleranceScale = theTolerance; }
0391 
0392   //! Add touch point with the given ID.
0393   //! This method is expected to be called from UI thread.
0394   //! @param theId touch unique identifier
0395   //! @param thePnt touch coordinates
0396   //! @param theClearBefore if TRUE previously registered touches will be removed
0397   Standard_EXPORT virtual void AddTouchPoint (Standard_Size theId,
0398                                               const Graphic3d_Vec2d& thePnt,
0399                                               Standard_Boolean theClearBefore = false) Standard_OVERRIDE;
0400 
0401   //! Remove touch point with the given ID.
0402   //! This method is expected to be called from UI thread.
0403   //! @param theId touch unique identifier
0404   //! @param theClearSelectPnts if TRUE will initiate clearing of selection points
0405   //! @return TRUE if point has been removed
0406   Standard_EXPORT virtual bool RemoveTouchPoint (Standard_Size theId,
0407                                                  Standard_Boolean theClearSelectPnts = false) Standard_OVERRIDE;
0408 
0409   //! Update touch point with the given ID.
0410   //! If point with specified ID was not registered before, it will be added.
0411   //! This method is expected to be called from UI thread.
0412   //! @param theId touch unique identifier
0413   //! @param thePnt touch coordinates
0414   Standard_EXPORT virtual void UpdateTouchPoint (Standard_Size theId,
0415                                                  const Graphic3d_Vec2d& thePnt) Standard_OVERRIDE;
0416 
0417   using Aspect_WindowInputListener::HasTouchPoints;
0418 
0419 public: //! @name 3d mouse input
0420 
0421   //! Process 3d mouse input event (redirects to translation, rotation and keys).
0422   Standard_EXPORT virtual bool Update3dMouse (const WNT_HIDSpaceMouse& theEvent) Standard_OVERRIDE;
0423 
0424 public: //! @name resize events
0425 
0426   //! Handle expose event (window content has been invalidation and should be redrawn).
0427   //! Default implementation does nothing.
0428   virtual void ProcessExpose() Standard_OVERRIDE {}
0429 
0430   //! Handle window resize event.
0431   //! Default implementation does nothing.
0432   virtual void ProcessConfigure (bool theIsResized) Standard_OVERRIDE
0433   {
0434     (void )theIsResized;
0435   }
0436 
0437   //! Handle window input event immediately.
0438   //! Default implementation does nothing - input events are accumulated in internal buffer until explicit FlushViewEvents() call.
0439   virtual void ProcessInput() Standard_OVERRIDE {}
0440 
0441   //! Handle focus event.
0442   //! Default implementation resets cached input state (pressed keys).
0443   virtual void ProcessFocus (bool theIsActivated) Standard_OVERRIDE
0444   {
0445     if (!theIsActivated)
0446     {
0447       ResetViewInput();
0448     }
0449   }
0450 
0451   //! Handle window close event.
0452   //! Default implementation does nothing.
0453   virtual void ProcessClose() Standard_OVERRIDE {}
0454 
0455 public:
0456 
0457   using Aspect_WindowInputListener::EventTime;
0458 
0459   //! Reset input state (pressed keys, mouse buttons, etc.) e.g. on window focus loss.
0460   //! This method is expected to be called from UI thread.
0461   Standard_EXPORT virtual void ResetViewInput();
0462 
0463   //! Reset view orientation.
0464   //! This method is expected to be called from UI thread.
0465   Standard_EXPORT virtual void UpdateViewOrientation (V3d_TypeOfOrientation theOrientation,
0466                                                       bool theToFitAll);
0467 
0468   //! Update buffer for rendering thread.
0469   //! This method is expected to be called within synchronization barrier between GUI
0470   //! and Rendering threads (e.g. GUI thread should be locked beforehand to avoid data races).
0471   //! @param theCtx interactive context
0472   //! @param theView active view
0473   //! @param theToHandle if TRUE, the HandleViewEvents() will be called
0474   Standard_EXPORT virtual void FlushViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
0475                                                 const Handle(V3d_View)& theView,
0476                                                 Standard_Boolean theToHandle = Standard_False);
0477 
0478   //! Process events within rendering thread.
0479   Standard_EXPORT virtual void HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx,
0480                                                  const Handle(V3d_View)& theView);
0481 
0482 public:
0483 
0484   //! Callback called by handleMoveTo() on Selection in 3D Viewer.
0485   //! This method is expected to be called from rendering thread.
0486   Standard_EXPORT virtual void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
0487                                                    const Handle(V3d_View)& theView);
0488 
0489   //! Callback called by handleMoveTo() on dragging object in 3D Viewer.
0490   //! This method is expected to be called from rendering thread.
0491   Standard_EXPORT virtual void OnObjectDragged (const Handle(AIS_InteractiveContext)& theCtx,
0492                                                 const Handle(V3d_View)& theView,
0493                                                 AIS_DragAction theAction);
0494 
0495   //! Callback called by HandleViewEvents() on Selection of another (sub)view.
0496   //! This method is expected to be called from rendering thread.
0497   Standard_EXPORT virtual void OnSubviewChanged (const Handle(AIS_InteractiveContext)& theCtx,
0498                                                  const Handle(V3d_View)& theOldView,
0499                                                  const Handle(V3d_View)& theNewView);
0500 
0501   //! Pick closest point under mouse cursor.
0502   //! This method is expected to be called from rendering thread.
0503   //! @param thePnt   [out] result point
0504   //! @param theCtx    [in] interactive context
0505   //! @param theView   [in] active view
0506   //! @param theCursor [in] mouse cursor
0507   //! @param theToStickToPickRay [in] when TRUE, the result point will lie on picking ray
0508   //! @return TRUE if result has been found
0509   Standard_EXPORT virtual bool PickPoint (gp_Pnt& thePnt,
0510                                           const Handle(AIS_InteractiveContext)& theCtx,
0511                                           const Handle(V3d_View)& theView,
0512                                           const Graphic3d_Vec2i& theCursor,
0513                                           bool theToStickToPickRay);
0514 
0515   //! Pick closest point by axis.
0516   //! This method is expected to be called from rendering thread.
0517   //! @param theTopPnt [out] result point
0518   //! @param theCtx    [in] interactive context
0519   //! @param theView   [in] active view
0520   //! @param theAxis   [in] selection axis
0521   //! @return TRUE if result has been found
0522   Standard_EXPORT virtual bool PickAxis (gp_Pnt& theTopPnt,
0523                                          const Handle(AIS_InteractiveContext)& theCtx,
0524                                          const Handle(V3d_View)& theView,
0525                                          const gp_Ax1& theAxis);
0526 
0527   //! Compute rotation gravity center point depending on rotation mode.
0528   //! This method is expected to be called from rendering thread.
0529   Standard_EXPORT virtual gp_Pnt GravityPoint (const Handle(AIS_InteractiveContext)& theCtx,
0530                                                const Handle(V3d_View)& theView);
0531 
0532   //! Modify view camera to fit all objects.
0533   //! Default implementation fits either all visible and all selected objects (swapped on each call).
0534   Standard_EXPORT virtual void FitAllAuto (const Handle(AIS_InteractiveContext)& theCtx,
0535                                            const Handle(V3d_View)& theView);
0536 
0537 public:
0538 
0539   //! Handle hot-keys defining new camera orientation (Aspect_VKey_ViewTop and similar keys).
0540   //! Default implementation starts an animated transaction from the current to the target camera orientation, when specific action key was pressed.
0541   //! This method is expected to be called from rendering thread.
0542   Standard_EXPORT virtual void handleViewOrientationKeys (const Handle(AIS_InteractiveContext)& theCtx,
0543                                                           const Handle(V3d_View)& theView);
0544 
0545   //! Perform navigation (Aspect_VKey_NavForward and similar keys).
0546   //! This method is expected to be called from rendering thread.
0547   Standard_EXPORT virtual AIS_WalkDelta handleNavigationKeys (const Handle(AIS_InteractiveContext)& theCtx,
0548                                                               const Handle(V3d_View)& theView);
0549 
0550   //! Perform immediate camera actions (rotate/zoom/pan) on gesture progress.
0551   //! This method is expected to be called from rendering thread.
0552   Standard_EXPORT virtual void handleCameraActions (const Handle(AIS_InteractiveContext)& theCtx,
0553                                                     const Handle(V3d_View)& theView,
0554                                                     const AIS_WalkDelta& theWalk);
0555 
0556   //! Perform moveto/selection/dragging.
0557   //! This method is expected to be called from rendering thread.
0558   Standard_EXPORT virtual void handleMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
0559                                              const Handle(V3d_View)& theView);
0560 
0561   //! Return TRUE if another frame should be drawn right after this one.
0562   bool toAskNextFrame() const { return myToAskNextFrame; }
0563 
0564   //! Set if another frame should be drawn right after this one.
0565   void setAskNextFrame (bool theToDraw = true) { myToAskNextFrame = theToDraw; }
0566 
0567   //! Return if panning anchor point has been defined.
0568   bool hasPanningAnchorPoint() const { return !Precision::IsInfinite (myPanPnt3d.X()); }
0569 
0570   //! Return active panning anchor point.
0571   const gp_Pnt& panningAnchorPoint() const { return myPanPnt3d; }
0572 
0573   //! Set active panning anchor point.
0574   void setPanningAnchorPoint (const gp_Pnt& thePnt) { myPanPnt3d = thePnt; }
0575 
0576   //! Handle panning event myGL.Panning.
0577   Standard_EXPORT virtual void handlePanning (const Handle(V3d_View)& theView);
0578 
0579   //! Handle Z rotation event myGL.ZRotate.
0580   Standard_EXPORT virtual void handleZRotate (const Handle(V3d_View)& theView);
0581 
0582   //! Return minimal camera distance for zoom operation.
0583   double MinZoomDistance() const { return myMinCamDistance; }
0584 
0585   //! Set minimal camera distance for zoom operation.
0586   void SetMinZoomDistance (double theDist) { myMinCamDistance = theDist; }
0587 
0588   //! Handle zoom event myGL.ZoomActions.
0589   //! This method is expected to be called from rendering thread.
0590   Standard_EXPORT virtual void handleZoom (const Handle(V3d_View)& theView,
0591                                            const Aspect_ScrollDelta& theParams,
0592                                            const gp_Pnt* thePnt);
0593 
0594   //! Handle ZScroll event myGL.ZoomActions.
0595   //! This method is expected to be called from rendering thread.
0596   Standard_EXPORT virtual void handleZFocusScroll (const Handle(V3d_View)& theView,
0597                                                    const Aspect_ScrollDelta& theParams);
0598 
0599   //! Handle orbital rotation events myGL.OrbitRotation.
0600   //! @param theView view to modify
0601   //! @param thePnt 3D point to rotate around
0602   //! @param theToLockZUp amend camera to exclude roll angle (put camera Up vector to plane containing global Z and view direction)
0603   Standard_EXPORT virtual void handleOrbitRotation (const Handle(V3d_View)& theView,
0604                                                     const gp_Pnt& thePnt,
0605                                                     bool theToLockZUp);
0606 
0607   //! Handle view direction rotation events myGL.ViewRotation.
0608   //! This method is expected to be called from rendering thread.
0609   //! @param theView       camera to modify
0610   //! @param theYawExtra   extra yaw increment
0611   //! @param thePitchExtra extra pitch increment
0612   //! @param theRoll       roll value
0613   //! @param theToRestartOnIncrement flag indicating flight mode
0614   Standard_EXPORT virtual void handleViewRotation (const Handle(V3d_View)& theView,
0615                                                    double theYawExtra,
0616                                                    double thePitchExtra,
0617                                                    double theRoll,
0618                                                    bool theToRestartOnIncrement);
0619 
0620   //! Handle view redraw.
0621   //! This method is expected to be called from rendering thread.
0622   Standard_EXPORT virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
0623                                                  const Handle(V3d_View)& theView);
0624 
0625 public:
0626 
0627   //! Perform XR input.
0628   //! This method is expected to be called from rendering thread.
0629   Standard_EXPORT virtual void handleXRInput (const Handle(AIS_InteractiveContext)& theCtx,
0630                                               const Handle(V3d_View)& theView,
0631                                               const AIS_WalkDelta& theWalk);
0632 
0633   //! Handle trackpad view turn action.
0634   Standard_EXPORT virtual void handleXRTurnPad (const Handle(AIS_InteractiveContext)& theCtx,
0635                                                 const Handle(V3d_View)& theView);
0636 
0637   //! Handle trackpad teleportation action.
0638   Standard_EXPORT virtual void handleXRTeleport (const Handle(AIS_InteractiveContext)& theCtx,
0639                                                  const Handle(V3d_View)& theView);
0640 
0641   //! Handle picking on trigger click.
0642   Standard_EXPORT virtual void handleXRPicking (const Handle(AIS_InteractiveContext)& theCtx,
0643                                                 const Handle(V3d_View)& theView);
0644 
0645   //! Perform dynamic highlighting for active hand.
0646   Standard_EXPORT virtual void handleXRHighlight (const Handle(AIS_InteractiveContext)& theCtx,
0647                                                   const Handle(V3d_View)& theView);
0648 
0649   //! Display auxiliary XR presentations.
0650   Standard_EXPORT virtual void handleXRPresentations (const Handle(AIS_InteractiveContext)& theCtx,
0651                                                       const Handle(V3d_View)& theView);
0652 
0653   //! Perform picking with/without dynamic highlighting for XR pose.
0654   Standard_EXPORT virtual Standard_Integer handleXRMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
0655                                                            const Handle(V3d_View)& theView,
0656                                                            const gp_Trsf& thePose,
0657                                                            const Standard_Boolean theToHighlight);
0658 
0659 protected:
0660 
0661   //! Flush buffers.
0662   Standard_EXPORT virtual void flushBuffers (const Handle(AIS_InteractiveContext)& theCtx,
0663                                              const Handle(V3d_View)& theView);
0664 
0665   //! Flush touch gestures.
0666   Standard_EXPORT virtual void flushGestures (const Handle(AIS_InteractiveContext)& theCtx,
0667                                               const Handle(V3d_View)& theView);
0668 
0669   //! Return current and previously fetched event times.
0670   //! This callback is intended to compute delta between sequentially processed events.
0671   //! @param thePrevTime [out] events time fetched previous time by this method
0672   //! @param theCurrTime [out] actual events time
0673   void updateEventsTime (double& thePrevTime,
0674                          double& theCurrTime)
0675   {
0676     thePrevTime = myLastEventsTime;
0677     myLastEventsTime = EventTime();
0678     theCurrTime = myLastEventsTime;
0679   }
0680 
0681   //! Perform selection via mouse click.
0682   //! This method is expected to be called from rendering thread.
0683   Standard_EXPORT virtual void handleSelectionPick (const Handle(AIS_InteractiveContext)& theCtx,
0684                                                     const Handle(V3d_View)& theView);
0685 
0686   //! Perform dynamic highlight on mouse move.
0687   //! This method is expected to be called from rendering thread.
0688   Standard_EXPORT virtual void handleDynamicHighlight (const Handle(AIS_InteractiveContext)& theCtx,
0689                                                        const Handle(V3d_View)& theView);
0690 
0691   //! Perform rubber-band selection.
0692   //! This method is expected to be called from rendering thread.
0693   Standard_EXPORT virtual void handleSelectionPoly (const Handle(AIS_InteractiveContext)& theCtx,
0694                                                     const Handle(V3d_View)& theView);
0695 
0696   //! Lazy AIS_InteractiveContext::MoveTo() with myPrevMoveTo check.
0697   Standard_EXPORT virtual void contextLazyMoveTo (const Handle(AIS_InteractiveContext)& theCtx,
0698                                                   const Handle(V3d_View)& theView,
0699                                                   const Graphic3d_Vec2i& thePnt);
0700 
0701 protected:
0702 
0703   AIS_ViewInputBuffer myUI;                       //!< buffer for UI thread
0704   AIS_ViewInputBuffer myGL;                       //!< buffer for rendering thread
0705 
0706   Standard_Real       myLastEventsTime;           //!< last fetched events timer value for computing delta/progress
0707   Standard_Boolean    myToAskNextFrame;           //!< flag indicating that another frame should be drawn right after this one
0708   Standard_Boolean    myIsContinuousRedraw;       //!< continuous redrawing (without immediate rendering optimization)
0709 
0710   Standard_Real       myMinCamDistance;           //!< minimal camera distance for zoom operation
0711   AIS_RotationMode    myRotationMode;             //!< rotation mode
0712   AIS_NavigationMode  myNavigationMode;           //!< navigation mode (orbit rotation / first person)
0713   Standard_ShortReal  myMouseAccel;               //!< mouse input acceleration ratio in First Person mode
0714   Standard_ShortReal  myOrbitAccel;               //!< Orbit rotation acceleration ratio
0715   Standard_Boolean    myToShowPanAnchorPoint;     //!< option displaying panning  anchor point
0716   Standard_Boolean    myToShowRotateCenter;       //!< option displaying rotation center point
0717   Standard_Boolean    myToLockOrbitZUp;           //!< force camera up orientation within AIS_NavigationMode_Orbit rotation mode
0718   Standard_Boolean    myToInvertPitch;            //!< flag inverting pitch direction while processing Aspect_VKey_NavLookUp/Aspect_VKey_NavLookDown
0719   Standard_Boolean    myToAllowTouchZRotation;    //!< enable z-rotation two-touches gesture; FALSE by default
0720   Standard_Boolean    myToAllowRotation;          //!< enable rotation; TRUE by default
0721   Standard_Boolean    myToAllowPanning;           //!< enable panning; TRUE by default
0722   Standard_Boolean    myToAllowZooming;           //!< enable zooming; TRUE by default
0723   Standard_Boolean    myToAllowZFocus;            //!< enable ZFocus change; TRUE by default
0724   Standard_Boolean    myToAllowHighlight;         //!< enable dynamic highlight on mouse move; TRUE by default
0725   Standard_Boolean    myToAllowDragging;          //!< enable dragging object; TRUE by default
0726   Standard_Boolean    myToStickToRayOnZoom;       //!< project picked point to ray while zooming at point, TRUE by default
0727   Standard_Boolean    myToStickToRayOnRotation;   //!< project picked point to ray while rotating around point; TRUE by default
0728 
0729   Standard_ShortReal  myWalkSpeedAbsolute;        //!< normal walking speed, in m/s; 1.5 by default
0730   Standard_ShortReal  myWalkSpeedRelative;        //!< walking speed relative to scene bounding box; 0.1 by default
0731   Standard_ShortReal  myThrustSpeed;              //!< active thrust value
0732   Standard_Boolean    myHasThrust;                //!< flag indicating active thrust
0733 
0734   Handle(AIS_AnimationCamera) myViewAnimation;    //!< view animation
0735   Handle(AIS_Animation)       myObjAnimation;     //!< objects animation
0736   Standard_Boolean       myToPauseObjAnimation;   //!< flag to pause objects animation on mouse click; FALSE by default
0737   Handle(AIS_RubberBand) myRubberBand;            //!< Rubber-band presentation
0738   Handle(SelectMgr_EntityOwner) myDragOwner;      //!< detected owner of currently dragged object
0739   Handle(AIS_InteractiveObject) myDragObject;     //!< currently dragged object
0740   Graphic3d_Vec2i     myPrevMoveTo;               //!< previous position of MoveTo event in 3D viewer
0741   Standard_Boolean    myHasHlrOnBeforeRotation;   //!< flag for restoring Computed mode after rotation
0742 
0743 protected: //! @name XR input variables
0744 
0745   NCollection_Array1<Handle(AIS_XRTrackedDevice)> myXRPrsDevices; //!< array of XR tracked devices presentations
0746   Quantity_Color             myXRLaserTeleColor;  //!< color of teleport laser
0747   Quantity_Color             myXRLaserPickColor;  //!< color of picking  laser
0748   Aspect_XRTrackedDeviceRole myXRLastTeleportHand;//!< active hand for teleport
0749   Aspect_XRTrackedDeviceRole myXRLastPickingHand; //!< active hand for picking objects
0750   Aspect_XRHapticActionData  myXRTeleportHaptic;  //!< vibration on picking teleport destination
0751   Aspect_XRHapticActionData  myXRPickingHaptic;   //!< vibration on dynamic highlighting
0752   Aspect_XRHapticActionData  myXRSelectHaptic;    //!< vibration on selection
0753   Standard_Real       myXRLastPickDepthLeft;      //!< last picking depth for left  hand
0754   Standard_Real       myXRLastPickDepthRight;     //!< last picking depth for right hand
0755   Standard_Real       myXRTurnAngle;              //!< discrete turn angle for XR trackpad
0756   Standard_Boolean    myToDisplayXRAuxDevices;    //!< flag to display auxiliary tracked XR devices
0757   Standard_Boolean    myToDisplayXRHands;         //!< flag to display XR hands
0758 
0759 protected: //! @name mouse input variables
0760 
0761   Standard_Real       myMouseClickThreshold;      //!< mouse click threshold in pixels; 3 by default
0762   Standard_Real       myMouseDoubleClickInt;      //!< double click interval in seconds; 0.4 by default
0763   Standard_ShortReal  myScrollZoomRatio;          //!< distance ratio for mapping mouse scroll event to zoom; 15.0 by default
0764 
0765   AIS_MouseGestureMap myMouseGestureMap;          //!< map defining mouse gestures
0766   AIS_MouseGestureMap myMouseGestureMapDrag;      //!< secondary map defining mouse gestures for dragging
0767   AIS_MouseGesture    myMouseActiveGesture;       //!< initiated mouse gesture (by pressing mouse button)
0768   AIS_MouseSelectionSchemeMap
0769                       myMouseSelectionSchemes;    //!< map defining selection schemes bound to mouse + modifiers
0770   Standard_Boolean    myMouseActiveIdleRotation;  //!< flag indicating view idle rotation state
0771   Graphic3d_Vec2i     myMousePressPoint;          //!< mouse position where active gesture was been initiated
0772   Graphic3d_Vec2i     myMouseProgressPoint;       //!< gesture progress
0773   OSD_Timer           myMouseClickTimer;          //!< timer for handling double-click event
0774   Standard_Integer    myMouseClickCounter;        //!< counter for handling double-click event
0775   Standard_Integer    myMouseSingleButton;        //!< index of mouse button pressed alone (>0)
0776   Standard_Boolean    myMouseStopDragOnUnclick;   //!< queue stop dragging even with at next mouse unclick
0777 
0778 protected: //! @name multi-touch input variables
0779 
0780   Standard_ShortReal  myTouchToleranceScale;      //!< tolerance scale factor; 1.0 by default
0781   Standard_ShortReal  myTouchClickThresholdPx;    //!< touch click threshold in pixels; 3 by default
0782   Standard_ShortReal  myTouchRotationThresholdPx; //!< threshold for starting one-touch rotation     gesture in pixels;  6 by default
0783   Standard_ShortReal  myTouchZRotationThreshold;  //!< threshold for starting two-touch Z-rotation   gesture in radians; 2 degrees by default
0784   Standard_ShortReal  myTouchPanThresholdPx;      //!< threshold for starting two-touch panning      gesture in pixels;  4 by default
0785   Standard_ShortReal  myTouchZoomThresholdPx;     //!< threshold for starting two-touch zoom (pitch) gesture in pixels;  6 by default
0786   Standard_ShortReal  myTouchZoomRatio;           //!< distance ratio for mapping two-touch zoom (pitch) gesture from pixels to zoom; 0.13 by default
0787   Standard_ShortReal  myTouchDraggingThresholdPx; //!< distance for starting one-touch dragging gesture in pixels;  6 by default
0788 
0789   Aspect_Touch        myTouchClick;               //!< single touch position for handling clicks
0790   OSD_Timer           myTouchDoubleTapTimer;      //!< timer for handling double tap
0791 
0792   Graphic3d_Vec2d     myStartPanCoord;            //!< touch coordinates at the moment of starting panning  gesture
0793   Graphic3d_Vec2d     myStartRotCoord;            //!< touch coordinates at the moment of starting rotating gesture
0794   Standard_Integer    myNbTouchesLast;            //!< number of touches within previous gesture flush to track gesture changes
0795   Standard_Boolean    myUpdateStartPointPan;      //!< flag indicating that new anchor  point should be picked for starting panning    gesture
0796   Standard_Boolean    myUpdateStartPointRot;      //!< flag indicating that new gravity point should be picked for starting rotation   gesture
0797   Standard_Boolean    myUpdateStartPointZRot;     //!< flag indicating that new gravity point should be picked for starting Z-rotation gesture
0798 
0799 protected: //! @name rotation/panning transient state variables
0800 
0801   Handle(AIS_Point)   myAnchorPointPrs1;          //!< anchor point presentation (Graphic3d_ZLayerId_Top)
0802   Handle(AIS_Point)   myAnchorPointPrs2;          //!< anchor point presentation (Graphic3d_ZLayerId_Topmost)
0803   gp_Pnt              myPanPnt3d;                 //!< active panning anchor point
0804   gp_Pnt              myRotatePnt3d;              //!< active rotation center of gravity
0805   gp_Dir              myCamStartOpUp;             //!< camera Up    direction at the beginning of rotation
0806   gp_Dir              myCamStartOpDir;            //!< camera View  direction at the beginning of rotation
0807   gp_Pnt              myCamStartOpEye;            //!< camera Eye    position at the beginning of rotation
0808   gp_Pnt              myCamStartOpCenter;         //!< camera Center position at the beginning of rotation
0809   gp_Vec              myCamStartOpToCenter;       //!< vector from rotation gravity point to camera Center at the beginning of rotation
0810   gp_Vec              myCamStartOpToEye;          //!< vector from rotation gravity point to camera Eye    at the beginning of rotation
0811   Graphic3d_Vec3d     myRotateStartYawPitchRoll;  //!< camera yaw pitch roll at the beginning of rotation
0812 
0813 };
0814 
0815 #endif // _AIS_ViewController_HeaderFile