Salome HOME
#16559 EDF - Changes to the Concatenate function: non regression test fails
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index c03eaa65029870ad03ce6f9d8e22856bb7161cb0..660c3e69f94115e98824b30ace7a2e3f83f7da20 100644 (file)
@@ -521,11 +521,10 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
 
   // Reading groups (sub-meshes are out of scope of MED import functionality)
   std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
-  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 );
+    SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str() );
     if ( aGroup ) {
       SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
       if ( aGroupDS ) {
@@ -2029,16 +2028,17 @@ bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
 
 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
                                    const char*               theName,
-                                   int&                      theId,
+                                   const int                 theId,
                                    const TopoDS_Shape&       theShape,
                                    const SMESH_PredicatePtr& thePredicate)
 {
-  if (_mapGroup.count(_groupId))
+  if ( _mapGroup.count( theId ))
     return NULL;
-  theId = _groupId;
-  SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
+  int id = ( theId < 0 ) ? _groupId : theId;
+  SMESH_Group* aGroup = new SMESH_Group ( id, this, theType, theName, theShape, thePredicate );
   GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
-  _mapGroup[_groupId++] = aGroup;
+  _mapGroup[ id ] = aGroup;
+  _groupId = 1 + _mapGroup.rbegin()->first;
   return aGroup;
 }
 
@@ -2050,7 +2050,7 @@ SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
 
 SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
 {
-  if ( !groupDS ) 
+  if ( !groupDS )
     throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
 
   std::map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
@@ -2075,7 +2075,7 @@ SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exce
 /*!
  * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
  *  \retval bool - true if new SMESH_Groups have been created
- * 
+ *
  */
 //================================================================================
 
@@ -2092,7 +2092,7 @@ bool SMESH_Mesh::SynchronizeGroups()
       _mapGroup[_groupId] = new SMESH_Group( groupDS );
   }
   if ( !_mapGroup.empty() )
-    _groupId = _mapGroup.rbegin()->first + 1;
+    _groupId = 1 + _mapGroup.rbegin()->first;
 
   return nbGroups < _mapGroup.size();
 }
@@ -2115,11 +2115,12 @@ SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
  */
 //=============================================================================
 
-SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
+SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID) const
 {
-  if (_mapGroup.find(theGroupID) == _mapGroup.end())
+  std::map <int, SMESH_Group*>::const_iterator id_grp = _mapGroup.find( theGroupID );
+  if ( id_grp == _mapGroup.end() )
     return NULL;
-  return _mapGroup[theGroupID];
+  return id_grp->second;
 }