]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create pop-up menu in 3d viewer
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 6 Jun 2014 15:19:21 +0000 (19:19 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 6 Jun 2014 15:19:21 +0000 (19:19 +0400)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ContextMenuMgr.h
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_Workshop.cpp

index b114aa3157d40f89b315244fa07720e1a7da10b5..a02f1d2dc397bc3a573ad4e54727067e52ba7883 100644 (file)
@@ -4,6 +4,8 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_SelectionMgr.h"
 #include "XGUI_Displayer.h"
+#include "XGUI_MainWindow.h"
+#include "XGUI_Viewer.h"
 
 #include "PartSetPlugin_Part.h"
 
@@ -14,6 +16,7 @@
 #include <QAction>
 #include <QContextMenuEvent>
 #include <QMenu>
+#include <QMdiArea>
 
 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) :
 QObject(theParent), myWorkshop(theParent)
@@ -81,8 +84,11 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
   QMenu* aMenu = 0;
   if (sender() == myWorkshop->objectBrowser())
     aMenu = objectBrowserMenu();
-
-  if (aMenu) {
+  else if (sender() == myWorkshop->mainWindow()->viewer()) {
+    aMenu = viewerMenu();
+  }
+  
+  if (aMenu && (aMenu->actions().size() > 0)) {
     aMenu->exec(theEvent->globalPos());
     delete aMenu;
   }
@@ -132,8 +138,38 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
   return 0;
 }
 
+QMenu* XGUI_ContextMenuMgr::viewerMenu() const
+{
+  QMenu* aMenu = new QMenu();
+  XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+  QFeatureList aFeatures = aSelMgr->selectedFeatures();
+  if (aFeatures.size() > 0) {
+    if (aFeatures.size() > 0)
+      aMenu->addAction(action("EDIT_CMD"));
+    aMenu->addAction(action("HIDE_CMD"));
+    aMenu->addAction(action("DELETE_CMD"));
+  }
+  QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
+  if (aMDI->actions().size() > 0) {
+    QMenu* aSubMenu = aMenu->addMenu(tr("Windows"));
+    aSubMenu->addActions(aMDI->actions());
+  }
+  if (aMenu->actions().size() > 0) {
+    return aMenu;
+  }
+  delete aMenu;
+  return 0;
+}
+
 void XGUI_ContextMenuMgr::connectObjectBrowser() const
 {
   connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), 
     this, SLOT(onContextMenuRequest(QContextMenuEvent*)));
-}
\ No newline at end of file
+}
+
+void XGUI_ContextMenuMgr::connectViewer() const
+{
+  // TODO: Adapt to SALOME mode
+  connect(myWorkshop->mainWindow()->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), 
+    this, SLOT(onContextMenuRequest(QContextMenuEvent*)));
+}
index 3ce0051fda314ed9624d02be22465e2b5750df58..a8255ff0cab25dc269bf109b82d373c7574c6280 100644 (file)
@@ -31,6 +31,8 @@ public:
 
   void connectObjectBrowser() const;
 
+  void connectViewer() const;
+
 signals:
   void actionTriggered(const QString& theId, bool isChecked);
 
@@ -41,6 +43,7 @@ private slots:
 
 private:
   QMenu* objectBrowserMenu() const;
+  QMenu* viewerMenu() const;
 
   QMap<QString, QAction*> myActions;
 
index 7ce708e65fe4e12e7c3faf5fbeb521512428d71e..ced60958b38a5855824c27001d6c39c258c155c2 100644 (file)
@@ -444,21 +444,22 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
     if (part() == theFeature) 
       return aIndex;
 
-    std::string aGroup = theFeature->getGroup();
+    //std::string aGroup = theFeature->getGroup();
     DocumentPtr aDoc = theFeature->document();
-    int aNb = aDoc->size(aGroup);
+    int aNb = aDoc->size(FEATURES_GROUP);
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (aDoc->feature(aGroup, i) == theFeature) {
+      if (aDoc->feature(FEATURES_GROUP, i) == theFeature) {
         aRow = i;
         break;
       }
     }
     if (aRow != -1) {
-      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+      return createIndex(aRow + 3, 0, (qint32) HistoryObject);
+/*      if (aGroup.compare(PARAMETERS_GROUP) == 0)
         return createIndex(aRow, 0, (qint32) ParamObject);
       if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
-        return createIndex(aRow, 0, (qint32) ConstructObject);
+        return createIndex(aRow, 0, (qint32) ConstructObject);*/
     }
   }
   return aIndex;
index db719599f1fe25c91454020efc937b3d2ef5c9e3..ff33f60eb7b4c9a48e0539c9890f1d6b8b1a51b5 100644 (file)
@@ -444,10 +444,10 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView)
     connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)),
             this,    SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)));
 
-    connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
-            this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
-    //connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
-    //        this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
+    //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
+    //        this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
+    connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
+            this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
 
     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
             this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
@@ -590,29 +590,29 @@ void XGUI_Viewer::updateViewsDrawMode() const
 }
 
 //******************************************************
-void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
-{
-  XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
-  if (!aWnd) return;
-
-  QMenu aMenu;
-
-  // Include Viewer actions
-  if (myActions.size() > 0) {
-    aMenu.addActions(myActions);
-    aMenu.addSeparator();
-  }
-  if (aWnd->actions().size() > 0) {
-    aMenu.addActions(aWnd->actions());
-    aMenu.addSeparator();
-  }
-
-  QMdiArea* aMDI = myMainWindow->mdiArea();
-  if (aMenu.actions().size() > 0) {
-    QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
-    aSubMenu->addActions(aMDI->actions());
-  } else {
-    aMenu.addActions(aMDI->actions());
-  }
-  aMenu.exec(theEvent->globalPos());
-}
\ No newline at end of file
+//void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
+//{
+//  XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
+//  if (!aWnd) return;
+//
+//  QMenu aMenu;
+//
+//  // Include Viewer actions
+//  if (myActions.size() > 0) {
+//    aMenu.addActions(myActions);
+//    aMenu.addSeparator();
+//  }
+//  if (aWnd->actions().size() > 0) {
+//    aMenu.addActions(aWnd->actions());
+//    aMenu.addSeparator();
+//  }
+//
+//  QMdiArea* aMDI = myMainWindow->mdiArea();
+//  if (aMenu.actions().size() > 0) {
+//    QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
+//    aSubMenu->addActions(aMDI->actions());
+//  } else {
+//    aMenu.addActions(aMDI->actions());
+//  }
+//  aMenu.exec(theEvent->globalPos());
+//}
index d85a160cf9edbf96c33e98cdce185eb2e4aec4be..664e58b2b772126e0d892c6ff6a1f11e733c905c 100644 (file)
@@ -156,6 +156,8 @@ signals:
   void activated(XGUI_ViewWindow* theWindow);
   void selectionChanged();
 
+  void contextMenuRequested(QContextMenuEvent*);
+
 public slots:
   void onWindowMinimized(QMdiSubWindow*);
   void onWindowActivated(QMdiSubWindow*);
@@ -165,7 +167,7 @@ private slots:
   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
   void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
-  void onContextMenuRequested(QContextMenuEvent* theEvent);
+  //void onContextMenuRequested(QContextMenuEvent* theEvent);
 
 private:
   void addView(QMdiSubWindow* theView);
index ca06c5e1f6007d6f78b9c616384d21a00e475bdd..0cbafb0458900478340ab074670918c8ba172262 100644 (file)
@@ -433,6 +433,7 @@ void XGUI_Workshop::onNew()
   if (!isSalomeMode()) {
     myMainWindow->showPythonConsole();
     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
+    myContextMenuMgr->connectViewer();
     aWnd->showMaximized();
     updateCommandStatus();
   }
@@ -832,8 +833,11 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList)
           aFeature = aObject->featureRef();
         }
       }
+      if (myDisplayer->isVisible(aFeature))
+        myDisplayer->erase(aFeature, false);
       aFeature->document()->removeFeature(aFeature);
     }
+    myDisplayer->updateViewer();
     aMgr->rootDocument()->finishOperation();
   }
 }