1 //=============================================================================
2 // File : Med_Gen_i.cxx
3 // Created : mer fév 20 15:47:57 CET 2002
4 // Author : Paul RASCLE, EDF
6 // Copyright : EDF 2001
8 //=============================================================================
11 #include "Med_Gen_i.hxx"
15 #include "FieldInt_i.hxx"
16 #include "FieldDouble_i.hxx"
17 #include "Support_i.hxx"
20 #include "MEDMEM_Mesh.hxx"
21 #include "MEDMEM_Field.hxx"
22 #include "MEDMEM_Med.hxx"
23 #include "MEDMEM_MedMedDriver.hxx"
24 #include "MEDMEM_MedMeshDriver.hxx"
25 #include "MEDMEM_MedFieldDriver.hxx"
26 #include "MEDMEM_define.hxx"
27 #include "MEDMEM_DriversDef.hxx"
30 #include "Utils_SINGLETON.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "utilities.h"
39 #include <TCollection_AsciiString.hxx>
40 #include <TColStd_SequenceOfAsciiString.hxx>
41 #include "SALOMEDS_Tool.hxx"
43 // Initialisation des variables statiques
44 map <string, string> Med_Gen_i::_MedCorbaObj;
45 string Med_Gen_i::_myFileName="";
46 string Med_Gen_i::_saveFileName="";
48 //=============================================================================
50 * default constructor: not for use
52 //=============================================================================
54 Med_Gen_i::Med_Gen_i()
56 MESSAGE("Med_Gen_i::Med_Gen_i");
59 //=============================================================================
61 * standard constructor
63 //=============================================================================
65 Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb,
66 PortableServer::POA_ptr poa,
67 PortableServer::ObjectId * contId,
68 const char *instanceName,
69 const char *interfaceName) :
70 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
72 MESSAGE("activate object");
74 _id = _poa->activate_object(_thisObj);
77 // get an NamingService interface
78 _NS = SINGLETON_<SALOME_NamingService>::Instance() ;
79 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
80 _NS->init_orb( _orb ) ;
82 //=============================================================================
84 * private method : change a study name in SALOMEDS::Study_var
86 //=============================================================================
88 SALOMEDS::Study_var Med_Gen_i::studyName2Study(const char* studyName)
89 throw(SALOME::SALOME_Exception)
91 string myStudyName(studyName);
93 if (myStudyName.size() == 0)
94 THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \
97 // Get StudyManager Reference, current study,
99 CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
100 SALOMEDS::StudyManager_var myStudyManager =
101 SALOMEDS::StudyManager::_narrow(obj);
102 if(CORBA::is_nil(myStudyManager))
103 THROW_SALOME_CORBA_EXCEPTION("No StudyManager Found in NameService", \
106 SALOMEDS::Study_var myStudy =
107 myStudyManager->GetStudyByName(myStudyName.c_str());
108 if (CORBA::is_nil(myStudy))
109 THROW_SALOME_CORBA_EXCEPTION("Wrong Study Name", \
112 return SALOMEDS::Study::_duplicate(myStudy) ;
115 //=============================================================================
117 * private method : add Med component in Study (Not MedGen ???)
119 //=============================================================================
121 void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy)
122 throw(SALOME::SALOME_Exception)
124 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
126 myBuilder->NewCommand();
128 // Create SComponent labelled 'Med' if it doesn't already exit
129 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med");
130 if ( CORBA::is_nil(medfather) )
132 // mpv: component label must be created in spite of "Locked" study flag state
133 bool aLocked = myStudy->GetProperties()->IsLocked();
134 if (aLocked) myStudy->GetProperties()->SetLocked(false);
136 MESSAGE("Add Component Med");
137 medfather = myBuilder->NewComponent("Med");
138 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(medfather, "AttributeName");
139 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
140 aName->SetValue("Med");
141 // Utilisation de this deconseillee par Paul ??
142 // myBuilder->DefineComponentInstance(medfather,POA_Engines::Med_Gen::_this());
143 CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
144 myBuilder->DefineComponentInstance(medfather,myO);
146 if (aLocked) myStudy->GetProperties()->SetLocked(true);
149 myBuilder->CommitCommand();
153 //=============================================================================
155 * Lit tous les objets contenus dans un fichier med et les lit en memoire
157 //=============================================================================
158 SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName,
159 const char* studyName)
160 throw(SALOME::SALOME_Exception)
163 SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
164 if (!_duringLoad) addInStudy(myStudy) ;
166 SALOME_MED::MED_ptr myMedIOR ;
169 // we create a new MED_i and add in study
170 MED_i * myMedI = new MED_i();
171 myMedIOR = myMedI->_this() ;
172 if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;
173 // create ::MED object, read all and add in study !
174 myMedI->init(myStudy,MED_DRIVER,fileName) ;
176 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
179 MESSAGE("Erreur a la lecture du fichier");
180 THROW_SALOME_CORBA_EXCEPTION("Unable to open File "\
183 return SALOME_MED::MED::_duplicate(myMedIOR) ;
186 //=============================================================================
188 * Prepare un Maillage sans le lire en memoire avec stokage dans l'etude
189 * des champs avec leur type
191 //=============================================================================
192 void Med_Gen_i::readStructFileWithFieldType (const char* fileName,
193 const char* studyName)
194 throw (SALOME::SALOME_Exception)
196 BEGIN_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
199 SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
201 if (!_duringLoad) addInStudy(myStudy) ;
205 // we create a new MED_i and add in study
206 MED_i * myMedI = new MED_i();
207 SALOME_MED::MED_ptr myMedIOR = myMedI->_this() ;
208 if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ;
209 // create ::MED object, read all and add in study !
210 myMedI->initWithFieldType(myStudy,MED_DRIVER,fileName) ;
212 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
215 MESSAGE("Erreur a la lecture du fichier");
216 THROW_SALOME_CORBA_EXCEPTION("Unable to open File "\
220 END_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)");
225 //=============================================================================
229 //=============================================================================
230 SALOME_MED::MESH_ptr Med_Gen_i::readMeshInFile(const char* fileName,
231 const char* studyName,
232 const char* meshName)
233 throw (SALOME::SALOME_Exception)
236 SALOMEDS::Study_var myStudy = studyName2Study(studyName) ;
238 if (!_duringLoad) addInStudy(myStudy) ;
240 // Creation du maillage
242 MESH * myMesh= new MESH() ;
243 myMesh->setName(meshName);
244 MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
247 myMeshDriver.setMeshName(meshName);
250 catch (const exception & ex)
252 MESSAGE("Exception Interceptee : ");
254 THROW_SALOME_CORBA_EXCEPTION("Unable to find this mesh in this file",SALOME::BAD_PARAM);
260 myMeshDriver.close();
262 catch (const exception & ex)
264 MESSAGE("Exception Interceptee : ");
266 THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file",SALOME::BAD_PARAM);
269 MESH_i * meshi = new MESH_i(myMesh);
270 //SALOME_MED::MESH_var mesh = SALOME_MED::MESH::_narrow(meshi->_this());
271 SALOME_MED::MESH_ptr mesh = meshi->_this();
274 // add the mesh object in study
275 if (!_duringLoad) meshi->addInStudy(myStudy,mesh);
277 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
278 return SALOME_MED::MESH::_duplicate(mesh);
280 //=============================================================================
284 //=============================================================================
285 SALOME_MED::FIELD_ptr Med_Gen_i::readFieldInFile(const char* fileName,
286 const char* studyName,
287 const char* fieldName,
290 throw (SALOME::SALOME_Exception)
293 string myStudyName(studyName);
295 if (myStudyName.size() == 0)
296 THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \
299 // Get StudyManager Reference, current study,
301 CORBA::Object_var obj = _NS->Resolve("/myStudyManager");
302 SALOMEDS::StudyManager_var myStudyManager =
303 SALOMEDS::StudyManager::_narrow(obj);
304 ASSERT(! CORBA::is_nil(myStudyManager));
305 SALOMEDS::Study_var myStudy =
306 myStudyManager->GetStudyByName(myStudyName.c_str());
307 if (CORBA::is_nil(myStudy))
308 THROW_SALOME_CORBA_EXCEPTION("Wrong Study Name", \
311 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
312 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med");
313 if (CORBA::is_nil(medfather))
315 myBuilder->NewCommand();
316 // mpv: component label must be created in spite of "Locked" study flag state
317 bool aLocked = myStudy->GetProperties()->IsLocked();
318 if (aLocked) myStudy->GetProperties()->SetLocked(false);
320 medfather = myBuilder->NewComponent("Med");
321 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
322 myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
323 aName->SetValue("Med");
324 CORBA::Object_var myO = _poa->id_to_reference(*_id); // this ior...
325 myBuilder->DefineComponentInstance(medfather,myO);
327 if (aLocked) myStudy->GetProperties()->SetLocked(true);
328 myBuilder->CommitCommand();
332 MESSAGE("MED dejà dans l étude");
334 MESSAGE("Lecture du fichier ")
339 FIELD_ * myField= new FIELD_() ;
340 MED * mymed = new MED(MED_DRIVER,fileName) ;
343 deque<string> fieldsNames = mymed->getFieldNames() ;
344 int numberOfFields = fieldsNames.size();
346 for (i=0; i<numberOfFields; i++)
348 if (fieldsNames[i]== fieldName) break;
350 if (i == numberOfFields)
352 THROW_SALOME_CORBA_EXCEPTION("Unable to find this field ",SALOME::BAD_PARAM);
356 deque<DT_IT_> myIteration = mymed->getFieldIteration (fieldName);
357 if (myIteration.size() != 1)
359 MESSAGE("WARNING : My iteration size is ")
360 SCRUTE(myIteration.size());
363 myField = mymed->getField(fieldName,iter,ordre);
365 catch (const exception & ex)
367 MESSAGE("Exception Interceptee : ");
369 THROW_SALOME_CORBA_EXCEPTION("Unable to find this field in this file",SALOME::BAD_PARAM);
372 SUPPORT * fieldSupport;
373 SALOME_MED::SUPPORT_ptr mySupportIOR;
376 fieldSupport=(SUPPORT *)myField->getSupport() ;
377 ASSERT(fieldSupport != NULL);
378 MESH * myMesh=(MESH *)fieldSupport->getMesh();
379 ASSERT(myMesh != NULL);
381 SCRUTE(myMesh->getName());
382 fieldSupport->update();
383 SUPPORT_i * mySupportI = new SUPPORT_i(fieldSupport);
384 mySupportIOR=mySupportI->_this();
386 catch (const exception & ex)
388 MESSAGE("Exception Interceptee : ");
390 THROW_SALOME_CORBA_EXCEPTION("Unable to find associated support",SALOME::BAD_PARAM);
393 med_type_champ type = myField->getValueType() ;
396 case MED_FR::MED_INT32:
400 ((FIELD<int>*)myField)->read() ;
401 FIELDINT_i * myFieldIntI = new FIELDINT_i(mySupportIOR,(FIELD<int>*)myField);
402 POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldIntI);
403 SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
404 if (!_duringLoad) myFieldIntI->addInStudy(myStudy,myFieldIOR) ;
405 return SALOME_MED::FIELD::_duplicate(myFieldIOR);
407 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
408 catch (const exception & ex)
410 MESSAGE("Exception Interceptee : ");
412 THROW_SALOME_CORBA_EXCEPTION("Unable to read int field",SALOME::BAD_PARAM);
416 case MED_FR::MED_REEL64:
420 ((FIELD<double>*)myField)->read() ;
421 FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i(mySupportIOR,(FIELD<double>*)myField);
422 POA_SALOME_MED::FIELD_tie<FIELD_i> * myFieldTie = new POA_SALOME_MED::FIELD_tie<FIELD_i>(myFieldDoubleI);
423 SALOME_MED::FIELD_ptr myFieldIOR = myFieldTie->_this() ;
424 if (!_duringLoad) myFieldDoubleI->addInStudy(myStudy,myFieldIOR) ;
425 return SALOME_MED::FIELD::_duplicate(myFieldIOR);
427 catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {}
428 catch (const exception & ex)
430 MESSAGE("Exception Interceptee : ");
432 THROW_SALOME_CORBA_EXCEPTION("Unable to read double field",SALOME::BAD_PARAM);
442 //=============================================================================
446 //=============================================================================
448 Med_Gen_i::~Med_Gen_i()
450 MESSAGE("Med_Gen_i::~Med_Gen_i");
453 //=============================================================================
455 * CORBA: Save Mesh objects (called when a study is saved)
457 //=============================================================================
458 SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent) {
459 const char* LOC = "Med_Gen_i::Save";
462 SALOMEDS::TMPFile_var aStreamFile;
463 // Get a temporary directory to store a file
464 TCollection_AsciiString aTmpDir = SALOMEDS_Tool::GetTmpDir();
465 // Create a list to store names of created files
466 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
467 TColStd_SequenceOfAsciiString aFileNames;
469 SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH");
470 if (!CORBA::is_nil(aMedMeshFather)) {
471 SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather);
472 for(; anIter->More(); anIter->Next()) {
473 SALOMEDS::SObject_var aSO = anIter->Value();
474 SALOMEDS::GenericAttribute_var anAttr;
475 if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
476 CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
477 SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
478 if (! CORBA::is_nil(myMesh)) {
479 TCollection_AsciiString aName;
481 aName += myMesh->getName();
483 // MESSAGE("Save mesh with name "<<aName.ToCString());
484 long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName());
485 myMesh->write(driverId,"");
486 aFileNames.Append(aName);
492 SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD");
493 if (!CORBA::is_nil(aMedFieldFather)) {
494 SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather);
495 for(; anIter->More(); anIter->Next()) {
496 SALOMEDS::SObject_var aSO = anIter->Value();
497 SALOMEDS::GenericAttribute_var anAttr;
498 if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
499 CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
500 SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
501 if (! CORBA::is_nil(myField)) {
502 TCollection_AsciiString aName;
504 aName += myField->getName();
506 // MESSAGE("Save mesh with name "<<aName.ToCString());
507 long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName());
508 myField->write(driverId,"");
509 aFileNames.Append(aName);
516 aSeq->length(aFileNames.Length());
517 for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString());
518 // Conver a file to the byte stream
519 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq);
520 // Remove the created file and tmp directory
521 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq, true);
522 // Return the created byte stream
523 return aStreamFile._retn();
528 //=============================================================================
530 * CORBA: Load Mesh objects (called when an existing study is opened)
532 //=============================================================================
534 CORBA::Boolean Med_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream) {
535 const char* LOC = "Med_Gen_i::Load";
538 // Get a temporary directory for a file
539 TCollection_AsciiString aTmpDir = SALOMEDS_Tool::GetTmpDir();
540 _saveFileName = CORBA::string_dup(aTmpDir.ToCString());
541 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString());
547 //=============================================================================
551 //=============================================================================
553 void Med_Gen_i::Close(const char *IORSComponent)
555 MESSAGE("Med_Gen_i::Close");
558 //=============================================================================
562 //=============================================================================
564 char* Med_Gen_i::ComponentDataType()
566 MESSAGE("Med_Gen_i::ComponentDataType");
567 return strdup("Med") ; /* What is this type ? */
570 //=============================================================================
572 * CORBA: give a persistent reference of a transient object (for study save)
574 //=============================================================================
576 char* Med_Gen_i::IORToLocalPersistentID(const char* IORString,
577 CORBA::Boolean& IsAFile)
579 const char * LOC = "Med_Gen_i::IORToLocalPersistentID" ;
583 if (string(IORString).size()==0) return strdup("");
584 // Well, we know where put object (_saveFilename) and we know object (IORString)
586 CORBA::Object_var myIOR = _orb->string_to_object(IORString);
589 SALOME_MED::MED_var myMed = SALOME_MED::MED::_narrow(myIOR);
590 if (! CORBA::is_nil(myMed))
592 // nothing to save : Support will be saved inside the mesh
593 string str_MedName="Objet Med + /OBJ_MED/";
594 return strdup(str_MedName.c_str()) ;
598 SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR);
599 if (! CORBA::is_nil(myMesh))
604 long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,_saveFileName.c_str(),myMesh->getName()) ;
605 myMesh->write(driverId,"");
606 str_MeshName=string("/ENS_MAA/")+string(myMesh->getName());
610 MESSAGE("Unable to save the mesh");
611 THROW_SALOME_CORBA_EXCEPTION("Unable to save Mesh in Med"\
612 ,SALOME::INTERNAL_ERROR);
614 return strdup(str_MeshName.c_str()) ;
618 SALOME_MED::SUPPORT_var mySupport = SALOME_MED::SUPPORT::_narrow(myIOR);
619 if (! CORBA::is_nil(mySupport))
621 // nothing to save : Support will be saved inside the mesh
622 string str_SupportName;
625 str_SupportName=string("/FAS/")+string(mySupport->getName());
626 str_SupportName+=string("/ENS_MAA/")+string(mySupport->getMesh()->getName());
627 SCRUTE(str_SupportName);
631 MESSAGE("Unable to save the support");
632 THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\
633 ,SALOME::INTERNAL_ERROR);
635 return strdup(str_SupportName.c_str());
638 SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR);
639 if (! CORBA::is_nil(myField))
641 string str_FieldName;
644 long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,_saveFileName.c_str(),myField->getName()) ;
645 myField->write(driverId,"");
646 str_FieldName=string("/CHA/")+string(myField->getName());
648 a<< myField->getOrderNumber();
649 b<< myField->getIterationNumber();
650 str_FieldName+=string("/ORDRE/")+a.str()+string("/ITER/")+b.str();
654 MESSAGE("Unable to save the mesh");
655 THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\
656 ,SALOME::INTERNAL_ERROR);
658 return strdup(str_FieldName.c_str());
661 //THROW_SALOME_CORBA_EXCEPTION("Unable to save IOR",SALOME::BAD_PARAM);
667 //=============================================================================
669 * CORBA: give a transient reference (when loading an object, opening study)
671 //=============================================================================
673 char* Med_Gen_i::LocalPersistentIDToIOR(const char* aLocalPersistentID)
675 const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ;
678 TCollection_AsciiString aTmpDir(CORBA::string_dup(_saveFileName.c_str()));
679 TCollection_AsciiString aFileName("MED_tmp_");
680 aFileName += CORBA::string_dup(aLocalPersistentID);
683 MESH * myMesh= new MESH() ;
684 myMesh->setName(aLocalPersistentID);
685 MED_MESH_RDONLY_DRIVER myMeshDriver((aTmpDir+aFileName).ToCString(),myMesh);
688 myMeshDriver.setMeshName(aLocalPersistentID);
691 catch (const exception & ex)
693 MESSAGE("Exception Interceptee : ");
695 THROW_SALOME_CORBA_EXCEPTION("Unable to find this mesh in this file",SALOME::BAD_PARAM);
700 MESSAGE("apres read");
701 myMeshDriver.close();
703 catch (const exception & ex)
705 MESSAGE("Exception Interceptee : ");
707 THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file",SALOME::BAD_PARAM);
710 MESH_i * meshi = new MESH_i(myMesh);
711 //SALOME_MED::MESH_var mesh = SALOME_MED::MESH::_narrow(meshi->_this());
712 SALOME_MED::MESH_ptr mesh = meshi->_this();
714 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
716 aSeq[0]=CORBA::string_dup(aFileName.ToCString());
717 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq, true);
719 return(CORBA::string_dup(_orb->object_to_string(mesh)));
724 //=============================================================================
726 * returns true, if can publish object
728 //=============================================================================
729 bool Med_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
730 SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theIOR);
731 return !(aMesh->_is_nil());
734 //=============================================================================
736 * publish the given object
738 //=============================================================================
739 SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
740 SALOMEDS::SObject_ptr theSObject,
741 CORBA::Object_ptr theObject,
742 const char* theName) throw (SALOME::SALOME_Exception)
744 SALOMEDS::SObject_var aResultSO;
746 if(CORBA::is_nil(theObject)) return aResultSO;
747 if(theStudy->_is_nil()) return aResultSO;
749 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
750 SALOMEDS::GenericAttribute_var anAttr;
751 SALOMEDS::AttributeName_var aName;
752 SALOMEDS::AttributeIOR_var anIOR;
753 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("Med");
755 if (aFather->_is_nil()) {
756 aFather = aBuilder->NewComponent("Med");
757 if (aFather->_is_nil()) return aResultSO;
758 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
759 aName = SALOMEDS::AttributeName::_narrow(anAttr);
760 aName->SetValue("MED");
761 aBuilder->DefineComponentInstance(aFather, Med_Gen::_this());
764 if (CORBA::is_nil(theSObject)) {
765 SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theObject);
766 aMesh->addInStudy(theStudy, aMesh);
767 SALOMEDS::SObject_var aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject));
769 if (!theSObject->ReferencedObject(aResultSO))
770 THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM);
772 // aBuilder->Addreference(theObject, aResultSO);
773 return aResultSO._retn();
776 //=============================================================================
778 * C factory, accessible with dlsym, after dlopen
780 //=============================================================================
784 PortableServer::ObjectId * MedEngine_factory(
786 PortableServer::POA_ptr poa,
787 PortableServer::ObjectId * contId,
788 const char *instanceName,
789 const char *interfaceName)
791 MESSAGE("PortableServer::ObjectId * MedEngine_factory()");
792 SCRUTE(interfaceName);
793 Med_Gen_i * myMed_Gen
794 = new Med_Gen_i(orb, poa, contId, instanceName, interfaceName);
795 return myMed_Gen->getId() ;