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