Salome HOME
2589be3438fc78e739012c21b903769cccec5ba7
[plugins/ghs3dplugin.git] / src / GUI / GHS3DPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2004-2022  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, or (at your option) any later version.
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 //  GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 //  File   : GHS3DPluginGUI_HypothesisCreator.cxx
22 //  Author : Michael Zorin
23 //  Module : GHS3DPlugin
24 //
25 #include "GHS3DPluginGUI_HypothesisCreator.h"
26 #include "GHS3DPluginGUI_Enums.h"
27 #include "GHS3DPluginGUI_Dlg.h"
28 #include "GHS3DPlugin_OptimizerHypothesis.hxx"
29
30 #include <GeometryGUI.h>
31
32 #include <SMESHGUI_Utils.h>
33 #include <SMESHGUI_SpinBox.h>
34 #include <SMESHGUI_HypothesesUtils.h>
35 #include <SMESH_NumberFilter.hxx>
36 #include <SMESH_TypeFilter.hxx>
37 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
38
39 #include <LightApp_SelectionMgr.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SalomeApp_IntSpinBox.h>
45 #include <SalomeApp_Tools.h>
46 #include <SalomeApp_TypeFilter.h>
47
48 #include "GHS3DPlugin_Hypothesis.hxx"
49
50 #include <QCheckBox>
51 #include <QComboBox>
52 #include <QButtonGroup>
53 #include <QFileInfo>
54 #include <QFrame>
55 #include <QGridLayout>
56 #include <QGroupBox>
57 #include <QHeaderView>
58 #include <QLabel>
59 #include <QLineEdit>
60 #include <QPalette>
61 #include <QPushButton>
62 #include <QRadioButton>
63 #include <QSpinBox>
64 #include <QtWidgets>
65 #include <QTabWidget>
66 #include <QTableWidget>
67 #include <QTableWidgetItem>
68 #include <QVBoxLayout>
69
70 #include <stdexcept>
71 #include <utilities.h>
72
73 namespace
74 {
75   QComboBox* getModeCombo( QWidget* parent, bool isPThreadCombo )
76   {
77     QComboBox* combo = new QComboBox( parent );
78     if ( isPThreadCombo )
79     {
80       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::SAFE, QObject::tr("MODE_SAFE"));
81       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::AGGRESSIVE, QObject::tr("MODE_AGGRESSIVE"));
82       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::NONE, QObject::tr("MODE_NONE"));
83     }
84     else
85     {
86       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::NO, QObject::tr("MODE_NO"));
87       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::YES, QObject::tr("MODE_YES"));
88       combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::ONLY, QObject::tr("MODE_ONLY"));
89     }
90     return combo;
91   }
92 }
93
94 //
95 // BEGIN EnforcedVertexTableWidgetDelegate
96 //
97
98 EnforcedVertexTableWidgetDelegate::EnforcedVertexTableWidgetDelegate(QObject *parent)
99   : QItemDelegate(parent)
100 {
101 }
102
103 QWidget *EnforcedVertexTableWidgetDelegate::createEditor(QWidget *parent,
104                                                          const QStyleOptionViewItem & option ,
105                                                          const QModelIndex & index ) const
106 {
107   QModelIndex father = index.parent();
108   QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
109   
110   if (index.column() == ENF_VER_X_COLUMN ||
111       index.column() == ENF_VER_Y_COLUMN ||
112       index.column() == ENF_VER_Z_COLUMN ||
113       index.column() == ENF_VER_SIZE_COLUMN) {
114     SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
115     if (index.column() == ENF_VER_SIZE_COLUMN)
116       editor->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
117     else
118       editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
119     editor->setReadOnly(!entry.isEmpty());
120     editor->setDisabled(!entry.isEmpty());
121     return editor;
122   }
123   else if (index.column() == ENF_VER_GROUP_COLUMN ||
124            index.column() == ENF_VER_NAME_COLUMN) {
125     //   else {
126     QLineEdit *editor = new QLineEdit(parent);
127     if (index.column() != ENF_VER_GROUP_COLUMN) {
128       editor->setReadOnly(!entry.isEmpty());
129       editor->setDisabled(!entry.isEmpty());
130     }
131     return editor;
132   }
133   return QItemDelegate::createEditor(parent, option, index);
134 }
135
136 void EnforcedVertexTableWidgetDelegate::setEditorData(QWidget *editor,
137                                                       const QModelIndex &index) const
138 {
139   if (index.column() == ENF_VER_X_COLUMN ||
140       index.column() == ENF_VER_Y_COLUMN ||
141       index.column() == ENF_VER_Z_COLUMN ||
142       index.column() == ENF_VER_SIZE_COLUMN)
143   {
144     SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
145     lineEdit->SetValue(index.data().toDouble());
146   } 
147   else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
148     QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
149     checkBox->setChecked(index.data().toBool());
150   }
151   else {
152     QItemDelegate::setEditorData(editor, index);
153   }
154 }
155
156 void EnforcedVertexTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
157                                                      const QModelIndex &index) const
158 {
159   QModelIndex parent = index.parent();
160   
161   QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
162   bool isCompound = parent.child(index.row(), ENF_VER_COMPOUND_COLUMN).data(Qt::CheckStateRole).toBool();
163   
164   if (index.column() == ENF_VER_X_COLUMN || 
165       index.column() == ENF_VER_Y_COLUMN || 
166       index.column() == ENF_VER_Z_COLUMN) {
167     SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
168     if (!isCompound && !vertexExists(model, index, lineEdit->GetString()))
169       model->setData(index, lineEdit->GetValue(), Qt::EditRole);
170   } 
171   else if (index.column() == ENF_VER_SIZE_COLUMN)
172   {
173     SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
174     const double newsize =  lineEdit->GetValue();
175     if (newsize > 0)
176       model->setData(index, newsize, Qt::EditRole);
177   } 
178   else if (index.column() == ENF_VER_NAME_COLUMN) {
179     QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
180     QString value = lineEdit->text();
181     if (entry.isEmpty() && !vertexExists(model, index, value))
182       model->setData(index, value, Qt::EditRole);
183   } 
184   else if (index.column() == ENF_VER_ENTRY_COLUMN) {
185     QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
186     QString value = lineEdit->text();
187     if (! vertexExists(model, index, value))
188       model->setData(index, value, Qt::EditRole);
189   }
190   else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
191     QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
192     model->setData(index, checkBox->isChecked(), Qt::CheckStateRole);
193   }
194   else {
195     QItemDelegate::setModelData(editor, model, index);
196   }
197 }
198
199 void EnforcedVertexTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
200                                                              const QStyleOptionViewItem &option,
201                                                              const QModelIndex &/* index */) const
202 {
203   editor->setGeometry(option.rect);
204 }
205
206 bool EnforcedVertexTableWidgetDelegate::vertexExists(QAbstractItemModel *model,
207                                                      const QModelIndex &index, 
208                                                      QString value) const
209 {
210   bool exists = false;
211   QModelIndex parent = index.parent();
212   int row = index.row();
213   int col = index.column();
214
215   if (parent.isValid() && !value.isEmpty()) {
216     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
217       double x, y, z;
218       if (col == ENF_VER_X_COLUMN) {
219         x = value.toDouble();
220         y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
221         z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
222       }
223       if (col == ENF_VER_Y_COLUMN) {
224         y = value.toDouble();
225         x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
226         z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
227       }
228       if (col == ENF_VER_Z_COLUMN) {
229         z = value.toDouble();
230         x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
231         y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
232       }
233       int nbChildren = model->rowCount(parent);
234       for (int i = 0 ; i < nbChildren ; i++) {
235         if (i != row) {
236           double childX = parent.child(i, ENF_VER_X_COLUMN).data().toDouble();
237           double childY = parent.child(i, ENF_VER_Y_COLUMN).data().toDouble();
238           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data().toDouble();
239           if ((childX == x) && (childY == y) && (childZ == z)) {
240             exists = true;
241             break;
242           }
243         }
244       }
245     }
246     else if (col == ENF_VER_NAME_COLUMN) {
247       QString name = parent.child(row, ENF_VER_NAME_COLUMN).data().toString();
248       if (name == value)
249         exists = true;
250     }
251   }
252
253   return exists;
254 }
255
256 //
257 // END EnforcedVertexTableWidgetDelegate
258 //
259
260 //
261 // BEGIN EnforcedMeshTableWidgetDelegate
262 //
263
264 EnforcedMeshTableWidgetDelegate::EnforcedMeshTableWidgetDelegate(QObject *parent)
265   : QItemDelegate(parent)
266 {
267 }
268
269 QWidget *EnforcedMeshTableWidgetDelegate::createEditor(QWidget *parent,
270                                                        const QStyleOptionViewItem & option ,
271                                                        const QModelIndex & index ) const
272 {
273   return QItemDelegate::createEditor(parent, option, index);
274 }
275
276 void EnforcedMeshTableWidgetDelegate::setEditorData(QWidget *editor,
277                                                     const QModelIndex &index) const
278 {
279   QItemDelegate::setEditorData(editor, index);
280 }
281
282 void EnforcedMeshTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
283                                                    const QModelIndex &index) const
284 {  
285   QItemDelegate::setModelData(editor, model, index);
286
287 }
288
289 void EnforcedMeshTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
290                                                            const QStyleOptionViewItem &option,
291                                                            const QModelIndex &/* index */) const
292 {
293   editor->setGeometry(option.rect);
294 }
295
296 //
297 // END EnforcedMeshTableWidgetDelegate
298 //
299
300
301 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
302   : SMESHGUI_GenericHypothesisCreator( theHypType ),
303     myName(0),
304     myOptimizationLevelCombo(0),
305     myMinSizeCheck(0),
306     myMaxSizeCheck(0),
307     myNumOfThreadsCheck(0),
308     myMinSizeSpin(0),
309     myMaxSizeSpin(0),
310     myGradationCheck(0),
311     myGradationSpin(0),
312     myNumOfThreadsSpin(0),
313     myUseProximityGroup(0),
314     myNbProximityLayers(0),
315     myToMakeGroupsOfDomains(0),
316     myToMeshHolesCheck(0),
317     myOptimizationCombo(0),
318     mySplitOverConstrainedCombo(0),
319     myPThreadsModeCombo(0),
320     myNumberOfThreadsSpin(0),
321     mySmoothOffSliversCheck(0),
322     myCreateNewNodesCheck(0),
323     myPthreadMode(0),
324     myParallelMode(0)
325 {
326   GeomToolSelected = NULL;
327   GeomToolSelected = getGeomSelectionTool();
328
329   iconVertex  = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
330   iconCompound  = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_COMPOUND")));
331   //   mySelectionMgr = SMESH::GetSelectionMgr(SMESHGUI::GetSMESHGUI());
332   myEnfMeshConstraintLabels << tr( "GHS3D_ENF_MESH_CONSTRAINT_NODE" ) << tr( "GHS3D_ENF_MESH_CONSTRAINT_EDGE" ) << tr("GHS3D_ENF_MESH_CONSTRAINT_FACE");
333 }
334
335 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
336 {
337   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
338   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
339   myEnfMeshWdg->deactivateSelection();
340 }
341
342 /**
343  * \brief {Get or create the geom selection tool for study}
344  * */
345 GeomSelectionTools* GHS3DPluginGUI_HypothesisCreator::getGeomSelectionTool()
346 {
347   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
348   if (that->GeomToolSelected == NULL) {
349     that->GeomToolSelected = new GeomSelectionTools();
350   }
351   return that->GeomToolSelected;
352 }
353
354 GEOM::GEOM_Gen_var GHS3DPluginGUI_HypothesisCreator::getGeomEngine()
355 {
356   return GeometryGUI::GetGeomGen();
357 }
358
359 bool GHS3DPluginGUI_HypothesisCreator::isOptimization() const
360 {
361   return ( hypType() == GHS3DPlugin_OptimizerHypothesis::GetHypType() );
362 }
363
364 void GHS3DPluginGUI_HypothesisCreator::onRadioButtomSelect()
365 {
366   onNumOfThreadsCheck();
367     
368   // Disable selection of standart+ 
369   QStandardItemModel * model = qobject_cast<QStandardItemModel*>(myOptimizationLevelCombo->model());
370   if(!model) return;
371   QStandardItem * item = model->item( GHS3DPlugin_Hypothesis::StandardPlus );
372   if(!item) return;
373
374   if ( myRadioBottomGroup->checkedId() == GHS3DPlugin_Hypothesis::MGTetra )
375   {
376     // Enable selection of stadart+
377     item->setEnabled(true);
378     // Set possibility to check memory options again.
379     myAdvWidget->maxMemoryCheck     ->setEnabled( true );
380     myAdvWidget->initialMemoryCheck ->setEnabled( true );
381
382     myAdvWidget->EnableAdvancedOptions( true );
383
384   }
385   else if ( myRadioBottomGroup->checkedId() == GHS3DPlugin_Hypothesis::MGTetraHPC )
386   {
387     // Disable selection of stadart+ 
388     item->setEnabled(false);
389     // Set to false memory checks and disable checkbox
390     myAdvWidget->maxMemoryCheck     ->setChecked( false );
391     myAdvWidget->initialMemoryCheck ->setChecked( false );
392     myAdvWidget->maxMemoryCheck     ->setEnabled( false );
393     myAdvWidget->initialMemoryCheck ->setEnabled( false );    
394     myAdvWidget->EnableAdvancedOptions( false );
395   }    
396
397 }
398
399 void GHS3DPluginGUI_HypothesisCreator::onNumOfThreadsCheck()
400 {
401   if ( myRadioBottomGroup->checkedId() == GHS3DPlugin_Hypothesis::MGTetra )
402   {
403     if ( myNumOfThreadsCheck->isChecked() )
404       myPthreadMode->setEnabled( true );
405     else
406       myPthreadMode->setEnabled( false );
407     
408     myParallelMode->setEnabled( false );
409   }
410   else if ( myRadioBottomGroup->checkedId() == GHS3DPlugin_Hypothesis::MGTetraHPC )
411   {
412     if ( myNumOfThreadsCheck->isChecked() )
413       myParallelMode->setEnabled( true );
414     else
415       myParallelMode->setEnabled( false );
416     
417     myPthreadMode->setEnabled( false );
418   }
419   else
420   {
421
422   }
423 }
424
425 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
426 {
427   QFrame* fr = new QFrame( 0 );
428   QVBoxLayout* lay = new QVBoxLayout( fr );
429   lay->setMargin( 5 );
430   lay->setSpacing( 0 );
431
432   // tab
433   QTabWidget* tab = new QTabWidget( fr );
434   tab->setTabShape( QTabWidget::Rounded );
435   tab->setTabPosition( QTabWidget::North );
436   lay->addWidget( tab );
437
438   // basic parameters
439   myStdGroup = new QWidget();
440   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
441   aStdLayout->setSpacing( 6 );
442   aStdLayout->setMargin( 11 );
443
444   int row = 0;
445   if ( isCreation() )
446   {
447     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
448     myName = new QLineEdit( myStdGroup );
449     aStdLayout->addWidget( myName, row++, 1, 1, 1 );
450   }
451   if ( isOptimization() )
452   {
453     myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
454     aStdLayout->addWidget( myToMeshHolesCheck, row, 0, 1, 1 );
455     myToMakeGroupsOfDomains = new QCheckBox( tr( "GHS3D_TO_MAKE_DOMAIN_GROUPS" ), myStdGroup );
456     aStdLayout->addWidget( myToMakeGroupsOfDomains, row++, 1, 1, 1 );
457
458     QLabel* optimizationLbl = new QLabel( tr( "GHS3D_OPTIMIZATION" ), myStdGroup );
459     aStdLayout->addWidget( optimizationLbl, row, 0, 1, 1 );
460     myOptimizationCombo = getModeCombo( myStdGroup, false );
461     aStdLayout->addWidget( myOptimizationCombo, row++, 1, 1, 1 );
462
463     QLabel* optimizatiolLevelLbl = new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup );
464     aStdLayout->addWidget( optimizatiolLevelLbl, row, 0, 1, 1 );
465     myOptimizationLevelCombo = new QComboBox( myStdGroup );
466     aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
467
468     QLabel* splitOverconstrainedLbl = new QLabel( tr("GHS3D_SPLIT_OVERCONSTRAINED"), myStdGroup );
469     aStdLayout->addWidget( splitOverconstrainedLbl, row, 0, 1, 1 );
470     mySplitOverConstrainedCombo = getModeCombo( myStdGroup, false );
471     aStdLayout->addWidget( mySplitOverConstrainedCombo, row++, 1, 1, 1 );
472
473     QLabel* pthreadsModeLbl = new QLabel( tr( "GHS3D_PTHREADS_MODE" ), myStdGroup);
474     aStdLayout->addWidget( pthreadsModeLbl, row, 0, 1, 1 );
475     myPThreadsModeCombo = getModeCombo( myStdGroup, true );
476     aStdLayout->addWidget( myPThreadsModeCombo, row++, 1, 1, 1 );
477
478     QLabel* nbThreadsLbl = new QLabel( tr( "GHS3D_NB_THREADS" ), myStdGroup);
479     aStdLayout->addWidget( nbThreadsLbl, row, 0, 1, 1 );
480     myNumberOfThreadsSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, myStdGroup );
481     aStdLayout->addWidget( myNumberOfThreadsSpin, row++, 1, 1, 1 );
482
483     mySmoothOffSliversCheck = new QCheckBox( tr( "GHS3D_SMOOTH_OFF_SLIVERS" ), myStdGroup );
484     aStdLayout->addWidget( mySmoothOffSliversCheck, row, 0, 1, 1 );
485     myCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myStdGroup );
486     aStdLayout->addWidget( myCreateNewNodesCheck, row++, 1, 1, 1 );
487   }
488   else
489   {
490     // Algorithm selection
491     QGroupBox* radioBottomGroup = new QGroupBox( tr("GHS3D_ALGO_SELECTION"), myStdGroup );
492     myRadioBottomGroup          = new QButtonGroup( radioBottomGroup );
493     
494     QRadioButton * GM_MSH      = new QRadioButton(tr("GHS3D_ALGO_MGTETRA"), radioBottomGroup );
495     QRadioButton * GM_MSH_HPC  = new QRadioButton(tr("GHS3D_ALGO_MGTETRAHPC"), radioBottomGroup );
496
497     myRadioBottomGroup->addButton( GM_MSH, 1 );    
498     myRadioBottomGroup->addButton( GM_MSH_HPC, 0 );
499     GM_MSH->setChecked( true );
500
501     QGridLayout* radioBottomLayout = new QGridLayout( radioBottomGroup );
502     radioBottomLayout->setSpacing( 4 );
503     radioBottomLayout->setMargin( 11 );
504     radioBottomLayout->addWidget( GM_MSH, 0, 0, 1, 1 );
505     radioBottomLayout->addWidget( GM_MSH_HPC, 0, 1, 1, 1 );
506
507     // Main parameters
508     QGroupBox* mainGroup          = new QGroupBox( tr("GHS3D_MAIN_PARAMS"), myStdGroup );
509     QLabel* optimizatiolLevelLbl  = new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), mainGroup );
510     QLabel* pthreadModeLbl        = new QLabel( tr( "GHS3D_PTHREAD_MODE" ), mainGroup );
511     QLabel* parallelStrat         = new QLabel( tr( "GHS3D_PARALLE_STRAT" ), mainGroup );
512
513     myOptimizationLevelCombo  = new QComboBox( mainGroup );
514     myMinSizeCheck            = new QCheckBox( tr("GHS3D_MIN_SIZE"), mainGroup );
515     myMaxSizeCheck            = new QCheckBox( tr("GHS3D_MAX_SIZE"), mainGroup );
516     myNumOfThreadsCheck       = new QCheckBox( tr("GHS3D_THREADS_SIZE"), mainGroup );
517     myPthreadMode             = new QComboBox( mainGroup );
518     myParallelMode            = new QComboBox( mainGroup );
519
520     myMinSizeSpin             = new SMESHGUI_SpinBox( mainGroup );
521     myMaxSizeSpin             = new SMESHGUI_SpinBox( mainGroup );
522     myNumOfThreadsSpin        = new SalomeApp_IntSpinBox( 1, 128, 1, mainGroup );
523
524     myMinSizeCheck->setChecked( false );
525     myMaxSizeCheck->setChecked( false );
526     myNumOfThreadsCheck->setChecked( false );
527
528     myMinSizeSpin->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
529     myMaxSizeSpin->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
530     myNumOfThreadsSpin->setValue( 4 );
531
532     myMinSizeSpin ->setEnabled( false );
533     myMaxSizeSpin ->setEnabled( false );
534     myNumOfThreadsSpin->setEnabled(false);
535     myPthreadMode ->setEnabled( false );
536     myParallelMode->setEnabled( false );
537
538     // ACTIONS ON BUTTOMS
539     connect( myMinSizeCheck,      SIGNAL( toggled(bool)), myMinSizeSpin,  SLOT( setEnabled(bool)));
540     connect( myMaxSizeCheck,      SIGNAL( toggled(bool)), myMaxSizeSpin,  SLOT( setEnabled(bool)));
541     connect( myNumOfThreadsCheck, SIGNAL( toggled(bool)), myNumOfThreadsSpin, SLOT( setEnabled(bool)));    
542     connect( myNumOfThreadsCheck, SIGNAL( toggled(bool)),  this, SLOT( onNumOfThreadsCheck() ));
543     connect( myNumOfThreadsCheck, SIGNAL( toggled(bool)),  this, SLOT( onNumOfThreadsCheck() ));
544     connect( GM_MSH,              SIGNAL( toggled( bool )),this, SLOT( onRadioButtomSelect() ));
545
546     QGridLayout* mainLayout = new QGridLayout( mainGroup );
547     mainLayout->setSpacing( 12 );
548     mainLayout->setMargin( 11 );
549     mainLayout->addWidget( optimizatiolLevelLbl,     0, 0, 1, 1 );
550     mainLayout->addWidget( myOptimizationLevelCombo, 0, 1, 1, 1 );
551     mainLayout->addWidget( myMinSizeCheck,           1, 0, 1, 1 );
552     mainLayout->addWidget( myMinSizeSpin,            1, 1, 1, 1 );
553     mainLayout->addWidget( myMaxSizeCheck,           2, 0, 1, 1 );
554     mainLayout->addWidget( myMaxSizeSpin,            2, 1, 1, 1 );
555     mainLayout->addWidget( myNumOfThreadsCheck,      3, 0, 1, 1 );
556     mainLayout->addWidget( myNumOfThreadsSpin,       3, 1, 1, 1 );
557     mainLayout->addWidget( pthreadModeLbl,           4, 0, 1, 1 );
558     mainLayout->addWidget( myPthreadMode,            4, 1, 1, 1 );
559     mainLayout->addWidget( parallelStrat,            5, 0, 1, 1 );
560     mainLayout->addWidget( myParallelMode,           5, 1, 1, 1 );
561     
562     // Volume proximity
563
564     QGroupBox* proxyGroup = new QGroupBox( tr("GHS3D_VOLUME_PROXIMITY"), myStdGroup );
565     myGradationCheck = new QCheckBox( tr("GHS3D_GRADATION"), proxyGroup );
566     myGradationSpin  = new SMESHGUI_SpinBox( proxyGroup );
567     myGradationSpin->RangeStepAndValidator(1, COORD_MAX, 0.1, "length_precision");
568     myGradationSpin->setEnabled( false );
569     connect( myGradationCheck, SIGNAL( toggled(bool)), myGradationSpin, SLOT( setEnabled(bool)));
570     myUseProximityGroup = new QGroupBox( tr("GHS3D_USE_VOLUME_PROXIMITY"), proxyGroup );
571     myUseProximityGroup->setCheckable( true );
572     //myUseProximityGroup->setChecked( false );
573     QLabel* nbProximityLayersLabel = new QLabel( tr("GHS3D_NB_LAYERS"));
574     myNbProximityLayers = new SalomeApp_IntSpinBox( 2, 1e6, 1, proxyGroup );
575
576     QHBoxLayout* useProxyLayout = new QHBoxLayout( myUseProximityGroup );
577     useProxyLayout->addWidget( nbProximityLayersLabel );
578     useProxyLayout->addWidget( myNbProximityLayers );
579
580     QGridLayout* proxyLayout = new QGridLayout( proxyGroup );
581     proxyLayout->setSpacing( 6 );
582     proxyLayout->setMargin( 11 );
583     proxyLayout->addWidget( myGradationCheck,    0, 0, 1, 1 );
584     proxyLayout->addWidget( myGradationSpin,     0, 1, 1, 1 );
585     proxyLayout->addWidget( myUseProximityGroup, 1, 0, 1, 2 );
586
587     // Other parameters
588
589     QGroupBox* otherGroup = new QGroupBox( tr("GHS3D_OTHER_PARAMETERS"), myStdGroup );
590     myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), otherGroup );
591     myToMakeGroupsOfDomains = new QCheckBox( tr( "GHS3D_TO_MAKE_DOMAIN_GROUPS" ), otherGroup );
592
593     QGridLayout* otherLayout = new QGridLayout( otherGroup );
594     otherLayout->setSpacing( 6 );
595     otherLayout->setMargin( 11 );
596     otherLayout->addWidget( myToMeshHolesCheck,      0, 0 );
597     otherLayout->addWidget( myToMakeGroupsOfDomains, 1, 0 );
598
599     aStdLayout->addWidget( radioBottomGroup,row++, 0, 1, 2 );
600     aStdLayout->addWidget( mainGroup,       row++, 0, 1, 2 );
601     aStdLayout->addWidget( proxyGroup,      row++, 0, 1, 2 );
602     aStdLayout->addWidget( otherGroup,      row++, 0, 1, 2 );
603
604     myPthreadMode->addItems( QStringList() << tr( "MODE_NONE" )   << tr( "MODE_AGGRESSIVE" ) << tr( "MODE_SAFE" ) );
605     myParallelMode->addItems( QStringList() << tr( "MODE_NONE" ) << tr( "MODE_REPRODUCIBLE_GIVEN_MAX_THREADS" )  << tr( "MODE_REPRODUCIBLE" ) << tr( "MODE_AGGRESSIVE" ) );
606   }
607   aStdLayout->setRowStretch( row, 10 );
608
609   myOptimizationLevelCombo->addItems( QStringList()
610                                       << tr( "LEVEL_NONE" )   << tr( "LEVEL_LIGHT" )
611                                       << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" )
612                                       << tr( "LEVEL_STRONG" ));
613
614   // advanced parameters
615   myAdvGroup = new QWidget();
616   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
617   anAdvLayout->setSpacing( 6 );
618   anAdvLayout->setMargin( 11 );
619   myAdvWidget = new GHS3DPluginGUI_AdvWidget(myAdvGroup);
620   anAdvLayout->addWidget( myAdvWidget);
621
622   myAdvWidget->maxMemoryCheck->setText(tr( "MAX_MEMORY_SIZE" ));
623   myAdvWidget->initialMemoryCheck->setText(tr( "INIT_MEMORY_SIZE" ));
624
625   myAdvWidget->maxMemorySpin->stepBy(10);
626   myAdvWidget->maxMemorySpin->setValue( 128 );
627
628   myAdvWidget->initialMemorySpin->stepBy(10);
629   myAdvWidget->initialMemorySpin->setValue( 100 );
630
631   myAdvWidget->initialMemoryLabel            ->setText (tr( "MEGABYTE" ));
632   myAdvWidget->maxMemoryLabel                ->setText (tr( "MEGABYTE" ));
633
634   myAdvWidget->workingDirectoryLabel         ->setText (tr( "WORKING_DIR" ));
635   myAdvWidget->workingDirectoryPushButton    ->setText (tr( "SELECT_DIR" ));
636   myAdvWidget->keepWorkingFilesCheck         ->setText (tr( "KEEP_WORKING_FILES" ));
637   myAdvWidget->verboseLevelLabel             ->setText (tr( "VERBOSE_LEVEL" ));
638   myAdvWidget->removeLogOnSuccessCheck       ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
639   myAdvWidget->logInFileCheck                ->setText (tr( "LOG_IN_FILE" ));
640   
641   myAdvWidget->memoryGroupBox                ->setTitle(tr( "MEMORY_GROUP_TITLE" ));
642   myAdvWidget->logGroupBox                   ->setTitle(tr( "LOG_GROUP_TITLE" ));
643   //myAdvWidget->advancedMeshingGroupBox       ->setTitle(tr( "ADVANCED_MESHING_GROUP_TITLE" ));
644   
645   // myAdvWidget->createNewNodesCheck           ->setText (tr( "TO_ADD_NODES" ));
646   // myAdvWidget->removeInitialCentralPointCheck->setText (tr( "NO_INITIAL_CENTRAL_POINT" ));
647   // myAdvWidget->boundaryRecoveryCheck         ->setText (tr( "RECOVERY_VERSION" ));
648   // myAdvWidget->FEMCorrectionCheck            ->setText (tr( "FEM_CORRECTION" ));
649   // myAdvWidget->gradationLabel                ->setText (tr( "GHS3D_GRADATION" ));
650   // myAdvWidget->gradationSpinBox->RangeStepAndValidator(0.0, 5.0, 0.05, "length_precision");
651
652   // if ( isOptimization() )
653   // {
654   //   myAdvWidget->createNewNodesCheck->hide();
655   //   myAdvWidget->removeInitialCentralPointCheck->hide();
656   //   myAdvWidget->boundaryRecoveryCheck->hide();
657   //   myAdvWidget->FEMCorrectionCheck->hide();
658   //   myAdvWidget->gradationLabel->hide();
659   //   myAdvWidget->gradationSpinBox->hide();
660   // }
661
662   // Enforced vertices parameters
663   myEnfGroup = new QWidget();
664   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
665   
666   myEnforcedTableWidget = new QTableWidget(myEnfGroup);
667   myEnforcedTableWidget->setMinimumWidth(300);
668   myEnforcedTableWidget->setRowCount( 0 );
669   myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS );
670   myEnforcedTableWidget->setSortingEnabled(true);
671   myEnforcedTableWidget->setHorizontalHeaderLabels
672     ( QStringList()
673       << tr( "GHS3D_ENF_NAME_COLUMN" ) << tr( "GHS3D_ENF_VER_X_COLUMN" )
674       << tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" )
675       << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN")
676       << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_ENF_GROUP_COLUMN" ));
677   myEnforcedTableWidget->verticalHeader()->hide();
678   myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true);
679   myEnforcedTableWidget->setAlternatingRowColors(true);
680   myEnforcedTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
681   myEnforcedTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
682   myEnforcedTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
683
684   myEnforcedTableWidget->resizeColumnsToContents();
685   myEnforcedTableWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
686   myEnforcedTableWidget->hideColumn(ENF_VER_COMPOUND_COLUMN);
687   
688   myEnforcedTableWidget->setItemDelegate(new EnforcedVertexTableWidgetDelegate());
689   
690   // VERTEX SELECTION
691   TColStd_MapOfInteger shapeTypes;
692   shapeTypes.Add( TopAbs_VERTEX );
693   shapeTypes.Add( TopAbs_COMPOUND );
694
695   SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes);
696   myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true);
697   myEnfVertexWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_VERTEX"), "QLineEdit { color: grey }");
698   
699   QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_X_LABEL" ), myEnfGroup );
700   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
701   myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
702   QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Y_LABEL" ), myEnfGroup );
703   myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
704   myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
705   QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Z_LABEL" ), myEnfGroup );
706   myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
707   myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
708   QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_SIZE_LABEL" ), myEnfGroup );
709   mySizeValue = new SMESHGUI_SpinBox(myEnfGroup);
710   mySizeValue->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
711
712   QLabel* myGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfGroup );
713   myGroupName = new QLineEdit(myEnfGroup);
714
715   addVertexButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfGroup);
716   addVertexButton->setEnabled(false);
717   removeVertexButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfGroup);
718
719   anEnfLayout->addWidget(myEnforcedTableWidget,     ENF_VER_VERTEX, 0, ENF_VER_NB_LINES, 1);
720   
721   QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
722   anEnfLayout2->addWidget(myEnfVertexWdg,           ENF_VER_VERTEX, 0, 1, 2);
723   anEnfLayout2->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 0, 1, 1);
724   anEnfLayout2->addWidget(myXCoord,                 ENF_VER_X_COORD, 1, 1, 1);
725   anEnfLayout2->addWidget(myYCoordLabel,            ENF_VER_Y_COORD, 0, 1, 1);
726   anEnfLayout2->addWidget(myYCoord,                 ENF_VER_Y_COORD, 1, 1, 1);
727   anEnfLayout2->addWidget(myZCoordLabel,            ENF_VER_Z_COORD, 0, 1, 1);
728   anEnfLayout2->addWidget(myZCoord,                 ENF_VER_Z_COORD, 1, 1, 1);
729   anEnfLayout2->addWidget(mySizeLabel,              ENF_VER_SIZE, 0, 1, 1);
730   anEnfLayout2->addWidget(mySizeValue,              ENF_VER_SIZE, 1, 1, 1);
731   anEnfLayout2->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 0, 1, 1);
732   anEnfLayout2->addWidget(myGroupName,              ENF_VER_GROUP, 1, 1, 1);
733   anEnfLayout2->addWidget(addVertexButton,          ENF_VER_BTN, 0, 1, 1);
734   anEnfLayout2->addWidget(removeVertexButton,       ENF_VER_BTN, 1, 1, 1);
735   anEnfLayout2->setRowStretch(ENF_VER_NB_LINES, 1);
736   
737   anEnfLayout->addLayout(anEnfLayout2,              ENF_VER_VERTEX, 1,ENF_VER_NB_LINES, 1);
738   anEnfLayout->setRowStretch(ENF_VER_VERTEX, 10);
739   
740
741   // Enforced meshes parameters
742   myEnfMeshGroup = new QWidget();
743   QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup);
744   
745   myEnforcedMeshTableWidget = new QTableWidget(myEnfGroup);
746   myEnforcedMeshTableWidget->setRowCount( 0 );
747   myEnforcedMeshTableWidget->setColumnCount( ENF_MESH_NB_COLUMNS );
748   myEnforcedMeshTableWidget->setSortingEnabled(true);
749   myEnforcedMeshTableWidget->verticalHeader()->hide();
750   QStringList enforcedMeshHeaders;
751   enforcedMeshHeaders << tr( "GHS3D_ENF_NAME_COLUMN" ) 
752                       << tr( "GHS3D_ENF_ENTRY_COLUMN" ) 
753                       << tr( "GHS3D_ENF_MESH_CONSTRAINT_COLUMN" ) 
754                       << tr( "GHS3D_ENF_GROUP_COLUMN" );
755   myEnforcedMeshTableWidget->setHorizontalHeaderLabels(enforcedMeshHeaders);
756   myEnforcedMeshTableWidget->horizontalHeader()->setStretchLastSection(true);
757   myEnforcedMeshTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
758
759   myEnforcedMeshTableWidget->setAlternatingRowColors(true);
760   myEnforcedMeshTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
761   myEnforcedMeshTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
762   myEnforcedMeshTableWidget->resizeColumnsToContents();
763   myEnforcedMeshTableWidget->hideColumn(ENF_MESH_ENTRY_COLUMN);
764   
765   myEnforcedMeshTableWidget->setItemDelegate(new EnforcedMeshTableWidgetDelegate());
766   
767   myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( SMESH::IDSOURCE, myEnfMeshGroup, /*multiSel=*/true);
768   myEnfMeshWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_MESH"), "QLineEdit { color: grey }");
769   
770   myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
771   
772   QLabel* myMeshConstraintLabel = new QLabel( tr( "GHS3D_ENF_MESH_CONSTRAINT_LABEL" ), myEnfMeshGroup );
773   myEnfMeshConstraint = new QComboBox(myEnfMeshGroup);
774   myEnfMeshConstraint->insertItems(0,myEnfMeshConstraintLabels);
775   myEnfMeshConstraint->setEditable(false);
776   myEnfMeshConstraint->setCurrentIndex(0);
777
778   QLabel* myMeshGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfMeshGroup );
779   myMeshGroupName = new QLineEdit(myEnfMeshGroup);
780
781   addEnfMeshButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfMeshGroup);
782   removeEnfMeshButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfMeshGroup);
783   
784   anEnfMeshLayout->addWidget(myEnforcedMeshTableWidget, ENF_MESH_MESH, 0, ENF_MESH_NB_LINES , 1);
785   
786   QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup);
787   anEnfMeshLayout2->addWidget(myEnfMeshWdg,             ENF_MESH_MESH, 0, 1, 2);
788   anEnfMeshLayout2->addWidget(myMeshConstraintLabel,    ENF_MESH_CONSTRAINT, 0, 1, 1);
789   anEnfMeshLayout2->addWidget(myEnfMeshConstraint,      ENF_MESH_CONSTRAINT, 1, 1, 1);
790   anEnfMeshLayout2->addWidget(myMeshGroupNameLabel,     ENF_MESH_GROUP, 0, 1, 1);
791   anEnfMeshLayout2->addWidget(myMeshGroupName,          ENF_MESH_GROUP, 1, 1, 1);
792   anEnfMeshLayout2->addWidget(addEnfMeshButton,         ENF_MESH_BTN, 0, 1, 1);
793   anEnfMeshLayout2->addWidget(removeEnfMeshButton,      ENF_MESH_BTN, 1, 1, 1);
794   anEnfMeshLayout2->setRowStretch(ENF_MESH_NB_LINES, 1);
795   
796   anEnfMeshLayout->addLayout(anEnfMeshLayout2,          ENF_MESH_MESH, 1, ENF_MESH_NB_LINES, 1);
797   anEnfMeshLayout->setRowStretch(ENF_MESH_MESH, 10);
798   
799   // add tabs
800   tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
801   tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
802   if ( !isOptimization() )
803   {
804     tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
805     tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "GHS3D_ENFORCED_MESHES" ) );
806   }
807   tab->setCurrentIndex( STD_TAB );
808
809   connect( myAdvWidget->maxMemoryCheck,             SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
810   connect( myAdvWidget->initialMemoryCheck,         SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
811   connect( myAdvWidget->logInFileCheck,             SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
812   connect( myAdvWidget->keepWorkingFilesCheck,      SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
813   connect( myAdvWidget->workingDirectoryPushButton, SIGNAL( clicked() ),       this, SLOT( onDirBtnClicked() ) );
814   connect( myAdvWidget->addBtn,                     SIGNAL( clicked() ),       this, SLOT( onAddOption() ) );
815   
816   connect( myEnforcedTableWidget,   SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( synchronizeCoords() ) );
817   connect( myEnforcedTableWidget,   SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
818   connect( myEnforcedTableWidget,   SIGNAL( itemSelectionChanged() ),         this, SLOT( synchronizeCoords() ) );
819   connect( addVertexButton,         SIGNAL( clicked()),                       this, SLOT( onAddEnforcedVertex() ) );
820   connect( removeVertexButton,      SIGNAL( clicked()),                       this, SLOT( onRemoveEnforcedVertex() ) );
821   connect( myEnfVertexWdg,          SIGNAL( contentModified()),               this, SLOT( onSelectEnforcedVertex() ) );
822   connect( myEnfVertexWdg,          SIGNAL( contentModified()),              this,  SLOT( checkVertexIsDefined() ) );
823   connect( myXCoord,                SIGNAL( textChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
824   connect( myYCoord,                SIGNAL( textChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
825   connect( myZCoord,                SIGNAL( textChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
826   connect( mySizeValue,             SIGNAL( textChanged(const QString&) ),   this,  SLOT( checkVertexIsDefined() ) );
827   connect( myXCoord,                SIGNAL( valueChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
828   connect( myYCoord,                SIGNAL( valueChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
829   connect( myZCoord,                SIGNAL( valueChanged(const QString&) ),   this,  SLOT( clearEnfVertexSelection() ) );
830   connect( mySizeValue,             SIGNAL( valueChanged(const QString&) ),   this,  SLOT( checkVertexIsDefined() ) );
831   connect( this,                    SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
832   
833   connect( addEnfMeshButton,        SIGNAL( clicked()),                       this, SLOT( onAddEnforcedMesh() ) );
834   connect( removeEnfMeshButton,     SIGNAL( clicked()),                       this, SLOT( onRemoveEnforcedMesh() ) );
835   
836   return fr;
837 }
838
839 /** 
840  * This method checks if an enforced vertex is defined;
841  **/
842 void GHS3DPluginGUI_HypothesisCreator::clearEnfVertexSelection()
843 {
844   if (myEnfVertexWdg->NbObjects() != 0) {
845     disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
846     disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
847     myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
848     connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
849     connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
850   }
851   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
852   that->checkVertexIsDefined();
853 }
854
855 /** 
856  * This method checks if an enforced vertex is defined;
857  **/
858 void GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined()
859 {
860   bool enfVertexIsDefined = false;
861   enfVertexIsDefined = (!mySizeValue->GetString().isEmpty() &&
862                         (!myEnfVertexWdg->NbObjects() == 0 ||
863                          (myEnfVertexWdg->NbObjects() == 0 && !myXCoord->GetString().isEmpty()
864                           && !myYCoord->GetString().isEmpty()
865                           && !myZCoord->GetString().isEmpty())));
866   emit vertexDefined(enfVertexIsDefined);
867 }
868
869 /** 
870  * This method checks if an enforced mesh is defined;
871  **/
872 void GHS3DPluginGUI_HypothesisCreator::checkEnfMeshIsDefined()
873 {
874   emit enfMeshDefined( myEnfVertexWdg->NbObjects() != 0);
875 }
876
877 /** 
878  * This method resets the content of the X, Y, Z, size and GroupName widgets;
879  **/
880 void GHS3DPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
881 {
882   myXCoord->setCleared(true);
883   myYCoord->setCleared(true);
884   myZCoord->setCleared(true);
885   myXCoord->setText("");
886   myYCoord->setText("");
887   myZCoord->setText("");
888   addVertexButton->setEnabled(false);
889 }
890
891 /** GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item)
892     This method updates the tooltip of a modified item. The QLineEdit widgets content
893     is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
894 */
895 void GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item)
896 {
897   int row = myEnforcedTableWidget->row(item);
898       
899   QVariant vertexName = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole);
900   QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
901   QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
902   QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
903   QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
904   QVariant entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
905   QString groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole).toString();
906   
907   clearEnforcedVertexWidgets();
908   
909   if ( !x.isNull() || !entry.isNull()) {
910     QString toolTip = vertexName.toString();
911     toolTip += QString("(");
912     if (entry.isNull() || (!entry.isNull() && entry.toString() == "")) {
913       toolTip += x.toString();
914       toolTip += QString(", ") + y.toString();
915       toolTip += QString(", ") + z.toString();
916     }
917     else
918       toolTip += entry.toString();
919     toolTip += QString(")");
920     
921     if (!size.isNull())
922       toolTip += QString("=") + size.toString();
923     
924     if (!groupName.isEmpty())
925       toolTip += QString(" [") + groupName + QString("]");
926
927     for (int col=0;col<ENF_VER_NB_COLUMNS;col++)
928       myEnforcedTableWidget->item(row,col)->setToolTip(toolTip);
929
930     if (!x.isNull()) {
931       disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
932       disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
933       disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
934       myXCoord->SetValue(x.toDouble());
935       myYCoord->SetValue(y.toDouble());
936       myZCoord->SetValue(z.toDouble());
937       connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
938       connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
939       connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
940     }
941     if (!size.isNull())
942       mySizeValue->SetValue(size.toDouble());
943     
944     if (!groupName.isEmpty())
945       myGroupName->setText(groupName);
946   }
947 }
948
949 void GHS3DPluginGUI_HypothesisCreator::onSelectEnforcedVertex()
950 {
951   size_t nbSelEnfVertex = myEnfVertexWdg->NbObjects();
952   clearEnforcedVertexWidgets();
953   if (nbSelEnfVertex == 1)
954   {
955     if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
956       return ;
957
958     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
959     if (myEnfVertex == GEOM::GEOM_Object::_nil())
960       return;
961     if (myEnfVertex->GetShapeType() == GEOM::VERTEX)
962     {
963       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( );
964       if (CORBA::is_nil(measureOp))
965         return;
966
967       CORBA::Double x,y,z;
968       measureOp->PointCoordinates (myEnfVertex, x, y, z);
969       if ( measureOp->IsDone() )
970       {
971         disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
972         disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
973         disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
974         myXCoord->SetValue(x);
975         myYCoord->SetValue(y);
976         myZCoord->SetValue(z);
977         connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
978         connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
979         connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
980       }
981     }
982   }
983 }
984
985 /** GHS3DPluginGUI_HypothesisCreator::synchronizeCoords()
986     This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
987     of the enforced vertex clicked in the tree widget.
988 */
989 void GHS3DPluginGUI_HypothesisCreator::synchronizeCoords()
990 {
991   clearEnforcedVertexWidgets();
992   QList<QTableWidgetItem *> items = myEnforcedTableWidget->selectedItems();
993   disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
994   if (! items.isEmpty()) {
995     QTableWidgetItem *item;
996     int row;
997     QVariant entry;
998     if (items.size() == 1) {
999       item = items[0];
1000       row = myEnforcedTableWidget->row(item);
1001       QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
1002       QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
1003       QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
1004       QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
1005       entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
1006       if (!entry.isNull()) {
1007         SMESH::string_array_var objIds = new SMESH::string_array;
1008         objIds->length(1);
1009         objIds[0] = entry.toString().toStdString().c_str();
1010         myEnfVertexWdg->SetObjects(objIds);
1011       }
1012       else {
1013         myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1014       }
1015       QVariant group = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole);
1016       if (!x.isNull()/* && entry.isNull()*/) {
1017         //         disconnect( myXCoord, SIGNAL( textChanged(const QString &)), this, SLOT( onSelectEnforcedVertex() ) );
1018         disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1019         disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1020         disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1021         myXCoord->SetValue(x.toDouble());
1022         myYCoord->SetValue(y.toDouble());
1023         myZCoord->SetValue(z.toDouble());
1024         connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1025         connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1026         connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
1027       }
1028       if (!size.isNull())
1029         mySizeValue->SetValue(size.toDouble());
1030       
1031       if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1032         myGroupName->setText(group.toString());
1033     }
1034     else {
1035       QList<QString> entryList;
1036       for (int i = 0; i < items.size(); ++i) {
1037         item = items[i];
1038         row = myEnforcedTableWidget->row(item);
1039         entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
1040         if (!entry.isNull())
1041           entryList << entry.toString();
1042       }
1043       if (entryList.size() > 0) {
1044         SMESH::string_array_var objIds = new SMESH::string_array;
1045         objIds->length(entryList.size());
1046         for (int i = 0; i < entryList.size() ; i++)
1047           objIds[i] = entryList.at(i).toStdString().c_str();
1048         myEnfVertexWdg->SetObjects(objIds);
1049       }
1050       else {
1051         myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1052       }
1053     }
1054   }
1055   else {
1056     myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1057   }
1058   connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
1059   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1060   that->checkVertexIsDefined();
1061 }
1062
1063 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh( meshName, geomEntry, elemType, size, groupName)
1064     This method adds in the tree widget an enforced mesh from mesh, submesh or group with optionally size and and groupName.
1065 */
1066 void GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh(std::string name,
1067                                                        std::string entry,
1068                                                        int elementType,
1069                                                        std::string groupName)
1070 {
1071   bool okToCreate = true;
1072   QString itemEntry = "";
1073   int itemElementType = 0;
1074   int rowCount = myEnforcedMeshTableWidget->rowCount();
1075   bool allColumns = true;
1076   for (int row = 0;row<rowCount;row++) {
1077     for (int col = 0 ; col < ENF_MESH_NB_COLUMNS ; col++) {
1078       if (col == ENF_MESH_CONSTRAINT_COLUMN){
1079         if (qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col)) == 0) {
1080           allColumns = false;
1081           break;
1082         }
1083       }
1084       else if (myEnforcedMeshTableWidget->item(row, col) == 0) {
1085         allColumns = false;
1086         break;
1087       }
1088       if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1089         QComboBox* itemComboBox = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col));
1090         itemElementType = itemComboBox->currentIndex();
1091       }
1092       else if (col == ENF_MESH_ENTRY_COLUMN)
1093         itemEntry = myEnforcedMeshTableWidget->item(row, col)->data(Qt::EditRole).toString();
1094     }
1095     
1096     if (!allColumns)
1097       break;
1098   
1099     if (itemEntry == QString(entry.c_str()) && itemElementType == elementType) { 
1100       okToCreate = false;
1101       break;
1102     } // if
1103   } // for
1104
1105     
1106   if (!okToCreate)
1107     return;
1108   
1109   myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1110   myEnforcedMeshTableWidget->setSortingEnabled(false);
1111   
1112   for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1113     if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1114       QComboBox* comboBox = new QComboBox();
1115       QPalette pal = comboBox->palette();
1116       pal.setColor(QPalette::Button, Qt::white);
1117       comboBox->setPalette(pal);
1118       comboBox->insertItems(0,myEnfMeshConstraintLabels);
1119       comboBox->setEditable(false);
1120       comboBox->setCurrentIndex(elementType);
1121       myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1122     }
1123     else {
1124       QTableWidgetItem* item = new QTableWidgetItem();
1125       item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1126       switch (col) {
1127       case ENF_MESH_NAME_COLUMN:
1128         item->setData( 0, name.c_str() );
1129         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1130         myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1131         break;
1132       case ENF_MESH_ENTRY_COLUMN:
1133         item->setData( 0, entry.c_str() );
1134         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1135         myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1136         break;
1137       case ENF_MESH_GROUP_COLUMN:
1138         item->setData( 0, groupName.c_str() );
1139         myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1140         break;
1141       default:
1142         break;
1143       }
1144     }
1145   }
1146   myEnforcedMeshTableWidget->setSortingEnabled(true);
1147 }
1148
1149 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex( x, y, z, size, vertexName, geomEntry, groupName)
1150     This method adds in the tree widget an enforced vertex with given size and coords (x,y,z) or GEOM vertex or compound and with optionally groupName.
1151 */
1152 void GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z, double size, std::string vertexName, std::string geomEntry, std::string groupName, bool isCompound)
1153 {
1154   myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1155   bool okToCreate = true;
1156   double itemX=0.,itemY=0.,itemZ=0.,itemSize = 0;
1157   QString itemEntry, itemGroupName = QString("");
1158   //   bool itemIsCompound;
1159   int rowCount = myEnforcedTableWidget->rowCount();
1160   QVariant data;
1161   bool allColumns;
1162   for (int row = 0;row<rowCount;row++) {
1163     allColumns = true;
1164     for (int col = 0 ; col < ENF_VER_NB_COLUMNS ; col++) {
1165       if (myEnforcedTableWidget->item(row, col) == 0) {
1166         allColumns = false;
1167         break;
1168       }
1169       
1170       data = myEnforcedTableWidget->item(row, col)->data(Qt::EditRole);
1171       if (!data.isNull()) {
1172         switch (col) {
1173         case ENF_VER_GROUP_COLUMN:
1174           itemGroupName = data.toString();
1175           break;
1176         case ENF_VER_ENTRY_COLUMN:
1177           itemEntry = data.toString();
1178           break;
1179         case ENF_VER_X_COLUMN:
1180           itemX = data.toDouble();
1181           break;
1182         case ENF_VER_Y_COLUMN:
1183           itemY = data.toDouble();
1184           break;
1185         case ENF_VER_Z_COLUMN:
1186           itemZ = data.toDouble();
1187           break;
1188         case ENF_VER_SIZE_COLUMN:
1189           itemSize = data.toDouble();
1190           break;
1191         default:
1192           break;
1193         }
1194       }
1195     }
1196     
1197     if (!allColumns)
1198       break;
1199
1200
1201     if (( !isCompound && ((itemX == x) && (itemY == y) && (itemZ == z))) ||
1202         ( !itemEntry.isEmpty() && ( itemEntry == geomEntry.c_str() )))
1203     {
1204       // update size
1205       if (itemSize != size) {
1206         myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size));
1207       }
1208       // update group name
1209       if (itemGroupName.toStdString() != groupName) {
1210         myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
1211       }
1212       okToCreate = false;
1213       break;
1214     } // if
1215   } // for
1216   if (!okToCreate) {
1217     if (geomEntry.empty()) {
1218     }
1219     else {
1220     }
1221     return;
1222   }
1223     
1224   int vertexIndex=0;
1225   int indexRef = -1;
1226   QString myVertexName;
1227   while(indexRef != vertexIndex) {
1228     indexRef = vertexIndex;
1229     if (vertexName.empty())
1230       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1231     else
1232       myVertexName = QString(vertexName.c_str());
1233
1234     for (int row = 0;row<rowCount;row++) {
1235       QString name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString();
1236       if (myVertexName == name) {
1237         vertexIndex++;
1238         break;
1239       }
1240     }
1241   }
1242   
1243   myEnforcedTableWidget->setRowCount(rowCount+1);
1244   myEnforcedTableWidget->setSortingEnabled(false);
1245   for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1246     QTableWidgetItem* item = new QTableWidgetItem();
1247     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1248     switch (col) {
1249     case ENF_VER_NAME_COLUMN:
1250       item->setData( Qt::EditRole, myVertexName );
1251       if (!geomEntry.empty()) {
1252         if (isCompound)
1253           item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1254         else
1255           item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1256       }
1257       break;
1258     case ENF_VER_X_COLUMN:
1259       if (!isCompound)
1260         item->setData( 0, QVariant(x) );
1261       break;
1262     case ENF_VER_Y_COLUMN:
1263       if (!isCompound)
1264         item->setData( 0, QVariant(y) );
1265       break;
1266     case ENF_VER_Z_COLUMN:
1267       if (!isCompound)
1268         item->setData( 0, QVariant(z) );
1269       break;
1270     case ENF_VER_SIZE_COLUMN:
1271       item->setData( 0, QVariant(size) );
1272       break;
1273     case ENF_VER_ENTRY_COLUMN:
1274       if (!geomEntry.empty())
1275         item->setData( 0, QString(geomEntry.c_str()) );
1276       break;
1277     case ENF_VER_COMPOUND_COLUMN:
1278       item->setData( Qt::CheckStateRole, isCompound );
1279       item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1280       break;
1281     case ENF_VER_GROUP_COLUMN:
1282       if (!groupName.empty())
1283         item->setData( 0, QString(groupName.c_str()) );
1284       break;
1285     default:
1286       break;
1287     }
1288     
1289     myEnforcedTableWidget->setItem(rowCount,col,item);
1290   }
1291
1292   connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this,  SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1293   
1294   myEnforcedTableWidget->setSortingEnabled(true);
1295   //   myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1296   updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1297 }
1298
1299 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1300     This method is called when a item is added into the enforced meshes tree widget
1301 */
1302 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1303 {
1304   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1305   
1306   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1307   myEnfMeshWdg->deactivateSelection();
1308
1309   for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1310     myEnforcedMeshTableWidget->resizeColumnToContents(column);
1311
1312   // Vertex selection
1313   size_t selEnfMeshes = myEnfMeshWdg->NbObjects();
1314   if (selEnfMeshes == 0)
1315     return;
1316
1317   std::string groupName = myMeshGroupName->text().simplified().toStdString();
1318   
1319   int elementType = myEnfMeshConstraint->currentIndex();
1320   
1321   
1322   _PTR(Study) aStudy = SMESH::getStudy();
1323   _PTR(SObject) aSObj;
1324   QString meshEntry = myEnfMeshWdg->GetValue();
1325   
1326   if (selEnfMeshes == 1)
1327   {
1328     aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str());
1329     CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj);
1330     if (!CORBA::is_nil(anObj)) {
1331       addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1332     }
1333   }
1334   else
1335   {
1336     QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts);
1337     QStringListIterator meshEntriesIt (meshEntries);
1338     while (meshEntriesIt.hasNext()) {
1339       aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str());
1340       CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj);
1341       if (!CORBA::is_nil(anObj)) {
1342         addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1343       }
1344     }
1345   }
1346
1347   myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil());
1348   
1349   for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1350     myEnforcedMeshTableWidget->resizeColumnToContents(column);  
1351 }
1352
1353
1354 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1355     This method is called when a item is added into the enforced vertices tree widget
1356 */
1357 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1358 {
1359   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1360   
1361   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1362   myEnfVertexWdg->deactivateSelection();
1363
1364   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1365     myEnforcedTableWidget->resizeColumnToContents(column);
1366
1367   // Vertex selection
1368   size_t selEnfVertex = myEnfVertexWdg->NbObjects();
1369   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1370   if ((selEnfVertex == 0) && coordsEmpty)
1371     return;
1372
1373   std::string groupName = myGroupName->text().simplified().toStdString();
1374
1375   double size = mySizeValue->GetValue();
1376   
1377   if (selEnfVertex <= 1)
1378   {
1379     double x = 0, y = 0, z=0;
1380     if (myXCoord->GetString() != "") {
1381       x = myXCoord->GetValue();
1382       y = myYCoord->GetValue();
1383       z = myZCoord->GetValue();
1384     }
1385     if (selEnfVertex == 1) {
1386       myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1387       std::string entry = "", name = "";
1388       bool isCompound = false;
1389       if ( !myEnfVertex->_is_nil() ) {
1390         entry = SMESH::toStdStr( myEnfVertex->GetStudyEntry() );
1391         name  = SMESH::toStdStr( myEnfVertex->GetName() );
1392         isCompound = ( myEnfVertex->GetShapeType() == GEOM::COMPOUND );
1393       }
1394       addEnforcedVertex(x, y, z, size, name, entry, groupName, isCompound);
1395     }
1396     else {
1397       addEnforcedVertex(x, y, z, size, "", "", groupName);
1398     }
1399   }
1400   else
1401   {
1402     if ( CORBA::is_nil(getGeomEngine()))
1403       return;
1404
1405     GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( );
1406     if (CORBA::is_nil(measureOp))
1407       return;
1408
1409     CORBA::Double x = 0, y = 0,z = 0;
1410     for ( size_t j = 0 ; j < selEnfVertex ; j++)
1411     {
1412       myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1413       if (myEnfVertex == GEOM::GEOM_Object::_nil())
1414         continue;
1415       if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1416         measureOp->PointCoordinates (myEnfVertex, x, y, z);
1417         if ( measureOp->IsDone() )
1418           addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1419       } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1420         addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true);
1421       }
1422     }
1423   }
1424
1425   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1426   
1427   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1428     myEnforcedTableWidget->resizeColumnToContents(column);  
1429 }
1430
1431 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1432     This method is called when a item is removed from the enforced meshes tree widget
1433 */
1434 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1435 {
1436   QList<int> selectedRows;
1437   QList<QTableWidgetItem *> selectedItems = myEnforcedMeshTableWidget->selectedItems();
1438   QTableWidgetItem* item;
1439   int row;
1440   foreach( item, selectedItems ) {
1441     row = item->row();
1442     if (!selectedRows.contains( row ) )
1443       selectedRows.append(row);
1444   }
1445
1446   qSort( selectedRows );
1447   QListIterator<int> it( selectedRows );
1448   it.toBack();
1449   while ( it.hasPrevious() ) {
1450     row = it.previous();
1451     myEnforcedMeshTableWidget->removeRow(row );
1452   }
1453
1454   myEnforcedMeshTableWidget->selectionModel()->clearSelection();
1455 }
1456
1457 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1458     This method is called when a item is removed from the enforced vertices tree widget
1459 */
1460 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1461 {
1462   QList<int> selectedRows;
1463   QList<QTableWidgetItem *> selectedItems = myEnforcedTableWidget->selectedItems();
1464   QTableWidgetItem* item;
1465   int row;
1466   foreach( item, selectedItems ) {
1467     row = item->row();
1468     if (!selectedRows.contains( row ) )
1469       selectedRows.append(row);
1470   }
1471   
1472   qSort( selectedRows );
1473   QListIterator<int> it( selectedRows );
1474   it.toBack();
1475   while ( it.hasPrevious() ) {
1476     row = it.previous();
1477     myEnforcedTableWidget->removeRow(row );
1478   }
1479
1480   myEnforcedTableWidget->selectionModel()->clearSelection();
1481 }
1482
1483 void GHS3DPluginGUI_HypothesisCreator::onToMeshHoles(bool /*isOn*/)
1484 {
1485   // myToMakeGroupsOfDomains->setEnabled( isOn );
1486   // if ( !isOn )
1487   //   myToMakeGroupsOfDomains->setChecked( false );
1488 }
1489
1490 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
1491 {
1492   QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myAdvWidget->workingDirectoryLineEdit->text(), QString() );
1493   if ( !dir.isEmpty() )
1494     myAdvWidget->workingDirectoryLineEdit->setText( dir );
1495 }
1496
1497 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
1498 {
1499   //myToMakeGroupsOfDomains->setEnabled( myToMeshHolesCheck->isChecked() );
1500   myAdvWidget->maxMemorySpin->setEnabled( myAdvWidget->maxMemoryCheck->isChecked() );
1501   //myAdvWidget->initialMemoryCheck->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1502   myAdvWidget->initialMemorySpin->setEnabled( myAdvWidget->initialMemoryCheck->isChecked() /*&& !myAdvWidget->boundaryRecoveryCheck->isChecked()*/ );
1503   //myOptimizationLevelCombo->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1504   if ( sender() == myAdvWidget->logInFileCheck ||
1505        sender() == myAdvWidget->keepWorkingFilesCheck )
1506   {
1507     bool logFileRemovable = ( myAdvWidget->logInFileCheck->isChecked() &&
1508                               !myAdvWidget->keepWorkingFilesCheck->isChecked() );
1509     myAdvWidget->removeLogOnSuccessCheck->setEnabled( logFileRemovable );
1510   }
1511 }
1512
1513 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
1514 {
1515   if ( !QFileInfo( myAdvWidget->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
1516     SUIT_MessageBox::warning( dlg(),
1517                               tr( "SMESH_WRN_WARNING" ),
1518                               tr( "GHS3D_PERMISSION_DENIED" ) );
1519     return false;
1520   }
1521
1522   GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1523     GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
1524
1525   myAdvWidget->myOptionTable->setFocus();
1526   QApplication::instance()->processEvents();
1527
1528   QString name, value;
1529   bool isDefault, ok = true;
1530   int iRow = 0, nbRows = myAdvWidget->myOptionTable->topLevelItemCount();
1531   for ( ; iRow < nbRows; ++iRow )
1532   {
1533     QTreeWidgetItem* row = myAdvWidget->myOptionTable->topLevelItem( iRow );
1534     myAdvWidget->GetOptionAndValue( row, name, value, isDefault );
1535
1536     if ( name.simplified().isEmpty() )
1537       continue; // invalid custom option
1538
1539     if ( isDefault ) // not selected option
1540       value.clear();
1541
1542     try {
1543       h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
1544     }
1545     catch ( const SALOME::SALOME_Exception& ex )
1546     {
1547       msg = ex.details.text.in();
1548       ok = false;
1549       break;
1550     }
1551   }
1552
1553   if ( !ok )
1554   {
1555     h->SetOptionValues( myOptions ); // restore values
1556   }
1557
1558   return ok;
1559 }
1560
1561 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
1562 {
1563   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1564   GHS3DHypothesisData data;
1565   readParamsFromHypo( data );
1566
1567   if ( myName )
1568   {
1569     myName->setText( data.myName );
1570
1571     int width = QFontMetrics( myName->font() ).width( data.myName );
1572     QGridLayout* aStdLayout = (QGridLayout*) myStdGroup->layout();
1573     aStdLayout->setColumnMinimumWidth( 1, width + 10 );
1574   }
1575   myToMeshHolesCheck                          ->setChecked    ( data.myToMeshHoles );
1576   myToMakeGroupsOfDomains                     ->setChecked    ( data.myToMakeGroupsOfDomains );
1577
1578   if ( data.myAlgorithm == GHS3DPlugin_Hypothesis::MGTetraHPC && data.myOptimizationLevel == GHS3DPlugin_Hypothesis::StandardPlus /*not implemented by MGTetraHPC*/ )
1579     myOptimizationLevelCombo                    ->setCurrentIndex( GHS3DPlugin_Hypothesis::None );
1580   else
1581     myOptimizationLevelCombo                    ->setCurrentIndex( data.myOptimizationLevel );
1582   
1583   if ( myOptimizationCombo ) // optimizer
1584   {
1585     myOptimizationCombo                         ->setCurrentIndex( data.myOptimization );
1586     mySplitOverConstrainedCombo                 ->setCurrentIndex( data.mySplitOverConstrained );
1587     myPThreadsModeCombo                         ->setCurrentIndex( data.myPThreadsMode );
1588     myNumberOfThreadsSpin                       ->setValue      ( data.myNumberOfThreads );
1589     mySmoothOffSliversCheck                     ->setChecked    ( data.mySmoothOffSlivers );
1590     myCreateNewNodesCheck                       ->setChecked    ( data.myToCreateNewNodes );
1591   }
1592   else
1593   {
1594     myRadioBottomGroup  ->button( data.myAlgorithm )->setChecked( true );
1595     myMinSizeSpin       ->setValue( data.myMinSize );
1596     myMinSizeCheck      ->setChecked( data.myUseMinSize );
1597     myMaxSizeSpin       ->setValue( data.myMaxSize );
1598     myMaxSizeCheck      ->setChecked( data.myUseMaxSize );
1599     myGradationCheck    ->setChecked( data.myUseGradation );
1600     myGradationSpin     ->setValue( data.myUseGradation ? data.myGradation : GHS3DPlugin_Hypothesis::DefaultGradation() );
1601     myUseProximityGroup ->setChecked( data.myUseProximity );
1602     myNbProximityLayers ->setValue( data.myNbProximityLayers );
1603     myNumOfThreadsCheck ->setChecked( data.myUseNumOfThreads );
1604     myNumOfThreadsSpin  ->setValue( data.myNumOfThreads );    
1605     myPthreadMode       ->setCurrentIndex( data.myPthreadMode );
1606     myParallelMode      ->setCurrentIndex( data.myParallelMode );    
1607   }
1608   myAdvWidget->maxMemoryCheck                 ->setChecked    ( data.myMaximumMemory > 0 );
1609   myAdvWidget->maxMemorySpin                  ->setValue
1610     ( qMax( data.myMaximumMemory, (float)myAdvWidget->maxMemorySpin->minimum() ));
1611   myAdvWidget->initialMemoryCheck             ->setChecked    ( data.myInitialMemory > 0 );
1612   myAdvWidget->initialMemorySpin              ->setValue
1613     ( qMax( data.myInitialMemory, (float)myAdvWidget->initialMemorySpin->minimum() ));
1614   myAdvWidget->workingDirectoryLineEdit       ->setText       ( data.myWorkingDir );
1615   myAdvWidget->keepWorkingFilesCheck           ->setChecked    ( data.myKeepFiles );
1616   myAdvWidget->verboseLevelSpin               ->setValue      ( data.myVerboseLevel );
1617   myAdvWidget->logInFileCheck                 ->setChecked    ( !data.myLogInStandardOutput );
1618   myAdvWidget->removeLogOnSuccessCheck        ->setChecked    ( data.myRemoveLogOnSuccess );
1619
1620   if ( myOptions.operator->() ) {
1621     for ( int i = 0, nb = myOptions->length(); i < nb; ++i )
1622       myAdvWidget->AddOption( that->myOptions[i].in() );
1623   }
1624   if ( myCustomOptions.operator->() ) {
1625     for ( int i = 0, nb = myCustomOptions->length(); i < nb; ++i )
1626       myAdvWidget->AddOption( that->myCustomOptions[i].in() );
1627   }
1628   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1629   myAdvWidget->EnableAdvancedOptions( data.myAlgorithm == GHS3DPlugin_Hypothesis::MGTetra );
1630
1631   TEnfVertexList::const_iterator it;
1632   int rowCount = 0;
1633   myEnforcedTableWidget->clearContents();
1634   myEnforcedTableWidget->setSortingEnabled(false);
1635   myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1636   for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
1637   {
1638     TEnfVertex* enfVertex = (*it);
1639     myEnforcedTableWidget->setRowCount(rowCount+1);
1640
1641     for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1642       QTableWidgetItem* item = new QTableWidgetItem();
1643       item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1644       switch (col) {
1645       case ENF_VER_NAME_COLUMN:
1646         item->setData( 0, enfVertex->name.c_str() );
1647         if (!enfVertex->geomEntry.empty()) {
1648           if (enfVertex->isCompound)
1649             item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1650           else
1651             item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1652             
1653         }
1654         break;
1655       case ENF_VER_X_COLUMN:
1656         if (!enfVertex->isCompound) {
1657           item->setData( 0, enfVertex->coords.at(0) );
1658         }
1659         break;
1660       case ENF_VER_Y_COLUMN:
1661         if (!enfVertex->isCompound) {
1662           item->setData( 0, enfVertex->coords.at(1) );
1663         }
1664         break;
1665       case ENF_VER_Z_COLUMN:
1666         if (!enfVertex->isCompound) {
1667           item->setData( 0, enfVertex->coords.at(2) );
1668         }
1669         break;
1670       case ENF_VER_SIZE_COLUMN:
1671         item->setData( 0, enfVertex->size );
1672         break;
1673       case ENF_VER_ENTRY_COLUMN:
1674         item->setData( 0, enfVertex->geomEntry.c_str() );
1675         break;
1676       case ENF_VER_COMPOUND_COLUMN:
1677         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1678         item->setData( Qt::CheckStateRole, enfVertex->isCompound );
1679         break;
1680       case ENF_VER_GROUP_COLUMN:
1681         item->setData( 0, enfVertex->groupName.c_str() );
1682         break;
1683       default:
1684         break;
1685       }
1686       
1687       myEnforcedTableWidget->setItem(rowCount,col,item);
1688     }
1689     that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1690     rowCount++;
1691   }
1692
1693   connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this,  SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1694   myEnforcedTableWidget->setSortingEnabled(true);
1695   
1696   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1697     myEnforcedTableWidget->resizeColumnToContents(column);
1698
1699   // Update Enforced meshes QTableWidget
1700   TEnfMeshList::const_iterator itMesh;
1701   rowCount = 0;
1702   myEnforcedMeshTableWidget->clearContents();
1703   myEnforcedMeshTableWidget->setSortingEnabled(false);
1704   //   myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1705   for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ )
1706   {
1707     TEnfMesh* enfMesh = (*itMesh);
1708     myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1709
1710     for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1711       if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1712         QComboBox* comboBox = new QComboBox();
1713         QPalette pal = comboBox->palette();
1714         pal.setColor(QPalette::Button, Qt::white);
1715         comboBox->setPalette(pal);
1716         comboBox->insertItems(0,myEnfMeshConstraintLabels);
1717         comboBox->setEditable(false);
1718         comboBox->setCurrentIndex(enfMesh->elementType);
1719         myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1720       }
1721       else {
1722         QTableWidgetItem* item = new QTableWidgetItem();
1723         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1724         switch (col) {
1725         case ENF_MESH_NAME_COLUMN:
1726           item->setData( 0, enfMesh->name.c_str() );
1727           item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1728           myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1729           break;
1730         case ENF_MESH_ENTRY_COLUMN:
1731           item->setData( 0, enfMesh->entry.c_str() );
1732           item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1733           myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1734           break;
1735         case ENF_MESH_GROUP_COLUMN:
1736           item->setData( 0, enfMesh->groupName.c_str() );
1737           myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1738           break;
1739         default:
1740           break;
1741         }
1742       }
1743       
1744     }
1745     rowCount++;
1746   }
1747
1748   myEnforcedMeshTableWidget->setSortingEnabled(true);
1749   
1750   for (int col=0;col<ENF_MESH_NB_COLUMNS;col++)
1751     myEnforcedMeshTableWidget->resizeColumnToContents(col);
1752   
1753   that->updateWidgets();
1754   that->checkVertexIsDefined();
1755 }
1756
1757 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
1758 {
1759   GHS3DHypothesisData data;
1760   readParamsFromWidgets( data );
1761   storeParamsToHypo( data );
1762     
1763   QString valStr = "";
1764     
1765   if ( !data.myBoundaryRecovery )
1766     valStr = " --components " + data.myToMeshHoles ? "all" : "outside_components" ;
1767     
1768   if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
1769     const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1770     valStr += " --optimisation_level ";
1771     valStr += level[ data.myOptimizationLevel ];
1772   }
1773   if ( data.myMaximumMemory > 0 ) {
1774     valStr += " --max_memory ";
1775     valStr += QString::number( data.myMaximumMemory );
1776   }
1777   if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
1778     valStr += " --automatic_memory ";
1779     valStr += QString::number( data.myInitialMemory );
1780   }
1781   valStr += " --verbose ";
1782   valStr += QString::number( data.myVerboseLevel );
1783     
1784   if ( !data.myToCreateNewNodes )
1785     valStr += " --no_internal_points";
1786     
1787   if ( data.myRemoveInitialCentralPoint )
1788     valStr += " --no_initial_central_point";
1789     
1790   // if ( data.myBoundaryRecovery )
1791   //   valStr += " -C";
1792     
1793   // if ( data.myFEMCorrection )
1794   //   valStr += " -FEM";
1795     
1796   if ( data.myGradation != 1.05 ) {
1797     valStr += " -Dcpropa=";
1798     valStr += QString::number( data.myGradation );
1799   }
1800     
1801   return valStr;
1802 }
1803
1804 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
1805 {
1806   GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1807     GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1808   GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis_var opt =
1809     GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis::_narrow( initParamsHypothesis() );
1810
1811   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1812   h_data.myName = isCreation() && data ? hypName() : "";
1813
1814   if ( !opt->_is_nil() )
1815   {
1816     h_data.myOptimization         = opt->GetOptimization();
1817     h_data.mySplitOverConstrained = opt->GetSplitOverConstrained();
1818     h_data.myPThreadsMode         = opt->GetPThreadsMode();
1819     h_data.myNumberOfThreads      = opt->GetMaximalNumberOfThreads();
1820     h_data.mySmoothOffSlivers     = opt->GetSmoothOffSlivers();
1821   }
1822   else
1823   {
1824     // avoid "Conditional jump or move depends on uninitialised value" error
1825     h_data.myOptimization         = 1;
1826     h_data.mySplitOverConstrained = 1;
1827     h_data.myPThreadsMode         = 1;
1828     h_data.myNumberOfThreads      = 1;
1829     h_data.mySmoothOffSlivers     = 1;
1830   }
1831   h_data.myAlgorithm                  = h->GetAlgorithm();
1832   h_data.myOptimizationLevel          = h->GetOptimizationLevel();
1833   h_data.myMinSize                    = h->GetMinSize();
1834   h_data.myMaxSize                    = h->GetMaxSize();
1835   this->myMinSizeDefault              = h->GetMinSizeDefault();
1836   this->myMaxSizeDefault              = h->GetMaxSizeDefault();
1837   if ( ! ( h_data.myUseMinSize        = h_data.myMinSize > 0 ))
1838     h_data.myMinSize                  = this->myMinSizeDefault;
1839   if ( ! ( h_data.myUseMaxSize        = h_data.myMaxSize > 0 ))
1840     h_data.myMaxSize                  = this->myMaxSizeDefault;
1841   h_data.myNbProximityLayers          = h->GetNbVolumeProximityLayers();
1842   h_data.myUseGradation               = h->GetGradation() != GHS3DPlugin_Hypothesis::DefaultGradation();
1843   h_data.myUseProximity               = h->GetVolumeProximity();
1844   h_data.myToMeshHoles                = h->GetToMeshHoles();
1845   h_data.myToMakeGroupsOfDomains      = h->GetToMakeGroupsOfDomains();
1846   h_data.myMaximumMemory              = h->GetMaximumMemory();
1847   h_data.myInitialMemory              = h->GetInitialMemory();
1848   h_data.myInitialMemory              = h->GetInitialMemory();
1849   h_data.myKeepFiles                  = h->GetKeepFiles();
1850   h_data.myWorkingDir                 = h->GetWorkingDirectory();
1851   h_data.myVerboseLevel               = h->GetVerboseLevel();
1852   h_data.myToCreateNewNodes           = h->GetToCreateNewNodes();
1853   //h_data.myRemoveInitialCentralPoint  = h->GetToRemoveCentralPoint();
1854   //h_data.myBoundaryRecovery           = h->GetToUseBoundaryRecoveryVersion();
1855   //h_data.myFEMCorrection              = h->GetFEMCorrection();
1856   h_data.myGradation                  = h->GetGradation();
1857   //h_data.myTextOption                 = h->GetAdvancedOption();
1858   h_data.myLogInStandardOutput        = h->GetStandardOutputLog();
1859   h_data.myRemoveLogOnSuccess         = h->GetRemoveLogOnSuccess();
1860   h_data.myUseNumOfThreads            = h->GetUseNumOfThreads();
1861   h_data.myNumOfThreads               = h->GetNumOfThreads();
1862   h_data.myPthreadMode                = h->GetPthreadMode();
1863   h_data.myParallelMode               = h->GetParallelMode();
1864
1865   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1866   that->myOptions       = h->GetOptionValues();
1867   that->myCustomOptions = h->GetAdvancedOptionValues();
1868   
1869   GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
1870   h_data.myEnforcedVertices.clear();
1871   for (CORBA::ULong i=0 ; i<vertices->length() ; i++) {
1872     TEnfVertex* myVertex = new TEnfVertex();
1873     myVertex->name = CORBA::string_dup(vertices[i].name.in());
1874     myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in());
1875     myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in());
1876     myVertex->size = vertices[i].size;
1877     myVertex->isCompound = vertices[i].isCompound;
1878     if (vertices[i].coords.length()) {
1879       for (CORBA::ULong c = 0; c < vertices[i].coords.length() ; c++)
1880         myVertex->coords.push_back(vertices[i].coords[c]);
1881     }
1882     h_data.myEnforcedVertices.insert(myVertex);
1883   }
1884   
1885   GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes();
1886   h_data.myEnforcedMeshes.clear();
1887   for (CORBA::ULong i=0 ; i<enfMeshes->length() ; i++) {
1888     TEnfMesh* myEnfMesh = new TEnfMesh();
1889     myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in());
1890     myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in());
1891     myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in());
1892     switch (enfMeshes[i].elementType) {
1893     case SMESH::NODE:
1894       myEnfMesh->elementType = 0;
1895       break;
1896     case SMESH::EDGE:
1897       myEnfMesh->elementType = 1;
1898       break;
1899     case SMESH::FACE:
1900       myEnfMesh->elementType = 2;
1901       break;
1902     default:
1903       break;
1904     }
1905     //     myEnfMesh->elementType = enfMeshes[i].elementType;
1906     h_data.myEnforcedMeshes.insert(myEnfMesh);
1907   }
1908   return true;
1909 }
1910
1911 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
1912 {
1913   GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1914     GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
1915   GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis_var opt =
1916     GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis::_narrow( initParamsHypothesis() );
1917
1918   bool ok = true;
1919   try
1920   {
1921     if( isCreation() )
1922       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1923
1924     if ( opt->_is_nil() )
1925     {
1926       h->SetAlgorithm                   ((CORBA::Short) h_data.myAlgorithm );
1927       h->SetUseNumOfThreads             ( h_data.myUseNumOfThreads     );
1928       h->SetNumOfThreads                ( (CORBA::Short) h_data.myNumOfThreads        );
1929       h->SetPthreadMode                 ( (CORBA::Short) h_data.myPthreadMode         );
1930       h->SetParallelMode                ( (CORBA::Short) h_data.myParallelMode        );
1931       h->SetGradation                   ( h_data.myGradation         );
1932       h->SetToMeshHoles                 ( h_data.myToMeshHoles       );
1933       h->SetToMakeGroupsOfDomains       ( h_data.myToMakeGroupsOfDomains );
1934       h->SetVolumeProximity             ( h_data.myUseProximity      );
1935       h->SetNbVolumeProximityLayers     ((CORBA::Short) h_data.myNbProximityLayers );
1936     }
1937
1938     // Common existing options optimization a MGTetra && MGTetraHPC
1939     h->SetOptimizationLevel           ((CORBA::Short) h_data.myOptimizationLevel );
1940     h->SetMinSize                     ( h_data.myUseMinSize ? h_data.myMinSize : 0 );
1941     h->SetMaxSize                     ( h_data.myUseMaxSize ? h_data.myMaxSize : 0 );
1942     h->SetMinMaxSizeDefault           ( this->myMinSizeDefault, this->myMaxSizeDefault );
1943
1944     h->SetMaximumMemory               ( h_data.myMaximumMemory     );
1945     h->SetInitialMemory               ( h_data.myInitialMemory     );
1946     h->SetKeepFiles                   ( h_data.myKeepFiles         );
1947     h->SetWorkingDirectory            ( h_data.myWorkingDir.toLatin1().constData() );
1948     h->SetVerboseLevel                ( h_data.myVerboseLevel      );
1949     //h->SetToRemoveCentralPoint        ( h_data.myRemoveInitialCentralPoint );
1950     //h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery  );
1951     //h->SetFEMCorrection               ( h_data.myFEMCorrection     );
1952     h->SetStandardOutputLog           ( h_data.myLogInStandardOutput );
1953     h->SetRemoveLogOnSuccess          ( h_data.myRemoveLogOnSuccess  );
1954     
1955
1956     if ( !opt->_is_nil() )
1957     {
1958       opt->SetToCreateNewNodes      ( h_data.myToCreateNewNodes  );
1959       opt->SetOptimization          ( (GHS3DPlugin::Mode) h_data.myOptimization );
1960       opt->SetSplitOverConstrained  ( (GHS3DPlugin::Mode) h_data.mySplitOverConstrained );
1961       opt->SetPThreadsMode          ( (GHS3DPlugin::PThreadsMode) h_data.myPThreadsMode );
1962       opt->SetSmoothOffSlivers      ( h_data.mySmoothOffSlivers );
1963       opt->SetMaximalNumberOfThreads((CORBA::Short) h_data.myNumberOfThreads );
1964     }
1965
1966     // Enforced vertices
1967     GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
1968     int nbVertexHyp = vertexHyp->length();
1969
1970     // 1. Clear all enforced vertices in hypothesis
1971     // 2. Add new enforced vertex according to h_data
1972     if ( nbVertexHyp > 0)
1973       h->ClearEnforcedVertices();
1974
1975     TEnfVertexList::const_iterator it;
1976     double x = 0, y = 0, z = 0;
1977     for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
1978       TEnfVertex* enfVertex = (*it);
1979       x =y =z = 0;
1980       if (enfVertex->coords.size()) {
1981         x = enfVertex->coords.at(0);
1982         y = enfVertex->coords.at(1);
1983         z = enfVertex->coords.at(2);
1984       }
1985       ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound);
1986     } // for
1987
1988     // Enforced Meshes
1989     GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes();
1990     int nbEnfMeshListHyp = enfMeshListHyp->length();
1991
1992     // 1. Clear all enforced vertices in hypothesis
1993     // 2. Add new enforced vertex according to h_data
1994     if ( nbEnfMeshListHyp > 0)
1995       h->ClearEnforcedMeshes();
1996
1997     TEnfMeshList::const_iterator itEnfMesh;
1998
1999     _PTR(Study) aStudy = SMESH::getStudy();
2000
2001     for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) {
2002       TEnfMesh* enfMesh = (*itEnfMesh);
2003
2004       _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str());
2005       SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
2006
2007       SMESH::ElementType elementType = SMESH::NODE;
2008       switch(enfMesh->elementType) {
2009       case 0:
2010         elementType = SMESH::NODE;
2011         break;
2012       case 1:
2013         elementType = SMESH::EDGE;
2014         break;
2015       case 2:
2016         elementType = SMESH::FACE;
2017         break;
2018       default:
2019         break;
2020       }
2021
2022       ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->name.c_str(), enfMesh->groupName.c_str());
2023     } // for
2024   } // try
2025   catch ( const SALOME::SALOME_Exception& ex )
2026   {
2027     SalomeApp_Tools::QtCatchCorbaException( ex );
2028     ok = false;
2029   }
2030   return ok;
2031 }
2032
2033 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
2034 {
2035   h_data.myName                    = myName ? myName->text() : "";
2036   h_data.myOptimizationLevel       = myOptimizationLevelCombo->currentIndex();
2037   if ( mySplitOverConstrainedCombo ) // optimizer
2038   {
2039     h_data.myToCreateNewNodes      = myCreateNewNodesCheck->isChecked();
2040     h_data.myOptimization          = myOptimizationCombo->currentIndex();
2041     h_data.mySplitOverConstrained  = mySplitOverConstrainedCombo->currentIndex();
2042     h_data.myPThreadsMode          = myPThreadsModeCombo->currentIndex();
2043     h_data.myNumberOfThreads       = myNumberOfThreadsSpin->value();
2044     h_data.mySmoothOffSlivers      = mySmoothOffSliversCheck->isChecked();
2045   }
2046   else
2047   {
2048     h_data.myMinSize               = myMinSizeSpin->value();
2049     h_data.myMaxSize               = myMaxSizeSpin->value();
2050     h_data.myUseMinSize            = myMinSizeCheck->isChecked();
2051     h_data.myUseMaxSize            = myMaxSizeCheck->isChecked();
2052     h_data.myGradation             = myGradationSpin->value();
2053     h_data.myUseGradation          = myGradationCheck->isChecked();
2054     h_data.myUseProximity          = myUseProximityGroup->isChecked();
2055     h_data.myNbProximityLayers     = myNbProximityLayers->value();
2056     h_data.myToMeshHoles           = myToMeshHolesCheck->isChecked();
2057     h_data.myToMakeGroupsOfDomains = myToMakeGroupsOfDomains->isChecked();
2058     h_data.myAlgorithm             = myRadioBottomGroup->checkedId();
2059     h_data.myUseNumOfThreads       = myNumOfThreadsCheck->isChecked();
2060     h_data.myNumOfThreads          = myNumOfThreadsSpin->value();
2061     h_data.myPthreadMode           = myPthreadMode->currentIndex();
2062     h_data.myParallelMode          = myParallelMode->currentIndex();
2063   }
2064   h_data.myMaximumMemory           = float( myAdvWidget->maxMemoryCheck->isChecked() ? myAdvWidget->maxMemorySpin->value() : -1 );
2065   h_data.myInitialMemory           = float( myAdvWidget->initialMemoryCheck->isChecked() ? myAdvWidget->initialMemorySpin->value() : -1 );
2066   h_data.myKeepFiles               = myAdvWidget->keepWorkingFilesCheck->isChecked();
2067   h_data.myWorkingDir              = myAdvWidget->workingDirectoryLineEdit->text().trimmed();
2068   h_data.myVerboseLevel            = short( myAdvWidget->verboseLevelSpin->value() );
2069   h_data.myLogInStandardOutput     = !myAdvWidget->logInFileCheck->isChecked();
2070   h_data.myRemoveLogOnSuccess      = myAdvWidget->removeLogOnSuccessCheck->isChecked();
2071
2072   // Enforced vertices
2073   h_data.myEnforcedVertices.clear();
2074   QVariant valueX, valueY, valueZ;
2075   for (int row=0 ; row<myEnforcedTableWidget->rowCount() ; row++)
2076   {
2077     TEnfVertex *myVertex = new TEnfVertex();
2078     myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
2079     myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
2080     myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
2081     valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole);
2082     valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole);
2083     valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole);
2084     if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) {
2085       myVertex->coords.push_back(valueX.toDouble());
2086       myVertex->coords.push_back(valueY.toDouble());
2087       myVertex->coords.push_back(valueZ.toDouble());
2088     }
2089     myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble();
2090     myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool();
2091     h_data.myEnforcedVertices.insert(myVertex);
2092   }
2093   
2094   // Enforced meshes
2095   h_data.myEnforcedMeshes.clear();
2096
2097   for (int row=0 ; row<myEnforcedMeshTableWidget->rowCount() ; row++)
2098   {
2099     TEnfMesh *myEnfMesh = new TEnfMesh();
2100     myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
2101     myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
2102     myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
2103     QComboBox* combo = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN));
2104     myEnfMesh->elementType = combo->currentIndex();
2105     h_data.myEnforcedMeshes.insert(myEnfMesh);
2106   }
2107
2108   return true;
2109 }
2110
2111 QString GHS3DPluginGUI_HypothesisCreator::caption() const
2112 {
2113   return tr( "GHS3D_TITLE" );
2114 }
2115
2116 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
2117 {
2118   return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
2119 }
2120
2121 QString GHS3DPluginGUI_HypothesisCreator::type() const
2122 {
2123   return tr( isOptimization() ? "GHS3D_OPTIMIZATIOL_HYPOTHESIS" : "GHS3D_HYPOTHESIS" );
2124 }
2125
2126 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
2127 {
2128   return isOptimization() ? "optimization_page.html" : "ghs3d_hypo_page.html";
2129 }
2130
2131 void GHS3DPluginGUI_HypothesisCreator::onAddOption()
2132 {
2133   myAdvWidget->AddOption( NULL, true );
2134 }