Salome HOME
[bos #41122][EDF] Quadrangle radial for face which curved edges didn't discretize...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 69cbc7390bcfaa078d777a057ee03f7710147467..fe6d17ac64be9e441f31443edadebca3f08833fc 100644 (file)
 //  File   : SMESHGUI.cxx
 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
 
+#include <Basics_OCCTVersion.hxx>
+
+#if OCC_VERSION_LARGE < 0x07080000
+
 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
+
+#else
+
+#ifdef _MSC_VER
+#ifndef _USE_MATH_DEFINES
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#endif
+
+#endif
+
 #ifdef HAVE_FINITE
 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
 #endif
@@ -70,6 +86,7 @@
 #include "SMESHGUI_Measurements.h"
 #include "SMESHGUI_MergeDlg.h"
 #include "SMESHGUI_MeshInfo.h"
+#include "SMESHGUI_Meshio.h"
 #include "SMESHGUI_MeshOp.h"
 #include "SMESHGUI_MeshOrderOp.h"
 #include "SMESHGUI_MeshPatternDlg.h"
@@ -213,6 +230,7 @@ namespace
   void Control( int theCommandID );
 
   // Definitions
+
   //================================================================================
   /*!
    * \brief Reads meshes from file
@@ -251,6 +269,12 @@ namespace
       filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"  );
       filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
     }
+    else if (theCommandID == SMESHOp::OpImportMESHIO) {
+      if (!SMESHGUI_Meshio::IsMeshioInstalled())
+        return;
+
+      filter = SMESHGUI_Meshio::GetImportFileFilter();
+    }
 
     QString anInitialPath = "";
     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
@@ -366,11 +390,20 @@ namespace
               }
               break;
             }
+          case SMESHOp::OpImportMESHIO:
+            {
+              aMeshes = SMESHGUI_Meshio::ImportMesh(theComponentMesh, filename, errors);
+              break;
+            }
           }
         }
         catch ( const SALOME::SALOME_Exception& S_ex ) {
-          errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
-                         arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
+          const QString exText(S_ex.details.text);
+          if (exText.startsWith("MESHIO"))
+            errors.append('\n' + exText);
+          else
+            errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
         }
 
         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
@@ -440,8 +473,14 @@ namespace
                          theCommandID == SMESHOp::OpPopupExportCGNS );
     const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF ||
                          theCommandID == SMESHOp::OpPopupExportGMF );
+    const bool isMESHIO = (theCommandID == SMESHOp::OpExportMESHIO);
+
+    if (isMESHIO && !SMESHGUI_Meshio::IsMeshioInstalled())
+    {
+      return;
+    }
 
-    const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
+    const bool multiMeshSupported = isMED || isCGNS || isMESHIO; // file can hold several meshes
     if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
       return;
     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
@@ -517,7 +556,7 @@ namespace
     SMESH::SMESH_Mesh_var            aMesh = aMeshOrGroup->GetMesh();
     QString                      aMeshName = (*aMeshIter).second;
 
-    if ( isMED || isCGNS ) // formats where group names must be unique
+    if (isMED || isCGNS || isMESHIO) // formats where group names must be unique
     {
       // check for equal group names within each mesh
       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
@@ -568,7 +607,7 @@ namespace
     {
       format = "CGNS";
       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
-    }
+    }    
     else if ( isGMF )
     {
       format = "GMF";
@@ -627,6 +666,7 @@ namespace
     // Get parameters of export operation
 
     QString aFilename;
+    QString aSelectedFilter; // for meshio to get a filter selected by user
     int aFormat =-1;         // for MED version used for write
     bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
 
@@ -637,6 +677,7 @@ namespace
     bool   toFindOutDim = true;
     bool    saveNumbers = resMgr->booleanValue( "SMESH", "med_save_numbers", true );
     bool     toRenumber = true;
+    bool  structureCGNS = false;
     double         zTol = resMgr->doubleValue( "SMESH", "med_ztolerance", 0. );
 
     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
@@ -657,20 +698,51 @@ namespace
                                             anInitialPath + QString("/") + aMeshName,
                                             aFilter, aTitle, false);
     }
-    else if ( isCGNS || isUNV || isDAT ) // Export to [ CGNS | UNV | DAT ] - one option
+    else if ( isCGNS )
     {
-      const char* theOptionResource = isCGNS ? "cgns_group_elems_by_type" : "export_renumber";
+      const char* theOptionResource = "cgns_group_elems_by_type";
       bool option = resMgr->booleanValue( "SMESH", theOptionResource, false );
 
       QStringList checkBoxes;
-      checkBoxes << QObject::tr( isCGNS ? "CGNS_EXPORT_ELEMS_BY_TYPE" : "SMESH_RENUMBER" );
+      checkBoxes << QObject::tr( "CGNS_EXPORT_ELEMS_BY_TYPE" ) << QObject::tr("STRUCTUREDCGNS");
+
+      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->setDirectory( anInitialPath );
+      fd->selectFile( aMeshName );
+      SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
+      fd->setValidator( fv );
+      fd->SetChecked( option, 0 );
+      
+      if ( fd->exec() )
+      {
+        aFilename     = fd->selectedFile();
+        structureCGNS = fd->IsChecked( 1 );        
+      }
+
+      toOverwrite = fv->isOverwrite( aFilename );
+      option      = fd->IsChecked( 0 );
+      SMESHGUI::resourceMgr()->setValue("SMESH", theOptionResource, option );
+      toCreateGroups = option;
+      
+      delete fd;
+    }
+    else if ( isUNV || isDAT ) // Export to [ UNV | DAT ] - one option
+    {
+      const char* theOptionResource = "export_renumber";
+      bool option = resMgr->booleanValue( "SMESH", theOptionResource, false );
+
+      QStringList checkBoxes;
+      checkBoxes << QObject::tr( "SMESH_RENUMBER" );
 
       SalomeApp_CheckFileDlg* fd =
         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
       fd->setWindowTitle( aTitle );
-      if ( isCGNS )
-        fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
-      else if ( isUNV )
+      if ( isUNV )
         fd->setNameFilter( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
       else if ( isDAT )
         fd->setNameFilter( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
@@ -686,25 +758,25 @@ namespace
       toOverwrite    = fv->isOverwrite( aFilename );
       option = fd->IsChecked( 0 );
       SMESHGUI::resourceMgr()->setValue("SMESH", theOptionResource, option );
-      ( isCGNS ? toCreateGroups : toRenumber ) = option;
+      toRenumber = option;
 
       delete fd;
     }
     else if ( isSTL ) // Export to STL
     {
       QMap<QString, int> aFilterMap;
+      QStringList filters;
       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
-
-      QStringList filters;
+      
       QMap<QString, int>::const_iterator it = aFilterMap.begin();
       for ( ; it != aFilterMap.end(); ++it )
-        filters.push_back( it.key() );
-
+        filters.push_back( it.key() );    
+     
       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
       fd->setWindowTitle( aTitle );
       fd->setNameFilters( filters );
-      fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
+
       if ( !anInitialPath.isEmpty() )
         fd->setDirectory( anInitialPath );
       fd->selectFile(aMeshName);
@@ -712,7 +784,8 @@ namespace
       while (!is_ok) {
         if ( fd->exec() )
           aFilename = fd->selectedFile();
-        aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
+        if ( isSTL )
+          aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
         is_ok = true;
       }
       delete fd;
@@ -872,6 +945,14 @@ namespace
         delete zTolWdg;
       delete fd;
     }
+    else if (isMESHIO)
+    {
+      if (SMESHGUI_Meshio::CheckMeshCount(aMeshList))
+      {
+        aFilename = SMESHGUI_Meshio::GetFileName(aSelectedFilter);
+        MESSAGE("aSelectedFilter: " << aSelectedFilter.toStdString());
+      }
+    }
     else
     {
       return;
@@ -939,14 +1020,21 @@ namespace
         else if ( isCGNS )
         {
           aMeshIter = aMeshList.begin();
+
           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
           {
             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
-            aMeshItem->ExportCGNS( aMeshOrGroup,
-                                   aFilename.toUtf8().data(),
-                                   toOverwrite && aMeshIndex == 0,
-                                   toCreateGroups );
+
+            if ( !structureCGNS )
+              aMeshItem->ExportCGNS( aMeshOrGroup,
+                                    aFilename.toUtf8().data(),
+                                    toOverwrite && aMeshIndex == 0,
+                                    toCreateGroups );
+            else                                  
+              aMeshItem->ExportStructuredCGNS( aMeshOrGroup,
+                                                aFilename.toUtf8().data(),
+                                                toOverwrite && aMeshIndex == 0 );
           }
         }
         else if ( isGMF )
@@ -954,20 +1042,38 @@ namespace
           toCreateGroups = true;
           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
         }
+        else if (isMESHIO)
+        {
+          SMESHGUI_Meshio::ExportMesh(aMeshList, aFilename, aSelectedFilter);
+        }
       }
       catch (const SALOME::SALOME_Exception& S_ex)
       {
         wc.suspend();
+        const QString exText(S_ex.details.text);
+
         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
+        else if (exText.startsWith("MESHIO"))
+        {
+          SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                   QObject::tr("SMESH_WRN_WARNING"),
+                                   QObject::tr("SMESH_EXPORT_FAILED_SHORT") + "\n\n" + exText);
+        }
+        else if ( isMED )
+        {
           SUIT_MessageBox::warning(SMESHGUI::desktop(),
                                    QObject::tr("SMESH_WRN_WARNING"),
                                    QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
+        }          
+        else
+          SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                   QObject::tr("SMESH_WRN_WARNING"),
+                                   SalomeApp_Tools::ExceptionToString(S_ex));                                           
         wc.resume();
       }
     }
@@ -2560,6 +2666,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
 
   //QAction* act = action( theCommandID );
+  bool logAction(false);
 
   switch (theCommandID) {
   case SMESHOp::OpDelete:
@@ -2572,6 +2679,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case SMESHOp::OpImportSTL:
   case SMESHOp::OpImportCGNS:
   case SMESHOp::OpImportGMF:
+  case SMESHOp::OpImportMESHIO:
   case SMESHOp::OpPopupImportDAT:
   case SMESHOp::OpPopupImportUNV:
   case SMESHOp::OpPopupImportMED:
@@ -2608,6 +2716,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case SMESHOp::OpExportSTL:
   case SMESHOp::OpExportCGNS:
   case SMESHOp::OpExportGMF:
+  case SMESHOp::OpExportMESHIO:
   case SMESHOp::OpPopupExportDAT:
   case SMESHOp::OpPopupExportMED:
   case SMESHOp::OpPopupExportUNV:
@@ -2877,6 +2986,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     break;
   case SMESHOp::OpCopyMesh:
     {
+      logAction = true;
       if (isStudyLocked()) break;
       EmitSignalDeactivateDialog();
       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
@@ -3702,6 +3812,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     }
   case SMESHOp::OpTranslation:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -3717,6 +3828,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     }
   case SMESHOp::OpRotation:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -3732,6 +3844,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     }
   case SMESHOp::OpSymmetry:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -3747,6 +3860,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     }
   case SMESHOp::OpScale:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -3763,6 +3877,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   case SMESHOp::OpOffset:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -3779,6 +3894,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   case SMESHOp::OpSewing:
     {
+      logAction = true;
       if(isStudyLocked()) break;
       if ( warnOnGeomModif() )
         break; // action forbidden as geometry modified
@@ -4008,6 +4124,14 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   anApp->updateActions(); //SRN: To update a Save button in the toolbar
   //updateObjBrowser();
+  if(logAction)
+  {
+    QAction* anAction = action( theCommandID );
+    CAM_Application::logStructuredUserEvent( "Mesh",
+                                             "Operation",
+                                             anAction->text(),
+                                             "activated" );
+  }
   return true;
 }
 
@@ -4072,7 +4196,7 @@ void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QStr
     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICON_%1" ).arg( po_id ).toLatin1().data() ), false );
   if ( !pix.isNull() )
     icon = QIcon( pix );
-
+  
   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
@@ -4136,6 +4260,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( SMESHOp::OpImportCGNS, "IMPORT_CGNS" );
 #endif
   createSMESHAction( SMESHOp::OpImportGMF,  "IMPORT_GMF"  );
+  createSMESHAction( SMESHOp::OpImportMESHIO,  "IMPORT_MESHIO" );
   createSMESHAction( SMESHOp::OpPopupImportUNV, "IMPORT_UNV");
   createSMESHAction( SMESHOp::OpPopupImportMED, "IMPORT_MED");
   createSMESHAction( SMESHOp::OpPopupImportSTL, "IMPORT_STL"  );
@@ -4152,6 +4277,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( SMESHOp::OpExportCGNS, "CGNS");
 #endif
   createSMESHAction( SMESHOp::OpExportGMF,      "GMF" );
+  createSMESHAction( SMESHOp::OpExportMESHIO,   "EXPORT_MESHIO" );
   createSMESHAction( SMESHOp::OpPopupExportDAT, "DAT" );
   createSMESHAction( SMESHOp::OpPopupExportMED, "MED" );
   createSMESHAction( SMESHOp::OpPopupExportUNV, "UNV" );
@@ -4401,6 +4527,7 @@ void SMESHGUI::initialize( CAM_Application* app )
       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
       basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 );
 
+  // Import menu
   //createMenu( SMESHOp::OpImportDAT, importId, -1 );
   createMenu( SMESHOp::OpImportUNV,  importId, -1 );
   createMenu( SMESHOp::OpImportMED,  importId, -1 );
@@ -4409,6 +4536,9 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( SMESHOp::OpImportCGNS, importId, -1 );
 #endif
   createMenu( SMESHOp::OpImportGMF,  importId, -1 );
+  createMenu( SMESHOp::OpImportMESHIO,  importId, -1 ); // formats supported by meshio lib
+
+  // Export menu
   createMenu( SMESHOp::OpExportDAT,  exportId, -1 );
   createMenu( SMESHOp::OpExportMED,  exportId, -1 );
   createMenu( SMESHOp::OpExportUNV,  exportId, -1 );
@@ -4417,6 +4547,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( SMESHOp::OpExportCGNS, exportId, -1 );
 #endif
   createMenu( SMESHOp::OpExportGMF,  exportId, -1 );
+  createMenu( SMESHOp::OpExportMESHIO,  exportId, -1 ); // formats supported by meshio lib
   createMenu( separator(), fileId, 10 );
 
   createMenu( SMESHOp::OpDelete, editId, -1 );
@@ -4838,6 +4969,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 #endif
   createPopupItem( SMESHOp::OpPopupExportGMF,  OB, mesh_group, only_one_non_empty, anId );
   createPopupItem( SMESHOp::OpPopupExportDAT,  OB, mesh_group, only_one_non_empty, anId );
+  createPopupItem( SMESHOp::OpExportMESHIO,    OB, mesh_group, only_one_non_empty, anId );
 
   anId = popupMgr()->insert( tr( "MEN_IMPORT" ), -1, -1 );        // IMPORT submenu
   createPopupItem( SMESHOp::OpPopupImportMED,  OB, smesh, "", anId );