X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMesh.cxx;h=5216e4307045cb5783b3b57edb0535c842d60b6e;hb=d03205f49b4e31d8968b0fcceb5980c779910c67;hp=181288b4bf3190809ef665a52266f65c02a909b3;hpb=b4b11b30ec3c8c59b9124a2c4efbd4b99039556f;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 181288b4b..5216e4307 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2014 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. +// 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 @@ -146,7 +146,7 @@ bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const * to be compared. An interpolation using MEDCouplingRemapper class should be then used. */ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec, - DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) + DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const { cellCor=0; nodeCor=0; @@ -329,10 +329,10 @@ void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) */ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) { - copyTinyStringsFrom(other); _time=other->_time; _iteration=other->_iteration; _order=other->_order; + copyTinyStringsFrom(other); } /*! @@ -371,8 +371,10 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const std::string& func) const { @@ -421,8 +423,10 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic2 "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic2 "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nbOfComp, const std::string& func) const { @@ -472,8 +476,10 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nb * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic3 "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic3 "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const std::string& func) const { @@ -626,8 +632,10 @@ const char *MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NormalizedCel * \param [in,out] elts - vector returning ids of the found cells. It is cleared * before inserting ids. * + * \if ENABLE_EXAMPLES * \ref cpp_mcumesh_getCellsContainingPoint "Here is a C++ example".
* \ref py_mcumesh_getCellsContainingPoint "Here is a Python example". + * \endif */ void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const { @@ -655,8 +663,10 @@ void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std * Number of cells in contact with the *i*-th point is * \a eltsIndex[ *i*+1 ] - \a eltsIndex[ *i* ]. * + * \if ENABLE_EXAMPLES * \ref cpp_mcumesh_getCellsContainingPoints "Here is a C++ example".
* \ref py_mcumesh_getCellsContainingPoints "Here is a Python example". + * \endif */ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, MEDCouplingAutoRefCountObjectPtr& elts, MEDCouplingAutoRefCountObjectPtr& eltsIndex) const { @@ -679,16 +689,41 @@ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints /*! * Writes \a this mesh into a VTK format file named as specified. - * \param [in] fileName - the name of the file to write in. + * \param [in] fileName - the name of the file to write in. If the extension is OK the fileName will be used directly. + * If extension is invalid or no extension the right extension will be appended. + * \return - the real fileName * \throw If \a fileName is not a writable file. + * \sa getVTKFileNameOf */ -void MEDCouplingMesh::writeVTK(const std::string& fileName, bool isBinary) const +std::string MEDCouplingMesh::writeVTK(const std::string& fileName, bool isBinary) const { + std::string ret(getVTKFileNameOf(fileName)); + // std::string cda,pda; MEDCouplingAutoRefCountObjectPtr byteArr; if(isBinary) { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } - writeVTKAdvanced(fileName,cda,pda,byteArr); + writeVTKAdvanced(ret,cda,pda,byteArr); + return ret; +} + +/*! + * This method takes in input a file name \a fileName and considering the VTK extension of \a this (depending on the type of \a this) + * returns a right file name. If the input \a fileName has a valid extension the returned string is equal to \a fileName. + * + * \sa getVTKFileExtension + */ +std::string MEDCouplingMesh::getVTKFileNameOf(const std::string& fileName) const +{ + std::string ret; + std::string part0,part1; + SplitExtension(fileName,part0,part1); + std::string ext("."); ext+=getVTKFileExtension(); + if(part1==ext) + ret=fileName; + else + ret=fileName+ext; + return ret; } void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const @@ -710,3 +745,16 @@ void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::s ofs.close(); } } + +void MEDCouplingMesh::SplitExtension(const std::string& fileName, std::string& baseName, std::string& extension) +{ + std::size_t pos(fileName.find_last_of('.')); + if(pos==std::string::npos) + { + baseName=fileName; + extension.clear(); + return ; + } + baseName=fileName.substr(0,pos); + extension=fileName.substr(pos); +}