Implementation of ExportMEDCoupling.

This commit is contained in:
Anthony Geay 2021-04-26 21:53:20 +02:00
parent b79f3c0765
commit cc54cd4b94
28 changed files with 629 additions and 223 deletions

View File

@ -663,6 +663,10 @@ module SMESH
in boolean overwrite, in boolean overwrite,
in boolean autoDimension) raises (SALOME::SALOME_Exception); 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 * Export a [part of] Mesh into a MED file
* @params * @params
@ -701,6 +705,13 @@ module SMESH
in string geomAssocFields, in string geomAssocFields,
in double ZTolerance) raises (SALOME::SALOME_Exception); in double ZTolerance) raises (SALOME::SALOME_Exception);
long long ExportPartToMEDCoupling( in SMESH_IDSource meshPart,
in boolean auto_groups,
in boolean autoDimension,
in GEOM::ListOfFields fields,
in string geomAssocFields,
in double ZTolerance) raises (SALOME::SALOME_Exception);
/*! /*!
* Export Mesh to SAUV formatted file * Export Mesh to SAUV formatted file
* Write a temporary med file and use med2sauv * Write a temporary med file and use med2sauv

View File

@ -20,6 +20,7 @@
# --- options --- # --- options ---
# additional include directories # additional include directories
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${MEDCOUPLING_INCLUDE_DIRS}
${MEDFILE_INCLUDE_DIRS} ${MEDFILE_INCLUDE_DIRS}
${HDF5_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS}
${KERNEL_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS}

View File

@ -26,7 +26,6 @@
// Module : SMESH // Module : SMESH
// //
#include "DriverMED_Family.h" #include "DriverMED_Family.h"
#include "MED_Factory.hxx"
#include <sstream> #include <sstream>
@ -366,67 +365,6 @@ DriverMED_Family
return aFamilies; return aFamilies;
} }
//=============================================================================
/*!
* Create TFamilyInfo for this family
*/
//=============================================================================
MED::PFamilyInfo
DriverMED_Family::GetFamilyInfo(const MED::PWrapper& theWrapper,
const MED::PMeshInfo& theMeshInfo) const
{
ostringstream aStr;
aStr << "FAM_" << myId;
set<string>::const_iterator aGrIter = myGroupNames.begin();
for(; aGrIter != myGroupNames.end(); aGrIter++){
aStr << "_" << *aGrIter;
}
string aValue = aStr.str();
// PAL19785,0019867 - med forbids whitespace to be the last char in the name
int maxSize = MED::GetNOMLength();
int lastCharPos = min( maxSize, (int) aValue.size() ) - 1;
while ( isspace( aValue[ lastCharPos ] ))
aValue.resize( lastCharPos-- );
MED::PFamilyInfo anInfo;
if(myId == 0 || myGroupAttributVal == 0){
anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
aValue,
myId,
myGroupNames);
}else{
MED::TStringVector anAttrDescs (1, ""); // 1 attribute with empty description,
MED::TIntVector anAttrIds (1, myId); // Id=0,
MED::TIntVector anAttrVals (1, myGroupAttributVal);
anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
aValue,
myId,
myGroupNames,
anAttrDescs,
anAttrIds,
anAttrVals);
}
// cout << endl;
// cout << "Groups: ";
// set<string>::iterator aGrIter = myGroupNames.begin();
// for (; aGrIter != myGroupNames.end(); aGrIter++)
// {
// cout << " " << *aGrIter;
// }
// cout << endl;
//
// cout << "Elements: ";
// set<const SMDS_MeshElement *>::iterator anIter = myElements.begin();
// for (; anIter != myElements.end(); anIter++)
// {
// cout << " " << (*anIter)->GetID();
// }
// cout << endl;
return anInfo;
}
//============================================================================= //=============================================================================
/*! /*!
* Initialize the tool by SMESHDS_GroupBase * Initialize the tool by SMESHDS_GroupBase

View File

@ -91,9 +91,10 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
const bool doAllInGroups); const bool doAllInGroups);
//! Create TFamilyInfo for this family //! Create TFamilyInfo for this family
template<class LowLevelWriter>
MED::PFamilyInfo MED::PFamilyInfo
GetFamilyInfo (const MED::PWrapper& theWrapper, GetFamilyInfo(const LowLevelWriter& theWrapper,
const MED::PMeshInfo& theMeshInfo) const; const MED::PMeshInfo& theMeshInfo) const;
//! Returns elements of this family //! Returns elements of this family
const ElementsSet& GetElements () const; const ElementsSet& GetElements () const;
@ -154,4 +155,70 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
ElemTypeSet myTypes; // Issue 0020576 ElemTypeSet myTypes; // Issue 0020576
}; };
#include "MED_Factory.hxx"
#include <set>
#include <string>
//=============================================================================
/*!
* Create TFamilyInfo for this family
*/
//=============================================================================
template<class LowLevelWriter>
MED::PFamilyInfo
DriverMED_Family::GetFamilyInfo(const LowLevelWriter& theWrapper,
const MED::PMeshInfo& theMeshInfo) const
{
std::ostringstream aStr;
aStr << "FAM_" << myId;
std::set<std::string>::const_iterator aGrIter = myGroupNames.begin();
for(; aGrIter != myGroupNames.end(); aGrIter++){
aStr << "_" << *aGrIter;
}
std::string aValue = aStr.str();
// PAL19785,0019867 - med forbids whitespace to be the last char in the name
int maxSize = MED::GetNOMLength();
int lastCharPos = std::min( maxSize, (int) aValue.size() ) - 1;
while ( isspace( aValue[ lastCharPos ] ))
aValue.resize( lastCharPos-- );
MED::PFamilyInfo anInfo;
if(myId == 0 || myGroupAttributVal == 0){
anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
aValue,
myId,
myGroupNames);
}else{
MED::TStringVector anAttrDescs (1, ""); // 1 attribute with empty description,
MED::TIntVector anAttrIds (1, myId); // Id=0,
MED::TIntVector anAttrVals (1, myGroupAttributVal);
anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
aValue,
myId,
myGroupNames,
anAttrDescs,
anAttrIds,
anAttrVals);
}
// cout << endl;
// cout << "Groups: ";
// set<string>::iterator aGrIter = myGroupNames.begin();
// for (; aGrIter != myGroupNames.end(); aGrIter++)
// {
// cout << " " << *aGrIter;
// }
// cout << endl;
//
// cout << "Elements: ";
// set<const SMDS_MeshElement *>::iterator anIter = myElements.begin();
// for (; anIter != myElements.end(); anIter++)
// {
// cout << " " << (*anIter)->GetID();
// }
// cout << endl;
return anInfo;
}
#endif #endif

View File

@ -35,6 +35,7 @@
#include "SMDS_SetIterator.hxx" #include "SMDS_SetIterator.hxx"
#include "SMESHDS_Mesh.hxx" #include "SMESHDS_Mesh.hxx"
#include "MED_Common.hxx" #include "MED_Common.hxx"
#include "MED_TFile.hxx"
#include <med.h> #include <med.h>
@ -343,13 +344,39 @@ namespace
} }
} }
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
{
MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
return this->PerformInternal<MED::PWrapper>(myMed);
}
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh_Mem::Perform()
{
void *ptr(nullptr);
std::size_t sz(0);
Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
bool isClosed(false);
{// let braces to flush (call of MED::PWrapper myMed destructor)
TMemFile *tfileInst = new TMemFile(&isClosed);
MED::PWrapper myMed = CrWrapperW(myFile, -1, tfileInst);
status = this->PerformInternal<MED::PWrapper>(myMed);
ptr = tfileInst->getData(); sz = tfileInst->getSize();
}
_data = MEDCoupling::DataArrayByte::New();
_data->useArray(reinterpret_cast<char *>(ptr),true,MEDCoupling::DeallocType::C_DEALLOC,sz,1);
if(!isClosed)
THROW_SALOME_EXCEPTION("DriverMED_W_SMESHDS_Mesh_Mem::Perform - MED memory file id is supposed to be closed !");
return status;
}
//================================================================================ //================================================================================
/*! /*!
* \brief Write my mesh * \brief Write my mesh
*/ */
//================================================================================ //================================================================================
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() template<class LowLevelWriter>
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformInternal(LowLevelWriter myMed)
{ {
Status aResult = DRS_OK; Status aResult = DRS_OK;
try { try {
@ -471,7 +498,6 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
} }
} }
MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName); PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
//MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName()); //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
myMed->SetMeshInfo(aMeshInfo); myMed->SetMeshInfo(aMeshInfo);
@ -532,7 +558,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
list<DriverMED_FamilyPtr>::iterator aFamsIter; list<DriverMED_FamilyPtr>::iterator aFamsIter;
for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++) for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
{ {
PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo); PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo<LowLevelWriter>(myMed,aMeshInfo);
myMed->SetFamilyInfo(aFamilyInfo); myMed->SetFamilyInfo(aFamilyInfo);
} }

View File

@ -74,7 +74,10 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
/*! add one mesh /*! add one mesh
*/ */
virtual Status Perform(); Status Perform() override;
template<class LowLevelWriter>
Driver_Mesh::Status PerformInternal(LowLevelWriter myMed);
private: private:
@ -94,4 +97,15 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
double myZTolerance; 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 #endif

View File

@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES(
${HDF5_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS}
${MEDFILE_INCLUDE_DIRS} ${MEDFILE_INCLUDE_DIRS}
${KERNEL_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS}
${MEDCOUPLING_INCLUDE_DIRS}
) )
# additional preprocessor / compiler flags # additional preprocessor / compiler flags
@ -37,6 +38,7 @@ SET(_link_LIBRARIES
${HDF5_LIBS} ${HDF5_LIBS}
${MEDFILE_C_LIBRARIES} ${MEDFILE_C_LIBRARIES}
${KERNEL_SALOMELocalTrace} ${KERNEL_SALOMELocalTrace}
${MEDCoupling_medloader}
) )
# --- headers --- # --- headers ---

View File

@ -183,10 +183,10 @@ namespace MED
if (!CheckCompatibility(fileName)) { if (!CheckCompatibility(fileName)) {
EXCEPTION(std::runtime_error, "Cannot open file '"<<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; bool isCreated = false;
if (!CheckCompatibility(fileName, true)) if (!CheckCompatibility(fileName, true))
@ -204,6 +204,6 @@ namespace MED
wantedMajor = theVersion/10; wantedMajor = theVersion/10;
wantedMinor = theVersion%10; wantedMinor = theVersion%10;
} }
return new MED::TWrapper(fileName, true, wantedMajor, wantedMinor); return new MED::TWrapper(fileName, true, tfileInst, wantedMajor, wantedMinor);
} }
} }

View File

@ -47,7 +47,7 @@ namespace MED
PWrapper CrWrapperR( const std::string& ); PWrapper CrWrapperR( const std::string& );
MEDWRAPPER_EXPORT 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 #endif // MED_Factory_HeaderFile

View File

@ -0,0 +1,93 @@
// 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 const TIdt& Id() const = 0;
};
class MEDIDTHoder : public TFileInternal
{
protected:
MEDIDTHoder(bool *isClosedStatus = nullptr):_isClosedStatus(isClosedStatus) { }
void UnRefFid()
{
if (--myCount == 0)
{
MEDfileClose(myFid);
myIsClosed = true;
if(_isClosedStatus)
*_isClosedStatus = true;
}
}
public:
const TIdt& Id() const override;
~MEDIDTHoder() { this->UnRefFid(); }
void Close() override { this->UnRefFid(); }
protected:
TInt myCount = 0;
TIdt myFid = 0;
bool myIsClosed = false;
bool *_isClosedStatus = nullptr;
};
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 !"); }
~TFileDecorator() { delete _effective; }
private:
TFileInternal *_effective = nullptr;
};
class TMemFile : public MEDIDTHoder
{
public:
TMemFile(bool* isClosedStatus = nullptr):MEDIDTHoder(isClosedStatus) { }
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;
};
}

View File

@ -23,7 +23,9 @@
#include "MED_Wrapper.hxx" #include "MED_Wrapper.hxx"
#include "MED_TStructures.hxx" #include "MED_TStructures.hxx"
#include "MED_Utilities.hxx" #include "MED_Utilities.hxx"
#include "MED_TFile.hxx"
#include "MEDFileUtilities.hxx"
#include <med.h> #include <med.h>
#include <med_err.h> #include <med_err.h>
#include <med_proto.h> #include <med_proto.h>
@ -76,90 +78,75 @@ namespace MED
} }
//--------------------------------------------------------------- //---------------------------------------------------------------
class TFile const TIdt& MEDIDTHoder::Id() const
{ {
TFile(); if (myFid < 0)
TFile(const TFile&); EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
return myFid;
}
public: void TMemFile::Open(EModeAcces theMode, TErr* theErr)
TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1): {
myCount(0), if (this->myCount++ == 0)
myFid(0),
myFileName(theFileName),
myMajor(theMajor),
myMinor(theMinor)
{ {
if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM; std::string dftFileName = MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInMem();
if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM; 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() TFile::TFile(const std::string& theFileName, TInt theMajor, TInt theMinor):
{ myFileName(theFileName),
Close(); 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 void TFile::Open(EModeAcces theMode, TErr* theErr)
Open(EModeAcces theMode, {
TErr* theErr = NULL) if (myCount++ == 0) {
{ const char* aFileName = myFileName.c_str();
if (myCount++ == 0) {
const char* aFileName = myFileName.c_str();
#ifdef WIN32 #ifdef WIN32
if (med_access_mode(theMode) == MED_ACC_RDWR) { if (med_access_mode(theMode) == MED_ACC_RDWR) {
// Force removing readonly attribute from a file under Windows, because of a bug in the HDF5 // 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"; std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1";
#ifdef UNICODE #ifdef UNICODE
const char* to_decode = aReadOlnyRmCmd.c_str(); const char* to_decode = aReadOlnyRmCmd.c_str();
int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0); int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0);
wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1]; wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1];
MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed); MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed);
awReadOlnyRmCmd[size_needed] = '\0'; awReadOlnyRmCmd[size_needed] = '\0';
_wsystem(awReadOlnyRmCmd); _wsystem(awReadOlnyRmCmd);
delete[] awReadOlnyRmCmd; delete[] awReadOlnyRmCmd;
#else #else
system(aReadOlnyRmCmd.c_str()); system(aReadOlnyRmCmd.c_str());
#endif #endif
}
#endif
myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
} }
if (theErr) #endif
*theErr = TErr(myFid); myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
else if (myFid < 0)
EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< myMajor <<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
} }
if (theErr)
const TIdt& *theErr = TErr(myFid);
Id() const else if (myFid < 0)
{ EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< myMajor <<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
if (myFid < 0) }
EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
return myFid;
}
void
Close()
{
if (--myCount == 0)
MEDfileClose(myFid);
}
protected:
TInt myCount;
TIdt myFid;
std::string myFileName;
TInt myMajor;
TInt myMinor;
};
//--------------------------------------------------------------- //---------------------------------------------------------------
class TFileWrapper class TFileWrapper
{ {
PFile myFile; PFileInternal myFile;
TInt myMinor; TInt myMinor;
public: public:
TFileWrapper(const PFile& theFile, TFileWrapper(const PFileInternal& theFile,
EModeAcces theMode, EModeAcces theMode,
TErr* theErr = NULL, TErr* theErr = NULL,
TInt theMinor=-1): TInt theMinor=-1):
@ -211,11 +198,15 @@ namespace MED
//--------------------------------------------------------------- //---------------------------------------------------------------
TWrapper TWrapper
::TWrapper(const std::string& theFileName, bool write, TInt theMajor, TInt theMinor): ::TWrapper(const std::string& theFileName, bool write, TFileInternal *tfileInst, TInt theMajor, TInt theMinor):
myFile(new TFile(theFileName, theMajor, theMinor)),
myMajor(theMajor), myMajor(theMajor),
myMinor(theMinor) myMinor(theMinor)
{ {
if(!tfileInst)
myFile.reset(new TFile(theFileName, theMajor, theMinor) );
else
myFile.reset(new TFileDecorator(tfileInst) );
TErr aRet; TErr aRet;
if ( write ) { if ( write ) {
myFile->Open(eLECTURE_ECRITURE, &aRet); myFile->Open(eLECTURE_ECRITURE, &aRet);

View File

@ -32,8 +32,8 @@
namespace MED namespace MED
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
class TFile; class TFileInternal;
typedef boost::shared_ptr<TFile> PFile; typedef std::shared_ptr<TFileInternal> PFileInternal;
typedef enum {eLECTURE, eLECTURE_ECRITURE, eLECTURE_AJOUT, eCREATION} EModeAcces; typedef enum {eLECTURE, eLECTURE_ECRITURE, eLECTURE_AJOUT, eCREATION} EModeAcces;
@ -52,7 +52,7 @@ namespace MED
TWrapper& operator=(const TWrapper&); TWrapper& operator=(const TWrapper&);
public: 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 virtual
~TWrapper(); ~TWrapper();
@ -938,7 +938,7 @@ namespace MED
TErr* theErr = NULL); TErr* theErr = NULL);
protected: protected:
PFile myFile; PFileInternal myFile;
TInt myMajor; TInt myMajor;
TInt myMinor; TInt myMinor;
}; };
@ -963,23 +963,23 @@ namespace MED
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//! Specialization of SharedPtr for TWrapper //! Specialization of SharedPtr for TWrapper
template<> template<>
class MEDWRAPPER_EXPORT SharedPtr<TWrapper>: public boost::shared_ptr<TWrapper> class MEDWRAPPER_EXPORT SharedPtr<TWrapper>: public std::shared_ptr<TWrapper>
{ {
public: public:
SharedPtr() {} SharedPtr() {}
SharedPtr(TWrapper* p): SharedPtr(TWrapper* p):
boost::shared_ptr<TWrapper>(p) std::shared_ptr<TWrapper>(p)
{} {}
template<class Y> template<class Y>
explicit SharedPtr(Y* p): explicit SharedPtr(Y* p):
boost::shared_ptr<TWrapper>(p) std::shared_ptr<TWrapper>(p)
{} {}
template<class Y> template<class Y>
SharedPtr(const SharedPtr<Y>& r): SharedPtr(const SharedPtr<Y>& r):
boost::shared_ptr<TWrapper>(boost::dynamic_pointer_cast<TWrapper,Y>(r)) std::shared_ptr<TWrapper>(boost::dynamic_pointer_cast<TWrapper,Y>(r))
{} {}
template<class Y> template<class Y>
@ -1021,7 +1021,7 @@ namespace MED
TWrapper* TWrapper*
get() const // never throws get() const // never throws
{ {
return boost::shared_ptr<TWrapper>::get(); return std::shared_ptr<TWrapper>::get();
} }
}; };
} }

View File

@ -1392,48 +1392,17 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
return false; return false;
} }
//================================================================================ void SMESH_Mesh::ExportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
/*!
* \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, const char* theMeshName,
bool theAutoGroups, bool theAutoGroups,
int theVersion,
const SMESHDS_Mesh* meshPart, const SMESHDS_Mesh* meshPart,
bool theAutoDimension, bool theAutoDimension,
bool theAddODOnVertices, bool theAddODOnVertices,
double theZTolerance, double theZTolerance,
bool theAllElemsToGroup) bool theAllElemsToGroup)
{ {
MESSAGE("MED_VERSION:"<< theVersion); Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
Driver_Mesh::Status status;
SMESH_TRY; SMESH_TRY;
DriverMED_W_SMESHDS_Mesh myWriter;
myWriter.SetFile ( file , theVersion);
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension ); myWriter.SetAutoDimension( theAutoDimension );
myWriter.AddODOnVertices ( theAddODOnVertices ); myWriter.AddODOnVertices ( theAddODOnVertices );
@ -1492,6 +1461,64 @@ void SMESH_Mesh::ExportMED(const char * file,
throw TooLargeForExport("MED"); 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 * \brief Export the mesh to a SAUV file

View File

@ -41,6 +41,8 @@
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx> #include <TopTools_ListOfShape.hxx>
#include "MEDCouplingMemArray.hxx"
#include <map> #include <map>
#include <list> #include <list>
#include <vector> #include <vector>
@ -62,6 +64,8 @@ class SMESH_HypoFilter;
class SMESH_subMesh; class SMESH_subMesh;
class TopoDS_Solid; class TopoDS_Solid;
class DriverMED_W_SMESHDS_Mesh;
typedef std::list<int> TListOfInt; typedef std::list<int> TListOfInt;
typedef std::list<TListOfInt> TListOfListOfInt; typedef std::list<TListOfInt> TListOfListOfInt;
@ -261,6 +265,15 @@ class SMESH_EXPORT SMESH_Mesh
TooLargeForExport(const char* format):runtime_error(format) {} 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, void ExportMED(const char * theFile,
const char* theMeshName = NULL, const char* theMeshName = NULL,
bool theAutoGroups = true, bool theAutoGroups = true,
@ -372,6 +385,16 @@ class SMESH_EXPORT SMESH_Mesh
private: 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 fillAncestorsMap(const TopoDS_Shape& theShape);
void getAncestorsSubMeshes(const TopoDS_Shape& theSubShape, void getAncestorsSubMeshes(const TopoDS_Shape& theSubShape,
std::vector< SMESH_subMesh* >& theSubMeshes) const; std::vector< SMESH_subMesh* >& theSubMeshes) const;

View File

@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${OpenCASCADE_INCLUDE_DIR} ${OpenCASCADE_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/Controls ${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/Driver ${PROJECT_SOURCE_DIR}/src/Driver
${PROJECT_SOURCE_DIR}/src/DriverDAT ${PROJECT_SOURCE_DIR}/src/DriverDAT

View File

@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/OBJECT ${PROJECT_SOURCE_DIR}/src/OBJECT
${PROJECT_SOURCE_DIR}/src/SMESHFiltersSelection ${PROJECT_SOURCE_DIR}/src/SMESHFiltersSelection
${PROJECT_SOURCE_DIR}/src/SMDS ${PROJECT_SOURCE_DIR}/src/SMDS

View File

@ -28,6 +28,7 @@ INCLUDE_DIRECTORIES(
${KERNEL_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS}
${GUI_INCLUDE_DIRS} ${GUI_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS} ${GEOM_INCLUDE_DIRS}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/Controls ${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/SMDS ${PROJECT_SOURCE_DIR}/src/SMDS
${PROJECT_SOURCE_DIR}/src/SMESHDS ${PROJECT_SOURCE_DIR}/src/SMESHDS

View File

@ -23,6 +23,8 @@
#include "SALOME_Container_i.hxx" #include "SALOME_Container_i.hxx"
#include "SALOME_KernelServices.hxx" #include "SALOME_KernelServices.hxx"
#include "SALOME_Fake_NamingService.hxx"
#include <cstring> #include <cstring>
static Engines::EngineComponent_var _unique_compo; static Engines::EngineComponent_var _unique_compo;
@ -46,6 +48,8 @@ Engines::EngineComponent_var RetrieveSMESHInstance()
// //
pman->activate(); 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"); SMESH_Gen_No_Session_i *servant = new SMESH_Gen_No_Session_i(orb, poa, conId, "SMESH_inst_2", "SMESH");
PortableServer::ObjectId *zeId = servant->getId(); PortableServer::ObjectId *zeId = servant->getId();
CORBA::Object_var zeRef = poa->id_to_reference(*zeId); CORBA::Object_var zeRef = poa->id_to_reference(*zeId);

View File

@ -29,7 +29,6 @@ SMESH_Gen_No_Session_i::SMESH_Gen_No_Session_i( CORBA::ORB_ptr orb,
const char* instanceName, 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,false)
{ {
myNS = new SALOME_Fake_NamingService;
} }
GEOM::GEOM_Gen_var SMESH_Gen_No_Session_i::GetGeomEngine( bool isShaper ) GEOM::GEOM_Gen_var SMESH_Gen_No_Session_i::GetGeomEngine( bool isShaper )

View File

@ -237,6 +237,14 @@ CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject
return anObj; return anObj;
} }
// Set Naming Service object
void SMESH_Gen_i::SetNS(SALOME_NamingService_Abstract *ns)
{
if(myNS)
delete myNS;
myNS = ns;
}
//============================================================================= //=============================================================================
/*! /*!
* GetNS [ static ] * GetNS [ static ]
@ -247,7 +255,7 @@ CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject
SALOME_NamingService_Abstract* SMESH_Gen_i::GetNS() SALOME_NamingService_Abstract* SMESH_Gen_i::GetNS()
{ {
if ( myNS == NULL ) { if ( !myNS ) {
myNS = SINGLETON_<SALOME_NamingService>::Instance(); myNS = SINGLETON_<SALOME_NamingService>::Instance();
ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()); ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
myNS->init_orb( GetORB() ); myNS->init_orb( GetORB() );

View File

@ -104,6 +104,8 @@ public:
static CORBA::ORB_var GetORB() { return myOrb;} static CORBA::ORB_var GetORB() { return myOrb;}
// Get SMESH module's POA object // Get SMESH module's POA object
static PortableServer::POA_var GetPOA() { return myPoa;} static PortableServer::POA_var GetPOA() { return myPoa;}
// Set Naming Service object
static void SetNS(SALOME_NamingService_Abstract *ns);
// Get Naming Service object // Get Naming Service object
static SALOME_NamingService_Abstract* GetNS(); static SALOME_NamingService_Abstract* GetNS();
// Get SALOME_LifeCycleCORBA object // Get SALOME_LifeCycleCORBA object

View File

@ -3684,6 +3684,25 @@ void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
} }
} }
/*!
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 * \brief Prepare a file for export and pass names of mesh groups from study to mesh DS
@ -3698,13 +3717,11 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
{ {
// Perform Export // Perform Export
PrepareForWriting(file, overwrite); PrepareForWriting(file, overwrite);
string aMeshName = "Mesh"; string aMeshName(this->generateMeshName());
SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant(); SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
if ( !aStudy->_is_nil() ) { if ( !aStudy->_is_nil() ) {
SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() ); SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
if ( !aMeshSO->_is_nil() ) { 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 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
if ( !aStudy->GetProperties()->IsLocked() ) if ( !aStudy->GetProperties()->IsLocked() )
{ {
@ -3763,6 +3780,23 @@ void SMESH_Mesh_i::ExportMED(const char* file,
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );
} }
CORBA::LongLong SMESH_Mesh_i::ExportMEDCoupling(CORBA::Boolean auto_groups, CORBA::Boolean autoDimension)
{
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
SMESH_TRY;
// TODO : Fix me ! 2 next lines are required
//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 * \brief Export a mesh to a SAUV file
@ -3862,23 +3896,47 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ class MEDFileSpeCls
/*! {
* \brief Export a part of mesh to a med file public:
*/ MEDFileSpeCls(const char *file, CORBA::Boolean overwrite, CORBA::Long version):_file(file),_overwrite(overwrite),_version(version) { }
//================================================================================ std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self) { return self.prepareMeshNameAndGroups(_file.c_str(),_overwrite); }
void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, SMESH_MeshPartDS* partDS,
const char* file, CORBA::Boolean autoDimension, bool have0dField,
CORBA::Boolean auto_groups, CORBA::Double ZTolerance)
CORBA::Long version, {
CORBA::Boolean overwrite, mesh->ExportMED( _file.c_str(), aMeshName.c_str(), auto_groups, _version,
CORBA::Boolean autoDimension, partDS, autoDimension,have0dField,ZTolerance);
const GEOM::ListOfFields& fields,
const char* geomAssocFields, }
CORBA::Double ZTolerance)
void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField, SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields, const char*geomAssocFields)
{
DriverMED_W_Field fieldWriter;
fieldWriter.SetFile( _file.c_str() );
fieldWriter.SetMeshName( aMeshName );
fieldWriter.AddODOnVertices( have0dField );
self.exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
}
void prepareForWriting(SMESH_Mesh_i& self) { self.PrepareForWriting(_file.c_str(), _overwrite); }
private:
std::string _file;
CORBA::Boolean _overwrite;
CORBA::Long _version;
};
template<class SPECLS>
void SMESH_Mesh_i::ExportPartToMEDCommon(SPECLS& speCls,
SMESH::SMESH_IDSource_ptr meshPart,
CORBA::Boolean auto_groups,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance)
{ {
MESSAGE("MED version: "<< version);
SMESH_TRY; SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -3924,10 +3982,8 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
if ( CORBA::is_nil( meshPart ) || if ( CORBA::is_nil( meshPart ) ||
SMESH::DownCast< SMESH_Mesh_i* >( meshPart )) SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{ {
aMeshName = prepareMeshNameAndGroups(file, overwrite); aMeshName = speCls.prepareMeshNameAndGroups(*this);
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, speCls.exportTo(_impl, aMeshName, auto_groups, nullptr, autoDimension, have0dField, ZTolerance);
0, autoDimension, /*addODOnVertices=*/have0dField,
ZTolerance);
meshDS = _impl->GetMeshDS(); meshDS = _impl->GetMeshDS();
} }
else else
@ -3935,7 +3991,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
PrepareForWriting(file, overwrite); speCls.prepareForWriting(*this);
SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( meshPart ); SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( meshPart );
if ( !SO->_is_nil() ) { if ( !SO->_is_nil() ) {
@ -3944,8 +4000,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
} }
SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart ); SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, speCls.exportTo(_impl, aMeshName, auto_groups, partDS, autoDimension, have0dField, ZTolerance);
partDS, autoDimension, /*addODOnVertices=*/have0dField, ZTolerance);
meshDS = tmpDSDeleter._obj = partDS; meshDS = tmpDSDeleter._obj = partDS;
} }
@ -3953,15 +4008,32 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
if ( _impl->HasShapeToMesh() ) if ( _impl->HasShapeToMesh() )
{ {
DriverMED_W_Field fieldWriter; speCls.exportField(*this,aMeshName,have0dField,meshDS,fields,geomAssocFields);
fieldWriter.SetFile( file );
fieldWriter.SetMeshName( aMeshName );
fieldWriter.AddODOnVertices( have0dField );
exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
} }
SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
/*!
* \brief Export a part of mesh to a med file
*/
//================================================================================
void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance)
{
MESSAGE("MED version: "<< version);
MEDFileSpeCls spe(file,overwrite,version);
this->ExportPartToMEDCommon<MEDFileSpeCls>(spe,meshPart,auto_groups,autoDimension,fields,geomAssocFields,ZTolerance);
// dump // dump
SMESH_TRY;
GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO; GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO;
goList->length( fields.length() ); goList->length( fields.length() );
for ( size_t i = 0; i < fields.length(); ++i ) for ( size_t i = 0; i < fields.length(); ++i )
@ -3980,10 +4052,45 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
<< ( geomAssocFields ? geomAssocFields : "" ) << "'," << ( geomAssocFields ? geomAssocFields : "" ) << "',"
<< TVar( ZTolerance ) << TVar( ZTolerance )
<< " )"; << " )";
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );
} }
class MEDFileMemSpeCls
{
public:
std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self) { return self.generateMeshName(); }
void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
SMESH_MeshPartDS* partDS,
CORBA::Boolean autoDimension, bool have0dField,
CORBA::Double ZTolerance)
{
_res = mesh->ExportMEDCoupling(aMeshName.c_str(),auto_groups,partDS,autoDimension,have0dField,ZTolerance);
}
void prepareForWriting(SMESH_Mesh_i& self) { /* nothing here */ }
void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField, SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields, const char*geomAssocFields)
{
THROW_IK_EXCEPTION("exportField Not implemented yet for full memory !");
}
public:
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> getData() { return _res; }
private:
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> _res;
};
CORBA::LongLong SMESH_Mesh_i::ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
CORBA::Boolean auto_groups,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance)
{
MEDFileMemSpeCls spe;
this->ExportPartToMEDCommon<MEDFileMemSpeCls>(spe,meshPart,auto_groups,autoDimension,fields,geomAssocFields,ZTolerance);
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> res( spe.getData() );
MEDCoupling::DataArrayByte *ret(res.retn());
return reinterpret_cast<CORBA::LongLong>(ret);
}
//================================================================================ //================================================================================
/*! /*!
* Write GEOM fields to MED file * Write GEOM fields to MED file

View File

@ -212,6 +212,10 @@ public:
CORBA::Boolean overwrite, CORBA::Boolean overwrite,
CORBA::Boolean autoDimension = true); 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 ExportSAUV( const char* file, CORBA::Boolean auto_groups );
void ExportDAT( const char* file ); void ExportDAT( const char* file );
@ -225,6 +229,16 @@ public:
const char* file, const char* file,
CORBA::Boolean withRequiredGroups); CORBA::Boolean withRequiredGroups);
template<class SPECLS>
void ExportPartToMEDCommon(SPECLS& speCls,
SMESH::SMESH_IDSource_ptr meshPart,
CORBA::Boolean auto_groups,
CORBA::Boolean autoDim,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance);
void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file, const char* file,
CORBA::Boolean auto_groups, CORBA::Boolean auto_groups,
@ -234,6 +248,14 @@ public:
const GEOM::ListOfFields& fields, const GEOM::ListOfFields& fields,
const char* geomAssocFields, const char* geomAssocFields,
CORBA::Double ZTolerance); CORBA::Double ZTolerance);
CORBA::LongLong ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
CORBA::Boolean auto_groups,
CORBA::Boolean autoDim,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance);
void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart, void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
const char* file); const char* file);
void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart, void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
@ -626,14 +648,9 @@ public:
std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
private: public:
std::string generateMeshName( );
std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite ); std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite );
/*!
* Check and correct names of mesh groups
*/
void checkGroupNames();
/* /*
* Write GEOM fields to MED file * Write GEOM fields to MED file
*/ */
@ -641,6 +658,12 @@ private:
SMESHDS_Mesh* meshDS, SMESHDS_Mesh* meshDS,
const GEOM::ListOfFields& fields, const GEOM::ListOfFields& fields,
const char* geomAssocFields); const char* geomAssocFields);
private:
/*!
* Check and correct names of mesh groups
*/
void checkGroupNames();
/*! /*!
* Convert submesh ids into submesh interfaces * Convert submesh ids into submesh interfaces
*/ */

View File

@ -2299,6 +2299,69 @@ class Mesh(metaclass = MeshMeta):
self.mesh.RemoveHypothesis( self.geom, hyp ) self.mesh.RemoveHypothesis( self.geom, hyp )
pass pass
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)
return self.mesh.ExportPartToMEDCoupling(meshPart, auto_groups, autoDimension, fields, geomAssocFields, z_tolerance)
else:
intPtr = self.mesh.ExportMEDCoupling(auto_groups, autoDimension)
import medcoupling
dab = medcoupling.FromPyIntPtrToDataArrayByte(intPtr)
return medcoupling.MEDFileMesh.New(dab)
def ExportMED(self, *args, **kwargs): def ExportMED(self, *args, **kwargs):
""" """
Export the mesh in a file in MED format Export the mesh in a file in MED format

View File

@ -29,6 +29,7 @@ INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${KERNEL_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS} ${GEOM_INCLUDE_DIRS}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESHUtils ${PROJECT_SOURCE_DIR}/src/SMESHUtils
${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHDS ${PROJECT_SOURCE_DIR}/src/SMESHDS

View File

@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${QWT_INCLUDE_DIR} ${QWT_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHUtils ${PROJECT_SOURCE_DIR}/src/SMESHUtils
${PROJECT_SOURCE_DIR}/src/SMESH_I ${PROJECT_SOURCE_DIR}/src/SMESH_I

View File

@ -27,6 +27,7 @@ INCLUDE_DIRECTORIES(
${MEDFILE_INCLUDE_DIRS} ${MEDFILE_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESHImpl ${PROJECT_SOURCE_DIR}/src/SMESHImpl
${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESHUtils ${PROJECT_SOURCE_DIR}/src/SMESHUtils

View File

@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}
${MEDCOUPLING_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESH_I ${PROJECT_SOURCE_DIR}/src/SMESH_I
${PROJECT_SOURCE_DIR}/src/SMESHDS ${PROJECT_SOURCE_DIR}/src/SMESHDS