]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx
Salome HOME
Module MULTIPR
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI_Dlg.cxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_GUI_Dlg.cxx
6  *
7  * \brief   see MULTIPR_GUI_Dlg.h
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13   
14 //*****************************************************************************
15 // Includes section
16 //*****************************************************************************
17
18 #include "MULTIPR_GUI_Dlg.h"
19 #include "MULTIPR_GUI.h"
20 #include "MULTIPR_Mesh.hxx"
21 #include "MULTIPR_DecimationFilter.hxx"
22
23 // Salome Includes
24 #include <SUIT_MessageBox.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_DataModel.h>
29 #include <SalomeApp_Study.h>
30 #include <SalomeApp_CheckFileDlg.h>
31 #include <LightApp_Study.h>
32 #include <LightApp_DataModel.h>
33 #include <LightApp_DataOwner.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <CAM_DataModel.h>
36 #include <CAM_Module.h>
37
38 #include <SALOME_LifeCycleCORBA.hxx>
39
40 #include <QtxPopupMgr.h>
41
42 // QT Includes
43 #include <qapplication.h>
44 #include <qinputdialog.h>
45 #include <qlayout.h>
46 #include <qpushbutton.h>
47 #include <qgroupbox.h>
48 #include <qvbox.h>
49 #include <qbuttongroup.h>
50 #include <qlabel.h>
51 #include <qcombobox.h>
52 #include <qvariant.h>
53 #include <qlineedit.h>
54 #include <qspinbox.h>
55 #include <qtooltip.h>
56 #include <qwhatsthis.h>
57 #include <qimage.h>
58 #include <qpixmap.h>
59
60
61 using namespace std;
62
63
64 MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : 
65         QDialog( theModule->application()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
66 {
67         mModule = theModule;
68         
69     buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
70     buttonGroupProcess->setGeometry( QRect( 10, 110, 450, 60 ) );
71
72     pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
73     pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
74
75     pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
76     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
77
78     buttonGroupSelectMesh = new QButtonGroup( this, "buttonGroupSelectMesh" );
79     buttonGroupSelectMesh->setGeometry( QRect( 10, 10, 450, 91 ) );
80
81     comboBoxSelectMesh = new QComboBox( FALSE, buttonGroupSelectMesh, "comboBoxSelectMesh" );
82     comboBoxSelectMesh->setGeometry( QRect( 160, 30, 280, 40 ) );
83         MULTIPR_ORB::string_array* listMeshes = theModule->getMULTIPRObj()->getMeshes();
84         for (int i=0; i<listMeshes->length() ; i++)
85         {
86                 const char* strItem = (*listMeshes)[i];
87                 comboBoxSelectMesh->insertItem(strItem);
88         }
89         comboBoxSelectMesh->setEditable(false);
90
91     textLabelSelectMesh = new QLabel( buttonGroupSelectMesh, "textLabelSelectMesh" );
92     textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) );
93     
94         setCaption( tr( "Extract groups from sequential MED file" ) );
95     buttonGroupProcess->setTitle( QString::null );
96     pushButtonCancel->setText( tr( "Cancel" ) );
97     pushButtonOK->setText( tr("OK") );
98     buttonGroupSelectMesh->setTitle( tr( "Select mesh" ) );
99     textLabelSelectMesh->setText( tr( "Mesh name" ) );
100         
101     resize( QSize(471, 185).expandedTo(minimumSizeHint()) );
102     clearWState( WState_Polished );
103         
104         connect(pushButtonOK,     SIGNAL(clicked()), this, SLOT(accept()));
105         connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
106 }
107
108
109 /*
110  *  Destroys the object and frees any allocated resources
111  */
112 MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg()
113 {
114     // no need to delete child widgets, Qt does it all for us
115 }
116
117
118 void MULTIPR_GUI_Partition1Dlg::accept()
119 {
120         const char* meshName = comboBoxSelectMesh->currentText().latin1();
121         
122         try
123         {
124                 mModule->getMULTIPRObj()->setMesh(meshName);
125                 
126                 QApplication::setOverrideCursor(Qt::waitCursor);
127                 mModule->getMULTIPRObj()->partitionneDomaine();
128                 QApplication::restoreOverrideCursor();
129                 
130         }
131         catch(...)
132         {
133                 SUIT_MessageBox::error1( 
134                         mModule->getAppli()->desktop(),
135                         "Import MED file error", 
136                         "Unable to set mesh", 
137                         tr("OK") );
138         }
139
140         QDialog::accept();
141         mModule->getAppli()->updateObjectBrowser();
142 }
143
144
145 void MULTIPR_GUI_Partition1Dlg::reject()
146 {
147         QDialog::reject();
148 }
149
150
151 MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) : 
152         QDialog( theModule->application()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
153 {
154         mModule = theModule;
155         
156     buttonGroupSplitParameters = new QButtonGroup( this, "buttonGroupSplitParameters" );
157     buttonGroupSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) );
158
159     textLabelSelectNbParts = new QLabel( buttonGroupSplitParameters, "textLabelSelectNbParts" );
160     textLabelSelectNbParts->setGeometry( QRect( 30, 30, 160, 31 ) );
161
162     textLabelSelectSplitter = new QLabel( buttonGroupSplitParameters, "textLabelSelectSplitter" );
163     textLabelSelectSplitter->setGeometry( QRect( 30, 80, 111, 31 ) );
164
165     comboBoxSelectSplitter = new QComboBox( FALSE, buttonGroupSplitParameters, "comboBoxSelectSplitter" );
166     comboBoxSelectSplitter->setGeometry( QRect( 210, 80, 150, 40 ) );
167         comboBoxSelectSplitter->insertItem("METIS");
168         comboBoxSelectSplitter->insertItem("SCOTCH");
169         comboBoxSelectSplitter->setEditable(false);
170
171     spinBoxNbParts = new QSpinBox( buttonGroupSplitParameters, "spinBoxNbParts" );
172     spinBoxNbParts->setGeometry( QRect( 210, 30, 150, 30 ) );
173     spinBoxNbParts->setMaxValue( 1000 );
174     spinBoxNbParts->setMinValue( 2 );
175     spinBoxNbParts->setValue( 2 );
176
177     buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
178     buttonGroupProcess->setGeometry( QRect( 10, 160, 380, 60 ) );
179
180     pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
181     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
182
183     pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
184     pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) );
185     
186         setCaption( tr( "Split selected part" ) );
187     buttonGroupSplitParameters->setTitle( tr( "Split parameters" ) );
188     textLabelSelectNbParts->setText( tr( "Number of sub-parts" ) );
189     textLabelSelectSplitter->setText( tr( "Splitter" ) );
190     buttonGroupProcess->setTitle( QString::null );
191     pushButtonOK->setText( tr("OK") );
192     pushButtonCancel->setText( tr( "Cancel" ) );
193         
194     resize( QSize(403, 234).expandedTo(minimumSizeHint()) );
195     clearWState( WState_Polished );
196         
197         connect(pushButtonOK,     SIGNAL(clicked()), this, SLOT(accept()));
198         connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
199 }
200
201 /*
202  *  Destroys the object and frees any allocated resources
203  */
204 MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg()
205 {
206     // no need to delete child widgets, Qt does it all for us
207 }
208
209
210 void MULTIPR_GUI_Partition2Dlg::accept()
211 {
212         const char* strSplitter = comboBoxSelectSplitter->currentText().latin1();
213         int nbParts = spinBoxNbParts->value();
214         int partitionner = -1;
215         if (strcmp(strSplitter, "METIS") == 0)
216         {
217                 partitionner = 0;
218         }
219         else if (strcmp(strSplitter, "SCOTCH") == 0)
220         {
221                 partitionner = 1;
222         }
223         
224         QApplication::setOverrideCursor(Qt::waitCursor);
225         
226         try
227         {
228                 const QStringList& partsList = mModule->getSelectedParts();
229                 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
230                 {
231                         const QString& partName = (*it);
232                         cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter;
233                         mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner);
234                 }
235                 
236         }
237         catch(...)
238         {
239                 SUIT_MessageBox::error1( 
240                         mModule->getAppli()->desktop(),
241                         "Split error", 
242                         "Error while splitting selected part(s)", 
243                         tr("OK") );
244         }
245         
246         QApplication::restoreOverrideCursor();
247         QDialog::accept();
248 }
249
250
251 void MULTIPR_GUI_Partition2Dlg::reject()
252 {
253         QDialog::reject();
254 }
255
256
257 MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) :
258         QDialog( theModule->application()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
259 {
260         mModule = theModule;
261         
262     buttonGroupSelectField = new QButtonGroup( this, "buttonGroupSelectField" );
263     buttonGroupSelectField->setGeometry( QRect( 10, 10, 450, 140 ) );
264
265     textLabelSelectFieldName = new QLabel( buttonGroupSelectField, "textLabelSelectFieldName" );
266     textLabelSelectFieldName->setGeometry( QRect( 30, 30, 141, 31 ) );
267
268     textLabelSelectFieldIteration = new QLabel( buttonGroupSelectField, "textLabelSelectFieldIteration" );
269     textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) );
270
271         MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields();
272         int maxIteration = 0;
273         for (int i=0 ; i<listFields->length() ; i++)
274         {
275                 const char* strItem = (*listFields)[i];
276                 CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem);
277                 if (nbIteration > maxIteration) 
278                 {
279                         maxIteration = nbIteration;
280                 }
281         }
282         
283     comboBoxSelectFieldIteration = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldIteration" );
284     comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 280, 40 ) );
285         for (int i=1 ; i<=maxIteration ; i++)
286         {
287                 comboBoxSelectFieldIteration->insertItem(QString::number(i));
288         }
289
290     comboBoxSelectFieldName = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldName" );
291     comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 280, 40 ) );
292         for (int i=0 ; i<listFields->length() ; i++)
293         {
294                 const char* strItem = (*listFields)[i];
295                 comboBoxSelectFieldName->insertItem(strItem);
296         }
297         comboBoxSelectFieldName->setEditable(false);
298         QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) );
299
300     buttonGroupSelectFilter = new QButtonGroup( this, "buttonGroupSelectFilter" );
301     buttonGroupSelectFilter->setGeometry( QRect( 10, 160, 450, 90 ) );
302
303     textLabelSelectFilter = new QLabel( buttonGroupSelectFilter, "textLabelSelectFilter" );
304     textLabelSelectFilter->setGeometry( QRect( 30, 30, 101, 31 ) );
305
306     comboBoxSelectFilter = new QComboBox( FALSE, buttonGroupSelectFilter, "comboBoxSelectFilter" );
307     comboBoxSelectFilter->setGeometry( QRect( 150, 30, 280, 40 ) );
308         comboBoxSelectFilter->insertItem("Filtre_GradientMoyen");
309
310     buttonGroupParameters = new QButtonGroup( this, "buttonGroupParameters" );
311     buttonGroupParameters->setGeometry( QRect( 10, 260, 450, 210 ) );
312
313     textLabelTMed = new QLabel( buttonGroupParameters, "textLabelTMed" );
314     textLabelTMed->setGeometry( QRect( 20, 40, 242, 30 ) );
315
316     textLabelTLow = new QLabel( buttonGroupParameters, "textLabelTLow" );
317     textLabelTLow->setGeometry( QRect( 20, 80, 208, 30 ) );
318
319     textLabelRadius = new QLabel( buttonGroupParameters, "textLabelRadius" );
320     textLabelRadius->setGeometry( QRect( 20, 120, 211, 30 ) );
321
322     textLabelBoxing = new QLabel( buttonGroupParameters, "textLabelBoxing" );
323     textLabelBoxing->setGeometry( QRect( 20, 160, 241, 30 ) );
324
325     lineEditTMed = new QLineEdit( buttonGroupParameters, "lineEditTMed" );
326     lineEditTMed->setGeometry( QRect( 320, 40, 111, 30 ) );
327
328     lineEditTLow = new QLineEdit( buttonGroupParameters, "lineEditTLow" );
329     lineEditTLow->setGeometry( QRect( 320, 80, 111, 30 ) );
330
331     lineEditRadius = new QLineEdit( buttonGroupParameters, "lineEditRadius" );
332     lineEditRadius->setGeometry( QRect( 320, 120, 111, 30 ) );
333
334     spinBoxBoxing = new QSpinBox( buttonGroupParameters, "spinBoxBoxing" );
335     spinBoxBoxing->setGeometry( QRect( 320, 160, 111, 30 ) );
336     spinBoxBoxing->setMaxValue( 200 );
337     spinBoxBoxing->setMinValue( 2 );
338     spinBoxBoxing->setValue( 100 );
339
340     buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
341     buttonGroupProcess->setGeometry( QRect( 10, 480, 450, 60 ) );
342
343     pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
344     pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
345
346     pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
347     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
348     
349         setCaption( tr( "Decimation" ) );
350     buttonGroupSelectField->setTitle( tr( "Select field" ) );
351     textLabelSelectFieldName->setText( tr( "Field name" ) );
352     textLabelSelectFieldIteration->setText( tr( "Iteration" ) );
353     buttonGroupSelectFilter->setTitle( tr( "Select filter" ) );
354     textLabelSelectFilter->setText( tr( "Filter name" ) );
355     buttonGroupParameters->setTitle( tr( "Set parameters" ) );
356     textLabelTMed->setText( tr( "Threshold for medium resolution" ) );
357     textLabelTLow->setText( tr( "Threshold for low resolution" ) );
358     textLabelRadius->setText( tr( "Radius (neighborhood)" ) );
359     textLabelBoxing->setText( tr( "Boxing parameter" ) );
360     lineEditTMed->setText( tr( "0.1" ) );
361     lineEditTLow->setText( tr( "0.2" ) );
362
363         float defaultRadius = 0.5f;
364     lineEditRadius->setText( QString::number(defaultRadius) );
365     buttonGroupProcess->setTitle( QString::null );
366     pushButtonCancel->setText( tr( "Cancel" ) );
367     pushButtonOK->setText( tr("OK") );
368         
369         pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" );
370     pushButtonThresholdAuto->setGeometry( QRect( 260, 80, 50, 30 ) );
371     QFont pushButtonThresholdAuto_font(  pushButtonThresholdAuto->font() );
372     pushButtonThresholdAuto_font.setPointSize( 11 );
373     pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font ); 
374         pushButtonThresholdAuto->setText( tr( "auto" ) );
375     QToolTip::add( pushButtonThresholdAuto, tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) );
376
377     pushButtonRadiusAuto = new QPushButton( buttonGroupParameters, "pushButtonRadiusAuto" );
378     pushButtonRadiusAuto->setGeometry( QRect( 260, 120, 50, 30 ) );
379     QFont pushButtonRadiusAuto_font(  pushButtonRadiusAuto->font() );
380     pushButtonRadiusAuto_font.setPointSize( 11 );
381     pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font ); 
382     pushButtonRadiusAuto->setText( tr( "auto" ) );
383     QToolTip::add( pushButtonRadiusAuto, tr( "set radius automatically (average #neighbours equal to 8)" ) );
384         
385     resize( QSize(470, 554).expandedTo(minimumSizeHint()) );
386     clearWState( WState_Polished );
387         
388         connect(pushButtonOK,            SIGNAL(clicked()), this, SLOT(accept()));
389         connect(pushButtonCancel,        SIGNAL(clicked()), this, SLOT(reject()));
390         connect(pushButtonRadiusAuto,    SIGNAL(clicked()), this, SLOT(OnRadiusAuto()));
391         connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto()));
392 }
393
394
395 /*
396  *  Destroys the object and frees any allocated resources
397  */
398 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
399 {
400     // no need to delete child widgets, Qt does it all for us
401 }
402
403
404 void MULTIPR_GUI_DecimateDlg::accept()
405 {       
406         const char* strFieldName = comboBoxSelectFieldName->currentText().latin1();
407         const char* strFieldIt   = comboBoxSelectFieldIteration->currentText().latin1();
408         int fieldIteration = atoi(strFieldIt);
409         
410         double thresholdMed;
411         int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed);
412         if ((ret != 1) || (thresholdMed <= 0.0f))
413         {
414                 SUIT_MessageBox::error1( 
415                         mModule->getAppli()->desktop(),
416                         "Decimation parameters error", 
417                         "Invalid medium threshold (should be > 0.0)", 
418                         tr("OK") );
419                         
420                 return;
421         }
422
423         double thresholdLow;
424         ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow);
425         if ((ret != 1) || (thresholdLow <= 0.0f))
426         {
427                 SUIT_MessageBox::error1( 
428                         mModule->getAppli()->desktop(),
429                         "Decimation parameters error", 
430                         "Invalid low threshold (should be > 0.0)", 
431                         tr("OK") );
432                         
433                 return;
434         }
435         
436         if (thresholdMed >= thresholdLow)
437         {
438                 SUIT_MessageBox::error1( 
439                         mModule->getAppli()->desktop(),
440                         "Decimation parameters error", 
441                         "Medium threshold must be < low threshold", 
442                         tr("OK") );
443                         
444                 return;
445         }
446
447         double radius;
448         ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
449         if ((ret != 1) || (radius <= 0.0f))
450         {
451                 SUIT_MessageBox::error1( 
452                         mModule->getAppli()->desktop(),
453                         "Decimation parameters error", 
454                         "Invalid radius (should be > 0.0)", 
455                         tr("OK") );
456                         
457                 return;
458         }
459         
460         QApplication::setOverrideCursor(Qt::waitCursor);
461         
462         try
463         {
464                 const QStringList& partsList = mModule->getSelectedParts();
465                 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
466                 {
467                         const QString& partName = (*it);
468                         
469                         mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value());
470                         
471                         mModule->getMULTIPRObj()->decimePartition(
472                                 partName.latin1(),
473                                 strFieldName,
474                                 fieldIteration,
475                                 comboBoxSelectFilter->currentText().latin1(),
476                                 thresholdMed,
477                                 thresholdLow,
478                                 radius);
479                 }
480         }
481         catch(...)
482         {
483                 SUIT_MessageBox::error1( 
484                         mModule->getAppli()->desktop(),
485                         "Decimation error", 
486                         "Error while decimating selected part(s)", 
487                         tr("OK") );
488         }
489         
490         QApplication::restoreOverrideCursor();
491         QDialog::accept();
492 }
493
494
495 void MULTIPR_GUI_DecimateDlg::reject()
496 {
497         QDialog::reject();
498 }
499
500
501 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
502 {
503         // evaluates default radius for the first selected part
504         const QStringList& partsList = mModule->getSelectedParts();
505         char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
506         
507         char   lMeshName[256];
508         int    lId;
509         char   lPartName[256];
510         char   lPath[256];
511         char   lMEDFileName[256];
512         
513         // parse infos
514         int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
515                 lMeshName,
516                 &lId,
517                 lPartName,
518                 lPath,
519                 lMEDFileName);
520         
521         QApplication::setOverrideCursor(Qt::waitCursor);
522         float defaultRadius = 0.5f;
523         try
524         {
525                 multipr::Mesh* mesh = new multipr::Mesh();
526                 mesh->readSequentialMED(lMEDFileName, lMeshName);
527                 const int averageNumberOfNeighbours = 8;
528                 defaultRadius = mesh->evalDefaultRadius(averageNumberOfNeighbours);
529                 delete mesh;
530         }
531         catch (...)
532         {
533         }
534         QApplication::restoreOverrideCursor();
535         
536     lineEditRadius->setText( QString::number(defaultRadius) );
537 }
538
539
540 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
541 {
542         // evaluates default radius for the first selected part
543         const QStringList& partsList = mModule->getSelectedParts();
544         char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
545         
546         char   lMeshName[256];
547         int    lId;
548         char   lPartName[256];
549         char   lPath[256];
550         char   lMEDFileName[256];
551         
552         // parse infos
553         int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
554                 lMeshName,
555                 &lId,
556                 lPartName,
557                 lPath,
558                 lMEDFileName);
559         
560         QApplication::setOverrideCursor(Qt::waitCursor);
561         float defaultRadius = 0.5f;
562         try
563         {
564                 multipr::Mesh* mesh = new multipr::Mesh();
565                 mesh->readSequentialMED(lMEDFileName, lMeshName);
566                 
567                 multipr::DecimationFilter* filter =
568                         multipr::DecimationFilter::create(comboBoxSelectFilter->currentText().latin1());
569                 
570                 double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
571                 
572                 multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
573                 if (filterGrad)
574                 {
575                         const char* strFieldIt   = comboBoxSelectFieldIteration->currentText().latin1();
576                         int fieldIteration = atoi(strFieldIt);
577                         
578                         double radius;
579                         ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
580                         if ((ret != 1) || (radius <= 0.0f))
581                         {
582                                 SUIT_MessageBox::error1( 
583                                         mModule->getAppli()->desktop(),
584                                         "Decimation parameters error", 
585                                         "Invalid radius (should be > 0.0)", 
586                                         tr("OK") );
587                                         
588                                 return;
589                         }
590                         
591                         filterGrad->getGradientInfo(
592                                 mesh,
593                                 comboBoxSelectFieldName->currentText().latin1(),
594                                 fieldIteration,
595                                 radius,
596                                 spinBoxBoxing->value(),
597                                 &gradMin,
598                                 &gradAvg,
599                                 &gradMax);
600                 }
601                 
602                 delete filter;
603                 delete mesh;
604                 
605                 lineEditTMed->setText( QString::number(gradMin) );
606                 lineEditTLow->setText( QString::number(gradMax) );
607         }
608         catch (...)
609         {
610         }
611         QApplication::restoreOverrideCursor();
612 }
613
614
615 //*****************************************************************************
616 // MULTIPR_GUI_ProgressCallbackDlg
617 //*****************************************************************************
618
619 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
620         QProgressDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
621 {
622         setLabel(new QLabel(this, "Please wait"));
623         setLabelText("Please wait");
624         setTotalSteps(100);
625 }
626
627
628 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
629 {
630 }
631
632
633 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
634 {
635         setCaption(pTaskTitle);
636         MULTIPR_ProgressCallback::init(pNumStep);
637 }
638
639
640 void MULTIPR_GUI_ProgressCallbackDlg::done()
641 {
642         setProgress(100);
643 }
644
645         
646 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
647 {
648         setProgress(int(pPercent));
649 }
650
651 // EOF