Salome HOME
b41264d77b160e08096eb11793e6e8ba74ed6d24
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_OperationMgr.cpp
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "XGUI_OperationMgr.h"
8 #include "XGUI_ModuleConnector.h"
9 #include "XGUI_Workshop.h"
10 #include "XGUI_ErrorMgr.h"
11 #include "XGUI_Tools.h"
12 #include "XGUI_ObjectsBrowser.h"
13 #include "XGUI_ContextMenuMgr.h"
14
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_ModelWidget.h>
17 #include "ModuleBase_Operation.h"
18 #include "ModuleBase_IWorkshop.h"
19 #include "ModuleBase_IModule.h"
20 #include <ModuleBase_IViewer.h>
21 #include "ModuleBase_OperationDescription.h"
22 #include "ModuleBase_OperationFeature.h"
23 #include "ModuleBase_Tools.h"
24
25 #include "ModelAPI_CompositeFeature.h"
26 #include "ModelAPI_Session.h"
27
28 #include <XGUI_PropertyPanel.h>
29 #include <QToolButton>
30
31 #include <QMessageBox>
32 #include <QApplication>
33 #include <QKeyEvent>
34
35 //#define DEBUG_CURRENT_FEATURE
36
37 /// Processes "Delete" key event of application. This key is used by several application actions.
38 /// There is a logical order of the actions processing. So the key can not be set for actions
39 /// as a shortcut. The class listens the key event and call operation manager processor.
40 class XGUI_ShortCutListener : public QObject
41 {
42 public:
43   /// Constructor
44   /// \param theParent the parent to be deleted when the parent is deleted
45   /// \param theOperationMgr the class to perform deletion
46   XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
47     : QObject(theParent), myOperationMgr(theOperationMgr)
48   {
49     qApp->installEventFilter(this);
50   }
51   ~XGUI_ShortCutListener() {}
52
53   /// Switch on short cut listener
54   void setActive(const bool theIsActive) { myIsActive = theIsActive; }
55
56   /// Redefinition of virtual function to process Delete key release
57   virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
58   {
59     bool isAccepted = false;
60     if (myIsActive && theEvent->type() == QEvent::KeyRelease) {
61       QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
62       if(aKeyEvent) {
63         switch (aKeyEvent->key()) {
64           case Qt::Key_Delete: {
65             isAccepted = myOperationMgr->onProcessDelete(theObject);
66           }
67         }
68       }
69     }
70     if (!isAccepted)
71       isAccepted = QObject::eventFilter(theObject, theEvent);
72     return isAccepted;
73   }
74
75 private:
76   XGUI_OperationMgr* myOperationMgr; /// processor for key event
77   bool myIsActive; /// boolean state whether the event filter perform own signal processing
78 };
79
80 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
81                                      ModuleBase_IWorkshop* theWorkshop)
82 : QObject(theParent), myWorkshop(theWorkshop)
83 {
84   /// we need to install filter to the application in order to react to 'Delete' key button
85   /// this key can not be a short cut for a corresponded action because we need to set
86   /// the actions priority
87   myShortCutListener = new XGUI_ShortCutListener(theParent, this);
88 }
89
90 XGUI_OperationMgr::~XGUI_OperationMgr()
91 {
92 }
93
94 void XGUI_OperationMgr::activate()
95 {
96   myShortCutListener->setActive(true);
97 }
98
99 void XGUI_OperationMgr::deactivate()
100 {
101   myShortCutListener->setActive(false);
102 }
103
104 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
105 {
106   return myOperations.count() > 0 ? myOperations.last() : 0;
107 }
108
109 bool XGUI_OperationMgr::isCurrentOperation(ModuleBase_Operation* theOperation)
110 {
111   if(!hasOperation())
112     return false;
113   return currentOperation() == theOperation;
114 }
115
116 bool XGUI_OperationMgr::hasOperation() const
117 {
118   return !myOperations.isEmpty() && (myOperations.last() != NULL);
119 }
120
121 bool XGUI_OperationMgr::hasOperation(const QString& theId) const
122 {
123   foreach(ModuleBase_Operation* aOp, myOperations) {
124     if (aOp->id() == theId)
125       return true;
126   }
127   return false;
128 }
129
130 ModuleBase_Operation* XGUI_OperationMgr::findOperation(const QString& theId) const
131 {
132   foreach(ModuleBase_Operation* aOp, myOperations) {
133     if (aOp->id() == theId)
134       return aOp;
135   }
136   return 0;
137 }
138
139
140 int XGUI_OperationMgr::operationsCount() const
141 {
142   return myOperations.count();
143 }
144
145 QStringList XGUI_OperationMgr::operationList() const
146 {
147   QStringList result;
148   foreach(ModuleBase_Operation* eachOperation, myOperations) {
149     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
150     if (aFOperation) {
151       FeaturePtr aFeature = aFOperation->feature();
152       if(aFeature) {
153         result << QString::fromStdString(aFeature->getKind());
154       }
155     }
156   }
157   return result;
158 }
159
160 ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
161 {
162   int idx = myOperations.lastIndexOf(theOperation);
163   if(idx == -1 || idx == 0) {
164     return NULL;
165   }
166   return myOperations.at(idx - 1);
167 }
168
169 bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
170 {
171   bool isAccepted = false;
172   if (theEvent->type() == QEvent::KeyRelease) {
173     QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
174     if(aKeyEvent)
175       isAccepted = onKeyReleased(theObject, aKeyEvent);
176   }
177   if (!isAccepted)
178     isAccepted = QObject::eventFilter(theObject, theEvent);
179
180   return isAccepted;
181 }
182
183 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
184 {
185   if (hasOperation())
186     currentOperation()->postpone();
187   myOperations.append(theOperation);
188
189   connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
190   connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
191   connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
192
193   connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
194   connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
195   connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
196
197   connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
198   connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
199
200   bool isStarted = theOperation->start();
201   if (isStarted)
202     onValidateOperation();
203   return isStarted;
204 }
205
206 bool XGUI_OperationMgr::abortAllOperations()
207 {
208   bool aResult = true;
209   if(!hasOperation())
210     return aResult;
211
212   if (operationsCount() == 1) {
213     ModuleBase_Operation* aCurrentOperation = currentOperation();
214     if (canStopOperation(aCurrentOperation)) {
215       abortOperation(aCurrentOperation);
216     }
217     else
218       aResult = false;
219   }
220   else {
221     aResult = QMessageBox::question(qApp->activeWindow(),
222                                     tr("Abort operation"),
223                                     tr("All active operations will be aborted."),
224                                     QMessageBox::Ok | QMessageBox::Cancel,
225                                     QMessageBox::Cancel) == QMessageBox::Ok;
226     while(aResult && hasOperation()) {
227       abortOperation(currentOperation());
228     }
229   }
230   return aResult;
231 }
232
233 bool XGUI_OperationMgr::commitAllOperations()
234 {
235   bool isCompositeCommitted = false, anOperationProcessed = false;
236   while (hasOperation()) {
237     ModuleBase_Operation* anOperation = currentOperation();
238     if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
239       anOperationProcessed = onCommitOperation();
240     } else {
241       abortOperation(anOperation);
242       anOperationProcessed = true;
243     }
244     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
245                                                                             (anOperation);
246     if (aFOperation) {
247       FeaturePtr aFeature = aFOperation->feature();
248       CompositeFeaturePtr aComposite = 
249           std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
250       isCompositeCommitted = aComposite.get();
251       if (isCompositeCommitted)
252         break;
253     }
254     // not processed[committed] operation might be used in composite feature,
255     // so the while will be stopped by the previous check.
256     // this code is not necessary, but logically should be done when the processing will not
257     // be done for not composite feature by some reasons
258     if (!anOperationProcessed)
259       break;
260   }
261   return true;
262 }
263
264 void XGUI_OperationMgr::onValidateOperation()
265 {
266   if (!hasOperation())
267     return;
268   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
269                                                                           (currentOperation());
270   if(aFOperation && aFOperation->feature().get())
271     XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
272 }
273
274 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
275 {
276   XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
277   if (theOperation) {
278     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
279     if (aFOperation)
280       anErrorMgr->updateAcceptAllAction(aFOperation->feature());
281   }
282   else {
283     foreach(ModuleBase_Operation* anOperation, myOperations) {
284       if (anOperation)
285         updateApplyOfOperations(anOperation);
286     }
287   }
288   // Apply button of the current operation should also be updated
289   onValidateOperation();
290 }
291
292 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
293 {
294   //in case of nested (sketch) operation no confirmation needed
295   if (isGrantedOperation(theOperation->id()))
296     return true;
297   if (theOperation && theOperation->isModified()) {
298     QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
299     int anAnswer = QMessageBox::question(qApp->activeWindow(),
300                                          tr("Abort operation"),
301                                          aMessage,
302                                          QMessageBox::Ok | QMessageBox::Cancel,
303                                          QMessageBox::Cancel);
304     return anAnswer == QMessageBox::Ok;
305   }
306   return true;
307 }
308
309 bool XGUI_OperationMgr::commitOperation()
310 {
311   //if (hasOperation() && currentOperation()->isValid()) {
312   //  onCommitOperation();
313   //  return true;
314   //}
315   //return false;
316   return onCommitOperation();
317 }
318
319 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
320 {
321   theOperation->resume();
322 }
323
324 bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
325 {
326   bool isGranted = false;
327
328   QListIterator<ModuleBase_Operation*> anIt(myOperations);
329   anIt.toBack();
330   ModuleBase_Operation* aPreviousOperation = 0;
331   while (anIt.hasPrevious() && !isGranted) {
332     ModuleBase_Operation* anOp = anIt.previous();
333     if (anOp)
334       isGranted = anOp->isGranted(theId);
335   }
336   return isGranted;
337 }
338
339 void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
340 {
341   SessionPtr aMgr = ModelAPI_Session::get();
342   DocumentPtr aDoc = aMgr->activeDocument();
343   bool aIsOp = aMgr->isOperation();
344   if (!aIsOp)
345     aMgr->startOperation(QString("Set current feature: %1").arg(theFeature->getKind().c_str()).toStdString());
346   aDoc->setCurrentFeature(theFeature, false);
347   if (!aIsOp)
348     aMgr->finishOperation();
349 }
350
351 bool XGUI_OperationMgr::canStartOperation(const QString& theId)
352 {
353   bool aCanStart = true;
354   ModuleBase_Operation* aCurrentOp = currentOperation();
355   if (aCurrentOp) {
356     bool aGranted = aCurrentOp->isGranted(theId);
357     // the started operation is granted for the current one,
358     // e.g. current - Sketch, started - Line
359     if (aGranted) {
360       aCanStart = true;
361     }
362     else {
363       if (!isGrantedOperation(theId)) {
364         // the operation is not granted in the current list of operations
365         // e.g. Edit Parameter when Sketch, Line in Sketch is active.
366         aCanStart = abortAllOperations();
367       }
368       else if (canStopOperation(aCurrentOp)) {
369         // the started operation is granted in the parrent operation,
370         // e.g. current - Line in Sketch, started Circle 
371         if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() && aCurrentOp->isModified())
372           aCurrentOp->commit();
373         else
374           abortOperation(aCurrentOp);
375       } else {
376         aCanStart = false;
377       }
378     }
379   }
380   return aCanStart;
381 }
382
383 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
384 {
385   ModuleBase_Operation* aCurrentOperation = currentOperation();
386   if (theOperation == aCurrentOperation)
387     theOperation->abort();
388   else {
389     // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
390     // all operation from the current to triggered should also be aborted
391     // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
392     while(hasOperation()) {
393       ModuleBase_Operation* aCurrentOperation = currentOperation();
394       aCurrentOperation->abort();
395       if(theOperation == aCurrentOperation)
396         break;
397     }
398   }
399 }
400
401 bool XGUI_OperationMgr::onCommitOperation()
402 {
403   bool isCommitted = false;
404   ModuleBase_Operation* anOperation = currentOperation();
405   if (anOperation && myWorkshop->module()->canCommitOperation())
406     isCommitted = anOperation->commit();
407   return isCommitted;
408 }
409
410 void XGUI_OperationMgr::onAbortOperation()
411 {
412   ModuleBase_Operation* aCurrentOperation = currentOperation();
413   if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
414     abortOperation(aCurrentOperation);
415   }
416 }
417
418 void XGUI_OperationMgr::onBeforeOperationStarted()
419 {
420   ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
421   if (!aCurrentOperation)
422     return;
423
424   /// Set current feature and remeber old current feature
425   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
426   if (aFOperation) {
427     SessionPtr aMgr = ModelAPI_Session::get();
428     DocumentPtr aDoc = aMgr->activeDocument();
429     // the parameter of current feature should be false, we should use all feature, not only visible
430     // in order to correctly save the previous feature of the nested operation, where the
431     // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
432     // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
433     // When sketch entity operation started, the sketch should be cashed here as the current.
434     // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
435     // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
436     // As a result the sketch disappears from the viewer. However after commit it is displayed back.
437     aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
438
439 #ifdef DEBUG_CURRENT_FEATURE
440     FeaturePtr aFeature = aFOperation->feature();
441     QString aKind = aFeature ? aFeature->getKind().c_str() : "";
442     qDebug(QString("onBeforeOperationStarted(), edit operation = %1, feature = %2")
443             .arg(aFOperation->isEditOperation())
444             .arg(ModuleBase_Tools::objectInfo(aFeature)).toStdString().c_str());
445
446     qDebug(QString("\tdocument->currentFeature(false) = %1").arg(
447             ModuleBase_Tools::objectInfo(ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
448 #endif
449
450     if (aFOperation->isEditOperation()) {// it should be performed by the feature edit only
451       // in create operation, the current feature is changed by addFeature()
452       aDoc->setCurrentFeature(aFOperation->feature(), false);
453       // this is the only place where flushes must be called after setCurrentFeature for the current
454       // moment: after this the opertion is not finished, so, the ObjectBrowser state may be corrupted
455       // (issue #1457)
456       static Events_Loop* aLoop = Events_Loop::loop();
457       static Events_ID aCreateEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
458       aLoop->flush(aCreateEvent);
459       static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
460       aLoop->flush(aDeleteEvent);
461     }
462
463 #ifdef DEBUG_CURRENT_FEATURE
464     qDebug("\tdocument->setCurrentFeature");
465     qDebug(QString("\tdocument->currentFeature(false) = %1").arg(
466             ModuleBase_Tools::objectInfo(ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
467 #endif
468   ModuleBase_IModule* aModule = myWorkshop->module();
469   if (aModule)
470     aModule->beforeOperationStarted(aFOperation);
471   }
472 }
473
474 void XGUI_OperationMgr::onOperationStarted()
475 {
476   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
477   updateApplyOfOperations(aSenderOperation);
478   emit operationStarted(aSenderOperation);
479 }
480
481 void XGUI_OperationMgr::onBeforeOperationAborted()
482 {
483   onBeforeOperationCommitted();
484 }
485
486 void XGUI_OperationMgr::onOperationAborted()
487 {
488   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
489   emit operationAborted(aSenderOperation);
490 }
491
492 void XGUI_OperationMgr::onBeforeOperationCommitted()
493 {
494   ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
495   if (!aCurrentOperation)
496     return;
497
498   /// Restore the previous current feature
499   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
500   if (aFOperation) {
501 #ifdef DEBUG_CURRENT_FEATURE
502     QString aKind = aFOperation->feature()->getKind().c_str();
503     qDebug(QString("onBeforeOperationCommitted(), edit operation = %1, feature = %2")
504             .arg(aFOperation->isEditOperation())
505             .arg(ModuleBase_Tools::objectInfo(aFOperation->feature())).toStdString().c_str());
506
507     qDebug(QString("\tdocument->currentFeature(false) = %1").arg(
508             ModuleBase_Tools::objectInfo(ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
509 #endif
510
511     if (aFOperation->isEditOperation()) {
512       /// Restore the previous current feature
513       setCurrentFeature(aFOperation->previousCurrentFeature());
514     }
515     else { // create operation
516       // the Top created feature should stays the current. In nested operations, like Line in the Sketch or
517       // Sketch in ExtrusionCut, a previous feature should be restored on commit. It is performed here
518       // in order to perform it in the current transaction without opening a new one.
519       if (myOperations.front() != aFOperation)
520         setCurrentFeature(aFOperation->previousCurrentFeature());
521     }
522 #ifdef DEBUG_CURRENT_FEATURE
523     qDebug("\tdocument->setCurrentFeature");
524     qDebug(QString("\tdocument->currentFeature(false) = %1").arg(
525             ModuleBase_Tools::objectInfo(ModelAPI_Session::get()->activeDocument()->currentFeature(false))).toStdString().c_str());
526 #endif
527     ModuleBase_IModule* aModule = myWorkshop->module();
528     if (aModule)
529       aModule->beforeOperationStopped(aFOperation);
530   }
531 }
532
533 void XGUI_OperationMgr::onOperationCommitted()
534 {
535   // apply state for all features from the stack of operations should be updated
536   updateApplyOfOperations();
537
538   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
539   emit operationCommitted(aSenderOperation);
540 }
541
542 void XGUI_OperationMgr::onOperationResumed()
543 {
544   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
545   emit operationResumed(aSenderOperation);
546 }
547
548 void XGUI_OperationMgr::onOperationStopped()
549 {
550   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
551   ModuleBase_Operation* aCurrentOperation = currentOperation();
552   if (!aSenderOperation || !aCurrentOperation || aSenderOperation != aCurrentOperation)
553     return;
554
555   myOperations.removeAll(aCurrentOperation);
556   aCurrentOperation->deleteLater();
557
558   emit operationStopped(aCurrentOperation);
559
560   // get last operation which can be resumed
561   ModuleBase_Operation* aResultOp = 0;
562   QListIterator<ModuleBase_Operation*> anIt(myOperations);
563   anIt.toBack();
564   while (anIt.hasPrevious()) {
565     ModuleBase_Operation* anOp = anIt.previous();
566     if (anOp) {
567       aResultOp = anOp;
568       break;
569     }
570   }
571   if (aResultOp) {
572     bool isModified = aCurrentOperation->isModified();
573     aResultOp->setIsModified(aResultOp->isModified() || isModified);
574     resumeOperation(aResultOp);
575     onValidateOperation();
576   }
577 }
578
579 bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
580 {
581   // Let the manager decide what to do with the given key combination.
582   ModuleBase_Operation* anOperation = currentOperation();
583   bool isAccepted = false;
584   switch (theEvent->key()) {
585     case Qt::Key_Return:
586     case Qt::Key_Enter: {
587       isAccepted = onProcessEnter(theObject);
588     }
589     break;
590     case Qt::Key_N:
591     case Qt::Key_P: {
592       bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
593       if (noModifiers) {
594         ModuleBase_IViewer* aViewer = myWorkshop->viewer();
595         Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
596         if (!aContext.IsNull()) {
597           Handle(V3d_View) aView = aViewer->activeView();
598           if ((theEvent->key() == Qt::Key_N))
599             aContext->HilightNextDetected(aView);
600           else if ((theEvent->key() == Qt::Key_P))
601             aContext->HilightPreviousDetected(aView);
602         }
603       }
604     }
605     break;
606     break;
607     default:
608       isAccepted = false;
609       break;
610   }
611   //if(anOperation) {
612   //  anOperation->keyReleased(theEvent->key());
613   //}
614   return isAccepted;
615 }
616
617 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
618 {
619   bool isAccepted = false;
620   ModuleBase_Operation* aOperation = currentOperation();
621   // to avoid enter processing when operation has not been started yet
622   if (!aOperation)
623     return isAccepted;
624   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
625   // only property panel enter is processed in order to do not process enter in application dialogs
626   bool isPPChild = isChildObject(theObject, aPanel);
627   if (!isPPChild)
628     return isAccepted;
629
630   ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
631   bool isAborted = false;
632   if (!anActiveWgt) {
633     QWidget* aFocusWidget = aPanel->focusWidget();
634     QToolButton* aCancelBtn = dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_CANCEL);
635     if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
636       abortOperation(aOperation);
637       isAccepted = true;
638       isAborted = true;
639     }
640   }
641   if (!isAborted) {
642     isAccepted = anActiveWgt && anActiveWgt->processEnter();
643     if (!isAccepted) {
644       isAccepted = myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
645       if (!isAccepted) {
646         /// functionality is similar to Apply click
647         ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
648         if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
649           // key released is emitted to apply the current value to the model if it was modified in PP
650           emit keyEnterReleased();
651           commitOperation();
652           isAccepted = true;
653         }
654         else
655           isAccepted = false;
656       }
657     }
658   }
659   return isAccepted;
660 }
661
662 bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
663 {
664   bool isAccepted = false;
665   ModuleBase_Operation* aOperation = currentOperation();
666   ModuleBase_ModelWidget* anActiveWgt = 0;
667   // firstly the widget should process Delete action
668   ModuleBase_IPropertyPanel* aPanel;
669   bool isPPChildObject = false;
670   if (aOperation) {
671     aPanel = aOperation->propertyPanel();
672     if (aPanel) {
673       isPPChildObject = isChildObject(theObject, aPanel);
674       // process delete in active widget only if delete sender is child of property panel
675       // it is necessary for the case when OB is shown, user perform selection and click Delete
676       if (isPPChildObject) {
677         anActiveWgt = aPanel->activeWidget();
678         if (anActiveWgt) {
679           isAccepted = anActiveWgt->processDelete();
680         }
681       }
682     }
683   }
684   if (!isAccepted) {
685     // after widget, object browser and viewer should process delete
686     /// other widgets such as line edit controls should not lead to
687     /// processing delete by workshop
688     XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
689     QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
690     bool isToDeleteObject = false;
691     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
692     XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
693     if (theObject == aBrowser->treeView()) {
694       aContextMenuMgr->updateObjectBrowserMenu();
695       isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
696     }
697     else if (isChildObject(theObject, aViewPort)) {
698       aContextMenuMgr->updateViewerMenu();
699       isToDeleteObject = aContextMenuMgr->action("DELETE_CMD")->isEnabled();
700     }
701     else if (isPPChildObject) {
702       // property panel child object is processed to process delete performed on Apply button of PP
703       isToDeleteObject = true;
704     }
705     if (isToDeleteObject) {
706       aWorkshop->deleteObjects();
707       isAccepted = true;
708     }
709   }
710
711   return isAccepted;
712 }
713
714 bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
715 {
716   bool isPPChild = false;
717   if (theParent && theObject) {
718     QObject* aParent = (QObject*)theObject;
719     while (aParent ) {
720       isPPChild = aParent == theParent;
721       if (isPPChild)
722         break;
723       aParent = aParent->parent();
724     }
725   }
726   return isPPChild;
727 }