1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 //=============================================================================
24 // File : MEDMEM_Mesh_i.cxx
27 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Mesh_i.cxx
28 //=============================================================================
32 #include "utilities.h"
33 #include "Utils_CorbaException.hxx"
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
37 #include "MEDMEM_convert.hxx"
38 #include "MEDMEM_Mesh_i.hxx"
39 #include "MEDMEM_Support_i.hxx"
40 #include "MEDMEM_Family_i.hxx"
41 #include "MEDMEM_Group_i.hxx"
42 #include "MEDMEM_FieldTemplate_i.hxx"
44 #include "MEDMEM_Mesh.hxx"
45 #include "MEDMEM_Family.hxx"
46 #include "MEDMEM_Group.hxx"
47 #include "MEDMEM_CellModel.hxx"
49 #include "SenderFactory.hxx"
50 #include "MultiCommException.hxx"
51 using namespace MEDMEM;
53 // Initialisation des variables statiques
54 map < int, ::GMESH *> GMESH_i::meshMap ;
55 int GMESH_i::meshIndex = 0 ;
59 //=============================================================================
63 //=============================================================================
66 SALOME::GenericObj_i(),
67 _mesh(constructConstMesh()),
68 _corbaIndex(MESH_i::meshIndex++),
71 MESH_i::meshMap[_corbaIndex]=_mesh;
73 //=============================================================================
77 //=============================================================================
81 _mesh->removeReference();
83 //=============================================================================
87 //=============================================================================
88 GMESH_i::GMESH_i(::GMESH * const m ) :
90 SALOME::GenericObj_i(),
92 _corbaIndex(MESH_i::meshIndex++),
95 if ( _mesh ) _mesh->addReference();
96 GMESH_i::meshMap[_corbaIndex]=_mesh;
98 //=============================================================================
102 //=============================================================================
103 //MESH_i::MESH_i(const MESH_i & m) :_mesh(m._mesh),
104 GMESH_i::GMESH_i( GMESH_i & m) :
106 SALOME::GenericObj_i(),
108 _corbaIndex(MESH_i::meshIndex++),
111 if ( _mesh ) _mesh->addReference();
112 GMESH_i::meshMap[_corbaIndex]=_mesh;
114 //=============================================================================
116 * Internal Method in order to have a const ptr
118 //=============================================================================
119 ::GMESH * GMESH_i::constructConstMesh() const
121 ::MESH * const ptrMesh =new ::MESH();
124 //=============================================================================
126 * CORBA: Accessor for Name
128 //=============================================================================
129 char * GMESH_i::getName()
130 throw (SALOME::SALOME_Exception)
133 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
134 SALOME::INTERNAL_ERROR);
138 return CORBA::string_dup(_mesh->getName().c_str());
140 catch (MEDEXCEPTION &ex)
142 MESSAGE("Unable to acces the mesh name");
143 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
146 //=============================================================================
148 * CORBA: Accessor for corbaindex cuisine interne
150 //=============================================================================
151 CORBA::Long GMESH_i::getCorbaIndex()
152 throw (SALOME::SALOME_Exception)
155 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
156 SALOME::INTERNAL_ERROR);
159 //=============================================================================
161 * CORBA: Accessor for Space Dimension
163 //=============================================================================
164 CORBA::Long GMESH_i::getSpaceDimension()
165 throw (SALOME::SALOME_Exception)
168 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
169 SALOME::INTERNAL_ERROR);
172 return _mesh->getSpaceDimension();
174 catch (MEDEXCEPTION &ex)
176 MESSAGE("Unable to acces the space dimension ");
177 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
180 //=============================================================================
182 * CORBA: Accessor for Mesh Dimension
184 //=============================================================================
185 CORBA::Long GMESH_i::getMeshDimension()
186 throw (SALOME::SALOME_Exception)
189 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
190 SALOME::INTERNAL_ERROR);
193 return _mesh->getMeshDimension();
195 catch (MEDEXCEPTION &ex)
197 MESSAGE("Unable to acces the mesh dimension ");
198 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
201 //=============================================================================
203 * CORBA: boolean indicating if mesh is a Grid
205 //=============================================================================
206 CORBA::Boolean GMESH_i::getIsAGrid()
207 throw (SALOME::SALOME_Exception)
210 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
211 SALOME::INTERNAL_ERROR);
214 return _mesh->getIsAGrid();
216 catch (MEDEXCEPTION &ex)
218 MESSAGE("Unable to acces mesh flag isAGrid");
219 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
223 //=============================================================================
225 * CORBA: Accessor for Coordinates System
227 //=============================================================================
228 char * GMESH_i::getCoordinatesSystem()
229 throw (SALOME::SALOME_Exception)
232 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
233 SALOME::INTERNAL_ERROR);
237 return CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
239 catch (MEDEXCEPTION &ex)
241 MESSAGE("Unable to acces the type of CoordinatesSystem");
242 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
246 //=============================================================================
248 * CORBA: Accessor for Coordinates Names
250 //=============================================================================
251 SALOME_TYPES::ListOfString * GMESH_i::getCoordinatesNames()
252 throw (SALOME::SALOME_Exception)
255 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
256 SALOME::INTERNAL_ERROR);
257 SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
260 int spaceDimension=_mesh->getSpaceDimension();
261 const string * coordinatesName =_mesh->getCoordinatesNames();
262 myseq->length(spaceDimension);
263 for (int i=0; i<spaceDimension; i++)
265 myseq[i]=CORBA::string_dup(coordinatesName[i].c_str());
268 catch (MEDEXCEPTION &ex)
270 MESSAGE("Unable to acces the coordinates names");
271 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
273 return myseq._retn();
276 //=============================================================================
278 * CORBA: Accessor for Coordinates Units
280 //=============================================================================
281 SALOME_TYPES::ListOfString * GMESH_i::getCoordinatesUnits()
282 throw (SALOME::SALOME_Exception)
285 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
286 SALOME::INTERNAL_ERROR);
287 SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
290 int spaceDimension=_mesh->getSpaceDimension();
291 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
292 myseq->length(spaceDimension);
293 for (int i=0; i<spaceDimension; i++)
295 myseq[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
298 catch (MEDEXCEPTION &ex)
300 MESSAGE("Unable to acces the coordinates units");
301 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
303 return myseq._retn();
305 //=============================================================================
307 * CORBA: Accessor for Number of Nodes
309 //=============================================================================
310 CORBA::Long GMESH_i::getNumberOfNodes()
311 throw (SALOME::SALOME_Exception)
314 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
315 SALOME::INTERNAL_ERROR);
318 return _mesh->getNumberOfNodes();
320 catch (MEDEXCEPTION &ex)
322 MESSAGE("Unable to acces number of nodes");
323 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
326 //=============================================================================
328 * CORBA: Accessor for number of Types
330 //=============================================================================
331 CORBA::Long GMESH_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity)
332 throw (SALOME::SALOME_Exception)
335 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
336 SALOME::INTERNAL_ERROR);
339 return _mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
341 catch (MEDEXCEPTION &ex)
343 MESSAGE("Unable to acces number of differents types");
344 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
347 //=============================================================================
349 * CORBA: Accessor for existing geometry element types
351 //=============================================================================
352 SALOME_MED::medGeometryElement GMESH_i::getElementType (SALOME_MED::medEntityMesh entity,
354 throw (SALOME::SALOME_Exception)
357 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
358 SALOME::INTERNAL_ERROR);
361 return _mesh->getElementType(convertIdlEntToMedEnt(entity),number);
363 catch (MEDEXCEPTION &ex)
365 MESSAGE("Unable to acces number of differents element types");
366 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
370 //=============================================================================
372 * CORBA: Accessor for existing geometry element types
373 * Not implemented for MED_ALL_ENTITIES
375 //=============================================================================
376 SALOME_MED::medGeometryElement_array * GMESH_i::getTypes (SALOME_MED::medEntityMesh entity)
377 throw (SALOME::SALOME_Exception)
380 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
381 SALOME::INTERNAL_ERROR);
382 if (entity ==SALOME_MED::MED_ALL_ENTITIES)
383 THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",\
385 SALOME_MED::medGeometryElement_array_var myseq =
386 new SALOME_MED::medGeometryElement_array;
389 int nbTypes=_mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
390 const medGeometryElement * elemts =_mesh->getTypes(
391 convertIdlEntToMedEnt(entity));
392 myseq->length(nbTypes);
393 for (int i=0; i<nbTypes; i++)
395 myseq[i]=convertMedEltToIdlElt(elemts[i]);
398 catch (MEDEXCEPTION &ex)
400 MESSAGE("Unable to acces coordinates");
401 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
403 return myseq._retn();
405 //=============================================================================
407 * CORBA: Returns number of elements of type medGeometryElement
408 * Not implemented for MED_ALL_ELEMENTS
409 * implemented for MED_ALL_ENTITIES
411 //=============================================================================
412 CORBA::Long GMESH_i::getNumberOfElements(SALOME_MED::medEntityMesh entity,
413 SALOME_MED::medGeometryElement geomElement)
414 throw (SALOME::SALOME_Exception)
417 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
418 SALOME::INTERNAL_ERROR);
419 if (verifieParam(entity,geomElement)==false)
420 THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
425 // if ( geomElement == SALOME_MED::MED_POLYGON ||
426 // geomElement == SALOME_MED::MED_POLYHEDRA )
427 // return _mesh->getNumberOfElementsWithPoly(convertIdlEntToMedEnt(entity),
428 // convertIdlEltToMedElt(geomElement));
430 return _mesh->getNumberOfElements(convertIdlEntToMedEnt(entity),
431 convertIdlEltToMedElt(geomElement));
433 catch (MEDEXCEPTION &ex)
435 MESSAGE("Unable to acces number of elements");
436 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
440 //=============================================================================
442 * CORBA: Returns number of families within the mesh
444 //=============================================================================
445 CORBA::Long GMESH_i::getNumberOfFamilies(SALOME_MED::medEntityMesh entity)
446 throw (SALOME::SALOME_Exception)
449 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
450 SALOME::INTERNAL_ERROR);
453 return _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
455 catch (MEDEXCEPTION &ex)
457 MESSAGE("Unable to acces number of families of the mesh");
458 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
461 //=============================================================================
463 * CORBA: Returns number of groups within the mesh
465 //=============================================================================
466 CORBA::Long GMESH_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity)
467 throw (SALOME::SALOME_Exception)
470 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
471 SALOME::INTERNAL_ERROR);
474 return _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
476 catch (MEDEXCEPTION &ex)
478 MESSAGE("Unable to acces number of groups of the mesh");
479 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
482 //=============================================================================
484 * CORBA: Returns references for families within the mesh
486 //=============================================================================
487 SALOME_MED::Family_array * GMESH_i::getFamilies(SALOME_MED::medEntityMesh entity)
488 throw (SALOME::SALOME_Exception)
491 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
492 SALOME::INTERNAL_ERROR);
493 SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
496 int nbfam= _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
497 myseq->length(nbfam);
498 vector<FAMILY*> fam(nbfam);
499 fam = _mesh->getFamilies(convertIdlEntToMedEnt(entity));
500 for (int i=0;i<nbfam;i++)
502 FAMILY_i * f1=new FAMILY_i(fam[i]);
503 myseq[i] = f1->_this();
506 catch (MEDEXCEPTION &ex)
508 MESSAGE("Unable to acces families of the mesh");
509 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
511 return myseq._retn();
513 //=============================================================================
515 * CORBA: Returns Coordinates global informations
517 //=============================================================================
518 SALOME_MED::GMESH::coordinateInfos * GMESH_i::getCoordGlobal()
519 throw (SALOME::SALOME_Exception)
522 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
523 SALOME::INTERNAL_ERROR);
524 SALOME_MED::GMESH::coordinateInfos_var all = new SALOME_MED::GMESH::coordinateInfos;
527 all->coordSystem = CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
529 int spaceDimension=_mesh->getSpaceDimension();
530 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
531 const string * coordinatesName =_mesh->getCoordinatesNames();
533 all->coordUnits.length(spaceDimension);
534 all->coordNames.length(spaceDimension);
535 for (int i=0; i<spaceDimension; i++)
537 all->coordUnits[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
538 all->coordNames[i]=CORBA::string_dup(coordinatesName[i].c_str());
541 catch (MEDEXCEPTION &ex)
543 MESSAGE("Unable to acces coordinate information ");
544 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
549 //=============================================================================
551 * CORBA: Returns references for family i within the mesh
553 //=============================================================================
554 SALOME_MED::FAMILY_ptr GMESH_i::getFamily(SALOME_MED::medEntityMesh entity,
556 throw (SALOME::SALOME_Exception)
559 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
560 SALOME::INTERNAL_ERROR);
563 const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i);
564 FAMILY_i * f1=new FAMILY_i(fam);
567 catch (MEDEXCEPTION &ex)
569 MESSAGE("Unable to acces specified family of the mesh");
570 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
574 //=============================================================================
576 * CORBA: Returns Mesh global informations
578 //=============================================================================
579 SALOME_MED::GMESH::meshInfos * GMESH_i::getMeshGlobal()
580 throw (SALOME::SALOME_Exception)
583 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
584 SALOME::INTERNAL_ERROR);
585 SALOME_MED::GMESH::meshInfos_var all = new SALOME_MED::GMESH::meshInfos;
588 all->name = CORBA::string_dup(_mesh->getName().c_str());
589 all->spaceDimension = _mesh->getSpaceDimension();
590 all->meshDimension = _mesh->getMeshDimension();
591 all->numberOfNodes = _mesh->getNumberOfNodes();
592 all->isAGrid = _mesh->getIsAGrid();
594 int nbFam= _mesh->getNumberOfFamilies(MED_NODE);
595 all->famNode.length(nbFam);
596 vector<FAMILY*> vNode (nbFam);
597 vNode = _mesh->getFamilies(MED_NODE);
598 for (int i=0;i<nbFam;i++)
600 FAMILY_i * f1=new FAMILY_i(vNode[i]);
601 all->famNode[i] = f1->_this();
604 nbFam = _mesh->getNumberOfFamilies(MED_EDGE);
605 all->famEdge.length(nbFam);
606 vector<FAMILY*> vEdge (nbFam);
607 vEdge = _mesh->getFamilies(MED_EDGE);
608 for (int i=0;i<nbFam;i++)
609 for (int i=0;i<nbFam;i++)
611 FAMILY_i * f1=new FAMILY_i(vEdge[i]);
612 all->famEdge[i] = f1->_this();
615 nbFam = _mesh->getNumberOfFamilies(MED_FACE);
616 all->famFace.length(nbFam);
617 vector<FAMILY*> vFace (nbFam);
618 vFace = _mesh->getFamilies(MED_FACE);
619 for (int i=0;i<nbFam;i++)
621 FAMILY_i * f1=new FAMILY_i(vFace[i]);
622 all->famFace[i] = f1->_this();
625 nbFam = _mesh->getNumberOfFamilies(MED_CELL);
626 all->famCell.length(nbFam);
627 vector<FAMILY*> vCell (nbFam);
628 vCell = _mesh->getFamilies(MED_CELL);
629 for (int i=0;i<nbFam;i++)
631 FAMILY_i * f1=new FAMILY_i(vCell[i]);
632 all->famCell[i] = f1->_this();
635 int nbGroup = _mesh->getNumberOfGroups(MED_NODE);
636 all->groupNode.length(nbGroup);
637 vector<GROUP*> gNode (nbGroup);
638 gNode = _mesh->getGroups(MED_NODE);
639 for (int i=0;i<nbGroup;i++)
641 GROUP_i * f1=new GROUP_i(gNode[i]);
642 all->groupNode[i] = f1->_this();
645 nbGroup = _mesh->getNumberOfGroups(MED_EDGE);
646 all->groupEdge.length(nbGroup);
647 vector<GROUP*> gEdge (nbGroup);
648 gEdge = _mesh->getGroups(MED_EDGE);
649 for (int i=0;i<nbGroup;i++)
651 GROUP_i * f1=new GROUP_i(gEdge[i]);
652 all->groupEdge[i] = f1->_this();
654 nbGroup = _mesh->getNumberOfGroups(MED_FACE);
655 all->groupFace.length(nbGroup);
656 vector<GROUP*> gFace (nbGroup);
657 gFace = _mesh->getGroups(MED_FACE);
658 for (int i=0;i<nbGroup;i++)
660 GROUP_i * f1=new GROUP_i(gFace[i]);
661 all->groupFace[i] = f1->_this();
664 nbGroup = _mesh->getNumberOfGroups(MED_CELL);
665 all->groupCell.length(nbGroup);
666 vector<GROUP*> gCell (nbGroup);
667 gCell = _mesh->getGroups(MED_CELL);
668 for (int i=0;i<nbGroup;i++)
670 GROUP_i * f1=new GROUP_i(gCell[i]);
671 all->groupCell[i] = f1->_this();
675 catch (MEDEXCEPTION &ex)
677 MESSAGE("Unable to acces mesh");
678 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
682 //=============================================================================
684 * CORBA: Returns references for groups within the mesh
686 //=============================================================================
687 SALOME_MED::Group_array * GMESH_i::getGroups(SALOME_MED::medEntityMesh entity)
688 throw (SALOME::SALOME_Exception)
691 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
692 SALOME::INTERNAL_ERROR);
693 SALOME_MED::Group_array_var myseq = new SALOME_MED::Group_array;
696 int nbgroups = _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
697 myseq->length(nbgroups);
698 vector<GROUP*> groups(nbgroups);
699 groups = _mesh->getGroups(convertIdlEntToMedEnt(entity));
700 for (int i=0;i<nbgroups;i++)
702 GROUP_i * f1=new GROUP_i(groups[i]);
703 myseq[i] = f1->_this();
706 catch (MEDEXCEPTION &ex)
708 MESSAGE("Unable to acces number of groups of the mesh");
709 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
711 return myseq._retn();
713 //=============================================================================
715 * CORBA: Returns references for group i within the mesh
717 //=============================================================================
718 SALOME_MED::GROUP_ptr GMESH_i::getGroup(SALOME_MED::medEntityMesh entity,
720 throw (SALOME::SALOME_Exception)
723 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
724 SALOME::INTERNAL_ERROR);
727 const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i);
728 GROUP_i * f1=new GROUP_i(grou);
731 catch (MEDEXCEPTION &ex)
733 MESSAGE("Unable to acces specified group of the mesh");
734 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
737 //=============================================================================
741 //=============================================================================
742 SALOME_MED::SUPPORT_ptr GMESH_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
743 throw (SALOME::SALOME_Exception)
746 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
747 SALOME::INTERNAL_ERROR);
750 SUPPORT * myNewSupport = _mesh->getBoundaryElements(convertIdlEntToMedEnt(entity));
751 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
752 return mySupportI->_this();
754 catch (MEDEXCEPTION &ex)
756 MESSAGE("Unable to get the volume ");
757 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
761 //=============================================================================
765 //=============================================================================
766 SALOME_MED::SUPPORT_ptr GMESH_i::getSupportOnAll(SALOME_MED::medEntityMesh entity)
767 throw (SALOME::SALOME_Exception)
770 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
771 SALOME::INTERNAL_ERROR);
774 const SUPPORT * myNewSupport = _mesh->getSupportOnAll(convertIdlEntToMedEnt(entity));
775 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
776 return mySupportI->_this();
778 catch (MEDEXCEPTION &ex)
780 MESSAGE("Unable to get the support ");
781 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
784 //=============================================================================
788 //=============================================================================
789 SALOME_MED::FIELD_ptr GMESH_i::getVolume(SALOME_MED::SUPPORT_ptr mySupport)
790 throw (SALOME::SALOME_Exception)
793 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
794 SALOME::INTERNAL_ERROR); try
796 int sup = mySupport->getCorbaIndex();
797 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
798 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
799 ::FIELD<double>*f=_mesh->getVolume( myCppSupport);
800 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
801 return medf->_this();
803 catch (MEDEXCEPTION &ex)
805 MESSAGE("Unable to get the volume ");
806 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
809 //=============================================================================
813 //=============================================================================
814 SALOME_MED::SUPPORT_ptr GMESH_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
815 throw (SALOME::SALOME_Exception)
818 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
819 SALOME::INTERNAL_ERROR);
822 int sup = mySupport3D->getCorbaIndex();
823 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
824 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
825 SUPPORT * myNewSupport = _mesh->getSkin(myCppSupport);
826 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
827 return mySupportI->_this() ;
829 catch (MEDEXCEPTION &ex)
831 MESSAGE("Unable to get the volume ");
832 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
835 //=============================================================================
839 //=============================================================================
840 SALOME_MED::FIELD_ptr GMESH_i::getArea(SALOME_MED::SUPPORT_ptr mySupport)
841 throw (SALOME::SALOME_Exception)
844 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
845 SALOME::INTERNAL_ERROR);
848 int sup = mySupport->getCorbaIndex();
849 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
850 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
851 ::FIELD<double>*f=_mesh->getArea( myCppSupport);
852 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
853 return medf->_this();
855 catch (MEDEXCEPTION &ex)
857 MESSAGE("Unable to get the area ");
858 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
861 //=============================================================================
865 //=============================================================================
866 SALOME_MED::FIELD_ptr GMESH_i::getLength(SALOME_MED::SUPPORT_ptr mySupport)
867 throw (SALOME::SALOME_Exception)
870 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
871 SALOME::INTERNAL_ERROR);
874 int sup = mySupport->getCorbaIndex();
875 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
876 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
877 ::FIELD<double>*f=_mesh->getLength( myCppSupport);
878 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
879 return medf->_this();
881 catch (MEDEXCEPTION &ex)
883 MESSAGE("Unable to get the length ");
884 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
887 //=============================================================================
891 //=============================================================================
892 SALOME_MED::FIELD_ptr GMESH_i::getNormal(SALOME_MED::SUPPORT_ptr mySupport)
893 throw (SALOME::SALOME_Exception)
896 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
897 SALOME::INTERNAL_ERROR);
900 int sup = mySupport->getCorbaIndex();
901 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
902 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
903 ::FIELD<double>*f=_mesh->getNormal( myCppSupport);
904 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
905 return medf->_this();
907 catch (MEDEXCEPTION &ex)
909 MESSAGE("Unable to get the normal ");
910 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
913 //=============================================================================
917 //=============================================================================
918 SALOME_MED::FIELD_ptr GMESH_i::getBarycenter(SALOME_MED::SUPPORT_ptr mySupport)
919 throw (SALOME::SALOME_Exception)
922 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
923 SALOME::INTERNAL_ERROR);
926 int sup = mySupport->getCorbaIndex();
927 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
928 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
929 ::FIELD<double>*f=_mesh->getBarycenter( myCppSupport);
930 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
931 return medf->_this();
933 catch (MEDEXCEPTION &ex)
935 MESSAGE("Unable to get the barycenter ");
936 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
939 //=============================================================================
943 //=============================================================================
944 SALOME_MED::FIELD_ptr GMESH_i::getNeighbourhood(SALOME_MED::SUPPORT_ptr mySupport)
945 throw (SALOME::SALOME_Exception)
948 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
949 SALOME::INTERNAL_ERROR);
950 MESSAGE("Not Implemented");
951 return SALOME_MED::FIELD::_nil();
953 //=============================================================================
955 * CORBA: add the Mesh in the StudyManager
957 //=============================================================================
958 void GMESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::GMESH_ptr myIor )
959 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
963 MESSAGE("Mesh already in Study");
964 THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
968 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
969 SALOMEDS::GenericAttribute_var anAttr;
970 SALOMEDS::AttributeName_var aName;
971 SALOMEDS::AttributeIOR_var aIOR;
973 // Find SComponent labelled 'MED'
974 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
975 myBuilder->NewCommand();
976 if ( CORBA::is_nil(medfather) )
977 THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
979 // Create SObject labelled 'MESH' if it doesn't already exit
980 // SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
981 // if ( CORBA::is_nil(medmeshfather) )
983 // MESSAGE("Add Object MEDMESH");
984 // medmeshfather = myBuilder->NewObject(medfather);
985 // //medmeshfather.Name = "MEDMESH" ;
986 // anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
987 // aName = SALOMEDS::AttributeName::_narrow(anAttr);
988 // aName->SetValue("MEDMESH");
992 string aPath = "/Med/MEDMESH";
993 SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
994 if ( CORBA::is_nil(medmeshfather) )
996 MESSAGE("Add Object MEDMESH");
998 myBuilder->AddDirectory( aPath.c_str() );
999 medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
1002 aPath += "/" + _mesh->getName();
1003 SALOMEDS::SObject_var meshSO = myStudy->FindObjectByPath( aPath.c_str());
1004 bool alreadyPublished = ! CORBA::is_nil( meshSO );
1005 if ( !alreadyPublished ) {
1006 MESSAGE("Add a mesh Object under MED/MEDMESH");
1007 meshSO = myBuilder->NewObject(medmeshfather);
1009 anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeName");
1010 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1011 aName->SetValue(_mesh->getName().c_str());
1014 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1015 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1016 CORBA::ORB_var &orb = init(0,0);
1017 string iorStr = orb->object_to_string(myIor);
1018 anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeIOR");
1019 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1020 aIOR->SetValue(iorStr.c_str());
1021 _meshId = meshSO->GetID();
1022 myBuilder->CommitCommand();
1024 // register the Corba pointer: increase the referrence count
1025 MESSAGE("Registering of the Corba Mesh pointer");
1029 //=============================================================================
1031 * CORBA: add the Mesh in the StudyManager
1033 //=============================================================================
1034 void GMESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::GMESH_ptr myIor,const string & fileName )
1035 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1037 if ( _meshId != "" )
1039 MESSAGE("Mesh already in Study");
1040 THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1044 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
1045 SALOMEDS::GenericAttribute_var anAttr;
1046 SALOMEDS::AttributeName_var aName;
1047 SALOMEDS::AttributeIOR_var aIOR;
1048 SALOMEDS::AttributeComment_var aComment;
1050 // Find SComponent labelled 'Med'
1051 SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1052 if ( CORBA::is_nil(medfather) )
1053 THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1055 // Create SObject labelled 'MESH' if it doesn't already exit
1056 SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1057 if ( CORBA::is_nil(medmeshfather) )
1059 MESSAGE("Add Object MEDMESH");
1060 medmeshfather = myBuilder->NewObject(medfather);
1061 //medmeshfather.Name = "MEDMESH" ;
1062 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1063 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1064 aName->SetValue("MEDMESH");
1068 MESSAGE("Add a mesh Object under MED/MEDMESH");
1069 myBuilder->NewCommand();
1070 SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
1072 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1073 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1074 CORBA::ORB_var &orb = init(0,0);
1075 CORBA::String_var iorStr = orb->object_to_string(myIor);
1076 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1077 aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1078 aIOR->SetValue(iorStr.in());
1079 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1080 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1081 aName->SetValue(_mesh->getName().c_str());
1082 anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
1083 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
1084 aComment->SetValue(fileName.c_str());
1085 _meshId = newObj->GetID();
1086 myBuilder->CommitCommand();
1088 // register the Corba pointer: increase the referrence count
1089 MESSAGE("Registering of the Corba Mesh pointer");
1093 //=============================================================================
1095 //=============================================================================
1097 * CORBA: write mesh in a med file
1099 //=============================================================================
1100 void GMESH_i::write(CORBA::Long i, const char* driverMeshName)
1101 throw (SALOME::SALOME_Exception)
1104 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1105 SALOME::INTERNAL_ERROR);
1110 catch (MEDEXCEPTION &ex)
1112 MESSAGE("Unable to write the mesh ");
1113 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1116 //=============================================================================
1118 * CORBA: read mesh in a med file
1120 //=============================================================================
1121 void GMESH_i::read(CORBA::Long i)
1122 throw (SALOME::SALOME_Exception)
1125 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1126 SALOME::INTERNAL_ERROR);
1131 catch (MEDEXCEPTION &ex)
1133 MESSAGE("Unable to read the mesh ");
1134 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1137 //=============================================================================
1139 * CORBA : release driver
1141 //=============================================================================
1142 void GMESH_i::rmDriver(CORBA::Long i)
1143 throw (SALOME::SALOME_Exception)
1146 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1147 SALOME::INTERNAL_ERROR);
1152 catch (MEDEXCEPTION &ex)
1154 MESSAGE("Unable to unlink the mesh from the driver ");
1155 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1156 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
1157 ,SALOME::INTERNAL_ERROR);
1160 //=============================================================================
1162 * CORBA : attach driver
1164 //=============================================================================
1165 CORBA::Long GMESH_i::addDriver(SALOME_MED::medDriverTypes driverType,
1166 const char* fileName, const char* meshName)
1167 throw (SALOME::SALOME_Exception)
1170 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1171 SALOME::INTERNAL_ERROR);
1174 int drivernum=_mesh->addDriver(
1175 convertIdlDriverToMedDriver(driverType),
1180 catch (MEDEXCEPTION &ex)
1182 MESSAGE("Unable to link the mesh to the driver ");
1183 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1187 //=============================================================================
1189 * CORBA : Test if this and other aggregate the same MESH using the MESH::operator==
1191 //=============================================================================
1192 CORBA::Boolean GMESH_i::areEquals(SALOME_MED::GMESH_ptr other)
1194 PortableServer::ServantBase *baseServ;
1196 baseServ=_default_POA()->reference_to_servant(other);
1203 baseServ->_remove_ref();
1204 GMESH_i *otherServ=dynamic_cast<GMESH_i *>(baseServ);
1205 return *_mesh==*otherServ->_mesh;
1210 //================================================================================
1212 * \brief Converts this GMESH into MESH
1214 //================================================================================
1216 SALOME_MED::MESH_ptr GMESH_i::convertInMESH() throw (SALOME::SALOME_Exception)
1219 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",SALOME::INTERNAL_ERROR);
1221 const MESH* mesh = _mesh->convertInMESH();
1222 MESH_i* mesh_i = new MESH_i( const_cast< MESH*> ( mesh ));
1223 return mesh_i->_this();