]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
(Issue #31) Proxy viewer created in order to provide uniform dispatching of events...
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Apr 2014 11:22:32 +0000 (15:22 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Apr 2014 11:22:32 +0000 (15:22 +0400)
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_SalomeViewer.h
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_ViewerProxy.cpp [new file with mode: 0644]
src/XGUI/XGUI_ViewerProxy.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index ff58fa0db21222415a88df30e438590a59068c8c..c81d706ab769bf52b00f4d2cad4d05f12c0f76e6 100644 (file)
@@ -18,7 +18,7 @@ Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
   return mySelector->viewer()->getAISContext();
 }
 
-Handle(V3d_Viewer) NewGeom_SalomeViewer::V3dViewer() const
+Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
 {
   return mySelector->viewer()->getViewer3d();
 }
index b6316e2b3fb37790587821924bf4c054f6ef1a3e..b84c5bc4a5a3e7cde576ef7a9365803ba0cc38a9 100644 (file)
@@ -23,7 +23,7 @@ public:
   virtual Handle(AIS_InteractiveContext) AISContext() const;
 
   //! Retrurns V3d_Vioewer from current viewer
-  virtual Handle(V3d_Viewer) V3dViewer() const;
+  virtual Handle(V3d_Viewer) v3dViewer() const;
 
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const;
index 00eed0ffec3c4e020e7d93692418f047b1245233..805e7673ab758cfce29f6daa011936bae785d2b5 100644 (file)
@@ -29,6 +29,7 @@ SET(PROJECT_HEADERS
     XGUI_ActionsMgr.h
     XGUI_ErrorDialog.h
     XGUI_SalomeViewer.h
+    XGUI_ViewerProxy.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -56,6 +57,7 @@ SET(PROJECT_SOURCES
     XGUI_SelectionMgr.cpp
     XGUI_ActionsMgr.cpp
     XGUI_ErrorDialog.cpp
+    XGUI_ViewerProxy.cpp
 )
 
 SET(PROJECT_RESOURCES 
index 4803c578df03b201ae433d3f94fa75ded37c0f18..dcfe8385d5091aa11ab59381cb771327fc27a439 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "XGUI_Displayer.h"
 #include "XGUI_Viewer.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ViewerProxy.h"
 
 #include <ModelAPI_Document.h>
 
@@ -13,9 +15,9 @@
 
 #include <AIS_Shape.hxx>
 
-XGUI_Displayer::XGUI_Displayer(const Handle(AIS_InteractiveContext)& theAIS)
+XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
 {
-  myAISContext = theAIS;
+  myWorkshop = theWorkshop;
 }
 
 XGUI_Displayer::~XGUI_Displayer()
@@ -142,3 +144,8 @@ void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
       ic->UpdateCurrentViewer();
   }
 }
+
+Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const 
+{ 
+  return myWorkshop->viewer()->AISContext(); 
+}
index 3b1b54f608003fac118f6906c3cb346be8e4b876..9299a81983f19bfa01e4d9434daaded33b102cf2 100644 (file)
@@ -19,7 +19,7 @@
 
 class XGUI_Viewer;
 class ModelAPI_Feature;
-
+class XGUI_Workshop;
 
 /**\class XGUI_Displayer
  * \ingroup GUI
@@ -30,7 +30,7 @@ class XGUI_EXPORT XGUI_Displayer
 public:
   /// Constructor
   /// \param theViewer the viewer
-  XGUI_Displayer(const Handle(AIS_InteractiveContext)& theAIS);
+  XGUI_Displayer(XGUI_Workshop* theWorkshop);
   /// Destructor
   virtual ~XGUI_Displayer();
 
@@ -84,11 +84,10 @@ protected:
   void closeAllContexts(const bool isUpdateViewer);
 
   /// Returns currently installed AIS_InteractiveContext
-  Handle(AIS_InteractiveContext) AISContext() const { return myAISContext; }
+  Handle(AIS_InteractiveContext) AISContext() const;
 
 protected:
-  ///< the viewer where the objects should be visualized
-  Handle(AIS_InteractiveContext) myAISContext;
+  XGUI_Workshop* myWorkshop;
   std::map<boost::shared_ptr<ModelAPI_Feature>, std::vector<Handle(AIS_InteractiveObject)> > myFeature2AISObjectMap;
 };
 
index 3ecd6e3cddc698d9b91bbf86d02071c25a12bd5e..059bbd819975302cd48771e27a067c74effc8627 100644 (file)
@@ -24,7 +24,7 @@ public:
   virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
 
   //! Retrurns V3d_Vioewer from current viewer
-  virtual Handle(V3d_Viewer) V3dViewer() const = 0;
+  virtual Handle(V3d_Viewer) v3dViewer() const = 0;
 
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const = 0;
index d117c1dea114bf86de617a1aee1bc4dfab7d0e30..8365772e730cff18b9dcd7a22ba5c38fdab27eeb 100644 (file)
@@ -4,7 +4,7 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_Viewer.h"
 #include "XGUI_SalomeConnector.h"
-#include "XGUI_SalomeViewer.h"
+#include "XGUI_ViewerProxy.h"
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_PluginManager.h>
@@ -69,30 +69,20 @@ QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
 //**************************************************************
 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
 {
-  if (myWorkshop->isSalomeMode()) {
-    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeViewer()->AISContext();
-    theList.Clear();
-    for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
-      theList.Append(aContext->SelectedInteractive());
-  } else {
-    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-    aViewer->getSelectedObjects(theList);
-  }
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  theList.Clear();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
+    theList.Append(aContext->SelectedInteractive());
 }
 
 //**************************************************************
 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
 {
-  if (myWorkshop->isSalomeMode()) {
-    theList.Clear();
-    Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeViewer()->AISContext();
-    for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
-      TopoDS_Shape aShape = aContext->SelectedShape();
-      if (!aShape.IsNull())
-        theList.Append(aShape);
-    }
-  } else {
-    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-    aViewer->getSelectedShapes(theList);
+  theList.Clear();
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+    TopoDS_Shape aShape = aContext->SelectedShape();
+    if (!aShape.IsNull())
+      theList.Append(aShape);
   }
 }
diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp
new file mode 100644 (file)
index 0000000..ff95ecf
--- /dev/null
@@ -0,0 +1,129 @@
+#include "XGUI_ViewerProxy.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_MainWindow.h"
+#include "XGUI_ViewPort.h"
+#include "XGUI_ViewWindow.h"
+#include "XGUI_Viewer.h"
+#include "XGUI_SalomeConnector.h"
+
+
+XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
+: XGUI_SalomeViewer(theParent), myWorkshop(theParent)
+{
+}
+
+
+Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->AISContext();
+  } else {
+    return myWorkshop->mainWindow()->viewer()->AISContext();
+  }
+}
+
+Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->v3dViewer();
+  } else {
+    return myWorkshop->mainWindow()->viewer()->v3dViewer();
+  }
+}
+
+Handle(V3d_View) XGUI_ViewerProxy::activeView() const
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->activeView();
+  } else {
+    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+    return aViewer->activeViewWindow()->viewPort()->getView();
+  }
+}
+void XGUI_ViewerProxy::connectToViewer()
+{
+  if (myWorkshop->isSalomeMode()) {
+    XGUI_SalomeViewer* aViewer = myWorkshop->salomeConnector()->viewer();
+
+    connect(aViewer, SIGNAL(lastViewClosed()),
+            this, SIGNAL(lastViewClosed()));
+    connect(aViewer, SIGNAL(tryCloseView()),
+            this, SIGNAL(tryCloseView()));
+    connect(aViewer, SIGNAL(deleteView()),
+            this, SIGNAL(deleteView()));
+    connect(aViewer, SIGNAL(viewCreated()),
+            this, SIGNAL(viewCreated()));
+    connect(aViewer, SIGNAL(activated()),
+            this, SIGNAL(activated()));
+
+    connect(aViewer, SIGNAL(mousePress(QMouseEvent* theEvent)),
+            this, SIGNAL(mousePress(QMouseEvent* theEvent)));
+    connect(aViewer, SIGNAL(mouseRelease(QMouseEvent* theEvent)),
+            this, SIGNAL(mouseRelease(QMouseEvent* theEvent)));
+    connect(aViewer, SIGNAL(mouseDoubleClick(QMouseEvent* theEvent)),
+            this, SIGNAL(mouseDoubleClick(QMouseEvent* theEvent)));
+    connect(aViewer, SIGNAL(mouseMove(QMouseEvent* theEvent)),
+            this, SIGNAL(mouseMove(QMouseEvent* theEvent)));
+    connect(aViewer, SIGNAL(keyPress(QKeyEvent* theEvent)),
+            this, SIGNAL(keyPress(QKeyEvent* theEvent)));
+    connect(aViewer, SIGNAL(keyRelease(QKeyEvent* theEvent)),
+            this, SIGNAL(keyRelease(QKeyEvent* theEvent)));
+  } else {
+    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+
+    connect(aViewer, SIGNAL(lastViewClosed()),
+            this, SIGNAL(lastViewClosed()));
+    connect(aViewer, SIGNAL(tryCloseView(XGUI_ViewWindow*)),
+            this, SIGNAL(tryCloseView()));
+    connect(aViewer, SIGNAL(deleteView(XGUI_ViewWindow*)),
+            this, SIGNAL(deleteView()));
+    connect(aViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)),
+            this, SIGNAL(viewCreated()));
+    connect(aViewer, SIGNAL(activated(XGUI_ViewWindow*)),
+            this, SIGNAL(activated()));
+
+    connect(aViewer, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMousePress(XGUI_ViewWindow*, QMouseEvent*)));
+    connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
+    connect(aViewer, SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
+    connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
+    connect(aViewer, SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)),
+            this, SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
+    connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)),
+            this, SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
+  }
+}
+
+void XGUI_ViewerProxy::onMousePress(XGUI_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mousePress(theEvent);
+}
+
+void XGUI_ViewerProxy::onMouseRelease(XGUI_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseRelease(theEvent);
+}
+
+void XGUI_ViewerProxy::onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseDoubleClick(theEvent);
+}
+
+void XGUI_ViewerProxy::onMouseMove(XGUI_ViewWindow*, QMouseEvent* theEvent)
+{
+  emit mouseMove(theEvent);
+}
+
+void XGUI_ViewerProxy::onKeyPress(XGUI_ViewWindow*, QKeyEvent* theEvent)
+{
+  emit keyPress(theEvent);
+}
+
+void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow*, QKeyEvent* theEvent)
+{
+  emit keyRelease(theEvent);
+}
diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h
new file mode 100644 (file)
index 0000000..7d26c49
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef XGUI_VIEWERPROXY_H
+#define XGUI_VIEWERPROXY_H
+
+#include "XGUI.h"
+#include "XGUI_SalomeViewer.h"
+
+class XGUI_Workshop;
+class XGUI_ViewWindow;
+
+/**
+* Proxy class which repersents or XGUI_Viewer or Salome Viewer
+* dependently on current launching environment.
+* It is reccomennded to use this class in operation for accessing to viewer 
+* functionality instead of direct access to a viewer
+*/
+class XGUI_ViewerProxy: public XGUI_SalomeViewer
+{
+  Q_OBJECT
+public:
+  XGUI_ViewerProxy(XGUI_Workshop* 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 connectToViewer();
+
+private slots:
+  void onMousePress(XGUI_ViewWindow*, QMouseEvent*);
+  void onMouseRelease(XGUI_ViewWindow*, QMouseEvent*);
+  void onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*);
+  void onMouseMove(XGUI_ViewWindow*, QMouseEvent*);
+  void onKeyPress(XGUI_ViewWindow*, QKeyEvent*);
+  void onKeyRelease(XGUI_ViewWindow*, QKeyEvent*);
+
+private:
+  XGUI_Workshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
index 912fa36dbffe0d08df570149ed25eefc36bb60c4..7f8b861d9eaed6881e25d769fe0a1426ec191a90 100644 (file)
@@ -17,6 +17,7 @@
 #include "XGUI_SalomeViewer.h"
 #include "XGUI_ActionsMgr.h"
 #include "XGUI_ErrorDialog.h"
+#include "XGUI_ViewerProxy.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Feature.h>
@@ -59,16 +60,17 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 {
   myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow();
 
-  // In SALOME viewer is accessible only when module is initialized
-  // and in SALOME mode myDisplayer object has to be created later
-  // So, displayer will be created on demand.
+  myDisplayer = new XGUI_Displayer(this);
 
   mySelector = new XGUI_SelectionMgr(this);
   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
+
   myOperationMgr = new XGUI_OperationMgr(this);
   myActionsMgr = new XGUI_ActionsMgr(this);
   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
 
+  myViewerProxy = new XGUI_ViewerProxy(this);
+
   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
@@ -363,6 +365,7 @@ void XGUI_Workshop::onNew()
     createDockWidgets();
     mySelector->connectViewers();
   }
+  myViewerProxy->connectToViewer();
   showObjectBrowser();
   if (!isSalomeMode()) {
     myMainWindow->showPythonConsole();
@@ -683,20 +686,6 @@ void XGUI_Workshop::onFeatureTriggered()
   }
 }
 
-//******************************************************
-XGUI_Displayer* XGUI_Workshop::displayer() const
-{
-  // In SALOME viewer is accessible only when module is initialized
-  // and in SALOME mode myDisplayer object has to be created later (on demand)
-  if (!myDisplayer) {
-    XGUI_Workshop* that = (XGUI_Workshop*)this;
-    that->myDisplayer = isSalomeMode() ?
-      new XGUI_Displayer(salomeViewer()->AISContext()):
-      new XGUI_Displayer(myMainWindow->viewer()->AISContext());
-  }
-  return myDisplayer;
-}
-
 //******************************************************
 void XGUI_Workshop::changeCurrentDocument()
 {
index d908ff5efb5b53c0a1b171caadcaf20a3bab75ff..f3e31fa885f95ca4d30d54eb6480441c2dd74791 100644 (file)
@@ -21,6 +21,7 @@ class XGUI_ObjectsBrowser;
 class XGUI_ActionsMgr;
 class XGUI_ErrorDialog;
 class XGUI_SalomeViewer;
+class XGUI_ViewerProxy;
 
 class ModuleBase_Operation;
 class ModuleBase_PropPanelOperation;
@@ -56,7 +57,7 @@ public:
   XGUI_SelectionMgr* selector() const { return mySelector; }
 
   //! Returns displayer
-  XGUI_Displayer* displayer() const;
+  XGUI_Displayer* displayer() const { return myDisplayer; }
 
   //! ! Returns operation manager.
   XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
@@ -84,6 +85,8 @@ public:
 
   void salomeViewerSelectionChanged();
 
+  XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
+
 signals:
   void salomeViewerSelection();
 
@@ -148,6 +151,7 @@ private:
   XGUI_ActionsMgr* myActionsMgr;
   XGUI_SalomeConnector* mySalomeConnector;
   XGUI_ErrorDialog* myErrorDlg;
+  XGUI_ViewerProxy* myViewerProxy;
 };
 
 #endif