Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:53

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 this framework.
0031 class SelectMgr_EntityOwner : public Standard_Transient
0032 {
0033   DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, Standard_Transient)
0034 public:
0035 
0036   //! Initializes the selection priority aPriority.
0037   Standard_EXPORT SelectMgr_EntityOwner(const Standard_Integer 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 Handle(SelectMgr_SelectableObject)& aSO, const Standard_Integer aPriority = 0);
0042 
0043   //! Constructs a framework from existing one
0044   //! anSO being attributed the selection priority aPriority.
0045   Standard_EXPORT SelectMgr_EntityOwner(const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer aPriority = 0);
0046 
0047   //! Return selection priority (within range [0-9]) for results with the same depth; 0 by default.
0048   //! Example - selection of shapes:
0049   //! the owners are selectable objects (presentations) a user can give vertex priority [3], edges [2] faces [1] shape [0],
0050   //! so that if during selection one vertex one edge and one face are simultaneously detected, the vertex will only be hilighted.
0051   Standard_Integer Priority() const { return mypriority; }
0052 
0053   //! Sets the selectable priority of the owner within range [0-9].
0054   void SetPriority (Standard_Integer thePriority) { mypriority = thePriority; }
0055 
0056   //! Returns true if there is a selectable object to serve as an owner.
0057   Standard_Boolean HasSelectable() const { return mySelectable != NULL; }
0058 
0059   //! Returns a selectable object detected in the working context.
0060   virtual Handle(SelectMgr_SelectableObject) Selectable() const { return mySelectable; }
0061 
0062   //! Sets the selectable object.
0063   virtual void SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj) { mySelectable = theSelObj.get(); }
0064 
0065   //! Handle mouse button click event.
0066   //! Does nothing by default and returns FALSE.
0067   //! @param thePoint      mouse cursor position
0068   //! @param theButton     clicked button
0069   //! @param theModifiers  key modifiers
0070   //! @param theIsDoubleClick flag indicating double mouse click
0071   //! @return TRUE if object handled click
0072   virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint,
0073                                              Aspect_VKeyMouse theButton,
0074                                              Aspect_VKeyFlags theModifiers,
0075                                              bool theIsDoubleClick)
0076   {
0077     (void )thePoint; (void )theButton; (void )theModifiers; (void )theIsDoubleClick;
0078     return Standard_False;
0079   }
0080 
0081   //! Returns true if the presentation manager highlights selections corresponding to the selection mode.
0082   virtual Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0083                                         const Standard_Integer theMode = 0) const
0084   {
0085     return mySelectable != NULL
0086         && thePrsMgr->IsHighlighted (mySelectable, theMode);
0087   }
0088   
0089   //! Highlights selectable object's presentation with display mode in presentation manager with given highlight style.
0090   //! Also a check for auto-highlight is performed - if selectable object manages highlighting on its own,
0091   //! execution will be passed to SelectMgr_SelectableObject::HilightOwnerWithColor method.
0092   Standard_EXPORT virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0093                                                  const Handle(Prs3d_Drawer)& theStyle,
0094                                                  const Standard_Integer theMode = 0);
0095 
0096   //! Removes highlighting from the owner of a detected selectable object in the presentation manager.
0097   //! This object could be the owner of a sensitive primitive.
0098   //! @param thePrsMgr presentation manager
0099   //! @param theMode   obsolete argument for compatibility, should be ignored by implementations
0100   virtual void Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0101                           const Standard_Integer theMode = 0)
0102   {
0103     (void )theMode;
0104     if (mySelectable != NULL)
0105     {
0106       thePrsMgr->Unhighlight (mySelectable);
0107     }
0108   }
0109 
0110   //! Clears the owners matching the value of the selection
0111   //! mode aMode from the presentation manager object aPM.
0112   virtual void Clear (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0113                       const Standard_Integer theMode = 0) /// TODO
0114   {
0115     (void )thePrsMgr;
0116     (void )theMode;
0117   }
0118 
0119   //! Returns TRUE if selectable has transformation.
0120   virtual Standard_Boolean HasLocation() const { return mySelectable != NULL && mySelectable->HasTransformation(); }
0121 
0122   //! Returns transformation of selectable.
0123   virtual TopLoc_Location Location() const
0124   {
0125     return mySelectable != NULL && mySelectable->HasTransformation()
0126          ? TopLoc_Location(mySelectable->Transformation())
0127          : TopLoc_Location();
0128   }
0129 
0130   //! Change owner location (callback for handling change of location of selectable object).
0131   virtual void SetLocation (const TopLoc_Location& theLocation)
0132   {
0133     (void )theLocation;
0134   }
0135 
0136   //! @return Standard_True if the owner is selected.
0137   Standard_Boolean IsSelected() const { return myIsSelected; }
0138 
0139   //! Set the state of the owner.
0140   //! @param theIsSelected [in] shows if owner is selected.
0141   void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
0142 
0143   //! If the object needs to be selected, it returns true.
0144   //! @param[in] theSelScheme  selection scheme
0145   //! @param[in] theIsDetected flag of object detection
0146   Standard_EXPORT Standard_Boolean Select (const AIS_SelectionScheme theSelScheme,
0147                                            const Standard_Boolean theIsDetected) const;
0148 
0149   //! Returns selection state.
0150   Standard_DEPRECATED ("Deprecated method - IsSelected() should be used instead")
0151   Standard_Integer State() const { return myIsSelected ? 1 : 0; }
0152 
0153   //! Set the state of the owner.
0154   //! The method is deprecated. Use SetSelected() instead.
0155   void State (const Standard_Integer theStatus) { myIsSelected = (theStatus == 1); }
0156 
0157   //! if owner is not auto hilighted, for group contains many such owners will be called one method HilightSelected of SelectableObject
0158   virtual Standard_Boolean IsAutoHilight() const
0159   {
0160     return mySelectable == NULL
0161         || mySelectable->IsAutoHilight();
0162   }
0163 
0164   //! if this method returns TRUE the owner will always call method Hilight for SelectableObject when the owner is detected.
0165   //! By default it always return FALSE.
0166   virtual Standard_Boolean IsForcedHilight() const { return Standard_False; }
0167   
0168   //! Set Z layer ID and update all presentations.
0169   virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId)
0170   {
0171     (void )theLayerId;
0172   }
0173 
0174   //! Implements immediate application of location transformation of parent object to dynamic highlight structure
0175   virtual void UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
0176                                     const Handle(PrsMgr_PresentationManager)& theManager,
0177                                     const Standard_Integer theDispMode)
0178   {
0179     if (mySelectable != NULL)
0180     {
0181       theManager->UpdateHighlightTrsf (theViewer, mySelectable, theDispMode);
0182     }
0183   }
0184 
0185   //! Returns true if pointer to selectable object of this owner is equal to the given one
0186   Standard_Boolean IsSameSelectable (const Handle(SelectMgr_SelectableObject)& theOther) const
0187   {
0188     return mySelectable == theOther.get();
0189   }
0190 
0191   //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
0192   Standard_Boolean ComesFromDecomposition() const { return myFromDecomposition; }
0193 
0194   //! Sets flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE).
0195   void SetComesFromDecomposition (const Standard_Boolean theIsFromDecomposition) { myFromDecomposition = theIsFromDecomposition; }
0196 
0197   //! Dumps the content of me into the stream
0198   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0199 
0200 public:
0201 
0202   //! Sets the selectable object.
0203   Standard_DEPRECATED ("Deprecated method - SetSelectable() should be used instead")
0204   void Set (const Handle(SelectMgr_SelectableObject)& theSelObj) { SetSelectable (theSelObj); }
0205 
0206   //! sets the selectable priority of the owner
0207   Standard_DEPRECATED ("Deprecated method - SetPriority() should be used instead")
0208   void Set (const Standard_Integer thePriority) { SetPriority (thePriority); }
0209 
0210 protected:
0211 
0212   SelectMgr_SelectableObject* mySelectable;        //!< raw pointer to selectable object
0213   Standard_Integer            mypriority;          //!< selection priority (for result with the same depth)
0214   Standard_Boolean            myIsSelected;        //!< flag indicating selected state
0215   Standard_Boolean            myFromDecomposition; //!< flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE)
0216 
0217 };
0218 
0219 DEFINE_STANDARD_HANDLE(SelectMgr_EntityOwner, Standard_Transient)
0220 
0221 Standard_DEPRECATED("Deprecated alias - SelectMgr_EntityOwner should be used instead")
0222 typedef SelectMgr_EntityOwner SelectBasics_EntityOwner;
0223 
0224 #endif // _SelectMgr_EntityOwner_HeaderFile