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