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