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