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>
61 //VRV: porting on Qt 3.0.5
62 #if QT_VERSION >= 0x030005
63 #include <qlineedit.h>
65 //VRV: porting on Qt 3.0.5
69 static CORBA::ORB_var _orb;
71 //=============================================================================
75 //=============================================================================
76 FilterGUI::FilterGUI() :
77 SalomeApp_Module( "FILTER" ),_sel(0)
81 //=============================================================================
85 //=============================================================================
86 void FilterGUI::createPopupItem( const int id,
87 const QString& clients,
89 const QString& theRule,
94 parentId = popupMgr()->actionId( action( pId ) );
96 if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
97 popupMgr()->insert( action( id ), parentId, 0 );
99 QChar lc = QtxPopupMgr::Selection::defEquality();
100 QString rule = "(%1)";
101 if( !types.isEmpty() )
102 rule += " and (%2) and (%3)";
104 rule = rule.arg( QString( "client in {%1}" ).arg( clients ) );
106 if( !types.isEmpty() )
108 rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
109 rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
112 popupMgr()->setRule( action( id ), rule, true );
115 void FilterGUI::createFilterAction( const int id, const QString& po_id, const QString& icon_id )
117 QWidget* parent = application()->desktop();
118 SUIT_ResourceMgr* mgr = application()->resourceMgr();
120 QPixmap pix; QIconSet icon;
121 if( !icon_id.isEmpty() )
122 pix = mgr->loadPixmap( "FILTER", tr( icon_id ) );
124 // pix = mgr->loadPixmap( "FILTER", tr( QString( "ICO_" )+po_id ) );
127 icon = QIconSet( pix );
129 createAction( id, tr( "TOP_" + po_id ), icon, tr( "MEN_" + po_id ), tr( "STB_" + po_id ), 0, parent, false, this, SLOT( onGUIEvent() ) );
132 //=============================================================================
136 //=============================================================================
137 void FilterGUI::initialize( CAM_Application* app )
139 SalomeApp_Module::initialize( app );
141 QWidget* parent = application()->desktop();
143 createFilterAction( 111, "OPEN" );
145 createFilterAction( 936, "FILTERING" );
147 int fileId = createMenu( tr( "MEN_FILE" ), -1, 1 );
148 createMenu( 111, fileId, 11 );
150 int FilterId = createMenu( tr( "DATA REDUCTION" ), -1, 50, 10 );
151 createMenu( separator(), FilterId, 10 );
152 createMenu( 936, FilterId, 11 );
156 void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
158 FilterGUI_Selection sel;
159 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
162 sel.init( client, app->selectionMgr() );
163 popupMgr()->updatePopup( menu, &sel );
167 QString FilterGUI::engineIOR() const
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( "" );
175 void FilterGUI::windows( QMap<int, int>& mappa ) const
177 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
178 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
182 //=============================================================================
186 //=============================================================================
187 void FilterGUI::onGUIEvent()
189 const QObject* obj = sender();
190 if ( !obj || !obj->inherits( "QAction" ) )
192 int id = actionId((QAction*)obj);
197 //=============================================================================
201 //=============================================================================
202 void FilterGUI::EmitSignalCloseAllDialogs()
204 emit SignalCloseAllDialogs();
207 //=============================================================================
211 //=============================================================================
212 bool FilterGUI::deactivateModule( SUIT_Study* study )
214 setMenuShown( false );
215 setToolShown( false );
217 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
218 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
220 EmitSignalCloseAllDialogs();
222 return SalomeApp_Module::deactivateModule( study );
225 //=============================================================================
229 //=============================================================================
230 bool FilterGUI::activateModule( SUIT_Study* study )
232 bool res = SalomeApp_Module::activateModule( study );
234 setMenuShown( true );
235 setToolShown( true );
237 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
238 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
242 //=============================================================================
246 //=============================================================================
247 void FilterGUI::onWindowActivated( SUIT_ViewWindow* )
251 //=============================================================================
255 //=============================================================================
256 bool FilterGUI::OnGUIEvent (int theCommandID)
260 SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
264 _PTR(Study) aStudy = myActiveStudy->studyDS();
265 //SALOME_NamingService* myNameService = parent->getNameService();
268 QStringList filtersList ;
270 filtersList.append( tr("FILTER_MEN_IMPORT_MED") );
271 filtersList.append( tr("FILTER_MEN_ALL_FILES") ) ;
273 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
277 switch (theCommandID)
281 MESSAGE("command " << theCommandID << " activated");
284 SelectParams *filter = new SelectParams(this,_sel);
286 catch ( SALOME_Exception& S_ex ) {
292 MESSAGE("command " << theCommandID << " activated");
294 // Selection du Fichier
295 file = SUIT_FileDlg::getFileName(application()->desktop(),
298 tr("FILTER_MEN_IMPORT"),
300 if (!file.isEmpty() )
301 _sel = new SelectField(this,file);
307 app->updateActions(); //SRN: To update a Save button in the toolbar
313 //=============================================================================
317 //=============================================================================
318 bool FilterGUI::OnMousePress (QMouseEvent* pe ,
319 SUIT_ViewWindow* wnd )
321 MESSAGE("FilterGUI::OnMousePress");
325 //=============================================================================
329 //=============================================================================
330 bool FilterGUI::OnMouseMove (QMouseEvent* pe ,
331 SUIT_ViewWindow* wnd )
333 // MESSAGE("FilterGUI::OnMouseMouve");
337 //=============================================================================
341 //=============================================================================
342 bool FilterGUI::OnKeyPress (QKeyEvent* pe,
343 SUIT_ViewWindow* wnd)
345 MESSAGE("FilterGUI::OnKeyPress");
349 //=============================================================================
353 //=============================================================================
354 void FilterGUI::setOrb()
357 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
358 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
359 _orb = init( 0 , 0 );
361 INFOS("internal error : orb not found");
364 ASSERT(! CORBA::is_nil(_orb));
368 Standard_EXPORT CAM_Module* createModule() {
369 return new FilterGUI();