1 // Created on: 2003-09-09
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <AIS_InteractiveContext.hxx>
18 #include <Aspect_InteriorStyle.hxx>
19 #include <Bnd_Box.hxx>
21 #include <Graphic3d_AspectFillArea3d.hxx>
22 #include <Graphic3d_MaterialAspect.hxx>
23 #include <Graphic3d_NameOfMaterial.hxx>
24 #include <MeshVS_Buffer.hxx>
25 #include <MeshVS_CommonSensitiveEntity.hxx>
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>
40 #include <MeshVS_SensitiveQuad.hxx>
41 #include <OSD_Timer.hxx>
42 #include <Prs3d_LineAspect.hxx>
43 #include <Prs3d_PointAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Prs3d_Root.hxx>
46 #include <Prs3d_ShadingAspect.hxx>
47 #include <PrsMgr_PresentationManager3d.hxx>
48 #include <Select3D_SensitiveBox.hxx>
49 #include <Select3D_SensitiveGroup.hxx>
50 #include <Select3D_SensitivePoint.hxx>
51 #include <Select3D_SensitiveTriangle.hxx>
52 #include <SelectBasics_SensitiveEntity.hxx>
53 #include <SelectMgr_EntityOwner.hxx>
54 #include <SelectMgr_Selection.hxx>
55 #include <SelectMgr_SequenceOfOwner.hxx>
56 #include <Standard_Type.hxx>
57 #include <StdSelect_BRepSelectionTool.hxx>
58 #include <TColgp_Array1OfPnt.hxx>
59 #include <TColStd_Array1OfInteger.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <TColStd_HPackedMapOfInteger.hxx>
62 #include <TColStd_ListIteratorOfListOfInteger.hxx>
63 #include <TColStd_ListIteratorOfListOfReal.hxx>
64 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
67 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_Mesh,AIS_InteractiveObject)
69 //================================================================
70 // Function : Constructor MeshVS_Mesh
72 //================================================================
73 MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped )
75 myDataSource.Nullify();
76 myHilighter.Nullify();
77 myWholeMeshOwner.Nullify();
78 mySelectionMethod = MeshVS_MSM_NODES;
80 SetAutoHilight ( Standard_False );
82 SetDisplayMode( MeshVS_DMF_WireFrame ); // Mode as defaut
83 SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode
85 SetColor ( Quantity_NOC_WHITE );
86 SetMaterial ( Graphic3d_NOM_PLASTIC );
88 myCurrentDrawer = new MeshVS_Drawer();
89 myCurrentDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_BLUE4 );
90 myCurrentDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID );
91 myCurrentDrawer->SetInteger ( MeshVS_DA_MaxFaceNodes, 10 );
92 myCurrentDrawer->SetBoolean ( MeshVS_DA_IsAllowOverlapped, theIsAllowOverlapped );
93 myCurrentDrawer->SetBoolean ( MeshVS_DA_Reflection, Standard_True );
94 myCurrentDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.8 );
95 myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeTime, Standard_False );
96 myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeSelectionTime, Standard_False );
97 myCurrentDrawer->SetBoolean ( MeshVS_DA_DisplayNodes, Standard_True );
98 myCurrentDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 );
99 myCurrentDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID );
100 myCurrentDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_O );
101 myCurrentDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_WHITE );
102 myCurrentDrawer->SetDouble ( MeshVS_DA_MarkerScale, 1.0 );
103 myCurrentDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
104 myCurrentDrawer->SetDouble ( MeshVS_DA_BeamWidth, 1.0 );
105 myCurrentDrawer->SetBoolean ( MeshVS_DA_SmoothShading, Standard_False );
106 myCurrentDrawer->SetBoolean ( MeshVS_DA_SupressBackFaces, Standard_False );
108 mySelectionDrawer = new MeshVS_Drawer();
109 mySelectionDrawer->Assign ( myCurrentDrawer );
110 mySelectionDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR );
111 mySelectionDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 );
112 mySelectionDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 );
114 mySelectionDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 );
115 mySelectionDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
116 mySelectionDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 );
118 myHilightDrawer = new MeshVS_Drawer ();
119 myHilightDrawer->Assign ( myCurrentDrawer );
120 myHilightDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.7 );
121 myHilightDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID );
122 myHilightDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_YELLOW );
123 myHilightDrawer->SetColor ( MeshVS_DA_BackInteriorColor, Quantity_NOC_YELLOW );
124 myHilightDrawer->SetColor ( MeshVS_DA_EdgeColor, Quantity_NOC_GREEN );
125 myHilightDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID );
126 myHilightDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 );
127 myHilightDrawer->SetMaterial ( MeshVS_DA_FrontMaterial, Graphic3d_NOM_PLASTIC );
128 myHilightDrawer->SetMaterial ( MeshVS_DA_BackMaterial, Graphic3d_NOM_PLASTIC );
130 myHilightDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 );
131 myHilightDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
132 myHilightDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 );
134 myHilightDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR );
135 myHilightDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 );
136 myHilightDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 );
139 //================================================================
140 // Function : AcceptDisplayMode
142 //================================================================
143 Standard_Boolean MeshVS_Mesh::AcceptDisplayMode (const Standard_Integer theMode) const
147 return Standard_False;
149 else if (myBuilders.IsEmpty())
151 return Standard_True;
154 for (MeshVS_SequenceOfPrsBuilder::Iterator aBuilderIter (myBuilders); aBuilderIter.More(); aBuilderIter.Next())
156 Handle(MeshVS_PrsBuilder) aBuilder = aBuilderIter.Value();
157 if (!aBuilder.IsNull()
158 && aBuilder->TestFlags (theMode))
160 return Standard_True;
163 return Standard_False;
166 //================================================================
167 // Function : Compute
169 //================================================================
170 void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
171 const Handle(Prs3d_Presentation)& thePresentation,
172 const Standard_Integer theMode )
174 Standard_Boolean toShowComputeTime = Standard_True;
175 myCurrentDrawer->GetBoolean (MeshVS_DA_ComputeTime, toShowComputeTime);
177 if (toShowComputeTime)
183 // Repair Ids in map if necessary
184 Handle( MeshVS_DataSource ) aDS = GetDataSource();
191 const TColStd_PackedMapOfInteger& aNodes = aDS->GetAllNodes();
192 const TColStd_PackedMapOfInteger& aElems = aDS->GetAllElements();
193 const Standard_Boolean hasNodes = !aNodes.IsEmpty();
194 const Standard_Boolean hasElements = !aElems.IsEmpty();
196 TColStd_PackedMapOfInteger aNodesToExclude, aElemsToExclude;
197 for (MeshVS_SequenceOfPrsBuilder::Iterator aBuilderIter (myBuilders); aBuilderIter.More(); aBuilderIter.Next())
199 const Handle(MeshVS_PrsBuilder)& aBuilder = aBuilderIter.Value();
200 if (!aBuilder.IsNull()
201 && aBuilder->TestFlags (theMode))
203 aBuilder->SetPresentationManager (thePrsMgr);
206 aBuilder->Build (thePresentation, aNodes, aNodesToExclude, Standard_False, theMode);
210 aBuilder->Build (thePresentation, aElems, aElemsToExclude, Standard_True, theMode);
215 if (toShowComputeTime)
217 Standard_Real aSec, aCpu;
218 Standard_Integer aMin, anHour;
219 aTimer.Show (aSec, aMin, anHour, aCpu);
220 std::cout << "DisplayMode : " << theMode << "\n";
221 std::cout << "Compute : " << aSec << " sec\n";
222 std::cout << "Compute CPU : " << aCpu << " sec\n\n";
226 //================================================================
227 // Function : scanFacesForSharedNodes
229 //================================================================
230 void MeshVS_Mesh::scanFacesForSharedNodes (const TColStd_PackedMapOfInteger& theAllElements,
231 const Standard_Integer theNbMaxFaceNodes,
232 TColStd_PackedMapOfInteger& theSharedNodes) const
234 theSharedNodes.Clear();
235 MeshVS_EntityType aType;
236 Standard_Integer aNbNodes;
237 MeshVS_Buffer aCoordsBuf (3 * theNbMaxFaceNodes * sizeof (Standard_Real));
238 TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3 * theNbMaxFaceNodes);
239 for (TColStd_MapIteratorOfPackedMapOfInteger aFaceIter (theAllElements); aFaceIter.More(); aFaceIter.Next())
241 const Standard_Integer aFaceIdx = aFaceIter.Key();
243 if (IsSelectableElem (aFaceIdx) &&
244 myDataSource->GetGeomType (aFaceIdx, Standard_True, aType) &&
245 aType == MeshVS_ET_Face)
247 myDataSource->GetGeom (aFaceIdx, Standard_True, aCoords, aNbNodes, aType );
251 MeshVS_Buffer aNodesBuf (aNbNodes * sizeof (Standard_Integer));
252 TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, aNbNodes);
253 if (!myDataSource->GetNodesByElement (aFaceIdx, aElemNodes, aNbNodes))
256 MeshVS_Buffer aFacePntsBuf (aNbNodes * 3 * sizeof (Standard_Real));
257 TColgp_Array1OfPnt aFacePnts (aFacePntsBuf, 1, aNbNodes);
258 for (Standard_Integer aNodeIdx = 1; aNodeIdx <= aNbNodes; ++aNodeIdx)
260 theSharedNodes.Add (aElemNodes (aNodeIdx));
266 //================================================================
267 // Function : ComputeSelection
269 //================================================================
270 void MeshVS_Mesh::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
271 const Standard_Integer theMode)
274 Standard_Boolean toShowComputeSelectionTime = Standard_True;
275 myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, toShowComputeSelectionTime);
276 if (toShowComputeSelectionTime)
282 Standard_Integer aMaxFaceNodes = 0;
283 Handle(MeshVS_DataSource) aSource = GetDataSource();
285 || myCurrentDrawer.IsNull()
286 || !myCurrentDrawer->GetInteger (MeshVS_DA_MaxFaceNodes, aMaxFaceNodes)
287 || aMaxFaceNodes <= 0)
292 const Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode();
293 if (myHilighter.IsNull()
294 || (aMode & MeshVS_DMF_OCCMask) == 0)
299 // Make two array aliases pointing to the same memory:
300 // - TColStd_Array1OfReal for getting values from MeshVS_DataSource interface
301 // - array of gp_Pnt for convenient work with array of points
302 MeshVS_Buffer aCoordsBuf (3 * aMaxFaceNodes * sizeof(Standard_Real));
303 NCollection_Array1<gp_Pnt> aPntArray (aCoordsBuf, 1, aMaxFaceNodes);
304 TColStd_Array1OfReal aPntArrayAsCoordArray (aCoordsBuf, 1, 3 * aMaxFaceNodes);
306 const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes();
307 const TColStd_PackedMapOfInteger& anAllElementsMap = aSource->GetAllElements();
308 if (aSource->IsAdvancedSelectionEnabled())
310 Handle(MeshVS_MeshOwner) anOwner;
311 for (MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt (GetOwnerMaps (Standard_False)); anIt.More(); anIt.Next())
313 anOwner = Handle(MeshVS_MeshOwner)::DownCast (anIt.Value());
314 if (!anOwner.IsNull())
316 // get the owner if it is already created
320 if (anOwner.IsNull())
322 // create one owner for the whole mesh and for all selection modes
323 anOwner = new MeshVS_MeshOwner (this, aSource, 5);
326 // Save the owner. It will be available via GetOwnerMaps method
327 if (!myMeshOwners.IsBound (1))
329 myMeshOwners.Bind (1, anOwner);
331 // Create one sensitive entity. It should detect mesh entities correspondingly to selection mode
332 Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh (anOwner, theMode);
333 theSelection->Add (aSensMesh);
339 case MeshVS_SMF_Node:
341 myNodeOwners.Clear();
342 for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllNodesMap); anIter.More(); anIter.Next())
344 const Standard_Integer aKey = anIter.Key();
345 Standard_Integer aNbNodes = 0;
346 MeshVS_EntityType aType = MeshVS_ET_NONE;
347 if (!myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType))
352 Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_False);
353 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, 5);
354 myNodeOwners.Bind (aKey, anOwner);
355 if (IsSelectableNode (aKey))
357 Handle(Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint (anOwner, aPntArray.First());
358 theSelection->Add (aPoint);
362 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
367 case MeshVS_SMF_Mesh:
369 if (myWholeMeshOwner.IsNull())
371 myWholeMeshOwner = new SelectMgr_EntityOwner (this);
374 switch (mySelectionMethod)
379 BoundingBox (aBndBox);
380 if (!aBndBox.IsVoid())
382 theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, aBndBox));
386 case MeshVS_MSM_NODES:
388 theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_NODES));
391 case MeshVS_MSM_PRECISE:
393 theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_PRECISE));
395 // since MeshVS_Mesh objects can contain free edges and vertices, it is necessary to create
396 // separate sensitive entity for each of them
397 TColStd_PackedMapOfInteger aSharedNodes;
398 scanFacesForSharedNodes (anAllElementsMap, aMaxFaceNodes, aSharedNodes);
400 // create sensitive entities for free edges, if there are any
401 Standard_Integer aNbNodes = 0;
402 MeshVS_EntityType aType = MeshVS_ET_NONE;
403 for (TColStd_MapIteratorOfPackedMapOfInteger anElemIter (anAllElementsMap); anElemIter.More(); anElemIter.Next())
405 const Standard_Integer anElemIdx = anElemIter.Key();
406 if (IsSelectableElem (anElemIdx)
407 && myDataSource->GetGeomType (anElemIdx, Standard_True, aType)
408 && aType == MeshVS_ET_Link)
410 myDataSource->GetGeom (anElemIdx, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
416 MeshVS_Buffer aNodesBuf (aNbNodes * sizeof(Standard_Integer));
417 TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, aNbNodes);
418 if (!myDataSource->GetNodesByElement (anElemIdx, aElemNodes, aNbNodes))
423 MeshVS_Buffer aPntsBuf (aNbNodes * 3 * sizeof(Standard_Real));
424 TColgp_Array1OfPnt aLinkPnts (aPntsBuf, 1, aNbNodes);
425 Standard_Boolean isVertsShared = Standard_True;
426 for (Standard_Integer aPntIdx = 1; aPntIdx <= aNbNodes; ++aPntIdx)
428 aLinkPnts (aPntIdx) = aPntArray.Value (aPntIdx);
429 isVertsShared = isVertsShared && aSharedNodes.Contains (aElemNodes (aPntIdx));
430 aSharedNodes.Add (aElemNodes (aPntIdx));
435 Handle(Select3D_SensitiveEntity) aLinkEnt = new Select3D_SensitiveSegment (myWholeMeshOwner, aLinkPnts.Value (1), aLinkPnts.Value (2));
436 theSelection->Add (aLinkEnt);
441 // create sensitive entities for free nodes, if there are any
442 for (TColStd_MapIteratorOfPackedMapOfInteger aNodesIter (anAllNodesMap); aNodesIter.More(); aNodesIter.Next())
444 const Standard_Integer aNodeIdx = aNodesIter.Key();
445 if (IsSelectableNode (aNodeIdx)
446 && myDataSource->GetGeom (aNodeIdx, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType)
447 && !aSharedNodes.Contains (aNodeIdx))
449 Handle(Select3D_SensitiveEntity) aNodeEnt = new Select3D_SensitivePoint (myWholeMeshOwner, aPntArray.First());
450 theSelection->Add (aNodeEnt);
458 case MeshVS_SMF_Group:
460 myGroupOwners.Clear();
462 TColStd_PackedMapOfInteger anAllGroupsMap;
463 aSource->GetAllGroups (anAllGroupsMap);
465 Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
466 for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllGroupsMap); anIter.More(); anIter.Next())
468 const Standard_Integer aKeyGroup = anIter.Key();
469 MeshVS_EntityType aGroupType = MeshVS_ET_NONE;
470 TColStd_PackedMapOfInteger aGroupMap;
471 if (!myDataSource->GetGroup (aKeyGroup, aGroupType, aGroupMap))
476 Standard_Address anAddr = myDataSource->GetGroupAddr (aKeyGroup);
477 Standard_Integer aPrior = 0;
480 case MeshVS_ET_Volume: aPrior = 1; break;
481 case MeshVS_ET_Face: aPrior = 2; break;
482 case MeshVS_ET_Link: aPrior = 3; break;
483 case MeshVS_ET_0D: aPrior = 4; break;
484 case MeshVS_ET_Node: aPrior = 5; break;
488 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True);
489 myGroupOwners.Bind (aKeyGroup, anOwner);
491 Standard_Boolean added = Standard_False;
492 Standard_Integer aNbNodes = 0;
493 MeshVS_EntityType aType = MeshVS_ET_NONE;
494 for (TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap); anIterMG.More(); anIterMG.Next())
496 Standard_Integer aKey = anIterMG.Key();
497 if (aGroupType == MeshVS_ET_Node)
499 if (myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType)
500 && IsSelectableNode/*!IsHiddenNode*/(aKey))
502 theSelection->Add (new Select3D_SensitivePoint (anOwner, aPntArray.First ()));
503 added = Standard_True;
506 else if (myDataSource->GetGeomType (aKey, Standard_True, aType)
507 && IsSelectableElem/*!IsHiddenElem*/(aKey))
509 myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
510 if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements
512 Handle(Select3D_SensitiveEntity) aSensFace;
515 aSensFace = new Select3D_SensitiveTriangle (anOwner,
516 aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3),
517 Select3D_TOS_INTERIOR);
519 else if (aNbNodes == 4)
521 aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray);
525 aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray);
527 theSelection->Add (aSensFace);
528 added = Standard_True;
530 else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements
532 Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2));
533 theSelection->Add (aSeg);
534 added = Standard_True;
536 else if (aType == MeshVS_ET_Volume
537 && aSource->Get3DGeom (aKey, aNbNodes, aTopo))
539 Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo);
540 theSelection->Add (aPolyhedron);
541 added = Standard_True;
543 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
545 Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey);
548 theSelection->Add (anEnt);
549 added = Standard_True;
556 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
561 default: // all residuary modes
563 Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
564 myElementOwners.Clear();
566 MeshVS_DataMapOfIntegerOwner* aCurMap = &my0DOwners;
567 if (theMode == MeshVS_ET_Link)
569 aCurMap = &myLinkOwners;
571 else if (theMode == MeshVS_ET_Face)
573 aCurMap = &myFaceOwners;
575 else if (theMode == MeshVS_ET_Volume)
577 aCurMap = &myVolumeOwners;
581 Standard_Integer aNbNodes = 0;
582 MeshVS_EntityType aType = MeshVS_ET_NONE;
583 for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap); anIterMV.More(); anIterMV.Next())
585 Standard_Integer aKey = anIterMV.Key();
586 if (myDataSource->GetGeomType (aKey, Standard_True, aType)
589 myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
590 Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_True);
592 Standard_Integer aPrior = 0;
595 case MeshVS_ET_Volume: aPrior = 1; break;
596 case MeshVS_ET_Face: aPrior = 2; break;
597 case MeshVS_ET_Link: aPrior = 3; break;
598 case MeshVS_ET_0D: aPrior = 4; break;
602 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, aPrior);
603 aCurMap->Bind (aKey, anOwner);
604 if (IsSelectableElem (aKey)) // The element is selectable
606 if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements
608 Handle(Select3D_SensitiveEntity) aSensFace;
611 aSensFace = new Select3D_SensitiveTriangle (anOwner,
612 aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3),
613 Select3D_TOS_INTERIOR);
615 else if (aNbNodes == 4)
617 aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray);
621 aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray);
623 theSelection->Add (aSensFace);
625 else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements
627 Handle(MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2));
628 theSelection->Add (aSeg);
630 else if (aType == MeshVS_ET_Volume
631 && aSource->Get3DGeom (aKey, aNbNodes, aTopo))
633 Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo);
634 theSelection->Add (aPolyhedron);
636 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
638 Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey);
641 theSelection->Add (anEnt);
647 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
656 StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
658 if (toShowComputeSelectionTime)
660 Standard_Real sec, cpu;
661 Standard_Integer min, hour;
662 gTimer.Show (sec, min, hour, cpu);
663 std::cout << "SelectionMode : " << theMode << "\n";
664 std::cout << "Compute selection: " << sec << " sec\n";
665 std::cout << "Compute selection CPU : " << cpu << " sec\n\n";
670 //================================================================
671 // Function : GetBuildersCount
673 //================================================================
674 Standard_Integer MeshVS_Mesh::GetBuildersCount () const
676 return myBuilders.Length();
679 //================================================================
680 // Function : GetFreeId
682 //================================================================
683 Standard_Integer MeshVS_Mesh::GetFreeId () const
685 TColStd_PackedMapOfInteger Ids;
686 Standard_Integer i, len = myBuilders.Length(), curId;
688 for ( i=1; i<=len; i++ )
689 Ids.Add( myBuilders.Value(i)->GetId () );
692 while ( Ids.Contains( curId ) )
698 //================================================================
699 // Function : GetBuilder
701 //================================================================
702 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilder ( const Standard_Integer Index ) const
704 if ( Index>=1 && Index<=myBuilders.Length() )
705 return myBuilders.Value( Index );
710 //================================================================
711 // Function : GetBuilderById
713 //================================================================
714 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilderById ( const Standard_Integer Id ) const
716 Handle (MeshVS_PrsBuilder) Result;
718 Standard_Integer i, len = myBuilders.Length();
719 for ( i=1; i<=len; i++ )
720 if ( myBuilders.Value(i)->GetId () == Id )
722 Result = myBuilders.Value(i);
728 //================================================================
729 // Function : AddBuilder
731 //================================================================
732 void MeshVS_Mesh::AddBuilder ( const Handle (MeshVS_PrsBuilder)& theBuilder,
733 const Standard_Boolean TreatAsHilighter )
735 if ( theBuilder.IsNull() )
738 Standard_Integer i, n = myBuilders.Length();
739 for ( i = 1; i<=n; i++ )
740 if ( myBuilders(i)->GetPriority() < theBuilder->GetPriority() )
744 myBuilders.Append ( theBuilder );
746 myBuilders.InsertBefore ( i, theBuilder );
748 if( TreatAsHilighter )
749 myHilighter = theBuilder;
752 //================================================================
753 // Function : RemoveBuilder
755 //================================================================
756 void MeshVS_Mesh::RemoveBuilder ( const Standard_Integer theIndex )
758 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( theIndex );
759 if ( !aBuild.IsNull() )
761 if ( aBuild == myHilighter )
762 myHilighter.Nullify();
763 myBuilders.Remove ( theIndex );
767 //================================================================
768 // Function : RemoveBuilderById
770 //================================================================
771 void MeshVS_Mesh::RemoveBuilderById ( const Standard_Integer Id )
773 Standard_Integer i, n = myBuilders.Length();
774 for ( i=1; i<=n; i++ )
776 Handle( MeshVS_PrsBuilder ) aCur = myBuilders(i);
777 if ( !aCur.IsNull() && aCur->GetId()==Id )
782 if ( GetBuilder( i )==myHilighter )
783 myHilighter.Nullify();
788 //================================================================
789 // Function : SetHiddenElems
791 //================================================================
792 void MeshVS_Mesh::SetHiddenElems ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
794 myHiddenElements = theMap;
796 // Note: update of list of selectable nodes -- this is not optimal!
797 Standard_Boolean AutoSelUpdate = Standard_False;
798 if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) &&
800 UpdateSelectableNodes();
803 //================================================================
804 // Function : SetHiddenNodes
806 //================================================================
807 void MeshVS_Mesh::SetHiddenNodes ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
809 myHiddenNodes = theMap;
811 // Note: update of list of selectable nodes -- this is not optimal!
812 Standard_Boolean AutoSelUpdate = Standard_False;
813 if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) &&
815 UpdateSelectableNodes();
818 //================================================================
819 // Function : GetHiddenElems
821 //================================================================
822 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenElems () const
824 return myHiddenElements;
827 //================================================================
828 // Function : GetHiddenNodes
830 //================================================================
831 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenNodes () const
833 return myHiddenNodes;
836 //================================================================
837 // Function : AddToMap
839 //================================================================
840 void AddToMap ( MeshVS_DataMapOfIntegerOwner& Result, const MeshVS_DataMapOfIntegerOwner& Addition )
842 MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt ( Addition );
843 for ( ; anIt.More(); anIt.Next() )
844 if ( Result.IsBound ( anIt.Key() ) )
845 Result.ChangeFind ( anIt.Key() ) = anIt.Value();
847 Result.Bind( anIt.Key(), anIt.Value() );
850 //================================================================
851 // Function : GetOwnerMaps
853 //================================================================
854 const MeshVS_DataMapOfIntegerOwner& MeshVS_Mesh::GetOwnerMaps ( const Standard_Boolean IsElements )
856 Handle(MeshVS_DataSource) aDS = GetDataSource();
857 if( !aDS.IsNull() && aDS->IsAdvancedSelectionEnabled() )
861 if ( myElementOwners.IsEmpty() )
863 AddToMap ( myElementOwners, my0DOwners );
864 AddToMap ( myElementOwners, myLinkOwners );
865 AddToMap ( myElementOwners, myFaceOwners );
866 AddToMap ( myElementOwners, myVolumeOwners );
868 return myElementOwners;
874 //================================================================
875 // Function : IsHiddenElem
877 //================================================================
878 Standard_Boolean MeshVS_Mesh::IsHiddenElem ( const Standard_Integer theID ) const
880 return ! myHiddenElements.IsNull() && myHiddenElements->Map().Contains( theID );
883 //================================================================
884 // Function : IsHiddenNode
886 //================================================================
887 Standard_Boolean MeshVS_Mesh::IsHiddenNode ( const Standard_Integer theID ) const
889 // note that by default all nodes are hidden
890 return myHiddenNodes.IsNull() || myHiddenNodes->Map().Contains( theID );
893 //================================================================
894 // Function : GetDrawer
896 //================================================================
897 Handle( MeshVS_Drawer ) MeshVS_Mesh::GetDrawer() const
899 return myCurrentDrawer;
902 //================================================================
903 // Function : SetDrawer
905 //================================================================
906 void MeshVS_Mesh::SetDrawer(const Handle(MeshVS_Drawer)& aDrawer)
908 myCurrentDrawer = aDrawer;
911 //================================================================
912 // Function : GetDataSource
914 //================================================================
915 Handle(MeshVS_DataSource) MeshVS_Mesh::GetDataSource() const
920 //================================================================
921 // Function : SetDataSource
923 //================================================================
924 void MeshVS_Mesh::SetDataSource( const Handle(MeshVS_DataSource)& theDataSource )
926 myDataSource = theDataSource;
929 //================================================================
930 // Function : HilightSelected
932 //================================================================
933 void MeshVS_Mesh::HilightSelected ( const Handle(PrsMgr_PresentationManager3d)& thePM,
934 const SelectMgr_SequenceOfOwner& theOwners )
936 if ( myHilighter.IsNull() )
939 // if ( mySelectionPrs.IsNull() )
940 // mySelectionPrs = new Prs3d_Presentation ( thePM->StructureManager() );
944 Handle( Prs3d_Presentation ) aSelectionPrs;
946 aSelectionPrs = GetSelectPresentation( thePM );
948 if( HasPresentation() )
949 aSelectionPrs->SetTransformPersistence (Presentation()->TransformPersistence());
952 // It is very important to call this parent method, because it check whether
953 // mySelectionPrs is created and if not, create it.
961 Standard_Integer len = theOwners.Length(), i;
963 Handle (MeshVS_MeshEntityOwner) anOwner;
964 TColStd_PackedMapOfInteger aSelNodes, aSelElements;
966 for( i=1; i<=len; i++ )
968 if (theOwners.Value (i) == GlobalSelOwner())
970 const Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
971 const Handle(Prs3d_Drawer)& aSelStyle = !HilightAttributes().IsNull() ? HilightAttributes() : GetContext()->SelectionStyle();
972 thePM->Color (this, aSelStyle, aHiMode);
975 anOwner = Handle (MeshVS_MeshEntityOwner)::DownCast ( theOwners.Value ( i ) );
976 if ( !anOwner.IsNull() )
978 // nkv: add support of mesh groups
979 if ( anOwner->IsGroup() ) {
980 MeshVS_EntityType aGroupType;
981 TColStd_PackedMapOfInteger aGroupMap;
982 if ( GetDataSource()->GetGroup( anOwner->ID(), aGroupType, aGroupMap ) ) {
983 if ( aGroupType == MeshVS_ET_Node ) {
984 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
985 if( IsSelectableNode/*!IsHiddenNode*/( anIt.Key() ) )
986 aSelNodes.Add( anIt.Key() );
989 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
990 if( IsSelectableElem/*!IsHiddenElem*/( anIt.Key() ) )
991 aSelElements.Add( anIt.Key() );
996 if( anOwner->Type() == MeshVS_ET_Node )
997 aSelNodes.Add( anOwner->ID() );
999 aSelElements.Add( anOwner->ID() );
1002 else if( GetDataSource()->IsAdvancedSelectionEnabled() )
1004 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwners.Value ( i ) );
1005 if( !aMeshOwner.IsNull() )
1007 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetSelectedNodes();
1008 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetSelectedElements();
1009 if( !aNodes.IsNull() )
1010 aSelNodes.Assign( aNodes->Map() );
1011 if( !aElems.IsNull() )
1012 aSelElements.Assign( aElems->Map() );
1015 //agv else if( theOwners.Value ( i )==myWholeMeshOwner )
1016 else if (IsWholeMeshOwner (theOwners.Value ( i )))
1018 TColStd_MapIteratorOfPackedMapOfInteger anIt(GetDataSource()->GetAllNodes());
1019 for( ; anIt.More(); anIt.Next() )
1020 if( !IsHiddenNode( anIt.Key() ) )
1021 aSelNodes.Add( anIt.Key() );
1023 anIt = TColStd_MapIteratorOfPackedMapOfInteger( GetDataSource()->GetAllElements() );
1024 for( ; anIt.More(); anIt.Next() )
1025 if( !IsHiddenElem( anIt.Key() ) )
1026 aSelElements.Add( anIt.Key() );
1032 Standard_Boolean IsNeedToRedisplay = Standard_False;
1034 aSelectionPrs->Clear();
1036 myHilighter->SetDrawer ( mySelectionDrawer );
1038 if( aSelNodes.Extent()>0 )
1040 TColStd_PackedMapOfInteger tmp;
1041 myHilighter->Build ( aSelectionPrs, aSelNodes, tmp, Standard_False, MeshVS_DMF_SelectionPrs );
1043 if( aSelElements.Extent()>0 )
1045 TColStd_PackedMapOfInteger tmp;
1046 myHilighter->Build( aSelectionPrs, aSelElements, tmp, Standard_True, MeshVS_DMF_SelectionPrs );
1049 myHilighter->SetDrawer ( 0 );
1051 IsNeedToRedisplay = Standard_True;
1053 aSelectionPrs->SetZLayer (Graphic3d_ZLayerId_Top);
1055 if ( IsNeedToRedisplay )
1057 aSelectionPrs->SetDisplayPriority(9);
1058 aSelectionPrs->Display();
1062 Standard_Real sec, cpu;
1063 Standard_Integer min, hour;
1065 gTimer.Show ( sec, min, hour, cpu );
1066 cout << "HilightSelected : " << endl;
1067 cout << aSelNodes.Extent() << " nodes " << endl;
1068 cout << aSelElements.Extent() << " elements " << endl;
1069 cout << "Time : " << sec << " sec" << endl;
1070 cout << "CPU time : " << cpu << " sec" << endl << endl;
1075 //================================================================
1076 // Function : HilightOwnerWithColor
1078 //================================================================
1079 void MeshVS_Mesh::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManager3d)& thePM,
1080 const Handle(Prs3d_Drawer)& theStyle,
1081 const Handle(SelectMgr_EntityOwner)& theOwner)
1083 if (theOwner.IsNull())
1086 const Quantity_Color& aColor = theStyle->Color();
1087 if (theOwner == GlobalSelOwner())
1089 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
1090 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
1094 if ( myHilighter.IsNull() )
1097 Handle( Prs3d_Presentation ) aHilightPrs;
1098 aHilightPrs = GetHilightPresentation( thePM );
1100 aHilightPrs->Clear();
1103 if( HasPresentation() )
1104 aHilightPrs->SetTransformPersistence (Presentation()->TransformPersistence());
1107 const Standard_Boolean isMeshEntityOwner = theOwner->IsKind ( STANDARD_TYPE ( MeshVS_MeshEntityOwner ) );
1108 const Standard_Boolean isWholeMeshOwner =
1109 //agv !Owner.IsNull() && Owner==myWholeMeshOwner;
1110 IsWholeMeshOwner (theOwner);
1112 Standard_Integer aDispMode = MeshVS_DMF_Shading;
1113 if ( HasDisplayMode() && ( DisplayMode() & MeshVS_DMF_OCCMask ) > MeshVS_DMF_WireFrame )
1114 aDispMode = ( DisplayMode() & MeshVS_DMF_OCCMask );
1115 //It because we draw hilighted owners only in shading or shrink (not in wireframe)
1117 myHilightDrawer->SetColor( MeshVS_DA_InteriorColor, aColor );
1118 myHilightDrawer->SetColor( MeshVS_DA_BackInteriorColor, aColor );
1119 myHilightDrawer->SetColor( MeshVS_DA_EdgeColor, aColor );
1120 myHilightDrawer->SetColor( MeshVS_DA_BeamColor, aColor );
1121 myHilightDrawer->SetColor( MeshVS_DA_MarkerColor, aColor );
1122 myHilighter->SetDrawer( myHilightDrawer );
1124 if( isMeshEntityOwner )
1126 Handle ( MeshVS_MeshEntityOwner ) theAISOwner = Handle ( MeshVS_MeshEntityOwner )::DownCast ( theOwner );
1127 MeshVS_EntityType aType = theAISOwner->Type();
1128 Standard_Integer anID = theAISOwner->ID();
1130 if ( theAISOwner->IsGroup() ) {
1131 MeshVS_EntityType aGroupType;
1132 TColStd_PackedMapOfInteger aGroupMap;
1133 if ( myDataSource->GetGroup( anID, aGroupType, aGroupMap ) ) {
1134 TColStd_PackedMapOfInteger tmp;
1135 myHilighter->Build( aHilightPrs, aGroupMap, tmp, aType!=MeshVS_ET_Node,
1136 aDispMode | MeshVS_DMF_HilightPrs );
1140 TColStd_PackedMapOfInteger anOne, tmp;
1142 myHilighter->Build( aHilightPrs, anOne, tmp, aType!=MeshVS_ET_Node,
1143 aDispMode | MeshVS_DMF_HilightPrs );
1146 else if( isWholeMeshOwner )
1148 if( ! GetDataSource().IsNull() )
1150 TColStd_PackedMapOfInteger tmp;
1151 myHilighter->Build( aHilightPrs, GetDataSource()->GetAllElements(), tmp,
1152 Standard_True, MeshVS_DMF_WireFrame );
1157 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwner );
1158 if( !aMeshOwner.IsNull() )
1160 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetDetectedNodes();
1161 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetDetectedElements();
1162 // hilight detected entities
1163 if( !aNodes.IsNull() )
1165 TColStd_PackedMapOfInteger tmp;
1166 myHilighter->Build( aHilightPrs, aNodes->Map(), tmp, Standard_False,
1167 aDispMode | MeshVS_DMF_HilightPrs );
1169 if( !aElems.IsNull() )
1171 TColStd_PackedMapOfInteger tmp;
1172 myHilighter->Build( aHilightPrs, aElems->Map(), tmp, Standard_True,
1173 aDispMode | MeshVS_DMF_HilightPrs );
1178 aHilightPrs->SetZLayer (Graphic3d_ZLayerId_Topmost);
1180 if (thePM->IsImmediateModeOn())
1182 thePM->AddToImmediateList (aHilightPrs);
1184 myHilighter->SetDrawer ( 0 );
1187 //=======================================================================
1188 //function : ClearSelected
1190 //=======================================================================
1191 void MeshVS_Mesh::ClearSelected ()
1193 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );
1194 if( !aSelectionPrs.IsNull() )
1195 aSelectionPrs->Clear();
1198 //=======================================================================
1199 //function : FindBuilder
1201 //=======================================================================
1202 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::FindBuilder ( const Standard_CString theTypeName ) const
1204 Standard_Integer len = myBuilders.Length();
1205 Handle(MeshVS_PrsBuilder) aBuilder;
1206 Standard_Boolean IsExist = Standard_False;
1208 for ( Standard_Integer i=1; i<=len && !IsExist; i++)
1209 if ( myBuilders.Value (i)->IsKind ( theTypeName ) )
1211 aBuilder = myBuilders.Value (i);
1212 IsExist = Standard_True;
1218 //=======================================================================
1219 //function : SetHilighter
1221 //=======================================================================
1222 void MeshVS_Mesh::SetHilighter ( const Handle( MeshVS_PrsBuilder )& Builder )
1224 myHilighter = Builder;
1227 //=======================================================================
1228 //function : SetHilighter
1230 //=======================================================================
1231 Standard_Boolean MeshVS_Mesh::SetHilighter ( const Standard_Integer Index )
1233 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( Index );
1234 Standard_Boolean aRes = ( !aBuild.IsNull() );
1236 myHilighter = aBuild;
1240 //=======================================================================
1241 //function : SetHilighter
1243 //=======================================================================
1244 Standard_Boolean MeshVS_Mesh::SetHilighterById ( const Standard_Integer Id )
1246 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilderById( Id );
1247 Standard_Boolean aRes = ( !aBuild.IsNull() );
1249 myHilighter = aBuild;
1253 //=======================================================================
1254 //function : GetHilighter
1256 //=======================================================================
1257 Handle( MeshVS_PrsBuilder ) MeshVS_Mesh::GetHilighter () const
1262 //=======================================================================
1263 //function : IsSelectableElem
1265 //=======================================================================
1266 Standard_Boolean MeshVS_Mesh::IsSelectableElem ( const Standard_Integer ID ) const
1268 return ! IsHiddenElem ( ID );
1271 //=======================================================================
1272 //function : IsSelectableNode
1274 //=======================================================================
1275 Standard_Boolean MeshVS_Mesh::IsSelectableNode ( const Standard_Integer ID ) const
1277 return mySelectableNodes.IsNull() ? ! IsHiddenNode ( ID ) :
1278 mySelectableNodes->Map().Contains( ID );
1281 //=======================================================================
1282 //function : GetSelectableNodes
1284 //=======================================================================
1285 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetSelectableNodes () const
1287 return mySelectableNodes;
1290 //=======================================================================
1291 //function : SetSelectableNodes
1293 //=======================================================================
1294 void MeshVS_Mesh::SetSelectableNodes ( const Handle(TColStd_HPackedMapOfInteger)& Ids )
1296 mySelectableNodes = Ids;
1299 //=======================================================================
1300 //function : UpdateSelectableNodes
1302 //=======================================================================
1303 void MeshVS_Mesh::UpdateSelectableNodes()
1305 mySelectableNodes = new TColStd_HPackedMapOfInteger;
1307 Standard_Integer aMaxFaceNodes;
1308 Handle( MeshVS_DataSource ) aSource = GetDataSource();
1309 if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger
1310 ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 )
1313 // all non-hidden nodes are selectable;
1314 // by default (i.e. if myHiddenNodes.IsNull()) all nodes are hidden
1315 if ( ! myHiddenNodes.IsNull() )
1317 mySelectableNodes->ChangeMap().Subtraction (aSource->GetAllNodes(),
1318 myHiddenNodes->Map());
1321 // add all nodes belonging to non-hidden elements
1322 TColStd_MapIteratorOfPackedMapOfInteger anIter( aSource->GetAllElements() );
1323 for ( ; anIter.More(); anIter.Next() )
1325 Standard_Integer aKey = anIter.Key();
1326 if ( IsHiddenElem (aKey) )
1329 MeshVS_Buffer aNodesBuf (aMaxFaceNodes*sizeof(Standard_Integer));
1330 TColStd_Array1OfInteger aNodes (aNodesBuf, 1, aMaxFaceNodes);
1331 Standard_Integer NbNodes;
1332 if ( !aSource->GetNodesByElement ( aKey, aNodes, NbNodes ) )
1334 for ( Standard_Integer i=1; i<=NbNodes; i++ )
1335 mySelectableNodes->ChangeMap().Add ( aNodes(i) );
1339 //=======================================================================
1340 //function : GetMeshSelMethod
1342 //=======================================================================
1343 MeshVS_MeshSelectionMethod MeshVS_Mesh::GetMeshSelMethod() const
1345 return mySelectionMethod;
1348 //=======================================================================
1349 //function : SetMeshSelMethod
1351 //=======================================================================
1352 void MeshVS_Mesh::SetMeshSelMethod( const MeshVS_MeshSelectionMethod M )
1354 mySelectionMethod = M;
1357 //=======================================================================
1358 //function : IsWholeMeshOwner
1360 //=======================================================================
1362 Standard_Boolean MeshVS_Mesh::IsWholeMeshOwner
1363 (const Handle(SelectMgr_EntityOwner)& theOwn) const
1365 return theOwn.IsNull() ? Standard_False : (theOwn == myWholeMeshOwner);