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