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