Salome HOME
[MEDCalc] add icons and menu for presentations
[modules/med.git] / src / MEDCalc / gui / MEDModule.cxx
1 // Copyright (C) 2007-2016  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 "MEDModule.hxx"
23 #include "QtHelper.hxx"
24
25 #include "SALOME_LifeCycleCORBA.hxx"
26 #include "QtxPopupMgr.h"
27
28 #include <SUIT_Desktop.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SalomeApp_Study.h>
32
33 #ifndef DISABLE_PVVIEWER
34 #include "PVViewer_ViewModel.h"
35 #endif
36
37 //! The only instance of the reference to engine
38 MED_ORB::MED_Gen_var MEDModule::myEngine;
39
40 MEDModule::MEDModule() :
41   SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0)
42 {
43   // Note also that we can't use the getApp() function here because
44   // the initialize(...) function has not been called yet.
45
46   init(); // internal initialization
47 }
48
49 MEDModule::~MEDModule()
50 {
51   if (_studyEditor)
52     delete _studyEditor;
53   if (_datasourceController)
54     delete _datasourceController;
55   //if (_workspaceController)
56   //  delete _workspaceController;
57   if (_presentationController)
58     delete _presentationController;
59 }
60
61 MED_ORB::MED_Gen_var
62 MEDModule::engine()
63 {
64   init(); // initialize engine, if necessary
65   return myEngine;
66 }
67
68 void
69 MEDModule::init()
70 {
71   // initialize MED module engine (load, if necessary)
72   if ( CORBA::is_nil( myEngine ) ) {
73     Engines::EngineComponent_var comp =
74       SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
75     myEngine = MED_ORB::MED_Gen::_narrow( comp );
76   }
77 }
78
79 void
80 MEDModule::initialize( CAM_Application* app )
81 {
82   // call the parent implementation
83   SalomeApp_Module::initialize( app );
84
85   // The following initializes the GUI widget and associated actions
86   this->createModuleWidgets();
87   this->createModuleActions();
88 }
89
90 QString
91 MEDModule::engineIOR() const
92 {
93   init(); // initialize engine, if necessary
94   CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
95   return QString( anIOR.in() );
96 }
97
98 QString
99 MEDModule::iconName() const
100 {
101   return tr("ICO_MED_SMALL");
102 }
103
104 void
105 MEDModule::windows( QMap<int, int>& theMap ) const
106 {
107   // want Object browser, in the left area
108   theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
109                  Qt::LeftDockWidgetArea );
110 #ifndef DISABLE_PYCONSOLE
111   // want Python console, in the bottom area
112   theMap.insert( SalomeApp_Application::WT_PyConsole,
113                  Qt::BottomDockWidgetArea );
114 #endif
115 }
116
117 void
118 MEDModule::viewManagers( QStringList& list ) const
119 {
120 #ifndef DISABLE_PVVIEWER
121   list.append( PVViewer_Viewer::Type() );
122 #endif
123 }
124
125 bool
126 MEDModule::activateModule( SUIT_Study* theStudy )
127 {
128   if ( CORBA::is_nil( myEngine ) )
129     return false;
130
131   // call parent implementation
132   bool bOk = SalomeApp_Module::activateModule( theStudy );
133   if (!bOk)
134     return false;
135
136   // show own menus
137   setMenuShown( true );
138   // show own toolbars
139   setToolShown( true );
140
141   //this->createStudyComponent(theStudy);
142   _workspaceController->showDockWidgets(true);
143   //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
144
145   // return the activation status
146   return bOk;
147 }
148
149 bool
150 MEDModule::deactivateModule( SUIT_Study* theStudy )
151 {
152   _workspaceController->showDockWidgets(false);
153   //this->unsetDockLayout();
154
155   // hide own menus
156   setMenuShown( false );
157   // hide own toolbars
158   setToolShown( false );
159
160   // call parent implementation and return the activation status
161   return SalomeApp_Module::deactivateModule( theStudy );
162 }
163
164 //
165 // =====================================================================
166 // This part add custom widgets (a dockwidget containing a tree view
167 // in this example) and add special actions in the toolbox of the
168 // module.
169 // =====================================================================
170 //
171
172 /*!
173  * This function implements the interface StandardApp_Module. It
174  * creates the widgets specific for this module, in particular the
175  * workspace widget and the dataspace widget.
176  */
177 void
178 MEDModule::createModuleWidgets() {
179   _studyEditor = new SALOME_AppStudyEditor(getApp());
180   _datasourceController = new DatasourceController(this);
181   _workspaceController = new WorkspaceController(this);
182   _xmedDataModel  = new XmedDataModel();
183   _workspaceController->setDataModel(_xmedDataModel);
184   _presentationController = new PresentationController(this);
185
186   connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
187     _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
188
189   connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
190     _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
191
192   connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
193     _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
194
195   connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
196     _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
197 }
198
199 void
200 MEDModule::createModuleActions() {
201   _datasourceController->createActions();
202   _workspaceController->createActions();
203   _presentationController->createActions();
204 }
205
206 int
207 MEDModule::createStandardAction(const QString& label,
208                                 QObject* slotobject,
209                                 const char* slotmember,
210                                 const QString& iconName,
211                                 const QString& tooltip)
212 {
213   SUIT_Desktop* dsk = getApp()->desktop();
214   SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
215
216   // If the tooltip is not defined, we choose instead the label text.
217   QString effToolTip(tooltip);
218   if ( effToolTip.isEmpty() )
219     effToolTip = label;
220
221   QAction* action = createAction(-1,
222                                  label,
223                                  resMgr->loadPixmap("MED", iconName),
224                                  label,
225                                  effToolTip,
226                                  0,
227                                  dsk,
228                                  false,
229                                  slotobject,
230                                  slotmember
231                                  );
232   return actionId(action);
233 }
234
235 void
236 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
237 {
238   // _GBO_ for a fine customization of the rule (for example with a
239   // test on the type of the selected object), see the LIGTH module:
240   // implement "LightApp_Selection*    createSelection() const;"
241   int parentId = -1;
242   QtxPopupMgr* mgr = this->popupMgr();
243   this->action( actionId )->setIconVisibleInMenu(true);
244   if (! menus.isEmpty())
245     mgr->insert ( this->action( actionId ), menus, parentId, 0 );
246   else
247     mgr->insert ( this->action( actionId ), parentId, 0 );
248   mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
249 }
250
251 MEDCALC::MEDPresentationViewMode
252 MEDModule::getSelectedViewMode()
253 {
254   return _presentationController->getSelectedViewMode();
255 }