#define _INCLUDE_DRIVER_MESH
#include "SMESH_ComputeError.hxx"
+#include "SMDS_Mesh.hxx"
#include <string>
#include <vector>
enum Status {
DRS_OK,
- DRS_EMPTY, // a file contains no mesh with the given name
- DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
- // so the numbers from the file are ignored
- DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
+ DRS_EMPTY, // a file contains no mesh with the given name
+ DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
+ // so the numbers from the file are ignored
+ 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_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);
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:
std::string myFile;
std::string myMeshName;
if ( !myMesh || myMesh->GetMeshInfo().NbElements() < 1 )
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
if ( cg_open(myFile.c_str(), CG_MODE_MODIFY, &_fn) != CG_OK &&
cg_open(myFile.c_str(), CG_MODE_WRITE, &_fn) != CG_OK )
else if ( meshDim == 2 )
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;
if ( cg_zone_write( _fn, iBase, "SMESH_Mesh", size,
CGNS_ENUMV( Unstructured ), &iZone) != CG_OK )
{
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;
int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
}
}
+//================================================================================
+/*!
+ * \brief Write my mesh
+ */
+//================================================================================
+
Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
{
Status aResult = DRS_OK;
try {
//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
//-------------------------------------------------------
string aMeshName;
aTCoordSlice[2] = 0.;
// node number
- int aNodeID = aCoordHelperPtr->GetID();
+ TInt aNodeID = FromIdType<TInt>( aCoordHelperPtr->GetID() );
aNodeInfo->SetElemNum( iNode, aNodeID );
#ifdef _EDF_NODE_IDS_
aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
{
Kernel_Utils::Localizer loc;
Status aResult = DRS_OK;
+
+ if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
+ return DRS_TOO_LARGE_MESH;
+
#if defined(WIN32) && defined(UNICODE)
std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
std::ofstream out_stream(aFile.c_str());
EXCEPTION(runtime_error,"ERROR: Output file not good.");
}
catch(const std::exception& exc){
- INFOS("Follow exception was cought:\n\t"<<exc.what());
+ INFOS("Follow exception was caught:\n\t"<<exc.what());
throw;
}
catch(...){
- INFOS("Unknown exception was cought !!!");
+ INFOS("Unknown exception was caught !!!");
throw;
}
return aResult;
bool theAllElemsToGroup)
{
MESSAGE("MED_VERSION:"<< theVersion);
+
+ Driver_Mesh::Status status;
SMESH_TRY;
DriverMED_W_SMESHDS_Mesh myWriter;
}
}
// Perform export
- myWriter.Perform();
+ status = myWriter.Perform();
SMESH_CATCH( SMESH::throwSalomeEx );
+
+ if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+ throw TooLargeForExport("MED");
}
//================================================================================
cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
cmd += "\"";
system(cmd.c_str());
- ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
- /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
- /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+ try {
+ ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
+ /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
+ /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+ }
+ catch ( TooLargeForExport )
+ {
+ throw TooLargeForExport("SAUV");
+ }
#ifdef WIN32
cmd = "%PYTHONBIN% ";
#else
void SMESH_Mesh::ExportDAT(const char * file,
const SMESHDS_Mesh* meshPart)
{
- Unexpect aCatch(SalomeException);
+ Driver_Mesh::Status status;
+ SMESH_TRY;
+
DriverDAT_W_SMDS_Mesh myWriter;
myWriter.SetFile( file );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetMeshId(_id);
- myWriter.Perform();
+ status = myWriter.Perform();
+
+ SMESH_CATCH( SMESH::throwSalomeEx );
+
+ if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+ throw TooLargeForExport("DAT");
}
//================================================================================
void SMESH_Mesh::ExportUNV(const char * file,
const SMESHDS_Mesh* meshPart)
{
- Unexpect aCatch(SalomeException);
+ Driver_Mesh::Status status;
+
+ SMESH_TRY;
DriverUNV_W_SMDS_Mesh myWriter;
myWriter.SetFile( file );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
}
}
}
- myWriter.Perform();
+ status = myWriter.Perform();
+
+ SMESH_CATCH( SMESH::throwSalomeEx );
+
+ if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+ throw TooLargeForExport("UNV");
}
//================================================================================
const char * name,
const SMESHDS_Mesh* meshPart)
{
- Unexpect aCatch(SalomeException);
+ Driver_Mesh::Status status;
+ SMESH_TRY;
+
DriverSTL_W_SMDS_Mesh myWriter;
myWriter.SetFile( file );
myWriter.SetIsAscii( isascii );
myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
myWriter.SetMeshId(_id);
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");
}
//================================================================================
const char * meshName,
const bool groupElemsByType)
{
+
int res = Driver_Mesh::DRS_FAIL;
+ SMESH_TRY;
// pass group names to SMESHDS
std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
}
#endif
+ SMESH_CATCH( SMESH::throwSalomeEx );
+
+ if ( res == Driver_Mesh::DRS_TOO_LARGE_MESH )
+ throw TooLargeForExport("CGNS");
+
if ( res != Driver_Mesh::DRS_OK )
throw SALOME_Exception("Export failed");
}
const SMESHDS_Mesh* meshDS,
bool withRequiredGroups)
{
+ Driver_Mesh::Status status;
+ SMESH_TRY;
+
DriverGMF_Write myWriter;
myWriter.SetFile( file );
myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
myWriter.SetExportRequiredGroups( withRequiredGroups );
- myWriter.Perform();
+ status = myWriter.Perform();
+
+ SMESH_CATCH( SMESH::throwSalomeEx );
+
+ if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+ throw TooLargeForExport("GMF");
}
//================================================================================
*/
typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap;
const TAncestorMap& GetAncestorMap() const { return _mapAncestors; }
+
/*!
* \brief Check group names for duplications.
* Consider maximum group name length stored in MED file
*/
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,
const char* theMeshName = NULL,
bool theAutoGroups = true,
aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
}
}
- catch (const SALOME::SALOME_Exception& S_ex){
+ catch (const SALOME::SALOME_Exception& S_ex)
+ {
wc.suspend();
- SUIT_MessageBox::warning(SMESHGUI::desktop(),
- QObject::tr("SMESH_WRN_WARNING"),
- QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
+ 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(),
+ QObject::tr("SMESH_WRN_WARNING"),
+ QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
wc.resume();
}
}
lab = lab + tr("INFO_COMPUTE") + "<br/>";
lab = lab + tr("INFO_REFINE") + ":";
items << wrap(tr("INFO_REFINE_LOCAL_SIZE"), "li")
- << wrap(tr("INFO_REFINE_SUBMESH"), "li");
+ << wrap(tr("INFO_REFINE_SUBMESH"), "li");
lab = lab + wrap(items.join(""), "ul");
items.clear();
gb = app->infoPanel()->addGroup(tr("INFO_GRP_IMPORT_MESH"));
items << wrap("UNV", "li")
- << wrap("MED", "li")
- << wrap("STL", "li")
- << wrap("CGNS", "li")
- << wrap("SAUV", "li")
- << wrap("GMF", "li");
+ << wrap("MED", "li")
+ << wrap("STL", "li")
+ << wrap("CGNS", "li")
+ << wrap("SAUV", "li")
+ << wrap("GMF", "li");
lab = tr("INFO_AVAILABLE_FORMATS") + ":" + wrap(items.join(""), "ul");
items.clear();
-
+
app->infoPanel()->addLabel(lab, gb);
gb = app->infoPanel()->addGroup(tr("INFO_GRP_CHECK_MESH"));
lab = tr("INFO_DISPLAY") + "<br/>";
items << wrap(tr("INFO_QUALITY_AREA"), "li")
- << wrap(tr("INFO_QUALITY_VOLUME"), "li")
- << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
- << wrap("...", "li");
+ << wrap(tr("INFO_QUALITY_VOLUME"), "li")
+ << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
+ << wrap("...", "li");
lab = lab + tr("INFO_QUALITY_INFO") + ":" + wrap(items.join(""), "ul");
items.clear();
lab = lab + tr("INFO_CLIPPING");
//-------------------------------------------------------------------------------------
// 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.
#define SMESH_CATCH( onExceptionFun ) \
} \
+ \
+ SMY_OWN_CATCH \
+ \
catch (Standard_Failure& ex) \
{ \
SMESH_Comment text("OCCT Exception: "); \
{ \
SMESH_CAUGHT onExceptionFun( ex.what() ); \
} \
- \
- SMY_OWN_CATCH \
- \
catch (...) \
{ \
SMESH_CAUGHT onExceptionFun("Unknown Exception caught"); \
#include <vtkUnstructuredGridWriter.h>
-// to pass CORBA exception through SMESH_TRY
-#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; }
+// to pass CORBA exception and TooLargeForExport exception through SMESH_TRY
+#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!
char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
{
- string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor,
- nbDigits);
+ string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, nbDigits);
return CORBA::string_dup( ver.c_str() );
}
*/
//================================================================================
-void SMESH_Mesh_i::ExportMED(const char* file,
- CORBA::Boolean auto_groups,
- CORBA::Long version,
- CORBA::Boolean overwrite,
- CORBA::Boolean autoDimension)
+void SMESH_Mesh_i::ExportMED(const char* file,
+ CORBA::Boolean auto_groups,
+ CORBA::Long version,
+ CORBA::Boolean overwrite,
+ CORBA::Boolean autoDimension)
{
//MESSAGE("MED minor version: "<< minor);
SMESH_TRY;
*/
//================================================================================
-void SMESH_Mesh_i::ExportSAUV (const char* file,
- CORBA::Boolean auto_groups)
+void SMESH_Mesh_i::ExportSAUV( const char* file, CORBA::Boolean auto_groups )
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
TPythonDump() << SMESH::SMESH_Mesh_var( _this())
<< ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
_impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
void SMESH_Mesh_i::ExportDAT (const char *file)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
- // Update Python script
// check names of groups
checkGroupNames();
+ // Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
// Perform Export
PrepareForWriting(file);
_impl->ExportDAT(file);
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
void SMESH_Mesh_i::ExportUNV (const char *file)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
- // Update Python script
// check names of groups
checkGroupNames();
+ // Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
// Perform Export
PrepareForWriting(file);
_impl->ExportUNV(file);
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
- // Update Python script
// check names of groups
checkGroupNames();
+ // Update Python script
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportSTL( r'" << file << "', " << isascii << " )";
// Perform Export
PrepareForWriting( file );
_impl->ExportSTL( file, isascii, name.in() );
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
/*!
void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
<< ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
/*!
const char* file,
::CORBA::Boolean isascii)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
<< meshPart<< ", r'" << file << "', " << isascii << ")";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//================================================================================
CORBA::Boolean groupElemsByType)
{
#ifdef WITH_CGNS
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
<< meshPart<< ", r'" << file << "', " << overwrite << ")";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
#else
THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
#endif
const char* file,
bool withRequiredGroups)
{
- Unexpect aCatch(SALOME_SalomeException);
+ SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
<< meshPart<< ", r'"
<< file << "', "
<< withRequiredGroups << ")";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
}
//=============================================================================
std::vector<const SMDS_MeshElement *> elems;
mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType );
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();
}
return result._retn();