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"
20 #include "MULTIPR_Mesh.hxx"
21 #include "MULTIPR_DecimationFilter.hxx"
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>
38 #include <SALOME_LifeCycleCORBA.hxx>
40 #include <QtxPopupMgr.h>
43 #include <qapplication.h>
44 #include <qinputdialog.h>
46 #include <qpushbutton.h>
47 #include <qgroupbox.h>
49 #include <qbuttongroup.h>
51 #include <qcombobox.h>
53 #include <qlineedit.h>
56 #include <qwhatsthis.h>
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)
69 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
70 buttonGroupProcess->setGeometry( QRect( 10, 110, 450, 60 ) );
72 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
73 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
75 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
76 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
78 buttonGroupSelectMesh = new QButtonGroup( this, "buttonGroupSelectMesh" );
79 buttonGroupSelectMesh->setGeometry( QRect( 10, 10, 450, 91 ) );
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++)
86 const char* strItem = (*listMeshes)[i];
87 comboBoxSelectMesh->insertItem(strItem);
89 comboBoxSelectMesh->setEditable(false);
91 textLabelSelectMesh = new QLabel( buttonGroupSelectMesh, "textLabelSelectMesh" );
92 textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) );
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" ) );
101 resize( QSize(471, 185).expandedTo(minimumSizeHint()) );
102 clearWState( WState_Polished );
104 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
105 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
110 * Destroys the object and frees any allocated resources
112 MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg()
114 // no need to delete child widgets, Qt does it all for us
118 void MULTIPR_GUI_Partition1Dlg::accept()
120 const char* meshName = comboBoxSelectMesh->currentText().latin1();
124 mModule->getMULTIPRObj()->setMesh(meshName);
126 QApplication::setOverrideCursor(Qt::waitCursor);
127 mModule->getMULTIPRObj()->partitionneDomaine();
128 QApplication::restoreOverrideCursor();
133 SUIT_MessageBox::error1(
134 mModule->getAppli()->desktop(),
135 "Import MED file error",
136 "Unable to set mesh",
141 mModule->getAppli()->updateObjectBrowser();
145 void MULTIPR_GUI_Partition1Dlg::reject()
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)
156 buttonGroupSplitParameters = new QButtonGroup( this, "buttonGroupSplitParameters" );
157 buttonGroupSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) );
159 textLabelSelectNbParts = new QLabel( buttonGroupSplitParameters, "textLabelSelectNbParts" );
160 textLabelSelectNbParts->setGeometry( QRect( 30, 30, 160, 31 ) );
162 textLabelSelectSplitter = new QLabel( buttonGroupSplitParameters, "textLabelSelectSplitter" );
163 textLabelSelectSplitter->setGeometry( QRect( 30, 80, 111, 31 ) );
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);
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 );
177 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
178 buttonGroupProcess->setGeometry( QRect( 10, 160, 380, 60 ) );
180 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
181 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
183 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
184 pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) );
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" ) );
194 resize( QSize(403, 234).expandedTo(minimumSizeHint()) );
195 clearWState( WState_Polished );
197 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
198 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
202 * Destroys the object and frees any allocated resources
204 MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg()
206 // no need to delete child widgets, Qt does it all for us
210 void MULTIPR_GUI_Partition2Dlg::accept()
212 const char* strSplitter = comboBoxSelectSplitter->currentText().latin1();
213 int nbParts = spinBoxNbParts->value();
214 int partitionner = -1;
215 if (strcmp(strSplitter, "METIS") == 0)
219 else if (strcmp(strSplitter, "SCOTCH") == 0)
224 QApplication::setOverrideCursor(Qt::waitCursor);
228 const QStringList& partsList = mModule->getSelectedParts();
229 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
231 const QString& partName = (*it);
232 cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter;
233 mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner);
239 SUIT_MessageBox::error1(
240 mModule->getAppli()->desktop(),
242 "Error while splitting selected part(s)",
246 QApplication::restoreOverrideCursor();
251 void MULTIPR_GUI_Partition2Dlg::reject()
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)
262 buttonGroupSelectField = new QButtonGroup( this, "buttonGroupSelectField" );
263 buttonGroupSelectField->setGeometry( QRect( 10, 10, 450, 140 ) );
265 textLabelSelectFieldName = new QLabel( buttonGroupSelectField, "textLabelSelectFieldName" );
266 textLabelSelectFieldName->setGeometry( QRect( 30, 30, 141, 31 ) );
268 textLabelSelectFieldIteration = new QLabel( buttonGroupSelectField, "textLabelSelectFieldIteration" );
269 textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) );
271 MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields();
272 int maxIteration = 0;
273 for (int i=0 ; i<listFields->length() ; i++)
275 const char* strItem = (*listFields)[i];
276 CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem);
277 if (nbIteration > maxIteration)
279 maxIteration = nbIteration;
283 comboBoxSelectFieldIteration = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldIteration" );
284 comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 280, 40 ) );
285 for (int i=1 ; i<=maxIteration ; i++)
287 comboBoxSelectFieldIteration->insertItem(QString::number(i));
290 comboBoxSelectFieldName = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldName" );
291 comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 280, 40 ) );
292 for (int i=0 ; i<listFields->length() ; i++)
294 const char* strItem = (*listFields)[i];
295 comboBoxSelectFieldName->insertItem(strItem);
297 comboBoxSelectFieldName->setEditable(false);
298 QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) );
300 buttonGroupSelectFilter = new QButtonGroup( this, "buttonGroupSelectFilter" );
301 buttonGroupSelectFilter->setGeometry( QRect( 10, 160, 450, 90 ) );
303 textLabelSelectFilter = new QLabel( buttonGroupSelectFilter, "textLabelSelectFilter" );
304 textLabelSelectFilter->setGeometry( QRect( 30, 30, 101, 31 ) );
306 comboBoxSelectFilter = new QComboBox( FALSE, buttonGroupSelectFilter, "comboBoxSelectFilter" );
307 comboBoxSelectFilter->setGeometry( QRect( 150, 30, 280, 40 ) );
308 comboBoxSelectFilter->insertItem("Filtre_GradientMoyen");
310 buttonGroupParameters = new QButtonGroup( this, "buttonGroupParameters" );
311 buttonGroupParameters->setGeometry( QRect( 10, 260, 450, 210 ) );
313 textLabelTMed = new QLabel( buttonGroupParameters, "textLabelTMed" );
314 textLabelTMed->setGeometry( QRect( 20, 40, 242, 30 ) );
316 textLabelTLow = new QLabel( buttonGroupParameters, "textLabelTLow" );
317 textLabelTLow->setGeometry( QRect( 20, 80, 208, 30 ) );
319 textLabelRadius = new QLabel( buttonGroupParameters, "textLabelRadius" );
320 textLabelRadius->setGeometry( QRect( 20, 120, 211, 30 ) );
322 textLabelBoxing = new QLabel( buttonGroupParameters, "textLabelBoxing" );
323 textLabelBoxing->setGeometry( QRect( 20, 160, 241, 30 ) );
325 lineEditTMed = new QLineEdit( buttonGroupParameters, "lineEditTMed" );
326 lineEditTMed->setGeometry( QRect( 320, 40, 111, 30 ) );
328 lineEditTLow = new QLineEdit( buttonGroupParameters, "lineEditTLow" );
329 lineEditTLow->setGeometry( QRect( 320, 80, 111, 30 ) );
331 lineEditRadius = new QLineEdit( buttonGroupParameters, "lineEditRadius" );
332 lineEditRadius->setGeometry( QRect( 320, 120, 111, 30 ) );
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 );
340 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
341 buttonGroupProcess->setGeometry( QRect( 10, 480, 450, 60 ) );
343 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
344 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
346 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
347 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
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" ) );
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") );
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)" ) );
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)" ) );
385 resize( QSize(470, 554).expandedTo(minimumSizeHint()) );
386 clearWState( WState_Polished );
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()));
396 * Destroys the object and frees any allocated resources
398 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
400 // no need to delete child widgets, Qt does it all for us
404 void MULTIPR_GUI_DecimateDlg::accept()
406 const char* strFieldName = comboBoxSelectFieldName->currentText().latin1();
407 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
408 int fieldIteration = atoi(strFieldIt);
411 int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed);
412 if ((ret != 1) || (thresholdMed <= 0.0f))
414 SUIT_MessageBox::error1(
415 mModule->getAppli()->desktop(),
416 "Decimation parameters error",
417 "Invalid medium threshold (should be > 0.0)",
424 ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow);
425 if ((ret != 1) || (thresholdLow <= 0.0f))
427 SUIT_MessageBox::error1(
428 mModule->getAppli()->desktop(),
429 "Decimation parameters error",
430 "Invalid low threshold (should be > 0.0)",
436 if (thresholdMed >= thresholdLow)
438 SUIT_MessageBox::error1(
439 mModule->getAppli()->desktop(),
440 "Decimation parameters error",
441 "Medium threshold must be < low threshold",
448 ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
449 if ((ret != 1) || (radius <= 0.0f))
451 SUIT_MessageBox::error1(
452 mModule->getAppli()->desktop(),
453 "Decimation parameters error",
454 "Invalid radius (should be > 0.0)",
460 QApplication::setOverrideCursor(Qt::waitCursor);
464 const QStringList& partsList = mModule->getSelectedParts();
465 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
467 const QString& partName = (*it);
469 mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value());
471 mModule->getMULTIPRObj()->decimePartition(
475 comboBoxSelectFilter->currentText().latin1(),
483 SUIT_MessageBox::error1(
484 mModule->getAppli()->desktop(),
486 "Error while decimating selected part(s)",
490 QApplication::restoreOverrideCursor();
495 void MULTIPR_GUI_DecimateDlg::reject()
501 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
503 // evaluates default radius for the first selected part
504 const QStringList& partsList = mModule->getSelectedParts();
505 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
511 char lMEDFileName[256];
514 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
521 QApplication::setOverrideCursor(Qt::waitCursor);
522 float defaultRadius = 0.5f;
525 multipr::Mesh* mesh = new multipr::Mesh();
526 mesh->readSequentialMED(lMEDFileName, lMeshName);
527 const int averageNumberOfNeighbours = 8;
528 defaultRadius = mesh->evalDefaultRadius(averageNumberOfNeighbours);
534 QApplication::restoreOverrideCursor();
536 lineEditRadius->setText( QString::number(defaultRadius) );
540 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
542 // evaluates default radius for the first selected part
543 const QStringList& partsList = mModule->getSelectedParts();
544 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
550 char lMEDFileName[256];
553 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
560 QApplication::setOverrideCursor(Qt::waitCursor);
561 float defaultRadius = 0.5f;
564 multipr::Mesh* mesh = new multipr::Mesh();
565 mesh->readSequentialMED(lMEDFileName, lMeshName);
567 multipr::DecimationFilter* filter =
568 multipr::DecimationFilter::create(comboBoxSelectFilter->currentText().latin1());
570 double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
572 multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
575 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
576 int fieldIteration = atoi(strFieldIt);
579 ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
580 if ((ret != 1) || (radius <= 0.0f))
582 SUIT_MessageBox::error1(
583 mModule->getAppli()->desktop(),
584 "Decimation parameters error",
585 "Invalid radius (should be > 0.0)",
591 filterGrad->getGradientInfo(
593 comboBoxSelectFieldName->currentText().latin1(),
596 spinBoxBoxing->value(),
605 lineEditTMed->setText( QString::number(gradMin) );
606 lineEditTLow->setText( QString::number(gradMax) );
611 QApplication::restoreOverrideCursor();
615 //*****************************************************************************
616 // MULTIPR_GUI_ProgressCallbackDlg
617 //*****************************************************************************
619 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
620 QProgressDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
622 setLabel(new QLabel(this, "Please wait"));
623 setLabelText("Please wait");
628 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
633 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
635 setCaption(pTaskTitle);
636 MULTIPR_ProgressCallback::init(pNumStep);
640 void MULTIPR_GUI_ProgressCallbackDlg::done()
646 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
648 setProgress(int(pPercent));