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