Salome HOME
Merge from V6_main 13/12/2012
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index 0b171a6efbb293fddecff2e4c8f44059ca114d11..2616e0b5f368b3b2c58b8d576a9590f7351ca54e 100644 (file)
@@ -347,16 +347,32 @@ void SMESH_Mesh::Load()
 
 void SMESH_Mesh::Clear()
 {
 
 void SMESH_Mesh::Clear()
 {
-  // clear mesh data
-  _myMeshDS->ClearMesh();
+  if ( HasShapeToMesh() ) // remove all nodes and elements
+  {
+    // clear mesh data
+    _myMeshDS->ClearMesh();
 
 
-  // update compute state of submeshes
-  if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
+    // update compute state of submeshes
+    if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
+    {
+      sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+      sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+      sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
+      sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
+    }
+  }
+  else // remove only nodes/elements computed by algorithms
   {
   {
-    sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
-    sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
-    sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
-    sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
+    if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
+    {
+      SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
+                                                               /*complexShapeFirst=*/true);
+      while ( smIt->more() )
+      {
+        sm = smIt->next();
+        sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
+      }
+    }
   }
   _isModified = false;
 }
   }
   _isModified = false;
 }
@@ -545,11 +561,13 @@ int SMESH_Mesh::CGNSToMesh(const char*  theFileName,
  */
 //================================================================================
 
  */
 //================================================================================
 
-SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName)
+SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
+                                            bool        theMakeRequiredGroups)
 {
   DriverGMF_Read myReader;
   myReader.SetMesh(_myMeshDS);
   myReader.SetFile(theFileName);
 {
   DriverGMF_Read myReader;
   myReader.SetMesh(_myMeshDS);
   myReader.SetFile(theFileName);
+  myReader.SetMakeRequiredGroups( theMakeRequiredGroups );
   myReader.Perform();
   //theMeshName = myReader.GetMeshName();
 
   myReader.Perform();
   //theMeshName = myReader.GetMeshName();
 
@@ -1419,11 +1437,14 @@ void SMESH_Mesh::ExportCGNS(const char *        file,
 //================================================================================
 
 void SMESH_Mesh::ExportGMF(const char *        file,
 //================================================================================
 
 void SMESH_Mesh::ExportGMF(const char *        file,
-                           const SMESHDS_Mesh* meshDS)
+                           const SMESHDS_Mesh* meshDS,
+                           bool                withRequiredGroups)
 {
   DriverGMF_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
 {
   DriverGMF_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
+  myWriter.SetExportRequiredGroups( withRequiredGroups );
+
   myWriter.Perform();
 }
 
   myWriter.Perform();
 }
 
@@ -1999,7 +2020,9 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
   {
     // a geom group is added. Insert it into lists of ancestors before
     // the first ancestor more complex than group members
   {
     // a geom group is added. Insert it into lists of ancestors before
     // the first ancestor more complex than group members
-    int memberType = TopoDS_Iterator( theShape ).Value().ShapeType();
+    TopoDS_Iterator subIt( theShape );
+    if ( !subIt.More() ) return;
+    int memberType = subIt.Value().ShapeType();
     for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
       for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
       {
     for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
       for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
       {