]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Interface to Salome Viewer is created (issue #31)
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Apr 2014 07:40:58 +0000 (11:40 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Apr 2014 07:40:58 +0000 (11:40 +0400)
src/NewGeom/CMakeLists.txt
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/NewGeom/NewGeom_SalomeViewer.cpp [new file with mode: 0644]
src/NewGeom/NewGeom_SalomeViewer.h [new file with mode: 0644]
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_SalomeViewer.h [new file with mode: 0644]
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 4d7a3b3e4ccd9e859dfcc62ca137b95080f0c01a..31e82979299a5a97450fa5335e95cf26314e2ba8 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
        NewGeom_Module.h
        NewGeom_DataModel.h
        NewGeom_OCCSelector.h
+       NewGeom_SalomeViewer.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -18,6 +19,7 @@ SET(PROJECT_SOURCES
        NewGeom_Module.cpp
        NewGeom_DataModel.cpp
        NewGeom_OCCSelector.cpp
+       NewGeom_SalomeViewer.cpp
 )
 
 SET(PROJECT_RESOURCES
index 8d1b9624646b31d0c800b0b3a199c4ed6b607518..7ef9d61f18c100692f12f54a3bec8d58f1196d1c 100644 (file)
@@ -33,6 +33,7 @@ NewGeom_Module::NewGeom_Module()
 : LightApp_Module( "NewGeom" ), mySelector(0)
 {
   myWorkshop = new XGUI_Workshop(this);
+  myProxyViewer = new NewGeom_SalomeViewer(this);
 }
 
 //******************************************************
@@ -100,6 +101,7 @@ NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
     foreach(SUIT_Selector* aSel, aList) {
       aSel->setEnabled(aSel == aSelector);
     }
+    myProxyViewer->setSelector(aSelector);
     return aSelector;
   }
   return 0;
@@ -214,17 +216,6 @@ QStringList NewGeom_Module::nestedActions(const QString& theId) const
   return QStringList();
 }
 
-//******************************************************
-Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const
-{
-  Handle(AIS_InteractiveContext) aContext;
-  OCCViewer_Viewer* aViewer = mySelector->viewer();
-  if (aViewer) {
-    aContext = aViewer->getAISContext();
-  }
-  return aContext;
-}
-
 //******************************************************
 void NewGeom_Module::selectionChanged()
 {
index 65e048e40cdb64240d0ea09a0d4547f0efd56589..9b63a18c636955e24e04e6347f39fb6f0151bed5 100644 (file)
@@ -4,6 +4,7 @@
 #define NewGeom_Module_H
 
 #include "NewGeom.h"
+#include "NewGeom_SalomeViewer.h"
 
 #include <LightApp_Module.h>
 #include <XGUI_SalomeConnector.h>
@@ -14,6 +15,7 @@
 class XGUI_Workshop; 
 class NewGeom_OCCSelector;
 class OCCViewer_Viewer;
+
 /** 
 * An implementation of SALOME connector class for implementation of
 * XGUI functionality as a module of SALOME
@@ -67,8 +69,8 @@ public:
   //! Returns list of nested actions according to the given command ID
   virtual QStringList nestedActions(const QString& theId) const;
 
-  //! Returns AIS_InteractiveContext from current OCCViewer
-  virtual Handle(AIS_InteractiveContext) AISContext() const;
+  //! Returns interface to Salome viewer
+  virtual XGUI_SalomeViewer* viewer() const { return myProxyViewer; }
 
 public slots:
   virtual bool activateModule( SUIT_Study* theStudy);
@@ -90,6 +92,8 @@ private:
 
   NewGeom_OCCSelector* mySelector;
 
+  NewGeom_SalomeViewer* myProxyViewer;
+
   QMap<QString, QStringList> myNestedActions;
 };
 
diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp
new file mode 100644 (file)
index 0000000..ff58fa0
--- /dev/null
@@ -0,0 +1,101 @@
+
+#include "NewGeom_SalomeViewer.h"
+#include "NewGeom_OCCSelector.h"
+
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
+
+#include <SUIT_ViewManager.h>
+
+NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
+: XGUI_SalomeViewer(theParent), mySelector(0)
+{
+}
+
+
+Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
+{
+  return mySelector->viewer()->getAISContext();
+}
+
+Handle(V3d_Viewer) NewGeom_SalomeViewer::V3dViewer() const
+{
+  return mySelector->viewer()->getViewer3d();
+}
+
+Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
+{
+  OCCViewer_Viewer* aViewer = mySelector->viewer();
+  SUIT_ViewManager* aMgr = aViewer->getViewManager();
+  OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
+  return aWnd->getViewPort()->getView();
+}
+
+void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
+{
+  if (mySelector) {
+    if (mySelector == theSel)
+      return;
+    else {
+      mySelector->viewer()->getViewManager()->disconnect(this);
+    }
+  }
+  mySelector = theSel;
+  OCCViewer_Viewer* aViewer = mySelector->viewer();
+  SUIT_ViewManager* aMgr = aViewer->getViewManager();
+
+  connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)),
+          this, SIGNAL(lastViewClosed()));
+  connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)),
+          this, SIGNAL(tryCloseView()));
+  connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)),
+          this, SIGNAL(deleteView()));
+  connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)),
+          this, SIGNAL(viewCreated()));
+  connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)),
+          this, SIGNAL(activated()));
+
+  connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+  connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+  connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
+  connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
+  connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
+          this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
+  connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)),
+          this, SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
+}
+
+
+void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mousePress(theEvent);
+}
+
+void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseRelease(theEvent);
+}
+
+void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseDoubleClick(theEvent);
+}
+
+void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseMove(theEvent);
+}
+
+void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
+{
+  emit keyPress(theEvent);
+}
+
+void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
+{
+  emit keyRelease(theEvent);
+}
diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h
new file mode 100644 (file)
index 0000000..b6316e2
--- /dev/null
@@ -0,0 +1,49 @@
+
+
+#ifndef NewGeom_SalomeViewer_H
+#define NewGeom_SalomeViewer_H
+
+#include "NewGeom.h"
+
+#include <XGUI_SalomeViewer.h>
+
+class SUIT_ViewWindow;
+class QMouseEvent;
+class QKeyEvent;
+
+class NewGeom_OCCSelector;
+
+class NewGeom_SalomeViewer: public XGUI_SalomeViewer
+{
+  Q_OBJECT
+public:
+  NewGeom_SalomeViewer(QObject* theParent);
+
+  //! Returns AIS_InteractiveContext from current OCCViewer
+  virtual Handle(AIS_InteractiveContext) AISContext() const;
+
+  //! Retrurns V3d_Vioewer from current viewer
+  virtual Handle(V3d_Viewer) V3dViewer() const;
+
+  //! Returns Vsd_View object from currently active view window
+  virtual Handle(V3d_View) activeView() const;
+
+  void setSelector(NewGeom_OCCSelector* theSel);
+
+  NewGeom_OCCSelector* selector() const { return mySelector; }
+
+private slots:
+  void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
+  void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
+  void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
+  void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
+  void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
+  void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
+
+
+private:
+  NewGeom_OCCSelector* mySelector;
+
+};
+
+#endif
index d8de8a441ad697af43190a3fe5aa38200e6af2e6..00eed0ffec3c4e020e7d93692418f047b1245233 100644 (file)
@@ -28,6 +28,7 @@ SET(PROJECT_HEADERS
     XGUI_SalomeConnector.h
     XGUI_ActionsMgr.h
     XGUI_ErrorDialog.h
+    XGUI_SalomeViewer.h
 )
 
 SET(PROJECT_AUTOMOC 
index f6e89cf17fe5da5f3639a29771eaff0a0fc2f7df..a55398cb15ef6db5ab732f78739dd6ecd0411e4b 100644 (file)
@@ -3,11 +3,11 @@
 
 #include "XGUI.h"
 
-#include <AIS_InteractiveContext.hxx>
 #include <QString>
 #include <QStringList>
 
 class QMainWindow;
+class XGUI_SalomeViewer;
 
 /**
 * An interface which provides a connection of XGUI functionality 
@@ -73,9 +73,9 @@ public:
 
   //! Returns list of nested actions according to the given command ID
   virtual QStringList nestedActions(const QString& theId) const = 0;
-  
-  //! Returns AIS_InteractiveContext from current OCCViewer
-  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+
+  //! Returns interface to Salome viewer
+  virtual XGUI_SalomeViewer* viewer() const = 0;
 };
 
 #endif
\ No newline at end of file
diff --git a/src/XGUI/XGUI_SalomeViewer.h b/src/XGUI/XGUI_SalomeViewer.h
new file mode 100644 (file)
index 0000000..3ecd6e3
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef XGUI_SALOMEVIEWER_H
+#define XGUI_SALOMEVIEWER_H
+
+#include "XGUI.h"
+
+#include <QObject>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_View.hxx>
+
+class QMouseEvent;
+class QKeyEvent;
+
+/**
+* A Base object for definition of connector object to
+* Salome Viewer. Reimplemented in NewGeom_SalomeViewer class
+*/
+class XGUI_EXPORT XGUI_SalomeViewer: public QObject
+{
+  Q_OBJECT
+public:
+  XGUI_SalomeViewer(QObject* theParent):QObject(theParent) {}
+
+  //! Returns AIS_InteractiveContext from current OCCViewer
+  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+
+  //! Retrurns V3d_Vioewer from current viewer
+  virtual Handle(V3d_Viewer) V3dViewer() const = 0;
+
+  //! Returns Vsd_View object from currently active view window
+  virtual Handle(V3d_View) activeView() const = 0;
+
+signals:
+  void lastViewClosed();
+  void tryCloseView();
+  void deleteView();
+  void viewCreated();
+  void mousePress(QMouseEvent* theEvent);
+  void mouseRelease(QMouseEvent* theEvent);
+  void mouseDoubleClick(QMouseEvent* theEvent);
+  void mouseMove(QMouseEvent* theEvent);
+  void keyPress(QKeyEvent* theEvent);
+  void keyRelease(QKeyEvent* theEvent);
+  void activated();
+
+};
+
+#endif
\ No newline at end of file
index 0bba0d847e44253acc5379e70d42b3c64deef85b..d117c1dea114bf86de617a1aee1bc4dfab7d0e30 100644 (file)
@@ -4,6 +4,7 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_Viewer.h"
 #include "XGUI_SalomeConnector.h"
+#include "XGUI_SalomeViewer.h"
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_PluginManager.h>
@@ -69,7 +70,7 @@ QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
 {
   if (myWorkshop->isSalomeMode()) {
-    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext();
+    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeViewer()->AISContext();
     theList.Clear();
     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
       theList.Append(aContext->SelectedInteractive());
@@ -84,7 +85,7 @@ void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList)
 {
   if (myWorkshop->isSalomeMode()) {
     theList.Clear();
-    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext();
+    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeViewer()->AISContext();
     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
       TopoDS_Shape aShape = aContext->SelectedShape();
       if (!aShape.IsNull())
@@ -94,4 +95,4 @@ void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList)
     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
     aViewer->getSelectedShapes(theList);
   }
-}
\ No newline at end of file
+}
index 90cb04fc3f3a21adf8f1e2e8bfdfbf5ad0d22ca1..912fa36dbffe0d08df570149ed25eefc36bb60c4 100644 (file)
@@ -14,6 +14,7 @@
 #include "XGUI_Displayer.h"
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
+#include "XGUI_SalomeViewer.h"
 #include "XGUI_ActionsMgr.h"
 #include "XGUI_ErrorDialog.h"
 
@@ -690,7 +691,7 @@ XGUI_Displayer* XGUI_Workshop::displayer() const
   if (!myDisplayer) {
     XGUI_Workshop* that = (XGUI_Workshop*)this;
     that->myDisplayer = isSalomeMode() ?
-      new XGUI_Displayer(salomeConnector()->AISContext()):
+      new XGUI_Displayer(salomeViewer()->AISContext()):
       new XGUI_Displayer(myMainWindow->viewer()->AISContext());
   }
   return myDisplayer;
@@ -717,3 +718,10 @@ void XGUI_Workshop::salomeViewerSelectionChanged()
 {
   emit salomeViewerSelection();
 }
+
+
+//**************************************************************
+XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const 
+{ 
+  return mySalomeConnector->viewer(); 
+}
index 41ac3b14420d9b6dac365184cb1227befd83aefb..d908ff5efb5b53c0a1b171caadcaf20a3bab75ff 100644 (file)
@@ -20,6 +20,8 @@ class XGUI_SalomeConnector;
 class XGUI_ObjectsBrowser;
 class XGUI_ActionsMgr;
 class XGUI_ErrorDialog;
+class XGUI_SalomeViewer;
+
 class ModuleBase_Operation;
 class ModuleBase_PropPanelOperation;
 
@@ -68,8 +70,12 @@ public:
   //! Redefinition of Events_Listener method
   virtual void processEvent(const Events_Message* theMessage);
 
+  //! Returns an object which provides interface to Salome Module (LightApp_Module)
   XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
 
+  //! Provides an object which provides interface to Salome Viewer
+  XGUI_SalomeViewer* salomeViewer() const;
+
   //! Returns true if the application works as SALOME module
   bool isSalomeMode() const { return mySalomeConnector != 0; }