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