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