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