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