]> SALOME platform Git repositories - modules/med.git/blob - src/MEDOP/gui/MEDOPModule.cxx
Salome HOME
Application of the patch of Cedric Aguere branch concerning the internationalization
[modules/med.git] / src / MEDOP / gui / MEDOPModule.cxx
1 // Copyright (C) 2007-2013  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.
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 <QWidget>
31
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_FileDlg.h>
36
37 enum {
38   MEDOP_MENU_ACTION_ID_IMPORT_MED = 100
39 };
40
41 MEDOPModule::MEDOPModule() :
42   StandardApp_Module()
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   this->setModuleName("MED");
48 }
49
50 //
51 // =====================================================================
52 // This part implements the mandatory interface
53 // =====================================================================
54 //
55 //=======================================================================
56 // function : initialize
57 // purpose  :
58 //=======================================================================
59 void MEDOPModule::initialize( CAM_Application* app ) {
60   StandardApp_Module::initialize( app );
61
62   QWidget* aParent = application()->desktop();
63   SUIT_ResourceMgr* resMgr = dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
64
65   QPixmap aPixmap = resMgr->loadPixmap("XMED", tr("ICO_IMPORT_MED"));
66   createAction( MEDOP_MENU_ACTION_ID_IMPORT_MED, tr("IMPORT_FROM_FILE"), QIcon(aPixmap),
67                 tr("IMPORT_MED_FILE"), "", (Qt::CTRL + Qt::Key_M), aParent, false,
68                 this, SLOT(onImportMedFile()));
69
70   int xmedId = createMenu( tr( "MEN_FILE" ), -1,  1 );
71   createMenu( MEDOP_MENU_ACTION_ID_IMPORT_MED, xmedId, 10 );
72 }
73
74
75 /*!
76  * Returns the engine of the XMED module, i.e. the SALOME component
77  * associated to the study root of the module.
78  */
79 Engines::EngineComponent_ptr MEDOPModule::getEngine() const {
80   return MEDOPFactoryClient::getFactory();
81 }
82
83 /*!
84  * Returns the base file name of the image used for the icon's
85  * module. The file is supposed to be located in the resource
86  * directory of the module.
87  */
88 QString MEDOPModule::studyIconName() {
89   return tr("ICO_MEDOP_SMALL");
90 }
91
92 //
93 // =====================================================================
94 // This part add custom widgets (a dockwidget containing a tree view
95 // in this example) and add special actions in the toolbox of the
96 // module.
97 // =====================================================================
98 //
99
100 /*!
101  * This function implements the interface StandardApp_Module. It
102  * creates the widgets specific for this module, in particular the
103  * workspace widget and the dataspace widget.
104  */
105 void MEDOPModule::createModuleWidgets() {
106   _datasourceController = new DatasourceController(this);
107   _workspaceController = new WorkspaceController(this);
108   _xmedDataModel  = new XmedDataModel();
109   _workspaceController->setDataModel(_xmedDataModel);
110
111   connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent *)),
112     _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent *)));
113 }
114
115 bool MEDOPModule::activateModule( SUIT_Study* theStudy )
116 {
117   bool bOk = StandardApp_Module::activateModule( theStudy );
118   _workspaceController->showDockWidgets(true);
119   this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
120   return bOk;
121 }
122 bool MEDOPModule::deactivateModule( SUIT_Study* theStudy )
123 {
124   _workspaceController->showDockWidgets(false);
125   this->unsetDockLayout();
126   return StandardApp_Module::deactivateModule( theStudy );
127 }
128
129 void MEDOPModule::createModuleActions() {
130   // Creating actions concerning the dataspace
131   _datasourceController->createActions();
132   // Creating actions concerning the workspace
133   _workspaceController->createActions();
134 }
135
136 void MEDOPModule::onImportMedFile()
137 {
138   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
139   if( !app )
140     return;
141   SUIT_Desktop* desktop = app->desktop();
142
143   QStringList filter;
144   filter.append( tr( "FILE_FILTER_MED" ) );
145
146   QString anInitialPath = "";
147   if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
148     anInitialPath = QDir::currentPath();
149
150   QString caption = tr( "IMPORT_FROM_FILE" );
151   QStringList filenames = SUIT_FileDlg::getOpenFileNames( desktop,
152                                                           anInitialPath,
153                                                           filter,
154                                                           caption );
155
156   if ( filenames.count() <= 0 )
157     return;
158
159   for ( QStringList::ConstIterator itFile = filenames.begin(); itFile != filenames.end(); ++itFile ) {
160     QString filename = *itFile;
161     _datasourceController->addDatasource(QCHARSTAR(filename));
162     updateObjBrowser(true);
163   }
164 }