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