X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_OperationMgr.cpp;h=09aa5b6cacd286ba5bcea7c5735cefdd4b557026;hb=c837befca5d8a28a000ac1b87345f038d87b727f;hp=e00490f8e16789f31d2ae213fe75a0857a207d2d;hpb=c4eab94a20a0d93100549a210582d46409fec1cc;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index e00490f8e..09aa5b6ca 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 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 @@ -40,8 +40,10 @@ #include "ModuleBase_OperationFeature.h" #include "ModuleBase_Tools.h" -#include "ModelAPI_CompositeFeature.h" -#include "ModelAPI_Session.h" +#include + +#include +#include #include #include @@ -50,6 +52,7 @@ #include #include #include +#include //#define DEBUG_CURRENT_FEATURE @@ -62,8 +65,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); } @@ -73,54 +76,69 @@ 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) { + 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(theEvent); if (aKeyEvent) { myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier); switch (aKeyEvent->key()) { - case Qt::Key_Delete: - isAccepted = myOperationMgr->onProcessDelete(theObject); + case Qt::Key_Delete: + isAccepted = myOperationMgr->onProcessDelete(theObject); + break; + case Qt::Key_F2: + myOperationMgr->xworkshop()->objectBrowser()->onEditItem(); + isAccepted = true; + break; + default: + isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent); break; - default: - isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent); - break; } } } else if (theEvent->type() == QEvent::KeyPress) { - QKeyEvent* aKeyEvent = dynamic_cast(theEvent); - myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier); - switch (aKeyEvent->key()) { - case Qt::Key_Escape: - isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent); - break; - default: - break; + if (myOperationMgr->hasOperation()) { + QKeyEvent* aKeyEvent = dynamic_cast(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) -: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0) + 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() @@ -342,7 +360,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(theOperation); + std::string aContext; + if (aOp && aOp->feature()) + 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); @@ -372,7 +396,6 @@ bool XGUI_OperationMgr::isGrantedOperation(const QString& theId) QListIterator anIt(myOperations); anIt.toBack(); - ModuleBase_Operation* aPreviousOperation = 0; while (anIt.hasPrevious() && !isGranted) { ModuleBase_Operation* anOp = anIt.previous(); if (anOp) @@ -444,16 +467,16 @@ 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) // all operation from the current to triggered should also be aborted // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort) while(hasOperation()) { - ModuleBase_Operation* aCurrentOperation = currentOperation(); - aCurrentOperation->abort(); - if(theOperation == aCurrentOperation) + ModuleBase_Operation* aCurOperation = currentOperation(); + aCurOperation->abort(); + if(theOperation == aCurOperation) break; } } @@ -634,8 +657,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(); } @@ -688,10 +711,13 @@ bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent) isAccepted = true; } } - } - break; - break; - default: + } + break; + case Qt::Key_H: + if ((theEvent->modifiers() == Qt::NoModifier)) + myWorkshop->viewer()->hideSelectionHighlight(); + break; + default: isAccepted = false; break; } @@ -704,7 +730,6 @@ bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent) bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent) { // Let the manager decide what to do with the given key combination. - ModuleBase_Operation* anOperation = currentOperation(); bool isAccepted = false; switch (theEvent->key()) { case Qt::Key_Escape: { @@ -718,15 +743,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(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(currentOperation()); + if (aFOperation) + aFOperation->setNeedToBeAborted(true); + } } } } @@ -744,6 +771,10 @@ bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent) } } break; + case Qt::Key_H: + if ((theEvent->modifiers() == Qt::NoModifier)) + myWorkshop->viewer()->showSelectionHighlight(); + break; } return isAccepted; } @@ -907,3 +938,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(); +}