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