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",
144 void MULTIPR_GUI_Partition1Dlg::reject()
150 MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) :
151 QDialog( theModule->application()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
155 buttonGroupSplitParameters = new QButtonGroup( this, "buttonGroupSplitParameters" );
156 buttonGroupSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) );
158 textLabelSelectNbParts = new QLabel( buttonGroupSplitParameters, "textLabelSelectNbParts" );
159 textLabelSelectNbParts->setGeometry( QRect( 30, 30, 160, 31 ) );
161 textLabelSelectSplitter = new QLabel( buttonGroupSplitParameters, "textLabelSelectSplitter" );
162 textLabelSelectSplitter->setGeometry( QRect( 30, 80, 111, 31 ) );
164 comboBoxSelectSplitter = new QComboBox( FALSE, buttonGroupSplitParameters, "comboBoxSelectSplitter" );
165 comboBoxSelectSplitter->setGeometry( QRect( 210, 80, 150, 40 ) );
166 comboBoxSelectSplitter->insertItem("METIS");
167 comboBoxSelectSplitter->insertItem("SCOTCH");
168 comboBoxSelectSplitter->setEditable(false);
170 spinBoxNbParts = new QSpinBox( buttonGroupSplitParameters, "spinBoxNbParts" );
171 spinBoxNbParts->setGeometry( QRect( 210, 30, 150, 30 ) );
172 spinBoxNbParts->setMaxValue( 1000 );
173 spinBoxNbParts->setMinValue( 2 );
174 spinBoxNbParts->setValue( 2 );
176 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
177 buttonGroupProcess->setGeometry( QRect( 10, 160, 380, 60 ) );
179 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
180 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
182 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
183 pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) );
185 setCaption( tr( "Split selected part" ) );
186 buttonGroupSplitParameters->setTitle( tr( "Split parameters" ) );
187 textLabelSelectNbParts->setText( tr( "Number of sub-parts" ) );
188 textLabelSelectSplitter->setText( tr( "Splitter" ) );
189 buttonGroupProcess->setTitle( QString::null );
190 pushButtonOK->setText( tr("OK") );
191 pushButtonCancel->setText( tr( "Cancel" ) );
193 resize( QSize(403, 234).expandedTo(minimumSizeHint()) );
194 clearWState( WState_Polished );
196 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
197 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
201 * Destroys the object and frees any allocated resources
203 MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg()
205 // no need to delete child widgets, Qt does it all for us
209 void MULTIPR_GUI_Partition2Dlg::accept()
211 const char* strSplitter = comboBoxSelectSplitter->currentText().latin1();
212 int nbParts = spinBoxNbParts->value();
213 int partitionner = -1;
214 if (strcmp(strSplitter, "METIS") == 0)
218 else if (strcmp(strSplitter, "SCOTCH") == 0)
223 QApplication::setOverrideCursor(Qt::waitCursor);
227 const QStringList& partsList = mModule->getSelectedParts();
228 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
230 const QString& partName = (*it);
231 cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl;
232 mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner);
238 SUIT_MessageBox::error1(
239 mModule->getAppli()->desktop(),
241 "Error while splitting selected part(s)",
245 QApplication::restoreOverrideCursor();
250 void MULTIPR_GUI_Partition2Dlg::reject()
256 MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) :
257 QDialog( theModule->application()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
261 buttonGroupSelectField = new QButtonGroup( this, "buttonGroupSelectField" );
262 buttonGroupSelectField->setGeometry( QRect( 10, 10, 450, 140 ) );
264 textLabelSelectFieldName = new QLabel( buttonGroupSelectField, "textLabelSelectFieldName" );
265 textLabelSelectFieldName->setGeometry( QRect( 30, 30, 141, 31 ) );
267 textLabelSelectFieldIteration = new QLabel( buttonGroupSelectField, "textLabelSelectFieldIteration" );
268 textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) );
270 MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields();
271 int maxIteration = 0;
272 for (int i=0 ; i<listFields->length() ; i++)
274 const char* strItem = (*listFields)[i];
275 CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem);
276 if (nbIteration > maxIteration)
278 maxIteration = nbIteration;
282 comboBoxSelectFieldIteration = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldIteration" );
283 comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 280, 40 ) );
284 for (int i=1 ; i<=maxIteration ; i++)
286 comboBoxSelectFieldIteration->insertItem(QString::number(i));
289 comboBoxSelectFieldName = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldName" );
290 comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 280, 40 ) );
291 for (int i=0 ; i<listFields->length() ; i++)
293 const char* strItem = (*listFields)[i];
294 comboBoxSelectFieldName->insertItem(strItem);
296 comboBoxSelectFieldName->setEditable(false);
297 QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) );
299 buttonGroupSelectFilter = new QButtonGroup( this, "buttonGroupSelectFilter" );
300 buttonGroupSelectFilter->setGeometry( QRect( 10, 160, 450, 90 ) );
302 textLabelSelectFilter = new QLabel( buttonGroupSelectFilter, "textLabelSelectFilter" );
303 textLabelSelectFilter->setGeometry( QRect( 30, 30, 101, 31 ) );
305 comboBoxSelectFilter = new QComboBox( FALSE, buttonGroupSelectFilter, "comboBoxSelectFilter" );
306 comboBoxSelectFilter->setGeometry( QRect( 150, 30, 280, 40 ) );
307 comboBoxSelectFilter->insertItem("Filtre_GradientMoyen");
309 buttonGroupParameters = new QButtonGroup( this, "buttonGroupParameters" );
310 buttonGroupParameters->setGeometry( QRect( 10, 260, 450, 210 ) );
312 textLabelTMed = new QLabel( buttonGroupParameters, "textLabelTMed" );
313 textLabelTMed->setGeometry( QRect( 20, 40, 242, 30 ) );
315 textLabelTLow = new QLabel( buttonGroupParameters, "textLabelTLow" );
316 textLabelTLow->setGeometry( QRect( 20, 80, 208, 30 ) );
318 textLabelRadius = new QLabel( buttonGroupParameters, "textLabelRadius" );
319 textLabelRadius->setGeometry( QRect( 20, 120, 211, 30 ) );
321 textLabelBoxing = new QLabel( buttonGroupParameters, "textLabelBoxing" );
322 textLabelBoxing->setGeometry( QRect( 20, 160, 241, 30 ) );
324 lineEditTMed = new QLineEdit( buttonGroupParameters, "lineEditTMed" );
325 lineEditTMed->setGeometry( QRect( 320, 40, 111, 30 ) );
327 lineEditTLow = new QLineEdit( buttonGroupParameters, "lineEditTLow" );
328 lineEditTLow->setGeometry( QRect( 320, 80, 111, 30 ) );
330 lineEditRadius = new QLineEdit( buttonGroupParameters, "lineEditRadius" );
331 lineEditRadius->setGeometry( QRect( 320, 120, 111, 30 ) );
333 spinBoxBoxing = new QSpinBox( buttonGroupParameters, "spinBoxBoxing" );
334 spinBoxBoxing->setGeometry( QRect( 320, 160, 111, 30 ) );
335 spinBoxBoxing->setMaxValue( 200 );
336 spinBoxBoxing->setMinValue( 2 );
337 spinBoxBoxing->setValue( 100 );
339 buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" );
340 buttonGroupProcess->setGeometry( QRect( 10, 480, 450, 60 ) );
342 pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" );
343 pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) );
345 pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" );
346 pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) );
348 setCaption( tr( "Decimation" ) );
349 buttonGroupSelectField->setTitle( tr( "Select field" ) );
350 textLabelSelectFieldName->setText( tr( "Field name" ) );
351 textLabelSelectFieldIteration->setText( tr( "Iteration" ) );
352 buttonGroupSelectFilter->setTitle( tr( "Select filter" ) );
353 textLabelSelectFilter->setText( tr( "Filter name" ) );
354 buttonGroupParameters->setTitle( tr( "Set parameters" ) );
355 textLabelTMed->setText( tr( "Threshold for medium resolution" ) );
356 textLabelTLow->setText( tr( "Threshold for low resolution" ) );
357 textLabelRadius->setText( tr( "Radius (neighborhood)" ) );
358 textLabelBoxing->setText( tr( "Boxing parameter" ) );
359 lineEditTMed->setText( tr( "0.1" ) );
360 lineEditTLow->setText( tr( "0.2" ) );
362 float defaultRadius = 0.5f;
363 lineEditRadius->setText( QString::number(defaultRadius) );
364 buttonGroupProcess->setTitle( QString::null );
365 pushButtonCancel->setText( tr( "Cancel" ) );
366 pushButtonOK->setText( tr("OK") );
368 pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" );
369 pushButtonThresholdAuto->setGeometry( QRect( 260, 80, 50, 30 ) );
370 QFont pushButtonThresholdAuto_font( pushButtonThresholdAuto->font() );
371 pushButtonThresholdAuto_font.setPointSize( 11 );
372 pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font );
373 pushButtonThresholdAuto->setText( tr( "auto" ) );
374 QToolTip::add( pushButtonThresholdAuto, tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) );
376 pushButtonRadiusAuto = new QPushButton( buttonGroupParameters, "pushButtonRadiusAuto" );
377 pushButtonRadiusAuto->setGeometry( QRect( 260, 120, 50, 30 ) );
378 QFont pushButtonRadiusAuto_font( pushButtonRadiusAuto->font() );
379 pushButtonRadiusAuto_font.setPointSize( 11 );
380 pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font );
381 pushButtonRadiusAuto->setText( tr( "auto" ) );
382 QToolTip::add( pushButtonRadiusAuto, tr( "set radius automatically (average #neighbours equal to 8)" ) );
384 resize( QSize(470, 554).expandedTo(minimumSizeHint()) );
385 clearWState( WState_Polished );
387 connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
388 connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
389 connect(pushButtonRadiusAuto, SIGNAL(clicked()), this, SLOT(OnRadiusAuto()));
390 connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto()));
395 * Destroys the object and frees any allocated resources
397 MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg()
399 // no need to delete child widgets, Qt does it all for us
403 void MULTIPR_GUI_DecimateDlg::accept()
405 const char* strFieldName = comboBoxSelectFieldName->currentText().latin1();
406 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
407 int fieldIteration = atoi(strFieldIt);
410 int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed);
411 if ((ret != 1) || (thresholdMed <= 0.0f))
413 SUIT_MessageBox::error1(
414 mModule->getAppli()->desktop(),
415 "Decimation parameters error",
416 "Invalid medium threshold (should be > 0.0)",
423 ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow);
424 if ((ret != 1) || (thresholdLow <= 0.0f))
426 SUIT_MessageBox::error1(
427 mModule->getAppli()->desktop(),
428 "Decimation parameters error",
429 "Invalid low threshold (should be > 0.0)",
435 if (thresholdMed >= thresholdLow)
437 SUIT_MessageBox::error1(
438 mModule->getAppli()->desktop(),
439 "Decimation parameters error",
440 "Medium threshold must be < low threshold",
447 ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius);
448 if ((ret != 1) || (radius <= 0.0f))
450 SUIT_MessageBox::error1(
451 mModule->getAppli()->desktop(),
452 "Decimation parameters error",
453 "Invalid radius (should be > 0.0)",
459 QApplication::setOverrideCursor(Qt::waitCursor);
463 const QStringList& partsList = mModule->getSelectedParts();
464 for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
466 const QString& partName = (*it);
468 mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value());
470 mModule->getMULTIPRObj()->decimePartition(
474 comboBoxSelectFilter->currentText().latin1(),
482 SUIT_MessageBox::error1(
483 mModule->getAppli()->desktop(),
485 "Error while decimating selected part(s)",
489 QApplication::restoreOverrideCursor();
494 void MULTIPR_GUI_DecimateDlg::reject()
500 void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
502 // evaluates default radius for the first selected part
503 const QStringList& partsList = mModule->getSelectedParts();
504 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
505 int fieldIteration = atoi(strFieldIt);
506 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
512 char lMEDFileName[256];
515 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
522 QApplication::setOverrideCursor(Qt::waitCursor);
523 float defaultRadius = 0.5f;
527 sprintf(strParams, "2");
529 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
531 comboBoxSelectFieldName->currentText().latin1(),
533 comboBoxSelectFilter->currentText().latin1(),
536 sscanf(res, "%f", &defaultRadius);
541 QApplication::restoreOverrideCursor();
543 lineEditRadius->setText( QString::number(defaultRadius) );
547 void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
549 // evaluates default radius for the first selected part
550 const QStringList& partsList = mModule->getSelectedParts();
551 const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1();
552 int fieldIteration = atoi(strFieldIt);
553 char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1());
559 char lMEDFileName[256];
562 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
569 QApplication::setOverrideCursor(Qt::waitCursor);
574 ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius);
575 if ((ret != 1) || (radius <= 0.0f))
577 SUIT_MessageBox::error1(
578 mModule->getAppli()->desktop(),
579 "Decimation parameters error",
580 "Invalid radius (should be > 0.0)",
587 sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value());
589 char* res = mModule->getMULTIPRObj()->evalDecimationParams(
591 comboBoxSelectFieldName->currentText().latin1(),
593 comboBoxSelectFilter->currentText().latin1(),
596 float gradMin, gradAvg, gradMax;
597 sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax);
599 lineEditTMed->setText( QString::number(gradMin) );
600 lineEditTLow->setText( QString::number(gradMax) );
606 QApplication::restoreOverrideCursor();
610 //*****************************************************************************
611 // MULTIPR_GUI_ProgressCallbackDlg
612 //*****************************************************************************
614 MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) :
615 QProgressDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
617 setLabel(new QLabel(this, "Please wait"));
618 setLabelText("Please wait");
623 MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg()
628 void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep)
630 setCaption(pTaskTitle);
631 MULTIPR_ProgressCallback::init(pNumStep);
635 void MULTIPR_GUI_ProgressCallbackDlg::done()
641 void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent)
643 setProgress(int(pPercent));