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