1 // FILTER FILTERGUI : FILTER component GUI implemetation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : FilterGUI.cxx
27 #include "utilities.h"
28 #include <FilterGUI_Selection.h>
29 #include "SelectParams.h"
30 #include "SelectField.h"
31 #include "FilterGUI.h"
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
37 #include <SALOME_LifeCycleCORBA.hxx>
38 #include <SALOME_InteractiveObject.hxx>
39 #include <SALOME_ListIO.hxx>
40 #include <SalomeApp_Tools.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_FileDlg.h>
45 #include <SUIT_ResourceMgr.h>
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>
54 #include <LightApp_SelectionMgr.h>
56 #include <OB_Browser.h>
59 #include <qinputdialog.h>
60 #include <qmessagebox.h>
63 //VRV: porting on Qt 3.0.5
64 #if QT_VERSION >= 0x030005
65 #include <qlineedit.h>
67 //VRV: porting on Qt 3.0.5
71 static CORBA::ORB_var _orb;
73 //=============================================================================
77 //=============================================================================
78 FilterGUI::FilterGUI() :
79 SalomeApp_Module( "FILTER" ),_sel(0)
83 //=============================================================================
87 //=============================================================================
88 void FilterGUI::createPopupItem( const int id,
89 const QString& clients,
91 const QString& theRule,
96 parentId = popupMgr()->actionId( action( pId ) );
98 if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
99 popupMgr()->insert( action( id ), parentId, 0 );
101 QChar lc = QtxPopupMgr::Selection::defEquality();
102 QString rule = "(%1)";
103 if( !types.isEmpty() )
104 rule += " and (%2) and (%3)";
106 rule = rule.arg( QString( "client in {%1}" ).arg( clients ) );
108 if( !types.isEmpty() )
110 rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
111 rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
114 popupMgr()->setRule( action( id ), rule, true );
117 void FilterGUI::createFilterAction( const int id, const QString& po_id, const QString& icon_id )
119 QWidget* parent = application()->desktop();
120 SUIT_ResourceMgr* mgr = application()->resourceMgr();
122 QPixmap pix; QIconSet icon;
123 if( !icon_id.isEmpty() )
124 pix = mgr->loadPixmap( "FILTER", tr( icon_id ) );
126 // pix = mgr->loadPixmap( "FILTER", tr( QString( "ICO_" )+po_id ) );
129 icon = QIconSet( pix );
131 createAction( id, tr( "TOP_" + po_id ), icon, tr( "MEN_" + po_id ), tr( "STB_" + po_id ), 0, parent, false, this, SLOT( onGUIEvent() ) );
134 //=============================================================================
138 //=============================================================================
139 void FilterGUI::initialize( CAM_Application* app )
141 SalomeApp_Module::initialize( app );
143 // QWidget* parent = application()->desktop();
145 createFilterAction( 111, "OPEN" );
147 createFilterAction( 936, "FILTERING" );
149 int fileId = createMenu( tr( "MEN_FILE" ), -1, 1 );
150 createMenu( 111, fileId, 11 );
152 int FilterId = createMenu( tr( "DATA REDUCTION" ), -1, 50, 10 );
153 createMenu( separator(), FilterId, 10 );
154 createMenu( 936, FilterId, 11 );
158 void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
160 FilterGUI_Selection sel;
161 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
164 sel.init( client, app->selectionMgr() );
165 popupMgr()->updatePopup( menu, &sel );
169 QString FilterGUI::engineIOR() const
171 // SALOME_FILTER::MED_Gen_ptr aMedGen = InitMedGen();
172 // if ( !CORBA::is_nil( aMedGen) )
173 // return QString( getApp()->orb()->object_to_string( aMedGen ));
174 return QString( "" );
177 void FilterGUI::windows( QMap<int, int>& mappa ) const
179 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
180 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
184 //=============================================================================
188 //=============================================================================
189 void FilterGUI::onGUIEvent()
191 const QObject* obj = sender();
192 if ( !obj || !obj->inherits( "QAction" ) )
194 int id = actionId((QAction*)obj);
199 //=============================================================================
203 //=============================================================================
204 void FilterGUI::EmitSignalCloseAllDialogs()
206 emit SignalCloseAllDialogs();
209 //=============================================================================
213 //=============================================================================
214 bool FilterGUI::deactivateModule( SUIT_Study* study )
216 setMenuShown( false );
217 setToolShown( false );
219 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
220 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
222 EmitSignalCloseAllDialogs();
224 return SalomeApp_Module::deactivateModule( study );
227 //=============================================================================
231 //=============================================================================
232 bool FilterGUI::activateModule( SUIT_Study* study )
234 bool res = SalomeApp_Module::activateModule( study );
236 setMenuShown( true );
237 setToolShown( true );
239 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
240 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
244 //=============================================================================
248 //=============================================================================
249 void FilterGUI::onWindowActivated( SUIT_ViewWindow* )
253 //=============================================================================
257 //=============================================================================
258 bool FilterGUI::OnGUIEvent (int theCommandID)
262 SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
266 _PTR(Study) aStudy = myActiveStudy->studyDS();
267 //SALOME_NamingService* myNameService = parent->getNameService();
270 QStringList filtersList ;
272 filtersList.append( tr("FILTER_MEN_IMPORT_MED") );
273 filtersList.append( tr("FILTER_MEN_ALL_FILES") ) ;
275 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
279 switch (theCommandID)
283 MESSAGE("command " << theCommandID << " activated");
286 SelectParams *filter;
288 application()->desktop()->setCursor(QCursor(Qt::WaitCursor));
289 filter = new SelectParams(this,_sel);
291 application()->desktop()->setCursor(QCursor(Qt::ArrowCursor));
294 catch ( SALOME_Exception& S_ex ) {
295 QMessageBox::information( application()->desktop(),
297 "Unable to select parameters for filtering.\n"
298 "You must select a reference field in a MED file before." );
302 MESSAGE("Select an input Field in MED file before filtering!!");
303 QMessageBox::information( application()->desktop(),
305 "Unable to select parameters for filtering.\n"
306 "You must select a reference field in a MED file before." );
312 MESSAGE("command " << theCommandID << " activated");
314 // Selection du Fichier
315 file = SUIT_FileDlg::getFileName(application()->desktop(),
318 tr("FILTER_MEN_IMPORT"),
320 if (!file.isEmpty() ){
321 _sel = new SelectField(this,file);
322 if ( _sel->exec() == QDialog::Rejected ){
332 app->updateActions(); //SRN: To update a Save button in the toolbar
338 //=============================================================================
342 //=============================================================================
343 bool FilterGUI::OnMousePress (QMouseEvent* pe ,
344 SUIT_ViewWindow* wnd )
346 MESSAGE("FilterGUI::OnMousePress");
350 //=============================================================================
354 //=============================================================================
355 bool FilterGUI::OnMouseMove (QMouseEvent* pe ,
356 SUIT_ViewWindow* wnd )
358 // MESSAGE("FilterGUI::OnMouseMouve");
362 //=============================================================================
366 //=============================================================================
367 bool FilterGUI::OnKeyPress (QKeyEvent* pe,
368 SUIT_ViewWindow* wnd)
370 MESSAGE("FilterGUI::OnKeyPress");
374 //=============================================================================
378 //=============================================================================
379 void FilterGUI::setOrb()
382 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
383 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
384 _orb = init( 0 , 0 );
386 INFOS("internal error : orb not found");
389 ASSERT(! CORBA::is_nil(_orb));
393 Standard_EXPORT CAM_Module* createModule() {
394 return new FilterGUI();