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