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