Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-17 08:36:09

0001 // Created on: 1995-02-13
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_SelectionManager_HeaderFile
0018 #define _SelectMgr_SelectionManager_HeaderFile
0019 
0020 #include <SelectMgr_ViewerSelector.hxx>
0021 #include <SelectMgr_TypeOfUpdate.hxx>
0022 
0023 class SelectMgr_SelectableObject;
0024 
0025 //! A framework to manage selection from the point of view of viewer selectors.
0026 //! These can be added and removed, and selection modes can be activated and deactivated.
0027 //! In addition, objects may be known to all selectors or only to some.
0028 class SelectMgr_SelectionManager : public Standard_Transient
0029 {
0030   DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectionManager, Standard_Transient)
0031 public:
0032   //! Constructs an empty selection manager object.
0033   Standard_EXPORT SelectMgr_SelectionManager(const Handle(SelectMgr_ViewerSelector)& theSelector);
0034 
0035   //! Return the Selector.
0036   const Handle(SelectMgr_ViewerSelector)& Selector() const { return mySelector; }
0037 
0038   //! Returns true if the manager contains the selectable object theObject.
0039   Standard_EXPORT Standard_Boolean
0040     Contains(const Handle(SelectMgr_SelectableObject)& theObject) const;
0041 
0042   //! Loads and computes selection mode theMode (if it is not equal to -1) in global context and
0043   //! adds selectable object to BVH tree. If the object theObject has an already calculated
0044   //! selection with mode theMode and it was removed, the selection will be recalculated.
0045   Standard_EXPORT void Load(const Handle(SelectMgr_SelectableObject)& theObject,
0046                             const Standard_Integer                    theMode = -1);
0047 
0048   //! Removes selectable object theObject from all viewer selectors it was added to previously,
0049   //! removes it from all contexts and clears all computed selections of theObject.
0050   Standard_EXPORT void Remove(const Handle(SelectMgr_SelectableObject)& theObject);
0051 
0052   //! Activates the selection mode theMode in the selector theSelector for the selectable object
0053   //! anObject. By default, theMode is equal to 0. If theSelector is set to default (NULL), the
0054   //! selection with the mode theMode will be activated in all the viewers available.
0055   Standard_EXPORT void Activate(const Handle(SelectMgr_SelectableObject)& theObject,
0056                                 const Standard_Integer                    theMode = 0);
0057 
0058   //! Deactivates mode theMode of theObject in theSelector. If theMode value is set to default (-1),
0059   //! all active selection modes will be deactivated. Likewise, if theSelector value is set to
0060   //! default (NULL), theMode will be deactivated in all viewer selectors.
0061   Standard_EXPORT void Deactivate(const Handle(SelectMgr_SelectableObject)& theObject,
0062                                   const Standard_Integer                    theMode = -1);
0063 
0064   //! Returns true if the selection with theMode is active for the selectable object theObject and
0065   //! selector theSelector. If all parameters are set to default values, it returns it there is any
0066   //! active selection in any known viewer selector for object theObject.
0067   Standard_EXPORT Standard_Boolean IsActivated(const Handle(SelectMgr_SelectableObject)& theObject,
0068                                                const Standard_Integer theMode = -1) const;
0069 
0070   //! Removes sensitive entities from all viewer selectors
0071   //! after method Clear() was called to the selection they belonged to
0072   //! or it was recomputed somehow.
0073   Standard_EXPORT void ClearSelectionStructures(const Handle(SelectMgr_SelectableObject)& theObj,
0074                                                 const Standard_Integer theMode = -1);
0075 
0076   //! Re-adds newly calculated sensitive  entities of recomputed selection
0077   //! defined by mode theMode to all viewer selectors contained that selection.
0078   Standard_EXPORT void RestoreSelectionStructures(const Handle(SelectMgr_SelectableObject)& theObj,
0079                                                   const Standard_Integer theMode = -1);
0080 
0081   //! Recomputes activated selections of theObject for all known viewer selectors according to
0082   //! theMode specified. If theMode is set to default (-1), then all activated selections will be
0083   //! recomputed. If theIsForce is set to true, then selection mode theMode for object theObject
0084   //! will be recomputed regardless of its activation status.
0085   Standard_EXPORT void RecomputeSelection(const Handle(SelectMgr_SelectableObject)& theObject,
0086                                           const Standard_Boolean theIsForce = Standard_False,
0087                                           const Standard_Integer theMode    = -1);
0088 
0089   //! Updates all selections of theObject in all viewer selectors according to its current update
0090   //! status. If theIsForce is set to true, the call is equal to recomputation.
0091   Standard_EXPORT void Update(const Handle(SelectMgr_SelectableObject)& theObject,
0092                               const Standard_Boolean                    theIsForce = Standard_True);
0093 
0094   //! Sets type of update of all selections of theObject to the given theType.
0095   Standard_EXPORT void SetUpdateMode(const Handle(SelectMgr_SelectableObject)& theObject,
0096                                      const SelectMgr_TypeOfUpdate              theType);
0097 
0098   //! Sets type of update of selection with theMode of theObject to the given theType.
0099   Standard_EXPORT void SetUpdateMode(const Handle(SelectMgr_SelectableObject)& theObject,
0100                                      const Standard_Integer                    theMode,
0101                                      const SelectMgr_TypeOfUpdate              theType);
0102 
0103   //! Allows to manage sensitivity of a particular selection of interactive object theObject and
0104   //! changes previous sensitivity value of all sensitive entities in selection with theMode
0105   //! to the given theNewSensitivity.
0106   Standard_EXPORT void SetSelectionSensitivity(const Handle(SelectMgr_SelectableObject)& theObject,
0107                                                const Standard_Integer                    theMode,
0108                                                const Standard_Integer theNewSens);
0109 
0110   //! Re-adds selectable object in BVHs in all viewer selectors.
0111   Standard_EXPORT void UpdateSelection(const Handle(SelectMgr_SelectableObject)& theObj);
0112 
0113 protected:
0114   //! Recomputes given selection mode and updates BVHs in all viewer selectors
0115   Standard_EXPORT void recomputeSelectionMode(const Handle(SelectMgr_SelectableObject)& theObject,
0116                                               const Handle(SelectMgr_Selection)& theSelection,
0117                                               const Standard_Integer             theMode);
0118 
0119 private:
0120   //! Loads and creates selection structures for object theObject with mode theMode in specified
0121   //! viewer selector theSelector. If theSelector is set to default value (NULL), the selection mode
0122   //! created will be added to all known viewer selectors.
0123   Standard_EXPORT void loadMode(const Handle(SelectMgr_SelectableObject)& theObject,
0124                                 const Standard_Integer                    theMode);
0125 
0126   //! In multi-thread mode queues sensitive entities to build its BVH in separate threads.
0127   //! Otherwise, builds BVH for heavyweight entities immediately.
0128   Standard_EXPORT void buildBVH(const Handle(SelectMgr_Selection)& theSelection);
0129 
0130 private:
0131   Handle(SelectMgr_ViewerSelector)                    mySelector;
0132   NCollection_Map<Handle(SelectMgr_SelectableObject)> myGlobal;
0133 };
0134 
0135 DEFINE_STANDARD_HANDLE(SelectMgr_SelectionManager, Standard_Transient)
0136 
0137 #endif // _SelectMgr_SelectionManager_HeaderFile