Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.cpp
index 28013c9df0d51abdfbe71b16c82de80c221718d2..f39331b6270ec89594ad50fb38349e03c71d8cbc 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;
@@ -467,6 +447,7 @@ void PartSet_MenuMgr::onActivatePart(bool)
     }
     if (aPart.get())
       aPart->activate();
+      myModule->workshop()->updateCommandStatus();
   }
 }
 
@@ -485,6 +466,8 @@ void PartSet_MenuMgr::activatePartSet() const
   if (isNewTransaction) aMgr->startOperation("Activation");
   aMgr->setActiveDocument(aMgr->moduleDocument());
   if (isNewTransaction) aMgr->finishOperation();
+
+  myModule->workshop()->updateCommandStatus();
 }
 
 void PartSet_MenuMgr::grantedOperationIds(ModuleBase_Operation* theOperation,
@@ -527,3 +510,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