Issue 0020514: EDF 1110 SMESH : Export many meshes in one Med File

This commit is contained in:
ouv 2010-01-11 07:17:11 +00:00
parent 238796e3d8
commit 6c4be33671
13 changed files with 411 additions and 59 deletions

View File

@ -339,6 +339,16 @@ module SMESH
* Can be used to check if the object was created in the same container, as this engine.
*/
long GetObjectId(in Object theObject);
/*!
* \brief Get MED version of the file by its name.
*/
boolean GetMEDVersion(in string theFileName, out MED_VERSION theVersion);
/*!
* \brief Get names of meshes defined in file with the specified name.
*/
string_array GetMeshNames(in string theFileName);
};
};

View File

@ -532,13 +532,23 @@ module SMESH
* the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
* the typical use is auto_groups=false.
* - theVersion : define the version of format of MED file, that will be created
* - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists
*/
void ExportToMEDX( in string file, in boolean auto_groups, in MED_VERSION theVersion, in boolean overwrite )
raises (SALOME::SALOME_Exception);
/*!
* Export Mesh to different MED Formats
* Works, just the same as ExportToMEDX, with overwrite parameter equal to true.
* The method is kept in order to support old functionality
*/
void ExportToMED( in string file, in boolean auto_groups, in MED_VERSION theVersion )
raises (SALOME::SALOME_Exception);
/*!
* Export Mesh to MED_V2_1 MED format
* Works, just the same as ExportToMED, with MED_VERSION parameter equal to MED_V2_1.
* Works, just the same as ExportToMEDX with MED_VERSION parameter equal to MED_V2_1
* and overwrite parameter equal to true
* The method is kept in order to support old functionality
*/
void ExportMED( in string file, in boolean auto_groups )

View File

@ -95,6 +95,7 @@ salomeinclude_HEADERS = \
SMESHGUI_FindElemByPointDlg.h \
SMESHGUI_MeshOrderDlg.h \
SMESHGUI_MeshOrderOp.h \
SMESHGUI_FileValidator.h \
SMESH_SMESHGUI.hxx
# Libraries targets
@ -166,7 +167,8 @@ dist_libSMESH_la_SOURCES = \
SMESHGUI_MeshInfosBox.cxx \
SMESHGUI_Make2DFrom3DOp.cxx \
SMESHGUI_MeshOrderDlg.cxx \
SMESHGUI_MeshOrderOp.cxx
SMESHGUI_MeshOrderOp.cxx \
SMESHGUI_FileValidator.cxx
MOC_FILES = \
SMESHGUI_moc.cxx \

View File

@ -38,6 +38,7 @@
#include "SMESHGUI_ExtrusionAlongPathDlg.h"
#include "SMESHGUI_ExtrusionDlg.h"
#include "SMESHGUI_FileInfoDlg.h"
#include "SMESHGUI_FileValidator.h"
#include "SMESHGUI_FilterDlg.h"
#include "SMESHGUI_FilterLibraryDlg.h"
#include "SMESHGUI_FindElemByPointDlg.h"
@ -272,17 +273,54 @@
if( aSel )
aSel->selectedObjects( selected );
SMESH::SMESH_Mesh_var aMesh;
if(selected.Extent() == 1)
aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(selected.First());
if ( aMesh->_is_nil() ) {
SUIT_MessageBox::warning( SMESHGUI::desktop(),
QObject::tr( "SMESH_WRN_WARNING" ),
QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
// actually, the following condition can't be met (added for insurance)
if( selected.Extent() == 0 ||
selected.Extent() > 1 && theCommandID != 122 && theCommandID != 125 )
return;
bool hasDuplicatedMeshNames = false;
QList< QPair< SMESH::SMESH_Mesh_var, QString > > aMeshList;
QList< QPair< SMESH::SMESH_Mesh_var, QString > >::iterator aMeshIter;
SALOME_ListIteratorOfListIO It( selected );
for( ; It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) anIObject = It.Value();
SMESH::SMESH_Mesh_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIObject );
if ( aMeshItem->_is_nil() ) {
SUIT_MessageBox::warning( SMESHGUI::desktop(),
QObject::tr( "SMESH_WRN_WARNING" ),
QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
return;
}
QString aMeshName = anIObject->getName();
// check for duplications
for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
if( aMeshName == (*aMeshIter).second ) {
hasDuplicatedMeshNames = true;
break;
}
}
aMeshList.append( QPair< SMESH::SMESH_Mesh_var, QString >( aMeshItem, aMeshName ) );
}
Handle(SALOME_InteractiveObject) anIObject = selected.First();
if( hasDuplicatedMeshNames ) {
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet != 0)
return;
}
aMeshIter = aMeshList.begin();
SMESH::SMESH_Mesh_var aMesh = (*aMeshIter).first;
QString aMeshName = (*aMeshIter).second;
QList<SALOMEDS::Color> aReservedColors;
QString aFilter, aTitle = QObject::tr("Export mesh");
QMap<QString, SMESH::MED_VERSION> aFilterMap;
QMap<QString, int> aFilterMapSTL;
@ -290,14 +328,18 @@
case 125:
case 122:
{
if (aMesh->HasDuplicatedGroupNamesMED()) {
int aRet = SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
if (aRet != SUIT_MessageBox::Yes)
return;
for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
if (aMeshItem->HasDuplicatedGroupNamesMED()) {
int aRet = SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet != 0)
return;
}
}
// PAL18696
QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
@ -317,9 +359,10 @@
int aRet = SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
if (aRet != SUIT_MessageBox::Yes)
QObject::tr("SMESH_EXPORT_UNV").arg(aMeshName),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet != 0)
return;
}
aFilter = QObject::tr("IDEAS files (*.unv)");
@ -336,16 +379,17 @@
SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()));
QObject::tr("SMESH_EXPORT_STL1").arg(aMeshName));
return;
}
if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
int aRet = SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
if (aRet != SUIT_MessageBox::Yes)
QObject::tr("SMESH_EXPORT_STL2").arg(aMeshName),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet != 0)
return;
}
@ -365,6 +409,7 @@
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
if ( resMgr )
toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
bool toOverwrite = true;
QString anInitialPath = "";
if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
@ -372,7 +417,7 @@
if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) {
if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + aMeshName,
aFilter, aTitle, false);
}
else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
@ -387,7 +432,7 @@
fd->selectFilter( QObject::tr("STL ASCII (*.stl)") );
if ( !anInitialPath.isEmpty() )
fd->setDirectory( anInitialPath );
fd->selectFile(anIObject->getName());
fd->selectFile(aMeshName);
bool is_ok = false;
while (!is_ok) {
if ( fd->exec() )
@ -417,22 +462,79 @@
fd->SetChecked(toCreateGroups);
if ( !anInitialPath.isEmpty() )
fd->setDirectory( anInitialPath );
fd->selectFile(anIObject->getName());
fd->selectFile(aMeshName);
SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
fd->setValidator( fv );
bool is_ok = false;
while (!is_ok) {
if ( fd->exec() )
aFilename = fd->selectedFile();
else {
aFilename = QString::null;
break;
}
aFormat = aFilterMap[fd->selectedFilter()];
toOverwrite = fv->isOverwrite();
is_ok = true;
if ( !aFilename.isEmpty()
&& (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
&& aFormat==SMESH::MED_V2_1) {
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
if (aRet != SUIT_MessageBox::Yes) {
is_ok = false;
if ( !aFilename.isEmpty() ) {
for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
if( (aMeshItem->NbPolygons()>0 || aMeshItem->NbPolyhedrons()>0)
&& aFormat==SMESH::MED_V2_1) {
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet != 0) {
is_ok = false;
break;
}
}
}
if( !toOverwrite ) {
SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
if( !isVersionOk || aVersion != aFormat ) {
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"), 0, 1);
if (aRet == 0)
toOverwrite = true;
else
is_ok = false;
}
QStringList aMeshNamesCollisionList;
SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
QString anExistingMeshName( aMeshNames[ i ] );
for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
QString anExportMeshName = (*aMeshIter).second;
if( anExportMeshName == anExistingMeshName ) {
aMeshNamesCollisionList.append( anExportMeshName );
break;
}
}
}
if( !aMeshNamesCollisionList.isEmpty() ) {
QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
QObject::tr("SMESH_BUT_YES"),
QObject::tr("SMESH_BUT_NO"),
QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
if (aRet == 0)
toOverwrite = true;
else if (aRet == 2)
is_ok = false;
}
}
}
}
@ -442,7 +544,7 @@
if ( !aFilename.isEmpty() ) {
// Check whether the file already exists and delete it if yes
QFile aFile( aFilename );
if ( aFile.exists() )
if ( aFile.exists() && toOverwrite )
aFile.remove();
SUIT_OverrideCursor wc;
@ -460,8 +562,14 @@
}
switch ( theCommandID ) {
case 125:
case 122:
aMesh->ExportToMED( aFilename.toLatin1().data(), toCreateGroups, aFormat );
case 122: {
int aMeshIndex = 0;
for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ ) {
SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
if( !aMeshItem->_is_nil() )
aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0 );
}
}
break;
case 124:
case 121:
@ -3135,8 +3243,9 @@ void SMESHGUI::initialize( CAM_Application* app )
popupMgr()->insert( separator(), -1, 0 );
QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
createPopupItem( 125, OB, mesh, only_one_non_empty ); // EXPORT_MED
createPopupItem( 125, OB, mesh, multiple_non_empty ); // EXPORT_MED
createPopupItem( 126, OB, mesh, only_one_non_empty ); // EXPORT_UNV
createPopupItem( 141, OB, mesh, only_one_non_empty ); // EXPORT_STL
//createPopupItem( 33, OB, subMesh + " " + group ); // DELETE

View File

@ -0,0 +1,76 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// 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.
//
// 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
//
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_FileValidator.cxx
// Author : Oleg UVAROV
// SMESH includes
//
#include "SMESHGUI_FileValidator.h"
// SALOME GUI includes
#include <SUIT_MessageBox.h>
#include <SUIT_Tools.h>
// Qt includes
#include <QFileInfo>
//=======================================================================
//function : SMESHGUI_FileValidator
//purpose :
//=======================================================================
SMESHGUI_FileValidator::SMESHGUI_FileValidator( QWidget* parent )
: SUIT_FileValidator( parent ),
myIsOverwrite( true )
{
}
//=======================================================================
//function : canSave
//purpose :
//=======================================================================
bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermission )
{
if ( QFile::exists( fileName ) ) {
if ( parent() ) {
int anAnswer = SUIT_MessageBox::question( parent(), QObject::tr( "SMESH_WRN_WARNING" ),
QObject::tr( "SMESH_FILE_EXISTS" ).arg( fileName ),
QObject::tr( "SMESH_BUT_OVERWRITE" ),
QObject::tr( "SMESH_BUT_ADD" ),
QObject::tr( "SMESH_BUT_CANCEL" ), 0, 2 );
if( anAnswer == 2 )
return false;
myIsOverwrite = anAnswer == 0;
}
// copied from SUIT_FileValidator
if ( checkPermission && !QFileInfo( fileName ).isWritable() ) {
if ( parent() )
SUIT_MessageBox::critical( parent(), QObject::tr( "SMESH_ERROR" ),
QObject::tr( "NO_PERMISSION" ).arg( fileName ) );
return false;
}
}
else {
return SUIT_FileValidator::canSave( fileName, checkPermission );
}
return true;
}

View File

@ -0,0 +1,48 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// 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.
//
// 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
//
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_FileValidator.h
// Author : Oleg UVAROV
//
#ifndef SMESHGUI_FILEVALIDATOR_H
#define SMESHGUI_FILEVALIDATOR_H
// SMESH includes
#include "SMESH_SMESHGUI.hxx"
// SALOME GUI includes
#include <SUIT_FileValidator.h>
class SMESHGUI_EXPORT SMESHGUI_FileValidator : public SUIT_FileValidator
{
public:
SMESHGUI_FileValidator( QWidget* = 0 );
virtual bool canSave( const QString&, bool = true );
bool isOverwrite() const { return myIsOverwrite; }
private:
bool myIsOverwrite;
};
#endif // SMESHGUI_FILEVALIDATOR_H

View File

@ -969,6 +969,10 @@ Please enter correct values and try again</translation>
<source>SMESH_BUT_OK</source>
<translation>&amp;Ok</translation>
</message>
<message>
<source>SMESH_BUT_OVERWRITE</source>
<translation>Over&amp;write</translation>
</message>
<message>
<source>SMESH_BUT_APPLY_AND_CLOSE</source>
<translation>A&amp;pply and Close</translation>
@ -1175,6 +1179,12 @@ Probably, there is not enough space on disk.</translation>
You can cancel exporting and rename them,
otherwise some group names in the resulting MED file
will not match ones in the study.
Do you want to continue ?</translation>
</message>
<message>
<source>SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES</source>
<translation>There are some meshes with the same names in the selection.
The result file may be incorrect.
Do you want to continue ?</translation>
</message>
<message>
@ -1183,6 +1193,19 @@ Do you want to continue ?</translation>
polygons and polyhedrons elements will be missed
For correct export use MED 2.2
Are you sure want to export to MED 2.1 ?</translation>
</message>
<message>
<source>SMESH_EXPORT_MED_VERSION_COLLISION</source>
<translation>MED version of the file "%1"
is unknown or doesn't match the selected version.
Overwrite the file?</translation>
</message>
<message>
<source>SMESH_EXPORT_MED_MESH_NAMES_COLLISION</source>
<translation>The selected file already contains
meshes with the following names: %1
The result file may be incorrect.
Overwrite the file?</translation>
</message>
<message>
<source>SMESH_EXPORT_STL1</source>
@ -1221,6 +1244,12 @@ Are you sure want to export to MED 2.1 ?</translation>
<source>SMESH_FEATUREEDGES</source>
<translation>Feature Edges</translation>
</message>
<message>
<source>SMESH_FILE_EXISTS</source>
<translation>The file "%1" already exists.
Do you want to overwrite it or
add the exported data to its contents?</translation>
</message>
<message>
<source>SMESH_FONT_ARIAL</source>
<translation>Arial</translation>

View File

@ -846,7 +846,8 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
}
}
// ----------------------------------------------------------------------
else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
else if ( method == "ExportToMED" || // ExportToMED() --> ExportMED()
method == "ExportToMEDX" ) { // ExportToMEDX() --> ExportMED()
theCommand->SetMethod( "ExportMED" );
}
// ----------------------------------------------------------------------

View File

@ -2193,6 +2193,49 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
return aNewMesh._retn();
}
//================================================================================
/*!
* SMESH_Gen_i::GetMEDVersion
*
* Get MED version of the file by its name
*/
//================================================================================
CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
SMESH::MED_VERSION& theVersion)
{
theVersion = SMESH::MED_V2_1;
MED::EVersion aVersion = MED::GetVersionId( theFileName );
switch( aVersion ) {
case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
case MED::eVUnknown : return false;
}
return false;
}
//================================================================================
/*!
* SMESH_Gen_i::GetMeshNames
*
* Get names of meshes defined in file with the specified name
*/
//================================================================================
SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
{
SMESH::string_array_var aResult = new SMESH::string_array();
MED::PWrapper aMed = MED::CrWrapper( theFileName );
MED::TErr anErr;
MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
if( anErr >= 0 ) {
aResult->length( aNbMeshes );
for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
}
}
return aResult._retn();
}
//=============================================================================
/*!
* SMESH_Gen_i::Save

View File

@ -320,6 +320,13 @@ public:
CORBA::Double theMergeTolerance)
throw ( SALOME::SALOME_Exception );
// Get MED version of the file by its name
CORBA::Boolean GetMEDVersion(const char* theFileName,
SMESH::MED_VERSION& theVersion);
// Get names of meshes defined in file with the specified name
SMESH::string_array* GetMeshNames(const char* theFileName);
// ****************************************************
// Interface inherited methods (from SALOMEDS::Driver)
// ****************************************************

View File

@ -2263,7 +2263,7 @@ CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
return _impl->HasDuplicatedGroupNamesMED();
}
void SMESH_Mesh_i::PrepareForWriting (const char* file)
void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
{
TCollection_AsciiString aFullName ((char*)file);
OSD_Path aPath (aFullName);
@ -2272,8 +2272,10 @@ void SMESH_Mesh_i::PrepareForWriting (const char* file)
// existing filesystem node
if (aFile.KindOfFile() == OSD_FILE) {
if (aFile.IsWriteable()) {
aFile.Reset();
aFile.Remove();
if (overwrite) {
aFile.Reset();
aFile.Remove();
}
if (aFile.Failed()) {
TCollection_AsciiString msg ("File ");
msg += aFullName + " cannot be replaced.";
@ -2304,15 +2306,16 @@ void SMESH_Mesh_i::PrepareForWriting (const char* file)
}
}
void SMESH_Mesh_i::ExportToMED (const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION theVersion)
void SMESH_Mesh_i::ExportToMEDX (const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION theVersion,
CORBA::Boolean overwrite)
throw(SALOME::SALOME_Exception)
{
Unexpect aCatch(SALOME_SalomeException);
// Perform Export
PrepareForWriting(file);
PrepareForWriting(file, overwrite);
const char* aMeshName = "Mesh";
SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
if ( !aStudy->_is_nil() ) {
@ -2344,17 +2347,25 @@ void SMESH_Mesh_i::ExportToMED (const char* file,
// check names of groups
checkGroupNames();
TPythonDump() << _this() << ".ExportToMED( '"
<< file << "', " << auto_groups << ", " << theVersion << " )";
TPythonDump() << _this() << ".ExportToMEDX( '"
<< file << "', " << auto_groups << ", " << theVersion << ", " << overwrite << " )";
_impl->ExportMED( file, aMeshName, auto_groups, theVersion );
}
void SMESH_Mesh_i::ExportToMED (const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION theVersion)
throw(SALOME::SALOME_Exception)
{
ExportToMEDX(file,auto_groups,theVersion,true);
}
void SMESH_Mesh_i::ExportMED (const char* file,
CORBA::Boolean auto_groups)
throw(SALOME::SALOME_Exception)
{
ExportToMED(file,auto_groups,SMESH::MED_V2_1);
ExportToMEDX(file,auto_groups,SMESH::MED_V2_1,true);
}
void SMESH_Mesh_i::ExportDAT (const char *file)

View File

@ -206,6 +206,8 @@ public:
*/
char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
void ExportToMEDX( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion, CORBA::Boolean overwrite )
throw (SALOME::SALOME_Exception);
void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
throw (SALOME::SALOME_Exception);
void ExportMED( const char* file, CORBA::Boolean auto_groups )
@ -338,7 +340,7 @@ public:
static SMESH::Hypothesis_Status
ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
static void PrepareForWriting (const char* file);
static void PrepareForWriting (const char* file, bool overwrite = true);
//int importMEDFile( const char* theFileName, const char* theMeshName );

View File

@ -1328,25 +1328,29 @@ class Mesh:
def Group(self, grp, name=""):
return self.GroupOnGeom(grp, name)
## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
# Exports the mesh in a file in MED format and chooses the \a version of MED format
## allowing to overwrite the file if it exists or add the exported data to its contents
# @param f the file name
# @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
# @param opt boolean parameter for creating/not creating
# the groups Group_On_All_Nodes, Group_On_All_Faces, ...
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @ingroup l2_impexp
def ExportToMED(self, f, version, opt=0):
self.mesh.ExportToMED(f, opt, version)
def ExportToMED(self, f, version, opt=0, overwrite=1):
self.mesh.ExportToMEDX(f, opt, version, overwrite)
## Exports the mesh in a file in MED format
## Exports the mesh in a file in MED format and chooses the \a version of MED format
## allowing to overwrite the file if it exists or add the exported data to its contents
# @param f is the file name
# @param 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.
# @param version MED format version(MED_V2_1 or MED_V2_2)
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @ingroup l2_impexp
def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
self.mesh.ExportToMED(f, auto_groups, version)
def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1):
self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
## Exports the mesh in a file in DAT format
# @param f the file name