1 //=============================================================================
2 // File : Support_i.cxx
5 // Copyright : EDF 2002
6 // $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Support_i.cxx
7 //=============================================================================
10 #include "Utils_CorbaException.hxx"
11 #include "Utils_ORB_INIT.hxx"
12 #include "Utils_SINGLETON.hxx"
14 #include CORBA_SERVER_HEADER(MED)
15 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
18 #include "MEDMEM_define.hxx"
19 #include "MEDMEM_Support.hxx"
21 #include "Support_i.hxx"
23 #include "convert.hxx"
25 // Initialisation des variables statiques
26 map < int, ::SUPPORT *> SUPPORT_i::supportMap ;
27 int SUPPORT_i::supportIndex = 0 ;
30 //=============================================================================
34 //=============================================================================
35 SUPPORT_i::SUPPORT_i() :_support((::SUPPORT *)NULL)
37 BEGIN_OF("Default Constructor SUPPORT_i");
38 END_OF("Default Constructor SUPPORT_i");
41 //=============================================================================
45 //=============================================================================
46 SUPPORT_i::SUPPORT_i(const ::SUPPORT * const s) :_support(s),
47 _corbaIndex(SUPPORT_i::supportIndex++)
49 BEGIN_OF("Constructor SUPPORT_i");
50 SUPPORT_i::supportMap[_corbaIndex]=(::SUPPORT *)_support;
51 END_OF("Constructor SUPPORT_i");
53 //=============================================================================
57 //=============================================================================
58 SUPPORT_i::SUPPORT_i(const SUPPORT_i &s) :_support(s._support),
59 _corbaIndex(SUPPORT_i::supportIndex++)
61 BEGIN_OF("Constructor SUPPORT_i");
62 SUPPORT_i::supportMap[_corbaIndex]=(::SUPPORT *)_support;
63 END_OF("Constructor SUPPORT_i");
65 //=============================================================================
69 //=============================================================================
71 SUPPORT_i::~SUPPORT_i()
74 //=============================================================================
76 * CORBA: Accessor for Corba Index
78 //=============================================================================
80 CORBA::Long SUPPORT_i::getCorbaIndex()
81 throw (SALOME::SALOME_Exception)
84 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
85 SALOME::INTERNAL_ERROR);
89 //=============================================================================
91 * CORBA: Accessor for Name
93 //=============================================================================
95 char * SUPPORT_i::getName()
96 throw (SALOME::SALOME_Exception)
99 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
100 SALOME::INTERNAL_ERROR);
103 return CORBA::string_dup(_support->getName().c_str());
107 MESSAGE("Unable to access the name of the support ");
108 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
109 ,SALOME::INTERNAL_ERROR);
114 //=============================================================================
116 * CORBA: Accessor for Description
118 //=============================================================================
120 char* SUPPORT_i::getDescription()
121 throw (SALOME::SALOME_Exception)
124 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
125 SALOME::INTERNAL_ERROR);
128 return CORBA::string_dup(_support->getDescription().c_str());
132 MESSAGE("Unable to access the description of the support ");
133 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
134 ,SALOME::INTERNAL_ERROR);
138 //=============================================================================
140 * CORBA: Accessor for Mesh
142 //=============================================================================
144 SALOME_MED::MESH_ptr SUPPORT_i::getMesh()
145 throw (SALOME::SALOME_Exception)
147 BEGIN_OF("SALOME_MED::MESH_ptr SUPPORT_i::getMesh()");
150 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
151 SALOME::INTERNAL_ERROR);
154 MESH * mesh = _support->getMesh();
158 MESH_i * m1 = new MESH_i(mesh);
159 SALOME_MED::MESH_ptr m2 = m1->POA_SALOME_MED::MESH::_this();
163 MESSAGE("SALOME_MED::MESH_ptr SUPPORT_i::getMesh() checking des pointeurs CORBA");
170 END_OF("SALOME_MED::MESH_ptr SUPPORT_i::getMesh()");
172 return (SALOME_MED::MESH::_duplicate(m2));
176 MESSAGE("Unable to access the assoicated mesh");
177 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
178 ,SALOME::INTERNAL_ERROR);
182 //=============================================================================
184 * CORBA: boolean indicating if support concerns all elements
186 //=============================================================================
188 CORBA::Boolean SUPPORT_i::isOnAllElements()
189 throw (SALOME::SALOME_Exception)
192 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
193 SALOME::INTERNAL_ERROR);
196 return _support->isOnAllElements();
200 MESSAGE("Unable to access the type of the support");
201 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
202 ,SALOME::INTERNAL_ERROR);
206 //=============================================================================
208 * CORBA: Accessor for type of support's entity
210 //=============================================================================
212 SALOME_MED::medEntityMesh SUPPORT_i::getEntity()
213 throw (SALOME::SALOME_Exception)
215 BEGIN_OF("SALOME_MED::medEntityMesh SUPPORT_i::getEntity()");
218 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
219 SALOME::INTERNAL_ERROR);
222 END_OF("SALOME_MED::medEntityMesh SUPPORT_i::getEntity()");
223 return convertMedEntToIdlEnt(_support->getEntity());
227 MESSAGE("Unable to access support s entity");
228 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object", \
229 SALOME::INTERNAL_ERROR);
233 //=============================================================================
235 * CORBA: Accessor for types of geometry elements
237 //=============================================================================
239 SALOME_MED::medGeometryElement_array * SUPPORT_i::getTypes()
240 throw (SALOME::SALOME_Exception)
243 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
244 SALOME::INTERNAL_ERROR);
245 SALOME_MED::medGeometryElement_array_var myseq = new SALOME_MED::medGeometryElement_array;
248 int mySeqLength=_support->getNumberOfTypes();
249 myseq->length(mySeqLength);
250 const medGeometryElement * elemts = _support->getTypes();
251 for (int i=0;i<mySeqLength;i++)
253 myseq[i]=convertMedEltToIdlElt(elemts[i]);
258 MESSAGE("Unable to access support different types");
259 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object", \
260 SALOME::INTERNAL_ERROR);
262 return myseq._retn();
265 //=============================================================================
267 * CORBA: Number of different types of geometry elements
268 * existing in the support
270 //=============================================================================
271 CORBA::Long SUPPORT_i::getNumberOfElements(SALOME_MED::medGeometryElement geomElement)
272 throw (SALOME::SALOME_Exception)
276 SCRUTE(SALOME_MED::MED_ALL_ELEMENTS);
279 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
280 SALOME::INTERNAL_ERROR);
283 return _support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
287 MESSAGE("Unable to access the number of support different types");
288 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
289 ,SALOME::INTERNAL_ERROR);
294 //=============================================================================
298 //=============================================================================
300 Engines::long_array * SUPPORT_i::getNumber(SALOME_MED::medGeometryElement geomElement)
301 throw (SALOME::SALOME_Exception)
305 SCRUTE(convertIdlEltToMedElt(geomElement));
308 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
309 SALOME::INTERNAL_ERROR);
310 Engines::long_array_var myseq= new Engines::long_array;
313 int nbelements=_support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
314 myseq->length(nbelements);
315 SCRUTE(_support->getName());
317 SCRUTE(convertIdlEltToMedElt(geomElement));
318 const int * numbers=_support->getNumber(convertIdlEltToMedElt(geomElement));
319 for (int i=0;i<nbelements;i++)
327 MESSAGE("Unable to access the support optionnal index");
328 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
329 ,SALOME::INTERNAL_ERROR);
331 return myseq._retn();
334 //=============================================================================
336 * CORBA: Global Nodes Index (optionnaly designed by the user)
337 * CORBA: ??????????????????????????????
339 //=============================================================================
341 Engines::long_array * SUPPORT_i::getNumberIndex()
342 throw (SALOME::SALOME_Exception)
345 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
346 SALOME::INTERNAL_ERROR);
347 Engines::long_array_var myseq= new Engines::long_array;
350 MESSAGE ("Nombre d'elements mis de façon stupide a MED_ALL_ELEMENTS");
351 int nbelements=_support->getNumberOfElements(::MED_ALL_ELEMENTS);
352 myseq->length(nbelements);
353 const int * numbers=_support->getNumberIndex();
354 for (int i=0;i<nbelements;i++)
361 MESSAGE("Unable to access the support index");
362 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
363 ,SALOME::INTERNAL_ERROR);
365 return myseq._retn();
369 //=============================================================================
371 * CORBA: Array containing indexes for elements included in the support
373 //=============================================================================
375 CORBA::Long SUPPORT_i::getNumberOfGaussPoints(SALOME_MED::medGeometryElement geomElement)
376 throw (SALOME::SALOME_Exception)
379 THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
380 SALOME::INTERNAL_ERROR);
383 return _support->getNumberOfGaussPoint(convertIdlEltToMedElt(geomElement));
387 MESSAGE("Unable to access number of Gauss points");
388 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
389 ,SALOME::INTERNAL_ERROR);
393 //=============================================================================
395 * CORBA: add the Support in the StudyManager
397 //=============================================================================
398 void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr myIor)
399 throw (SALOME::SALOME_Exception)
401 BEGIN_OF("SUPPORT_i::addInStudy");
403 if ( _supportId != "" )
405 MESSAGE("Support already in Study");
406 THROW_SALOME_CORBA_EXCEPTION("Support already in Study", \
410 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
411 SALOMEDS::GenericAttribute_var anAttr;
412 SALOMEDS::AttributeName_var aName;
413 SALOMEDS::AttributeIOR_var aIOR;
415 // Find SComponent labelled 'Med'
416 MESSAGE("Find SComponent labelled 'Med'");
417 // SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med");
418 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
419 if ( CORBA::is_nil(medfather) )
420 THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
422 if ( CORBA::is_nil(myStudy) )
423 THROW_SALOME_CORBA_EXCEPTION("Study deleted !!!",SALOME::INTERNAL_ERROR);
425 // Find SObject MESH (represent mesh in support)
426 SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
427 if ( CORBA::is_nil(medmeshfather) )
429 cout << "On a leve l exception" << flush;
430 THROW_SALOME_CORBA_EXCEPTION("SObject labelled 'MEDMESH' not Found",SALOME::INTERNAL_ERROR);
432 cout << "Find SObject MESH (represent mesh in support)"<< flush;
434 string meshName = getMesh()->getName() ;
436 // seulement sous Med : il peut y avoir le meme sous SMESH !!!
437 SALOMEDS::SObject_var medsupportfather = myStudy->FindObject(meshName.c_str());
438 if ( CORBA::is_nil(medsupportfather) )
439 THROW_SALOME_CORBA_EXCEPTION("SObject Mesh in Support not Found",SALOME::INTERNAL_ERROR);
440 // perhaps add MESH automatically ?
442 MESSAGE("Add a support Object under MED/MESH/MESHNAME");
443 SALOMEDS::SObject_var medsupfather = myStudy->FindObject("MEDSUPPORT");
444 if ( CORBA::is_nil(medsupfather) )
446 MESSAGE("Add Object MEDSUPPORT");
447 medsupfather = myBuilder->NewObject(medmeshfather);
448 anAttr = myBuilder->FindOrCreateAttribute(medsupfather, "AttributeName");
449 aName = SALOMEDS::AttributeName::_narrow(anAttr);
450 aName->SetValue("MEDSUPPORT");
455 //myBuilder->NewCommand();
456 SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str());
457 // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!!
458 if ( CORBA::is_nil(supportEntry) )
460 // not already in study : we create it !
461 SALOMEDS::SObject_var newObj = myBuilder->NewObject(medsupfather);
462 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
463 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
464 CORBA::ORB_var &orb = init(0,0);
465 string iorStr = orb->object_to_string(myIor);
466 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
467 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
468 aIOR->SetValue(iorStr.c_str());
469 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
470 aName = SALOMEDS::AttributeName::_narrow(anAttr);
471 aName->SetValue(_support->getName().c_str());
472 _supportId = newObj->GetID();
476 // already in study : put new AttributeIOR !
477 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
478 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
479 CORBA::ORB_var &orb = init(0,0);
480 string iorStr = orb->object_to_string(myIor);
481 anAttr = myBuilder->FindOrCreateAttribute(supportEntry, "AttributeIOR");
482 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
483 aIOR->SetValue(iorStr.c_str());
485 myBuilder->CommitCommand();
487 END_OF("SUPPORT_i::addInStudy");