X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Mesh.cxx;h=a07089b8dcf9cfbc4cdf44fa640982315c2d47a0;hb=78fb42dc3ea751d55039317d05b7e96ff86c0931;hp=4648b5a3d21a8b150de2aab3eac416a2638f0667;hpb=ddd20dd94358856385f639219bbdfbd1e14239d7;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 4648b5a3d..a07089b8d 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -210,46 +210,85 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape() void SMESH_Mesh::Clear() { - // clear sub-meshes; get ready to re-compute as a side-effect + // clear mesh data + _myMeshDS->ClearMesh(); - if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) - { + // update compute state of submeshes + if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) { SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, /*complexShapeFirst=*/false); + while ( smIt->more() ) { + sm = smIt->next(); + sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + } + } + +// // clear sub-meshes; get ready to re-compute as a side-effect + +// if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) +// { +// SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, +// /*complexShapeFirst=*/false); +// while ( smIt->more() ) +// { +// sm = smIt->next(); +// TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); +// if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) +// // all other shapes depends on vertices so they are already cleaned +// sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); +// // to recompute even if failed +// sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); +// } +// } + +// // clear entities not on sub-meshes + +// SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); +// while ( vIt->more() ) +// _myMeshDS->RemoveFreeElement( vIt->next(), 0 ); + +// SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); +// while ( fIt->more() ) +// _myMeshDS->RemoveFreeElement( fIt->next(), 0 ); + +// SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); +// while ( eIt->more() ) +// _myMeshDS->RemoveFreeElement( eIt->next(), 0 ); + +// SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); +// while ( nIt->more() ) { +// const SMDS_MeshNode * node = nIt->next(); +// if ( node->NbInverseElements() == 0 ) +// _myMeshDS->RemoveFreeNode( node, 0 ); +// else +// _myMeshDS->RemoveNode(node); +// } +} + +//======================================================================= +/*! + * \brief Remove all nodes and elements of indicated shape + */ +//======================================================================= + +void SMESH_Mesh::ClearSubMesh(const int theShapeId) +{ + // clear sub-meshes; get ready to re-compute as a side-effect + if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) ) + { + SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, + /*complexShapeFirst=*/false); while ( smIt->more() ) { sm = smIt->next(); TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) - // all other shapes depends on vertices so they are already cleaned - sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); + // all other shapes depends on vertices so they are already cleaned + sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // to recompute even if failed sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); } } - - // clear entities not on sub-meshes - - SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); - while ( vIt->more() ) - _myMeshDS->RemoveFreeElement( vIt->next(), 0 ); - - SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); - while ( fIt->more() ) - _myMeshDS->RemoveFreeElement( fIt->next(), 0 ); - - SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); - while ( eIt->more() ) - _myMeshDS->RemoveFreeElement( eIt->next(), 0 ); - - SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); - while ( nIt->more() ) { - const SMDS_MeshNode * node = nIt->next(); - if ( node->NbInverseElements() == 0 ) - _myMeshDS->RemoveFreeNode( node, 0 ); - else - _myMeshDS->RemoveNode(node); - } } //======================================================================= @@ -596,24 +635,28 @@ SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const //======================================================================= /*! * \brief Return the hypothesis assigned to the shape - * \param aSubShape - the shape to check - * \param aFilter - the hypothesis filter - * \param andAncestors - flag to check hypos assigned to ancestors of the shape - * \retval SMESH_Hypothesis* - the first hypo passed through aFilter + * \param aSubShape - the shape to check + * \param aFilter - the hypothesis filter + * \param andAncestors - flag to check hypos assigned to ancestors of the shape + * \param assignedTo - to return the shape the found hypo is assigned to + * \retval SMESH_Hypothesis* - the first hypo passed through aFilter */ //======================================================================= const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape, const SMESH_HypoFilter& aFilter, - const bool andAncestors) const + const bool andAncestors, + TopoDS_Shape* assignedTo) const { { const std::list& hypList = _myMeshDS->GetHypothesis(aSubShape); std::list::const_iterator hyp = hypList.begin(); for ( ; hyp != hypList.end(); hyp++ ) { const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp ); - if ( aFilter.IsOk( h, aSubShape)) + if ( aFilter.IsOk( h, aSubShape)) { + if ( assignedTo ) *assignedTo = aSubShape; return h; + } } } if ( andAncestors ) @@ -625,8 +668,10 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubS std::list::const_iterator hyp = hypList.begin(); for ( ; hyp != hypList.end(); hyp++ ) { const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp ); - if (aFilter.IsOk( h, it.Value() )) + if (aFilter.IsOk( h, it.Value() )) { + if ( assignedTo ) *assignedTo = it.Value(); return h; + } } } } @@ -1434,3 +1479,41 @@ SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem { return _myMeshDS->GetElementType( id, iselem ); } + +//============================================================================= +/*! + * \brief Convert group on geometry into standalone group + */ +//============================================================================= + +SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID ) +{ + SMESH_Group* aGroup = 0; + std::map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID ); + if ( itg == _mapGroup.end() ) + return aGroup; + + SMESH_Group* anOldGrp = (*itg).second; + SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS(); + if ( !anOldGrp || !anOldGrpDS ) + return aGroup; + + // create new standalone group + aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() ); + _mapGroup[theGroupID] = aGroup; + + SMESHDS_Group* aNewGrpDS = dynamic_cast( aGroup->GetGroupDS() ); + GetMeshDS()->RemoveGroup( anOldGrpDS ); + GetMeshDS()->AddGroup( aNewGrpDS ); + + // add elements (or nodes) into new created group + SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements(); + while ( anItr->more() ) + aNewGrpDS->Add( (anItr->next())->GetID() ); + + // remove old group + delete anOldGrp; + + return aGroup; +} +