Salome HOME
23605: [EDF] HYDRO: parent mesh for Copy mesh with new geometry
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index ffab1b05646c38130011d64b642ac0fce86d2e11..6dface544a8a84bdfe28e4b37611b63b539d9b8a 100644 (file)
@@ -3158,8 +3158,12 @@ namespace // utils for CopyMeshWithGeom()
 
       if ( 0 < oldID && oldID < (int)myGIPMap->length() )
       {
-        if ( myGIPMap[ oldID ].length() == 1 )
+        if (( myGIPMap[ oldID ].length() == 1 ) ||
+            ( myGIPMap[ oldID ].length() > 1 &&
+              getShapeType( mySrcMesh_i, oldID ) == TopAbs_VERTEX ))
+        {
           newID = myGIPMap[ oldID ][ 0 ];
+        }
       }
       return newID;
     }
@@ -3563,9 +3567,9 @@ throw ( SALOME::SALOME_Exception )
 
 
   // copy mesh elements, keeping IDs
+  SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
   if ( theToCopyElements && theSourceMesh->NbNodes() > 0 )
   {
-    SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
     ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
     ::SMESH_MeshEditor::ElemFeatures elemData;
 
@@ -3646,12 +3650,20 @@ throw ( SALOME::SALOME_Exception )
 
     if ( !stdlGroup->_is_nil() )
     {
-      if ( theToCopyElements )
+      if ( newMeshDS->GetMeshInfo().NbElements( SMDSAbs_ElementType( elemType )) > 0 )
       {
         SMESH::long_array_var elemIDs = stdlGroup->GetIDs();
-        stdlGroup = theNewMesh->CreateGroup( elemType, name );
-        stdlGroup->Add( elemIDs );
-        newGroup = SMESH::SMESH_GroupBase::_narrow( stdlGroup );
+        const bool isElem = ( elemType != SMESH::NODE );
+        CORBA::ULong iE = 0;
+        for ( ; iE < elemIDs->length(); ++iE ) // check if any element has been copied
+          if ( newMeshDS->GetElementType( elemIDs[ iE ], isElem ) != SMDSAbs_All )
+            break;
+        if ( iE < elemIDs->length() )
+        {
+          stdlGroup = theNewMesh->CreateGroup( elemType, name );
+          stdlGroup->Add( elemIDs );
+          newGroup = SMESH::SMESH_GroupBase::_narrow( stdlGroup );
+        }
       }
     }
     else if ( !geomGroup->_is_nil() )
@@ -3766,7 +3778,7 @@ throw ( SALOME::SALOME_Exception )
     SALOMEDS::SObject_wrap newSO = ObjectToSObject( newGroup );
     if ( !srcSO->_is_nil() )
     {
-      CORBA::String_var srcID, newID;
+      CORBA::String_var srcID, newID("");
       srcID = srcSO->GetID();
       if ( !newSO->_is_nil() )
         newID = newSO->GetID();