Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM_I / MEDMEM_Field_i.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 //           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 // 
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 // 
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 //=============================================================================
20 // File      : MEDMEM_Field_i.cxx
21 // Created   : mer fév 20 15:47:57 CET 2002
22 // Author    : EDF
23 // Project   : SALOME
24 // $Header   : $
25 //=============================================================================
26
27 #include "MEDMEM_Field_i.hxx"
28
29 #include "SALOME_NamingService.hxx"
30 #include "SALOME_LifeCycleCORBA.hxx"
31
32 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
33 #include CORBA_CLIENT_HEADER(MED_Gen)
34
35 using namespace MEDMEM;
36 using namespace MED_EN;
37
38 map < int, ::FIELD_ * > FIELD_i::fieldMap ;
39 int  FIELD_i::fieldIndex = 0;
40
41 //=============================================================================
42 /*!
43  * Default constructor
44  */
45 //=============================================================================
46
47 //FIELD_i::FIELD_i():_fieldTptr(FIELD_i::constructConstField())
48 FIELD_i::FIELD_i():_fieldTptr(constructConstField()),_corbaIndex(FIELD_i::fieldIndex++)
49 {
50         BEGIN_OF("Default Constructor Field_i");
51         END_OF(" Default Constructor Field_i");
52 }
53 //=============================================================================
54 /*!
55  * Destructor
56  */
57 //=============================================================================
58 FIELD_i::~FIELD_i()
59 {
60   if (_ownCppPtr) delete _fieldTptr;
61 }
62 //=============================================================================
63 /*!
64  * Constructor
65  */
66 //=============================================================================
67 FIELD_i::FIELD_i(::FIELD_ * const field, bool ownCppPtr):
68   _fieldTptr(field),
69   _corbaIndex(FIELD_i::fieldIndex++),
70   _FieldId(""),
71   _ownCppPtr(ownCppPtr)
72 {
73   BEGIN_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
74   FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
75
76   MESSAGE("FIELD_i::FIELD_i  Checking of pointeurs !!!");
77
78   SCRUTE(_fieldTptr);
79
80   END_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
81 }
82
83 //=============================================================================
84 /*!
85  * Constructor par recopie
86  */
87 //=============================================================================
88 FIELD_i::FIELD_i( FIELD_i & f):_fieldTptr(f._fieldTptr),
89                                _corbaIndex(FIELD_i::fieldIndex++),
90                                _FieldId(""), _ownCppPtr(false)
91 {
92         BEGIN_OF("Constructor Field_i");
93         FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
94         END_OF("Constructor Field_i");
95 }
96 //=============================================================================
97 /*!
98  * Constructor d un pointeur constant 
99  */
100 //=============================================================================
101  ::FIELD_ * FIELD_i::constructConstField() const
102 {
103         ::FIELD_ * const ptrField =new ::FIELD_();
104         return ptrField;
105 }
106
107 //=============================================================================
108 /*!
109  * CORBA: Accessor for Fields's Name
110  */
111 //=============================================================================
112 char * FIELD_i::getName()
113 throw (SALOME::SALOME_Exception)
114 {
115         if (_fieldTptr==NULL)
116                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
117                                              SALOME::INTERNAL_ERROR);
118         try
119         {
120                 return CORBA::string_dup(_fieldTptr->getName().c_str());
121         }
122         catch (MEDEXCEPTION &ex)
123         {
124                 MESSAGE("Exception en accedant au nom");
125                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
126         }
127 }
128
129 void FIELD_i::setName(const char* theName)
130   throw (SALOME::SALOME_Exception)
131 {
132   if (_fieldTptr == NULL)
133     THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
134
135   try {
136     _fieldTptr->setName(theName);
137   }
138   catch (MEDEXCEPTION &ex) {
139     MESSAGE("Exception en accedant au nom");
140     THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
141   }
142 }
143
144 //=============================================================================
145 /*!
146  * CORBA: Accessor for Fields's Description
147  */
148 //=============================================================================
149 char * FIELD_i::getDescription()
150 throw (SALOME::SALOME_Exception)
151 {
152         if (_fieldTptr==NULL)
153                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
154                                              SALOME::INTERNAL_ERROR);
155         try
156         {
157                 return CORBA::string_dup(_fieldTptr->getDescription().c_str());
158         }
159         catch (MEDEXCEPTION &ex)
160         {
161                 MESSAGE("Exception en accedant a la description");
162                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
163         }
164 }
165 //=============================================================================
166 /*!
167  * CORBA: Accessor for Fields's Support
168  */
169 //=============================================================================
170 SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()
171   throw (SALOME::SALOME_Exception)
172 {
173   BEGIN_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
174
175   if (_fieldTptr==NULL)
176     THROW_SALOME_CORBA_EXCEPTION("No associated Field",
177                                  SALOME::INTERNAL_ERROR);
178   
179   SUPPORT_i* servant = new SUPPORT_i(_fieldTptr->getSupport());
180
181   SALOME_MED::SUPPORT_ptr support=servant->_this();
182
183   SCRUTE(_fieldTptr);
184
185   END_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
186
187   return support ;
188 }
189 //=============================================================================
190 /*!
191  * CORBA: Accessor for Fields's Number of components
192  */
193 //=============================================================================
194 CORBA::Long FIELD_i::getNumberOfComponents()
195 throw (SALOME::SALOME_Exception)
196 {
197         if (_fieldTptr==NULL)
198                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
199                                              SALOME::INTERNAL_ERROR);
200         try
201         {
202                 return _fieldTptr->getNumberOfComponents();
203         }
204         catch (MEDEXCEPTION &ex)
205         {
206                 MESSAGE("Exception en accedant au support");
207                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
208         }
209 }
210 //=============================================================================
211 /*!
212  * CORBA: Accessor for names of component I
213  */
214 //=============================================================================
215 char * FIELD_i::getComponentName(CORBA::Long i)
216 throw (SALOME::SALOME_Exception)
217 {
218         if (_fieldTptr==NULL)
219                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
220                                              SALOME::INTERNAL_ERROR);
221         try
222         {
223                 return CORBA::string_dup(_fieldTptr->getComponentName(i).c_str());
224         }
225         catch (MEDEXCEPTION &ex)
226         {
227                 MESSAGE("Exception en accedant au nom d un component");
228                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
229         }
230 }
231 //=============================================================================
232 /*!
233  * CORBA: Accessor for unit of component I
234  */
235 //=============================================================================
236 char * FIELD_i::getComponentUnit(CORBA::Long i)
237 throw (SALOME::SALOME_Exception)
238 {
239         if (_fieldTptr==NULL)
240                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
241                                              SALOME::INTERNAL_ERROR);
242         try
243         {
244                 return CORBA::string_dup(_fieldTptr->getMEDComponentUnit(i).c_str());
245         }
246         catch (MEDEXCEPTION &ex)
247         {
248                 MESSAGE("Exception en accedant au nom d un component");
249                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
250         }
251 }
252 //=============================================================================
253 /*!
254  * CORBA: Accessor for description of component I
255  */
256 //=============================================================================
257 char * FIELD_i::getComponentDescription(CORBA::Long i)
258 throw (SALOME::SALOME_Exception)
259 {
260         if (_fieldTptr==NULL)
261                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
262                                              SALOME::INTERNAL_ERROR);
263         try
264         {
265                 return CORBA::string_dup(_fieldTptr->getComponentDescription(i).c_str());
266         }
267         catch (MEDEXCEPTION &ex)
268         {
269                 MESSAGE("Exception en accedant a la description d un component");
270                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
271         }
272 }
273 //=============================================================================
274 /*!
275  * CORBA: Accessor for iteration number 
276  */
277 //=============================================================================
278 CORBA::Long FIELD_i::getIterationNumber()
279 throw (SALOME::SALOME_Exception)
280 {
281         if (_fieldTptr==NULL)
282                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
283                                              SALOME::INTERNAL_ERROR);
284         try
285         {
286                 return _fieldTptr->getIterationNumber();
287         }
288         catch (MEDEXCEPTION &ex)
289         {
290                 MESSAGE("Exception en accedant au champ");
291                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
292         }
293 }
294 //=============================================================================
295 /*!
296  * CORBA: Accessor for Corba Number 
297  */
298 //=============================================================================
299 CORBA::Long FIELD_i::getCorbaIndex()
300 throw (SALOME::SALOME_Exception)
301 {
302         if (_fieldTptr==NULL)
303                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
304                                              SALOME::INTERNAL_ERROR);
305         return _corbaIndex;
306         
307 }
308 //=============================================================================
309 /*!
310  * CORBA: Accessor for iteration number 
311  */
312 //=============================================================================
313 CORBA::Long FIELD_i::getOrderNumber()
314 throw (SALOME::SALOME_Exception)
315 {
316         if (_fieldTptr==NULL)
317                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
318                                              SALOME::INTERNAL_ERROR);
319         try
320         {
321                 return _fieldTptr->getOrderNumber();
322         }
323         catch (MEDEXCEPTION &ex)
324         {
325                 MESSAGE("Exception en accedant au champ");
326                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
327         }
328 }
329 //=============================================================================
330 /*!
331  * CORBA: Accessor for gauss numbers presence.
332  */
333 //=============================================================================
334 CORBA::Boolean FIELD_i::getGaussPresence()
335 {
336        if (_fieldTptr==NULL)
337                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
338                                              SALOME::INTERNAL_ERROR);
339         try
340         {
341                 return _fieldTptr->getGaussPresence();
342         }
343         catch (MEDEXCEPTION &ex)
344         {
345                 MESSAGE("Exception en accedant au champ");
346                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
347         }
348 }
349 //=============================================================================
350 /*!
351  * CORBA: Accessor  
352  */
353 //=============================================================================
354 CORBA::Double FIELD_i::getTime()
355 throw (SALOME::SALOME_Exception)
356 {
357         if (_fieldTptr==NULL)
358                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
359                                              SALOME::INTERNAL_ERROR);
360         try
361         {
362                 return _fieldTptr->getTime();
363         }
364         catch (MEDEXCEPTION &ex)
365         {
366                 MESSAGE("Exception en accedant au champ");
367                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
368         }
369 }
370 //=============================================================================
371 /*!
372  * CORBA: Accessor for Fields's Components names
373  */
374 //=============================================================================
375 SALOME_MED::string_array * FIELD_i::getComponentsNames()
376 throw (SALOME::SALOME_Exception)    
377 {
378         if (_fieldTptr==NULL)
379                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
380                                              SALOME::INTERNAL_ERROR);
381         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
382         try
383         {
384                 int nbcom = _fieldTptr->getNumberOfComponents();
385                 myseq->length(nbcom);
386                 const string * namecom=_fieldTptr->getComponentsNames();
387                 for (int i=0;i<nbcom;i++)
388                 {
389                         myseq[i]=CORBA::string_dup(namecom[i].c_str());
390                 }
391         }
392         catch (MEDEXCEPTION &ex)
393         {
394                 MESSAGE("Exception en accedant au champ");
395                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
396         }
397         return myseq._retn();
398 }
399 //=============================================================================
400 /*!
401  * CORBA: Accessor for Fields's Components units
402  */
403 //=============================================================================
404 SALOME_MED::string_array * FIELD_i::getComponentsUnits()
405 throw (SALOME::SALOME_Exception)
406 {
407         if (_fieldTptr==NULL)
408                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
409                                              SALOME::INTERNAL_ERROR);
410         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
411         try
412         {
413                 int nbcom = _fieldTptr->getNumberOfComponents();
414                 myseq->length(nbcom);
415                 const string * unitcom=_fieldTptr->getMEDComponentsUnits();
416                 for (int i=0;i<nbcom;i++)
417                 {
418                         myseq[i]=CORBA::string_dup(unitcom[i].c_str());
419                 }
420         }
421         catch (MEDEXCEPTION &ex)
422         {
423                 MESSAGE("Exception en accedant au champ");
424                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
425         }
426         return myseq._retn();
427 }
428 //=============================================================================
429 /*!
430  * CORBA: Accessor for Fields's Components descriptions
431  */
432 //=============================================================================
433 SALOME_MED::string_array * FIELD_i::getComponentsDescriptions()
434 throw (SALOME::SALOME_Exception)    
435 {
436         if (_fieldTptr==NULL)
437                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
438                                              SALOME::INTERNAL_ERROR);
439         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
440         try
441         {
442                 int nbcom = _fieldTptr->getNumberOfComponents();
443                 myseq->length(nbcom);
444                 const string * namecom=_fieldTptr->getComponentsDescriptions();
445                 for (int i=0;i<nbcom;i++)
446                 {
447                         myseq[i]=CORBA::string_dup(namecom[i].c_str());
448                 }
449         }
450         catch (MEDEXCEPTION &ex)
451         {
452                 MESSAGE("Exception en accedant au champ");
453                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
454         }
455         return myseq._retn();
456 }
457
458 //=============================================================================
459 /*!
460  * CORBA: Add in Study
461  */
462 //=============================================================================
463 void FIELD_i::addInStudy (SALOMEDS::Study_ptr   myStudy, 
464                           SALOME_MED::FIELD_ptr myIor)
465   throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
466 {
467   SALOMEDS::SComponent_var aComponent = PublishMedComponent(myStudy);
468   if (CORBA::is_nil(aComponent))
469     THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found", SALOME::INTERNAL_ERROR);
470   addInStudyToComponent(aComponent, myIor);
471 }
472
473 static SALOMEDS::SObject_ptr FindChildByName (SALOMEDS::SObject_ptr theFather,
474                                               const string          theName)
475 {
476   SALOMEDS::SObject_var aChild;
477   if (CORBA::is_nil(theFather))
478     return aChild._retn();
479
480   SALOMEDS::SObject_var aCurChild;
481   SALOMEDS::ChildIterator_ptr anIter = theFather->GetStudy()->NewChildIterator(theFather);
482   for (; anIter->More() && aChild->_is_nil(); anIter->Next()) {
483     aCurChild = anIter->Value();
484     string aCurName = aCurChild->GetName();
485     if (aCurName == theName)
486       aChild = aCurChild;
487   }
488   return aChild._retn();
489 }
490
491 void FIELD_i::addInStudyToComponent (SALOMEDS::SComponent_ptr myComponent,
492                                      SALOME_MED::FIELD_ptr    myIor)
493   throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
494 {
495         BEGIN_OF(" FIELD_i::addInStudy");
496
497         if (CORBA::is_nil(myComponent) || CORBA::is_nil(myIor))
498           THROW_SALOME_CORBA_EXCEPTION("Null parameter", SALOME::BAD_PARAM);
499
500         if (_fieldTptr == NULL)
501           THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
502
503         if (_FieldId != "") {
504           MESSAGE("Field already in Study");
505           THROW_SALOME_CORBA_EXCEPTION("Field already in Study", SALOME::BAD_PARAM);
506         }
507
508         SALOMEDS::Study_var myStudy = myComponent->GetStudy();
509         SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder();
510
511         SALOMEDS::GenericAttribute_var anAttr;
512         SALOMEDS::AttributeName_var    aName;
513         SALOMEDS::AttributeIOR_var     aIOR;
514
515         // Create SObject labelled 'MEDFIELD' if it doesn't already exist
516         SALOMEDS::Study::ListOfSObject_var aMEDFIELDs =
517           myStudy->FindObjectByName("MEDFIELD", myComponent->ComponentDataType());
518         int aLength = aMEDFIELDs->length();
519         SALOMEDS::SObject_var medfieldfather;
520         if (aLength > 0) {
521           medfieldfather = aMEDFIELDs[0];
522         }
523         else {
524           MESSAGE("Add Object 'MEDFIELD'");
525           medfieldfather = aBuilder->NewObject(myComponent);
526           anAttr = aBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName");
527           aName = SALOMEDS::AttributeName::_narrow(anAttr);
528           aName->SetValue("MEDFIELD");
529         }
530
531         // Create SObject labelled 'FIELDNAME' if it doesn't already exit
532         string fieldName = _fieldTptr->getName();
533         SALOMEDS::SObject_var medfieldnamefather = FindChildByName(medfieldfather, fieldName);
534         if ( CORBA::is_nil(medfieldnamefather) ) 
535         {
536           MESSAGE("Add Object "<<fieldName);
537           medfieldnamefather = aBuilder->NewObject(medfieldfather);
538           anAttr = aBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName");
539           aName = SALOMEDS::AttributeName::_narrow(anAttr);
540           aName->SetValue(fieldName.c_str());
541         }
542
543         string fieldEntryPath = "/";
544         //fieldEntryPath += "Med/";
545         string componentName = myComponent->GetName();
546         fieldEntryPath += componentName + "/MEDFIELD/" + fieldName + "/";
547
548         int iterationNumber = _fieldTptr->getIterationNumber();
549         SCRUTE(iterationNumber);
550
551         int orderNumber = _fieldTptr->getOrderNumber();
552         SCRUTE(orderNumber);
553
554         ostringstream iterationName;
555         iterationName<<"(" << iterationNumber << "," << orderNumber << ")";
556         string supportName = (_fieldTptr->getSupport())->getName();
557         string meshName = ((_fieldTptr->getSupport())->getMesh())->getName();
558
559         SCRUTE(meshName);
560         for (string::size_type pos=0; pos<meshName.size(); ++pos) {
561           if (isspace(meshName[pos])) meshName[pos] = '_';
562         }
563
564         char * fieldEntryName;
565         int lenName = strlen(iterationName.str().c_str()) + 4 +
566           strlen(supportName.c_str()) + 4 + strlen(meshName.c_str()) + 1;
567
568         fieldEntryName = new char[lenName];
569         fieldEntryName = strcpy(fieldEntryName,iterationName.str().c_str());
570         fieldEntryName = strcat(fieldEntryName,"_ON_");
571         fieldEntryName = strcat(fieldEntryName,supportName.c_str());
572         fieldEntryName = strcat(fieldEntryName,"_OF_");
573         fieldEntryName = strcat(fieldEntryName,meshName.c_str());
574
575         SCRUTE(fieldEntryName);
576         fieldEntryPath += fieldEntryName;
577
578         // Create object labelled according to Field's Name
579
580         SALOMEDS::SObject_var fieldSO = myStudy->FindObjectByPath(fieldEntryPath.c_str());
581         bool alreadyPublished = ! CORBA::is_nil(fieldSO);
582         aBuilder->NewCommand();
583         if ( !alreadyPublished )
584         {
585           MESSAGE("Add a Field Object under "<<fieldName);
586           fieldSO = aBuilder->NewObject(medfieldnamefather);
587           // check that this method and getEntryPath() build the same path,
588           // though this is true only for MED component
589           MESSAGE("fieldEntryPath: "<< fieldEntryPath);
590           MESSAGE("getEntryPath(): "<< getEntryPath());
591           if (componentName == "Med")
592             ASSERT( getEntryPath() == fieldEntryPath );
593         }
594         anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeName");
595         aName = SALOMEDS::AttributeName::_narrow(anAttr);
596         aName->SetValue(fieldEntryName);
597
598         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
599         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
600         CORBA::ORB_var &orb = init(0,0);
601         string iorStr = orb->object_to_string(myIor);
602         anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeIOR");
603         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
604         aIOR->SetValue(iorStr.c_str());
605         _FieldId = fieldSO->GetID();
606
607         if ( !alreadyPublished )
608         {
609           MESSAGE("Computing path to Support");
610
611           string supportEntryPath = SUPPORT_i::getEntryPath( _fieldTptr->getSupport() );
612           SCRUTE(supportEntryPath);
613
614           SALOMEDS::SObject_var supportObject =
615             myStudy->FindObjectByPath(supportEntryPath.c_str());
616
617           SCRUTE(supportObject);
618
619           if ( CORBA::is_nil(supportObject) ) 
620           {
621             MESSAGE("supportObject is a nil corba object");
622             MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ;
623           } 
624           else 
625           {
626             MESSAGE("supportObject is OK and is now going to be referenced !");
627             SALOMEDS::SObject_var newObjSupport = aBuilder->NewObject(fieldSO);
628             aBuilder->Addreference(newObjSupport,supportObject);
629             MESSAGE(" OUF !!!");
630           }
631         }
632
633         aBuilder->CommitCommand();
634
635         delete [] fieldEntryName;
636
637         // register the Corba pointer: increase the referrence count
638         MESSAGE("Registering of the Corba Field pointer");
639         Register();
640
641         MESSAGE("FIELD_i::addInStudy");
642
643         //END_OF("FIELD_i::addInStudy");
644 }
645
646 //=============================================================================
647 /*!
648  * CORBA: write
649  */
650 //=============================================================================
651 void FIELD_i::write (CORBA::Long i, const char* driverFieldName)
652 throw (SALOME::SALOME_Exception)
653 {
654         if (_fieldTptr==NULL)
655                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
656                                              SALOME::INTERNAL_ERROR);
657         try
658         {
659                 _fieldTptr->write(i,driverFieldName);
660         }
661         catch (MEDEXCEPTION &)
662         {
663                 MESSAGE("Exception en accedant au champ");
664                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\
665                                                 ,SALOME::INTERNAL_ERROR);
666         }
667 }
668 //=============================================================================
669 /*!
670  * CORBA: read
671  */
672 //=============================================================================
673 void FIELD_i::read (CORBA::Long i)
674 throw (SALOME::SALOME_Exception)
675 {
676         if (_fieldTptr==NULL)
677                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
678                                              SALOME::INTERNAL_ERROR);
679         try
680         {
681                 _fieldTptr->read(i);
682         }
683         catch (MEDEXCEPTION &ex)
684         {
685                 MESSAGE("Exception en accedant au champ");
686                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
687         }
688 }
689 //=============================================================================
690 /*!
691  * CORBA: rmDriver
692  */
693 //=============================================================================
694 void FIELD_i::rmDriver (CORBA::Long i)
695 throw (SALOME::SALOME_Exception)
696 {
697         if (_fieldTptr==NULL)
698                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
699                                              SALOME::INTERNAL_ERROR);
700         try
701         {
702                 _fieldTptr->rmDriver(i);
703         }
704         catch (MEDEXCEPTION &ex)
705         {
706                 MESSAGE("Exception en accedant au champ");
707                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
708         }
709 }
710 //=============================================================================
711 /*!
712  * CORBA: addDriver
713  */
714 //=============================================================================
715 CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType, 
716                         const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception)
717 {
718         if (_fieldTptr==NULL)
719                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
720                                              SALOME::INTERNAL_ERROR);
721         try
722         {
723                 int drivernum=_fieldTptr->addDriver(
724                                         convertIdlDriverToMedDriver(driverType),
725                                         fileName,
726                                         fieldName);
727                 return drivernum;
728         }
729         catch (MEDEXCEPTION &ex)
730         {
731                 MESSAGE("Exception en accedant au champ");
732                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
733         }
734 }
735
736 //=============================================================================
737 /*!
738  * internal method: publish MED component
739  */
740 //=============================================================================
741
742 SALOMEDS::SComponent_ptr FIELD_i::PublishMedComponent(SALOMEDS::Study_ptr theStudy)
743 {
744   if ( CORBA::is_nil(theStudy) )
745     return SALOMEDS::SComponent::_nil();
746
747   SALOMEDS::SComponent_var medfather = theStudy->FindComponent("MED");
748   if ( !CORBA::is_nil(medfather) )
749     return medfather._retn();
750
751   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
752   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
753   CORBA::ORB_var &orb = init(0,0);
754
755   SALOME_NamingService* ns = SINGLETON_<SALOME_NamingService>::Instance();
756   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
757   ns->init_orb( orb );
758
759   SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( ns );
760
761   SALOME_ModuleCatalog::ModuleCatalog_var aCatalog  = 
762     SALOME_ModuleCatalog::ModuleCatalog::_narrow(ns->Resolve("/Kernel/ModulCatalog"));
763   if ( CORBA::is_nil( aCatalog ) )
764     return medfather._retn();
765   SALOME_ModuleCatalog::Acomponent_var aComp = aCatalog->GetComponent( "MED" );
766   if ( CORBA::is_nil( aComp ) )
767     return medfather._retn();
768   
769   SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
770   aBuilder->NewCommand();
771   bool aLocked = theStudy->GetProperties()->IsLocked();
772   if (aLocked) theStudy->GetProperties()->SetLocked(false);
773   
774   medfather = aBuilder->NewComponent("MED");
775   SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(medfather, "AttributeName");
776   SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
777   aName->SetValue( aComp->componentusername() );
778   
779   Engines::Component_var aMedComponent = lcc->FindOrLoad_Component("FactoryServer", "MED");
780   SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow( aMedComponent );
781   aBuilder->DefineComponentInstance(medfather, aMedEngine);
782   
783   if (aLocked) theStudy->GetProperties()->SetLocked(true);
784   aBuilder->CommitCommand();
785   
786   return medfather._retn();
787 }
788
789 //================================================================================
790 /*!
791  * \brief Return a default path to publish this field
792   * \retval string - the path
793  */
794 //================================================================================
795
796 string FIELD_i::getEntryPath ()
797 {
798   string path;
799   if ( _fieldTptr &&
800        _fieldTptr->getSupport() &&
801        _fieldTptr->getSupport()->getMesh() )
802   {
803     string meshName = _fieldTptr->getSupport()->getMesh()->getName();
804     for (string::size_type pos=0; pos<meshName.size(); ++pos)
805     {
806       if (isspace(meshName[pos])) meshName[pos] = '_';
807     }
808     ostringstream os ;
809
810     os << "/Med/MEDFIELD/" << _fieldTptr->getName() << "/" 
811        << "(" << _fieldTptr->getIterationNumber()
812        << "," << _fieldTptr->getOrderNumber()
813        << ")_ON_" << _fieldTptr->getSupport()->getName()
814        << "_OF_" << meshName;
815
816     path = os.str();
817   }
818   return path;
819 }