1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_OperationMgr.h"
23 #include "XGUI_ActiveControlMgr.h"
24 #include "XGUI_ActiveControlSelector.h"
25 #include "XGUI_FacesPanelSelector.h"
26 #include "XGUI_ModuleConnector.h"
27 #include "XGUI_Workshop.h"
28 #include "XGUI_ErrorMgr.h"
29 #include "XGUI_FacesPanel.h"
30 #include "XGUI_Tools.h"
31 #include "XGUI_ObjectsBrowser.h"
32 #include "XGUI_ContextMenuMgr.h"
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_ModelWidget.h>
36 #include "ModuleBase_Operation.h"
37 #include "ModuleBase_IWorkshop.h"
38 #include "ModuleBase_IModule.h"
39 #include <ModuleBase_IViewer.h>
40 #include "ModuleBase_OperationDescription.h"
41 #include "ModuleBase_OperationFeature.h"
42 #include "ModuleBase_Tools.h"
44 #include "ModelAPI_CompositeFeature.h"
45 #include "ModelAPI_Session.h"
47 #include <XGUI_PropertyPanel.h>
48 #include <QToolButton>
51 #include <QMessageBox>
52 #include <QApplication>
55 //#define DEBUG_CURRENT_FEATURE
57 /// Processes "Delete" key event of application. This key is used by several application actions.
58 /// There is a logical order of the actions processing. So the key can not be set for actions
59 /// as a shortcut. The class listens the key event and call operation manager processor.
60 class XGUI_ShortCutListener : public QObject
64 /// \param theParent the parent to be deleted when the parent is deleted
65 /// \param theOperationMgr the class to perform deletion
66 XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
67 : QObject(theParent), myOperationMgr(theOperationMgr), myIsActive(false)
69 qApp->installEventFilter(this);
71 ~XGUI_ShortCutListener() {}
73 /// Switch on short cut listener
74 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
76 /// Redefinition of virtual function to process Delete key release
77 virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
79 bool isAccepted = false;
81 if (theEvent->type() == QEvent::KeyRelease) {
82 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
84 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
85 switch (aKeyEvent->key()) {
87 isAccepted = myOperationMgr->onProcessDelete(theObject);
90 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
95 else if (theEvent->type() == QEvent::KeyPress) {
96 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
97 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
98 switch (aKeyEvent->key()) {
100 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
108 isAccepted = QObject::eventFilter(theObject, theEvent);
113 XGUI_OperationMgr* myOperationMgr; /// processor for key event
114 bool myIsActive; /// boolean state whether the event filter perform own signal processing
117 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
118 ModuleBase_IWorkshop* theWorkshop)
119 : QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
121 /// we need to install filter to the application in order to react to 'Delete' key button
122 /// this key can not be a short cut for a corresponded action because we need to set
123 /// the actions priority
124 myShortCutListener = new XGUI_ShortCutListener(theParent, this);
127 XGUI_OperationMgr::~XGUI_OperationMgr()
131 void XGUI_OperationMgr::activate()
133 myShortCutListener->setActive(true);
136 void XGUI_OperationMgr::deactivate()
138 myShortCutListener->setActive(false);
141 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
143 return myOperations.count() > 0 ? myOperations.last() : 0;
146 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
150 return currentOperation() == theOperation;
153 bool XGUI_OperationMgr::hasOperation() const
155 return !myOperations.isEmpty() && (myOperations.last() != NULL);
158 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
160 foreach(ModuleBase_Operation* aOp, myOperations) {
161 if (aOp->id() == theId)
167 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
169 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
170 while (anIt != myOperations.begin()) {
172 ModuleBase_Operation* anOperation = *anIt;
173 if (anOperation->id() == theId)
180 int XGUI_OperationMgr::operationsCount() const
182 return myOperations.count();
185 QStringList XGUI_OperationMgr::operationList() const
188 foreach(ModuleBase_Operation* eachOperation, myOperations) {
189 ModuleBase_OperationFeature* aFOperation =
190 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
192 FeaturePtr aFeature = aFOperation->feature();
194 result << QString::fromStdString(aFeature->getKind());
201 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
203 int idx = myOperations.lastIndexOf(theOperation);
204 if(idx == -1 || idx == 0) {
207 return myOperations.at(idx - 1);
210 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
212 ModuleBase_ModelWidget* anActiveWidget = 0;
213 ModuleBase_Operation* anOperation = currentOperation();
215 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
217 anActiveWidget = aPanel->activeWidget();
219 return anActiveWidget;
222 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
225 currentOperation()->postpone();
226 myOperations.append(theOperation);
228 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
229 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
230 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
232 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
233 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
234 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
236 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
237 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
239 bool isStarted = theOperation->start();
241 onValidateOperation();
245 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
251 if (operationsCount() == 1) {
252 ModuleBase_Operation* aCurrentOperation = currentOperation();
253 if (canStopOperation(aCurrentOperation, theMessageKind)) {
254 abortOperation(aCurrentOperation);
260 if (theMessageKind == XGUI_AbortOperationMessage) {
261 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
262 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
263 myActiveMessageBox = 0;
265 else if (theMessageKind == XGUI_InformationMessage) {
266 QString aMessage = tr("Please validate all your active operations before saving.");
267 myActiveMessageBox = createInformationBox(aMessage);
268 myActiveMessageBox->exec();
269 myActiveMessageBox = 0;
270 aResult = false; // do not perform abort
272 while(aResult && hasOperation()) {
273 abortOperation(currentOperation());
279 bool XGUI_OperationMgr::commitAllOperations()
281 bool isCompositeCommitted = false, anOperationProcessed = false;
282 while (hasOperation()) {
283 ModuleBase_Operation* anOperation = currentOperation();
284 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
285 anOperationProcessed = commitOperation();
287 abortOperation(anOperation);
288 anOperationProcessed = true;
290 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
293 FeaturePtr aFeature = aFOperation->feature();
294 CompositeFeaturePtr aComposite =
295 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
296 isCompositeCommitted = aComposite.get();
297 if (isCompositeCommitted)
300 // not processed[committed] operation might be used in composite feature,
301 // so the while will be stopped by the previous check.
302 // this code is not necessary, but logically should be done when the processing will not
303 // be done for not composite feature by some reasons
304 if (!anOperationProcessed)
310 void XGUI_OperationMgr::onValidateOperation()
314 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
315 (currentOperation());
316 if(aFOperation && aFOperation->feature().get())
317 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
320 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
322 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
324 ModuleBase_OperationFeature* aFOperation =
325 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
327 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
330 foreach(ModuleBase_Operation* anOperation, myOperations) {
332 updateApplyOfOperations(anOperation);
335 // Apply button of the current operation should also be updated
336 onValidateOperation();
339 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
340 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
342 //in case of nested (sketch) operation no confirmation needed
343 if (isGrantedOperation(theOperation->id()))
345 if (theOperation && theOperation->isModified()) {
346 if (theMessageKind == XGUI_AbortOperationMessage) {
347 QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
348 myActiveMessageBox = createMessageBox(aMessage);
349 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
350 myActiveMessageBox = 0;
353 else if (theMessageKind == XGUI_InformationMessage) {
354 QString aMessage = tr("Please validate your %1 before saving.").arg(theOperation->id());
355 myActiveMessageBox = createInformationBox(aMessage);
356 myActiveMessageBox->exec();
357 myActiveMessageBox = 0;
364 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
366 theOperation->resume();
369 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
371 bool isGranted = false;
373 QListIterator<ModuleBase_Operation*> anIt(myOperations);
375 ModuleBase_Operation* aPreviousOperation = 0;
376 while (anIt.hasPrevious() && !isGranted) {
377 ModuleBase_Operation* anOp = anIt.previous();
379 isGranted = anOp->isGranted(theId);
384 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
386 SessionPtr aMgr = ModelAPI_Session::get();
387 DocumentPtr aDoc = aMgr->activeDocument();
388 bool aIsOp = aMgr->isOperation();
390 aMgr->startOperation(QString("Set current feature: %1")
391 .arg(theFeature->getKind().c_str()).toStdString());
392 aDoc->setCurrentFeature(theFeature, false);
393 #ifdef DEBUG_CURRENT_FEATURE
394 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
395 ModuleBase_Tools::objectName(
396 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
400 aMgr->finishOperation();
403 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
405 bool aCanStart = true;
407 ModuleBase_Operation* aCurrentOp = currentOperation();
409 bool aGranted = aCurrentOp->isGranted(theId);
410 // the started operation is granted for the current one,
411 // e.g. current - Sketch, started - Line
416 if (!isGrantedOperation(theId)) {
417 // the operation is not granted in the current list of operations
418 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
419 aCanStart = abortAllOperations();
421 else if (canStopOperation(aCurrentOp)) {
422 // the started operation is granted in the parrent operation,
423 // e.g. current - Line in Sketch, started Circle
424 stopOperation(aCurrentOp, isCommitted);
433 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
435 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
436 theOperation->isModified()) {
437 isCommitted = theOperation->commit();
440 abortOperation(theOperation);
444 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
446 ModuleBase_Operation* aCurrentOperation = currentOperation();
447 if (theOperation == aCurrentOperation)
448 theOperation->abort();
450 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
451 // all operation from the current to triggered should also be aborted
452 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
453 while(hasOperation()) {
454 ModuleBase_Operation* aCurrentOperation = currentOperation();
455 aCurrentOperation->abort();
456 if(theOperation == aCurrentOperation)
462 bool XGUI_OperationMgr::commitOperation()
464 bool isCommitted = false;
465 ModuleBase_Operation* anOperation = currentOperation();
466 if (anOperation && myWorkshop->module()->canCommitOperation())
467 isCommitted = anOperation->commit();
471 void XGUI_OperationMgr::onAbortOperation()
473 ModuleBase_Operation* aCurrentOperation = currentOperation();
474 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
475 abortOperation(aCurrentOperation);
479 void XGUI_OperationMgr::onAbortAllOperation()
481 abortAllOperations();
484 void XGUI_OperationMgr::onBeforeOperationStarted()
486 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
487 if (!aCurrentOperation)
490 /// Set current feature and remeber old current feature
491 ModuleBase_OperationFeature* aFOperation =
492 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
494 SessionPtr aMgr = ModelAPI_Session::get();
495 DocumentPtr aDoc = aMgr->activeDocument();
496 // the parameter of current feature should be false, we should use all feature, not only
497 // visible in order to correctly save the previous feature of the nested operation, where the
498 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
499 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
500 // When sketch entity operation started, the sketch should be cashed here as the current.
501 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
502 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
503 // As a result the sketch disappears from the viewer.
504 // However after commit it is displayed back.
505 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
507 #ifdef DEBUG_CURRENT_FEATURE
508 FeaturePtr aFeature = aFOperation->feature();
509 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
511 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
512 .arg(aFOperation->isEditOperation())
513 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
514 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
515 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
518 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
519 // in create operation, the current feature is changed by addFeature()
520 aDoc->setCurrentFeature(aFOperation->feature(), false);
521 #ifdef DEBUG_CURRENT_FEATURE
522 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
523 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
525 // this is the only place where flushes must be called after setCurrentFeature for the
526 // current moment: after this the opertion is not finished, so, the ObjectBrowser
527 // state may be corrupted (issue #1457)
528 static Events_Loop* aLoop = Events_Loop::loop();
529 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
530 aLoop->flush(aCreateEvent);
531 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
532 aLoop->flush(aDeleteEvent);
537 void XGUI_OperationMgr::onOperationStarted()
539 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
540 updateApplyOfOperations(aSenderOperation);
541 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
542 aWorkshop->operationStarted(aSenderOperation);
545 void XGUI_OperationMgr::onBeforeOperationAborted()
547 onBeforeOperationCommitted();
550 void XGUI_OperationMgr::onOperationAborted()
552 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
553 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
554 aWorkshop->setStatusBarMessage("");
555 emit operationAborted(aSenderOperation);
558 void XGUI_OperationMgr::onBeforeOperationCommitted()
560 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
561 if (!aCurrentOperation)
564 /// Restore the previous current feature
565 ModuleBase_OperationFeature* aFOperation =
566 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
568 #ifdef DEBUG_CURRENT_FEATURE
569 QString aKind = aFOperation->feature()->getKind().c_str();
570 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
571 .arg(aFOperation->isEditOperation())
572 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
573 qDebug(QString(" document->currentFeature(false) = %1").arg(
574 ModuleBase_Tools::objectName(
575 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
576 .toStdString().c_str());
579 if (aFOperation->isEditOperation()) {
580 /// Restore the previous current feature
581 setCurrentFeature(aFOperation->previousCurrentFeature());
583 else { // create operation
584 // the Top created feature should stays the current. In nested operations,
585 // like Line in the Sketch or
586 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
587 // It is performed here
588 // in order to perform it in the current transaction without opening a new one.
589 if (myOperations.front() != aFOperation)
590 setCurrentFeature(aFOperation->previousCurrentFeature());
592 ModuleBase_IModule* aModule = myWorkshop->module();
594 aModule->beforeOperationStopped(aFOperation);
598 void XGUI_OperationMgr::onOperationCommitted()
600 // apply state for all features from the stack of operations should be updated
601 updateApplyOfOperations();
603 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
604 emit operationCommitted(aSenderOperation);
607 void XGUI_OperationMgr::onOperationResumed()
609 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
610 emit operationResumed(aSenderOperation);
613 void XGUI_OperationMgr::onOperationStopped()
615 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
616 ModuleBase_Operation* aCurrentOperation = currentOperation();
617 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
620 myOperations.removeAll(aCurrentOperation);
621 aCurrentOperation->deleteLater();
623 emit operationStopped(aCurrentOperation);
625 // get last operation which can be resumed
626 ModuleBase_Operation* aResultOp = 0;
627 QListIterator<ModuleBase_Operation*> anIt(myOperations);
629 while (anIt.hasPrevious()) {
630 ModuleBase_Operation* anOp = anIt.previous();
637 bool isModified = aCurrentOperation->isModified();
638 aResultOp->setIsModified(aResultOp->isModified() || isModified);
639 resumeOperation(aResultOp);
640 onValidateOperation();
644 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
646 // Let the manager decide what to do with the given key combination.
647 ModuleBase_Operation* anOperation = currentOperation();
648 bool isAccepted = false;
649 switch (theEvent->key()) {
651 case Qt::Key_Backtab:
653 ModuleBase_Operation* aOperation = currentOperation();
655 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
657 QWidget* aFocusedWidget = qApp->focusWidget();
658 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
659 if (!isPPChildObject) {
660 // check for case when the operation is started but property panel is not filled
661 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
662 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
670 case Qt::Key_Enter: {
671 isAccepted = onProcessEnter(theObject);
676 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
678 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
679 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
680 if (!aContext.IsNull()) {
681 Handle(V3d_View) aView = aViewer->activeView();
682 if ((theEvent->key() == Qt::Key_N))
683 aContext->HilightNextDetected(aView);
684 else if ((theEvent->key() == Qt::Key_P))
685 aContext->HilightPreviousDetected(aView);
696 // anOperation->keyReleased(theEvent->key());
701 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
703 // Let the manager decide what to do with the given key combination.
704 ModuleBase_Operation* anOperation = currentOperation();
705 bool isAccepted = false;
706 switch (theEvent->key()) {
707 case Qt::Key_Escape: {
708 // processing in message box
709 if (myActiveMessageBox)
711 myActiveMessageBox->reject();
714 // processing in the active widget
715 ModuleBase_Operation* aOperation = currentOperation();
716 if (!isAccepted && aOperation) {
717 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
718 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
721 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
723 ModuleBase_OperationFeature* aFOperation =
724 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
726 aFOperation->setNeedToBeAborted(true);
732 XGUI_ActiveControlSelector* anActiveSelector =
733 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
734 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
735 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
737 // default Escape button functionality
738 if (!isAccepted && aOperation) {
748 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
750 bool isAccepted = false;
751 ModuleBase_Operation* aOperation = currentOperation();
752 // to avoid enter processing when operation has not been started yet
755 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
758 // the next code is obsolete as we want to process Enter in property panel always
759 // only property panel enter is processed in order to do not process enter in application dialogs
760 //bool isPPChild = isChildObject(theObject, aPanel);
762 // return isAccepted;
764 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
765 bool isAborted = false;
767 QWidget* aFocusWidget = aPanel->focusWidget();
768 QToolButton* aCancelBtn =
769 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
770 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
771 abortOperation(aOperation);
777 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
780 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
782 /// functionality is similar to Apply click
783 ModuleBase_OperationFeature* aFOperation =
784 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
786 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
787 // key released is emitted to apply the current value to the model
788 // if it was modified in PP
789 emit keyEnterReleased();
801 bool editorControl(QObject* theObject)
803 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
807 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
809 bool isAccepted = false;
810 ModuleBase_Operation* aOperation = currentOperation();
811 ModuleBase_ModelWidget* anActiveWgt = 0;
812 // firstly the widget should process Delete action
813 ModuleBase_IPropertyPanel* aPanel;
814 bool isPPChildObject = false;
816 aPanel = aOperation->propertyPanel();
818 isPPChildObject = isChildObject(theObject, aPanel);
819 // process delete in active widget only if delete sender is child of property panel
820 // it is necessary for the case when OB is shown, user perform selection and click Delete
821 if (isPPChildObject) {
822 anActiveWgt = aPanel->activeWidget();
824 isAccepted = anActiveWgt->processAction(ActionDelete);
831 XGUI_ActiveControlSelector* anActiveSelector =
832 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
833 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
834 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
837 // after widget, object browser and viewer should process delete
838 /// other widgets such as line edit controls should not lead to
839 /// processing delete by workshop
840 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
841 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
842 bool isToDeleteObject = false;
843 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
844 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
845 if (theObject == aBrowser->treeView()) {
846 aContextMenuMgr->updateObjectBrowserMenu();
847 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
849 else if (isChildObject(theObject, aViewPort)) {
850 aContextMenuMgr->updateViewerMenu();
851 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
853 else if (isPPChildObject) {
854 // property panel child object is processed to process delete performed on Apply button of PP
855 isToDeleteObject = true;
857 else if (editorControl(theObject)) {
858 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
862 if (isToDeleteObject) {
863 aWorkshop->deleteObjects();
871 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
873 bool isPPChild = false;
874 if (theParent && theObject) {
875 QObject* aParent = (QObject*)theObject;
877 isPPChild = aParent == theParent;
880 aParent = aParent->parent();
886 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
888 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
889 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
890 qApp->activeWindow());
891 aMessageBox->setDefaultButton(QMessageBox::Cancel);
892 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
897 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
899 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
900 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
901 qApp->activeWindow());
902 aMessageBox->setDefaultButton(QMessageBox::Ok);
903 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key