Salome HOME
Explicitely create a PVViewer
[modules/med.git] / src / MEDOP / gui / MEDOPModule.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author : Guillaume Boulant (EDF)
21
22 #include "MEDOPModule.hxx"
23 #include "QtHelper.hxx"
24
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOMEDS)
27
28 #include "MEDOPFactoryClient.hxx"
29
30 #include <LightApp_Application.h>
31 #include "PVViewer_ViewManager.h"
32 #include "PVViewer_ViewWindow.h"
33 #include "PVViewer_ViewModel.h"
34 #include "SUIT_ViewManager.h"
35
36 MEDOPModule::MEDOPModule() :
37   StandardApp_Module()
38 {
39   // Note also that we can't use the getApp() function here because
40   // the initialize(...) function has not been called yet.
41
42   this->setModuleName("MED");
43 }
44
45 //
46 // =====================================================================
47 // This part implements the mandatory interface
48 // =====================================================================
49 //
50
51 /*!
52  * Returns the engine of the XMED module, i.e. the SALOME component
53  * associated to the study root of the module.
54  */
55 Engines::EngineComponent_ptr MEDOPModule::getEngine() const {
56   return MEDOPFactoryClient::getFactory();
57 }
58
59 /*!
60  * Returns the base file name of the image used for the icon's
61  * module. The file is supposed to be located in the resource
62  * directory of the module.
63  */
64 QString MEDOPModule::studyIconName() {
65   return tr("ICO_MEDOP_SMALL");
66 }
67
68 //
69 // =====================================================================
70 // This part add custom widgets (a dockwidget containing a tree view
71 // in this example) and add special actions in the toolbox of the
72 // module.
73 // =====================================================================
74 //
75
76 /*!
77  * This function implements the interface StandardApp_Module. It
78  * creates the widgets specific for this module, in particular the
79  * workspace widget and the dataspace widget.
80  */
81 void MEDOPModule::createModuleWidgets() {
82   _datasourceController = new DatasourceController(this);
83   _workspaceController = new WorkspaceController(this);
84   _xmedDataModel  = new XmedDataModel();
85   _workspaceController->setDataModel(_xmedDataModel);
86
87   connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent *)),
88     _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent *)));
89 }
90
91 /*!
92   \brief Shows (toShow = true) or hides ParaView view window
93 */
94 void MEDOPModule::showView( bool toShow )
95 {
96   LightApp_Application* anApp = getApp();
97   PVViewer_ViewManager* viewMgr =
98     dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), false ) );
99   if ( !viewMgr ) {
100     viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop(), anApp->logWindow() );
101     anApp->addViewManager( viewMgr );
102     connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
103              anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
104   }
105
106   PVViewer_ViewWindow* pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->getActiveView() );
107   if ( !pvWnd ) {
108     pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->createViewWindow() );
109     // this also connects to the pvserver and instantiates relevant PV behaviors
110   }
111
112   pvWnd->setShown( toShow );
113   if ( toShow ) pvWnd->setFocus();
114 }
115
116 bool MEDOPModule::activateModule( SUIT_Study* theStudy )
117 {
118   bool bOk = StandardApp_Module::activateModule( theStudy );
119   showView(true);
120   _workspaceController->showDockWidgets(true);
121   this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
122   return bOk;
123 }
124 bool MEDOPModule::deactivateModule( SUIT_Study* theStudy )
125 {
126   _workspaceController->showDockWidgets(false);
127   this->unsetDockLayout();
128   showView(false);
129   return StandardApp_Module::deactivateModule( theStudy );
130 }
131
132 void MEDOPModule::createModuleActions() {
133   // Creating actions concerning the dataspace
134   _datasourceController->createActions();
135   // Creating actions concerning the workspace
136   _workspaceController->createActions();
137 }