]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
21948: EDF SMESH : Memory is not freed when deleting a mesh
authoreap <eap@opencascade.com>
Fri, 14 Dec 2012 13:34:34 +0000 (13:34 +0000)
committereap <eap@opencascade.com>
Fri, 14 Dec 2012 13:34:34 +0000 (13:34 +0000)
   Elimenate memory leaks on CORBA objects, servants of SALOMEDS objects etc

12 files changed:
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_DumpPython.cxx
src/SMESH_I/SMESH_Filter_i.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_Gen_i_1.cxx
src/SMESH_I/SMESH_Hypothesis_i.cxx
src/SMESH_I/SMESH_MEDMesh_i.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_NoteBook.cxx
src/SMESH_I/SMESH_PreMeshInfo.cxx

index 4dc84a2a15083b369efa9098fc46631bdc267555..57a076883f6fa04f107a99bd22e86be21a89fd85 100644 (file)
 //
 #include "SMESH_2smeshpy.hxx"
 
-#include "utilities.h"
 #include "SMESH_PythonDump.hxx"
 #include "SMESH_NoteBook.hxx"
 #include "SMESH_Filter_i.hxx"
 
+#include <SALOMEDS_wrap.hxx>
+#include <utilities.h>
+
 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
 
@@ -431,7 +433,7 @@ _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod
   {
     // find a GEOM entry
     _pyID geomID;
-    SALOMEDS::SComponent_var geomComp = theStudy->FindComponent("GEOM");
+    SALOMEDS::SComponent_wrap geomComp = theStudy->FindComponent("GEOM");
     if ( geomComp->_is_nil() ) return;
     CORBA::String_var entry = geomComp->GetID();
     geomID = entry.in();
@@ -1329,7 +1331,7 @@ bool _pyGen::IsNotPublished(const _pyID& theObjID) const
   // either the SMESH object is not in study or it is a GEOM object
   if ( IsGeomObject( theObjID ))
   {
-    SALOMEDS::SObject_var so = myStudy->FindObjectID( theObjID.ToCString() );
+    SALOMEDS::SObject_wrap so = myStudy->FindObjectID( theObjID.ToCString() );
     if ( so->_is_nil() ) return true;
     CORBA::Object_var obj = so->GetObject();
     return CORBA::is_nil( obj );
index e76a8a7360fe547ea3e487b2b54a340cd304def2..8b44c6b3e200ce40a67114162640112db99ba21d 100644 (file)
 //  Module  : SMESH
 
 #include "SMESH_PythonDump.hxx"
-#include "SMESH_Gen_i.hxx"
+
+#include "SMESH_2smeshpy.hxx"
+#include "SMESH_Comment.hxx"
 #include "SMESH_Filter_i.hxx"
+#include "SMESH_Gen_i.hxx"
 #include "SMESH_MeshEditor_i.hxx"
-#include "SMESH_2smeshpy.hxx"
+
+#include <SALOMEDS_wrap.hxx>
 
 #include <TColStd_HSequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
-#include <SMESH_Comment.hxx>
-
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
@@ -72,7 +74,7 @@ namespace SMESH
       SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
       std::string aString = myStream.str();
       TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
-      SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
+      SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
       if(!aStudy->_is_nil() && !aCollection.IsEmpty()){
         aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
         if(MYDEBUG) MESSAGE(aString);
@@ -238,10 +240,13 @@ namespace SMESH
   TPythonDump::
   operator<<(SALOMEDS::SObject_ptr aSObject)
   {
-    if ( !aSObject->_is_nil() )
-      myStream << aSObject->GetID();
-    else
+    if ( !aSObject->_is_nil() ) {
+      CORBA::String_var entry = aSObject->GetID();
+      myStream << entry.in();
+    }
+    else {
       myStream << NotPublishedObjectName();
+    }
     return *this;
   }
 
@@ -249,9 +254,9 @@ namespace SMESH
   TPythonDump::
   operator<<(CORBA::Object_ptr theArg)
   {
-    SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-    SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+    SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
     if(!aSObject->_is_nil()) {
       CORBA::String_var id = aSObject->GetID();
       myStream << id;
@@ -270,8 +275,8 @@ namespace SMESH
   TPythonDump::
   operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
   {
-    SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
-    SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SALOMEDS::Study_var     aStudy = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
     if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
       myStream << "hyp_" << theArg->GetId();
     else
@@ -285,18 +290,22 @@ namespace SMESH
   {
     if ( CORBA::is_nil( theArg ) )
       return *this << "None";
-    SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-    SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+    SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
     if(!aSObject->_is_nil())
+    {
       return *this << aSObject;
+    }
     if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theArg ))
+    {
       return *this << filter;
-    SMESH::SMESH_Mesh_var mesh = theArg->GetMesh();
-    if ( !theArg->_is_equivalent( mesh ))
+    }
+    if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theArg ))
     {
-      SMESH::long_array_var anElementsId = theArg->GetIDs();
-      SMESH::array_of_ElementType_var types =  theArg->GetTypes();
+      SMESH::SMESH_Mesh_var            mesh = theArg->GetMesh();
+      SMESH::long_array_var    anElementsId = theArg->GetIDs();
+      SMESH::array_of_ElementType_var types = theArg->GetTypes();
       SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
       return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
     }
@@ -590,7 +599,8 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
   if (CORBA::is_nil(aStudy))
     return new Engines::TMPFile(0);
 
-  SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
+  CORBA::String_var compDataType = ComponentDataType();
+  SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
   if (CORBA::is_nil(aSO))
     return new Engines::TMPFile(0);
 
@@ -599,9 +609,9 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
   Resource_DataMapOfAsciiStringAsciiString aMapNames;
   //TCollection_AsciiString s ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
 
-  SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
+  SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
   for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
-    SALOMEDS::SObject_var aValue = Itr->Value();
+    SALOMEDS::SObject_wrap aValue = Itr->Value();
     CORBA::String_var anID = aValue->GetID();
     CORBA::String_var aName = aValue->GetName();
     TCollection_AsciiString aGUIName ( (char*) aName.in() );
@@ -613,13 +623,15 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
   }
 
   // Get trace of restored study
-  //SALOMEDS::SObject_var aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
+  //SALOMEDS::SObject_wrap aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-  SALOMEDS::GenericAttribute_var anAttr =
+  SALOMEDS::GenericAttribute_wrap anAttr =
     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
 
-  char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
-  TCollection_AsciiString aSavedTrace (oldValue);
+  SALOMEDS::AttributePythonObject_var pyAttr =
+    SALOMEDS::AttributePythonObject::_narrow(anAttr);
+  CORBA::String_var oldValue = pyAttr->GetObject();
+  TCollection_AsciiString aSavedTrace (oldValue.out());
 
   // Add trace of API methods calls and replace study entries by names
   TCollection_AsciiString aScript;
@@ -675,14 +687,16 @@ void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
   TCollection_AsciiString aScript = GetNewPythonLines(theStudy->StudyId());
 
   // Check contents of PythonObject attribute
-  SALOMEDS::SObject_var aSO = theStudy->FindComponent(ComponentDataType());
-  //SALOMEDS::SObject_var aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
+  CORBA::String_var compDataType = ComponentDataType();
+  SALOMEDS::SObject_wrap aSO = theStudy->FindComponent( compDataType.in() );
   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
-  SALOMEDS::GenericAttribute_var anAttr =
+  SALOMEDS::GenericAttribute_wrap anAttr =
     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
 
-  char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
-  TCollection_AsciiString oldScript (oldValue);
+  SALOMEDS::AttributePythonObject_var pyAttr =
+    SALOMEDS::AttributePythonObject::_narrow(anAttr);
+  CORBA::String_var oldValue = pyAttr->GetObject();
+  TCollection_AsciiString oldScript (oldValue.out());
 
   if (oldScript.Length() > 0) {
     oldScript += "\n";
@@ -692,7 +706,7 @@ void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
   }
 
   // Store in PythonObject attribute
-  SALOMEDS::AttributePythonObject::_narrow(anAttr)->SetObject(oldScript.ToCString(), 1);
+  pyAttr->SetObject(oldScript.ToCString(), 1);
 
   // Clean trace of API methods calls
   CleanPythonTrace(theStudy->StudyId());
@@ -776,7 +790,9 @@ namespace {
       isValidName = false;
     }
     // shorten names like CartesianParameters3D_400_400_400_1000000_1
-    if ( aName.Length() > 20 && nbUnderscore > 2 )
+    const int nbAllowedUnderscore = 3; /* changed from 2 to 3 by an user request
+                                          posted to SALOME Forum */
+    if ( aName.Length() > 20 && nbUnderscore > nbAllowedUnderscore )
     {
       p = aName.Location( "_", 20, aName.Length());
       if ( p > 1 )
@@ -792,14 +808,14 @@ namespace {
  */
 //=============================================================================
 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
-                        (SALOMEDS::Study_ptr theStudy,
+                        (SALOMEDS::Study_ptr                       theStudy,
                          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
                          Resource_DataMapOfAsciiStringAsciiString& theNames,
-                         bool isPublished,
-                         bool isMultiFile,
-                         bool isHistoricalDump,
-                         bool& aValidScript,
-                         const TCollection_AsciiString& theSavedTrace)
+                         bool                                      isPublished,
+                         bool                                      isMultiFile,
+                         bool                                      isHistoricalDump,
+                         bool&                                     aValidScript,
+                         const TCollection_AsciiString&            theSavedTrace)
 {
   int aStudyID = theStudy->StudyId();
 
@@ -1014,7 +1030,8 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   if (isPublished)
   {
     //Output the script that sets up the visual parameters.
-    char* script = theStudy->GetDefaultScript(ComponentDataType(), "\t");
+    CORBA::String_var compDataType = ComponentDataType();
+    char* script = theStudy->GetDefaultScript( compDataType.in(), "\t");
     if (script && strlen(script) > 0) {
       anUpdatedScript += "\n\n\t### Store presentation parameters of displayed objects\n";
       anUpdatedScript += script;
index fc5314b8cbf339ae8721f9bd3ab80bd492256889..523bf46770efc3b13e4f8987e3f0f9ef54c22605 100644 (file)
 //
 #include "SMESH_Filter_i.hxx"
 
-#include "SMESH_Gen_i.hxx"
-#include "SMESH_PythonDump.hxx"
-
+#include "SMDS_ElemIterator.hxx"
 #include "SMDS_Mesh.hxx"
-#include "SMDS_MeshNode.hxx"
 #include "SMDS_MeshElement.hxx"
-#include "SMDS_ElemIterator.hxx"
-
+#include "SMDS_MeshNode.hxx"
 #include "SMESHDS_Mesh.hxx"
+#include "SMESH_Gen_i.hxx"
+#include "SMESH_PythonDump.hxx"
+
+#include <SALOMEDS_wrap.hxx>
 
 #include <BRep_Tool.hxx>
 #include <Geom_CylindricalSurface.hxx>
@@ -496,7 +496,9 @@ static TopoDS_Shape getShapeByName( const char* theName )
       {
         CORBA::Object_var        anObj = aList[ 0 ]->GetObject();
         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
-        return aSMESHGen->GeomObjectToShape( aGeomObj );
+        TopoDS_Shape             shape = aSMESHGen->GeomObjectToShape( aGeomObj );
+        SALOME::UnRegister( aList ); // UnRegister() objects in aList
+        return shape;
       }
     }
   }
@@ -509,7 +511,7 @@ static TopoDS_Shape getShapeByID (const char* theID)
     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
     if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
+      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
       if ( !aSObj->_is_nil() ) {
         CORBA::Object_var          obj = aSObj->GetObject();
         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
@@ -526,7 +528,7 @@ static std::string getShapeNameByID (const char* theID)
     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
     if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
+      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
       if ( !aSObj->_is_nil() ) {
         CORBA::String_var name = aSObj->GetName();
         return name.in();
index ca74c6a0b834164368cd28da71311f63475d8bd7..eb5e0449bdb4dcfc5ebf2cbd0e0bbbc182fa0659 100644 (file)
 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
 #include CORBA_CLIENT_HEADER(SALOME_Session)
 
+// helpers about SALOME::GenericObj
+#include <SALOMEDS_wrap.hxx>
+#include <SALOMEDS_Attributes_wrap.hxx>
+#include <GEOM_GenericObjPtr.h>
+
 #include <map>
 #include <fstream>
 #include <cstdio>
@@ -176,16 +181,16 @@ PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theOb
 
 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
 {
-  SALOMEDS::GenericAttribute_var anAttr;
+  SALOMEDS::GenericAttribute_wrap anAttr;
   CORBA::Object_var anObj;
   if ( !theSObject->_is_nil() ) {
     try {
-      if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
-        SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow( anAttr );
+      if( theSObject->FindAttribute( anAttr.inout(), "AttributeIOR" ) ) {
+        SALOMEDS::AttributeIOR_wrap anIOR  = anAttr;
         CORBA::String_var aValue = anIOR->Value();
         if( strcmp( aValue, "" ) != 0 )
           anObj = GetORB()->string_to_object( aValue );
-        }
+      }
     }
     catch( ... ) {
       INFOS( "SObjectToObject - Unknown exception was caught!!!" );
@@ -234,7 +239,7 @@ SALOME_LifeCycleCORBA*  SMESH_Gen_i::GetLCC() {
  *  Get GEOM::GEOM_Gen reference
  */
 //=============================================================================
-GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
+GEOM::GEOM_Gen_var SMESH_Gen_i::GetGeomEngine() {
   //CCRT GEOM::GEOM_Gen_var aGeomEngine =
   //CCRT   GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
   //CCRT return aGeomEngine._retn();
@@ -341,7 +346,7 @@ SMESH_Gen_i::~SMESH_Gen_i()
   }
   myStudyContextMap.clear();
   // delete shape reader
-  if ( !myShapeReader )
+  if ( myShapeReader )
     delete myShapeReader;
 }
 
@@ -604,29 +609,27 @@ void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
   myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
   // create study context, if it doesn't exist and set current study
   int studyId = GetCurrentStudyID();
-  if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
+  if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() )
     myStudyContextMap[ studyId ] = new StudyContext;
-  }
 
   // myCurrentStudy may be nil
   if ( !theStudyIsBeingClosed && !CORBA::is_nil( myCurrentStudy ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
-    if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
-      aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
-
+    SALOMEDS::SComponent_wrap GEOM_var = myCurrentStudy->FindComponent( "GEOM" );
+    if( !GEOM_var->_is_nil() )
+      aStudyBuilder->LoadWith( GEOM_var, GetGeomEngine() );
     // NPAL16168, issue 0020210
     // Let meshes update their data depending on GEOM groups that could change
     if ( curStudyId != studyId )
     {
-      //SALOMEDS::SComponent_var me =  PublishComponent( myCurrentStudy );
-      SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
-        ( myCurrentStudy->FindComponent( ComponentDataType() ) );
+      CORBA::String_var compDataType = ComponentDataType();
+      SALOMEDS::SComponent_wrap me = myCurrentStudy->FindComponent( compDataType.in() );
       if ( !me->_is_nil() ) {
-        SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
+        SALOMEDS::ChildIterator_wrap anIter = myCurrentStudy->NewChildIterator( me );
         for ( ; anIter->More(); anIter->Next() ) {
-          SALOMEDS::SObject_var so = anIter->Value();
-          CORBA::Object_var    ior = SObjectToObject( so );
-          if ( SMESH_Mesh_i*  mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
+          SALOMEDS::SObject_wrap so = anIter->Value();
+          CORBA::Object_var     ior = SObjectToObject( so );
+          if ( SMESH_Mesh_i*   mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
             mesh->CheckGeomGroupModif();
         }
       }
@@ -682,7 +685,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam
 
   // Publish hypothesis/algorithm in the study
   if ( CanPublishInStudy( hyp ) ) {
-    SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
+    SALOMEDS::SObject_wrap aSO = PublishHypothesis( myCurrentStudy, hyp );
     if ( !aSO->_is_nil() ) {
       // Update Python script
       TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
@@ -746,9 +749,11 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
       // check local shape
       SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
       int nbLocalHyps = aHypList->length();
-      for ( int i = 0; i < nbLocalHyps; i++ )
-        if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
+      for ( int i = 0; i < nbLocalHyps; i++ ) {
+        CORBA::String_var hypName = aHypList[i]->GetName();
+        if ( strcmp( theHypType, hypName.in() ) == 0 ) // FOUND local!
           return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
+      }
       // check super shapes
       TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
       while ( nbLocalHyps == 0 && itShape.More() ) {
@@ -896,7 +901,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObj
   if ( CanPublishInStudy( mesh ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
-    SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
+    SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
     aStudyBuilder->CommitCommand();
     if ( !aSO->_is_nil() ) {
       // Update Python script
@@ -927,7 +932,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
   if ( CanPublishInStudy( mesh ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
-    SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
+    SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
     aStudyBuilder->CommitCommand();
     if ( !aSO->_is_nil() ) {
       // Update Python script
@@ -958,7 +963,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName
   if ( CanPublishInStudy( aMesh ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
-    SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
+    SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
     aStudyBuilder->CommitCommand();
     if ( !aSO->_is_nil() ) {
       // Update Python script
@@ -1020,7 +1025,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa
       SMESH::SMESH_Mesh_var mesh = createMesh();
 
       // publish mesh in the study
-      SALOMEDS::SObject_var aSO;
+      SALOMEDS::SObject_wrap aSO;
       if ( CanPublishInStudy( mesh ) )
         aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
       if ( !aSO->_is_nil() ) {
@@ -1125,7 +1130,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName
   if ( CanPublishInStudy( aMesh ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
-    SALOMEDS::SObject_var aSO = PublishInStudy
+    SALOMEDS::SObject_wrap aSO = PublishInStudy
       ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
     aStudyBuilder->CommitCommand();
     if ( !aSO->_is_nil() ) {
@@ -1199,15 +1204,17 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
 
         meshServant->GetImpl().GetMeshDS()->Modified();
         // publish mesh in the study
-        SALOMEDS::SObject_var aSO;
+        SALOMEDS::SObject_wrap aSO;
         if ( CanPublishInStudy( mesh ) )
           aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
 
         // Python Dump
-        if ( !aSO->_is_nil() )
+        if ( !aSO->_is_nil() ) {
           aPythonDump << aSO;
-        else
+        }
+        else {
           aPythonDump << "mesh_" << i;
+        }
       }
       aStudyBuilder->CommitCommand();
     }
@@ -1250,7 +1257,7 @@ SMESH_Gen_i::CreateMeshesFromGMF( const char*             theFileName,
   if ( CanPublishInStudy( aMesh ) ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
-    SALOMEDS::SObject_var aSO = PublishInStudy
+    SALOMEDS::SObject_wrap aSO = PublishInStudy
       ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
     aStudyBuilder->CommitCommand();
     if ( !aSO->_is_nil() ) {
@@ -1320,16 +1327,16 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
   if ( algo ) {
     if ( !myCurrentStudy->_is_nil() ) {
       // find algo in the study
-      SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
-        ( myCurrentStudy->FindComponent( ComponentDataType() ) );
+      CORBA::String_var compDataType  = ComponentDataType();
+      SALOMEDS::SComponent_wrap father = myCurrentStudy->FindComponent( compDataType.in() );
       if ( !father->_is_nil() ) {
-        SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
+        SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( father );
         for ( ; itBig->More(); itBig->Next() ) {
-          SALOMEDS::SObject_var gotBranch = itBig->Value();
+          SALOMEDS::SObject_wrap gotBranch = itBig->Value();
           if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
-            SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
+            SALOMEDS::ChildIterator_wrap algoIt = myCurrentStudy->NewChildIterator( gotBranch );
             for ( ; algoIt->More(); algoIt->Next() ) {
-              SALOMEDS::SObject_var algoSO = algoIt->Value();
+              SALOMEDS::SObject_wrap algoSO = algoIt->Value();
               CORBA::Object_var     algoIOR = SObjectToObject( algoSO );
               if ( !CORBA::is_nil( algoIOR )) {
                 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
@@ -1396,11 +1403,14 @@ SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr
           errStruct.code       = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
           errStruct.comment    = error->myComment.c_str();
           errStruct.subShapeID = sm->GetId();
-          SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
-          if ( !algoSO->_is_nil() )
-            errStruct.algoName = algoSO->GetName();
-          else
+          SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->myAlgo );
+          if ( !algoSO->_is_nil() ) {
+            CORBA::String_var algoName = algoSO->GetName();
+            errStruct.algoName = algoName;
+          }
+          else {
             errStruct.algoName = error->myAlgo->GetName();
+          }
           errStruct.hasBadMesh = !error->myBadElements.empty();
         }
       }
@@ -1548,9 +1558,11 @@ SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMes
         errStruct.algoDim      = error->_algoDim;
         errStruct.isGlobalAlgo = error->_isGlobalAlgo;
         errStruct.algoName     = "";
-        SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
-        if ( !algoSO->_is_nil() )
-          errStruct.algoName   = algoSO->GetName();
+        SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->_algo );
+        if ( !algoSO->_is_nil() ) {
+          CORBA::String_var algoName = algoSO->GetName();
+          errStruct.algoName = algoName.in();
+        }
       }
     }
   }
@@ -2004,7 +2016,7 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
  *  \param theMesh - the mesh the element is in
  *  \param theElementID - the element ID
  *  \param theGeomName - the name of the result geom object if it is not yet published
- *  \retval GEOM::GEOM_Object_ptr - the found or just published geom object
+ *  \retval GEOM::GEOM_Object_ptr - the found or just published geom object (no need to UnRegister())
  */
 //================================================================================
 
@@ -2016,31 +2028,34 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
 {
   Unexpect aCatch(SALOME_SalomeException);
 
-  GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
+  GEOM::GEOM_Object_wrap geom = FindGeometryByMeshElement(theMesh, theElementID);
   if ( !geom->_is_nil() ) {
     GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
     GEOM::GEOM_Gen_ptr    geomGen   = GetGeomEngine();
 
     // try to find the corresponding SObject
-    SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
+    SALOMEDS::SObject_wrap SObj = ObjectToSObject( myCurrentStudy, geom.in() );
     if ( SObj->_is_nil() ) // submesh can be not found even if published
     {
       // try to find published submesh
       GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
       if ( !geom->IsMainShape() && list->length() == 1 ) {
-        SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
-        SALOMEDS::ChildIterator_var it;
-        if ( !mainSO->_is_nil() )
+        SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
+        SALOMEDS::ChildIterator_wrap it;
+        if ( !mainSO->_is_nil() ) {
           it = myCurrentStudy->NewChildIterator( mainSO );
+        }
         if ( !it->_is_nil() ) {
-          for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
-            GEOM::GEOM_Object_var subGeom =
-              GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
+          for ( it->InitEx(true); it->More(); it->Next() ) {
+            SALOMEDS::SObject_wrap      so = it->Value();
+            CORBA::Object_var         obj = SObjectToObject( so );
+            GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
             if ( !subGeom->_is_nil() ) {
               GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
               if ( subList->length() == 1 && list[0] == subList[0] ) {
-                SObj = it->Value();
+                SObj = so;
                 geom = subGeom;
+                break;
               }
             }
           }
@@ -2051,8 +2066,12 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
       SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
 
     // return only published geometry
-    if ( !SObj->_is_nil() )
-      return geom._retn();
+    if ( !SObj->_is_nil() ) {
+      //return geom._retn(); -- servant of geom must be UnRegister()ed;
+      CORBA::Object_var    obj = SObjectToObject( SObj );
+      GEOM::GEOM_Object_var go = GEOM::GEOM_Object::_narrow( obj );
+      return go._retn();
+    }
   }
   return GEOM::GEOM_Object::_nil();
 }
@@ -2062,7 +2081,7 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
  * \brief Return geometrical object the given element is built on.
  *  \param theMesh - the mesh the element is in
  *  \param theElementID - the element ID
- *  \retval GEOM::GEOM_Object_ptr - the found geom object
+ *  \retval GEOM::GEOM_Object_ptr - the found or created (UnRegister()!) geom object
  */
 //================================================================================
 
@@ -2092,14 +2111,16 @@ SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
         GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
         if ( geom->_is_nil() ) {
           // try to find a published sub-shape
-          SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
-          SALOMEDS::ChildIterator_var it;
-          if ( !mainSO->_is_nil() )
+          SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
+          SALOMEDS::ChildIterator_wrap it;
+          if ( !mainSO->_is_nil() ) {
             it = myCurrentStudy->NewChildIterator( mainSO );
+          }
           if ( !it->_is_nil() ) {
             for ( it->InitEx(true); it->More(); it->Next() ) {
-              GEOM::GEOM_Object_var subGeom =
-                GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
+              SALOMEDS::SObject_wrap      so = it->Value();
+              CORBA::Object_var         obj = SObjectToObject( so );
+              GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
               if ( !subGeom->_is_nil() ) {
                 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
                 if ( subList->length() == 1 && shapeID == subList[0] ) {
@@ -2112,11 +2133,13 @@ SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
         }
         if ( geom->_is_nil() ) {
           // explode
-          GEOM::GEOM_IShapesOperations_var op =
-            geomGen->GetIShapesOperations( GetCurrentStudyID() );
+          GEOM::ShapesOpPtr op = geomGen->GetIShapesOperations( GetCurrentStudyID() );
           if ( !op->_is_nil() )
             geom = op->GetSubShape( mainShape, shapeID );
         }
+        else {
+          geom->Register();
+        }
         if ( !geom->_is_nil() ) {
           GeomObjectToShape( geom ); // let geom client remember the found shape
           return geom._retn();
@@ -2345,7 +2368,7 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
             if ( theCommonGroups ) {
               for(aGroupType=SMESH::NODE;aGroupType<=SMESH::BALL;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
                 string str = "Gr";
-                SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
+                SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
                 if(aMeshSObj)
                   str += aMeshSObj->GetName();
                 str += "_";
@@ -2512,7 +2535,7 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
   }
 
   // IPAL21468 Change icon of compound because it need not be computed.
-  SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
+  SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
   SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
 
   if (aNewMeshDS)
@@ -2558,7 +2581,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
   SMESH_Mesh_i*       newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
   if ( !newMesh_i )
     THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
-  SALOMEDS::SObject_var meshSO = ObjectToSObject(myCurrentStudy, newMesh );
+  SALOMEDS::SObject_wrap meshSO = ObjectToSObject(myCurrentStudy, newMesh );
   if ( !meshSO->_is_nil() )
   {
     SetName( meshSO, meshName, "Mesh" );
@@ -2883,9 +2906,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
   // SetStoreName() to groups before storing hypotheses to let them refer to
   // groups using "store name", which is "Group <group_persistent_id>"
   {
-    SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
+    SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
     for ( ; itBig->More(); itBig->Next() ) {
-      SALOMEDS::SObject_var gotBranch = itBig->Value();
+      SALOMEDS::SObject_wrap gotBranch = itBig->Value();
       if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
         CORBA::Object_var anObject = SObjectToObject( gotBranch );
         if ( !CORBA::is_nil( anObject ) ) {
@@ -2920,9 +2943,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
   aFile->CreateOnDisk();
 
   // --> iterator for top-level objects
-  SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
+  SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
   for ( ; itBig->More(); itBig->Next() ) {
-    SALOMEDS::SObject_var gotBranch = itBig->Value();
+    SALOMEDS::SObject_wrap gotBranch = itBig->Value();
 
     // --> hypotheses root branch (only one for the study)
     if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
@@ -2931,9 +2954,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
       aTopGroup->CreateOnDisk();
 
       // iterator for all hypotheses
-      SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
+      SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
       for ( ; it->More(); it->Next() ) {
-        SALOMEDS::SObject_var mySObject = it->Value();
+        SALOMEDS::SObject_wrap mySObject = it->Value();
         CORBA::Object_var anObject = SObjectToObject( mySObject );
         if ( !CORBA::is_nil( anObject ) ) {
           SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
@@ -3000,9 +3023,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
       aTopGroup->CreateOnDisk();
 
       // iterator for all algorithms
-      SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
+      SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
       for ( ; it->More(); it->Next() ) {
-        SALOMEDS::SObject_var mySObject = it->Value();
+        SALOMEDS::SObject_wrap mySObject = it->Value();
         CORBA::Object_var anObject = SObjectToObject( mySObject );
         if ( !CORBA::is_nil( anObject ) ) {
           SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
@@ -3126,12 +3149,12 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             aDataset->CloseOnDisk();
 
             // write reference on a shape if exists
-            SALOMEDS::SObject_var myRef;
+            SALOMEDS::SObject_wrap myRef;
             bool shapeRefFound = false;
-            bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
+            bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef.inout() );
             if ( found ) {
-              SALOMEDS::SObject_var myShape;
-              bool ok = myRef->ReferencedObject( myShape );
+              SALOMEDS::SObject_wrap myShape;
+              bool ok = myRef->ReferencedObject( myShape.inout() );
               if ( ok ) {
                 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
                 string myRefOnObject = myShape->GetID();
@@ -3146,8 +3169,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             }
 
             // write applied hypotheses if exist
-            SALOMEDS::SObject_var myHypBranch;
-            found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
+            SALOMEDS::SObject_wrap myHypBranch;
+            found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
             if ( found && !shapeRefFound && hasShape) { // remove applied hyps
               myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
             }
@@ -3155,12 +3178,12 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
               aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
               aGroup->CreateOnDisk();
 
-              SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
+              SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myHypBranch );
               int hypNb = 0;
               for ( ; it->More(); it->Next() ) {
-                SALOMEDS::SObject_var mySObject = it->Value();
-                SALOMEDS::SObject_var myRefOnHyp;
-                bool ok = mySObject->ReferencedObject( myRefOnHyp );
+                SALOMEDS::SObject_wrap mySObject = it->Value();
+                SALOMEDS::SObject_wrap myRefOnHyp;
+                bool ok = mySObject->ReferencedObject( myRefOnHyp.inout() );
                 if ( ok ) {
                   // san - it is impossible to recover applied hypotheses
                   //       using their entries within Load() method,
@@ -3189,8 +3212,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             }
 
             // write applied algorithms if exist
-            SALOMEDS::SObject_var myAlgoBranch;
-            found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
+            SALOMEDS::SObject_wrap myAlgoBranch;
+            found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
+                                              myAlgoBranch.inout() );
             if ( found && !shapeRefFound && hasShape) { // remove applied algos
               myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
             }
@@ -3198,12 +3222,12 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
               aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
               aGroup->CreateOnDisk();
 
-              SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
+              SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myAlgoBranch );
               int algoNb = 0;
               for ( ; it->More(); it->Next() ) {
-                SALOMEDS::SObject_var mySObject = it->Value();
-                SALOMEDS::SObject_var myRefOnAlgo;
-                bool ok = mySObject->ReferencedObject( myRefOnAlgo );
+                SALOMEDS::SObject_wrap mySObject = it->Value();
+                SALOMEDS::SObject_wrap myRefOnAlgo;
+                bool ok = mySObject->ReferencedObject( myRefOnAlgo.inout() );
                 if ( ok ) {
                   // san - it is impossible to recover applied algorithms
                   //       using their entries within Load() method,
@@ -3234,18 +3258,18 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             // --> submesh objects sub-branches
 
             for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
-              SALOMEDS::SObject_var mySubmeshBranch;
-              found = gotBranch->FindSubObject( i, mySubmeshBranch );
+              SALOMEDS::SObject_wrap mySubmeshBranch;
+              found = gotBranch->FindSubObject( i, mySubmeshBranch.inout() );
 
               if ( found ) // check if there is shape reference in submeshes
               {
                 bool hasShapeRef = false;
-                SALOMEDS::ChildIterator_var itSM =
+                SALOMEDS::ChildIterator_wrap itSM =
                   myCurrentStudy->NewChildIterator( mySubmeshBranch );
                 for ( ; itSM->More(); itSM->Next() ) {
-                  SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
-                  if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
-                    mySubRef->ReferencedObject( myShape );
+                  SALOMEDS::SObject_wrap mySubRef, myShape, mySObject = itSM->Value();
+                  if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
+                    mySubRef->ReferencedObject( myShape.inout() );
                   if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
                     hasShapeRef = true;
                   else
@@ -3296,9 +3320,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                 aGroup->CreateOnDisk();
 
                 // iterator for all submeshes of given type
-                SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
+                SALOMEDS::ChildIterator_wrap itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
                 for ( ; itSM->More(); itSM->Next() ) {
-                  SALOMEDS::SObject_var mySObject = itSM->Value();
+                  SALOMEDS::SObject_wrap mySObject = itSM->Value();
                   CORBA::Object_var anSubObject = SObjectToObject( mySObject );
                   if ( !CORBA::is_nil( anSubObject ))
                   {
@@ -3313,9 +3337,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                     aSubGroup->CreateOnDisk();
 
                     // write reference on a shape, already checked if it exists
-                    SALOMEDS::SObject_var mySubRef, myShape;
-                    if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
-                      mySubRef->ReferencedObject( myShape );
+                    SALOMEDS::SObject_wrap mySubRef, myShape;
+                    if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
+                      mySubRef->ReferencedObject( myShape.inout() );
                     string myRefOnObject = myShape->GetID();
                     if ( myRefOnObject.length() > 0 ) {
                       aSize[ 0 ] = myRefOnObject.length() + 1;
@@ -3326,18 +3350,19 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                     }
 
                     // write applied hypotheses if exist
-                    SALOMEDS::SObject_var mySubHypBranch;
-                    found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
+                    SALOMEDS::SObject_wrap mySubHypBranch;
+                    found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(),
+                                                      mySubHypBranch.inout() );
                     if ( found ) {
                       aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
                       aSubSubGroup->CreateOnDisk();
 
-                      SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
+                      SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( mySubHypBranch );
                       int hypNb = 0;
                       for ( ; it->More(); it->Next() ) {
-                        SALOMEDS::SObject_var mySubSObject = it->Value();
-                        SALOMEDS::SObject_var myRefOnHyp;
-                        bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
+                        SALOMEDS::SObject_wrap mySubSObject = it->Value();
+                        SALOMEDS::SObject_wrap myRefOnHyp;
+                        bool ok = mySubSObject->ReferencedObject( myRefOnHyp.inout() );
                         if ( ok ) {
                           //string myRefOnObject = myRefOnHyp->GetID();
                           CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
@@ -3361,18 +3386,20 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                     }
 
                     // write applied algorithms if exist
-                    SALOMEDS::SObject_var mySubAlgoBranch;
-                    found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
+                    SALOMEDS::SObject_wrap mySubAlgoBranch;
+                    found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
+                                                      mySubAlgoBranch.inout() );
                     if ( found ) {
                       aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
                       aSubSubGroup->CreateOnDisk();
 
-                      SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
+                      SALOMEDS::ChildIterator_wrap it =
+                        myCurrentStudy->NewChildIterator( mySubAlgoBranch );
                       int algoNb = 0;
                       for ( ; it->More(); it->Next() ) {
-                        SALOMEDS::SObject_var mySubSObject = it->Value();
-                        SALOMEDS::SObject_var myRefOnAlgo;
-                        bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
+                        SALOMEDS::SObject_wrap mySubSObject = it->Value();
+                        SALOMEDS::SObject_wrap myRefOnAlgo;
+                        bool ok = mySubSObject->ReferencedObject( myRefOnAlgo.inout() );
                         if ( ok ) {
                           //string myRefOnObject = myRefOnAlgo->GetID();
                           CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
@@ -3442,9 +3469,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             }
 
             // groups root sub-branch
-            SALOMEDS::SObject_var myGroupsBranch;
+            SALOMEDS::SObject_wrap myGroupsBranch;
             for ( int i = GetNodeGroupsTag(); i <= GetBallElementsGroupsTag(); i++ ) {
-              found = gotBranch->FindSubObject( i, myGroupsBranch );
+              found = gotBranch->FindSubObject( i, myGroupsBranch.inout() );
               if ( found ) {
                 char name_group[ 30 ];
                 if ( i == GetNodeGroupsTag() )
@@ -3463,9 +3490,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                 aGroup = new HDFgroup( name_group, aTopGroup );
                 aGroup->CreateOnDisk();
 
-                SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
+                SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myGroupsBranch );
                 for ( ; it->More(); it->Next() ) {
-                  SALOMEDS::SObject_var mySObject = it->Value();
+                  SALOMEDS::SObject_wrap mySObject = it->Value();
                   CORBA::Object_var aSubObject = SObjectToObject( mySObject );
                   if ( !CORBA::is_nil( aSubObject ) ) {
                     SMESH_GroupBase_i* myGroupImpl =
@@ -3515,9 +3542,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                     SMESHDS_GroupOnGeom* aGeomGrp =
                       dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
                     if ( aGeomGrp ) {
-                      SALOMEDS::SObject_var mySubRef, myShape;
-                      if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
-                          mySubRef->ReferencedObject( myShape ) &&
+                      SALOMEDS::SObject_wrap mySubRef, myShape;
+                      if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ) &&
+                          mySubRef->ReferencedObject( myShape.inout() ) &&
                           !CORBA::is_nil( myShape->GetObject() ))
                       {
                         string myRefOnObject = myShape->GetID();
@@ -3878,10 +3905,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
   TCollection_AsciiString tmpDir =
     isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
 
-    INFOS( "THE URL++++++++++++++" )
-    INFOS( theURL );
-    INFOS( "THE TMP PATH+++++++++" );
-    INFOS( tmpDir );
+  INFOS( "THE URL++++++++++++++" );
+  INFOS( theURL );
+  INFOS( "THE TMP PATH+++++++++" );
+  INFOS( tmpDir );
 
   // Convert the stream into sequence of files to process
   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
@@ -4020,8 +4047,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             if ( myImpl ) {
               // myImpl->LoadFrom( hypdata.c_str() );
               hypDataList.push_back( make_pair( myImpl, hypdata ));
-              string iorString = GetORB()->object_to_string( myHyp );
-              int newId = myStudyContext->findId( iorString );
+              CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
+              int newId = myStudyContext->findId( iorString.in() );
               myStudyContext->mapOldToNew( id, newId );
             }
             else
@@ -4120,8 +4147,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             if ( myImpl ) {
               //myImpl->LoadFrom( hypdata.c_str() );
               hypDataList.push_back( make_pair( myImpl, hypdata ));
-              string iorString = GetORB()->object_to_string( myHyp );
-              int newId = myStudyContext->findId( iorString );
+              CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
+              int newId = myStudyContext->findId( iorString.in() );
               myStudyContext->mapOldToNew( id, newId );
             }
             else
@@ -4161,8 +4188,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             continue;
           meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
 
-          string iorString = GetORB()->object_to_string( myNewMesh );
-          int newId = myStudyContext->findId( iorString );
+          CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
+          int newId = myStudyContext->findId( iorString.in() );
           myStudyContext->mapOldToNew( id, newId );
 
           // ouv : NPAL12872
@@ -4178,6 +4205,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             aDataset->ReadFromDisk( anAutoColor );
             aDataset->CloseOnDisk();
             myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
+            delete [] anAutoColor;
           }
 
           // try to read and set reference to shape
@@ -4191,7 +4219,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             aDataset->ReadFromDisk( refFromFile );
             aDataset->CloseOnDisk();
             if ( strlen( refFromFile ) > 0 ) {
-              SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
+              SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
 
               // Make sure GEOM data are loaded first
               //loadGeomData( shapeSO->GetFatherComponent() );
@@ -4203,6 +4231,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                   myNewMeshImpl->SetShape( aShapeObject );
               }
             }
+            delete [] refFromFile;
           }
 
           // issue 20918. Restore Persistent Id of SMESHDS_Mesh
@@ -4215,6 +4244,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             aDataset->ReadFromDisk( meshPersistentId );
             aDataset->CloseOnDisk();
             myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
+            delete [] meshPersistentId;
           }
         }
       }
@@ -4245,8 +4275,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
       bool hasData = false;
 
       // get mesh old id
-      string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
-      int newId = myStudyContext->findId( iorString );
+      CORBA::String_var iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
+      int newId = myStudyContext->findId( iorString.in() );
       int id = myStudyContext->getOldId( newId );
 
       // try to find mesh data dataset
@@ -4265,6 +4295,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
           // myReader.Perform();
           hasData = true;
         }
+        delete [] strHasData;
       }
 
       // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
@@ -4287,9 +4318,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             aDataset->ReadFromDisk( refFromFile );
             aDataset->CloseOnDisk();
             // san - it is impossible to recover applied algorithms using their entries within Load() method
-            //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
+            //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
             //CORBA::Object_var hypObject = SObjectToObject( hypSO );
             int id = atoi( refFromFile );
+            delete [] refFromFile;
             string anIOR = myStudyContext->getIORbyOldId( id );
             if ( !anIOR.empty() ) {
               CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
@@ -4323,9 +4355,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             aDataset->ReadFromDisk( refFromFile );
             aDataset->CloseOnDisk();
             // san - it is impossible to recover applied hypotheses using their entries within Load() method
-            //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
+            //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
             //CORBA::Object_var hypObject = SObjectToObject( hypSO );
             int id = atoi( refFromFile );
+            delete [] refFromFile;
             string anIOR = myStudyContext->getIORbyOldId( id );
             if ( !anIOR.empty() ) {
               CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
@@ -4393,7 +4426,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 aDataset->ReadFromDisk( refFromFile );
                 aDataset->CloseOnDisk();
                 if ( strlen( refFromFile ) > 0 ) {
-                  SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
+                  SALOMEDS::SObject_wrap subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
                   CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
                   if ( !CORBA::is_nil( subShapeObject ) ) {
                     aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
@@ -4543,7 +4576,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 aDataset->ReadFromDisk( refFromFile );
                 aDataset->CloseOnDisk();
                 if ( strlen( refFromFile ) > 0 ) {
-                  SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
+                  SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
                   CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
                   if ( !CORBA::is_nil( shapeObject ) ) {
                     aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
@@ -4579,7 +4612,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 continue;
 
               string iorSubString = GetORB()->object_to_string( aNewGroup );
-              int newSubId = myStudyContext->findId( iorSubString );
+              int        newSubId = myStudyContext->findId( iorSubString );
               myStudyContext->mapOldToNew( subid, newSubId );
 
               SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
@@ -4770,24 +4803,6 @@ void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
     myStudyContextMap.erase( studyId );
   }
 
-  // delete SMESH_Mesh's
-//   See bug IPAL19437.
-//
-//   StudyContextStruct* context = myGen.GetStudyContext( studyId );
-//   map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
-//   for ( ; i_mesh != context->mapMesh.end(); ++i_mesh ) {
-//     printf( "--------------------------- SMESH_Gen_i::Close, delete aGroup = %p \n", i_mesh->second );
-//     delete i_mesh->second;
-//   }
-
-
-  // delete SMESHDS_Mesh's
-  // it's too long on big meshes
-//   if ( context->myDocument ) {
-//     delete context->myDocument;
-//     context->myDocument = 0;
-//   }
-
   // remove the tmp files meshes are loaded from
   SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
 
@@ -4906,7 +4921,7 @@ void SMESH_Gen_i::SetName(const char* theIOR,
 {
   if ( theIOR && strcmp( theIOR, "" ) ) {
     CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
-    SALOMEDS::SObject_var aSO = ObjectToSObject( myCurrentStudy, anObject );
+    SALOMEDS::SObject_wrap aSO = ObjectToSObject( myCurrentStudy, anObject );
     if ( !aSO->_is_nil() ) {
       SetName( aSO, theName );
     }
index 746f73765029ed22d53a0120bdb47e062615a90c..c240ba7d7467a8417793ae95fc18c240330a9a38 100644 (file)
@@ -146,7 +146,7 @@ public:
   // Get SALOME_LifeCycleCORBA object
   static SALOME_LifeCycleCORBA* GetLCC();
   // Retrieve and get GEOM engine reference
-  static GEOM::GEOM_Gen_ptr GetGeomEngine();
+  static GEOM::GEOM_Gen_var GetGeomEngine();
   // Get object of the CORBA reference
   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
   // Get CORBA object corresponding to the SALOMEDS::SObject
index 1638083b5869b129580b36225e97542b924cff39..b78d04a85fa6ad60133696c528ede339afff9a8d 100644 (file)
 
 #include "SMESH_Gen_i.hxx"
 
-#include "SMESH_Mesh_i.hxx"
-#include "SMESH_Hypothesis_i.hxx"
 #include "SMESH_Algo_i.hxx"
+#include "SMESH_Comment.hxx"
 #include "SMESH_Group_i.hxx"
+#include "SMESH_Hypothesis_i.hxx"
+#include "SMESH_Mesh_i.hxx"
 #include "SMESH_subMesh_i.hxx"
 
 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
 
-#include "utilities.h"
-#include "Utils_ExceptHandlers.hxx"
+#include <utilities.h>
+#include <Utils_ExceptHandlers.hxx>
+#include <SALOMEDS_wrap.hxx>
+#include <SALOMEDS_Attributes_wrap.hxx>
 
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Solid.hxx>
@@ -182,13 +185,13 @@ bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
 
 //=======================================================================
 //function : ObjectToSObject
-//purpose  : 
+//purpose  : Put a result into a SALOMEDS::SObject_wrap or call UnRegister()!
 //=======================================================================
 
 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
                                                    CORBA::Object_ptr   theObject)
 {
-  SALOMEDS::SObject_var aSO;
+  SALOMEDS::SObject_wrap aSO;
   if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
   {
     CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
@@ -256,30 +259,33 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr   theStudy,
                                      const char*           thePixMap = 0,
                                      const bool            theSelectable = true)
 {
-  SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
+  SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
   if ( SO->_is_nil() ) {
     if ( theTag == 0 )
       SO = aStudyBuilder->NewObject( theFatherObject );
-    else if ( !theFatherObject->FindSubObject( theTag, SO ))
+    else if ( !theFatherObject->FindSubObject( theTag, SO.inout() ))
       SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
   }
 
-  SALOMEDS::GenericAttribute_var anAttr;
+  SALOMEDS::GenericAttribute_wrap anAttr;
   if ( !CORBA::is_nil( theIOR )) {
     anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
     CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
-    SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
+    SALOMEDS::AttributeIOR_wrap iorAttr = anAttr;
+    iorAttr->SetValue( objStr.in() );
   }
   if ( thePixMap ) {
     anAttr  = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
-    SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
+    SALOMEDS::AttributePixMap_wrap pm = anAttr;
     pm->SetPixMap( thePixMap );
   }
   if ( !theSelectable ) {
-    anAttr   = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
-    SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
+    anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
+    SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
+    selAttr->SetSelectable( false );
   }
+
   return SO._retn();
 }
 
@@ -293,18 +299,18 @@ void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
                           const char*           theDefaultName)
 {
   if ( !theSObject->_is_nil() ) {
-    SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
-    SALOMEDS::GenericAttribute_var anAttr =
+    SALOMEDS::Study_var               aStudy = theSObject->GetStudy();
+    SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+    SALOMEDS::GenericAttribute_wrap   anAttr =
       aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
-    SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
+    SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
     if ( theName && strlen( theName ) != 0 )
       aNameAttr->SetValue( theName );
     else {
-      CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
-      if ( strlen( curName ) == 0 ) {
-        TCollection_AsciiString aName( (char*) theDefaultName );
-        aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
-        aNameAttr->SetValue( aName.ToCString() );
+      CORBA::String_var curName = aNameAttr->Value();
+      if ( strlen( curName.in() ) == 0 ) {
+        SMESH_Comment aName(theDefaultName);
+        aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
       }
     }
   }
@@ -320,11 +326,11 @@ void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
 {
   if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
   {
-    SALOMEDS::Study_var aStudy = theSObject->GetStudy();
+    SALOMEDS::Study_var               aStudy = theSObject->GetStudy();
     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-    SALOMEDS::GenericAttribute_var anAttr =
+    SALOMEDS::GenericAttribute_wrap anAttr =
       aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
-    SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
+    SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
     aPMAttr->SetPixMap( thePixMap );
   }
 }
@@ -339,24 +345,27 @@ static void addReference (SALOMEDS::Study_ptr   theStudy,
                           CORBA::Object_ptr     theToObject,
                           int                   theTag = 0)
 {
-  SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
+  SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
   if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
-    SALOMEDS::SObject_var aReferenceSO;
+    SALOMEDS::SObject_wrap aReferenceSO;
     if ( !theTag ) {
       // check if the reference to theToObject already exists
       // and find a free label for the reference object
       bool isReferred = false;
       int tag = 1;
-      SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
+      SALOMEDS::ChildIterator_wrap anIter = theStudy->NewChildIterator( theSObject );
       for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
-        if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
-          if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
+        SALOMEDS::SObject_wrap curSO = anIter->Value();
+        if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
+          CORBA::String_var refEntry = aReferenceSO->GetID();
+          CORBA::String_var  toEntry = aToObjSO->GetID();
+          if ( strcmp( refEntry, toEntry ) == 0 )
             isReferred = true;
         }
         else if ( !theTag ) {
-          SALOMEDS::GenericAttribute_var anAttr;
-          if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
+          SALOMEDS::GenericAttribute_wrap anAttr;
+          if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
             theTag = tag;
         }
       }
@@ -365,7 +374,7 @@ static void addReference (SALOMEDS::Study_ptr   theStudy,
       if ( !theTag )
         theTag = tag;
     }
-    if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
+    if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
       aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
     aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
   }
@@ -386,7 +395,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy
      throw (SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-  SALOMEDS::SObject_var aSO;
+  SALOMEDS::SObject_wrap aSO;
   if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
     return aSO._retn();
   if(MYDEBUG) MESSAGE("PublishInStudy");
@@ -432,8 +441,8 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theSt
     return SALOMEDS::SComponent::_nil();
   if(MYDEBUG) MESSAGE("PublishComponent");
 
-  SALOMEDS::SComponent_var father =
-    SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
+  CORBA::String_var   compDataType = ComponentDataType();
+  SALOMEDS::SComponent_wrap father = theStudy->FindComponent( compDataType.in() );
   if ( !CORBA::is_nil( father ) )
     return father._retn();
 
@@ -442,20 +451,21 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theSt
   if ( CORBA::is_nil( aCat ) )
     return father._retn();
 
-  SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
+  SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.in() );
   if ( CORBA::is_nil( aComp ) )
     return father._retn();
 
-  SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder(); 
-  SALOMEDS::GenericAttribute_var anAttr;
-  SALOMEDS::AttributePixMap_var  aPixmap;
+  SALOMEDS::StudyBuilder_var      aStudyBuilder = theStudy->NewBuilder(); 
+  SALOMEDS::GenericAttribute_wrap anAttr;
+  SALOMEDS::AttributePixMap_wrap  aPixmap;
 
-  father  = aStudyBuilder->NewComponent( ComponentDataType() );
+  father  = aStudyBuilder->NewComponent( compDataType.in() );
   aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
   anAttr  = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
-  aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
-  aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
-  SetName( father, aComp->componentusername(), "MESH" );
+  aPixmap = anAttr;
+  aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
+  CORBA::String_var userName = aComp->componentusername();
+  SetName( father, userName.in(), "MESH" );
   if(MYDEBUG) MESSAGE("PublishComponent--END");
 
   return father._retn();
@@ -475,9 +485,10 @@ static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
   if ( !theSObject->_is_nil() ) {
     SALOMEDS::Study_var aStudy = theSObject->GetStudy();
     if ( !aStudy->_is_nil() ) {
-      SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
+      SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
       for ( ; anIter->More(); anIter->Next() ) {
-        long nTag = anIter->Value()->Tag();
+        SALOMEDS::SObject_wrap anSO = anIter->Value();
+        long nTag = anSO->Tag();
         if ( nTag > aTag )
           aTag = nTag;
       }
@@ -502,10 +513,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
 
   // find or publish a mesh
 
-  SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
+  SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
   if ( aMeshSO->_is_nil() )
   {
-    SALOMEDS::SComponent_var father = PublishComponent( theStudy );
+    SALOMEDS::SComponent_wrap father = PublishComponent( theStudy );
     if ( father->_is_nil() )
       return aMeshSO._retn();
 
@@ -531,9 +542,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
     // Publish global hypotheses
 
     SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
-    for ( int i = 0; i < hypList->length(); i++ ) {
+    for ( int i = 0; i < hypList->length(); i++ )
+    {
       SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
-      PublishHypothesis( theStudy, aHyp );
+      SALOMEDS::SObject_wrap so = PublishHypothesis( theStudy, aHyp );
       AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
     }
   }
@@ -549,7 +561,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
     SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
     if ( !CORBA::is_nil( aSubMesh )) {
       aShapeObject = aSubMesh->GetSubShape();
-      PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
+      SALOMEDS::SObject_wrap( PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject ));
     }
   }
 
@@ -560,12 +572,11 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
   {
     SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
     if ( !aGroup->_is_nil() ) {
-      GEOM::GEOM_Object_var  aShapeObj;
-      SMESH::SMESH_GroupOnGeom_var aGeomGroup =
-        SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
+      GEOM::GEOM_Object_var aShapeObj;
+      SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
       if ( !aGeomGroup->_is_nil() )
         aShapeObj = aGeomGroup->GetShape();
-      PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
+      SALOMEDS::SObject_wrap( PublishGroup( theStudy, theMesh, aGroup, aShapeObj ));
     }
   }
 
@@ -588,10 +599,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr      theS
       theSubMesh->_is_nil() || theShapeObject->_is_nil() )
     return SALOMEDS::SObject::_nil();
 
-  SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
+  SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
   if ( aSubMeshSO->_is_nil() )
   {
-    SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
+    SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
     if ( aMeshSO->_is_nil() ) {
       aMeshSO = PublishMesh( theStudy, theMesh );
       if ( aMeshSO->_is_nil())
@@ -632,8 +643,11 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr      theS
     }
 
     // Find or create submesh root
-    SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
+    SALOMEDS::SObject_wrap aRootSO = publish (theStudy, CORBA::Object::_nil(),
                                              aMeshSO, aRootTag, 0, false );
+    if ( aRootSO->_is_nil() )
+      return aSubMeshSO._retn();
+
     SetName( aRootSO, aRootName );
 
     // Add new submesh to corresponding sub-tree
@@ -652,13 +666,12 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr      theS
 
   // Publish hypothesis
 
-  SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
-  if ( hypList )
-    for ( int i = 0; i < hypList->length(); i++ ) {
-      SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
-      PublishHypothesis( theStudy, aHyp );
-      AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
-    }
+  SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
+  for ( int i = 0; i < hypList->length(); i++ ) {
+    SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
+    SALOMEDS::SObject_wrap so = PublishHypothesis( theStudy, aHyp );
+    AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
+  }
 
   return aSubMeshSO._retn();
 }
@@ -677,10 +690,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr    theStudy
   if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
     return SALOMEDS::SObject::_nil();
 
-  SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
+  SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theStudy, theGroup );
   if ( aGroupSO->_is_nil() )
   {
-    SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
+    SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
     if ( aMeshSO->_is_nil() ) {
       aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
       if ( aMeshSO->_is_nil())
@@ -698,8 +711,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr    theStudy
       long aRootTag = GetNodeGroupsTag() + aType - 1;
 
       // Find or create groups root
-      SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
+      SALOMEDS::SObject_wrap aRootSO = publish (theStudy, CORBA::Object::_nil(),
                                                aMeshSO, aRootTag, 0, false );
+      if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
+
       if ( aType < sizeof(aRootNames)/sizeof(char*) )
         SetName( aRootSO, aRootNames[aType] );
 
@@ -746,35 +761,34 @@ SALOMEDS::SObject_ptr
   if (theStudy->_is_nil() || theHyp->_is_nil())
     return SALOMEDS::SObject::_nil();
 
-  SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
+  CORBA::String_var hypType = theHyp->GetName();
+
+  SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
   if ( aHypSO->_is_nil() )
   {
-    SALOMEDS::SComponent_var father = PublishComponent( theStudy );
+    SALOMEDS::SComponent_wrap father = PublishComponent( theStudy );
     if ( father->_is_nil() )
       return aHypSO._retn();
 
     //Find or Create Hypothesis root
     bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
     int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
-    SALOMEDS::SObject_var aRootSO =
+    SALOMEDS::SObject_wrap aRootSO =
       publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
                isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
     SetName( aRootSO, isAlgo ?  "Algorithms" : "Hypotheses" );
 
     // Add New Hypothesis
     string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
-    aPmName += theHyp->GetName();
+    aPmName += hypType.in();
     // prepend plugin name to pixmap name
-    string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
+    string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
     if ( pluginName != "StdMeshers" )
       aPmName = pluginName + "::" + aPmName;
     aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
   }
 
-  if ( !aHypSO->_is_nil() ) {
-    CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
-    SetName( aHypSO, theName, aHypName );
-  }
+  SetName( aHypSO, theName, hypType.in() );
 
   if(MYDEBUG) MESSAGE("PublishHypothesis--END")
   return aHypSO._retn();
@@ -791,7 +805,7 @@ SALOMEDS::SObject_ptr
                                         GEOM::GEOM_Object_ptr theShape)
 {
   if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
-  SALOMEDS::SObject_var aMeshOrSubMesh;
+  SALOMEDS::SObject_wrap aMeshOrSubMesh;
   if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
     return aMeshOrSubMesh._retn();
   
@@ -834,15 +848,15 @@ bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
                             && theMesh->HasShapeToMesh()) )
     return false;
 
-  SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
+  SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
   if ( aMeshSO->_is_nil() )
     aMeshSO = PublishMesh( theStudy, theMesh );
-  SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
+  SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theStudy, theHyp );
   if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
     return false;
 
   // Find a mesh or submesh refering to theShape
-  SALOMEDS::SObject_var aMeshOrSubMesh =
+  SALOMEDS::SObject_wrap aMeshOrSubMesh =
     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
   if ( aMeshOrSubMesh->_is_nil() )
   {
@@ -861,15 +875,14 @@ bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
 
   //Find or Create Applied Hypothesis root
   bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
-  SALOMEDS::SObject_var AHR =
+  SALOMEDS::SObject_wrap AHR =
     publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
              aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
              aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
   SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
-  if ( AHR->_is_nil() )
-    return false;
 
   addReference( theStudy, AHR, theHyp );
+
   if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
   return true;
 }
@@ -889,27 +902,36 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy
                             && theMesh->HasShapeToMesh()))
     return false;
 
-  SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
+  SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
   if ( aHypSO->_is_nil() )
     return false;
 
+  CORBA::String_var hypEntry = aHypSO->GetID();
+
   // Find a mesh or submesh refering to theShape
-  SALOMEDS::SObject_var aMeshOrSubMesh =
+  SALOMEDS::SObject_wrap aMeshOrSubMesh =
     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
   if ( aMeshOrSubMesh->_is_nil() )
     return false;
 
   // Find and remove a reference to aHypSO
-  SALOMEDS::SObject_var aRef, anObj;
-  CORBA::String_var     anID = CORBA::string_dup( aHypSO->GetID() );
-  SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
-  for ( it->InitEx( true ); it->More(); it->Next() ) {
+  SALOMEDS::SObject_wrap aRef, anObj;
+  SALOMEDS::ChildIterator_wrap it = theStudy->NewChildIterator( aMeshOrSubMesh );
+  bool found = false;
+  for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
     anObj = it->Value();
-    if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
-      theStudy->NewBuilder()->RemoveObject( anObj );
-      break;
+    if (anObj->ReferencedObject( aRef.inout() ))
+    {
+      CORBA::String_var refEntry = aRef->GetID();
+      found = ( strcmp( refEntry, hypEntry ) == 0 );
+    }
+    if ( found )
+    {
+      SALOMEDS::StudyBuilder_var builder = theStudy->NewBuilder();
+      builder->RemoveObject( anObj );
     }
   }
+
   return true;
 }
 
@@ -919,7 +941,7 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy
 //=======================================================================
 void SMESH_Gen_i::UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char* theParameters)
 {
-  SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = GetCurrentStudy();
   if ( aStudy->_is_nil() )
     return;
   myLastParameters.clear();
@@ -950,11 +972,11 @@ void SMESH_Gen_i::UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char*
 
   // if(VARIABLE_DEBUG)
   //   cout<<"UpdateParameters : "<<theParameters<<endl;
-  // //SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
+  // //SALOMEDS::Study_var aStudy = GetCurrentStudy();
   // if(aStudy->_is_nil() || CORBA::is_nil(theObject)) 
   //   return;
 
-  // SALOMEDS::SObject_var aSObj =  ObjectToSObject(aStudy,theObject);
+  // SALOMEDS::SObject_wrap aSObj =  ObjectToSObject(aStudy,theObject);
   // if(aSObj->_is_nil())  
   //   return;
 
@@ -1066,22 +1088,21 @@ char* SMESH_Gen_i::ParseParameters(const char* theParameters)
 //function : GetParameters
 //purpose  : 
 //=======================================================================
+
 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
 {
-  TCollection_AsciiString aResult;
-
-  SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
-  SALOMEDS::SObject_var aSObj =  ObjectToSObject(aStudy,theObject);
-
-  if(!aStudy->_is_nil() && 
-     !CORBA::is_nil(theObject) && 
-     !aSObj->_is_nil()){
-    
-    SALOMEDS::GenericAttribute_var anAttr;
-    if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
-      aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
+  CORBA::String_var aResult("");
+
+  SALOMEDS::SObject_wrap aSObj = ObjectToSObject( myCurrentStudy,theObject);
+  if ( !aSObj->_is_nil() )
+  {
+    SALOMEDS::GenericAttribute_wrap attr;
+    if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
+    {
+      SALOMEDS::AttributeString_wrap strAttr = attr;
+      aResult = strAttr->Value();
     }
   }
-  
-  return CORBA::string_dup( aResult.ToCString() );
+
+  return CORBA::string_dup( aResult.in() );
 }
index f0fed296401201f4d8d9bc894612017bc409616c..c6d837f4932f7e2d3c1c237a2061281ed699912b 100644 (file)
 //  Author : Paul RASCLE, EDF
 //  Module : SMESH
 //
-#include <iostream>
-#include <sstream>
 #include "SMESH_Hypothesis_i.hxx"
 #include "SMESH_Gen_i.hxx"
-#include "utilities.h"
+
+#include <utilities.h>
+#include <SALOMEDS_wrap.hxx>
+
+#include <iostream>
+#include <sstream>
 
 using namespace std;
 
@@ -42,7 +45,7 @@ using namespace std;
 //=============================================================================
 
 SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA )
-     : SALOME::GenericObj_i( thePOA )
+  : SALOME::GenericObj_i( thePOA )
 {
   MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" );
   myBaseImpl = 0;
@@ -127,12 +130,13 @@ CORBA::Long SMESH_Hypothesis_i::GetId()
  *
  */
 //=============================================================================
-bool SMESH_Hypothesis_i::IsPublished(){
+bool SMESH_Hypothesis_i::IsPublished()
+{
   bool res = false;
-  SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
-  if(gen){
-    SALOMEDS::SObject_var SO = 
-      SMESH_Gen_i::ObjectToSObject(gen->GetCurrentStudy() , SMESH::SMESH_Hypothesis::_narrow(_this()));
+  if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen())
+  {
+    SALOMEDS::Study_var study = gen->GetCurrentStudy();
+    SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( study, _this());
     res = !SO->_is_nil();
   }
   return res;
@@ -210,105 +214,6 @@ void SMESH_Hypothesis_i::setOldParameters (const char* theParameters)
   }
 }
 
-//=============================================================================
-/*!
- *  SMESH_Hypothesis_i::SetParameters()
- *
- */
-//=============================================================================
-// void SMESH_Hypothesis_i::SetParameters(const char* theParameters)
-// {
-//   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
-//   //char * aParameters = CORBA::string_dup(theParameters);
-//   if(gen){
-//     gen->UpdateParameters(theParameters);
-//     // if(IsPublished()) {
-//     //   SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Hypothesis::_narrow(_this()),aParameters);
-//     // }
-//     // else {
-//     //   myBaseImpl->SetParameters(gen->ParseParameters(aParameters));
-//     // }
-//   }
-// }
-
-// //=============================================================================
-// /*!
-//  *  SMESH_Hypothesis_i::GetParameters()
-//  *
-//  */
-// //=============================================================================
-// char* SMESH_Hypothesis_i::GetParameters()
-// {
-//   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
-//   char* aResult;
-//   if(IsPublished()) {
-//     MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get Parameters from SObject");
-//     aResult = gen->GetParameters(SMESH::SMESH_Hypothesis::_narrow(_this()));
-//   }
-//   else {
-//     MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get local parameters");
-//     aResult = myBaseImpl->GetParameters(); 
-//   }
-//   return CORBA::string_dup(aResult);
-// }
-
-// //=============================================================================
-// /*!
-//  *  SMESH_Hypothesis_i::GetLastParameters()
-//  *
-//  */
-// //=============================================================================
-// SMESH::ListOfParameters* SMESH_Hypothesis_i::GetLastParameters()
-// {
-//   SMESH::ListOfParameters_var aResult = new SMESH::ListOfParameters();
-//   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
-//   if(gen) {
-//     char *aParameters;
-//     if(IsPublished())
-//      aParameters = GetParameters();
-//     else
-//       aParameters = myBaseImpl->GetLastParameters();
-
-//     SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
-//     if(!aStudy->_is_nil()) {
-//       SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); 
-//       if(aSections->length() > 0) {
-//         SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
-//         aResult->length(aVars.length());
-//         for(int i = 0;i < aVars.length();i++)
-//           aResult[i] = CORBA::string_dup( aVars[i]);
-//       }
-//     }
-//   }
-//   return aResult._retn();
-// }
-
-// //=============================================================================
-// /*!
-//  *  SMESH_Hypothesis_i::SetLastParameters()
-//  *
-//  */
-// //=============================================================================
-// void SMESH_Hypothesis_i::SetLastParameters(const char* theParameters)
-// {
-//   if(!IsPublished()) {
-//     myBaseImpl->SetLastParameters(theParameters);
-//   }
-// }
-// //=============================================================================
-// /*!
-//  *  SMESH_Hypothesis_i::ClearParameters()
-//  *
-//  */
-// //=============================================================================
-// void SMESH_Hypothesis_i::ClearParameters()
-// {
-//   myMethod2VarParams.clear();
-//   // if(!IsPublished()) {
-//   //   myBaseImpl->ClearParameters();
-//   // }
-// }
-
 //=============================================================================
 /*!
  *  SMESH_Hypothesis_i::GetImpl
index 823c8a037057165e95fc78d76e8bc43e8b4f76bd..ffde0e00fc947bb2e67e274f169807970f89b81d 100644 (file)
@@ -31,6 +31,9 @@
 #include "SMESHDS_Mesh.hxx"
 #include "SMESHDS_SubMesh.hxx"
 
+#include "SMESH_MEDSupport_i.hxx"
+#include "SMESH_MEDFamily_i.hxx"
+
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopTools_MapOfShape.hxx>
 
-#include "utilities.h"
-#include "Utils_CorbaException.hxx"
-
-#include "SMESH_MEDSupport_i.hxx"
-#include "SMESH_MEDFamily_i.hxx"
+#include <utilities.h>
+#include <Utils_CorbaException.hxx>
 
-# include "Utils_ORB_INIT.hxx"
-# include "Utils_SINGLETON.hxx"
-# include "Utils_ExceptHandlers.hxx"
+#include <Utils_ORB_INIT.hxx>
+#include <Utils_SINGLETON.hxx>
+#include <Utils_ExceptHandlers.hxx>
+#include <SALOMEDS_wrap.hxx>
 
 extern "C"
 {
@@ -119,11 +120,12 @@ char *SMESH_MEDMesh_i::getName() throw(SALOME::SALOME_Exception)
   {
     SMESH_Gen_i*             gen = SMESH_Gen_i::GetSMESHGen();
     SALOMEDS::Study_var    study = gen->GetCurrentStudy();
-    SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, _mesh_i->_this());
+    SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( study, _mesh_i->_this());
     if ( meshSO->_is_nil() )
       return CORBA::string_dup("toto");
 
     CORBA::String_var name = meshSO->GetName();
+
     return CORBA::string_dup( name.in() );
   }
   catch(...)
@@ -856,50 +858,8 @@ void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
   if (_meshId != "")
   {
     MESSAGE("Mesh already in Study");
-    THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
-                                 SALOME::BAD_PARAM);
-  };
-
-  /*
-   * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
-   * 
-   * // Create SComponent labelled 'MED' if it doesn't already exit
-   * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
-   * if ( CORBA::is_nil(medfather) ) 
-   * {
-   * MESSAGE("Add Component MED");
-   * medfather = myBuilder->NewComponent("MED");
-   * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
-   * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
-   * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
-   * aName->SetValue("MED");
-   * 
-   * myBuilder->DefineComponentInstance(medfather,myIor);
-   * 
-   * } ;
-   * 
-   * MESSAGE("Add a mesh Object under MED");
-   * myBuilder->NewCommand();
-   * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
-   * 
-   * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-   * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
-   * CORBA::ORB_var &orb = init(0,0);
-   * CORBA::String_var iorStr = orb->object_to_string(myIor);
-   * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.in());
-   * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
-   * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
-   * aIOR->SetValue(iorStr.c_str());
-   * 
-   * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
-   * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
-   * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
-   * aName->SetValue(_mesh_i->getName().c_str());
-   * 
-   * _meshId = newObj->GetID();
-   * myBuilder->CommitCommand();
-   * 
-   */
+    THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", SALOME::BAD_PARAM);
+  }
   END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
 }
 
index 0709265bf2aab9c7d49509f93d010808abad7b76..e6cbf330f1db40cc2d52a9338236f06ef9c4dc73 100644 (file)
@@ -29,8 +29,6 @@
 
 #include "SMESH_MeshEditor_i.hxx"
 
-#include "DriverMED_R_SMESHDS_Mesh.h"
-#include "DriverMED_W_SMESHDS_Mesh.h"
 #include "SMDS_EdgePosition.hxx"
 #include "SMDS_ElemIterator.hxx"
 #include "SMDS_FacePosition.hxx"
 #include "SMDS_MeshVolume.hxx"
 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
 #include "SMDS_SetIterator.hxx"
-#include "SMDS_SetIterator.hxx"
 #include "SMDS_VolumeTool.hxx"
-#include "SMESHDS_Command.hxx"
-#include "SMESHDS_CommandType.hxx"
 #include "SMESHDS_Group.hxx"
 #include "SMESHDS_GroupOnGeom.hxx"
 #include "SMESH_ControlsDef.hxx"
 #include "SMESH_Filter_i.hxx"
-#include "SMESH_Filter_i.hxx"
-#include "SMESH_Gen_i.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Group.hxx"
 #include "SMESH_Group_i.hxx"
-#include "SMESH_Group_i.hxx"
-#include "SMESH_MEDMesh_i.hxx"
-#include "SMESH_MeshEditor.hxx"
 #include "SMESH_MeshPartDS.hxx"
 #include "SMESH_MesherHelper.hxx"
-#include "SMESH_PreMeshInfo.hxx"
-#include "SMESH_PythonDump.hxx"
 #include "SMESH_PythonDump.hxx"
 #include "SMESH_subMeshEventListener.hxx"
 #include "SMESH_subMesh_i.hxx"
-#include "SMESH_subMesh_i.hxx"
 
-#include "utilities.h"
-#include "Utils_ExceptHandlers.hxx"
-#include "Utils_CorbaException.hxx"
+#include <utilities.h>
+#include <Utils_ExceptHandlers.hxx>
+#include <Utils_CorbaException.hxx>
+#include <SALOMEDS_wrap.hxx>
 
 #include <BRepAdaptor_Surface.hxx>
 #include <BRep_Tool.hxx>
@@ -112,7 +100,7 @@ namespace MeshEditor_I {
     SMDSAbs_ElementType myPreviewType; // type to show
     //!< Constructor
     TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
-      _isShapeToMesh = (_id =_studyId =_idDoc = 0);
+      _isShapeToMesh = (_id =_studyId = 0);
       _myMeshDS  = new SMESHDS_Mesh( _id, true );
       myPreviewType = previewElements;
     }
@@ -709,6 +697,11 @@ SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_arr
   return anIDSourceVar._retn();
 }
 
+bool SMESH_MeshEditor_i::IsTemporaryIDSource( SMESH::SMESH_IDSource_ptr& idSource )
+{
+  return SMESH::DownCast<SMESH_MeshEditor_i::_IDSource*>( idSource );
+}
+
 void SMESH_MeshEditor_i::deleteAuxIDSources()
 {
   std::list< _IDSource* >::iterator idSrcIt = myAuxIDSources.begin();
@@ -5281,10 +5274,10 @@ void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr th
 
 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
 {
-  SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
-  SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
-  SALOMEDS::Study_var study = gen->GetCurrentStudy();
-  SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
+  SMESH_Gen_i*              gen = SMESH_Gen_i::GetSMESHGen();
+  SMESH::SMESH_Mesh_var    mesh = gen->CreateEmptyMesh();
+  SALOMEDS::Study_var     study = gen->GetCurrentStudy();
+  SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( study, mesh );
   gen->SetName( meshSO, theMeshName, "Mesh" );
   gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
 
index afe7656491c7ebdf32d3ab5f312796866f3377d8..9e88515ee16e2c37166fe1163258469596c8ecda 100644 (file)
 #include "SMESH_subMesh_i.hxx"
 
 #include <OpUtil.hxx>
+#include <SALOMEDS_Attributes_wrap.hxx>
+#include <SALOMEDS_wrap.hxx>
 #include <SALOME_NamingService.hxx>
 #include <Utils_CorbaException.hxx>
 #include <Utils_ExceptHandlers.hxx>
 #include <Utils_SINGLETON.hxx>
 #include <utilities.h>
+
 #include <GEOMImpl_Types.hxx>
+#include <GEOM_GenericObjPtr.h>
 
 // OCCT Includes
 #include <BRep_Builder.hxx>
@@ -92,9 +96,6 @@ using SMESH::TPythonDump;
 
 int SMESH_Mesh_i::_idGenerator = 0;
 
-//To disable automatic genericobj management, the following line should be commented.
-//Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
-#define WITHGENERICOBJ
 
 //=============================================================================
 /*!
@@ -108,10 +109,10 @@ SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
 : SALOME::GenericObj_i( thePOA )
 {
   MESSAGE("SMESH_Mesh_i");
-  _impl = NULL;
-  _gen_i = gen_i;
-  _id = _idGenerator++;
-  _studyId = studyId;
+  _impl        = NULL;
+  _gen_i       = gen_i;
+  _id          = _idGenerator++;
+  _studyId     = studyId;
   _preMeshInfo = NULL;
 }
 
@@ -125,50 +126,38 @@ SMESH_Mesh_i::~SMESH_Mesh_i()
 {
   MESSAGE("~SMESH_Mesh_i");
 
-#ifdef WITHGENERICOBJ
   // destroy groups
   map<int, SMESH::SMESH_GroupBase_ptr>::iterator itGr;
-  for (itGr = _mapGroups.begin(); itGr != _mapGroups.end(); itGr++) {
-    if ( CORBA::is_nil( itGr->second ))
-      continue;
-    SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>(SMESH_Gen_i::GetServant(itGr->second).in());
-    if (aGroup) {
-      // this method is called from destructor of group (PAL6331)
+  for (itGr = _mapGroups.begin(); itGr != _mapGroups.end(); itGr++)
+    if (SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>(itGr->second))
+    {
+      // _impl->RemoveGroup() is called by ~SMESH_GroupBase_i() (PAL6331)
       //_impl->RemoveGroup( aGroup->GetLocalID() );
       aGroup->myMeshServant = 0;
       aGroup->UnRegister();
     }
-  }
   _mapGroups.clear();
 
   // destroy submeshes
   map<int, SMESH::SMESH_subMesh_ptr>::iterator itSM;
-  for ( itSM = _mapSubMeshIor.begin(); itSM != _mapSubMeshIor.end(); itSM++ ) {
-    if ( CORBA::is_nil( itSM->second ))
-      continue;
-    SMESH_subMesh_i* aSubMesh = dynamic_cast<SMESH_subMesh_i*>(SMESH_Gen_i::GetServant(itSM->second).in());
-    if (aSubMesh) {
+  for ( itSM = _mapSubMeshIor.begin(); itSM != _mapSubMeshIor.end(); itSM++ )
+    if ( SMESH_subMesh_i* aSubMesh = SMESH::DownCast<SMESH_subMesh_i*>( itSM->second ))
+    {
       aSubMesh->UnRegister();
     }
-  }
   _mapSubMeshIor.clear();
 
   // destroy hypotheses
   map<int, SMESH::SMESH_Hypothesis_ptr>::iterator itH;
-  for ( itH = _mapHypo.begin(); itH != _mapHypo.end(); itH++ ) {
-    if ( CORBA::is_nil( itH->second ))
-      continue;
-    SMESH_Hypothesis_i* aHypo = dynamic_cast<SMESH_Hypothesis_i*>(SMESH_Gen_i::GetServant(itH->second).in());
-    if (aHypo) {
+  for ( itH = _mapHypo.begin(); itH != _mapHypo.end(); itH++ )
+    if ( SMESH_Hypothesis_i* aHypo = SMESH::DownCast<SMESH_Hypothesis_i*>( itH->second ))
+    {
       aHypo->UnRegister();
     }
-  }
   _mapHypo.clear();
-#endif
 
   delete _impl; _impl = NULL;
-
-  if ( _preMeshInfo ) delete _preMeshInfo; _preMeshInfo = NULL;
+  delete _preMeshInfo; _preMeshInfo = NULL;
 }
 
 //=============================================================================
@@ -280,6 +269,8 @@ void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
   catch(SALOME_Exception & S_ex) {
     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
   }
+  _impl->GetMeshDS()->Modified();
+
   TPythonDump() <<  _this() << ".Clear()";
 }
 
@@ -302,6 +293,9 @@ void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
   catch(SALOME_Exception & S_ex) {
     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
   }
+  _impl->GetMeshDS()->Modified();
+
+  TPythonDump() <<  _this() << ".ClearSubMesh( " << ShapeID << " )";
 }
 
 //=============================================================================
@@ -621,9 +615,7 @@ SMESH_Hypothesis::Hypothesis_Status
     status = _impl->AddHypothesis(myLocSubShape, hypId);
     if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
       _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
-#ifdef WITHGENERICOBJ
       _mapHypo[hypId]->Register();
-#endif
       // assure there is a corresponding submesh
       if ( !_impl->IsMainShape( myLocSubShape )) {
         int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
@@ -827,7 +819,7 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap
     if ( subMesh->_is_nil() )
       subMesh = createSubMesh( aSubShapeObject );
     if ( _gen_i->CanPublishInStudy( subMesh )) {
-      SALOMEDS::SObject_var aSO =
+      SALOMEDS::SObject_wrap aSO =
         _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
                                subMesh, aSubShapeObject, theName );
       if ( !aSO->_is_nil()) {
@@ -850,27 +842,31 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap
 //=============================================================================
 
 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
-     throw (SALOME::SALOME_Exception)
+  throw (SALOME::SALOME_Exception)
 {
   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
   if ( theSubMesh->_is_nil() )
     return;
 
   GEOM::GEOM_Object_var aSubShapeObject;
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() )  {
     // Remove submesh's SObject
-    SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
+    SALOMEDS::SObject_wrap anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
     if ( !anSO->_is_nil() ) {
       long aTag = SMESH_Gen_i::GetRefOnShapeTag();
-      SALOMEDS::SObject_var anObj, aRef;
-      if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
-        aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
-
-//       if ( aSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
-//         aSubShapeObject = theSubMesh->GetSubShape();
+      SALOMEDS::SObject_wrap anObj, aRef;
+      if ( anSO->FindSubObject( aTag, anObj.inout() ) &&
+           anObj->ReferencedObject( aRef.inout() ))
+      {
+        CORBA::Object_var obj = aRef->GetObject();
+        aSubShapeObject = GEOM::GEOM_Object::_narrow( obj );
+      }
+      // if ( aSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
+      //   aSubShapeObject = theSubMesh->GetSubShape();
 
-      aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
+      SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
+      builder->RemoveObjectWithChildren( anSO );
 
       // Update Python script
       TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
@@ -900,7 +896,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType
     SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
 
   if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
-    SALOMEDS::SObject_var aSO =
+    SALOMEDS::SObject_wrap aSO =
       _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
                            aNewGroup, GEOM::GEOM_Object::_nil(), theName);
     if ( !aSO->_is_nil()) {
@@ -937,7 +933,7 @@ SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType    theElemType,
       ( createGroup( theElemType, theName, aShape ));
 
     if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
-      SALOMEDS::SObject_var aSO =
+      SALOMEDS::SObject_wrap aSO =
         _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
                              aNewGroup, theGeomObj, theName);
       if ( !aSO->_is_nil()) {
@@ -987,7 +983,7 @@ SMESH_Mesh_i::CreateGroupFromFilter(SMESH::ElementType theElemType,
 
   if ( _gen_i->CanPublishInStudy( aNewGroup ) )
   {
-    SALOMEDS::SObject_var aSO =
+    SALOMEDS::SObject_wrap aSO =
       _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(), aNewGroup,
                            GEOM::GEOM_Object::_nil(), theName);
     if ( !aSO->_is_nil()) {
@@ -1017,16 +1013,17 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
   if ( !aGroup )
     return;
 
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() )  {
-    SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
+    SALOMEDS::SObject_wrap aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
 
     if ( !aGroupSO->_is_nil() ) {
       // Update Python script
       TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
 
       // Remove group's SObject
-      aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
+      SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
+      builder->RemoveObjectWithChildren( aGroupSO );
     }
   }
 
@@ -1147,6 +1144,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the
          theGroup1->GetType() != theGroup2->GetType() )
       return SMESH::SMESH_Group::_nil();
 
+    TPythonDump pyDump;
+
     // Create Union
     SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
     if ( aResGrp->_is_nil() )
@@ -1173,15 +1172,10 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the
 
     aResGrp->Add( aResIds );
 
-    // Clear python lines, created by CreateGroup() and Add()
-    SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-    _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-    _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-
     // Update Python script
-    TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
-                  << theGroup1 << ", " << theGroup2 << ", '"
-                  << theName << "' )";
+    pyDump << aResGrp << " = " << _this() << ".UnionGroups( "
+           << theGroup1 << ", " << theGroup2 << ", '"
+           << theName << "' )";
 
     return aResGrp._retn();
   }
@@ -1239,6 +1233,8 @@ throw (SALOME::SALOME_Exception)
       }
     }
 
+    TPythonDump pyDump;
+
     // Create group
     SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
     if ( aResGrp->_is_nil() )
@@ -1248,22 +1244,13 @@ throw (SALOME::SALOME_Exception)
     SMESH::long_array_var aResIds = new SMESH::long_array;
     aResIds->length( anIds.size() );
     
-    //NCollection_Map< int >::Iterator anIter( anIds );
-    for ( int i = 0; i<anIds.size(); i++ )
-    {
+    for ( size_t i = 0; i<anIds.size(); i++ )
       aResIds[ i ] = anIds[i];
-    }
     aResGrp->Add( aResIds );
 
-    // Clear python lines, created by CreateGroup() and Add()
-    SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-
     // Update Python script
-    
-    TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
-                  << &theGroups << ", '" << theName << "' )";
+    pyDump << aResGrp << " = " << _this() << ".UnionListOfGroups( "
+           << &theGroups << ", '" << theName << "' )";
 
     return aResGrp._retn();
   }
@@ -1281,7 +1268,7 @@ throw (SALOME::SALOME_Exception)
 //=============================================================================
 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
                                                       SMESH::SMESH_GroupBase_ptr theGroup2,
-                                                      const char* theName )
+                                                      const char*                theName )
   throw (SALOME::SALOME_Exception)
 {
   if ( _preMeshInfo )
@@ -1291,6 +1278,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr
        theGroup1->GetType() != theGroup2->GetType() )
     return SMESH::SMESH_Group::_nil();
 
+  TPythonDump pyDump;
+
   // Create Intersection
   SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
   if ( aResGrp->_is_nil() )
@@ -1305,27 +1294,19 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr
     aMap1.Add( anIds1[ i1 ] );
 
   TColStd_SequenceOfInteger aSeq;
-
   for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
     if ( aMap1.Contains( anIds2[ i2 ] ) )
       aSeq.Append( anIds2[ i2 ] );
 
   SMESH::long_array_var aResIds = new SMESH::long_array;
   aResIds->length( aSeq.Length() );
-
-  for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+  for ( size_t resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
     aResIds[ resI ] = aSeq( resI + 1 );
-
   aResGrp->Add( aResIds );
 
-  // Clear python lines, created by CreateGroup() and Add()
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-  _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-  _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-
   // Update Python script
-  TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
-                << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
+  pyDump << aResGrp << " = " << _this() << ".IntersectGroups( "
+         << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
 
   return aResGrp._retn();
 }
@@ -1394,6 +1375,8 @@ SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups,
         anIds.push_back( aCurrId );
     }
 
+    TPythonDump pyDump;
+
     // Create group
     SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
     if ( aResGrp->_is_nil() )
@@ -1403,22 +1386,13 @@ SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups,
     SMESH::long_array_var aResIds = new SMESH::long_array;
     aResIds->length( anIds.size() );
     
-    //NCollection_Map< int >::Iterator aListIter( anIds );
-    for ( int i = 0; i<anIds.size(); i++ )
-    {
+    for ( size_t i = 0; i<anIds.size(); i++ )
       aResIds[ i ] = anIds[i];
-    }
     aResGrp->Add( aResIds );
 
-    // Clear python lines, created by CreateGroup() and Add()
-    SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-
     // Update Python script
-    
-    TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
-                  << &theGroups << ", '" << theName << "' )";
+    pyDump << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
+           << &theGroups << ", '" << theName << "' )";
 
     return aResGrp._retn();
   }
@@ -1446,6 +1420,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr
        theGroup1->GetType() != theGroup2->GetType() )
     return SMESH::SMESH_Group::_nil();
 
+  TPythonDump pyDump;
+
   // Perform Cutting
   SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
   if ( aResGrp->_is_nil() )
@@ -1469,18 +1445,12 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr
 
   for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
     aResIds[ resI ] = aSeq( resI + 1 );
-
   aResGrp->Add( aResIds );
 
-  // Clear python lines, created by CreateGroup() and Add()
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-  _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-  _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
-
   // Update Python script
-  TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
-                << theGroup1 << ", " << theGroup2 << ", '"
-                << theName << "' )";
+  pyDump << aResGrp << " = " << _this() << ".CutGroups( "
+         << theGroup1 << ", " << theGroup2 << ", '"
+         << theName << "' )";
 
   return aResGrp._retn();
 }
@@ -1567,6 +1537,8 @@ SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
       }
     }
 
+    TPythonDump pyDump;
+
     // Create group
     SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
     if ( aResGrp->_is_nil() )
@@ -1577,21 +1549,13 @@ SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
     aResIds->length( anIds.size() );
     
     for (int i=0; i<anIds.size(); i++ )
-    {
       aResIds[ i ] = anIds[i];
-    }
     aResGrp->Add( aResIds );
 
-    // Clear python lines, created by CreateGroup() and Add()
-    SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-
     // Update Python script
-
-    TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
-                  << &theMainGroups << ", " << &theToolGroups << ", '"
-                  << theName << "' )";
+    pyDump << aResGrp << " = " << _this() << ".CutListOfGroups( "
+           << &theMainGroups << ", " << &theToolGroups << ", '"
+           << theName << "' )";
     
     return aResGrp._retn();
   }
@@ -1736,6 +1700,8 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
 
     // Create group
 
+    TPythonDump pyDump;
+
     SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
     if ( aResGrp->_is_nil() )
       return SMESH::SMESH_Group::_nil();
@@ -1748,15 +1714,9 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
       aResIds[ i ] = aResultIds[i];
     aResGrp->Add( aResIds );
 
-    // Remove strings corresponding to group creation
-    SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-    _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
-
     // Update Python script
-    
-    TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
-                  << &theGroups << ", " << theElemType << ", '" << theName << "' )";
+    pyDump << aResGrp << " = " << _this() << ".CreateDimGroup( "
+           << &theGroups << ", " << theElemType << ", '" << theName << "' )";
 
     return aResGrp._retn();
   }
@@ -1778,13 +1738,13 @@ void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
   if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
     return;
   // group SO
-  SALOMEDS::Study_var   study  = _gen_i->GetCurrentStudy();
-  SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
+  SALOMEDS::Study_var   study   = _gen_i->GetCurrentStudy();
+  SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
   if ( groupSO->_is_nil() )
     return;
   // group indices
   GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
-  GEOM::GEOM_IGroupOperations_var groupOp =
+  GEOM::GEOM_IGroupOperations_wrap groupOp =
     geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
   GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
 
@@ -1832,7 +1792,7 @@ TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
   // get geom group
   SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
   if ( study->_is_nil() ) return newShape; // means "not changed"
-  SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
+  SALOMEDS::SObject_wrap groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
   if ( !groupSO->_is_nil() )
   {
     CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
@@ -1842,9 +1802,9 @@ TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
     // get indices of group items
     set<int> curIndices;
     GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
-    GEOM::GEOM_IGroupOperations_var groupOp =
+    GEOM::GEOM_IGroupOperations_wrap groupOp =
       geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
-    GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
+    GEOM::ListOfLong_var   ids = groupOp->GetObjects( geomGroup );
     for ( int i = 0; i < ids->length(); ++i )
       curIndices.insert( ids[i] );
 
@@ -1859,7 +1819,7 @@ TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
     TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
     geomClient->RemoveShapeFromBuffer( groupIOR );
     newShape = _gen_i->GeomObjectToShape( geomGroup );
-  }    
+  }
 
   if ( newShape.IsNull() ) {
     // geom group becomes empty - return empty compound
@@ -2084,10 +2044,10 @@ void SMESH_Mesh_i::CheckGeomGroupModif()
         if ( _mapGroups.find( oldID ) == _mapGroups.end() )
           continue;
         // get group name
-        SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
-        CORBA::String_var     name    = groupSO->GetName();
+        SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
+        CORBA::String_var      name    = groupSO->GetName();
         // update
-        SMESH_GroupBase_i* group_i    = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
+        SMESH_GroupBase_i*  group_i    = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
         int newID;
         if ( group_i && _impl->AddGroup( geomType->second, name.in(), newID, geom._shape ))
           group_i->changeLocalId( newID );
@@ -2101,7 +2061,7 @@ void SMESH_Mesh_i::CheckGeomGroupModif()
   // Update icons
 
   CORBA::Long newNbEntities = NbNodes() + NbElements();
-  list< SALOMEDS::SObject_var > soToUpdateIcons;
+  list< SALOMEDS::SObject_wrap > soToUpdateIcons;
   if ( newNbEntities != nbEntities )
   {
     // Add all SObjects with icons to soToUpdateIcons
@@ -2116,7 +2076,7 @@ void SMESH_Mesh_i::CheckGeomGroupModif()
       soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
   }
 
-  list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
+  list< SALOMEDS::SObject_wrap >::iterator so = soToUpdateIcons.begin();
   for ( ; so != soToUpdateIcons.end(); ++so )
     _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
 }
@@ -2156,15 +2116,15 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase
   _mapGroups.erase( anId );
 
   SALOMEDS::StudyBuilder_var builder;
-  SALOMEDS::SObject_var aGroupSO;
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
-  if ( !aStudy->_is_nil() )  {
-    builder = aStudy->NewBuilder();
+  SALOMEDS::SObject_wrap      aGroupSO;
+  SALOMEDS::Study_var        aStudy = _gen_i->GetCurrentStudy();
+  if ( !aStudy->_is_nil() ) {
+    builder  = aStudy->NewBuilder();
     aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
-    if ( !aGroupSO->_is_nil() ) {
-
+    if ( !aGroupSO->_is_nil() )
+    {
       // remove reference to geometry
-      SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
+      SALOMEDS::ChildIterator_wrap chItr = aStudy->NewChildIterator(aGroupSO);
       for ( ; chItr->More(); chItr->Next() )
         // Remove group's child SObject
         builder->RemoveObject( chItr->Value() );
@@ -2180,28 +2140,24 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase
         const int isEmpty = ( elemTypes->length() == 0 );
         if ( !isEmpty )
         {
-          SALOMEDS::GenericAttribute_var anAttr =
+          SALOMEDS::GenericAttribute_wrap anAttr =
             builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
-          SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
+          SALOMEDS::AttributePixMap_wrap pm = anAttr;
           pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
         }
       }
     }
   }
 
-  // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
-  SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
-  aGroupImpl->Register();
-  // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
-
   // remember new group in own map
   aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
   _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
 
   // register CORBA object for persistence
-  /*int nextId =*/ _gen_i->RegisterObject( aGroup );
+  _gen_i->RegisterObject( aGroup );
 
-  builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
+  CORBA::String_var ior = _gen_i->GetORB()->object_to_string( aGroup );
+  builder->SetIOR( aGroupSO, ior.in() );
 
   return aGroup._retn();
 }
@@ -2339,11 +2295,6 @@ SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType
     else
       aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
 
-    // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
-    SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
-    aGroupImpl->Register();
-    // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
-
     aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
     _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
 
@@ -2731,25 +2682,23 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char*    file,
   // Perform Export
   PrepareForWriting(file, overwrite);
   string aMeshName = "Mesh";
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() ) {
-    SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
+    SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
     if ( !aMeshSO->_is_nil() ) {
       CORBA::String_var name = aMeshSO->GetName();
       aMeshName = name;
       // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
       if ( !aStudy->GetProperties()->IsLocked() )
       {
-        SALOMEDS::GenericAttribute_var anAttr;
+        SALOMEDS::GenericAttribute_wrap anAttr;
         SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-        SALOMEDS::AttributeExternalFileDef_var aFileName;
         anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
-        aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
+        SALOMEDS::AttributeExternalFileDef_wrap aFileName = anAttr;
         ASSERT(!aFileName->_is_nil());
         aFileName->SetValue(file);
-        SALOMEDS::AttributeFileType_var aFileType;
         anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
-        aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
+        SALOMEDS::AttributeFileType_wrap aFileType = anAttr;
         ASSERT(!aFileType->_is_nil());
         aFileType->SetValue("FICHIERMED");
       }
@@ -2924,9 +2873,9 @@ void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
   PrepareForWriting(file, overwrite);
 
   string aMeshName = "Mesh";
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() ) {
-    SALOMEDS::SObject_var SO = _gen_i->ObjectToSObject( aStudy, meshPart );
+    SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( aStudy, meshPart );
     if ( !SO->_is_nil() ) {
       CORBA::String_var name = SO->GetName();
       aMeshName = name;
@@ -3803,7 +3752,6 @@ CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
   if(!elem)
     return -1;
 
-  //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
   ::SMESH_MeshEditor aMeshEditor(_impl);
   int index = aMeshEditor.FindShape( elem );
   if(index>0)
@@ -4146,7 +4094,7 @@ SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
 
 void SMESH_Mesh_i::CreateGroupServants()
 {
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
 
   set<int> addedIDs;
   ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
@@ -4172,10 +4120,6 @@ void SMESH_Mesh_i::CreateGroupServants()
       aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
     }
 
-    // To ensure correct mapping of servant and correct reference counting in GenericObj_i
-    SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
-    aGroupImpl->Register();
-
     SMESH::SMESH_GroupBase_var groupVar =
       SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
     _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
@@ -4255,7 +4199,7 @@ void SMESH_Mesh_i::checkGroupNames()
   if ( !nbGrp )
     return;
 
-  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
   if ( aStudy->_is_nil() )
     return; // nothing to do
   
@@ -4271,7 +4215,7 @@ void SMESH_Mesh_i::checkGroupNames()
     SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
     if ( !aGrp )
       continue;
-    SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
+    SALOMEDS::SObject_wrap aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
     if ( aGrpSO->_is_nil() )
       continue;
     // correct name of the mesh group if necessary
@@ -4315,7 +4259,7 @@ SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
   if(gen) {
     char *aParameters = GetParameters();
-    SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
+    SALOMEDS::Study_var aStudy = gen->GetCurrentStudy();
     if(!aStudy->_is_nil()) {
       SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); 
       if(aSections->length() > 0) {
index 7ecbe082382a2b20eb9677cdae5093d6a59c5810..816a29a972dbd3cbbbe9c42236f8a47359de4d12 100644 (file)
@@ -30,6 +30,9 @@
 #include <TColStd_SequenceOfAsciiString.hxx>
 #include <TColStd_HSequenceOfInteger.hxx>
 
+#include <SALOMEDS_wrap.hxx>
+#include <SALOMEDS_Attributes_wrap.hxx>
+
 #include <vector>
 #include <string>
 
@@ -642,14 +645,14 @@ void SMESH_NoteBook::ReplaceVariables()
         // this (and above) code can work wrong since nb of states can differ from nb of
         // dumped calls due to the fix of
         // issue 0021364:: Dump of netgen parameters has duplicate lines
-        SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
-        SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
-        SALOMEDS::SObject_var sobj = aStudy->FindObjectID( (*it).first.ToCString() );
-        CORBA::Object_var      obj = aGen->SObjectToObject( sobj );
+        SMESH_Gen_i *          aGen = SMESH_Gen_i::GetSMESHGen();
+        SALOMEDS::Study_var  aStudy = aGen->GetCurrentStudy();
+        SALOMEDS::SObject_wrap sobj = aStudy->FindObjectID( (*it).first.ToCString() );
+        CORBA::Object_var       obj = aGen->SObjectToObject( sobj );
         if ( SMESH_Hypothesis_i* h = SMESH::DownCast< SMESH_Hypothesis_i*>( obj ))
         {
           TState aCurrentState = aStates->GetCurrectState();
-          int argIndex = h->getParamIndex( aMethod, aCurrentState.size() );
+          int         argIndex = h->getParamIndex( aMethod, aCurrentState.size() );
           if ( 0 <= argIndex && argIndex < aCurrentState.size() &&
                !aCurrentState[argIndex].IsEmpty() )
             aCmd->SetArg( 1, aCurrentState[argIndex] );
@@ -681,22 +684,26 @@ void SMESH_NoteBook::InitObjectMap()
   if(!aGen)
     return;
   
-  SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
+  SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy();
   if(aStudy->_is_nil())
     return;
   
-  SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
+  CORBA::String_var compDataType = aGen->ComponentDataType();
+  SALOMEDS::SObject_wrap     aSO = aStudy->FindComponent( compDataType.in() );
   if(CORBA::is_nil(aSO))
     return;
   
-  SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
-  char* aParameters;
-  for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
-    SALOMEDS::SObject_var aSObject = Itr->Value();
-    SALOMEDS::GenericAttribute_var anAttr;
-    if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
-      aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
-      SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
+  SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
+  CORBA::String_var aParameters;
+  for( Itr->InitEx(true); Itr->More(); Itr->Next())
+  {
+    SALOMEDS::SObject_wrap aSObject = Itr->Value();
+    SALOMEDS::GenericAttribute_wrap anAttr;
+    if ( aSObject->FindAttribute( anAttr.inout(), "AttributeString"))
+    {
+      SALOMEDS::AttributeString_wrap strAttr = anAttr;
+      aParameters = strAttr->Value();
+      SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters.in());
       if(MYDEBUG) {
         cout<<"Entry : "<< aSObject->GetID()<<endl;
         cout<<"aParameters : "<<aParameters<<endl;
@@ -718,12 +725,13 @@ void SMESH_NoteBook::InitObjectMap()
       if(anObjType == "LayerDistribution")
         aState = new LayerDistributionStates();
       else
-        aState = new  SMESH_ObjectStates(anObjType);
+        aState = new SMESH_ObjectStates(anObjType);
 
       for(int i = 0; i < aSections->length(); i++) {
         TState aVars;
         SALOMEDS::ListOfStrings aListOfVars = aSections[i];
-        for(int j = 0;j<aListOfVars.length();j++) {
+        for ( int j = 0; j<aListOfVars.length(); j++)
+        {
           TCollection_AsciiString aVar(aListOfVars[j].in());
           if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
             aVar.InsertBefore(1,            SMESH::TVar::Quote() );
@@ -888,7 +896,7 @@ bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double&
 
   const char* aName = aVarName.ToCString();
   if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
-    theValue = aStudy->GetReal(aVarName.ToCString());
+    theValue = aStudy->GetReal(aName);
     ok = true;
   }
 
index 0a3d58614a4a37e466e9c35517af8492cc6d9f0b..c59cc186013b270b8767ee2b73e0e4fcaf94b8f6 100644 (file)
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_subMesh_i.hxx"
 
+#include <MED_Factory.hxx>
+
 #include <HDFarray.hxx>
 #include <HDFdataset.hxx>
 #include <HDFfile.hxx>
 #include <HDFgroup.hxx>
-#include <MED_Factory.hxx>
 #include <SALOMEDS_Tool.hxx>
+#include <SALOMEDS_wrap.hxx>
 
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
@@ -143,8 +145,8 @@ namespace
       SALOMEDS::Study_var study = gen->GetCurrentStudy();
       if ( !study->_is_nil() && study->StudyId() == mesh->GetStudyId() )
       {
-        SALOMEDS::SObject_var meshSO = gen->ObjectToSObject(study, mesh->_this() );
-        CORBA::Object_var obj = gen->GetNS()->Resolve( "/Kernel/Session" );
+        SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject(study, mesh->_this() );
+        CORBA::Object_var        obj = gen->GetNS()->Resolve( "/Kernel/Session" );
         _session = SALOME::Session::_narrow( obj );
         if ( !meshSO->_is_nil() && !_session->_is_nil() )
         {
@@ -929,6 +931,7 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
       aDataset->ReadFromDisk( isModified );
       aDataset->CloseOnDisk();
       _mesh->GetImpl().SetIsModified( bool(*isModified));
+      delete [] isModified;
     }
 
     bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
@@ -1165,9 +1168,9 @@ void SMESH_PreMeshInfo::ForgetAllData() const
   map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
   for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
   {
-    if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
+    if ( SMESH_subMesh_i* sm_i = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
     {
-      SMESH_PreMeshInfo* & info = sm->changePreMeshInfo();
+      SMESH_PreMeshInfo* & info = sm_i->changePreMeshInfo();
       delete info;
       info = NULL;
     }
@@ -1195,6 +1198,18 @@ void SMESH_PreMeshInfo::ForgetAllData() const
   // PreMeshInfo_CATCH;
 }
 
+//================================================================================
+/*!
+ * \brief remove all SMESH_PreMeshInfo fields from mesh and its child objects w/o data loading
+ */
+//================================================================================
+
+void SMESH_PreMeshInfo::ForgetAllData( SMESH_Mesh_i* mesh )
+{
+  if ( mesh && mesh->changePreMeshInfo() )
+    mesh->changePreMeshInfo()->ForgetAllData();
+}
+
 //================================================================================
 /*!
  * \brief Calls either FullLoadFromFile() or ForgetAllData() depending on preferences
@@ -1274,10 +1289,10 @@ void SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD(SALOMEDS::SComponent_ptr sme
   SALOMEDS::Study_var study = smeshComp->GetStudy();
   if ( theStudyIDToMeshCounter[ (int) study->StudyId() ] > 0 )
   {
-    SALOMEDS::ChildIterator_var itBig = study->NewChildIterator( smeshComp );
+    SALOMEDS::ChildIterator_wrap itBig = study->NewChildIterator( smeshComp );
     for ( ; itBig->More(); itBig->Next() ) {
-      SALOMEDS::SObject_var gotBranch = itBig->Value();
-      CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject( gotBranch );
+      SALOMEDS::SObject_wrap gotBranch = itBig->Value();
+      CORBA::Object_var       anObject = SMESH_Gen_i::SObjectToObject( gotBranch );
       if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( anObject ))
       {
         if ( mesh->changePreMeshInfo() )