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 #include "GMESHClient.hxx"
24 #include "MEDMEM_convert.hxx"
25 #include "UtilClient.hxx"
26 #include "COORDINATEClient.hxx"
27 #include "CONNECTIVITYClient.hxx"
28 #include "FAMILYClient.hxx"
29 #include "GROUPClient.hxx"
30 #include "MESHClient.hxx"
31 #include "Utils_CorbaException.hxx"
33 using namespace MEDMEM;
34 using namespace MED_EN;
36 //=============================================================================
40 //=============================================================================
42 GMESHClient::GMESHClient(const SALOME_MED::GMESH_ptr m) :
43 GMESH(), //_refCounter(1),
44 IOR_Mesh(SALOME_MED::GMESH::_duplicate(m)),
45 _complete(false), _uMesh(0)
52 //=============================================================================
54 * Transforme un IOR Famille en Famille Client
56 //=============================================================================
58 FAMILY * convertFamily(const SALOME_MED::FAMILY_ptr &F, GMESH *M)
60 return new FAMILYClient(F, M);
62 //=============================================================================
64 * Transforme un IOR groupe en groupe Client
66 //=============================================================================
67 GROUP * convertGroup(const SALOME_MED::GROUP_ptr &F, GMESH *M)
69 return new GROUPClient(F, M);
72 //=============================================================================
74 * Remplit les informations générales
76 //=============================================================================
77 void GMESHClient::blankCopy()
79 SALOME_MED::GMESH::meshInfos_var all = IOR_Mesh->getMeshGlobal();
82 _spaceDimension = all->spaceDimension;
84 convertCorbaArray<SALOME_MED::FAMILY_ptr>
86 //IOR_Mesh->getFamilies(MED_NODE),
88 (void *) (convertFamily), this);
90 convertCorbaArray<SALOME_MED::FAMILY_ptr>
92 //IOR_Mesh->getFamilies(MED_EDGE),
94 (void *) (convertFamily), this);
96 convertCorbaArray<SALOME_MED::FAMILY_ptr>
98 //IOR_Mesh->getFamilies(MED_FACE),
100 (void *) (convertFamily), this);
102 convertCorbaArray<SALOME_MED::FAMILY_ptr>
104 //IOR_Mesh->getFamilies(MED_CELL),
106 (void *) (convertFamily), this);
108 convertCorbaArray<SALOME_MED::GROUP_ptr>
110 //IOR_Mesh->getGroups(MED_NODE),
112 (void *) (convertGroup), this);
114 convertCorbaArray<SALOME_MED::GROUP_ptr>
116 //IOR_Mesh->getGroups(MED_EDGE),
118 (void *) (convertGroup), this);
120 convertCorbaArray<SALOME_MED::GROUP_ptr>
122 //IOR_Mesh->getGroups(MED_FACE),
124 (void *) (convertGroup), this);
126 convertCorbaArray<SALOME_MED::GROUP_ptr>
128 //IOR_Mesh->getGroups(MED_CELL),
130 (void *) (convertGroup), this);
132 if ( !IOR_Mesh->getIsAGrid() && !dynamic_cast<MESHClient*>(this))
134 SALOME_MED::MESH_var umeshIOR = IOR_Mesh->convertInMESH();
135 _uMesh = new MESHClient( umeshIOR );
140 //=============================================================================
142 * Remplit les informations sur les coordonnees et la connectivite
144 //=============================================================================
146 void GMESHClient::fillCopy()
148 int size = _familyNode.size();
150 for (int i = 0; i < size; i++)
152 FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyNode[i]);
158 size = _familyCell.size();
160 for (int i = 0; i < size; i++)
162 FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyCell[i]);
168 size = _familyFace.size();
170 for (int i = 0; i < size; i++)
172 FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyFace[i]);
178 size = _familyEdge.size();
180 for (int i = 0; i < size; i++)
182 FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyEdge[i]);
191 THROW_SALOME_CORBA_EXCEPTION("GRID client does not exists",SALOME::INTERNAL_ERROR);
196 //=============================================================================
198 * Test equality between 2 GMESHClients.
200 //=============================================================================
201 bool GMESHClient::operator==(const GMESH& other) const
203 const GMESHClient* otherClt=dynamic_cast<const GMESHClient *>(&other);
210 return IOR_Mesh->areEquals(otherClt->IOR_Mesh);
215 //=============================================================================
219 //=============================================================================
221 GMESHClient::~GMESHClient()
224 _uMesh->removeReference();
225 IOR_Mesh->UnRegister();
228 //=============================================================================
230 * Write all the content of the GMESH using driver referenced by the integer handler index
232 //=============================================================================
234 void GMESHClient::write(int index/*=0*/) const
236 if ( index < 0 || index >= (int)_drivers.size() || !_drivers[index] )
237 throw MED_EXCEPTION ( LOCALIZED( STRING("GMESHClient::write(int index): ")
238 << "The index given is invalid, index must be between 0 and |"
239 << _drivers.size() ));
241 const_cast<GMESHClient*>(this)->fillCopy();
242 _uMesh->write( *_drivers[index], _drivers[index]->getAccessMode() );
245 //=============================================================================
247 * Write all the content of the GMESH using genDriver
249 //=============================================================================
251 void GMESHClient::write(const GENDRIVER & genDriver,
252 MED_EN::med_mode_acces medMode) const
254 const_cast<GMESHClient*>(this)->fillCopy();
255 _uMesh->write(genDriver,medMode);
258 //=============================================================================
260 * Write all the content of the GMESH
262 //=============================================================================
264 void GMESHClient::write(driverTypes driverType,
265 const std::string& filename,
266 const std::string& meshname,
267 MED_EN::med_mode_acces medMode) const
269 const_cast<GMESHClient*>(this)->fillCopy();
270 _uMesh->write(driverType, filename,meshname,medMode);
273 //================================================================================
275 * \brief fillCopy() and then print myself to a stream
277 //================================================================================
279 void GMESHClient::printMySelf(ostream &os) const
281 GMESHClient* that = (GMESHClient*)this;
284 _uMesh->printMySelf( os );
286 os << "GMESHClient " << (void*) this;
289 bool GMESHClient::isEmpty() const
291 return _uMesh ? _uMesh->isEmpty() : (IOR_Mesh->getNumberOfNodes() < 1);
294 bool GMESHClient::deepCompare(const GMESH& other) const
296 if ( getIsAGrid() != other.getIsAGrid() ||
297 getIsAGrid()) // no client nor server for GRID -> can't compare
300 return _uMesh ? _uMesh->deepCompare( other ) : false;
303 int GMESHClient::getMeshDimension() const
305 return IOR_Mesh->getMeshDimension();
308 bool GMESHClient::getIsAGrid() const
310 return IOR_Mesh->getIsAGrid();
313 std::string GMESHClient::getCoordinatesSystem() const
315 CORBA::String_var s = IOR_Mesh->getCoordinatesSystem();
319 const std::string* GMESHClient::getCoordinatesNames() const
321 return _uMesh ? _uMesh->getCoordinatesNames() : (std::string*) 0;
324 const std::string* GMESHClient::getCoordinatesUnits() const
326 return _uMesh ? _uMesh->getCoordinatesUnits() : (std::string*) 0;
329 int GMESHClient::getNumberOfNodes() const
331 return IOR_Mesh->getNumberOfNodes();
334 int GMESHClient::getNumberOfTypes(MED_EN::medEntityMesh entity) const
336 return IOR_Mesh->getNumberOfTypes(entity);
339 int GMESHClient::getNumberOfElements(MED_EN::medEntityMesh entity,
340 MED_EN::medGeometryElement type) const
342 return IOR_Mesh->getNumberOfElements(entity,type);
345 const MED_EN::medGeometryElement* GMESHClient::getTypes(MED_EN::medEntityMesh entity) const
347 return _uMesh ? _uMesh->getTypes(entity) : (MED_EN::medGeometryElement*) 0;
350 MED_EN::medGeometryElement GMESHClient::getElementType(MED_EN::medEntityMesh entity,
353 return IOR_Mesh->getElementType(entity,i);
356 const MESH* GMESHClient::convertInMESH() const
360 SALOME_MED::MESH_var umeshIOR = IOR_Mesh->convertInMESH();
361 const_cast<GMESHClient*>(this)->_uMesh = new MESHClient( umeshIOR );
363 _uMesh->addReference();
367 SUPPORT* GMESHClient::getBoundaryElements(MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION)
369 SALOME_MED::SUPPORT_var s = IOR_Mesh->getBoundaryElements(entity);
370 return new SUPPORTClient( s );
373 SUPPORT* GMESHClient::getSkin(const SUPPORT* sup) throw (MEDEXCEPTION)
375 return _uMesh ? _uMesh->getSkin( sup ) : (SUPPORT*)0;
378 SUPPORT* GMESHClient::buildSupportOnNodeFromElementList(const std::list<int>& elems,
379 MED_EN::medEntityMesh entity) const
382 return _uMesh ? _uMesh->buildSupportOnNodeFromElementList(elems,entity ) : (SUPPORT*)0;
385 void GMESHClient::fillSupportOnNodeFromElementList(const std::list<int>& elems,
389 if ( _uMesh ) _uMesh->fillSupportOnNodeFromElementList(elems,sup);
392 FIELD<double>* GMESHClient::getVolume(const SUPPORT* sup , bool isAbs) const
395 FIELD<double>* f = (FIELD<double>*) 0;
398 sup->setMesh( _uMesh );
399 f = _uMesh->getVolume(sup,isAbs);
400 sup->setMesh( this );
405 FIELD<double>* GMESHClient::getArea(const SUPPORT* sup) const throw (MEDEXCEPTION)
407 FIELD<double>* f = (FIELD<double>*) 0;
410 sup->setMesh( _uMesh );
411 f = _uMesh->getArea(sup);
412 sup->setMesh( this );
417 FIELD<double>* GMESHClient::getLength(const SUPPORT* sup) const throw (MEDEXCEPTION)
419 FIELD<double>* f = (FIELD<double>*) 0;
422 sup->setMesh( _uMesh );
423 f = _uMesh->getLength(sup);
424 sup->setMesh( this );
429 FIELD<double>* GMESHClient::getNormal(const SUPPORT* sup) const throw (MEDEXCEPTION)
431 FIELD<double>* f = (FIELD<double>*) 0;
434 sup->setMesh( _uMesh );
435 f = _uMesh->getNormal(sup);
436 sup->setMesh( this );
441 FIELD<double>* GMESHClient::getBarycenter(const SUPPORT* sup) const throw (MEDEXCEPTION)
443 FIELD<double>* f = (FIELD<double>*) 0;
446 sup->setMesh( _uMesh );
447 f = _uMesh->getBarycenter(sup);
448 sup->setMesh( this );
453 std::vector<std::vector<double> > GMESHClient::getBoundingBox() const
455 std::vector<std::vector<double> > bb;
457 bb = _uMesh->getBoundingBox();