Salome HOME
PAL18696 SMESH : version of MED export
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 6a6910a1ceb50f5ffb0a1155deda689142b714f2..1a952b542b07c3c3f3b815faedff409d65af4b0f 100644 (file)
@@ -35,6 +35,7 @@
 #include "SMESHGUI_RemoveElementsDlg.h"
 #include "SMESHGUI_MeshInfosDlg.h"
 #include "SMESHGUI_StandardMeshInfosDlg.h"
+#include "SMESHGUI_WhatIsDlg.h"
 #include "SMESHGUI_Preferences_ColorDlg.h"
 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
 #include "SMESHGUI_Preferences_SelectionDlg.h"
 #include "SALOMEDSClient_StudyBuilder.hxx"
 #include "SALOMEDSClient_SComponent.hxx"
 
+#include <Standard_ErrorHandler.hxx>
+
 using namespace std;
 
 //namespace{
@@ -275,9 +278,11 @@ using namespace std;
               if (aRet)
                 return;
             }
-
-            aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
-            aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
+            // PAL18696
+            QString v21( aMesh->GetVersionString( SMESH::MED_V2_1, 2));
+            QString v22( aMesh->GetVersionString( SMESH::MED_V2_2, 2));
+            aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
+            aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
           }
          break;
        case 124:
@@ -1260,7 +1265,18 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 214:                                    // UPDATE
     {
       if(checkLock(aStudy)) break;
-      SMESH::UpdateView();
+      try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+        OCC_CATCH_SIGNALS;
+#endif
+        SMESH::UpdateView();
+      }
+      catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
+      }
+      catch (...) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
+      }
 
       SALOME_ListIO l;
       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
@@ -1290,22 +1306,31 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
       extractContainers( sel_objects, to_process );
 
-      if (vtkwnd) {
-       SALOME_ListIteratorOfListIO It( to_process );
-       for (; It.More(); It.Next()) {
-         Handle(SALOME_InteractiveObject) IOS = It.Value();
-         if (IOS->hasEntry()) {
-            SMESH::UpdateView(anAction, IOS->getEntry());
-            if (anAction == SMESH::eDisplayOnly)
-              anAction = SMESH::eDisplay;
-         }
-       }
-      }
+      try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+        OCC_CATCH_SIGNALS;
+#endif
+        if (vtkwnd) {
+          SALOME_ListIteratorOfListIO It( to_process );
+          for (; It.More(); It.Next()) {
+            Handle(SALOME_InteractiveObject) IOS = It.Value();
+            if (IOS->hasEntry()) {
+              if (!SMESH::UpdateView(anAction, IOS->getEntry()))
+                break; // PAL16774 (Crash after display of many groups)
+              if (anAction == SMESH::eDisplayOnly)
+                anAction = SMESH::eDisplay;
+            }
+          }
+        }
 
-      // PAL13338 + PAL15161 -->
-      if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy) /*&& !automaticUpdate()*/ )
-       SMESH::UpdateView();
-      // PAL13338 + PAL15161 <--
+        // PAL13338 + PAL15161 -->
+        if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
+          SMESH::UpdateView();
+        // PAL13338 + PAL15161 <--
+      }
+      catch (...) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
+      }
 
       if (anAction == SMESH::eErase) {
        SALOME_ListIO l1;
@@ -1364,82 +1389,6 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if (checkLock(aStudy)) break;
 
       startOperation( 701 );
-//       LightApp_SelectionMgr *Sel = selectionMgr();
-//       SALOME_ListIO selected; Sel->selectedObjects( selected );
-
-//       int nbSel = selected.Extent();
-//       if (nbSel != 1) {
-//         SUIT_MessageBox::warn1(desktop(),
-//                                tr("SMESH_WRN_WARNING"),
-//                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
-//                                tr("SMESH_BUT_OK"));
-//         break;
-//       }
-
-//       SMESH::SMESH_Mesh_var aMesh;
-//       SMESH::SMESH_subMesh_var aSubMesh;
-//       Handle(SALOME_InteractiveObject) IObject = selected.First();
-//       if (IObject->hasEntry()) {
-//         _PTR(SObject) aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
-//         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
-//         if ( aShapeObject->_is_nil() ) {
-//           // imported mesh
-//           break;
-//         }
-//         if ( aMeshSObj ) {
-//           aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
-//           aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
-//           if ( !aSubMesh->_is_nil() )
-//             aMesh = aSubMesh->GetFather();
-
-//           if (!aMesh->_is_nil()) {
-//             SMESH::algo_error_array_var errors = GetSMESHGen()->GetAlgoState(aMesh,aShapeObject);
-//             if ( errors->length() > 0 ) {
-//               SUIT_MessageBox::warn1(desktop(),
-//                                      tr("SMESH_WRN_WARNING"),
-//                                      SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
-//                                      tr("SMESH_BUT_OK"));
-//               break;
-//             }
-
-//             try {
-//               if (GetSMESHGen()->Compute(aMesh, aShapeObject))
-//                 SMESH::ModifiedMesh(aMeshSObj, true);
-//               else
-//                 SUIT_MessageBox::warn1(desktop(),
-//                                        tr("SMESH_WRN_WARNING"),
-//                                        tr("SMESH_WRN_COMPUTE_FAILED"),
-//                                        tr("SMESH_BUT_OK"));
-//             }
-//             catch(const SALOME::SALOME_Exception & S_ex){
-//               SalomeApp_Tools::QtCatchCorbaException(S_ex);
-//             }
-
-//             updateObjBrowser();
-
-//             if (automaticUpdate()) {
-//               SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(this, /*create*/true);
-//               if (aVTKView) {
-//                 CORBA::Long anId = aStudy->StudyId();
-//                 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
-//                 if (aVisualObj) {
-//                   aVisualObj->Update();
-//                   SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
-//                   if (!anActor) {
-//                     anActor = SMESH::CreateActor(aStudy, IObject->getEntry());
-//                     if (anActor) {
-//                       SMESH::DisplayActor(aVTKView, anActor); //apo
-//                       SMESH::FitAll();
-//                     }
-//                   }
-//                   SMESH::RepaintCurrentView();
-//                   Sel->setSelectedObjects( selected );
-//                 }
-//               }
-//             }
-//           }
-//         }
-//       }
     }
     break;
 
@@ -1845,6 +1794,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+  case 903:                                    // WHAT IS
+    {
+      EmitSignalDeactivateDialog();
+      new SMESHGUI_WhatIsDlg( this, "", false);
+      break;
+    }
+
   case 1100:                                   // EDIT HYPOTHESIS
     {
       if(checkLock(aStudy)) break;
@@ -2410,7 +2366,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  125, "EXPORT_MED" );
   createSMESHAction(  126, "EXPORT_UNV" );
   createSMESHAction(  141, "EXPORT_STL" );
-  createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
+  createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
   createSMESHAction( 5105, "SEL_FILTER_LIB" );
   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
@@ -2428,6 +2384,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
+  createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
@@ -2484,7 +2441,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
   createSMESHAction(  220, "ALL" );
   createSMESHAction( 1100, "EDIT_HYPO" );
-  createSMESHAction( 1101, "RENAME" );
+  createSMESHAction( 1101, "RENAME", "", Key_F2 );
   createSMESHAction( 1102, "UNASSIGN" );
   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
@@ -2559,6 +2516,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( separator(), meshId, -1 );
   createMenu( 900, meshId, -1 );
   createMenu( 902, meshId, -1 );
+  createMenu( 903, meshId, -1 );
   createMenu( separator(), meshId, -1 );
 
   createMenu( 6003, ctrlId, -1 );
@@ -2645,6 +2603,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( separator(), meshTb );
   createTool( 900, meshTb );
   createTool( 902, meshTb );
+  createTool( 903, meshTb );
   createTool( separator(), meshTb );
 
   createTool( 6001, ctrlTb );
@@ -2742,6 +2701,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 214, OB, mesh_group );                  // UPDATE
   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
   createPopupItem( 902, OB, mesh );                        // STD_INFO
+  createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
   popupMgr()->insert( separator(), -1, 0 );
   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
@@ -2752,10 +2712,11 @@ void SMESHGUI::initialize( CAM_Application* app )
   popupMgr()->insert( separator(), -1, 0 );
 
   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
-  createPopupItem( 125, OB, mesh, only_one_non_empty );    // EXPORT_MED
-  createPopupItem( 126, OB, mesh, only_one_non_empty );    // EXPORT_UNV
-  createPopupItem( 141, OB, mesh, only_one_non_empty );    // EXPORT_STL
-  createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
+  createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
+  createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
+  createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
+  //createPopupItem(  33, OB, subMesh + " " + group );      // DELETE
+  createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
   popupMgr()->insert( separator(), -1, 0 );
 
   // popup for viewer
@@ -2766,6 +2727,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 214, View, mesh_group ); // UPDATE
   createPopupItem( 900, View, mesh_group ); // ADV_INFO
   createPopupItem( 902, View, mesh );       // STD_INFO
+  createPopupItem( 903, View, mesh_group ); // WHAT_IS
   popupMgr()->insert( separator(), -1, 0 );
 
   int anId;
@@ -3006,6 +2968,12 @@ bool SMESHGUI::deactivateModule( SUIT_Study* study )
   return SalomeApp_Module::deactivateModule( study );
 }
 
+void SMESHGUI::studyClosed( SUIT_Study* s )
+{
+  SMESH::RemoveVisuData( s->id() );
+  SalomeApp_Module::studyClosed( s );
+}
+
 void SMESHGUI::OnGUIEvent()
 {
   const QObject* obj = sender();
@@ -3148,6 +3116,7 @@ void SMESHGUI::createPreferences()
 
   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
+  addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
 
   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
@@ -3238,7 +3207,8 @@ void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
     if( name=="selection_object_color" || name=="selection_element_color" ||
         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
-        name=="selection_precision_node" || name=="selection_precision_element" )
+        name=="selection_precision_node" || name=="selection_precision_element" ||
+       name=="selection_precision_object")
       SMESH::UpdateSelectionProp( this );
     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);