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(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
69 : QObject(theParent), 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)
81 bool isAccepted = false;
84 // Do not process keys for modal dialogues: all keys has to be processed within the dialog
85 // There is only one exception: ModuleBase_EditorDialog
86 QWindow* aWnd = qApp->modalWindow();
87 QString aName = "NoModal";
89 if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
90 aName = aWnd->objectName();
92 if (aName == "NoModal") {
93 if (theEvent->type() == QEvent::KeyRelease) {
94 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
96 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
97 switch (aKeyEvent->key()) {
99 isAccepted = myOperationMgr->onProcessDelete(theObject);
102 isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
107 else if (theEvent->type() == QEvent::KeyPress) {
108 if (myOperationMgr->hasOperation()) {
109 QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
110 myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
111 isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
117 isAccepted = QObject::eventFilter(theObject, theEvent);
122 XGUI_OperationMgr* myOperationMgr; /// processor for key event
123 bool myIsActive; /// boolean state whether the event filter perform own signal processing
126 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
127 ModuleBase_IWorkshop* theWorkshop)
128 : QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
130 /// we need to install filter to the application in order to react to 'Delete' key button
131 /// this key can not be a short cut for a corresponded action because we need to set
132 /// the actions priority
133 myShortCutListener = new XGUI_ShortCutListener(theParent, this);
136 XGUI_OperationMgr::~XGUI_OperationMgr()
140 void XGUI_OperationMgr::activate()
142 myShortCutListener->setActive(true);
145 void XGUI_OperationMgr::deactivate()
147 myShortCutListener->setActive(false);
150 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
152 return myOperations.count() > 0 ? myOperations.last() : 0;
155 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
159 return currentOperation() == theOperation;
162 bool XGUI_OperationMgr::hasOperation() const
164 return !myOperations.isEmpty() && (myOperations.last() != NULL);
167 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
169 foreach(ModuleBase_Operation* aOp, myOperations) {
170 if (aOp->id() == theId)
176 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
178 QList<ModuleBase_Operation*>::const_iterator anIt = myOperations.end();
179 while (anIt != myOperations.begin()) {
181 ModuleBase_Operation* anOperation = *anIt;
182 if (anOperation->id() == theId)
189 int XGUI_OperationMgr::operationsCount() const
191 return myOperations.count();
194 QStringList XGUI_OperationMgr::operationList() const
197 foreach(ModuleBase_Operation* eachOperation, myOperations) {
198 ModuleBase_OperationFeature* aFOperation =
199 dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
201 FeaturePtr aFeature = aFOperation->feature();
203 result << QString::fromStdString(aFeature->getKind());
210 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
212 int idx = myOperations.lastIndexOf(theOperation);
213 if(idx == -1 || idx == 0) {
216 return myOperations.at(idx - 1);
219 ModuleBase_ModelWidget* XGUI_OperationMgr::activeWidget() const
221 ModuleBase_ModelWidget* anActiveWidget = 0;
222 ModuleBase_Operation* anOperation = currentOperation();
224 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
226 anActiveWidget = aPanel->activeWidget();
228 return anActiveWidget;
231 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
234 currentOperation()->postpone();
235 myOperations.append(theOperation);
237 connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
238 connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
239 connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
241 connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
242 connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
243 connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
245 connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
246 connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
248 bool isStarted = theOperation->start();
250 onValidateOperation();
254 bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
260 if (operationsCount() == 1) {
261 ModuleBase_Operation* aCurrentOperation = currentOperation();
262 if (canStopOperation(aCurrentOperation, theMessageKind)) {
263 abortOperation(aCurrentOperation);
269 if (theMessageKind == XGUI_AbortOperationMessage) {
270 myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
271 aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
272 myActiveMessageBox = 0;
274 else if (theMessageKind == XGUI_InformationMessage) {
275 QString aMessage = tr("Please validate all your active operations before saving.");
276 myActiveMessageBox = createInformationBox(aMessage);
277 myActiveMessageBox->exec();
278 myActiveMessageBox = 0;
279 aResult = false; // do not perform abort
281 while(aResult && hasOperation()) {
282 abortOperation(currentOperation());
288 bool XGUI_OperationMgr::commitAllOperations()
290 bool isCompositeCommitted = false, anOperationProcessed = false;
291 while (hasOperation()) {
292 ModuleBase_Operation* anOperation = currentOperation();
293 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
294 anOperationProcessed = commitOperation();
296 abortOperation(anOperation);
297 anOperationProcessed = true;
299 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
302 FeaturePtr aFeature = aFOperation->feature();
303 CompositeFeaturePtr aComposite =
304 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
305 isCompositeCommitted = aComposite.get();
306 if (isCompositeCommitted)
309 // not processed[committed] operation might be used in composite feature,
310 // so the while will be stopped by the previous check.
311 // this code is not necessary, but logically should be done when the processing will not
312 // be done for not composite feature by some reasons
313 if (!anOperationProcessed)
319 void XGUI_OperationMgr::onValidateOperation()
323 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
324 (currentOperation());
325 if(aFOperation && aFOperation->feature().get())
326 XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
329 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
331 XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
333 ModuleBase_OperationFeature* aFOperation =
334 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
336 anErrorMgr->updateAcceptAllAction(aFOperation->feature());
339 foreach(ModuleBase_Operation* anOperation, myOperations) {
341 updateApplyOfOperations(anOperation);
344 // Apply button of the current operation should also be updated
345 onValidateOperation();
348 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
349 const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
351 //in case of nested (sketch) operation no confirmation needed
352 if (isGrantedOperation(theOperation->id()))
354 if (theOperation && theOperation->isModified()) {
355 ModuleBase_OperationFeature* aOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
356 std::string aContext;
358 aContext = aOp->feature()->getKind();
359 QString aTitle = Config_Translator::translate(aContext,
360 theOperation->getDescription()->description().toStdString()).c_str();
362 if (theMessageKind == XGUI_AbortOperationMessage) {
363 QString aMessage = tr("%1 operation will be aborted.").arg(aTitle);
364 myActiveMessageBox = createMessageBox(aMessage);
365 bool aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
366 myActiveMessageBox = 0;
369 else if (theMessageKind == XGUI_InformationMessage) {
370 QString aMessage = tr("Please validate your %1 before saving.").arg(aTitle);
371 myActiveMessageBox = createInformationBox(aMessage);
372 myActiveMessageBox->exec();
373 myActiveMessageBox = 0;
380 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
382 theOperation->resume();
385 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
387 bool isGranted = false;
389 QListIterator<ModuleBase_Operation*> anIt(myOperations);
391 ModuleBase_Operation* aPreviousOperation = 0;
392 while (anIt.hasPrevious() && !isGranted) {
393 ModuleBase_Operation* anOp = anIt.previous();
395 isGranted = anOp->isGranted(theId);
400 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
402 SessionPtr aMgr = ModelAPI_Session::get();
403 DocumentPtr aDoc = aMgr->activeDocument();
404 bool aIsOp = aMgr->isOperation();
406 aMgr->startOperation(QString("Set current feature: %1")
407 .arg(theFeature->getKind().c_str()).toStdString());
408 aDoc->setCurrentFeature(theFeature, false);
409 #ifdef DEBUG_CURRENT_FEATURE
410 qDebug(QString(" document->setCurrentFeature(false) = %1 SET").arg(
411 ModuleBase_Tools::objectName(
412 ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
416 aMgr->finishOperation();
419 bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
421 bool aCanStart = true;
423 ModuleBase_Operation* aCurrentOp = currentOperation();
425 bool aGranted = aCurrentOp->isGranted(theId);
426 // the started operation is granted for the current one,
427 // e.g. current - Sketch, started - Line
432 if (!isGrantedOperation(theId)) {
433 // the operation is not granted in the current list of operations
434 // e.g. Edit Parameter when Sketch, Line in Sketch is active.
435 aCanStart = abortAllOperations();
437 else if (canStopOperation(aCurrentOp)) {
438 // the started operation is granted in the parrent operation,
439 // e.g. current - Line in Sketch, started Circle
440 stopOperation(aCurrentOp, isCommitted);
449 void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
451 if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() &&
452 theOperation->isModified()) {
453 isCommitted = theOperation->commit();
456 abortOperation(theOperation);
460 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
462 ModuleBase_Operation* aCurrentOperation = currentOperation();
463 if (theOperation && (theOperation == aCurrentOperation))
464 theOperation->abort();
466 // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
467 // all operation from the current to triggered should also be aborted
468 // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
469 while(hasOperation()) {
470 ModuleBase_Operation* aCurrentOperation = currentOperation();
471 aCurrentOperation->abort();
472 if(theOperation == aCurrentOperation)
478 bool XGUI_OperationMgr::commitOperation()
480 bool isCommitted = false;
481 ModuleBase_Operation* anOperation = currentOperation();
482 if (anOperation && myWorkshop->module()->canCommitOperation())
483 isCommitted = anOperation->commit();
487 void XGUI_OperationMgr::onAbortOperation()
489 ModuleBase_Operation* aCurrentOperation = currentOperation();
490 if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
491 abortOperation(aCurrentOperation);
495 void XGUI_OperationMgr::onAbortAllOperation()
497 abortAllOperations();
500 void XGUI_OperationMgr::onBeforeOperationStarted()
502 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
503 if (!aCurrentOperation)
506 /// Set current feature and remeber old current feature
507 ModuleBase_OperationFeature* aFOperation =
508 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
510 SessionPtr aMgr = ModelAPI_Session::get();
511 DocumentPtr aDoc = aMgr->activeDocument();
512 // the parameter of current feature should be false, we should use all feature, not only
513 // visible in order to correctly save the previous feature of the nested operation, where the
514 // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
515 // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
516 // When sketch entity operation started, the sketch should be cashed here as the current.
517 // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
518 // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
519 // As a result the sketch disappears from the viewer.
520 // However after commit it is displayed back.
521 aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
523 #ifdef DEBUG_CURRENT_FEATURE
524 FeaturePtr aFeature = aFOperation->feature();
525 QString aKind = aFeature ? aFeature->getKind().c_str() : "";
527 qDebug(QString("onBeforeOperationStarted() isEditOperation = %1, feature = %2")
528 .arg(aFOperation->isEditOperation())
529 .arg(ModuleBase_Tools::objectName(aFeature)).toStdString().c_str());
530 qDebug(QString(" document->currentFeature(false) = %1 : DO: setPreviousCurrentFeature").arg(
531 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
534 if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
535 // in create operation, the current feature is changed by addFeature()
536 aDoc->setCurrentFeature(aFOperation->feature(), false);
537 #ifdef DEBUG_CURRENT_FEATURE
538 qDebug(QString(" document->setCurrentFeature(false) = %1").arg(
539 ModuleBase_Tools::objectName(aDoc->currentFeature(false))).toStdString().c_str());
541 // this is the only place where flushes must be called after setCurrentFeature for the
542 // current moment: after this the opertion is not finished, so, the ObjectBrowser
543 // state may be corrupted (issue #1457)
544 static Events_Loop* aLoop = Events_Loop::loop();
545 static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
546 aLoop->flush(aCreateEvent);
547 static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
548 aLoop->flush(aDeleteEvent);
553 void XGUI_OperationMgr::onOperationStarted()
555 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
556 updateApplyOfOperations(aSenderOperation);
557 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
558 aWorkshop->operationStarted(aSenderOperation);
561 void XGUI_OperationMgr::onBeforeOperationAborted()
563 onBeforeOperationCommitted();
566 void XGUI_OperationMgr::onOperationAborted()
568 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
569 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
570 aWorkshop->setStatusBarMessage("");
571 emit operationAborted(aSenderOperation);
574 void XGUI_OperationMgr::onBeforeOperationCommitted()
576 ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
577 if (!aCurrentOperation)
580 /// Restore the previous current feature
581 ModuleBase_OperationFeature* aFOperation =
582 dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
584 #ifdef DEBUG_CURRENT_FEATURE
585 QString aKind = aFOperation->feature()->getKind().c_str();
586 qDebug(QString("onBeforeOperationCommitted() isEditOperation = %1, feature = %2")
587 .arg(aFOperation->isEditOperation())
588 .arg(ModuleBase_Tools::objectName(aFOperation->feature())).toStdString().c_str());
589 qDebug(QString(" document->currentFeature(false) = %1").arg(
590 ModuleBase_Tools::objectName(
591 ModelAPI_Session::get()->activeDocument()->currentFeature(false)))
592 .toStdString().c_str());
595 if (aFOperation->isEditOperation()) {
596 /// Restore the previous current feature
597 setCurrentFeature(aFOperation->previousCurrentFeature());
599 else { // create operation
600 // the Top created feature should stays the current. In nested operations,
601 // like Line in the Sketch or
602 // Sketch in ExtrusionCut, a previous feature should be restored on commit.
603 // It is performed here
604 // in order to perform it in the current transaction without opening a new one.
605 if (myOperations.front() != aFOperation)
606 setCurrentFeature(aFOperation->previousCurrentFeature());
608 ModuleBase_IModule* aModule = myWorkshop->module();
610 aModule->beforeOperationStopped(aFOperation);
614 void XGUI_OperationMgr::onOperationCommitted()
616 // apply state for all features from the stack of operations should be updated
617 updateApplyOfOperations();
619 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
620 emit operationCommitted(aSenderOperation);
623 void XGUI_OperationMgr::onOperationResumed()
625 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
626 emit operationResumed(aSenderOperation);
629 void XGUI_OperationMgr::onOperationStopped()
631 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
632 ModuleBase_Operation* aCurrentOperation = currentOperation();
633 if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
636 myOperations.removeAll(aCurrentOperation);
637 aCurrentOperation->deleteLater();
639 emit operationStopped(aCurrentOperation);
641 // get last operation which can be resumed
642 ModuleBase_Operation* aResultOp = 0;
643 QListIterator<ModuleBase_Operation*> anIt(myOperations);
645 while (anIt.hasPrevious()) {
646 ModuleBase_Operation* anOp = anIt.previous();
653 //bool isModified = aCurrentOperation->isModified();
654 //aResultOp->setIsModified(aResultOp->isModified() || isModified);
655 resumeOperation(aResultOp);
656 onValidateOperation();
660 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
662 bool isAccepted = false;
664 // Let the manager decide what to do with the given key combination.
665 ModuleBase_Operation* anOperation = currentOperation();
666 switch (theEvent->key()) {
668 case Qt::Key_Backtab:
670 ModuleBase_Operation* aOperation = currentOperation();
672 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
674 QWidget* aFocusedWidget = qApp->focusWidget();
675 bool isPPChildObject = aFocusedWidget && isChildObject(aFocusedWidget, aPanel);
676 if (!isPPChildObject) {
677 // check for case when the operation is started but property panel is not filled
678 XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
679 aPP->setFocusNextPrevChild(theEvent->key() == Qt::Key_Tab);
687 case Qt::Key_Enter: {
688 isAccepted = onProcessEnter(theObject);
693 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
695 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
696 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
697 if (!aContext.IsNull()) {
698 Handle(V3d_View) aView = aViewer->activeView();
699 if ((theEvent->key() == Qt::Key_N))
700 aContext->HilightNextDetected(aView);
701 else if ((theEvent->key() == Qt::Key_P))
702 aContext->HilightPreviousDetected(aView);
703 aViewer->updateHighlight();
710 if ((theEvent->modifiers() == Qt::NoModifier))
711 myWorkshop->viewer()->hideSelectionHighlight();
718 // anOperation->keyReleased(theEvent->key());
723 bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
725 // Let the manager decide what to do with the given key combination.
726 ModuleBase_Operation* anOperation = currentOperation();
727 bool isAccepted = false;
728 switch (theEvent->key()) {
729 case Qt::Key_Escape: {
730 // processing in message box
731 if (myActiveMessageBox)
733 myActiveMessageBox->reject();
736 // processing in the active widget
737 ModuleBase_Operation* aOperation = currentOperation();
738 if (!isAccepted && aOperation) {
739 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
741 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
744 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEscape);
746 ModuleBase_OperationFeature* aFOperation =
747 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
749 aFOperation->setNeedToBeAborted(true);
756 XGUI_ActiveControlSelector* anActiveSelector =
757 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
758 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
759 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionEscape);
761 // default Escape button functionality
762 if (!isAccepted && aOperation) {
769 if ((theEvent->modifiers() == Qt::NoModifier))
770 myWorkshop->viewer()->showSelectionHighlight();
776 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
778 bool isAccepted = false;
779 ModuleBase_Operation* aOperation = currentOperation();
780 // to avoid enter processing when operation has not been started yet
783 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
786 // the next code is obsolete as we want to process Enter in property panel always
787 // only property panel enter is processed in order to do not process enter in application dialogs
788 //bool isPPChild = isChildObject(theObject, aPanel);
790 // return isAccepted;
792 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
793 bool isAborted = false;
795 QWidget* aFocusWidget = aPanel->focusWidget();
796 QToolButton* aCancelBtn =
797 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
798 if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
799 abortOperation(aOperation);
805 isAccepted = anActiveWgt && anActiveWgt->processAction(ActionEnter);
808 myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
810 /// functionality is similar to Apply click
811 ModuleBase_OperationFeature* aFOperation =
812 dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
814 myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
815 // key released is emitted to apply the current value to the model
816 // if it was modified in PP
817 emit keyEnterReleased();
829 bool editorControl(QObject* theObject)
831 QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>(theObject);
835 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
837 bool isAccepted = false;
838 ModuleBase_Operation* aOperation = currentOperation();
839 ModuleBase_ModelWidget* anActiveWgt = 0;
840 // firstly the widget should process Delete action
841 ModuleBase_IPropertyPanel* aPanel;
842 bool isPPChildObject = false;
844 aPanel = aOperation->propertyPanel();
846 isPPChildObject = isChildObject(theObject, aPanel);
847 // process delete in active widget only if delete sender is child of property panel
848 // it is necessary for the case when OB is shown, user perform selection and click Delete
849 if (isPPChildObject) {
850 anActiveWgt = aPanel->activeWidget();
852 isAccepted = anActiveWgt->processAction(ActionDelete);
859 XGUI_ActiveControlSelector* anActiveSelector =
860 XGUI_Tools::workshop(myWorkshop)->activeControlMgr()->activeSelector();
861 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
862 isAccepted = XGUI_Tools::workshop(myWorkshop)->facesPanel()->processAction(ActionDelete);
865 // after widget, object browser and viewer should process delete
866 /// other widgets such as line edit controls should not lead to
867 /// processing delete by workshop
868 XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
869 QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
870 bool isToDeleteObject = false;
871 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
872 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
873 if (theObject == aBrowser->treeView()) {
874 aContextMenuMgr->updateObjectBrowserMenu();
875 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
877 else if (isChildObject(theObject, aViewPort)) {
878 aContextMenuMgr->updateViewerMenu();
879 isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
881 else if (isPPChildObject) {
882 // property panel child object is processed to process delete performed on Apply button of PP
883 isToDeleteObject = true;
885 else if (editorControl(theObject)) {
886 isToDeleteObject = false; /// Line Edit of Rename operation in ObjectBrowser
890 if (isToDeleteObject) {
891 aWorkshop->deleteObjects();
899 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
901 bool isPPChild = false;
902 if (theParent && theObject) {
903 QObject* aParent = (QObject*)theObject;
905 isPPChild = aParent == theParent;
908 aParent = aParent->parent();
914 QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
916 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
917 QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
918 qApp->activeWindow());
919 aMessageBox->setDefaultButton(QMessageBox::Cancel);
920 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
925 QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
927 QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
928 QObject::tr("Validate operation"), theMessage, QMessageBox::Ok,
929 qApp->activeWindow());
930 aMessageBox->setDefaultButton(QMessageBox::Ok);
931 aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key