Salome HOME
The external feature should be executed manually in order to return first result.
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.cpp
index e09654f96a5b21e1ba5a4fc312e9f2d567c50c4b..9b5919c20d411df18d759c8cbe87ccc36781c5ee 100644 (file)
@@ -26,6 +26,8 @@
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_Displayer.h>
+#include <XGUI_DataModel.h>
+#include <XGUI_ObjectsBrowser.h>
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
@@ -86,6 +88,11 @@ void PartSet_MenuMgr::createActions()
   aAction = new QAction(QIcon(":icons/edit.png"), tr("Edit..."), this);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onEdit(bool)));
   myActions["EDIT_CMD"] = aAction;
+
+  aAction = new QAction(QIcon(), tr("Select parent feature"), this);
+  aAction->setCheckable(false);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSelectParentFeature()));
+  myActions["SELECT_PARENT_CMD"] = aAction;
 }
 
 
@@ -113,7 +120,7 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*
   bool hasAttribute = false;
   bool hasFeature = false;
 
-  QList<ModuleBase_ViewerPrs> aPrsList = aSelection->getSelected(ModuleBase_ISelection::AllControls);
+  QList<ModuleBase_ViewerPrs> aPrsList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
   TopoDS_Shape aShape;
   ResultPtr aResult;
   FeaturePtr aFeature;
@@ -205,6 +212,23 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*
   return true;
 }
 
+void PartSet_MenuMgr::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
+{
+  ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
+
+  bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+                        PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (isActiveSketch) {
+    theStdActions["WIREFRAME_CMD"]->setEnabled(false);
+    theStdActions["SHADING_CMD"]->setEnabled(false);
+    theStdActions["SHOW_ONLY_CMD"]->setEnabled(false);
+    theStdActions["SHOW_CMD"]->setEnabled(false);
+    theStdActions["HIDE_CMD"]->setEnabled(false);
+    theStdActions["HIDEALL_CMD"]->setEnabled(false);
+  }
+}
+
+
 void PartSet_MenuMgr::onLineHighlighted(QAction* theAction)
 {
   if (myPrevId != -1) {
@@ -283,12 +307,10 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction)
       anOperation->abort();
 
     SessionPtr aMgr = ModelAPI_Session::get();
-    std::set<FeaturePtr> anIgnoredFeatures;
-    anIgnoredFeatures.insert(myModule->sketchMgr()->activeSketch());
 
     QString aName = tr("Detach %1").arg(aLine->data()->name().c_str());
     aMgr->startOperation(aName.toStdString());
-    aWorkshop->deleteFeatures(aToDelFeatures, anIgnoredFeatures);
+    aWorkshop->deleteFeatures(aToDelFeatures);
     aMgr->finishOperation();
   }
   myCoinsideLines.clear();
@@ -466,3 +488,20 @@ void PartSet_MenuMgr::onEdit(bool)
   if (aFeature.get() != NULL)
     myModule->editFeature(aFeature);
 }
+
+void PartSet_MenuMgr::onSelectParentFeature()
+{
+  QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects();
+  if (aObjects.size() != 1)
+    return;
+
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>( aObjects.first() );
+  if( !aResult.get() )
+    return;
+
+  FeaturePtr aParentFeature = aResult->document()->feature( aResult );
+  QObjectPtrList aSelection;
+  aSelection.append( aParentFeature );
+  myModule->workshop()->selection()->setSelectedObjects( aSelection );
+}