Salome HOME
Issue #2155 Trim removes multi-rotation constraint, undo leads to wrong DOF
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_MenuMgr.cpp
4 // Created:     03 April 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_MenuMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_SketcherMgr.h"
10 #include "PartSet_Tools.h"
11
12 #include <PartSetPlugin_Part.h>
13
14 #include <GeomAPI_Pnt2d.h>
15 #include <GeomDataAPI_Point2D.h>
16
17 #include <SketchPlugin_ConstraintCoincidence.h>
18 #include <SketchPlugin_Line.h>
19 #include <SketchPlugin_Circle.h>
20 #include <SketchPlugin_Point.h>
21 #include <SketchPlugin_Sketch.h>
22
23 #include <ModuleBase_ISelection.h>
24 #include <ModuleBase_Operation.h>
25 #include <ModuleBase_OperationAction.h>
26 #include <ModuleBase_OperationFeature.h>
27 #include <ModuleBase_ViewerPrs.h>
28 #include <ModuleBase_Tools.h>
29
30 #include <XGUI_ModuleConnector.h>
31 #include <XGUI_Workshop.h>
32 #include <XGUI_Displayer.h>
33 #include <XGUI_DataModel.h>
34 #include <XGUI_OperationMgr.h>
35 #include <XGUI_ObjectsBrowser.h>
36
37 #include <Events_Loop.h>
38 #include <ModelAPI_Events.h>
39 #include <ModelAPI_Session.h>
40 #include <ModelAPI_ResultParameter.h>
41
42 #include <QMainWindow>
43 #include <QAction>
44 #include <QMenu>
45 #include <QEvent>
46
47 #include <TopoDS.hxx>
48 #include <BRep_Tool.hxx>
49
50 PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule)
51   : QObject(theModule), myModule(theModule), myPrevId(-1)
52 {
53   createActions();
54 }
55
56
57 QAction* PartSet_MenuMgr::action(const QString& theId) const
58 {
59   if (myActions.contains(theId))
60     return myActions[theId];
61   return 0;
62 }
63
64 void PartSet_MenuMgr::addAction(const QString& theId, QAction* theAction)
65 {
66   if (myActions.contains(theId))
67     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
68   theAction->setData(theId);
69   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
70   myActions[theId] = theAction;
71 }
72
73 void PartSet_MenuMgr::createActions()
74 {
75   QAction* aAction;
76
77   QWidget* aParent = myModule->workshop()->desktop();
78   aAction = ModuleBase_Tools::createAction(QIcon(), tr("Auxiliary"), aParent);
79   aAction->setCheckable(true);
80   addAction("AUXILIARY_CMD", aAction);
81
82   aAction = ModuleBase_Tools::createAction(QIcon(":icons/activate.png"), tr("Activate"), aParent,
83                                            this, SLOT(onActivatePart(bool)));
84   myActions["ACTIVATE_PART_CMD"] = aAction;
85
86   // Activate PartSet
87   aAction = ModuleBase_Tools::createAction(QIcon(":icons/activate.png"), tr("Activate"), aParent,
88                         this, SLOT(onActivatePartSet(bool)));
89   myActions["ACTIVATE_PARTSET_CMD"] = aAction;
90
91   aAction = ModuleBase_Tools::createAction(QIcon(":icons/edit.png"), tr("Edit..."), aParent,
92                          this, SLOT(onEdit(bool)));
93   myActions["EDIT_CMD"] = aAction;
94 }
95
96
97 void PartSet_MenuMgr::onAction(bool isChecked)
98 {
99   QAction* aAction = static_cast<QAction*>(sender());
100   QString anId = aAction->data().toString();
101
102   if (anId == "AUXILIARY_CMD") {
103     setAuxiliary(isChecked);
104   }
105 }
106
107 bool PartSet_MenuMgr::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
108                                     QWidget* theParent,
109                                     QMap<int, QAction*>& theMenuActions) const
110 {
111   int anIndex = 0;
112
113   ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
114   if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
115       !myModule->sketchMgr()->isNestedSketchOperation(anOperation))
116     return false;
117
118   myCoinsideLines.clear();
119   ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
120
121   bool aIsDetach = false;
122   bool hasAttribute = false;
123   bool hasFeature = false;
124
125   QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
126   if (aPrsList.size() > 1) {
127     hasFeature = true;
128   } else if (aPrsList.size() == 1) {
129     ResultPtr aResult;
130     FeaturePtr aFeature;
131     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
132       aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
133       if (aResult.get() != NULL) {
134         const GeomShapePtr& aShape = aPrs->shape();
135         if (aShape.get() && aShape->isEqual(aResult->shape()))
136           hasFeature = true;
137         else
138           hasAttribute = true;
139       } else {
140         aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aPrs->object());
141         hasFeature = (aFeature.get() != NULL);
142       }
143     }
144
145     const GeomShapePtr& aShape = aPrsList.first()->shape();
146     if (aShape.get() && !aShape->isNull() && aShape->shapeType() == GeomAPI_Shape::VERTEX) {
147       // Find 2d coordinates
148       FeaturePtr aSketchFea = myModule->sketchMgr()->activeSketch();
149       if (aSketchFea->getKind() == SketchPlugin_Sketch::ID()) {
150         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
151         gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aTDShape));
152         std::shared_ptr<GeomAPI_Pnt> aPnt3d(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
153         std::shared_ptr<GeomAPI_Pnt2d> aSelPnt = PartSet_Tools::convertTo2D(aSketchFea, aPnt3d);
154
155         // Find coincident in these coordinates
156         ObjectPtr aObj = aPrsList.first()->object();
157         FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
158         FeaturePtr aCoincident = PartSet_Tools::findFirstCoincidence(aFeature, aSelPnt);
159         // If we have coincidence then add Detach menu
160         if (aCoincident.get() != NULL) {
161           QList<FeaturePtr> aCoins;
162           mySelectedFeature = aCoincident;
163           QList<bool> anIsAttributes;
164           PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, aCoins,
165                                           SketchPlugin_ConstraintCoincidence::ENTITY_A(),
166                                           anIsAttributes);
167           PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, aCoins,
168                                           SketchPlugin_ConstraintCoincidence::ENTITY_B(),
169                                           anIsAttributes);
170           if (myCoinsideLines.size() > 0) {
171             aIsDetach = true;
172             QMenu* aSubMenu = new QMenu(tr("Detach"), theParent);
173             theMenuActions[anIndex++] = aSubMenu->menuAction();
174             QAction* aAction;
175             int i = 0;
176             foreach (FeaturePtr aCoins, myCoinsideLines) {
177               QString anItemText = aCoins->data()->name().c_str();
178 #ifdef _DEBUG
179               if (anIsAttributes[i])
180                 anItemText += " [attribute]";
181 #endif
182               aAction = aSubMenu->addAction(anItemText);
183               aAction->setData(QVariant(i));
184               i++;
185             }
186             connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*)));
187             connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide()));
188             connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*)));
189           }
190         }
191       }
192     }
193   }
194   if (!hasAttribute) {
195     bool isAuxiliary;
196     if (canSetAuxiliary(isAuxiliary)) {
197       QAction* anAction = action("AUXILIARY_CMD");
198       theMenuActions[anIndex++] = anAction;
199       anAction->setChecked(isAuxiliary);
200     }
201   }
202
203   if (!aIsDetach && hasFeature) {
204     // Delete item should be the last in the list of actions
205     theMenuActions[1000] = theStdActions["DELETE_CMD"];
206   }
207
208   return true;
209 }
210
211 void PartSet_MenuMgr::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
212 {
213   ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
214
215   bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
216                         myModule->sketchMgr()->isNestedSketchOperation(anOperation);
217   if (isActiveSketch) {
218     theStdActions["WIREFRAME_CMD"]->setEnabled(false);
219     theStdActions["SHADING_CMD"]->setEnabled(false);
220     theStdActions["SHOW_ONLY_CMD"]->setEnabled(false);
221     theStdActions["SHOW_CMD"]->setEnabled(false);
222     theStdActions["HIDE_CMD"]->setEnabled(false);
223     theStdActions["HIDEALL_CMD"]->setEnabled(false);
224   }
225 }
226
227
228 void PartSet_MenuMgr::onLineHighlighted(QAction* theAction)
229 {
230   if (myPrevId != -1) {
231     // Restore color for previous object
232     setLineColor(myPrevId, myColor, false);
233   }
234   myPrevId = theAction->data().toInt();
235   myColor = setLineColor(myPrevId, Qt::white, true);
236 }
237
238 QColor PartSet_MenuMgr::setLineColor(int theId, const QColor theColor, bool theUpdate)
239 {
240   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
241   XGUI_Workshop* aWorkshop = aConnector->workshop();
242   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
243
244   FeaturePtr aLine = myCoinsideLines.at(myPrevId);
245   std::list<ResultPtr>::const_iterator aIt;
246   const std::list<ResultPtr>& aResults = aLine->results();
247   QColor aColor;
248   for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
249     aColor = aDisplayer->setObjectColor((*aIt), theColor, false);
250   }
251   if (theUpdate)
252     aDisplayer->updateViewer();
253   return aColor;
254 }
255
256
257 void addRefCoincidentFeatures(const std::set<AttributePtr>& theRefList,
258   std::shared_ptr<GeomAPI_Pnt2d>& theRefPnt,
259   QObjectPtrList& theOutList)
260 {
261   std::set<AttributePtr>::const_iterator aIt;
262   for (aIt = theRefList.cbegin(); aIt != theRefList.cend(); ++aIt) {
263     std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
264     FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
265     if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
266       std::shared_ptr<GeomAPI_Pnt2d> aPnt = PartSet_Tools::getCoincedencePoint(aConstrFeature);
267       if (aPnt.get() == NULL)
268         return;
269       gp_Pnt aP = aPnt->impl<gp_Pnt>();
270       if (theRefPnt->isEqual(aPnt) && (!theOutList.contains(aConstrFeature))) {
271         theOutList.append(aConstrFeature);
272       }
273     }
274   }
275 }
276
277 void PartSet_MenuMgr::onLineDetach(QAction* theAction)
278 {
279   int aId = theAction->data().toInt();
280   FeaturePtr aLine = myCoinsideLines.at(aId);
281   std::shared_ptr<GeomAPI_Pnt2d> aOrig = PartSet_Tools::getCoincedencePoint(mySelectedFeature);
282   if (!aOrig.get())
283     return;
284
285   const std::set<AttributePtr>& aRefsList = aLine->data()->refsToMe();
286
287   QObjectPtrList aToDelFeatures;
288
289   addRefCoincidentFeatures(aRefsList, aOrig, aToDelFeatures);
290
291   const std::list<ResultPtr>& aResults = aLine->results();
292   std::list<ResultPtr>::const_iterator aResIt;
293   for (aResIt = aResults.cbegin(); aResIt != aResults.cend(); aResIt++) {
294     ResultPtr aResult = (*aResIt);
295     const std::set<AttributePtr>& aRefList = aResult->data()->refsToMe();
296     addRefCoincidentFeatures(aRefList, aOrig, aToDelFeatures);
297   }
298   if (aToDelFeatures.size() > 0) {
299     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
300     XGUI_Workshop* aWorkshop = aConnector->workshop();
301     ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
302
303     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(
304                                    tr("Detach %1").arg(aLine->data()->name().c_str()), myModule);
305     bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
306     XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
307     // the active nested sketch operation should be aborted unconditionally
308     // the Delete action should be additionally granted for the Sketch operation
309     // in order to do not abort/commit it
310     bool isCommitted;
311     if (!anOpMgr->canStartOperation(tr("Detach"), isCommitted))
312       return; // the objects are processed but can not be deleted
313
314     anOpMgr->startOperation(anOpAction);
315     aWorkshop->deleteFeatures(aToDelFeatures);
316
317     anOpMgr->commitOperation();
318   }
319   myCoinsideLines.clear();
320 }
321
322
323 void PartSet_MenuMgr::onDetachMenuHide()
324 {
325   if (myPrevId != -1) {
326     // Restore color for previous object
327     setLineColor(myPrevId, myColor, false);
328   }
329   // Clear previous definitions
330   myPrevId = -1;
331 }
332
333
334 void PartSet_MenuMgr::setAuxiliary(const bool isChecked)
335 {
336   ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
337
338   CompositeFeaturePtr aSketch = myModule->sketchMgr()->activeSketch();
339   bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
340                         myModule->sketchMgr()->isNestedSketchOperation(anOperation);
341   if (!isActiveSketch)
342     return;
343
344   QObjectPtrList anObjects;
345   bool isUseTransaction = false;
346   // 1. change auxiliary type of a created feature
347   if (myModule->sketchMgr()->isNestedCreateOperation(anOperation, aSketch) &&
348       PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) {
349       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
350                                                                (anOperation);
351       if (aFOperation)
352         anObjects.append(aFOperation->feature());
353   }
354   else {
355     isUseTransaction = true;
356     // 2. change auxiliary type of selected sketch entities
357     ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
358     anObjects = aSelection->selectedPresentations();
359   }
360
361   QAction* anAction = action("AUXILIARY_CMD");
362   //SessionPtr aMgr = ModelAPI_Session::get();
363   ModuleBase_OperationAction* anOpAction = 0;
364   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
365   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
366   if (isUseTransaction) {
367     anOpAction = new ModuleBase_OperationAction(anAction->text(), myModule);
368     bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
369
370     bool isCommitted;
371     if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
372       return; // the objects are processed but can not be deleted
373
374     anOpMgr->startOperation(anOpAction);
375   }
376   if (anObjects.size() > 0) {
377     QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
378     for (; anIt != aLast; anIt++) {
379       FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
380       if (aFeature.get() != NULL) {
381         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
382                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
383         if (aSketchFeature.get() != NULL) {
384           std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
385
386           std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
387             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
388             aSketchFeature->data()->attribute(anAttribute));
389           if (anAuxiliaryAttr)
390             anAuxiliaryAttr->setValue(isChecked);
391         }
392       }
393     }
394   }
395   if (isUseTransaction)
396     anOpMgr->commitOperation();
397
398   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
399 }
400
401 bool PartSet_MenuMgr::canSetAuxiliary(bool& theValue) const
402 {
403   bool anEnabled = false;
404   ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
405
406   CompositeFeaturePtr aSketch = myModule->sketchMgr()->activeSketch();
407   bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
408                         myModule->sketchMgr()->isNestedSketchOperation(anOperation);
409   if (!isActiveSketch)
410     return anEnabled;
411
412   QObjectPtrList anObjects;
413   // 1. change auxiliary type of a created feature
414   if (myModule->sketchMgr()->isNestedCreateOperation(anOperation, aSketch) &&
415     PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) {
416     ModuleBase_OperationFeature* aFOperation =
417       dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
418     if (aFOperation)
419       anObjects.append(aFOperation->feature());
420   }
421   else {
422     /// The operation should not be aborted here, because the method does not changed
423     /// the auxilliary state, but checks the possibility to perform this
424     ///if (myModule->sketchMgr()->isNestedSketchOperation(anOperation))
425     ///  anOperation->abort();
426     // 2. change auxiliary type of selected sketch entities
427     ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
428     anObjects = aSelection->selectedPresentations();
429   }
430
431   bool isNotAuxiliaryFound = false;
432   if (anObjects.size() > 0) {
433     QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
434     for (; anIt != aLast && !isNotAuxiliaryFound; anIt++) {
435       FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
436       if ((aFeature.get() != NULL) && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
437         anEnabled = true;
438         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
439                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
440         if (aSketchFeature.get() != NULL) {
441           std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
442
443           std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
444             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
445             aSketchFeature->data()->attribute(anAttribute));
446           if (anAuxiliaryAttr)
447             isNotAuxiliaryFound = !anAuxiliaryAttr->value();
448         }
449       }
450     }
451   }
452   theValue = anObjects.size() && !isNotAuxiliaryFound;
453   return anEnabled;
454 }
455
456 void PartSet_MenuMgr::onActivatePart(bool)
457 {
458   if (myModule->workshop()->currentOperation())
459     return;
460   QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects();
461   if (aObjects.size() > 0) {
462     ObjectPtr aObj = aObjects.first();
463     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
464     if (!aPart.get()) {
465       FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
466       if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
467         aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
468       }
469     }
470     if (aPart.get()) {
471       activatePart(aPart);
472       myModule->workshop()->updateCommandStatus();
473     }
474   }
475 }
476
477 void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const
478 {
479   bool isFirstLoad = !thePart->partDoc().get();
480   thePart->activate();
481   if (isFirstLoad) {
482     XGUI_Workshop* aWorkshop = myModule->getWorkshop();
483     XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser();
484     DocumentPtr aDoc = thePart->partDoc();
485     std::list<bool> aStates;
486     aDoc->restoreNodesState(aStates);
487     aObjBrowser->setStateForDoc(aDoc, aStates);
488   }
489 }
490
491 void PartSet_MenuMgr::onActivatePartSet(bool)
492 {
493   if (myModule->workshop()->currentOperation())
494     return;
495   activatePartSet();
496 }
497
498 void PartSet_MenuMgr::activatePartSet() const
499 {
500   SessionPtr aMgr = ModelAPI_Session::get();
501   bool isNewTransaction = !aMgr->isOperation();
502   // activation may cause changes in current features in document, so it must be in transaction
503   if (isNewTransaction)
504     aMgr->startOperation("Activation");
505   aMgr->setActiveDocument(aMgr->moduleDocument());
506   if (isNewTransaction) aMgr->finishOperation();
507
508   myModule->workshop()->updateCommandStatus();
509 }
510
511 void PartSet_MenuMgr::grantedOperationIds(ModuleBase_Operation* theOperation,
512                                           QStringList& theIds) const
513 {
514   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
515     theIds.append(tr("Detach"));
516     theIds.append(tr("Auxiliary"));
517   }
518 }
519
520 void PartSet_MenuMgr::onEdit(bool)
521 {
522   QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects();
523   FeaturePtr aFeature;
524   foreach(ObjectPtr aObj, aObjects) {
525     aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
526     if (aFeature.get())
527       break;
528   }
529   if (aFeature.get() == NULL) {
530     ResultParameterPtr aParam;
531     foreach(ObjectPtr aObj, aObjects) {
532       aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObj);
533       if (aParam.get())
534         break;
535     }
536     if (aParam.get() != NULL)
537       aFeature = ModelAPI_Feature::feature(aParam);
538   }
539   if (aFeature.get() != NULL)
540     myModule->editFeature(aFeature);
541 }
542
543 bool PartSet_MenuMgr::eventFilter(QObject* theObj, QEvent* theEvent)
544 {
545   if (theEvent->type() == QEvent::MouseButtonDblClick) {
546     SessionPtr aMgr = ModelAPI_Session::get();
547     if (aMgr->activeDocument() != aMgr->moduleDocument())
548       activatePartSet();
549   }
550   return QObject::eventFilter(theObj, theEvent);
551 }