X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Mesh.cxx;h=5f29eb32cd4c72c61f524fc64fd491eb9d53f7d7;hb=e7e45ad8cb4d23a1709cccd4f6c6858e7409ee8a;hp=4479c7de8cb0e119cf695fd25ca09247d3659ea2;hpb=8e93201bcf959a3355c84d17a6a10d52d0a7114e;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 4479c7de8..5f29eb32c 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -23,7 +23,6 @@ // File : SMESH_Mesh.cxx // Author : Paul RASCLE, EDF // Module : SMESH -// $Header$ // #include "SMESH_Mesh.hxx" #include "SMESH_subMesh.hxx" @@ -50,7 +49,9 @@ #include "DriverSTL_R_SMDS_Mesh.h" #undef _Precision_HeaderFile +#include #include +#include #include #include #include @@ -95,6 +96,7 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId, _myMeshDS = theDocument->GetMesh(_idDoc); _isShapeToMesh = false; _isAutoColor = false; + _shapeDiagonal = 0.0; _myMeshDS->ShapeToMesh( PseudoShape() ); } @@ -155,6 +157,8 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape) // clear SMESHDS TopoDS_Shape aNullShape; _myMeshDS->ShapeToMesh( aNullShape ); + + _shapeDiagonal = 0.0; } // set a new geometry @@ -202,6 +206,33 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape() return aSolid; } +//======================================================================= +/*! + * \brief Return diagonal size of bounding box of a shape + */ +//======================================================================= + +double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape) +{ + Bnd_Box Box; + BRepBndLib::Add(aShape, Box); + return sqrt( Box.SquareExtent() ); +} + +//======================================================================= +/*! + * \brief Return diagonal size of bounding box of shape to mesh + */ +//======================================================================= + +double SMESH_Mesh::GetShapeDiagonalSize() const +{ + if ( _shapeDiagonal == 0. && _isShapeToMesh ) + const_cast(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() ); + + return _shapeDiagonal; +} + //======================================================================= /*! * \brief Remove all nodes and elements @@ -265,6 +296,32 @@ void SMESH_Mesh::Clear() // } } +//======================================================================= +/*! + * \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 ); + // to recompute even if failed + sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + } + } +} + //======================================================================= //function : UNVToMesh //purpose : @@ -1453,3 +1510,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; +} +