Salome HOME
in createGroup(), make a unique name if no name is provided
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 1019e527302c08ddba0b3588f0e0a09a2d49c205..ad026374c3e1b4a55b3405ae0bce14f4565c3ae2 100644 (file)
@@ -132,7 +132,7 @@ SMESH_Mesh_i::~SMESH_Mesh_i()
       // this method is called from destructor of group (PAL6331)
       //_impl->RemoveGroup( aGroup->GetLocalID() );
       aGroup->myMeshServant = 0;
-      aGroup->Destroy();
+      aGroup->UnRegister();
     }
   }
   _mapGroups.clear();
@@ -144,7 +144,7 @@ SMESH_Mesh_i::~SMESH_Mesh_i()
       continue;
     SMESH_subMesh_i* aSubMesh = dynamic_cast<SMESH_subMesh_i*>(SMESH_Gen_i::GetServant(itSM->second).in());
     if (aSubMesh) {
-      aSubMesh->Destroy();
+      aSubMesh->UnRegister();
     }
   }
   _mapSubMeshIor.clear();
@@ -156,7 +156,7 @@ SMESH_Mesh_i::~SMESH_Mesh_i()
       continue;
     SMESH_Hypothesis_i* aHypo = dynamic_cast<SMESH_Hypothesis_i*>(SMESH_Gen_i::GetServant(itH->second).in());
     if (aHypo) {
-      aHypo->Destroy();
+      aHypo->UnRegister();
     }
   }
   _mapHypo.clear();
@@ -2070,6 +2070,18 @@ SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElem
                                                       const char*         theName,
                                                       const TopoDS_Shape& theShape )
 {
+  std::string newName;
+  if ( !theName || strlen( theName ) == 0 )
+  {
+    std::set< std::string > presentNames;
+    std::map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i_gr = _mapGroups.begin();
+    for ( ; i_gr != _mapGroups.end(); ++i_gr )
+      presentNames.insert( i_gr->second->GetName() );
+    do {
+      newName = "noname_Group_" + SMESH_Comment( presentNames.size() + 1 );
+    } while ( !presentNames.insert( newName ).second );
+    theName = newName.c_str();
+  }
   int anId;
   SMESH::SMESH_GroupBase_var aGroup;
   if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {