Salome HOME
SWIG exception: removing C++11 warnings, minimal work.
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshSupport.cxx
index d92a46de7a852469f2e5175c9f0e26b8304871c7..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
@@ -19,7 +19,6 @@
 // Author : Anthony Geay (EDF R&D)
 
 #include "MEDFileMeshSupport.hxx"
-
 #include "MEDLoaderBase.hxx"
 #include "MEDFileMeshLL.hxx"
 #include "MEDFileSafeCaller.txx"
 
 using namespace MEDCoupling;
 
-MEDFileMeshSupport *MEDFileMeshSupport::New()
-{
-  return new MEDFileMeshSupport;
-}
-
-MEDFileMeshSupport *MEDFileMeshSupport::New(const std::string& fileName, int smid)
+MEDFileMeshSupports *MEDFileMeshSupports::New(const std::string& fileName)
 {
   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
-  return New(fid,smid);
-}
-
-MEDFileMeshSupport *MEDFileMeshSupport::New(med_idt fid, int smid)
-{
-  return new MEDFileMeshSupport(fid,smid);
-}
-
-std::vector<const BigMemoryObject *> MEDFileMeshSupport::getDirectChildrenWithNull() const
-{
-  return std::vector<const BigMemoryObject *>();
-}
-
-std::size_t MEDFileMeshSupport::getHeapMemorySizeWithoutChildren() const
-{
-  return 0;
-}
-
-int MEDFileMeshSupport::getSpaceDim() const
-{
-  return _space_dim;
-}
-
-void MEDFileMeshSupport::setSpaceDim(int dim)
-{
-  _space_dim=dim;
-}
-
-int MEDFileMeshSupport::getMeshDim() const
-{
-  return _mesh_dim;
-}
-
-void MEDFileMeshSupport::setMeshDim(int dim)
-{
-  _mesh_dim=dim;
-}
-
-void MEDFileMeshSupport::writeLL(med_idt fid) const
-{
-}
-
-MEDFileMeshSupport::MEDFileMeshSupport(med_idt fid, int smid)
-{
-  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,smid+1));
-  INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
-  MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid+1,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit));
-  _name=MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE);
-  _description=MEDLoaderBase::buildStringFromFortran(description,MED_COMMENT_SIZE);
-  _axis_type=MEDFileMeshL2::TraduceAxisType(axType);
-  int nCoords(0),nmodels(0);
-  {
-    med_bool chgt=MED_FALSE,trsf=MED_FALSE;
-    nCoords=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_COORDINATE,MED_NODAL,&chgt,&trsf);
-    nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
-  }
-  _coords=DataArrayDouble::New(); _coords->alloc(nCoords,nAxis);
-  for(int i=0;i<nAxis;i++)
-    {
-      std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
-                                                          MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
-      _coords->setInfoOnComponent(i,info);
-    }
-  MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer()));
-  {
-    med_bool chgt=MED_FALSE,trsf=MED_FALSE;
-    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf)>0)
-      {
-        _fam_coords=DataArrayInt::New();
-        _fam_coords->alloc(nCoords,1);
-        MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
-      }
-    else
-      _fam_coords=0;
-    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&chgt,&trsf)>0)
-      {
-        _num_coords=DataArrayInt::New();
-        _num_coords->alloc(nCoords,1);
-        MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
-      }
-    else
-    _num_coords=0;
-    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&chgt,&trsf)>0)
-      {
-        _name_coords=DataArrayAsciiChar::New();
-        _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
-        MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
-        _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
-      }
-    else
-      _name_coords=0;
-  }
-    //med_bool withnodename;
-  //MEDmeshNodeRd(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer(),);
-  std::cerr << nCoords << " ** " << nmodels << std::endl;
-}
-
-MEDFileMeshSupport::~MEDFileMeshSupport()
-{
-}
-
-MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1),_axis_type(AX_CART)
-{
+  return New(fid);
 }
 
 MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid)
@@ -159,7 +48,17 @@ MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid)
   int nbSM(MEDnSupportMesh(fid));
   _supports.resize(nbSM);
   for(int i=0;i<nbSM;i++)
-    _supports[i]=MEDFileMeshSupport::New(fid,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);
+    }
 }
 
 MEDFileMeshSupports::MEDFileMeshSupports()
@@ -181,12 +80,62 @@ std::vector<const BigMemoryObject *> MEDFileMeshSupports::getDirectChildrenWithN
 
 std::size_t MEDFileMeshSupports::getHeapMemorySizeWithoutChildren() const
 {
-  return _supports.capacity()*sizeof(MCAuto<MEDFileMeshSupport>);
+  return _supports.capacity()*sizeof(MCAuto<MEDFileUMesh>);
 }
 
 void MEDFileMeshSupports::writeLL(med_idt fid) const
 {
-  for(std::vector< MCAuto<MEDFileMeshSupport> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
+  for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
     if((*it).isNotNull())
       (*it)->writeLL(fid);
 }
+
+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;
+}
+
+const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& name) const
+{
+  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());
+}
+
+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 !");
+    }
+}