1 //=============================================================================
2 // File : MEDMEM_Field_i.cxx
3 // Created : mer fév 20 15:47:57 CET 2002
6 // Copyright : EDF 2002
7 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Field_i.cxx
8 //=============================================================================
9 #include "MEDMEM_Field_i.hxx"
11 using namespace MEDMEM;
12 using namespace MED_EN;
14 map < int, ::FIELD_ * > FIELD_i::fieldMap ;
15 int FIELD_i::fieldIndex = 0;
16 //=============================================================================
20 //=============================================================================
22 //FIELD_i::FIELD_i():_fieldTptr(FIELD_i::constructConstField())
23 FIELD_i::FIELD_i():_fieldTptr(constructConstField()),_corbaIndex(FIELD_i::fieldIndex++)
25 BEGIN_OF("Default Constructor Field_i");
26 END_OF(" Default Constructor Field_i");
28 //=============================================================================
32 //=============================================================================
35 if (_ownCppPtr) delete _fieldTptr;
37 //=============================================================================
41 //=============================================================================
42 FIELD_i::FIELD_i(::FIELD_ * const field, bool ownCppPtr):
44 _corbaIndex(FIELD_i::fieldIndex++),
48 BEGIN_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
49 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
51 MESSAGE("FIELD_i::FIELD_i Checking of pointeurs !!!");
55 END_OF("Constructor FIELD_i(SALOME_MED::SUPPORT_ptr support,::FIELD<T> * const field)");
58 //=============================================================================
60 * Constructor par recopie
62 //=============================================================================
63 FIELD_i::FIELD_i( FIELD_i & f):_fieldTptr(f._fieldTptr),
64 _corbaIndex(FIELD_i::fieldIndex++),
65 _FieldId(""), _ownCppPtr(false)
67 BEGIN_OF("Constructor Field_i");
68 FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
69 END_OF("Constructor Field_i");
71 //=============================================================================
73 * Constructor d un pointeur constant
75 //=============================================================================
76 ::FIELD_ * FIELD_i::constructConstField() const
78 ::FIELD_ * const ptrField =new ::FIELD_();
81 //=============================================================================
83 * CORBA: Accessor for Fields's Name
85 //=============================================================================
86 char * FIELD_i::getName()
87 throw (SALOME::SALOME_Exception)
90 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
91 SALOME::INTERNAL_ERROR);
94 return CORBA::string_dup(_fieldTptr->getName().c_str());
96 catch (MEDEXCEPTION &ex)
98 MESSAGE("Exception en accedant au nom");
99 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
102 //=============================================================================
104 * CORBA: Accessor for Fields's Description
106 //=============================================================================
107 char * FIELD_i::getDescription()
108 throw (SALOME::SALOME_Exception)
110 if (_fieldTptr==NULL)
111 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
112 SALOME::INTERNAL_ERROR);
115 return CORBA::string_dup(_fieldTptr->getDescription().c_str());
117 catch (MEDEXCEPTION &ex)
119 MESSAGE("Exception en accedant a la description");
120 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
123 //=============================================================================
125 * CORBA: Accessor for Fields's Support
127 //=============================================================================
129 SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()
130 throw (SALOME::SALOME_Exception)
132 BEGIN_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
134 if (_fieldTptr==NULL)
135 THROW_SALOME_CORBA_EXCEPTION("No associated Field",
136 SALOME::INTERNAL_ERROR);
138 SUPPORT_i* servant = new SUPPORT_i(_fieldTptr->getSupport());
140 SALOME_MED::SUPPORT_ptr support=servant->_this();
144 END_OF("SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()");
148 //=============================================================================
150 * CORBA: Accessor for Fields's Number of components
152 //=============================================================================
153 CORBA::Long FIELD_i::getNumberOfComponents()
154 throw (SALOME::SALOME_Exception)
156 if (_fieldTptr==NULL)
157 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
158 SALOME::INTERNAL_ERROR);
161 return _fieldTptr->getNumberOfComponents();
163 catch (MEDEXCEPTION &ex)
165 MESSAGE("Exception en accedant au support");
166 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
169 //=============================================================================
171 * CORBA: Accessor for names of component I
173 //=============================================================================
174 char * FIELD_i::getComponentName(CORBA::Long i)
175 throw (SALOME::SALOME_Exception)
177 if (_fieldTptr==NULL)
178 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
179 SALOME::INTERNAL_ERROR);
182 return CORBA::string_dup(_fieldTptr->getComponentName(i).c_str());
184 catch (MEDEXCEPTION &ex)
186 MESSAGE("Exception en accedant au nom d un component");
187 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
190 //=============================================================================
192 * CORBA: Accessor for unit of component I
194 //=============================================================================
195 char * FIELD_i::getComponentUnit(CORBA::Long i)
196 throw (SALOME::SALOME_Exception)
198 if (_fieldTptr==NULL)
199 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
200 SALOME::INTERNAL_ERROR);
203 return CORBA::string_dup(_fieldTptr->getMEDComponentUnit(i).c_str());
205 catch (MEDEXCEPTION &ex)
207 MESSAGE("Exception en accedant au nom d un component");
208 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
211 //=============================================================================
213 * CORBA: Accessor for description of component I
215 //=============================================================================
216 char * FIELD_i::getComponentDescription(CORBA::Long i)
217 throw (SALOME::SALOME_Exception)
219 if (_fieldTptr==NULL)
220 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
221 SALOME::INTERNAL_ERROR);
224 return CORBA::string_dup(_fieldTptr->getComponentDescription(i).c_str());
226 catch (MEDEXCEPTION &ex)
228 MESSAGE("Exception en accedant a la description d un component");
229 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
232 //=============================================================================
234 * CORBA: Accessor for iteration number
236 //=============================================================================
237 CORBA::Long FIELD_i::getIterationNumber()
238 throw (SALOME::SALOME_Exception)
240 if (_fieldTptr==NULL)
241 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
242 SALOME::INTERNAL_ERROR);
245 return _fieldTptr->getIterationNumber();
247 catch (MEDEXCEPTION &ex)
249 MESSAGE("Exception en accedant au champ");
250 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
253 //=============================================================================
255 * CORBA: Accessor for Corba Number
257 //=============================================================================
258 CORBA::Long FIELD_i::getCorbaIndex()
259 throw (SALOME::SALOME_Exception)
261 if (_fieldTptr==NULL)
262 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
263 SALOME::INTERNAL_ERROR);
267 //=============================================================================
269 * CORBA: Accessor for iteration number
271 //=============================================================================
272 CORBA::Long FIELD_i::getOrderNumber()
273 throw (SALOME::SALOME_Exception)
275 if (_fieldTptr==NULL)
276 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
277 SALOME::INTERNAL_ERROR);
280 return _fieldTptr->getOrderNumber();
282 catch (MEDEXCEPTION &ex)
284 MESSAGE("Exception en accedant au champ");
285 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
288 //=============================================================================
292 //=============================================================================
293 CORBA::Double FIELD_i::getTime()
294 throw (SALOME::SALOME_Exception)
296 if (_fieldTptr==NULL)
297 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
298 SALOME::INTERNAL_ERROR);
301 return _fieldTptr->getTime();
303 catch (MEDEXCEPTION &ex)
305 MESSAGE("Exception en accedant au champ");
306 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
309 //=============================================================================
311 * CORBA: Accessor for Fields's Components names
313 //=============================================================================
314 SALOME_MED::string_array * FIELD_i::getComponentsNames()
315 throw (SALOME::SALOME_Exception)
317 if (_fieldTptr==NULL)
318 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
319 SALOME::INTERNAL_ERROR);
320 SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
323 int nbcom = _fieldTptr->getNumberOfComponents();
324 myseq->length(nbcom);
325 const string * namecom=_fieldTptr->getComponentsNames();
326 for (int i=0;i<nbcom;i++)
328 myseq[i]=CORBA::string_dup(namecom[i].c_str());
331 catch (MEDEXCEPTION &ex)
333 MESSAGE("Exception en accedant au champ");
334 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
336 return myseq._retn();
338 //=============================================================================
340 * CORBA: Accessor for Fields's Components units
342 //=============================================================================
343 SALOME_MED::string_array * FIELD_i::getComponentsUnits()
344 throw (SALOME::SALOME_Exception)
346 if (_fieldTptr==NULL)
347 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
348 SALOME::INTERNAL_ERROR);
349 SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
352 int nbcom = _fieldTptr->getNumberOfComponents();
353 myseq->length(nbcom);
354 const string * unitcom=_fieldTptr->getMEDComponentsUnits();
355 for (int i=0;i<nbcom;i++)
357 myseq[i]=CORBA::string_dup(unitcom[i].c_str());
360 catch (MEDEXCEPTION &ex)
362 MESSAGE("Exception en accedant au champ");
363 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
365 return myseq._retn();
367 //=============================================================================
369 * CORBA: Accessor for Fields's Components descriptions
371 //=============================================================================
372 SALOME_MED::string_array * FIELD_i::getComponentsDescriptions()
373 throw (SALOME::SALOME_Exception)
375 if (_fieldTptr==NULL)
376 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
377 SALOME::INTERNAL_ERROR);
378 SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
381 int nbcom = _fieldTptr->getNumberOfComponents();
382 myseq->length(nbcom);
383 const string * namecom=_fieldTptr->getComponentsDescriptions();
384 for (int i=0;i<nbcom;i++)
386 myseq[i]=CORBA::string_dup(namecom[i].c_str());
389 catch (MEDEXCEPTION &ex)
391 MESSAGE("Exception en accedant au champ");
392 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
394 return myseq._retn();
396 //=============================================================================
398 * CORBA: Add in Study
400 //=============================================================================
401 void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy,
402 SALOME_MED::FIELD_ptr myIor )
403 throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
405 BEGIN_OF(" FIELD_i::addInStudy");
406 if (_fieldTptr==NULL)
407 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
408 SALOME::INTERNAL_ERROR);
409 if ( _FieldId != "" )
411 MESSAGE("Field already in Study");
412 THROW_SALOME_CORBA_EXCEPTION("Field already in Study", \
417 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
418 SALOMEDS::GenericAttribute_var anAttr;
419 SALOMEDS::AttributeName_var aName;
420 SALOMEDS::AttributeIOR_var aIOR;
422 // Create SComponent labelled 'Med'
423 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
424 if ( CORBA::is_nil(medfather) )
425 THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'MED' not Found",SALOME::INTERNAL_ERROR);
427 // Create SObject labelled 'MEDFIELD' if it doesn't already exit
428 SALOMEDS::SObject_var medfieldfather = myStudy->FindObject("MEDFIELD");
429 if ( CORBA::is_nil(medfieldfather) )
431 MESSAGE("Add Object 'MEDFIELD'");
432 medfieldfather = myBuilder->NewObject(medfather);
433 anAttr = myBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName");
434 aName = SALOMEDS::AttributeName::_narrow(anAttr);
435 aName->SetValue("MEDFIELD");
439 string fieldName = _fieldTptr->getName();
441 // Create SObject labelled 'FIELDNAME' if it doesn't already exit
442 SALOMEDS::SObject_var medfieldnamefather = myStudy->FindObject(fieldName.c_str());
443 if ( CORBA::is_nil(medfieldnamefather) )
445 MESSAGE("Add Object "<<fieldName);
446 medfieldnamefather = myBuilder->NewObject(medfieldfather);
447 anAttr = myBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName");
448 aName = SALOMEDS::AttributeName::_narrow(anAttr);
449 aName->SetValue(fieldName.c_str());
453 // Create object labelled according to Field's Name
455 MESSAGE("Add a Field Object under "<<fieldName);
456 myBuilder->NewCommand();
457 SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfieldnamefather);
459 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
460 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
461 CORBA::ORB_var &orb = init(0,0);
463 int iterationNumber = _fieldTptr->getIterationNumber();
464 SCRUTE(iterationNumber);
466 int orderNumber = _fieldTptr->getOrderNumber();
469 ostringstream iterationName ;
470 iterationName<<"(" << iterationNumber << "," << orderNumber << ")";
471 // string supportName = _support->getName();
472 string supportName = (_fieldTptr->getSupport())->getName();
473 // string meshName = (_support->getMesh())->getName();
474 string meshName = ((_fieldTptr->getSupport())->getMesh())->getName();
475 string meshNameStudy = meshName;
477 char * fieldEntryName;
478 int lenName = strlen(iterationName.str().c_str()) + 4 +
479 strlen(supportName.c_str()) + 4 + strlen(meshName.c_str()) + 1;
481 fieldEntryName = new char[lenName];
482 fieldEntryName = strcpy(fieldEntryName,iterationName.str().c_str());
483 fieldEntryName = strcat(fieldEntryName,"_ON_");
484 fieldEntryName = strcat(fieldEntryName,supportName.c_str());
485 fieldEntryName = strcat(fieldEntryName,"_OF_");
487 for (string::size_type pos=0; pos<meshNameStudy.size();++pos)
489 if (isspace(meshNameStudy[pos])) meshNameStudy[pos] = '_';
492 SCRUTE(meshNameStudy);
494 fieldEntryName = strcat(fieldEntryName,meshNameStudy.c_str());
496 SCRUTE(fieldEntryName);
498 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
499 aName = SALOMEDS::AttributeName::_narrow(anAttr);
500 // aName->SetValue(iterationName.str().c_str());
501 aName->SetValue(fieldEntryName);
503 string iorStr = orb->object_to_string(myIor);
504 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
505 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
506 aIOR->SetValue(iorStr.c_str());
507 myBuilder->CommitCommand();
508 _FieldId = newObj->GetID();
510 MESSAGE("Computing path to Support");
512 char * supportEntryPath;
513 lenName = 28 + 15 + strlen(meshName.c_str()) + 1 +
514 strlen(supportName.c_str()) + 1;
515 supportEntryPath = new char[lenName];
516 supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/MEDSUPPORTS_OF_");
517 supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str());
518 supportEntryPath = strcat(supportEntryPath,"/");
519 supportEntryPath = strcat(supportEntryPath,supportName.c_str());
521 SCRUTE(supportEntryPath);
523 MESSAGE("supportEntryPath in field " << supportEntryPath << " length " << lenName);
525 // SALOMEDS::SObject_var supportObject = myStudy->FindObject(supportName.c_str());
526 SALOMEDS::SObject_var supportObject = myStudy->FindObjectByPath(supportEntryPath);
528 SCRUTE(supportObject);
530 if ( CORBA::is_nil(supportObject) )
532 MESSAGE("supportObject is a nil corba object");
533 MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ;
537 MESSAGE("supportObject is OK and is now going to be referenced !");
538 SALOMEDS::SObject_var newObjSupport = myBuilder->NewObject(newObj);
539 myBuilder->Addreference(newObjSupport,supportObject);
543 myBuilder->CommitCommand();
545 delete [] supportEntryPath;
546 delete [] fieldEntryName;
548 // register the Corba pointer: increase the referrence count
549 MESSAGE("Registering of the Corba Field pointer");
552 MESSAGE("FIELD_i::addInStudy");
554 //END_OF("FIELD_i::addInStudy");
556 //=============================================================================
560 //=============================================================================
561 void FIELD_i::write (CORBA::Long i, const char* driverFieldName)
562 throw (SALOME::SALOME_Exception)
564 if (_fieldTptr==NULL)
565 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
566 SALOME::INTERNAL_ERROR);
569 _fieldTptr->write(i,driverFieldName);
571 catch (MEDEXCEPTION &ex)
573 MESSAGE("Exception en accedant au champ");
574 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\
575 ,SALOME::INTERNAL_ERROR);
578 //=============================================================================
582 //=============================================================================
583 void FIELD_i::read (CORBA::Long i)
584 throw (SALOME::SALOME_Exception)
586 if (_fieldTptr==NULL)
587 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
588 SALOME::INTERNAL_ERROR);
593 catch (MEDEXCEPTION &ex)
595 MESSAGE("Exception en accedant au champ");
596 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
599 //=============================================================================
603 //=============================================================================
604 void FIELD_i::rmDriver (CORBA::Long i)
605 throw (SALOME::SALOME_Exception)
607 if (_fieldTptr==NULL)
608 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
609 SALOME::INTERNAL_ERROR);
612 _fieldTptr->rmDriver(i);
614 catch (MEDEXCEPTION &ex)
616 MESSAGE("Exception en accedant au champ");
617 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
620 //=============================================================================
624 //=============================================================================
625 CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType,
626 const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception)
628 if (_fieldTptr==NULL)
629 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
630 SALOME::INTERNAL_ERROR);
633 int drivernum=_fieldTptr->addDriver(
634 convertIdlDriverToMedDriver(driverType),
639 catch (MEDEXCEPTION &ex)
641 MESSAGE("Exception en accedant au champ");
642 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);