+ _shapeDiagonal = 0.0;
+ }
+
+ // set a new geometry
+ if ( !aShape.IsNull() )
+ {
+ _myMeshDS->ShapeToMesh(aShape);
+ _isShapeToMesh = true;
+ _nbSubShapes = _myMeshDS->MaxShapeIndex();
+
+ // fill _mapAncestors
+ int desType, ancType;
+ for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
+ for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
+ TopExp::MapShapesAndAncestors ( aShape,
+ (TopAbs_ShapeEnum) desType,
+ (TopAbs_ShapeEnum) ancType,
+ _mapAncestors );
+ }
+ else
+ {
+ _isShapeToMesh = false;
+ _shapeDiagonal = 0.0;
+ _myMeshDS->ShapeToMesh( PseudoShape() );
+ }
+}
+
+//=======================================================================
+/*!
+ * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
+ */
+//=======================================================================
+
+TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
+{
+ return _myMeshDS->ShapeToMesh();
+}
+
+//=======================================================================
+/*!
+ * \brief Return a solid which is returned by GetShapeToMesh() if
+ * a real geometry to be meshed was not set
+ */
+//=======================================================================
+
+const TopoDS_Solid& SMESH_Mesh::PseudoShape()
+{
+ static TopoDS_Solid aSolid;
+ if ( aSolid.IsNull() )
+ {
+ aSolid = BRepPrimAPI_MakeBox(1,1,1);
+ }
+ return aSolid;
+}
+
+//=======================================================================
+/*!
+ * \brief Return diagonal size of bounding box of a shape
+ */
+//=======================================================================
+
+double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
+{
+ 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;