reintroduction of choice of MED minor version when exporting MED files

This commit is contained in:
Paul RASCLE 2018-07-13 15:35:34 +02:00
parent 1b80c8bc60
commit 49ff23c94f
15 changed files with 254 additions and 103 deletions

View File

@ -622,6 +622,10 @@ module SMESH
* 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, if it exists
* - minor : define the minor version of MED file format.
* The minor must be between 0 and the current minor version of MED file library.
* If minor is equal to -1, the minor version is not changed (default).
* The major version cannot be changed.
* - autoDimension : 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
@ -630,6 +634,7 @@ module SMESH
*/
void ExportMED( in string fileName,
in boolean auto_groups,
in long minor,
in boolean overwrite,
in boolean autoDimension) raises (SALOME::SALOME_Exception);
@ -639,6 +644,10 @@ module SMESH
* - meshPart : a part of mesh to store
* - fileName : name of the MED file
* - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists
* - minor : define the minor version (y, where version is x.y.z) of MED file format.
* The minor must be between 0 and the current minor version of MED file library.
* If minor is equal to -1, the minor version is not changed (default).
* The major version (x, where version is x.y.z) cannot be changed.
* - autoDimension : if @c True, a space dimension for export is defined by mesh
* configuration; for example a planar mesh lying on XOY plane
* will be exported as a mesh in 2D space.
@ -654,6 +663,7 @@ module SMESH
void ExportPartToMED( in SMESH_IDSource meshPart,
in string fileName,
in boolean auto_groups,
in long minor,
in boolean overwrite,
in boolean autoDimension,
in GEOM::ListOfFields fields,
@ -666,6 +676,11 @@ module SMESH
void ExportSAUV( in string file, in boolean auto_groups )
raises (SALOME::SALOME_Exception);
/*!
* Return string representation of a MED file version comprising nbDigits
*/
string GetVersionString(in long minor, in short nbDigits);
/*!
* Export Mesh to different Formats
* (UNV supported version is I-DEAS 10)

View File

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

View File

@ -35,6 +35,8 @@
#include "SMDS_SetIterator.hxx"
#include "SMESHDS_Mesh.hxx"
#include <med.h>
#include <BRep_Tool.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
@ -62,11 +64,41 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
myDoAllInGroups(false)
{}
void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor)
{
myMinor = theMinor;
Driver_SMESHDS_Mesh::SetFile(theFileName);
}
/*!
* MED version is either the latest available, or with an inferior minor,
* to ensure backward compatibility on writing med files.
*/
string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theVersion, int theNbDigits)
{
TInt majeur, mineur, release;
majeur=MED_MAJOR_NUM;
mineur=MED_MINOR_NUM;
release=MED_RELEASE_NUM;
TInt imposedMineur = mineur;
if (theVersion < 0)
imposedMineur = mineur;
else if (theVersion > MED_MINOR_NUM)
imposedMineur = mineur;
else
imposedMineur = theVersion;
ostringstream name;
if ( theNbDigits > 0 )
name << majeur;
if ( theNbDigits > 1 )
name << "." << imposedMineur;
if ( theNbDigits > 2 )
name << "." << release;
return name.str();
}
void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
{
myGroups.push_back(theGroup);
@ -425,7 +457,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
}
}
MED::PWrapper myMed = CrWrapperW(myFile);
MED::PWrapper myMed = CrWrapperW(myFile, myMinor);
PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
//MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
myMed->SetMeshInfo(aMeshInfo);

View File

@ -48,9 +48,11 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
DriverMED_W_SMESHDS_Mesh();
void SetFile(const std::string& theFileName);
void SetFile(const std::string& theFileName, int theMinor=-1);
void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; }
static std::string GetVersionString(int theVersion, int theNbDigits=2);
void AddGroupOfNodes();
void AddGroupOfEdges();
void AddGroupOfFaces();
@ -87,6 +89,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
bool myAutoDimension;
bool myAddODOnVertices;
bool myDoAllInGroups;
int myMinor;
};
#endif

View File

@ -111,10 +111,10 @@ namespace MED
return new MED::TWrapper(fileName);
}
PWrapper CrWrapperW(const std::string& fileName)
PWrapper CrWrapperW(const std::string& fileName, int theMinor)
{
if (!CheckCompatibility(fileName))
remove(fileName.c_str());
return new MED::TWrapper(fileName);
return new MED::TWrapper(fileName, theMinor);
}
}

View File

@ -43,7 +43,7 @@ namespace MED
PWrapper CrWrapperR( const std::string& );
MEDWRAPPER_EXPORT
PWrapper CrWrapperW( const std::string& );
PWrapper CrWrapperW( const std::string&, int theMinor=-1 );
}
#endif // MED_Factory_HeaderFile

View File

@ -26,6 +26,7 @@
#include <med.h>
#include <med_err.h>
#include <med_proto.h>
#include <boost/version.hpp>
@ -77,11 +78,14 @@ namespace MED
TFile(const TFile&);
public:
TFile(const std::string& theFileName):
TFile(const std::string& theFileName, TInt theMinor=-1):
myCount(0),
myFid(0),
myFileName(theFileName)
{}
myFileName(theFileName),
myMinor(theMinor)
{
if ((myMinor < 0) || (myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
}
~TFile()
{
@ -94,12 +98,12 @@ namespace MED
{
if (myCount++ == 0) {
const char* aFileName = myFileName.c_str();
myFid = MEDfileOpen(aFileName, med_access_mode(theMode));
myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), MED_MAJOR_NUM, myMinor, MED_RELEASE_NUM);
}
if (theErr)
*theErr = TErr(myFid);
else if (myFid < 0)
EXCEPTION(std::runtime_error, "TFile - MEDfileOpen('"<<myFileName<<"',"<<theMode<<")");
EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< MED_MAJOR_NUM<<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
}
const TIdt&
@ -121,19 +125,24 @@ namespace MED
TInt myCount;
TIdt myFid;
std::string myFileName;
TInt myMinor;
};
//---------------------------------------------------------------
class TFileWrapper
{
PFile myFile;
TInt myMinor;
public:
TFileWrapper(const PFile& theFile,
EModeAcces theMode,
TErr* theErr = NULL):
myFile(theFile)
TErr* theErr = NULL,
TInt theMinor=-1):
myFile(theFile),
myMinor(theMinor)
{
if (myMinor < 0) myMinor = MED_MINOR_NUM;
myFile->Open(theMode, theErr);
}
@ -178,8 +187,9 @@ namespace MED
//---------------------------------------------------------------
TWrapper
::TWrapper(const std::string& theFileName):
myFile(new TFile(theFileName))
::TWrapper(const std::string& theFileName, TInt theMinor):
myMinor(theMinor),
myFile(new TFile(theFileName, theMinor))
{
TErr aRet;
myFile->Open(eLECTURE_ECRITURE, &aRet);
@ -208,7 +218,7 @@ namespace MED
TWrapper
::GetNbMeshes(TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -223,7 +233,7 @@ namespace MED
MED::TMeshInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -284,7 +294,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -368,7 +378,7 @@ namespace MED
::GetNbFamilies(const MED::TMeshInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -385,7 +395,7 @@ namespace MED
const MED::TMeshInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -404,7 +414,7 @@ namespace MED
const MED::TMeshInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -423,7 +433,7 @@ namespace MED
MED::TFamilyInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -481,7 +491,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -603,7 +613,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -652,7 +662,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -694,7 +704,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -743,7 +753,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -785,7 +795,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -843,7 +853,7 @@ namespace MED
EGeometrieElement theGeom,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -890,7 +900,7 @@ namespace MED
ETable theTable,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -918,7 +928,7 @@ namespace MED
::GetNodeInfo(MED::TNodeInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1009,7 +1019,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1320,7 +1330,7 @@ namespace MED
EConnectivite theConnMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return 0;
@ -1353,7 +1363,7 @@ namespace MED
::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1412,7 +1422,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1564,7 +1574,7 @@ namespace MED
EConnectivite theConnMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
@ -1610,7 +1620,7 @@ namespace MED
::GetPolyedreInfo(TPolyedreInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1673,7 +1683,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -1869,7 +1879,7 @@ namespace MED
{
TEntityInfo anInfo;
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return anInfo;
@ -1981,7 +1991,7 @@ namespace MED
EConnectivite theConnMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -2030,7 +2040,7 @@ namespace MED
::GetCellInfo(MED::TCellInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -2097,7 +2107,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -2275,7 +2285,8 @@ namespace MED
TWrapper
::GetBallGeom(const TMeshInfo& theMeshInfo)
{
TFileWrapper aFileWrapper(myFile, eLECTURE);
TErr anError;
TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
// read med_geometry_type of "MED_BALL" element
char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
@ -2287,7 +2298,8 @@ namespace MED
TWrapper
::GetNbBalls(const TMeshInfo& theMeshInfo)
{
TFileWrapper aFileWrapper(myFile, eLECTURE);
TErr anError;
TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
EGeometrieElement ballType = GetBallGeom(theMeshInfo);
if (ballType < 0)
@ -2302,7 +2314,7 @@ namespace MED
::GetBallInfo(TBallInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
// check geometry of MED_BALL
if (theInfo.myGeom == eBALL)
@ -2352,7 +2364,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
TErr ret;
char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
@ -2480,7 +2492,7 @@ namespace MED
TWrapper
::GetNbFields(TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -2494,7 +2506,7 @@ namespace MED
::GetNbComp(TInt theFieldId,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -2509,7 +2521,7 @@ namespace MED
MED::TFieldInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -2574,7 +2586,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -2661,7 +2673,7 @@ namespace MED
TWrapper
::GetNbGauss(TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -2675,7 +2687,7 @@ namespace MED
::GetGaussPreInfo(TInt theId,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
@ -2715,7 +2727,7 @@ namespace MED
TGaussInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -2761,7 +2773,7 @@ namespace MED
TErr* theErr)
{
theEntity = EEntiteMaillage(-1);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr) {
if (theEntityInfo.empty())
@ -2884,7 +2896,7 @@ namespace MED
MED::TTimeStampInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
@ -3037,7 +3049,7 @@ namespace MED
TWrapper
::GetNbProfiles(TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
@ -3051,7 +3063,7 @@ namespace MED
::GetProfilePreInfo(TInt theId,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return TProfileInfo::TInfo();
@ -3079,7 +3091,7 @@ namespace MED
TProfileInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -3124,7 +3136,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -3177,7 +3189,7 @@ namespace MED
const TKey2Gauss& theKey2Gauss,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -3361,7 +3373,7 @@ namespace MED
EModeAcces theMode,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -3698,7 +3710,7 @@ namespace MED
::GetGrilleInfo(TGrilleInfo& theInfo,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -3868,7 +3880,7 @@ namespace MED
{
if (theInfo.myMeshInfo->myType != eSTRUCTURE)
return;
TFileWrapper aFileWrapper(myFile, theMode, theErr);
TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
@ -4003,7 +4015,7 @@ namespace MED
EGrilleType& theGridType,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)");
@ -4029,7 +4041,7 @@ namespace MED
TIntVector& theStruct,
TErr* theErr)
{
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;

View File

@ -52,7 +52,7 @@ namespace MED
TWrapper& operator=(const TWrapper&);
public:
TWrapper(const std::string& theFileName);
TWrapper(const std::string& theFileName, TInt theMinor=-1);
virtual
~TWrapper();
@ -939,6 +939,7 @@ namespace MED
protected:
PFile myFile;
TInt myMinor;
};
//----------------------------------------------------------------------------

View File

@ -1402,6 +1402,10 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
* \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] theMinor - define the minor version (y, where version is x.y.z) of MED file format.
* The theMinor must be between 0 and the current minor version of MED file library.
* If theMinor is equal to -1, the minor version is not changed (default).
* The major version (x, where version is x.y.z) cannot be changed.
* \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
@ -1417,6 +1421,7 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
void SMESH_Mesh::ExportMED(const char * file,
const char* theMeshName,
bool theAutoGroups,
int theMinor,
const SMESHDS_Mesh* meshPart,
bool theAutoDimension,
bool theAddODOnVertices,
@ -1427,7 +1432,7 @@ void SMESH_Mesh::ExportMED(const char * file,
SMESH_TRY;
DriverMED_W_SMESHDS_Mesh myWriter;
myWriter.SetFile ( file );
myWriter.SetFile ( file , theMinor);
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension );
myWriter.AddODOnVertices ( theAddODOnVertices );

View File

@ -254,6 +254,7 @@ class SMESH_EXPORT SMESH_Mesh
void ExportMED(const char * theFile,
const char* theMeshName = NULL,
bool theAutoGroups = true,
int TheMinor = -1,
const SMESHDS_Mesh* theMeshPart = 0,
bool theAutoDimension = false,
bool theAddODOnVertices = false,

View File

@ -655,6 +655,8 @@ namespace
// Get parameters of export operation
QString aFilename;
int aFormat =-1; // for MED minor versions
// Init the parameters with the default values
bool aIsASCII_STL = true;
bool toCreateGroups = false;
@ -741,14 +743,40 @@ namespace
}
else if ( isMED || isSAUV ) // Export to MED or SAUV
{
QStringList filters;
QMap<QString, int> aFilterMap;
if ( isMED ) {
filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
//filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
QString vmed (aMesh->GetVersionString(-1, 2));
MESSAGE("MED version: " << vmed.toStdString());
int minor = vmed.split(".").last().toInt();
MESSAGE("MED version minor: "<< minor);
minor +=3; // TODO test, to remove
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vmed ) + " (*.med)", minor );
for (int ii=0; ii<minor; ii++)
{
QString vs = aMesh->GetVersionString(ii, 2);
std::ostringstream vss; // TODO test, to remove
vss << "4."; //
vss << ii; //
vs = vss.str().c_str(); // TODO test, to remove
MESSAGE("MED version: " << vs.toStdString());
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", ii);
}
}
else { // isSAUV
filters << QObject::tr( "SAUV_FILES_FILTER" ) + " (*.sauv *.sauve)";
aFilterMap.insert("All files (*)", -1 );
aFilterMap.insert("SAUV files (*.sauv)", -1 );
aFilterMap.insert("SAUV files (*.sauve)", -1 );
}
QStringList filters;
QString aDefaultFilter;
QMap<QString, int>::const_iterator it = aFilterMap.begin();
for ( ; it != aFilterMap.end(); ++it ) {
filters.push_back( it.key() );
if (it.key() == 0)
aDefaultFilter = it.key();
}
QStringList checkBoxes;
checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
@ -788,6 +816,8 @@ namespace
aFilename = QString::null;
break;
}
aFormat = aFilterMap[fd->selectedNameFilter()];
MESSAGE("selected minor: " << aFormat);
toOverwrite = fv->isOverwrite();
is_ok = true;
if ( !aFilename.isEmpty() ) {
@ -879,10 +909,10 @@ namespace
const QString& geoAssFields = aFieldList[ aMeshIndex ].second;
const bool hasFields = ( fields.length() || !geoAssFields.isEmpty() );
if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ))
aMeshItem->ExportMED( aFilename.toUtf8().data(), toCreateGroups,
aMeshItem->ExportMED( aFilename.toUtf8().data(), toCreateGroups, aFormat,
toOverwrite && aMeshIndex == 0, toFindOutDim );
else
aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups,
aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups, aFormat,
toOverwrite && aMeshIndex == 0, toFindOutDim,
fields, geoAssFields.toLatin1().data() );
}

View File

@ -27,6 +27,10 @@
<source>TEXT_FILES_FILTER</source>
<translation>TXT files</translation>
</message>
<message>
<source>MED_VX_FILES_FILTER</source>
<translation>MED %1 files</translation>
</message>
<message>
<source>STL_FILES_FILTER</source>
<translation>STL files</translation>

View File

@ -448,6 +448,19 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileNa
return ConvertDriverMEDReadStatus(status);
}
//================================================================================
/*!
* \brief Return string representation of a MED file version comprising nbDigits
*/
//================================================================================
char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
{
string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor,
nbDigits);
return CORBA::string_dup( ver.c_str() );
}
//=============================================================================
/*!
* ImportUNVFile
@ -2987,22 +3000,26 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
void SMESH_Mesh_i::ExportMED(const char* file,
CORBA::Boolean auto_groups,
CORBA::Long minor,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension)
throw(SALOME::SALOME_Exception)
{
//MESSAGE("SMESH::MED_VERSION:"<< theVersion);
MESSAGE("MED minor version: "<< minor);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
string aMeshName = prepareMeshNameAndGroups(file, overwrite);
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, 0, autoDimension );
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension );
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
<< file << "', " << auto_groups << ", "
<< overwrite << ", "
<< autoDimension << " )";
<< file << "', "
<< "auto_groups=" <<auto_groups << ", "
<< "minor=" << minor << ", "
<< "overwrite=" << overwrite << ", "
<< "meshPart=None, "
<< "autoDimension=" << autoDimension << " )";
SMESH_CATCH( SMESH::throwCorbaException );
}
@ -3112,12 +3129,14 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
CORBA::Long minor,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
const char* geomAssocFields)
throw (SALOME::SALOME_Exception)
{
MESSAGE("MED minor version: "<< minor);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
@ -3164,7 +3183,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{
aMeshName = prepareMeshNameAndGroups(file, overwrite);
_impl->ExportMED( file, aMeshName.c_str(), auto_groups,
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
0, autoDimension, /*addODOnVertices=*/have0dField);
meshDS = _impl->GetMeshDS();
}
@ -3182,7 +3201,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
}
SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
_impl->ExportMED( file, aMeshName.c_str(), auto_groups,
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
partDS, autoDimension, /*addODOnVertices=*/have0dField);
meshDS = tmpDSDeleter._obj = partDS;
}
@ -3207,11 +3226,15 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] );
goList[i] = gbo;
}
TPythonDump() << _this() << ".ExportPartToMED( "
<< meshPart << ", r'" << file << "', "
<< auto_groups << ", " << overwrite << ", "
<< autoDimension << ", " << goList
<< ", '" << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
TPythonDump() << _this() << ".ExportPartToMED( r'"
<< file << "', "
<< "auto_groups=" << auto_groups << ", "
<< "minor=" << minor << ", "
<< "overwrite=" << overwrite << ", "
<< "meshPart=" << meshPart << ", "
<< "autoDimension=" << autoDimension << ", "
<< "fields=" << goList << ", geomAssocFields='"
<< ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
SMESH_CATCH( SMESH::throwCorbaException );
}

View File

@ -225,9 +225,14 @@ public:
* Consider maximum group name length stored in MED file.
*/
CORBA::Boolean HasDuplicatedGroupNamesMED();
/*!
* Return string representation of a MED file version comprising nbDigits
*/
char* GetVersionString(CORBA::Long minor, CORBA::Short nbDigits);
void ExportMED( const char* file,
CORBA::Boolean auto_groups,
CORBA::Long minor,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension = true) throw (SALOME::SALOME_Exception);
@ -247,6 +252,7 @@ public:
void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
CORBA::Long minor,
CORBA::Boolean overwrite,
CORBA::Boolean autoDim,
const GEOM::ListOfFields& fields,

View File

@ -25,8 +25,18 @@ from salome.geom import geomBuilder
import SMESH # This is necessary for back compatibility
import omniORB # back compatibility
SMESH.MED_V2_1 = omniORB.EnumItem("MED_V2_1", 0) # back compatibility
SMESH.MED_V2_2 = omniORB.EnumItem("MED_V2_2", 1) # back compatibility
SMESH.MED_V2_1 = 11 #omniORB.EnumItem("MED_V2_1", 11) # back compatibility: use number > MED minor version
SMESH.MED_V2_2 = 12 #omniORB.EnumItem("MED_V2_2", 12) # back compatibility: latest minor will be used
SMESH.MED_MINOR_0 = 20 # back compatibility
SMESH.MED_MINOR_1 = 21 # back compatibility
SMESH.MED_MINOR_2 = 22 # back compatibility
SMESH.MED_MINOR_3 = 23 # back compatibility
SMESH.MED_MINOR_4 = 24 # back compatibility
SMESH.MED_MINOR_5 = 25 # back compatibility
SMESH.MED_MINOR_6 = 26 # back compatibility
SMESH.MED_MINOR_7 = 27 # back compatibility
SMESH.MED_MINOR_8 = 28 # back compatibility
SMESH.MED_MINOR_9 = 29 # back compatibility
from SMESH import *
from salome.smesh.smesh_algorithm import Mesh_Algorithm
@ -2157,6 +2167,10 @@ class Mesh(metaclass = MeshMeta):
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.
minor (int): define the minor version (y, where version is x.y.z) of MED file format.
The minor must be between 0 and the current minor version of MED file library.
If minor is equal to -1, the minor version is not changed (default).
The major version (x, where version is x.y.z) cannot be changed.
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
@ -2175,16 +2189,18 @@ class Mesh(metaclass = MeshMeta):
- 's' stands for "_solids _" field.
"""
# process positional arguments
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
fileName = args[0]
auto_groups = args[1] if len(args) > 1 else False
overwrite = args[2] if len(args) > 2 else True
meshPart = args[3] if len(args) > 3 else None
autoDimension = args[4] if len(args) > 4 else True
fields = args[5] if len(args) > 5 else []
geomAssocFields = args[6] if len(args) > 6 else ''
minor = args[2] if len(args) > 2 else -1
overwrite = args[3] if len(args) > 3 else True
meshPart = args[4] if len(args) > 4 else None
autoDimension = args[5] if len(args) > 5 else True
fields = args[6] if len(args) > 6 else []
geomAssocFields = args[7] if len(args) > 7 else ''
# process keywords arguments
auto_groups = kwargs.get("auto_groups", auto_groups)
minor = kwargs.get("minor", minor)
overwrite = kwargs.get("overwrite", overwrite)
meshPart = kwargs.get("meshPart", meshPart)
autoDimension = kwargs.get("autoDimension", autoDimension)
@ -2196,10 +2212,10 @@ class Mesh(metaclass = MeshMeta):
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
self.mesh.ExportPartToMED( meshPart, fileName, auto_groups, overwrite, autoDimension,
self.mesh.ExportPartToMED( meshPart, fileName, auto_groups, minor, overwrite, autoDimension,
fields, geomAssocFields)
else:
self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension)
def ExportSAUV(self, f, auto_groups=0):
"""
@ -2336,7 +2352,7 @@ class Mesh(metaclass = MeshMeta):
print("WARNING: ExportToMED() is deprecated, use ExportMED() instead")
# process positional arguments
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
fileName = args[0]
auto_groups = args[1] if len(args) > 1 else False
overwrite = args[2] if len(args) > 2 else True
@ -2346,8 +2362,9 @@ class Mesh(metaclass = MeshMeta):
auto_groups = kwargs.get("auto_groups", auto_groups) # new keyword name
overwrite = kwargs.get("overwrite", overwrite)
autoDimension = kwargs.get("autoDimension", autoDimension)
minor = -1
# invoke engine's function
self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension)
def ExportToMEDX(self, *args, **kwargs):
"""
@ -2370,7 +2387,7 @@ class Mesh(metaclass = MeshMeta):
print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead")
# process positional arguments
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
fileName = args[0]
auto_groups = args[1] if len(args) > 1 else False
overwrite = args[2] if len(args) > 2 else True
@ -2379,8 +2396,9 @@ class Mesh(metaclass = MeshMeta):
auto_groups = kwargs.get("auto_groups", auto_groups)
overwrite = kwargs.get("overwrite", overwrite)
autoDimension = kwargs.get("autoDimension", autoDimension)
minor = -1
# invoke engine's function
self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension)
# Operations with groups:
# ----------------------
@ -6842,19 +6860,19 @@ class meshProxy(SMESH._objref_SMESH_Mesh):
return SMESH._objref_SMESH_Mesh.CreateDimGroup(self, *args)
def ExportToMEDX(self, *args): # function removed
print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead")
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
SMESH._objref_SMESH_Mesh.ExportMED(self, *args)
def ExportToMED(self, *args): # function removed
print("WARNING: ExportToMED() is deprecated, use ExportMED() instead")
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method
args.append(True)
SMESH._objref_SMESH_Mesh.ExportMED(self, *args)
def ExportPartToMED(self, *args): # 'version' parameter removed
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
SMESH._objref_SMESH_Mesh.ExportPartToMED(self, *args)
def ExportMED(self, *args): # signature of method changed
args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
#args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method
args.append(True)
SMESH._objref_SMESH_Mesh.ExportMED(self, *args)