1 // Copyright (C) 2014-2024 CEA, EDF
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"
32 #include "XGUI_Selection.h"
33 #include "XGUI_SelectionMgr.h"
35 #include <ModuleBase_IPropertyPanel.h>
36 #include <ModuleBase_ModelWidget.h>
37 #include "ModuleBase_Operation.h"
38 #include "ModuleBase_IWorkshop.h"
39 #include "ModuleBase_IModule.h"
40 #include <ModuleBase_IViewer.h>
41 #include "ModuleBase_OperationDescription.h"
42 #include "ModuleBase_OperationFeature.h"
43 #include "ModuleBase_Tools.h"
45 #include <Config_Translator.h>
47 #include <ModelAPI_CompositeFeature.h>
48 #include <ModelAPI_Session.h>
50 #include <XGUI_PropertyPanel.h>
51 #include <QToolButton>
54 #include <QMessageBox>
55 #include <QApplication>
59 //#define DEBUG_CURRENT_FEATURE
61 /// Processes "Delete" key event of application. This key is used by several application actions.
62 /// There is a logical order of the actions processing. So the key can not be set for actions
63 /// as a shortcut. The class listens the key event and call operation manager processor.
64 class XGUI_ShortCutListener : public QObject
68 /// \param theParent the parent to be deleted when the parent is deleted
69 /// \param theOperationMgr the class to perform deletion
70 XGUI_ShortCutListener(XGUI_OperationMgr* theOperationMgr)
71 : QObject(theOperationMgr), myOperationMgr(theOperationMgr), myIsActive(false)
73 qApp->installEventFilter(this);
75 ~XGUI_ShortCutListener() {}
77 /// Switch on short cut listener
78 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
80 /// Redefinition of virtual function to process Delete key release
81 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
84 XGUI_OperationMgr* myOperationMgr; /// processor for key event
85 bool myIsActive; /// boolean state whether the event filter perform own signal processing
88 bool XGUI_ShortCutListener::eventFilter(QObject *theObject, QEvent *theEvent)
90 bool isAccepted = false;
93 // Do not process keys for modal dialogues: all keys has to be processed within the dialog
94 // There is only one exception: ModuleBase_EditorDialog
95 QWindow* aWnd = qApp->modalWindow();
96 QString aName = "NoModal";
98 if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
99 aName = aWnd->objectName();
101 if (aName == "NoModal") {
102 if (theEvent->type() == QEvent::KeyRelease) {
103 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
105 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
106 switch (aKeyEvent->key()) {
108 isAccepted = myOperationMgr->onProcessDelete(theObject);
112 QObjectPtrList anObjects = myOperationMgr->xworkshop()->selector()->selection()->selectedObjects();
113 if (myOperationMgr->xworkshop()->abortAllOperations())
115 myOperationMgr->xworkshop()->objectBrowser()->setObjectsSelected(anObjects);
116 myOperationMgr->xworkshop()->objectBrowser()->onEditItem();
122 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
127 else if (theEvent->type() == QEvent::KeyPress) {
128 if (myOperationMgr->hasOperation()) {
129 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
130 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
131 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
137 isAccepted = QObject::eventFilter(theObject, theEvent);
143 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
144 ModuleBase_IWorkshop* theWorkshop)
145 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
147 /// we need to install filter to the application in order to react to 'Delete' key button
148 /// this key can not be a short cut for a corresponded action because we need to set
149 /// the actions priority
150 myShortCutListener = new XGUI_ShortCutListener(this);
153 XGUI_OperationMgr::~XGUI_OperationMgr()
157 void XGUI_OperationMgr::activate()
159 myShortCutListener->setActive(true);
162 void XGUI_OperationMgr::deactivate()
164 myShortCutListener->setActive(false);
167 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
169 return myOperations.count() > 0 ? myOperations.last() : 0;
172 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
176 return currentOperation() == theOperation;
179 bool XGUI_OperationMgr::hasOperation() const
181 return !myOperations.isEmpty() && (myOperations.last() != NULL);
184 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
186 foreach(ModuleBase_Operation* aOp, myOperations) {
187 if (aOp->id() == theId)
193 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
195 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
196 while (anIt != myOperations.begin()) {
198 ModuleBase_Operation* anOperation = *anIt;
199 if (anOperation->id() == theId)
206 int XGUI_OperationMgr::operationsCount() const
208 return myOperations.count();
211 QStringList XGUI_OperationMgr::operationList() const
214 foreach(ModuleBase_Operation* eachOperation, myOperations) {
215 ModuleBase_OperationFeature* aFOperation =
216 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
218 FeaturePtr aFeature = aFOperation->feature();
220 result << QString::fromStdString(aFeature->getKind());
227 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
229 int idx = myOperations.lastIndexOf(theOperation);
230 if(idx == -1 || idx == 0) {
233 return myOperations.at(idx - 1);
236 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
238 ModuleBase_ModelWidget* anActiveWidget = 0;
239 ModuleBase_Operation* anOperation = currentOperation();
241 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
243 anActiveWidget = aPanel->activeWidget();
245 return anActiveWidget;
248 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
251 currentOperation()->postpone();
252 myOperations.append(theOperation);
254 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
255 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
256 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
258 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
259 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
260 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
262 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
263 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
265 bool isStarted = theOperation->start();
267 onValidateOperation();
271 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
277 if (operationsCount() == 1) {
278 ModuleBase_Operation* aCurrentOperation = currentOperation();
279 if (canStopOperation(aCurrentOperation, theMessageKind)) {
280 abortOperation(aCurrentOperation);
286 if (theMessageKind == XGUI_AbortOperationMessage) {
287 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
288 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
289 myActiveMessageBox = 0;
291 else if (theMessageKind == XGUI_InformationMessage) {
292 QString aMessage = tr("Please validate all your active operations before saving.");
293 myActiveMessageBox = createInformationBox(aMessage);
294 myActiveMessageBox->exec();
295 myActiveMessageBox = 0;
296 aResult = false; // do not perform abort
298 while(aResult && hasOperation()) {
299 abortOperation(currentOperation());
305 bool XGUI_OperationMgr::commitAllOperations()
307 bool isCompositeCommitted = false, anOperationProcessed = false;
308 while (hasOperation()) {
309 ModuleBase_Operation* anOperation = currentOperation();
310 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
311 anOperationProcessed = commitOperation();
313 abortOperation(anOperation);
314 anOperationProcessed = true;
316 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
319 FeaturePtr aFeature = aFOperation->feature();
320 CompositeFeaturePtr aComposite =
321 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
322 isCompositeCommitted = aComposite.get();
323 if (isCompositeCommitted)
326 // not processed[committed] operation might be used in composite feature,
327 // so the while will be stopped by the previous check.
328 // this code is not necessary, but logically should be done when the processing will not
329 // be done for not composite feature by some reasons
330 if (!anOperationProcessed)
336 void XGUI_OperationMgr::onValidateOperation()
340 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
341 (currentOperation());
342 if(aFOperation && aFOperation->feature().get())
343 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
346 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
348 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
350 ModuleBase_OperationFeature* aFOperation =
351 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
353 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
356 foreach(ModuleBase_Operation* anOperation, myOperations) {
358 updateApplyOfOperations(anOperation);
361 // Apply button of the current operation should also be updated
362 onValidateOperation();
365 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
366 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
368 //in case of nested (sketch) operation no confirmation needed
369 if (isGrantedOperation(theOperation->id()))
371 if (theOperation && theOperation->isModified()) {
372 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
373 std::string aContext;
374 if (aOp && aOp->feature())
375 aContext = aOp->feature()->getKind();
376 QString aTitle = Config_Translator::translate(aContext,
377 theOperation->getDescription()->description().toStdString()).c_str();
379 if (theMessageKind == XGUI_AbortOperationMessage) {
380 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
381 myActiveMessageBox = createMessageBox(aMessage);
382 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
383 myActiveMessageBox = 0;
386 else if (theMessageKind == XGUI_InformationMessage) {
387 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
388 myActiveMessageBox = createInformationBox(aMessage);
389 myActiveMessageBox->exec();
390 myActiveMessageBox = 0;
397 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
399 theOperation->resume();
402 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
404 bool isGranted = false;
406 QListIterator<ModuleBase_Operation*> anIt(myOperations);
408 while (anIt.hasPrevious() && !isGranted) {
409 ModuleBase_Operation* anOp = anIt.previous();
411 isGranted = anOp->isGranted(theId);
416 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
418 SessionPtr aMgr = ModelAPI_Session::get();
419 DocumentPtr aDoc = aMgr->activeDocument();
420 bool aIsOp = aMgr->isOperation();
422 aMgr->startOperation(QString("Set current feature: %1")
423 .arg(theFeature->getKind().c_str()).toStdString());
424 aDoc->setCurrentFeature(theFeature, false);
425 #ifdef DEBUG_CURRENT_FEATURE
426 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
427 ModuleBase_Tools::objectName(
428 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
432 aMgr->finishOperation();
435 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
437 bool aCanStart = true;
439 ModuleBase_Operation* aCurrentOp = currentOperation();
441 bool aGranted = aCurrentOp->isGranted(theId);
442 // the started operation is granted for the current one,
443 // e.g. current - Sketch, started - Line
448 if (!isGrantedOperation(theId)) {
449 // the operation is not granted in the current list of operations
450 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
451 aCanStart = abortAllOperations();
453 else if (canStopOperation(aCurrentOp)) {
454 // the started operation is granted in the parrent operation,
455 // e.g. current - Line in Sketch, started Circle
456 stopOperation(aCurrentOp, isCommitted);
465 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
467 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
468 theOperation->isModified()) {
469 isCommitted = theOperation->commit();
472 abortOperation(theOperation);
476 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
478 ModuleBase_Operation* aCurrentOperation = currentOperation();
479 if (theOperation && (theOperation == aCurrentOperation))
480 theOperation->abort();
482 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
483 // all operation from the current to triggered should also be aborted
484 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
485 while(hasOperation()) {
486 ModuleBase_Operation* aCurOperation = currentOperation();
487 aCurOperation->abort();
488 if(theOperation == aCurOperation)
494 bool XGUI_OperationMgr::commitOperation()
496 bool isCommitted = false;
497 ModuleBase_Operation* anOperation = currentOperation();
498 if (anOperation && myWorkshop->module()->canCommitOperation())
499 isCommitted = anOperation->commit();
503 void XGUI_OperationMgr::onAbortOperation()
505 ModuleBase_Operation* aCurrentOperation = currentOperation();
506 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
507 abortOperation(aCurrentOperation);
511 void XGUI_OperationMgr::onAbortAllOperation()
513 abortAllOperations();
516 void XGUI_OperationMgr::onBeforeOperationStarted()
518 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
519 if (!aCurrentOperation)
522 /// Set current feature and remeber old current feature
523 ModuleBase_OperationFeature* aFOperation =
524 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
526 SessionPtr aMgr = ModelAPI_Session::get();
527 DocumentPtr aDoc = aMgr->activeDocument();
528 // the parameter of current feature should be false, we should use all feature, not only
529 // visible in order to correctly save the previous feature of the nested operation, where the
530 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
531 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
532 // When sketch entity operation started, the sketch should be cashed here as the current.
533 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
534 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
535 // As a result the sketch disappears from the viewer.
536 // However after commit it is displayed back.
537 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
539 #ifdef DEBUG_CURRENT_FEATURE
540 FeaturePtr aFeature = aFOperation->feature();
541 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
543 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
544 .arg(aFOperation->isEditOperation())
545 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
546 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
547 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
550 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
551 // in create operation, the current feature is changed by addFeature()
552 aDoc->setCurrentFeature(aFOperation->feature(), false);
553 #ifdef DEBUG_CURRENT_FEATURE
554 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
555 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
557 // this is the only place where flushes must be called after setCurrentFeature for the
558 // current moment: after this the opertion is not finished, so, the ObjectBrowser
559 // state may be corrupted (issue #1457)
560 static Events_Loop* aLoop = Events_Loop::loop();
561 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
562 aLoop->flush(aCreateEvent);
563 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
564 aLoop->flush(aDeleteEvent);
569 void XGUI_OperationMgr::onOperationStarted()
571 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
572 updateApplyOfOperations(aSenderOperation);
573 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
574 aWorkshop->operationStarted(aSenderOperation);
577 void XGUI_OperationMgr::onBeforeOperationAborted()
579 onBeforeOperationCommitted();
582 void XGUI_OperationMgr::onOperationAborted()
584 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
585 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
586 aWorkshop->setStatusBarMessage("");
587 emit operationAborted(aSenderOperation);
590 void XGUI_OperationMgr::onBeforeOperationCommitted()
592 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
593 if (!aCurrentOperation)
596 /// Restore the previous current feature
597 ModuleBase_OperationFeature* aFOperation =
598 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
600 #ifdef DEBUG_CURRENT_FEATURE
601 QString aKind = aFOperation->feature()->getKind().c_str();
602 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
603 .arg(aFOperation->isEditOperation())
604 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
605 qDebug(QString(" document->currentFeature(false) = %1").arg(
606 ModuleBase_Tools::objectName(
607 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
608 .toStdString().c_str());
611 if (aFOperation->isEditOperation()) {
612 /// Restore the previous current feature
613 setCurrentFeature(aFOperation->previousCurrentFeature());
615 else { // create operation
616 // the Top created feature should stays the current. In nested operations,
617 // like Line in the Sketch or
618 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
619 // It is performed here
620 // in order to perform it in the current transaction without opening a new one.
621 if (myOperations.front() != aFOperation)
622 setCurrentFeature(aFOperation->previousCurrentFeature());
624 ModuleBase_IModule* aModule = myWorkshop->module();
626 aModule->beforeOperationStopped(aFOperation);
630 void XGUI_OperationMgr::onOperationCommitted()
632 // apply state for all features from the stack of operations should be updated
633 updateApplyOfOperations();
635 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
636 emit operationCommitted(aSenderOperation);
639 void XGUI_OperationMgr::onOperationResumed()
641 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
642 emit operationResumed(aSenderOperation);
645 void XGUI_OperationMgr::onOperationStopped()
647 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
648 ModuleBase_Operation* aCurrentOperation = currentOperation();
649 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
652 myOperations.removeAll(aCurrentOperation);
653 aCurrentOperation->deleteLater();
655 emit operationStopped(aCurrentOperation);
657 // get last operation which can be resumed
658 ModuleBase_Operation* aResultOp = 0;
659 QListIterator<ModuleBase_Operation*> anIt(myOperations);
661 while (anIt.hasPrevious()) {
662 ModuleBase_Operation* anOp = anIt.previous();
669 //bool isModified = aCurrentOperation->isModified();
670 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
671 resumeOperation(aResultOp);
672 onValidateOperation();
676 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
678 bool isAccepted = false;
680 // Let the manager decide what to do with the given key combination.
681 ModuleBase_Operation* anOperation = currentOperation();
682 switch (theEvent->key()) {
684 case Qt::Key_Backtab:
686 ModuleBase_Operation* aOperation = currentOperation();
688 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
690 QWidget* aFocusedWidget = qApp->focusWidget();
691 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
692 if (!isPPChildObject) {
693 // check for case when the operation is started but property panel is not filled
694 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
695 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
703 case Qt::Key_Enter: {
704 isAccepted = onProcessEnter(theObject);
709 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
711 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
712 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
713 if (!aContext.IsNull()) {
714 Handle(V3d_View) aView = aViewer->activeView();
715 if ((theEvent->key() == Qt::Key_N))
716 aContext->HilightNextDetected(aView);
717 else if ((theEvent->key() == Qt::Key_P))
718 aContext->HilightPreviousDetected(aView);
719 aViewer->updateHighlight();
726 if ((theEvent->modifiers() == Qt::NoModifier))
727 myWorkshop->viewer()->hideSelectionHighlight();
734 // anOperation->keyReleased(theEvent->key());
739 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
741 // Let the manager decide what to do with the given key combination.
742 bool isAccepted = false;
743 switch (theEvent->key()) {
744 case Qt::Key_Escape: {
745 // processing in message box
746 if (myActiveMessageBox)
748 myActiveMessageBox->reject();
751 // processing in the active widget
752 ModuleBase_Operation* aOperation = currentOperation();
753 if (!isAccepted && aOperation) {
754 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
756 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
759 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
761 ModuleBase_OperationFeature* aFOperation =
762 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
764 aFOperation->setNeedToBeAborted(true);
771 XGUI_ActiveControlSelector* anActiveSelector =
772 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
773 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
774 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
776 // default Escape button functionality
777 if (!isAccepted && aOperation) {
784 if ((theEvent->modifiers() == Qt::NoModifier))
785 myWorkshop->viewer()->showSelectionHighlight();
791 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
793 bool isAccepted = false;
794 ModuleBase_Operation* aOperation = currentOperation();
795 // to avoid enter processing when operation has not been started yet
798 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
801 // the next code is obsolete as we want to process Enter in property panel always
802 // only property panel enter is processed in order to do not process enter in application dialogs
803 //bool isPPChild = isChildObject(theObject, aPanel);
805 // return isAccepted;
807 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
808 bool isAborted = false;
810 QWidget* aFocusWidget = aPanel->focusWidget();
811 QToolButton* aCancelBtn =
812 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
813 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
814 abortOperation(aOperation);
820 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
823 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
825 /// functionality is similar to Apply click
826 ModuleBase_OperationFeature* aFOperation =
827 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
829 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
830 // key released is emitted to apply the current value to the model
831 // if it was modified in PP
832 emit keyEnterReleased();
844 bool editorControl(QObject* theObject)
846 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
850 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
852 bool isAccepted = false;
853 ModuleBase_Operation* aOperation = currentOperation();
854 ModuleBase_ModelWidget* anActiveWgt = 0;
855 // firstly the widget should process Delete action
856 ModuleBase_IPropertyPanel* aPanel;
857 bool isPPChildObject = false;
859 aPanel = aOperation->propertyPanel();
861 isPPChildObject = isChildObject(theObject, aPanel);
862 // process delete in active widget only if delete sender is child of property panel
863 // it is necessary for the case when OB is shown, user perform selection and click Delete
864 if (isPPChildObject) {
865 anActiveWgt = aPanel->activeWidget();
867 isAccepted = anActiveWgt->processAction(ActionDelete);
874 XGUI_ActiveControlSelector* anActiveSelector =
875 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
876 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
877 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
880 // after widget, object browser and viewer should process delete
881 /// other widgets such as line edit controls should not lead to
882 /// processing delete by workshop
883 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
884 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
885 bool isToDeleteObject = false;
886 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
887 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
888 if (theObject == aBrowser->treeView()) {
889 aContextMenuMgr->updateObjectBrowserMenu();
890 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
892 else if (isChildObject(theObject, aViewPort)) {
893 aContextMenuMgr->updateViewerMenu();
894 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
896 else if (isPPChildObject) {
897 // property panel child object is processed to process delete performed on Apply button of PP
898 isToDeleteObject = true;
900 else if (editorControl(theObject)) {
901 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
905 if (isToDeleteObject) {
906 aWorkshop->deleteObjects();
914 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
916 bool isPPChild = false;
917 if (theParent && theObject) {
918 QObject* aParent = (QObject*)theObject;
920 isPPChild = aParent == theParent;
923 aParent = aParent->parent();
929 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
931 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
932 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
933 qApp->activeWindow());
934 aMessageBox->setDefaultButton(QMessageBox::Cancel);
935 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
940 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
942 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
943 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
944 qApp->activeWindow());
945 aMessageBox->setDefaultButton(QMessageBox::Ok);
946 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
951 XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
953 XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
954 return aConnector->workshop();