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