myDoGroupOfBalls(false),
myAutoDimension(false),
myAddODOnVertices(false),
- myDoAllInGroups(false)
+ myDoAllInGroups(false),
+ myVersion(-1)
{}
-void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor)
+void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion)
{
- myMinor = theMinor;
+ myVersion = theVersion;
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)
+string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theMinor, int theNbDigits)
{
TInt majeur, mineur, release;
majeur=MED_MAJOR_NUM;
release=MED_RELEASE_NUM;
TInt imposedMineur = mineur;
- if (theVersion < 0)
+ if (theMinor < 0)
imposedMineur = mineur;
- else if (theVersion > MED_MINOR_NUM)
+ else if (theMinor > MED_MINOR_NUM)
imposedMineur = mineur;
else
- imposedMineur = theVersion;
+ imposedMineur = theMinor;
ostringstream name;
if ( theNbDigits > 0 )
}
}
- MED::PWrapper myMed = CrWrapperW(myFile, myMinor);
+ MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
//MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
myMed->SetMeshInfo(aMeshInfo);
DriverMED_W_SMESHDS_Mesh();
- void SetFile(const std::string& theFileName, int theMinor=-1);
+ void SetFile(const std::string& theFileName, int theVersion=-1);
void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; }
- static std::string GetVersionString(int theVersion, int theNbDigits=2);
+ static std::string GetVersionString(int theMinor, int theNbDigits=2);
void AddGroupOfNodes();
void AddGroupOfEdges();
bool myAutoDimension;
bool myAddODOnVertices;
bool myDoAllInGroups;
- int myMinor;
+ int myVersion;
};
#endif
return new MED::TWrapper(fileName);
}
- PWrapper CrWrapperW(const std::string& fileName, int theMinor)
+ PWrapper CrWrapperW(const std::string& fileName, int theVersion)
{
+ bool isCreated = false;
if (!CheckCompatibility(fileName, true))
- remove(fileName.c_str());
- return new MED::TWrapper(fileName, theMinor);
+ {
+ remove(fileName.c_str());
+ isCreated = true;
+ }
+ int minor = -1;
+ if (isCreated)
+ {
+ med_int wantedMajor = MED_MAJOR_NUM;
+ med_int wantedMinor = MED_MINOR_NUM;
+ if (theVersion > 0)
+ {
+ wantedMajor = theVersion/10;
+ wantedMinor = theVersion%10;
+ }
+ if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
+ {
+ if (wantedMinor < MED_MINOR_NUM)
+ minor = wantedMinor;
+ }
+ else // an empty existing med file of the right version will be used for append
+ {
+ int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
+ bool isVersionOK = false;
+ for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
+ if (medVersionsOK[ii] == theVersion)
+ {
+ isVersionOK =true;
+ break;
+ }
+ if (isVersionOK) // copy an empty existing med file of the right version, for append
+ {
+ MESSAGE("copy an empty existing med file of the right version, for append" << theVersion);
+ }
+ }
+ }
+ return new MED::TWrapper(fileName, minor);
}
}
PWrapper CrWrapperR( const std::string& );
MEDWRAPPER_EXPORT
- PWrapper CrWrapperW( const std::string&, int theMinor=-1 );
+ PWrapper CrWrapperW( const std::string&, int theVersion=-1 );
}
#endif // MED_Factory_HeaderFile
TWrapper& operator=(const TWrapper&);
public:
- TWrapper(const std::string& theFileName, TInt theMinor=-1);
+ TWrapper(const std::string& theFileName, TInt theVersion=-1);
virtual
~TWrapper();
void SMESH_Mesh::ExportMED(const char * file,
const char* theMeshName,
bool theAutoGroups,
- int theMinor,
+ int theVersion,
const SMESHDS_Mesh* meshPart,
bool theAutoDimension,
bool theAddODOnVertices,
bool theAllElemsToGroup)
throw(SALOME_Exception)
{
- //MESSAGE("MED_VERSION:"<< theVersion);
+ MESSAGE("MED_VERSION:"<< theVersion);
SMESH_TRY;
DriverMED_W_SMESHDS_Mesh myWriter;
- myWriter.SetFile ( file , theMinor);
+ myWriter.SetFile ( file , theVersion);
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension );
myWriter.AddODOnVertices ( theAddODOnVertices );
void ExportMED(const char * theFile,
const char* theMeshName = NULL,
bool theAutoGroups = true,
- int TheMinor = -1,
+ int theVersion = -1,
const SMESHDS_Mesh* theMeshPart = 0,
bool theAutoDimension = false,
bool theAddODOnVertices = false,
// Get parameters of export operation
QString aFilename;
- int aFormat =-1; // for MED minor versions
+ int aFormat =-1; // for MED version used for write
bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
// Init the parameters with the default values
}
else if ( isMED || isSAUV ) // Export to MED or SAUV
{
+ int defaultVersion = 0;
QMap<QString, int> aFilterMap;
if ( isMED ) {
//filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
//QString vmed (aMesh->GetVersionString(-1, 2));
//MESSAGE("MED version: " << vmed.toStdString());
SMESH::long_array_var mvok = aMesh->GetMEDVersionsCompatibleForAppend();
- for ( int i = 0; i < mvok->length(); ++i )
+ for ( int i = 0; i < mvok->length(); ++i ) // i=0 must correspond to the current version to set the default filter on it
{
int versionInt = mvok[i];
+ if (i == 0)
+ defaultVersion = versionInt;
std::ostringstream vss;
vss << versionInt/10;
vss << ".";
vss << versionInt%10;
QString vs = vss.str().c_str();
MESSAGE("MED version: " << vs.toStdString());
- aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", i);
+ aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", versionInt);
}
}
else { // isSAUV
aFilterMap.insert("All files (*)", -1 );
- aFilterMap.insert("SAUV files (*.sauv)", 0 );
+ aFilterMap.insert("SAUV files (*.sauv)", defaultVersion ); // 0 = default filter (defaultVersion)
aFilterMap.insert("SAUV files (*.sauve)", -1 );
}
-
+ MESSAGE("default version="<< defaultVersion);
QStringList filters;
QMap<QString, int>::const_iterator it = aFilterMap.begin();
QString aDefaultFilter = it.key();
for ( ; it != aFilterMap.end(); ++it ) {
filters.push_back( it.key() );
- if (it.value() == 0) // explicit default for MED = current MED version
+ if (it.value() == defaultVersion) // explicit default for MED = current MED version
aDefaultFilter = it.key();
}
QStringList checkBoxes;
break;
}
aFormat = aFilterMap[fd->selectedNameFilter()];
- MESSAGE("selected minor: " << aFormat << " file: " << aFilename.toUtf8().constData());
+ MESSAGE("selected version: " << aFormat << " file: " << aFilename.toUtf8().constData());
toOverwrite = fv->isOverwrite(aFilename);
MESSAGE("toOverwrite:" << toOverwrite);
is_ok = true;
if ( !aFilename.isEmpty() ) {
if( !toOverwrite ) {
- // can't append to an existing using other format
+ // append is only possible if the existing file format is compatible
bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() );
MESSAGE("Append check, isVersionOk:" << isVersionOk);
if ( !isVersionOk ) {
void SMESH_Mesh_i::ExportMED(const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension)
throw(SALOME::SALOME_Exception)
_preMeshInfo->FullLoadFromFile();
string aMeshName = prepareMeshNameAndGroups(file, overwrite);
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension );
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension );
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
<< file << "', "
<< "auto_groups=" <<auto_groups << ", "
- << "minor=" << minor << ", "
+ << "minor=" << version << ", "
<< "overwrite=" << overwrite << ", "
<< "meshPart=None, "
<< "autoDimension=" << autoDimension << " )";
void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
const char* geomAssocFields)
throw (SALOME::SALOME_Exception)
{
- //MESSAGE("MED minor version: "<< minor);
+ MESSAGE("MED version: "<< version);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{
aMeshName = prepareMeshNameAndGroups(file, overwrite);
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
0, autoDimension, /*addODOnVertices=*/have0dField);
meshDS = _impl->GetMeshDS();
}
}
SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
partDS, autoDimension, /*addODOnVertices=*/have0dField);
meshDS = tmpDSDeleter._obj = partDS;
}
<< meshPart << ", r'"
<< file << "', "
<< auto_groups << ", "
- << minor << ", "
+ << version << ", "
<< overwrite << ", "
<< autoDimension << ", "
<< goList << ", '"
void ExportMED( const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension = true) throw (SALOME::SALOME_Exception);
void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDim,
const GEOM::ListOfFields& fields,