Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 1995-02-20
0002 // Created by: Mister rmi
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_SelectableObject_HeaderFile
0018 #define _SelectMgr_SelectableObject_HeaderFile
0019 
0020 #include <PrsMgr_PresentableObject.hxx>
0021 #include <SelectMgr_IndexedMapOfOwner.hxx>
0022 #include <SelectMgr_SequenceOfSelection.hxx>
0023 #include <SelectMgr_Selection.hxx>
0024 #include <SelectMgr_SequenceOfOwner.hxx>
0025 
0026 class SelectMgr_EntityOwner;
0027 
0028 //! A framework to supply the structure of the object to be selected.
0029 //! At the first pick, this structure is created by calling the appropriate algorithm and retaining this framework for further picking.
0030 //! This abstract framework is inherited in Application Interactive Services (AIS), notably in AIS_InteractiveObject.
0031 //! Consequently, 3D selection should be handled by the relevant daughter classes and their member functions in AIS.
0032 //! This is particularly true in the creation of new interactive objects.
0033 //!
0034 //! Key interface methods to be implemented by every Selectable Object:
0035 //! * Presentable Object (PrsMgr_PresentableObject)
0036 //!   Consider defining an enumeration of supported Display Mode indexes for particular Interactive Object or class of Interactive Objects.
0037 //!   - AcceptDisplayMode() accepting display modes implemented by this object;
0038 //!   - Compute() computing presentation for the given display mode index;
0039 //! * Selectable Object (SelectMgr_SelectableObject)
0040 //!   Consider defining an enumeration of supported Selection Mode indexes for particular Interactive Object or class of Interactive Objects.
0041 //!   - ComputeSelection() computing selectable entities for the given selection mode index.
0042 class SelectMgr_SelectableObject : public PrsMgr_PresentableObject
0043 {
0044   DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
0045   friend class SelectMgr_SelectionManager;
0046 public:
0047 
0048   //! Clears all selections of the object
0049   Standard_EXPORT virtual ~SelectMgr_SelectableObject();
0050 
0051   //! Computes sensitive primitives for the given selection mode - key interface method of Selectable Object.
0052   //! @param theSelection selection to fill
0053   //! @param theMode selection mode to create sensitive primitives
0054   virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
0055                                  const Standard_Integer theMode) = 0;
0056 
0057   //! Informs the graphic context that the interactive Object may be decomposed into sub-shapes for dynamic selection.
0058   //! The most used Interactive Object is AIS_Shape.
0059   virtual Standard_Boolean AcceptShapeDecomposition() const { return Standard_False; }
0060 
0061   //! Re-computes the sensitive primitives for all modes. IMPORTANT: Do not use
0062   //! this method to update selection primitives except implementing custom selection manager!
0063   //! This method does not take into account necessary BVH updates, but may invalidate the pointers
0064   //! it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
0065   Standard_EXPORT void RecomputePrimitives();
0066   
0067   //! Re-computes the sensitive primitives which correspond to the <theMode>th selection mode.
0068   //! IMPORTANT: Do not use this method to update selection primitives except implementing custom selection manager!
0069   //! selection manager! This method does not take into account necessary BVH updates, but may invalidate
0070   //! the pointers it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
0071   Standard_EXPORT void RecomputePrimitives (const Standard_Integer theMode);
0072   
0073   //! Adds the selection aSelection with the selection mode
0074   //! index aMode to this framework.
0075   Standard_EXPORT void AddSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode);
0076   
0077   //! Empties all the selections in the SelectableObject
0078   //! <update> parameter defines whether all object's
0079   //! selections should be flagged for further update or not.
0080   //! This improved method can be used to recompute an
0081   //! object's selection (without redisplaying the object
0082   //! completely) when some selection mode is activated not for the first time.
0083   Standard_EXPORT void ClearSelections (const Standard_Boolean update = Standard_False);
0084   
0085   //! Returns the selection having specified selection mode or NULL.
0086   Standard_EXPORT const Handle(SelectMgr_Selection)& Selection (const Standard_Integer theMode) const;
0087 
0088   //! Returns true if a selection corresponding to the selection mode theMode was computed for this object.
0089   Standard_Boolean HasSelection (const Standard_Integer theMode) const { return !Selection (theMode).IsNull(); }
0090 
0091   //! Return the sequence of selections.
0092   const SelectMgr_SequenceOfSelection& Selections() const { return myselections; }
0093 
0094   Standard_EXPORT void ResetTransformation() Standard_OVERRIDE;
0095   
0096   //! Recomputes the location of the selection aSelection.
0097   Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE;
0098   
0099   //! Updates locations in all sensitive entities from <aSelection>
0100   //! and in corresponding entity owners.
0101   Standard_EXPORT virtual void UpdateTransformations (const Handle(SelectMgr_Selection)& aSelection);
0102   
0103   //! Method which draws selected owners ( for fast presentation draw )
0104   Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0105                                                 const SelectMgr_SequenceOfOwner& theSeq);
0106   
0107   //! Method which clear all selected owners belonging
0108   //! to this selectable object ( for fast presentation draw )
0109   Standard_EXPORT virtual void ClearSelected();
0110 
0111   //! Method that needs to be implemented when the object
0112   //! manages selection and dynamic highlighting on its own.
0113   //! Clears or invalidates dynamic highlight presentation.
0114   //! By default it clears immediate draw of given presentation
0115   //! manager.
0116   Standard_EXPORT virtual void ClearDynamicHighlight (const Handle(PrsMgr_PresentationManager)& theMgr);
0117 
0118   //! Method which hilight an owner belonging to
0119   //! this selectable object  ( for fast presentation draw )
0120   Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
0121                                                       const Handle(Prs3d_Drawer)& theStyle,
0122                                                       const Handle(SelectMgr_EntityOwner)& theOwner);
0123   
0124   //! If returns True, the old mechanism for highlighting selected objects is used (HilightSelected Method may be empty).
0125   //! If returns False, the HilightSelected method will be fully responsible for highlighting selected entity owners belonging to this selectable object.
0126   virtual Standard_Boolean IsAutoHilight() const { return myAutoHilight; }
0127   
0128   //! Set AutoHilight property to true or false.
0129   virtual void SetAutoHilight (const Standard_Boolean theAutoHilight) { myAutoHilight = theAutoHilight; }
0130   
0131   //! Creates or returns existing presentation for highlighting detected object.
0132   //! @param thePrsMgr presentation manager to create new presentation
0133   //! @return existing or newly created presentation (when thePrsMgr is not NULL)
0134   Standard_EXPORT Handle(Prs3d_Presentation) GetHilightPresentation (const Handle(PrsMgr_PresentationManager)& thePrsMgr);
0135 
0136   //! Creates or returns existing presentation for highlighting selected object.
0137   //! @param thePrsMgr presentation manager to create new presentation
0138   //! @return existing or newly created presentation (when thePrsMgr is not NULL)
0139   Standard_EXPORT Handle(Prs3d_Presentation) GetSelectPresentation (const Handle(PrsMgr_PresentationManager)& thePrsMgr);
0140 
0141   //! Removes presentations returned by GetHilightPresentation() and GetSelectPresentation().
0142   Standard_EXPORT virtual void ErasePresentations (Standard_Boolean theToRemove);
0143 
0144   //! Set Z layer ID and update all presentations of the selectable object.
0145   //! The layers mechanism allows drawing objects in higher layers in overlay of objects in lower layers.
0146   Standard_EXPORT virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0147   
0148   //! Sets update status FULL to selections of the object. Must be used as the only method of UpdateSelection
0149   //! from outer classes to prevent BVH structures from being outdated.
0150   void UpdateSelection (const Standard_Integer theMode = -1)
0151   {
0152     updateSelection (theMode);
0153   }
0154 
0155   //! Sets common entity owner for assembly sensitive object entities
0156   Standard_EXPORT void SetAssemblyOwner (const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer theMode = -1);
0157 
0158   //! Returns a bounding box of sensitive entities with the owners given if they are a part of activated selection
0159   Standard_EXPORT Bnd_Box BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners);
0160 
0161   //! Returns the mode for selection of object as a whole; 0 by default.
0162   Standard_Integer GlobalSelectionMode() const { return myGlobalSelMode; }
0163 
0164   //! Returns the owner of mode for selection of object as a whole
0165   Standard_EXPORT virtual Handle(SelectMgr_EntityOwner) GlobalSelOwner() const;
0166 
0167   //! Returns common entity owner if the object is an assembly
0168   Standard_EXPORT virtual const Handle(SelectMgr_EntityOwner)& GetAssemblyOwner() const;
0169 
0170   //! Dumps the content of me into the stream
0171   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0172 
0173 protected:
0174 
0175   //! Protected empty constructor.
0176   Standard_EXPORT SelectMgr_SelectableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
0177 
0178   //! Override global selection mode.
0179   void setGlobalSelMode (const Standard_Integer theMode)
0180   {
0181     myGlobalSelMode = theMode > 0 ? theMode : 0;
0182   }
0183 
0184   //! Update clipping planes state.
0185   Standard_EXPORT virtual void UpdateClipping() Standard_OVERRIDE;
0186 
0187   //! Sets update status FULL to selections of the object.
0188   //! Must be used as the only method of UpdateSelection from outer classes to prevent BVH structures from being outdated.
0189   Standard_EXPORT virtual void updateSelection (const Standard_Integer theMode);
0190 
0191 protected:
0192 
0193   SelectMgr_SequenceOfSelection myselections;    //!< list of selections
0194   Handle(Prs3d_Presentation)    mySelectionPrs;  //!< optional presentation for highlighting selected object
0195   Handle(Prs3d_Presentation)    myHilightPrs;    //!< optional presentation for highlighting detected object
0196   Standard_Integer              myGlobalSelMode; //!< global selection mode
0197   Standard_Boolean              myAutoHilight;   //!< auto-highlighting flag defining
0198 
0199 };
0200 
0201 DEFINE_STANDARD_HANDLE(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
0202 
0203 #endif // _SelectMgr_SelectableObject_HeaderFile