Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.cpp
index b191e7fa31e2e54c65425ab2b9ad20e0cd35d71e..a74824431b559a7be3066491d82b2b33fa344597 100644 (file)
@@ -4,6 +4,9 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_SelectionMgr.h"
 
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+
 #include <QAction>
 #include <QContextMenuEvent>
 #include <QMenu>
@@ -22,6 +25,15 @@ void XGUI_ContextMenuMgr::createActions()
 {
   QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
   addAction("EDIT_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/activate.png"), tr("Activate"), this);
+  addAction("ACTIVATE_PART_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this);
+  addAction("DEACTIVATE_PART_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
+  addAction("DELETE_CMD", aAction);
 }
 
 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
@@ -69,16 +81,38 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
 
 QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
 {
+  QList<QAction*> aActions;
   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
   QFeatureList aFeatures = aSelMgr->selectedFeatures();
   if (aFeatures.size() == 1) {
+    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
     FeaturePtr aFeature = aFeatures.first();
-    if (aFeature->getKind() != "Part") {
-      QMenu* aMenu = new QMenu();
-      aMenu->addAction(action("EDIT_CMD"));
-      return aMenu;
+    //Process Feature
+    if (aFeature) {
+      if (aFeature->getKind() == "Part") {
+        boost::shared_ptr<ModelAPI_Document> aFeaDoc = aFeature->data()->docRef("PartDocument")->value();
+        if (aMgr->currentDocument() == aFeaDoc)
+          aActions.append(action("DEACTIVATE_PART_CMD"));
+        else 
+          aActions.append(action("ACTIVATE_PART_CMD"));
+      } else {
+        aActions.append(action("EDIT_CMD"));
+      }
+      aActions.append(action("DELETE_CMD"));
+
+    // Process Root object (document)
+    } else { // If feature is 0 the it means that selected root object (document)
+      if (aMgr->currentDocument() != aMgr->rootDocument()) {
+        aActions.append(action("ACTIVATE_PART_CMD"));
+      }
     }
   }
+  aActions.append(myWorkshop->objectBrowser()->actions());
+  if (aActions.size() > 0) {
+    QMenu* aMenu = new QMenu();
+    aMenu->addActions(aActions);
+    return aMenu;
+  }
   return 0;
 }