1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_GUI_Dlg.cxx
7 * \brief see MULTIPR_GUI_Dlg.h
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 //*****************************************************************************
16 //*****************************************************************************
18 #include "MULTIPR_GUI_Dlg.h"
19 #include "MULTIPR_GUI.h"
22 #include <SUIT_MessageBox.h>
23 #include <SUIT_ResourceMgr.h>
24 #include <SUIT_Session.h>
25 #include <SalomeApp_Application.h>
26 #include <SalomeApp_CheckFileDlg.h>
27 #include <LightApp_SelectionMgr.h>
29 #include <SALOME_LifeCycleCORBA.hxx>
32 #include <qapplication.h>
33 #include <qinputdialog.h>
35 #include <qpushbutton.h>
36 #include <qgroupbox.h>
38 #include <qbuttongroup.h>
40 #include <qcombobox.h>
42 #include <qlineedit.h>
45 #include <qwhatsthis.h>
53 MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) :
55 theModule->application()->desktop(),
58 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
63 buttonGroupProcess->setGeometry( QRect( 10, 110, 450, 60 ) );
65 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
66 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
68 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
69 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
71 buttonGroupSelectMesh = new QButtonGroup( this, "buttonGroupSelectMesh" );
72 buttonGroupSelectMesh->setGeometry( QRect( 10, 10, 450, 91 ) );
74 comboBoxSelectMesh = new QComboBox( FALSE, buttonGroupSelectMesh, "comboBoxSelectMesh" );
75 comboBoxSelectMesh->setGeometry( QRect( 160, 30, 280, 40 ) );
76 MULTIPR_ORB::string_array* listMeshes = theModule->getMULTIPRObj()->getMeshes();
77 for (int i=0; i<listMeshes->length() ; i++)
79 const char* strItem = (*listMeshes)[i];
80 comboBoxSelectMesh->insertItem(strItem);
82 comboBoxSelectMesh->setEditable(false);
84 textLabelSelectMesh = new QLabel( buttonGroupSelectMesh, "textLabelSelectMesh" );
85 textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) );
87 setCaption( tr( "Extract groups from sequential MED file" ) );
88 buttonGroupProcess->setTitle( QString::null );
89 pushButtonCancel->setText( tr( "Cancel" ) );
90 pushButtonOK->setText( tr("OK") );
91 buttonGroupSelectMesh->setTitle( tr( "Select mesh" ) );
92 textLabelSelectMesh->setText( tr( "Mesh name" ) );
94 resize( QSize(471, 185).expandedTo(minimumSizeHint()) );
95 clearWState( WState_Polished );
97 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
98 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
103 * Destroys the object and frees any allocated resources
105 MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg()
107 // no need to delete child widgets, Qt does it all for us
111 void MULTIPR_GUI_Partition1Dlg::accept()
113 const char* meshName = comboBoxSelectMesh->currentText().latin1();
117 mModule->getMULTIPRObj()->setMesh(meshName);
119 QApplication::setOverrideCursor(Qt::waitCursor);
120 mModule->getMULTIPRObj()->partitionneDomaine();
121 QApplication::restoreOverrideCursor();
126 SUIT_MessageBox::error1(
127 mModule->getAppli()->desktop(),
128 "Import MED file error",
129 "Unable to set mesh",
137 void MULTIPR_GUI_Partition1Dlg::reject()
143 MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) :
145 theModule->application()->desktop(),
148 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
152 buttonGroupSplitParameters = new QButtonGroup( this, "buttonGroupSplitParameters" );
153 buttonGroupSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) );
155 textLabelSelectNbParts = new QLabel( buttonGroupSplitParameters, "textLabelSelectNbParts" );
156 textLabelSelectNbParts->setGeometry( QRect( 30, 30, 160, 31 ) );
158 textLabelSelectSplitter = new QLabel( buttonGroupSplitParameters, "textLabelSelectSplitter" );
159 textLabelSelectSplitter->setGeometry( QRect( 30, 80, 111, 31 ) );
161 comboBoxSelectSplitter = new QComboBox( FALSE, buttonGroupSplitParameters, "comboBoxSelectSplitter" );
162 comboBoxSelectSplitter->setGeometry( QRect( 210, 80, 150, 40 ) );
163 comboBoxSelectSplitter->insertItem("METIS");
164 comboBoxSelectSplitter->insertItem("SCOTCH");
165 comboBoxSelectSplitter->setEditable(false);
167 spinBoxNbParts = new QSpinBox( buttonGroupSplitParameters, "spinBoxNbParts" );
168 spinBoxNbParts->setGeometry( QRect( 210, 30, 150, 30 ) );
169 spinBoxNbParts->setMaxValue( 1000 );
170 spinBoxNbParts->setMinValue( 2 );
171 spinBoxNbParts->setValue( 2 );
173 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
174 buttonGroupProcess->setGeometry( QRect( 10, 160, 380, 60 ) );
176 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
177 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
179 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
180 pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) );
182 setCaption( tr( "Split selected part" ) );
183 buttonGroupSplitParameters->setTitle( tr( "Split parameters" ) );
184 textLabelSelectNbParts->setText( tr( "Number of sub-parts" ) );
185 textLabelSelectSplitter->setText( tr( "Splitter" ) );
186 buttonGroupProcess->setTitle( QString::null );
187 pushButtonOK->setText( tr("OK") );
188 pushButtonCancel->setText( tr( "Cancel" ) );
190 resize( QSize(403, 234).expandedTo(minimumSizeHint()) );
191 clearWState( WState_Polished );
193 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
194 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
199 * Destroys the object and frees any allocated resources
201 MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg()
203 // no need to delete child widgets, Qt does it all for us
207 void MULTIPR_GUI_Partition2Dlg::accept()
209 const char* strSplitter = comboBoxSelectSplitter->currentText().latin1();
210 int nbParts = spinBoxNbParts->value();
211 int partitionner = -1;
212 if (strcmp(strSplitter, "METIS") == 0)
216 else if (strcmp(strSplitter, "SCOTCH") == 0)
221 QApplication::setOverrideCursor(Qt::waitCursor);
225 const QStringList& partsList = mModule->getSelectedParts();
226 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
228 const QString& partName = (*it);
229 //cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl;
230 mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner);
236 SUIT_MessageBox::error1(
237 mModule->getAppli()->desktop(),
239 "Error while splitting selected part(s)",
243 QApplication::restoreOverrideCursor();
248 void MULTIPR_GUI_Partition2Dlg::reject()
254 MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) :
256 theModule->application()->desktop(),
259 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
263 buttonGroupSelectField = new QButtonGroup( this, "buttonGroupSelectField" );
264 buttonGroupSelectField->setGeometry( QRect( 10, 10, 450, 140 ) );
266 textLabelSelectFieldName = new QLabel( buttonGroupSelectField, "textLabelSelectFieldName" );
267 textLabelSelectFieldName->setGeometry( QRect( 30, 30, 141, 31 ) );
269 textLabelSelectFieldIteration = new QLabel( buttonGroupSelectField, "textLabelSelectFieldIteration" );
270 textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) );
272 MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields();
273 int maxIteration = 0;
274 for (int i=0 ; i<listFields->length() ; i++)
276 const char* strItem = (*listFields)[i];
277 CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem);
278 if (nbIteration > maxIteration)
280 maxIteration = nbIteration;
284 comboBoxSelectFieldIteration = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldIteration" );
285 comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 280, 40 ) );
286 for (int i=1 ; i<=maxIteration ; i++)
288 comboBoxSelectFieldIteration->insertItem(QString::number(i));
291 comboBoxSelectFieldName = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldName" );
292 comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 280, 40 ) );
293 for (int i=0 ; i<listFields->length() ; i++)
295 const char* strItem = (*listFields)[i];
296 comboBoxSelectFieldName->insertItem(strItem);
298 comboBoxSelectFieldName->setEditable(false);
299 QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) );
301 buttonGroupSelectFilter = new QButtonGroup( this, "buttonGroupSelectFilter" );
302 buttonGroupSelectFilter->setGeometry( QRect( 10, 160, 450, 90 ) );
304 textLabelSelectFilter = new QLabel( buttonGroupSelectFilter, "textLabelSelectFilter" );
305 textLabelSelectFilter->setGeometry( QRect( 30, 30, 101, 31 ) );
307 comboBoxSelectFilter = new QComboBox( FALSE, buttonGroupSelectFilter, "comboBoxSelectFilter" );
308 comboBoxSelectFilter->setGeometry( QRect( 150, 30, 280, 40 ) );
309 comboBoxSelectFilter->insertItem("Filtre_GradientMoyen");
311 buttonGroupParameters = new QButtonGroup( this, "buttonGroupParameters" );
312 buttonGroupParameters->setGeometry( QRect( 10, 260, 450, 210 ) );
314 textLabelTMed = new QLabel( buttonGroupParameters, "textLabelTMed" );
315 textLabelTMed->setGeometry( QRect( 20, 40, 242, 30 ) );
317 textLabelTLow = new QLabel( buttonGroupParameters, "textLabelTLow" );
318 textLabelTLow->setGeometry( QRect( 20, 80, 208, 30 ) );
320 textLabelRadius = new QLabel( buttonGroupParameters, "textLabelRadius" );
321 textLabelRadius->setGeometry( QRect( 20, 120, 211, 30 ) );
323 textLabelBoxing = new QLabel( buttonGroupParameters, "textLabelBoxing" );
324 textLabelBoxing->setGeometry( QRect( 20, 160, 241, 30 ) );
326 lineEditTMed = new QLineEdit( buttonGroupParameters, "lineEditTMed" );
327 lineEditTMed->setGeometry( QRect( 320, 40, 111, 30 ) );
329 lineEditTLow = new QLineEdit( buttonGroupParameters, "lineEditTLow" );
330 lineEditTLow->setGeometry( QRect( 320, 80, 111, 30 ) );
332 lineEditRadius = new QLineEdit( buttonGroupParameters, "lineEditRadius" );
333 lineEditRadius->setGeometry( QRect( 320, 120, 111, 30 ) );
335 spinBoxBoxing = new QSpinBox( buttonGroupParameters, "spinBoxBoxing" );
336 spinBoxBoxing->setGeometry( QRect( 320, 160, 111, 30 ) );
337 spinBoxBoxing->setMaxValue( 200 );
338 spinBoxBoxing->setMinValue( 2 );
339 spinBoxBoxing->setValue( 100 );
340 QToolTip::add( spinBoxBoxing, tr( "grid: number of cells along each axis" ) );
342 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
343 buttonGroupProcess->setGeometry( QRect( 10, 480, 450, 60 ) );
345 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
346 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
348 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
349 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
350 pushButtonCancel->setAccel( QKeySequence( tr( "Esc" ) ) );
352 setCaption( tr( "Decimation" ) );
353 buttonGroupSelectField->setTitle( tr( "Select field" ) );
354 textLabelSelectFieldName->setText( tr( "Field name" ) );
355 textLabelSelectFieldIteration->setText( tr( "Field iteration" ) );
356 buttonGroupSelectFilter->setTitle( tr( "Select filter" ) );
357 textLabelSelectFilter->setText( tr( "Filter name" ) );
358 buttonGroupParameters->setTitle( tr( "Set parameters" ) );
359 textLabelTMed->setText( tr( "Threshold for medium resolution" ) );
360 textLabelTLow->setText( tr( "Threshold for low resolution" ) );
361 textLabelRadius->setText( tr( "Radius (neighborhood)" ) );
362 textLabelBoxing->setText( tr( "Acceleration structure (boxing)" ) );
363 lineEditTMed->setText( tr( "0.1" ) );
364 lineEditTLow->setText( tr( "0.2" ) );
366 float defaultRadius = 0.5f;
367 lineEditRadius->setText( QString::number(defaultRadius) );
368 buttonGroupProcess->setTitle( QString::null );
369 pushButtonCancel->setText( tr( "Cancel" ) );
370 pushButtonOK->setText( tr("OK") );
372 pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" );
373 pushButtonThresholdAuto->setGeometry( QRect( 260, 80, 50, 30 ) );
374 QFont pushButtonThresholdAuto_font( pushButtonThresholdAuto->font() );
375 pushButtonThresholdAuto_font.setPointSize( 11 );
376 pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font );
377 pushButtonThresholdAuto->setText( tr( "auto" ) );
378 QToolTip::add( pushButtonThresholdAuto, tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) );
380 pushButtonRadiusAuto = new QPushButton( buttonGroupParameters, "pushButtonRadiusAuto" );
381 pushButtonRadiusAuto->setGeometry( QRect( 260, 120, 50, 30 ) );
382 QFont pushButtonRadiusAuto_font( pushButtonRadiusAuto->font() );
383 pushButtonRadiusAuto_font.setPointSize( 11 );
384 pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font );
385 pushButtonRadiusAuto->setText( tr( "auto" ) );
386 QToolTip::add( pushButtonRadiusAuto, tr( "set radius automatically (average #neighbours equal to 8)" ) );
388 resize( QSize(470, 554).expandedTo(minimumSizeHint()) );
389 clearWState( WState_Polished );
391 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
392 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
393 connect(pushButtonRadiusAuto, SIGNAL(clicked()), this, SLOT(OnRadiusAuto()));
394 connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto()));
399 * Destroys the object and frees any allocated resources
401 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
403 // no need to delete child widgets, Qt does it all for us
407 void MULTIPR_GUI_DecimateDlg::accept()
409 const char* strFieldName = comboBoxSelectFieldName->currentText().latin1();
410 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
411 int fieldIteration = atoi(strFieldIt);
414 int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed);
415 if ((ret != 1) || (thresholdMed <= 0.0f))
417 SUIT_MessageBox::error1(
418 mModule->getAppli()->desktop(),
419 "Decimation parameters error",
420 "Invalid medium threshold (should be > 0.0)",
427 ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow);
428 if ((ret != 1) || (thresholdLow <= 0.0f))
430 SUIT_MessageBox::error1(
431 mModule->getAppli()->desktop(),
432 "Decimation parameters error",
433 "Invalid low threshold (should be > 0.0)",
439 if (thresholdMed >= thresholdLow)
441 SUIT_MessageBox::error1(
442 mModule->getAppli()->desktop(),
443 "Decimation parameters error",
444 "Medium threshold must be < low threshold",
451 ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
452 if ((ret != 1) || (radius <= 0.0f))
454 SUIT_MessageBox::error1(
455 mModule->getAppli()->desktop(),
456 "Decimation parameters error",
457 "Invalid radius (should be > 0.0)",
463 QApplication::setOverrideCursor(Qt::waitCursor);
467 const QStringList& partsList = mModule->getSelectedParts();
468 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
470 const QString& partName = (*it);
472 mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value());
474 mModule->getMULTIPRObj()->decimePartition(
478 comboBoxSelectFilter->currentText().latin1(),
486 SUIT_MessageBox::error1(
487 mModule->getAppli()->desktop(),
489 "Error while decimating selected part(s)",
493 QApplication::restoreOverrideCursor();
498 void MULTIPR_GUI_DecimateDlg::reject()
504 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
506 // evaluates default radius for the first selected part
507 const QStringList& partsList = mModule->getSelectedParts();
508 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
509 int fieldIteration = atoi(strFieldIt);
510 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
516 char lMEDFileName[256];
519 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
531 QApplication::setOverrideCursor(Qt::waitCursor);
532 float defaultRadius = 0.5f;
536 sprintf(strParams, "2");
538 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
540 comboBoxSelectFieldName->currentText().latin1(),
542 comboBoxSelectFilter->currentText().latin1(),
545 sscanf(res, "%f", &defaultRadius);
550 QApplication::restoreOverrideCursor();
552 lineEditRadius->setText( QString::number(defaultRadius) );
556 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
558 // evaluates default radius for the first selected part
559 const QStringList& partsList = mModule->getSelectedParts();
560 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
561 int fieldIteration = atoi(strFieldIt);
562 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
568 char lMEDFileName[256];
571 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
578 QApplication::setOverrideCursor(Qt::waitCursor);
583 ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius);
584 if ((ret != 1) || (radius <= 0.0f))
586 SUIT_MessageBox::error1(
587 mModule->getAppli()->desktop(),
588 "Decimation parameters error",
589 "Invalid radius (should be > 0.0)",
596 sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value());
598 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
600 comboBoxSelectFieldName->currentText().latin1(),
602 comboBoxSelectFilter->currentText().latin1(),
605 float gradMin, gradAvg, gradMax;
606 sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax);
608 lineEditTMed->setText( QString::number(gradMin) );
609 lineEditTLow->setText( QString::number(gradMax) );
615 QApplication::restoreOverrideCursor();
619 //*****************************************************************************
620 // MULTIPR_GUI_ProgressCallbackDlg
621 // QT dialog box used to display progress in time consuming task (e.g. save)
622 //*****************************************************************************
624 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
629 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
631 setLabel(new QLabel(this, "Please wait"));
632 setLabelText("Please wait");
637 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
643 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
645 setCaption(pTaskTitle);
646 MULTIPR_ProgressCallback::init(pNumStep);
650 void MULTIPR_GUI_ProgressCallbackDlg::done()
656 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
658 setProgress(int(pPercent));