Back to index

salome-med  6.5.0
GMESHClient.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "GMESHClient.hxx"
00024 #include "MEDMEM_convert.hxx"
00025 #include "UtilClient.hxx"
00026 #include "COORDINATEClient.hxx"
00027 #include "CONNECTIVITYClient.hxx"
00028 #include "FAMILYClient.hxx"
00029 #include "GROUPClient.hxx"
00030 #include "MESHClient.hxx"
00031 #include "Utils_CorbaException.hxx"
00032 
00033 using namespace MEDMEM;
00034 using namespace MED_EN;
00035 
00036 //=============================================================================
00040 //=============================================================================
00041 
00042 GMESHClient::GMESHClient(const SALOME_MED::GMESH_ptr m) : 
00043   GMESH(), //_refCounter(1),
00044   IOR_Mesh(SALOME_MED::GMESH::_duplicate(m)),
00045   _complete(false), _uMesh(0)
00046 
00047 {
00048   ASSERT(m);
00049 
00050   blankCopy();
00051 }
00052 //=============================================================================
00056 //=============================================================================
00057 
00058 FAMILY * convertFamily(const SALOME_MED::FAMILY_ptr &F, GMESH *M) 
00059 {
00060   return new FAMILYClient(F, M);
00061 }
00062 //=============================================================================
00066 //=============================================================================
00067 GROUP * convertGroup(const SALOME_MED::GROUP_ptr &F, GMESH *M) 
00068 {
00069   return new GROUPClient(F, M);
00070 }
00071 
00072 //=============================================================================
00076 //=============================================================================
00077 void GMESHClient::blankCopy()
00078 {
00079   SALOME_MED::GMESH::meshInfos_var all = IOR_Mesh->getMeshGlobal();
00080 
00081   _name           = all->name;
00082   _spaceDimension = all->spaceDimension;
00083 
00084   convertCorbaArray<SALOME_MED::FAMILY_ptr>
00085     (_familyNode, 
00086      //IOR_Mesh->getFamilies(MED_NODE),
00087      &all->famNode,
00088      (void *) (convertFamily), this);
00089  
00090   convertCorbaArray<SALOME_MED::FAMILY_ptr>
00091     (_familyEdge, 
00092      //IOR_Mesh->getFamilies(MED_EDGE),
00093      &all->famEdge,
00094      (void *) (convertFamily), this);
00095  
00096   convertCorbaArray<SALOME_MED::FAMILY_ptr>
00097     (_familyFace, 
00098      //IOR_Mesh->getFamilies(MED_FACE),
00099      &all->famFace,
00100      (void *) (convertFamily), this);
00101  
00102   convertCorbaArray<SALOME_MED::FAMILY_ptr>
00103     (_familyCell, 
00104      //IOR_Mesh->getFamilies(MED_CELL),
00105      &all->famCell,
00106      (void *) (convertFamily), this);
00107  
00108   convertCorbaArray<SALOME_MED::GROUP_ptr>
00109     (_groupNode, 
00110      //IOR_Mesh->getGroups(MED_NODE),
00111      &all->groupNode,
00112      (void *) (convertGroup), this);
00113  
00114   convertCorbaArray<SALOME_MED::GROUP_ptr>
00115     (_groupEdge, 
00116      //IOR_Mesh->getGroups(MED_EDGE),
00117      &all->groupEdge,
00118      (void *) (convertGroup), this);
00119  
00120   convertCorbaArray<SALOME_MED::GROUP_ptr>
00121     (_groupFace, 
00122      //IOR_Mesh->getGroups(MED_FACE),
00123      &all->groupFace,
00124      (void *) (convertGroup), this);
00125  
00126   convertCorbaArray<SALOME_MED::GROUP_ptr>
00127     (_groupCell, 
00128      //IOR_Mesh->getGroups(MED_CELL),
00129      &all->groupCell,
00130      (void *) (convertGroup), this);
00131 
00132   if ( !IOR_Mesh->getIsAGrid() && !dynamic_cast<MESHClient*>(this))
00133   {
00134     SALOME_MED::MESH_var umeshIOR = IOR_Mesh->convertInMESH();
00135     _uMesh = new MESHClient( umeshIOR );
00136   }
00137 
00138   _complete = false;
00139 }
00140 //=============================================================================
00144 //=============================================================================
00145 
00146 void GMESHClient::fillCopy()
00147 {
00148   int size = _familyNode.size();
00149 
00150   for (int i = 0; i < size; i++)
00151     {
00152       FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyNode[i]);
00153       ASSERT(_fam);
00154 
00155       _fam->fillCopy();
00156     }
00157 
00158   size = _familyCell.size();
00159 
00160   for (int i = 0; i < size; i++)
00161     {
00162       FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyCell[i]);
00163       ASSERT(_fam);
00164 
00165       _fam->fillCopy();
00166     }
00167 
00168   size = _familyFace.size();
00169 
00170   for (int i = 0; i < size; i++)
00171     {
00172       FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyFace[i]);
00173       ASSERT(_fam);
00174 
00175       _fam->fillCopy();
00176     }
00177 
00178   size = _familyEdge.size();
00179 
00180   for (int i = 0; i < size; i++)
00181     {
00182       FAMILYClient * _fam = dynamic_cast<FAMILYClient *> (_familyEdge[i]);
00183       ASSERT(_fam);
00184 
00185       _fam->fillCopy();
00186     }
00187 
00188   if ( _uMesh )
00189     _uMesh->fillCopy();
00190   else
00191     THROW_SALOME_CORBA_EXCEPTION("GRID client does not exists",SALOME::INTERNAL_ERROR);
00192 
00193   _complete = true;
00194 }
00195 
00196 //=============================================================================
00200 //=============================================================================
00201 bool GMESHClient::operator==(const GMESH& other) const
00202 {
00203   const GMESHClient* otherClt=dynamic_cast<const GMESHClient *>(&other);
00204   if(otherClt)
00205     {
00206       if(this==otherClt)
00207         {
00208           return true;
00209         }
00210       return IOR_Mesh->areEquals(otherClt->IOR_Mesh);
00211     }
00212   return false;
00213 }
00214 
00215 //=============================================================================
00219 //=============================================================================
00220 
00221 GMESHClient::~GMESHClient()
00222 {
00223   if ( _uMesh )
00224     _uMesh->removeReference();
00225   IOR_Mesh->UnRegister();
00226 }
00227 
00228 //=============================================================================
00232 //=============================================================================
00233 
00234 void GMESHClient::write(int index/*=0*/) const
00235 {
00236   if ( index < 0 || index >= (int)_drivers.size() || !_drivers[index] )
00237     throw MED_EXCEPTION ( LOCALIZED( STRING("GMESHClient::write(int index): ")
00238                                      << "The index given is invalid, index must be between  0 and |"
00239                                      << _drivers.size() ));
00240 
00241   const_cast<GMESHClient*>(this)->fillCopy();
00242   _uMesh->write( *_drivers[index], _drivers[index]->getAccessMode() );
00243 }
00244 
00245 //=============================================================================
00249 //=============================================================================
00250 
00251 void GMESHClient::write(const GENDRIVER &      genDriver,
00252                         MED_EN::med_mode_acces medMode) const
00253 {
00254   const_cast<GMESHClient*>(this)->fillCopy();
00255   _uMesh->write(genDriver,medMode);
00256 }
00257 
00258 //=============================================================================
00262 //=============================================================================
00263 
00264 void GMESHClient::write(driverTypes        driverType,
00265                         const std::string& filename,
00266                         const std::string& meshname,
00267                         MED_EN::med_mode_acces medMode) const
00268 {
00269   const_cast<GMESHClient*>(this)->fillCopy();
00270   _uMesh->write(driverType, filename,meshname,medMode);
00271 }
00272 
00273 //================================================================================
00277 //================================================================================
00278 
00279 void GMESHClient::printMySelf(ostream &os) const
00280 {
00281   GMESHClient* that = (GMESHClient*)this;
00282   that->fillCopy();
00283   if ( _uMesh )
00284     _uMesh->printMySelf( os );
00285   else
00286     os << "GMESHClient " << (void*) this;
00287 }
00288 
00289 bool GMESHClient::isEmpty() const
00290 {
00291   return _uMesh ? _uMesh->isEmpty() : (IOR_Mesh->getNumberOfNodes() < 1);
00292 }
00293 
00294 bool GMESHClient::deepCompare(const GMESH& other) const
00295 {
00296   if ( getIsAGrid() != other.getIsAGrid() ||
00297        getIsAGrid()) // no client nor server for GRID -> can't compare
00298     return false;
00299 
00300   return _uMesh ? _uMesh->deepCompare( other ) : false;
00301 }
00302 
00303 int GMESHClient::getMeshDimension() const
00304 {
00305   return IOR_Mesh->getMeshDimension();
00306 }
00307 
00308 bool GMESHClient::getIsAGrid() const
00309 {
00310   return IOR_Mesh->getIsAGrid();
00311 }
00312 
00313 std::string GMESHClient::getCoordinatesSystem() const
00314 {
00315   CORBA::String_var s = IOR_Mesh->getCoordinatesSystem();
00316   return s._retn();
00317 }
00318 
00319 const std::string* GMESHClient::getCoordinatesNames() const
00320 {
00321   return _uMesh ? _uMesh->getCoordinatesNames() : (std::string*) 0;
00322 }
00323 
00324 const std::string* GMESHClient::getCoordinatesUnits() const
00325 {
00326   return _uMesh ? _uMesh->getCoordinatesUnits() : (std::string*) 0;
00327 }
00328 
00329 int GMESHClient::getNumberOfNodes() const
00330 {
00331   return IOR_Mesh->getNumberOfNodes();
00332 }
00333 
00334 int GMESHClient::getNumberOfTypes(MED_EN::medEntityMesh entity) const
00335 {
00336   return IOR_Mesh->getNumberOfTypes(entity);
00337 }
00338 
00339 int GMESHClient::getNumberOfElements(MED_EN::medEntityMesh entity,
00340                                      MED_EN::medGeometryElement type) const
00341 {
00342   return IOR_Mesh->getNumberOfElements(entity,type);
00343 }
00344 
00345 const MED_EN::medGeometryElement* GMESHClient::getTypes(MED_EN::medEntityMesh entity) const
00346 {
00347   return _uMesh ? _uMesh->getTypes(entity) : (MED_EN::medGeometryElement*) 0;
00348 }
00349 
00350 MED_EN::medGeometryElement GMESHClient::getElementType(MED_EN::medEntityMesh entity,
00351                                                        int i) const
00352 {
00353   return IOR_Mesh->getElementType(entity,i);
00354 }
00355 
00356 const MESH* GMESHClient::convertInMESH() const
00357 {
00358   if ( !_uMesh )
00359   {
00360     SALOME_MED::MESH_var umeshIOR = IOR_Mesh->convertInMESH();
00361     const_cast<GMESHClient*>(this)->_uMesh = new MESHClient( umeshIOR );
00362   }
00363   _uMesh->addReference();
00364   return _uMesh;
00365 }
00366 
00367 SUPPORT* GMESHClient::getBoundaryElements(MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION)
00368 {
00369   SALOME_MED::SUPPORT_var s = IOR_Mesh->getBoundaryElements(entity);
00370   return new SUPPORTClient( s );
00371 }
00372 
00373 SUPPORT* GMESHClient::getSkin(const SUPPORT* sup) throw (MEDEXCEPTION)
00374 {
00375   return _uMesh ? _uMesh->getSkin( sup ) : (SUPPORT*)0;
00376 }
00377 
00378 SUPPORT* GMESHClient::buildSupportOnNodeFromElementList(const std::list<int>& elems,
00379                                                         MED_EN::medEntityMesh entity) const
00380    throw (MEDEXCEPTION)
00381 {
00382   return _uMesh ? _uMesh->buildSupportOnNodeFromElementList(elems,entity ) : (SUPPORT*)0;
00383 }
00384 
00385 void GMESHClient::fillSupportOnNodeFromElementList(const std::list<int>& elems,
00386                                                    SUPPORT* sup) const
00387    throw (MEDEXCEPTION)
00388 {
00389   if ( _uMesh ) _uMesh->fillSupportOnNodeFromElementList(elems,sup);
00390 }
00391 
00392 FIELD<double>* GMESHClient::getVolume(const SUPPORT* sup , bool isAbs) const
00393   throw (MEDEXCEPTION)
00394 {
00395   FIELD<double>* f = (FIELD<double>*) 0;
00396   if ( _uMesh && sup )
00397   {
00398     sup->setMesh( _uMesh );
00399     f = _uMesh->getVolume(sup,isAbs);
00400     sup->setMesh( this );
00401   }
00402   return f;
00403 }
00404 
00405 FIELD<double>* GMESHClient::getArea(const SUPPORT* sup) const throw (MEDEXCEPTION)
00406 {
00407   FIELD<double>* f = (FIELD<double>*) 0;
00408   if ( _uMesh && sup )
00409   {
00410     sup->setMesh( _uMesh );
00411     f = _uMesh->getArea(sup);
00412     sup->setMesh( this );
00413   }
00414   return f;
00415 }
00416 
00417 FIELD<double>* GMESHClient::getLength(const SUPPORT* sup) const throw (MEDEXCEPTION)
00418 {
00419   FIELD<double>* f = (FIELD<double>*) 0;
00420   if ( _uMesh && sup )
00421   {
00422     sup->setMesh( _uMesh );
00423     f = _uMesh->getLength(sup);
00424     sup->setMesh( this );
00425   }
00426   return f;
00427 }
00428 
00429 FIELD<double>* GMESHClient::getNormal(const SUPPORT* sup) const throw (MEDEXCEPTION)
00430 {
00431   FIELD<double>* f = (FIELD<double>*) 0;
00432   if ( _uMesh && sup )
00433   {
00434     sup->setMesh( _uMesh );
00435     f = _uMesh->getNormal(sup);
00436     sup->setMesh( this );
00437   }
00438   return f;
00439 }
00440 
00441 FIELD<double>* GMESHClient::getBarycenter(const SUPPORT* sup) const throw (MEDEXCEPTION)
00442 {
00443   FIELD<double>* f = (FIELD<double>*) 0;
00444   if ( _uMesh && sup )
00445   {
00446     sup->setMesh( _uMesh );
00447     f = _uMesh->getBarycenter(sup);
00448     sup->setMesh( this );
00449   }
00450   return f;
00451 }
00452 
00453 std::vector<std::vector<double> > GMESHClient::getBoundingBox() const
00454 {
00455   std::vector<std::vector<double> > bb;
00456   if ( _uMesh )
00457     bb = _uMesh->getBoundingBox();
00458   return bb;
00459 }
00460