Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:16

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