1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XGUI_OperationMgr.h"
22 #include "XGUI_ActiveControlMgr.h"
23 #include "XGUI_ActiveControlSelector.h"
24 #include "XGUI_FacesPanelSelector.h"
25 #include "XGUI_ModuleConnector.h"
26 #include "XGUI_Workshop.h"
27 #include "XGUI_ErrorMgr.h"
28 #include "XGUI_FacesPanel.h"
29 #include "XGUI_Tools.h"
30 #include "XGUI_ObjectsBrowser.h"
31 #include "XGUI_ContextMenuMgr.h"
33 #include <ModuleBase_IPropertyPanel.h>
34 #include <ModuleBase_ModelWidget.h>
35 #include "ModuleBase_Operation.h"
36 #include "ModuleBase_IWorkshop.h"
37 #include "ModuleBase_IModule.h"
38 #include <ModuleBase_IViewer.h>
39 #include "ModuleBase_OperationDescription.h"
40 #include "ModuleBase_OperationFeature.h"
41 #include "ModuleBase_Tools.h"
43 #include <Config_Translator.h>
45 #include <ModelAPI_CompositeFeature.h>
46 #include <ModelAPI_Session.h>
48 #include <XGUI_PropertyPanel.h>
49 #include <QToolButton>
52 #include <QMessageBox>
53 #include <QApplication>
57 //#define DEBUG_CURRENT_FEATURE
59 /// Processes "Delete" key event of application. This key is used by several application actions.
60 /// There is a logical order of the actions processing. So the key can not be set for actions
61 /// as a shortcut. The class listens the key event and call operation manager processor.
62 class XGUI_ShortCutListener : public QObject
66 /// \param theParent the parent to be deleted when the parent is deleted
67 /// \param theOperationMgr the class to perform deletion
68 XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
69 : QObject(theParent), myOperationMgr(theOperationMgr), myIsActive(false)
71 qApp->installEventFilter(this);
73 ~XGUI_ShortCutListener() {}
75 /// Switch on short cut listener
76 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
78 /// Redefinition of virtual function to process Delete key release
79 virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
81 bool isAccepted = false;
84 // Do not process keys for modal dialogues: all keys has to be processed within the dialog
85 // There is only one exception: ModuleBase_EditorDialog
86 QWindow* aWnd = qApp->modalWindow();
87 QString aName = "NoModal";
89 if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
90 aName = aWnd->objectName();
92 if (aName == "NoModal") {
93 if (theEvent->type() == QEvent::KeyRelease) {
94 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
96 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
97 switch (aKeyEvent->key()) {
99 isAccepted = myOperationMgr->onProcessDelete(theObject);
102 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
107 else if (theEvent->type() == QEvent::KeyPress) {
108 if (myOperationMgr->hasOperation()) {
109 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
110 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
111 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
117 isAccepted = QObject::eventFilter(theObject, theEvent);
122 XGUI_OperationMgr* myOperationMgr; /// processor for key event
123 bool myIsActive; /// boolean state whether the event filter perform own signal processing
126 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
127 ModuleBase_IWorkshop* theWorkshop)
128 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
130 /// we need to install filter to the application in order to react to 'Delete' key button
131 /// this key can not be a short cut for a corresponded action because we need to set
132 /// the actions priority
133 myShortCutListener = new XGUI_ShortCutListener(theParent, this);
136 XGUI_OperationMgr::~XGUI_OperationMgr()
140 void XGUI_OperationMgr::activate()
142 myShortCutListener->setActive(true);
145 void XGUI_OperationMgr::deactivate()
147 myShortCutListener->setActive(false);
150 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
152 return myOperations.count() > 0 ? myOperations.last() : 0;
155 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
159 return currentOperation() == theOperation;
162 bool XGUI_OperationMgr::hasOperation() const
164 return !myOperations.isEmpty() && (myOperations.last() != NULL);
167 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
169 foreach(ModuleBase_Operation* aOp, myOperations) {
170 if (aOp->id() == theId)
176 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
178 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
179 while (anIt != myOperations.begin()) {
181 ModuleBase_Operation* anOperation = *anIt;
182 if (anOperation->id() == theId)
189 int XGUI_OperationMgr::operationsCount() const
191 return myOperations.count();
194 QStringList XGUI_OperationMgr::operationList() const
197 foreach(ModuleBase_Operation* eachOperation, myOperations) {
198 ModuleBase_OperationFeature* aFOperation =
199 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
201 FeaturePtr aFeature = aFOperation->feature();
203 result << QString::fromStdString(aFeature->getKind());
210 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
212 int idx = myOperations.lastIndexOf(theOperation);
213 if(idx == -1 || idx == 0) {
216 return myOperations.at(idx - 1);
219 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
221 ModuleBase_ModelWidget* anActiveWidget = 0;
222 ModuleBase_Operation* anOperation = currentOperation();
224 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
226 anActiveWidget = aPanel->activeWidget();
228 return anActiveWidget;
231 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
234 currentOperation()->postpone();
235 myOperations.append(theOperation);
237 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
238 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
239 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
241 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
242 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
243 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
245 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
246 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
248 bool isStarted = theOperation->start();
250 onValidateOperation();
254 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
260 if (operationsCount() == 1) {
261 ModuleBase_Operation* aCurrentOperation = currentOperation();
262 if (canStopOperation(aCurrentOperation, theMessageKind)) {
263 abortOperation(aCurrentOperation);
269 if (theMessageKind == XGUI_AbortOperationMessage) {
270 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
271 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
272 myActiveMessageBox = 0;
274 else if (theMessageKind == XGUI_InformationMessage) {
275 QString aMessage = tr("Please validate all your active operations before saving.");
276 myActiveMessageBox = createInformationBox(aMessage);
277 myActiveMessageBox->exec();
278 myActiveMessageBox = 0;
279 aResult = false; // do not perform abort
281 while(aResult && hasOperation()) {
282 abortOperation(currentOperation());
288 bool XGUI_OperationMgr::commitAllOperations()
290 bool isCompositeCommitted = false, anOperationProcessed = false;
291 while (hasOperation()) {
292 ModuleBase_Operation* anOperation = currentOperation();
293 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
294 anOperationProcessed = commitOperation();
296 abortOperation(anOperation);
297 anOperationProcessed = true;
299 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
302 FeaturePtr aFeature = aFOperation->feature();
303 CompositeFeaturePtr aComposite =
304 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
305 isCompositeCommitted = aComposite.get();
306 if (isCompositeCommitted)
309 // not processed[committed] operation might be used in composite feature,
310 // so the while will be stopped by the previous check.
311 // this code is not necessary, but logically should be done when the processing will not
312 // be done for not composite feature by some reasons
313 if (!anOperationProcessed)
319 void XGUI_OperationMgr::onValidateOperation()
323 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
324 (currentOperation());
325 if(aFOperation && aFOperation->feature().get())
326 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
329 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
331 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
333 ModuleBase_OperationFeature* aFOperation =
334 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
336 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
339 foreach(ModuleBase_Operation* anOperation, myOperations) {
341 updateApplyOfOperations(anOperation);
344 // Apply button of the current operation should also be updated
345 onValidateOperation();
348 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
349 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
351 //in case of nested (sketch) operation no confirmation needed
352 if (isGrantedOperation(theOperation->id()))
354 if (theOperation && theOperation->isModified()) {
355 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
356 std::string aContext;
358 aContext = aOp->feature()->getKind();
359 QString aTitle = Config_Translator::translate(aContext,
360 theOperation->getDescription()->description().toStdString()).c_str();
362 if (theMessageKind == XGUI_AbortOperationMessage) {
363 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
364 myActiveMessageBox = createMessageBox(aMessage);
365 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
366 myActiveMessageBox = 0;
369 else if (theMessageKind == XGUI_InformationMessage) {
370 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
371 myActiveMessageBox = createInformationBox(aMessage);
372 myActiveMessageBox->exec();
373 myActiveMessageBox = 0;
380 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
382 theOperation->resume();
385 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
387 bool isGranted = false;
389 QListIterator<ModuleBase_Operation*> anIt(myOperations);
391 while (anIt.hasPrevious() && !isGranted) {
392 ModuleBase_Operation* anOp = anIt.previous();
394 isGranted = anOp->isGranted(theId);
399 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
401 SessionPtr aMgr = ModelAPI_Session::get();
402 DocumentPtr aDoc = aMgr->activeDocument();
403 bool aIsOp = aMgr->isOperation();
405 aMgr->startOperation(QString("Set current feature: %1")
406 .arg(theFeature->getKind().c_str()).toStdString());
407 aDoc->setCurrentFeature(theFeature, false);
408 #ifdef DEBUG_CURRENT_FEATURE
409 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
410 ModuleBase_Tools::objectName(
411 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
415 aMgr->finishOperation();
418 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
420 bool aCanStart = true;
422 ModuleBase_Operation* aCurrentOp = currentOperation();
424 bool aGranted = aCurrentOp->isGranted(theId);
425 // the started operation is granted for the current one,
426 // e.g. current - Sketch, started - Line
431 if (!isGrantedOperation(theId)) {
432 // the operation is not granted in the current list of operations
433 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
434 aCanStart = abortAllOperations();
436 else if (canStopOperation(aCurrentOp)) {
437 // the started operation is granted in the parrent operation,
438 // e.g. current - Line in Sketch, started Circle
439 stopOperation(aCurrentOp, isCommitted);
448 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
450 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
451 theOperation->isModified()) {
452 isCommitted = theOperation->commit();
455 abortOperation(theOperation);
459 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
461 ModuleBase_Operation* aCurrentOperation = currentOperation();
462 if (theOperation && (theOperation == aCurrentOperation))
463 theOperation->abort();
465 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
466 // all operation from the current to triggered should also be aborted
467 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
468 while(hasOperation()) {
469 ModuleBase_Operation* aCurOperation = currentOperation();
470 aCurOperation->abort();
471 if(theOperation == aCurOperation)
477 bool XGUI_OperationMgr::commitOperation()
479 bool isCommitted = false;
480 ModuleBase_Operation* anOperation = currentOperation();
481 if (anOperation && myWorkshop->module()->canCommitOperation())
482 isCommitted = anOperation->commit();
486 void XGUI_OperationMgr::onAbortOperation()
488 ModuleBase_Operation* aCurrentOperation = currentOperation();
489 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
490 abortOperation(aCurrentOperation);
494 void XGUI_OperationMgr::onAbortAllOperation()
496 abortAllOperations();
499 void XGUI_OperationMgr::onBeforeOperationStarted()
501 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
502 if (!aCurrentOperation)
505 /// Set current feature and remeber old current feature
506 ModuleBase_OperationFeature* aFOperation =
507 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
509 SessionPtr aMgr = ModelAPI_Session::get();
510 DocumentPtr aDoc = aMgr->activeDocument();
511 // the parameter of current feature should be false, we should use all feature, not only
512 // visible in order to correctly save the previous feature of the nested operation, where the
513 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
514 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
515 // When sketch entity operation started, the sketch should be cashed here as the current.
516 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
517 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
518 // As a result the sketch disappears from the viewer.
519 // However after commit it is displayed back.
520 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
522 #ifdef DEBUG_CURRENT_FEATURE
523 FeaturePtr aFeature = aFOperation->feature();
524 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
526 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
527 .arg(aFOperation->isEditOperation())
528 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
529 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
530 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
533 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
534 // in create operation, the current feature is changed by addFeature()
535 aDoc->setCurrentFeature(aFOperation->feature(), false);
536 #ifdef DEBUG_CURRENT_FEATURE
537 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
538 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
540 // this is the only place where flushes must be called after setCurrentFeature for the
541 // current moment: after this the opertion is not finished, so, the ObjectBrowser
542 // state may be corrupted (issue #1457)
543 static Events_Loop* aLoop = Events_Loop::loop();
544 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
545 aLoop->flush(aCreateEvent);
546 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
547 aLoop->flush(aDeleteEvent);
552 void XGUI_OperationMgr::onOperationStarted()
554 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
555 updateApplyOfOperations(aSenderOperation);
556 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
557 aWorkshop->operationStarted(aSenderOperation);
560 void XGUI_OperationMgr::onBeforeOperationAborted()
562 onBeforeOperationCommitted();
565 void XGUI_OperationMgr::onOperationAborted()
567 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
568 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
569 aWorkshop->setStatusBarMessage("");
570 emit operationAborted(aSenderOperation);
573 void XGUI_OperationMgr::onBeforeOperationCommitted()
575 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
576 if (!aCurrentOperation)
579 /// Restore the previous current feature
580 ModuleBase_OperationFeature* aFOperation =
581 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
583 #ifdef DEBUG_CURRENT_FEATURE
584 QString aKind = aFOperation->feature()->getKind().c_str();
585 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
586 .arg(aFOperation->isEditOperation())
587 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
588 qDebug(QString(" document->currentFeature(false) = %1").arg(
589 ModuleBase_Tools::objectName(
590 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
591 .toStdString().c_str());
594 if (aFOperation->isEditOperation()) {
595 /// Restore the previous current feature
596 setCurrentFeature(aFOperation->previousCurrentFeature());
598 else { // create operation
599 // the Top created feature should stays the current. In nested operations,
600 // like Line in the Sketch or
601 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
602 // It is performed here
603 // in order to perform it in the current transaction without opening a new one.
604 if (myOperations.front() != aFOperation)
605 setCurrentFeature(aFOperation->previousCurrentFeature());
607 ModuleBase_IModule* aModule = myWorkshop->module();
609 aModule->beforeOperationStopped(aFOperation);
613 void XGUI_OperationMgr::onOperationCommitted()
615 // apply state for all features from the stack of operations should be updated
616 updateApplyOfOperations();
618 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
619 emit operationCommitted(aSenderOperation);
622 void XGUI_OperationMgr::onOperationResumed()
624 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
625 emit operationResumed(aSenderOperation);
628 void XGUI_OperationMgr::onOperationStopped()
630 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
631 ModuleBase_Operation* aCurrentOperation = currentOperation();
632 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
635 myOperations.removeAll(aCurrentOperation);
636 aCurrentOperation->deleteLater();
638 emit operationStopped(aCurrentOperation);
640 // get last operation which can be resumed
641 ModuleBase_Operation* aResultOp = 0;
642 QListIterator<ModuleBase_Operation*> anIt(myOperations);
644 while (anIt.hasPrevious()) {
645 ModuleBase_Operation* anOp = anIt.previous();
652 //bool isModified = aCurrentOperation->isModified();
653 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
654 resumeOperation(aResultOp);
655 onValidateOperation();
659 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
661 bool isAccepted = false;
663 // Let the manager decide what to do with the given key combination.
664 ModuleBase_Operation* anOperation = currentOperation();
665 switch (theEvent->key()) {
667 case Qt::Key_Backtab:
669 ModuleBase_Operation* aOperation = currentOperation();
671 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
673 QWidget* aFocusedWidget = qApp->focusWidget();
674 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
675 if (!isPPChildObject) {
676 // check for case when the operation is started but property panel is not filled
677 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
678 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
686 case Qt::Key_Enter: {
687 isAccepted = onProcessEnter(theObject);
692 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
694 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
695 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
696 if (!aContext.IsNull()) {
697 Handle(V3d_View) aView = aViewer->activeView();
698 if ((theEvent->key() == Qt::Key_N))
699 aContext->HilightNextDetected(aView);
700 else if ((theEvent->key() == Qt::Key_P))
701 aContext->HilightPreviousDetected(aView);
702 aViewer->updateHighlight();
709 if ((theEvent->modifiers() == Qt::NoModifier))
710 myWorkshop->viewer()->hideSelectionHighlight();
717 // anOperation->keyReleased(theEvent->key());
722 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
724 // Let the manager decide what to do with the given key combination.
725 bool isAccepted = false;
726 switch (theEvent->key()) {
727 case Qt::Key_Escape: {
728 // processing in message box
729 if (myActiveMessageBox)
731 myActiveMessageBox->reject();
734 // processing in the active widget
735 ModuleBase_Operation* aOperation = currentOperation();
736 if (!isAccepted && aOperation) {
737 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
739 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
742 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
744 ModuleBase_OperationFeature* aFOperation =
745 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
747 aFOperation->setNeedToBeAborted(true);
754 XGUI_ActiveControlSelector* anActiveSelector =
755 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
756 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
757 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
759 // default Escape button functionality
760 if (!isAccepted && aOperation) {
767 if ((theEvent->modifiers() == Qt::NoModifier))
768 myWorkshop->viewer()->showSelectionHighlight();
774 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
776 bool isAccepted = false;
777 ModuleBase_Operation* aOperation = currentOperation();
778 // to avoid enter processing when operation has not been started yet
781 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
784 // the next code is obsolete as we want to process Enter in property panel always
785 // only property panel enter is processed in order to do not process enter in application dialogs
786 //bool isPPChild = isChildObject(theObject, aPanel);
788 // return isAccepted;
790 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
791 bool isAborted = false;
793 QWidget* aFocusWidget = aPanel->focusWidget();
794 QToolButton* aCancelBtn =
795 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
796 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
797 abortOperation(aOperation);
803 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
806 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
808 /// functionality is similar to Apply click
809 ModuleBase_OperationFeature* aFOperation =
810 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
812 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
813 // key released is emitted to apply the current value to the model
814 // if it was modified in PP
815 emit keyEnterReleased();
827 bool editorControl(QObject* theObject)
829 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
833 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
835 bool isAccepted = false;
836 ModuleBase_Operation* aOperation = currentOperation();
837 ModuleBase_ModelWidget* anActiveWgt = 0;
838 // firstly the widget should process Delete action
839 ModuleBase_IPropertyPanel* aPanel;
840 bool isPPChildObject = false;
842 aPanel = aOperation->propertyPanel();
844 isPPChildObject = isChildObject(theObject, aPanel);
845 // process delete in active widget only if delete sender is child of property panel
846 // it is necessary for the case when OB is shown, user perform selection and click Delete
847 if (isPPChildObject) {
848 anActiveWgt = aPanel->activeWidget();
850 isAccepted = anActiveWgt->processAction(ActionDelete);
857 XGUI_ActiveControlSelector* anActiveSelector =
858 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
859 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
860 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
863 // after widget, object browser and viewer should process delete
864 /// other widgets such as line edit controls should not lead to
865 /// processing delete by workshop
866 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
867 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
868 bool isToDeleteObject = false;
869 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
870 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
871 if (theObject == aBrowser->treeView()) {
872 aContextMenuMgr->updateObjectBrowserMenu();
873 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
875 else if (isChildObject(theObject, aViewPort)) {
876 aContextMenuMgr->updateViewerMenu();
877 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
879 else if (isPPChildObject) {
880 // property panel child object is processed to process delete performed on Apply button of PP
881 isToDeleteObject = true;
883 else if (editorControl(theObject)) {
884 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
888 if (isToDeleteObject) {
889 aWorkshop->deleteObjects();
897 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
899 bool isPPChild = false;
900 if (theParent && theObject) {
901 QObject* aParent = (QObject*)theObject;
903 isPPChild = aParent == theParent;
906 aParent = aParent->parent();
912 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
914 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
915 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
916 qApp->activeWindow());
917 aMessageBox->setDefaultButton(QMessageBox::Cancel);
918 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
923 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
925 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
926 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
927 qApp->activeWindow());
928 aMessageBox->setDefaultButton(QMessageBox::Ok);
929 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key