]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx
Salome HOME
0bec8d85652f97b690952a2c56e79bdeabe63d93
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI_Dlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Partitioning/decimation module for the SALOME v3.2 platform
21 //
22 /**
23 * \file    MULTIPR_GUI_Dlg.cxx
24 *
25 * \brief   see MULTIPR_GUI_Dlg.h
26 *
27 * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
28
29 * \date    01/2007
30 */
31
32 //*****************************************************************************
33 // Includes section
34 //*****************************************************************************
35
36 #include "MULTIPR_GUI_Dlg.h"
37 #include "MULTIPR_GUI.h"
38
39 // Salome Includes
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_CheckFileDlg.h>
45 #include <LightApp_SelectionMgr.h>
46
47 #include <SALOME_LifeCycleCORBA.hxx>
48
49 // QT Includes
50 #include <QApplication>
51 #include <QInputDialog>
52 #include <QLayout>
53 #include <QPushButton>
54 #include <QGroupBox>
55 #include <QVBoxLayout>
56 #include <QLabel>
57 #include <QComboBox>
58 #include <QVariant>
59 #include <QLineEdit>
60 #include <QSpinBox>
61 #include <QWhatsThis>
62 #include <QImage>
63 #include <QPixmap>
64
65 // MED include
66 extern "C"
67 {
68     #include "med.h"
69 }
70
71 using namespace std;
72
73 MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : 
74     QDialog(
75         (QWidget*)theModule->application()->desktop(), 
76         Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
77 {
78     mModule = theModule;
79     
80     groupBoxProcess = new QGroupBox( "groupBoxProcess",this );
81     groupBoxProcess->setGeometry( QRect( 10, 110, 450, 60 ) );
82
83     pushButtonOK = new QPushButton( QString("pushButtonOK"),groupBoxProcess );
84     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
85     
86     pushButtonCancel = new QPushButton( QString("pushButtonCancel"),groupBoxProcess );
87     pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
88
89     groupBoxSelectMesh = new QGroupBox( "groupBoxSelectMesh",this );
90     groupBoxSelectMesh->setGeometry( QRect( 10, 10, 450, 91 ) );
91
92     comboBoxSelectMesh = new QComboBox( groupBoxSelectMesh );
93     comboBoxSelectMesh->setGeometry( QRect( 160, 30, 280, 40 ) );
94     MULTIPR_ORB::string_array* listMeshes = theModule->getMULTIPRObj()->getMeshes();
95     for (int i=0; i<listMeshes->length() ; i++)
96     {
97         const char* strItem = (*listMeshes)[i];
98         comboBoxSelectMesh->insertItem(0,strItem);
99     }
100     comboBoxSelectMesh->setEditable(false);
101
102     textLabelSelectMesh = new QLabel( "textLabelSelectMesh",groupBoxSelectMesh );
103     textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) );
104     
105     setWindowTitle( tr( "Extract groups from sequential MED file" ) );
106     groupBoxProcess->setTitle( QString::null );
107     pushButtonCancel->setText( tr( "Cancel" ) );
108     pushButtonOK->setText( tr("OK") );
109     groupBoxSelectMesh->setTitle( tr( "Select mesh" ) );
110     textLabelSelectMesh->setText( tr( "Mesh name" ) );
111     
112     resize( QSize(471, 185).expandedTo(minimumSizeHint()) );
113     //clearWState( WState_Polished );
114     
115     connect(pushButtonOK,     SIGNAL(clicked()), this, SLOT(accept()));
116     connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
117 }
118
119
120 /*
121 *  Destroys the object and frees any allocated resources
122 */
123 MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg()
124 {
125     // no need to delete child widgets, Qt does it all for us
126 }
127
128
129 void MULTIPR_GUI_Partition1Dlg::accept()
130 {
131     const char* meshName = comboBoxSelectMesh->currentText().toLatin1();
132     
133     try
134     {
135         mModule->getMULTIPRObj()->setMesh(meshName);
136         
137         QApplication::setOverrideCursor(Qt::WaitCursor);
138         mModule->getMULTIPRObj()->partitionneDomaine();
139         QApplication::restoreOverrideCursor();
140         
141     }
142     catch(...)
143     {
144         SUIT_MessageBox::critical( 
145             (QWidget*)mModule->getAppli()->desktop(),
146             QString("Import MED file error"), 
147             QString("Unable to set mesh"));
148     }
149
150     QDialog::accept();
151 }
152
153
154 void MULTIPR_GUI_Partition1Dlg::reject()
155 {
156     QDialog::reject();
157 }
158
159
160 MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) : 
161     QDialog(
162         (QWidget*)theModule->application()->desktop(), 
163         Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
164 {
165     mModule = theModule;
166     
167     groupBoxSplitParameters = new QGroupBox( "groupBoxSplitParameters",this );
168     groupBoxSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) );
169
170     textLabelSelectNbParts = new QLabel( "textLabelSelectNbParts",groupBoxSplitParameters );
171     textLabelSelectNbParts->setGeometry( QRect( 30, 30, 160, 31 ) );
172
173     textLabelSelectSplitter = new QLabel( "textLabelSelectSplitter",groupBoxSplitParameters );
174     textLabelSelectSplitter->setGeometry( QRect( 30, 80, 111, 31 ) );
175
176     comboBoxSelectSplitter = new QComboBox(groupBoxSplitParameters);
177     comboBoxSelectSplitter->setGeometry( QRect( 210, 80, 150, 40 ) );
178     comboBoxSelectSplitter->insertItem(0,"METIS");
179     comboBoxSelectSplitter->insertItem(0,"SCOTCH");
180     comboBoxSelectSplitter->setEditable(false);
181
182     spinBoxNbParts = new QSpinBox( groupBoxSplitParameters);
183     spinBoxNbParts->setGeometry( QRect( 210, 30, 150, 30 ) );
184     spinBoxNbParts->setMaximum( 1000 );
185     spinBoxNbParts->setMinimum( 2 );
186     spinBoxNbParts->setValue( 2 );
187
188     groupBoxProcess = new QGroupBox( "groupBoxProcess",this );
189     groupBoxProcess->setGeometry( QRect( 10, 160, 380, 60 ) );
190
191     pushButtonOK = new QPushButton( QString("pushButtonOK"),groupBoxProcess );
192     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
193
194     pushButtonCancel = new QPushButton( QString("pushButtonCancel"),groupBoxProcess );
195     pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) );
196     
197     setWindowTitle( tr( "Split selected part" ) );
198     groupBoxSplitParameters->setTitle( tr( "Split parameters" ) );
199     textLabelSelectNbParts->setText( tr( "Number of sub-parts" ) );
200     textLabelSelectSplitter->setText( tr( "Splitter" ) );
201     groupBoxProcess->setTitle( QString::null );
202     pushButtonOK->setText( tr("OK") );
203     pushButtonCancel->setText( tr( "Cancel" ) );
204     
205     resize( QSize(403, 234).expandedTo(minimumSizeHint()) );
206     //clearWState( WState_Polished );
207     
208     connect(pushButtonOK,     SIGNAL(clicked()), this, SLOT(accept()));
209     connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
210 }
211
212
213 /*
214 *  Destroys the object and frees any allocated resources
215 */
216 MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg()
217 {
218     // no need to delete child widgets, Qt does it all for us
219 }
220
221
222 void MULTIPR_GUI_Partition2Dlg::accept()
223 {
224     const char* strSplitter = comboBoxSelectSplitter->currentText().toLatin1();
225     int nbParts = spinBoxNbParts->value();
226     int partitionner = -1;
227     if (strcmp(strSplitter, "METIS") == 0)
228     {
229         partitionner = 0;
230     }
231     else if (strcmp(strSplitter, "SCOTCH") == 0)
232     {
233         partitionner = 1;
234     }
235     
236     QApplication::setOverrideCursor(Qt::WaitCursor);
237     
238     try
239     {
240         const QStringList& partsList = mModule->getSelectedParts();
241         for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
242         {
243             const QString& partName = (*it);
244             //cout << "Split " << partName.toLatin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl;
245             mModule->getMULTIPRObj()->partitionneGroupe(partName.toLatin1(), nbParts, partitionner);
246         }
247         
248     }
249     catch(...)
250     {
251         SUIT_MessageBox::critical( 
252             (QWidget*)mModule->getAppli()->desktop(),
253             "Split error", 
254             "Error while splitting selected part(s)"); 
255     }
256     
257     QApplication::restoreOverrideCursor();
258     QDialog::accept();
259 }
260
261
262 void MULTIPR_GUI_Partition2Dlg::reject()
263 {
264     QDialog::reject();
265 }
266
267
268 MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) :
269     QDialog(
270     (QWidget*)theModule->application()->desktop(), 
271         Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
272 {
273     mModule = theModule;
274     groupBoxSelectField = new QGroupBox("groupBoxSelectField",this );
275     groupBoxSelectField->setGeometry( QRect( 10, 10, 710, 140 ) );
276
277     textLabelSelectFieldName = new QLabel( "textLabelSelectFieldName",groupBoxSelectField );
278     textLabelSelectFieldName->setGeometry( QRect( 30, 30, 141, 31 ) );
279
280     textLabelSelectFieldIteration = new QLabel( "textLabelSelectFieldIteration",groupBoxSelectField );
281     textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) );
282
283     const QStringList& partsList = mModule->getSelectedParts();
284     // Lets get the fields !.
285     QString allParts = partsList.join("|");
286     MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields(allParts.toLatin1());
287     int maxIteration = 0;
288     int i, j;
289     for (i = 0 ; i < listFields->length() ; ++i)
290     {
291         char* strItem = (*listFields)[i];
292         for (j = 0; strItem[j] && strItem[j] != ' '; ++j);
293         strItem[j] = 0;
294         CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(allParts.toLatin1(), strItem);
295         strItem[j] = ' ';
296         if (nbIteration > maxIteration) 
297         {
298             maxIteration = nbIteration;
299         }
300     }
301
302     comboBoxSelectFieldIteration = new QComboBox( groupBoxSelectField );
303     comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 540, 40 ) );
304     for (int i=1 ; i<=maxIteration ; i++)
305     {
306         comboBoxSelectFieldIteration->insertItem(0,QString::number(i));
307     }
308
309     comboBoxSelectFieldName = new QComboBox(groupBoxSelectField );
310     comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 540, 40 ) );
311     for (int i=0 ; i<listFields->length() ; i++)
312     {
313         const char* strItem = (*listFields)[i];
314         comboBoxSelectFieldName->insertItem(0,strItem);
315     }
316     comboBoxSelectFieldName->setEditable(false);
317     comboBoxSelectFieldName->setToolTip(tr( "only scalar fields are listed (multi-component fields are not displayed)" ));
318
319     groupBoxSelectFilter = new QGroupBox("groupBoxSelectFilter",this );
320     groupBoxSelectFilter->setGeometry( QRect( 10, 160, 710, 90 ) );
321
322     textLabelSelectFilter = new QLabel( "textLabelSelectFilter",groupBoxSelectFilter );
323     textLabelSelectFilter->setGeometry( QRect( 30, 30, 101, 31 ) );
324
325     comboBoxSelectFilter = new QComboBox( groupBoxSelectFilter );
326     comboBoxSelectFilter->setGeometry( QRect( 150, 30, 540, 40 ) );
327     comboBoxSelectFilter->insertItem(0,"Filtre_GradientMoyen");
328     comboBoxSelectFilter->insertItem(0,"Filtre_Direct");
329
330     groupBoxParameters = new QGroupBox( "groupBoxParameters" ,this);
331     groupBoxParameters->setGeometry( QRect( 10, 260, 710, 210 ) );
332
333     textLabelTMed = new QLabel( "textLabelTMed",groupBoxParameters );
334     textLabelTMed->setGeometry( QRect( 20, 40, 242, 30 ) );
335
336     textLabelTLow = new QLabel( "textLabelTLow",groupBoxParameters );
337     textLabelTLow->setGeometry( QRect( 20, 80, 208, 30 ) );
338
339     textLabelRadius = new QLabel( "textLabelRadius",groupBoxParameters );
340     textLabelRadius->setGeometry( QRect( 20, 120, 211, 30 ) );
341
342     textLabelBoxing = new QLabel( "textLabelBoxing",groupBoxParameters );
343     textLabelBoxing->setGeometry( QRect( 20, 160, 241, 30 ) );
344
345     lineEditTMed = new QLineEdit( groupBoxParameters );
346     lineEditTMed->setGeometry( QRect( 580, 40, 111, 30 ) );
347
348     lineEditTLow = new QLineEdit( groupBoxParameters );
349     lineEditTLow->setGeometry( QRect( 580, 80, 111, 30 ) );
350
351     lineEditRadius = new QLineEdit( groupBoxParameters );
352     lineEditRadius->setGeometry( QRect( 580, 120, 111, 30 ) );
353
354     spinBoxBoxing = new QSpinBox( groupBoxParameters );
355     spinBoxBoxing->setGeometry( QRect( 580, 160, 111, 30 ) );
356     spinBoxBoxing->setMaximum( 200 );
357     spinBoxBoxing->setMinimum( 2 );
358     spinBoxBoxing->setValue( 100 );
359     spinBoxBoxing->setToolTip(tr( "grid: number of cells along each axis" ) );
360
361         infoGroup = new QGroupBox("infoGroup",this);
362         infoGroup->setGeometry( QRect( 10, 480, 710, 60 ) );
363
364         char* stats;
365         int tmp;
366         // Accumulator used to display the number of meshes in the current selection.
367         int acum = 0;
368     for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
369     {
370                 const QString& partName = (*it);
371                 stats = theModule->getMULTIPRObj()->getMEDInfo(partName.toLatin1());
372                 sscanf(stats, "%d", &tmp);
373                 acum += tmp;
374     }
375         
376         char buf[512];
377         sprintf(buf, "%d", acum);
378         textLabelInfo = new QLabel( "textLabelInfo",infoGroup);
379         textLabelInfo->setText("Number of cells:");
380     textLabelInfo->setGeometry( QRect( 20, 10, 242, 30 ) );     
381         textLabelInfoValue = new QLabel( "textLabelInfoValue",infoGroup);
382         textLabelInfoValue->setAlignment(Qt::AlignRight);
383         textLabelInfoValue->setText(buf);
384     textLabelInfoValue->setGeometry( QRect( 400, 10, 290, 30 ) );       
385                         
386     groupBoxProcess = new QGroupBox("groupBoxProcess",this );
387     groupBoxProcess->setGeometry( QRect( 10, 580, 710, 60 ) );
388
389     pushButtonOK = new QPushButton( QString( "pushButtonOK"),groupBoxProcess );
390     pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
391     
392     pushButtonCancel = new QPushButton( QString("pushButtonCancel"),groupBoxProcess );
393     pushButtonCancel->setGeometry( QRect( 581, 10, 110, 41 ) );
394     pushButtonCancel->setShortcut( QKeySequence( tr( "Esc" ) ) );
395     
396     setWindowTitle( tr( "Decimation" ) );
397     groupBoxSelectField->setTitle( tr( "Select field" ) );
398     textLabelSelectFieldName->setText( tr( "Field name" ) );
399     textLabelSelectFieldIteration->setText( tr( "Field iteration" ) );
400     groupBoxSelectFilter->setTitle( tr( "Select filter" ) );
401     textLabelSelectFilter->setText( tr( "Filter name" ) );
402     groupBoxParameters->setTitle( tr( "Set parameters" ) );
403     textLabelTMed->setText( tr( "Threshold for medium resolution" ) );
404     textLabelTLow->setText( tr( "Threshold for low resolution" ) );
405     textLabelRadius->setText( tr( "Radius (neighborhood)" ) );
406     textLabelBoxing->setText( tr( "Acceleration structure (boxing)" ) );
407     lineEditTMed->setText( tr( "0.1" ) );
408     lineEditTLow->setText( tr( "0.2" ) );
409
410     float defaultRadius = 0.5f;
411     lineEditRadius->setText( QString::number(defaultRadius) );
412     groupBoxProcess->setTitle( QString::null );
413     pushButtonCancel->setText( tr( "Cancel" ) );
414     pushButtonOK->setText( tr("OK") );
415     
416     pushButtonThresholdAuto = new QPushButton( QString("pushButtonThresholdAuto"),groupBoxParameters );
417     pushButtonThresholdAuto->setGeometry( QRect( 520, 80, 50, 30 ) );
418     QFont pushButtonThresholdAuto_font(  pushButtonThresholdAuto->font() );
419     pushButtonThresholdAuto_font.setPointSize( 11 );
420     pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font ); 
421     pushButtonThresholdAuto->setText( tr( "auto" ) );
422     pushButtonThresholdAuto->setToolTip(tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) );
423
424     pushButtonRadiusAuto = new QPushButton( QString("pushButtonRadiusAuto"),groupBoxParameters );
425     pushButtonRadiusAuto->setGeometry( QRect( 520, 120, 50, 30 ) );
426     QFont pushButtonRadiusAuto_font(  pushButtonRadiusAuto->font() );
427     pushButtonRadiusAuto_font.setPointSize( 11 );
428     pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font ); 
429     pushButtonRadiusAuto->setText( tr( "auto" ) );
430     pushButtonRadiusAuto->setToolTip(tr( "set radius automatically (average #neighbours equal to 8)" ));
431     
432     resize( QSize(730, 654).expandedTo(minimumSizeHint()) );
433     //clearWState( WState_Polished );
434     
435     connect(pushButtonOK,            SIGNAL(clicked()), this, SLOT(accept()));
436     connect(pushButtonCancel,        SIGNAL(clicked()), this, SLOT(reject()));
437     connect(pushButtonRadiusAuto,    SIGNAL(clicked()), this, SLOT(OnRadiusAuto()));
438     connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto()));
439     connect(comboBoxSelectFilter,    SIGNAL(activated(const QString &)), this, SLOT(selectField(const QString &)));
440 }
441
442
443 /*
444 *  Destroys the object and frees any allocated resources
445 */
446 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
447 {
448     // no need to delete child widgets, Qt does it all for us
449 }
450
451
452 void MULTIPR_GUI_DecimateDlg::accept()
453 {
454     const char* strFieldNameTmp = comboBoxSelectFieldName->currentText().toLatin1();
455     const char* strFieldIt   = comboBoxSelectFieldIteration->currentText().toLatin1();
456     int fieldIteration = atoi(strFieldIt);
457
458     char                strFieldName[MED_TAILLE_NOM + 1];
459     const               char* filterName = comboBoxSelectFilter->currentText().toLatin1();
460     char                params[MULTIPR_GUI_MAX_PARAMS_LENGTH];
461     int                 i;
462
463     // Get the field name.
464     strncpy(strFieldName, strFieldNameTmp, MED_TAILLE_NOM);
465     strFieldName[MED_TAILLE_NOM] = '\0';
466     for (i = 0; strFieldName[i] && strFieldName[i] != ' '; ++i);
467     strFieldName[i] = 0;
468
469     // Fill the corresponding filter parameters string.
470     if (strcmp(filterName, "Filtre_GradientMoyen") == 0)
471     {
472       if (this->setGradAvgFilterParams(params) == false)
473       {
474         return ;
475       }
476     }
477     else if (strcmp(filterName, "Filtre_Direct") == 0)
478     {
479       if (this->setDirectFilterParams(params) == false)
480       {
481         return ;
482       }
483     }
484     else
485     {
486       SUIT_MessageBox::critical(
487                 (QWidget*)mModule->getAppli()->desktop(),
488                 "Decimation error", 
489                 "Unknown filter name."); 
490     }
491
492     QApplication::setOverrideCursor(Qt::WaitCursor);
493
494     MULTIPR_ORB::string_array*  list = NULL;
495     try
496     {
497       const QStringList& partsList = mModule->getSelectedParts();
498       for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
499       {
500         const QString& partName = (*it);
501
502         list = mModule->getMULTIPRObj()->decimePartition(partName.toLatin1(),
503                                                          strFieldName,
504                                                          fieldIteration,
505                                                          filterName,
506                                                          params);
507       }
508     }
509     catch(...)
510     {
511         SUIT_MessageBox::critical( 
512             (QWidget*)mModule->getAppli()->desktop(),
513             "Decimation error",
514             "Error while decimating selected part(s)");
515     }
516
517     if (list != NULL && list->length() >= 4)
518     {
519       const char* rate = (*list)[list->length() - 1];
520       SUIT_MessageBox::information((QWidget*)mModule->getAppli()->desktop(),
521                              "Compression rate", 
522                              rate);
523     }
524     QApplication::restoreOverrideCursor();
525     QDialog::accept();
526 }
527
528 bool MULTIPR_GUI_DecimateDlg::setGradAvgFilterParams(char* pParams)
529 {
530     int boxing = spinBoxBoxing->value();
531
532     double thresholdMed;
533     int ret = sscanf(lineEditTMed->text().toLatin1(), "%lf", &thresholdMed);
534     if ((ret != 1) || (thresholdMed <= 0.0f))
535     {
536         SUIT_MessageBox::critical( 
537             (QWidget*)mModule->getAppli()->desktop(),
538             "Decimation parameters error", 
539             "Invalid medium threshold (should be > 0.0)");
540             
541         return false;
542     }
543
544     double thresholdLow;
545     ret = sscanf(lineEditTLow->text().toLatin1(), "%lf", &thresholdLow);
546     if ((ret != 1) || (thresholdLow <= 0.0f))
547     {
548         SUIT_MessageBox::critical( 
549             (QWidget*)mModule->getAppli()->desktop(),
550             "Decimation parameters error", 
551             "Invalid low threshold (should be > 0.0)");
552             
553         return false;
554     }
555     
556     if (thresholdMed >= thresholdLow)
557     {
558         SUIT_MessageBox::critical( 
559             (QWidget*)mModule->getAppli()->desktop(),
560             "Decimation parameters error", 
561             "Medium threshold must be < low threshold");
562             
563         return false;
564     }
565
566     double radius;
567     ret = sscanf(lineEditRadius->text().toLatin1(), "%lf", &radius);
568     if ((ret != 1) || (radius <= 0.0f))
569     {
570         SUIT_MessageBox::critical( 
571             (QWidget*)mModule->getAppli()->desktop(),
572             "Decimation parameters error", 
573             "Invalid radius (should be > 0.0)");
574             
575         return false;
576     }
577
578     sprintf(pParams, "%lf %lf %lf %d", thresholdMed, thresholdLow, radius, boxing);
579
580     return true;
581 }
582
583 bool MULTIPR_GUI_DecimateDlg::setDirectFilterParams(char* pParams)
584 {
585     double thresholdMed;
586     int ret = sscanf(lineEditTMed->text().toLatin1(), "%lf", &thresholdMed);
587     if (ret != 1)
588     {
589         SUIT_MessageBox::critical( 
590             (QWidget*)mModule->getAppli()->desktop(),
591             "Decimation parameters error", 
592             "Invalid medium threshold.");
593             
594         return false;
595     }
596
597     double thresholdLow;
598     ret = sscanf(lineEditTLow->text().toLatin1(), "%lf", &thresholdLow);
599     if (ret != 1)
600     {
601         SUIT_MessageBox::critical( 
602             (QWidget*)mModule->getAppli()->desktop(),
603             "Decimation parameters error", 
604             "Invalid low threshold.");
605             
606         return false;
607     }
608     
609     if (thresholdMed >= thresholdLow)
610     {
611         SUIT_MessageBox::critical( 
612             (QWidget*)mModule->getAppli()->desktop(),
613             "Decimation parameters error", 
614             "Medium threshold must be < low threshold");
615             
616         return false;
617     }
618
619         sprintf(pParams, "%lf %lf", thresholdMed, thresholdLow);
620         
621         return true;
622 }
623
624 void MULTIPR_GUI_DecimateDlg::selectField(const QString& valueText)
625 {
626         if (valueText == "Filtre_GradientMoyen")
627         {
628                 lineEditRadius->show();
629                 spinBoxBoxing->show();
630                 pushButtonRadiusAuto->show();
631                 textLabelRadius->show();
632         textLabelBoxing->show();
633                 //pushButtonThresholdAuto->show();
634         }
635         else if (valueText == "Filtre_Direct")
636         {
637                 lineEditRadius->hide();
638                 spinBoxBoxing->hide();
639                 pushButtonRadiusAuto->hide();
640                 textLabelRadius->hide();
641         textLabelBoxing->hide();
642                 //pushButtonThresholdAuto->hide();
643         }
644         else
645         {
646         SUIT_MessageBox::critical(
647             (QWidget*)mModule->getAppli()->desktop(),
648             "Decimation error", 
649             "Unknown filter name.");
650         }
651 }
652
653 void MULTIPR_GUI_DecimateDlg::reject()
654 {
655     QDialog::reject();
656 }
657
658
659 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
660 {
661     // evaluates default radius for the first selected part
662     const QStringList& partsList = mModule->getSelectedParts();
663     const char* strFieldIt   = comboBoxSelectFieldIteration->currentText().toLatin1();
664     int fieldIteration = atoi(strFieldIt);
665     char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].toLatin1());
666     
667     char   lMeshName[256];
668     int    lId;
669     char   lPartName[256];
670     char   lPath[256];
671     char   lMEDFileName[256];
672     
673     // parse infos
674     int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
675         lMeshName,
676         &lId,
677         lPartName,
678         lPath,
679         lMEDFileName);
680         
681     if (ret != 5)
682     {
683         return;
684     }
685     
686     QApplication::setOverrideCursor(Qt::WaitCursor);
687     float defaultRadius = 0.5f;
688     try
689     {
690         char strParams[256];
691         sprintf(strParams, "2");
692         
693         char* res = mModule->getMULTIPRObj()->evalDecimationParams(
694             lPartName,
695             comboBoxSelectFieldName->currentText().toLatin1(),
696             fieldIteration,
697             comboBoxSelectFilter->currentText().toLatin1(),
698             strParams);
699         
700         sscanf(res, "%f", &defaultRadius);
701     }
702     catch (...)
703     {
704     }
705     QApplication::restoreOverrideCursor();
706     
707     lineEditRadius->setText( QString::number(defaultRadius) );
708 }
709
710
711 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
712 {
713     // evaluates default radius for the first selected part
714     const QStringList& partsList = mModule->getSelectedParts();
715     const char* strFieldIt  = comboBoxSelectFieldIteration->currentText().toLatin1();
716     int fieldIteration = atoi(strFieldIt);
717     char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].toLatin1());
718     QString filterName = comboBoxSelectFilter->currentText();
719
720     char   lMeshName[256];
721     int    lId;
722     char   lPartName[256];
723     char   lPath[256];
724     char   lMEDFileName[256];
725     
726     // parse infos
727     int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
728         lMeshName,
729         &lId,
730         lPartName,
731         lPath,
732         lMEDFileName);
733     
734     QApplication::setOverrideCursor(Qt::WaitCursor);
735     if (filterName == "Filtre_GradientMoyen")
736     {
737         try
738         {
739             float radius;
740             ret = sscanf(lineEditRadius->text().toLatin1(), "%f", &radius);
741             if ((ret != 1) || (radius <= 0.0f))
742             {
743                 SUIT_MessageBox::critical( 
744                     (QWidget*)mModule->getAppli()->desktop(),
745                     "Decimation parameters error", 
746                     "Invalid radius (should be > 0.0)");
747                     
748                 return;
749             }
750             
751             char strParams[256];        
752             sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value());
753             
754             char* res = mModule->getMULTIPRObj()->evalDecimationParams(
755                 lPartName,
756                 comboBoxSelectFieldName->currentText().toLatin1(),
757                 fieldIteration,
758                 comboBoxSelectFilter->currentText().toLatin1(),
759                 strParams);
760             
761             float gradMin, gradAvg, gradMax;
762             sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax);
763             
764             lineEditTMed->setText( QString::number(gradMin) );
765             lineEditTLow->setText( QString::number(gradMax) );
766         }
767         catch (...)
768         {
769         }
770     }
771     else if (filterName == "Filtre_Direct")
772     {
773         float   lMin = 1.0f;
774         float   lMax = 2.0f;
775         
776         mModule->getMULTIPRObj()->getFieldMinMax(lPartName, comboBoxSelectFieldName->currentText().toLatin1(), lMin, lMax);
777         lineEditTMed->setText(QString::number(lMin));
778         lineEditTLow->setText(QString::number(lMax));
779     }
780     else
781         {
782         SUIT_MessageBox::critical(
783             (QWidget*)mModule->getAppli()->desktop(),
784             "Decimation error", 
785             "Unknown filter name."); 
786         }
787     QApplication::restoreOverrideCursor();
788 }
789
790 //*****************************************************************************
791 // MULTIPR_GUI_ProgressCallbackDlg
792 // QT dialog box used to display progress in time consuming task (e.g. save)
793 //*****************************************************************************
794
795 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
796     QProgressDialog(
797         parent, 
798         Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
799 {
800     setLabel(new QLabel(QString("Please wait"),this));
801     setLabelText("Please wait");
802 //    setTotalSteps(100);
803 }
804
805
806 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
807 {
808     // do nothing
809 }
810
811
812 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
813 {
814     setWindowTitle(pTaskTitle);
815     MULTIPR_ProgressCallback::init(pNumStep);
816 }
817
818
819 void MULTIPR_GUI_ProgressCallbackDlg::done()
820 {
821     setValue(100);
822 }
823
824     
825 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
826 {
827     setValue(int(pPercent));
828 }
829
830
831 //*****************************************************************************
832 // MULTIPR_GUI_EmptyMeshCallbackDlg
833 // QT dialog box used to inform about empty meshes
834 //*****************************************************************************
835
836 MULTIPR_GUI_EmptyMeshCallbackDlg::MULTIPR_GUI_EmptyMeshCallbackDlg(QWidget* parent)
837 {
838     mParent = parent;
839 }
840
841
842 MULTIPR_GUI_EmptyMeshCallbackDlg::~MULTIPR_GUI_EmptyMeshCallbackDlg()
843 {
844     // do nothing
845 }
846
847
848 void MULTIPR_GUI_EmptyMeshCallbackDlg::reportEmptyMesh(string pInfo)
849 {
850     char msg[256];
851     sprintf(msg, "Empty mesh detected (%s)", pInfo.c_str());
852     
853     SUIT_MessageBox::warning( 
854         mParent,
855         "Empty mesh detected", 
856         msg); 
857 }
858
859 // EOF