1 // Copyright (C) 2014-2019 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>
56 //#define DEBUG_CURRENT_FEATURE
58 /// Processes "Delete" key event of application. This key is used by several application actions.
59 /// There is a logical order of the actions processing. So the key can not be set for actions
60 /// as a shortcut. The class listens the key event and call operation manager processor.
61 class XGUI_ShortCutListener : public QObject
65 /// \param theParent the parent to be deleted when the parent is deleted
66 /// \param theOperationMgr the class to perform deletion
67 XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
68 : QObject(theParent), myOperationMgr(theOperationMgr), myIsActive(false)
70 qApp->installEventFilter(this);
72 ~XGUI_ShortCutListener() {}
74 /// Switch on short cut listener
75 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
77 /// Redefinition of virtual function to process Delete key release
78 virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
80 bool isAccepted = false;
82 if (theEvent->type() == QEvent::KeyRelease) {
83 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
85 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
86 switch (aKeyEvent->key()) {
88 isAccepted = myOperationMgr->onProcessDelete(theObject);
91 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
96 else if (theEvent->type() == QEvent::KeyPress) {
97 if (!qApp->modalWindow()) {
98 if (myOperationMgr->hasOperation()) {
99 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
100 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
101 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
107 isAccepted = QObject::eventFilter(theObject, theEvent);
112 XGUI_OperationMgr* myOperationMgr; /// processor for key event
113 bool myIsActive; /// boolean state whether the event filter perform own signal processing
116 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
117 ModuleBase_IWorkshop* theWorkshop)
118 : QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
120 /// we need to install filter to the application in order to react to 'Delete' key button
121 /// this key can not be a short cut for a corresponded action because we need to set
122 /// the actions priority
123 myShortCutListener = new XGUI_ShortCutListener(theParent, this);
126 XGUI_OperationMgr::~XGUI_OperationMgr()
130 void XGUI_OperationMgr::activate()
132 myShortCutListener->setActive(true);
135 void XGUI_OperationMgr::deactivate()
137 myShortCutListener->setActive(false);
140 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
142 return myOperations.count() > 0 ? myOperations.last() : 0;
145 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
149 return currentOperation() == theOperation;
152 bool XGUI_OperationMgr::hasOperation() const
154 return !myOperations.isEmpty() && (myOperations.last() != NULL);
157 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
159 foreach(ModuleBase_Operation* aOp, myOperations) {
160 if (aOp->id() == theId)
166 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
168 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
169 while (anIt != myOperations.begin()) {
171 ModuleBase_Operation* anOperation = *anIt;
172 if (anOperation->id() == theId)
179 int XGUI_OperationMgr::operationsCount() const
181 return myOperations.count();
184 QStringList XGUI_OperationMgr::operationList() const
187 foreach(ModuleBase_Operation* eachOperation, myOperations) {
188 ModuleBase_OperationFeature* aFOperation =
189 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
191 FeaturePtr aFeature = aFOperation->feature();
193 result << QString::fromStdString(aFeature->getKind());
200 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
202 int idx = myOperations.lastIndexOf(theOperation);
203 if(idx == -1 || idx == 0) {
206 return myOperations.at(idx - 1);
209 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
211 ModuleBase_ModelWidget* anActiveWidget = 0;
212 ModuleBase_Operation* anOperation = currentOperation();
214 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
216 anActiveWidget = aPanel->activeWidget();
218 return anActiveWidget;
221 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
224 currentOperation()->postpone();
225 myOperations.append(theOperation);
227 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
228 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
229 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
231 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
232 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
233 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
235 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
236 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
238 bool isStarted = theOperation->start();
240 onValidateOperation();
244 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
250 if (operationsCount() == 1) {
251 ModuleBase_Operation* aCurrentOperation = currentOperation();
252 if (canStopOperation(aCurrentOperation, theMessageKind)) {
253 abortOperation(aCurrentOperation);
259 if (theMessageKind == XGUI_AbortOperationMessage) {
260 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
261 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
262 myActiveMessageBox = 0;
264 else if (theMessageKind == XGUI_InformationMessage) {
265 QString aMessage = tr("Please validate all your active operations before saving.");
266 myActiveMessageBox = createInformationBox(aMessage);
267 myActiveMessageBox->exec();
268 myActiveMessageBox = 0;
269 aResult = false; // do not perform abort
271 while(aResult && hasOperation()) {
272 abortOperation(currentOperation());
278 bool XGUI_OperationMgr::commitAllOperations()
280 bool isCompositeCommitted = false, anOperationProcessed = false;
281 while (hasOperation()) {
282 ModuleBase_Operation* anOperation = currentOperation();
283 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
284 anOperationProcessed = commitOperation();
286 abortOperation(anOperation);
287 anOperationProcessed = true;
289 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
292 FeaturePtr aFeature = aFOperation->feature();
293 CompositeFeaturePtr aComposite =
294 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
295 isCompositeCommitted = aComposite.get();
296 if (isCompositeCommitted)
299 // not processed[committed] operation might be used in composite feature,
300 // so the while will be stopped by the previous check.
301 // this code is not necessary, but logically should be done when the processing will not
302 // be done for not composite feature by some reasons
303 if (!anOperationProcessed)
309 void XGUI_OperationMgr::onValidateOperation()
313 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
314 (currentOperation());
315 if(aFOperation && aFOperation->feature().get())
316 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
319 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
321 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
323 ModuleBase_OperationFeature* aFOperation =
324 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
326 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
329 foreach(ModuleBase_Operation* anOperation, myOperations) {
331 updateApplyOfOperations(anOperation);
334 // Apply button of the current operation should also be updated
335 onValidateOperation();
338 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
339 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
341 //in case of nested (sketch) operation no confirmation needed
342 if (isGrantedOperation(theOperation->id()))
344 if (theOperation && theOperation->isModified()) {
345 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
346 std::string aContext;
348 aContext = aOp->feature()->getKind();
349 QString aTitle = Config_Translator::translate(aContext,
350 theOperation->getDescription()->description().toStdString()).c_str();
352 if (theMessageKind == XGUI_AbortOperationMessage) {
353 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
354 myActiveMessageBox = createMessageBox(aMessage);
355 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
356 myActiveMessageBox = 0;
359 else if (theMessageKind == XGUI_InformationMessage) {
360 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
361 myActiveMessageBox = createInformationBox(aMessage);
362 myActiveMessageBox->exec();
363 myActiveMessageBox = 0;
370 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
372 theOperation->resume();
375 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
377 bool isGranted = false;
379 QListIterator<ModuleBase_Operation*> anIt(myOperations);
381 ModuleBase_Operation* aPreviousOperation = 0;
382 while (anIt.hasPrevious() && !isGranted) {
383 ModuleBase_Operation* anOp = anIt.previous();
385 isGranted = anOp->isGranted(theId);
390 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
392 SessionPtr aMgr = ModelAPI_Session::get();
393 DocumentPtr aDoc = aMgr->activeDocument();
394 bool aIsOp = aMgr->isOperation();
396 aMgr->startOperation(QString("Set current feature: %1")
397 .arg(theFeature->getKind().c_str()).toStdString());
398 aDoc->setCurrentFeature(theFeature, false);
399 #ifdef DEBUG_CURRENT_FEATURE
400 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
401 ModuleBase_Tools::objectName(
402 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
406 aMgr->finishOperation();
409 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
411 bool aCanStart = true;
413 ModuleBase_Operation* aCurrentOp = currentOperation();
415 bool aGranted = aCurrentOp->isGranted(theId);
416 // the started operation is granted for the current one,
417 // e.g. current - Sketch, started - Line
422 if (!isGrantedOperation(theId)) {
423 // the operation is not granted in the current list of operations
424 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
425 aCanStart = abortAllOperations();
427 else if (canStopOperation(aCurrentOp)) {
428 // the started operation is granted in the parrent operation,
429 // e.g. current - Line in Sketch, started Circle
430 stopOperation(aCurrentOp, isCommitted);
439 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
441 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
442 theOperation->isModified()) {
443 isCommitted = theOperation->commit();
446 abortOperation(theOperation);
450 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
452 ModuleBase_Operation* aCurrentOperation = currentOperation();
453 if (theOperation && (theOperation == aCurrentOperation))
454 theOperation->abort();
456 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
457 // all operation from the current to triggered should also be aborted
458 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
459 while(hasOperation()) {
460 ModuleBase_Operation* aCurrentOperation = currentOperation();
461 aCurrentOperation->abort();
462 if(theOperation == aCurrentOperation)
468 bool XGUI_OperationMgr::commitOperation()
470 bool isCommitted = false;
471 ModuleBase_Operation* anOperation = currentOperation();
472 if (anOperation && myWorkshop->module()->canCommitOperation())
473 isCommitted = anOperation->commit();
477 void XGUI_OperationMgr::onAbortOperation()
479 ModuleBase_Operation* aCurrentOperation = currentOperation();
480 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
481 abortOperation(aCurrentOperation);
485 void XGUI_OperationMgr::onAbortAllOperation()
487 abortAllOperations();
490 void XGUI_OperationMgr::onBeforeOperationStarted()
492 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
493 if (!aCurrentOperation)
496 /// Set current feature and remeber old current feature
497 ModuleBase_OperationFeature* aFOperation =
498 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
500 SessionPtr aMgr = ModelAPI_Session::get();
501 DocumentPtr aDoc = aMgr->activeDocument();
502 // the parameter of current feature should be false, we should use all feature, not only
503 // visible in order to correctly save the previous feature of the nested operation, where the
504 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
505 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
506 // When sketch entity operation started, the sketch should be cashed here as the current.
507 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
508 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
509 // As a result the sketch disappears from the viewer.
510 // However after commit it is displayed back.
511 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
513 #ifdef DEBUG_CURRENT_FEATURE
514 FeaturePtr aFeature = aFOperation->feature();
515 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
517 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
518 .arg(aFOperation->isEditOperation())
519 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
520 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
521 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
524 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
525 // in create operation, the current feature is changed by addFeature()
526 aDoc->setCurrentFeature(aFOperation->feature(), false);
527 #ifdef DEBUG_CURRENT_FEATURE
528 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
529 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
531 // this is the only place where flushes must be called after setCurrentFeature for the
532 // current moment: after this the opertion is not finished, so, the ObjectBrowser
533 // state may be corrupted (issue #1457)
534 static Events_Loop* aLoop = Events_Loop::loop();
535 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
536 aLoop->flush(aCreateEvent);
537 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
538 aLoop->flush(aDeleteEvent);
543 void XGUI_OperationMgr::onOperationStarted()
545 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
546 updateApplyOfOperations(aSenderOperation);
547 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
548 aWorkshop->operationStarted(aSenderOperation);
551 void XGUI_OperationMgr::onBeforeOperationAborted()
553 onBeforeOperationCommitted();
556 void XGUI_OperationMgr::onOperationAborted()
558 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
559 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
560 aWorkshop->setStatusBarMessage("");
561 emit operationAborted(aSenderOperation);
564 void XGUI_OperationMgr::onBeforeOperationCommitted()
566 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
567 if (!aCurrentOperation)
570 /// Restore the previous current feature
571 ModuleBase_OperationFeature* aFOperation =
572 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
574 #ifdef DEBUG_CURRENT_FEATURE
575 QString aKind = aFOperation->feature()->getKind().c_str();
576 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
577 .arg(aFOperation->isEditOperation())
578 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
579 qDebug(QString(" document->currentFeature(false) = %1").arg(
580 ModuleBase_Tools::objectName(
581 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
582 .toStdString().c_str());
585 if (aFOperation->isEditOperation()) {
586 /// Restore the previous current feature
587 setCurrentFeature(aFOperation->previousCurrentFeature());
589 else { // create operation
590 // the Top created feature should stays the current. In nested operations,
591 // like Line in the Sketch or
592 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
593 // It is performed here
594 // in order to perform it in the current transaction without opening a new one.
595 if (myOperations.front() != aFOperation)
596 setCurrentFeature(aFOperation->previousCurrentFeature());
598 ModuleBase_IModule* aModule = myWorkshop->module();
600 aModule->beforeOperationStopped(aFOperation);
604 void XGUI_OperationMgr::onOperationCommitted()
606 // apply state for all features from the stack of operations should be updated
607 updateApplyOfOperations();
609 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
610 emit operationCommitted(aSenderOperation);
613 void XGUI_OperationMgr::onOperationResumed()
615 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
616 emit operationResumed(aSenderOperation);
619 void XGUI_OperationMgr::onOperationStopped()
621 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
622 ModuleBase_Operation* aCurrentOperation = currentOperation();
623 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
626 myOperations.removeAll(aCurrentOperation);
627 aCurrentOperation->deleteLater();
629 emit operationStopped(aCurrentOperation);
631 // get last operation which can be resumed
632 ModuleBase_Operation* aResultOp = 0;
633 QListIterator<ModuleBase_Operation*> anIt(myOperations);
635 while (anIt.hasPrevious()) {
636 ModuleBase_Operation* anOp = anIt.previous();
643 //bool isModified = aCurrentOperation->isModified();
644 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
645 resumeOperation(aResultOp);
646 onValidateOperation();
650 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
652 bool isAccepted = false;
654 // Let the manager decide what to do with the given key combination.
655 ModuleBase_Operation* anOperation = currentOperation();
656 switch (theEvent->key()) {
658 case Qt::Key_Backtab:
660 ModuleBase_Operation* aOperation = currentOperation();
662 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
664 QWidget* aFocusedWidget = qApp->focusWidget();
665 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
666 if (!isPPChildObject) {
667 // check for case when the operation is started but property panel is not filled
668 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
669 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
677 case Qt::Key_Enter: {
678 isAccepted = onProcessEnter(theObject);
683 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
685 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
686 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
687 if (!aContext.IsNull()) {
688 Handle(V3d_View) aView = aViewer->activeView();
689 if ((theEvent->key() == Qt::Key_N))
690 aContext->HilightNextDetected(aView);
691 else if ((theEvent->key() == Qt::Key_P))
692 aContext->HilightPreviousDetected(aView);
693 aViewer->updateHighlight();
700 if ((theEvent->modifiers() == Qt::NoModifier))
701 myWorkshop->viewer()->hideSelectionHighlight();
708 // anOperation->keyReleased(theEvent->key());
713 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
715 // Let the manager decide what to do with the given key combination.
716 ModuleBase_Operation* anOperation = currentOperation();
717 bool isAccepted = false;
718 switch (theEvent->key()) {
719 case Qt::Key_Escape: {
720 // processing in message box
721 if (myActiveMessageBox)
723 myActiveMessageBox->reject();
726 // processing in the active widget
727 ModuleBase_Operation* aOperation = currentOperation();
728 if (!isAccepted && aOperation) {
729 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
731 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
734 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
736 ModuleBase_OperationFeature* aFOperation =
737 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
739 aFOperation->setNeedToBeAborted(true);
746 XGUI_ActiveControlSelector* anActiveSelector =
747 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
748 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
749 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
751 // default Escape button functionality
752 if (!isAccepted && aOperation) {
759 if ((theEvent->modifiers() == Qt::NoModifier))
760 myWorkshop->viewer()->showSelectionHighlight();
766 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
768 bool isAccepted = false;
769 ModuleBase_Operation* aOperation = currentOperation();
770 // to avoid enter processing when operation has not been started yet
773 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
776 // the next code is obsolete as we want to process Enter in property panel always
777 // only property panel enter is processed in order to do not process enter in application dialogs
778 //bool isPPChild = isChildObject(theObject, aPanel);
780 // return isAccepted;
782 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
783 bool isAborted = false;
785 QWidget* aFocusWidget = aPanel->focusWidget();
786 QToolButton* aCancelBtn =
787 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
788 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
789 abortOperation(aOperation);
795 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
798 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
800 /// functionality is similar to Apply click
801 ModuleBase_OperationFeature* aFOperation =
802 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
804 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
805 // key released is emitted to apply the current value to the model
806 // if it was modified in PP
807 emit keyEnterReleased();
819 bool editorControl(QObject* theObject)
821 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
825 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
827 bool isAccepted = false;
828 ModuleBase_Operation* aOperation = currentOperation();
829 ModuleBase_ModelWidget* anActiveWgt = 0;
830 // firstly the widget should process Delete action
831 ModuleBase_IPropertyPanel* aPanel;
832 bool isPPChildObject = false;
834 aPanel = aOperation->propertyPanel();
836 isPPChildObject = isChildObject(theObject, aPanel);
837 // process delete in active widget only if delete sender is child of property panel
838 // it is necessary for the case when OB is shown, user perform selection and click Delete
839 if (isPPChildObject) {
840 anActiveWgt = aPanel->activeWidget();
842 isAccepted = anActiveWgt->processAction(ActionDelete);
849 XGUI_ActiveControlSelector* anActiveSelector =
850 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
851 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
852 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
855 // after widget, object browser and viewer should process delete
856 /// other widgets such as line edit controls should not lead to
857 /// processing delete by workshop
858 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
859 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
860 bool isToDeleteObject = true;
861 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
862 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
863 if (theObject == aBrowser->treeView()) {
864 aContextMenuMgr->updateObjectBrowserMenu();
865 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
867 else if (isChildObject(theObject, aViewPort)) {
868 aContextMenuMgr->updateViewerMenu();
869 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
871 else if (isPPChildObject) {
872 // property panel child object is processed to process delete performed on Apply button of PP
873 isToDeleteObject = true;
875 else if (editorControl(theObject)) {
876 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
880 if (isToDeleteObject) {
881 aWorkshop->deleteObjects();
889 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
891 bool isPPChild = false;
892 if (theParent && theObject) {
893 QObject* aParent = (QObject*)theObject;
895 isPPChild = aParent == theParent;
898 aParent = aParent->parent();
904 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
906 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
907 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
908 qApp->activeWindow());
909 aMessageBox->setDefaultButton(QMessageBox::Cancel);
910 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
915 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
917 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
918 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
919 qApp->activeWindow());
920 aMessageBox->setDefaultButton(QMessageBox::Ok);
921 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key