1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 //=============================================================================
24 // File : MEDMEM_Field_i.cxx
25 // Created : mer fév 20 15:47:57 CET 2002
28 //=============================================================================
30 #include "MEDMEM_Field_i.hxx"
32 #include "SALOME_NamingService.hxx"
33 #include "SALOME_LifeCycleCORBA.hxx"
35 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
36 #include CORBA_CLIENT_HEADER(MED_Gen)
38 using namespace MEDMEM;
39 using namespace MED_EN;
41 map < int, ::FIELD_ * > FIELD_i::fieldMap ;
42 int FIELD_i::fieldIndex = 0;
44 //=============================================================================
48 //=============================================================================
50 //FIELD_i::FIELD_i():_fieldTptr(FIELD_i::constructConstField())
51 FIELD_i::FIELD_i():_fieldTptr(constructConstField()),_corbaIndex(FIELD_i::fieldIndex++)
54 //=============================================================================
58 //=============================================================================
62 _fieldTptr->removeReference();
63 //if (_ownCppPtr) delete _fieldTptr;
65 //=============================================================================
69 //=============================================================================
70 FIELD_i::FIELD_i(::FIELD_ * const field, bool ownCppPtr):
71 _ownCppPtr(ownCppPtr),
73 _corbaIndex(FIELD_i::fieldIndex++),
76 if ( _fieldTptr ) _fieldTptr->addReference();
77 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
79 MESSAGE("FIELD_i::FIELD_i Checking of pointeurs !!!");
84 //=============================================================================
86 * Constructor par recopie
88 //=============================================================================
89 FIELD_i::FIELD_i( FIELD_i & f):_ownCppPtr(false), _fieldTptr(f._fieldTptr),
90 _corbaIndex(FIELD_i::fieldIndex++),
93 if ( _fieldTptr ) _fieldTptr->addReference();
94 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
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 if (_fieldTptr==NULL)
174 THROW_SALOME_CORBA_EXCEPTION("No associated Field",
175 SALOME::INTERNAL_ERROR);
177 SUPPORT_i* servant = new SUPPORT_i(_fieldTptr->getSupport());
179 SALOME_MED::SUPPORT_ptr support=servant->_this();
185 //=============================================================================
187 * CORBA: Accessor for Fields's Number of components
189 //=============================================================================
190 CORBA::Long FIELD_i::getNumberOfComponents()
191 throw (SALOME::SALOME_Exception)
193 if (_fieldTptr==NULL)
194 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
195 SALOME::INTERNAL_ERROR);
198 return _fieldTptr->getNumberOfComponents();
200 catch (MEDEXCEPTION &ex)
202 MESSAGE("Exception en accedant au support");
203 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
206 //=============================================================================
208 * CORBA: Accessor for names of component I
210 //=============================================================================
211 char * FIELD_i::getComponentName(CORBA::Long i)
212 throw (SALOME::SALOME_Exception)
214 if (_fieldTptr==NULL)
215 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
216 SALOME::INTERNAL_ERROR);
219 return CORBA::string_dup(_fieldTptr->getComponentName(i).c_str());
221 catch (MEDEXCEPTION &ex)
223 MESSAGE("Exception en accedant au nom d un component");
224 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
227 //=============================================================================
229 * CORBA: Accessor for unit of component I
231 //=============================================================================
232 char * FIELD_i::getComponentUnit(CORBA::Long i)
233 throw (SALOME::SALOME_Exception)
235 if (_fieldTptr==NULL)
236 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
237 SALOME::INTERNAL_ERROR);
240 return CORBA::string_dup(_fieldTptr->getMEDComponentUnit(i).c_str());
242 catch (MEDEXCEPTION &ex)
244 MESSAGE("Exception en accedant au nom d un component");
245 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
248 //=============================================================================
250 * CORBA: Accessor for description of component I
252 //=============================================================================
253 char * FIELD_i::getComponentDescription(CORBA::Long i)
254 throw (SALOME::SALOME_Exception)
256 if (_fieldTptr==NULL)
257 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
258 SALOME::INTERNAL_ERROR);
261 return CORBA::string_dup(_fieldTptr->getComponentDescription(i).c_str());
263 catch (MEDEXCEPTION &ex)
265 MESSAGE("Exception en accedant a la description d un component");
266 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
269 //=============================================================================
271 * CORBA: Accessor for iteration number
273 //=============================================================================
274 CORBA::Long FIELD_i::getIterationNumber()
275 throw (SALOME::SALOME_Exception)
277 if (_fieldTptr==NULL)
278 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
279 SALOME::INTERNAL_ERROR);
282 return _fieldTptr->getIterationNumber();
284 catch (MEDEXCEPTION &ex)
286 MESSAGE("Exception en accedant au champ");
287 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
290 //=============================================================================
292 * CORBA: Accessor for Corba Number
294 //=============================================================================
295 CORBA::Long FIELD_i::getCorbaIndex()
296 throw (SALOME::SALOME_Exception)
298 if (_fieldTptr==NULL)
299 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
300 SALOME::INTERNAL_ERROR);
304 //=============================================================================
306 * CORBA: Accessor for iteration number
308 //=============================================================================
309 CORBA::Long FIELD_i::getOrderNumber()
310 throw (SALOME::SALOME_Exception)
312 if (_fieldTptr==NULL)
313 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
314 SALOME::INTERNAL_ERROR);
317 return _fieldTptr->getOrderNumber();
319 catch (MEDEXCEPTION &ex)
321 MESSAGE("Exception en accedant au champ");
322 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
325 //=============================================================================
327 * CORBA: Accessor for gauss numbers presence.
329 //=============================================================================
330 CORBA::Boolean FIELD_i::getGaussPresence()
332 if (_fieldTptr==NULL)
333 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
334 SALOME::INTERNAL_ERROR);
337 return _fieldTptr->getGaussPresence();
339 catch (MEDEXCEPTION &ex)
341 MESSAGE("Exception en accedant au champ");
342 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
345 //=============================================================================
349 //=============================================================================
350 CORBA::Double FIELD_i::getTime()
351 throw (SALOME::SALOME_Exception)
353 if (_fieldTptr==NULL)
354 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
355 SALOME::INTERNAL_ERROR);
358 return _fieldTptr->getTime();
360 catch (MEDEXCEPTION &ex)
362 MESSAGE("Exception en accedant au champ");
363 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
366 //=============================================================================
368 * CORBA: Accessor for Fields's Components names
370 //=============================================================================
371 SALOME_TYPES::ListOfString * FIELD_i::getComponentsNames()
372 throw (SALOME::SALOME_Exception)
374 if (_fieldTptr==NULL)
375 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
376 SALOME::INTERNAL_ERROR);
377 SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
380 int nbcom = _fieldTptr->getNumberOfComponents();
381 myseq->length(nbcom);
382 const string * namecom=_fieldTptr->getComponentsNames();
383 for (int i=0;i<nbcom;i++)
385 myseq[i]=CORBA::string_dup(namecom[i].c_str());
388 catch (MEDEXCEPTION &ex)
390 MESSAGE("Exception en accedant au champ");
391 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
393 return myseq._retn();
395 //=============================================================================
397 * CORBA: Accessor for Fields's Components units
399 //=============================================================================
400 SALOME_TYPES::ListOfString * FIELD_i::getComponentsUnits()
401 throw (SALOME::SALOME_Exception)
403 if (_fieldTptr==NULL)
404 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
405 SALOME::INTERNAL_ERROR);
406 SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
409 int nbcom = _fieldTptr->getNumberOfComponents();
410 myseq->length(nbcom);
411 const string * unitcom=_fieldTptr->getMEDComponentsUnits();
412 for (int i=0;i<nbcom;i++)
414 myseq[i]=CORBA::string_dup(unitcom[i].c_str());
417 catch (MEDEXCEPTION &ex)
419 MESSAGE("Exception en accedant au champ");
420 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
422 return myseq._retn();
424 //=============================================================================
426 * CORBA: Accessor for Fields's Components descriptions
428 //=============================================================================
429 SALOME_TYPES::ListOfString * FIELD_i::getComponentsDescriptions()
430 throw (SALOME::SALOME_Exception)
432 if (_fieldTptr==NULL)
433 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
434 SALOME::INTERNAL_ERROR);
435 SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
438 int nbcom = _fieldTptr->getNumberOfComponents();
439 myseq->length(nbcom);
440 const string * namecom=_fieldTptr->getComponentsDescriptions();
441 for (int i=0;i<nbcom;i++)
443 myseq[i]=CORBA::string_dup(namecom[i].c_str());
446 catch (MEDEXCEPTION &ex)
448 MESSAGE("Exception en accedant au champ");
449 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
451 return myseq._retn();
454 //=============================================================================
456 * CORBA: Add in Study
458 //=============================================================================
459 void FIELD_i::addInStudy (SALOMEDS::Study_ptr myStudy,
460 SALOME_MED::FIELD_ptr myIor)
461 throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
463 SALOMEDS::SComponent_var aComponent = PublishMedComponent(myStudy);
464 if (CORBA::is_nil(aComponent))
465 THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found", SALOME::INTERNAL_ERROR);
466 addInStudyToComponent(aComponent, myIor);
469 static SALOMEDS::SObject_ptr FindChildByName (SALOMEDS::SObject_ptr theFather,
470 const string theName)
472 SALOMEDS::SObject_var aChild;
473 if (CORBA::is_nil(theFather))
474 return aChild._retn();
476 SALOMEDS::SObject_var aCurChild;
477 SALOMEDS::ChildIterator_ptr anIter = theFather->GetStudy()->NewChildIterator(theFather);
478 for (; anIter->More() && aChild->_is_nil(); anIter->Next()) {
479 aCurChild = anIter->Value();
480 string aCurName = aCurChild->GetName();
481 if (aCurName == theName)
484 return aChild._retn();
487 void FIELD_i::addInStudyToComponent (SALOMEDS::SComponent_ptr myComponent,
488 SALOME_MED::FIELD_ptr myIor)
489 throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
491 if (CORBA::is_nil(myComponent) || CORBA::is_nil(myIor))
492 THROW_SALOME_CORBA_EXCEPTION("Null parameter", SALOME::BAD_PARAM);
494 if (_fieldTptr == NULL)
495 THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
497 if (_FieldId != "") {
498 MESSAGE("Field already in Study");
499 THROW_SALOME_CORBA_EXCEPTION("Field already in Study", SALOME::BAD_PARAM);
502 SALOMEDS::Study_var myStudy = myComponent->GetStudy();
503 SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder();
505 SALOMEDS::GenericAttribute_var anAttr;
506 SALOMEDS::AttributeName_var aName;
507 SALOMEDS::AttributeIOR_var aIOR;
509 // Create SObject labelled 'MEDFIELD' if it doesn't already exist
510 SALOMEDS::Study::ListOfSObject_var aMEDFIELDs =
511 myStudy->FindObjectByName("MEDFIELD", myComponent->ComponentDataType());
512 int aLength = aMEDFIELDs->length();
513 SALOMEDS::SObject_var medfieldfather;
515 medfieldfather = aMEDFIELDs[0];
518 MESSAGE("Add Object 'MEDFIELD'");
519 medfieldfather = aBuilder->NewObject(myComponent);
520 anAttr = aBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName");
521 aName = SALOMEDS::AttributeName::_narrow(anAttr);
522 aName->SetValue("MEDFIELD");
525 // Create SObject labelled 'FIELDNAME' if it doesn't already exit
526 string fieldName = _fieldTptr->getName();
527 SALOMEDS::SObject_var medfieldnamefather = FindChildByName(medfieldfather, fieldName);
528 if ( CORBA::is_nil(medfieldnamefather) )
530 MESSAGE("Add Object "<<fieldName);
531 medfieldnamefather = aBuilder->NewObject(medfieldfather);
532 anAttr = aBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName");
533 aName = SALOMEDS::AttributeName::_narrow(anAttr);
534 aName->SetValue(fieldName.c_str());
537 string fieldEntryPath = "/";
538 //fieldEntryPath += "Med/";
539 string componentName = myComponent->GetName();
540 fieldEntryPath += componentName + "/MEDFIELD/" + fieldName + "/";
542 int iterationNumber = _fieldTptr->getIterationNumber();
543 SCRUTE(iterationNumber);
545 int orderNumber = _fieldTptr->getOrderNumber();
548 ostringstream iterationName;
549 iterationName<<"(" << iterationNumber << "," << orderNumber << ")";
550 string supportName = (_fieldTptr->getSupport())->getName();
551 string meshName = ((_fieldTptr->getSupport())->getMesh())->getName();
554 for (string::size_type pos=0; pos<meshName.size(); ++pos) {
555 if (isspace(meshName[pos])) meshName[pos] = '_';
558 char * fieldEntryName;
559 int lenName = strlen(iterationName.str().c_str()) + 4 +
560 strlen(supportName.c_str()) + 4 + strlen(meshName.c_str()) + 1;
562 fieldEntryName = new char[lenName];
563 fieldEntryName = strcpy(fieldEntryName,iterationName.str().c_str());
564 fieldEntryName = strcat(fieldEntryName,"_ON_");
565 fieldEntryName = strcat(fieldEntryName,supportName.c_str());
566 fieldEntryName = strcat(fieldEntryName,"_OF_");
567 fieldEntryName = strcat(fieldEntryName,meshName.c_str());
569 SCRUTE(fieldEntryName);
570 fieldEntryPath += fieldEntryName;
572 // Create object labelled according to Field's Name
574 SALOMEDS::SObject_var fieldSO = myStudy->FindObjectByPath(fieldEntryPath.c_str());
575 bool alreadyPublished = ! CORBA::is_nil(fieldSO);
576 aBuilder->NewCommand();
577 if ( !alreadyPublished )
579 MESSAGE("Add a Field Object under "<<fieldName);
580 fieldSO = aBuilder->NewObject(medfieldnamefather);
581 // check that this method and getEntryPath() build the same path,
582 // though this is true only for MED component
583 MESSAGE("fieldEntryPath: "<< fieldEntryPath);
584 MESSAGE("getEntryPath(): "<< getEntryPath());
585 if (componentName == "Med")
586 ASSERT( getEntryPath() == fieldEntryPath );
588 anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeName");
589 aName = SALOMEDS::AttributeName::_narrow(anAttr);
590 aName->SetValue(fieldEntryName);
592 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
593 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
594 CORBA::ORB_var &orb = init(0,0);
595 string iorStr = orb->object_to_string(myIor);
596 anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeIOR");
597 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
598 aIOR->SetValue(iorStr.c_str());
599 _FieldId = fieldSO->GetID();
601 if ( !alreadyPublished )
603 MESSAGE("Computing path to Support");
605 string supportEntryPath = SUPPORT_i::getEntryPath( _fieldTptr->getSupport() );
606 SCRUTE(supportEntryPath);
608 SALOMEDS::SObject_var supportObject =
609 myStudy->FindObjectByPath(supportEntryPath.c_str());
611 SCRUTE(supportObject);
613 if ( CORBA::is_nil(supportObject) )
615 MESSAGE("supportObject is a nil corba object");
616 MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ;
620 MESSAGE("supportObject is OK and is now going to be referenced !");
621 SALOMEDS::SObject_var newObjSupport = aBuilder->NewObject(fieldSO);
622 aBuilder->Addreference(newObjSupport,supportObject);
627 aBuilder->CommitCommand();
629 delete [] fieldEntryName;
631 // register the Corba pointer: increase the referrence count
632 MESSAGE("Registering of the Corba Field pointer");
635 MESSAGE("FIELD_i::addInStudy");
640 //=============================================================================
644 //=============================================================================
645 void FIELD_i::write (CORBA::Long i, const char* driverFieldName)
646 throw (SALOME::SALOME_Exception)
648 if (_fieldTptr==NULL)
649 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
650 SALOME::INTERNAL_ERROR);
653 _fieldTptr->write(i);
655 catch (MEDEXCEPTION &)
657 MESSAGE("Exception en accedant au champ");
658 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\
659 ,SALOME::INTERNAL_ERROR);
662 //=============================================================================
666 //=============================================================================
667 void FIELD_i::read (CORBA::Long i)
668 throw (SALOME::SALOME_Exception)
670 if (_fieldTptr==NULL)
671 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
672 SALOME::INTERNAL_ERROR);
677 catch (MEDEXCEPTION &ex)
679 MESSAGE("Exception en accedant au champ");
680 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
683 //=============================================================================
687 //=============================================================================
688 void FIELD_i::rmDriver (CORBA::Long i)
689 throw (SALOME::SALOME_Exception)
691 if (_fieldTptr==NULL)
692 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
693 SALOME::INTERNAL_ERROR);
696 _fieldTptr->rmDriver(i);
698 catch (MEDEXCEPTION &ex)
700 MESSAGE("Exception en accedant au champ");
701 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
704 //=============================================================================
708 //=============================================================================
709 CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType,
710 const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception)
712 if (_fieldTptr==NULL)
713 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
714 SALOME::INTERNAL_ERROR);
717 int drivernum=_fieldTptr->addDriver(
718 convertIdlDriverToMedDriver(driverType),
723 catch (MEDEXCEPTION &ex)
725 MESSAGE("Exception en accedant au champ");
726 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
730 //=============================================================================
732 * internal method: publish MED component
734 //=============================================================================
736 SALOMEDS::SComponent_ptr FIELD_i::PublishMedComponent(SALOMEDS::Study_ptr theStudy)
738 if ( CORBA::is_nil(theStudy) )
739 return SALOMEDS::SComponent::_nil();
741 SALOMEDS::SComponent_var medfather = theStudy->FindComponent("MED");
742 if ( !CORBA::is_nil(medfather) )
743 return medfather._retn();
745 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
746 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
747 CORBA::ORB_var &orb = init(0,0);
749 SALOME_NamingService* ns = SINGLETON_<SALOME_NamingService>::Instance();
750 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
753 SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( ns );
755 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
756 SALOME_ModuleCatalog::ModuleCatalog::_narrow(ns->Resolve("/Kernel/ModulCatalog"));
757 if ( CORBA::is_nil( aCatalog ) )
758 return medfather._retn();
759 SALOME_ModuleCatalog::Acomponent_var aComp = aCatalog->GetComponent( "MED" );
760 if ( CORBA::is_nil( aComp ) )
761 return medfather._retn();
763 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
764 aBuilder->NewCommand();
765 bool aLocked = theStudy->GetProperties()->IsLocked();
766 if (aLocked) theStudy->GetProperties()->SetLocked(false);
768 medfather = aBuilder->NewComponent("MED");
769 SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(medfather, "AttributeName");
770 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
771 aName->SetValue( aComp->componentusername() );
773 Engines::EngineComponent_var aMedComponent = lcc->FindOrLoad_Component("FactoryServer", "MED");
774 SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow( aMedComponent );
775 aBuilder->DefineComponentInstance(medfather, aMedEngine);
777 if (aLocked) theStudy->GetProperties()->SetLocked(true);
778 aBuilder->CommitCommand();
780 return medfather._retn();
783 //================================================================================
785 * \brief Return a default path to publish this field
786 * \retval string - the path
788 //================================================================================
790 string FIELD_i::getEntryPath ()
794 _fieldTptr->getSupport() &&
795 _fieldTptr->getSupport()->getMesh() )
797 string meshName = _fieldTptr->getSupport()->getMesh()->getName();
798 for (string::size_type pos=0; pos<meshName.size(); ++pos)
800 if (isspace(meshName[pos])) meshName[pos] = '_';
804 os << "/Med/MEDFIELD/" << _fieldTptr->getName() << "/"
805 << "(" << _fieldTptr->getIterationNumber()
806 << "," << _fieldTptr->getOrderNumber()
807 << ")_ON_" << _fieldTptr->getSupport()->getName()
808 << "_OF_" << meshName;