Salome HOME
SWIG exception: removing C++11 warnings, minimal work.
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshSupport.cxx
index b7ff2ab561524754a565cfc3959aac5c16e88a92..c1fb5c051c7b8ee8b05625dbf3244940d2d280aa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // Author : Anthony Geay (EDF R&D)
 
 #include "MEDFileMeshSupport.hxx"
-
 #include "MEDLoaderBase.hxx"
+#include "MEDFileMeshLL.hxx"
 #include "MEDFileSafeCaller.txx"
 
 #include "InterpKernelAutoPtr.hxx"
 
 using namespace MEDCoupling;
 
-MEDFileMeshSupport *MEDFileMeshSupport::New()
+MEDFileMeshSupports *MEDFileMeshSupports::New(const std::string& fileName)
 {
-  return new MEDFileMeshSupport;
+  MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+  return New(fid);
 }
 
-MEDFileMeshSupport *MEDFileMeshSupport::New(const std::string& fileName, int smid)
+MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid)
 {
-  MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
-  return New(fid,smid);
+  return new MEDFileMeshSupports(fid);
 }
 
-MEDFileMeshSupport *MEDFileMeshSupport::New(med_idt fid, int smid)
+MEDFileMeshSupports *MEDFileMeshSupports::New()
 {
-  return new MEDFileMeshSupport(fid,smid);
+  return new MEDFileMeshSupports;
 }
 
-std::vector<const BigMemoryObject *> MEDFileMeshSupport::getDirectChildrenWithNull() const
+MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid)
 {
-  return std::vector<const BigMemoryObject *>();
+  int nbSM(MEDnSupportMesh(fid));
+  _supports.resize(nbSM);
+  for(int i=0;i<nbSM;i++)
+    {
+      INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+      INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
+      med_axis_type axType;
+      int nAxis(MEDsupportMeshnAxis(fid,i+1));
+      INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
+      int spaceDim(0),meshDim(0);
+      MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,msn,&spaceDim,&meshDim,description,&axType,axisName,axisUnit));
+      std::string name(MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE));
+      _supports[i]=MEDFileUMesh::New(fid,name);
+    }
 }
 
-std::size_t MEDFileMeshSupport::getHeapMemorySizeWithoutChildren() const
+MEDFileMeshSupports::MEDFileMeshSupports()
 {
-  return 0;
 }
 
-int MEDFileMeshSupport::getSpaceDim() const
+MEDFileMeshSupports::~MEDFileMeshSupports()
 {
-  return _space_dim;
 }
 
-void MEDFileMeshSupport::setSpaceDim(int dim)
+std::vector<const BigMemoryObject *> MEDFileMeshSupports::getDirectChildrenWithNull() const
 {
-  _space_dim=dim;
+  std::size_t sz(_supports.size());
+  std::vector<const BigMemoryObject *> ret(sz);
+  for(std::size_t i=0;i<sz;i++)
+    ret[i]=_supports[i];
+  return ret;
 }
 
-int MEDFileMeshSupport::getMeshDim() const
+std::size_t MEDFileMeshSupports::getHeapMemorySizeWithoutChildren() const
 {
-  return _mesh_dim;
+  return _supports.capacity()*sizeof(MCAuto<MEDFileUMesh>);
 }
 
-void MEDFileMeshSupport::setMeshDim(int dim)
+void MEDFileMeshSupports::writeLL(med_idt fid) const
 {
-  _mesh_dim=dim;
+  for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
+    if((*it).isNotNull())
+      (*it)->writeLL(fid);
 }
 
-void MEDFileMeshSupport::writeLL(med_idt fid) const
+std::vector<std::string> MEDFileMeshSupports::getSupMeshNames() const
 {
+  std::vector<std::string> ret;
+  for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
+    if((*it).isNotNull())
+      ret.push_back((*it)->getName());
+  return ret;
 }
 
-MEDFileMeshSupport::MEDFileMeshSupport(med_idt fid, int smid)
+const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& name) const
 {
-  INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
-  INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
-  med_axis_type axType;
-  int nAxis(MEDsupportMeshnAxis(fid,smid));
-  INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
-  MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit));
+  std::vector<std::string> mns;
+  for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
+    {
+      if((*it).isNotNull())
+        {
+          std::string na((*it)->getName());
+          if(na==name)
+            return *it;
+          else
+            mns.push_back(na);
+        }
+    }
+  std::ostringstream oss;
+  oss << "MEDFileMeshSupports::getSupMeshWithName : no such name \"" << name << "\". Possibilities are :";
+  std::copy(mns.begin(),mns.end(),std::ostream_iterator<std::string>(oss,","));
+  oss << " !";
+  throw INTERP_KERNEL::Exception(oss.str());
 }
 
-MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1)
+int MEDFileMeshSupports::getNumberOfNodesInConnOf(TypeOfField entity, const std::string& name) const
 {
+  const MEDFileUMesh *sup(getSupMeshWithName(name));
+  switch(entity)
+    {
+    case ON_NODES:
+      return sup->getNumberOfNodes();
+    case ON_CELLS:
+      {
+        std::vector<INTERP_KERNEL::NormalizedCellType> gt(sup->getAllGeoTypes());
+        if(gt.size()!=1)
+          throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : on cells only one geometric type allowed !");
+        const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(gt[0]));
+        return sup->getNumberOfCellsAtLevel(0)*cm.getNumberOfNodes();
+      }
+    default:
+      throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : not recognized entity type !");
+    }
 }