Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 09:04:52

0001 // Created on: 1995-05-23
0002 // Created by: Robert COUBLANC
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _SelectMgr_EntityOwner_HeaderFile
0018 #define _SelectMgr_EntityOwner_HeaderFile
0019 
0020 #include <AIS_SelectionScheme.hxx>
0021 #include <Aspect_VKey.hxx>
0022 #include <PrsMgr_PresentationManager.hxx>
0023 #include <SelectMgr_SelectableObject.hxx>
0024 #include <TopLoc_Location.hxx>
0025 
0026 class V3d_Viewer;
0027 
0028 //! A framework to define classes of owners of sensitive primitives.
0029 //! The owner is the link between application and selection data structures.
0030 //! For the application to make its own objects selectable, it must define owner classes inheriting
0031 //! this framework.
0032 class SelectMgr_EntityOwner : public Standard_Transient
0033 {
0034   DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, Standard_Transient)
0035 public:
0036   //! Initializes the selection priority aPriority.
0037   Standard_EXPORT SelectMgr_EntityOwner(const int aPriority = 0);
0038 
0039   //! Constructs a framework with the selectable object
0040   //! anSO being attributed the selection priority aPriority.
0041   Standard_EXPORT SelectMgr_EntityOwner(const occ::handle<SelectMgr_SelectableObject>& aSO,
0042                                         const int aPriority = 0);
0043 
0044   //! Constructs a framework from existing one
0045   //! anSO being attributed the selection priority aPriority.
0046   Standard_EXPORT SelectMgr_EntityOwner(const occ::handle<SelectMgr_EntityOwner>& theOwner,
0047                                         const int                                 aPriority = 0);
0048 
0049   //! Return selection priority (within range [0-9]) for results with the same depth; 0 by default.
0050   //! Example - selection of shapes:
0051   //! the owners are selectable objects (presentations) a user can give vertex priority [3], edges
0052   //! [2] faces [1] shape [0], so that if during selection one vertex one edge and one face are
0053   //! simultaneously detected, the vertex will only be hilighted.
0054   int Priority() const { return mypriority; }
0055 
0056   //! Sets the selectable priority of the owner within range [0-9].
0057   void SetPriority(int thePriority) { mypriority = thePriority; }
0058 
0059   //! Returns true if there is a selectable object to serve as an owner.
0060   bool HasSelectable() const { return mySelectable != nullptr; }
0061 
0062   //! Returns a selectable object detected in the working context.
0063   virtual occ::handle<SelectMgr_SelectableObject> Selectable() const { return mySelectable; }
0064 
0065   //! Sets the selectable object.
0066   virtual void SetSelectable(const occ::handle<SelectMgr_SelectableObject>& theSelObj)
0067   {
0068     mySelectable = theSelObj.get();
0069   }
0070 
0071   //! Handle mouse button click event.
0072   //! Does nothing by default and returns FALSE.
0073   //! @param thePoint      mouse cursor position
0074   //! @param theButton     clicked button
0075   //! @param theModifiers  key modifiers
0076   //! @param theIsDoubleClick flag indicating double mouse click
0077   //! @return TRUE if object handled click
0078   //! For all selection schemes, allowing to select an object,
0079   //! it's available
0080   virtual bool HandleMouseClick(const NCollection_Vec2<int>& thePoint,
0081                                 Aspect_VKeyMouse             theButton,
0082                                 Aspect_VKeyFlags             theModifiers,
0083                                 bool                         theIsDoubleClick)
0084   {
0085     (void)thePoint;
0086     (void)theButton;
0087     (void)theModifiers;
0088     (void)theIsDoubleClick;
0089     return false;
0090   }
0091 
0092   //! Returns true if the presentation manager highlights selections corresponding to the selection
0093   //! mode.
0094   virtual bool IsHilighted(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0095                            const int                                      theMode = 0) const
0096   {
0097     return mySelectable != nullptr && thePrsMgr->IsHighlighted(mySelectable, theMode);
0098   }
0099 
0100   //! Highlights selectable object's presentation with display mode in presentation manager with
0101   //! given highlight style. Also a check for auto-highlight is performed - if selectable object
0102   //! manages highlighting on its own, execution will be passed to
0103   //! SelectMgr_SelectableObject::HilightOwnerWithColor method.
0104   Standard_EXPORT virtual void HilightWithColor(
0105     const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0106     const occ::handle<Prs3d_Drawer>&               theStyle,
0107     const int                                      theMode = 0);
0108 
0109   //! Removes highlighting from the owner of a detected selectable object in the presentation
0110   //! manager. This object could be the owner of a sensitive primitive.
0111   //! @param thePrsMgr presentation manager
0112   //! @param theMode   obsolete argument for compatibility, should be ignored by implementations
0113   virtual void Unhilight(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0114                          const int                                      theMode = 0)
0115   {
0116     (void)theMode;
0117     if (mySelectable != nullptr)
0118     {
0119       thePrsMgr->Unhighlight(mySelectable);
0120     }
0121   }
0122 
0123   //! Clears the owners matching the value of the selection
0124   //! mode aMode from the presentation manager object aPM.
0125   virtual void Clear(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0126                      const int                                      theMode = 0) /// TODO
0127   {
0128     (void)thePrsMgr;
0129     (void)theMode;
0130   }
0131 
0132   //! Returns TRUE if selectable has transformation.
0133   virtual bool HasLocation() const
0134   {
0135     return mySelectable != nullptr && mySelectable->HasTransformation();
0136   }
0137 
0138   //! Returns transformation of selectable.
0139   virtual TopLoc_Location Location() const
0140   {
0141     return mySelectable != nullptr && mySelectable->HasTransformation()
0142              ? TopLoc_Location(mySelectable->Transformation())
0143              : TopLoc_Location();
0144   }
0145 
0146   //! Change owner location (callback for handling change of location of selectable object).
0147   virtual void SetLocation(const TopLoc_Location& theLocation) { (void)theLocation; }
0148 
0149   //! @return true if the owner is selected.
0150   bool IsSelected() const { return myIsSelected; }
0151 
0152   //! Set the state of the owner.
0153   //! @param[in] theIsSelected  shows if owner is selected.
0154   void SetSelected(const bool theIsSelected) { myIsSelected = theIsSelected; }
0155 
0156   //! If the object needs to be selected, it returns true.
0157   //! @param[in] theSelScheme  selection scheme
0158   //! @param[in] theIsDetected flag of object detection
0159   Standard_EXPORT bool Select(const AIS_SelectionScheme theSelScheme,
0160                               const bool                theIsDetected) const;
0161 
0162   //! Returns selection state.
0163   Standard_DEPRECATED("Deprecated method - IsSelected() should be used instead")
0164   int State() const { return myIsSelected ? 1 : 0; }
0165 
0166   //! Set the state of the owner.
0167   //! The method is deprecated. Use SetSelected() instead.
0168   void State(const int theStatus) { myIsSelected = (theStatus == 1); }
0169 
0170   //! if owner is not auto hilighted, for group contains many such owners will be called one method
0171   //! HilightSelected of SelectableObject
0172   virtual bool IsAutoHilight() const
0173   {
0174     return mySelectable == nullptr || mySelectable->IsAutoHilight();
0175   }
0176 
0177   //! if this method returns TRUE the owner will always call method Hilight for SelectableObject
0178   //! when the owner is detected. By default it always return FALSE.
0179   virtual bool IsForcedHilight() const { return false; }
0180 
0181   //! Set Z layer ID and update all presentations.
0182   virtual void SetZLayer(const Graphic3d_ZLayerId theLayerId) { (void)theLayerId; }
0183 
0184   //! Implements immediate application of location transformation of parent object to dynamic
0185   //! highlight structure
0186   virtual void UpdateHighlightTrsf(const occ::handle<V3d_Viewer>&                 theViewer,
0187                                    const occ::handle<PrsMgr_PresentationManager>& theManager,
0188                                    const int                                      theDispMode)
0189   {
0190     if (mySelectable != nullptr)
0191     {
0192       theManager->UpdateHighlightTrsf(theViewer, mySelectable, theDispMode);
0193     }
0194   }
0195 
0196   //! Returns true if pointer to selectable object of this owner is equal to the given one
0197   bool IsSameSelectable(const occ::handle<SelectMgr_SelectableObject>& theOther) const
0198   {
0199     return mySelectable == theOther.get();
0200   }
0201 
0202   //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
0203   bool ComesFromDecomposition() const { return myFromDecomposition; }
0204 
0205   //! Sets flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE).
0206   void SetComesFromDecomposition(const bool theIsFromDecomposition)
0207   {
0208     myFromDecomposition = theIsFromDecomposition;
0209   }
0210 
0211   //! Dumps the content of me into the stream
0212   Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0213 
0214 public:
0215   //! Sets the selectable object.
0216   Standard_DEPRECATED("Deprecated method - SetSelectable() should be used instead")
0217   void Set(const occ::handle<SelectMgr_SelectableObject>& theSelObj) { SetSelectable(theSelObj); }
0218 
0219   //! sets the selectable priority of the owner
0220   Standard_DEPRECATED("Deprecated method - SetPriority() should be used instead")
0221   void Set(const int thePriority) { SetPriority(thePriority); }
0222 
0223 protected:
0224   SelectMgr_SelectableObject* mySelectable; //!< raw pointer to selectable object
0225   // clang-format off
0226   int            mypriority;          //!< selection priority (for result with the same depth)
0227   bool            myIsSelected;        //!< flag indicating selected state
0228   bool            myFromDecomposition; //!< flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE)
0229   // clang-format on
0230 };
0231 
0232 #endif // _SelectMgr_EntityOwner_HeaderFile