Salome HOME
Copyright update 2020
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index 3146a923c7689a119960e1027790039593b4e25a..beb73a742bf21ec7a7b4e0378f233924c1ee4c78 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include "ModuleBase_OperationFeature.h"
 #include "ModuleBase_Tools.h"
 
-#include "ModelAPI_CompositeFeature.h"
-#include "ModelAPI_Session.h"
+#include <Config_Translator.h>
+
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Session.h>
 
 #include <XGUI_PropertyPanel.h>
 #include <QToolButton>
@@ -50,6 +52,7 @@
 #include <QMessageBox>
 #include <QApplication>
 #include <QKeyEvent>
+#include <QWindow>
 
 //#define DEBUG_CURRENT_FEATURE
 
@@ -76,25 +79,38 @@ public:
   virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
   {
     bool isAccepted = false;
+
     if (myIsActive) {
-      if (theEvent->type() == QEvent::KeyRelease) {
-        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-        if (aKeyEvent) {
-          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-          switch (aKeyEvent->key()) {
+      // 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;
+              break;
             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);
           }
         }
-      }
-      else if (theEvent->type() == QEvent::KeyPress) {
-        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-        myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-        isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
       }
     }
     if (!isAccepted)
@@ -336,7 +352,13 @@ bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
   if (isGrantedOperation(theOperation->id()))
     return true;
   if (theOperation && theOperation->isModified()) {
-    QString aTitle = theOperation->getDescription()->description();
+    ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    std::string aContext;
+    if (aOp)
+      aContext = aOp->feature()->getKind();
+    QString aTitle = Config_Translator::translate(aContext,
+      theOperation->getDescription()->description().toStdString()).c_str();
+
     if (theMessageKind == XGUI_AbortOperationMessage) {
       QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
       myActiveMessageBox = createMessageBox(aMessage);
@@ -438,7 +460,7 @@ void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool&
 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
 {
   ModuleBase_Operation* aCurrentOperation = currentOperation();
-  if (theOperation == aCurrentOperation)
+  if (theOperation && (theOperation == aCurrentOperation))
     theOperation->abort();
   else {
     // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
@@ -628,8 +650,8 @@ void XGUI_OperationMgr::onOperationStopped()
     }
   }
   if (aResultOp) {
-    bool isModified = aCurrentOperation->isModified();
-    aResultOp->setIsModified(aResultOp->isModified() || isModified);
+    //bool isModified = aCurrentOperation->isModified();
+    //aResultOp->setIsModified(aResultOp->isModified() || isModified);
     resumeOperation(aResultOp);
     onValidateOperation();
   }
@@ -678,7 +700,7 @@ bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
             aContext->HilightNextDetected(aView);
           else if ((theEvent->key() == Qt::Key_P))
             aContext->HilightPreviousDetected(aView);
-          //aViewer->updateHighlight();
+          aViewer->updateHighlight();
           isAccepted = true;
         }
       }
@@ -715,15 +737,17 @@ bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
       ModuleBase_Operation* aOperation = currentOperation();
       if (!isAccepted && aOperation) {
         ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-        ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
-        if (anActiveWgt)
-        {
-          isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
-          if (isAccepted) {
-            ModuleBase_OperationFeature* aFOperation =
-              dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
-            if (aFOperation)
-              aFOperation->setNeedToBeAborted(true);
+        if (aPanel) {
+          ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
+          if (anActiveWgt)
+          {
+            isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
+            if (isAccepted) {
+              ModuleBase_OperationFeature* aFOperation =
+                dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
+              if (aFOperation)
+                aFOperation->setNeedToBeAborted(true);
+            }
           }
         }
       }