1 //=============================================================================
2 // File : MEDMEM_Med_i.cxx
5 // Copyright : EDF 2002
6 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_i.cxx
7 //=============================================================================
11 //#include "MEDMEM_Field.hxx"
13 #include "MEDMEM_Med_i.hxx"
14 #include "MEDMEM_Mesh_i.hxx"
15 #include "MEDMEM_FieldDouble_i.hxx"
16 #include "MEDMEM_FieldInt_i.hxx"
17 #include "MEDMEM_Support_i.hxx"
18 #include "MEDMEM_Family_i.hxx"
19 #include "MEDMEM_Group_i.hxx"
20 #include "MEDMEM_convert.hxx"
22 #include "MEDMEM_DriversDef.hxx"
23 #include "utilities.h"
24 #include "Utils_CorbaException.hxx"
27 using namespace MEDMEM;
29 //=============================================================================
33 //=============================================================================
34 MED_i::MED_i():_med((::MED*)NULL)
36 BEGIN_OF("Default Constructor MED_i");
37 END_OF("Default Constructor MED_i");
39 //=============================================================================
43 //=============================================================================
44 void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName)
46 const char * LOC = "MED_i::init(driverTypes, const string &)";
49 // we create all IOR from _med
50 _med = new ::MED(driverType,fileName);
53 deque<string> meshesNames = _med->getMeshNames();
54 int numberOfMeshes = meshesNames.size();
55 for (int i=0; i<numberOfMeshes; i++)
57 ::MESH * myMesh = _med->getMesh(meshesNames[i]);
59 MESH_i * myMeshI = new MESH_i(myMesh);
60 SALOME_MED::MESH_ptr myMeshIOR = myMeshI->_this();
61 _meshes[meshesNames[i]] = myMeshIOR;
62 // myMeshI->addInStudy(myStudy,myMeshIOR,fileName);
66 _med->updateSupport();
69 // we add all families
70 vector<FAMILY*> familyVector;
71 vector<FAMILY*>::iterator familyVectorIt;
74 vector<GROUP*> groupVector;
75 vector<GROUP*>::iterator groupVectorIt;
77 MED_EN::MESH_ENTITIES::const_iterator currentEntity;
78 for (int i=0; i<numberOfMeshes; i++)
80 ::MESH * ptrMesh = _med->getMesh(meshesNames[i]);
81 for (currentEntity = MED_EN::meshEntities.begin();
82 currentEntity != MED_EN::meshEntities.end();
85 // MESSAGE(LOC << ": for entity " << (*currentEntity).first);
87 familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first);
88 int nb = familyVector.size();
89 // MESSAGE(LOC << ": there is(are) " << nb << " family(ies)");
90 for (familyVectorIt = familyVector.begin();
91 familyVectorIt != familyVector.end();
94 FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt);
95 SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this();
96 // myFamilyI->addInStudy(myStudy,myFamilyIOR);
100 groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first);
101 nb = groupVector.size();
102 // MESSAGE(LOC << ": there is(are) " << nb << " group(s)");
103 for (groupVectorIt = groupVector.begin();
104 groupVectorIt != groupVector.end();
107 GROUP_i * myGroupI = new GROUP_i(*groupVectorIt);
108 SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this();
109 // myGroupI->addInStudy(myStudy,myGroupIOR);
114 for (int i=0; i<numberOfMeshes; i++)
116 map<MED_EN::medEntityMesh,::SUPPORT*> mySupports = _med->getSupports(meshesNames[i]);
117 map<MED_EN::medEntityMesh,::SUPPORT*>::const_iterator itSupport;
118 map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> & mySupportsIOR
119 = _supports[meshesNames[i]];
120 for ( itSupport = mySupports.begin(); itSupport != mySupports.end(); itSupport++ )
122 SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second);
123 SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this();
124 mySupportsIOR[(*itSupport).first] = mySupportIOR;
125 // mySupportI->addInStudy(myStudy,mySupportIOR);
130 deque<string> fieldsNames = _med->getFieldNames();
131 int numberOfFields = fieldsNames.size();
132 for (int i=0; i<numberOfFields; i++)
134 deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
135 int numberOfIteration = myIteration.size();
136 for (int j=0; j<numberOfIteration; j++)
138 ::FIELD_ * myField = _med->getField(fieldsNames[i], myIteration[j].dt, myIteration[j].it);
139 string meshName = myField->getSupport()->getMesh()->getName();
140 medEntityMesh myEntity = myField->getSupport()->getEntity();
141 map<string, map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> >::const_iterator
142 itSupportOnMesh = _supports.find(meshName);
143 if ( itSupportOnMesh == _supports.end() )
144 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
145 << "There is no support on mesh named |"
146 << meshName << "|" ));
147 const map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> & SupportOnMesh
148 = (*itSupportOnMesh).second;
149 map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport
150 = SupportOnMesh.find(myEntity);
151 if (itSupport == SupportOnMesh.end())
152 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
153 << "There is no support on entity "
154 << entity << " in mesh named |"
155 << meshName << "|"));
156 SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second;
157 med_type_champ type = myField->getValueType();
158 SALOME_MED::FIELD_ptr myFieldIOR;
161 case MED_EN::MED_INT32 :
163 ((FIELD<int>*)myField)->read();
164 FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD<int>*)myField);
165 myFieldIOR = myFieldIntI->_this();
166 // myFieldIntI->addInStudy(myStudy,myFieldIOR);
170 case MED_EN::MED_REEL64:
172 ((FIELD<double>*)myField)->read();
173 FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD<double>*)myField);
174 myFieldIOR = myFieldDoubleI->_this();
175 // myFieldDoubleI->addInStudy(myStudy,myFieldIOR);
180 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
181 <<" * Iteration "<<FieldIteration[j].dt
182 <<", order number "<<FieldIteration[j].it
183 <<" has wrong type : "<<type));
189 dtIt.dt = myIteration[j].dt;
190 dtIt.it = myIteration[j].it;
191 _fields[fieldsNames[i]][dtIt] = myFieldIOR;
198 //=============================================================================
202 //=============================================================================
203 void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName)
205 const char * LOC = "MED_i::initWithFieldType(driverTypes, const string &)";
208 // we create all IOR from _med
213 _med = new ::MED(driverType,fileName);
215 int numberOfMeshes = _med->getNumberOfMeshes();
216 SCRUTE(numberOfMeshes);
218 deque<string> meshesNames = _med->getMeshNames();
219 string meshName0 = meshesNames[0];
223 for (int i=0; i<numberOfMeshes; i++)
225 string meshNamei = meshesNames[i];
228 ::MESH * myMesh = _med->getMesh(meshNamei);
230 MESH_i * myMeshI = new MESH_i(myMesh);
231 SALOME_MED::MESH_ptr myMeshIOR = myMeshI->_this();
232 _meshes[meshesNames[i]]=myMeshIOR;
233 myMeshI->addInStudy(myStudy,myMeshIOR);
237 _med->updateSupport();
240 // we add all families
241 vector<FAMILY*> familyVector;
242 vector<FAMILY*>::iterator familyVectorIt;
245 vector<GROUP*> groupVector;
246 vector<GROUP*>::iterator groupVectorIt;
248 SCRUTE(numberOfMeshes);
250 MED_EN::MESH_ENTITIES::const_iterator currentEntity;
251 for (int i=0; i<numberOfMeshes; i++)
253 ::MESH * ptrMesh = _med->getMesh(meshesNames[i]);
257 for (currentEntity = MED_EN::meshEntities.begin();
258 currentEntity != MED_EN::meshEntities.end();
261 MESSAGE(LOC << ": for entity " << (*currentEntity).first);
263 familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first);
264 int nb = familyVector.size();
265 MESSAGE(LOC << ": there is(are) " << nb << " family(ies)");
266 for (familyVectorIt = familyVector.begin();
267 familyVectorIt != familyVector.end();
270 FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt);
271 SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this();
272 myFamilyI->addInStudy(myStudy,myFamilyIOR);
276 groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first);
277 nb = groupVector.size();
278 MESSAGE(LOC << ": there is(are) " << nb << " group(s)");
279 for (groupVectorIt = groupVector.begin();
280 groupVectorIt != groupVector.end();
283 GROUP_i * myGroupI = new GROUP_i(*groupVectorIt);
284 SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this();
285 myGroupI->addInStudy(myStudy,myGroupIOR);
290 for (int i=0; i<numberOfMeshes; i++)
292 map<MED_EN::medEntityMesh,::SUPPORT*> mySupports = _med->getSupports(meshesNames[i]);
293 map<MED_EN::medEntityMesh,::SUPPORT*>::const_iterator itSupport;
294 map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> &
295 mySupportsIOR = _supports[meshesNames[i]];
296 for (itSupport=mySupports.begin(); itSupport!=mySupports.end(); itSupport++ )
298 SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second);
299 SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this();
300 mySupportsIOR[(*itSupport).first]= mySupportIOR;
301 mySupportI->addInStudy(myStudy,mySupportIOR);
308 // for (int i=0; i<numberOfMeshes; i++)
310 // string meshName = meshesNames[i];
311 // char * supportEntryPath;
313 // string supportName;
314 // SALOMEDS::SObject_var supportEntry;
316 // supportName = "SupportOnAll_MED_MAILLE";
317 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
318 // supportEntryPath = new char[lenName];
319 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
320 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
321 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
322 // supportEntryPath = strcat(supportEntryPath,"/");
323 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
325 // SCRUTE(supportEntryPath);
327 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
329 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
331 // if ( CORBA::is_nil(supportEntry) )
332 // cout << "The reuse in Med is OK " << endl;
334 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
335 // delete [] supportEntryPath;
339 // supportName = "SupportOnAll_MED_FACE";
340 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
341 // supportEntryPath = new char[lenName];
342 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
343 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
344 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
345 // supportEntryPath = strcat(supportEntryPath,"/");
346 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
348 // SCRUTE(supportEntryPath);
350 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
352 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
354 // if ( CORBA::is_nil(supportEntry) )
355 // cout << "The reuse in Med is OK " << endl;
357 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
358 // delete [] supportEntryPath;
362 // supportName = "SupportOnAll_MED_ARETE";
363 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
364 // supportEntryPath = new char[lenName];
365 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
366 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
367 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
368 // supportEntryPath = strcat(supportEntryPath,"/");
369 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
371 // SCRUTE(supportEntryPath);
373 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
375 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
377 // if ( CORBA::is_nil(supportEntry) )
378 // cout << "The reuse in Med is OK " << endl;
380 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
381 // delete [] supportEntryPath;
386 // supportName = "SupportOnAll_MED_NOEUD";
387 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
388 // supportEntryPath = new char[lenName];
389 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
390 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
391 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
392 // supportEntryPath = strcat(supportEntryPath,"/");
393 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
395 // SCRUTE(supportEntryPath);
397 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
399 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
401 // if ( CORBA::is_nil(supportEntry) )
402 // cout << "The reuse in Med is OK " << endl;
404 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
405 // delete [] supportEntryPath;
419 deque<string> fieldsNames = _med->getFieldNames();
420 int numberOfFields = fieldsNames.size();
422 SCRUTE(numberOfFields);
424 for (int i=0; i<numberOfFields; i++)
426 MESSAGE("The name of the " << i << "^th fields is "<< fieldsNames[i]);
428 deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
429 int numberOfIteration = myIteration.size();
431 SCRUTE(numberOfIteration);
433 for (int j=0; j<numberOfIteration; j++)
435 MESSAGE("its " << i << "^th iteration is dt = " << myIteration[j].dt << " it = " << myIteration[j].it);
439 for (int i=0; i<numberOfFields; i++)
442 MESSAGE("dealing with the fields collection " << fieldsNames[i]);
444 deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
445 int numberOfIteration = myIteration.size();
447 SCRUTE(numberOfIteration);
449 for (int j=0; j<numberOfIteration; j++)
451 int dt = myIteration[j].dt;
452 int it = myIteration[j].it;
454 MESSAGE("Treatement of " << fieldsNames[i] << " dt = " << dt << " it = " << it);
456 ::FIELD_ * myField = _med->getField(fieldsNames[i],dt,it);
458 string meshName = myField->getSupport()->getMesh()->getName();
459 medEntityMesh myEntity = myField->getSupport()->getEntity();
460 map<string, map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> >::const_iterator
461 itSupportOnMesh = _supports.find(meshName);
462 if (itSupportOnMesh == _supports.end() )
463 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
464 << "There is no support on mesh named |"
465 << meshName << "|"));
466 const map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> & SupportOnMesh
467 = (*itSupportOnMesh).second;
468 map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport
469 = SupportOnMesh.find(myEntity);
470 if (itSupport == SupportOnMesh.end() )
471 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
472 << "There is no support on entity "
473 << entity << " in mesh named |"
474 << meshName << "|"));
475 SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second;
476 med_type_champ type = myField->getValueType();
484 case MED_EN::MED_INT32:
486 ((FIELD<int>*)myField)->read();
487 FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD<int>*)myField);
488 SALOME_MED::FIELDINT_ptr myFieldIntIOR;
489 myFieldIntIOR = myFieldIntI->_this();
491 MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it);
493 myFieldIntI->addInStudy(myStudy,myFieldIntIOR);
494 _fields[fieldsNames[i]][dtIt] = myFieldIntIOR;
498 case MED_EN::MED_REEL64:
500 ((FIELD<double>*)myField)->read();
501 FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD<double>*)myField);
502 SALOME_MED::FIELDDOUBLE_ptr myFieldDoubleIOR;
503 myFieldDoubleIOR = myFieldDoubleI->_this();
505 MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it);
507 myFieldDoubleI->addInStudy(myStudy,myFieldDoubleIOR);
508 _fields[fieldsNames[i]][dtIt] = myFieldDoubleIOR;
514 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
515 <<" * Iteration "<<FieldIteration[j].dt
516 <<", order number "<<FieldIteration[j].it
517 <<" has wrong type : "<<type));
523 MESSAGE("Here we are i="<< i);
540 // for (int i=0; i<numberOfMeshes; i++)
542 // string meshName = meshesNames[i];
543 // char * supportEntryPath;
545 // string supportName;
546 // SALOMEDS::SObject_var supportEntry;
548 // supportName = "SupportOnAll_MED_MAILLE";
549 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
550 // supportEntryPath = new char[lenName];
551 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
552 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
553 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
554 // supportEntryPath = strcat(supportEntryPath,"/");
555 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
557 // SCRUTE(supportEntryPath);
559 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
561 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
563 // if ( CORBA::is_nil(supportEntry) )
564 // cout << "The reuse in Med is OK " << endl;
566 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
567 // delete [] supportEntryPath;
571 // supportName = "SupportOnAll_MED_FACE";
572 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
573 // supportEntryPath = new char[lenName];
574 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
575 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
576 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
577 // supportEntryPath = strcat(supportEntryPath,"/");
578 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
580 // SCRUTE(supportEntryPath);
582 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
584 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
586 // if ( CORBA::is_nil(supportEntry) )
587 // cout << "The reuse in Med is OK " << endl;
589 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
590 // delete [] supportEntryPath;
594 // supportName = "SupportOnAll_MED_ARETE";
595 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
596 // supportEntryPath = new char[lenName];
597 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
598 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
599 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
600 // supportEntryPath = strcat(supportEntryPath,"/");
601 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
603 // SCRUTE(supportEntryPath);
605 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
607 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
609 // if ( CORBA::is_nil(supportEntry) )
610 // cout << "The reuse in Med is OK " << endl;
612 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
613 // delete [] supportEntryPath;
618 // supportName = "SupportOnAll_MED_NOEUD";
619 // lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str());
620 // supportEntryPath = new char[lenName];
621 // supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
622 // supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
623 // supportEntryPath = strcat(supportEntryPath,meshName.c_str());
624 // supportEntryPath = strcat(supportEntryPath,"/");
625 // supportEntryPath = strcat(supportEntryPath,supportName.c_str());
627 // SCRUTE(supportEntryPath);
629 // cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl;
631 // supportEntry = myStudy->FindObjectByPath(supportEntryPath);
633 // if ( CORBA::is_nil(supportEntry) )
634 // cout << "The reuse in Med is OK " << endl;
636 // cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl;
637 // delete [] supportEntryPath;
661 //=============================================================================
665 //=============================================================================
669 //=============================================================================
671 * CORBA: Accessor for Number of meshes
673 //=============================================================================
674 CORBA::Long MED_i::getNumberOfMeshes()
675 throw (SALOME::SALOME_Exception)
678 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
679 SALOME::INTERNAL_ERROR);
682 return _med->getNumberOfMeshes();
684 catch (MEDEXCEPTION &ex)
686 MESSAGE("Unable to get the number of meshes in Med Object");
687 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
690 //=============================================================================
692 * CORBA: Accessor for Number of fields
694 //=============================================================================
695 CORBA::Long MED_i::getNumberOfFields()
696 throw (SALOME::SALOME_Exception)
699 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
700 SALOME::INTERNAL_ERROR);
703 return _med->getNumberOfFields();
705 catch (MEDEXCEPTION &ex)
707 MESSAGE("Unable to get the number of fields in Med Object");
708 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
711 //=============================================================================
713 * CORBA: Accessor for meshes names
715 //=============================================================================
716 SALOME_MED::string_array * MED_i::getMeshNames()
717 throw (SALOME::SALOME_Exception)
720 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
721 SALOME::INTERNAL_ERROR);
722 SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
725 int nbMeshes=_med->getNumberOfMeshes();
726 myseq->length(nbMeshes);
727 string * nameMeshes = new string[nbMeshes];
728 _med->getMeshNames(nameMeshes);
729 for (int i=0;i<nbMeshes;i++)
731 myseq[i]=CORBA::string_dup(nameMeshes[i].c_str());
733 delete [] nameMeshes;
736 catch (MEDEXCEPTION &ex)
738 MESSAGE("Unable to get the names of the meshes in Med Object");
739 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
741 return myseq._retn();
743 //=============================================================================
745 * CORBA: Accessor for fields names
747 //=============================================================================
748 SALOME_MED::string_array * MED_i::getFieldNames()
749 throw (SALOME::SALOME_Exception)
752 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
753 SALOME::INTERNAL_ERROR);
754 SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
757 deque<string> nameFields = _med->getFieldNames();
758 int nbFields = nameFields.size();
759 myseq->length(nbFields);
761 for (int i=0;i<nbFields;i++)
763 myseq[i]=CORBA::string_dup(nameFields[i].c_str());
766 catch (MEDEXCEPTION &ex)
768 MESSAGE("Unable to get the names of the fields in Med Object");
769 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
771 return myseq._retn();
773 //=============================================================================
775 * CORBA: Accessor for a specific mesh
777 //=============================================================================
778 SALOME_MED::MESH_ptr MED_i::getMeshByName(const char* meshName)
779 throw (SALOME::SALOME_Exception)
782 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
783 SALOME::INTERNAL_ERROR);
786 MESH * mesh=_med->getMesh(meshName);
787 MESH_i * m1 = new MESH_i(mesh);
788 return m1->POA_SALOME_MED::MESH::_this();
790 catch (MEDEXCEPTION &ex)
792 MESSAGE("Unable to get the specified mesh");
793 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
797 //=============================================================================
799 * CORBA: Accessor for a specific mesh
801 //=============================================================================
802 SALOME_MED::MESH_ptr MED_i::getMesh(SALOME_MED::FIELD_ptr fieldPtr)
803 throw (SALOME::SALOME_Exception)
806 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
807 SALOME::INTERNAL_ERROR);
808 int ind=fieldPtr->getCorbaIndex();
812 SALOME_MED::FIELDINT_var fieldint =SALOME_MED::FIELDINT::_narrow(fieldPtr);
813 if (CORBA::is_nil(fieldint))
816 SALOME_MED::FIELDDOUBLE_var fielddouble =
817 SALOME_MED::FIELDDOUBLE::_narrow(fieldPtr);
818 ASSERT(!CORBA::is_nil(fielddouble));
820 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
822 ::FIELD<double> * fdouble = (::FIELD<double> *)FIELD_i::fieldMap[ind];
823 MESH * mesh=_med->getMesh(fdouble);
828 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
830 ::FIELD<int> * fint = (::FIELD<int> *)FIELD_i::fieldMap[ind];
831 MESH * mesh=_med->getMesh(fint);
833 MESH_i * meshi = new MESH_i(mesh);
834 return meshi->POA_SALOME_MED::MESH::_this();
837 //=============================================================================
839 * CORBA: Accessor for Number of iteration of a given field by its name.
841 //=============================================================================
842 CORBA::Long MED_i::getFieldNumberOfIteration(const char* fieldName)
843 throw (SALOME::SALOME_Exception)
846 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
847 SALOME::INTERNAL_ERROR);
851 deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
852 return fieldIteration.size();
854 catch (MEDEXCEPTION &ex)
856 MESSAGE("Unable to get the number of iteration of the field " << fieldName << " in Med Object");
857 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
860 //=============================================================================
862 * CORBA: Accessor for the Corba equivalent DT_IT_ (see MEDMEM direcrtory)
863 * of a given field by its name and its number (sequence of two long integers).
865 //=============================================================================
866 SALOME_MED::long_array * MED_i::getFieldIteration(const char* fieldName,CORBA::Long i)
867 throw (SALOME::SALOME_Exception)
870 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
871 SALOME::INTERNAL_ERROR);
873 SALOME_MED::long_array_var myseq = new SALOME_MED::long_array;
876 deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
877 int numberOfIteration = fieldIteration.size();
879 if (i < 0 || i >=numberOfIteration)
880 THROW_SALOME_CORBA_EXCEPTION("The integer i should be geater or equal to 0 and lesser then numberOfIteration", \
881 SALOME::INTERNAL_ERROR);
884 myseq[0] = fieldIteration[i].dt;
885 myseq[1] = fieldIteration[i].it;
886 return myseq._retn();
888 catch (MEDEXCEPTION &ex)
890 MESSAGE("Unable to get the sequence of DT_IT of the given field");
891 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
894 //=============================================================================
896 * CORBA: Accessor for the list of Corba equivalent DT_IT_ (see MEDMEM direcrtory)
897 * of a given field by its name (sequence of two by iteration number long integers).
899 //=============================================================================
900 SALOME_MED::long_array * MED_i::getFieldIterations(const char* fieldName)
901 throw (SALOME::SALOME_Exception)
904 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
905 SALOME::INTERNAL_ERROR);
907 SALOME_MED::long_array_var myseq = new SALOME_MED::long_array;
910 deque<DT_IT_> fieldIteration = _med->getFieldIteration(string(fieldName));
911 int numberOfIteration = fieldIteration.size();
912 int size = 2*numberOfIteration;
916 for (int i=0; i<numberOfIteration; i++)
919 myseq[index] = fieldIteration[i].dt;
921 myseq[index] = fieldIteration[i].it;
924 return myseq._retn();
926 catch (MEDEXCEPTION &ex)
928 MESSAGE("Unable to get the sequence of DT_IT of the given field");
929 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
932 //=============================================================================
934 * CORBA: Accessor for a specific field
936 //=============================================================================
937 SALOME_MED::FIELD_ptr MED_i::getField(const char* fieldName,
938 CORBA::Long pasTemps,
939 CORBA::Long numOrdre )
940 throw (SALOME::SALOME_Exception)
942 const char * LOC="MED_i::getField(const char*,CORBA::Long,CORBA::Long) ";
947 dtIt.dt= (int)pasTemps;
948 dtIt.it= (int)numOrdre;
950 map<string,MAP_IOR_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
952 if ( itFields == _fields.end() )
953 THROW_SALOME_CORBA_EXCEPTION("Field not found !", SALOME::INTERNAL_ERROR);
955 const MAP_IOR_DT_IT_ & map_dtIt = (*itFields).second;
956 MAP_IOR_DT_IT_::const_iterator itMap_dtIt = map_dtIt.find(dtIt);
958 if ( itMap_dtIt == map_dtIt.end() )
959 THROW_SALOME_CORBA_EXCEPTION("Iteration not found !", SALOME::INTERNAL_ERROR);
962 return (*itMap_dtIt).second;
965 //=============================================================================
967 * CORBA: Accessor for a specific field
969 //=============================================================================
970 CORBA::Long MED_i::addDriver(SALOME_MED::medDriverTypes driverType, const char* fileName)
971 throw (SALOME::SALOME_Exception)
974 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
975 SALOME::INTERNAL_ERROR);
978 int driv=_med->addDriver(convertIdlDriverToMedDriver(driverType),
982 catch (MEDEXCEPTION &ex)
984 MESSAGE("Unable to add a driver to the med object");
985 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
989 //=============================================================================
991 * CORBA: relase the driver (mandatory)
993 //=============================================================================
994 void MED_i::rmDriver(CORBA::Long i)
995 throw (SALOME::SALOME_Exception)
998 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
999 SALOME::INTERNAL_ERROR);
1004 catch (MEDEXCEPTION &ex)
1006 MESSAGE("Unable to unlink the driver from the med object");
1007 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1010 //=============================================================================
1012 * CORBA: read med objects relations
1014 //=============================================================================
1015 void MED_i::readFileStruct(CORBA::Long i)
1016 throw (SALOME::SALOME_Exception)
1019 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1020 SALOME::INTERNAL_ERROR);
1023 _med->readFileStruct(i);
1025 catch (MEDEXCEPTION &ex)
1027 MESSAGE("Unable to read the structure of this file ");
1028 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1031 //=============================================================================
1033 * CORBA: write specifics objects f
1035 //=============================================================================
1036 void MED_i::writeFrom(CORBA::Long i)
1037 throw (SALOME::SALOME_Exception)
1040 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1041 SALOME::INTERNAL_ERROR);
1046 catch (MEDEXCEPTION &ex)
1048 MESSAGE("Unable to write this driver ");
1049 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1052 //=============================================================================
1054 * CORBA: write objects
1056 //=============================================================================
1057 void MED_i::write(CORBA::Long i)
1058 throw (SALOME::SALOME_Exception)
1061 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1062 SALOME::INTERNAL_ERROR);
1067 catch (MEDEXCEPTION &ex)
1069 MESSAGE("Unable to write this file ");
1070 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1073 //=============================================================================
1075 * CORBA: Add Mesh in Med objects
1077 //=============================================================================
1078 void MED_i::addMesh(SALOME_MED::MESH_ptr ptrMesh)
1079 throw (SALOME::SALOME_Exception)
1082 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1083 SALOME::INTERNAL_ERROR);
1086 int ind=ptrMesh->getCorbaIndex();
1088 ASSERT(MESH_i::meshMap.find(ind) !=MESH_i::meshMap.end());
1089 MESH * mesh= MESH_i::meshMap[ind];
1090 _med->addMesh(mesh);
1092 catch (MEDEXCEPTION &ex)
1094 MESSAGE("Unable to link this mesh to this med object");
1095 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1098 //=============================================================================
1100 * CORBA: Add field in Med objects
1102 //=============================================================================
1103 void MED_i::addField(SALOME_MED::FIELD_ptr ptrField)
1104 throw (SALOME::SALOME_Exception)
1107 THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\
1108 SALOME::INTERNAL_ERROR);
1109 int ind=ptrField->getCorbaIndex();
1112 SALOME_MED::FIELDINT_var fieldint =SALOME_MED::FIELDINT::_narrow(ptrField);
1113 if (CORBA::is_nil(fieldint))
1116 SALOME_MED::FIELDDOUBLE_var fielddouble =
1117 SALOME_MED::FIELDDOUBLE::_narrow(ptrField);
1118 ASSERT(!CORBA::is_nil(fielddouble));
1120 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
1122 ::FIELD<double> * fdouble = (::FIELD<double> *)FIELD_i::fieldMap[ind];
1124 //_med->addField(fdouble);
1129 ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end());
1130 ::FIELD<int> * fint = (::FIELD<int> *)FIELD_i::fieldMap[ind];
1131 //_med->addField(fint);
1134 //=============================================================================
1136 * CORBA: Add Med object in Study
1138 //=============================================================================
1139 void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor)
1140 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1142 BEGIN_OF("MED_Mesh_i::addInStudy");
1145 MESSAGE("Med already in Study");
1146 THROW_SALOME_CORBA_EXCEPTION("Med already in Study", \
1150 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
1151 myBuilder->NewCommand();
1152 SALOMEDS::GenericAttribute_var anAttr;
1153 SALOMEDS::AttributeName_var aName;
1154 SALOMEDS::AttributeIOR_var aIOR;
1156 // Create SComponent labelled 'MED' if it doesn't already exit
1157 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1158 if ( CORBA::is_nil(medfather) )
1160 THROW_SALOME_CORBA_EXCEPTION("Component Med not found",
1164 MESSAGE("Add a MED Object under Med");
1165 SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
1167 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1168 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
1169 CORBA::ORB_var &orb = init(0,0);
1170 string iorStr = orb->object_to_string(myIor);
1171 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1172 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1173 aIOR->SetValue(iorStr.c_str());
1174 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1175 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1176 aName->SetValue("Objet MED");
1177 _medId = newObj->GetID();
1178 myBuilder->CommitCommand();
1180 // register the Corba pointer: increase the referrence count
1181 MESSAGE("Registering of the Corba Med pointer");
1184 END_OF("Med_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
1187 //=============================================================================
1189 * CORBA: Add Med object in Study with a name medObjName
1191 //=============================================================================
1192 void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor,
1193 const char * fileName)
1194 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1196 BEGIN_OF("MED_i::addInStudy(myStudy, myIor, fileName)");
1199 MESSAGE("Med already in Study");
1200 THROW_SALOME_CORBA_EXCEPTION("Med already in Study", \
1204 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
1205 myBuilder->NewCommand();
1206 SALOMEDS::GenericAttribute_var anAttr;
1207 SALOMEDS::AttributeName_var aName;
1208 SALOMEDS::AttributeIOR_var aIOR;
1210 // Create SComponent labelled 'MED' if it doesn't already exit
1211 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1212 if ( CORBA::is_nil(medfather) )
1214 THROW_SALOME_CORBA_EXCEPTION("Component Med not found",
1218 MESSAGE("Add a MED Object under Med");
1221 string::size_type pos1=string(fileName).rfind('/');
1222 string::size_type lenFileName = strlen(fileName);
1223 string fileNameShort = string(fileName,pos1+1,lenFileName-pos1-1);
1225 SCRUTE(fileNameShort);
1227 int lenName = 21 + strlen(fileNameShort.c_str()) + 1;
1228 medObjName = new char[lenName];
1229 medObjName = strcpy(medObjName,"MED_OBJECT_FROM_FILE_");
1230 medObjName = strcat(medObjName,fileNameShort.c_str());
1232 SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
1234 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1235 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
1236 CORBA::ORB_var &orb = init(0,0);
1237 string iorStr = orb->object_to_string(myIor);
1238 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1239 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1240 aIOR->SetValue(iorStr.c_str());
1241 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1242 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1243 aName->SetValue(medObjName);
1244 _medId = newObj->GetID();
1245 myBuilder->CommitCommand();
1247 delete [] medObjName;
1249 // char * medObjName1;
1250 // lenName = 26 + strlen(fileNameShort.c_str());
1251 // medObjName1 = new char[lenName];
1252 // medObjName1 = strcpy(medObjName1,"/MED/MED_OBJECT_FROM_FILE_");
1253 // medObjName1 = strcat(medObjName1,fileNameShort.c_str());
1255 // SALOMEDS::SObject_var medEntry = myStudy->FindObjectByPath(medObjName1);
1256 // if (!CORBA::is_nil(medEntry))
1258 // MESSAGE("MED_Mesh_i::addInStudy(myStudy, myIor, fileName) : The reuse in Med of Object MED from Study is OK");
1262 // MESSAGE("MED_Mesh_i::addInStudy(myStudy, myIor, fileName) : the reuse in Med of Object MED is not OK and there was a problem in the storage in the study");
1265 // delete [] medObjName1;
1267 // register the Corba pointer: increase the referrence count
1268 MESSAGE("Registering of the Corba Med pointer");
1271 END_OF("Med_i::addInStudy(myStudy, myIor, medObjName)");