Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index 3bca93a90f19e6fc9bd569c22014a91fecc42054..5db1d07a7f8f405993ff2c7fca3df30d2eea37fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,8 @@
 #include "XGUI_Tools.h"
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_ContextMenuMgr.h"
+#include "XGUI_Selection.h"
+#include "XGUI_SelectionMgr.h"
 
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_ModelWidget.h>
@@ -65,8 +67,8 @@ public:
   /// Constructor
   /// \param theParent the parent to be deleted when the parent is deleted
   /// \param theOperationMgr the class to perform deletion
-  XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
-    : QObject(theParent), myOperationMgr(theOperationMgr), myIsActive(false)
+  XGUI_ShortCutListener(XGUI_OperationMgr* theOperationMgr)
+    : QObject(theOperationMgr), myOperationMgr(theOperationMgr), myIsActive(false)
   {
     qApp->installEventFilter(this);
   }
@@ -76,61 +78,76 @@ public:
   void setActive(const bool theIsActive) { myIsActive = theIsActive; }
 
   /// Redefinition of virtual function to process Delete key release
-  virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
-  {
-    bool isAccepted = false;
-
-    if (myIsActive) {
-      // Do not process keys for modal dialogues: all keys has to be processed within the dialog
-      // There is only one exception: ModuleBase_EditorDialog
-      QWindow* aWnd = qApp->modalWindow();
-      QString aName = "NoModal";
-      if (aWnd) {
-        if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
-          aName = aWnd->objectName();
-      }
-      if (aName == "NoModal") {
-        if (theEvent->type() == QEvent::KeyRelease) {
-          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-          if (aKeyEvent) {
-            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-            switch (aKeyEvent->key()) {
-            case Qt::Key_Delete:
-              isAccepted = myOperationMgr->onProcessDelete(theObject);
-              break;
-            default:
-              isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
-              break;
+  virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+
+private:
+  XGUI_OperationMgr* myOperationMgr; /// processor for key event
+  bool myIsActive; /// boolean state whether the event filter perform own signal processing
+};
+
+bool XGUI_ShortCutListener::eventFilter(QObject *theObject, QEvent *theEvent)
+{
+  bool isAccepted = false;
+
+  if (myIsActive) {
+    // Do not process keys for modal dialogues: all keys has to be processed within the dialog
+    // There is only one exception: ModuleBase_EditorDialog
+    QWindow* aWnd = qApp->modalWindow();
+    QString aName = "NoModal";
+    if (aWnd) {
+      if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
+        aName = aWnd->objectName();
+    }
+    if (aName == "NoModal") {
+      if (theEvent->type() == QEvent::KeyRelease) {
+        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+        if (aKeyEvent) {
+          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+          switch (aKeyEvent->key()) {
+          case Qt::Key_Delete:
+            isAccepted = myOperationMgr->onProcessDelete(theObject);
+            break;
+          case Qt::Key_F2:
+          {
+            QObjectPtrList anObjects = myOperationMgr->xworkshop()->selector()->selection()->selectedObjects();
+            if (myOperationMgr->xworkshop()->abortAllOperations())
+            {
+              myOperationMgr->xworkshop()->objectBrowser()->setObjectsSelected(anObjects);
+              myOperationMgr->xworkshop()->objectBrowser()->onEditItem();
             }
+            isAccepted = true;
+            break;
           }
-        }
-        else if (theEvent->type() == QEvent::KeyPress) {
-          if (myOperationMgr->hasOperation()) {
-            QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-            isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+          default:
+            isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
+            break;
           }
         }
       }
+      else if (theEvent->type() == QEvent::KeyPress) {
+        if (myOperationMgr->hasOperation()) {
+          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+          isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+        }
+      }
     }
-    if (!isAccepted)
-      isAccepted = QObject::eventFilter(theObject, theEvent);
-    return isAccepted;
   }
+  if (!isAccepted)
+    isAccepted = QObject::eventFilter(theObject, theEvent);
+  return isAccepted;
+}
+
 
-private:
-  XGUI_OperationMgr* myOperationMgr; /// processor for key event
-  bool myIsActive; /// boolean state whether the event filter perform own signal processing
-};
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
-                                     ModuleBase_IWorkshop* theWorkshop)
+  ModuleBase_IWorkshop* theWorkshop)
 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
 {
   /// we need to install filter to the application in order to react to 'Delete' key button
   /// this key can not be a short cut for a corresponded action because we need to set
   /// the actions priority
-  myShortCutListener = new XGUI_ShortCutListener(theParent, this);
+  myShortCutListener = new XGUI_ShortCutListener(this);
 }
 
 XGUI_OperationMgr::~XGUI_OperationMgr()
@@ -354,7 +371,7 @@ bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
   if (theOperation && theOperation->isModified()) {
     ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
     std::string aContext;
-    if (aOp)
+    if (aOp && aOp->feature())
       aContext = aOp->feature()->getKind();
     QString aTitle = Config_Translator::translate(aContext,
       theOperation->getDescription()->description().toStdString()).c_str();
@@ -930,3 +947,9 @@ QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
 
   return aMessageBox;
 }
+
+XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
+{
+  XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
+  return aConnector->workshop();
+}