Salome HOME
add possibility to change the size of histogram
[modules/filter.git] / src / FILTERGUI / FilterGUI.cxx
1 //  FILTER FILTERGUI : FILTER component GUI implemetation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : FilterGUI.cxx
25 //  Module : FILTER
26
27 #include "utilities.h"
28 #include <FilterGUI_Selection.h>
29 #include "SelectParams.h"
30 #include "SelectField.h"
31 #include "FilterGUI.h"
32
33 // SALOME Includes
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
36
37 #include <SALOME_LifeCycleCORBA.hxx>
38 #include <SALOME_InteractiveObject.hxx>
39 #include <SALOME_ListIO.hxx>
40 #include <SalomeApp_Tools.h>
41
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_FileDlg.h>
45 #include <SUIT_ResourceMgr.h>
46
47 #include <CAM_Application.h>
48 #include <SalomeApp_Application.h>
49 #include <SalomeApp_DataModel.h>
50 #include <SalomeApp_Study.h>
51 #include <SALOMEDSClient_Study.hxx>
52 #include <SALOMEDSClient_SObject.hxx>
53
54 #include <LightApp_SelectionMgr.h>
55
56 #include <OB_Browser.h>
57
58 // QT Includes
59 #include <qinputdialog.h>
60
61 //VRV: porting on Qt 3.0.5
62 #if QT_VERSION >= 0x030005
63 #include <qlineedit.h>
64 #endif
65 //VRV: porting on Qt 3.0.5
66
67 using namespace std;
68
69 static CORBA::ORB_var   _orb;
70
71 //=============================================================================
72 /*!
73  *
74  */
75 //=============================================================================
76 FilterGUI::FilterGUI() :
77   SalomeApp_Module( "FILTER" ),_sel(0)
78 {
79 }
80
81 //=============================================================================
82 /*!
83  *
84  */
85 //=============================================================================
86 void FilterGUI::createPopupItem( const int id,
87                               const QString& clients,
88                               const QString& types,
89                               const QString& theRule,
90                               const int pId )
91 {
92   int parentId = pId;
93   if( pId!=-1 )
94     parentId = popupMgr()->actionId( action( pId ) );
95
96   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
97     popupMgr()->insert( action( id ), parentId, 0 );
98
99   QChar lc = QtxPopupMgr::Selection::defEquality();
100   QString rule = "(%1)";
101   if( !types.isEmpty() )
102     rule += " and (%2) and (%3)";
103
104   rule = rule.arg( QString( "client in {%1}" ).arg( clients ) );
105
106   if( !types.isEmpty() )
107   {
108     rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
109     rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
110   }
111   rule += theRule;
112   popupMgr()->setRule( action( id ), rule, true );
113 }
114
115 void FilterGUI::createFilterAction( const int id, const QString& po_id, const QString& icon_id )
116 {
117   QWidget* parent = application()->desktop();
118   SUIT_ResourceMgr* mgr = application()->resourceMgr();
119
120   QPixmap pix; QIconSet icon;
121   if( !icon_id.isEmpty() )
122     pix = mgr->loadPixmap( "FILTER", tr( icon_id ) );
123 //   else
124 //     pix = mgr->loadPixmap( "FILTER", tr( QString( "ICO_" )+po_id ) );
125
126   if ( !pix.isNull() )
127     icon = QIconSet( pix );
128
129   createAction( id, tr( "TOP_" + po_id ), icon, tr( "MEN_" + po_id ), tr( "STB_" + po_id ), 0, parent, false, this, SLOT( onGUIEvent() ) );
130 }
131
132 //=============================================================================
133 /*!
134  *
135  */
136 //=============================================================================
137 void FilterGUI::initialize( CAM_Application* app )
138 {
139   SalomeApp_Module::initialize( app );
140
141   QWidget* parent = application()->desktop();
142
143   createFilterAction(  111, "OPEN" );
144
145   createFilterAction( 936, "FILTERING" );
146
147   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 );
148   createMenu( 111, fileId, 11 );
149
150   int FilterId = createMenu( tr( "DATA REDUCTION" ), -1, 50, 10 );
151   createMenu( separator(), FilterId, 10 );
152   createMenu( 936, FilterId, 11 );
153
154 }
155
156 void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
157 {
158   FilterGUI_Selection sel;
159   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
160   if( app )
161   {
162     sel.init( client, app->selectionMgr() );
163     popupMgr()->updatePopup( menu, &sel );
164   }
165 }
166
167 QString FilterGUI::engineIOR() const
168 {
169 //   SALOME_FILTER::MED_Gen_ptr aMedGen = InitMedGen();
170 //   if ( !CORBA::is_nil( aMedGen) )
171 //     return QString( getApp()->orb()->object_to_string( aMedGen ));
172   return QString( "" );
173 }
174
175 void FilterGUI::windows( QMap<int, int>& mappa ) const
176 {
177   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
178   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
179 }
180
181
182 //=============================================================================
183 /*!
184  *
185  */
186 //=============================================================================
187 void FilterGUI::onGUIEvent()
188 {
189   const QObject* obj = sender();
190   if ( !obj || !obj->inherits( "QAction" ) )
191     return;
192   int id = actionId((QAction*)obj);
193   if ( id != -1 )
194     OnGUIEvent( id );
195 }
196
197 //=============================================================================
198 /*!
199  *
200  */
201 //=============================================================================
202 void FilterGUI::EmitSignalCloseAllDialogs()
203 {
204   emit SignalCloseAllDialogs();
205 }
206
207 //=============================================================================
208 /*!
209  *
210  */
211 //=============================================================================
212 bool FilterGUI::deactivateModule( SUIT_Study* study )
213 {
214   setMenuShown( false );
215   setToolShown( false );
216
217   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
218              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
219
220   EmitSignalCloseAllDialogs();
221
222   return SalomeApp_Module::deactivateModule( study );
223 }
224
225 //=============================================================================
226 /*!
227  *
228  */
229 //=============================================================================
230 bool FilterGUI::activateModule( SUIT_Study* study )
231 {
232   bool res = SalomeApp_Module::activateModule( study );
233
234   setMenuShown( true );
235   setToolShown( true );
236
237   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
238           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
239   return res;
240 }
241
242 //=============================================================================
243 /*!
244  *
245  */
246 //=============================================================================
247 void FilterGUI::onWindowActivated( SUIT_ViewWindow* )
248 {
249 }
250
251 //=============================================================================
252 /*!
253  *
254  */
255 //=============================================================================
256 bool FilterGUI::OnGUIEvent (int theCommandID)
257 {
258   setOrb();
259
260   SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
261   if( !myActiveStudy )
262     return false;
263
264   _PTR(Study) aStudy = myActiveStudy->studyDS();
265   //SALOME_NamingService* myNameService = parent->getNameService();
266
267   QString file;
268   QStringList filtersList ;
269
270   filtersList.append( tr("FILTER_MEN_IMPORT_MED") );
271   filtersList.append( tr("FILTER_MEN_ALL_FILES") ) ;
272
273   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
274   if( !app )
275     return false;
276
277   switch (theCommandID)
278     {
279     case 936:
280       {
281         MESSAGE("command " << theCommandID << " activated");
282
283         try {
284           SelectParams *filter = new SelectParams(this,_sel);
285         }
286         catch ( SALOME_Exception& S_ex ) {
287         }
288         break;
289       }
290     case 111:
291       {
292         MESSAGE("command " << theCommandID << " activated");
293
294         // Selection du Fichier
295         file = SUIT_FileDlg::getFileName(application()->desktop(),
296                                         "",
297                                         filtersList,
298                                         tr("FILTER_MEN_IMPORT"),
299                                         true);
300         if (!file.isEmpty() )
301           _sel = new SelectField(this,file);
302
303         break;
304       }
305     }
306
307   app->updateActions(); //SRN: To update a Save button in the toolbar
308
309   return true;
310 }
311
312
313 //=============================================================================
314 /*!
315  *
316  */
317 //=============================================================================
318 bool FilterGUI::OnMousePress (QMouseEvent* pe ,
319                            SUIT_ViewWindow* wnd )
320 {
321   MESSAGE("FilterGUI::OnMousePress");
322   return true;
323 }
324
325 //=============================================================================
326 /*!
327  *
328  */
329 //=============================================================================
330 bool FilterGUI::OnMouseMove (QMouseEvent* pe ,
331                           SUIT_ViewWindow* wnd )
332 {
333   //   MESSAGE("FilterGUI::OnMouseMouve");
334   return true;
335 }
336
337 //=============================================================================
338 /*!
339  *
340  */
341 //=============================================================================
342 bool FilterGUI::OnKeyPress (QKeyEvent* pe,
343                          SUIT_ViewWindow* wnd)
344 {
345   MESSAGE("FilterGUI::OnKeyPress");
346   return true;
347 }
348
349 //=============================================================================
350 /*!
351  *
352  */
353 //=============================================================================
354 void FilterGUI::setOrb()
355 {
356   try {
357     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
358     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
359     _orb = init( 0 , 0 );
360   } catch (...) {
361     INFOS("internal error : orb not found");
362     _orb = 0;
363   }
364   ASSERT(! CORBA::is_nil(_orb));
365 }
366
367 extern "C" {
368   Standard_EXPORT CAM_Module* createModule() {
369     return new FilterGUI();
370   }
371 }