From: vsv Date: Wed, 30 Apr 2014 07:40:58 +0000 (+0400) Subject: Interface to Salome Viewer is created (issue #31) X-Git-Tag: V_0.2~102 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e9d86ad2a12c582582e33458bb95a35853fe405c;p=modules%2Fshaper.git Interface to Salome Viewer is created (issue #31) --- diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt index 4d7a3b3e4..31e829792 100644 --- a/src/NewGeom/CMakeLists.txt +++ b/src/NewGeom/CMakeLists.txt @@ -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 diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index 8d1b96246..7ef9d61f1 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -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() { diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 65e048e40..9b63a18c6 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -4,6 +4,7 @@ #define NewGeom_Module_H #include "NewGeom.h" +#include "NewGeom_SalomeViewer.h" #include #include @@ -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 myNestedActions; }; diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp new file mode 100644 index 000000000..ff58fa0db --- /dev/null +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -0,0 +1,101 @@ + +#include "NewGeom_SalomeViewer.h" +#include "NewGeom_OCCSelector.h" + +#include +#include + +#include + +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(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 index 000000000..b6316e2b3 --- /dev/null +++ b/src/NewGeom/NewGeom_SalomeViewer.h @@ -0,0 +1,49 @@ + + +#ifndef NewGeom_SalomeViewer_H +#define NewGeom_SalomeViewer_H + +#include "NewGeom.h" + +#include + +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 diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index d8de8a441..00eed0ffe 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -28,6 +28,7 @@ SET(PROJECT_HEADERS XGUI_SalomeConnector.h XGUI_ActionsMgr.h XGUI_ErrorDialog.h + XGUI_SalomeViewer.h ) SET(PROJECT_AUTOMOC diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index f6e89cf17..a55398cb1 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -3,11 +3,11 @@ #include "XGUI.h" -#include #include #include 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 index 000000000..3ecd6e3cd --- /dev/null +++ b/src/XGUI/XGUI_SalomeViewer.h @@ -0,0 +1,47 @@ +#ifndef XGUI_SALOMEVIEWER_H +#define XGUI_SALOMEVIEWER_H + +#include "XGUI.h" + +#include +#include +#include + +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 diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 0bba0d847..d117c1dea 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -4,6 +4,7 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_Viewer.h" #include "XGUI_SalomeConnector.h" +#include "XGUI_SalomeViewer.h" #include #include @@ -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& 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& theList) XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); aViewer->getSelectedShapes(theList); } -} \ No newline at end of file +} diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 90cb04fc3..912fa36db 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 41ac3b144..d908ff5ef 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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; }