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