Salome HOME
Provide connection of new features in SALOME module
[modules/shaper.git] / src / NewGeom / NewGeom_Module.cpp
index ee68ba0c91d0ac5947dec781ea33d085fa4206d7..fc07f5d55bf7f280db540e4aed232fa1fc4e5585 100644 (file)
@@ -2,23 +2,32 @@
 
 #include "NewGeom_Module.h"
 #include "NewGeom_DataModel.h"
+#include "NewGeom_OCCSelector.h"
 
 #include <XGUI_Workshop.h>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_ContextMenuMgr.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_OCCSelector.h>
 #include <OCCViewer_ViewModel.h>
 
+#include <SUIT_Selector.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 
+#include <QtxPopupMgr.h>
 #include <QtxActionMenuMgr.h>
 
+#include <QDockWidget>
+#include <QAction>
 
 extern "C" {
   NewGeom_EXPORT CAM_Module* createModule() {
     return new NewGeom_Module();
   }
-  
+    
   NewGeom_EXPORT char* getModuleVersion() {
     return "0.0";
   }
@@ -27,9 +36,10 @@ extern "C" {
 
 //******************************************************
 NewGeom_Module::NewGeom_Module()
-: LightApp_Module( "NewGeom" )
+: LightApp_Module( "NewGeom" ), mySelector(0)
 {
   myWorkshop = new XGUI_Workshop(this);
+  myProxyViewer = new NewGeom_SalomeViewer(this);
 }
 
 //******************************************************
@@ -64,6 +74,17 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
   if (isDone) {
     setMenuShown( true );
     setToolShown( true );
+
+    if (!mySelector) {
+      ViewManagerList OCCViewManagers;
+      application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
+      if (OCCViewManagers.size() > 0) {
+        mySelector = createSelector(OCCViewManagers.first());
+      }
+    }
+    myWorkshop->propertyPanel()->hide();
+    QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
+    action(myEraseAll)->setEnabled(false);
   }
   return isDone;
 }
@@ -73,9 +94,37 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
 {
   setMenuShown( false );
   setToolShown( false );
+  //myWorkshop->contextMenuMgr()->disconnectViewer();
   return LightApp_Module::deactivateModule(theStudy);
 }
 
+//******************************************************
+void NewGeom_Module::onViewManagerAdded( SUIT_ViewManager* theMgr )
+{
+  if ((!mySelector)) {
+    mySelector = createSelector(theMgr);
+  }
+}
+
+//******************************************************
+NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
+{
+  if (theMgr->getType() == OCCViewer_Viewer::Type()) {
+    OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
+    NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, 
+                                                             getApp()->selectionMgr());
+    LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
+    QList<SUIT_Selector*> aList;
+    aMgr->selectors(aList);
+    foreach(SUIT_Selector* aSel, aList) {
+      aSel->setEnabled(aSel == aSelector);
+    }
+    myProxyViewer->setSelector(aSelector);
+    return aSelector;
+  }
+  return 0;
+}
+
 //******************************************************
 CAM_DataModel* NewGeom_Module::createDataModel()
 {
@@ -83,15 +132,13 @@ CAM_DataModel* NewGeom_Module::createDataModel()
 }
 
 //******************************************************
-void NewGeom_Module::addFeature(const QString& theWBName,
-                                const QString& theId, 
-                                const QString& theTitle, 
-                                const QString& theTip,
-                                const QIcon& theIcon, 
-                                bool isCheckable,
-                                QObject* theReciever,
-                                const char* theMember,
-                                const QKeySequence& theKeys)
+QAction* NewGeom_Module::addFeature(const QString& theWBName,
+                                    const QString& theId, 
+                                    const QString& theTitle, 
+                                    const QString& theTip,
+                                    const QIcon& theIcon, 
+                                    const QKeySequence& theKeys,
+                                    bool isCheckable)
 {
   int aMenu = createMenu(theWBName, -1, -1, 50);
   int aTool = createTool(theWBName);
@@ -102,21 +149,21 @@ void NewGeom_Module::addFeature(const QString& theWBName,
   int aKeys = 0;
   for (int i = 0; i < theKeys.count(); i++) 
     aKeys += theKeys[i];
-  createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
-               isCheckable, theReciever, theMember);
+  QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
+                                  isCheckable);
+  aAction->setData(theId);
   int aItemId = createMenu( aId,  aMenu, -1, 10 );
   int aToolId = createTool( aId, aTool );
+  return aAction;
 }
 
 //******************************************************
-void NewGeom_Module::addEditCommand(const QString& theId,
-                                    const QString& theTitle,
-                                    const QString& theTip,
-                                    const QIcon& theIcon, 
-                                    bool isCheckable,
-                                    QObject* theReciever,
-                                    const char* theMember,
-                                    const QKeySequence& theKeys)
+QAction* NewGeom_Module::addEditCommand(const QString& theId,
+                                        const QString& theTitle,
+                                        const QString& theTip,
+                                        const QIcon& theIcon, 
+                                        const QKeySequence& theKeys,
+                                        bool isCheckable)
 {
   int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
 
@@ -126,9 +173,11 @@ void NewGeom_Module::addEditCommand(const QString& theId,
   int aKeys = 0;
   for (int i = 0; i < theKeys.count(); i++) 
     aKeys += theKeys[i];
-  createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
-               isCheckable, theReciever, theMember);
+  QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
+                                  isCheckable);
+  aAction->setData(theId);
   createMenu( aId, aMenu, 10 );
+  return aAction;
 }
 
 //******************************************************
@@ -138,6 +187,21 @@ void NewGeom_Module::addEditMenuSeparator()
   createMenu( separator(), aMenu, -1, 10 );
 }
 
+//******************************************************
+QList<QAction*> NewGeom_Module::commandList() const
+{
+  QList<QAction*> aActions;
+  for (int i = 0; i < myActionsList.size(); i++)
+    aActions.append(action(i));
+  return aActions;
+}
+
+//******************************************************
+QStringList NewGeom_Module::commandIdList() const
+{
+  return myActionsList;
+}
+
 //******************************************************
 QMainWindow* NewGeom_Module::desktop() const
 {
@@ -164,13 +228,29 @@ QAction* NewGeom_Module::command(const QString& theId) const
 }
 
 //******************************************************
-Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const
+void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions)
 {
-  Handle(AIS_InteractiveContext) aContext;
-  SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type());
-  if (aMgr) {
-    OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(aMgr->getViewModel());
-    aContext = aViewer->getAISContext();
-  }
-  return aContext;
+  myNestedActions[theId] = theActions;
+}
+
+//******************************************************
+QStringList NewGeom_Module::nestedActions(const QString& theId) const
+{
+  if (myNestedActions.contains(theId))
+    return myNestedActions[theId];
+  return QStringList();
+}
+
+//******************************************************
+void NewGeom_Module::selectionChanged()
+{
+  LightApp_Module::selectionChanged();
+  myWorkshop->salomeViewerSelectionChanged();
+}
+
+//******************************************************
+void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
+{
+  myWorkshop->contextMenuMgr()->addViewerItems(theMenu);
+  LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
 }
\ No newline at end of file