Salome HOME
This commit was generated by cvs2git to create tag 'V4_1_0a3'.
[modules/filter.git] / src / FILTERGUI / SelectParams.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <stdlib.h>
22 #include <math.h>
23 #include "SelectParams.h"
24 #include "MEDMEM_MedMeshDriver.hxx"
25 #include "MEDMEM_EnsightMeshDriver.hxx"
26
27 #include <SUIT_FileDlg.h>
28
29 #include "Utils_SALOME_Exception.hxx"
30 #include <SalomeApp_Tools.h>
31
32 #include <qlabel.h>
33 #include <qgroupbox.h>
34 #include <qframe.h>
35 #include <qlayout.h>
36 #include <qlineedit.h>
37 #include <qbuttongroup.h>
38 #include <qradiobutton.h>
39 #include <qpushbutton.h>
40 #include <qfiledialog.h>
41 #include <qmessagebox.h>
42 #include <qcursor.h>
43
44 SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
45                            const char* name,
46                            bool modal, WFlags fl) throw(SALOME_Exception)
47   : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),_size(1024),_sel(sel)
48 {
49   MESSAGE("SelectParams constructor");
50   if(sel){
51     // read reference field values
52     _filter = sel->getFilter();
53
54     // Get reference field and time step
55     _inputFile = sel->getFile();
56     _inputMesh = sel->getMesh();
57     _inputField = sel->getField();
58     _inputTS = sel->getTimeStep();
59
60     if( _inputFile.isEmpty() || _inputMesh.isEmpty() || _inputField.isEmpty())
61       throw SALOME_Exception("Select an input Field in MED file before filtering!!");
62     
63     _filter->readReferenceField(_inputMesh,_inputField,_inputTS);
64
65     // Build QT widgets
66     buildFrame();
67   }
68   // if no reference field selection: throw exception
69   else
70     throw SALOME_Exception("Select an input Field in MED file before filtering!!");
71
72   // Allocate histogram arrays
73   _x = new double[_size];
74   _y = new double[_size];
75
76 }
77
78 SelectParams::~SelectParams()
79 {
80   cout << "SelectParams: destructor called" << endl;
81
82   // destrcution of histogram arrays
83   delete _x;
84   delete _y;
85   
86   // destruction of SelectField object and Filter object in it
87   delete _sel;
88 }
89
90 void SelectParams::buildFrame()
91 {
92   // build widgets for select filtering parameters
93   QGridLayout* _lay = new QGridLayout( this, 1, 2 );
94
95   QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
96   _lay->addWidget( _GroupC1,0,0 );
97
98   _GroupC1->setTitle( tr( "FILTER_PARAMS"  ) );
99   _GroupC1->setColumnLayout(0, Qt::Vertical );
100   _GroupC1->layout()->setSpacing( 0 );
101   _GroupC1->layout()->setMargin( 0 );
102   _myGroupLayout = new QGridLayout( _GroupC1->layout() );
103   _myGroupLayout->setAlignment( Qt::AlignTop );
104   _myGroupLayout->setSpacing( 6 );
105   _myGroupLayout->setMargin( 11 );
106   _myGroupLayout->setColStretch( 0, 0 );
107   _myGroupLayout->setColStretch( 1, 1 );
108
109   int row = 0;
110
111   QString qs1(tr("FILTER_INPUT_FILE"));
112   qs1.append(basename((char*)(_inputFile.ascii())));
113   _myGroupLayout->addWidget( new QLabel( qs1, _GroupC1 ), row, 0 );
114   row++;
115
116   QString qs2(tr("FILTER_INPUT_MESH"));
117   qs2.append(_inputMesh);
118   _myGroupLayout->addWidget( new QLabel( qs2, _GroupC1 ), row, 0 );
119   row++;
120
121   QString qs3(tr("FILTER_INPUT_FIELD"));
122   qs3.append(_inputField);
123   _myGroupLayout->addWidget( new QLabel( qs3, _GroupC1 ), row, 0 );
124   row++;
125
126   QString qs4(tr("FILTER_INPUT_TS"));
127   char strTS[128];
128   sprintf(strTS,"%d\0",_inputTS);
129   qs4.append(strTS);
130   _myGroupLayout->addWidget( new QLabel( qs4, _GroupC1 ), row, 0 );
131   row++;
132
133   // 0)  field function to calculate histogram (radiogroup)
134   _myFunc = new QButtonGroup( tr("FILTER_SELECT_FUNC"), _GroupC1 );
135   _myFunc->setExclusive( true );
136   _myFunc->setColumnLayout( 0, Qt::Horizontal );
137
138   _myFieldB = new QRadioButton( tr("FILTER_FIELD"), _myFunc );
139   _myFieldB->setChecked(true);
140
141   QGridLayout* convLay = new QGridLayout( _myFunc->layout() );
142   convLay->addWidget( _myFieldB, 0, 0 );
143   convLay->addWidget( _myGradB = new QRadioButton( tr("FILTER_GRADIENT"), _myFunc ), 0, 1 );
144   _myGroupLayout->addWidget( _myFunc, row, 0 );
145   row++;
146
147   // 01)  histogram size (line edit)
148   _myHSize = new QButtonGroup( tr(""), _GroupC1 );
149   _myHSize->setExclusive( true );
150   _myHSize->setColumnLayout( 0, Qt::Horizontal );
151   QGridLayout* shLay = new QGridLayout( _myHSize->layout() );
152   shLay->addWidget( _myLSH = new QLabel( tr("FILTER_SIZE_HISTO") , _myHSize ), 0, 0 );
153   shLay->addWidget( _myLESH = new QLineEdit( "1024", _myHSize ), 0, 1 );
154   _myGroupLayout->addWidget( _myHSize, row, 0 );
155   row++;
156
157   // 1)  display histogram button (pushbutton)
158   _myHisto = new QPushButton( "", _GroupC1 );
159   _myHisto->setText(tr("FILTER_DISPLAY_HISTO"));
160   _myHisto->setAutoDefault(FALSE);
161   _myGroupLayout->addWidget( _myHisto, row, 0 );
162   row++;
163
164   // 2)  scale of histogram (radiogroup)
165   _myFScale = new QButtonGroup( tr("FILTER_TYPE_DISPLAY"), _GroupC1 );
166   _myFScale->setExclusive( true );
167   _myFScale->setColumnLayout( 0, Qt::Horizontal );
168
169   _myLinear = new QRadioButton( tr("FILTER_LINEAR"), _myFScale );
170   _myLinear->setChecked(true);
171   _myLog = new QRadioButton( tr("FILTER_LOG"), _myFScale );
172   _myFScale->setDisabled(true);
173
174   QGridLayout* scaleLay = new QGridLayout( _myFScale->layout() );
175   scaleLay->addWidget( _myLinear, 0, 0 );
176   scaleLay->addWidget( _myLog, 0, 1 );
177   _myGroupLayout->addWidget( _myFScale, row, 0 );
178   row++;
179
180   // 3)  number of thresholds (radiogroup)
181   _myNbThresh = new QButtonGroup( tr("FILTER_SEL_THRESH"), _GroupC1 );
182   _myNbThresh->setExclusive( true );
183   _myNbThresh->setColumnLayout( 0, Qt::Horizontal );
184   QGridLayout* nbtLay = new QGridLayout( _myNbThresh->layout() );
185   nbtLay->addWidget( _myOneThresh = new QRadioButton( tr("FILTER_ONE_THRESH"), _myNbThresh ), 0, 0 );
186   nbtLay->addWidget( _myTwoThresh = new QRadioButton( tr("FILTER_TWO_THRESH"), _myNbThresh ), 0, 1 );
187   _myGroupLayout->addWidget( _myNbThresh, row, 0 );
188
189   _myOneThresh->setChecked(true);
190   _myNbThresh->setDisabled(true);
191   row++;
192
193   // 4)  reference area on thresholds (radiogroup)
194   _myArea = new QButtonGroup( tr("FILTER_REF_AREA"), _GroupC1 );
195   _myArea->setExclusive( true );
196   _myArea->setColumnLayout( 0, Qt::Horizontal );
197   QGridLayout* areaLay = new QGridLayout( _myArea->layout() );
198   areaLay->addWidget( _myInt = new QRadioButton( tr("FILTER_BOTTOM"), _myArea ), 0, 0 );
199   areaLay->addWidget( _myExt = new QRadioButton( tr("FILTER_UP"), _myArea ), 0, 1 );
200   _myGroupLayout->addWidget( _myArea, row, 0 );
201
202   _myExt->setChecked(true);
203   _myArea->setDisabled(true);
204   row++;
205
206   // 5)  threshold values (line edit)
207   _myVThresh = new QButtonGroup( tr("FILTER_TRESH_VAL"), _GroupC1 );
208   _myVThresh->setExclusive( true );
209   _myVThresh->setColumnLayout( 0, Qt::Horizontal );
210   QGridLayout* ftLay = new QGridLayout( _myVThresh->layout() );
211   ftLay->addWidget( _myLFT = new QLabel( tr("FILTER_VAL_TRESH") , _myVThresh ), 0, 0 );
212   ftLay->addWidget( _myLEFT = new QLineEdit( "", _myVThresh ), 0, 1 );
213   ftLay->addWidget( _myLST = new QLabel( tr("FILTER_VAL_2_TRESH") , _myVThresh ), 1, 0 );
214   ftLay->addWidget( _myLEST = new QLineEdit( "", _myVThresh ), 1, 1 );
215   _myGroupLayout->addWidget( _myVThresh, row, 0 );
216
217   _myVThresh->setDisabled(true);
218   _myLST->hide();
219   _myLEST->hide();
220   row++;
221
222   // 6)  output file name (line edit)
223   _myOutFile = new QButtonGroup( tr("FILTER_OUT_FILE"), _GroupC1 );
224   _myOutFile->setExclusive( true );
225   _myOutFile->setColumnLayout( 0, Qt::Horizontal );
226
227   _myOFB = new QPushButton( "", _myOutFile );
228   _myOFB->setText(tr("FILTER_BROWSE"));
229   _myOFB->setAutoDefault(FALSE);
230
231   QGridLayout* outLay = new QGridLayout( _myOutFile->layout() );
232   outLay->addWidget( _myOFB, 0, 0 );
233   outLay->addWidget( _myOFN = new QLineEdit( "", _myOutFile ), 0, 1 );
234   _myGroupLayout->addWidget( _myOutFile, row, 0 );
235
236   _myOutFile->setDisabled(true);
237   row++;
238
239   // 8)  buttons Process, Close and Help 
240   _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
241   _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
242   _GroupButtons->setTitle(tr("" ));
243   _GroupButtons->setColumnLayout(0, Qt::Vertical);
244   _GroupButtons->layout()->setSpacing(0);
245   _GroupButtons->layout()->setMargin(0);
246   _GroupButtonsLayout = new QGridLayout(_GroupButtons->layout());
247   _GroupButtonsLayout->setAlignment(Qt::AlignTop);
248   _GroupButtonsLayout->setSpacing(6);
249   _GroupButtonsLayout->setMargin(11);
250   _myProc = new QPushButton(_GroupButtons, "buttonProcess");
251   _myProc->setText(tr("FILTER_PROCESS"));
252   _myProc->setAutoDefault(FALSE);
253   _GroupButtonsLayout->addWidget(_myProc, 0, 0);
254   _buttonHelp = new QPushButton(_GroupButtons, "buttonHelp");
255   _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
256   _buttonHelp->setAutoDefault(FALSE);
257   _GroupButtonsLayout->addWidget(_buttonHelp, 0, 2);
258   _buttonCancel = new QPushButton(_GroupButtons, "buttonCancel");
259   _buttonCancel->setText(tr("FILTER_BUT_CANCEL" ));
260   _buttonCancel->setAutoDefault(FALSE);
261   _GroupButtonsLayout->addWidget(_buttonCancel, 0, 1);
262   _myGroupLayout->addWidget( _GroupButtons, row, 0 );
263   _GroupButtons->setDisabled(true);
264   row++;
265
266   _GroupC2 = new QGroupBox( this, "GroupC2" );
267   _lay->addWidget( _GroupC2,0,1 );
268
269   _GroupC2->setTitle( tr( "FILTER_HISTO" ) );
270   _GroupC2->setColumnLayout(0, Qt::Vertical );
271   _GroupC2->layout()->setSpacing( 0 );
272   _GroupC2->layout()->setMargin( 0 );
273   _myGroupLayout2 = new QGridLayout( _GroupC2->layout() );
274
275   // 9)  histogram curve
276   _myPlot = new QwtPlot(_GroupC2);
277   _myHistoCurve = _myPlot->insertCurve( QString() );
278   _myPlot->setCurvePen( _myHistoCurve, QPen( Qt::red, 1 ) );
279   _myPlot->setCurveTitle( _myHistoCurve, "Histogram" );
280
281   _myGroupLayout2->addWidget( _myPlot, 0, 0 );
282
283   // 10)  reduction rate (label)
284   QString qs5(tr("FILTER_RED_RATE"));
285   qs5.append(" = 0.5");
286   _myLRR = new QLabel( qs5, _GroupC2 );
287   _myGroupLayout2->addWidget( _myLRR, 1, 0 );
288
289   _GroupC2->hide();
290
291   _myHistoFThresh = _myPlot->insertCurve( QString() );
292   _myPlot->setCurvePen( _myHistoFThresh, QPen( Qt::black, 1 ) );
293   _myHistoSThresh = _myPlot->insertCurve( QString() );
294   _myPlot->setCurvePen( _myHistoSThresh, QPen( Qt::black, 1 ) );
295
296   connect( _myGradB, SIGNAL(clicked()), this, SLOT(gradSelected()));
297   connect( _myLESH, SIGNAL(returnPressed()), this, SLOT(enterSHisto()));
298   connect( _myHisto, SIGNAL(clicked()), this, SLOT(updateHisto()));
299   connect( _myLinear, SIGNAL(clicked()), this, SLOT(scaleSelected()));
300   connect( _myLog, SIGNAL(clicked()), this, SLOT(scaleSelected()));
301   connect( _myOneThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
302   connect( _myTwoThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
303   connect( _myInt, SIGNAL(clicked()), this, SLOT(areaSelected()));
304   connect( _myExt, SIGNAL(clicked()), this, SLOT(areaSelected()));
305   connect( _myLEFT, SIGNAL(returnPressed()), this, SLOT(enterFThresh()));
306   connect( _myLEST, SIGNAL(returnPressed()), this, SLOT(enterSThresh()));
307   connect( _myPlot, SIGNAL(plotMouseMoved(const QMouseEvent &)), this, SLOT(moveThresh(const QMouseEvent &)));
308   connect( _myOFB, SIGNAL(clicked()), this, SLOT(getOutFileName()));
309   connect( _myProc, SIGNAL(clicked()), this, SLOT(process()));
310   connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
311   connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
312
313   _GroupC2->setMinimumSize( 500, 500 );
314   _GroupC2->setMaximumSize( 500, 500 );
315   setMinimumSize( 750, 500 );
316   setMaximumSize( 750, 500 );
317
318 }
319
320 void SelectParams::gradSelected()
321 {
322   try{
323     setCursor(QCursor(Qt::WaitCursor));
324     _filter->buildGradient();
325     setCursor(QCursor(Qt::ArrowCursor));
326   }
327   catch(SALOME_FILTER::FILTER_Gen::FilterError){
328     _myFieldB->setChecked(true);
329     QMessageBox::information( this,
330                               "Filtering",
331                               "Unable to calculate gradient on vector field.\n"
332                               "You must select a reference scalar field." );
333   }
334   catch(...){
335     MESSAGE("unknownException");
336   }
337 }
338
339 void SelectParams::enterSHisto()
340 {
341   // Deallocate old histogram arrays
342   delete _x;
343   delete _y;
344
345   // get new histogram size
346   _size = atoi(_myLESH->text());
347
348   // Allocate new histogram arrays
349   _x = new double[_size];
350   _y = new double[_size];
351 }
352
353 void SelectParams::scaleSelected()
354 {
355   // draw linear or log Y scale depend on user
356   if( _myLinear->isChecked() ){
357     _ymin = 0.0;
358     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
359   }
360   else{
361     // set min to 0.1 for log scale
362     _ymin = 0.1;
363     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
364   }
365   _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
366   _myPlot->replot();
367 }
368
369 void SelectParams::nbThreshSelected()
370 {
371   if( _myOneThresh->isChecked() ){
372     // if one threshold choice between bottom and up for reference area
373     _myInt->setText(tr("FILTER_BOTTOM"));
374     _myExt->setText(tr("FILTER_UP"));
375     _myLFT->setText(tr("FILTER_VAL_TRESH"));
376     _myLST->hide();
377     _myLEST->hide();
378     // draw first threshold
379     displayFThresh();
380     // erase second threshold
381     clearSThresh();
382   }
383   else{
384     // if two thresholds choice between interior and exterior fir reference area
385     _myInt->setText(tr("FILTER_INT"));
386     _myExt->setText(tr("FILTER_EXT"));
387     _myLFT->setText(tr("FILTER_VAL_1_TRESH"));
388     if(_myLST->isHidden())
389       _myLST->show();
390     if(_myLEST->isHidden())
391       _myLEST->show();
392     // draw two thresholds
393     displayFThresh();
394     displaySThresh();
395   }
396   calcRateRed();
397 }
398
399 void SelectParams::areaSelected()
400 {
401   // calculate reduction rate after thresholds selection
402   calcRateRed();
403 }
404
405 void SelectParams::enterFThresh()
406 {
407   displayFThresh();
408   calcRateRed();
409 }
410
411 void SelectParams::enterSThresh()
412 {
413   displaySThresh();
414   calcRateRed();
415 }
416
417 void SelectParams::calcHisto()
418 {
419   char strth[128];
420   CORBA::Double min, max;
421   CORBA::Long size = _size;
422   SALOME_FILTER::LongSeq* histo;
423
424   if( _myFieldB->isChecked() ){
425     // calculate histogram values on field
426     _filter->getMinMax(min,max,SALOME_FILTER::F_FIELD);
427     histo = _filter->getHistogram(size,SALOME_FILTER::F_FIELD);
428   }
429   else{
430     // calculate histogram values on gradient
431      _filter->getMinMax(min,max,SALOME_FILTER::F_GRAD);
432     histo = _filter->getHistogram(size,SALOME_FILTER::F_GRAD);
433   }
434   _xmin = min;
435   _xmax = max;
436   vector<int> myh(_size);
437   for(int i=0;i<_size;i++)
438     myh[i] = (*histo)[i];
439
440   if( _myLinear->isChecked() )
441     _ymin = 0.0;
442   else
443     _ymin = 0.1;
444   _ymax = 0.0;
445
446   for(int i=0;i<_size;i++){
447     // calculate absisses for histogram values
448     _x[i]=_xmin+(i*(_xmax-_xmin))/_size;
449     // set zero to 0.01 because pb of zeros in log display with qwt
450     if(myh[i])
451       _y[i]=(double)myh[i];
452     else
453       _y[i]=0.01;
454     if( _y[i] > _ymax )
455       _ymax = _y[i];
456   }
457
458   // init thresholds values
459   _fthresh = (_xmin + _xmax)/2.0;
460   _sthresh = (_xmin + 3.*_xmax)/4.0;
461   sprintf(strth,"%g",_fthresh);
462   _myLEFT->setText(QString(strth));
463   sprintf(strth,"%g",_sthresh);
464   _myLEST->setText(QString(strth));
465 }
466
467 void SelectParams::displayHisto()
468 {
469   // associate values to curve
470   _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
471   // give extrema values for each axis
472   _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax );
473   _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
474   if( _myLinear->isChecked() )
475     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
476   else
477     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
478   // associate mapping to plot to move thresholds on display
479   _qmap = _myPlot->canvasMap(_myPlot->curveXAxis( _myHistoCurve ));
480   _qmap.setDblRange(_xmin,_xmax);
481   _myPlot->replot();
482 }
483
484 void SelectParams::enableWidgets()
485 {
486   if(_GroupC2->isHidden()){
487     _myFScale->setEnabled(true);
488     _myNbThresh->setEnabled(true);
489     _myArea->setEnabled(true);
490     _myVThresh->setEnabled(true);
491     _myOutFile->setEnabled(true);
492     _GroupButtons->setEnabled(true);
493     _GroupC2->show();
494   }
495 }
496
497 void SelectParams::updateHisto()
498 {
499   calcHisto();
500   displayHisto();
501   displayFThresh();
502   if( _myTwoThresh->isChecked() )
503     displaySThresh();
504   calcRateRed();
505   enableWidgets();
506 }
507
508 void SelectParams::displayFThresh()
509 {
510   _fthresh = atof(_myLEFT->text());
511
512   // draw first threshold curve
513   for(int i=0;i<100;i++){
514     _xft[i]=_fthresh;
515     _yft[i]=((i-1)*_ymax)/100.0;
516   }
517   _myPlot->setCurveData( _myHistoFThresh, _xft, _yft, 100 );
518   _myPlot->replot();
519 }
520
521 void SelectParams::displaySThresh()
522 {
523   _sthresh = atof(_myLEST->text());
524
525   // draw second threshold curve
526   for(int i=0;i<100;i++){
527     _xst[i]=_sthresh;
528     _yst[i]=((i-1)*_ymax)/100.0;
529   }
530   _myPlot->setCurveData( _myHistoSThresh, _xst, _yst, 100 );
531   _myPlot->replot();
532 }
533
534 void SelectParams::clearSThresh()
535 {
536   _sthresh = atof(_myLEST->text());
537
538   // erase second threshold curve
539   for(int i=0;i<100;i++){
540     _xst[i]=_sthresh;
541     _yst[i]=0.0;
542   }
543   _myPlot->setCurveData( _myHistoSThresh, _xst, _yst, 100 );
544   _myPlot->replot();
545 }
546
547 void SelectParams::moveThresh(const QMouseEvent &e)
548 {
549   char strth[128];
550
551   // move threshold curve with mouse
552   int delta = abs(e.x()-_qmap.transform(_fthresh));
553   if( delta < 5 ){
554     // moving first threshold curve
555     sprintf(strth,"%g",_qmap.invTransform(e.x()));
556     _myLEFT->setText(QString(strth));
557     displayFThresh();
558   }
559   else if( _myTwoThresh->isChecked() ){
560     delta = abs(e.x()-_qmap.transform(_sthresh));
561     if( delta < 5 ){
562       // moving second threshold curve
563       sprintf(strth,"%g",_qmap.invTransform(e.x()));
564       _myLEST->setText(QString(strth));
565       displaySThresh();
566     }
567   }
568   calcRateRed();
569 }
570
571 void SelectParams::getOutFileName()
572 {
573   // get output MED file name
574   QString file = QFileDialog::getSaveFileName("",
575                                               "*.med",
576                                               _myOFB,
577                                               "save file dialog",
578                                               "Choose a file to save" );
579   if(!file.isEmpty())
580     _myOFN->setText(file);
581
582   // Selection du Fichier
583 //   file = SUIT_FileDlg::getFileName(application()->desktop(),
584 //                                 "",
585 //                                 filtersList,
586 //                                 "Output MED file name",
587 //                                 true);
588 }
589
590 void SelectParams::process() throw(SALOME_Exception)
591 {
592   int nbthresh;
593   string command;
594
595   MESSAGE("Input MED File : "<<_inputFile);
596   MESSAGE("Input Mesh : "<<_inputMesh);
597   MESSAGE("Input Field : "<<_inputField);
598   MESSAGE("Input Time Step : "<<_inputTS);
599   MESSAGE("Output file name: " << _myOFN->text() );
600
601   setCursor(QCursor(Qt::WaitCursor));
602
603   MESSAGE("Generate Criteria");
604   // generate MED integer field (0 or 1) for filtoo input
605   try{
606     if( _myOneThresh->isChecked() )
607       nbthresh = 1;
608     else
609       nbthresh = 2;
610     SALOME_FILTER::ref_func rf;
611     if(_myFieldB->isChecked())
612       rf = SALOME_FILTER::F_FIELD;
613     else
614       rf = SALOME_FILTER::F_GRAD;
615     _filter->generateCriteria(nbthresh,_fthresh,_sthresh,_myExt->isChecked(),rf);
616   }
617   catch (SALOME_FILTER::FILTER_Gen::FilterError){
618     QMessageBox::information( this,
619                               "Filtering",
620                               "Unable to process filtering.\n"
621                               "You must select a reference field on nodes." );
622     reject();
623     return;
624   }
625
626   // create ensight input files to filtoo
627   try{
628     _filter->createEnsightInputFiles();
629   }
630   catch (SALOME_FILTER::FILTER_Gen::FilterError& ex){
631     throw SALOME_Exception(ex.error_msg);
632   }
633
634   // call filtoo
635   try{
636     _filter->filtering();
637   }
638   catch (SALOME_FILTER::FILTER_Gen::FilterError){
639     QMessageBox::information( this,
640                               "Filtering",
641                               "Unable to process filtering.\n"
642                               "FILTOO ERROR see /tmp/filter.log file." );
643     reject();
644     return;
645   }
646  
647   // project input fields on new mesh
648   try{
649     _filter->projectFieldsOnDecimateMesh();
650   }
651   catch (SALOME_FILTER::FILTER_Gen::FilterError& ex){
652     throw SALOME_Exception(ex.error_msg);
653   }
654
655   // create new MED file with new mesh and fields
656   _filter->createMedOutputFile(_myOFN->text());
657
658   QMessageBox::information( this,
659                             "Filtering",
660                             "Filtering done.\n"
661                             "" );
662   // close the window
663   accept();
664
665 }
666
667 void SelectParams::calcRateRed()
668 {
669   int i1, i2, i;
670   int atot=0, asel=0, atot1;
671   double rateRed=0.0;
672
673   // calculate reduction rate depend on reference area defined by threshold values
674   i1 = (int)((double)_size * ( _fthresh - _xmin ) / ( _xmax - _xmin ));
675   if( _myOneThresh->isChecked() ){
676     for(i=0;i<i1;i++)
677       atot += (int)_y[i];
678     asel = atot;
679     for(i=i1;i<_size;i++)
680       atot += (int)_y[i];
681     if( _myExt->isChecked() )
682       asel = atot - asel;
683   }
684   else{
685     i2 = (int)((double)_size * ( _sthresh - _xmin ) / ( _xmax - _xmin ));
686     if( i2 < i1 ){
687       i=i1;
688       i1=i2;
689       i2=i;
690     }
691     for(i=0;i<i1;i++)
692       atot += (int)_y[i];
693     atot1=atot;
694     for(i=i1;i<i2;i++)
695       atot += (int)_y[i];
696     asel = atot - atot1;
697     for(i=i2;i<_size;i++)
698       atot += (int)_y[i];
699     if( _myExt->isChecked() )
700       asel = atot - asel;
701   }
702   rateRed = (double)asel / (double) atot;
703
704   // display reduction rate value
705   QString qs(tr("FILTER_RED_RATE"));
706   char str[128];
707   sprintf(str," = %4.2g",rateRed);
708   qs.append(str);
709   _myLRR->setText( qs );
710
711 }
712
713 void SelectParams::ClickOnCancel()
714 {
715   MESSAGE("click on Cancel");
716   reject();
717 }
718
719 void SelectParams::ClickOnHelp()
720 {
721   MESSAGE("click on Help");
722 }