Salome HOME
updating the main trunk with the CEA debug devellopment from the branch
[modules/med.git] / src / MEDMEM_I / MEDMEM_Support_i.cxx
1 //=============================================================================
2 // File      : MEDMEM_Support_i.cxx
3 // Project   : SALOME
4 // Author    : EDF
5 // Copyright : EDF 2002
6 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Support_i.cxx
7 //=============================================================================
8
9 #include "utilities.h"
10 #include "Utils_CorbaException.hxx"
11 #include "Utils_ORB_INIT.hxx"
12 #include "Utils_SINGLETON.hxx"
13
14 #include CORBA_SERVER_HEADER(MED)
15 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
16
17
18 #include "MEDMEM_define.hxx"
19 #include "MEDMEM_Support.hxx"
20
21 #include "MEDMEM_Support_i.hxx"
22 #include "MEDMEM_Mesh_i.hxx"
23 #include "MEDMEM_convert.hxx"
24
25 #include "SenderFactory.hxx"
26 #include "MultiCommException.hxx"
27 using namespace MEDMEM;
28
29 // Initialisation des variables statiques
30 map < int, ::SUPPORT *> SUPPORT_i::supportMap ;
31 int SUPPORT_i::supportIndex = 0 ;
32
33
34 //=============================================================================
35 /*!
36  * Default constructor
37  */
38 //=============================================================================
39 SUPPORT_i::SUPPORT_i() :_support((::SUPPORT *)NULL),_corbaIndex(SUPPORT_i::supportIndex++)
40 {
41         BEGIN_OF("Default Constructor SUPPORT_i");
42         END_OF("Default Constructor SUPPORT_i");
43 }
44
45 //=============================================================================
46 /*!
47  * Constructor
48  */
49 //=============================================================================
50 SUPPORT_i::SUPPORT_i(const ::SUPPORT * const s) :_support(s),
51                    _corbaIndex(SUPPORT_i::supportIndex++)
52 {
53         BEGIN_OF("Constructor SUPPORT_i");
54         SUPPORT_i::supportMap[_corbaIndex]=(::SUPPORT *)_support;
55         END_OF("Constructor SUPPORT_i");
56 }
57 //=============================================================================
58 /*!
59  * Constructor
60  */
61 //=============================================================================
62 SUPPORT_i::SUPPORT_i(const SUPPORT_i &s) :_support(s._support),
63                             _corbaIndex(SUPPORT_i::supportIndex++)
64 {
65         BEGIN_OF("Constructor SUPPORT_i");
66         SUPPORT_i::supportMap[_corbaIndex]=(::SUPPORT *)_support;
67         END_OF("Constructor SUPPORT_i");
68 }
69 //=============================================================================
70 /*!
71  * Destructor
72  */
73 //=============================================================================
74
75 SUPPORT_i::~SUPPORT_i()
76 {
77 }
78 //=============================================================================
79 /*!
80  * CORBA: Accessor for Corba Index 
81  */
82 //=============================================================================
83
84 CORBA::Long SUPPORT_i::getCorbaIndex()
85 throw (SALOME::SALOME_Exception)
86 {
87         if (_support==NULL)
88                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
89                                              SALOME::INTERNAL_ERROR);
90         return _corbaIndex;
91 }
92
93 //=============================================================================
94 /*!
95  * CORBA: Accessor for Name 
96  */
97 //=============================================================================
98
99 char * SUPPORT_i::getName()     
100 throw (SALOME::SALOME_Exception)
101 {
102         if (_support==NULL)
103                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
104                                              SALOME::INTERNAL_ERROR);
105         try
106         {
107                 return CORBA::string_dup(_support->getName().c_str());
108         }
109         catch (MEDEXCEPTION &ex)
110         {
111                 MESSAGE("Unable to access the name of the support ");
112                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
113         }
114
115 }
116
117 //=============================================================================
118 /*!
119  * CORBA: Accessor for Description 
120  */
121 //=============================================================================
122
123 char*  SUPPORT_i::getDescription()
124 throw (SALOME::SALOME_Exception)
125 {
126         if (_support==NULL)
127                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
128                                              SALOME::INTERNAL_ERROR);
129         try
130         {
131                 return CORBA::string_dup(_support->getDescription().c_str());
132         }
133         catch (MEDEXCEPTION &ex)
134         {
135                 MESSAGE("Unable to access the description of the support ");
136                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
137         }
138 }
139
140 //=============================================================================
141 /*!
142  * CORBA: Accessor for Description and Name
143  */
144 //=============================================================================
145
146 SALOME_MED::SUPPORT::supportInfos * SUPPORT_i::getSupportGlobal()
147 throw (SALOME::SALOME_Exception)
148 {
149         if (_support==NULL)
150                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
151                                              SALOME::INTERNAL_ERROR);
152         SALOME_MED::SUPPORT::supportInfos_var all = new SALOME_MED::SUPPORT::supportInfos;
153         try
154         {
155                 all->name               = CORBA::string_dup(_support->getName().c_str());
156                 all->description        = CORBA::string_dup(_support->getDescription().c_str());
157                 const int numberOfTypes = _support->getNumberOfTypes();
158                 all->numberOfGeometricType = numberOfTypes;
159                 all->entity = _support->getEntity();
160
161                 all->types.length(numberOfTypes);
162                 all->nbEltTypes.length(numberOfTypes);
163                 const medGeometryElement * elemts = _support->getTypes();
164                 for (int i=0;i<numberOfTypes;i++)
165                 {
166                         all->types[i]      = convertMedEltToIdlElt(elemts[i]);
167                         all->nbEltTypes[i] = _support->getNumberOfElements(elemts[i]);
168                 }
169         }
170         catch (MEDEXCEPTION &ex)
171         {
172                 MESSAGE("Unable to access the description of the support ");
173                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
174         }
175         return all._retn();
176
177 }
178
179
180 //=============================================================================
181 /*!
182  * CORBA: Accessor for Mesh 
183  */
184 //=============================================================================
185
186 SALOME_MED::MESH_ptr SUPPORT_i::getMesh()
187 throw (SALOME::SALOME_Exception)
188 {
189   BEGIN_OF("SALOME_MED::MESH_ptr SUPPORT_i::getMesh()");
190
191         if (_support==NULL)
192                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
193                                              SALOME::INTERNAL_ERROR);
194         try
195         {
196                 MESH * mesh = _support->getMesh();
197
198                 SCRUTE(mesh) ;
199
200                 MESH_i * m1 = new MESH_i(mesh);
201                 SALOME_MED::MESH_ptr m2 = m1->POA_SALOME_MED::MESH::_this();
202                 MESSAGE("SALOME_MED::MESH_ptr SUPPORT_i::getMesh() checking des pointeurs CORBA");
203
204                 SCRUTE(m1);
205                 SCRUTE(m2);
206
207                 END_OF("SALOME_MED::MESH_ptr SUPPORT_i::getMesh()");
208
209                 return (m2);
210         }
211         catch (MEDEXCEPTION &ex)
212         {
213                 MESSAGE("Unable to access the assoicated mesh");
214                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
215         }
216 }
217
218 //=============================================================================
219 /*!
220  * CORBA: boolean indicating if support concerns all elements 
221  */
222 //=============================================================================
223
224 CORBA::Boolean SUPPORT_i::isOnAllElements()
225 throw (SALOME::SALOME_Exception)
226 {
227         if (_support==NULL)
228                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
229                                              SALOME::INTERNAL_ERROR);
230         try
231         {
232                 return _support->isOnAllElements();
233         }
234         catch (MEDEXCEPTION &ex)
235         {
236                 MESSAGE("Unable to access the type of the support");
237                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
238         }
239 }
240
241 //=============================================================================
242 /*!
243  * CORBA:
244  */
245 //=============================================================================
246 CORBA::Long SUPPORT_i::getNumberOfTypes()
247 throw (SALOME::SALOME_Exception)
248 {
249         if (_support==NULL)
250                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
251                                              SALOME::INTERNAL_ERROR);
252         try
253         {
254                 return _support->getNumberOfTypes();
255         }
256         catch (MEDEXCEPTION &ex)
257         {
258                 MESSAGE("Unable to access  number of support different types");
259                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
260         }
261
262 }
263
264
265 //=============================================================================
266 /*!
267  * CORBA: Accessor for type of support's entity 
268  */
269 //=============================================================================
270
271 SALOME_MED::medEntityMesh SUPPORT_i::getEntity() 
272 throw (SALOME::SALOME_Exception)
273 {
274   BEGIN_OF("SALOME_MED::medEntityMesh SUPPORT_i::getEntity()");
275
276   if (_support==NULL)
277     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
278                                              SALOME::INTERNAL_ERROR);
279   try
280     {
281       END_OF("SALOME_MED::medEntityMesh SUPPORT_i::getEntity()");
282       return convertMedEntToIdlEnt(_support->getEntity());
283     }
284   catch (MEDEXCEPTION &ex)
285     {
286       MESSAGE("Unable to access support s entity");
287                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
288     }
289 }
290
291 //=============================================================================
292 /*!
293  * CORBA: Accessor for types of geometry elements 
294  */
295 //=============================================================================
296
297 SALOME_MED::medGeometryElement_array * SUPPORT_i::getTypes() 
298 throw (SALOME::SALOME_Exception)
299 {
300         if (_support==NULL)
301                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
302                                              SALOME::INTERNAL_ERROR);
303         SALOME_MED::medGeometryElement_array_var myseq = new SALOME_MED::medGeometryElement_array;
304         try
305         {
306                 int mySeqLength=_support->getNumberOfTypes();
307                 myseq->length(mySeqLength);
308                 const medGeometryElement * elemts = _support->getTypes();
309                 for (int i=0;i<mySeqLength;i++)
310                 {
311                         myseq[i]=convertMedEltToIdlElt(elemts[i]);
312                 }
313         }
314         catch (MEDEXCEPTION &ex)
315         {
316                 MESSAGE("Unable to access support different types");
317                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
318         }
319         return myseq._retn();
320 }
321
322 //=============================================================================
323 /*!
324  * CORBA: Number of different types of geometry elements
325  *        existing in the support
326  */
327 //=============================================================================
328 CORBA::Long SUPPORT_i::getNumberOfElements(SALOME_MED::medGeometryElement geomElement) 
329 throw (SALOME::SALOME_Exception)
330 {
331
332   SCRUTE(geomElement);
333   SCRUTE(SALOME_MED::MED_ALL_ELEMENTS);
334
335         if (_support==NULL)
336                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
337                                              SALOME::INTERNAL_ERROR);
338         try
339         {
340                 return _support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
341         }
342         catch (MEDEXCEPTION &ex)
343         {
344                 MESSAGE("Unable to access the number of support different types");
345                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
346         }
347
348 }
349
350 //=============================================================================
351 /*!
352  * CORBA: get Nodes 
353  */
354 //=============================================================================
355
356 SALOME_MED::long_array *  SUPPORT_i::getNumber(SALOME_MED::medGeometryElement geomElement) 
357 throw (SALOME::SALOME_Exception)
358 {
359   SCRUTE(_support);
360   SCRUTE(geomElement);
361   SCRUTE(convertIdlEltToMedElt(geomElement));
362
363         if (_support==NULL)
364                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
365                                              SALOME::INTERNAL_ERROR);
366         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
367         try
368         {
369                 int nbelements=_support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
370                 myseq->length(nbelements);
371 SCRUTE(_support->getName());
372 SCRUTE(nbelements);
373 SCRUTE(convertIdlEltToMedElt(geomElement));
374                 const int * numbers=_support->getNumber(convertIdlEltToMedElt(geomElement));
375                 for (int i=0;i<nbelements;i++)
376                 {
377                         myseq[i]=numbers[i];
378 SCRUTE(numbers[i]);
379                 }
380         }
381         catch (MEDEXCEPTION &ex)
382         {
383                 MESSAGE("Unable to access the support optionnal index");
384                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
385         }
386         return myseq._retn();
387         
388 }
389
390 //=============================================================================
391 /*!
392  * CORBA: 2nd get Nodes 
393  */
394 //=============================================================================
395 SALOME::SenderInt_ptr SUPPORT_i::getSenderForNumber(SALOME_MED::medGeometryElement geomElement) 
396                                            throw (SALOME::SALOME_Exception)
397 {
398   SCRUTE(_support);
399   SCRUTE(geomElement);
400   SCRUTE(convertIdlEltToMedElt(geomElement));
401   if (_support==NULL)
402     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
403                                  SALOME::INTERNAL_ERROR);
404   SALOME::SenderInt_ptr ret;
405   try
406     {
407       int nbelements=_support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
408       const int * numbers=_support->getNumber(convertIdlEltToMedElt(geomElement));
409       ret=SenderFactory::buildSender(*this,numbers,nbelements);
410     }
411   catch (MEDEXCEPTION &ex)
412     {
413       MESSAGE("Unable to access the support optionnal index");
414       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
415     }
416   catch(MultiCommException &ex2)
417           THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
418   return ret;
419 }
420 //=============================================================================
421 /*!
422  * CORBA: Global Nodes Index (optionnaly designed by the user)
423  * CORBA:  ??????????????????????????????
424  */
425 //=============================================================================
426
427 SALOME_MED::long_array *  SUPPORT_i::getNumberIndex()
428 throw (SALOME::SALOME_Exception)
429 {
430         if (_support==NULL)
431                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
432                                              SALOME::INTERNAL_ERROR);
433         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
434         try
435         {
436                 MESSAGE ("Nombre d'elements  mis de façon stupide a MED_ALL_ELEMENTS");
437                 int nbelements=_support->getNumberOfElements(::MED_ALL_ELEMENTS);
438                 myseq->length(nbelements);
439                 const int * numbers=_support->getNumberIndex();
440                 for (int i=0;i<nbelements;i++)
441                 {
442                         myseq[i]=numbers[i];
443                 }
444         }
445         catch (MEDEXCEPTION &ex)
446         {
447                 MESSAGE("Unable to access the support index");
448                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
449         }
450         return myseq._retn();
451         
452 }
453 //=============================================================================
454 /*!
455  * CORBA: 2nd Global Nodes Index (optionnaly designed by the user)
456  */
457 //=============================================================================
458
459 SALOME::SenderInt_ptr SUPPORT_i::getSenderForNumberIndex() 
460   throw (SALOME::SALOME_Exception)
461 {
462   if (_support==NULL)
463     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
464                                  SALOME::INTERNAL_ERROR);
465   SALOME::SenderInt_ptr ret;
466   try
467     {
468       MESSAGE ("Nombre d'elements  mis de façon stupide a MED_ALL_ELEMENTS");
469       int nbelements=_support->getNumberOfElements(::MED_ALL_ELEMENTS);
470       const int * numbers=_support->getNumberIndex();
471       ret=SenderFactory::buildSender(*this,numbers,nbelements);
472     }
473   catch (MEDEXCEPTION &ex)
474     {
475       MESSAGE("Unable to access the support index");
476       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
477     }
478   catch(MultiCommException &ex2)
479           THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
480   return ret;
481 }
482 //=============================================================================
483 /*!
484  * CORBA:
485  */
486 //=============================================================================
487
488 void SUPPORT_i::getBoundaryElements()
489 throw (SALOME::SALOME_Exception)
490 {
491         if (_support==NULL)
492                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
493                                              SALOME::INTERNAL_ERROR);
494         try
495         {
496                 (const_cast< ::SUPPORT *>(_support))->getBoundaryElements();
497         }
498         catch (MEDEXCEPTION &ex)
499         {
500                 MESSAGE("Unable to access elements");
501                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
502                                                 ,SALOME::INTERNAL_ERROR);
503         }
504 }
505
506
507 //=============================================================================
508 /*!
509  * CORBA: Array containing indexes for elements included in the support  
510  */
511 //=============================================================================
512
513 CORBA::Long SUPPORT_i::getNumberOfGaussPoint(SALOME_MED::medGeometryElement geomElement)
514 throw (SALOME::SALOME_Exception)
515 {
516         if (_support==NULL)
517                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
518                                              SALOME::INTERNAL_ERROR);
519         try
520         {
521                 return _support->getNumberOfGaussPoint(convertIdlEltToMedElt(geomElement));
522         }
523         catch (MEDEXCEPTION &ex)
524         {
525                 MESSAGE("Unable to access number of Gauss points");
526                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
527         }
528 }
529 //=============================================================================
530 /*!
531  * CORBA: Global Nodes Index (optionnaly designed by the user)
532  */
533 //=============================================================================
534 SALOME_MED::long_array *  SUPPORT_i::getNumbersOfGaussPoint()
535 throw (SALOME::SALOME_Exception)
536 {
537         if (_support==NULL)
538                 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
539                                              SALOME::INTERNAL_ERROR);
540         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
541         try
542         {
543                 int mySeqLength=_support->getNumberOfTypes();
544                 myseq->length(mySeqLength);
545                 const medGeometryElement * elemts = _support->getTypes();
546                 for (int i=0;i<mySeqLength;i++)
547                 {
548                         myseq[i]= _support->getNumberOfGaussPoint(elemts[i]);
549                 }
550         }
551         catch (MEDEXCEPTION &ex)
552         {
553                 MESSAGE("Unable to access number of Gauss points");
554                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
555         }
556 }
557 //=============================================================================
558 /*!
559  * CORBA: add the Support in the StudyManager 
560  */
561 //=============================================================================
562 void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr myIor)
563   throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
564 {
565   const char * LOC = "SUPPORT_i::addInStudy";
566   BEGIN_OF(LOC);
567
568   if ( _supportId != "" )
569   {
570       MESSAGE(LOC << "Support already in Study");
571       THROW_SALOME_CORBA_EXCEPTION("Support already in Study", \
572                                    SALOME::BAD_PARAM);
573   };
574
575   if ( CORBA::is_nil(myStudy) )
576   {
577       MESSAGE(LOC << "Study not found");
578       THROW_SALOME_CORBA_EXCEPTION("Study deleted !!!",
579                                     SALOME::INTERNAL_ERROR);
580   }
581
582   
583   SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
584   SALOMEDS::GenericAttribute_var anAttr;
585   SALOMEDS::AttributeName_var    aName;
586   SALOMEDS::AttributeIOR_var     aIOR;
587   
588   // Find SComponent labelled 'Med'
589   MESSAGE(LOC << " Find SComponent labelled 'MED'");
590   SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
591   if ( CORBA::is_nil(medfather) ) 
592   { 
593     MESSAGE(LOC << "MED not found");
594     THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
595   }
596
597   // Find SObject MESH (represent mesh in support)
598   SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath("/Med/MEDMESH");
599   if ( CORBA::is_nil(medmeshfather) )
600   { 
601     MESSAGE(LOC << " No /Med/MEDMESH Found in study")
602     THROW_SALOME_CORBA_EXCEPTION("SObject labelled 'MEDMESH' not Found",SALOME::INTERNAL_ERROR);
603   }
604   MESSAGE(LOC << " Find SObject MESH (represent mesh in support)");
605
606   string meshName = getMesh()->getName() ;
607   string meshNameStudy = meshName;
608
609   for (string::size_type pos=0; pos<meshNameStudy.size();++pos)
610     {
611       if (isspace(meshNameStudy[pos])) meshNameStudy[pos] = '_';
612     }
613
614                 // seulement sous Med : il peut y avoir le meme sous SMESH !!!
615   SALOMEDS::SObject_var medsupportfather = myStudy->FindObject(meshName.c_str()); 
616   if ( CORBA::is_nil(medsupportfather) ) 
617     THROW_SALOME_CORBA_EXCEPTION("SObject Mesh in Support not Found",SALOME::INTERNAL_ERROR);
618   // perhaps add MESH automatically ?
619   
620   MESSAGE("Add a support Object under /MED/MESH/MESHNAME");
621
622   char * medsupfatherName;
623   int lenName = 15 + strlen(meshName.c_str()) + 1;
624   medsupfatherName = new char[lenName];
625   medsupfatherName = strcpy(medsupfatherName,"MEDSUPPORTS_OF_");
626   medsupfatherName = strcat(medsupfatherName,meshNameStudy.c_str());
627
628   SCRUTE(medsupfatherName);
629
630   SALOMEDS::SObject_var medsupfather = myStudy->FindObject(medsupfatherName);
631   if ( CORBA::is_nil(medsupfather) )
632   {
633                 MESSAGE("Add Object MEDSUPPORT");
634                 medsupfather = myBuilder->NewObject(medmeshfather);
635                 anAttr = myBuilder->FindOrCreateAttribute(medsupfather, "AttributeName");
636                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
637                 aName->SetValue(medsupfatherName);
638
639   } ;
640
641   //myBuilder->NewCommand();
642
643   string supportName = _support->getName();
644
645   SCRUTE(supportName);
646
647   SCRUTE(meshNameStudy);
648
649   char * supportEntryPath;
650   lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str())+1;
651   supportEntryPath = new char[lenName];
652   supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
653   supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
654   supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str());
655   supportEntryPath = strcat(supportEntryPath,"/");
656   supportEntryPath = strcat(supportEntryPath,supportName.c_str());
657
658   //SCRUTE(supportEntryPath);
659
660   MESSAGE("supportEntryPath in support " << supportEntryPath << " length " << lenName);
661
662 //   SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str());
663                          // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!!
664   SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath);
665
666   if ( CORBA::is_nil(supportEntry) ) 
667   {
668     MESSAGE(" supportEntry is a nil corba object and is going to be created");
669     // not already in study : we create it !
670     SALOMEDS::SObject_var newObj = myBuilder->NewObject(medsupfather);
671     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
672     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
673     CORBA::ORB_var &orb = init(0,0);
674     string iorStr = orb->object_to_string(myIor);
675     anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
676     aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
677     aIOR->SetValue(iorStr.c_str());
678     anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
679     aName = SALOMEDS::AttributeName::_narrow(anAttr);
680     aName->SetValue(_support->getName().c_str());
681     _supportId = newObj->GetID();
682   } 
683   else 
684   {
685     // already in study : put new AttributeIOR !
686     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
687     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
688     CORBA::ORB_var &orb = init(0,0);
689     string iorStr = orb->object_to_string(myIor);
690     anAttr = myBuilder->FindOrCreateAttribute(supportEntry, "AttributeIOR");
691     aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
692     aIOR->SetValue(iorStr.c_str());
693   }
694   myBuilder->CommitCommand();
695
696   SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath);
697
698   MESSAGE("Just for checking, reuse of the corba pointer");
699
700   if ( CORBA::is_nil(supportEntry) ) 
701     {
702       MESSAGE("The reuse is OK");
703     }
704   else 
705     {
706       MESSAGE("well !! the reuse is not OK and there was a problem in the storage in the study");
707     }
708
709   delete [] medsupfatherName;
710   delete [] supportEntryPath;
711
712   // register the Corba pointer: increase the referrence count
713   MESSAGE("Registering of the Corba Support pointer");
714   Register();
715
716   END_OF(LOC);
717 }