From: vsv Date: Wed, 30 Apr 2014 11:22:32 +0000 (+0400) Subject: (Issue #31) Proxy viewer created in order to provide uniform dispatching of events... X-Git-Tag: V_0.2~100 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c008126286a78ecb31e217b97070f8dcfa56e7c;p=modules%2Fshaper.git (Issue #31) Proxy viewer created in order to provide uniform dispatching of events from Salome and XGUI viewers --- diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index ff58fa0db..c81d706ab 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -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(); } diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h index b6316e2b3..b84c5bc4a 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.h +++ b/src/NewGeom/NewGeom_SalomeViewer.h @@ -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; diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 00eed0ffe..805e7673a 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -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 diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 4803c578d..dcfe8385d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -4,6 +4,8 @@ #include "XGUI_Displayer.h" #include "XGUI_Viewer.h" +#include "XGUI_Workshop.h" +#include "XGUI_ViewerProxy.h" #include @@ -13,9 +15,9 @@ #include -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(); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 3b1b54f60..9299a8198 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -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, std::vector > myFeature2AISObjectMap; }; diff --git a/src/XGUI/XGUI_SalomeViewer.h b/src/XGUI/XGUI_SalomeViewer.h index 3ecd6e3cd..059bbd819 100644 --- a/src/XGUI/XGUI_SalomeViewer.h +++ b/src/XGUI/XGUI_SalomeViewer.h @@ -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; diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index d117c1dea..8365772e7 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -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 #include @@ -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& 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 index 000000000..ff95ecff6 --- /dev/null +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -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 index 000000000..7d26c4924 --- /dev/null +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 912fa36db..7f8b861d9 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -17,6 +17,7 @@ #include "XGUI_SalomeViewer.h" #include "XGUI_ActionsMgr.h" #include "XGUI_ErrorDialog.h" +#include "XGUI_ViewerProxy.h" #include #include @@ -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() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index d908ff5ef..f3e31fa88 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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