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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //=============================================================================
20 // File : MEDMEM_Field_i.cxx
21 // Created : mer fév 20 15:47:57 CET 2002
25 //=============================================================================
27 #include "MEDMEM_Field_i.hxx"
29 #include "SALOME_NamingService.hxx"
30 #include "SALOME_LifeCycleCORBA.hxx"
32 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
33 #include CORBA_CLIENT_HEADER(MED_Gen)
35 using namespace MEDMEM;
36 using namespace MED_EN;
38 map < int, ::FIELD_ * > FIELD_i::fieldMap ;
39 int FIELD_i::fieldIndex = 0;
41 //=============================================================================
45 //=============================================================================
47 //FIELD_i::FIELD_i():_fieldTptr(FIELD_i::constructConstField())
48 FIELD_i::FIELD_i():_fieldTptr(constructConstField()),_corbaIndex(FIELD_i::fieldIndex++)
50 BEGIN_OF("Default Constructor Field_i");
51 END_OF(" Default Constructor Field_i");
53 //=============================================================================
57 //=============================================================================
60 if (_ownCppPtr) delete _fieldTptr;
62 //=============================================================================
66 //=============================================================================
67 FIELD_i::FIELD_i(::FIELD_ * const field, bool ownCppPtr):
69 _corbaIndex(FIELD_i::fieldIndex++),
73 BEGIN_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
74 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
76 MESSAGE("FIELD_i::FIELD_i Checking of pointeurs !!!");
80 END_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
83 //=============================================================================
85 * Constructor par recopie
87 //=============================================================================
88 FIELD_i::FIELD_i( FIELD_i & f):_fieldTptr(f._fieldTptr),
89 _corbaIndex(FIELD_i::fieldIndex++),
90 _FieldId(""), _ownCppPtr(false)
92 BEGIN_OF("Constructor Field_i");
93 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
94 END_OF("Constructor Field_i");
96 //=============================================================================
98 * Constructor d un pointeur constant
100 //=============================================================================
101 ::FIELD_ * FIELD_i::constructConstField() const
103 ::FIELD_ * const ptrField =new ::FIELD_();
107 //=============================================================================
109 * CORBA: Accessor for Fields's Name
111 //=============================================================================
112 char * FIELD_i::getName()
113 throw (SALOME::SALOME_Exception)
115 if (_fieldTptr==NULL)
116 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
117 SALOME::INTERNAL_ERROR);
120 return CORBA::string_dup(_fieldTptr->getName().c_str());
122 catch (MEDEXCEPTION &ex)
124 MESSAGE("Exception en accedant au nom");
125 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
129 void FIELD_i::setName(const char* theName)
130 throw (SALOME::SALOME_Exception)
132 if (_fieldTptr == NULL)
133 THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
136 _fieldTptr->setName(theName);
138 catch (MEDEXCEPTION &ex) {
139 MESSAGE("Exception en accedant au nom");
140 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
144 //=============================================================================
146 * CORBA: Accessor for Fields's Description
148 //=============================================================================
149 char * FIELD_i::getDescription()
150 throw (SALOME::SALOME_Exception)
152 if (_fieldTptr==NULL)
153 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
154 SALOME::INTERNAL_ERROR);
157 return CORBA::string_dup(_fieldTptr->getDescription().c_str());
159 catch (MEDEXCEPTION &ex)
161 MESSAGE("Exception en accedant a la description");
162 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
165 //=============================================================================
167 * CORBA: Accessor for Fields's Support
169 //=============================================================================
170 SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()
171 throw (SALOME::SALOME_Exception)
173 BEGIN_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
175 if (_fieldTptr==NULL)
176 THROW_SALOME_CORBA_EXCEPTION("No associated Field",
177 SALOME::INTERNAL_ERROR);
179 SUPPORT_i* servant = new SUPPORT_i(_fieldTptr->getSupport());
181 SALOME_MED::SUPPORT_ptr support=servant->_this();
185 END_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
189 //=============================================================================
191 * CORBA: Accessor for Fields's Number of components
193 //=============================================================================
194 CORBA::Long FIELD_i::getNumberOfComponents()
195 throw (SALOME::SALOME_Exception)
197 if (_fieldTptr==NULL)
198 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
199 SALOME::INTERNAL_ERROR);
202 return _fieldTptr->getNumberOfComponents();
204 catch (MEDEXCEPTION &ex)
206 MESSAGE("Exception en accedant au support");
207 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
210 //=============================================================================
212 * CORBA: Accessor for names of component I
214 //=============================================================================
215 char * FIELD_i::getComponentName(CORBA::Long i)
216 throw (SALOME::SALOME_Exception)
218 if (_fieldTptr==NULL)
219 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
220 SALOME::INTERNAL_ERROR);
223 return CORBA::string_dup(_fieldTptr->getComponentName(i).c_str());
225 catch (MEDEXCEPTION &ex)
227 MESSAGE("Exception en accedant au nom d un component");
228 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
231 //=============================================================================
233 * CORBA: Accessor for unit of component I
235 //=============================================================================
236 char * FIELD_i::getComponentUnit(CORBA::Long i)
237 throw (SALOME::SALOME_Exception)
239 if (_fieldTptr==NULL)
240 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
241 SALOME::INTERNAL_ERROR);
244 return CORBA::string_dup(_fieldTptr->getMEDComponentUnit(i).c_str());
246 catch (MEDEXCEPTION &ex)
248 MESSAGE("Exception en accedant au nom d un component");
249 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
252 //=============================================================================
254 * CORBA: Accessor for description of component I
256 //=============================================================================
257 char * FIELD_i::getComponentDescription(CORBA::Long i)
258 throw (SALOME::SALOME_Exception)
260 if (_fieldTptr==NULL)
261 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
262 SALOME::INTERNAL_ERROR);
265 return CORBA::string_dup(_fieldTptr->getComponentDescription(i).c_str());
267 catch (MEDEXCEPTION &ex)
269 MESSAGE("Exception en accedant a la description d un component");
270 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
273 //=============================================================================
275 * CORBA: Accessor for iteration number
277 //=============================================================================
278 CORBA::Long FIELD_i::getIterationNumber()
279 throw (SALOME::SALOME_Exception)
281 if (_fieldTptr==NULL)
282 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
283 SALOME::INTERNAL_ERROR);
286 return _fieldTptr->getIterationNumber();
288 catch (MEDEXCEPTION &ex)
290 MESSAGE("Exception en accedant au champ");
291 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
294 //=============================================================================
296 * CORBA: Accessor for Corba Number
298 //=============================================================================
299 CORBA::Long FIELD_i::getCorbaIndex()
300 throw (SALOME::SALOME_Exception)
302 if (_fieldTptr==NULL)
303 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
304 SALOME::INTERNAL_ERROR);
308 //=============================================================================
310 * CORBA: Accessor for iteration number
312 //=============================================================================
313 CORBA::Long FIELD_i::getOrderNumber()
314 throw (SALOME::SALOME_Exception)
316 if (_fieldTptr==NULL)
317 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
318 SALOME::INTERNAL_ERROR);
321 return _fieldTptr->getOrderNumber();
323 catch (MEDEXCEPTION &ex)
325 MESSAGE("Exception en accedant au champ");
326 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
329 //=============================================================================
331 * CORBA: Accessor for gauss numbers presence.
333 //=============================================================================
334 CORBA::Boolean FIELD_i::getGaussPresence()
336 if (_fieldTptr==NULL)
337 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
338 SALOME::INTERNAL_ERROR);
341 return _fieldTptr->getGaussPresence();
343 catch (MEDEXCEPTION &ex)
345 MESSAGE("Exception en accedant au champ");
346 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
349 //=============================================================================
353 //=============================================================================
354 CORBA::Double FIELD_i::getTime()
355 throw (SALOME::SALOME_Exception)
357 if (_fieldTptr==NULL)
358 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
359 SALOME::INTERNAL_ERROR);
362 return _fieldTptr->getTime();
364 catch (MEDEXCEPTION &ex)
366 MESSAGE("Exception en accedant au champ");
367 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
370 //=============================================================================
372 * CORBA: Accessor for Fields's Components names
374 //=============================================================================
375 SALOME_MED::string_array * FIELD_i::getComponentsNames()
376 throw (SALOME::SALOME_Exception)
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;
384 int nbcom = _fieldTptr->getNumberOfComponents();
385 myseq->length(nbcom);
386 const string * namecom=_fieldTptr->getComponentsNames();
387 for (int i=0;i<nbcom;i++)
389 myseq[i]=CORBA::string_dup(namecom[i].c_str());
392 catch (MEDEXCEPTION &ex)
394 MESSAGE("Exception en accedant au champ");
395 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
397 return myseq._retn();
399 //=============================================================================
401 * CORBA: Accessor for Fields's Components units
403 //=============================================================================
404 SALOME_MED::string_array * FIELD_i::getComponentsUnits()
405 throw (SALOME::SALOME_Exception)
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;
413 int nbcom = _fieldTptr->getNumberOfComponents();
414 myseq->length(nbcom);
415 const string * unitcom=_fieldTptr->getMEDComponentsUnits();
416 for (int i=0;i<nbcom;i++)
418 myseq[i]=CORBA::string_dup(unitcom[i].c_str());
421 catch (MEDEXCEPTION &ex)
423 MESSAGE("Exception en accedant au champ");
424 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
426 return myseq._retn();
428 //=============================================================================
430 * CORBA: Accessor for Fields's Components descriptions
432 //=============================================================================
433 SALOME_MED::string_array * FIELD_i::getComponentsDescriptions()
434 throw (SALOME::SALOME_Exception)
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;
442 int nbcom = _fieldTptr->getNumberOfComponents();
443 myseq->length(nbcom);
444 const string * namecom=_fieldTptr->getComponentsDescriptions();
445 for (int i=0;i<nbcom;i++)
447 myseq[i]=CORBA::string_dup(namecom[i].c_str());
450 catch (MEDEXCEPTION &ex)
452 MESSAGE("Exception en accedant au champ");
453 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
455 return myseq._retn();
458 //=============================================================================
460 * CORBA: Add in Study
462 //=============================================================================
463 void FIELD_i::addInStudy (SALOMEDS::Study_ptr myStudy,
464 SALOME_MED::FIELD_ptr myIor)
465 throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
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);
473 static SALOMEDS::SObject_ptr FindChildByName (SALOMEDS::SObject_ptr theFather,
474 const string theName)
476 SALOMEDS::SObject_var aChild;
477 if (CORBA::is_nil(theFather))
478 return aChild._retn();
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)
488 return aChild._retn();
491 void FIELD_i::addInStudyToComponent (SALOMEDS::SComponent_ptr myComponent,
492 SALOME_MED::FIELD_ptr myIor)
493 throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
495 BEGIN_OF(" FIELD_i::addInStudy");
497 if (CORBA::is_nil(myComponent) || CORBA::is_nil(myIor))
498 THROW_SALOME_CORBA_EXCEPTION("Null parameter", SALOME::BAD_PARAM);
500 if (_fieldTptr == NULL)
501 THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
503 if (_FieldId != "") {
504 MESSAGE("Field already in Study");
505 THROW_SALOME_CORBA_EXCEPTION("Field already in Study", SALOME::BAD_PARAM);
508 SALOMEDS::Study_var myStudy = myComponent->GetStudy();
509 SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder();
511 SALOMEDS::GenericAttribute_var anAttr;
512 SALOMEDS::AttributeName_var aName;
513 SALOMEDS::AttributeIOR_var aIOR;
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;
521 medfieldfather = aMEDFIELDs[0];
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");
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) )
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());
543 string fieldEntryPath = "/";
544 //fieldEntryPath += "Med/";
545 string componentName = myComponent->GetName();
546 fieldEntryPath += componentName + "/MEDFIELD/" + fieldName + "/";
548 int iterationNumber = _fieldTptr->getIterationNumber();
549 SCRUTE(iterationNumber);
551 int orderNumber = _fieldTptr->getOrderNumber();
554 ostringstream iterationName;
555 iterationName<<"(" << iterationNumber << "," << orderNumber << ")";
556 string supportName = (_fieldTptr->getSupport())->getName();
557 string meshName = ((_fieldTptr->getSupport())->getMesh())->getName();
560 for (string::size_type pos=0; pos<meshName.size(); ++pos) {
561 if (isspace(meshName[pos])) meshName[pos] = '_';
564 char * fieldEntryName;
565 int lenName = strlen(iterationName.str().c_str()) + 4 +
566 strlen(supportName.c_str()) + 4 + strlen(meshName.c_str()) + 1;
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());
575 SCRUTE(fieldEntryName);
576 fieldEntryPath += fieldEntryName;
578 // Create object labelled according to Field's Name
580 SALOMEDS::SObject_var fieldSO = myStudy->FindObjectByPath(fieldEntryPath.c_str());
581 bool alreadyPublished = ! CORBA::is_nil(fieldSO);
582 aBuilder->NewCommand();
583 if ( !alreadyPublished )
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 );
594 anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeName");
595 aName = SALOMEDS::AttributeName::_narrow(anAttr);
596 aName->SetValue(fieldEntryName);
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();
607 if ( !alreadyPublished )
609 MESSAGE("Computing path to Support");
611 string supportEntryPath = SUPPORT_i::getEntryPath( _fieldTptr->getSupport() );
612 SCRUTE(supportEntryPath);
614 SALOMEDS::SObject_var supportObject =
615 myStudy->FindObjectByPath(supportEntryPath.c_str());
617 SCRUTE(supportObject);
619 if ( CORBA::is_nil(supportObject) )
621 MESSAGE("supportObject is a nil corba object");
622 MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ;
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);
633 aBuilder->CommitCommand();
635 delete [] fieldEntryName;
637 // register the Corba pointer: increase the referrence count
638 MESSAGE("Registering of the Corba Field pointer");
641 MESSAGE("FIELD_i::addInStudy");
643 //END_OF("FIELD_i::addInStudy");
646 //=============================================================================
650 //=============================================================================
651 void FIELD_i::write (CORBA::Long i, const char* driverFieldName)
652 throw (SALOME::SALOME_Exception)
654 if (_fieldTptr==NULL)
655 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
656 SALOME::INTERNAL_ERROR);
659 _fieldTptr->write(i,driverFieldName);
661 catch (MEDEXCEPTION &)
663 MESSAGE("Exception en accedant au champ");
664 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\
665 ,SALOME::INTERNAL_ERROR);
668 //=============================================================================
672 //=============================================================================
673 void FIELD_i::read (CORBA::Long i)
674 throw (SALOME::SALOME_Exception)
676 if (_fieldTptr==NULL)
677 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
678 SALOME::INTERNAL_ERROR);
683 catch (MEDEXCEPTION &ex)
685 MESSAGE("Exception en accedant au champ");
686 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
689 //=============================================================================
693 //=============================================================================
694 void FIELD_i::rmDriver (CORBA::Long i)
695 throw (SALOME::SALOME_Exception)
697 if (_fieldTptr==NULL)
698 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
699 SALOME::INTERNAL_ERROR);
702 _fieldTptr->rmDriver(i);
704 catch (MEDEXCEPTION &ex)
706 MESSAGE("Exception en accedant au champ");
707 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
710 //=============================================================================
714 //=============================================================================
715 CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType,
716 const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception)
718 if (_fieldTptr==NULL)
719 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
720 SALOME::INTERNAL_ERROR);
723 int drivernum=_fieldTptr->addDriver(
724 convertIdlDriverToMedDriver(driverType),
729 catch (MEDEXCEPTION &ex)
731 MESSAGE("Exception en accedant au champ");
732 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
736 //=============================================================================
738 * internal method: publish MED component
740 //=============================================================================
742 SALOMEDS::SComponent_ptr FIELD_i::PublishMedComponent(SALOMEDS::Study_ptr theStudy)
744 if ( CORBA::is_nil(theStudy) )
745 return SALOMEDS::SComponent::_nil();
747 SALOMEDS::SComponent_var medfather = theStudy->FindComponent("MED");
748 if ( !CORBA::is_nil(medfather) )
749 return medfather._retn();
751 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
752 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
753 CORBA::ORB_var &orb = init(0,0);
755 SALOME_NamingService* ns = SINGLETON_<SALOME_NamingService>::Instance();
756 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
759 SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( ns );
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();
769 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
770 aBuilder->NewCommand();
771 bool aLocked = theStudy->GetProperties()->IsLocked();
772 if (aLocked) theStudy->GetProperties()->SetLocked(false);
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() );
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);
783 if (aLocked) theStudy->GetProperties()->SetLocked(true);
784 aBuilder->CommitCommand();
786 return medfather._retn();
789 //================================================================================
791 * \brief Return a default path to publish this field
792 * \retval string - the path
794 //================================================================================
796 string FIELD_i::getEntryPath ()
800 _fieldTptr->getSupport() &&
801 _fieldTptr->getSupport()->getMesh() )
803 string meshName = _fieldTptr->getSupport()->getMesh()->getName();
804 for (string::size_type pos=0; pos<meshName.size(); ++pos)
806 if (isspace(meshName[pos])) meshName[pos] = '_';
810 os << "/Med/MEDFIELD/" << _fieldTptr->getName() << "/"
811 << "(" << _fieldTptr->getIterationNumber()
812 << "," << _fieldTptr->getOrderNumber()
813 << ")_ON_" << _fieldTptr->getSupport()->getName()
814 << "_OF_" << meshName;