]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM_I/MEDMEM_Med_i.cxx
Salome HOME
updating the main trunk with the CEA debug devellopment from the branch
[modules/med.git] / src / MEDMEM_I / MEDMEM_Med_i.cxx
1 //=============================================================================
2 // File      : MEDMEM_Med_i.cxx
3 // Project   : SALOME
4 // Author    : EDF
5 // Copyright : EDF 2002
6 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_i.cxx
7 //=============================================================================
8
9 #include <deque>
10
11 //#include "MEDMEM_Field.hxx"
12
13 #include "MEDMEM_Med_i.hxx"
14 #include "MEDMEM_Mesh_i.hxx"
15 #include "MEDMEM_FieldDouble_i.hxx"
16 #include "MEDMEM_FieldInt_i.hxx"
17 #include "MEDMEM_Support_i.hxx"
18 #include "MEDMEM_Family_i.hxx"
19 #include "MEDMEM_Group_i.hxx"
20 #include "MEDMEM_convert.hxx"
21
22 #include "MEDMEM_DriversDef.hxx"
23 #include "utilities.h"
24 #include "Utils_CorbaException.hxx"
25
26 using namespace std;
27 using namespace MEDMEM;
28
29 //=============================================================================
30 /*!
31  * Default constructor
32  */
33 //=============================================================================
34 MED_i::MED_i():_med((::MED*)NULL)
35 {
36         BEGIN_OF("Default Constructor MED_i");
37         END_OF("Default Constructor MED_i");
38 }
39 //=============================================================================
40 /*!
41  * methods
42  */
43 //=============================================================================
44 void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName)
45 {
46         const char * LOC = "MED_i::init(driverTypes, const string &)";
47         BEGIN_OF(LOC);
48
49   // we create all IOR from _med
50         _med = new ::MED(driverType,fileName);
51
52   // MESHES :
53         deque<string> meshesNames = _med->getMeshNames();
54         int numberOfMeshes = meshesNames.size();
55         for (int i=0; i<numberOfMeshes; i++) 
56         {
57                 ::MESH * myMesh = _med->getMesh(meshesNames[i]);
58                 myMesh->read();
59                 MESH_i * myMeshI = new MESH_i(myMesh);
60                 SALOME_MED::MESH_ptr myMeshIOR = myMeshI->_this();
61                 _meshes[meshesNames[i]] = myMeshIOR;
62 //              myMeshI->addInStudy(myStudy,myMeshIOR,fileName);
63         }
64
65   // SUPPORTS :
66         _med->updateSupport();
67
68   // FAMILIES :
69   // we add all families 
70         vector<FAMILY*> familyVector;
71         vector<FAMILY*>::iterator familyVectorIt;
72   // GROUPS :
73   // we add all groups
74         vector<GROUP*> groupVector;
75         vector<GROUP*>::iterator groupVectorIt;
76   
77         MED_EN::MESH_ENTITIES::const_iterator currentEntity; 
78         for (int i=0; i<numberOfMeshes; i++) 
79         {
80                 ::MESH * ptrMesh = _med->getMesh(meshesNames[i]);
81                 for (currentEntity = MED_EN::meshEntities.begin();
82                      currentEntity != MED_EN::meshEntities.end(); 
83                      currentEntity++) 
84                 {
85 //                   MESSAGE(LOC << ": for entity " << (*currentEntity).first);
86                 // family :
87                      familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first);
88                      int nb = familyVector.size();
89 //                   MESSAGE(LOC << ": there is(are) " << nb << " family(ies)");
90                      for (familyVectorIt = familyVector.begin();
91                           familyVectorIt != familyVector.end();
92                           familyVectorIt++) 
93                      {
94                           FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt);
95                           SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this();
96 //                         myFamilyI->addInStudy(myStudy,myFamilyIOR);
97                      }
98
99                // group :
100                      groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first);
101                      nb = groupVector.size();
102 //                   MESSAGE(LOC << ": there is(are) " << nb << " group(s)");
103                     for (groupVectorIt = groupVector.begin();
104                          groupVectorIt != groupVector.end();
105                          groupVectorIt++) 
106                     {
107                          GROUP_i * myGroupI = new GROUP_i(*groupVectorIt);
108                          SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this();
109 //                       myGroupI->addInStudy(myStudy,myGroupIOR);
110                     }
111                 }      
112         }
113
114         for (int i=0; i<numberOfMeshes; i++) 
115         {
116               map<MED_EN::medEntityMesh,::SUPPORT*> mySupports = _med->getSupports(meshesNames[i]);
117               map<MED_EN::medEntityMesh,::SUPPORT*>::const_iterator itSupport;
118               map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> & mySupportsIOR 
119                                 = _supports[meshesNames[i]];
120               for ( itSupport = mySupports.begin(); itSupport != mySupports.end(); itSupport++ ) 
121               {
122                     SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second);
123                     SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this();
124                     mySupportsIOR[(*itSupport).first] = mySupportIOR;
125 //                  mySupportI->addInStudy(myStudy,mySupportIOR);
126               }
127         }
128
129   // FIELDS :
130         deque<string> fieldsNames = _med->getFieldNames();
131         int numberOfFields = fieldsNames.size();
132         for (int i=0; i<numberOfFields; i++) 
133         {
134              deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
135              int numberOfIteration = myIteration.size();
136              for (int j=0; j<numberOfIteration; j++) 
137              {
138                  ::FIELD_ * myField = _med->getField(fieldsNames[i], myIteration[j].dt, myIteration[j].it);
139                  string meshName = myField->getSupport()->getMesh()->getName();
140                  medEntityMesh myEntity = myField->getSupport()->getEntity();
141                  map<string, map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> >::const_iterator 
142                                                              itSupportOnMesh = _supports.find(meshName);
143                  if ( itSupportOnMesh == _supports.end() )
144                       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
145                                          << "There is no support on mesh named |" 
146                                          << meshName << "|" ));
147                  const map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> & SupportOnMesh 
148                                         = (*itSupportOnMesh).second;
149                  map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport 
150                                         = SupportOnMesh.find(myEntity);
151                  if (itSupport == SupportOnMesh.end())
152                       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
153                                          << "There is no support on entity "
154                                          << entity << " in mesh named |" 
155                                          << meshName << "|"));
156                  SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second;
157                  med_type_champ type = myField->getValueType();
158                  SALOME_MED::FIELD_ptr myFieldIOR;
159                  switch (type) 
160                  {
161                          case MED_EN::MED_INT32 : 
162                          {
163                              ((FIELD<int>*)myField)->read();
164                              FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD<int>*)myField);
165                              myFieldIOR = myFieldIntI->_this();
166 //                           myFieldIntI->addInStudy(myStudy,myFieldIOR);
167                              break;
168                          }
169
170                         case MED_EN::MED_REEL64: 
171                         {
172                              ((FIELD<double>*)myField)->read();
173                              FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD<double>*)myField);
174                              myFieldIOR = myFieldDoubleI->_this();
175 //                           myFieldDoubleI->addInStudy(myStudy,myFieldIOR);
176                              break;
177                         }
178                         default: 
179                         {
180                              throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
181                                          <<"   * Iteration "<<FieldIteration[j].dt
182                                          <<", order number "<<FieldIteration[j].it
183                                          <<" has wrong type : "<<type));
184                              break;
185                         }
186                 }
187
188                 DT_IT_ dtIt;
189                 dtIt.dt  = myIteration[j].dt;
190                 dtIt.it  = myIteration[j].it;
191                 _fields[fieldsNames[i]][dtIt] = myFieldIOR;
192              }
193   }
194   
195   END_OF(LOC);
196 }
197
198 //=============================================================================
199 /*!
200  * methods
201  */
202 //=============================================================================
203 void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName)
204 {
205         const char * LOC = "MED_i::initWithFieldType(driverTypes, const string &)";
206         BEGIN_OF(LOC);
207
208   // we create all IOR from _med
209
210         SCRUTE(driverType);
211         SCRUTE(fileName)
212
213         _med = new ::MED(driverType,fileName);
214
215         int numberOfMeshes = _med->getNumberOfMeshes();
216         SCRUTE(numberOfMeshes);
217   // MESHES :
218         deque<string> meshesNames = _med->getMeshNames();
219         string meshName0 = meshesNames[0];
220
221         SCRUTE(meshName0);
222
223         for (int i=0; i<numberOfMeshes; i++) 
224         {
225             string meshNamei = meshesNames[i];
226             SCRUTE(meshNamei);
227
228             ::MESH * myMesh = _med->getMesh(meshNamei);
229             myMesh->read();
230             MESH_i * myMeshI = new MESH_i(myMesh);
231             SALOME_MED::MESH_ptr myMeshIOR = myMeshI->_this();
232             _meshes[meshesNames[i]]=myMeshIOR;
233             myMeshI->addInStudy(myStudy,myMeshIOR);
234         }
235
236   // SUPPORTS :
237         _med->updateSupport();
238
239   // FAMILIES :
240   // we add all families 
241         vector<FAMILY*> familyVector;
242         vector<FAMILY*>::iterator familyVectorIt;
243   // GROUPS :
244   // we add all groups
245         vector<GROUP*> groupVector;
246         vector<GROUP*>::iterator groupVectorIt;
247   
248         SCRUTE(numberOfMeshes);
249
250         MED_EN::MESH_ENTITIES::const_iterator currentEntity; 
251         for (int i=0; i<numberOfMeshes; i++) 
252         {
253                 ::MESH * ptrMesh = _med->getMesh(meshesNames[i]);
254
255                 SCRUTE(ptrMesh);
256
257                 for (currentEntity = MED_EN::meshEntities.begin();
258                      currentEntity != MED_EN::meshEntities.end(); 
259                      currentEntity++) 
260                 {
261                      MESSAGE(LOC << ": for entity " << (*currentEntity).first);
262                 // family :
263                      familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first);
264                      int nb = familyVector.size();
265                      MESSAGE(LOC << ": there is(are) " << nb << " family(ies)");
266                      for (familyVectorIt = familyVector.begin();
267                           familyVectorIt != familyVector.end();
268                           familyVectorIt++) 
269                      {
270                           FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt);
271                           SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this();
272                            myFamilyI->addInStudy(myStudy,myFamilyIOR);
273                      }
274
275                // group :
276                      groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first);
277                      nb = groupVector.size();
278                      MESSAGE(LOC << ": there is(are) " << nb << " group(s)");
279                     for (groupVectorIt = groupVector.begin();
280                          groupVectorIt != groupVector.end();
281                          groupVectorIt++) 
282                     {
283                          GROUP_i * myGroupI = new GROUP_i(*groupVectorIt);
284                          SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this();
285                          myGroupI->addInStudy(myStudy,myGroupIOR);
286                     }
287                 }      
288         }
289
290         for (int i=0; i<numberOfMeshes; i++) 
291         {
292             map<MED_EN::medEntityMesh,::SUPPORT*> mySupports = _med->getSupports(meshesNames[i]);
293             map<MED_EN::medEntityMesh,::SUPPORT*>::const_iterator itSupport;
294             map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> & 
295                         mySupportsIOR = _supports[meshesNames[i]];
296             for (itSupport=mySupports.begin(); itSupport!=mySupports.end(); itSupport++ ) 
297             {
298                  SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second);
299                  SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this();
300                  mySupportsIOR[(*itSupport).first]= mySupportIOR;
301                  mySupportI->addInStudy(myStudy,mySupportIOR);
302             }
303         }
304
305
306
307
308 //      for (int i=0; i<numberOfMeshes; i++) 
309 //        {
310 //          string meshName = meshesNames[i];
311 //          char * supportEntryPath;
312 //          int lenName;
313 //          string supportName;
314 //          SALOMEDS::SObject_var supportEntry;
315
316 //          supportName = "SupportOnAll_MED_MAILLE";
317 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
318 //          supportEntryPath = new char[lenName];
319 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
320 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
321 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
322 //          supportEntryPath = strcat(supportEntryPath,"/");
323 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
324
325 //          SCRUTE(supportEntryPath);
326
327 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
328
329 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
330
331 //          if ( CORBA::is_nil(supportEntry) ) 
332 //            cout << "The reuse in Med is OK " << endl;
333 //          else 
334 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
335 //          delete [] supportEntryPath;
336
337
338
339 //          supportName = "SupportOnAll_MED_FACE";
340 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
341 //          supportEntryPath = new char[lenName];
342 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
343 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
344 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
345 //          supportEntryPath = strcat(supportEntryPath,"/");
346 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
347
348 //          SCRUTE(supportEntryPath);
349
350 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
351
352 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
353
354 //          if ( CORBA::is_nil(supportEntry) ) 
355 //            cout << "The reuse in Med is OK " << endl;
356 //          else 
357 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
358 //          delete [] supportEntryPath;
359
360
361
362 //          supportName = "SupportOnAll_MED_ARETE";
363 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
364 //          supportEntryPath = new char[lenName];
365 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
366 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
367 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
368 //          supportEntryPath = strcat(supportEntryPath,"/");
369 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
370
371 //          SCRUTE(supportEntryPath);
372
373 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
374
375 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
376
377 //          if ( CORBA::is_nil(supportEntry) ) 
378 //            cout << "The reuse in Med is OK " << endl;
379 //          else 
380 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
381 //          delete [] supportEntryPath;
382
383
384
385
386 //          supportName = "SupportOnAll_MED_NOEUD";
387 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
388 //          supportEntryPath = new char[lenName];
389 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
390 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
391 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
392 //          supportEntryPath = strcat(supportEntryPath,"/");
393 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
394
395 //          SCRUTE(supportEntryPath);
396
397 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
398
399 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
400
401 //          if ( CORBA::is_nil(supportEntry) ) 
402 //            cout << "The reuse in Med is OK " << endl;
403 //          else 
404 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
405 //          delete [] supportEntryPath;
406
407
408
409
410 //        }
411
412
413
414
415
416
417
418   // FIELDS :
419         deque<string> fieldsNames = _med->getFieldNames();
420         int numberOfFields = fieldsNames.size();
421
422         SCRUTE(numberOfFields);
423
424         for (int i=0; i<numberOfFields; i++) 
425           {
426             MESSAGE("The name of the " << i << "^th fields is "<< fieldsNames[i]);
427
428             deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
429             int numberOfIteration = myIteration.size();
430
431             SCRUTE(numberOfIteration);
432
433             for (int j=0; j<numberOfIteration; j++) 
434               {
435                 MESSAGE("its " << i << "^th iteration is dt = " << myIteration[j].dt << " it = " << myIteration[j].it);
436               }
437           }
438
439         for (int i=0; i<numberOfFields; i++) 
440           {
441
442             MESSAGE("dealing with the fields collection " << fieldsNames[i]);
443
444              deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
445              int numberOfIteration = myIteration.size();
446
447              SCRUTE(numberOfIteration);
448
449              for (int j=0; j<numberOfIteration; j++) 
450              {
451                int dt = myIteration[j].dt;
452                int it = myIteration[j].it;
453
454                MESSAGE("Treatement of " << fieldsNames[i] << " dt = " << dt << " it = " << it);
455
456                   ::FIELD_ * myField = _med->getField(fieldsNames[i],dt,it);
457
458                   string meshName = myField->getSupport()->getMesh()->getName();
459                   medEntityMesh myEntity = myField->getSupport()->getEntity();
460                   map<string, map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> >::const_iterator 
461                         itSupportOnMesh = _supports.find(meshName);
462                   if (itSupportOnMesh == _supports.end() )
463                         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
464                                          << "There is no support on mesh named |" 
465                                          << meshName << "|"));
466                   const map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> & SupportOnMesh 
467                                 = (*itSupportOnMesh).second;
468                   map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport
469                                 = SupportOnMesh.find(myEntity);
470                   if (itSupport == SupportOnMesh.end() )
471                         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
472                                          << "There is no support on entity "
473                                          << entity << " in mesh named |" 
474                                          << meshName << "|"));
475                   SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second;
476                   med_type_champ type = myField->getValueType();
477
478                   DT_IT_ dtIt;
479                   dtIt.dt  = dt;
480                   dtIt.it  = it;
481
482                   switch (type) 
483                   {
484                      case MED_EN::MED_INT32: 
485                      {
486                         ((FIELD<int>*)myField)->read();
487                         FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD<int>*)myField);
488                         SALOME_MED::FIELDINT_ptr myFieldIntIOR;
489                         myFieldIntIOR = myFieldIntI->_this();
490
491                         MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it);
492
493                         myFieldIntI->addInStudy(myStudy,myFieldIntIOR);
494                         _fields[fieldsNames[i]][dtIt] = myFieldIntIOR;
495                         break;
496                      }
497
498                      case MED_EN::MED_REEL64: 
499                      {
500                         ((FIELD<double>*)myField)->read();
501                         FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD<double>*)myField);
502                         SALOME_MED::FIELDDOUBLE_ptr myFieldDoubleIOR;
503                         myFieldDoubleIOR = myFieldDoubleI->_this();
504
505                         MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it);
506
507                         myFieldDoubleI->addInStudy(myStudy,myFieldDoubleIOR);
508                         _fields[fieldsNames[i]][dtIt] = myFieldDoubleIOR;
509                         break;
510                      }
511
512                     default: 
513                     {
514                         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
515                                          <<"   * Iteration "<<FieldIteration[j].dt
516                                          <<", order number "<<FieldIteration[j].it
517                                          <<" has wrong type : "<<type));
518                         break;
519                      }
520                   }
521              }
522
523              MESSAGE("Here we are i="<< i);
524         }
525   
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540 //      for (int i=0; i<numberOfMeshes; i++) 
541 //        {
542 //          string meshName = meshesNames[i];
543 //          char * supportEntryPath;
544 //          int lenName;
545 //          string supportName;
546 //          SALOMEDS::SObject_var supportEntry;
547
548 //          supportName = "SupportOnAll_MED_MAILLE";
549 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
550 //          supportEntryPath = new char[lenName];
551 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
552 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
553 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
554 //          supportEntryPath = strcat(supportEntryPath,"/");
555 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
556
557 //          SCRUTE(supportEntryPath);
558
559 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
560
561 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
562
563 //          if ( CORBA::is_nil(supportEntry) ) 
564 //            cout << "The reuse in Med is OK " << endl;
565 //          else 
566 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
567 //          delete [] supportEntryPath;
568
569
570
571 //          supportName = "SupportOnAll_MED_FACE";
572 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
573 //          supportEntryPath = new char[lenName];
574 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
575 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
576 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
577 //          supportEntryPath = strcat(supportEntryPath,"/");
578 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
579
580 //          SCRUTE(supportEntryPath);
581
582 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
583
584 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
585
586 //          if ( CORBA::is_nil(supportEntry) ) 
587 //            cout << "The reuse in Med is OK " << endl;
588 //          else 
589 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
590 //          delete [] supportEntryPath;
591
592
593
594 //          supportName = "SupportOnAll_MED_ARETE";
595 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
596 //          supportEntryPath = new char[lenName];
597 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
598 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
599 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
600 //          supportEntryPath = strcat(supportEntryPath,"/");
601 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
602
603 //          SCRUTE(supportEntryPath);
604
605 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
606
607 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
608
609 //          if ( CORBA::is_nil(supportEntry) ) 
610 //            cout << "The reuse in Med is OK " << endl;
611 //          else 
612 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
613 //          delete [] supportEntryPath;
614
615
616
617
618 //          supportName = "SupportOnAll_MED_NOEUD";
619 //          lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
620 //          supportEntryPath = new char[lenName];
621 //          supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
622 //          supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
623 //          supportEntryPath = strcat(supportEntryPath,meshName.c_str());
624 //          supportEntryPath = strcat(supportEntryPath,"/");
625 //          supportEntryPath = strcat(supportEntryPath,supportName.c_str());
626
627 //          SCRUTE(supportEntryPath);
628
629 //          cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
630
631 //          supportEntry = myStudy->FindObjectByPath(supportEntryPath);
632
633 //          if ( CORBA::is_nil(supportEntry) ) 
634 //            cout << "The reuse in Med is OK " << endl;
635 //          else 
636 //            cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
637 //          delete [] supportEntryPath;
638
639
640
641
642 //        }
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658         END_OF(LOC);
659 }
660
661 //=============================================================================
662 /*!
663  * Destructor
664  */
665 //=============================================================================
666 MED_i::~MED_i()
667 {
668 }
669 //=============================================================================
670 /*!
671  * CORBA: Accessor for Number of meshes
672  */
673 //=============================================================================
674 CORBA::Long MED_i::getNumberOfMeshes() 
675 throw (SALOME::SALOME_Exception)
676 {
677         if (_med==NULL)
678                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
679                                              SALOME::INTERNAL_ERROR);
680         try
681         {
682                 return _med->getNumberOfMeshes();
683         }
684         catch (MEDEXCEPTION &ex)
685         {
686                 MESSAGE("Unable to get the number of meshes in Med Object");
687                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
688         }
689 }
690 //=============================================================================
691 /*!
692  * CORBA: Accessor for Number of fields
693  */
694 //=============================================================================
695 CORBA::Long MED_i::getNumberOfFields() 
696 throw (SALOME::SALOME_Exception)
697 {
698         if (_med==NULL)
699                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
700                                              SALOME::INTERNAL_ERROR);
701         try
702         {
703                 return _med->getNumberOfFields();
704         }
705         catch (MEDEXCEPTION &ex)
706         {
707                 MESSAGE("Unable to get the number of fields in Med Object");
708                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
709         }
710 }
711 //=============================================================================
712 /*!
713  * CORBA: Accessor for meshes names
714  */
715 //=============================================================================
716 SALOME_MED::string_array * MED_i::getMeshNames()      
717 throw (SALOME::SALOME_Exception)
718 {
719         if (_med==NULL)
720                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
721                                              SALOME::INTERNAL_ERROR);
722         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
723         try
724         {
725                 int nbMeshes=_med->getNumberOfMeshes();
726                 myseq->length(nbMeshes);
727                 string * nameMeshes = new string[nbMeshes];
728                 _med->getMeshNames(nameMeshes);
729                 for (int i=0;i<nbMeshes;i++)
730                 {
731                         myseq[i]=CORBA::string_dup(nameMeshes[i].c_str());
732                 }
733                 delete [] nameMeshes;
734                 nameMeshes=NULL;
735         }
736         catch (MEDEXCEPTION &ex)
737         {
738                 MESSAGE("Unable to get the names of the meshes in Med Object");
739                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
740         }
741         return myseq._retn();
742 }
743 //=============================================================================
744 /*!
745  * CORBA: Accessor for fields names
746  */
747 //=============================================================================
748 SALOME_MED::string_array * MED_i::getFieldNames()     
749   throw (SALOME::SALOME_Exception)
750 {
751   if (_med==NULL)
752     THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
753                                              SALOME::INTERNAL_ERROR);
754   SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
755   try
756     {
757       deque<string> nameFields = _med->getFieldNames();
758       int nbFields = nameFields.size();
759       myseq->length(nbFields);
760
761       for (int i=0;i<nbFields;i++)
762         {
763           myseq[i]=CORBA::string_dup(nameFields[i].c_str());
764         }
765     }
766   catch (MEDEXCEPTION &ex)
767     {
768       MESSAGE("Unable to get the names of the fields in Med Object");
769       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
770     }
771   return myseq._retn();
772 }
773 //=============================================================================
774 /*!
775  * CORBA: Accessor for a specific mesh
776  */
777 //=============================================================================
778 SALOME_MED::MESH_ptr MED_i::getMeshByName(const char* meshName) 
779 throw (SALOME::SALOME_Exception)
780 {
781         if (_med==NULL)
782                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
783                                              SALOME::INTERNAL_ERROR);
784         try
785         {
786                 MESH * mesh=_med->getMesh(meshName);
787                 MESH_i * m1 = new MESH_i(mesh);
788                 return m1->POA_SALOME_MED::MESH::_this();
789         }
790         catch (MEDEXCEPTION &ex)
791         {
792                 MESSAGE("Unable to get the specified mesh");
793                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
794         }
795
796 }
797 //=============================================================================
798 /*!
799  * CORBA: Accessor for a specific mesh
800  */
801 //=============================================================================
802 SALOME_MED::MESH_ptr MED_i::getMesh(SALOME_MED::FIELD_ptr fieldPtr) 
803 throw (SALOME::SALOME_Exception)
804 {
805         if (_med==NULL)
806                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
807                                              SALOME::INTERNAL_ERROR);
808         int ind=fieldPtr->getCorbaIndex();
809         SCRUTE(ind);
810
811         MESH * mesh;
812         SALOME_MED::FIELDINT_var fieldint =SALOME_MED::FIELDINT::_narrow(fieldPtr);
813         if (CORBA::is_nil(fieldint))
814         {
815                 MESSAGE("Double");
816                 SALOME_MED::FIELDDOUBLE_var fielddouble = 
817                             SALOME_MED::FIELDDOUBLE::_narrow(fieldPtr);
818                 ASSERT(!CORBA::is_nil(fielddouble));
819
820                 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
821
822                 ::FIELD<double> * fdouble = (::FIELD<double> *)FIELD_i::fieldMap[ind];
823                 MESH * mesh=_med->getMesh(fdouble);
824         }
825         else
826         {
827                 MESSAGE("Integer");
828                 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
829
830                 ::FIELD<int> * fint = (::FIELD<int> *)FIELD_i::fieldMap[ind];
831                 MESH * mesh=_med->getMesh(fint);
832         }
833         MESH_i * meshi = new MESH_i(mesh);
834         return meshi->POA_SALOME_MED::MESH::_this();
835
836 }
837 //=============================================================================
838 /*!
839  * CORBA: Accessor for Number of iteration of a given field by its name.
840  */
841 //=============================================================================
842 CORBA::Long MED_i::getFieldNumberOfIteration(const char* fieldName) 
843   throw (SALOME::SALOME_Exception)
844 {
845   if (_med==NULL)
846     THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
847                                  SALOME::INTERNAL_ERROR);
848
849   try
850     {
851       deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
852       return fieldIteration.size();
853     }
854   catch (MEDEXCEPTION &ex)
855     {
856       MESSAGE("Unable to get the number of iteration of the field " << fieldName << " in Med Object");
857       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
858     }
859 }
860 //=============================================================================
861 /*!
862  * CORBA: Accessor for the Corba equivalent DT_IT_ (see MEDMEM direcrtory)
863  * of a given field by its name and its number (sequence of two long integers).
864  */
865 //=============================================================================
866 SALOME_MED::long_array * MED_i::getFieldIteration(const char* fieldName,CORBA::Long i) 
867   throw (SALOME::SALOME_Exception)
868 {
869   if (_med==NULL)
870     THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
871                                  SALOME::INTERNAL_ERROR);
872
873   SALOME_MED::long_array_var myseq = new SALOME_MED::long_array;
874   try
875     {
876       deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
877       int numberOfIteration = fieldIteration.size();
878
879       if (i < 0 || i >=numberOfIteration)
880         THROW_SALOME_CORBA_EXCEPTION("The integer i should be geater or equal to 0 and lesser then numberOfIteration", \
881                                      SALOME::INTERNAL_ERROR);
882
883       myseq->length(2);
884       myseq[0] = fieldIteration[i].dt;
885       myseq[1] = fieldIteration[i].it;
886       return myseq._retn();
887     }
888   catch (MEDEXCEPTION &ex)
889     {
890       MESSAGE("Unable to get the sequence of DT_IT of the given field");
891       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
892     }
893 }
894 //=============================================================================
895 /*!
896  * CORBA: Accessor for the list of Corba equivalent DT_IT_ (see MEDMEM direcrtory)
897  * of a given field by its name (sequence of two by iteration number long integers).
898  */
899 //=============================================================================
900 SALOME_MED::long_array * MED_i::getFieldIterations(const char* fieldName) 
901   throw (SALOME::SALOME_Exception)
902 {
903   if (_med==NULL)
904     THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
905                                  SALOME::INTERNAL_ERROR);
906
907   SALOME_MED::long_array_var myseq = new SALOME_MED::long_array;
908   try
909     {
910       deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
911       int numberOfIteration = fieldIteration.size();
912       int size = 2*numberOfIteration;
913
914       myseq->length(size);
915
916       for (int i=0; i<numberOfIteration; i++)
917         {
918           int index = 2*i;
919           myseq[index] = fieldIteration[i].dt;
920           index = index+1;
921           myseq[index] = fieldIteration[i].it;
922         }
923
924       return myseq._retn();
925     }
926   catch (MEDEXCEPTION &ex)
927     {
928       MESSAGE("Unable to get the sequence of DT_IT of the given field");
929       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
930     }
931 }
932 //=============================================================================
933 /*!
934  * CORBA: Accessor for a specific field
935  */
936 //=============================================================================
937 SALOME_MED::FIELD_ptr MED_i::getField(const char* fieldName, 
938                                       CORBA::Long pasTemps, 
939                                       CORBA::Long numOrdre ) 
940 throw (SALOME::SALOME_Exception)
941 {
942         const char * LOC="MED_i::getField(const char*,CORBA::Long,CORBA::Long) ";
943         BEGIN_OF(LOC);
944
945         DT_IT_ dtIt;
946
947         dtIt.dt= (int)pasTemps;
948         dtIt.it= (int)numOrdre;
949
950         map<string,MAP_IOR_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
951
952         if ( itFields == _fields.end() ) 
953                 THROW_SALOME_CORBA_EXCEPTION("Field not found !", SALOME::INTERNAL_ERROR);
954   
955         const MAP_IOR_DT_IT_ & map_dtIt = (*itFields).second;
956         MAP_IOR_DT_IT_::const_iterator itMap_dtIt =  map_dtIt.find(dtIt);
957   
958         if ( itMap_dtIt == map_dtIt.end() )
959                 THROW_SALOME_CORBA_EXCEPTION("Iteration not found !", SALOME::INTERNAL_ERROR);
960   
961         END_OF(LOC);
962         return (*itMap_dtIt).second;
963
964 }
965 //=============================================================================
966 /*!
967  * CORBA: Accessor for a specific field
968  */
969 //=============================================================================
970 CORBA::Long MED_i::addDriver(SALOME_MED::medDriverTypes driverType, const char* fileName) 
971 throw (SALOME::SALOME_Exception)
972 {
973         if (_med==NULL)
974                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
975                                              SALOME::INTERNAL_ERROR);
976         try
977         {
978                 int driv=_med->addDriver(convertIdlDriverToMedDriver(driverType),
979                                         fileName);
980                 return driv;
981         }
982         catch (MEDEXCEPTION &ex)
983         {
984                 MESSAGE("Unable to add a driver to the med object");
985                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
986         }
987         
988 }
989 //=============================================================================
990 /*!
991  * CORBA: relase the driver (mandatory)
992  */
993 //=============================================================================
994 void MED_i::rmDriver(CORBA::Long i) 
995 throw (SALOME::SALOME_Exception)
996 {
997         if (_med==NULL)
998                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
999                                              SALOME::INTERNAL_ERROR);
1000         try
1001         {
1002                 _med->rmDriver(i);
1003         }
1004         catch (MEDEXCEPTION &ex)
1005         {
1006                 MESSAGE("Unable to unlink the driver from the med object");
1007                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1008         }
1009 }
1010 //=============================================================================
1011 /*!
1012  * CORBA: read med objects relations
1013  */
1014 //=============================================================================
1015 void MED_i::readFileStruct(CORBA::Long i) 
1016 throw (SALOME::SALOME_Exception)
1017 {
1018         if (_med==NULL)
1019                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1020                                              SALOME::INTERNAL_ERROR);
1021         try
1022         {
1023                 _med->readFileStruct(i);
1024         }
1025         catch (MEDEXCEPTION &ex)
1026         {
1027                 MESSAGE("Unable to read the structure of this file ");
1028                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1029         }
1030 }
1031 //=============================================================================
1032 /*!
1033  * CORBA: write specifics objects f
1034  */
1035 //=============================================================================
1036 void MED_i::writeFrom(CORBA::Long i) 
1037 throw (SALOME::SALOME_Exception)
1038 {
1039         if (_med==NULL)
1040                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1041                                              SALOME::INTERNAL_ERROR);
1042         try
1043         {
1044                 _med->writeFrom(i);
1045         }
1046         catch (MEDEXCEPTION &ex)
1047         {
1048                 MESSAGE("Unable to write this driver ");
1049                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1050         }
1051 }
1052 //=============================================================================
1053 /*!
1054  * CORBA: write objects
1055  */
1056 //=============================================================================
1057 void MED_i::write(CORBA::Long i) 
1058 throw (SALOME::SALOME_Exception)
1059 {
1060         if (_med==NULL)
1061                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1062                                              SALOME::INTERNAL_ERROR);
1063         try
1064         {
1065                 _med->write(i);
1066         }
1067         catch (MEDEXCEPTION &ex)
1068         {
1069                 MESSAGE("Unable to write this file ");
1070                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1071         }
1072 }
1073 //=============================================================================
1074 /*!
1075  * CORBA: Add Mesh in Med objects
1076  */
1077 //=============================================================================
1078 void MED_i::addMesh(SALOME_MED::MESH_ptr ptrMesh) 
1079 throw (SALOME::SALOME_Exception)
1080 {
1081         if (_med==NULL)
1082                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1083                                              SALOME::INTERNAL_ERROR);
1084         try
1085         {
1086                 int ind=ptrMesh->getCorbaIndex();
1087                 SCRUTE(ind);
1088                 ASSERT(MESH_i::meshMap.find(ind) !=MESH_i::meshMap.end());
1089                 MESH * mesh= MESH_i::meshMap[ind];
1090                 _med->addMesh(mesh);
1091         }
1092         catch (MEDEXCEPTION &ex)
1093         {
1094                 MESSAGE("Unable to link this mesh to this med object");
1095                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1096         }
1097 }
1098 //=============================================================================
1099 /*!
1100  * CORBA: Add field in Med objects
1101  */
1102 //=============================================================================
1103 void MED_i::addField(SALOME_MED::FIELD_ptr ptrField) 
1104 throw (SALOME::SALOME_Exception)
1105 {
1106         if (_med==NULL)
1107                 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1108                                              SALOME::INTERNAL_ERROR);
1109         int ind=ptrField->getCorbaIndex();
1110         SCRUTE(ind);
1111
1112         SALOME_MED::FIELDINT_var fieldint =SALOME_MED::FIELDINT::_narrow(ptrField);
1113         if (CORBA::is_nil(fieldint))
1114         {
1115                 MESSAGE("Double");
1116                 SALOME_MED::FIELDDOUBLE_var fielddouble = 
1117                             SALOME_MED::FIELDDOUBLE::_narrow(ptrField);
1118                 ASSERT(!CORBA::is_nil(fielddouble));
1119
1120                 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
1121
1122                 ::FIELD<double> * fdouble = (::FIELD<double> *)FIELD_i::fieldMap[ind];
1123                 // A modifier
1124                 //_med->addField(fdouble);
1125         }
1126         else
1127         {
1128                 MESSAGE("Integer");
1129                 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
1130                 ::FIELD<int> * fint = (::FIELD<int> *)FIELD_i::fieldMap[ind];
1131                 //_med->addField(fint);
1132         }
1133 }
1134 //=============================================================================
1135 /*!
1136  * CORBA: Add Med object in Study 
1137  */
1138 //=============================================================================
1139 void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor) 
1140 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1141 {
1142         BEGIN_OF("MED_Mesh_i::addInStudy");
1143         if ( _medId != "" )
1144         {
1145                 MESSAGE("Med already in Study");
1146                     THROW_SALOME_CORBA_EXCEPTION("Med already in Study", \
1147                                  SALOME::BAD_PARAM);
1148         };
1149
1150         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1151         myBuilder->NewCommand();
1152         SALOMEDS::GenericAttribute_var anAttr;
1153         SALOMEDS::AttributeName_var    aName;
1154         SALOMEDS::AttributeIOR_var     aIOR;
1155
1156         // Create SComponent labelled 'MED' if it doesn't already exit
1157         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1158         if ( CORBA::is_nil(medfather) )
1159         {
1160           THROW_SALOME_CORBA_EXCEPTION("Component Med not found",
1161                                        SALOME::BAD_PARAM);
1162         };
1163
1164         MESSAGE("Add a MED Object under Med");
1165         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
1166
1167         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1168         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
1169         CORBA::ORB_var &orb = init(0,0);
1170         string iorStr = orb->object_to_string(myIor);
1171         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1172         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1173         aIOR->SetValue(iorStr.c_str());
1174         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1175         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1176         aName->SetValue("Objet MED");
1177         _medId = newObj->GetID();
1178         myBuilder->CommitCommand();
1179
1180         // register the Corba pointer: increase the referrence count
1181         MESSAGE("Registering of the Corba Med pointer");
1182         Register();
1183
1184         END_OF("Med_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
1185 }
1186
1187 //=============================================================================
1188 /*!
1189  * CORBA: Add Med object in Study with a name medObjName
1190  */
1191 //=============================================================================
1192 void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor,
1193                        const char * fileName) 
1194   throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1195 {
1196         BEGIN_OF("MED_i::addInStudy(myStudy, myIor, fileName)");
1197         if ( _medId != "" )
1198         {
1199                 MESSAGE("Med already in Study");
1200                     THROW_SALOME_CORBA_EXCEPTION("Med already in Study", \
1201                                  SALOME::BAD_PARAM);
1202         };
1203
1204         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1205         myBuilder->NewCommand();
1206         SALOMEDS::GenericAttribute_var anAttr;
1207         SALOMEDS::AttributeName_var    aName;
1208         SALOMEDS::AttributeIOR_var     aIOR;
1209
1210         // Create SComponent labelled 'MED' if it doesn't already exit
1211         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1212         if ( CORBA::is_nil(medfather) )
1213         {
1214           THROW_SALOME_CORBA_EXCEPTION("Component Med not found",
1215                                        SALOME::BAD_PARAM);
1216         };
1217
1218         MESSAGE("Add a MED Object under Med");
1219
1220         char * medObjName;
1221         string::size_type pos1=string(fileName).rfind('/');
1222         string::size_type lenFileName = strlen(fileName);
1223         string fileNameShort = string(fileName,pos1+1,lenFileName-pos1-1);
1224
1225         SCRUTE(fileNameShort);
1226
1227         int lenName = 21 + strlen(fileNameShort.c_str()) + 1;
1228         medObjName = new char[lenName];
1229         medObjName = strcpy(medObjName,"MED_OBJECT_FROM_FILE_");
1230         medObjName = strcat(medObjName,fileNameShort.c_str());
1231
1232         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
1233
1234         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1235         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
1236         CORBA::ORB_var &orb = init(0,0);
1237         string iorStr = orb->object_to_string(myIor);
1238         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1239         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1240         aIOR->SetValue(iorStr.c_str());
1241         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1242         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1243         aName->SetValue(medObjName);
1244         _medId = newObj->GetID();
1245         myBuilder->CommitCommand();
1246
1247         delete [] medObjName;
1248
1249 //      char * medObjName1;
1250 //      lenName = 26 + strlen(fileNameShort.c_str());
1251 //      medObjName1 = new char[lenName];
1252 //      medObjName1 = strcpy(medObjName1,"/MED/MED_OBJECT_FROM_FILE_");
1253 //      medObjName1 = strcat(medObjName1,fileNameShort.c_str());
1254
1255 //      SALOMEDS::SObject_var medEntry = myStudy->FindObjectByPath(medObjName1);
1256 //      if (!CORBA::is_nil(medEntry))
1257 //        {
1258 //          MESSAGE("MED_Mesh_i::addInStudy(myStudy, myIor, fileName) : The reuse in Med of Object MED from Study is OK");
1259 //        }
1260 //      else
1261 //        {
1262 //          MESSAGE("MED_Mesh_i::addInStudy(myStudy, myIor, fileName) : the reuse in Med of Object MED is not OK and there was a problem in the storage in the study");
1263 //        }
1264
1265 //      delete [] medObjName1;
1266
1267         // register the Corba pointer: increase the referrence count
1268         MESSAGE("Registering of the Corba Med pointer");
1269         Register();
1270
1271         END_OF("Med_i::addInStudy(myStudy, myIor, medObjName)");
1272 }