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