From 54724c4c48d51e12ddc5e5c9e7456e88da770375 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 8 May 2008 15:20:32 +0000 Subject: [PATCH] Introduced ViewExtender --- src/CAM/CAM_Application.cxx | 2 +- src/CAM/CAM_Application.h | 4 ++ src/LightApp/LightApp_Application.cxx | 3 + src/SVTK/Makefile.am | 8 +-- src/SVTK/SVTK_ViewModel.cxx | 92 +++++++++++++++++++++++++-- src/SVTK/SVTK_ViewModel.h | 16 +++++ 6 files changed, 115 insertions(+), 10 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 7eef172f8..4972fdde2 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -393,9 +393,9 @@ bool CAM_Application::activateModule( CAM_Module* mod ) return false; } } - updateCommandsStatus(); + emit moduleActivated(myModule); return true; } diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index b79be8c38..525bd2d4b 100755 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -66,6 +66,10 @@ public: virtual void createEmptyStudy(); + +signals: + void moduleActivated(CAM_Module*); + protected: virtual SUIT_Study* createNewStudy(); virtual void updateCommandsStatus(); diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index bb7eb2311..fa4d8498e 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -561,6 +561,7 @@ void LightApp_Application::createActions() moduleAction->insertModule( *it, icon ); } + connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), this, SLOT( onModuleActivation( const QString& ) ) ); registerAction( ModulesListId, moduleAction ); } @@ -1297,6 +1298,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ), resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) ); new LightApp_VTKSelector( vm, mySelMgr ); + vm->connectToApplication(this); } #else viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() ); @@ -2551,6 +2553,7 @@ bool LightApp_Application::activateModule( CAM_Module* mod ) if ( objectBrowser() ) objectBrowser()->updateTree(); + //emit moduleActivated(mod); return res; } diff --git a/src/SVTK/Makefile.am b/src/SVTK/Makefile.am index 283d63a70..427443d5f 100755 --- a/src/SVTK/Makefile.am +++ b/src/SVTK/Makefile.am @@ -36,11 +36,11 @@ salomeinclude_HEADERS= \ SVTK_FontWidget.h \ SVTK_CubeAxesActor2D.h \ SVTK_Functor.h \ - SVTK_MainWindow.h \ SVTK_View.h \ SVTK_ViewManager.h \ SVTK_ViewModel.h \ SVTK_ViewWindow.h \ + SVTK_MainWindow.h \ SVTK_Renderer.h \ SVTK_InteractorStyle.h \ SVTK_RenderWindowInteractor.h \ @@ -67,12 +67,12 @@ dist_libSVTK_la_SOURCES= \ SVTK_DialogBase.cxx \ SVTK_FontWidget.cxx \ SVTK_Trihedron.cxx \ - SVTK_MainWindow.cxx \ SVTK_View.cxx \ SVTK_ViewManager.cxx \ SVTK_ViewModel.cxx \ SVTK_Renderer.cxx \ SVTK_ViewWindow.cxx \ + SVTK_MainWindow.cxx \ SVTK_InteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ SVTK_GenericRenderWindowInteractor.cxx \ @@ -116,7 +116,7 @@ libSVTK_la_CPPFLAGS= \ $(VTK_INCLUDES) \ $(BOOST_CPPFLAGS) \ -I$(srcdir)/../Qtx -I$(srcdir)/../SUIT -I$(srcdir)/../OBJECT -I$(srcdir)/../Prs \ - -I$(srcdir)/../VTKViewer + -I$(srcdir)/../VTKViewer -I$(srcdir)/../CAM -I$(srcdir)/../STD libSVTK_la_LDFLAGS= \ $(QT_MT_LIBS) \ @@ -124,7 +124,7 @@ libSVTK_la_LDFLAGS= \ $(VTK_LIBS) $(OGL_LIBS) libSVTK_la_LIBADD= ../Qtx/libqtx.la ../SUIT/libsuit.la ../OBJECT/libSalomeObject.la \ - ../Prs/libSalomePrs.la ../VTKViewer/libVTKViewer.la + ../Prs/libSalomePrs.la ../VTKViewer/libVTKViewer.la ../CAM/libCAM.la # Executable bin_PROGRAMS = SVTK diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index b8edb171c..71990b72b 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -25,20 +25,26 @@ #include //#include "SUIT_Session.h" -#include "SUIT_ViewModel.h" -#include "SUIT_ViewManager.h" - #include "SVTK_Selection.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" #include "SVTK_View.h" -#include "SVTK_MainWindow.h" +//#include "SVTK_MainWindow.h" #include "SVTK_Prs.h" #include "VTKViewer_ViewModel.h" +#include "SUIT_ViewModel.h" +#include "SUIT_ViewManager.h" +#include "CAM_Module.h" +#include "CAM_Application.h" + #include +#include + +#include + // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study. // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from // SALOMEDS::StudyManager - no linkage with SalomeApp. @@ -66,6 +72,7 @@ */ SVTK_Viewer::SVTK_Viewer() { + myActiveModule = 0; myTrihedronSize = 105; myTrihedronRelative = true; } @@ -122,7 +129,14 @@ createView( SUIT_Desktop* theDesktop ) aViewWindow->setBackgroundColor( backgroundColor() ); aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() ); - + + if (myActiveModule) { + CAM_ViewExtender* aExtender = myActiveModule->getViewExtender(); + if (aExtender) { + QtxActionToolMgr* aMgr = aViewWindow->toolMgr(); + myExtToolBarId = aExtender->createToolbar(aMgr); + } + } return aViewWindow; } @@ -203,6 +217,10 @@ SVTK_Viewer thePopup->addAction( (*it)->toggleViewAction() ); aView->RefreshDumpImage(); } +// SALOME_ViewExtender* aExtender = myActiveModule->getViewExtender(); +// if (aExtender) { +// aExtender->contextMenuPopup(thePopup); +// } } /*! @@ -497,3 +515,67 @@ SVTK_Viewer if(SVTK_View* aView = aViewWindow->getView()) aView->Repaint(); } + +void SVTK_Viewer::connectToApplication( CAM_Application* theApp ) +{ + onModuleActivated(theApp->activeModule()); +// CAM_Module* aModule = dynamic_cast(theApp->activeModule()); +// if (aModule) { +// if (myActiveModule != aModule) { +// CAM_ViewExtender* aExtender = (myActiveModule)? myActiveModule->getViewExtender() : 0; +// if (aExtender) +// aExtender->deactivate(); + +// myActiveModule = aModule; +// aExtender = myActiveModule->getViewExtender(); +// if (aExtender) +// aExtender->activate(); + +// updateToolBars(); +// } +// } + connect(theApp, SIGNAL(moduleActivated(CAM_Module*)), + this, SLOT(onModuleActivated(CAM_Module*))); +} + + +void SVTK_Viewer::onModuleActivated( CAM_Module* mod ) +{ + CAM_Module* aModule = dynamic_cast(mod); + if (aModule) { + if (myActiveModule != aModule) { + CAM_ViewExtender* aExtender = (myActiveModule)? myActiveModule->getViewExtender() : 0; + if (aExtender) + aExtender->deactivate(); + + myActiveModule = aModule; + aExtender = myActiveModule->getViewExtender(); + if (aExtender) + aExtender->activate(); + + updateToolBars(); + } + } +} + + +void SVTK_Viewer::updateToolBars() +{ + if (!myActiveModule) return; + + CAM_ViewExtender* aExtender = myActiveModule->getViewExtender(); + int aNewId = -1; + QVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if(TViewWindow* aViewWnd = dynamic_cast(aViewWindow)) { + QtxActionToolMgr* aMgr = aViewWnd->toolMgr(); + if (myExtToolBarId != -1) + aMgr->removeToolBar(myExtToolBarId); + if (aExtender) + aNewId = aExtender->createToolbar(aMgr); + } + } + } + myExtToolBarId = aNewId; +} diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index a76da1dbc..46b595669 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -26,10 +26,14 @@ #include "SALOME_InteractiveObject.hxx" #include +#include class QMouseEvent; class SVTK_ViewWindow; +class CAM_Module; +class CAM_Application; +class CAM_Module; //! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View @@ -107,6 +111,10 @@ public: //! See #SALOME_View::Repaint() virtual void Repaint(); + + virtual void connectToApplication(CAM_Application* theApp); + + protected slots: void onMousePress(SUIT_ViewWindow*, QMouseEvent*); void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); @@ -115,12 +123,20 @@ protected slots: void onDumpView(); void onChangeBgColor(); + void onModuleActivated( CAM_Module* mod ); + private: + void updateToolBars(); + + QColor myBgColor; vtkFloatingPointType myTrihedronSize; bool myTrihedronRelative; bool mySelectionEnabled; bool myMultiSelectionEnabled; + + CAM_Module* myActiveModule; + int myExtToolBarId; }; #endif -- 2.39.2