-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 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
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "XGUI_OperationMgr.h"
+
+#include "XGUI_ActiveControlMgr.h"
+#include "XGUI_ActiveControlSelector.h"
+#include "XGUI_FacesPanelSelector.h"
#include "XGUI_ModuleConnector.h"
#include "XGUI_Workshop.h"
#include "XGUI_ErrorMgr.h"
+#include "XGUI_FacesPanel.h"
#include "XGUI_Tools.h"
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_ContextMenuMgr.h"
#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>
#include <QMessageBox>
#include <QApplication>
#include <QKeyEvent>
+#include <QWindow>
//#define DEBUG_CURRENT_FEATURE
/// 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);
}
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<QKeyEvent*>(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();
+ 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<QKeyEvent*>(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<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), mySHIFTPressed(false), myActiveMessageBox(0)
{
/// 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()
if (isGrantedOperation(theOperation->id()))
return true;
if (theOperation && theOperation->isModified()) {
+ 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(theOperation->id());
+ QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
myActiveMessageBox = createMessageBox(aMessage);
bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
myActiveMessageBox = 0;
return aResult;
}
else if (theMessageKind == XGUI_InformationMessage) {
- QString aMessage = tr("Please validate your %1 before saving.").arg(theOperation->id());
+ QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
myActiveMessageBox = createInformationBox(aMessage);
myActiveMessageBox->exec();
myActiveMessageBox = 0;
void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
{
- if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() && theOperation->isModified())
+ if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
+ theOperation->isModified()) {
isCommitted = theOperation->commit();
- else {
+ } else {
isCommitted = false;
abortOperation(theOperation);
}
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)
void XGUI_OperationMgr::onOperationAborted()
{
ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+ XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ aWorkshop->setStatusBarMessage("");
emit operationAborted(aSenderOperation);
}
}
}
if (aResultOp) {
- bool isModified = aCurrentOperation->isModified();
- aResultOp->setIsModified(aResultOp->isModified() || isModified);
+ //bool isModified = aCurrentOperation->isModified();
+ //aResultOp->setIsModified(aResultOp->isModified() || isModified);
resumeOperation(aResultOp);
onValidateOperation();
}
bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
{
+ bool isAccepted = false;
+
// 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_Tab:
case Qt::Key_Backtab:
aContext->HilightNextDetected(aView);
else if ((theEvent->key() == Qt::Key_P))
aContext->HilightPreviousDetected(aView);
+ aViewer->updateHighlight();
+ isAccepted = true;
}
}
- }
- break;
- break;
- default:
+ }
+ break;
+ case Qt::Key_H:
+ if ((theEvent->modifiers() == Qt::NoModifier))
+ myWorkshop->viewer()->hideSelectionHighlight();
+ break;
+ default:
isAccepted = false;
break;
}
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 (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);
+ }
+ }
+ }
+ }
+ if (!isAccepted)
+ {
+ XGUI_ActiveControlSelector* anActiveSelector =
+ XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
+ if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
+ isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
}
// default Escape button functionality
if (!isAccepted && aOperation) {
}
}
break;
+ case Qt::Key_H:
+ if ((theEvent->modifiers() == Qt::NoModifier))
+ myWorkshop->viewer()->showSelectionHighlight();
+ break;
}
return isAccepted;
}
if (!aOperation)
return isAccepted;
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ if (!aPanel)
+ return isAccepted;
// the next code is obsolete as we want to process Enter in property panel always
// only property panel enter is processed in order to do not process enter in application dialogs
//bool isPPChild = isChildObject(theObject, aPanel);
}
}
}
+ if (!isAccepted)
+ {
+ XGUI_ActiveControlSelector* anActiveSelector =
+ XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
+ if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
+ isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
+ }
if (!isAccepted) {
// after widget, object browser and viewer should process delete
/// other widgets such as line edit controls should not lead to
return aMessageBox;
}
+
+XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
+{
+ XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
+ return aConnector->workshop();
+}