From: Anthony Geay Date: Tue, 17 Jan 2017 17:27:25 +0000 (+0100) Subject: Start of mesh support + Header set/get X-Git-Tag: V8_3_0a2~38^2~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4aed19cb3f96f7072311a8006f6a5b3ae9312bc0;p=tools%2Fmedcoupling.git Start of mesh support + Header set/get --- diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index d1c2583b6..78a427e02 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -69,6 +69,7 @@ SET(medloader_SOURCES MEDFileData.cxx MEDFileFieldOverView.cxx MEDFileMeshReadSelector.cxx + MEDFileMeshSupport.cxx SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index ab7b59e69..6add25ef6 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -19,6 +19,10 @@ // Author : Anthony Geay (CEA/DEN) #include "MEDFileData.hxx" +#include "MEDLoaderBase.hxx" +#include "MEDFileSafeCaller.txx" + +#include "InterpKernelAutoPtr.hxx" using namespace MEDCoupling; @@ -41,13 +45,13 @@ MEDFileData *MEDFileData::New() MEDFileData *MEDFileData::deepCopy() const { MCAuto fields; - if((const MEDFileFields *)_fields) + if(_fields.isNotNull()) fields=_fields->deepCopy(); MCAuto meshes; - if((const MEDFileMeshes *)_meshes) + if(_meshes.isNotNull()) meshes=_meshes->deepCopy(); MCAuto params; - if((const MEDFileParameters *)_params) + if(_params.isNotNull()) params=_params->deepCopy(); MCAuto ret(MEDFileData::New()); ret->_fields=fields; ret->_meshes=meshes; ret->_params=params; @@ -56,7 +60,7 @@ MEDFileData *MEDFileData::deepCopy() const std::size_t MEDFileData::getHeapMemorySizeWithoutChildren() const { - return 0; + return _header.capacity(); } std::vector MEDFileData::getDirectChildrenWithNull() const @@ -300,9 +304,10 @@ MEDFileData::MEDFileData() MEDFileData::MEDFileData(med_idt fid) try { - _fields=MEDFileFields::New(fid); - _meshes=MEDFileMeshes::New(fid); - _params=MEDFileParameters::New(fid); + readHeader(fid); + _fields=MEDFileFields::New(fid); + _meshes=MEDFileMeshes::New(fid); + _params=MEDFileParameters::New(fid); } catch(INTERP_KERNEL::Exception& e) { @@ -311,6 +316,7 @@ catch(INTERP_KERNEL::Exception& e) void MEDFileData::writeLL(med_idt fid) const { + writeHeader(fid); const MEDFileMeshes *ms(_meshes); if(ms) ms->writeLL(fid); @@ -321,3 +327,28 @@ void MEDFileData::writeLL(med_idt fid) const if(ps) ps->writeLL(fid); } + +std::string MEDFileData::getHeader() const +{ + return _header; +} + + +void MEDFileData::setHeader(const std::string& header) +{ + _header=header; +} + +void MEDFileData::readHeader(med_idt fid) +{ + INTERP_KERNEL::AutoPtr header(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE)); + MEDFILESAFECALLERRD0(MEDfileCommentRd,(fid,header)); + _header=MEDLoaderBase::buildStringFromFortran(header,MED_COMMENT_SIZE); +} + +void MEDFileData::writeHeader(med_idt fid) const +{ + INTERP_KERNEL::AutoPtr header(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE)); + MEDLoaderBase::safeStrCpy(_header.c_str(),MED_COMMENT_SIZE,header,_too_long_str); + MEDFILESAFECALLERWR0(MEDfileCommentWr,(fid,header)); +} diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index c7f923336..2baac71f6 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -25,6 +25,7 @@ #include "MEDFileParameter.hxx" #include "MEDFileField.hxx" #include "MEDFileMesh.hxx" +#include "MEDFileMeshSupport.hxx" namespace MEDCoupling { @@ -52,6 +53,9 @@ namespace MEDCoupling MEDLOADER_EXPORT int getNumberOfParams() const; MEDLOADER_EXPORT std::string simpleRepr() const; // + MEDLOADER_EXPORT std::string getHeader() const; + MEDLOADER_EXPORT void setHeader(const std::string& header); + // MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); MEDLOADER_EXPORT bool changeMeshName(const std::string& oldMeshName, const std::string& newMeshName); MEDLOADER_EXPORT bool unPolyzeMeshes(); @@ -61,10 +65,14 @@ namespace MEDCoupling private: MEDFileData(); MEDFileData(med_idt fid); + void readHeader(med_idt fid); + void writeHeader(med_idt fid) const; private: MCAuto _fields; MCAuto _meshes; MCAuto _params; + std::vector< MCAuto > _mesh_supports; + std::string _header; }; } diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx new file mode 100644 index 000000000..b7ff2ab56 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -0,0 +1,92 @@ +// Copyright (C) 2007-2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#include "MEDFileMeshSupport.hxx" + +#include "MEDLoaderBase.hxx" +#include "MEDFileSafeCaller.txx" + +#include "InterpKernelAutoPtr.hxx" + +using namespace MEDCoupling; + +MEDFileMeshSupport *MEDFileMeshSupport::New() +{ + return new MEDFileMeshSupport; +} + +MEDFileMeshSupport *MEDFileMeshSupport::New(const std::string& fileName, int smid) +{ + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,smid); +} + +MEDFileMeshSupport *MEDFileMeshSupport::New(med_idt fid, int smid) +{ + return new MEDFileMeshSupport(fid,smid); +} + +std::vector MEDFileMeshSupport::getDirectChildrenWithNull() const +{ + return std::vector(); +} + +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 msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + INTERP_KERNEL::AutoPtr description(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + med_axis_type axType; + int nAxis(MEDsupportMeshnAxis(fid,smid)); + INTERP_KERNEL::AutoPtr 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)); +} + +MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1) +{ +} diff --git a/src/MEDLoader/MEDFileMeshSupport.hxx b/src/MEDLoader/MEDFileMeshSupport.hxx new file mode 100644 index 000000000..f8d136776 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshSupport.hxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#ifndef __MEDFILEMESHSUPPORT_HXX__ +#define __MEDFILEMESHSUPPORT_HXX__ + +#include "MEDLoaderDefines.hxx" +#include "MEDFileUtilities.txx" + +#include "MEDCouplingRefCountObject.hxx" + +namespace MEDCoupling +{ + class MEDFileMeshSupport : public RefCountObject, public MEDFileWritableStandAlone + { + public: + MEDLOADER_EXPORT static MEDFileMeshSupport *New(const std::string& fileName); + MEDLOADER_EXPORT static MEDFileMeshSupport *New(const std::string& fileName, int smid); + MEDLOADER_EXPORT static MEDFileMeshSupport *New(med_idt fid, int smid); + MEDLOADER_EXPORT static MEDFileMeshSupport *New(); + MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDLOADER_EXPORT int getSpaceDim() const; + MEDLOADER_EXPORT void setSpaceDim(int dim); + MEDLOADER_EXPORT int getMeshDim() const; + MEDLOADER_EXPORT void setMeshDim(int dim); + private: + void writeLL(med_idt fid) const; + MEDFileMeshSupport(med_idt fid, int smid); + MEDFileMeshSupport(); + private: + int _space_dim; + int _mesh_dim; + std::string _description; + }; +} + +#endif diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index b5d356128..10057bca1 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -3595,6 +3595,8 @@ namespace MEDCoupling // bool changeMeshName(const std::string& oldMeshName, const std::string& newMeshName) throw(INTERP_KERNEL::Exception); bool unPolyzeMeshes() throw(INTERP_KERNEL::Exception); + std::string getHeader() const throw(INTERP_KERNEL::Exception); + void setHeader(const std::string& header) throw(INTERP_KERNEL::Exception); // %extend {