Salome HOME
Overload of MEDLoader.ReadField method to ease access of medcoupling for new comers
[tools/medcoupling.git] / src / MEDLoader / MEDFileStructureElement.cxx
index 4ef945d155ea954eef73fff399af99df15a3483d..0eb37f489f64d47061cf6ae2bec34fcfa2494c1c 100644 (file)
@@ -34,6 +34,11 @@ std::string MEDFileSEHolder::getModelName() const
   return _father->getName();
 }
 
+std::string MEDFileSEHolder::getName() const
+{
+  return _name;
+}
+
 void MEDFileSEHolder::setName(const std::string& name)
 {
   _name=name;
@@ -90,7 +95,6 @@ MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *fathe
     }
   if(constatttype==MED_ATT_NAME)
     pflSz++;
-  std::cerr << "******* " << pflSz << std::endl;
   _val->alloc(pflSz,nbCompo);
   MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer()));
   if(constatttype==MED_ATT_NAME)
@@ -179,6 +183,7 @@ MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const ME
   _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE);
   _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE);
   _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType);
+  _tof=MEDFileMesh::ConvertFromMEDFileEntity(entiyType);
   _cst_att.resize(nConsAttr);
   for(int i=0;i<nConsAttr;i++)
     _cst_att[i]=MEDFileSEConstAtt::New(fid,this,i,ms->getSupMeshWithName(_sup_mesh_name));
@@ -251,8 +256,48 @@ int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbComp
     }
 }
 
+int MEDFileStructureElement::getDynGT() const
+{
+  return _id_type;
+}
+
+TypeOfField MEDFileStructureElement::getEntity() const
+{
+  return _tof;
+}
+
+std::string MEDFileStructureElement::getMeshName() const
+{
+  return _sup_mesh_name;
+}
+
+std::vector<std::string> MEDFileStructureElement::getVarAtts() const
+{
+  std::vector<std::string> ret;
+  for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
+    if((*it).isNotNull())
+      ret.push_back((*it)->getName());
+  return ret;
+}
+
+const MEDFileSEVarAtt *MEDFileStructureElement::getVarAtt(const std::string& varName) const
+{
+  for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
+    if((*it).isNotNull())
+      if((*it)->getName()==varName)
+        return *it;
+  std::ostringstream oss; oss << "MEDFileStructureElement::getVarAtt : no var att with name \"" << varName << "\" !";
+  throw INTERP_KERNEL::Exception(oss.str());
+}
+
 ////////////////////
 
+MEDFileStructureElements *MEDFileStructureElements::New(const std::string& fileName, const MEDFileMeshSupports *ms)
+{
+  MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+  return New(fid,ms);
+}
+
 MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms)
 {
   return new MEDFileStructureElements(fid,ms);
@@ -286,6 +331,7 @@ MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMes
   _elems.resize(nbSE);
   for(int i=0;i<nbSE;i++)
     _elems[i]=MEDFileStructureElement::New(fid,i,ms);
+  _sup.takeRef(ms);
 }
 
 MEDFileStructureElements::MEDFileStructureElements()
@@ -296,3 +342,69 @@ MEDFileStructureElements::~MEDFileStructureElements()
 {
 }
 
+int MEDFileStructureElements::getNumberOf() const
+{
+  return _elems.size();
+}
+
+std::vector<int> MEDFileStructureElements::getDynGTAvail() const
+{
+  std::vector<int> ret;
+  for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
+    {
+      const MEDFileStructureElement *elt(*it);
+      if(elt)
+        ret.push_back(elt->getDynGT());
+    }
+  return ret;
+}
+
+const MEDFileStructureElement *MEDFileStructureElements::getWithGT(int idGT) const
+{
+  for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
+    if((*it).isNotNull())
+      {
+        if((*it)->getDynGT()==idGT)
+          return *it;
+      }
+  std::ostringstream oss; oss << "MEDFileStructureElements::getWithGT : no such geo type " << idGT << " !";
+  throw INTERP_KERNEL::Exception(oss.str());
+}
+
+int MEDFileStructureElements::getNumberOfNodesPerSE(const std::string& seName) const
+{
+  if(seName=="MED_PARTICLE")
+    return 1;
+  const MEDFileStructureElement *se(getSEWithName(seName));
+  std::string meshName(se->getMeshName());
+  return _sup->getNumberOfNodesInConnOf(se->getEntity(),meshName);
+}
+
+const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const
+{
+  for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
+    {
+      if((*it).isNotNull())
+        if((*it)->getName()==seName)
+          return *it;
+    }
+  std::ostringstream oss; oss << "MEDFileStructureElements::getSEWithName : no such structure element with name " << seName << " !";
+  throw INTERP_KERNEL::Exception(oss.str());
+}
+
+std::vector<std::string> MEDFileStructureElements::getVarAttsOf(const std::string& seName) const
+{
+  const MEDFileStructureElement *se(getSEWithName(seName));
+  return se->getVarAtts();
+}
+
+const MEDFileSEVarAtt *MEDFileStructureElements::getVarAttOf(const std::string &seName, const std::string& varName) const
+{
+  const MEDFileStructureElement *se(getSEWithName(seName));
+  return se->getVarAtt(varName);
+}
+
+const MEDFileUMesh *MEDFileStructureElements::getSupMeshWithName(const std::string& name) const
+{
+  return _sup->getSupMeshWithName(name);
+}