Salome HOME
[bos #40644][CEA](2024-T1) Feature search.
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
index a7046eaca0523675b8d361f7ca4c88e0f9d4c681..a8300ea62c7789956cb0aa22830b6fc367cd68bf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -30,6 +30,7 @@
   // E.A. : some same symbols : acosh, asinh, ...
   #include <Standard_math.hxx>
   #ifndef DISABLE_PYCONSOLE
+    #include <Python.h>
     #include <pymath.h>
   #endif
 #endif
@@ -71,6 +72,7 @@
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
 #include <SUIT_OverrideCursor.h>
+#include <SUIT_FindActionDialog.h>
 
 #include <QtxTreeView.h>
 
 #include <ToolsGUI_RegWidget.h>
 
 #include <vector>
+#include <iostream>
 
 #include <SALOMEDS_Tool.hxx>
 
@@ -341,12 +344,12 @@ void SalomeApp_Application::createActions()
   //! Dump study
   createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIcon(),
                 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
-                Qt::CTRL+Qt::Key_D, desk, false, this, SLOT( onDumpStudy() ) );
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onDumpStudy() ), "/PRP_DESK_FILE_DUMP_STUDY" );
 
   //! Load script
   createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIcon(),
                 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
-                Qt::CTRL+Qt::Key_T, desk, false, this, SLOT( onLoadScript() ) );
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onLoadScript() ), "/PRP_DESK_FILE_LOAD_SCRIPT" );
 
   //! Properties
   createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIcon(),
@@ -356,22 +359,27 @@ void SalomeApp_Application::createActions()
   //! Catalog Generator
   createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ),  QIcon(),
                 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
-                Qt::ALT+Qt::SHIFT+Qt::Key_G, desk, false, this, SLOT( onCatalogGen() ) );
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onCatalogGen() ), "/PRP_DESK_CATALOG_GENERATOR" );
 
   //! Registry Display
   createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ),  QIcon(),
                 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
                 /*Qt::SHIFT+Qt::Key_D*/0, desk, false, this, SLOT( onRegDisplay() ) );
 
+  //! Find action dialog
+  createAction( FindActionId, tr( "TOT_DESK_FIND_ACTION" ),  QIcon(),
+                tr( "MEN_DESK_FIND_ACTION" ), tr( "PRP_DESK_FIND_ACTION" ),
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onFindAction() ), "/PRP_DESK_FIND_ACTION" );
+
   createAction( ConnectId, tr( "TOT_DESK_CONNECT_STUDY" ), QIcon(),
                 tr( "MEN_DESK_CONNECT" ), tr( "PRP_DESK_CONNECT" ),
-                Qt::CTRL+Qt::Key_L, desk, false, this, SLOT( onLoadDoc() ) );
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onLoadDoc() ), "/PRP_DESK_CONNECT" );
   //no need at this action for mono-study application because study is always exists
   action( ConnectId )->setVisible( false );
 
   createAction( DisconnectId, tr( "TOT_DESK_DISCONNECT_STUDY" ), QIcon(),
                 tr( "MEN_DESK_DISCONNECT" ), tr( "PRP_DESK_DISCONNECT" ),
-                Qt::CTRL+Qt::Key_U, desk, false, this, SLOT( onUnloadDoc() ) );
+                QKeySequence::UnknownKey, desk, false, this, SLOT( onUnloadDoc() ), "/PRP_DESK_DISCONNECT" );
   //no need at this action for mono-study application because study is always exists
   action( DisconnectId )->setVisible( false );
 
@@ -395,6 +403,7 @@ void SalomeApp_Application::createActions()
   int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, MenuToolsId, 50 );
   createMenu( CatalogGenId, toolsMenu, 10, -1 );
   createMenu( RegDisplayId, toolsMenu, 10, -1 );
+  createMenu( FindActionId, toolsMenu, 10, -1 );
   createMenu( separator(), toolsMenu, -1, 15, -1 );
 
   createExtraActions();
@@ -534,7 +543,28 @@ void SalomeApp_Application::onUnloadDoc( bool ask )
 /*!SLOT. Create new study and load script*/
 void SalomeApp_Application::onNewWithScript()
 {
-  execScript(true);
+  QStringList filtersList;
+  filtersList.append(tr("PYTHON_FILES_FILTER"));
+  filtersList.append(tr("ALL_FILES_FILTER"));
+
+  QString anInitialPath = "";
+  if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+    anInitialPath = QDir::currentPath();
+
+  QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+  if ( !aFile.isEmpty() )
+  {
+    onNewDoc();
+
+#ifndef DISABLE_PYCONSOLE
+    QString command = QString("exec(open(\"%1\", \"rb\").read())").arg(aFile);
+    PyConsole_Console* pyConsole = pythonConsole();
+    PropertyMgr propm( this, "IsLoadedScript", true );
+    if ( pyConsole )
+      pyConsole->exec( command );
+#endif
+  }
 }
 
 
@@ -989,7 +1019,26 @@ void SalomeApp_Application::onLoadScript( )
     return;
   }
 
-  execScript(false);
+  QStringList filtersList;
+  filtersList.append(tr("PYTHON_FILES_FILTER"));
+  filtersList.append(tr("ALL_FILES_FILTER"));
+
+  QString anInitialPath = "";
+  if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+    anInitialPath = QDir::currentPath();
+
+  QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+  if ( !aFile.isEmpty() )
+  {
+#ifndef DISABLE_PYCONSOLE
+    QString command = QString("exec(compile(open('%1', 'rb').read(), '%1', 'exec'))").arg(aFile);
+    PyConsole_Console* pyConsole = pythonConsole();
+    PropertyMgr propm( this, "IsLoadedScript", true );
+    if ( pyConsole )
+      pyConsole->exec(command);
+#endif
+  }
 }
 
 /*!Private SLOT. On save GUI state.*/
@@ -1534,6 +1583,25 @@ void SalomeApp_Application::onRegDisplay()
   regWnd->activateWindow();
 }
 
+/*!Display Action Search dialog */
+void SalomeApp_Application::onFindAction()
+{
+  const auto pActiveModule = activeModule();
+  if (pActiveModule && pActiveModule->name() == "PARAVIS") {
+    return;
+    // ParaViS module has its own action search dialog (Quick Launch dialog).
+    // Keep this conditional block until ParaViS's actions are not added to ShortcutMgr resource and asset files.
+  }
+
+  SUIT_FindActionDialog aDlg( desktop() );
+  if (pActiveModule)
+    aDlg.setActiveModuleID(pActiveModule->name());
+  else
+    aDlg.setActiveModuleID();
+
+  aDlg.exec();
+}
+
 /*!find original object by double click on item */
 void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj )
 {
@@ -2102,50 +2170,6 @@ PyConsole_Interp* SalomeApp_Application::createPyInterp()
 
 #endif // DISABLE_PYCONSOLE
 
-/*
-  Opens a file dialog to choose a python script.
-*/
-QString SalomeApp_Application::getScriptFileName()
-{
-  QStringList filtersList;
-  filtersList.append(tr("PYTHON_FILES_FILTER"));
-  filtersList.append(tr("ALL_FILES_FILTER"));
-
-  const QString anInitialPath =
-    SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : "";
-    
-  return SUIT_FileDlg::getFileName(desktop(), anInitialPath, filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, true);
-}
-
-/*
-  Execute script in python console.
-*/
-void SalomeApp_Application::execScript(bool isNewDoc)
-{
-  const QString aFile = getScriptFileName();
-  if (aFile.isEmpty())
-  {
-    return;
-  }
-
-  if (isNewDoc)
-  {
-    onNewDoc();
-  }
-
-#ifndef DISABLE_PYCONSOLE
-  PyConsole_Console* pyConsole = pythonConsole();
-  PropertyMgr propm(this, "IsLoadedScript", true);
-  if (pyConsole)
-  {
-    QString command = QString("exec(compile(open('%1', 'rb').read(), '%1', 'exec'))").arg(aFile);
-    SUIT_Tools::addTraceToPythonCommand(aFile, command);
-
-    pyConsole->exec(command);
-  }
-#endif
-}
-
 void SalomeApp_Application::ensureShaperIsActivated()
 {
   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
@@ -2158,7 +2182,7 @@ void SalomeApp_Application::ensureShaperIsActivated()
     study->dataModels( models );
     for( int i = 0; i < models.count() && !shaperIsActive; i++ )
       shaperIsActive = models[i]->module()->moduleName() == "Shaper";
-       
+
     if (shaper && !shaperIsActive)
       onDesktopMessage("register_module_in_study/Shaper");
   }