1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // FILTER FILTERGUI : FILTER component GUI implemetation
20 // File : FilterGUI.cxx
23 #include "utilities.h"
24 #include <FilterGUI_Selection.h>
25 #include "SelectParams.h"
26 #include "SelectField.h"
27 #include "FilterGUI.h"
30 #include "Utils_ORB_INIT.hxx"
31 #include "Utils_SINGLETON.hxx"
33 #include <SALOME_LifeCycleCORBA.hxx>
34 #include <SALOME_InteractiveObject.hxx>
35 #include <SALOME_ListIO.hxx>
36 #include <SalomeApp_Tools.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Tools.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_ResourceMgr.h>
43 #include <CAM_Application.h>
44 #include <SalomeApp_Application.h>
45 #include <SalomeApp_DataModel.h>
46 #include <SalomeApp_Study.h>
47 #include <SALOMEDSClient_Study.hxx>
48 #include <SALOMEDSClient_SObject.hxx>
50 #include <LightApp_SelectionMgr.h>
52 #include <OB_Browser.h>
55 #include <qinputdialog.h>
56 #include <qmessagebox.h>
59 //VRV: porting on Qt 3.0.5
60 #if QT_VERSION >= 0x030005
61 #include <qlineedit.h>
63 //VRV: porting on Qt 3.0.5
67 static CORBA::ORB_var _orb;
69 //=============================================================================
73 //=============================================================================
74 FilterGUI::FilterGUI() :
75 SalomeApp_Module( "FILTER" ),_sel(0)
79 //=============================================================================
83 //=============================================================================
84 void FilterGUI::createPopupItem( const int id,
85 const QString& clients,
87 const QString& theRule,
92 parentId = popupMgr()->actionId( action( pId ) );
94 if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
95 popupMgr()->insert( action( id ), parentId, 0 );
97 QChar lc = QtxPopupMgr::Selection::defEquality();
98 QString rule = "(%1)";
99 if( !types.isEmpty() )
100 rule += " and (%2) and (%3)";
102 rule = rule.arg( QString( "client in {%1}" ).arg( clients ) );
104 if( !types.isEmpty() )
106 rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
107 rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
110 popupMgr()->setRule( action( id ), rule, true );
113 void FilterGUI::createFilterAction( const int id, const QString& po_id, const QString& icon_id )
115 QWidget* parent = application()->desktop();
116 SUIT_ResourceMgr* mgr = application()->resourceMgr();
118 QPixmap pix; QIconSet icon;
119 if( !icon_id.isEmpty() )
120 pix = mgr->loadPixmap( "FILTER", tr( icon_id ) );
122 // pix = mgr->loadPixmap( "FILTER", tr( QString( "ICO_" )+po_id ) );
125 icon = QIconSet( pix );
127 createAction( id, tr( "TOP_" + po_id ), icon, tr( "MEN_" + po_id ), tr( "STB_" + po_id ), 0, parent, false, this, SLOT( onGUIEvent() ) );
130 //=============================================================================
134 //=============================================================================
135 void FilterGUI::initialize( CAM_Application* app )
137 SalomeApp_Module::initialize( app );
139 // QWidget* parent = application()->desktop();
141 createFilterAction( 111, "OPEN" );
143 createFilterAction( 936, "FILTERING" );
145 int fileId = createMenu( tr( "MEN_FILE" ), -1, 1 );
146 createMenu( 111, fileId, 11 );
148 int FilterId = createMenu( tr( "DATA REDUCTION" ), -1, 50, 10 );
149 createMenu( separator(), FilterId, 10 );
150 createMenu( 936, FilterId, 11 );
154 void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
156 FilterGUI_Selection sel;
157 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
160 sel.init( client, app->selectionMgr() );
161 popupMgr()->updatePopup( menu, &sel );
165 //=============================================================================
169 //=============================================================================
170 SALOME_FILTER::FILTER_Gen_ptr FilterGUI::InitFilterGen() const
172 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
173 Engines::Component_var comp =
174 SALOME_LifeCycleCORBA(app->namingService()).FindOrLoad_Component( "FactoryServer", "FILTER" );
176 MESSAGE("_________________________________________");
177 SALOME_FILTER::FILTER_Gen_var clr = SALOME_FILTER::FILTER_Gen::_narrow(comp);
178 ASSERT(!CORBA::is_nil(clr));
182 QString FilterGUI::engineIOR() const
185 SALOME_FILTER::FILTER_Gen_ptr aFilterGen = InitFilterGen();
186 if ( !CORBA::is_nil( aFilterGen) ){
187 CORBA::String_var objStr = getApp()->orb()->object_to_string( aFilterGen );
188 anIOR = QString( objStr.in() );
193 void FilterGUI::windows( QMap<int, int>& mappa ) const
195 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
196 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
200 //=============================================================================
204 //=============================================================================
205 void FilterGUI::onGUIEvent()
207 const QObject* obj = sender();
208 if ( !obj || !obj->inherits( "QAction" ) )
210 int id = actionId((QAction*)obj);
215 //=============================================================================
219 //=============================================================================
220 void FilterGUI::EmitSignalCloseAllDialogs()
222 emit SignalCloseAllDialogs();
225 //=============================================================================
229 //=============================================================================
230 bool FilterGUI::deactivateModule( SUIT_Study* study )
232 setMenuShown( false );
233 setToolShown( false );
235 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
236 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
238 EmitSignalCloseAllDialogs();
240 return SalomeApp_Module::deactivateModule( study );
243 //=============================================================================
247 //=============================================================================
248 bool FilterGUI::activateModule( SUIT_Study* study )
250 bool res = SalomeApp_Module::activateModule( study );
252 setMenuShown( true );
253 setToolShown( true );
255 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
256 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
260 //=============================================================================
264 //=============================================================================
265 void FilterGUI::onWindowActivated( SUIT_ViewWindow* )
269 //=============================================================================
273 //=============================================================================
274 bool FilterGUI::OnGUIEvent (int theCommandID)
278 SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
282 _PTR(Study) aStudy = myActiveStudy->studyDS();
283 //SALOME_NamingService* myNameService = parent->getNameService();
286 QStringList filtersList ;
288 filtersList.append( tr("FILTER_MEN_IMPORT_MED") );
289 filtersList.append( tr("FILTER_MEN_ALL_FILES") ) ;
291 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
295 switch (theCommandID)
299 MESSAGE("command " << theCommandID << " activated");
302 SelectParams *filter;
304 application()->desktop()->setCursor(QCursor(Qt::WaitCursor));
305 filter = new SelectParams(this,_sel);
307 application()->desktop()->setCursor(QCursor(Qt::ArrowCursor));
310 catch ( SALOME_Exception& S_ex ) {
313 MESSAGE("Select an input Field in MED file before filtering!!");
314 QMessageBox::information( application()->desktop(),
316 "Unable to select parameters for filtering.\n"
317 "You must select a reference field in a MED file before." );
321 MESSAGE("Select an input Field in MED file before filtering!!");
322 QMessageBox::information( application()->desktop(),
324 "Unable to select parameters for filtering.\n"
325 "You must select a reference field in a MED file before." );
331 MESSAGE("command " << theCommandID << " activated");
333 // Selection du Fichier
334 file = SUIT_FileDlg::getFileName(application()->desktop(),
337 tr("FILTER_MEN_IMPORT"),
339 if (!file.isEmpty() ){
340 _sel = new SelectField(this,file);
341 if ( _sel->exec() == QDialog::Rejected ){
351 app->updateActions(); //SRN: To update a Save button in the toolbar
357 //=============================================================================
361 //=============================================================================
362 bool FilterGUI::OnMousePress (QMouseEvent* pe ,
363 SUIT_ViewWindow* wnd )
365 MESSAGE("FilterGUI::OnMousePress");
369 //=============================================================================
373 //=============================================================================
374 bool FilterGUI::OnMouseMove (QMouseEvent* pe ,
375 SUIT_ViewWindow* wnd )
377 // MESSAGE("FilterGUI::OnMouseMouve");
381 //=============================================================================
385 //=============================================================================
386 bool FilterGUI::OnKeyPress (QKeyEvent* pe,
387 SUIT_ViewWindow* wnd)
389 MESSAGE("FilterGUI::OnKeyPress");
393 //=============================================================================
397 //=============================================================================
398 void FilterGUI::setOrb()
401 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
402 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
403 _orb = init( 0 , 0 );
405 INFOS("internal error : orb not found");
408 ASSERT(! CORBA::is_nil(_orb));
412 Standard_EXPORT CAM_Module* createModule() {
413 return new FilterGUI();