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 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
66 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
68 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
69 pushButtonOK->setGeometry( QRect( 10, 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 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
346 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
347 pushButtonCancel->setAccel( QKeySequence( tr( "Esc" ) ) );
349 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
350 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
351 pushButtonOK->setAccel( QKeySequence( tr( "Return" ) ) );
353 setCaption( tr( "Decimation" ) );
354 buttonGroupSelectField->setTitle( tr( "Select field" ) );
355 textLabelSelectFieldName->setText( tr( "Field name" ) );
356 textLabelSelectFieldIteration->setText( tr( "Field iteration" ) );
357 buttonGroupSelectFilter->setTitle( tr( "Select filter" ) );
358 textLabelSelectFilter->setText( tr( "Filter name" ) );
359 buttonGroupParameters->setTitle( tr( "Set parameters" ) );
360 textLabelTMed->setText( tr( "Threshold for medium resolution" ) );
361 textLabelTLow->setText( tr( "Threshold for low resolution" ) );
362 textLabelRadius->setText( tr( "Radius (neighborhood)" ) );
363 textLabelBoxing->setText( tr( "Acceleration structure (boxing)" ) );
364 lineEditTMed->setText( tr( "0.1" ) );
365 lineEditTLow->setText( tr( "0.2" ) );
367 float defaultRadius = 0.5f;
368 lineEditRadius->setText( QString::number(defaultRadius) );
369 buttonGroupProcess->setTitle( QString::null );
370 pushButtonCancel->setText( tr( "Cancel" ) );
371 pushButtonOK->setText( tr("OK") );
373 pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" );
374 pushButtonThresholdAuto->setGeometry( QRect( 260, 80, 50, 30 ) );
375 QFont pushButtonThresholdAuto_font( pushButtonThresholdAuto->font() );
376 pushButtonThresholdAuto_font.setPointSize( 11 );
377 pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font );
378 pushButtonThresholdAuto->setText( tr( "auto" ) );
379 QToolTip::add( pushButtonThresholdAuto, tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) );
381 pushButtonRadiusAuto = new QPushButton( buttonGroupParameters, "pushButtonRadiusAuto" );
382 pushButtonRadiusAuto->setGeometry( QRect( 260, 120, 50, 30 ) );
383 QFont pushButtonRadiusAuto_font( pushButtonRadiusAuto->font() );
384 pushButtonRadiusAuto_font.setPointSize( 11 );
385 pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font );
386 pushButtonRadiusAuto->setText( tr( "auto" ) );
387 QToolTip::add( pushButtonRadiusAuto, tr( "set radius automatically (average #neighbours equal to 8)" ) );
389 resize( QSize(470, 554).expandedTo(minimumSizeHint()) );
390 clearWState( WState_Polished );
392 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
393 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
394 connect(pushButtonRadiusAuto, SIGNAL(clicked()), this, SLOT(OnRadiusAuto()));
395 connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto()));
400 * Destroys the object and frees any allocated resources
402 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
404 // no need to delete child widgets, Qt does it all for us
408 void MULTIPR_GUI_DecimateDlg::accept()
410 const char* strFieldName = comboBoxSelectFieldName->currentText().latin1();
411 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
412 int fieldIteration = atoi(strFieldIt);
415 int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed);
416 if ((ret != 1) || (thresholdMed <= 0.0f))
418 SUIT_MessageBox::error1(
419 mModule->getAppli()->desktop(),
420 "Decimation parameters error",
421 "Invalid medium threshold (should be > 0.0)",
428 ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow);
429 if ((ret != 1) || (thresholdLow <= 0.0f))
431 SUIT_MessageBox::error1(
432 mModule->getAppli()->desktop(),
433 "Decimation parameters error",
434 "Invalid low threshold (should be > 0.0)",
440 if (thresholdMed >= thresholdLow)
442 SUIT_MessageBox::error1(
443 mModule->getAppli()->desktop(),
444 "Decimation parameters error",
445 "Medium threshold must be < low threshold",
452 ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
453 if ((ret != 1) || (radius <= 0.0f))
455 SUIT_MessageBox::error1(
456 mModule->getAppli()->desktop(),
457 "Decimation parameters error",
458 "Invalid radius (should be > 0.0)",
464 QApplication::setOverrideCursor(Qt::waitCursor);
468 const QStringList& partsList = mModule->getSelectedParts();
469 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
471 const QString& partName = (*it);
473 mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value());
475 mModule->getMULTIPRObj()->decimePartition(
479 comboBoxSelectFilter->currentText().latin1(),
487 SUIT_MessageBox::error1(
488 mModule->getAppli()->desktop(),
490 "Error while decimating selected part(s)",
494 QApplication::restoreOverrideCursor();
499 void MULTIPR_GUI_DecimateDlg::reject()
505 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
507 // evaluates default radius for the first selected part
508 const QStringList& partsList = mModule->getSelectedParts();
509 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
510 int fieldIteration = atoi(strFieldIt);
511 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
517 char lMEDFileName[256];
520 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
532 QApplication::setOverrideCursor(Qt::waitCursor);
533 float defaultRadius = 0.5f;
537 sprintf(strParams, "2");
539 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
541 comboBoxSelectFieldName->currentText().latin1(),
543 comboBoxSelectFilter->currentText().latin1(),
546 sscanf(res, "%f", &defaultRadius);
551 QApplication::restoreOverrideCursor();
553 lineEditRadius->setText( QString::number(defaultRadius) );
557 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
559 // evaluates default radius for the first selected part
560 const QStringList& partsList = mModule->getSelectedParts();
561 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
562 int fieldIteration = atoi(strFieldIt);
563 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
569 char lMEDFileName[256];
572 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
579 QApplication::setOverrideCursor(Qt::waitCursor);
584 ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius);
585 if ((ret != 1) || (radius <= 0.0f))
587 SUIT_MessageBox::error1(
588 mModule->getAppli()->desktop(),
589 "Decimation parameters error",
590 "Invalid radius (should be > 0.0)",
597 sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value());
599 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
601 comboBoxSelectFieldName->currentText().latin1(),
603 comboBoxSelectFilter->currentText().latin1(),
606 float gradMin, gradAvg, gradMax;
607 sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax);
609 lineEditTMed->setText( QString::number(gradMin) );
610 lineEditTLow->setText( QString::number(gradMax) );
616 QApplication::restoreOverrideCursor();
620 //*****************************************************************************
621 // MULTIPR_GUI_ProgressCallbackDlg
622 // QT dialog box used to display progress in time consuming task (e.g. save)
623 //*****************************************************************************
625 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
630 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
632 setLabel(new QLabel(this, "Please wait"));
633 setLabelText("Please wait");
638 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
644 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
646 setCaption(pTaskTitle);
647 MULTIPR_ProgressCallback::init(pNumStep);
651 void MULTIPR_GUI_ProgressCallbackDlg::done()
657 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
659 setProgress(int(pPercent));