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_ModedPresentation.hxx>
48 #include <PrsMgr_PresentationManager3d.hxx>
49 #include <Select3D_SensitiveBox.hxx>
50 #include <Select3D_SensitiveGroup.hxx>
51 #include <Select3D_SensitivePoint.hxx>
52 #include <Select3D_SensitiveTriangle.hxx>
53 #include <SelectBasics_SensitiveEntity.hxx>
54 #include <SelectMgr_EntityOwner.hxx>
55 #include <SelectMgr_Selection.hxx>
56 #include <SelectMgr_SequenceOfOwner.hxx>
57 #include <Standard_Type.hxx>
58 #include <StdSelect_BRepSelectionTool.hxx>
59 #include <TColgp_Array1OfPnt.hxx>
60 #include <TColStd_Array1OfInteger.hxx>
61 #include <TColStd_Array1OfReal.hxx>
62 #include <TColStd_HPackedMapOfInteger.hxx>
63 #include <TColStd_ListIteratorOfListOfInteger.hxx>
64 #include <TColStd_ListIteratorOfListOfReal.hxx>
65 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
66 #include <TColStd_SequenceOfInteger.hxx>
68 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_Mesh,AIS_InteractiveObject)
70 //================================================================
71 // Function : Constructor MeshVS_Mesh
73 //================================================================
74 MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped )
76 myDataSource.Nullify();
77 myHilighter.Nullify();
78 myWholeMeshOwner.Nullify();
79 mySelectionMethod = MeshVS_MSM_NODES;
81 SetAutoHilight ( Standard_False );
83 SetDisplayMode( MeshVS_DMF_WireFrame ); // Mode as defaut
84 SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode
86 SetColor ( Quantity_NOC_WHITE );
87 SetMaterial ( Graphic3d_NOM_PLASTIC );
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 );
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 );
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 );
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 );
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 );
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 );
140 //================================================================
141 // Function : AcceptDisplayMode
143 //================================================================
144 Standard_Boolean MeshVS_Mesh::AcceptDisplayMode (const Standard_Integer theMode) const
148 return Standard_False;
150 else if (myBuilders.IsEmpty())
152 return Standard_True;
155 for (MeshVS_SequenceOfPrsBuilder::Iterator aBuilderIter (myBuilders); aBuilderIter.More(); aBuilderIter.Next())
157 Handle(MeshVS_PrsBuilder) aBuilder = aBuilderIter.Value();
158 if (!aBuilder.IsNull()
159 && aBuilder->TestFlags (theMode))
161 return Standard_True;
164 return Standard_False;
167 //================================================================
168 // Function : Compute
170 //================================================================
171 void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
172 const Handle(Prs3d_Presentation)& thePresentation,
173 const Standard_Integer theMode )
175 Standard_Boolean toShowComputeTime = Standard_True;
176 myCurrentDrawer->GetBoolean (MeshVS_DA_ComputeTime, toShowComputeTime);
178 if (toShowComputeTime)
184 // Repair Ids in map if necessary
185 Handle( MeshVS_DataSource ) aDS = GetDataSource();
192 const TColStd_PackedMapOfInteger& aNodes = aDS->GetAllNodes();
193 const TColStd_PackedMapOfInteger& aElems = aDS->GetAllElements();
194 const Standard_Boolean hasNodes = !aNodes.IsEmpty();
195 const Standard_Boolean hasElements = !aElems.IsEmpty();
197 TColStd_PackedMapOfInteger aNodesToExclude, aElemsToExclude;
198 for (MeshVS_SequenceOfPrsBuilder::Iterator aBuilderIter (myBuilders); aBuilderIter.More(); aBuilderIter.Next())
200 const Handle(MeshVS_PrsBuilder)& aBuilder = aBuilderIter.Value();
201 if (!aBuilder.IsNull()
202 && aBuilder->TestFlags (theMode))
204 aBuilder->SetPresentationManager (thePrsMgr);
207 aBuilder->Build (thePresentation, aNodes, aNodesToExclude, Standard_False, theMode);
211 aBuilder->Build (thePresentation, aElems, aElemsToExclude, Standard_True, theMode);
216 if (toShowComputeTime)
218 Standard_Real aSec, aCpu;
219 Standard_Integer aMin, anHour;
220 aTimer.Show (aSec, aMin, anHour, aCpu);
221 std::cout << "DisplayMode : " << theMode << "\n";
222 std::cout << "Compute : " << aSec << " sec\n";
223 std::cout << "Compute CPU : " << aCpu << " sec\n\n";
227 //================================================================
228 // Function : scanFacesForSharedNodes
230 //================================================================
231 void MeshVS_Mesh::scanFacesForSharedNodes (const TColStd_PackedMapOfInteger& theAllElements,
232 const Standard_Integer theNbMaxFaceNodes,
233 TColStd_PackedMapOfInteger& theSharedNodes) const
235 theSharedNodes.Clear();
236 MeshVS_EntityType aType;
237 Standard_Integer aNbNodes;
238 MeshVS_Buffer aCoordsBuf (3 * theNbMaxFaceNodes * sizeof (Standard_Real));
239 TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3 * theNbMaxFaceNodes);
240 for (TColStd_MapIteratorOfPackedMapOfInteger aFaceIter (theAllElements); aFaceIter.More(); aFaceIter.Next())
242 const Standard_Integer aFaceIdx = aFaceIter.Key();
244 if (IsSelectableElem (aFaceIdx) &&
245 myDataSource->GetGeomType (aFaceIdx, Standard_True, aType) &&
246 aType == MeshVS_ET_Face)
248 myDataSource->GetGeom (aFaceIdx, Standard_True, aCoords, aNbNodes, aType );
252 MeshVS_Buffer aNodesBuf (aNbNodes * sizeof (Standard_Integer));
253 TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, aNbNodes);
254 if (!myDataSource->GetNodesByElement (aFaceIdx, aElemNodes, aNbNodes))
257 MeshVS_Buffer aFacePntsBuf (aNbNodes * 3 * sizeof (Standard_Real));
258 TColgp_Array1OfPnt aFacePnts (aFacePntsBuf, 1, aNbNodes);
259 for (Standard_Integer aNodeIdx = 1; aNodeIdx <= aNbNodes; ++aNodeIdx)
261 theSharedNodes.Add (aElemNodes (aNodeIdx));
267 //================================================================
268 // Function : ComputeSelection
270 //================================================================
271 void MeshVS_Mesh::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
272 const Standard_Integer theMode)
275 Standard_Boolean toShowComputeSelectionTime = Standard_True;
276 myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, toShowComputeSelectionTime);
277 if (toShowComputeSelectionTime)
283 Standard_Integer aMaxFaceNodes = 0;
284 Handle(MeshVS_DataSource) aSource = GetDataSource();
286 || myCurrentDrawer.IsNull()
287 || !myCurrentDrawer->GetInteger (MeshVS_DA_MaxFaceNodes, aMaxFaceNodes)
288 || aMaxFaceNodes <= 0)
293 const Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode();
294 if (myHilighter.IsNull()
295 || (aMode & MeshVS_DMF_OCCMask) == 0)
300 // Make two array aliases pointing to the same memory:
301 // - TColStd_Array1OfReal for getting values from MeshVS_DataSource interface
302 // - array of gp_Pnt for convenient work with array of points
303 MeshVS_Buffer aCoordsBuf (3 * aMaxFaceNodes * sizeof(Standard_Real));
304 NCollection_Array1<gp_Pnt> aPntArray (aCoordsBuf, 1, aMaxFaceNodes);
305 TColStd_Array1OfReal aPntArrayAsCoordArray (aCoordsBuf, 1, 3 * aMaxFaceNodes);
307 const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes();
308 const TColStd_PackedMapOfInteger& anAllElementsMap = aSource->GetAllElements();
309 if (aSource->IsAdvancedSelectionEnabled())
311 Handle(MeshVS_MeshOwner) anOwner;
312 for (MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt (GetOwnerMaps (Standard_False)); anIt.More(); anIt.Next())
314 anOwner = Handle(MeshVS_MeshOwner)::DownCast (anIt.Value());
315 if (!anOwner.IsNull())
317 // get the owner if it is already created
321 if (anOwner.IsNull())
323 // create one owner for the whole mesh and for all selection modes
324 anOwner = new MeshVS_MeshOwner (this, aSource, 5);
327 // Save the owner. It will be available via GetOwnerMaps method
328 if (!myMeshOwners.IsBound (1))
330 myMeshOwners.Bind (1, anOwner);
332 // Create one sensitive entity. It should detect mesh entities correspondingly to selection mode
333 Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh (anOwner, theMode);
334 theSelection->Add (aSensMesh);
340 case MeshVS_SMF_Node:
342 myNodeOwners.Clear();
343 for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllNodesMap); anIter.More(); anIter.Next())
345 const Standard_Integer aKey = anIter.Key();
346 Standard_Integer aNbNodes = 0;
347 MeshVS_EntityType aType = MeshVS_ET_NONE;
348 if (!myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType))
353 Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_False);
354 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, 5);
355 myNodeOwners.Bind (aKey, anOwner);
356 if (IsSelectableNode (aKey))
358 Handle(Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint (anOwner, aPntArray.First());
359 theSelection->Add (aPoint);
363 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
368 case MeshVS_SMF_Mesh:
370 if (myWholeMeshOwner.IsNull())
372 myWholeMeshOwner = new SelectMgr_EntityOwner (this);
375 switch (mySelectionMethod)
380 BoundingBox (aBndBox);
381 if (!aBndBox.IsVoid())
383 theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, aBndBox));
387 case MeshVS_MSM_NODES:
389 theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_NODES));
392 case MeshVS_MSM_PRECISE:
394 theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_PRECISE));
396 // since MeshVS_Mesh objects can contain free edges and vertices, it is necessary to create
397 // separate sensitive entity for each of them
398 TColStd_PackedMapOfInteger aSharedNodes;
399 scanFacesForSharedNodes (anAllElementsMap, aMaxFaceNodes, aSharedNodes);
401 // create sensitive entities for free edges, if there are any
402 Standard_Integer aNbNodes = 0;
403 MeshVS_EntityType aType = MeshVS_ET_NONE;
404 for (TColStd_MapIteratorOfPackedMapOfInteger anElemIter (anAllElementsMap); anElemIter.More(); anElemIter.Next())
406 const Standard_Integer anElemIdx = anElemIter.Key();
407 if (IsSelectableElem (anElemIdx)
408 && myDataSource->GetGeomType (anElemIdx, Standard_True, aType)
409 && aType == MeshVS_ET_Link)
411 myDataSource->GetGeom (anElemIdx, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
417 MeshVS_Buffer aNodesBuf (aNbNodes * sizeof(Standard_Integer));
418 TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, aNbNodes);
419 if (!myDataSource->GetNodesByElement (anElemIdx, aElemNodes, aNbNodes))
424 MeshVS_Buffer aPntsBuf (aNbNodes * 3 * sizeof(Standard_Real));
425 TColgp_Array1OfPnt aLinkPnts (aPntsBuf, 1, aNbNodes);
426 Standard_Boolean isVertsShared = Standard_True;
427 for (Standard_Integer aPntIdx = 1; aPntIdx <= aNbNodes; ++aPntIdx)
429 aLinkPnts (aPntIdx) = aPntArray.Value (aPntIdx);
430 isVertsShared = isVertsShared && aSharedNodes.Contains (aElemNodes (aPntIdx));
431 aSharedNodes.Add (aElemNodes (aPntIdx));
436 Handle(Select3D_SensitiveEntity) aLinkEnt = new Select3D_SensitiveSegment (myWholeMeshOwner, aLinkPnts.Value (1), aLinkPnts.Value (2));
437 theSelection->Add (aLinkEnt);
442 // create sensitive entities for free nodes, if there are any
443 for (TColStd_MapIteratorOfPackedMapOfInteger aNodesIter (anAllNodesMap); aNodesIter.More(); aNodesIter.Next())
445 const Standard_Integer aNodeIdx = aNodesIter.Key();
446 if (IsSelectableNode (aNodeIdx)
447 && myDataSource->GetGeom (aNodeIdx, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType)
448 && !aSharedNodes.Contains (aNodeIdx))
450 Handle(Select3D_SensitiveEntity) aNodeEnt = new Select3D_SensitivePoint (myWholeMeshOwner, aPntArray.First());
451 theSelection->Add (aNodeEnt);
459 case MeshVS_SMF_Group:
461 myGroupOwners.Clear();
463 TColStd_PackedMapOfInteger anAllGroupsMap;
464 aSource->GetAllGroups (anAllGroupsMap);
466 Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
467 for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllGroupsMap); anIter.More(); anIter.Next())
469 const Standard_Integer aKeyGroup = anIter.Key();
470 MeshVS_EntityType aGroupType = MeshVS_ET_NONE;
471 TColStd_PackedMapOfInteger aGroupMap;
472 if (!myDataSource->GetGroup (aKeyGroup, aGroupType, aGroupMap))
477 Standard_Address anAddr = myDataSource->GetGroupAddr (aKeyGroup);
478 Standard_Integer aPrior = 0;
481 case MeshVS_ET_Volume: aPrior = 1; break;
482 case MeshVS_ET_Face: aPrior = 2; break;
483 case MeshVS_ET_Link: aPrior = 3; break;
484 case MeshVS_ET_0D: aPrior = 4; break;
485 case MeshVS_ET_Node: aPrior = 5; break;
489 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True);
490 myGroupOwners.Bind (aKeyGroup, anOwner);
492 Standard_Boolean added = Standard_False;
493 Standard_Integer aNbNodes = 0;
494 MeshVS_EntityType aType = MeshVS_ET_NONE;
495 for (TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap); anIterMG.More(); anIterMG.Next())
497 Standard_Integer aKey = anIterMG.Key();
498 if (aGroupType == MeshVS_ET_Node)
500 if (myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType)
501 && IsSelectableNode/*!IsHiddenNode*/(aKey))
503 theSelection->Add (new Select3D_SensitivePoint (anOwner, aPntArray.First ()));
504 added = Standard_True;
507 else if (myDataSource->GetGeomType (aKey, Standard_True, aType)
508 && IsSelectableElem/*!IsHiddenElem*/(aKey))
510 myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
511 if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements
513 Handle(Select3D_SensitiveEntity) aSensFace;
516 aSensFace = new Select3D_SensitiveTriangle (anOwner,
517 aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3),
518 Select3D_TOS_INTERIOR);
520 else if (aNbNodes == 4)
522 aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray);
526 aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray);
528 theSelection->Add (aSensFace);
529 added = Standard_True;
531 else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements
533 Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2));
534 theSelection->Add (aSeg);
535 added = Standard_True;
537 else if (aType == MeshVS_ET_Volume
538 && aSource->Get3DGeom (aKey, aNbNodes, aTopo))
540 Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo);
541 theSelection->Add (aPolyhedron);
542 added = Standard_True;
544 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
546 Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey);
549 theSelection->Add (anEnt);
550 added = Standard_True;
557 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
562 default: // all residuary modes
564 Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
565 myElementOwners.Clear();
567 MeshVS_DataMapOfIntegerOwner* aCurMap = &my0DOwners;
568 if (theMode == MeshVS_ET_Link)
570 aCurMap = &myLinkOwners;
572 else if (theMode == MeshVS_ET_Face)
574 aCurMap = &myFaceOwners;
576 else if (theMode == MeshVS_ET_Volume)
578 aCurMap = &myVolumeOwners;
582 Standard_Integer aNbNodes = 0;
583 MeshVS_EntityType aType = MeshVS_ET_NONE;
584 for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap); anIterMV.More(); anIterMV.Next())
586 Standard_Integer aKey = anIterMV.Key();
587 if (myDataSource->GetGeomType (aKey, Standard_True, aType)
590 myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType);
591 Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_True);
593 Standard_Integer aPrior = 0;
596 case MeshVS_ET_Volume: aPrior = 1; break;
597 case MeshVS_ET_Face: aPrior = 2; break;
598 case MeshVS_ET_Link: aPrior = 3; break;
599 case MeshVS_ET_0D: aPrior = 4; break;
603 Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, aPrior);
604 aCurMap->Bind (aKey, anOwner);
605 if (IsSelectableElem (aKey)) // The element is selectable
607 if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements
609 Handle(Select3D_SensitiveEntity) aSensFace;
612 aSensFace = new Select3D_SensitiveTriangle (anOwner,
613 aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3),
614 Select3D_TOS_INTERIOR);
616 else if (aNbNodes == 4)
618 aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray);
622 aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray);
624 theSelection->Add (aSensFace);
626 else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements
628 Handle(MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2));
629 theSelection->Add (aSeg);
631 else if (aType == MeshVS_ET_Volume
632 && aSource->Get3DGeom (aKey, aNbNodes, aTopo))
634 Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo);
635 theSelection->Add (aPolyhedron);
637 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
639 Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey);
642 theSelection->Add (anEnt);
648 theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner));
657 StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
659 if (toShowComputeSelectionTime)
661 Standard_Real sec, cpu;
662 Standard_Integer min, hour;
663 gTimer.Show (sec, min, hour, cpu);
664 std::cout << "SelectionMode : " << theMode << "\n";
665 std::cout << "Compute selection: " << sec << " sec\n";
666 std::cout << "Compute selection CPU : " << cpu << " sec\n\n";
671 //================================================================
672 // Function : GetBuildersCount
674 //================================================================
675 Standard_Integer MeshVS_Mesh::GetBuildersCount () const
677 return myBuilders.Length();
680 //================================================================
681 // Function : GetFreeId
683 //================================================================
684 Standard_Integer MeshVS_Mesh::GetFreeId () const
686 TColStd_PackedMapOfInteger Ids;
687 Standard_Integer i, len = myBuilders.Length(), curId;
689 for ( i=1; i<=len; i++ )
690 Ids.Add( myBuilders.Value(i)->GetId () );
693 while ( Ids.Contains( curId ) )
699 //================================================================
700 // Function : GetBuilder
702 //================================================================
703 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilder ( const Standard_Integer Index ) const
705 if ( Index>=1 && Index<=myBuilders.Length() )
706 return myBuilders.Value( Index );
711 //================================================================
712 // Function : GetBuilderById
714 //================================================================
715 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilderById ( const Standard_Integer Id ) const
717 Handle (MeshVS_PrsBuilder) Result;
719 Standard_Integer i, len = myBuilders.Length();
720 for ( i=1; i<=len; i++ )
721 if ( myBuilders.Value(i)->GetId () == Id )
723 Result = myBuilders.Value(i);
729 //================================================================
730 // Function : AddBuilder
732 //================================================================
733 void MeshVS_Mesh::AddBuilder ( const Handle (MeshVS_PrsBuilder)& theBuilder,
734 const Standard_Boolean TreatAsHilighter )
736 if ( theBuilder.IsNull() )
739 Standard_Integer i, n = myBuilders.Length();
740 for ( i = 1; i<=n; i++ )
741 if ( myBuilders(i)->GetPriority() < theBuilder->GetPriority() )
745 myBuilders.Append ( theBuilder );
747 myBuilders.InsertBefore ( i, theBuilder );
749 if( TreatAsHilighter )
750 myHilighter = theBuilder;
753 //================================================================
754 // Function : RemoveBuilder
756 //================================================================
757 void MeshVS_Mesh::RemoveBuilder ( const Standard_Integer theIndex )
759 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( theIndex );
760 if ( !aBuild.IsNull() )
762 if ( aBuild == myHilighter )
763 myHilighter.Nullify();
764 myBuilders.Remove ( theIndex );
768 //================================================================
769 // Function : RemoveBuilderById
771 //================================================================
772 void MeshVS_Mesh::RemoveBuilderById ( const Standard_Integer Id )
774 Standard_Integer i, n = myBuilders.Length();
775 for ( i=1; i<=n; i++ )
777 Handle( MeshVS_PrsBuilder ) aCur = myBuilders(i);
778 if ( !aCur.IsNull() && aCur->GetId()==Id )
783 if ( GetBuilder( i )==myHilighter )
784 myHilighter.Nullify();
789 //================================================================
790 // Function : SetHiddenElems
792 //================================================================
793 void MeshVS_Mesh::SetHiddenElems ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
795 myHiddenElements = theMap;
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 ) &&
801 UpdateSelectableNodes();
804 //================================================================
805 // Function : SetHiddenNodes
807 //================================================================
808 void MeshVS_Mesh::SetHiddenNodes ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
810 myHiddenNodes = theMap;
812 // Note: update of list of selectable nodes -- this is not optimal!
813 Standard_Boolean AutoSelUpdate = Standard_False;
814 if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) &&
816 UpdateSelectableNodes();
819 //================================================================
820 // Function : GetHiddenElems
822 //================================================================
823 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenElems () const
825 return myHiddenElements;
828 //================================================================
829 // Function : GetHiddenNodes
831 //================================================================
832 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenNodes () const
834 return myHiddenNodes;
837 //================================================================
838 // Function : AddToMap
840 //================================================================
841 void AddToMap ( MeshVS_DataMapOfIntegerOwner& Result, const MeshVS_DataMapOfIntegerOwner& Addition )
843 MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt ( Addition );
844 for ( ; anIt.More(); anIt.Next() )
845 if ( Result.IsBound ( anIt.Key() ) )
846 Result.ChangeFind ( anIt.Key() ) = anIt.Value();
848 Result.Bind( anIt.Key(), anIt.Value() );
851 //================================================================
852 // Function : GetOwnerMaps
854 //================================================================
855 const MeshVS_DataMapOfIntegerOwner& MeshVS_Mesh::GetOwnerMaps ( const Standard_Boolean IsElements )
857 Handle(MeshVS_DataSource) aDS = GetDataSource();
858 if( !aDS.IsNull() && aDS->IsAdvancedSelectionEnabled() )
862 if ( myElementOwners.IsEmpty() )
864 AddToMap ( myElementOwners, my0DOwners );
865 AddToMap ( myElementOwners, myLinkOwners );
866 AddToMap ( myElementOwners, myFaceOwners );
867 AddToMap ( myElementOwners, myVolumeOwners );
869 return myElementOwners;
875 //================================================================
876 // Function : IsHiddenElem
878 //================================================================
879 Standard_Boolean MeshVS_Mesh::IsHiddenElem ( const Standard_Integer theID ) const
881 return ! myHiddenElements.IsNull() && myHiddenElements->Map().Contains( theID );
884 //================================================================
885 // Function : IsHiddenNode
887 //================================================================
888 Standard_Boolean MeshVS_Mesh::IsHiddenNode ( const Standard_Integer theID ) const
890 // note that by default all nodes are hidden
891 return myHiddenNodes.IsNull() || myHiddenNodes->Map().Contains( theID );
894 //================================================================
895 // Function : GetDrawer
897 //================================================================
898 Handle( MeshVS_Drawer ) MeshVS_Mesh::GetDrawer() const
900 return myCurrentDrawer;
903 //================================================================
904 // Function : SetDrawer
906 //================================================================
907 void MeshVS_Mesh::SetDrawer(const Handle(MeshVS_Drawer)& aDrawer)
909 myCurrentDrawer = aDrawer;
912 //================================================================
913 // Function : GetDataSource
915 //================================================================
916 Handle(MeshVS_DataSource) MeshVS_Mesh::GetDataSource() const
921 //================================================================
922 // Function : SetDataSource
924 //================================================================
925 void MeshVS_Mesh::SetDataSource( const Handle(MeshVS_DataSource)& theDataSource )
927 myDataSource = theDataSource;
930 //================================================================
931 // Function : HilightSelected
933 //================================================================
934 void MeshVS_Mesh::HilightSelected ( const Handle(PrsMgr_PresentationManager3d)& thePM,
935 const SelectMgr_SequenceOfOwner& theOwners )
937 if ( myHilighter.IsNull() )
940 // if ( mySelectionPrs.IsNull() )
941 // mySelectionPrs = new Prs3d_Presentation ( thePM->StructureManager() );
945 Handle( Prs3d_Presentation ) aSelectionPrs;
947 aSelectionPrs = GetSelectPresentation( thePM );
949 if( HasPresentation() )
950 aSelectionPrs->SetTransformPersistence (Presentation()->TransformPersistence());
953 // It is very important to call this parent method, because it check whether
954 // mySelectionPrs is created and if not, create it.
962 Standard_Integer len = theOwners.Length(), i;
964 Handle (MeshVS_MeshEntityOwner) anOwner;
965 TColStd_PackedMapOfInteger aSelNodes, aSelElements;
967 for( i=1; i<=len; i++ )
969 if (theOwners.Value (i) == GlobalSelOwner())
971 const Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
972 const Handle(Prs3d_Drawer)& aSelStyle = !HilightAttributes().IsNull() ? HilightAttributes() : GetContext()->SelectionStyle();
973 thePM->Color (this, aSelStyle, aHiMode);
976 anOwner = Handle (MeshVS_MeshEntityOwner)::DownCast ( theOwners.Value ( i ) );
977 if ( !anOwner.IsNull() )
979 // nkv: add support of mesh groups
980 if ( anOwner->IsGroup() ) {
981 MeshVS_EntityType aGroupType;
982 TColStd_PackedMapOfInteger aGroupMap;
983 if ( GetDataSource()->GetGroup( anOwner->ID(), aGroupType, aGroupMap ) ) {
984 if ( aGroupType == MeshVS_ET_Node ) {
985 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
986 if( IsSelectableNode/*!IsHiddenNode*/( anIt.Key() ) )
987 aSelNodes.Add( anIt.Key() );
990 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
991 if( IsSelectableElem/*!IsHiddenElem*/( anIt.Key() ) )
992 aSelElements.Add( anIt.Key() );
997 if( anOwner->Type() == MeshVS_ET_Node )
998 aSelNodes.Add( anOwner->ID() );
1000 aSelElements.Add( anOwner->ID() );
1003 else if( GetDataSource()->IsAdvancedSelectionEnabled() )
1005 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwners.Value ( i ) );
1006 if( !aMeshOwner.IsNull() )
1008 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetSelectedNodes();
1009 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetSelectedElements();
1010 if( !aNodes.IsNull() )
1011 aSelNodes.Assign( aNodes->Map() );
1012 if( !aElems.IsNull() )
1013 aSelElements.Assign( aElems->Map() );
1016 //agv else if( theOwners.Value ( i )==myWholeMeshOwner )
1017 else if (IsWholeMeshOwner (theOwners.Value ( i )))
1019 TColStd_MapIteratorOfPackedMapOfInteger anIt(GetDataSource()->GetAllNodes());
1020 for( ; anIt.More(); anIt.Next() )
1021 if( !IsHiddenNode( anIt.Key() ) )
1022 aSelNodes.Add( anIt.Key() );
1024 anIt = TColStd_MapIteratorOfPackedMapOfInteger( GetDataSource()->GetAllElements() );
1025 for( ; anIt.More(); anIt.Next() )
1026 if( !IsHiddenElem( anIt.Key() ) )
1027 aSelElements.Add( anIt.Key() );
1033 Standard_Boolean IsNeedToRedisplay = Standard_False;
1035 aSelectionPrs->Clear();
1037 myHilighter->SetDrawer ( mySelectionDrawer );
1039 if( aSelNodes.Extent()>0 )
1041 TColStd_PackedMapOfInteger tmp;
1042 myHilighter->Build ( aSelectionPrs, aSelNodes, tmp, Standard_False, MeshVS_DMF_SelectionPrs );
1044 if( aSelElements.Extent()>0 )
1046 TColStd_PackedMapOfInteger tmp;
1047 myHilighter->Build( aSelectionPrs, aSelElements, tmp, Standard_True, MeshVS_DMF_SelectionPrs );
1050 myHilighter->SetDrawer ( 0 );
1052 IsNeedToRedisplay = Standard_True;
1054 aSelectionPrs->SetZLayer (Graphic3d_ZLayerId_Top);
1056 if ( IsNeedToRedisplay )
1058 aSelectionPrs->SetDisplayPriority(9);
1059 aSelectionPrs->Display();
1063 Standard_Real sec, cpu;
1064 Standard_Integer min, hour;
1066 gTimer.Show ( sec, min, hour, cpu );
1067 cout << "HilightSelected : " << endl;
1068 cout << aSelNodes.Extent() << " nodes " << endl;
1069 cout << aSelElements.Extent() << " elements " << endl;
1070 cout << "Time : " << sec << " sec" << endl;
1071 cout << "CPU time : " << cpu << " sec" << endl << endl;
1076 //================================================================
1077 // Function : HilightOwnerWithColor
1079 //================================================================
1080 void MeshVS_Mesh::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManager3d)& thePM,
1081 const Handle(Prs3d_Drawer)& theStyle,
1082 const Handle(SelectMgr_EntityOwner)& theOwner)
1084 if (theOwner.IsNull())
1087 const Quantity_Color& aColor = theStyle->Color();
1088 if (theOwner == GlobalSelOwner())
1090 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
1091 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
1095 if ( myHilighter.IsNull() )
1098 Handle( Prs3d_Presentation ) aHilightPrs;
1099 aHilightPrs = GetHilightPresentation( thePM );
1101 aHilightPrs->Clear();
1104 if( HasPresentation() )
1105 aHilightPrs->SetTransformPersistence (Presentation()->TransformPersistence());
1108 const Standard_Boolean isMeshEntityOwner = theOwner->IsKind ( STANDARD_TYPE ( MeshVS_MeshEntityOwner ) );
1109 const Standard_Boolean isWholeMeshOwner =
1110 //agv !Owner.IsNull() && Owner==myWholeMeshOwner;
1111 IsWholeMeshOwner (theOwner);
1113 Standard_Integer aDispMode = MeshVS_DMF_Shading;
1114 if ( HasDisplayMode() && ( DisplayMode() & MeshVS_DMF_OCCMask ) > MeshVS_DMF_WireFrame )
1115 aDispMode = ( DisplayMode() & MeshVS_DMF_OCCMask );
1116 //It because we draw hilighted owners only in shading or shrink (not in wireframe)
1118 myHilightDrawer->SetColor( MeshVS_DA_InteriorColor, aColor );
1119 myHilightDrawer->SetColor( MeshVS_DA_BackInteriorColor, aColor );
1120 myHilightDrawer->SetColor( MeshVS_DA_EdgeColor, aColor );
1121 myHilightDrawer->SetColor( MeshVS_DA_BeamColor, aColor );
1122 myHilightDrawer->SetColor( MeshVS_DA_MarkerColor, aColor );
1123 myHilighter->SetDrawer( myHilightDrawer );
1125 if( isMeshEntityOwner )
1127 Handle ( MeshVS_MeshEntityOwner ) theAISOwner = Handle ( MeshVS_MeshEntityOwner )::DownCast ( theOwner );
1128 MeshVS_EntityType aType = theAISOwner->Type();
1129 Standard_Integer anID = theAISOwner->ID();
1131 if ( theAISOwner->IsGroup() ) {
1132 MeshVS_EntityType aGroupType;
1133 TColStd_PackedMapOfInteger aGroupMap;
1134 if ( myDataSource->GetGroup( anID, aGroupType, aGroupMap ) ) {
1135 TColStd_PackedMapOfInteger tmp;
1136 myHilighter->Build( aHilightPrs, aGroupMap, tmp, aType!=MeshVS_ET_Node,
1137 aDispMode | MeshVS_DMF_HilightPrs );
1141 TColStd_PackedMapOfInteger anOne, tmp;
1143 myHilighter->Build( aHilightPrs, anOne, tmp, aType!=MeshVS_ET_Node,
1144 aDispMode | MeshVS_DMF_HilightPrs );
1147 else if( isWholeMeshOwner )
1149 if( ! GetDataSource().IsNull() )
1151 TColStd_PackedMapOfInteger tmp;
1152 myHilighter->Build( aHilightPrs, GetDataSource()->GetAllElements(), tmp,
1153 Standard_True, MeshVS_DMF_WireFrame );
1158 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwner );
1159 if( !aMeshOwner.IsNull() )
1161 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetDetectedNodes();
1162 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetDetectedElements();
1163 // hilight detected entities
1164 if( !aNodes.IsNull() )
1166 TColStd_PackedMapOfInteger tmp;
1167 myHilighter->Build( aHilightPrs, aNodes->Map(), tmp, Standard_False,
1168 aDispMode | MeshVS_DMF_HilightPrs );
1170 if( !aElems.IsNull() )
1172 TColStd_PackedMapOfInteger tmp;
1173 myHilighter->Build( aHilightPrs, aElems->Map(), tmp, Standard_True,
1174 aDispMode | MeshVS_DMF_HilightPrs );
1179 aHilightPrs->SetZLayer (Graphic3d_ZLayerId_Topmost);
1181 if (thePM->IsImmediateModeOn())
1183 thePM->AddToImmediateList (aHilightPrs);
1185 myHilighter->SetDrawer ( 0 );
1188 //=======================================================================
1189 //function : ClearSelected
1191 //=======================================================================
1192 void MeshVS_Mesh::ClearSelected ()
1194 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );
1195 if( !aSelectionPrs.IsNull() )
1196 aSelectionPrs->Clear();
1199 //=======================================================================
1200 //function : FindBuilder
1202 //=======================================================================
1203 Handle (MeshVS_PrsBuilder) MeshVS_Mesh::FindBuilder ( const Standard_CString theTypeName ) const
1205 Standard_Integer len = myBuilders.Length();
1206 Handle(MeshVS_PrsBuilder) aBuilder;
1207 Standard_Boolean IsExist = Standard_False;
1209 for ( Standard_Integer i=1; i<=len && !IsExist; i++)
1210 if ( myBuilders.Value (i)->IsKind ( theTypeName ) )
1212 aBuilder = myBuilders.Value (i);
1213 IsExist = Standard_True;
1219 //=======================================================================
1220 //function : SetHilighter
1222 //=======================================================================
1223 void MeshVS_Mesh::SetHilighter ( const Handle( MeshVS_PrsBuilder )& Builder )
1225 myHilighter = Builder;
1228 //=======================================================================
1229 //function : SetHilighter
1231 //=======================================================================
1232 Standard_Boolean MeshVS_Mesh::SetHilighter ( const Standard_Integer Index )
1234 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( Index );
1235 Standard_Boolean aRes = ( !aBuild.IsNull() );
1237 myHilighter = aBuild;
1241 //=======================================================================
1242 //function : SetHilighter
1244 //=======================================================================
1245 Standard_Boolean MeshVS_Mesh::SetHilighterById ( const Standard_Integer Id )
1247 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilderById( Id );
1248 Standard_Boolean aRes = ( !aBuild.IsNull() );
1250 myHilighter = aBuild;
1254 //=======================================================================
1255 //function : GetHilighter
1257 //=======================================================================
1258 Handle( MeshVS_PrsBuilder ) MeshVS_Mesh::GetHilighter () const
1263 //=======================================================================
1264 //function : IsSelectableElem
1266 //=======================================================================
1267 Standard_Boolean MeshVS_Mesh::IsSelectableElem ( const Standard_Integer ID ) const
1269 return ! IsHiddenElem ( ID );
1272 //=======================================================================
1273 //function : IsSelectableNode
1275 //=======================================================================
1276 Standard_Boolean MeshVS_Mesh::IsSelectableNode ( const Standard_Integer ID ) const
1278 return mySelectableNodes.IsNull() ? ! IsHiddenNode ( ID ) :
1279 mySelectableNodes->Map().Contains( ID );
1282 //=======================================================================
1283 //function : GetSelectableNodes
1285 //=======================================================================
1286 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetSelectableNodes () const
1288 return mySelectableNodes;
1291 //=======================================================================
1292 //function : SetSelectableNodes
1294 //=======================================================================
1295 void MeshVS_Mesh::SetSelectableNodes ( const Handle(TColStd_HPackedMapOfInteger)& Ids )
1297 mySelectableNodes = Ids;
1300 //=======================================================================
1301 //function : UpdateSelectableNodes
1303 //=======================================================================
1304 void MeshVS_Mesh::UpdateSelectableNodes()
1306 mySelectableNodes = new TColStd_HPackedMapOfInteger;
1308 Standard_Integer aMaxFaceNodes;
1309 Handle( MeshVS_DataSource ) aSource = GetDataSource();
1310 if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger
1311 ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 )
1314 // all non-hidden nodes are selectable;
1315 // by default (i.e. if myHiddenNodes.IsNull()) all nodes are hidden
1316 if ( ! myHiddenNodes.IsNull() )
1318 mySelectableNodes->ChangeMap().Subtraction (aSource->GetAllNodes(),
1319 myHiddenNodes->Map());
1322 // add all nodes belonging to non-hidden elements
1323 TColStd_MapIteratorOfPackedMapOfInteger anIter( aSource->GetAllElements() );
1324 for ( ; anIter.More(); anIter.Next() )
1326 Standard_Integer aKey = anIter.Key();
1327 if ( IsHiddenElem (aKey) )
1330 MeshVS_Buffer aNodesBuf (aMaxFaceNodes*sizeof(Standard_Integer));
1331 TColStd_Array1OfInteger aNodes (aNodesBuf, 1, aMaxFaceNodes);
1332 Standard_Integer NbNodes;
1333 if ( !aSource->GetNodesByElement ( aKey, aNodes, NbNodes ) )
1335 for ( Standard_Integer i=1; i<=NbNodes; i++ )
1336 mySelectableNodes->ChangeMap().Add ( aNodes(i) );
1340 //=======================================================================
1341 //function : GetMeshSelMethod
1343 //=======================================================================
1344 MeshVS_MeshSelectionMethod MeshVS_Mesh::GetMeshSelMethod() const
1346 return mySelectionMethod;
1349 //=======================================================================
1350 //function : SetMeshSelMethod
1352 //=======================================================================
1353 void MeshVS_Mesh::SetMeshSelMethod( const MeshVS_MeshSelectionMethod M )
1355 mySelectionMethod = M;
1358 //=======================================================================
1359 //function : IsWholeMeshOwner
1361 //=======================================================================
1363 Standard_Boolean MeshVS_Mesh::IsWholeMeshOwner
1364 (const Handle(SelectMgr_EntityOwner)& theOwn) const
1366 return theOwn.IsNull() ? Standard_False : (theOwn == myWholeMeshOwner);