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"
22 #include "XGUI_ModuleConnector.h"
23 #include "XGUI_Workshop.h"
24 #include "XGUI_ErrorMgr.h"
25 #include "XGUI_Tools.h"
26 #include "XGUI_ObjectsBrowser.h"
27 #include "XGUI_ContextMenuMgr.h"
29 #include <ModuleBase_IPropertyPanel.h>
30 #include <ModuleBase_ModelWidget.h>
31 #include "ModuleBase_Operation.h"
32 #include "ModuleBase_IWorkshop.h"
33 #include "ModuleBase_IModule.h"
34 #include <ModuleBase_IViewer.h>
35 #include "ModuleBase_OperationDescription.h"
36 #include "ModuleBase_OperationFeature.h"
37 #include "ModuleBase_Tools.h"
39 #include "ModelAPI_CompositeFeature.h"
40 #include "ModelAPI_Session.h"
42 #include <XGUI_PropertyPanel.h>
43 #include <QToolButton>
46 #include <QMessageBox>
47 #include <QApplication>
50 //#define DEBUG_CURRENT_FEATURE
52 /// Processes "Delete" key event of application. This key is used by several application actions.
53 /// There is a logical order of the actions processing. So the key can not be set for actions
54 /// as a shortcut. The class listens the key event and call operation manager processor.
55 class XGUI_ShortCutListener : public QObject
59 /// \param theParent the parent to be deleted when the parent is deleted
60 /// \param theOperationMgr the class to perform deletion
61 XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
62 : QObject(theParent), myOperationMgr(theOperationMgr)
64 qApp->installEventFilter(this);
66 ~XGUI_ShortCutListener() {}
68 /// Switch on short cut listener
69 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
71 /// Redefinition of virtual function to process Delete key release
72 virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
74 bool isAccepted = false;
76 if (theEvent->type() == QEvent::KeyRelease) {
77 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
79 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
80 switch (aKeyEvent->key()) {
82 isAccepted = myOperationMgr->onProcessDelete(theObject);
85 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
90 else if (theEvent->type() == QEvent::KeyPress) {
91 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
92 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
93 switch (aKeyEvent->key()) {
95 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
103 isAccepted = QObject::eventFilter(theObject, theEvent);
108 XGUI_OperationMgr* myOperationMgr; /// processor for key event
109 bool myIsActive; /// boolean state whether the event filter perform own signal processing
112 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
113 ModuleBase_IWorkshop* theWorkshop)
114 : QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
116 /// we need to install filter to the application in order to react to 'Delete' key button
117 /// this key can not be a short cut for a corresponded action because we need to set
118 /// the actions priority
119 myShortCutListener = new XGUI_ShortCutListener(theParent, this);
122 XGUI_OperationMgr::~XGUI_OperationMgr()
126 void XGUI_OperationMgr::activate()
128 myShortCutListener->setActive(true);
131 void XGUI_OperationMgr::deactivate()
133 myShortCutListener->setActive(false);
136 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
138 return myOperations.count() > 0 ? myOperations.last() : 0;
141 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
145 return currentOperation() == theOperation;
148 bool XGUI_OperationMgr::hasOperation() const
150 return !myOperations.isEmpty() && (myOperations.last() != NULL);
153 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
155 foreach(ModuleBase_Operation* aOp, myOperations) {
156 if (aOp->id() == theId)
162 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
164 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
165 while (anIt != myOperations.begin()) {
167 ModuleBase_Operation* anOperation = *anIt;
168 if (anOperation->id() == theId)
175 int XGUI_OperationMgr::operationsCount() const
177 return myOperations.count();
180 QStringList XGUI_OperationMgr::operationList() const
183 foreach(ModuleBase_Operation* eachOperation, myOperations) {
184 ModuleBase_OperationFeature* aFOperation =
185 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
187 FeaturePtr aFeature = aFOperation->feature();
189 result << QString::fromStdString(aFeature->getKind());
196 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
198 int idx = myOperations.lastIndexOf(theOperation);
199 if(idx == -1 || idx == 0) {
202 return myOperations.at(idx - 1);
205 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
208 currentOperation()->postpone();
209 myOperations.append(theOperation);
211 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
212 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
213 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
215 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
216 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
217 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
219 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
220 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
222 bool isStarted = theOperation->start();
224 onValidateOperation();
228 bool XGUI_OperationMgr::abortAllOperations()
234 if (operationsCount() == 1) {
235 ModuleBase_Operation* aCurrentOperation = currentOperation();
236 if (canStopOperation(aCurrentOperation)) {
237 abortOperation(aCurrentOperation);
243 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
244 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
245 myActiveMessageBox = 0;
246 while(aResult && hasOperation()) {
247 abortOperation(currentOperation());
253 bool XGUI_OperationMgr::commitAllOperations()
255 bool isCompositeCommitted = false, anOperationProcessed = false;
256 while (hasOperation()) {
257 ModuleBase_Operation* anOperation = currentOperation();
258 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
259 anOperationProcessed = onCommitOperation();
261 abortOperation(anOperation);
262 anOperationProcessed = true;
264 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
267 FeaturePtr aFeature = aFOperation->feature();
268 CompositeFeaturePtr aComposite =
269 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
270 isCompositeCommitted = aComposite.get();
271 if (isCompositeCommitted)
274 // not processed[committed] operation might be used in composite feature,
275 // so the while will be stopped by the previous check.
276 // this code is not necessary, but logically should be done when the processing will not
277 // be done for not composite feature by some reasons
278 if (!anOperationProcessed)
284 void XGUI_OperationMgr::onValidateOperation()
288 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
289 (currentOperation());
290 if(aFOperation && aFOperation->feature().get())
291 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
294 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
296 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
298 ModuleBase_OperationFeature* aFOperation =
299 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
301 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
304 foreach(ModuleBase_Operation* anOperation, myOperations) {
306 updateApplyOfOperations(anOperation);
309 // Apply button of the current operation should also be updated
310 onValidateOperation();
313 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
315 //in case of nested (sketch) operation no confirmation needed
316 if (isGrantedOperation(theOperation->id()))
318 if (theOperation && theOperation->isModified()) {
319 QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
321 myActiveMessageBox = createMessageBox(aMessage);
322 int anAnswer = myActiveMessageBox->exec() == QMessageBox::Ok;
323 myActiveMessageBox = 0;
329 bool XGUI_OperationMgr::commitOperation()
331 //if (hasOperation() && currentOperation()->isValid()) {
332 // onCommitOperation();
336 return onCommitOperation();
339 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
341 theOperation->resume();
344 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
346 bool isGranted = false;
348 QListIterator<ModuleBase_Operation*> anIt(myOperations);
350 ModuleBase_Operation* aPreviousOperation = 0;
351 while (anIt.hasPrevious() && !isGranted) {
352 ModuleBase_Operation* anOp = anIt.previous();
354 isGranted = anOp->isGranted(theId);
359 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
361 SessionPtr aMgr = ModelAPI_Session::get();
362 DocumentPtr aDoc = aMgr->activeDocument();
363 bool aIsOp = aMgr->isOperation();
365 aMgr->startOperation(QString("Set current feature: %1")
366 .arg(theFeature->getKind().c_str()).toStdString());
367 aDoc->setCurrentFeature(theFeature, false);
368 #ifdef DEBUG_CURRENT_FEATURE
369 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
370 ModuleBase_Tools::objectName(
371 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
375 aMgr->finishOperation();
378 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
380 bool aCanStart = true;
382 ModuleBase_Operation* aCurrentOp = currentOperation();
384 bool aGranted = aCurrentOp->isGranted(theId);
385 // the started operation is granted for the current one,
386 // e.g. current - Sketch, started - Line
391 if (!isGrantedOperation(theId)) {
392 // the operation is not granted in the current list of operations
393 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
394 aCanStart = abortAllOperations();
396 else if (canStopOperation(aCurrentOp)) {
397 // the started operation is granted in the parrent operation,
398 // e.g. current - Line in Sketch, started Circle
399 stopOperation(aCurrentOp, isCommitted);
408 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
410 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() && theOperation->isModified())
411 isCommitted = theOperation->commit();
414 abortOperation(theOperation);
418 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
420 ModuleBase_Operation* aCurrentOperation = currentOperation();
421 if (theOperation == aCurrentOperation)
422 theOperation->abort();
424 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
425 // all operation from the current to triggered should also be aborted
426 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
427 while(hasOperation()) {
428 ModuleBase_Operation* aCurrentOperation = currentOperation();
429 aCurrentOperation->abort();
430 if(theOperation == aCurrentOperation)
436 bool XGUI_OperationMgr::onCommitOperation()
438 bool isCommitted = false;
439 ModuleBase_Operation* anOperation = currentOperation();
440 if (anOperation && myWorkshop->module()->canCommitOperation())
441 isCommitted = anOperation->commit();
445 void XGUI_OperationMgr::onAbortOperation()
447 ModuleBase_Operation* aCurrentOperation = currentOperation();
448 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
449 abortOperation(aCurrentOperation);
453 void XGUI_OperationMgr::onBeforeOperationStarted()
455 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
456 if (!aCurrentOperation)
459 /// Set current feature and remeber old current feature
460 ModuleBase_OperationFeature* aFOperation =
461 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
463 SessionPtr aMgr = ModelAPI_Session::get();
464 DocumentPtr aDoc = aMgr->activeDocument();
465 // the parameter of current feature should be false, we should use all feature, not only
466 // visible in order to correctly save the previous feature of the nested operation, where the
467 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
468 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
469 // When sketch entity operation started, the sketch should be cashed here as the current.
470 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
471 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
472 // As a result the sketch disappears from the viewer.
473 // However after commit it is displayed back.
474 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
476 #ifdef DEBUG_CURRENT_FEATURE
477 FeaturePtr aFeature = aFOperation->feature();
478 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
480 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
481 .arg(aFOperation->isEditOperation())
482 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
483 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
484 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
487 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
488 // in create operation, the current feature is changed by addFeature()
489 aDoc->setCurrentFeature(aFOperation->feature(), false);
490 #ifdef DEBUG_CURRENT_FEATURE
491 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
492 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
494 // this is the only place where flushes must be called after setCurrentFeature for the
495 // current moment: after this the opertion is not finished, so, the ObjectBrowser
496 // state may be corrupted (issue #1457)
497 static Events_Loop* aLoop = Events_Loop::loop();
498 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
499 aLoop->flush(aCreateEvent);
500 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
501 aLoop->flush(aDeleteEvent);
506 void XGUI_OperationMgr::onOperationStarted()
508 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
509 updateApplyOfOperations(aSenderOperation);
510 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
511 aWorkshop->operationStarted(aSenderOperation);
514 void XGUI_OperationMgr::onBeforeOperationAborted()
516 onBeforeOperationCommitted();
519 void XGUI_OperationMgr::onOperationAborted()
521 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
522 emit operationAborted(aSenderOperation);
525 void XGUI_OperationMgr::onBeforeOperationCommitted()
527 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
528 if (!aCurrentOperation)
531 /// Restore the previous current feature
532 ModuleBase_OperationFeature* aFOperation =
533 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
535 #ifdef DEBUG_CURRENT_FEATURE
536 QString aKind = aFOperation->feature()->getKind().c_str();
537 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
538 .arg(aFOperation->isEditOperation())
539 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
540 qDebug(QString(" document->currentFeature(false) = %1").arg(
541 ModuleBase_Tools::objectName(
542 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
543 .toStdString().c_str());
546 if (aFOperation->isEditOperation()) {
547 /// Restore the previous current feature
548 setCurrentFeature(aFOperation->previousCurrentFeature());
550 else { // create operation
551 // the Top created feature should stays the current. In nested operations,
552 // like Line in the Sketch or
553 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
554 // It is performed here
555 // in order to perform it in the current transaction without opening a new one.
556 if (myOperations.front() != aFOperation)
557 setCurrentFeature(aFOperation->previousCurrentFeature());
559 ModuleBase_IModule* aModule = myWorkshop->module();
561 aModule->beforeOperationStopped(aFOperation);
565 void XGUI_OperationMgr::onOperationCommitted()
567 // apply state for all features from the stack of operations should be updated
568 updateApplyOfOperations();
570 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
571 emit operationCommitted(aSenderOperation);
574 void XGUI_OperationMgr::onOperationResumed()
576 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
577 emit operationResumed(aSenderOperation);
580 void XGUI_OperationMgr::onOperationStopped()
582 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
583 ModuleBase_Operation* aCurrentOperation = currentOperation();
584 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
587 myOperations.removeAll(aCurrentOperation);
588 aCurrentOperation->deleteLater();
590 emit operationStopped(aCurrentOperation);
592 // get last operation which can be resumed
593 ModuleBase_Operation* aResultOp = 0;
594 QListIterator<ModuleBase_Operation*> anIt(myOperations);
596 while (anIt.hasPrevious()) {
597 ModuleBase_Operation* anOp = anIt.previous();
604 bool isModified = aCurrentOperation->isModified();
605 aResultOp->setIsModified(aResultOp->isModified() || isModified);
606 resumeOperation(aResultOp);
607 onValidateOperation();
611 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
613 // Let the manager decide what to do with the given key combination.
614 ModuleBase_Operation* anOperation = currentOperation();
615 bool isAccepted = false;
616 switch (theEvent->key()) {
618 case Qt::Key_Backtab:
620 ModuleBase_Operation* aOperation = currentOperation();
622 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
624 QWidget* aFocusedWidget = qApp->focusWidget();
625 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
626 if (!isPPChildObject) {
627 // check for case when the operation is started but property panel is not filled
628 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
629 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
637 case Qt::Key_Enter: {
638 isAccepted = onProcessEnter(theObject);
643 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
645 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
646 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
647 if (!aContext.IsNull()) {
648 Handle(V3d_View) aView = aViewer->activeView();
649 if ((theEvent->key() == Qt::Key_N))
650 aContext->HilightNextDetected(aView);
651 else if ((theEvent->key() == Qt::Key_P))
652 aContext->HilightPreviousDetected(aView);
663 // anOperation->keyReleased(theEvent->key());
668 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
670 // Let the manager decide what to do with the given key combination.
671 ModuleBase_Operation* anOperation = currentOperation();
672 bool isAccepted = false;
673 switch (theEvent->key()) {
674 case Qt::Key_Escape: {
675 // processing in message box
676 if (myActiveMessageBox)
678 myActiveMessageBox->reject();
681 // processing in the active widget
682 ModuleBase_Operation* aOperation = currentOperation();
683 if (!isAccepted && aOperation) {
684 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
685 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
687 isAccepted = anActiveWgt && anActiveWgt->processEscape();
689 // default Escape button functionality
690 if (!isAccepted && aOperation) {
700 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
702 bool isAccepted = false;
703 ModuleBase_Operation* aOperation = currentOperation();
704 // to avoid enter processing when operation has not been started yet
707 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
708 // the next code is obsolete as we want to process Enter in property panel always
709 // only property panel enter is processed in order to do not process enter in application dialogs
710 //bool isPPChild = isChildObject(theObject, aPanel);
712 // return isAccepted;
714 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
715 bool isAborted = false;
717 QWidget* aFocusWidget = aPanel->focusWidget();
718 QToolButton* aCancelBtn =
719 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
720 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
721 abortOperation(aOperation);
727 isAccepted = anActiveWgt && anActiveWgt->processEnter();
730 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
732 /// functionality is similar to Apply click
733 ModuleBase_OperationFeature* aFOperation =
734 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
736 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
737 // key released is emitted to apply the current value to the model
738 // if it was modified in PP
739 emit keyEnterReleased();
751 bool editorControl(QObject* theObject)
753 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
757 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
759 bool isAccepted = false;
760 ModuleBase_Operation* aOperation = currentOperation();
761 ModuleBase_ModelWidget* anActiveWgt = 0;
762 // firstly the widget should process Delete action
763 ModuleBase_IPropertyPanel* aPanel;
764 bool isPPChildObject = false;
766 aPanel = aOperation->propertyPanel();
768 isPPChildObject = isChildObject(theObject, aPanel);
769 // process delete in active widget only if delete sender is child of property panel
770 // it is necessary for the case when OB is shown, user perform selection and click Delete
771 if (isPPChildObject) {
772 anActiveWgt = aPanel->activeWidget();
774 isAccepted = anActiveWgt->processDelete();
780 // after widget, object browser and viewer should process delete
781 /// other widgets such as line edit controls should not lead to
782 /// processing delete by workshop
783 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
784 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
785 bool isToDeleteObject = false;
786 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
787 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
788 if (theObject == aBrowser->treeView()) {
789 aContextMenuMgr->updateObjectBrowserMenu();
790 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
792 else if (isChildObject(theObject, aViewPort)) {
793 aContextMenuMgr->updateViewerMenu();
794 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
796 else if (isPPChildObject) {
797 // property panel child object is processed to process delete performed on Apply button of PP
798 isToDeleteObject = true;
800 else if (editorControl(theObject)) {
801 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
805 if (isToDeleteObject) {
806 aWorkshop->deleteObjects();
814 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
816 bool isPPChild = false;
817 if (theParent && theObject) {
818 QObject* aParent = (QObject*)theObject;
820 isPPChild = aParent == theParent;
823 aParent = aParent->parent();
829 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
831 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
832 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
833 qApp->activeWindow());
834 aMessageBox->setDefaultButton(QMessageBox::Cancel);
835 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key