42cf5bc1 |
1 | // Created on: 1995-02-13 |
2 | // Created by: Mister rmi |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _SelectMgr_SelectionManager_HeaderFile |
18 | #define _SelectMgr_SelectionManager_HeaderFile |
19 | |
42cf5bc1 |
20 | #include <SelectMgr_ViewerSelector.hxx> |
42cf5bc1 |
21 | #include <SelectMgr_TypeOfUpdate.hxx> |
42cf5bc1 |
22 | |
b5cce1ab |
23 | class SelectMgr_SelectableObject; |
42cf5bc1 |
24 | |
b5cce1ab |
25 | //! A framework to manage selection from the point of view of viewer selectors. |
26 | //! These can be added and removed, and selection modes can be activated and deactivated. |
27 | //! In addition, objects may be known to all selectors or only to some. |
25e59720 |
28 | class SelectMgr_SelectionManager : public Standard_Transient |
42cf5bc1 |
29 | { |
b5cce1ab |
30 | DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectionManager, Standard_Transient) |
42cf5bc1 |
31 | public: |
32 | |
42cf5bc1 |
33 | //! Constructs an empty selection manager object. |
68dcee02 |
34 | Standard_EXPORT SelectMgr_SelectionManager (const Handle(SelectMgr_ViewerSelector)& theSelector); |
35 | |
36 | //! Return the Selector. |
37 | const Handle(SelectMgr_ViewerSelector)& Selector() const { return mySelector; } |
a5162275 |
38 | |
42cf5bc1 |
39 | //! Returns true if the manager contains the selectable object theObject. |
40 | Standard_EXPORT Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const; |
41 | |
42 | //! Loads and computes selection mode theMode (if it is not equal to -1) in global context and adds selectable |
43 | //! object to BVH tree. If the object theObject has an already calculated selection with mode theMode and it was removed, |
44 | //! the selection will be recalculated. |
45 | Standard_EXPORT void Load (const Handle(SelectMgr_SelectableObject)& theObject, const Standard_Integer theMode = -1); |
46 | |
42cf5bc1 |
47 | //! Removes selectable object theObject from all viewer selectors it was added to previously, removes it from all contexts |
48 | //! and clears all computed selections of theObject. |
49 | Standard_EXPORT void Remove (const Handle(SelectMgr_SelectableObject)& theObject); |
50 | |
42cf5bc1 |
51 | //! Activates the selection mode theMode in the selector theSelector for the selectable object anObject. |
52 | //! By default, theMode is equal to 0. If theSelector is set to default (NULL), the selection with the mode theMode |
53 | //! will be activated in all the viewers available. |
b5cce1ab |
54 | Standard_EXPORT void Activate (const Handle(SelectMgr_SelectableObject)& theObject, |
68dcee02 |
55 | const Standard_Integer theMode = 0); |
42cf5bc1 |
56 | |
57 | //! Deactivates mode theMode of theObject in theSelector. If theMode value is set to default (-1), all |
b5cce1ab |
58 | //! active selection modes will be deactivated. Likewise, if theSelector value is set to default (NULL), theMode |
42cf5bc1 |
59 | //! will be deactivated in all viewer selectors. |
b5cce1ab |
60 | Standard_EXPORT void Deactivate (const Handle(SelectMgr_SelectableObject)& theObject, |
68dcee02 |
61 | const Standard_Integer theMode = -1); |
42cf5bc1 |
62 | |
63 | //! Returns true if the selection with theMode is active for the selectable object theObject and selector theSelector. |
64 | //! If all parameters are set to default values, it returns it there is any active selection in any known viewer selector for |
65 | //! object theObject. |
b5cce1ab |
66 | Standard_EXPORT Standard_Boolean IsActivated (const Handle(SelectMgr_SelectableObject)& theObject, |
68dcee02 |
67 | const Standard_Integer theMode = -1) const; |
42cf5bc1 |
68 | |
69 | //! Removes sensitive entities from all viewer selectors |
70 | //! after method Clear() was called to the selection they belonged to |
71 | //! or it was recomputed somehow. |
b5cce1ab |
72 | Standard_EXPORT void ClearSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj, |
68dcee02 |
73 | const Standard_Integer theMode = -1); |
42cf5bc1 |
74 | |
b5cce1ab |
75 | //! Re-adds newly calculated sensitive entities of recomputed selection |
42cf5bc1 |
76 | //! defined by mode theMode to all viewer selectors contained that selection. |
b5cce1ab |
77 | Standard_EXPORT void RestoreSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj, |
68dcee02 |
78 | const Standard_Integer theMode = -1); |
42cf5bc1 |
79 | |
80 | //! Recomputes activated selections of theObject for all known viewer selectors according to theMode specified. |
81 | //! If theMode is set to default (-1), then all activated selections will be recomputed. If theIsForce is set to true, |
82 | //! then selection mode theMode for object theObject will be recomputed regardless of its activation status. |
83 | Standard_EXPORT void RecomputeSelection (const Handle(SelectMgr_SelectableObject)& theObject, const Standard_Boolean theIsForce = Standard_False, const Standard_Integer theMode = -1); |
84 | |
85 | //! Updates all selections of theObject in all viewer selectors according to its current update status. |
86 | //! If theIsForce is set to true, the call is equal to recomputation. |
87 | Standard_EXPORT void Update (const Handle(SelectMgr_SelectableObject)& theObject, const Standard_Boolean theIsForce = Standard_True); |
68dcee02 |
88 | |
42cf5bc1 |
89 | //! Sets type of update of all selections of theObject to the given theType. |
90 | Standard_EXPORT void SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject, const SelectMgr_TypeOfUpdate theType); |
91 | |
92 | //! Sets type of update of selection with theMode of theObject to the given theType. |
93 | Standard_EXPORT void SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject, const Standard_Integer theMode, const SelectMgr_TypeOfUpdate theType); |
94 | |
8a1170ad |
95 | //! Allows to manage sensitivity of a particular selection of interactive object theObject and |
96 | //! changes previous sensitivity value of all sensitive entities in selection with theMode |
97 | //! to the given theNewSensitivity. |
98 | Standard_EXPORT void SetSelectionSensitivity (const Handle(SelectMgr_SelectableObject)& theObject, |
99 | const Standard_Integer theMode, |
100 | const Standard_Integer theNewSens); |
42cf5bc1 |
101 | |
1d92133e |
102 | //! Re-adds selectable object in BVHs in all viewer selectors. |
103 | Standard_EXPORT void UpdateSelection (const Handle(SelectMgr_SelectableObject)& theObj); |
104 | |
42cf5bc1 |
105 | protected: |
106 | |
45d5cbf8 |
107 | //! Recomputes given selection mode and updates BVHs in all viewer selectors |
108 | Standard_EXPORT void recomputeSelectionMode (const Handle(SelectMgr_SelectableObject)& theObject, |
109 | const Handle(SelectMgr_Selection)& theSelection, |
110 | const Standard_Integer theMode); |
42cf5bc1 |
111 | |
42cf5bc1 |
112 | private: |
113 | |
42cf5bc1 |
114 | //! Loads and creates selection structures for object theObject with mode theMode in specified |
115 | //! viewer selector theSelector. If theSelector is set to default value (NULL), the selection mode |
116 | //! created will be added to all known viewer selectors. |
b5cce1ab |
117 | Standard_EXPORT void loadMode (const Handle(SelectMgr_SelectableObject)& theObject, |
68dcee02 |
118 | const Standard_Integer theMode); |
42cf5bc1 |
119 | |
6a2fb7a1 |
120 | //! In multi-thread mode queues sensitive entities to build its BVH in separate threads. |
121 | //! Otherwise, builds BVH for heavyweight entities immediately. |
122 | Standard_EXPORT void buildBVH (const Handle(SelectMgr_Selection)& theSelection); |
123 | |
b5cce1ab |
124 | private: |
42cf5bc1 |
125 | |
68dcee02 |
126 | Handle(SelectMgr_ViewerSelector) mySelector; |
b5cce1ab |
127 | NCollection_Map<Handle(SelectMgr_SelectableObject)> myGlobal; |
42cf5bc1 |
128 | |
129 | }; |
130 | |
b5cce1ab |
131 | DEFINE_STANDARD_HANDLE(SelectMgr_SelectionManager, Standard_Transient) |
42cf5bc1 |
132 | |
133 | #endif // _SelectMgr_SelectionManager_HeaderFile |