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