Salome HOME
23607: [EDF] HYDRO: Copy mesh with geometry - problems of Copy elements
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index ffab1b05646c38130011d64b642ac0fce86d2e11..ac694c4feacf8b61498e02470a72df1e959b1165 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;
     }
@@ -3450,6 +3454,7 @@ throw ( SALOME::SALOME_Exception )
 
   SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theSourceMesh );
   SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theNewMesh );
+  srcMesh_i->Load();
 
   ShapeMapper shapeMapper( srcMesh_i, newMesh_i, this );
 
@@ -3563,9 +3568,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 +3651,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 +3779,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();