b311480e |
1 | // Created on: 2007-01-25 |
2 | // Created by: Sergey KOCHETKOV |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <MeshVS_DataSource.hxx> |
18 | #include <MeshVS_Mesh.hxx> |
19 | #include <MeshVS_MeshOwner.hxx> |
20 | #include <PrsMgr_PresentationManager.hxx> |
21 | #include <PrsMgr_PresentationManager3d.hxx> |
7fd59977 |
22 | #include <SelectBasics_EntityOwner.hxx> |
23 | #include <SelectMgr_SelectableObject.hxx> |
42cf5bc1 |
24 | #include <Standard_Type.hxx> |
25 | #include <TColStd_HPackedMapOfInteger.hxx> |
7fd59977 |
26 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> |
27 | |
92efcf78 |
28 | IMPLEMENT_STANDARD_RTTIEXT(MeshVS_MeshOwner,SelectMgr_EntityOwner) |
29 | |
7fd59977 |
30 | #ifndef MeshVS_PRSBUILDERHXX |
31 | #include <MeshVS_PrsBuilder.hxx> |
32 | #endif |
33 | |
34 | |
35 | //================================================================ |
36 | // Function : Constructor MeshVS_MeshOwner |
37 | // Purpose : |
38 | //================================================================ |
39 | MeshVS_MeshOwner::MeshVS_MeshOwner (const SelectMgr_SOPtr& theSelObj, |
40 | const Handle(MeshVS_DataSource)& theDS, |
41 | const Standard_Integer thePriority) |
42 | : SelectMgr_EntityOwner ( theSelObj, thePriority ) |
43 | { |
44 | myLastID = -1; |
45 | if( !theDS.IsNull() ) |
46 | myDataSource = theDS; |
47 | SelectBasics_EntityOwner::Set ( thePriority ); |
48 | } |
49 | |
50 | //================================================================ |
51 | // Function : GetDataSource |
52 | // Purpose : |
53 | //================================================================ |
54 | const Handle(MeshVS_DataSource)& MeshVS_MeshOwner::GetDataSource () const |
55 | { |
56 | return myDataSource; |
57 | } |
58 | |
59 | //================================================================ |
60 | // Function : GetSelectedNodes |
61 | // Purpose : |
62 | //================================================================ |
63 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedNodes () const |
64 | { |
65 | return mySelectedNodes; |
66 | } |
67 | |
68 | //================================================================ |
69 | // Function : GetSelectedElements |
70 | // Purpose : |
71 | //================================================================ |
72 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedElements () const |
73 | { |
74 | return mySelectedElems; |
75 | } |
76 | |
77 | //================================================================ |
78 | // Function : AddSelectedEntities |
79 | // Purpose : |
80 | //================================================================ |
81 | void MeshVS_MeshOwner::AddSelectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes, |
82 | const Handle(TColStd_HPackedMapOfInteger)& Elems) |
83 | { |
84 | if( mySelectedNodes.IsNull() ) |
85 | mySelectedNodes = Nodes; |
86 | else if( !Nodes.IsNull() ) |
87 | mySelectedNodes->ChangeMap().Unite( Nodes->Map() ); |
88 | if( mySelectedElems.IsNull() ) |
89 | mySelectedElems = Elems; |
90 | else if( !Elems.IsNull() ) |
91 | mySelectedElems->ChangeMap().Unite( Elems->Map() ); |
92 | } |
93 | |
94 | //================================================================ |
95 | // Function : ClearSelectedEntities |
96 | // Purpose : |
97 | //================================================================ |
98 | void MeshVS_MeshOwner::ClearSelectedEntities () |
99 | { |
100 | mySelectedNodes.Nullify(); |
101 | mySelectedElems.Nullify(); |
102 | } |
103 | |
104 | //================================================================ |
105 | // Function : GetDetectedNodes |
106 | // Purpose : |
107 | //================================================================ |
108 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedNodes () const |
109 | { |
110 | return myDetectedNodes; |
111 | } |
112 | |
113 | //================================================================ |
114 | // Function : GetDetectedElements |
115 | // Purpose : |
116 | //================================================================ |
117 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedElements () const |
118 | { |
119 | return myDetectedElems; |
120 | } |
121 | |
122 | //================================================================ |
123 | // Function : SetDetectedEntities |
124 | // Purpose : |
125 | //================================================================ |
126 | void MeshVS_MeshOwner::SetDetectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes, |
127 | const Handle(TColStd_HPackedMapOfInteger)& Elems) |
128 | { |
129 | myDetectedNodes = Nodes; |
130 | myDetectedElems = Elems; |
c398b00e |
131 | if (IsSelected()) SetSelected (Standard_False); |
7fd59977 |
132 | } |
133 | |
134 | //================================================================ |
135 | // Function : HilightWithColor |
136 | // Purpose : |
137 | //================================================================ |
138 | void MeshVS_MeshOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, |
f838dac4 |
139 | const Handle(Prs3d_Drawer)& theStyle, |
d3f26155 |
140 | const Standard_Integer /*theMode*/) |
7fd59977 |
141 | { |
142 | Handle( SelectMgr_SelectableObject ) aSelObj; |
143 | if ( HasSelectable() ) |
144 | aSelObj = Selectable(); |
145 | |
146 | if ( thePM->IsImmediateModeOn() && aSelObj->IsKind( STANDARD_TYPE( MeshVS_Mesh ) ) ) |
147 | { |
148 | // Update last detected entity ID |
149 | Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes(); |
150 | Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements(); |
151 | if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 ) |
152 | { |
153 | TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() ); |
d3f26155 |
154 | if( myLastID != anIt.Key() ) |
7fd59977 |
155 | { |
d3f26155 |
156 | myLastID = anIt.Key(); |
7fd59977 |
157 | } |
d3f26155 |
158 | } |
7fd59977 |
159 | else if( !aElems.IsNull() && aElems->Map().Extent() == 1 ) |
160 | { |
161 | TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() ); |
d3f26155 |
162 | if( myLastID != anIt.Key() ) |
7fd59977 |
163 | { |
d3f26155 |
164 | myLastID = anIt.Key(); |
7fd59977 |
165 | } |
166 | } |
167 | |
168 | // hilight detected entities |
169 | Handle( MeshVS_Mesh ) aMesh = Handle( MeshVS_Mesh )::DownCast ( aSelObj ); |
8e5fb5ea |
170 | aMesh->HilightOwnerWithColor ( thePM, theStyle, this ); |
7fd59977 |
171 | } |
172 | } |
173 | |
f838dac4 |
174 | void MeshVS_MeshOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePM, const Standard_Integer ) |
7fd59977 |
175 | { |
f838dac4 |
176 | SelectMgr_EntityOwner::Unhilight (thePM); |
7fd59977 |
177 | |
178 | Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes(); |
179 | Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements(); |
180 | if( ( !aNodes.IsNull() && !aNodes->Map().Contains( myLastID ) ) || |
181 | ( !aElems.IsNull() && !aElems->Map().Contains( myLastID ) ) ) |
182 | return; |
183 | // Reset last detected ID |
184 | myLastID = -1; |
185 | } |
186 | |
187 | Standard_Boolean MeshVS_MeshOwner::IsForcedHilight () const |
188 | { |
189 | Standard_Boolean aHilight = Standard_True; |
190 | Standard_Integer aKey = -1; |
191 | if( myLastID > 0 ) |
192 | { |
193 | // Check the detected entity and |
194 | // allow to hilight it if it differs from the last detected entity <myLastID> |
195 | Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes(); |
196 | if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 ) |
197 | { |
198 | TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() ); |
d3f26155 |
199 | aKey = anIt.Key(); |
200 | if( myLastID == aKey ) |
201 | { |
202 | aHilight = Standard_False; |
7fd59977 |
203 | } |
204 | } |
205 | Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements(); |
206 | if( !aElems.IsNull() && aElems->Map().Extent() == 1 ) |
207 | { |
208 | TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() ); |
d3f26155 |
209 | aKey = anIt.Key(); |
210 | if( myLastID == aKey ) |
7fd59977 |
211 | { |
d3f26155 |
212 | aHilight = Standard_False; |
7fd59977 |
213 | } |
214 | } |
215 | } |
216 | return aHilight; |
217 | } |