in boolean overwrite,
in boolean autoDimension) raises (SALOME::SALOME_Exception);
+ long long ExportMEDCoupling(in boolean auto_groups,
+ in boolean autoDimension
+ ) raises (SALOME::SALOME_Exception);
+
/*!
* Export a [part of] Mesh into a MED file
* @params
#include "DriverMED_Family.h"
#include "MED_Factory.hxx"
#include "MED_Utilities.hxx"
-#include "MEDCoupling_Wrapper.hxx"
#include "SMDS_IteratorOnIterators.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_SetIterator.hxx"
#include "SMESHDS_Mesh.hxx"
#include "MED_Common.hxx"
+#include "MED_TFile.hxx"
#include <med.h>
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
{
- PerformMedcoupling();
MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
return this->PerformInternal<MED::PWrapper>(myMed);
}
-Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformMedcoupling()
+Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh_Mem::Perform()
{
- MED::MCPWrapper myMed(new MED::MCTWrapper);
- return this->PerformInternal<MED::MCPWrapper>(myMed);
+ TMemFile *tfileInst = new TMemFile;
+ MED::PWrapper myMed = CrWrapperW(myFile, -1, tfileInst);
+ Driver_Mesh::Status status = this->PerformInternal<MED::PWrapper>(myMed);
+ _data = MEDCoupling::DataArrayByte::New();
+ _data->useArray(reinterpret_cast<char *>(tfileInst->getData()),true,MEDCoupling::DeallocType::C_DEALLOC,tfileInst->getSize(),1);
+ if(!tfileInst->IsClosed())
+ THROW_SALOME_EXCEPTION("DriverMED_W_SMESHDS_Mesh_Mem::Perform - MED memory file id is supposed to be closed !");
+ return status;
}
//================================================================================
/*! add one mesh
*/
- virtual Status Perform();
-
- Status PerformMedcoupling();
+ Status Perform() override;
template<class LowLevelWriter>
Driver_Mesh::Status PerformInternal(LowLevelWriter myMed);
double myZTolerance;
};
+#include "MEDCouplingMemArray.hxx"
+
+class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh_Mem : public DriverMED_W_SMESHDS_Mesh
+{
+public:
+ Status Perform() override;
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> getData() { return _data; }
+private:
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> _data;
+};
+
#endif
MED_Structures.cxx
MED_Utilities.cxx
MED_Wrapper.cxx
- MEDCoupling_Wrapper.cxx
)
# --- rules ---
+++ /dev/null
-// Copyright (C) 2021 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
-//
-
-#include "MEDCoupling_Wrapper.hxx"
-#include "MED_TStructures.hxx"
-
-using namespace MED;
-using namespace MEDCoupling;
-
-//Copie directe
-PMeshInfo MCTWrapper::CrMeshInfo(TInt theDim,
- TInt theSpaceDim,
- const std::string& theValue,
- EMaillage theType,
- const std::string& theDesc)
-{
- return PMeshInfo(new TTMeshInfo(theDim, theSpaceDim, theValue, theType, theDesc));
-}
-
-void MCTWrapper::SetMeshInfo(const TMeshInfo& theInfo)
-{
- _mesh_name = theInfo.GetName();
- _mesh_dim = theInfo.GetDim();
- _space_dim = theInfo.GetSpaceDim();
-}
-
-//Copie directe
-PNodeInfo MCTWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo,
- TInt theNbElem,
- EModeSwitch theMode,
- ERepere theSystem,
- EBooleen theIsElemNum,
- EBooleen theIsElemNames)
-{
- return PNodeInfo(new TTNodeInfo
- (theMeshInfo,
- theNbElem,
- theMode,
- theSystem,
- theIsElemNum,
- theIsElemNames));
-}
-
-void MCTWrapper::SetNodeInfo(const TNodeInfo& theInfo)
-{
- MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
- MED::PNodeCoord aCoord(anInfo.myCoord);
- MED::TInt aNbElem(anInfo.myNbElem);
- std::string aCoordNames(anInfo.myCoordNames.data());
- std::string aCoordUnits(anInfo.myCoordUnits.data());
- std::vector<std::string> comps( DataArray::SplitStringInChuncks(aCoordNames,MED_SNAME_SIZE) );
- std::vector<std::string> units( DataArray::SplitStringInChuncks(aCoordUnits,MED_SNAME_SIZE) );
- std::size_t nbComps( comps.size() );
- if( nbComps != units.size() )
- THROW_IK_EXCEPTION("MCTWrapper::SetNodeInfo : mismatch length " << nbComps << " != " << units.size() << " !");
- std::vector<std::string> compUnits(nbComps);
- for( std::size_t i = 0 ; i < nbComps ; ++i )
- {
- compUnits[i] = DataArray::BuildInfoFromVarAndUnit(comps[i],units[i]) ;
- }
- _coords = DataArrayDouble::New();
- _coords->alloc(aNbElem,this->_space_dim);
- std::copy(aCoord->data(),aCoord->data()+aNbElem*this->_space_dim,_coords->getPointer());
- _coords->setInfoOnComponents(compUnits);
-}
-
-void MCTWrapper::GetFamilyInfo(TInt theFamId, TFamilyInfo& theInfo)
-{
- std::string aFamilyName(theInfo.myName.data());
- MED::TInt aFamilyId(theInfo.myId);
- std::string aGroupNames(theInfo.myGroupNames.data());
-}
-
-//copie
- PFamilyInfo
- MCTWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
- const std::string& theValue,
- TInt theId,
- const MED::TStringSet& theGroupNames,
- const MED::TStringVector& theAttrDescs,
- const MED::TIntVector& theAttrIds,
- const MED::TIntVector& theAttrVals)
- {
- return PFamilyInfo(new TTFamilyInfo
- (theMeshInfo,
- theValue,
- theId,
- theGroupNames,
- theAttrDescs,
- theAttrIds,
- theAttrVals));
- }
-
- //copie
- PPolygoneInfo
- MCTWrapper::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- TInt theConnSize,
- EConnectivite theConnMode,
- EBooleen theIsElemNum,
- EBooleen theIsElemNames)
- {
- return PPolygoneInfo(new TTPolygoneInfo
- (theMeshInfo,
- theEntity,
- theGeom,
- theNbElem,
- theConnSize,
- theConnMode,
- theIsElemNum,
- theIsElemNames));
- }
-
- //copie
- PPolygoneInfo
- MCTWrapper
- ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- const TIntVector& theIndexes,
- const TIntVector& theConnectivities,
- EConnectivite theConnMode,
- const TIntVector& theFamilyNums,
- const TIntVector& theElemNums,
- const TStringVector& theElemNames)
- {
- return PPolygoneInfo(new TTPolygoneInfo
- (theMeshInfo,
- theEntity,
- theGeom,
- theIndexes,
- theConnectivities,
- theConnMode,
- theFamilyNums,
- theElemNums,
- theElemNames));
- }
-
- //copie
- PPolyedreInfo
- MCTWrapper
- ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- TInt theNbFaces,
- TInt theConnSize,
- EConnectivite theConnMode,
- EBooleen theIsElemNum,
- EBooleen theIsElemNames)
- {
- return PPolyedreInfo(new TTPolyedreInfo
- (theMeshInfo,
- theEntity,
- theGeom,
- theNbElem,
- theNbFaces,
- theConnSize,
- theConnMode,
- theIsElemNum,
- theIsElemNames));
- }
-
-//copie
- PBallInfo
- MCTWrapper
- ::CrBallInfo(const PMeshInfo& theMeshInfo,
- TInt theNbBalls,
- EBooleen theIsElemNum)
- {
- return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
- }
-
- PCellInfo
- MCTWrapper
- ::CrCellInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- EConnectivite theConnMode,
- EBooleen theIsElemNum,
- EBooleen theIsElemNames,
- EModeSwitch theMode)
- {
- return PCellInfo(new TTCellInfo
- (theMeshInfo,
- theEntity,
- theGeom,
- theNbElem,
- theConnMode,
- theIsElemNum,
- theIsElemNames,
- theMode));
- }
+++ /dev/null
-// Copyright (C) 2021 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
-//
-
-#pragma once
-
-#include "MED_Wrapper.hxx"
-
-#include "MEDFileMesh.hxx"
-
-namespace MED
-{
- class MEDWRAPPER_EXPORT MCTWrapper
- {
- public:
- //! Create a MEDWrapper MED Mesh representation
- PMeshInfo
- CrMeshInfo(TInt theDim = 0,
- TInt theSpaceDim = 0,
- const std::string& theValue = "",
- EMaillage theType = eNON_STRUCTURE,
- const std::string& theDesc = "");
- //! Write the MEDWrapper MED Mesh representation into the MED file
- void SetMeshInfo(const TMeshInfo& theInfo);
- //! Write a MEDWrapper MED Family representation into the MED file
- void SetFamilyInfo(const TFamilyInfo& theInfo) { }
- //! Create a MEDWrapper MED Nodes representation
- PNodeInfo
- CrNodeInfo(const PMeshInfo& theMeshInfo,
- TInt theNbElem,
- EModeSwitch theMode = eFULL_INTERLACE,
- ERepere theSystem = eCART,
- EBooleen theIsElemNum = eVRAI,
- EBooleen theIsElemNames = eFAUX);
- //! Write the MEDWrapper MED Nodes representation into the MED file
- void SetNodeInfo(const TNodeInfo& theInfo);
-
- //! Read a MEDWrapper MED Family representation by its numbers
- void GetFamilyInfo(TInt theFamId, TFamilyInfo& theInfo);
-
- //! Create a MEDWrapper MED Family representation
- PFamilyInfo
- CrFamilyInfo(const PMeshInfo& theMeshInfo,
- const std::string& theValue,
- TInt theId,
- const TStringSet& theGroupNames,
- const TStringVector& theAttrDescs = TStringVector(),
- const TIntVector& theAttrIds = TIntVector(),
- const TIntVector& theAttrVals = TIntVector());
-
- //! Create a MEDWrapper MED Polygones representation
- virtual
- PPolygoneInfo
- CrPolygoneInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- TInt theConnSize,
- EConnectivite theConnMode = eNOD,
- EBooleen theIsElemNum = eVRAI,
- EBooleen theIsElemNames = eVRAI);
-
- //! Create a MEDWrapper MED Polygones representation
- virtual
- PPolygoneInfo
- CrPolygoneInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- const TIntVector& theIndexes,
- const TIntVector& theConnectivities,
- EConnectivite theConnMode = eNOD,
- const TIntVector& theFamilyNums = TIntVector(),
- const TIntVector& theElemNums = TIntVector(),
- const TStringVector& theElemNames = TStringVector());
-
-
- //! Write a MEDWrapper MED Polygones representation into the MED file
- void SetPolygoneInfo(const TPolygoneInfo& theInfo) { }
-
-
- //! Create a MEDWrapper MED Polyedres representation
- PPolyedreInfo
- CrPolyedreInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- TInt theNbFaces,
- TInt theConnSize,
- EConnectivite theConnMode = eNOD,
- EBooleen theIsElemNum = eVRAI,
- EBooleen theIsElemNames = eVRAI);
-
-
- //! Write a MEDWrapper MED Polyedres representation into the MED file
- void SetPolyedreInfo(const TPolyedreInfo& theInfo) { }
-
-
- //! Create a MEDWrapper MED Balls representation
- /*! This feature is supported since version 3.0 */
- PBallInfo
- CrBallInfo(const PMeshInfo& theMeshInfo,
- TInt theNbBalls,
- EBooleen theIsElemNum = eVRAI);
-
- //! Write a MEDWrapper representation of MED_BALL into the MED file
- /*! This feature is supported since version 3.0 */
- void
- SetBallInfo(const TBallInfo& theInfo) { }
-
-
- //! Create a MEDWrapper MED Cells representation
- virtual
- PCellInfo
- CrCellInfo(const PMeshInfo& theMeshInfo,
- EEntiteMaillage theEntity,
- EGeometrieElement theGeom,
- TInt theNbElem,
- EConnectivite theConnMode = eNOD,
- EBooleen theIsElemNum = eVRAI,
- EBooleen theIsElemNames = eFAUX,
- EModeSwitch theMode = eFULL_INTERLACE);
-
- //! Write the MEDWrapper MED Cells representation into the MED file
- void SetCellInfo(const TCellInfo& theInfo) { }
- private:
- MEDCoupling::MCAuto<MEDCoupling::MEDFileUMesh> _mc_mesh;
- MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> _coords;
- std::string _mesh_name;
- int _space_dim;
- int _mesh_dim;
- };
-
- using MCPWrapper = std::shared_ptr<MCTWrapper>;
-}
if (!CheckCompatibility(fileName)) {
EXCEPTION(std::runtime_error, "Cannot open file '"<<fileName<<"'.");
}
- return new MED::TWrapper(fileName, false);
+ return new MED::TWrapper(fileName, false, nullptr);
}
- PWrapper CrWrapperW(const std::string& fileName, int theVersion)
+ PWrapper CrWrapperW(const std::string& fileName, int theVersion, TFileInternal *tfileInst)
{
bool isCreated = false;
if (!CheckCompatibility(fileName, true))
wantedMajor = theVersion/10;
wantedMinor = theVersion%10;
}
- return new MED::TWrapper(fileName, true, wantedMajor, wantedMinor);
+ return new MED::TWrapper(fileName, true, tfileInst, wantedMajor, wantedMinor);
}
}
PWrapper CrWrapperR( const std::string& );
MEDWRAPPER_EXPORT
- PWrapper CrWrapperW( const std::string&, int theVersion=-1 );
+ PWrapper CrWrapperW( const std::string&, int theVersion=-1 , TFileInternal *tfileInst=nullptr );
}
#endif // MED_Factory_HeaderFile
--- /dev/null
+// Copyright (C) 2021 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
+//
+
+#pragma once
+
+#include "MED_Wrapper.hxx"
+
+namespace MED
+{
+ class TFileInternal
+ {
+ public:
+ virtual ~TFileInternal() = default;
+ virtual void Open(EModeAcces theMode, TErr* theErr = nullptr) = 0;
+ virtual void Close() = 0;
+ virtual bool IsClosed() const = 0;
+ virtual const TIdt& Id() const = 0;
+ };
+
+ class MEDIDTHoder : public TFileInternal
+ {
+ protected:
+ MEDIDTHoder() = default;
+ void UnRefFid()
+ {
+ if (--myCount == 0)
+ {
+ MEDfileClose(myFid);
+ myIsClosed = true;
+ }
+ }
+ public:
+ const TIdt& Id() const override;
+ ~MEDIDTHoder() { this->UnRefFid(); }
+ void Close() override { this->UnRefFid(); }
+ bool IsClosed() const override { return myIsClosed; }
+ protected:
+ TInt myCount = 0;
+ TIdt myFid = 0;
+ bool myIsClosed = false;
+ };
+
+ class TFileDecorator : public TFileInternal
+ {
+ public:
+ TFileDecorator(TFileInternal *effective):_effective(effective) { }
+ void Open(EModeAcces theMode, TErr* theErr = nullptr) override { if(_effective) _effective->Open(theMode,theErr); }
+ void Close() override { if(_effective) _effective->Close(); }
+ const TIdt& Id() const override { if(_effective) return _effective->Id(); EXCEPTION(std::runtime_error, "TFileDecorator - GetFid() : no effective TFile !"); }
+ bool IsClosed() const override { if(_effective) return _effective->IsClosed(); EXCEPTION(std::runtime_error, "TFileDecorator - IsClosed() : no effective TFile !"); }
+ ~TFileDecorator() { delete _effective; }
+ private:
+ TFileInternal *_effective = nullptr;
+ };
+
+ class TMemFile : public MEDIDTHoder
+ {
+ public:
+ TMemFile() = default;
+ void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
+ void *getData() const { return memfile.app_image_ptr; }
+ std::size_t getSize() const { return memfile.app_image_size; }
+ private:
+ med_memfile memfile = MED_MEMFILE_INIT;
+ };
+
+ class TFile : public MEDIDTHoder
+ {
+ public:
+ TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1);
+ void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
+ protected:
+ std::string myFileName;
+ TInt myMajor;
+ TInt myMinor;
+ };
+}
#include "MED_Wrapper.hxx"
#include "MED_TStructures.hxx"
#include "MED_Utilities.hxx"
+#include "MED_TFile.hxx"
+#include "MEDFileUtilities.hxx"
#include <med.h>
#include <med_err.h>
#include <med_proto.h>
}
//---------------------------------------------------------------
- class TFile
+ const TIdt& MEDIDTHoder::Id() const
{
- TFile();
- TFile(const TFile&);
+ if (myFid < 0)
+ EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
+ return myFid;
+ }
- public:
- TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1):
- myCount(0),
- myFid(0),
- myFileName(theFileName),
- myMajor(theMajor),
- myMinor(theMinor)
+ void TMemFile::Open(EModeAcces theMode, TErr* theErr)
+ {
+ if (this->myCount++ == 0)
{
- if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM;
- if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
+ std::string dftFileName = MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInMem();
+ memfile = MED_MEMFILE_INIT;
+ memfile.app_image_ptr=0;
+ memfile.app_image_size=0;
+ myFid = MEDmemFileOpen(dftFileName.c_str(),&memfile,MED_FALSE,MED_ACC_CREAT);
}
+ if (theErr)
+ *theErr = TErr(myFid);
+ else if (myFid < 0)
+ EXCEPTION(std::runtime_error,"TMemFile - MEDmemFileOpen");
+ }
- ~TFile()
- {
- Close();
- }
+ TFile::TFile(const std::string& theFileName, TInt theMajor, TInt theMinor):
+ myFileName(theFileName),
+ myMajor(theMajor),
+ myMinor(theMinor)
+ {
+ if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM;
+ if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
+ }
- void
- Open(EModeAcces theMode,
- TErr* theErr = NULL)
- {
- if (myCount++ == 0) {
- const char* aFileName = myFileName.c_str();
+ void TFile::Open(EModeAcces theMode, TErr* theErr)
+ {
+ if (myCount++ == 0) {
+ const char* aFileName = myFileName.c_str();
#ifdef WIN32
- if (med_access_mode(theMode) == MED_ACC_RDWR) {
- // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5
- std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1";
+ if (med_access_mode(theMode) == MED_ACC_RDWR) {
+ // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5
+ std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1";
#ifdef UNICODE
- const char* to_decode = aReadOlnyRmCmd.c_str();
- int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0);
- wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1];
- MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed);
- awReadOlnyRmCmd[size_needed] = '\0';
- _wsystem(awReadOlnyRmCmd);
- delete[] awReadOlnyRmCmd;
+ const char* to_decode = aReadOlnyRmCmd.c_str();
+ int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0);
+ wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1];
+ MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed);
+ awReadOlnyRmCmd[size_needed] = '\0';
+ _wsystem(awReadOlnyRmCmd);
+ delete[] awReadOlnyRmCmd;
#else
- system(aReadOlnyRmCmd.c_str());
-#endif
- }
+ system(aReadOlnyRmCmd.c_str());
#endif
- myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
}
- if (theErr)
- *theErr = TErr(myFid);
- else if (myFid < 0)
- EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< myMajor <<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
- }
-
- const TIdt&
- Id() const
- {
- if (myFid < 0)
- EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
- return myFid;
- }
-
- void
- Close()
- {
- if (--myCount == 0)
- MEDfileClose(myFid);
+#endif
+ myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
}
-
- protected:
- TInt myCount;
- TIdt myFid;
- std::string myFileName;
- TInt myMajor;
- TInt myMinor;
- };
+ if (theErr)
+ *theErr = TErr(myFid);
+ else if (myFid < 0)
+ EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< myMajor <<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
+ }
//---------------------------------------------------------------
class TFileWrapper
{
- PFile myFile;
+ PFileInternal myFile;
TInt myMinor;
public:
- TFileWrapper(const PFile& theFile,
+ TFileWrapper(const PFileInternal& theFile,
EModeAcces theMode,
TErr* theErr = NULL,
TInt theMinor=-1):
//---------------------------------------------------------------
TWrapper
- ::TWrapper(const std::string& theFileName, bool write, TInt theMajor, TInt theMinor):
- myFile(new TFile(theFileName, theMajor, theMinor)),
+ ::TWrapper(const std::string& theFileName, bool write, TFileInternal *tfileInst, TInt theMajor, TInt theMinor):
myMajor(theMajor),
myMinor(theMinor)
{
+ if(!tfileInst)
+ myFile.reset(new TFile(theFileName, theMajor, theMinor) );
+ else
+ myFile.reset(new TFileDecorator(tfileInst) );
+
TErr aRet;
if ( write ) {
myFile->Open(eLECTURE_ECRITURE, &aRet);
namespace MED
{
//----------------------------------------------------------------------------
- class TFile;
- typedef std::shared_ptr<TFile> PFile;
+ class TFileInternal;
+ typedef std::shared_ptr<TFileInternal> PFileInternal;
typedef enum {eLECTURE, eLECTURE_ECRITURE, eLECTURE_AJOUT, eCREATION} EModeAcces;
TWrapper& operator=(const TWrapper&);
public:
- TWrapper(const std::string& theFileName, bool write, TInt theMajor=-1, TInt theVersion=-1);
+ TWrapper(const std::string& theFileName, bool write, TFileInternal *tfileInst = nullptr, TInt theMajor=-1, TInt theVersion=-1);
virtual
~TWrapper();
TErr* theErr = NULL);
protected:
- PFile myFile;
+ PFileInternal myFile;
TInt myMajor;
TInt myMinor;
};
return false;
}
-//================================================================================
-/*!
- * \brief Export the mesh to a med file
- * \param [in] file - name of the MED file
- * \param [in] theMeshName - name of this mesh
- * \param [in] theAutoGroups - boolean parameter for creating/not creating
- * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
- * the typical use is auto_groups=false.
- * \param [in] theVersion - define the minor (xy, where version is x.y.z) of MED file format.
- * If theVersion is equal to -1, the minor version is not changed (default).
- * \param [in] meshPart - mesh data to export
- * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
- * - 1D if all mesh nodes lie on OX coordinate axis, or
- * - 2D if all mesh nodes lie on XOY coordinate plane, or
- * - 3D in the rest cases.
- * If \a theAutoDimension is \c false, the space dimension is always 3.
- * \param [in] theAddODOnVertices - to create 0D elements on all vertices
- * \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
- * \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
- * within a given tolerance, the coordinate is set to zero.
- * If \a ZTolerance is negative, the node coordinates are kept as is.
- * \return int - mesh index in the file
- */
-//================================================================================
-
-void SMESH_Mesh::ExportMED(const char * file,
+void SMESH_Mesh::ExportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
const char* theMeshName,
bool theAutoGroups,
- int theVersion,
const SMESHDS_Mesh* meshPart,
bool theAutoDimension,
bool theAddODOnVertices,
double theZTolerance,
bool theAllElemsToGroup)
{
- MESSAGE("MED_VERSION:"<< theVersion);
-
- Driver_Mesh::Status status;
+ Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
SMESH_TRY;
-
- DriverMED_W_SMESHDS_Mesh myWriter;
- myWriter.SetFile ( file , theVersion);
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension );
myWriter.AddODOnVertices ( theAddODOnVertices );
throw TooLargeForExport("MED");
}
+/*!
+ * Same as SMESH_Mesh::ExportMED except for \a file and \a theVersion
+ */
+MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> SMESH_Mesh::ExportMEDCoupling(
+ const char* theMeshName,
+ bool theAutoGroups,
+ const SMESHDS_Mesh* meshPart,
+ bool theAutoDimension,
+ bool theAddODOnVertices,
+ double theZTolerance,
+ bool theAllElemsToGroup)
+{
+ DriverMED_W_SMESHDS_Mesh_Mem myWriter;
+ this->ExportMEDCommmon(myWriter,theMeshName,theAutoGroups,meshPart,theAutoDimension,theAddODOnVertices,theZTolerance,theAllElemsToGroup);
+ return myWriter.getData();
+}
+
+//================================================================================
+/*!
+ * \brief Export the mesh to a med file
+ * \param [in] file - name of the MED file
+ * \param [in] theMeshName - name of this mesh
+ * \param [in] theAutoGroups - boolean parameter for creating/not creating
+ * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
+ * the typical use is auto_groups=false.
+ * \param [in] theVersion - define the minor (xy, where version is x.y.z) of MED file format.
+ * If theVersion is equal to -1, the minor version is not changed (default).
+ * \param [in] meshPart - mesh data to export
+ * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
+ * - 1D if all mesh nodes lie on OX coordinate axis, or
+ * - 2D if all mesh nodes lie on XOY coordinate plane, or
+ * - 3D in the rest cases.
+ * If \a theAutoDimension is \c false, the space dimension is always 3.
+ * \param [in] theAddODOnVertices - to create 0D elements on all vertices
+ * \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
+ * \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
+ * within a given tolerance, the coordinate is set to zero.
+ * If \a ZTolerance is negative, the node coordinates are kept as is.
+ * \return int - mesh index in the file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportMED(const char * file,
+ const char* theMeshName,
+ bool theAutoGroups,
+ int theVersion,
+ const SMESHDS_Mesh* meshPart,
+ bool theAutoDimension,
+ bool theAddODOnVertices,
+ double theZTolerance,
+ bool theAllElemsToGroup)
+{
+ MESSAGE("MED_VERSION:"<< theVersion);
+ DriverMED_W_SMESHDS_Mesh myWriter;
+ myWriter.SetFile( file , theVersion );
+ this->ExportMEDCommmon(myWriter,theMeshName,theAutoGroups,meshPart,theAutoDimension,theAddODOnVertices,theZTolerance,theAllElemsToGroup);
+}
+
//================================================================================
/*!
* \brief Export the mesh to a SAUV file
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
+#include "MEDCouplingMemArray.hxx"
+
#include <map>
#include <list>
#include <vector>
class SMESH_subMesh;
class TopoDS_Solid;
+class DriverMED_W_SMESHDS_Mesh;
+
typedef std::list<int> TListOfInt;
typedef std::list<TListOfInt> TListOfListOfInt;
TooLargeForExport(const char* format):runtime_error(format) {}
};
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> ExportMEDCoupling(
+ const char* theMeshName = NULL,
+ bool theAutoGroups = true,
+ const SMESHDS_Mesh* theMeshPart = 0,
+ bool theAutoDimension = false,
+ bool theAddODOnVertices = false,
+ double theZTolerance = -1.,
+ bool theAllElemsToGroup = false);
+
void ExportMED(const char * theFile,
const char* theMeshName = NULL,
bool theAutoGroups = true,
private:
+ void ExportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
+ const char* theMeshName,
+ bool theAutoGroups,
+ const SMESHDS_Mesh* meshPart,
+ bool theAutoDimension,
+ bool theAddODOnVertices,
+ double theZTolerance,
+ bool theAllElemsToGroup);
+
+private:
void fillAncestorsMap(const TopoDS_Shape& theShape);
void getAncestorsSubMeshes(const TopoDS_Shape& theSubShape,
std::vector< SMESH_subMesh* >& theSubMeshes) const;
${Boost_INCLUDE_DIRS}
${OpenCASCADE_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/Driver
${PROJECT_SOURCE_DIR}/src/DriverDAT
${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/OBJECT
${PROJECT_SOURCE_DIR}/src/SMESHFiltersSelection
${PROJECT_SOURCE_DIR}/src/SMDS
${KERNEL_INCLUDE_DIRS}
${GUI_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/SMDS
${PROJECT_SOURCE_DIR}/src/SMESHDS
#include "SALOME_Container_i.hxx"
#include "SALOME_KernelServices.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+
#include <cstring>
static Engines::EngineComponent_var _unique_compo;
//
pman->activate();
//
+ SMESH_Gen_i::SetNS(new SALOME_Fake_NamingService);
+ //
SMESH_Gen_No_Session_i *servant = new SMESH_Gen_No_Session_i(orb, poa, conId, "SMESH_inst_2", "SMESH");
PortableServer::ObjectId *zeId = servant->getId();
CORBA::Object_var zeRef = poa->id_to_reference(*zeId);
PortableServer::POA_ptr poa,
PortableServer::ObjectId* contId,
const char* instanceName,
- const char* interfaceName):SMESH_Gen_i(orb,poa,contId,instanceName,interfaceName,false)
+ const char* interfaceName):SMESH_Gen_i(orb,poa,contId,instanceName,interfaceName,true)
{
- myNS = new SALOME_Fake_NamingService;
}
GEOM::GEOM_Gen_var SMESH_Gen_No_Session_i::GetGeomEngine( bool isShaper )
return anObj;
}
+// Set Naming Service object
+void SMESH_Gen_i::SetNS(SALOME_NamingService_Abstract *ns)
+{
+ if(myNS)
+ delete myNS;
+ myNS = ns;
+}
+
//=============================================================================
/*!
* GetNS [ static ]
SALOME_NamingService_Abstract* SMESH_Gen_i::GetNS()
{
- if ( myNS == NULL ) {
+ if ( !myNS ) {
myNS = SINGLETON_<SALOME_NamingService>::Instance();
ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
myNS->init_orb( GetORB() );
static CORBA::ORB_var GetORB() { return myOrb;}
// Get SMESH module's POA object
static PortableServer::POA_var GetPOA() { return myPoa;}
+ // Set Naming Service object
+ static void SetNS(SALOME_NamingService_Abstract *ns);
// Get Naming Service object
static SALOME_NamingService_Abstract* GetNS();
// Get SALOME_LifeCycleCORBA object
}
}
+/*!
+ Return a MeshName
+ */
+std::string SMESH_Mesh_i::generateMeshName()
+{
+ string aMeshName = "Mesh";
+ SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
+ if ( !aStudy->_is_nil() )
+ {
+ SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
+ if ( !aMeshSO->_is_nil() )
+ {
+ CORBA::String_var name = aMeshSO->GetName();
+ aMeshName = name;
+ }
+ }
+ return aMeshName;
+}
+
//================================================================================
/*!
* \brief Prepare a file for export and pass names of mesh groups from study to mesh DS
{
// Perform Export
PrepareForWriting(file, overwrite);
- string aMeshName = "Mesh";
+ string aMeshName(this->generateMeshName());
SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
if ( !aStudy->_is_nil() ) {
SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
if ( !aMeshSO->_is_nil() ) {
- CORBA::String_var name = aMeshSO->GetName();
- aMeshName = name;
// asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
if ( !aStudy->GetProperties()->IsLocked() )
{
SMESH_CATCH( SMESH::throwCorbaException );
}
+CORBA::LongLong SMESH_Mesh_i::ExportMEDCoupling(CORBA::Boolean auto_groups, CORBA::Boolean autoDimension)
+{
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
+ SMESH_TRY;
+ if( !this->_gen_i->IsEmbeddedMode() )
+ SMESH::throwCorbaException("SMESH_Mesh_i::ExportMEDCoupling : only for embedded mode !");
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ string aMeshName = this->generateMeshName();
+ data = _impl->ExportMEDCoupling( aMeshName.c_str(), auto_groups, 0, autoDimension );
+ SMESH_CATCH( SMESH::throwCorbaException );
+ MEDCoupling::DataArrayByte *ret(data.retn());
+ return reinterpret_cast<CORBA::LongLong>(ret);
+}
+
//================================================================================
/*!
* \brief Export a mesh to a SAUV file
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension = true);
+ CORBA::LongLong ExportMEDCoupling(CORBA::Boolean auto_groups,
+ CORBA::Boolean autoDimension = true
+ );
+
void ExportSAUV( const char* file, CORBA::Boolean auto_groups );
void ExportDAT( const char* file );
std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
private:
+ std::string generateMeshName( );
std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite );
/*!
self.mesh.RemoveHypothesis( self.geom, hyp )
pass
pass
+
+ def ExportMEDCoupling(self, *args, **kwargs):
+ """
+ Export the mesh in a memory representation.
+
+ Parameters:
+ auto_groups (boolean): parameter for creating/not creating
+ the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
+ the typical use is auto_groups=False.
+ overwrite (boolean): parameter for overwriting/not overwriting the file
+ meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
+ autoDimension: if *True* (default), a space dimension of a MED mesh can be either
+
+ - 1D if all mesh nodes lie on OX coordinate axis, or
+ - 2D if all mesh nodes lie on XOY coordinate plane, or
+ - 3D in the rest cases.
+
+ If *autoDimension* is *False*, the space dimension is always 3.
+ fields: list of GEOM fields defined on the shape to mesh.
+ geomAssocFields: each character of this string means a need to export a
+ corresponding field; correspondence between fields and characters
+ is following:
+
+ - 'v' stands for "_vertices_" field;
+ - 'e' stands for "_edges_" field;
+ - 'f' stands for "_faces_" field;
+ - 's' stands for "_solids_" field.
+
+ zTolerance (float): tolerance in Z direction. If Z coordinate of a node is
+ close to zero within a given tolerance, the coordinate is set to zero.
+ If *ZTolerance* is negative (default), the node coordinates are kept as is.
+ """
+ auto_groups = args[0] if len(args) > 0 else False
+ meshPart = args[1] if len(args) > 1 else None
+ autoDimension = args[2] if len(args) > 2 else True
+ fields = args[3] if len(args) > 3 else []
+ geomAssocFields = args[4] if len(args) > 4 else ''
+ z_tolerance = args[5] if len(args) > 5 else -1.
+ # process keywords arguments
+ auto_groups = kwargs.get("auto_groups", auto_groups)
+ meshPart = kwargs.get("meshPart", meshPart)
+ autoDimension = kwargs.get("autoDimension", autoDimension)
+ fields = kwargs.get("fields", fields)
+ geomAssocFields = kwargs.get("geomAssocFields", geomAssocFields)
+ z_tolerance = kwargs.get("zTolerance", z_tolerance)
+
+ # invoke engine's function
+ if meshPart or fields or geomAssocFields or z_tolerance > 0:
+ unRegister = genObjUnRegister()
+ if isinstance( meshPart, list ):
+ meshPart = self.GetIDSource( meshPart, SMESH.ALL )
+ unRegister.set( meshPart )
+
+ z_tolerance,Parameters,hasVars = ParseParameters(z_tolerance)
+ self.mesh.SetParameters(Parameters)
+
+ self.mesh.ExportPartToMEDCoupling( meshPart, auto_groups,
+ autoDimension,
+ fields, geomAssocFields, z_tolerance)
+ else:
+ self.mesh.ExportMEDCoupling(auto_groups, autoDimension)
+
+
def ExportMED(self, *args, **kwargs):
"""
Export the mesh in a file in MED format
${Boost_INCLUDE_DIRS}
${KERNEL_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESHUtils
${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHDS
${Boost_INCLUDE_DIRS}
${QWT_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHUtils
${PROJECT_SOURCE_DIR}/src/SMESH_I
${MEDFILE_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESHImpl
${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHUtils
${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
+ ${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESH_I
${PROJECT_SOURCE_DIR}/src/SMESHDS