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