Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / NewGeom / NewGeom_Module.cpp
index 7285933d12304a230923c714c7e4c3206a733da5..2b7e8e5c9ec49ce41af79c52300d840ac1d488fa 100644 (file)
@@ -2,25 +2,29 @@
 
 #include "NewGeom_Module.h"
 #include "NewGeom_DataModel.h"
+#include "NewGeom_OCCSelector.h"
 
 #include <XGUI_Workshop.h>
+#include <XGUI_PropertyPanel.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_OCCSelector.h>
 #include <OCCViewer_ViewModel.h>
-#include <SUIT_Selector.h>
 
+#include <SUIT_Selector.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 
 #include <QtxActionMenuMgr.h>
 
+#include <QDockWidget>
+
 extern "C" {
   NewGeom_EXPORT CAM_Module* createModule() {
     return new NewGeom_Module();
   }
-  
+    
   NewGeom_EXPORT char* getModuleVersion() {
     return "0.0";
   }
@@ -29,9 +33,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);
 }
 
 //******************************************************
@@ -66,15 +71,46 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
   if (isDone) {
     setMenuShown( true );
     setToolShown( true );
-
-    SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type());
-    if (aMgr) {
-      OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(aMgr->getViewModel());
+    myWorkshop->propertyPanel()->hide();
+
+    if (!mySelector) {
+      ViewManagerList OCCViewManagers;
+      application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
+      if (OCCViewManagers.size() > 0) {
+        mySelector = createSelector(OCCViewManagers.first());
+      }
     }
   }
   return isDone;
 }
 
+//******************************************************
+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;
+}
+
 //******************************************************
 bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
 {
@@ -171,20 +207,22 @@ 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();
+  myWorkshop->salomeViewerSelectionChanged();
 }