Check mesh size before export

This commit is contained in:
eap 2021-03-12 19:29:02 +03:00
parent 293adaddb5
commit 6d54a9deb2
10 changed files with 190 additions and 62 deletions

View File

@ -28,6 +28,7 @@
#define _INCLUDE_DRIVER_MESH #define _INCLUDE_DRIVER_MESH
#include "SMESH_ComputeError.hxx" #include "SMESH_ComputeError.hxx"
#include "SMDS_Mesh.hxx"
#include <string> #include <string>
#include <vector> #include <vector>
@ -55,7 +56,8 @@ class MESHDRIVER_EXPORT Driver_Mesh
// so the numbers from the file are ignored // so the numbers from the file are ignored
DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
DRS_FAIL // general failure (exception etc.) DRS_FAIL, // general failure (exception etc.)
DRS_TOO_LARGE_MESH // mesh is too large for export
}; };
void SetMeshId(int theMeshId); void SetMeshId(int theMeshId);
@ -70,6 +72,22 @@ class MESHDRIVER_EXPORT Driver_Mesh
virtual SMESH_ComputeErrorPtr GetError(); virtual SMESH_ComputeErrorPtr GetError();
//virtual bool CanExportMesh() const { return false; } //= 0;
// check if a mesh is too large to export it using IDTYPE;
// check either max ID or number of elements
template< typename IDTYPE >
static bool IsMeshTooLarge( const SMDS_Mesh* mesh, bool checkIDs )
{
if ( sizeof( IDTYPE ) < sizeof( smIdType ))
{
const smIdType maxNB = std::numeric_limits< IDTYPE >::max();
return (( checkIDs ? mesh->MaxNodeID() : mesh->NbNodes() ) > maxNB ||
( checkIDs ? mesh->MaxElementID() : mesh->NbElements() > maxNB ));
}
return false;
}
protected: protected:
std::string myFile; std::string myFile;
std::string myMeshName; std::string myMeshName;

View File

@ -248,6 +248,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
if ( !myMesh || myMesh->GetMeshInfo().NbElements() < 1 ) if ( !myMesh || myMesh->GetMeshInfo().NbElements() < 1 )
return addMessage( !myMesh ? "NULL mesh" : "Empty mesh (no elements)", /*fatal = */true ); return addMessage( !myMesh ? "NULL mesh" : "Empty mesh (no elements)", /*fatal = */true );
if ( Driver_Mesh::IsMeshTooLarge< cgsize_t >( myMesh, /*checkIDs =*/ false))
return DRS_TOO_LARGE_MESH;
// open the file // open the file
if ( cg_open(myFile.c_str(), CG_MODE_MODIFY, &_fn) != CG_OK && if ( cg_open(myFile.c_str(), CG_MODE_MODIFY, &_fn) != CG_OK &&
cg_open(myFile.c_str(), CG_MODE_WRITE, &_fn) != CG_OK ) cg_open(myFile.c_str(), CG_MODE_WRITE, &_fn) != CG_OK )
@ -282,7 +285,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
else if ( meshDim == 2 ) else if ( meshDim == 2 )
nbCells = myMesh->NbFaces(); nbCells = myMesh->NbFaces();
cgsize_t size[9] = { myMesh->NbNodes(), nbCells, /*NBoundVertex=*/0, 0,0,0,0,0,0 }; cgsize_t size[9] = { FromIdType<cgsize_t>( myMesh->NbNodes() ),
FromIdType<cgsize_t>( nbCells ),
/*NBoundVertex=*/0, 0,0,0,0,0,0 };
int iZone; int iZone;
if ( cg_zone_write( _fn, iBase, "SMESH_Mesh", size, if ( cg_zone_write( _fn, iBase, "SMESH_Mesh", size,
CGNS_ENUMV( Unstructured ), &iZone) != CG_OK ) CGNS_ENUMV( Unstructured ), &iZone) != CG_OK )

View File

@ -100,6 +100,9 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
{ {
Kernel_Utils::Localizer loc; Kernel_Utils::Localizer loc;
if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
return DRS_TOO_LARGE_MESH;
const int dim = 3, version = sizeof(double) < 8 ? 1 : 2; const int dim = 3, version = sizeof(double) < 8 ? 1 : 2;
int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim ); int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );

View File

@ -343,12 +343,21 @@ namespace
} }
} }
//================================================================================
/*!
* \brief Write my mesh
*/
//================================================================================
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
{ {
Status aResult = DRS_OK; Status aResult = DRS_OK;
try { try {
//MESSAGE("Perform - myFile : "<<myFile); //MESSAGE("Perform - myFile : "<<myFile);
if ( Driver_Mesh::IsMeshTooLarge< TInt >( myMesh, /*checkIDs =*/ true ))
return DRS_TOO_LARGE_MESH;
// Creating the MED mesh for corresponding SMDS structure // Creating the MED mesh for corresponding SMDS structure
//------------------------------------------------------- //-------------------------------------------------------
string aMeshName; string aMeshName;
@ -559,7 +568,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
aTCoordSlice[2] = 0.; aTCoordSlice[2] = 0.;
// node number // node number
int aNodeID = aCoordHelperPtr->GetID(); TInt aNodeID = FromIdType<TInt>( aCoordHelperPtr->GetID() );
aNodeInfo->SetElemNum( iNode, aNodeID ); aNodeInfo->SetElemNum( iNode, aNodeID );
#ifdef _EDF_NODE_IDS_ #ifdef _EDF_NODE_IDS_
aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 )); aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));

View File

@ -45,6 +45,10 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
{ {
Kernel_Utils::Localizer loc; Kernel_Utils::Localizer loc;
Status aResult = DRS_OK; Status aResult = DRS_OK;
if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
return DRS_TOO_LARGE_MESH;
#if defined(WIN32) && defined(UNICODE) #if defined(WIN32) && defined(UNICODE)
std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile); std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
std::ofstream out_stream(aFile.c_str()); std::ofstream out_stream(aFile.c_str());
@ -256,11 +260,11 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
EXCEPTION(runtime_error,"ERROR: Output file not good."); EXCEPTION(runtime_error,"ERROR: Output file not good.");
} }
catch(const std::exception& exc){ catch(const std::exception& exc){
INFOS("Follow exception was cought:\n\t"<<exc.what()); INFOS("Follow exception was caught:\n\t"<<exc.what());
throw; throw;
} }
catch(...){ catch(...){
INFOS("Unknown exception was cought !!!"); INFOS("Unknown exception was caught !!!");
throw; throw;
} }
return aResult; return aResult;

View File

@ -1428,6 +1428,8 @@ void SMESH_Mesh::ExportMED(const char * file,
bool theAllElemsToGroup) bool theAllElemsToGroup)
{ {
MESSAGE("MED_VERSION:"<< theVersion); MESSAGE("MED_VERSION:"<< theVersion);
Driver_Mesh::Status status;
SMESH_TRY; SMESH_TRY;
DriverMED_W_SMESHDS_Mesh myWriter; DriverMED_W_SMESHDS_Mesh myWriter;
@ -1482,9 +1484,12 @@ void SMESH_Mesh::ExportMED(const char * file,
} }
} }
// Perform export // Perform export
myWriter.Perform(); status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx ); SMESH_CATCH( SMESH::throwSalomeEx );
if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("MED");
} }
//================================================================================ //================================================================================
@ -1509,9 +1514,15 @@ void SMESH_Mesh::ExportSAUV(const char *file,
cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')"; cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
cmd += "\""; cmd += "\"";
system(cmd.c_str()); system(cmd.c_str());
try {
ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1, ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
/*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false, /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
/*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413 /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
}
catch ( TooLargeForExport )
{
throw TooLargeForExport("SAUV");
}
#ifdef WIN32 #ifdef WIN32
cmd = "%PYTHONBIN% "; cmd = "%PYTHONBIN% ";
#else #else
@ -1541,12 +1552,19 @@ void SMESH_Mesh::ExportSAUV(const char *file,
void SMESH_Mesh::ExportDAT(const char * file, void SMESH_Mesh::ExportDAT(const char * file,
const SMESHDS_Mesh* meshPart) const SMESHDS_Mesh* meshPart)
{ {
Unexpect aCatch(SalomeException); Driver_Mesh::Status status;
SMESH_TRY;
DriverDAT_W_SMDS_Mesh myWriter; DriverDAT_W_SMDS_Mesh myWriter;
myWriter.SetFile( file ); myWriter.SetFile( file );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetMeshId(_id); myWriter.SetMeshId(_id);
myWriter.Perform(); status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx );
if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("DAT");
} }
//================================================================================ //================================================================================
@ -1558,7 +1576,9 @@ void SMESH_Mesh::ExportDAT(const char * file,
void SMESH_Mesh::ExportUNV(const char * file, void SMESH_Mesh::ExportUNV(const char * file,
const SMESHDS_Mesh* meshPart) const SMESHDS_Mesh* meshPart)
{ {
Unexpect aCatch(SalomeException); Driver_Mesh::Status status;
SMESH_TRY;
DriverUNV_W_SMDS_Mesh myWriter; DriverUNV_W_SMDS_Mesh myWriter;
myWriter.SetFile( file ); myWriter.SetFile( file );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
@ -1579,7 +1599,12 @@ void SMESH_Mesh::ExportUNV(const char * file,
} }
} }
} }
myWriter.Perform(); status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx );
if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("UNV");
} }
//================================================================================ //================================================================================
@ -1593,14 +1618,21 @@ void SMESH_Mesh::ExportSTL(const char * file,
const char * name, const char * name,
const SMESHDS_Mesh* meshPart) const SMESHDS_Mesh* meshPart)
{ {
Unexpect aCatch(SalomeException); Driver_Mesh::Status status;
SMESH_TRY;
DriverSTL_W_SMDS_Mesh myWriter; DriverSTL_W_SMDS_Mesh myWriter;
myWriter.SetFile( file ); myWriter.SetFile( file );
myWriter.SetIsAscii( isascii ); myWriter.SetIsAscii( isascii );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS); myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
myWriter.SetMeshId(_id); myWriter.SetMeshId(_id);
if ( name ) myWriter.SetName( name ); if ( name ) myWriter.SetName( name );
myWriter.Perform(); status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx );
if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("STL");
} }
//================================================================================ //================================================================================
@ -1614,7 +1646,9 @@ void SMESH_Mesh::ExportCGNS(const char * file,
const char * meshName, const char * meshName,
const bool groupElemsByType) const bool groupElemsByType)
{ {
int res = Driver_Mesh::DRS_FAIL; int res = Driver_Mesh::DRS_FAIL;
SMESH_TRY;
// pass group names to SMESHDS // pass group names to SMESHDS
std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
@ -1644,6 +1678,11 @@ void SMESH_Mesh::ExportCGNS(const char * file,
} }
#endif #endif
SMESH_CATCH( SMESH::throwSalomeEx );
if ( res == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("CGNS");
if ( res != Driver_Mesh::DRS_OK ) if ( res != Driver_Mesh::DRS_OK )
throw SALOME_Exception("Export failed"); throw SALOME_Exception("Export failed");
} }
@ -1658,12 +1697,20 @@ void SMESH_Mesh::ExportGMF(const char * file,
const SMESHDS_Mesh* meshDS, const SMESHDS_Mesh* meshDS,
bool withRequiredGroups) bool withRequiredGroups)
{ {
Driver_Mesh::Status status;
SMESH_TRY;
DriverGMF_Write myWriter; DriverGMF_Write myWriter;
myWriter.SetFile( file ); myWriter.SetFile( file );
myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS )); myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
myWriter.SetExportRequiredGroups( withRequiredGroups ); myWriter.SetExportRequiredGroups( withRequiredGroups );
myWriter.Perform(); status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx );
if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
throw TooLargeForExport("GMF");
} }
//================================================================================ //================================================================================

View File

@ -245,12 +245,22 @@ class SMESH_EXPORT SMESH_Mesh
*/ */
typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap; typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap;
const TAncestorMap& GetAncestorMap() const { return _mapAncestors; } const TAncestorMap& GetAncestorMap() const { return _mapAncestors; }
/*! /*!
* \brief Check group names for duplications. * \brief Check group names for duplications.
* Consider maximum group name length stored in MED file * Consider maximum group name length stored in MED file
*/ */
bool HasDuplicatedGroupNamesMED(); bool HasDuplicatedGroupNamesMED();
/*!
* \brief Exception thrown by Export*() in case if a mesh is too large for export
* due to limitation of a format
*/
struct TooLargeForExport : public std::runtime_error
{
TooLargeForExport(const char* format):runtime_error(format) {}
};
void ExportMED(const char * theFile, void ExportMED(const char * theFile,
const char* theMeshName = NULL, const char* theMeshName = NULL,
bool theAutoGroups = true, bool theAutoGroups = true,

View File

@ -992,8 +992,16 @@ namespace
aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups ); aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
} }
} }
catch (const SALOME::SALOME_Exception& S_ex){ catch (const SALOME::SALOME_Exception& S_ex)
{
wc.suspend(); wc.suspend();
if ( S_ex.details.type == SALOME::COMM && // communicate about too large mesh
strncmp( "format=", S_ex.details.sourceFile.in(), 7 ) == 0 )
SUIT_MessageBox::critical(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr(S_ex.details.text.in() ));
else
SUIT_MessageBox::warning(SMESHGUI::desktop(), SUIT_MessageBox::warning(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"), QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex)); QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));

View File

@ -65,11 +65,14 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// A macro makes description of a caught exception and calls onExceptionFun(const char*). // A macro makes description of a caught exception and calls onExceptionFun(const char*).
// Two onExceptionFun() are defined here: SMESH::throwSalomeEx() and SMESH::doNothing(). // Several onExceptionFun() are defined here: throwSalomeEx(), doNothing() and returnError().
// To add your own catch close, define SMY_OWN_CATCH macro before including this file. // To add your own catch close, define SMY_OWN_CATCH macro before including this file.
#define SMESH_CATCH( onExceptionFun ) \ #define SMESH_CATCH( onExceptionFun ) \
} \ } \
\
SMY_OWN_CATCH \
\
catch (Standard_Failure& ex) \ catch (Standard_Failure& ex) \
{ \ { \
SMESH_Comment text("OCCT Exception: "); \ SMESH_Comment text("OCCT Exception: "); \
@ -92,9 +95,6 @@
{ \ { \
SMESH_CAUGHT onExceptionFun( ex.what() ); \ SMESH_CAUGHT onExceptionFun( ex.what() ); \
} \ } \
\
SMY_OWN_CATCH \
\
catch (...) \ catch (...) \
{ \ { \
SMESH_CAUGHT onExceptionFun("Unknown Exception caught"); \ SMESH_CAUGHT onExceptionFun("Unknown Exception caught"); \

View File

@ -84,8 +84,15 @@
#include <vtkUnstructuredGridWriter.h> #include <vtkUnstructuredGridWriter.h>
// to pass CORBA exception through SMESH_TRY // to pass CORBA exception and TooLargeForExport exception through SMESH_TRY
#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; } #define SMY_OWN_CATCH \
catch( SALOME::SALOME_Exception& se ) { throw se; } \
catch( ::SMESH_Mesh::TooLargeForExport& ex ) \
{ SALOME::ExceptionStruct se = { \
SALOME::COMM, \
CORBA::string_dup(SMESH_Comment("Mesh is too large for export in format ") << ex.what()), \
CORBA::string_dup(SMESH_Comment("format=") << ex.what() ), 0 }; \
throw SALOME::SALOME_Exception( se ); }
#include "SMESH_TryCatch.hxx" // include after OCCT headers! #include "SMESH_TryCatch.hxx" // include after OCCT headers!
@ -461,8 +468,7 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileNa
char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits) char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
{ {
string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, nbDigits);
nbDigits);
return CORBA::string_dup( ver.c_str() ); return CORBA::string_dup( ver.c_str() );
} }
@ -3763,10 +3769,9 @@ void SMESH_Mesh_i::ExportMED(const char* file,
*/ */
//================================================================================ //================================================================================
void SMESH_Mesh_i::ExportSAUV (const char* file, void SMESH_Mesh_i::ExportSAUV( const char* file, CORBA::Boolean auto_groups )
CORBA::Boolean auto_groups)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -3774,6 +3779,8 @@ void SMESH_Mesh_i::ExportSAUV (const char* file,
TPythonDump() << SMESH::SMESH_Mesh_var( _this()) TPythonDump() << SMESH::SMESH_Mesh_var( _this())
<< ".ExportSAUV( r'" << file << "', " << auto_groups << " )"; << ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
_impl->ExportSAUV(file, aMeshName.c_str(), auto_groups); _impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
SMESH_CATCH( SMESH::throwCorbaException );
} }
@ -3785,18 +3792,20 @@ void SMESH_Mesh_i::ExportSAUV (const char* file,
void SMESH_Mesh_i::ExportDAT (const char *file) void SMESH_Mesh_i::ExportDAT (const char *file)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
// Update Python script
// check names of groups // check names of groups
checkGroupNames(); checkGroupNames();
// Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )"; TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
// Perform Export // Perform Export
PrepareForWriting(file); PrepareForWriting(file);
_impl->ExportDAT(file); _impl->ExportDAT(file);
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
@ -3807,18 +3816,20 @@ void SMESH_Mesh_i::ExportDAT (const char *file)
void SMESH_Mesh_i::ExportUNV (const char *file) void SMESH_Mesh_i::ExportUNV (const char *file)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
// Update Python script
// check names of groups // check names of groups
checkGroupNames(); checkGroupNames();
// Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )"; TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
// Perform Export // Perform Export
PrepareForWriting(file); PrepareForWriting(file);
_impl->ExportUNV(file); _impl->ExportUNV(file);
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
@ -3829,13 +3840,13 @@ void SMESH_Mesh_i::ExportUNV (const char *file)
void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii) void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
// Update Python script
// check names of groups // check names of groups
checkGroupNames(); checkGroupNames();
// Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportSTL( r'" << file << "', " << isascii << " )"; << ".ExportSTL( r'" << file << "', " << isascii << " )";
@ -3847,6 +3858,8 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
// Perform Export // Perform Export
PrepareForWriting( file ); PrepareForWriting( file );
_impl->ExportSTL( file, isascii, name.in() ); _impl->ExportSTL( file, isascii, name.in() );
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
@ -4249,7 +4262,7 @@ void SMESH_Mesh_i::exportMEDFields( DriverMED_W_Field& fieldWriter,
void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart, void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file) const char* file)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -4260,6 +4273,8 @@ void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )"; << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
/*! /*!
@ -4270,7 +4285,7 @@ void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart, void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file) const char* file)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -4281,6 +4296,8 @@ void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )"; << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
/*! /*!
@ -4292,7 +4309,7 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file, const char* file,
::CORBA::Boolean isascii) ::CORBA::Boolean isascii)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -4308,6 +4325,8 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( " TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
<< meshPart<< ", r'" << file << "', " << isascii << ")"; << meshPart<< ", r'" << file << "', " << isascii << ")";
SMESH_CATCH( SMESH::throwCorbaException );
} }
//================================================================================ //================================================================================
@ -4322,7 +4341,7 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
CORBA::Boolean groupElemsByType) CORBA::Boolean groupElemsByType)
{ {
#ifdef WITH_CGNS #ifdef WITH_CGNS
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -4344,6 +4363,9 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( " TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
<< meshPart<< ", r'" << file << "', " << overwrite << ")"; << meshPart<< ", r'" << file << "', " << overwrite << ")";
SMESH_CATCH( SMESH::throwCorbaException );
#else #else
THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR); THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
#endif #endif
@ -4359,7 +4381,7 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file, const char* file,
bool withRequiredGroups) bool withRequiredGroups)
{ {
Unexpect aCatch(SALOME_SalomeException); SMESH_TRY;
if ( _preMeshInfo ) if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile(); _preMeshInfo->FullLoadFromFile();
@ -4372,6 +4394,8 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
<< meshPart<< ", r'" << meshPart<< ", r'"
<< file << "', " << file << "', "
<< withRequiredGroups << ")"; << withRequiredGroups << ")";
SMESH_CATCH( SMESH::throwCorbaException );
} }
//============================================================================= //=============================================================================
@ -5526,7 +5550,7 @@ SMESH::smIdType_array* SMESH_Mesh_i::GetElementsByNodes(const SMESH::smIdType_ar
std::vector<const SMDS_MeshElement *> elems; std::vector<const SMDS_MeshElement *> elems;
mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType ); mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType );
result->length( elems.size() ); result->length( elems.size() );
for ( smIdType i = 0; i < elems.size(); ++i ) for ( size_t i = 0; i < elems.size(); ++i )
result[i] = elems[i]->GetID(); result[i] = elems[i]->GetID();
} }
return result._retn(); return result._retn();