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