Salome HOME
Check mesh size before export
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 4ad5cb8c675c041e427fa8c400b0235e42219c1c..50a7e89101aa3d2d7a7e38a6503ac70c760411aa 100644 (file)
 
 #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!
 
@@ -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)
 {
-  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() );
 }
 
@@ -640,7 +646,7 @@ SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr       aSubShape,
 {
   Unexpect aCatch(SALOME_SalomeException);
 
-  const int prevNbMeshEnt = NbNodes() + NbElements();
+  const smIdType prevNbMeshEnt = NbNodes() + NbElements();
 
   if ( _preMeshInfo )
     _preMeshInfo->ForgetOrLoad();
@@ -1148,11 +1154,11 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup
     THROW_SALOME_CORBA_EXCEPTION( "RemoveGroupWithContents(): group does not belong to this mesh",
                                   SALOME::BAD_PARAM);
 
-  vector<int> nodeIds; // to remove nodes becoming free
+  vector<smIdType> nodeIds; // to remove nodes becoming free
   bool isNodal = ( theGroup->GetType() == SMESH::NODE );
   if ( !isNodal && !theGroup->IsEmpty() )
   {
-    CORBA::Long elemID = theGroup->GetID( 1 );
+    SMESH::smIdType elemID = theGroup->GetID( 1 );
     int nbElemNodes = GetElemNbNodes( elemID );
     if ( nbElemNodes > 0 )
       nodeIds.reserve( theGroup->Size() * nbElemNodes );
@@ -1857,7 +1863,7 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfIDSources& theGroups,
         SMDS_ElemIteratorPtr nIt = elOfType->nodesIterator();
         for ( nbChecked = 1; nIt->more() && !toStopChecking; ++nbChecked )
         {
-          const int nID = nIt->next()->GetID();
+          const smIdType nID = nIt->next()->GetID();
           if ( nID < isNodeInGroupsSize && isNodeInGroups[ nID ] &&
                isToInclude( nbChecked, ++nbCommon, nbNodes, nbCorners, toStopChecking ))
           {
@@ -2090,12 +2096,12 @@ void SMESH_Mesh_i::ReplaceShape(GEOM::GEOM_Object_ptr theNewGeom)
       while ( elemIt->more() )
       {
         const SMDS_MeshElement* e = elemIt->next();
-        const int          elemID = e->GetID();
+        const smIdType     elemID = e->GetID();
         const int         shapeID = e->GetShapeID();
         TRange &        lastRange = ranges.back();
         if ( lastRange.shapeID != shapeID ||
              lastRange.toID    != elemID )
-          ranges.push_back( TRange{ shapeID, elemID, elemID + 1 });
+          ranges.push_back( TRange{ shapeID, FromIdType<int>(elemID), FromIdType<int>(elemID + 1) });
         else
           lastRange.toID = elemID + 1;
 
@@ -2407,7 +2413,7 @@ void SMESH_Mesh_i::CheckGeomModif( bool theIsBreakLink )
   if ( !theIsBreakLink )
     if ( mainGO->GetType() == GEOM_GROUP || !geomChanged )  // is group or not modified
     {
-      int nb = NbNodes() + NbElements();
+      smIdType nb = NbNodes() + NbElements();
       CheckGeomGroupModif();
       if ( nb != NbNodes() + NbElements() ) // something removed due to hypotheses change
         _gen_i->UpdateIcons( me );
@@ -2795,7 +2801,7 @@ void SMESH_Mesh_i::CheckGeomGroupModif()
 
   if ( !_impl->HasShapeToMesh() ) return;
 
-  CORBA::Long nbEntities = NbNodes() + NbElements();
+  SMESH::smIdType nbEntities = NbNodes() + NbElements();
 
   // Check if group contents changed
 
@@ -2997,7 +3003,7 @@ void SMESH_Mesh_i::CheckGeomGroupModif()
 
   // Update icons
 
-  CORBA::Long newNbEntities = NbNodes() + NbElements();
+  SMESH::smIdType newNbEntities = NbNodes() + NbElements();
   list< SALOMEDS::SObject_wrap > soToUpdateIcons;
   if ( newNbEntities != nbEntities )
   {
@@ -3342,7 +3348,7 @@ SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
   while(its != logDS.end()){
     SMESHDS_Command *com = *its;
     int comType = com->GetType();
-    int lgcom = com->GetNumber();
+    smIdType lgcom = com->GetNumber();
     const list < smIdType >&intList = com->GetIndexes();
     int inum = intList.size();
     list < smIdType >::const_iterator ii = intList.begin();
@@ -3732,11 +3738,11 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char*    file,
  */
 //================================================================================
 
-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;
@@ -3763,10 +3769,9 @@ void SMESH_Mesh_i::ExportMED(const char*        file,
  */
 //================================================================================
 
-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();
 
@@ -3774,6 +3779,8 @@ void SMESH_Mesh_i::ExportSAUV (const char* file,
   TPythonDump() << SMESH::SMESH_Mesh_var( _this())
                 << ".ExportSAUV( r'" << file << "', " << 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)
 {
-  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 );
 }
 
 //================================================================================
@@ -3807,18 +3816,20 @@ void SMESH_Mesh_i::ExportDAT (const char *file)
 
 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 );
 }
 
 //================================================================================
@@ -3829,13 +3840,13 @@ void SMESH_Mesh_i::ExportUNV (const char *file)
 
 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 << " )";
 
@@ -3847,6 +3858,8 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
   // Perform Export
   PrepareForWriting( file );
   _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,
                                    const char*                 file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4260,6 +4273,8 @@ void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this())
                 << ".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,
                                    const char*                 file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4281,6 +4296,8 @@ void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this())
                 << ".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,
                                    ::CORBA::Boolean            isascii)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4308,6 +4325,8 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
                 << 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)
 {
 #ifdef WITH_CGNS
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4344,6 +4363,9 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
 
   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
@@ -4359,7 +4381,7 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
                              const char*                 file,
                              bool                        withRequiredGroups)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4372,6 +4394,8 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
                 << meshPart<< ", r'"
                 << file << "', "
                 << 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;
     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();
@@ -6324,7 +6348,7 @@ SMDS_ElemIteratorPtr SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_ptr theObje
     SMDSAbs_ElementType iterType = isNodes ? SMDSAbs_Node : elemType;
     if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theObject ))
     {
-      int nbIds;
+      SMESH::smIdType nbIds;
       if ( SMESH::smIdType* ids = SMESH_MeshEditor_i::GetTemporaryIDs( theObject, nbIds ))
         elemIt = SMDS_ElemIteratorPtr( new IDSourceIterator( meshDS, ids, nbIds, iterType ));
     }
@@ -7072,20 +7096,20 @@ smIdType SMESH_MeshPartDS::MinNodeID() const
 smIdType SMESH_MeshPartDS::MaxElementID() const
 {
   if ( _meshDS ) return _meshDS->MaxElementID();
-  int maxID = 0;
+  smIdType maxID = 0;
   for ( int iType = SMDSAbs_Edge; iType < SMDSAbs_NbElementTypes; ++iType )
     if ( !_elements[ iType ].empty() )
-      maxID = Max( maxID, (*_elements[ iType ].rbegin())->GetID() );
+      maxID = std::max( maxID, (*_elements[ iType ].rbegin())->GetID() );
   return maxID;
 }
 // -------------------------------------------------------------------------------------
 smIdType SMESH_MeshPartDS::MinElementID() const
 {
   if ( _meshDS ) return _meshDS->MinElementID();
-  int minID = 0;
+  smIdType minID = 0;
   for ( int iType = SMDSAbs_Edge; iType < SMDSAbs_NbElementTypes; ++iType )
     if ( !_elements[ iType ].empty() )
-      minID = Min( minID, (*_elements[ iType ].begin())->GetID() );
+      minID = std::min( minID, (*_elements[ iType ].begin())->GetID() );
   return minID;
 }
 // -------------------------------------------------------------------------------------