b311480e |
1 | // Created on: 2003-09-09 |
2 | // Created by: Alexander SOLOVYOV |
973c2be1 |
3 | // Copyright (c) 2003-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 | |
17 | #include <AIS_InteractiveContext.hxx> |
7fd59977 |
18 | #include <Aspect_InteriorStyle.hxx> |
42cf5bc1 |
19 | #include <Bnd_Box.hxx> |
20 | #include <gp_Pnt.hxx> |
21 | #include <Graphic3d_AspectFillArea3d.hxx> |
22 | #include <Graphic3d_MaterialAspect.hxx> |
23 | #include <Graphic3d_NameOfMaterial.hxx> |
24 | #include <MeshVS_Buffer.hxx> |
25 | #include <MeshVS_DataMapIteratorOfDataMapOfIntegerOwner.hxx> |
26 | #include <MeshVS_DataSource.hxx> |
27 | #include <MeshVS_Drawer.hxx> |
28 | #include <MeshVS_DrawerAttribute.hxx> |
29 | #include <MeshVS_DummySensitiveEntity.hxx> |
30 | #include <MeshVS_Mesh.hxx> |
31 | #include <MeshVS_MeshEntityOwner.hxx> |
32 | #include <MeshVS_MeshOwner.hxx> |
33 | #include <MeshVS_PrsBuilder.hxx> |
34 | #include <MeshVS_SelectionModeFlags.hxx> |
35 | #include <MeshVS_SensitiveFace.hxx> |
36 | #include <MeshVS_SensitiveMesh.hxx> |
37 | #include <MeshVS_SensitivePolyhedron.hxx> |
38 | #include <MeshVS_SensitiveSegment.hxx> |
39 | #include <OSD_Timer.hxx> |
7fd59977 |
40 | #include <Prs3d_LineAspect.hxx> |
42cf5bc1 |
41 | #include <Prs3d_PointAspect.hxx> |
7fd59977 |
42 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 |
43 | #include <Prs3d_Root.hxx> |
44 | #include <Prs3d_ShadingAspect.hxx> |
7fd59977 |
45 | #include <PrsMgr_ModedPresentation.hxx> |
46 | #include <PrsMgr_PresentationManager3d.hxx> |
42cf5bc1 |
47 | #include <Select3D_SensitiveBox.hxx> |
48 | #include <Select3D_SensitiveGroup.hxx> |
49 | #include <Select3D_SensitivePoint.hxx> |
7fd59977 |
50 | #include <SelectBasics_SensitiveEntity.hxx> |
42cf5bc1 |
51 | #include <SelectMgr_EntityOwner.hxx> |
52 | #include <SelectMgr_Selection.hxx> |
7fd59977 |
53 | #include <SelectMgr_SequenceOfOwner.hxx> |
42cf5bc1 |
54 | #include <Standard_Type.hxx> |
55 | #include <TColgp_Array1OfPnt.hxx> |
7fd59977 |
56 | #include <TColStd_Array1OfInteger.hxx> |
42cf5bc1 |
57 | #include <TColStd_Array1OfReal.hxx> |
58 | #include <TColStd_HPackedMapOfInteger.hxx> |
59 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
7fd59977 |
60 | #include <TColStd_ListIteratorOfListOfReal.hxx> |
42cf5bc1 |
61 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> |
7fd59977 |
62 | #include <TColStd_SequenceOfInteger.hxx> |
7fd59977 |
63 | |
92efcf78 |
64 | IMPLEMENT_STANDARD_RTTIEXT(MeshVS_Mesh,AIS_InteractiveObject) |
65 | |
7fd59977 |
66 | //================================================================ |
67 | // Function : Constructor MeshVS_Mesh |
68 | // Purpose : |
69 | //================================================================ |
70 | MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped ) |
71 | { |
72 | myDataSource.Nullify(); |
73 | myHilighter.Nullify(); |
74 | myWholeMeshOwner.Nullify(); |
75 | mySelectionMethod = MeshVS_MSM_NODES; |
76 | |
77 | SetAutoHilight ( Standard_False ); |
78 | |
79 | SetDisplayMode( MeshVS_DMF_WireFrame ); // Mode as defaut |
80 | SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode |
81 | |
82 | SetColor ( Quantity_NOC_WHITE ); |
83 | SetMaterial ( Graphic3d_NOM_PLASTIC ); |
84 | |
85 | myCurrentDrawer = new MeshVS_Drawer(); |
86 | myCurrentDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_BLUE4 ); |
87 | myCurrentDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID ); |
88 | myCurrentDrawer->SetInteger ( MeshVS_DA_MaxFaceNodes, 10 ); |
89 | myCurrentDrawer->SetBoolean ( MeshVS_DA_IsAllowOverlapped, theIsAllowOverlapped ); |
90 | myCurrentDrawer->SetBoolean ( MeshVS_DA_Reflection, Standard_True ); |
91 | myCurrentDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.8 ); |
92 | myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeTime, Standard_False ); |
93 | myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeSelectionTime, Standard_False ); |
94 | myCurrentDrawer->SetBoolean ( MeshVS_DA_DisplayNodes, Standard_True ); |
95 | myCurrentDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 ); |
96 | myCurrentDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID ); |
97 | myCurrentDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_O ); |
98 | myCurrentDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_WHITE ); |
99 | myCurrentDrawer->SetDouble ( MeshVS_DA_MarkerScale, 1.0 ); |
100 | myCurrentDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID ); |
101 | myCurrentDrawer->SetDouble ( MeshVS_DA_BeamWidth, 1.0 ); |
102 | myCurrentDrawer->SetBoolean ( MeshVS_DA_SmoothShading, Standard_False ); |
103 | myCurrentDrawer->SetBoolean ( MeshVS_DA_SupressBackFaces, Standard_False ); |
104 | |
105 | mySelectionDrawer = new MeshVS_Drawer(); |
106 | mySelectionDrawer->Assign ( myCurrentDrawer ); |
107 | mySelectionDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR ); |
108 | mySelectionDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 ); |
109 | mySelectionDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 ); |
110 | |
111 | mySelectionDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 ); |
112 | mySelectionDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID ); |
113 | mySelectionDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 ); |
114 | |
115 | myHilightDrawer = new MeshVS_Drawer (); |
116 | myHilightDrawer->Assign ( myCurrentDrawer ); |
117 | myHilightDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.7 ); |
118 | myHilightDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID ); |
119 | myHilightDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_YELLOW ); |
120 | myHilightDrawer->SetColor ( MeshVS_DA_BackInteriorColor, Quantity_NOC_YELLOW ); |
121 | myHilightDrawer->SetColor ( MeshVS_DA_EdgeColor, Quantity_NOC_GREEN ); |
122 | myHilightDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID ); |
123 | myHilightDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 ); |
124 | myHilightDrawer->SetMaterial ( MeshVS_DA_FrontMaterial, Graphic3d_NOM_PLASTIC ); |
125 | myHilightDrawer->SetMaterial ( MeshVS_DA_BackMaterial, Graphic3d_NOM_PLASTIC ); |
126 | |
127 | myHilightDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 ); |
128 | myHilightDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID ); |
129 | myHilightDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 ); |
130 | |
131 | myHilightDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR ); |
132 | myHilightDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 ); |
133 | myHilightDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 ); |
134 | } |
135 | |
7fd59977 |
136 | //================================================================ |
137 | // Function : Compute |
138 | // Purpose : |
139 | //================================================================ |
140 | void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
141 | const Handle(Prs3d_Presentation)& thePresentation, |
142 | const Standard_Integer theMode ) |
143 | { |
144 | OSD_Timer gTimer; |
145 | |
146 | Standard_Boolean ShowComputeTime = Standard_True; |
147 | myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeTime, ShowComputeTime ); |
148 | |
149 | if ( ShowComputeTime ) |
150 | { |
151 | gTimer.Reset(); |
152 | gTimer.Start(); |
153 | } |
154 | |
155 | // Repair Ids in map if necessary |
156 | Handle( MeshVS_DataSource ) aDS = GetDataSource(); |
157 | if ( aDS.IsNull() ) |
158 | return; |
159 | |
160 | const TColStd_PackedMapOfInteger& aNodes = aDS->GetAllNodes(); |
161 | const TColStd_PackedMapOfInteger& aElems = aDS->GetAllElements(); |
162 | Standard_Boolean HasNodes = !aNodes.IsEmpty(), |
163 | HasElements = !aElems.IsEmpty(); |
164 | |
165 | TColStd_PackedMapOfInteger aNodesToExclude, aElemsToExclude; |
166 | |
167 | thePresentation->Clear(); |
168 | Standard_Integer len = myBuilders.Length(); |
169 | if ( theMode > 0 ) |
170 | for ( Standard_Integer i=1; i<=len; i++ ) |
171 | { |
172 | Handle (MeshVS_PrsBuilder) aCurrent = myBuilders.Value ( i ); |
173 | if ( !aCurrent.IsNull() && aCurrent->TestFlags ( theMode ) ) |
174 | { |
175 | aCurrent->SetPresentationManager( thePrsMgr ); |
176 | if( HasNodes ) |
177 | aCurrent->Build ( thePresentation, aNodes, aNodesToExclude, Standard_False, theMode ); |
178 | if( HasElements ) |
179 | aCurrent->Build ( thePresentation, aElems, aElemsToExclude, Standard_True, theMode ); |
180 | } |
181 | } |
182 | |
183 | |
184 | if ( ShowComputeTime ) |
185 | { |
186 | Standard_Real sec, cpu; |
187 | Standard_Integer min, hour; |
188 | |
189 | gTimer.Show ( sec, min, hour, cpu ); |
190 | cout << "DisplayMode : " << theMode << endl; |
191 | cout << "Compute : " << sec << " sec" << endl; |
192 | cout << "Compute CPU : " << cpu << " sec" << endl << endl; |
193 | gTimer.Stop(); |
194 | } |
195 | } |
196 | |
197 | //================================================================ |
198 | // Function : ComputeSelection |
199 | // Purpose : |
200 | //================================================================ |
201 | void MeshVS_Mesh::ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, |
202 | const Standard_Integer theMode ) |
203 | { |
204 | OSD_Timer gTimer; |
205 | |
206 | Standard_Boolean ShowComputeSelectionTime = Standard_True; |
207 | myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, ShowComputeSelectionTime ); |
208 | |
209 | if ( ShowComputeSelectionTime ) |
210 | { |
211 | gTimer.Reset(); |
212 | gTimer.Start(); |
213 | } |
214 | |
215 | Standard_Integer aMaxFaceNodes; |
216 | Handle( MeshVS_DataSource ) aSource = GetDataSource(); |
217 | |
218 | if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger |
219 | ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 ) |
220 | return; |
221 | |
222 | MeshVS_Buffer aCoordsBuf (3*aMaxFaceNodes*sizeof(Standard_Real)); |
223 | TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3*aMaxFaceNodes); |
224 | Standard_Integer NbNodes; |
225 | |
226 | MeshVS_EntityType aType; |
227 | Standard_Address anAddr; |
228 | TColStd_MapIteratorOfPackedMapOfInteger anIter; |
229 | Standard_Real x, y, z; |
230 | |
231 | Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode(); |
232 | if ( myHilighter.IsNull() || ( aMode & MeshVS_DMF_OCCMask ) == 0 ) |
233 | return; |
234 | const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes(); |
235 | const TColStd_PackedMapOfInteger& anAllElementsMap= aSource->GetAllElements(); |
236 | //agv Standard_Integer i; |
237 | |
238 | // skt: advanced mesh selection |
239 | if( aSource->IsAdvancedSelectionEnabled() ) { |
240 | Handle(MeshVS_MeshOwner) anOwner; |
241 | // Get the owner if it is already created |
242 | MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt( GetOwnerMaps( Standard_False ) ); |
243 | for( ; anIt.More(); anIt.Next() ) |
244 | { |
245 | anOwner = Handle(MeshVS_MeshOwner)::DownCast( anIt.Value() ); |
246 | // clear selected entities |
247 | if( !anOwner.IsNull() ) |
248 | break; |
249 | } |
250 | if( anOwner.IsNull() ) |
251 | // Create one owner for the whole mesh and for all selection modes |
252 | anOwner = new MeshVS_MeshOwner( this, aSource, 5 ); |
253 | // Save the owner. It will be available via GetOwnerMaps method |
254 | if( !myMeshOwners.IsBound( 1 ) ) |
255 | myMeshOwners.Bind( 1, anOwner ); |
256 | // Create one sensitive entity. It should detect mesh entities correspondingly |
257 | // to selection mode |
258 | Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh( anOwner, theMode ); |
259 | theSelection->Add ( aSensMesh ); |
260 | } |
261 | else { |
262 | switch ( theMode ) |
263 | { |
264 | case MeshVS_SMF_Node: // Nodes |
265 | |
266 | myNodeOwners.Clear(); |
267 | |
268 | for ( anIter.Initialize( anAllNodesMap ); anIter.More(); anIter.Next() ) |
269 | { |
270 | Standard_Integer aKey = anIter.Key(); |
271 | if ( !myDataSource->GetGeom ( aKey, Standard_False, aCoords, NbNodes, aType ) ) |
272 | continue; |
273 | |
274 | anAddr = myDataSource->GetAddr ( aKey, Standard_False ); |
275 | |
276 | Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner |
277 | ( this, aKey, anAddr, aType, 5 ); |
278 | |
279 | myNodeOwners.Bind ( aKey, anOwner ); |
280 | |
281 | if ( IsSelectableNode( aKey ) ) |
282 | { |
283 | x = aCoords(1); |
284 | y = aCoords(2); |
285 | z = aCoords(3); |
286 | Handle (Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint |
287 | ( anOwner, gp_Pnt (x, y, z) ); |
288 | theSelection->Add ( aPoint ); |
289 | } |
290 | else |
291 | theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); |
292 | } |
293 | break; |
294 | |
295 | case MeshVS_SMF_Mesh: |
296 | |
297 | if( myWholeMeshOwner.IsNull() ) |
298 | myWholeMeshOwner = new SelectMgr_EntityOwner( this ); |
299 | |
300 | switch( mySelectionMethod ) |
301 | { |
302 | case MeshVS_MSM_BOX: |
303 | { |
eb1ebea4 |
304 | Bnd_Box box; |
7fd59977 |
305 | TColStd_MapIteratorOfPackedMapOfInteger anIterN( anAllNodesMap ); |
7fd59977 |
306 | for( ; anIterN.More(); anIterN.Next() ) |
eb1ebea4 |
307 | { |
eafb234b |
308 | if( myDataSource->GetGeom( anIterN.Key(), Standard_False, aCoords, NbNodes, aType ) ) { |
eb1ebea4 |
309 | box.Add (gp_Pnt (aCoords(1), aCoords(2), aCoords(3))); |
eafb234b |
310 | } |
eb1ebea4 |
311 | } |
312 | if (!box.IsVoid()) |
313 | theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, box)); |
7fd59977 |
314 | } |
315 | break; |
316 | |
317 | case MeshVS_MSM_NODES: |
318 | { |
319 | TColStd_MapIteratorOfPackedMapOfInteger anIterN( anAllNodesMap ); |
320 | for( ; anIterN.More(); anIterN.Next() ) |
321 | if( myDataSource->GetGeom( anIterN.Key(), Standard_False, aCoords, NbNodes, aType ) && |
709e97a0 |
322 | IsSelectableNode( anIterN.Key() ) ) |
7fd59977 |
323 | theSelection->Add( new Select3D_SensitivePoint( myWholeMeshOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) ); |
324 | } |
325 | break; |
326 | |
327 | case MeshVS_MSM_PRECISE: |
328 | { |
329 | Handle( Select3D_SensitiveEntity ) anEnt; |
330 | TColStd_MapIteratorOfPackedMapOfInteger anIterMV( anAllElementsMap ); |
331 | |
332 | TColStd_PackedMapOfInteger aSharedNodes; |
333 | for( ; anIterMV.More(); anIterMV.Next() ) |
334 | { |
335 | Standard_Integer aKey = anIterMV.Key(); |
336 | |
337 | if( IsSelectableElem( aKey ) && |
338 | myDataSource->GetGeomType( aKey, Standard_True, aType ) && |
339 | aType==MeshVS_ET_Face ) |
340 | { |
341 | myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); |
342 | if( NbNodes==0 ) |
343 | continue; |
344 | |
345 | MeshVS_Buffer aNodesBuf (NbNodes*sizeof(Standard_Integer)); |
346 | TColStd_Array1OfInteger aElemNodes(aNodesBuf, 1, NbNodes); |
347 | if ( !myDataSource->GetNodesByElement ( aKey, aElemNodes, NbNodes ) ) |
348 | continue; |
349 | |
350 | TColgp_Array1OfPnt Points( 1, NbNodes ); |
351 | for ( Standard_Integer i=1; i<=NbNodes; i++ ) |
352 | { |
353 | Points (i) = gp_Pnt ( aCoords (3*i-2), aCoords (3*i-1), aCoords (3*i) ); |
354 | aSharedNodes.Add( aElemNodes( i ) ); |
355 | } |
356 | |
bf3977c9 |
357 | anEnt = new Select3D_SensitiveFace( myWholeMeshOwner, Points, Select3D_TOS_INTERIOR); |
7fd59977 |
358 | theSelection->Add( anEnt ); |
359 | } |
360 | } |
361 | for( anIterMV.Initialize( anAllElementsMap ); anIterMV.More(); anIterMV.Next() ) |
362 | { |
363 | Standard_Integer aKey = anIterMV.Key(); |
364 | |
365 | if( IsSelectableElem( aKey ) && |
366 | myDataSource->GetGeomType( aKey, Standard_True, aType ) && |
367 | aType==MeshVS_ET_Link ) |
368 | { |
369 | myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); |
370 | if( NbNodes==0 ) |
371 | continue; |
372 | |
373 | MeshVS_Buffer aNodesBuf (NbNodes*sizeof(Standard_Integer)); |
374 | TColStd_Array1OfInteger aElemNodes(aNodesBuf, 1, NbNodes); |
375 | if ( !myDataSource->GetNodesByElement ( aKey, aElemNodes, NbNodes ) ) |
376 | continue; |
377 | |
378 | TColgp_Array1OfPnt Points( 1, NbNodes ); |
379 | Standard_Boolean all_shared = Standard_True; |
380 | for ( Standard_Integer i=1; i<=NbNodes; i++ ) |
381 | { |
382 | Points (i) = gp_Pnt ( aCoords (3*i-2), aCoords (3*i-1), aCoords (3*i) ); |
383 | all_shared = all_shared && aSharedNodes.Contains( aElemNodes( i ) ); |
384 | aSharedNodes.Add( aElemNodes( i ) ); |
385 | } |
386 | |
387 | if( !all_shared ) |
388 | { |
389 | anEnt = new Select3D_SensitiveSegment( myWholeMeshOwner, Points.Value( 1 ), Points.Value( 2 ) ); |
390 | theSelection->Add( anEnt ); |
391 | } |
392 | } |
393 | } |
394 | for( anIterMV.Initialize( anAllNodesMap ); anIterMV.More(); anIterMV.Next() ) |
395 | { |
396 | Standard_Integer aKey = anIterMV.Key(); |
397 | if( IsSelectableElem( aKey ) && |
398 | myDataSource->GetGeom ( aKey, Standard_False, aCoords, NbNodes, aType ) && |
399 | !aSharedNodes.Contains( aKey ) ) |
400 | { |
401 | anEnt = new Select3D_SensitivePoint( myWholeMeshOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) ; |
402 | theSelection->Add( anEnt ); |
403 | } |
404 | } |
405 | } |
406 | break; |
407 | } |
408 | break; |
409 | |
410 | case MeshVS_SMF_Group: |
411 | { |
412 | myGroupOwners.Clear(); |
413 | |
414 | TColStd_PackedMapOfInteger anAllGroupsMap; |
415 | aSource->GetAllGroups( anAllGroupsMap ); |
416 | |
417 | Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo; |
418 | |
419 | for ( anIter.Initialize( anAllGroupsMap ); anIter.More(); anIter.Next() ) |
420 | { |
421 | Standard_Integer aKeyGroup = anIter.Key(); |
422 | |
423 | MeshVS_EntityType aGroupType; |
424 | TColStd_PackedMapOfInteger aGroupMap; |
425 | if ( !myDataSource->GetGroup( aKeyGroup, aGroupType, aGroupMap ) ) |
426 | continue; |
427 | |
428 | anAddr = myDataSource->GetGroupAddr ( aKeyGroup ); |
429 | Standard_Integer aPrior = 0; |
430 | |
431 | if( aGroupType == MeshVS_ET_Volume ) |
432 | aPrior = 1; |
433 | if ( aGroupType == MeshVS_ET_Face ) |
434 | aPrior = 2; |
435 | else if ( aGroupType == MeshVS_ET_Link ) |
436 | aPrior = 3; |
437 | else if ( aGroupType == MeshVS_ET_0D ) |
438 | aPrior = 4; |
439 | else if ( aGroupType == MeshVS_ET_Node ) |
440 | aPrior = 5; |
441 | |
442 | Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner |
443 | ( this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True ); |
444 | |
445 | myGroupOwners.Bind( aKeyGroup, anOwner ); |
446 | |
447 | Standard_Boolean added = Standard_False; |
448 | for ( TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap); |
449 | anIterMG.More(); anIterMG.Next() ) |
450 | { |
451 | Standard_Integer aKey = anIterMG.Key(); |
452 | if ( aGroupType == MeshVS_ET_Node ) { |
453 | if( myDataSource->GetGeom( aKey, Standard_False, aCoords, NbNodes, aType ) && |
454 | IsSelectableNode/*!IsHiddenNode*/( aKey ) ) { |
455 | theSelection->Add( new Select3D_SensitivePoint( anOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) ); |
456 | added = Standard_True; |
457 | } |
458 | } |
459 | else if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) && |
460 | IsSelectableElem/*!IsHiddenElem*/( aKey ) ) { |
461 | myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); |
462 | |
463 | TColgp_Array1OfPnt anArr( 1, NbNodes ); |
464 | for ( Standard_Integer i=1; i<=NbNodes; i++ ) |
465 | { |
466 | x = aCoords(3*i-2); |
467 | y = aCoords(3*i-1); |
468 | z = aCoords(3*i); |
469 | anArr.SetValue ( i, gp_Pnt ( x, y, z ) ); |
470 | } |
471 | |
472 | if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements |
473 | { |
474 | Handle (MeshVS_SensitiveFace) aFace = |
475 | new MeshVS_SensitiveFace( anOwner, anArr ); |
476 | theSelection->Add ( aFace ); |
477 | added = Standard_True; |
478 | } |
479 | else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements |
480 | { |
481 | Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment |
482 | ( anOwner, anArr(1), anArr(2) ); |
483 | theSelection->Add ( aSeg ); |
484 | added = Standard_True; |
485 | } |
486 | else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) ) |
487 | { |
488 | Handle( MeshVS_SensitivePolyhedron ) aPolyhedron = |
489 | new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo ); |
490 | theSelection->Add( aPolyhedron ); |
491 | added = Standard_True; |
492 | } |
493 | else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!! |
494 | { |
495 | Handle (SelectBasics_SensitiveEntity) anEnt = |
496 | myHilighter->CustomSensitiveEntity ( anOwner, aKey ); |
497 | if (!anEnt.IsNull()) { |
498 | theSelection->Add ( anEnt ); |
499 | added = Standard_True; |
500 | } |
501 | } |
502 | } |
503 | } |
504 | if ( !added ) |
505 | theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); |
506 | } |
507 | } |
508 | break; |
509 | |
510 | default: // all residuary modes |
511 | { |
512 | Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo; |
513 | |
514 | myElementOwners.Clear(); |
515 | |
516 | MeshVS_DataMapOfIntegerOwner* CurMap = &my0DOwners; |
517 | if ( theMode == MeshVS_ET_Link ) |
518 | CurMap = &myLinkOwners; |
519 | else if ( theMode == MeshVS_ET_Face ) |
520 | CurMap = &myFaceOwners; |
521 | else if ( theMode == MeshVS_ET_Volume ) |
522 | CurMap = &myVolumeOwners; |
523 | |
524 | CurMap->Clear(); |
525 | |
526 | for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap); |
527 | anIterMV.More(); anIterMV.Next() ) |
528 | { |
529 | Standard_Integer aKey = anIterMV.Key(); |
530 | |
531 | if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) && theMode == aType ) |
532 | { |
533 | myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); |
534 | anAddr = myDataSource->GetAddr ( aKey, Standard_True ); |
535 | |
536 | Standard_Integer aPrior = 0; |
537 | |
538 | if( aType == MeshVS_ET_Volume ) |
539 | aPrior = 1; |
540 | if ( aType == MeshVS_ET_Face ) |
541 | aPrior = 2; |
542 | else if ( aType == MeshVS_ET_Link ) |
543 | aPrior = 3; |
544 | else if ( aType == MeshVS_ET_0D ) |
545 | aPrior = 4; |
546 | |
547 | Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner |
548 | ( this, aKey, anAddr, aType, aPrior ); |
549 | |
550 | CurMap->Bind ( aKey, anOwner ); |
551 | |
552 | if ( IsSelectableElem( aKey ) ) //The element is selectable |
553 | { |
554 | TColgp_Array1OfPnt anArr( 1, NbNodes ); |
555 | for ( Standard_Integer i=1; i<=NbNodes; i++ ) |
556 | { |
557 | x = aCoords(3*i-2); |
558 | y = aCoords(3*i-1); |
559 | z = aCoords(3*i); |
560 | anArr.SetValue ( i, gp_Pnt ( x, y, z ) ); |
561 | } |
562 | |
563 | if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements |
564 | { |
565 | Handle (MeshVS_SensitiveFace) aFace = |
566 | new MeshVS_SensitiveFace( anOwner, anArr ); |
567 | theSelection->Add ( aFace ); |
568 | } |
569 | else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements |
570 | { |
571 | Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment |
572 | ( anOwner, anArr(1), anArr(2) ); |
573 | theSelection->Add ( aSeg ); |
574 | } |
575 | else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) ) |
576 | { |
577 | Handle( MeshVS_SensitivePolyhedron ) aPolyhedron = |
578 | new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo ); |
579 | theSelection->Add( aPolyhedron ); |
580 | } |
581 | else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!! |
582 | { |
583 | Handle (SelectBasics_SensitiveEntity) anEnt = |
584 | myHilighter->CustomSensitiveEntity ( anOwner, aKey ); |
585 | if (!anEnt.IsNull()) |
586 | theSelection->Add ( anEnt ); |
587 | } |
588 | } |
589 | else |
590 | theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); |
591 | } |
592 | } |
593 | } |
594 | break; |
595 | } |
596 | } |
597 | |
598 | if ( ShowComputeSelectionTime ) |
599 | { |
600 | Standard_Real sec, cpu; |
601 | Standard_Integer min, hour; |
602 | |
603 | gTimer.Show ( sec, min, hour, cpu ); |
604 | cout << "SelectionMode : " << theMode << endl; |
605 | cout << "Compute selection: " << sec << " sec" << endl; |
606 | cout << "Compute selection CPU : " << cpu << " sec" << endl << endl; |
607 | gTimer.Stop(); |
608 | } |
609 | } |
610 | |
611 | //================================================================ |
612 | // Function : GetBuildersCount |
613 | // Purpose : |
614 | //================================================================ |
615 | Standard_Integer MeshVS_Mesh::GetBuildersCount () const |
616 | { |
617 | return myBuilders.Length(); |
618 | } |
619 | |
620 | //================================================================ |
621 | // Function : GetFreeId |
622 | // Purpose : |
623 | //================================================================ |
624 | Standard_Integer MeshVS_Mesh::GetFreeId () const |
625 | { |
626 | TColStd_PackedMapOfInteger Ids; |
627 | Standard_Integer i, len = myBuilders.Length(), curId; |
628 | |
629 | for ( i=1; i<=len; i++ ) |
630 | Ids.Add( myBuilders.Value(i)->GetId () ); |
631 | |
632 | curId = 0; |
633 | while ( Ids.Contains( curId ) ) |
634 | curId++; |
635 | |
636 | return curId; |
637 | } |
638 | |
639 | //================================================================ |
640 | // Function : GetBuilder |
641 | // Purpose : |
642 | //================================================================ |
643 | Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilder ( const Standard_Integer Index ) const |
644 | { |
645 | if ( Index>=1 && Index<=myBuilders.Length() ) |
646 | return myBuilders.Value( Index ); |
647 | else |
648 | return 0; |
649 | } |
650 | |
651 | //================================================================ |
652 | // Function : GetBuilderById |
653 | // Purpose : |
654 | //================================================================ |
655 | Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilderById ( const Standard_Integer Id ) const |
656 | { |
657 | Handle (MeshVS_PrsBuilder) Result; |
658 | |
659 | Standard_Integer i, len = myBuilders.Length(); |
660 | for ( i=1; i<=len; i++ ) |
661 | if ( myBuilders.Value(i)->GetId () == Id ) |
662 | { |
663 | Result = myBuilders.Value(i); |
664 | break; |
665 | } |
666 | return Result; |
667 | } |
668 | |
669 | //================================================================ |
670 | // Function : AddBuilder |
671 | // Purpose : |
672 | //================================================================ |
673 | void MeshVS_Mesh::AddBuilder ( const Handle (MeshVS_PrsBuilder)& theBuilder, |
674 | const Standard_Boolean TreatAsHilighter ) |
675 | { |
676 | if ( theBuilder.IsNull() ) |
677 | return; |
678 | |
679 | Standard_Integer i, n = myBuilders.Length(); |
680 | for ( i = 1; i<=n; i++ ) |
681 | if ( myBuilders(i)->GetPriority() < theBuilder->GetPriority() ) |
682 | break; |
683 | |
684 | if ( i>n ) |
685 | myBuilders.Append ( theBuilder ); |
686 | else |
687 | myBuilders.InsertBefore ( i, theBuilder ); |
688 | |
689 | if( TreatAsHilighter ) |
690 | myHilighter = theBuilder; |
691 | } |
692 | |
693 | //================================================================ |
694 | // Function : RemoveBuilder |
695 | // Purpose : |
696 | //================================================================ |
697 | void MeshVS_Mesh::RemoveBuilder ( const Standard_Integer theIndex ) |
698 | { |
699 | Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( theIndex ); |
700 | if ( !aBuild.IsNull() ) |
701 | { |
702 | if ( aBuild == myHilighter ) |
703 | myHilighter.Nullify(); |
704 | myBuilders.Remove ( theIndex ); |
705 | } |
706 | } |
707 | |
708 | //================================================================ |
709 | // Function : RemoveBuilderById |
710 | // Purpose : |
711 | //================================================================ |
712 | void MeshVS_Mesh::RemoveBuilderById ( const Standard_Integer Id ) |
713 | { |
714 | Standard_Integer i, n = myBuilders.Length(); |
715 | for ( i=1; i<=n; i++ ) |
716 | { |
717 | Handle( MeshVS_PrsBuilder ) aCur = myBuilders(i); |
718 | if ( !aCur.IsNull() && aCur->GetId()==Id ) |
719 | break; |
720 | } |
721 | if ( i>=1 && i<=n ) |
722 | { |
723 | if ( GetBuilder( i )==myHilighter ) |
724 | myHilighter.Nullify(); |
725 | RemoveBuilder ( i ); |
726 | } |
727 | } |
728 | |
729 | //================================================================ |
730 | // Function : SetHiddenElems |
731 | // Purpose : |
732 | //================================================================ |
733 | void MeshVS_Mesh::SetHiddenElems ( const Handle(TColStd_HPackedMapOfInteger)& theMap ) |
734 | { |
735 | myHiddenElements = theMap; |
736 | |
737 | // Note: update of list of selectable nodes -- this is not optimal! |
738 | Standard_Boolean AutoSelUpdate = Standard_False; |
739 | if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) && |
740 | AutoSelUpdate ) |
741 | UpdateSelectableNodes(); |
742 | } |
743 | |
744 | //================================================================ |
745 | // Function : SetHiddenNodes |
746 | // Purpose : |
747 | //================================================================ |
748 | void MeshVS_Mesh::SetHiddenNodes ( const Handle(TColStd_HPackedMapOfInteger)& theMap ) |
749 | { |
750 | myHiddenNodes = theMap; |
751 | |
752 | // Note: update of list of selectable nodes -- this is not optimal! |
753 | Standard_Boolean AutoSelUpdate = Standard_False; |
754 | if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) && |
755 | AutoSelUpdate ) |
756 | UpdateSelectableNodes(); |
757 | } |
758 | |
759 | //================================================================ |
760 | // Function : GetHiddenElems |
761 | // Purpose : |
762 | //================================================================ |
763 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenElems () const |
764 | { |
765 | return myHiddenElements; |
766 | } |
767 | |
768 | //================================================================ |
769 | // Function : GetHiddenNodes |
770 | // Purpose : |
771 | //================================================================ |
772 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenNodes () const |
773 | { |
774 | return myHiddenNodes; |
775 | } |
776 | |
777 | //================================================================ |
778 | // Function : AddToMap |
779 | // Purpose : |
780 | //================================================================ |
781 | void AddToMap ( MeshVS_DataMapOfIntegerOwner& Result, const MeshVS_DataMapOfIntegerOwner& Addition ) |
782 | { |
783 | MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt ( Addition ); |
784 | for ( ; anIt.More(); anIt.Next() ) |
785 | if ( Result.IsBound ( anIt.Key() ) ) |
786 | Result.ChangeFind ( anIt.Key() ) = anIt.Value(); |
787 | else |
788 | Result.Bind( anIt.Key(), anIt.Value() ); |
789 | } |
790 | |
791 | //================================================================ |
792 | // Function : GetOwnerMaps |
793 | // Purpose : |
794 | //================================================================ |
795 | const MeshVS_DataMapOfIntegerOwner& MeshVS_Mesh::GetOwnerMaps ( const Standard_Boolean IsElements ) |
796 | { |
797 | Handle(MeshVS_DataSource) aDS = GetDataSource(); |
798 | if( !aDS.IsNull() && aDS->IsAdvancedSelectionEnabled() ) |
799 | return myMeshOwners; |
800 | if ( IsElements ) |
801 | { |
802 | if ( myElementOwners.IsEmpty() ) |
803 | { |
804 | AddToMap ( myElementOwners, my0DOwners ); |
805 | AddToMap ( myElementOwners, myLinkOwners ); |
806 | AddToMap ( myElementOwners, myFaceOwners ); |
807 | AddToMap ( myElementOwners, myVolumeOwners ); |
808 | } |
809 | return myElementOwners; |
810 | } |
811 | else |
812 | return myNodeOwners; |
813 | } |
814 | |
815 | //================================================================ |
816 | // Function : IsHiddenElem |
817 | // Purpose : |
818 | //================================================================ |
819 | Standard_Boolean MeshVS_Mesh::IsHiddenElem ( const Standard_Integer theID ) const |
820 | { |
821 | return ! myHiddenElements.IsNull() && myHiddenElements->Map().Contains( theID ); |
822 | } |
823 | |
824 | //================================================================ |
825 | // Function : IsHiddenNode |
826 | // Purpose : |
827 | //================================================================ |
828 | Standard_Boolean MeshVS_Mesh::IsHiddenNode ( const Standard_Integer theID ) const |
829 | { |
830 | // note that by default all nodes are hidden |
831 | return myHiddenNodes.IsNull() || myHiddenNodes->Map().Contains( theID ); |
832 | } |
833 | |
834 | //================================================================ |
835 | // Function : GetDrawer |
836 | // Purpose : |
837 | //================================================================ |
838 | Handle( MeshVS_Drawer ) MeshVS_Mesh::GetDrawer() const |
839 | { |
840 | return myCurrentDrawer; |
841 | } |
842 | |
843 | //================================================================ |
844 | // Function : SetDrawer |
845 | // Purpose : |
846 | //================================================================ |
847 | void MeshVS_Mesh::SetDrawer(const Handle(MeshVS_Drawer)& aDrawer) |
848 | { |
849 | myCurrentDrawer = aDrawer; |
850 | } |
851 | |
852 | //================================================================ |
853 | // Function : GetDataSource |
854 | // Purpose : |
855 | //================================================================ |
856 | Handle(MeshVS_DataSource) MeshVS_Mesh::GetDataSource() const |
857 | { |
858 | return myDataSource; |
859 | } |
860 | |
861 | //================================================================ |
862 | // Function : SetDataSource |
863 | // Purpose : |
864 | //================================================================ |
865 | void MeshVS_Mesh::SetDataSource( const Handle(MeshVS_DataSource)& theDataSource ) |
866 | { |
867 | myDataSource = theDataSource; |
868 | } |
869 | |
870 | //================================================================ |
871 | // Function : HilightSelected |
872 | // Purpose : |
873 | //================================================================ |
874 | void MeshVS_Mesh::HilightSelected ( const Handle(PrsMgr_PresentationManager3d)& thePM, |
875 | const SelectMgr_SequenceOfOwner& theOwners ) |
876 | { |
877 | if ( myHilighter.IsNull() ) |
878 | return; |
879 | |
880 | // if ( mySelectionPrs.IsNull() ) |
881 | // mySelectionPrs = new Prs3d_Presentation ( thePM->StructureManager() ); |
882 | |
883 | //new functionality |
884 | |
885 | Handle( Prs3d_Presentation ) aSelectionPrs; |
886 | |
887 | aSelectionPrs = GetSelectPresentation( thePM ); |
888 | |
889 | if( HasPresentation() ) |
890 | aSelectionPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); |
891 | //---------------- |
892 | |
893 | // It is very important to call this parent method, because it check whether |
894 | // mySelectionPrs is created and if not, create it. |
895 | |
0797d9d3 |
896 | #ifdef OCCT_DEBUG |
7fd59977 |
897 | OSD_Timer gTimer; |
898 | gTimer.Reset(); |
899 | gTimer.Start(); |
900 | #endif |
901 | |
902 | Standard_Integer len = theOwners.Length(), i; |
903 | |
904 | Handle (MeshVS_MeshEntityOwner) anOwner; |
905 | TColStd_PackedMapOfInteger aSelNodes, aSelElements; |
906 | |
907 | for( i=1; i<=len; i++ ) |
908 | { |
673cf4e3 |
909 | if (theOwners.Value (i) == GlobalSelOwner()) |
910 | { |
911 | const Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0; |
912 | const Quantity_NameOfColor aSelColor = GetContext().IsNull() ? Quantity_NOC_GRAY80 : GetContext()->SelectionColor(); |
913 | thePM->Color (this, aSelColor, aHiMode); |
914 | continue; |
915 | } |
7fd59977 |
916 | anOwner = Handle (MeshVS_MeshEntityOwner)::DownCast ( theOwners.Value ( i ) ); |
917 | if ( !anOwner.IsNull() ) |
918 | { |
919 | // nkv: add support of mesh groups |
920 | if ( anOwner->IsGroup() ) { |
921 | MeshVS_EntityType aGroupType; |
922 | TColStd_PackedMapOfInteger aGroupMap; |
923 | if ( GetDataSource()->GetGroup( anOwner->ID(), aGroupType, aGroupMap ) ) { |
924 | if ( aGroupType == MeshVS_ET_Node ) { |
925 | for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() ) |
926 | if( IsSelectableNode/*!IsHiddenNode*/( anIt.Key() ) ) |
927 | aSelNodes.Add( anIt.Key() ); |
928 | } |
929 | else { |
930 | for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() ) |
931 | if( IsSelectableElem/*!IsHiddenElem*/( anIt.Key() ) ) |
932 | aSelElements.Add( anIt.Key() ); |
933 | } |
934 | } |
935 | } |
936 | else { |
937 | if( anOwner->Type() == MeshVS_ET_Node ) |
938 | aSelNodes.Add( anOwner->ID() ); |
939 | else |
940 | aSelElements.Add( anOwner->ID() ); |
941 | } |
942 | } |
943 | else if( GetDataSource()->IsAdvancedSelectionEnabled() ) |
944 | { |
945 | Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwners.Value ( i ) ); |
946 | if( !aMeshOwner.IsNull() ) |
947 | { |
948 | Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetSelectedNodes(); |
949 | Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetSelectedElements(); |
950 | if( !aNodes.IsNull() ) |
951 | aSelNodes.Assign( aNodes->Map() ); |
952 | if( !aElems.IsNull() ) |
953 | aSelElements.Assign( aElems->Map() ); |
954 | } |
955 | } |
956 | //agv else if( theOwners.Value ( i )==myWholeMeshOwner ) |
957 | else if (IsWholeMeshOwner (theOwners.Value ( i ))) |
958 | { |
959 | TColStd_MapIteratorOfPackedMapOfInteger anIt(GetDataSource()->GetAllNodes()); |
960 | for( ; anIt.More(); anIt.Next() ) |
961 | if( !IsHiddenNode( anIt.Key() ) ) |
962 | aSelNodes.Add( anIt.Key() ); |
963 | |
964 | anIt = TColStd_MapIteratorOfPackedMapOfInteger( GetDataSource()->GetAllElements() ); |
965 | for( ; anIt.More(); anIt.Next() ) |
966 | if( !IsHiddenElem( anIt.Key() ) ) |
967 | aSelElements.Add( anIt.Key() ); |
968 | |
969 | break; |
970 | } |
971 | } |
972 | |
973 | Standard_Boolean IsNeedToRedisplay = Standard_False; |
974 | |
975 | aSelectionPrs->Clear(); |
976 | |
977 | myHilighter->SetDrawer ( mySelectionDrawer ); |
978 | |
979 | if( aSelNodes.Extent()>0 ) |
980 | { |
981 | TColStd_PackedMapOfInteger tmp; |
982 | myHilighter->Build ( aSelectionPrs, aSelNodes, tmp, Standard_False, MeshVS_DMF_SelectionPrs ); |
983 | } |
984 | if( aSelElements.Extent()>0 ) |
985 | { |
986 | TColStd_PackedMapOfInteger tmp; |
987 | myHilighter->Build( aSelectionPrs, aSelElements, tmp, Standard_True, MeshVS_DMF_SelectionPrs ); |
988 | } |
989 | |
990 | myHilighter->SetDrawer ( 0 ); |
991 | |
992 | IsNeedToRedisplay = Standard_True; |
993 | |
c3282ec1 |
994 | aSelectionPrs->SetZLayer (Graphic3d_ZLayerId_Top); |
995 | |
7fd59977 |
996 | if ( IsNeedToRedisplay ) |
997 | { |
998 | aSelectionPrs->SetDisplayPriority(9); |
999 | aSelectionPrs->Display(); |
1000 | } |
1001 | |
0797d9d3 |
1002 | #ifdef OCCT_DEBUG |
7fd59977 |
1003 | Standard_Real sec, cpu; |
1004 | Standard_Integer min, hour; |
1005 | |
1006 | gTimer.Show ( sec, min, hour, cpu ); |
1007 | cout << "HilightSelected : " << endl; |
1008 | cout << aSelNodes.Extent() << " nodes " << endl; |
1009 | cout << aSelElements.Extent() << " elements " << endl; |
1010 | cout << "Time : " << sec << " sec" << endl; |
1011 | cout << "CPU time : " << cpu << " sec" << endl << endl; |
1012 | gTimer.Stop(); |
1013 | #endif |
1014 | } |
1015 | |
1016 | //================================================================ |
1017 | // Function : HilightOwnerWithColor |
1018 | // Purpose : |
1019 | //================================================================ |
1020 | void MeshVS_Mesh::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManager3d)& PM, |
1021 | const Quantity_NameOfColor Color, |
1022 | const Handle(SelectMgr_EntityOwner)& Owner) |
1023 | { |
673cf4e3 |
1024 | if (Owner.IsNull()) |
1025 | return; |
1026 | |
1027 | if (Owner == GlobalSelOwner()) |
1028 | { |
1029 | Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0; |
1030 | PM->Color (this, Color, aHiMode, NULL, Graphic3d_ZLayerId_Top); |
1031 | return; |
1032 | } |
1033 | |
7fd59977 |
1034 | if ( myHilighter.IsNull() ) |
1035 | return; |
1036 | |
7fd59977 |
1037 | Handle( Prs3d_Presentation ) aHilightPrs; |
1038 | aHilightPrs = GetHilightPresentation( PM ); |
1039 | |
1040 | aHilightPrs->Clear(); |
1041 | |
1042 | //new functionality |
1043 | if( HasPresentation() ) |
1044 | aHilightPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); |
1045 | //---------------- |
7fd59977 |
1046 | |
1047 | const Standard_Boolean isMeshEntityOwner = Owner->IsKind ( STANDARD_TYPE ( MeshVS_MeshEntityOwner ) ); |
1048 | const Standard_Boolean isWholeMeshOwner = |
1049 | //agv !Owner.IsNull() && Owner==myWholeMeshOwner; |
1050 | IsWholeMeshOwner (Owner); |
1051 | |
1052 | Standard_Integer aDispMode = MeshVS_DMF_Shading; |
1053 | if ( HasDisplayMode() && ( DisplayMode() & MeshVS_DMF_OCCMask ) > MeshVS_DMF_WireFrame ) |
1054 | aDispMode = ( DisplayMode() & MeshVS_DMF_OCCMask ); |
1055 | //It because we draw hilighted owners only in shading or shrink (not in wireframe) |
1056 | |
1057 | myHilightDrawer->SetColor( MeshVS_DA_InteriorColor, Color ); |
1058 | myHilightDrawer->SetColor( MeshVS_DA_BackInteriorColor, Color ); |
1059 | myHilightDrawer->SetColor( MeshVS_DA_EdgeColor, Color ); |
1060 | myHilightDrawer->SetColor( MeshVS_DA_BeamColor, Color ); |
1061 | myHilightDrawer->SetColor( MeshVS_DA_MarkerColor, Color ); |
1062 | myHilighter->SetDrawer( myHilightDrawer ); |
1063 | |
1064 | if( isMeshEntityOwner ) |
1065 | { |
1066 | Handle ( MeshVS_MeshEntityOwner ) theAISOwner = Handle ( MeshVS_MeshEntityOwner )::DownCast ( Owner ); |
1067 | MeshVS_EntityType aType = theAISOwner->Type(); |
1068 | Standard_Integer anID = theAISOwner->ID(); |
1069 | |
1070 | if ( theAISOwner->IsGroup() ) { |
1071 | MeshVS_EntityType aGroupType; |
1072 | TColStd_PackedMapOfInteger aGroupMap; |
1073 | if ( myDataSource->GetGroup( anID, aGroupType, aGroupMap ) ) { |
1074 | TColStd_PackedMapOfInteger tmp; |
1075 | myHilighter->Build( aHilightPrs, aGroupMap, tmp, aType!=MeshVS_ET_Node, |
1076 | aDispMode | MeshVS_DMF_HilightPrs ); |
1077 | } |
1078 | } |
1079 | else { |
1080 | TColStd_PackedMapOfInteger anOne, tmp; |
1081 | anOne.Add (anID); |
1082 | myHilighter->Build( aHilightPrs, anOne, tmp, aType!=MeshVS_ET_Node, |
1083 | aDispMode | MeshVS_DMF_HilightPrs ); |
1084 | } |
1085 | } |
1086 | else if( isWholeMeshOwner ) |
1087 | { |
1088 | if( ! GetDataSource().IsNull() ) |
1089 | { |
1090 | TColStd_PackedMapOfInteger tmp; |
1091 | myHilighter->Build( aHilightPrs, GetDataSource()->GetAllElements(), tmp, |
1092 | Standard_True, MeshVS_DMF_WireFrame ); |
1093 | } |
1094 | } |
1095 | else |
1096 | { |
1097 | Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( Owner ); |
1098 | if( !aMeshOwner.IsNull() ) |
1099 | { |
1100 | Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetDetectedNodes(); |
1101 | Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetDetectedElements(); |
1102 | // hilight detected entities |
1103 | if( !aNodes.IsNull() ) |
1104 | { |
1105 | TColStd_PackedMapOfInteger tmp; |
1106 | myHilighter->Build( aHilightPrs, aNodes->Map(), tmp, Standard_False, |
1107 | aDispMode | MeshVS_DMF_HilightPrs ); |
1108 | } |
1109 | if( !aElems.IsNull() ) |
1110 | { |
1111 | TColStd_PackedMapOfInteger tmp; |
1112 | myHilighter->Build( aHilightPrs, aElems->Map(), tmp, Standard_True, |
1113 | aDispMode | MeshVS_DMF_HilightPrs ); |
1114 | } |
1115 | } |
1116 | } |
1117 | |
c3282ec1 |
1118 | aHilightPrs->SetZLayer (Graphic3d_ZLayerId_Topmost); |
1119 | |
679ecdee |
1120 | if (PM->IsImmediateModeOn()) |
1121 | { |
1122 | PM->AddToImmediateList (aHilightPrs); |
1123 | } |
7fd59977 |
1124 | myHilighter->SetDrawer ( 0 ); |
1125 | } |
1126 | |
1127 | //======================================================================= |
1128 | //function : ClearSelected |
1129 | //purpose : |
1130 | //======================================================================= |
1131 | void MeshVS_Mesh::ClearSelected () |
1132 | { |
1133 | Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL ); |
1134 | if( !aSelectionPrs.IsNull() ) |
1135 | aSelectionPrs->Clear(); |
1136 | } |
1137 | |
1138 | //======================================================================= |
1139 | //function : FindBuilder |
1140 | //purpose : |
1141 | //======================================================================= |
1142 | Handle (MeshVS_PrsBuilder) MeshVS_Mesh::FindBuilder ( const Standard_CString theTypeName ) const |
1143 | { |
1144 | Standard_Integer len = myBuilders.Length(); |
1145 | Handle(MeshVS_PrsBuilder) aBuilder; |
1146 | Standard_Boolean IsExist = Standard_False; |
1147 | |
1148 | for ( Standard_Integer i=1; i<=len && !IsExist; i++) |
1149 | if ( myBuilders.Value (i)->IsKind ( theTypeName ) ) |
1150 | { |
1151 | aBuilder = myBuilders.Value (i); |
1152 | IsExist = Standard_True; |
1153 | } |
1154 | |
1155 | return aBuilder; |
1156 | } |
1157 | |
1158 | //======================================================================= |
1159 | //function : SetHilighter |
1160 | //purpose : |
1161 | //======================================================================= |
1162 | void MeshVS_Mesh::SetHilighter ( const Handle( MeshVS_PrsBuilder )& Builder ) |
1163 | { |
1164 | myHilighter = Builder; |
1165 | } |
1166 | |
1167 | //======================================================================= |
1168 | //function : SetHilighter |
1169 | //purpose : |
1170 | //======================================================================= |
1171 | Standard_Boolean MeshVS_Mesh::SetHilighter ( const Standard_Integer Index ) |
1172 | { |
1173 | Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( Index ); |
1174 | Standard_Boolean aRes = ( !aBuild.IsNull() ); |
1175 | if ( aRes ) |
1176 | myHilighter = aBuild; |
1177 | return aRes; |
1178 | } |
1179 | |
1180 | //======================================================================= |
1181 | //function : SetHilighter |
1182 | //purpose : |
1183 | //======================================================================= |
1184 | Standard_Boolean MeshVS_Mesh::SetHilighterById ( const Standard_Integer Id ) |
1185 | { |
1186 | Handle( MeshVS_PrsBuilder ) aBuild = GetBuilderById( Id ); |
1187 | Standard_Boolean aRes = ( !aBuild.IsNull() ); |
1188 | if ( aRes ) |
1189 | myHilighter = aBuild; |
1190 | return aRes; |
1191 | } |
1192 | |
1193 | //======================================================================= |
1194 | //function : GetHilighter |
1195 | //purpose : |
1196 | //======================================================================= |
1197 | Handle( MeshVS_PrsBuilder ) MeshVS_Mesh::GetHilighter () const |
1198 | { |
1199 | return myHilighter; |
1200 | } |
1201 | |
1202 | //======================================================================= |
1203 | //function : IsSelectableElem |
1204 | //purpose : |
1205 | //======================================================================= |
1206 | Standard_Boolean MeshVS_Mesh::IsSelectableElem ( const Standard_Integer ID ) const |
1207 | { |
1208 | return ! IsHiddenElem ( ID ); |
1209 | } |
1210 | |
1211 | //======================================================================= |
1212 | //function : IsSelectableNode |
1213 | //purpose : |
1214 | //======================================================================= |
1215 | Standard_Boolean MeshVS_Mesh::IsSelectableNode ( const Standard_Integer ID ) const |
1216 | { |
1217 | return mySelectableNodes.IsNull() ? ! IsHiddenNode ( ID ) : |
1218 | mySelectableNodes->Map().Contains( ID ); |
1219 | } |
1220 | |
1221 | //======================================================================= |
1222 | //function : GetSelectableNodes |
1223 | //purpose : |
1224 | //======================================================================= |
1225 | const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetSelectableNodes () const |
1226 | { |
1227 | return mySelectableNodes; |
1228 | } |
1229 | |
1230 | //======================================================================= |
1231 | //function : SetSelectableNodes |
1232 | //purpose : |
1233 | //======================================================================= |
1234 | void MeshVS_Mesh::SetSelectableNodes ( const Handle(TColStd_HPackedMapOfInteger)& Ids ) |
1235 | { |
1236 | mySelectableNodes = Ids; |
1237 | } |
1238 | |
1239 | //======================================================================= |
1240 | //function : UpdateSelectableNodes |
1241 | //purpose : |
1242 | //======================================================================= |
1243 | void MeshVS_Mesh::UpdateSelectableNodes() |
1244 | { |
1245 | mySelectableNodes = new TColStd_HPackedMapOfInteger; |
1246 | |
1247 | Standard_Integer aMaxFaceNodes; |
1248 | Handle( MeshVS_DataSource ) aSource = GetDataSource(); |
1249 | if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger |
1250 | ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 ) |
1251 | return; |
1252 | |
1253 | // all non-hidden nodes are selectable; |
1254 | // by default (i.e. if myHiddenNodes.IsNull()) all nodes are hidden |
1255 | if ( ! myHiddenNodes.IsNull() ) |
1256 | { |
1257 | mySelectableNodes->ChangeMap().Subtraction (aSource->GetAllNodes(), |
1258 | myHiddenNodes->Map()); |
1259 | } |
1260 | |
1261 | // add all nodes belonging to non-hidden elements |
1262 | TColStd_MapIteratorOfPackedMapOfInteger anIter( aSource->GetAllElements() ); |
1263 | for ( ; anIter.More(); anIter.Next() ) |
1264 | { |
1265 | Standard_Integer aKey = anIter.Key(); |
1266 | if ( IsHiddenElem (aKey) ) |
1267 | continue; |
1268 | |
1269 | MeshVS_Buffer aNodesBuf (aMaxFaceNodes*sizeof(Standard_Integer)); |
1270 | TColStd_Array1OfInteger aNodes (aNodesBuf, 1, aMaxFaceNodes); |
1271 | Standard_Integer NbNodes; |
1272 | if ( !aSource->GetNodesByElement ( aKey, aNodes, NbNodes ) ) |
1273 | continue; |
1274 | for ( Standard_Integer i=1; i<=NbNodes; i++ ) |
1275 | mySelectableNodes->ChangeMap().Add ( aNodes(i) ); |
1276 | } |
1277 | } |
1278 | |
1279 | //======================================================================= |
1280 | //function : GetMeshSelMethod |
1281 | //purpose : |
1282 | //======================================================================= |
1283 | MeshVS_MeshSelectionMethod MeshVS_Mesh::GetMeshSelMethod() const |
1284 | { |
1285 | return mySelectionMethod; |
1286 | } |
1287 | |
1288 | //======================================================================= |
1289 | //function : SetMeshSelMethod |
1290 | //purpose : |
1291 | //======================================================================= |
1292 | void MeshVS_Mesh::SetMeshSelMethod( const MeshVS_MeshSelectionMethod M ) |
1293 | { |
1294 | mySelectionMethod = M; |
1295 | } |
1296 | |
1297 | //======================================================================= |
1298 | //function : IsWholeMeshOwner |
1299 | //purpose : |
1300 | //======================================================================= |
1301 | |
1302 | Standard_Boolean MeshVS_Mesh::IsWholeMeshOwner |
1303 | (const Handle(SelectMgr_EntityOwner)& theOwn) const |
1304 | { |
1305 | return theOwn.IsNull() ? Standard_False : (theOwn == myWholeMeshOwner); |
1306 | } |