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();
112 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
117 else if (theEvent->type() == QEvent::KeyPress) {
118 if (myOperationMgr->hasOperation()) {
119 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
120 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
121 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
127 isAccepted = QObject::eventFilter(theObject, theEvent);
133 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
134 ModuleBase_IWorkshop* theWorkshop)
135 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
137 /// we need to install filter to the application in order to react to 'Delete' key button
138 /// this key can not be a short cut for a corresponded action because we need to set
139 /// the actions priority
140 myShortCutListener = new XGUI_ShortCutListener(this);
143 XGUI_OperationMgr::~XGUI_OperationMgr()
147 void XGUI_OperationMgr::activate()
149 myShortCutListener->setActive(true);
152 void XGUI_OperationMgr::deactivate()
154 myShortCutListener->setActive(false);
157 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
159 return myOperations.count() > 0 ? myOperations.last() : 0;
162 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
166 return currentOperation() == theOperation;
169 bool XGUI_OperationMgr::hasOperation() const
171 return !myOperations.isEmpty() && (myOperations.last() != NULL);
174 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
176 foreach(ModuleBase_Operation* aOp, myOperations) {
177 if (aOp->id() == theId)
183 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
185 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
186 while (anIt != myOperations.begin()) {
188 ModuleBase_Operation* anOperation = *anIt;
189 if (anOperation->id() == theId)
196 int XGUI_OperationMgr::operationsCount() const
198 return myOperations.count();
201 QStringList XGUI_OperationMgr::operationList() const
204 foreach(ModuleBase_Operation* eachOperation, myOperations) {
205 ModuleBase_OperationFeature* aFOperation =
206 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
208 FeaturePtr aFeature = aFOperation->feature();
210 result << QString::fromStdString(aFeature->getKind());
217 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
219 int idx = myOperations.lastIndexOf(theOperation);
220 if(idx == -1 || idx == 0) {
223 return myOperations.at(idx - 1);
226 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
228 ModuleBase_ModelWidget* anActiveWidget = 0;
229 ModuleBase_Operation* anOperation = currentOperation();
231 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
233 anActiveWidget = aPanel->activeWidget();
235 return anActiveWidget;
238 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
241 currentOperation()->postpone();
242 myOperations.append(theOperation);
244 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
245 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
246 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
248 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
249 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
250 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
252 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
253 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
255 bool isStarted = theOperation->start();
257 onValidateOperation();
261 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
267 if (operationsCount() == 1) {
268 ModuleBase_Operation* aCurrentOperation = currentOperation();
269 if (canStopOperation(aCurrentOperation, theMessageKind)) {
270 abortOperation(aCurrentOperation);
276 if (theMessageKind == XGUI_AbortOperationMessage) {
277 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
278 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
279 myActiveMessageBox = 0;
281 else if (theMessageKind == XGUI_InformationMessage) {
282 QString aMessage = tr("Please validate all your active operations before saving.");
283 myActiveMessageBox = createInformationBox(aMessage);
284 myActiveMessageBox->exec();
285 myActiveMessageBox = 0;
286 aResult = false; // do not perform abort
288 while(aResult && hasOperation()) {
289 abortOperation(currentOperation());
295 bool XGUI_OperationMgr::commitAllOperations()
297 bool isCompositeCommitted = false, anOperationProcessed = false;
298 while (hasOperation()) {
299 ModuleBase_Operation* anOperation = currentOperation();
300 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
301 anOperationProcessed = commitOperation();
303 abortOperation(anOperation);
304 anOperationProcessed = true;
306 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
309 FeaturePtr aFeature = aFOperation->feature();
310 CompositeFeaturePtr aComposite =
311 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
312 isCompositeCommitted = aComposite.get();
313 if (isCompositeCommitted)
316 // not processed[committed] operation might be used in composite feature,
317 // so the while will be stopped by the previous check.
318 // this code is not necessary, but logically should be done when the processing will not
319 // be done for not composite feature by some reasons
320 if (!anOperationProcessed)
326 void XGUI_OperationMgr::onValidateOperation()
330 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
331 (currentOperation());
332 if(aFOperation && aFOperation->feature().get())
333 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
336 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
338 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
340 ModuleBase_OperationFeature* aFOperation =
341 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
343 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
346 foreach(ModuleBase_Operation* anOperation, myOperations) {
348 updateApplyOfOperations(anOperation);
351 // Apply button of the current operation should also be updated
352 onValidateOperation();
355 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
356 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
358 //in case of nested (sketch) operation no confirmation needed
359 if (isGrantedOperation(theOperation->id()))
361 if (theOperation && theOperation->isModified()) {
362 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
363 std::string aContext;
365 aContext = aOp->feature()->getKind();
366 QString aTitle = Config_Translator::translate(aContext,
367 theOperation->getDescription()->description().toStdString()).c_str();
369 if (theMessageKind == XGUI_AbortOperationMessage) {
370 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
371 myActiveMessageBox = createMessageBox(aMessage);
372 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
373 myActiveMessageBox = 0;
376 else if (theMessageKind == XGUI_InformationMessage) {
377 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
378 myActiveMessageBox = createInformationBox(aMessage);
379 myActiveMessageBox->exec();
380 myActiveMessageBox = 0;
387 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
389 theOperation->resume();
392 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
394 bool isGranted = false;
396 QListIterator<ModuleBase_Operation*> anIt(myOperations);
398 while (anIt.hasPrevious() && !isGranted) {
399 ModuleBase_Operation* anOp = anIt.previous();
401 isGranted = anOp->isGranted(theId);
406 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
408 SessionPtr aMgr = ModelAPI_Session::get();
409 DocumentPtr aDoc = aMgr->activeDocument();
410 bool aIsOp = aMgr->isOperation();
412 aMgr->startOperation(QString("Set current feature: %1")
413 .arg(theFeature->getKind().c_str()).toStdString());
414 aDoc->setCurrentFeature(theFeature, false);
415 #ifdef DEBUG_CURRENT_FEATURE
416 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
417 ModuleBase_Tools::objectName(
418 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
422 aMgr->finishOperation();
425 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
427 bool aCanStart = true;
429 ModuleBase_Operation* aCurrentOp = currentOperation();
431 bool aGranted = aCurrentOp->isGranted(theId);
432 // the started operation is granted for the current one,
433 // e.g. current - Sketch, started - Line
438 if (!isGrantedOperation(theId)) {
439 // the operation is not granted in the current list of operations
440 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
441 aCanStart = abortAllOperations();
443 else if (canStopOperation(aCurrentOp)) {
444 // the started operation is granted in the parrent operation,
445 // e.g. current - Line in Sketch, started Circle
446 stopOperation(aCurrentOp, isCommitted);
455 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
457 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
458 theOperation->isModified()) {
459 isCommitted = theOperation->commit();
462 abortOperation(theOperation);
466 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
468 ModuleBase_Operation* aCurrentOperation = currentOperation();
469 if (theOperation && (theOperation == aCurrentOperation))
470 theOperation->abort();
472 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
473 // all operation from the current to triggered should also be aborted
474 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
475 while(hasOperation()) {
476 ModuleBase_Operation* aCurOperation = currentOperation();
477 aCurOperation->abort();
478 if(theOperation == aCurOperation)
484 bool XGUI_OperationMgr::commitOperation()
486 bool isCommitted = false;
487 ModuleBase_Operation* anOperation = currentOperation();
488 if (anOperation && myWorkshop->module()->canCommitOperation())
489 isCommitted = anOperation->commit();
493 void XGUI_OperationMgr::onAbortOperation()
495 ModuleBase_Operation* aCurrentOperation = currentOperation();
496 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
497 abortOperation(aCurrentOperation);
501 void XGUI_OperationMgr::onAbortAllOperation()
503 abortAllOperations();
506 void XGUI_OperationMgr::onBeforeOperationStarted()
508 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
509 if (!aCurrentOperation)
512 /// Set current feature and remeber old current feature
513 ModuleBase_OperationFeature* aFOperation =
514 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
516 SessionPtr aMgr = ModelAPI_Session::get();
517 DocumentPtr aDoc = aMgr->activeDocument();
518 // the parameter of current feature should be false, we should use all feature, not only
519 // visible in order to correctly save the previous feature of the nested operation, where the
520 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
521 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
522 // When sketch entity operation started, the sketch should be cashed here as the current.
523 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
524 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
525 // As a result the sketch disappears from the viewer.
526 // However after commit it is displayed back.
527 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
529 #ifdef DEBUG_CURRENT_FEATURE
530 FeaturePtr aFeature = aFOperation->feature();
531 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
533 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
534 .arg(aFOperation->isEditOperation())
535 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
536 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
537 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
540 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
541 // in create operation, the current feature is changed by addFeature()
542 aDoc->setCurrentFeature(aFOperation->feature(), false);
543 #ifdef DEBUG_CURRENT_FEATURE
544 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
545 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
547 // this is the only place where flushes must be called after setCurrentFeature for the
548 // current moment: after this the opertion is not finished, so, the ObjectBrowser
549 // state may be corrupted (issue #1457)
550 static Events_Loop* aLoop = Events_Loop::loop();
551 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
552 aLoop->flush(aCreateEvent);
553 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
554 aLoop->flush(aDeleteEvent);
559 void XGUI_OperationMgr::onOperationStarted()
561 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
562 updateApplyOfOperations(aSenderOperation);
563 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
564 aWorkshop->operationStarted(aSenderOperation);
567 void XGUI_OperationMgr::onBeforeOperationAborted()
569 onBeforeOperationCommitted();
572 void XGUI_OperationMgr::onOperationAborted()
574 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
575 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
576 aWorkshop->setStatusBarMessage("");
577 emit operationAborted(aSenderOperation);
580 void XGUI_OperationMgr::onBeforeOperationCommitted()
582 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
583 if (!aCurrentOperation)
586 /// Restore the previous current feature
587 ModuleBase_OperationFeature* aFOperation =
588 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
590 #ifdef DEBUG_CURRENT_FEATURE
591 QString aKind = aFOperation->feature()->getKind().c_str();
592 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
593 .arg(aFOperation->isEditOperation())
594 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
595 qDebug(QString(" document->currentFeature(false) = %1").arg(
596 ModuleBase_Tools::objectName(
597 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
598 .toStdString().c_str());
601 if (aFOperation->isEditOperation()) {
602 /// Restore the previous current feature
603 setCurrentFeature(aFOperation->previousCurrentFeature());
605 else { // create operation
606 // the Top created feature should stays the current. In nested operations,
607 // like Line in the Sketch or
608 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
609 // It is performed here
610 // in order to perform it in the current transaction without opening a new one.
611 if (myOperations.front() != aFOperation)
612 setCurrentFeature(aFOperation->previousCurrentFeature());
614 ModuleBase_IModule* aModule = myWorkshop->module();
616 aModule->beforeOperationStopped(aFOperation);
620 void XGUI_OperationMgr::onOperationCommitted()
622 // apply state for all features from the stack of operations should be updated
623 updateApplyOfOperations();
625 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
626 emit operationCommitted(aSenderOperation);
629 void XGUI_OperationMgr::onOperationResumed()
631 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
632 emit operationResumed(aSenderOperation);
635 void XGUI_OperationMgr::onOperationStopped()
637 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
638 ModuleBase_Operation* aCurrentOperation = currentOperation();
639 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
642 myOperations.removeAll(aCurrentOperation);
643 aCurrentOperation->deleteLater();
645 emit operationStopped(aCurrentOperation);
647 // get last operation which can be resumed
648 ModuleBase_Operation* aResultOp = 0;
649 QListIterator<ModuleBase_Operation*> anIt(myOperations);
651 while (anIt.hasPrevious()) {
652 ModuleBase_Operation* anOp = anIt.previous();
659 //bool isModified = aCurrentOperation->isModified();
660 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
661 resumeOperation(aResultOp);
662 onValidateOperation();
666 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
668 bool isAccepted = false;
670 // Let the manager decide what to do with the given key combination.
671 ModuleBase_Operation* anOperation = currentOperation();
672 switch (theEvent->key()) {
674 case Qt::Key_Backtab:
676 ModuleBase_Operation* aOperation = currentOperation();
678 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
680 QWidget* aFocusedWidget = qApp->focusWidget();
681 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
682 if (!isPPChildObject) {
683 // check for case when the operation is started but property panel is not filled
684 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
685 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
693 case Qt::Key_Enter: {
694 isAccepted = onProcessEnter(theObject);
699 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
701 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
702 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
703 if (!aContext.IsNull()) {
704 Handle(V3d_View) aView = aViewer->activeView();
705 if ((theEvent->key() == Qt::Key_N))
706 aContext->HilightNextDetected(aView);
707 else if ((theEvent->key() == Qt::Key_P))
708 aContext->HilightPreviousDetected(aView);
709 aViewer->updateHighlight();
716 if ((theEvent->modifiers() == Qt::NoModifier))
717 myWorkshop->viewer()->hideSelectionHighlight();
724 // anOperation->keyReleased(theEvent->key());
729 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
731 // Let the manager decide what to do with the given key combination.
732 bool isAccepted = false;
733 switch (theEvent->key()) {
734 case Qt::Key_Escape: {
735 // processing in message box
736 if (myActiveMessageBox)
738 myActiveMessageBox->reject();
741 // processing in the active widget
742 ModuleBase_Operation* aOperation = currentOperation();
743 if (!isAccepted && aOperation) {
744 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
746 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
749 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
751 ModuleBase_OperationFeature* aFOperation =
752 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
754 aFOperation->setNeedToBeAborted(true);
761 XGUI_ActiveControlSelector* anActiveSelector =
762 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
763 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
764 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
766 // default Escape button functionality
767 if (!isAccepted && aOperation) {
774 if ((theEvent->modifiers() == Qt::NoModifier))
775 myWorkshop->viewer()->showSelectionHighlight();
781 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
783 bool isAccepted = false;
784 ModuleBase_Operation* aOperation = currentOperation();
785 // to avoid enter processing when operation has not been started yet
788 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
791 // the next code is obsolete as we want to process Enter in property panel always
792 // only property panel enter is processed in order to do not process enter in application dialogs
793 //bool isPPChild = isChildObject(theObject, aPanel);
795 // return isAccepted;
797 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
798 bool isAborted = false;
800 QWidget* aFocusWidget = aPanel->focusWidget();
801 QToolButton* aCancelBtn =
802 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
803 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
804 abortOperation(aOperation);
810 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
813 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
815 /// functionality is similar to Apply click
816 ModuleBase_OperationFeature* aFOperation =
817 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
819 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
820 // key released is emitted to apply the current value to the model
821 // if it was modified in PP
822 emit keyEnterReleased();
834 bool editorControl(QObject* theObject)
836 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
840 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
842 bool isAccepted = false;
843 ModuleBase_Operation* aOperation = currentOperation();
844 ModuleBase_ModelWidget* anActiveWgt = 0;
845 // firstly the widget should process Delete action
846 ModuleBase_IPropertyPanel* aPanel;
847 bool isPPChildObject = false;
849 aPanel = aOperation->propertyPanel();
851 isPPChildObject = isChildObject(theObject, aPanel);
852 // process delete in active widget only if delete sender is child of property panel
853 // it is necessary for the case when OB is shown, user perform selection and click Delete
854 if (isPPChildObject) {
855 anActiveWgt = aPanel->activeWidget();
857 isAccepted = anActiveWgt->processAction(ActionDelete);
864 XGUI_ActiveControlSelector* anActiveSelector =
865 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
866 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
867 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
870 // after widget, object browser and viewer should process delete
871 /// other widgets such as line edit controls should not lead to
872 /// processing delete by workshop
873 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
874 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
875 bool isToDeleteObject = false;
876 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
877 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
878 if (theObject == aBrowser->treeView()) {
879 aContextMenuMgr->updateObjectBrowserMenu();
880 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
882 else if (isChildObject(theObject, aViewPort)) {
883 aContextMenuMgr->updateViewerMenu();
884 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
886 else if (isPPChildObject) {
887 // property panel child object is processed to process delete performed on Apply button of PP
888 isToDeleteObject = true;
890 else if (editorControl(theObject)) {
891 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
895 if (isToDeleteObject) {
896 aWorkshop->deleteObjects();
904 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
906 bool isPPChild = false;
907 if (theParent && theObject) {
908 QObject* aParent = (QObject*)theObject;
910 isPPChild = aParent == theParent;
913 aParent = aParent->parent();
919 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
921 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
922 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
923 qApp->activeWindow());
924 aMessageBox->setDefaultButton(QMessageBox::Cancel);
925 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
930 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
932 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
933 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
934 qApp->activeWindow());
935 aMessageBox->setDefaultButton(QMessageBox::Ok);
936 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
941 XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
943 XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
944 return aConnector->workshop();