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