+ if ( !aShape.IsNull() ) {
+ Bnd_Box Box;
+ BRepBndLib::Add(aShape, Box);
+ return sqrt( Box.SquareExtent() );
+ }
+ return 0;
+}
+
+//=======================================================================
+/*!
+ * \brief Return diagonal size of bounding box of shape to mesh
+ */
+//=======================================================================
+
+double SMESH_Mesh::GetShapeDiagonalSize() const
+{
+ if ( _shapeDiagonal == 0. && _isShapeToMesh )
+ const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
+
+ return _shapeDiagonal;
+}
+
+//=======================================================================
+/*!
+ * \brief Remove all nodes and elements
+ */
+//=======================================================================
+
+void SMESH_Mesh::Clear()
+{
+ // clear mesh data
+ _myMeshDS->ClearMesh();
+
+ // 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 );
+ // to recompute even if failed
+ sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ }
+}
+
+//=======================================================================
+//function : UNVToMesh
+//purpose :
+//=======================================================================
+
+int SMESH_Mesh::UNVToMesh(const char* theFileName)
+{
+ if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
+ if(_isShapeToMesh)
+ throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
+ _isShapeToMesh = false;
+ DriverUNV_R_SMDS_Mesh myReader;
+ myReader.SetMesh(_myMeshDS);
+ myReader.SetFile(theFileName);
+ myReader.SetMeshId(-1);
+ myReader.Perform();
+ if(MYDEBUG){
+ MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
+ MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
+ MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
+ MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
+ }
+ SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
+ if (aGroup != 0) {
+ TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
+ //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
+ aGroup->InitSubGroupsIterator();
+ while (aGroup->MoreSubGroups()) {
+ SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
+ std::string aName = aGroupNames[aSubGroup];
+ int aId;
+
+ SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
+ if ( aSMESHGroup ) {
+ if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
+ SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
+ if ( aGroupDS ) {
+ aGroupDS->SetStoreName(aName.c_str());
+ aSubGroup->InitIterator();
+ const SMDS_MeshElement* aElement = 0;
+ while (aSubGroup->More()) {
+ aElement = aSubGroup->Next();
+ if (aElement) {
+ aGroupDS->SMDSGroup().Add(aElement);
+ }
+ }
+ if (aElement)
+ aGroupDS->SetType(aElement->GetType());
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+//=======================================================================
+//function : MEDToMesh
+//purpose :
+//=======================================================================
+
+int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
+{
+ if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
+ if(_isShapeToMesh)
+ throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
+ _isShapeToMesh = false;
+ DriverMED_R_SMESHDS_Mesh myReader;
+ myReader.SetMesh(_myMeshDS);
+ myReader.SetMeshId(-1);
+ myReader.SetFile(theFileName);
+ myReader.SetMeshName(theMeshName);
+ Driver_Mesh::Status status = myReader.Perform();
+ if(MYDEBUG){
+ MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
+ MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
+ MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
+ MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
+ }
+
+ // Reading groups (sub-meshes are out of scope of MED import functionality)
+ std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
+ if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
+ int anId;
+ std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
+ for ( ; name_type != aGroupNames.end(); name_type++ ) {
+ SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
+ if ( aGroup ) {
+ if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
+ SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
+ if ( aGroupDS ) {
+ aGroupDS->SetStoreName( name_type->first.c_str() );
+ myReader.GetGroup( aGroupDS );
+ }
+ }
+ }
+ return (int) status;
+}
+
+//=======================================================================
+//function : STLToMesh
+//purpose :
+//=======================================================================