From 022d142b242cb27cc99dd62c4a5193a16697737b Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 13 Sep 2017 17:12:57 +0200 Subject: [PATCH] 0029158: Visualization - suspicious pass-through of case labels in switch statements MeshVS_Mesh::ComputeSelection() - fixed incorrect fall-through from MeshVS_SMF_Mesh to MeshVS_SMF_Group. --- src/MeshVS/MeshVS_Mesh.cxx | 572 ++++++++++++++++++------------------- 1 file changed, 282 insertions(+), 290 deletions(-) diff --git a/src/MeshVS/MeshVS_Mesh.cxx b/src/MeshVS/MeshVS_Mesh.cxx index 372c53d0db..59b28e51fc 100644 --- a/src/MeshVS/MeshVS_Mesh.cxx +++ b/src/MeshVS/MeshVS_Mesh.cxx @@ -242,410 +242,402 @@ void MeshVS_Mesh::scanFacesForSharedNodes (const TColStd_PackedMapOfInteger& the // Function : ComputeSelection // Purpose : //================================================================ -void MeshVS_Mesh::ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, - const Standard_Integer theMode ) +void MeshVS_Mesh::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, + const Standard_Integer theMode) { OSD_Timer gTimer; - - Standard_Boolean ShowComputeSelectionTime = Standard_True; - myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, ShowComputeSelectionTime ); - - if ( ShowComputeSelectionTime ) + Standard_Boolean toShowComputeSelectionTime = Standard_True; + myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, toShowComputeSelectionTime); + if (toShowComputeSelectionTime) { gTimer.Reset(); gTimer.Start(); } - Standard_Integer aMaxFaceNodes; - Handle( MeshVS_DataSource ) aSource = GetDataSource(); - - if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger - ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 ) + Standard_Integer aMaxFaceNodes = 0; + Handle(MeshVS_DataSource) aSource = GetDataSource(); + if (aSource.IsNull() + || myCurrentDrawer.IsNull() + || !myCurrentDrawer->GetInteger (MeshVS_DA_MaxFaceNodes, aMaxFaceNodes) + || aMaxFaceNodes <= 0) + { return; - - MeshVS_Buffer aCoordsBuf (3*aMaxFaceNodes*sizeof(Standard_Real)); - TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3*aMaxFaceNodes); - Standard_Integer NbNodes; - - MeshVS_EntityType aType; - Standard_Address anAddr; - TColStd_MapIteratorOfPackedMapOfInteger anIter; - Standard_Real x, y, z; - - Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode(); - if ( myHilighter.IsNull() || ( aMode & MeshVS_DMF_OCCMask ) == 0 ) - return; - const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes(); - const TColStd_PackedMapOfInteger& anAllElementsMap= aSource->GetAllElements(); -//agv Standard_Integer i; - - // skt: advanced mesh selection - if( aSource->IsAdvancedSelectionEnabled() ) { - Handle(MeshVS_MeshOwner) anOwner; - // Get the owner if it is already created - MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt( GetOwnerMaps( Standard_False ) ); - for( ; anIt.More(); anIt.Next() ) - { - anOwner = Handle(MeshVS_MeshOwner)::DownCast( anIt.Value() ); - // clear selected entities - if( !anOwner.IsNull() ) - break; - } - if( anOwner.IsNull() ) - // Create one owner for the whole mesh and for all selection modes - anOwner = new MeshVS_MeshOwner( this, aSource, 5 ); - // Save the owner. It will be available via GetOwnerMaps method - if( !myMeshOwners.IsBound( 1 ) ) - myMeshOwners.Bind( 1, anOwner ); - // Create one sensitive entity. It should detect mesh entities correspondingly - // to selection mode - Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh( anOwner, theMode ); - theSelection->Add ( aSensMesh ); } - else { - switch ( theMode ) + + const Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode(); + if (myHilighter.IsNull() + || (aMode & MeshVS_DMF_OCCMask) == 0) + { + return; + } + + // Make two array aliases pointing to the same memory: + // - TColStd_Array1OfReal for getting values from MeshVS_DataSource interface + // - array of gp_Pnt for convenient work with array of points + MeshVS_Buffer aCoordsBuf (3 * aMaxFaceNodes * sizeof(Standard_Real)); + NCollection_Array1 aPntArray (aCoordsBuf, 1, aMaxFaceNodes); + TColStd_Array1OfReal aPntArrayAsCoordArray (aCoordsBuf, 1, 3 * aMaxFaceNodes); + + const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes(); + const TColStd_PackedMapOfInteger& anAllElementsMap = aSource->GetAllElements(); + if (aSource->IsAdvancedSelectionEnabled()) + { + Handle(MeshVS_MeshOwner) anOwner; + for (MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt (GetOwnerMaps (Standard_False)); anIt.More(); anIt.Next()) { - case MeshVS_SMF_Node: // Nodes - - myNodeOwners.Clear(); - - for ( anIter.Initialize( anAllNodesMap ); anIter.More(); anIter.Next() ) + anOwner = Handle(MeshVS_MeshOwner)::DownCast (anIt.Value()); + if (!anOwner.IsNull()) { - Standard_Integer aKey = anIter.Key(); - if ( !myDataSource->GetGeom ( aKey, Standard_False, aCoords, NbNodes, aType ) ) - continue; - - anAddr = myDataSource->GetAddr ( aKey, Standard_False ); - - Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner - ( this, aKey, anAddr, aType, 5 ); - - myNodeOwners.Bind ( aKey, anOwner ); - - if ( IsSelectableNode( aKey ) ) - { - x = aCoords(1); - y = aCoords(2); - z = aCoords(3); - Handle (Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint - ( anOwner, gp_Pnt (x, y, z) ); - theSelection->Add ( aPoint ); - } - else - theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); + // get the owner if it is already created + break; } - break; + } + if (anOwner.IsNull()) + { + // create one owner for the whole mesh and for all selection modes + anOwner = new MeshVS_MeshOwner (this, aSource, 5); + } - case MeshVS_SMF_Mesh: - - if( myWholeMeshOwner.IsNull() ) - myWholeMeshOwner = new SelectMgr_EntityOwner( this ); - - switch (mySelectionMethod) + // Save the owner. It will be available via GetOwnerMaps method + if (!myMeshOwners.IsBound (1)) + { + myMeshOwners.Bind (1, anOwner); + } + // Create one sensitive entity. It should detect mesh entities correspondingly to selection mode + Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh (anOwner, theMode); + theSelection->Add (aSensMesh); + } + else + { + switch (theMode) + { + case MeshVS_SMF_Node: { - case MeshVS_MSM_BOX: - { - Bnd_Box aBndBox; - BoundingBox (aBndBox); - if (!aBndBox.IsVoid()) - theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, aBndBox)); - } - break; - case MeshVS_MSM_NODES: - { - theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_NODES)); - } - break; - case MeshVS_MSM_PRECISE: - { - theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_PRECISE)); - - // since MeshVS_Mesh objects can contain free edges and vertices, it is necessary to create - // separate sensitive entity for each of them - TColStd_PackedMapOfInteger aSharedNodes; - scanFacesForSharedNodes (anAllElementsMap, aMaxFaceNodes, aSharedNodes); - - // create sensitive entities for free edges, if there are any - for (TColStd_MapIteratorOfPackedMapOfInteger anElemIter (anAllElementsMap); anElemIter.More(); anElemIter.Next()) + myNodeOwners.Clear(); + for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllNodesMap); anIter.More(); anIter.Next()) { - const Standard_Integer anElemIdx = anElemIter.Key(); - - if (IsSelectableElem (anElemIdx) && - myDataSource->GetGeomType (anElemIdx, Standard_True, aType) && - aType == MeshVS_ET_Link) + const Standard_Integer aKey = anIter.Key(); + Standard_Integer aNbNodes = 0; + MeshVS_EntityType aType = MeshVS_ET_NONE; + if (!myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType)) { - myDataSource->GetGeom (anElemIdx, Standard_True, aCoords, NbNodes, aType); - if (NbNodes == 0) - continue; - - MeshVS_Buffer aNodesBuf (NbNodes * sizeof (Standard_Integer)); - TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, NbNodes); - if (!myDataSource->GetNodesByElement (anElemIdx, aElemNodes, NbNodes)) - continue; + continue; + } - MeshVS_Buffer aPntsBuf (NbNodes * 3 * sizeof (Standard_Real)); - TColgp_Array1OfPnt aLinkPnts (aPntsBuf, 1, NbNodes); - Standard_Boolean isVertsShared = Standard_True; - for (Standard_Integer aPntIdx = 1; aPntIdx <= NbNodes; ++aPntIdx) - { - aLinkPnts (aPntIdx) = gp_Pnt (aCoords (3 * aPntIdx - 2), - aCoords (3 * aPntIdx - 1), - aCoords (3 * aPntIdx)); - isVertsShared = isVertsShared && aSharedNodes.Contains (aElemNodes (aPntIdx)); - aSharedNodes.Add (aElemNodes (aPntIdx)); - } - - if (!isVertsShared) - { - Handle(Select3D_SensitiveEntity) aLinkEnt - = new Select3D_SensitiveSegment (myWholeMeshOwner, aLinkPnts.Value (1), aLinkPnts.Value (2)); - theSelection->Add (aLinkEnt); - } + Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_False); + Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, 5); + myNodeOwners.Bind (aKey, anOwner); + if (IsSelectableNode (aKey)) + { + Handle(Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint (anOwner, aPntArray.First()); + theSelection->Add (aPoint); + } + else + { + theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner)); } } - - // create sensitive entities for free nodes, if there are any - for (TColStd_MapIteratorOfPackedMapOfInteger aNodesIter (anAllNodesMap); aNodesIter.More(); aNodesIter.Next()) + break; + } + case MeshVS_SMF_Mesh: + { + if (myWholeMeshOwner.IsNull()) { - const Standard_Integer aNodeIdx = aNodesIter.Key(); - if (IsSelectableNode (aNodeIdx) && - myDataSource->GetGeom (aNodeIdx, Standard_False, aCoords, NbNodes, aType) && - !aSharedNodes.Contains (aNodeIdx)) - { - Handle(Select3D_SensitiveEntity) aNodeEnt - = new Select3D_SensitivePoint (myWholeMeshOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3))); - theSelection->Add (aNodeEnt); - } + myWholeMeshOwner = new SelectMgr_EntityOwner (this); } - } - break; - } - case MeshVS_SMF_Group: + switch (mySelectionMethod) + { + case MeshVS_MSM_BOX: + { + Bnd_Box aBndBox; + BoundingBox (aBndBox); + if (!aBndBox.IsVoid()) + { + theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, aBndBox)); + } + break; + } + case MeshVS_MSM_NODES: + { + theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_NODES)); + break; + } + case MeshVS_MSM_PRECISE: + { + theSelection->Add (new MeshVS_CommonSensitiveEntity (myWholeMeshOwner, this, MeshVS_MSM_PRECISE)); + + // since MeshVS_Mesh objects can contain free edges and vertices, it is necessary to create + // separate sensitive entity for each of them + TColStd_PackedMapOfInteger aSharedNodes; + scanFacesForSharedNodes (anAllElementsMap, aMaxFaceNodes, aSharedNodes); + + // create sensitive entities for free edges, if there are any + Standard_Integer aNbNodes = 0; + MeshVS_EntityType aType = MeshVS_ET_NONE; + for (TColStd_MapIteratorOfPackedMapOfInteger anElemIter (anAllElementsMap); anElemIter.More(); anElemIter.Next()) + { + const Standard_Integer anElemIdx = anElemIter.Key(); + if (IsSelectableElem (anElemIdx) + && myDataSource->GetGeomType (anElemIdx, Standard_True, aType) + && aType == MeshVS_ET_Link) + { + myDataSource->GetGeom (anElemIdx, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType); + if (aNbNodes == 0) + { + continue; + } + + MeshVS_Buffer aNodesBuf (aNbNodes * sizeof(Standard_Integer)); + TColStd_Array1OfInteger aElemNodes (aNodesBuf, 1, aNbNodes); + if (!myDataSource->GetNodesByElement (anElemIdx, aElemNodes, aNbNodes)) + { + continue; + } + + MeshVS_Buffer aPntsBuf (aNbNodes * 3 * sizeof(Standard_Real)); + TColgp_Array1OfPnt aLinkPnts (aPntsBuf, 1, aNbNodes); + Standard_Boolean isVertsShared = Standard_True; + for (Standard_Integer aPntIdx = 1; aPntIdx <= aNbNodes; ++aPntIdx) + { + aLinkPnts (aPntIdx) = aPntArray.Value (aPntIdx); + isVertsShared = isVertsShared && aSharedNodes.Contains (aElemNodes (aPntIdx)); + aSharedNodes.Add (aElemNodes (aPntIdx)); + } + + if (!isVertsShared) + { + Handle(Select3D_SensitiveEntity) aLinkEnt = new Select3D_SensitiveSegment (myWholeMeshOwner, aLinkPnts.Value (1), aLinkPnts.Value (2)); + theSelection->Add (aLinkEnt); + } + } + } + + // create sensitive entities for free nodes, if there are any + for (TColStd_MapIteratorOfPackedMapOfInteger aNodesIter (anAllNodesMap); aNodesIter.More(); aNodesIter.Next()) + { + const Standard_Integer aNodeIdx = aNodesIter.Key(); + if (IsSelectableNode (aNodeIdx) + && myDataSource->GetGeom (aNodeIdx, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType) + && !aSharedNodes.Contains (aNodeIdx)) + { + Handle(Select3D_SensitiveEntity) aNodeEnt = new Select3D_SensitivePoint (myWholeMeshOwner, aPntArray.First()); + theSelection->Add (aNodeEnt); + } + } + } + break; + } + break; + } + case MeshVS_SMF_Group: { myGroupOwners.Clear(); TColStd_PackedMapOfInteger anAllGroupsMap; - aSource->GetAllGroups( anAllGroupsMap ); + aSource->GetAllGroups (anAllGroupsMap); - Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo; - - for ( anIter.Initialize( anAllGroupsMap ); anIter.More(); anIter.Next() ) + Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo; + for (TColStd_MapIteratorOfPackedMapOfInteger anIter (anAllGroupsMap); anIter.More(); anIter.Next()) { - Standard_Integer aKeyGroup = anIter.Key(); - - MeshVS_EntityType aGroupType; + const Standard_Integer aKeyGroup = anIter.Key(); + MeshVS_EntityType aGroupType = MeshVS_ET_NONE; TColStd_PackedMapOfInteger aGroupMap; - if ( !myDataSource->GetGroup( aKeyGroup, aGroupType, aGroupMap ) ) + if (!myDataSource->GetGroup (aKeyGroup, aGroupType, aGroupMap)) + { continue; + } - anAddr = myDataSource->GetGroupAddr ( aKeyGroup ); + Standard_Address anAddr = myDataSource->GetGroupAddr (aKeyGroup); Standard_Integer aPrior = 0; + switch (aGroupType) + { + case MeshVS_ET_Volume: aPrior = 1; break; + case MeshVS_ET_Face: aPrior = 2; break; + case MeshVS_ET_Link: aPrior = 3; break; + case MeshVS_ET_0D: aPrior = 4; break; + case MeshVS_ET_Node: aPrior = 5; break; + default: break; + } - if( aGroupType == MeshVS_ET_Volume ) - aPrior = 1; - if ( aGroupType == MeshVS_ET_Face ) - aPrior = 2; - else if ( aGroupType == MeshVS_ET_Link ) - aPrior = 3; - else if ( aGroupType == MeshVS_ET_0D ) - aPrior = 4; - else if ( aGroupType == MeshVS_ET_Node ) - aPrior = 5; - - Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner - ( this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True ); - - myGroupOwners.Bind( aKeyGroup, anOwner ); + Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True); + myGroupOwners.Bind (aKeyGroup, anOwner); Standard_Boolean added = Standard_False; - for ( TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap); - anIterMG.More(); anIterMG.Next() ) + Standard_Integer aNbNodes = 0; + MeshVS_EntityType aType = MeshVS_ET_NONE; + for (TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap); anIterMG.More(); anIterMG.Next()) { Standard_Integer aKey = anIterMG.Key(); - if ( aGroupType == MeshVS_ET_Node ) { - if( myDataSource->GetGeom( aKey, Standard_False, aCoords, NbNodes, aType ) && - IsSelectableNode/*!IsHiddenNode*/( aKey ) ) { - theSelection->Add( new Select3D_SensitivePoint( anOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) ); + if (aGroupType == MeshVS_ET_Node) + { + if (myDataSource->GetGeom (aKey, Standard_False, aPntArrayAsCoordArray, aNbNodes, aType) + && IsSelectableNode/*!IsHiddenNode*/(aKey)) + { + theSelection->Add (new Select3D_SensitivePoint (anOwner, aPntArray.First ())); added = Standard_True; } } - else if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) && - IsSelectableElem/*!IsHiddenElem*/( aKey ) ) { - myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); - - TColgp_Array1OfPnt anArr( 1, NbNodes ); - for ( Standard_Integer i=1; i<=NbNodes; i++ ) - { - x = aCoords(3*i-2); - y = aCoords(3*i-1); - z = aCoords(3*i); - anArr.SetValue ( i, gp_Pnt ( x, y, z ) ); - } - - if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements + else if (myDataSource->GetGeomType (aKey, Standard_True, aType) + && IsSelectableElem/*!IsHiddenElem*/(aKey)) + { + myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType); + if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements { Handle(Select3D_SensitiveEntity) aSensFace; - if (NbNodes == 3) + if (aNbNodes == 3) { aSensFace = new Select3D_SensitiveTriangle (anOwner, - anArr.Value (1), anArr.Value (2), anArr.Value (3), + aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3), Select3D_TOS_INTERIOR); } - else if (NbNodes == 4) + else if (aNbNodes == 4) { - aSensFace = new MeshVS_SensitiveQuad (anOwner, anArr); + aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray); } else { - aSensFace = new MeshVS_SensitiveFace (anOwner, anArr); + aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray); } theSelection->Add (aSensFace); added = Standard_True; } - else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements + else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements { - Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment - ( anOwner, anArr(1), anArr(2) ); - theSelection->Add ( aSeg ); + Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2)); + theSelection->Add (aSeg); added = Standard_True; } - else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) ) + else if (aType == MeshVS_ET_Volume + && aSource->Get3DGeom (aKey, aNbNodes, aTopo)) { - Handle( MeshVS_SensitivePolyhedron ) aPolyhedron = - new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo ); - theSelection->Add( aPolyhedron ); + Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo); + theSelection->Add (aPolyhedron); added = Standard_True; } else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!! { - Handle (SelectBasics_SensitiveEntity) anEnt = - myHilighter->CustomSensitiveEntity ( anOwner, aKey ); - if (!anEnt.IsNull()) { - theSelection->Add ( anEnt ); + Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey); + if (!anEnt.IsNull()) + { + theSelection->Add (anEnt); added = Standard_True; } } } } - if ( !added ) - theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); + if (!added) + { + theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner)); + } } + break; } - break; - - default: // all residuary modes + default: // all residuary modes { - Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo; - + Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo; myElementOwners.Clear(); - MeshVS_DataMapOfIntegerOwner* CurMap = &my0DOwners; - if ( theMode == MeshVS_ET_Link ) - CurMap = &myLinkOwners; - else if ( theMode == MeshVS_ET_Face ) - CurMap = &myFaceOwners; - else if ( theMode == MeshVS_ET_Volume ) - CurMap = &myVolumeOwners; + MeshVS_DataMapOfIntegerOwner* aCurMap = &my0DOwners; + if (theMode == MeshVS_ET_Link) + { + aCurMap = &myLinkOwners; + } + else if (theMode == MeshVS_ET_Face) + { + aCurMap = &myFaceOwners; + } + else if (theMode == MeshVS_ET_Volume) + { + aCurMap = &myVolumeOwners; + } + aCurMap->Clear(); - CurMap->Clear(); - - for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap); - anIterMV.More(); anIterMV.Next() ) + Standard_Integer aNbNodes = 0; + MeshVS_EntityType aType = MeshVS_ET_NONE; + for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap); anIterMV.More(); anIterMV.Next()) { Standard_Integer aKey = anIterMV.Key(); - - if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) && theMode == aType ) + if (myDataSource->GetGeomType (aKey, Standard_True, aType) + && theMode == aType) { - myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ); - anAddr = myDataSource->GetAddr ( aKey, Standard_True ); + myDataSource->GetGeom (aKey, Standard_True, aPntArrayAsCoordArray, aNbNodes, aType); + Standard_Address anAddr = myDataSource->GetAddr (aKey, Standard_True); Standard_Integer aPrior = 0; - - if( aType == MeshVS_ET_Volume ) - aPrior = 1; - if ( aType == MeshVS_ET_Face ) - aPrior = 2; - else if ( aType == MeshVS_ET_Link ) - aPrior = 3; - else if ( aType == MeshVS_ET_0D ) - aPrior = 4; - - Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner - ( this, aKey, anAddr, aType, aPrior ); - - CurMap->Bind ( aKey, anOwner ); - - if ( IsSelectableElem( aKey ) ) //The element is selectable + switch (aType) { - TColgp_Array1OfPnt anArr( 1, NbNodes ); - for ( Standard_Integer i=1; i<=NbNodes; i++ ) - { - x = aCoords(3*i-2); - y = aCoords(3*i-1); - z = aCoords(3*i); - anArr.SetValue ( i, gp_Pnt ( x, y, z ) ); - } + case MeshVS_ET_Volume: aPrior = 1; break; + case MeshVS_ET_Face: aPrior = 2; break; + case MeshVS_ET_Link: aPrior = 3; break; + case MeshVS_ET_0D: aPrior = 4; break; + default: break; + } - if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements + Handle(MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner (this, aKey, anAddr, aType, aPrior); + aCurMap->Bind (aKey, anOwner); + if (IsSelectableElem (aKey)) // The element is selectable + { + if (aType == MeshVS_ET_Face && aNbNodes > 0) // Faces: 2D-elements { Handle(Select3D_SensitiveEntity) aSensFace; - if (NbNodes == 3) + if (aNbNodes == 3) { aSensFace = new Select3D_SensitiveTriangle (anOwner, - anArr.Value (1), anArr.Value (2), anArr.Value (3), + aPntArray.Value (1), aPntArray.Value (2), aPntArray.Value (3), Select3D_TOS_INTERIOR); } - else if (NbNodes == 4) + else if (aNbNodes == 4) { - aSensFace = new MeshVS_SensitiveQuad (anOwner, anArr); + aSensFace = new MeshVS_SensitiveQuad (anOwner, aPntArray); } else { - aSensFace = new MeshVS_SensitiveFace (anOwner, anArr); + aSensFace = new MeshVS_SensitiveFace (anOwner, aPntArray); } theSelection->Add (aSensFace); } - else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements + else if (aType == MeshVS_ET_Link && aNbNodes > 0) // Links: 1D-elements { - Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment - ( anOwner, anArr(1), anArr(2) ); - theSelection->Add ( aSeg ); + Handle(MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment (anOwner, aPntArray (1), aPntArray (2)); + theSelection->Add (aSeg); } - else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) ) + else if (aType == MeshVS_ET_Volume + && aSource->Get3DGeom (aKey, aNbNodes, aTopo)) { - Handle( MeshVS_SensitivePolyhedron ) aPolyhedron = - new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo ); - theSelection->Add( aPolyhedron ); + Handle(MeshVS_SensitivePolyhedron) aPolyhedron = new MeshVS_SensitivePolyhedron (anOwner, aPntArray, aTopo); + theSelection->Add (aPolyhedron); } else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!! { - Handle (SelectBasics_SensitiveEntity) anEnt = - myHilighter->CustomSensitiveEntity ( anOwner, aKey ); + Handle(SelectBasics_SensitiveEntity) anEnt = myHilighter->CustomSensitiveEntity (anOwner, aKey); if (!anEnt.IsNull()) - theSelection->Add ( anEnt ); + { + theSelection->Add (anEnt); + } } } else - theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) ); + { + theSelection->Add (new MeshVS_DummySensitiveEntity (anOwner)); + } } } + break; } - break; } } StdSelect_BRepSelectionTool::PreBuildBVH (theSelection); - if ( ShowComputeSelectionTime ) + if (toShowComputeSelectionTime) { Standard_Real sec, cpu; Standard_Integer min, hour; - - gTimer.Show ( sec, min, hour, cpu ); - cout << "SelectionMode : " << theMode << endl; - cout << "Compute selection: " << sec << " sec" << endl; - cout << "Compute selection CPU : " << cpu << " sec" << endl << endl; + gTimer.Show (sec, min, hour, cpu); + std::cout << "SelectionMode : " << theMode << "\n"; + std::cout << "Compute selection: " << sec << " sec\n"; + std::cout << "Compute selection CPU : " << cpu << " sec\n\n"; gTimer.Stop(); } }