1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XGUI_OperationMgr.h"
22 #include "XGUI_ActiveControlMgr.h"
23 #include "XGUI_ActiveControlSelector.h"
24 #include "XGUI_FacesPanelSelector.h"
25 #include "XGUI_ModuleConnector.h"
26 #include "XGUI_Workshop.h"
27 #include "XGUI_ErrorMgr.h"
28 #include "XGUI_FacesPanel.h"
29 #include "XGUI_Tools.h"
30 #include "XGUI_ObjectsBrowser.h"
31 #include "XGUI_ContextMenuMgr.h"
33 #include <ModuleBase_IPropertyPanel.h>
34 #include <ModuleBase_ModelWidget.h>
35 #include "ModuleBase_Operation.h"
36 #include "ModuleBase_IWorkshop.h"
37 #include "ModuleBase_IModule.h"
38 #include <ModuleBase_IViewer.h>
39 #include "ModuleBase_OperationDescription.h"
40 #include "ModuleBase_OperationFeature.h"
41 #include "ModuleBase_Tools.h"
43 #include <Config_Translator.h>
45 #include <ModelAPI_CompositeFeature.h>
46 #include <ModelAPI_Session.h>
48 #include <XGUI_PropertyPanel.h>
49 #include <QToolButton>
52 #include <QMessageBox>
53 #include <QApplication>
57 //#define DEBUG_CURRENT_FEATURE
59 /// Processes "Delete" key event of application. This key is used by several application actions.
60 /// There is a logical order of the actions processing. So the key can not be set for actions
61 /// as a shortcut. The class listens the key event and call operation manager processor.
62 class XGUI_ShortCutListener : public QObject
66 /// \param theParent the parent to be deleted when the parent is deleted
67 /// \param theOperationMgr the class to perform deletion
68 XGUI_ShortCutListener(XGUI_OperationMgr* theOperationMgr)
69 : QObject(theOperationMgr), myOperationMgr(theOperationMgr), myIsActive(false)
71 qApp->installEventFilter(this);
73 ~XGUI_ShortCutListener() {}
75 /// Switch on short cut listener
76 void setActive(const bool theIsActive) { myIsActive = theIsActive; }
78 /// Redefinition of virtual function to process Delete key release
79 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
82 XGUI_OperationMgr* myOperationMgr; /// processor for key event
83 bool myIsActive; /// boolean state whether the event filter perform own signal processing
86 bool XGUI_ShortCutListener::eventFilter(QObject *theObject, QEvent *theEvent)
88 bool isAccepted = false;
91 // Do not process keys for modal dialogues: all keys has to be processed within the dialog
92 // There is only one exception: ModuleBase_EditorDialog
93 QWindow* aWnd = qApp->modalWindow();
94 QString aName = "NoModal";
96 if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
97 aName = aWnd->objectName();
99 if (aName == "NoModal") {
100 if (theEvent->type() == QEvent::KeyRelease) {
101 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
103 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
104 switch (aKeyEvent->key()) {
106 isAccepted = myOperationMgr->onProcessDelete(theObject);
109 myOperationMgr->xworkshop()->objectBrowser()->onEditItem();
113 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
118 else if (theEvent->type() == QEvent::KeyPress) {
119 if (myOperationMgr->hasOperation()) {
120 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
121 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
122 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
128 isAccepted = QObject::eventFilter(theObject, theEvent);
134 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
135 ModuleBase_IWorkshop* theWorkshop)
136 : QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
138 /// we need to install filter to the application in order to react to 'Delete' key button
139 /// this key can not be a short cut for a corresponded action because we need to set
140 /// the actions priority
141 myShortCutListener = new XGUI_ShortCutListener(this);
144 XGUI_OperationMgr::~XGUI_OperationMgr()
148 void XGUI_OperationMgr::activate()
150 myShortCutListener->setActive(true);
153 void XGUI_OperationMgr::deactivate()
155 myShortCutListener->setActive(false);
158 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
160 return myOperations.count() > 0 ? myOperations.last() : 0;
163 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
167 return currentOperation() == theOperation;
170 bool XGUI_OperationMgr::hasOperation() const
172 return !myOperations.isEmpty() && (myOperations.last() != NULL);
175 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
177 foreach(ModuleBase_Operation* aOp, myOperations) {
178 if (aOp->id() == theId)
184 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
186 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
187 while (anIt != myOperations.begin()) {
189 ModuleBase_Operation* anOperation = *anIt;
190 if (anOperation->id() == theId)
197 int XGUI_OperationMgr::operationsCount() const
199 return myOperations.count();
202 QStringList XGUI_OperationMgr::operationList() const
205 foreach(ModuleBase_Operation* eachOperation, myOperations) {
206 ModuleBase_OperationFeature* aFOperation =
207 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
209 FeaturePtr aFeature = aFOperation->feature();
211 result << QString::fromStdString(aFeature->getKind());
218 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
220 int idx = myOperations.lastIndexOf(theOperation);
221 if(idx == -1 || idx == 0) {
224 return myOperations.at(idx - 1);
227 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
229 ModuleBase_ModelWidget* anActiveWidget = 0;
230 ModuleBase_Operation* anOperation = currentOperation();
232 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
234 anActiveWidget = aPanel->activeWidget();
236 return anActiveWidget;
239 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
242 currentOperation()->postpone();
243 myOperations.append(theOperation);
245 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
246 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
247 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
249 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
250 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
251 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
253 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
254 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
256 bool isStarted = theOperation->start();
258 onValidateOperation();
262 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
268 if (operationsCount() == 1) {
269 ModuleBase_Operation* aCurrentOperation = currentOperation();
270 if (canStopOperation(aCurrentOperation, theMessageKind)) {
271 abortOperation(aCurrentOperation);
277 if (theMessageKind == XGUI_AbortOperationMessage) {
278 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
279 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
280 myActiveMessageBox = 0;
282 else if (theMessageKind == XGUI_InformationMessage) {
283 QString aMessage = tr("Please validate all your active operations before saving.");
284 myActiveMessageBox = createInformationBox(aMessage);
285 myActiveMessageBox->exec();
286 myActiveMessageBox = 0;
287 aResult = false; // do not perform abort
289 while(aResult && hasOperation()) {
290 abortOperation(currentOperation());
296 bool XGUI_OperationMgr::commitAllOperations()
298 bool isCompositeCommitted = false, anOperationProcessed = false;
299 while (hasOperation()) {
300 ModuleBase_Operation* anOperation = currentOperation();
301 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
302 anOperationProcessed = commitOperation();
304 abortOperation(anOperation);
305 anOperationProcessed = true;
307 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
310 FeaturePtr aFeature = aFOperation->feature();
311 CompositeFeaturePtr aComposite =
312 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
313 isCompositeCommitted = aComposite.get();
314 if (isCompositeCommitted)
317 // not processed[committed] operation might be used in composite feature,
318 // so the while will be stopped by the previous check.
319 // this code is not necessary, but logically should be done when the processing will not
320 // be done for not composite feature by some reasons
321 if (!anOperationProcessed)
327 void XGUI_OperationMgr::onValidateOperation()
331 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
332 (currentOperation());
333 if(aFOperation && aFOperation->feature().get())
334 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
337 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
339 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
341 ModuleBase_OperationFeature* aFOperation =
342 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
344 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
347 foreach(ModuleBase_Operation* anOperation, myOperations) {
349 updateApplyOfOperations(anOperation);
352 // Apply button of the current operation should also be updated
353 onValidateOperation();
356 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
357 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
359 //in case of nested (sketch) operation no confirmation needed
360 if (isGrantedOperation(theOperation->id()))
362 if (theOperation && theOperation->isModified()) {
363 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
364 std::string aContext;
366 aContext = aOp->feature()->getKind();
367 QString aTitle = Config_Translator::translate(aContext,
368 theOperation->getDescription()->description().toStdString()).c_str();
370 if (theMessageKind == XGUI_AbortOperationMessage) {
371 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
372 myActiveMessageBox = createMessageBox(aMessage);
373 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
374 myActiveMessageBox = 0;
377 else if (theMessageKind == XGUI_InformationMessage) {
378 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
379 myActiveMessageBox = createInformationBox(aMessage);
380 myActiveMessageBox->exec();
381 myActiveMessageBox = 0;
388 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
390 theOperation->resume();
393 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
395 bool isGranted = false;
397 QListIterator<ModuleBase_Operation*> anIt(myOperations);
399 ModuleBase_Operation* aPreviousOperation = 0;
400 while (anIt.hasPrevious() && !isGranted) {
401 ModuleBase_Operation* anOp = anIt.previous();
403 isGranted = anOp->isGranted(theId);
408 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
410 SessionPtr aMgr = ModelAPI_Session::get();
411 DocumentPtr aDoc = aMgr->activeDocument();
412 bool aIsOp = aMgr->isOperation();
414 aMgr->startOperation(QString("Set current feature: %1")
415 .arg(theFeature->getKind().c_str()).toStdString());
416 aDoc->setCurrentFeature(theFeature, false);
417 #ifdef DEBUG_CURRENT_FEATURE
418 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
419 ModuleBase_Tools::objectName(
420 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
424 aMgr->finishOperation();
427 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
429 bool aCanStart = true;
431 ModuleBase_Operation* aCurrentOp = currentOperation();
433 bool aGranted = aCurrentOp->isGranted(theId);
434 // the started operation is granted for the current one,
435 // e.g. current - Sketch, started - Line
440 if (!isGrantedOperation(theId)) {
441 // the operation is not granted in the current list of operations
442 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
443 aCanStart = abortAllOperations();
445 else if (canStopOperation(aCurrentOp)) {
446 // the started operation is granted in the parrent operation,
447 // e.g. current - Line in Sketch, started Circle
448 stopOperation(aCurrentOp, isCommitted);
457 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
459 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
460 theOperation->isModified()) {
461 isCommitted = theOperation->commit();
464 abortOperation(theOperation);
468 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
470 ModuleBase_Operation* aCurrentOperation = currentOperation();
471 if (theOperation && (theOperation == aCurrentOperation))
472 theOperation->abort();
474 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
475 // all operation from the current to triggered should also be aborted
476 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
477 while(hasOperation()) {
478 ModuleBase_Operation* aCurrentOperation = currentOperation();
479 aCurrentOperation->abort();
480 if(theOperation == aCurrentOperation)
486 bool XGUI_OperationMgr::commitOperation()
488 bool isCommitted = false;
489 ModuleBase_Operation* anOperation = currentOperation();
490 if (anOperation && myWorkshop->module()->canCommitOperation())
491 isCommitted = anOperation->commit();
495 void XGUI_OperationMgr::onAbortOperation()
497 ModuleBase_Operation* aCurrentOperation = currentOperation();
498 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
499 abortOperation(aCurrentOperation);
503 void XGUI_OperationMgr::onAbortAllOperation()
505 abortAllOperations();
508 void XGUI_OperationMgr::onBeforeOperationStarted()
510 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
511 if (!aCurrentOperation)
514 /// Set current feature and remeber old current feature
515 ModuleBase_OperationFeature* aFOperation =
516 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
518 SessionPtr aMgr = ModelAPI_Session::get();
519 DocumentPtr aDoc = aMgr->activeDocument();
520 // the parameter of current feature should be false, we should use all feature, not only
521 // visible in order to correctly save the previous feature of the nested operation, where the
522 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
523 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
524 // When sketch entity operation started, the sketch should be cashed here as the current.
525 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
526 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
527 // As a result the sketch disappears from the viewer.
528 // However after commit it is displayed back.
529 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
531 #ifdef DEBUG_CURRENT_FEATURE
532 FeaturePtr aFeature = aFOperation->feature();
533 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
535 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
536 .arg(aFOperation->isEditOperation())
537 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
538 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
539 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
542 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
543 // in create operation, the current feature is changed by addFeature()
544 aDoc->setCurrentFeature(aFOperation->feature(), false);
545 #ifdef DEBUG_CURRENT_FEATURE
546 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
547 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
549 // this is the only place where flushes must be called after setCurrentFeature for the
550 // current moment: after this the opertion is not finished, so, the ObjectBrowser
551 // state may be corrupted (issue #1457)
552 static Events_Loop* aLoop = Events_Loop::loop();
553 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
554 aLoop->flush(aCreateEvent);
555 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
556 aLoop->flush(aDeleteEvent);
561 void XGUI_OperationMgr::onOperationStarted()
563 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
564 updateApplyOfOperations(aSenderOperation);
565 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
566 aWorkshop->operationStarted(aSenderOperation);
569 void XGUI_OperationMgr::onBeforeOperationAborted()
571 onBeforeOperationCommitted();
574 void XGUI_OperationMgr::onOperationAborted()
576 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
577 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
578 aWorkshop->setStatusBarMessage("");
579 emit operationAborted(aSenderOperation);
582 void XGUI_OperationMgr::onBeforeOperationCommitted()
584 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
585 if (!aCurrentOperation)
588 /// Restore the previous current feature
589 ModuleBase_OperationFeature* aFOperation =
590 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
592 #ifdef DEBUG_CURRENT_FEATURE
593 QString aKind = aFOperation->feature()->getKind().c_str();
594 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
595 .arg(aFOperation->isEditOperation())
596 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
597 qDebug(QString(" document->currentFeature(false) = %1").arg(
598 ModuleBase_Tools::objectName(
599 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
600 .toStdString().c_str());
603 if (aFOperation->isEditOperation()) {
604 /// Restore the previous current feature
605 setCurrentFeature(aFOperation->previousCurrentFeature());
607 else { // create operation
608 // the Top created feature should stays the current. In nested operations,
609 // like Line in the Sketch or
610 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
611 // It is performed here
612 // in order to perform it in the current transaction without opening a new one.
613 if (myOperations.front() != aFOperation)
614 setCurrentFeature(aFOperation->previousCurrentFeature());
616 ModuleBase_IModule* aModule = myWorkshop->module();
618 aModule->beforeOperationStopped(aFOperation);
622 void XGUI_OperationMgr::onOperationCommitted()
624 // apply state for all features from the stack of operations should be updated
625 updateApplyOfOperations();
627 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
628 emit operationCommitted(aSenderOperation);
631 void XGUI_OperationMgr::onOperationResumed()
633 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
634 emit operationResumed(aSenderOperation);
637 void XGUI_OperationMgr::onOperationStopped()
639 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
640 ModuleBase_Operation* aCurrentOperation = currentOperation();
641 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
644 myOperations.removeAll(aCurrentOperation);
645 aCurrentOperation->deleteLater();
647 emit operationStopped(aCurrentOperation);
649 // get last operation which can be resumed
650 ModuleBase_Operation* aResultOp = 0;
651 QListIterator<ModuleBase_Operation*> anIt(myOperations);
653 while (anIt.hasPrevious()) {
654 ModuleBase_Operation* anOp = anIt.previous();
661 //bool isModified = aCurrentOperation->isModified();
662 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
663 resumeOperation(aResultOp);
664 onValidateOperation();
668 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
670 bool isAccepted = false;
672 // Let the manager decide what to do with the given key combination.
673 ModuleBase_Operation* anOperation = currentOperation();
674 switch (theEvent->key()) {
676 case Qt::Key_Backtab:
678 ModuleBase_Operation* aOperation = currentOperation();
680 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
682 QWidget* aFocusedWidget = qApp->focusWidget();
683 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
684 if (!isPPChildObject) {
685 // check for case when the operation is started but property panel is not filled
686 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
687 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
695 case Qt::Key_Enter: {
696 isAccepted = onProcessEnter(theObject);
701 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
703 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
704 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
705 if (!aContext.IsNull()) {
706 Handle(V3d_View) aView = aViewer->activeView();
707 if ((theEvent->key() == Qt::Key_N))
708 aContext->HilightNextDetected(aView);
709 else if ((theEvent->key() == Qt::Key_P))
710 aContext->HilightPreviousDetected(aView);
711 aViewer->updateHighlight();
718 if ((theEvent->modifiers() == Qt::NoModifier))
719 myWorkshop->viewer()->hideSelectionHighlight();
726 // anOperation->keyReleased(theEvent->key());
731 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
733 // Let the manager decide what to do with the given key combination.
734 ModuleBase_Operation* anOperation = currentOperation();
735 bool isAccepted = false;
736 switch (theEvent->key()) {
737 case Qt::Key_Escape: {
738 // processing in message box
739 if (myActiveMessageBox)
741 myActiveMessageBox->reject();
744 // processing in the active widget
745 ModuleBase_Operation* aOperation = currentOperation();
746 if (!isAccepted && aOperation) {
747 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
749 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
752 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
754 ModuleBase_OperationFeature* aFOperation =
755 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
757 aFOperation->setNeedToBeAborted(true);
764 XGUI_ActiveControlSelector* anActiveSelector =
765 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
766 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
767 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
769 // default Escape button functionality
770 if (!isAccepted && aOperation) {
777 if ((theEvent->modifiers() == Qt::NoModifier))
778 myWorkshop->viewer()->showSelectionHighlight();
784 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
786 bool isAccepted = false;
787 ModuleBase_Operation* aOperation = currentOperation();
788 // to avoid enter processing when operation has not been started yet
791 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
794 // the next code is obsolete as we want to process Enter in property panel always
795 // only property panel enter is processed in order to do not process enter in application dialogs
796 //bool isPPChild = isChildObject(theObject, aPanel);
798 // return isAccepted;
800 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
801 bool isAborted = false;
803 QWidget* aFocusWidget = aPanel->focusWidget();
804 QToolButton* aCancelBtn =
805 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
806 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
807 abortOperation(aOperation);
813 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
816 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
818 /// functionality is similar to Apply click
819 ModuleBase_OperationFeature* aFOperation =
820 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
822 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
823 // key released is emitted to apply the current value to the model
824 // if it was modified in PP
825 emit keyEnterReleased();
837 bool editorControl(QObject* theObject)
839 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
843 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
845 bool isAccepted = false;
846 ModuleBase_Operation* aOperation = currentOperation();
847 ModuleBase_ModelWidget* anActiveWgt = 0;
848 // firstly the widget should process Delete action
849 ModuleBase_IPropertyPanel* aPanel;
850 bool isPPChildObject = false;
852 aPanel = aOperation->propertyPanel();
854 isPPChildObject = isChildObject(theObject, aPanel);
855 // process delete in active widget only if delete sender is child of property panel
856 // it is necessary for the case when OB is shown, user perform selection and click Delete
857 if (isPPChildObject) {
858 anActiveWgt = aPanel->activeWidget();
860 isAccepted = anActiveWgt->processAction(ActionDelete);
867 XGUI_ActiveControlSelector* anActiveSelector =
868 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
869 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
870 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
873 // after widget, object browser and viewer should process delete
874 /// other widgets such as line edit controls should not lead to
875 /// processing delete by workshop
876 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
877 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
878 bool isToDeleteObject = false;
879 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
880 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
881 if (theObject == aBrowser->treeView()) {
882 aContextMenuMgr->updateObjectBrowserMenu();
883 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
885 else if (isChildObject(theObject, aViewPort)) {
886 aContextMenuMgr->updateViewerMenu();
887 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
889 else if (isPPChildObject) {
890 // property panel child object is processed to process delete performed on Apply button of PP
891 isToDeleteObject = true;
893 else if (editorControl(theObject)) {
894 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
898 if (isToDeleteObject) {
899 aWorkshop->deleteObjects();
907 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
909 bool isPPChild = false;
910 if (theParent && theObject) {
911 QObject* aParent = (QObject*)theObject;
913 isPPChild = aParent == theParent;
916 aParent = aParent->parent();
922 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
924 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
925 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
926 qApp->activeWindow());
927 aMessageBox->setDefaultButton(QMessageBox::Cancel);
928 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
933 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
935 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
936 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
937 qApp->activeWindow());
938 aMessageBox->setDefaultButton(QMessageBox::Ok);
939 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
944 XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
946 XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
947 return aConnector->workshop();