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(XGUI_OperationMgr* theOperationMgr)
69 : QObject(theOperationMgr), 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);
82 XGUI_OperationMgr* myOperationMgr; /// processor for key event
83 bool myIsActive; /// boolean state whether the event filter perform own signal processing
86 bool XGUI_ShortCutListener::eventFilter(QObject *theObject, QEvent *theEvent)
88 bool isAccepted = false;
91 // Do not process keys for modal dialogues: all keys has to be processed within the dialog
92 // There is only one exception: ModuleBase_EditorDialog
93 QWindow* aWnd = qApp->modalWindow();
94 QString aName = "NoModal";
96 if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
97 aName = aWnd->objectName();
99 if (aName == "NoModal") {
100 if (theEvent->type() == QEvent::KeyRelease) {
101 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
103 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
104 switch (aKeyEvent->key()) {
106 isAccepted = myOperationMgr->onProcessDelete(theObject);
109 myOperationMgr->xworkshop()->objectBrowser()->onEditItem();
113 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
118 else if (theEvent->type() == QEvent::KeyPress) {
119 if (myOperationMgr->hasOperation()) {
120 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
121 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
122 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
128 isAccepted = QObject::eventFilter(theObject, theEvent);
134 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
135 ModuleBase_IWorkshop* theWorkshop)
136 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
138 /// we need to install filter to the application in order to react to 'Delete' key button
139 /// this key can not be a short cut for a corresponded action because we need to set
140 /// the actions priority
141 myShortCutListener = new XGUI_ShortCutListener(this);
144 XGUI_OperationMgr::~XGUI_OperationMgr()
148 void XGUI_OperationMgr::activate()
150 myShortCutListener->setActive(true);
153 void XGUI_OperationMgr::deactivate()
155 myShortCutListener->setActive(false);
158 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
160 return myOperations.count() > 0 ? myOperations.last() : 0;
163 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
167 return currentOperation() == theOperation;
170 bool XGUI_OperationMgr::hasOperation() const
172 return !myOperations.isEmpty() && (myOperations.last() != NULL);
175 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
177 foreach(ModuleBase_Operation* aOp, myOperations) {
178 if (aOp->id() == theId)
184 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
186 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
187 while (anIt != myOperations.begin()) {
189 ModuleBase_Operation* anOperation = *anIt;
190 if (anOperation->id() == theId)
197 int XGUI_OperationMgr::operationsCount() const
199 return myOperations.count();
202 QStringList XGUI_OperationMgr::operationList() const
205 foreach(ModuleBase_Operation* eachOperation, myOperations) {
206 ModuleBase_OperationFeature* aFOperation =
207 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
209 FeaturePtr aFeature = aFOperation->feature();
211 result << QString::fromStdString(aFeature->getKind());
218 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
220 int idx = myOperations.lastIndexOf(theOperation);
221 if(idx == -1 || idx == 0) {
224 return myOperations.at(idx - 1);
227 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
229 ModuleBase_ModelWidget* anActiveWidget = 0;
230 ModuleBase_Operation* anOperation = currentOperation();
232 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
234 anActiveWidget = aPanel->activeWidget();
236 return anActiveWidget;
239 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
242 currentOperation()->postpone();
243 myOperations.append(theOperation);
245 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
246 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
247 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
249 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
250 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
251 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
253 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
254 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
256 bool isStarted = theOperation->start();
258 onValidateOperation();
262 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
268 if (operationsCount() == 1) {
269 ModuleBase_Operation* aCurrentOperation = currentOperation();
270 if (canStopOperation(aCurrentOperation, theMessageKind)) {
271 abortOperation(aCurrentOperation);
277 if (theMessageKind == XGUI_AbortOperationMessage) {
278 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
279 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
280 myActiveMessageBox = 0;
282 else if (theMessageKind == XGUI_InformationMessage) {
283 QString aMessage = tr("Please validate all your active operations before saving.");
284 myActiveMessageBox = createInformationBox(aMessage);
285 myActiveMessageBox->exec();
286 myActiveMessageBox = 0;
287 aResult = false; // do not perform abort
289 while(aResult && hasOperation()) {
290 abortOperation(currentOperation());
296 bool XGUI_OperationMgr::commitAllOperations()
298 bool isCompositeCommitted = false, anOperationProcessed = false;
299 while (hasOperation()) {
300 ModuleBase_Operation* anOperation = currentOperation();
301 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
302 anOperationProcessed = commitOperation();
304 abortOperation(anOperation);
305 anOperationProcessed = true;
307 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
310 FeaturePtr aFeature = aFOperation->feature();
311 CompositeFeaturePtr aComposite =
312 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
313 isCompositeCommitted = aComposite.get();
314 if (isCompositeCommitted)
317 // not processed[committed] operation might be used in composite feature,
318 // so the while will be stopped by the previous check.
319 // this code is not necessary, but logically should be done when the processing will not
320 // be done for not composite feature by some reasons
321 if (!anOperationProcessed)
327 void XGUI_OperationMgr::onValidateOperation()
331 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
332 (currentOperation());
333 if(aFOperation && aFOperation->feature().get())
334 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
337 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
339 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
341 ModuleBase_OperationFeature* aFOperation =
342 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
344 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
347 foreach(ModuleBase_Operation* anOperation, myOperations) {
349 updateApplyOfOperations(anOperation);
352 // Apply button of the current operation should also be updated
353 onValidateOperation();
356 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
357 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
359 //in case of nested (sketch) operation no confirmation needed
360 if (isGrantedOperation(theOperation->id()))
362 if (theOperation && theOperation->isModified()) {
363 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
364 std::string aContext;
366 aContext = aOp->feature()->getKind();
367 QString aTitle = Config_Translator::translate(aContext,
368 theOperation->getDescription()->description().toStdString()).c_str();
370 if (theMessageKind == XGUI_AbortOperationMessage) {
371 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
372 myActiveMessageBox = createMessageBox(aMessage);
373 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
374 myActiveMessageBox = 0;
377 else if (theMessageKind == XGUI_InformationMessage) {
378 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
379 myActiveMessageBox = createInformationBox(aMessage);
380 myActiveMessageBox->exec();
381 myActiveMessageBox = 0;
388 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
390 theOperation->resume();
393 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
395 bool isGranted = false;
397 QListIterator<ModuleBase_Operation*> anIt(myOperations);
399 while (anIt.hasPrevious() && !isGranted) {
400 ModuleBase_Operation* anOp = anIt.previous();
402 isGranted = anOp->isGranted(theId);
407 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
409 SessionPtr aMgr = ModelAPI_Session::get();
410 DocumentPtr aDoc = aMgr->activeDocument();
411 bool aIsOp = aMgr->isOperation();
413 aMgr->startOperation(QString("Set current feature: %1")
414 .arg(theFeature->getKind().c_str()).toStdString());
415 aDoc->setCurrentFeature(theFeature, false);
416 #ifdef DEBUG_CURRENT_FEATURE
417 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
418 ModuleBase_Tools::objectName(
419 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
423 aMgr->finishOperation();
426 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
428 bool aCanStart = true;
430 ModuleBase_Operation* aCurrentOp = currentOperation();
432 bool aGranted = aCurrentOp->isGranted(theId);
433 // the started operation is granted for the current one,
434 // e.g. current - Sketch, started - Line
439 if (!isGrantedOperation(theId)) {
440 // the operation is not granted in the current list of operations
441 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
442 aCanStart = abortAllOperations();
444 else if (canStopOperation(aCurrentOp)) {
445 // the started operation is granted in the parrent operation,
446 // e.g. current - Line in Sketch, started Circle
447 stopOperation(aCurrentOp, isCommitted);
456 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
458 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
459 theOperation->isModified()) {
460 isCommitted = theOperation->commit();
463 abortOperation(theOperation);
467 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
469 ModuleBase_Operation* aCurrentOperation = currentOperation();
470 if (theOperation && (theOperation == aCurrentOperation))
471 theOperation->abort();
473 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
474 // all operation from the current to triggered should also be aborted
475 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
476 while(hasOperation()) {
477 ModuleBase_Operation* aCurOperation = currentOperation();
478 aCurOperation->abort();
479 if(theOperation == aCurOperation)
485 bool XGUI_OperationMgr::commitOperation()
487 bool isCommitted = false;
488 ModuleBase_Operation* anOperation = currentOperation();
489 if (anOperation && myWorkshop->module()->canCommitOperation())
490 isCommitted = anOperation->commit();
494 void XGUI_OperationMgr::onAbortOperation()
496 ModuleBase_Operation* aCurrentOperation = currentOperation();
497 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
498 abortOperation(aCurrentOperation);
502 void XGUI_OperationMgr::onAbortAllOperation()
504 abortAllOperations();
507 void XGUI_OperationMgr::onBeforeOperationStarted()
509 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
510 if (!aCurrentOperation)
513 /// Set current feature and remeber old current feature
514 ModuleBase_OperationFeature* aFOperation =
515 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
517 SessionPtr aMgr = ModelAPI_Session::get();
518 DocumentPtr aDoc = aMgr->activeDocument();
519 // the parameter of current feature should be false, we should use all feature, not only
520 // visible in order to correctly save the previous feature of the nested operation, where the
521 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
522 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
523 // When sketch entity operation started, the sketch should be cashed here as the current.
524 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
525 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
526 // As a result the sketch disappears from the viewer.
527 // However after commit it is displayed back.
528 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
530 #ifdef DEBUG_CURRENT_FEATURE
531 FeaturePtr aFeature = aFOperation->feature();
532 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
534 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
535 .arg(aFOperation->isEditOperation())
536 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
537 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
538 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
541 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
542 // in create operation, the current feature is changed by addFeature()
543 aDoc->setCurrentFeature(aFOperation->feature(), false);
544 #ifdef DEBUG_CURRENT_FEATURE
545 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
546 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
548 // this is the only place where flushes must be called after setCurrentFeature for the
549 // current moment: after this the opertion is not finished, so, the ObjectBrowser
550 // state may be corrupted (issue #1457)
551 static Events_Loop* aLoop = Events_Loop::loop();
552 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
553 aLoop->flush(aCreateEvent);
554 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
555 aLoop->flush(aDeleteEvent);
560 void XGUI_OperationMgr::onOperationStarted()
562 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
563 updateApplyOfOperations(aSenderOperation);
564 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
565 aWorkshop->operationStarted(aSenderOperation);
568 void XGUI_OperationMgr::onBeforeOperationAborted()
570 onBeforeOperationCommitted();
573 void XGUI_OperationMgr::onOperationAborted()
575 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
576 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
577 aWorkshop->setStatusBarMessage("");
578 emit operationAborted(aSenderOperation);
581 void XGUI_OperationMgr::onBeforeOperationCommitted()
583 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
584 if (!aCurrentOperation)
587 /// Restore the previous current feature
588 ModuleBase_OperationFeature* aFOperation =
589 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
591 #ifdef DEBUG_CURRENT_FEATURE
592 QString aKind = aFOperation->feature()->getKind().c_str();
593 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
594 .arg(aFOperation->isEditOperation())
595 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
596 qDebug(QString(" document->currentFeature(false) = %1").arg(
597 ModuleBase_Tools::objectName(
598 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
599 .toStdString().c_str());
602 if (aFOperation->isEditOperation()) {
603 /// Restore the previous current feature
604 setCurrentFeature(aFOperation->previousCurrentFeature());
606 else { // create operation
607 // the Top created feature should stays the current. In nested operations,
608 // like Line in the Sketch or
609 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
610 // It is performed here
611 // in order to perform it in the current transaction without opening a new one.
612 if (myOperations.front() != aFOperation)
613 setCurrentFeature(aFOperation->previousCurrentFeature());
615 ModuleBase_IModule* aModule = myWorkshop->module();
617 aModule->beforeOperationStopped(aFOperation);
621 void XGUI_OperationMgr::onOperationCommitted()
623 // apply state for all features from the stack of operations should be updated
624 updateApplyOfOperations();
626 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
627 emit operationCommitted(aSenderOperation);
630 void XGUI_OperationMgr::onOperationResumed()
632 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
633 emit operationResumed(aSenderOperation);
636 void XGUI_OperationMgr::onOperationStopped()
638 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
639 ModuleBase_Operation* aCurrentOperation = currentOperation();
640 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
643 myOperations.removeAll(aCurrentOperation);
644 aCurrentOperation->deleteLater();
646 emit operationStopped(aCurrentOperation);
648 // get last operation which can be resumed
649 ModuleBase_Operation* aResultOp = 0;
650 QListIterator<ModuleBase_Operation*> anIt(myOperations);
652 while (anIt.hasPrevious()) {
653 ModuleBase_Operation* anOp = anIt.previous();
660 //bool isModified = aCurrentOperation->isModified();
661 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
662 resumeOperation(aResultOp);
663 onValidateOperation();
667 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
669 bool isAccepted = false;
671 // Let the manager decide what to do with the given key combination.
672 ModuleBase_Operation* anOperation = currentOperation();
673 switch (theEvent->key()) {
675 case Qt::Key_Backtab:
677 ModuleBase_Operation* aOperation = currentOperation();
679 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
681 QWidget* aFocusedWidget = qApp->focusWidget();
682 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
683 if (!isPPChildObject) {
684 // check for case when the operation is started but property panel is not filled
685 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
686 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
694 case Qt::Key_Enter: {
695 isAccepted = onProcessEnter(theObject);
700 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
702 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
703 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
704 if (!aContext.IsNull()) {
705 Handle(V3d_View) aView = aViewer->activeView();
706 if ((theEvent->key() == Qt::Key_N))
707 aContext->HilightNextDetected(aView);
708 else if ((theEvent->key() == Qt::Key_P))
709 aContext->HilightPreviousDetected(aView);
710 aViewer->updateHighlight();
717 if ((theEvent->modifiers() == Qt::NoModifier))
718 myWorkshop->viewer()->hideSelectionHighlight();
725 // anOperation->keyReleased(theEvent->key());
730 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
732 // Let the manager decide what to do with the given key combination.
733 bool isAccepted = false;
734 switch (theEvent->key()) {
735 case Qt::Key_Escape: {
736 // processing in message box
737 if (myActiveMessageBox)
739 myActiveMessageBox->reject();
742 // processing in the active widget
743 ModuleBase_Operation* aOperation = currentOperation();
744 if (!isAccepted && aOperation) {
745 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
747 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
750 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
752 ModuleBase_OperationFeature* aFOperation =
753 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
755 aFOperation->setNeedToBeAborted(true);
762 XGUI_ActiveControlSelector* anActiveSelector =
763 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
764 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
765 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
767 // default Escape button functionality
768 if (!isAccepted && aOperation) {
775 if ((theEvent->modifiers() == Qt::NoModifier))
776 myWorkshop->viewer()->showSelectionHighlight();
782 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
784 bool isAccepted = false;
785 ModuleBase_Operation* aOperation = currentOperation();
786 // to avoid enter processing when operation has not been started yet
789 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
792 // the next code is obsolete as we want to process Enter in property panel always
793 // only property panel enter is processed in order to do not process enter in application dialogs
794 //bool isPPChild = isChildObject(theObject, aPanel);
796 // return isAccepted;
798 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
799 bool isAborted = false;
801 QWidget* aFocusWidget = aPanel->focusWidget();
802 QToolButton* aCancelBtn =
803 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
804 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
805 abortOperation(aOperation);
811 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
814 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
816 /// functionality is similar to Apply click
817 ModuleBase_OperationFeature* aFOperation =
818 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
820 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
821 // key released is emitted to apply the current value to the model
822 // if it was modified in PP
823 emit keyEnterReleased();
835 bool editorControl(QObject* theObject)
837 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
841 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
843 bool isAccepted = false;
844 ModuleBase_Operation* aOperation = currentOperation();
845 ModuleBase_ModelWidget* anActiveWgt = 0;
846 // firstly the widget should process Delete action
847 ModuleBase_IPropertyPanel* aPanel;
848 bool isPPChildObject = false;
850 aPanel = aOperation->propertyPanel();
852 isPPChildObject = isChildObject(theObject, aPanel);
853 // process delete in active widget only if delete sender is child of property panel
854 // it is necessary for the case when OB is shown, user perform selection and click Delete
855 if (isPPChildObject) {
856 anActiveWgt = aPanel->activeWidget();
858 isAccepted = anActiveWgt->processAction(ActionDelete);
865 XGUI_ActiveControlSelector* anActiveSelector =
866 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
867 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
868 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
871 // after widget, object browser and viewer should process delete
872 /// other widgets such as line edit controls should not lead to
873 /// processing delete by workshop
874 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
875 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
876 bool isToDeleteObject = false;
877 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
878 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
879 if (theObject == aBrowser->treeView()) {
880 aContextMenuMgr->updateObjectBrowserMenu();
881 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
883 else if (isChildObject(theObject, aViewPort)) {
884 aContextMenuMgr->updateViewerMenu();
885 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
887 else if (isPPChildObject) {
888 // property panel child object is processed to process delete performed on Apply button of PP
889 isToDeleteObject = true;
891 else if (editorControl(theObject)) {
892 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
896 if (isToDeleteObject) {
897 aWorkshop->deleteObjects();
905 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
907 bool isPPChild = false;
908 if (theParent && theObject) {
909 QObject* aParent = (QObject*)theObject;
911 isPPChild = aParent == theParent;
914 aParent = aParent->parent();
920 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
922 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
923 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
924 qApp->activeWindow());
925 aMessageBox->setDefaultButton(QMessageBox::Cancel);
926 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
931 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
933 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
934 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
935 qApp->activeWindow());
936 aMessageBox->setDefaultButton(QMessageBox::Ok);
937 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
942 XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
944 XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
945 return aConnector->workshop();