Salome HOME
Merge Dev_2.1.0 with PythonAPI branch
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.cpp
index 28013c9df0d51abdfbe71b16c82de80c221718d2..d2a2f4efec3e7a80509ad230b6df387ae52fbaca 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <QAction>
 #include <QMenu>
+#include <QEvent>
 
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
@@ -149,28 +150,7 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*
         // Find coincident in these coordinates
         ObjectPtr aObj = aPrsList.first().object();
         FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-        const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
-        std::set<AttributePtr>::const_iterator aIt;
-        FeaturePtr aCoincident;
-        for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
-          std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
-          FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
-          if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
-            std::shared_ptr<GeomAPI_Pnt2d> a2dPnt = 
-              PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
-            if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { 
-              aCoincident = aConstrFeature;
-              break;
-            } else {
-              a2dPnt = PartSet_Tools::getPoint(aConstrFeature,
-                                               SketchPlugin_ConstraintCoincidence::ENTITY_B());
-              if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { 
-                aCoincident = aConstrFeature;
-                break;
-              }
-            }
-          }
-        }
+        FeaturePtr aCoincident = PartSet_Tools::findFirstCoincidence(aFeature, aSelPnt);
         // If we have coincidence then add Detach menu
         if (aCoincident.get() != NULL) {
           mySelectedFeature = aCoincident;
@@ -527,3 +507,13 @@ void PartSet_MenuMgr::onSelectParentFeature()
   aSelection.append( aParentFeature );
   myModule->workshop()->selection()->setSelectedObjects( aSelection );
 }
+
+bool PartSet_MenuMgr::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+  if (theEvent->type() == QEvent::MouseButtonDblClick) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    if (aMgr->activeDocument() != aMgr->moduleDocument())
+      activatePartSet();
+  }
+  return QObject::eventFilter(theObj, theEvent);
+}
\ No newline at end of file