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