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