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