Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MED / Med_Gen_i.cxx
index f9cb6e889e2bd9fa612c6edd43d20f7a01d4fcb7..0d4bb3060ac0ddd8beddbab00055d1922dec40ba 100755 (executable)
@@ -1,23 +1,23 @@
 //  MED MED : implemetation of MED idl descriptions
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //
@@ -26,7 +26,6 @@
 //  Module : MED
 //  $Header$
 
-using namespace std;
 #include "Med_Gen_i.hxx"
 
 #include "MEDMEM_Mesh_i.hxx"
@@ -39,7 +38,7 @@ using namespace std;
 #include "MEDMEM_Field.hxx"
 #include "MEDMEM_Med.hxx"
 #include "MEDMEM_MedMedDriver.hxx"
-#include "MEDMEM_MedMeshDriver.hxx"
+#include "MEDMEM_MedMeshDriver21.hxx"
 #include "MEDMEM_MedFieldDriver.hxx"
 #include "MEDMEM_define.hxx"
 #include "MEDMEM_DriversDef.hxx"
@@ -59,6 +58,7 @@ using namespace std;
 #include <HDFascii.hxx>
 #include "SALOMEDS_Tool.hxx"
 
+using namespace std;
 using namespace MEDMEM;
 
 // Initialisation des variables statiques
@@ -85,8 +85,8 @@ Med_Gen_i::Med_Gen_i()
 
 Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb,
                                PortableServer::POA_ptr poa,
-                               PortableServer::ObjectId * contId, 
-                               const char *instanceName, 
+                               PortableServer::ObjectId * contId,
+                               const char *instanceName,
                                const char *interfaceName) :
   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
 {
@@ -116,14 +116,14 @@ SALOMEDS::Study_var Med_Gen_i::studyName2Study(const char* studyName)
                                  SALOME::BAD_PARAM);
 
   // Get StudyManager Reference, current study,
-  
+
   CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
   SALOMEDS::StudyManager_var myStudyManager =
     SALOMEDS::StudyManager::_narrow(obj);
   if(CORBA::is_nil(myStudyManager))
     THROW_SALOME_CORBA_EXCEPTION("No StudyManager Found in NameService", \
                                  SALOME::BAD_PARAM);
-  
+
   SALOMEDS::Study_var myStudy =
     myStudyManager->GetStudyByName(myStudyName.c_str());
   if (CORBA::is_nil(myStudy))
@@ -143,7 +143,6 @@ void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy)
   throw(SALOME::SALOME_Exception)
 {
   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) )
@@ -152,7 +151,7 @@ void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy)
       // mpv: component label must be created in spite of "Locked" study flag state
       bool aLocked = myStudy->GetProperties()->IsLocked();
       if (aLocked) myStudy->GetProperties()->SetLocked(false);
-      
+
       MESSAGE("Add Component Med");
       medfather = myBuilder->NewComponent("MED");
       SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(medfather, "AttributeName");
@@ -164,18 +163,18 @@ void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy)
       SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
       if ( !Comp->_is_nil() ) {
        aName->SetValue( Comp->componentusername() );
-      }    
-      
+      }
+
       //           Utilisation de this  deconseillee par Paul ??
       //           myBuilder->DefineComponentInstance(medfather,POA_Engines::MED_Gen::_this());
       CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
       myBuilder->DefineComponentInstance(medfather,myO);
-      
+
       if (aLocked) myStudy->GetProperties()->SetLocked(true);
       myBuilder->CommitCommand();
-    } 
-  
-   
+    }
+
+
 }
 
 //=============================================================================
@@ -187,17 +186,20 @@ SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName,
                                 const char* studyName)
   throw(SALOME::SALOME_Exception)
 {
+        beginService("Med_Gen_i::readStructFile");
+
        SCRUTE(fileName);
        SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
-        if (!_duringLoad) addInStudy(myStudy) ;
+//         if (!_duringLoad) addInStudy(myStudy) ;
 
        SALOME_MED::MED_ptr myMedIOR ;
-       try 
+       try
        {
          // we create a new MED_i and add in study
          MED_i * myMedI = new MED_i();
          myMedIOR = myMedI->_this() ;
-         if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;        
+//       if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;
+//       if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR,fileName) ;
          // create ::MED object, read all and add in study !
          myMedI->init(myStudy,MED_DRIVER,fileName) ;
        }
@@ -208,7 +210,9 @@ SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName,
                 THROW_SALOME_CORBA_EXCEPTION("Unable to open File "\
                                                 ,SALOME::BAD_PARAM);
         }
-       return SALOME_MED::MED::_duplicate(myMedIOR) ;
+
+        endService("Med_Gen_i::readStructFile");
+       return myMedIOR;
 }
 
 //=============================================================================
@@ -221,19 +225,20 @@ void Med_Gen_i::readStructFileWithFieldType (const char* fileName,
                                             const char* studyName)
 throw (SALOME::SALOME_Exception)
 {
-  BEGIN_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
+        beginService("Med_Gen_i::readStructFileWithFieldType");
+
+       BEGIN_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
 
        SCRUTE(fileName);
        SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
-
        if (!_duringLoad) addInStudy(myStudy) ;
 
-       try 
+       try
        {
          // we create a new MED_i and add in study
          MED_i * myMedI = new MED_i();
          SALOME_MED::MED_ptr myMedIOR = myMedI->_this() ;
-         if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;        
+         if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR,fileName) ;
          // create ::MED object, read all and add in study !
          myMedI->initWithFieldType(myStudy,MED_DRIVER,fileName) ;
        }
@@ -245,6 +250,7 @@ throw (SALOME::SALOME_Exception)
                                                 ,SALOME::BAD_PARAM);
         }
 
+        endService("Med_Gen_i::readStructFileWithFieldType");
        END_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
 
 
@@ -260,22 +266,23 @@ SALOME_MED::MESH_ptr Med_Gen_i::readMeshInFile(const char* fileName,
                                               const char* meshName)
 throw (SALOME::SALOME_Exception)
 {
+        beginService("Med_Gen_i::readMeshInFile");
        SCRUTE(fileName);
        SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
 
-       if (!_duringLoad) addInStudy(myStudy) ;
+//     if (!_duringLoad) addInStudy(myStudy) ;
 
 // Creation du maillage
 
        MESH * myMesh= new MESH() ;
        myMesh->setName(meshName);
-       MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
+       MED_MESH_RDONLY_DRIVER21 myMeshDriver(fileName,myMesh);
        try
        {
                myMeshDriver.setMeshName(meshName);
                myMeshDriver.open();
        }
-        catch (const exception & ex)
+        catch (const std::exception & ex)
         {
                 MESSAGE("Exception Interceptee : ");
                 SCRUTE(ex.what());
@@ -287,7 +294,7 @@ throw (SALOME::SALOME_Exception)
                 MESSAGE("apres read");
                myMeshDriver.close();
        }
-        catch (const exception & ex)
+        catch (const std::exception & ex)
         {
                 MESSAGE("Exception Interceptee : ");
                 SCRUTE(ex.what());
@@ -300,10 +307,12 @@ throw (SALOME::SALOME_Exception)
        try
         {
          // add the mesh object in study
-         if (!_duringLoad) meshi->addInStudy(myStudy,mesh);
+//       if (!_duringLoad) meshi->addInStudy(myStudy,mesh);
        }
         catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
-        return SALOME_MED::MESH::_duplicate(mesh);
+
+        endService("Med_Gen_i::readMeshInFile");
+        return mesh;
 }
 //=============================================================================
 /*!
@@ -317,6 +326,7 @@ SALOME_MED::FIELD_ptr Med_Gen_i::readFieldInFile(const char* fileName,
                                               CORBA::Long iter)
 throw (SALOME::SALOME_Exception)
 {
+        beginService("Med_Gen_i::readFieldInFile");
        SCRUTE(fileName);
        string myStudyName(studyName);
 
@@ -325,7 +335,7 @@ throw (SALOME::SALOME_Exception)
                                  SALOME::BAD_PARAM);
 
        // Get StudyManager Reference, current study,
-       
+
        CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
        SALOMEDS::StudyManager_var myStudyManager =
                        SALOMEDS::StudyManager::_narrow(obj);
@@ -355,8 +365,8 @@ throw (SALOME::SALOME_Exception)
                SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
                if ( !Comp->_is_nil() ) {
                  aName->SetValue( Comp->componentusername() );
-               }    
-       
+               }
+
                 CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
                 myBuilder->DefineComponentInstance(medfather,myO);
 
@@ -365,14 +375,14 @@ throw (SALOME::SALOME_Exception)
 
         }
         else
-                        MESSAGE("MED dejà dans l étude");
+                        MESSAGE("MED dejà dans l étude");
 
        MESSAGE("Lecture du fichier ")
        SCRUTE(fileName);
 
 // Creation du champ
 
-       FIELD_ * myField= new FIELD_() ;
+       FIELD_ * myField;
         MED * mymed = new MED(MED_DRIVER,fileName) ;
        try
        {
@@ -398,15 +408,14 @@ throw (SALOME::SALOME_Exception)
 */
                myField = mymed->getField(fieldName,iter,ordre);
        }
-        catch (const exception & ex)
+        catch (const std::exception & ex)
         {
                 MESSAGE("Exception Interceptee : ");
                 SCRUTE(ex.what());
                 THROW_SALOME_CORBA_EXCEPTION("Unable to find this field in this file",SALOME::BAD_PARAM);
         };
-                       
+
        SUPPORT * fieldSupport;
-       SALOME_MED::SUPPORT_ptr mySupportIOR;
         try
        {
                fieldSupport=(SUPPORT *)myField->getSupport() ;
@@ -416,10 +425,8 @@ throw (SALOME::SALOME_Exception)
                myMesh->read();
                SCRUTE(myMesh->getName());
                fieldSupport->update();
-               SUPPORT_i * mySupportI = new SUPPORT_i(fieldSupport);
-               mySupportIOR=mySupportI->_this();
        }
-        catch (const exception & ex)
+        catch (const std::exception & ex)
         {
                 MESSAGE("Exception Interceptee : ");
                 SCRUTE(ex.what());
@@ -427,21 +434,21 @@ throw (SALOME::SALOME_Exception)
         };
 
        med_type_champ type = myField->getValueType() ;
-       switch (type) 
+       switch (type)
        {
-        case MED_FR::MED_INT32:        
+        case MED_EN::MED_INT32:
         {
-               try 
+               try
                {
                        ((FIELD<int>*)myField)->read() ;
-                       FIELDINT_i * myFieldIntI = new FIELDINT_i(mySupportIOR,(FIELD<int>*)myField);
-                       POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldIntI);
-                       SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
-                       if (!_duringLoad) myFieldIntI->addInStudy(myStudy,myFieldIOR) ;
-                       return SALOME_MED::FIELD::_duplicate(myFieldIOR);
+                       FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD<int>*)myField);
+                       SALOME_MED::FIELD_ptr myFieldIOR = myFieldIntI->_this();
+//                     if (!_duringLoad) myFieldIntI->addInStudy(myStudy,myFieldIOR) ;
+                       endService("Med_Gen_i::readFieldInFile");
+                       return myFieldIOR;
                }
                catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
-               catch (const exception & ex)
+               catch (const std::exception & ex)
                {
                                MESSAGE("Exception Interceptee : ");
                        SCRUTE(ex.what());
@@ -449,19 +456,19 @@ throw (SALOME::SALOME_Exception)
                };
                break;
         }
-        case MED_FR::MED_REEL64: 
+        case MED_EN::MED_REEL64:
         {
-               try 
+               try
                {
                        ((FIELD<double>*)myField)->read() ;
-                       FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i(mySupportIOR,(FIELD<double>*)myField);
-                       POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldDoubleI);
-                       SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
-                       if (!_duringLoad) myFieldDoubleI->addInStudy(myStudy,myFieldIOR) ;
-                       return SALOME_MED::FIELD::_duplicate(myFieldIOR);
+                       FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD<double>*)myField);
+                       SALOME_MED::FIELD_ptr myFieldIOR = myFieldDoubleI->_this() ;
+//                     if (!_duringLoad) myFieldDoubleI->addInStudy(myStudy,myFieldIOR) ;
+                       endService("Med_Gen_i::readFieldInFile");
+                       return myFieldIOR;
                }
                catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
-               catch (const exception & ex)
+               catch (const std::exception & ex)
                {
                                MESSAGE("Exception Interceptee : ");
                        SCRUTE(ex.what());
@@ -471,7 +478,7 @@ throw (SALOME::SALOME_Exception)
         }
        }
 
-       
+
 }
 
 
@@ -499,17 +506,18 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
 
   SALOMEDS::TMPFile_var aStreamFile;
   // Get a temporary directory to store a file
-  TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
+  TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
   // Create a list to store names of created files
   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
   TColStd_SequenceOfAsciiString aFileNames;
 
   CORBA::String_var aSaveStudyName("");
-  if (isMultiFile) aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
+  if (isMultiFile) aSaveStudyName = CORBA::string_dup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str());
 
   SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
   if (!CORBA::is_nil(aMedMeshFather)) {
     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
+    anIter->InitEx(1);
     for(; anIter->More(); anIter->Next()) {
       SALOMEDS::SObject_var aSO = anIter->Value();
       SALOMEDS::GenericAttribute_var anAttr;
@@ -517,7 +525,7 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
        CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
        SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
        if (! CORBA::is_nil(myMesh)) {
-         TCollection_AsciiString aName(strdup(aSaveStudyName));
+         TCollection_AsciiString aName(aSaveStudyName);
          aName += "_MEDMESH_";
          aName += myMesh->getName();
          aName += ".med";
@@ -533,6 +541,7 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD");
   if (!CORBA::is_nil(aMedFieldFather)) {
     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather);
+    anIter->InitEx(1);
     for(; anIter->More(); anIter->Next()) {
       SALOMEDS::SObject_var aSO = anIter->Value();
       SALOMEDS::GenericAttribute_var anAttr;
@@ -544,13 +553,13 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
          a<< myField->getOrderNumber();
          b<< myField->getIterationNumber();
 
-         TCollection_AsciiString aName(strdup(aSaveStudyName));
+         TCollection_AsciiString aName(aSaveStudyName);
          aName += "_MEDFIELD_";
          aName += myField->getName();
          aName += "_ORDRE_";
-         aName += strdup(a.str().c_str());
+         aName += (char*)(a.str().c_str());
          aName += "_ITER_";
-         aName += strdup(b.str().c_str());
+         aName += (char*)(b.str().c_str());
          aName += ".med";
          MESSAGE("Save mesh with name "<<aName.ToCString());
          long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName());
@@ -570,7 +579,7 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
   // Return the created byte stream
   return aStreamFile._retn();
-  
+
   END_OF(LOC);
 }
 
@@ -579,20 +588,21 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
                                        bool isMultiFile) {
   const char* LOC = "Med_Gen_i::SaveASCII";
   BEGIN_OF(LOC);
-  
+
   SALOMEDS::TMPFile_var aStreamFile;
   // Get a temporary directory to store a file
-  TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
+  TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
   // Create a list to store names of created files
   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
   TColStd_SequenceOfAsciiString aFileNames;
-  
+
   CORBA::String_var aSaveStudyName("");
-  if (isMultiFile) aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
-  
+  if (isMultiFile) aSaveStudyName = CORBA::string_dup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str());
+
   SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
   if (!CORBA::is_nil(aMedMeshFather)) {
     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
+    anIter->InitEx(1);
     for(; anIter->More(); anIter->Next()) {
       SALOMEDS::SObject_var aSO = anIter->Value();
       SALOMEDS::GenericAttribute_var anAttr;
@@ -600,14 +610,14 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
        CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
        SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
        if (! CORBA::is_nil(myMesh)) {
-         TCollection_AsciiString aName(strdup(aSaveStudyName));
+         TCollection_AsciiString aName(aSaveStudyName);
          aName += "_MEDMESH_";
          aName += myMesh->getName();
          aName += ".med";
          MESSAGE("Save mesh with name "<<aName.ToCString());
          long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName());
          myMesh->write(driverId,"");
-         HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true);
+         HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true);
          aFileNames.Append(aName);
        }
       }
@@ -617,6 +627,7 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
   SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD");
   if (!CORBA::is_nil(aMedFieldFather)) {
     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather);
+    anIter->InitEx(1);
     for(; anIter->More(); anIter->Next()) {
       SALOMEDS::SObject_var aSO = anIter->Value();
       SALOMEDS::GenericAttribute_var anAttr;
@@ -628,18 +639,18 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
          a<< myField->getOrderNumber();
          b<< myField->getIterationNumber();
 
-         TCollection_AsciiString aName(strdup(aSaveStudyName));
+         TCollection_AsciiString aName(aSaveStudyName);
          aName += "_MEDFIELD_";
          aName += myField->getName();
          aName += "_ORDRE_";
-         aName += strdup(a.str().c_str());
+         aName += (char*)(a.str().c_str());
          aName += "_ITER_";
-         aName += strdup(b.str().c_str());
+         aName += (char*)(b.str().c_str());
          aName += ".med";
          MESSAGE("Save mesh with name "<<aName.ToCString());
          long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName());
          myField->write(driverId,"");
-         HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true);
+         HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true);
          aFileNames.Append(aName);
        }
       }
@@ -655,8 +666,6 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
   // Return the created byte stream
   return aStreamFile._retn();
-  
-  END_OF(LOC);
 }
 
 //=============================================================================
@@ -674,13 +683,11 @@ CORBA::Boolean Med_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
 
   // Get a temporary directory for a file
   TCollection_AsciiString aTmpDir =
-    (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
+    (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
   _saveFileName = CORBA::string_dup(aTmpDir.ToCString());
   SALOMEDS::ListOfFileNames_var aSeq =
     SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), isMultiFile);
   return true;
-
-  END_OF(LOC);
 }
 
 CORBA::Boolean Med_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
@@ -692,7 +699,7 @@ CORBA::Boolean Med_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
 
 //=============================================================================
 /*!
- *  CORBA: 
+ *  CORBA:
  */
 //=============================================================================
 
@@ -723,12 +730,12 @@ void Med_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
 char* Med_Gen_i::ComponentDataType()
 {
   MESSAGE("Med_Gen_i::ComponentDataType");
-  return strdup("MED") ; /* What is this type ? */
+  return CORBA::string_dup("MED") ; /* What is this type ? */
 }
-    
+
 //=============================================================================
 /*!
- *  CORBA: give a persistent reference of a transient object (for study save) 
+ *  CORBA: give a persistent reference of a transient object (for study save)
  */
 //=============================================================================
 
@@ -741,31 +748,31 @@ char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
   SCRUTE(IORString);
 
 
-  if (string(IORString).size()==0) return "_MED";
+  if (string(IORString).size()==0) return CORBA::string_dup("_MED");
   // Well, we know where put object (_saveFilename) and we know object (IORString)
   // cast object :
   CORBA::Object_var myIOR = _orb->string_to_object(IORString);
 
   // MED
   SALOME_MED::MED_var myMed = SALOME_MED::MED::_narrow(myIOR);
-  if (! CORBA::is_nil(myMed)) 
+  if (! CORBA::is_nil(myMed))
   {
         // nothing to save : Support will be saved inside the mesh
        string str_MedName="_MED Objet Med + /OBJ_MED/";
-        return strdup(str_MedName.c_str()) ; 
+        return CORBA::string_dup(str_MedName.c_str()) ;
   }
+
   // MESH
   SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
-  if (! CORBA::is_nil(myMesh)) 
+  if (! CORBA::is_nil(myMesh))
   {
     CORBA::String_var aName((string("_MEDMESH_")+ myMesh->getName() + ".med").c_str());
-    return strdup(aName._retn()) ;
+    return aName._retn() ;
   }
-    
+
   // SUPPORT
   SALOME_MED::SUPPORT_var mySupport = SALOME_MED::SUPPORT::_narrow(myIOR);
-  if (! CORBA::is_nil(mySupport)) 
+  if (! CORBA::is_nil(mySupport))
   {
         // nothing to save : Support will be saved inside the mesh
        string str_SupportName;
@@ -781,11 +788,11 @@ char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                 THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\
                                               ,SALOME::INTERNAL_ERROR);
        }
-    return strdup(("_MED"+str_SupportName).c_str());
+    return CORBA::string_dup(("_MED"+str_SupportName).c_str());
   }
-    
+
   SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
-  if (! CORBA::is_nil(myField)) 
+  if (! CORBA::is_nil(myField))
   {
     string str_FieldName;
     ostringstream a,b;
@@ -795,13 +802,11 @@ char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                             string("_ORDRE_")+a.str()+
                             string("_ITER_")+b.str() +
                             ".med").c_str());
-    return strdup(aName._retn());
+    return aName._retn();
   }
 
   //THROW_SALOME_CORBA_EXCEPTION("Unable to save IOR",SALOME::BAD_PARAM);
-  return "_MED";
-
-  END_OF(LOC) ;
+  return CORBA::string_dup("_MED");
 }
 
 //=============================================================================
@@ -818,12 +823,12 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
 {
   const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ;
   BEGIN_OF(LOC) ;
-  TCollection_AsciiString aTmpDir(CORBA::string_dup(_saveFileName.c_str()));
+  TCollection_AsciiString aTmpDir((char*)(_saveFileName.c_str()));
 
   TCollection_AsciiString aSaveStudyName("");
-  if (isMultiFile) aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
+  if (isMultiFile) aSaveStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()).c_str();
 
-  if (strcmp(aLocalPersistentID, "Objet Med + /OBJ_MED/") == 0) return strdup(""); // MED
+  if (strcmp(aLocalPersistentID, "Objet Med + /OBJ_MED/") == 0) return CORBA::string_dup(""); // MED
 
   if (strncmp(aLocalPersistentID, "_MEDMESH_",9) == 0) {// MESH
     MESH * myMesh= new MESH() ;
@@ -835,18 +840,18 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
 
     char* aFileName;
     if (isASCII) {
-      char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + strdup(aLocalPersistentID)).ToCString());
+      char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString());
       aFileName = new char[strlen(aResultPath) + 19];
       sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath);
       delete(aResultPath);
-    } else aFileName = strdup((aTmpDir + aSaveStudyName + strdup(aLocalPersistentID)).ToCString());
-    MED_MESH_RDONLY_DRIVER myMeshDriver(aFileName,myMesh);
+    } else aFileName = CORBA::string_dup((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString());
+    MED_MESH_RDONLY_DRIVER21 myMeshDriver(aFileName,myMesh);
     try
       {
        myMeshDriver.setMeshName(aMeshName);
        myMeshDriver.open();
       }
-    catch (const exception & ex)
+    catch (const std::exception & ex)
       {
        MESSAGE("Exception Interceptee : ");
        SCRUTE(ex.what());
@@ -858,7 +863,7 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
        MESSAGE("apres read");
        myMeshDriver.close();
       }
-    catch (const exception & ex)
+    catch (const std::exception & ex)
       {
        MESSAGE("Exception Interceptee : ");
        SCRUTE(ex.what());
@@ -874,18 +879,16 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
     if (isASCII) {
       SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
       aFilesToRemove->length(1);
-      aFilesToRemove[0] = strdup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName))]));
-      SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName), aFilesToRemove, true);
+      aFilesToRemove[0] = CORBA::string_dup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str())]));
+      SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str(), aFilesToRemove, true);
     }
     delete(aFileName);
     return(CORBA::string_dup(_orb->object_to_string(mesh)));
   } else if (strncmp(aLocalPersistentID, "_MEDFIELD_",14) == 0) { // FIELD
-    return(strdup("")); // not implemented yet
+    return(CORBA::string_dup("")); // not implemented yet
   }
 
-  return strdup("");
-
-  END_OF(LOC) ;
+  return CORBA::string_dup("");
 }
 
 //=============================================================================
@@ -931,7 +934,7 @@ SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
     if ( !Comp->_is_nil() ) {
       aName->SetValue( Comp->componentusername() );
-    }    
+    }
     aBuilder->DefineComponentInstance(aFather, MED_Gen::_this());
   }
 
@@ -940,7 +943,7 @@ SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
     aMesh->addInStudy(theStudy, aMesh);
     SALOMEDS::SObject_var aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject));
   } else {
-    if (!theSObject->ReferencedObject(aResultSO)) 
+    if (!theSObject->ReferencedObject(aResultSO))
       THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM);
   }
 //    aBuilder->Addreference(theObject, aResultSO);
@@ -979,30 +982,33 @@ SALOMEDS::TMPFile* Med_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::L
   // Try to get GEOM_Shape object by given SObject
   SALOMEDS::GenericAttribute_var anAttr;
   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return new SALOMEDS::TMPFile(0);
-  CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
+  CORBA::String_var anIOR = CORBA::string_dup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
   CORBA::Object_var anObj = _orb->string_to_object(anIOR);
   SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
   if (aMesh->_is_nil()) return new SALOMEDS::TMPFile(0);
 
   // Get a temporary directory to store a temporary file
-  CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
+  CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
   // Create a list to store names of created files
   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
   aSeq->length(1);
-  aSeq[0] = strdup(aMesh->getName());
+  aSeq[0] = CORBA::string_dup(aMesh->getName());
   char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
   strcpy(aFullName, aTmpDir);
   strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
-  long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,strdup(aFullName) , aMesh->getName());
+  long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,aFullName , aMesh->getName());
   aMesh->write(driverId,"");
-  delete(aFullName);
-  
-  aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
-  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
-  
+
+  //  aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
+  char* aFullName1 = new char[strlen(aTmpDir)+1];
+  strcpy(aFullName1, aTmpDir);
+  aStreamFile = SALOMEDS_Tool::PutFilesToStream(aFullName1, aSeq.in(), false);
+  //  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
+  SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true);
+
   // Assign an ID = 1 the the type SALOME_MED::MESH
   theObjectID = 1;
+
   return aStreamFile._retn();
 }
 
@@ -1028,36 +1034,40 @@ SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
                                           SALOMEDS::SObject_ptr theObject) {
   SALOMEDS::SObject_var aResultSO = SALOMEDS::SObject::_duplicate(theObject);
   if (theStream.length() == 0) return aResultSO._retn();
-  
+
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
 
-  CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
-  SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
-  CORBA::String_var aMeshName = strdup(aSeq[0]);
+  CORBA::String_var aTmpDir = CORBA::string_dup(SALOMEDS_Tool::GetTmpDir().c_str());
+  char* aFullName2 = new char[strlen(aTmpDir)+1];
+  strcpy(aFullName2,aTmpDir);
+  //  SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
+  SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aFullName2, false);
+  CORBA::String_var aMeshName = CORBA::string_dup(aSeq[0]);
   char* aFullName = new char[strlen(aTmpDir)+strlen(aMeshName)+1];
   strcpy(aFullName, aTmpDir);
   strcpy(aFullName+strlen(aTmpDir), aMeshName);
 
   MESH * myMesh= new MESH() ;
-  myMesh->setName((char*)aMeshName);
-  MED_MESH_RDONLY_DRIVER myMeshDriver(aFullName, myMesh);
+  //  myMesh->setName(aMeshName.c_str());
+  char* aFullMeshName = new char[strlen(aMeshName)+1];
+  strcpy(aFullMeshName,aMeshName);
+  myMesh->setName(aFullMeshName);
+  MED_MESH_RDONLY_DRIVER21 myMeshDriver(aFullName, myMesh);
   try {
-    myMeshDriver.setMeshName((char*)aMeshName);
+    myMeshDriver.setMeshName(aFullMeshName);
     myMeshDriver.open();
-  } catch (const exception & ex) {
+  } catch (const std::exception & ex) {
     MESSAGE("Exception Interceptee : ");
     SCRUTE(ex.what());
-    delete(aFullName);
     return aResultSO._retn();
   };
   try {
     myMeshDriver.read();
     ("apres read");
     myMeshDriver.close();
-  } catch (const exception & ex) {
+  } catch (const std::exception & ex) {
     MESSAGE("Exception Interceptee : ");
     SCRUTE(ex.what());
-    delete(aFullName);
     return aResultSO._retn();
   };
   // set new mesh name, becouse now there are no possibility to operate meshes with the same names
@@ -1074,8 +1084,10 @@ SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
   CORBA::String_var anIORString = _orb->object_to_string(mesh);
   aResultSO = aStudy->FindObjectIOR(anIORString);
 
-  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
-  delete(aFullName);
+  char * aFullName1 = new char[strlen(aTmpDir)+1];
+  strcpy(aFullName1,aTmpDir);
+  //  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
+  SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true);
   return aResultSO._retn();
 }
 
@@ -1085,8 +1097,8 @@ SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
 
 
 //=============================================================================
-/*! 
- * C factory, accessible with dlsym, after dlopen  
+/*!
+ * C factory, accessible with dlsym, after dlopen
  */
 //=============================================================================
 
@@ -1094,14 +1106,14 @@ extern "C"
 {
   PortableServer::ObjectId * MEDEngine_factory(
                               CORBA::ORB_ptr orb,
-                              PortableServer::POA_ptr poa, 
+                              PortableServer::POA_ptr poa,
                               PortableServer::ObjectId * contId,
-                              const char *instanceName, 
+                              const char *instanceName,
                               const char *interfaceName)
   {
     MESSAGE("PortableServer::ObjectId * MedEngine_factory()");
     SCRUTE(interfaceName);
-    Med_Gen_i * myMed_Gen 
+    Med_Gen_i * myMed_Gen
       = new Med_Gen_i(orb, poa, contId, instanceName, interfaceName);
     return myMed_Gen->getId() ;
   }