Salome HOME
Fix for "23678: [CEA 13186] messages in the python window" issue.
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index cd9c86098033368bdc5ae2f1c797362f91ad1fed..e04476d35f242b1538cc608fb3a07e5190db5253 100644 (file)
@@ -1965,7 +1965,8 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
       meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
       myLocMesh.GetMeshDS()->Modified();
       UpdateIcons( theMesh );
-      HighLightInvalid( theMesh, /*isInvalid=*/!ok );
+      if ( ok )
+        HighLightInvalid( theMesh, /*isInvalid=*/false );
       return ok;
     }
   }
@@ -2951,6 +2952,7 @@ namespace // utils for CopyMeshWithGeom()
 {
   typedef std::map< std::string, std::string >             TStr2StrMap;
   typedef std::map< std::string, std::set< std::string > > TStr2StrSetMap;
+  //typedef std::map< std::set<int>, int >                   TIdSet2IndexMap;
 
   //================================================================================
   /*!
@@ -2968,6 +2970,9 @@ namespace // utils for CopyMeshWithGeom()
 
     TStr2StrMap   myOld2NewEntryMap; // map of study entries
 
+    //GEOM::ListOfGO_var         mySubshapes; // sub-shapes existing in the new geometry
+    //TIdSet2IndexMap            myIds2SubshapeIndex; // to find an existing sub-shape
+
     bool                       myGIPMapDone;
     GEOM::ListOfListOfLong_var myGIPMap; // filled by GetInPlaceMap()
 
@@ -3158,7 +3163,19 @@ namespace // utils for CopyMeshWithGeom()
       if ( 0 < oldID && oldID < (int)myGIPMap->length() )
       {
         if ( myGIPMap[ oldID ].length() == 1 )
+        {
           newID = myGIPMap[ oldID ][ 0 ];
+        }
+        else if ( myGIPMap[ oldID ].length() > 1 &&
+                  getShapeType( mySrcMesh_i, oldID ) == TopAbs_VERTEX )
+        {
+          // select a meshed VERTEX
+          SMESH_subMesh* newSM;
+          for ( CORBA::ULong i = 0; i < myGIPMap[ oldID ].length() && !newID; ++i )
+            if (( newSM = myNewMesh_i->GetImpl().GetSubMeshContaining( myGIPMap[ oldID ][ i ] )) &&
+                ( !newSM->IsEmpty() ))
+              newID = myGIPMap[ oldID ][ i ];
+        }
       }
       return newID;
     }
@@ -3387,7 +3404,7 @@ namespace // utils for CopyMeshWithGeom()
       seq[ seq->length() - 1 ] = item;
     }
   }
-}
+} // namespace // utils for CopyMeshWithGeom()
 
 //================================================================================
 /*!
@@ -3449,6 +3466,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 );
 
@@ -3562,9 +3580,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;
 
@@ -3621,6 +3639,8 @@ throw ( SALOME::SALOME_Exception )
       if ( SMESH_subMesh* newSM = newMesh_i->GetImpl().GetSubMeshContaining( newID ))
         newSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
     }
+
+    newMeshDS->Modified();
   }
 
 
@@ -3631,7 +3651,7 @@ throw ( SALOME::SALOME_Exception )
   SALOME::GenericObj_wrap< SMESH::FilterManager > filterMgr = CreateFilterManager();
 
   SMESH::ListOfGroups_var groups = theSourceMesh->GetGroups();
-  CORBA::ULong nbGroups = groups->length(), nbAddedGroups = 0;
+  CORBA::ULong nbGroups = theToCopyGroups ? groups->length() : 0, nbAddedGroups = 0;
   for ( CORBA::ULong i = 0; i < nbGroups + nbAddedGroups; ++i )
   {
     SMESH::SMESH_Group_var         stdlGroup = SMESH::SMESH_Group::_narrow        ( groups[ i ]);
@@ -3645,12 +3665,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() )
@@ -3765,7 +3793,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();
@@ -3778,12 +3806,16 @@ throw ( SALOME::SALOME_Exception )
 
   } // loop on groups
 
-  // set mesh name
-  SALOMEDS::SObject_wrap soNew = ObjectToSObject( theNewMesh );
-  SALOMEDS::SObject_wrap soOld = ObjectToSObject( theSourceMesh );
-  CORBA::String_var oldName = soOld->GetName();
-  SetName( soNew, oldName.in(), "Mesh" );
+  newMeshDS->CompactMesh();
 
+  // set mesh name
+  if ( !theMeshName || !theMeshName[0] )
+  {
+    SALOMEDS::SObject_wrap soNew = ObjectToSObject( theNewMesh );
+    SALOMEDS::SObject_wrap soOld = ObjectToSObject( theSourceMesh );
+    CORBA::String_var oldName = soOld->GetName();
+    SetName( soNew, oldName.in(), "Mesh" );
+  }
   // mark invalid objects
   shapeMapper.GetInvalid( theInvalidEntries, invalidSObjects );
 
@@ -3950,6 +3982,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
   cmd+="\" \"";
   cmd+=meshfile;
   cmd+="\"";
+#ifdef WIN32
+  cmd+=" 2>NUL";
+#endif
   system(cmd.ToCString());
 
   // MED writer to be used by storage process