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