Salome HOME
Merging with the MAN_SALOME2 branch
[modules/med.git] / src / MED / Med_Gen_i.cxx
1 //  MED MED : implemetation of MED idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Med_Gen_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : MED
27 //  $Header$
28
29 using namespace std;
30 #include "Med_Gen_i.hxx"
31
32 #include "MEDMEM_Mesh_i.hxx"
33 #include "MEDMEM_Med_i.hxx"
34 #include "MEDMEM_FieldInt_i.hxx"
35 #include "MEDMEM_FieldDouble_i.hxx"
36 #include "MEDMEM_Support_i.hxx"
37
38
39 #include "MEDMEM_Mesh.hxx"
40 #include "MEDMEM_Field.hxx"
41 #include "MEDMEM_Med.hxx"
42 #include "MEDMEM_MedMedDriver.hxx"
43 #include "MEDMEM_MedMeshDriver.hxx"
44 #include "MEDMEM_MedFieldDriver.hxx"
45 #include "MEDMEM_define.hxx"
46 #include "MEDMEM_DriversDef.hxx"
47
48
49 #include "Utils_SINGLETON.hxx"
50 #include "OpUtil.hxx"
51 #include "Utils_CorbaException.hxx"
52 #include "utilities.h"
53
54 #include <string>
55 #include <deque>
56 #include <map>
57
58 #include <TCollection_AsciiString.hxx>
59 #include <TColStd_SequenceOfAsciiString.hxx>
60 #include <HDFascii.hxx>
61 #include "SALOMEDS_Tool.hxx"
62
63 using namespace MEDMEM;
64
65 // Initialisation des variables statiques
66  map <string, string> Med_Gen_i::_MedCorbaObj;
67  string Med_Gen_i::_myFileName="";
68  string Med_Gen_i::_saveFileName="";
69
70 //=============================================================================
71 /*!
72  *  default constructor: not for use
73  */
74 //=============================================================================
75
76 Med_Gen_i::Med_Gen_i()
77 {
78   MESSAGE("Med_Gen_i::Med_Gen_i");
79 }
80
81 //=============================================================================
82 /*!
83  *  standard constructor
84  */
85 //=============================================================================
86
87 Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb,
88                                 PortableServer::POA_ptr poa,
89                                 PortableServer::ObjectId * contId, 
90                                 const char *instanceName, 
91                                 const char *interfaceName) :
92   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
93 {
94   MESSAGE("activate object");
95   _thisObj = this ;
96   _id = _poa->activate_object(_thisObj);
97
98   _duringLoad=false;
99   // get an NamingService interface
100   _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
101   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
102   _NS->init_orb( _orb ) ;
103 }
104 //=============================================================================
105 /*!
106  *  private method : change a study name in SALOMEDS::Study_var
107  */
108 //=============================================================================
109
110 SALOMEDS::Study_var Med_Gen_i::studyName2Study(const char* studyName)
111   throw(SALOME::SALOME_Exception)
112 {
113   string myStudyName(studyName);
114
115   if (myStudyName.size() == 0)
116     THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \
117                                  SALOME::BAD_PARAM);
118
119   // Get StudyManager Reference, current study,
120   
121   CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
122   SALOMEDS::StudyManager_var myStudyManager =
123     SALOMEDS::StudyManager::_narrow(obj);
124   if(CORBA::is_nil(myStudyManager))
125     THROW_SALOME_CORBA_EXCEPTION("No StudyManager Found in NameService", \
126                                  SALOME::BAD_PARAM);
127   
128   SALOMEDS::Study_var myStudy =
129     myStudyManager->GetStudyByName(myStudyName.c_str());
130   if (CORBA::is_nil(myStudy))
131     THROW_SALOME_CORBA_EXCEPTION("Wrong Study Name", \
132                                  SALOME::BAD_PARAM);
133
134   return SALOMEDS::Study::_duplicate(myStudy) ;
135 }
136
137 //=============================================================================
138 /*!
139  *  private method : add Med component in Study (Not MedGen ???)
140  */
141 //=============================================================================
142
143 void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy)
144   throw(SALOME::SALOME_Exception)
145 {
146   SALOMEDS::StudyBuilder_var  myBuilder = myStudy->NewBuilder();
147   
148   myBuilder->NewCommand();
149   
150   // Create SComponent labelled 'Med' if it doesn't already exit
151   SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
152   if ( CORBA::is_nil(medfather) )
153     {
154       // mpv: component label must be created in spite of "Locked" study flag state
155       bool aLocked = myStudy->GetProperties()->IsLocked();
156       if (aLocked) myStudy->GetProperties()->SetLocked(false);
157       
158       MESSAGE("Add Component Med");
159       medfather = myBuilder->NewComponent("MED");
160       SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(medfather, "AttributeName");
161       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
162       //NRI      aName->SetValue("Med");
163
164       CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
165       SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
166       SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
167       if ( !Comp->_is_nil() ) {
168         aName->SetValue( Comp->componentusername() );
169       }    
170
171       //            Utilisation de this  deconseillee par Paul ??
172       //            myBuilder->DefineComponentInstance(medfather,POA_Engines::Med_Gen::_this());
173       CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
174       myBuilder->DefineComponentInstance(medfather,myO);
175       
176       if (aLocked) myStudy->GetProperties()->SetLocked(true);
177     } 
178   
179   myBuilder->CommitCommand();
180    
181 }
182
183 //=============================================================================
184 /*!
185  * Lit tous les objets contenus dans un fichier med et les lit en memoire
186  */
187 //=============================================================================
188 SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName,
189                                 const char* studyName)
190   throw(SALOME::SALOME_Exception)
191 {
192         SCRUTE(fileName);
193         SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
194         if (!_duringLoad) addInStudy(myStudy) ;
195
196         SALOME_MED::MED_ptr myMedIOR ;
197         try 
198         {
199           // we create a new MED_i and add in study
200           MED_i * myMedI = new MED_i();
201           myMedIOR = myMedI->_this() ;
202           if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;        
203           // create ::MED object, read all and add in study !
204           myMedI->init(myStudy,MED_DRIVER,fileName) ;
205         }
206         catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
207         catch(...)
208         {
209                 MESSAGE("Erreur a la lecture du fichier");
210                 THROW_SALOME_CORBA_EXCEPTION("Unable to open File "\
211                                                 ,SALOME::BAD_PARAM);
212         }
213         return SALOME_MED::MED::_duplicate(myMedIOR) ;
214 }
215
216 //=============================================================================
217 /*!
218  *  Prepare un Maillage sans le lire en memoire avec stokage dans l'etude
219  *  des champs avec leur type
220  */
221 //=============================================================================
222 void Med_Gen_i::readStructFileWithFieldType (const char* fileName,
223                                              const char* studyName)
224 throw (SALOME::SALOME_Exception)
225 {
226   BEGIN_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
227
228         SCRUTE(fileName);
229         SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
230
231         if (!_duringLoad) addInStudy(myStudy) ;
232
233         try 
234         {
235           // we create a new MED_i and add in study
236           MED_i * myMedI = new MED_i();
237           SALOME_MED::MED_ptr myMedIOR = myMedI->_this() ;
238           if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;        
239           // create ::MED object, read all and add in study !
240           myMedI->initWithFieldType(myStudy,MED_DRIVER,fileName) ;
241         }
242         catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
243         catch(...)
244         {
245                 MESSAGE("Erreur a la lecture du fichier");
246                 THROW_SALOME_CORBA_EXCEPTION("Unable to open File "\
247                                                 ,SALOME::BAD_PARAM);
248         }
249
250         END_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
251
252
253 }
254
255 //=============================================================================
256 /*!
257  *  Sert un Maillage
258  */
259 //=============================================================================
260 SALOME_MED::MESH_ptr Med_Gen_i::readMeshInFile(const char* fileName,
261                                                const char* studyName,
262                                                const char* meshName)
263 throw (SALOME::SALOME_Exception)
264 {
265         SCRUTE(fileName);
266         SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
267
268         if (!_duringLoad) addInStudy(myStudy) ;
269
270 // Creation du maillage
271
272         MESH * myMesh= new MESH() ;
273         myMesh->setName(meshName);
274         MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
275         try
276         {
277                 myMeshDriver.setMeshName(meshName);
278                 myMeshDriver.open();
279         }
280         catch (const exception & ex)
281         {
282                 MESSAGE("Exception Interceptee : ");
283                 SCRUTE(ex.what());
284                 THROW_SALOME_CORBA_EXCEPTION("Unable to find this mesh in this file",SALOME::BAD_PARAM);
285         };
286         try
287         {
288                 myMeshDriver.read();
289                 MESSAGE("apres read");
290                 myMeshDriver.close();
291         }
292         catch (const exception & ex)
293         {
294                 MESSAGE("Exception Interceptee : ");
295                 SCRUTE(ex.what());
296                 THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file",SALOME::BAD_PARAM);
297         };
298
299         MESH_i * meshi = new MESH_i(myMesh);
300         //SALOME_MED::MESH_var mesh = SALOME_MED::MESH::_narrow(meshi->_this());
301         SALOME_MED::MESH_ptr mesh = meshi->_this();
302         try
303         {
304         // add the mesh object in study
305                 if (!_duringLoad) meshi->addInStudy(myStudy,mesh);
306         }
307         catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
308         return SALOME_MED::MESH::_duplicate(mesh);
309 }
310 //=============================================================================
311 /*!
312  *  Sert un Champ
313  */
314 //=============================================================================
315 SALOME_MED::FIELD_ptr Med_Gen_i::readFieldInFile(const char* fileName,
316                                                const char* studyName,
317                                                const char* fieldName,
318                                                CORBA::Long ordre,
319                                                CORBA::Long iter)
320 throw (SALOME::SALOME_Exception)
321 {
322         SCRUTE(fileName);
323         string myStudyName(studyName);
324
325         if (myStudyName.size() == 0)
326                 THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \
327                                  SALOME::BAD_PARAM);
328
329         // Get StudyManager Reference, current study,
330         
331         CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
332         SALOMEDS::StudyManager_var myStudyManager =
333                         SALOMEDS::StudyManager::_narrow(obj);
334         ASSERT(! CORBA::is_nil(myStudyManager));
335         SALOMEDS::Study_var myStudy =
336                 myStudyManager->GetStudyByName(myStudyName.c_str());
337         if (CORBA::is_nil(myStudy))
338         THROW_SALOME_CORBA_EXCEPTION("Wrong Study Name", \
339                                  SALOME::BAD_PARAM);
340
341         SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
342         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
343         if (CORBA::is_nil(medfather))
344         {
345                 myBuilder->NewCommand();
346                 // mpv: component label must be created in spite of "Locked" study flag state
347                 bool aLocked = myStudy->GetProperties()->IsLocked();
348                 if (aLocked) myStudy->GetProperties()->SetLocked(false);
349
350                 medfather = myBuilder->NewComponent("MED");
351                 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
352                       myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
353                 //NRI           aName->SetValue("Med");
354
355                 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
356                 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
357                 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
358                 if ( !Comp->_is_nil() ) {
359                   aName->SetValue( Comp->componentusername() );
360                 }    
361
362                 CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
363                 myBuilder->DefineComponentInstance(medfather,myO);
364
365                 if (aLocked) myStudy->GetProperties()->SetLocked(true);
366                 myBuilder->CommitCommand();
367
368         }
369         else
370                         MESSAGE("MED dejà dans l Ã©tude");
371
372         MESSAGE("Lecture du fichier ")
373         SCRUTE(fileName);
374
375 // Creation du champ
376
377         FIELD_ * myField= new FIELD_() ;
378         MED * mymed = new MED(MED_DRIVER,fileName) ;
379         try
380         {
381                 deque<string> fieldsNames = mymed->getFieldNames() ;
382                 int numberOfFields = fieldsNames.size();
383                 int i;
384                 for (i=0; i<numberOfFields; i++)
385                 {
386                         if (fieldsNames[i]== fieldName) break;
387                 }
388                 if (i == numberOfFields)
389                 {
390                         THROW_SALOME_CORBA_EXCEPTION("Unable to find this field ",SALOME::BAD_PARAM);
391                 }
392                 MESSAGE("trouve");
393 /*
394                 deque<DT_IT_> myIteration = mymed->getFieldIteration (fieldName);
395                 if (myIteration.size() != 1)
396                 {
397                         MESSAGE("WARNING : My iteration size is ")
398                         SCRUTE(myIteration.size());
399                 }
400 */
401                 myField = mymed->getField(fieldName,iter,ordre);
402         }
403         catch (const exception & ex)
404         {
405                 MESSAGE("Exception Interceptee : ");
406                 SCRUTE(ex.what());
407                 THROW_SALOME_CORBA_EXCEPTION("Unable to find this field in this file",SALOME::BAD_PARAM);
408         };
409                         
410         SUPPORT * fieldSupport;
411         SALOME_MED::SUPPORT_ptr mySupportIOR;
412         try
413         {
414                 fieldSupport=(SUPPORT *)myField->getSupport() ;
415                 ASSERT(fieldSupport != NULL);
416                 MESH * myMesh=(MESH *)fieldSupport->getMesh();
417                 ASSERT(myMesh != NULL);
418                 myMesh->read();
419                 SCRUTE(myMesh->getName());
420                 fieldSupport->update();
421                 SUPPORT_i * mySupportI = new SUPPORT_i(fieldSupport);
422                 mySupportIOR=mySupportI->_this();
423         }
424         catch (const exception & ex)
425         {
426                 MESSAGE("Exception Interceptee : ");
427                 SCRUTE(ex.what());
428                 THROW_SALOME_CORBA_EXCEPTION("Unable to find associated support",SALOME::BAD_PARAM);
429         };
430
431         med_type_champ type = myField->getValueType() ;
432         switch (type) 
433         {
434          case MED_FR::MED_INT32:        
435          {
436                 try 
437                 {
438                         ((FIELD<int>*)myField)->read() ;
439                         FIELDINT_i * myFieldIntI = new FIELDINT_i(mySupportIOR,(FIELD<int>*)myField);
440                         POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldIntI);
441                         SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
442                         if (!_duringLoad) myFieldIntI->addInStudy(myStudy,myFieldIOR) ;
443                         return SALOME_MED::FIELD::_duplicate(myFieldIOR);
444                 }
445                 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
446                 catch (const exception & ex)
447                 {
448                         MESSAGE("Exception Interceptee : ");
449                         SCRUTE(ex.what());
450                         THROW_SALOME_CORBA_EXCEPTION("Unable to read int field",SALOME::BAD_PARAM);
451                 };
452                 break;
453          }
454          case MED_FR::MED_REEL64: 
455          {
456                 try 
457                 {
458                         ((FIELD<double>*)myField)->read() ;
459                         FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i(mySupportIOR,(FIELD<double>*)myField);
460                         POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldDoubleI);
461                         SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
462                         if (!_duringLoad) myFieldDoubleI->addInStudy(myStudy,myFieldIOR) ;
463                         return SALOME_MED::FIELD::_duplicate(myFieldIOR);
464                 }
465                 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
466                 catch (const exception & ex)
467                 {
468                         MESSAGE("Exception Interceptee : ");
469                         SCRUTE(ex.what());
470                         THROW_SALOME_CORBA_EXCEPTION("Unable to read double field",SALOME::BAD_PARAM);
471                 };
472                 break;
473          }
474         }
475
476         
477 }
478
479
480 //=============================================================================
481 /*!
482  *  Destructor
483  */
484 //=============================================================================
485
486 Med_Gen_i::~Med_Gen_i()
487 {
488   MESSAGE("Med_Gen_i::~Med_Gen_i");
489 }
490
491 //=============================================================================
492 /*!
493  *  CORBA: Save Mesh objects (called when a study is saved)
494  */
495 //=============================================================================
496 SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
497                                    const char* theURL,
498                                    bool isMultiFile) {
499   const char* LOC = "Med_Gen_i::Save";
500   BEGIN_OF(LOC);
501
502   SALOMEDS::TMPFile_var aStreamFile;
503   // Get a temporary directory to store a file
504   TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
505   // Create a list to store names of created files
506   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
507   TColStd_SequenceOfAsciiString aFileNames;
508
509   CORBA::String_var aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
510
511   SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
512   if (!CORBA::is_nil(aMedMeshFather)) {
513     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
514     for(; anIter->More(); anIter->Next()) {
515       SALOMEDS::SObject_var aSO = anIter->Value();
516       SALOMEDS::GenericAttribute_var anAttr;
517       if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
518         CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
519         SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
520         if (! CORBA::is_nil(myMesh)) {
521           TCollection_AsciiString aName(strdup(aSaveStudyName));
522           aName += "_MEDMESH_";
523           aName += myMesh->getName();
524           aName += ".med";
525           MESSAGE("Save mesh with name "<<aName.ToCString());
526           long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName());
527           myMesh->write(driverId,"");
528           aFileNames.Append(aName);
529         }
530       }
531     }
532   }
533
534   SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD");
535   if (!CORBA::is_nil(aMedFieldFather)) {
536     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather);
537     for(; anIter->More(); anIter->Next()) {
538       SALOMEDS::SObject_var aSO = anIter->Value();
539       SALOMEDS::GenericAttribute_var anAttr;
540       if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
541         CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
542         SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
543         if (! CORBA::is_nil(myField)) {
544           ostringstream a,b;
545           a<< myField->getOrderNumber();
546           b<< myField->getIterationNumber();
547
548           TCollection_AsciiString aName(strdup(aSaveStudyName));
549           aName += "_MEDFIELD_";
550           aName += myField->getName();
551           aName += "_ORDRE_";
552           aName += strdup(a.str().c_str());
553           aName += "_ITER_";
554           aName += strdup(b.str().c_str());
555           aName += ".med";
556           MESSAGE("Save mesh with name "<<aName.ToCString());
557           long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName());
558           myField->write(driverId,"");
559           aFileNames.Append(aName);
560         }
561       }
562     }
563   }
564
565   int i;
566   aSeq->length(aFileNames.Length());
567   for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString());
568   // Conver a file to the byte stream
569   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
570   // Remove the created file and tmp directory
571   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
572   // Return the created byte stream
573   return aStreamFile._retn();
574   
575   END_OF(LOC);
576 }
577
578 SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
579                                         const char* theURL,
580                                         bool isMultiFile) {
581   const char* LOC = "Med_Gen_i::SaveASCII";
582   BEGIN_OF(LOC);
583   
584   SALOMEDS::TMPFile_var aStreamFile;
585   // Get a temporary directory to store a file
586   TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
587   // Create a list to store names of created files
588   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
589   TColStd_SequenceOfAsciiString aFileNames;
590   
591   CORBA::String_var aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
592   
593   SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
594   if (!CORBA::is_nil(aMedMeshFather)) {
595     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
596     for(; anIter->More(); anIter->Next()) {
597       SALOMEDS::SObject_var aSO = anIter->Value();
598       SALOMEDS::GenericAttribute_var anAttr;
599       if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
600         CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
601         SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
602         if (! CORBA::is_nil(myMesh)) {
603           TCollection_AsciiString aName(strdup(aSaveStudyName));
604           aName += "_MEDMESH_";
605           aName += myMesh->getName();
606           aName += ".med";
607           MESSAGE("Save mesh with name "<<aName.ToCString());
608           long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName());
609           myMesh->write(driverId,"");
610           HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true);
611           aFileNames.Append(aName);
612         }
613       }
614     }
615   }
616
617   SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD");
618   if (!CORBA::is_nil(aMedFieldFather)) {
619     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather);
620     for(; anIter->More(); anIter->Next()) {
621       SALOMEDS::SObject_var aSO = anIter->Value();
622       SALOMEDS::GenericAttribute_var anAttr;
623       if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
624         CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
625         SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
626         if (! CORBA::is_nil(myField)) {
627           ostringstream a,b;
628           a<< myField->getOrderNumber();
629           b<< myField->getIterationNumber();
630
631           TCollection_AsciiString aName(strdup(aSaveStudyName));
632           aName += "_MEDFIELD_";
633           aName += myField->getName();
634           aName += "_ORDRE_";
635           aName += strdup(a.str().c_str());
636           aName += "_ITER_";
637           aName += strdup(b.str().c_str());
638           aName += ".med";
639           MESSAGE("Save mesh with name "<<aName.ToCString());
640           long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName());
641           myField->write(driverId,"");
642           HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true);
643           aFileNames.Append(aName);
644         }
645       }
646     }
647   }
648
649   int i;
650   aSeq->length(aFileNames.Length());
651   for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString());
652   // Conver a file to the byte stream
653   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
654   // Remove the created file and tmp directory
655   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
656   // Return the created byte stream
657   return aStreamFile._retn();
658   
659   END_OF(LOC);
660 }
661
662 //=============================================================================
663 /*!
664  *  CORBA: Load Mesh objects (called when an existing study is opened)
665  */
666 //=============================================================================
667
668 CORBA::Boolean Med_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
669                                const SALOMEDS::TMPFile& theStream,
670                                const char* theURL,
671                                bool isMultiFile) {
672   const char* LOC = "Med_Gen_i::Load";
673   BEGIN_OF(LOC);
674
675   // Get a temporary directory for a file
676   TCollection_AsciiString aTmpDir =
677     (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
678   _saveFileName = CORBA::string_dup(aTmpDir.ToCString());
679   SALOMEDS::ListOfFileNames_var aSeq =
680     SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), isMultiFile);
681   return true;
682
683   END_OF(LOC);
684 }
685
686 CORBA::Boolean Med_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
687                                     const SALOMEDS::TMPFile& theStream,
688                                     const char* theURL,
689                                     bool isMultiFile) {
690   return Load(theComponent, theStream, theURL, isMultiFile);
691 }
692
693 //=============================================================================
694 /*!
695  *  CORBA: 
696  */
697 //=============================================================================
698
699 void Med_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
700 {
701   MESSAGE("Med_Gen_i::Close");
702   SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
703   if (!CORBA::is_nil(aMedMeshFather)) {
704     SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
705     for(; anIter->More(); anIter->Next()) {
706       SALOMEDS::SObject_var aSO = anIter->Value();
707       SALOMEDS::GenericAttribute_var anAttr;
708       if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
709         CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
710         SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
711         // here must call method destroy of myMesh, but it not implented yet
712       }
713     }
714   }
715 }
716
717 //=============================================================================
718 /*!
719  *  CORBA:
720  */
721 //=============================================================================
722
723 char* Med_Gen_i::ComponentDataType()
724 {
725   MESSAGE("Med_Gen_i::ComponentDataType");
726   return strdup("MED") ; /* What is this type ? */
727 }
728     
729 //=============================================================================
730 /*!
731  *  CORBA: give a persistent reference of a transient object (for study save) 
732  */
733 //=============================================================================
734
735 char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
736                                         const char* IORString,
737                                         CORBA::Boolean isMultiFile,
738                                         CORBA::Boolean isASCII) {
739   const char * LOC = "Med_Gen_i::IORToLocalPersistentID" ;
740   BEGIN_OF(LOC) ;
741   SCRUTE(IORString);
742
743   string aSaveStudyName(strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL())));
744   
745
746   if (string(IORString).size()==0) return strdup((aSaveStudyName+"_MED").c_str());
747   // Well, we know where put object (_saveFilename) and we know object (IORString)
748   // cast object :
749   CORBA::Object_var myIOR = _orb->string_to_object(IORString);
750
751   // MED
752   SALOME_MED::MED_var myMed = SALOME_MED::MED::_narrow(myIOR);
753   if (! CORBA::is_nil(myMed)) 
754   {
755         // nothing to save : Support will be saved inside the mesh
756         string str_MedName=aSaveStudyName + "_MED Objet Med + /OBJ_MED/";
757         return strdup(str_MedName.c_str()) ; 
758   }
759  
760   // MESH
761   SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
762   if (! CORBA::is_nil(myMesh)) 
763   {
764     CORBA::String_var aName((aSaveStudyName+"_MEDMESH_"+ myMesh->getName() + ".med").c_str());
765     return strdup(aName._retn()) ;
766   }
767     
768   // SUPPORT
769   SALOME_MED::SUPPORT_var mySupport = SALOME_MED::SUPPORT::_narrow(myIOR);
770   if (! CORBA::is_nil(mySupport)) 
771   {
772         // nothing to save : Support will be saved inside the mesh
773         string str_SupportName;
774         try
775         {
776                 str_SupportName=string("/FAS/")+string(mySupport->getName());
777                 str_SupportName+=string("/ENS_MAA/")+string(mySupport->getMesh()->getName());
778                 SCRUTE(str_SupportName);
779         }
780         catch(...)
781         {
782                 MESSAGE("Unable to save the support");
783                 THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\
784                                               ,SALOME::INTERNAL_ERROR);
785         }
786     return strdup((aSaveStudyName+"_MED"+str_SupportName).c_str());
787   }
788     
789   SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
790   if (! CORBA::is_nil(myField)) 
791   {
792     string str_FieldName;
793     ostringstream a,b;
794     a<< myField->getOrderNumber();
795     b<< myField->getIterationNumber();
796     CORBA::String_var aName((aSaveStudyName+"_MEDFIELD_"+ myField->getName() +
797                              string("_ORDRE_")+a.str()+
798                              string("_ITER_")+b.str() +
799                              ".med").c_str());
800     return strdup(aName._retn());
801   }
802
803   //THROW_SALOME_CORBA_EXCEPTION("Unable to save IOR",SALOME::BAD_PARAM);
804   return strdup((aSaveStudyName+"_MED").c_str());
805
806   END_OF(LOC) ;
807 }
808
809 //=============================================================================
810 /*!
811  *  CORBA: give a transient reference (when loading an object, opening study)
812  */
813 //=============================================================================
814
815 char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
816                                         const char* aLocalPersistentID,
817                                         CORBA::Boolean isMultiFile,
818                                         CORBA::Boolean isASCII)
819      throw(SALOME::SALOME_Exception)
820 {
821   const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ;
822   BEGIN_OF(LOC) ;
823   TCollection_AsciiString aTmpDir(CORBA::string_dup(_saveFileName.c_str()));
824
825   string aSaveStudyName(strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL())));
826   int aStudyNameLen = strlen(aSaveStudyName.c_str());
827
828   if (strlen(aLocalPersistentID) <= aStudyNameLen) return strdup("");
829   if (strcmp(aLocalPersistentID, "Objet Med + /OBJ_MED/") == 0) return strdup(""); // MED
830
831   if (strncmp(&(aLocalPersistentID[aStudyNameLen]), "_MEDMESH_",9) == 0) {// MESH
832     MESH * myMesh= new MESH() ;
833     int aMeshNameLen = strlen(aLocalPersistentID) - 12 - aStudyNameLen;
834     char* aMeshName = new char[aMeshNameLen];
835     strncpy(aMeshName, &(aLocalPersistentID[aStudyNameLen + 9]), aMeshNameLen-1);
836     aMeshName[aMeshNameLen-1] = 0;
837     myMesh->setName(aMeshName);
838
839     char* aFileName;
840     if (isASCII) {
841       char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + strdup(aLocalPersistentID)).ToCString());
842       aFileName = new char[strlen(aResultPath) + 19];
843       sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath);
844       delete(aResultPath);
845     } else aFileName = strdup((aTmpDir + strdup(aLocalPersistentID)).ToCString());
846     MED_MESH_RDONLY_DRIVER myMeshDriver(aFileName,myMesh);
847     try
848       {
849         myMeshDriver.setMeshName(aMeshName);
850         myMeshDriver.open();
851       }
852     catch (const exception & ex)
853       {
854         MESSAGE("Exception Interceptee : ");
855         SCRUTE(ex.what());
856         THROW_SALOME_CORBA_EXCEPTION("Unable to find this mesh in this file",SALOME::BAD_PARAM);
857       };
858     try
859       {
860         myMeshDriver.read();
861         MESSAGE("apres read");
862         myMeshDriver.close();
863       }
864     catch (const exception & ex)
865       {
866         MESSAGE("Exception Interceptee : ");
867         SCRUTE(ex.what());
868         THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file",SALOME::BAD_PARAM);
869       }
870     MESH_i * meshi = new MESH_i(myMesh);
871     //SALOME_MED::MESH_var mesh = SALOME_MED::MESH::_narrow(meshi->_this());
872     SALOME_MED::MESH_ptr mesh = meshi->_this();
873     SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
874     aSeq->length(1);
875     aSeq[0]=CORBA::string_dup(aLocalPersistentID);
876     if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
877     if (isASCII) {
878       SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
879       aFilesToRemove->length(1);
880       aFilesToRemove[0] = strdup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName))]));
881       SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName), aFilesToRemove, true);
882     }
883     delete(aFileName);
884     return(CORBA::string_dup(_orb->object_to_string(mesh)));
885   } else if (strncmp(&(aLocalPersistentID[aStudyNameLen]), "_MEDFIELD_",14) == 0) { // FIELD
886     return(strdup("")); // not implemented yet
887   }
888
889   return strdup("");
890
891   END_OF(LOC) ;
892 }
893
894 //=============================================================================
895 /*!
896  *  returns true, if can publish object
897  */
898 //=============================================================================
899 bool Med_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
900   SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theIOR);
901   return !(aMesh->_is_nil());
902 }
903
904 //=============================================================================
905 /*!
906  *  publish the given object
907  */
908 //=============================================================================
909 SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
910                                                 SALOMEDS::SObject_ptr theSObject,
911                                                 CORBA::Object_ptr theObject,
912                                                 const char* theName) throw (SALOME::SALOME_Exception)
913 {
914   SALOMEDS::SObject_var aResultSO;
915
916   if(CORBA::is_nil(theObject)) return aResultSO;
917   if(theStudy->_is_nil()) return aResultSO;
918
919   SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
920   SALOMEDS::GenericAttribute_var anAttr;
921   SALOMEDS::AttributeName_var    aName;
922   SALOMEDS::AttributeIOR_var     anIOR;
923   SALOMEDS::SComponent_var aFather = theStudy->FindComponent("MED");
924
925   if (aFather->_is_nil()) {
926     aFather = aBuilder->NewComponent("MED");
927     if (aFather->_is_nil()) return aResultSO;
928     anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
929     aName = SALOMEDS::AttributeName::_narrow(anAttr);
930     //NRI    aName->SetValue("MED");
931
932     CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
933     SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
934     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" );
935     if ( !Comp->_is_nil() ) {
936       aName->SetValue( Comp->componentusername() );
937     }    
938     aBuilder->DefineComponentInstance(aFather, MED_Gen::_this());
939   }
940
941   if (CORBA::is_nil(theSObject)) {
942     SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theObject);
943     aMesh->addInStudy(theStudy, aMesh);
944     SALOMEDS::SObject_var aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject));
945   } else {
946     if (!theSObject->ReferencedObject(aResultSO)) 
947       THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM);
948   }
949 //    aBuilder->Addreference(theObject, aResultSO);
950   return aResultSO._retn();
951 }
952
953 //=============================================================================
954 /*!
955  *  returns true, if can copy the object
956  */
957 //=============================================================================
958 CORBA::Boolean Med_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
959   // Try to retrieve known by MED component mesh by given IOR
960   SALOMEDS::GenericAttribute_var anAttr;
961   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
962   CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
963   SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
964   // If the object is null one it can't be copied: return false
965   if (aMesh->_is_nil()) return false;
966   return true;
967 }
968
969 //=============================================================================
970 /*!
971  *  create copy of the object and put it to the stream
972  */
973 //=============================================================================
974 SALOMEDS::TMPFile* Med_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
975     // Declare a sequence of the byte to store the copied object
976   SALOMEDS::TMPFile_var aStreamFile;
977
978   // Try to get GEOM_Shape object by given SObject
979   SALOMEDS::GenericAttribute_var anAttr;
980   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return new SALOMEDS::TMPFile(0);
981   CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
982   CORBA::Object_var anObj = _orb->string_to_object(anIOR);
983   SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
984   if (aMesh->_is_nil()) return new SALOMEDS::TMPFile(0);
985
986   // Get a temporary directory to store a temporary file
987   CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
988   // Create a list to store names of created files
989   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
990   aSeq->length(1);
991   aSeq[0] = strdup(aMesh->getName());
992   char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
993   strcpy(aFullName, aTmpDir);
994   strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
995   long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,strdup(aFullName) , aMesh->getName());
996   aMesh->write(driverId,"");
997   delete(aFullName);
998   
999   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
1000   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
1001   
1002   // Assign an ID = 1 the the type SALOME_MED::MESH
1003   theObjectID = 1;
1004  
1005   return aStreamFile._retn();
1006 }
1007
1008 //=============================================================================
1009 /*!
1010  *  returns true, if can copy the object
1011  */
1012 //=============================================================================
1013 CORBA::Boolean Med_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1014   // The MED component can paste only objects copied by MED component
1015   // and with the object type = 1 (mesh)
1016   if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
1017   return true;
1018 }
1019
1020 //=============================================================================
1021 /*!
1022  *  returns true, if can copy the object
1023  */
1024 //=============================================================================
1025 SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
1026                                            CORBA::Long theObjectID,
1027                                            SALOMEDS::SObject_ptr theObject) {
1028   SALOMEDS::SObject_var aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1029   if (theStream.length() == 0) return aResultSO._retn();
1030   
1031   SALOMEDS::Study_var aStudy = theObject->GetStudy();
1032
1033   CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
1034   SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1035   CORBA::String_var aMeshName = strdup(aSeq[0]);
1036   char* aFullName = new char[strlen(aTmpDir)+strlen(aMeshName)+1];
1037   strcpy(aFullName, aTmpDir);
1038   strcpy(aFullName+strlen(aTmpDir), aMeshName);
1039
1040   MESH * myMesh= new MESH() ;
1041   myMesh->setName((char*)aMeshName);
1042   MED_MESH_RDONLY_DRIVER myMeshDriver(aFullName, myMesh);
1043   try {
1044     myMeshDriver.setMeshName((char*)aMeshName);
1045     myMeshDriver.open();
1046   } catch (const exception & ex) {
1047     MESSAGE("Exception Interceptee : ");
1048     SCRUTE(ex.what());
1049     delete(aFullName);
1050     return aResultSO._retn();
1051   };
1052   try {
1053     myMeshDriver.read();
1054     ("apres read");
1055     myMeshDriver.close();
1056   } catch (const exception & ex) {
1057     MESSAGE("Exception Interceptee : ");
1058     SCRUTE(ex.what());
1059     delete(aFullName);
1060     return aResultSO._retn();
1061   };
1062   // set new mesh name, becouse now there are no possibility to operate meshes with the same names
1063 //    srand((unsigned int)time(NULL));
1064   int aRND = rand(); //Get a random number to present a name of a copied mesh
1065   char aCopiedMeshName[20];
1066   sprintf(aCopiedMeshName,"MESH_COPY_%d",aRND);
1067   myMesh->setName(aCopiedMeshName);
1068   MESH_i * meshi = new MESH_i(myMesh);
1069   SALOME_MED::MESH_ptr mesh = meshi->_this();
1070   // add the mesh object in study
1071   meshi->addInStudy(aStudy,mesh);
1072   // get the IOR attribute of just added mesh
1073   CORBA::String_var anIORString = _orb->object_to_string(mesh);
1074   aResultSO = aStudy->FindObjectIOR(anIORString);
1075
1076   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
1077   delete(aFullName);
1078   return aResultSO._retn();
1079 }
1080
1081
1082
1083
1084
1085
1086 //=============================================================================
1087 /*! 
1088  * C factory, accessible with dlsym, after dlopen  
1089  */
1090 //=============================================================================
1091
1092 extern "C"
1093 {
1094   PortableServer::ObjectId * MEDEngine_factory(
1095                                CORBA::ORB_ptr orb,
1096                                PortableServer::POA_ptr poa, 
1097                                PortableServer::ObjectId * contId,
1098                                const char *instanceName, 
1099                                const char *interfaceName)
1100   {
1101     MESSAGE("PortableServer::ObjectId * MedEngine_factory()");
1102     SCRUTE(interfaceName);
1103     Med_Gen_i * myMed_Gen 
1104       = new Med_Gen_i(orb, poa, contId, instanceName, interfaceName);
1105     return myMed_Gen->getId() ;
1106   }
1107 }