Salome HOME
IPAL54303: CGNS export problems
authoreap <eap@opencascade.com>
Fri, 25 Aug 2017 13:45:03 +0000 (16:45 +0300)
committereap <eap@opencascade.com>
Fri, 25 Aug 2017 13:45:03 +0000 (16:45 +0300)
13 files changed:
idl/SMESH_Mesh.idl
src/DriverCGNS/DriverCGNS_Write.cxx
src/DriverCGNS/DriverCGNS_Write.hxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_FieldSelectorWdg.cxx
src/SMESHGUI/SMESHGUI_FieldSelectorWdg.h
src/SMESHGUI/SMESH_msg_en.ts
src/SMESHUtils/SMESH_TryCatch.hxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx
src/SMESH_SWIG/smeshBuilder.py

index cef3831ee99245d92db46a343f57f552c267c7f8..d96d67db70fc7f833c4419948c3111db3af4b10f 100644 (file)
@@ -715,7 +715,8 @@ module SMESH
                     in boolean isascii ) raises (SALOME::SALOME_Exception);
     void ExportCGNS( in SMESH_IDSource meshPart, 
                      in string         file,
                     in boolean isascii ) raises (SALOME::SALOME_Exception);
     void ExportCGNS( in SMESH_IDSource meshPart, 
                      in string         file,
-                     in boolean        overwrite ) raises (SALOME::SALOME_Exception);
+                     in boolean        overwrite,
+                     in boolean        groupElemsByType) raises (SALOME::SALOME_Exception);
     void ExportGMF( in SMESH_IDSource  meshPart, 
                     in string          file,
                     in boolean         withRequiredGroups) raises (SALOME::SALOME_Exception);
     void ExportGMF( in SMESH_IDSource  meshPart, 
                     in string          file,
                     in boolean         withRequiredGroups) raises (SALOME::SALOME_Exception);
index 844bb863fb224023fed8656ba464d80ec2b2e729..657cb529e51a1bf349fb613e9aadffce27ead84d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "DriverCGNS_Write.hxx"
 
 
 #include "DriverCGNS_Write.hxx"
 
+#include "SMDS_IteratorOnIterators.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_VolumeTool.hxx"
 #include "SMESHDS_GroupBase.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_VolumeTool.hxx"
 #include "SMESHDS_GroupBase.hxx"
@@ -330,7 +331,24 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
   // write into a section all successive elements of one geom type
   int iSec;
   vector< cgsize_t > elemData;
   // write into a section all successive elements of one geom type
   int iSec;
   vector< cgsize_t > elemData;
-  SMDS_ElemIteratorPtr  elemIt = myMesh->elementsIterator();
+  SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator();
+  vector< SMDS_ElemIteratorPtr > elemItVec;
+  if ( _elementsByType )
+  {
+    // create an iterator returning all elements by type
+    for ( int type = SMDSEntity_Node + 1; type < SMDSEntity_Last; ++type )
+    {
+      if ( type == SMDSEntity_Ball )
+        continue; // not supported
+      elemIt = myMesh->elementEntityIterator( SMDSAbs_EntityType( type ));
+      if ( elemIt->more() )
+        elemItVec.push_back( elemIt );
+    }
+    typedef SMDS_IteratorOnIterators< const SMDS_MeshElement*,
+                                      vector< SMDS_ElemIteratorPtr > > TVecIterator;
+    elemIt.reset( new TVecIterator( elemItVec ));
+  }
+
   const SMDS_MeshElement* elem = elemIt->next();
   while ( elem )
   {
   const SMDS_MeshElement* elem = elemIt->next();
   while ( elem )
   {
@@ -397,6 +415,15 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
         elem = elemIt->more() ? elemIt->next() : 0;
       continue;
     }
         elem = elemIt->more() ? elemIt->next() : 0;
       continue;
     }
+    else // skip NOT SUPPORTED elements
+    {
+      while ( elemIt->more() )
+      {
+        elem = elemIt->next();
+        if ( elem->GetEntityType() != elemType )
+          break;
+      }
+    }
 
     SMESH_Comment sectionName( cg_ElementTypeName( cgType ));
     sectionName << " " << startID << " - " << cgID-1;
 
     SMESH_Comment sectionName( cg_ElementTypeName( cgType ));
     sectionName << " " << startID << " - " << cgID-1;
@@ -405,6 +432,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
                           cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
       return addMessage( cg_get_error(), /*fatal = */true );
   }
                           cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
       return addMessage( cg_get_error(), /*fatal = */true );
   }
+
   // Write polyhedral volumes
   // -------------------------
 
   // Write polyhedral volumes
   // -------------------------
 
@@ -531,6 +559,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
     CGNS_ENUMT( GridLocation_t ) location = CGNS_ENUMV( Vertex );
     if ( group->GetType() != SMDSAbs_Node )
     {
     CGNS_ENUMT( GridLocation_t ) location = CGNS_ENUMV( Vertex );
     if ( group->GetType() != SMDSAbs_Node )
     {
+#if CGNS_VERSION > 3130
+      location = CGNS_ENUMV( CellCenter );
+#else
       switch ( meshDim ) {
       case 3:
         switch ( group->GetType() ) {
       switch ( meshDim ) {
       case 3:
         switch ( group->GetType() ) {
@@ -551,6 +582,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
         location = CGNS_ENUMV( EdgeCenter ); break; // ???
         break;
       }
         location = CGNS_ENUMV( EdgeCenter ); break; // ???
         break;
       }
+#endif
     }
 
     // try to extract type of boundary condition from the group name
     }
 
     // try to extract type of boundary condition from the group name
@@ -568,6 +600,8 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
       const SMDS_MeshElement* elem = elemIt->next();
       pnts.push_back( cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ]));
     }
       const SMDS_MeshElement* elem = elemIt->next();
       pnts.push_back( cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ]));
     }
+    if ( pnts.size() == 0 )
+      continue; // can't store empty group
     int iBC;
     if ( cg_boco_write( _fn, iBase, iZone, name.c_str(), bcType,
                         CGNS_ENUMV( PointList ), pnts.size(), &pnts[0], &iBC) != CG_OK )
     int iBC;
     if ( cg_boco_write( _fn, iBase, iZone, name.c_str(), bcType,
                         CGNS_ENUMV( PointList ), pnts.size(), &pnts[0], &iBC) != CG_OK )
@@ -589,7 +623,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
  */
 //================================================================================
 
  */
 //================================================================================
 
-DriverCGNS_Write::DriverCGNS_Write(): _fn(0)
+DriverCGNS_Write::DriverCGNS_Write(): _fn(0), _elementsByType( false )
 {
 }
 
 {
 }
 
index e427f97541296039480173161e29fbe7d209b948..fd0ba22398ce0f8a2a758989a575e8cabc50efd3 100644 (file)
@@ -45,9 +45,16 @@ public:
 
   virtual Status Perform();
 
 
   virtual Status Perform();
 
+  // to export elements either in the order of their IDs or by geometric type
+  void SetElementsByType( bool isByType ) { _elementsByType = isByType; }
+
 private:
 
   int _fn; //!< file index
 private:
 
   int _fn; //!< file index
+
+  // if true all elements of same geometry are exported at ones,
+  // else elements are exported in order of their IDs
+  bool _elementsByType;
 };
 
 #endif
 };
 
 #endif
index 893a28aba659e6f8fbfb93475a251acddc4c0b97..cf9f77f0af2d5e9a57fed1706246a35d95342254 100644 (file)
@@ -1537,6 +1537,7 @@ void SMESH_Mesh::ExportUNV(const char *        file,
   myWriter.SetMeshId(_id);
   //  myWriter.SetGroups(_mapGroup);
 
   myWriter.SetMeshId(_id);
   //  myWriter.SetGroups(_mapGroup);
 
+  // pass group names to SMESHDS
   if ( !meshPart )
   {
     for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
   if ( !meshPart )
   {
     for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
@@ -1581,17 +1582,37 @@ void SMESH_Mesh::ExportSTL(const char *        file,
 
 void SMESH_Mesh::ExportCGNS(const char *        file,
                             const SMESHDS_Mesh* meshDS,
 
 void SMESH_Mesh::ExportCGNS(const char *        file,
                             const SMESHDS_Mesh* meshDS,
-                            const char *        meshName)
+                            const char *        meshName,
+                            const bool          groupElemsByType)
 {
   int res = Driver_Mesh::DRS_FAIL;
 {
   int res = Driver_Mesh::DRS_FAIL;
+
+  // pass group names to SMESHDS
+  for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
+    SMESH_Group*       group   = it->second;
+    SMESHDS_GroupBase* groupDS = group->GetGroupDS();
+    if ( groupDS ) {
+      string groupName = group->GetName();
+      groupDS->SetStoreName( groupName.c_str() );
+    }
+  }
 #ifdef WITH_CGNS
 #ifdef WITH_CGNS
+
   DriverCGNS_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
   myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
   if ( meshName && meshName[0] )
     myWriter.SetMeshName( meshName );
   DriverCGNS_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
   myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
   if ( meshName && meshName[0] )
     myWriter.SetMeshName( meshName );
+  myWriter.SetElementsByType( groupElemsByType );
   res = myWriter.Perform();
   res = myWriter.Perform();
+  if ( res != Driver_Mesh::DRS_OK )
+  {
+    SMESH_ComputeErrorPtr err = myWriter.GetError();
+    if ( err && !err->IsOK() && !err->myComment.empty() )
+      throw SALOME_Exception(("Export failed: " + err->myComment ).c_str() );
+  }
+
 #endif
   if ( res != Driver_Mesh::DRS_OK )
     throw SALOME_Exception("Export failed");
 #endif
   if ( res != Driver_Mesh::DRS_OK )
     throw SALOME_Exception("Export failed");
index a8ec5dfae4e0fdfc1762cd981c82ddcccc53dea1..91a1f2cdb5a810f314944d21be1b9726d57f093f 100644 (file)
@@ -267,7 +267,8 @@ class SMESH_EXPORT SMESH_Mesh
                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
   void ExportCGNS(const char *        file,
                   const SMESHDS_Mesh* mesh,
                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
   void ExportCGNS(const char *        file,
                   const SMESHDS_Mesh* mesh,
-                  const char *        meshName = 0);
+                  const char *        meshName = 0,
+                  const bool          groupElemsByType = false);
   void ExportGMF(const char *        file,
                  const SMESHDS_Mesh* mesh,
                  bool                withRequiredGroups = true );
   void ExportGMF(const char *        file,
                  const SMESHDS_Mesh* mesh,
                  bool                withRequiredGroups = true );
index 1145efb17d3b1fe336704c0005693a320a395e3a..afe1b1f6c0838f7217152994da361d18c651c553 100644 (file)
@@ -684,7 +684,14 @@ namespace
     }
     else if ( isCGNS )// Export to CGNS
     {
     }
     else if ( isCGNS )// Export to CGNS
     {
-      SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
+      const char* theByTypeResource = "cgns_group_elems_by_type";
+      toCreateGroups = SMESHGUI::resourceMgr()->booleanValue( "SMESH", theByTypeResource, false );
+
+      QStringList checkBoxes;
+      checkBoxes << QObject::tr("CGNS_EXPORT_ELEMS_BY_TYPE");
+
+      SalomeApp_CheckFileDlg* fd =
+        new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
       fd->setWindowTitle( aTitle );
       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
       if ( !anInitialPath.isEmpty() )
       fd->setWindowTitle( aTitle );
       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
       if ( !anInitialPath.isEmpty() )
@@ -692,10 +699,13 @@ namespace
       fd->selectFile(aMeshName);
       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
       fd->setValidator( fv );
       fd->selectFile(aMeshName);
       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
       fd->setValidator( fv );
+      fd->SetChecked( toCreateGroups, 0 );
 
       if ( fd->exec() )
         aFilename = fd->selectedFile();
 
       if ( fd->exec() )
         aFilename = fd->selectedFile();
-      toOverwrite = fv->isOverwrite();
+      toOverwrite    = fv->isOverwrite();
+      toCreateGroups = fd->IsChecked(0);
+      SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups );
 
       delete fd;
     }
 
       delete fd;
     }
@@ -754,7 +764,7 @@ namespace
 
       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
       QList< QWidget* > wdgList;
 
       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
       QList< QWidget* > wdgList;
-      if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
+      if ( fieldSelWdg->GetAllFields( aMeshList, aFieldList ))
         wdgList.append( fieldSelWdg );
 
       SalomeApp_CheckFileDlg* fd =
         wdgList.append( fieldSelWdg );
 
       SalomeApp_CheckFileDlg* fd =
@@ -858,7 +868,7 @@ namespace
       }
       toCreateGroups = fd->IsChecked(0);
       toFindOutDim   = fd->IsChecked(1);
       }
       toCreateGroups = fd->IsChecked(0);
       toFindOutDim   = fd->IsChecked(1);
-      fieldSelWdg->GetSelectedFeilds();
+      fieldSelWdg->GetSelectedFields();
       if ( !fieldSelWdg->parent() )
         delete fieldSelWdg;
       delete fd;
       if ( !fieldSelWdg->parent() )
         delete fieldSelWdg;
       delete fd;
@@ -948,7 +958,8 @@ namespace
             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
             aMeshItem->ExportCGNS( aMeshOrGroup,
                                    aFilename.toUtf8().data(),
             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
             aMeshItem->ExportCGNS( aMeshOrGroup,
                                    aFilename.toUtf8().data(),
-                                   toOverwrite && aMeshIndex == 0 );
+                                   toOverwrite && aMeshIndex == 0,
+                                   toCreateGroups );
           }
         }
         else if ( isGMF )
           }
         }
         else if ( isGMF )
index 8b060f647c19d1c999e820f0673fac252cc3aeaf..91034498099e2bca288b7a9b63f0b97c0eb32f72 100644 (file)
@@ -86,7 +86,7 @@ SMESHGUI_FieldSelectorWdg::SMESHGUI_FieldSelectorWdg( QWidget* p )
  * \brief Retrieves all fields defined on geometry of given meshes
  */
 bool SMESHGUI_FieldSelectorWdg::
  * \brief Retrieves all fields defined on geometry of given meshes
  */
 bool SMESHGUI_FieldSelectorWdg::
-GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
+GetAllFields(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
              QList< QPair< GEOM::ListOfFields_var, QString > >&          fields)
 {
   myFields = & fields;
              QList< QPair< GEOM::ListOfFields_var, QString > >&          fields)
 {
   myFields = & fields;
@@ -166,7 +166,7 @@ GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
 /*!
  * \brief Filter off not selected fields from myFields
  */
 /*!
  * \brief Filter off not selected fields from myFields
  */
-bool SMESHGUI_FieldSelectorWdg::GetSelectedFeilds()
+bool SMESHGUI_FieldSelectorWdg::GetSelectedFields()
 {
   int nbSelected = 0;
   if ( myTree->isEnabled() )
 {
   int nbSelected = 0;
   if ( myTree->isEnabled() )
index 8a88bf41d77954ff6eff8222a2a7afb6785f5ee7..025a4de7308b4805d8b50307d37a5af061bee136 100644 (file)
@@ -43,13 +43,13 @@ class SMESHGUI_EXPORT SMESHGUI_FieldSelectorWdg : public QGroupBox
  public:
   SMESHGUI_FieldSelectorWdg( QWidget* = 0 );
 
  public:
   SMESHGUI_FieldSelectorWdg( QWidget* = 0 );
 
-  bool GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
+  bool GetAllFields(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
                     QList< QPair< GEOM::ListOfFields_var,          QString > >& fields);
 
                     QList< QPair< GEOM::ListOfFields_var,          QString > >& fields);
 
-  bool GetSelectedFeilds();
+  bool GetSelectedFields();
 
  private slots:
 
  private slots:
-  
+
   void onItemCheck(QTreeWidgetItem * item, int column);
 
  private:
   void onItemCheck(QTreeWidgetItem * item, int column);
 
  private:
index a5e80c6594129f1b5e6b9f370e5f2a5c779e4f0f..bd744f709dfd5ddc8e4a55ad5976fc0be79cd6ba 100644 (file)
         <source>CGNS_FILES_FILTER</source>
         <translation>CGNS files</translation>
     </message>
         <source>CGNS_FILES_FILTER</source>
         <translation>CGNS files</translation>
     </message>
+    <message>
+        <source>CGNS_EXPORT_ELEMS_BY_TYPE</source>
+        <translation>Group elements by type</translation>
+    </message>
     <message>
         <source>GMF_ASCII_FILES_FILTER</source>
         <translation>GMF ASCII files</translation>
     <message>
         <source>GMF_ASCII_FILES_FILTER</source>
         <translation>GMF ASCII files</translation>
index ccdf3b1dadcf4b2ace94d8f4b3f8a254df3abdec..05d00a1b551b76b60b431565434e55b246ada466 100644 (file)
 #define OCC_CATCH_SIGNALS
 #endif
 
 #define OCC_CATCH_SIGNALS
 #endif
 
-// Define macros to catch and convert some of possible exceptions into text or SALOME_Exception
+// Define macros to catch and convert some of possible exceptions into text or SALOME_Exception.
+// WARNING: SALOME::SALOME_Exception (CORBA exception) is not treated here; to care about it add
+//          #define SMY_OWN_CATCH catch ( SALOME::SALOME_Exception & e ) { do_something(e); }
+//          before #include<SMESH_TryCatch.hxx>
+
 
 //-------------------------------------------------------------------------------------
 #define SMESH_TRY                               \
 
 //-------------------------------------------------------------------------------------
 #define SMESH_TRY                               \
index 268dfd829b3fc4fc058a6aa1a141a57ec528911e..1634462335e320232a37275c649a69ac98278660 100644 (file)
@@ -3628,7 +3628,8 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
 
 void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
                               const char*                 file,
 
 void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
                               const char*                 file,
-                              CORBA::Boolean              overwrite)
+                              CORBA::Boolean              overwrite,
+                              CORBA::Boolean              groupElemsByType)
   throw (SALOME::SALOME_Exception)
 {
 #ifdef WITH_CGNS
   throw (SALOME::SALOME_Exception)
 {
 #ifdef WITH_CGNS
@@ -3646,8 +3647,12 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
     CORBA::String_var name = so->GetName();
     meshName = name.in();
   }
     CORBA::String_var name = so->GetName();
     meshName = name.in();
   }
+  SMESH_TRY;
+
   SMESH_MeshPartDS partDS( meshPart );
   SMESH_MeshPartDS partDS( meshPart );
-  _impl->ExportCGNS(file, &partDS, meshName.c_str() );
+  _impl->ExportCGNS(file, &partDS, meshName.c_str(), groupElemsByType );
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
                 << meshPart<< ", r'" << file << "', " << overwrite << ")";
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
                 << meshPart<< ", r'" << file << "', " << overwrite << ")";
index 62d08763d3e4dac3a7c3aa8514e0e1f3387e57f4..39fd2aa1cd12d618a8ef6534acdb21ca6784b293 100644 (file)
@@ -251,7 +251,8 @@ public:
   void ExportSTL( const char* file, bool isascii ) throw (SALOME::SALOME_Exception);
   void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart,
                   const char*               file,
   void ExportSTL( const char* file, bool isascii ) throw (SALOME::SALOME_Exception);
   void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart,
                   const char*               file,
-                  CORBA::Boolean            overwrite) throw (SALOME::SALOME_Exception);
+                  CORBA::Boolean            overwrite,
+                  CORBA::Boolean            groupElemsByType) throw (SALOME::SALOME_Exception);
   void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart,
                  const char*               file,
                  CORBA::Boolean            withRequiredGroups) throw (SALOME::SALOME_Exception);
   void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart,
                  const char*               file,
                  CORBA::Boolean            withRequiredGroups) throw (SALOME::SALOME_Exception);
index 8105c71c6d3b0a11630f3a52d93d0021f5f38dcf..11ba7dcf72b55763411e21c5d6621de22fa550fa 100644 (file)
@@ -1879,8 +1879,11 @@ class Mesh:
     #  @param f is the file name
     #  @param overwrite boolean parameter for overwriting/not overwriting the file
     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
     #  @param f is the file name
     #  @param overwrite boolean parameter for overwriting/not overwriting the file
     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
+    #  @param groupElemsByType if true all elements of same entity type are exported at ones,
+    #         else elements are exported in order of their IDs which can cause creation
+    #         of multiple cgns sections
     #  @ingroup l2_impexp
     #  @ingroup l2_impexp
-    def ExportCGNS(self, f, overwrite=1, meshPart=None):
+    def ExportCGNS(self, f, overwrite=1, meshPart=None, groupElemsByType=False):
         unRegister = genObjUnRegister()
         if isinstance( meshPart, list ):
             meshPart = self.GetIDSource( meshPart, SMESH.ALL )
         unRegister = genObjUnRegister()
         if isinstance( meshPart, list ):
             meshPart = self.GetIDSource( meshPart, SMESH.ALL )
@@ -1889,7 +1892,7 @@ class Mesh:
             meshPart = meshPart.mesh
         elif not meshPart:
             meshPart = self.mesh
             meshPart = meshPart.mesh
         elif not meshPart:
             meshPart = self.mesh
-        self.mesh.ExportCGNS(meshPart, f, overwrite)
+        self.mesh.ExportCGNS(meshPart, f, overwrite, groupElemsByType)
 
     ## Export the mesh in a file in GMF format.
     #  GMF files must have .mesh extension for the ASCII format and .meshb for
 
     ## Export the mesh in a file in GMF format.
     #  GMF files must have .mesh extension for the ASCII format and .meshb for
@@ -2010,6 +2013,8 @@ class Mesh:
     #  @ingroup l2_grps_create
     def MakeGroupByIds(self, groupName, elementType, elemIDs):
         group = self.mesh.CreateGroup(elementType, groupName)
     #  @ingroup l2_grps_create
     def MakeGroupByIds(self, groupName, elementType, elemIDs):
         group = self.mesh.CreateGroup(elementType, groupName)
+        if isinstance( elemIDs, Mesh ):
+            elemIDs = elemIDs.GetMesh()
         if hasattr( elemIDs, "GetIDs" ):
             if hasattr( elemIDs, "SetMesh" ):
                 elemIDs.SetMesh( self.GetMesh() )
         if hasattr( elemIDs, "GetIDs" ):
             if hasattr( elemIDs, "SetMesh" ):
                 elemIDs.SetMesh( self.GetMesh() )