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