Salome HOME
Regression: mesh objects are not deleted => memory leaks
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i_1.cxx
index dc21b915cd32f6004ffd9ad9220fec1df464efd9..1b1ccc4ea17c27c13d7974682a5a9b1edca3a87a 100644 (file)
@@ -165,7 +165,7 @@ bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
 {
   if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(getStudyServant()));
   
-  if( !myIsEnablePublish )
+  if ( !myIsEnablePublish )
     return false;
 
   SMESH::SMESH_Mesh_var aMesh       = SMESH::SMESH_Mesh::_narrow(theIOR);
@@ -308,10 +308,12 @@ static SALOMEDS::SObject_ptr publish(CORBA::Object_ptr     theIOR,
     if ( !sameIOR )
     {
       iorAttr->SetValue( objStr.in() );
-      // UnRegister() !!! --> No: random problems when meshing in parallel (yacs foreach) in distributed python scripts
-//      SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
-//      if ( !genObj->_is_nil() )
-//        genObj->UnRegister();
+      // UnRegister() !!! --> random problems when meshing in parallel (yacs foreach) in
+      // distributed python scripts, because simultaneously created meshes are
+      // published into the same SO; as a result the mesh published first dies
+      SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
+      if ( !genObj->_is_nil() )
+        genObj->UnRegister();
     }
   }
 
@@ -479,6 +481,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObje
 {
   Unexpect aCatch(SALOME_SalomeException);
   SALOMEDS::SObject_wrap aSO;
+  if ( !myIsEnablePublish )
+    return aSO._retn();
   if ( CORBA::is_nil( theIOR ))
     return aSO._retn();
   if(MYDEBUG) MESSAGE("PublishInStudy");
@@ -521,6 +525,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObje
 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
 {
   if(MYDEBUG) MESSAGE("PublishComponent");
+  if ( !myIsEnablePublish )
+    return SALOMEDS::SComponent::_nil();
 
   SALOMEDS::StudyBuilder_var    aStudyBuilder  = getStudyServant()->NewBuilder();
   SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder();
@@ -572,8 +578,10 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
                                                 const char*           theName)
 {
+  if ( !myIsEnablePublish )
+    return SALOMEDS::SObject::_nil();
   if ( CORBA::is_nil( theMesh ))
-    return SALOMEDS::SComponent::_nil();
+    return SALOMEDS::SObject::_nil();
   if(MYDEBUG) MESSAGE("PublishMesh--IN");
 
   // find or publish a mesh
@@ -592,7 +600,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
     else
       aTag++;
 
-    aMeshSO = publish ( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
+    aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
     if ( aMeshSO->_is_nil() )
       return aMeshSO._retn();
   }
@@ -659,6 +667,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr    theM
                                                    GEOM::GEOM_Object_ptr    theShapeObject,
                                                    const char*              theName)
 {
+  if ( !myIsEnablePublish )
+    return SALOMEDS::SObject::_nil();
   if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
     return SALOMEDS::SObject::_nil();
 
@@ -749,6 +759,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
                                                  GEOM::GEOM_Object_ptr  theShapeObject,
                                                  const char*            theName)
 {
+  if ( !myIsEnablePublish )
+    return SALOMEDS::SObject::_nil();
   if (theMesh->_is_nil() || theGroup->_is_nil() )
     return SALOMEDS::SObject::_nil();
 
@@ -823,6 +835,8 @@ SALOMEDS::SObject_ptr
                                   const char*                 theName)
 {
   if(MYDEBUG) MESSAGE("PublishHypothesis")
+  if ( !myIsEnablePublish )
+    return SALOMEDS::SObject::_nil();
   if (theHyp->_is_nil())
     return SALOMEDS::SObject::_nil();
 
@@ -879,8 +893,10 @@ void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
     SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
   else if ( mesh_i->IsComputedOK() )
     SetPixMap( so, "ICON_SMESH_TREE_MESH" );
-  else
+  else if ( mesh_i->HasShapeToMesh() )
     SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
+  else
+    SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
 
   // set icons of sub-objects
   SALOMEDS::Study_var         study = getStudyServant();
@@ -1387,3 +1403,14 @@ int StudyContext::getOldId( const int newId )
   }
   return 0;
 }
+
+//=======================================================================
+//function : Clear
+//purpose  : clear data
+//=======================================================================
+
+void StudyContext::Clear()
+{
+  mapIdToIOR.Clear();
+  mapIdToId.Clear();
+}