Salome HOME
Copyright update: 2016
[plugins/ghs3dplugin.git] / src / GUI / GHS3DPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2004-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 //  File   : GHS3DPluginGUI_HypothesisCreator.cxx
22 //  Author : Michael Zorin
23 //  Module : GHS3DPlugin
24 //
25 #include "GHS3DPluginGUI_HypothesisCreator.h"
26 #include "GHS3DPluginGUI_Enums.h"
27 #include "GHS3DPluginGUI_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   long 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     long err = GlobalMemoryStatusEx (&statex);
86     if (err != 0) {
87       long totMB = 
88         statex.ullTotalPhys / 1024 / 1024 +
89         statex.ullTotalPageFile / 1024 / 1024 +
90         statex.ullTotalVirtual / 1024 / 1024;
91       return (long) ( 0.7 * totMB );
92     }
93 #else
94     struct sysinfo si;
95     long err = sysinfo( &si );
96     if ( err == 0 ) {
97       long totMB =
98         si.totalram * si.mem_unit / 1024 / 1024 +
99         si.totalswap * si.mem_unit / 1024 / 1024 ;
100       return (long) ( 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 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_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( "GHS3D_ENF_MESH_CONSTRAINT_NODE" ) << tr( "GHS3D_ENF_MESH_CONSTRAINT_EDGE" ) << tr("GHS3D_ENF_MESH_CONSTRAINT_FACE");
338 }
339
340 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
341 {
342   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_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* GHS3DPluginGUI_HypothesisCreator::getGeomSelectionTool()
351 {
352   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_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 GHS3DPluginGUI_HypothesisCreator::getGeomEngine()
361 {
362   return GeometryGUI::GetGeomGen();
363 }
364
365 QFrame* GHS3DPluginGUI_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( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
394   aStdLayout->addWidget( myToMeshHolesCheck, row, 0, 1, 1 );
395   myToMakeGroupsOfDomains = new QCheckBox( tr( "GHS3D_TO_MAKE_DOMAIN_GROUPS" ), myStdGroup );
396   aStdLayout->addWidget( myToMakeGroupsOfDomains, row++, 1, 1, 1 );
397
398   aStdLayout->addWidget( new QLabel( tr( "GHS3D_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 GHS3DPluginGUI_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->stepBy(10);
420   myAdvWidget->maxMemorySpin->setValue( 128 );
421
422   myAdvWidget->initialMemorySpin->stepBy(10);
423   myAdvWidget->initialMemorySpin->setValue( 100 );
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( "GHS3D_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( "GHS3D_ENF_NAME_COLUMN" )
458                   << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" )
459                   << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN") << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_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);
481   myEnfVertexWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_VERTEX"), "QLineEdit { color: grey }");
482   
483   QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_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( "GHS3D_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( "GHS3D_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( "GHS3D_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( "GHS3D_ENF_GROUP_LABEL" ), myEnfGroup );
497   myGroupName = new QLineEdit(myEnfGroup);
498
499   addVertexButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfGroup);
500   addVertexButton->setEnabled(false);
501   removeVertexButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfGroup);
502 //   myGlobalGroupName = new QCheckBox(tr("GHS3D_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( "GHS3D_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( "GHS3D_ENF_NAME_COLUMN" ) 
549                       << tr( "GHS3D_ENF_ENTRY_COLUMN" ) 
550                       << tr( "GHS3D_ENF_MESH_CONSTRAINT_COLUMN" ) 
551                       << tr( "GHS3D_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("GHS3D_ENF_SELECT_MESH"), "QLineEdit { color: grey }");
568   
569   myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
570   
571   QLabel* myMeshConstraintLabel = new QLabel( tr( "GHS3D_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( "GHS3D_ENF_GROUP_LABEL" ), myEnfMeshGroup );
578   myMeshGroupName = new QLineEdit(myEnfMeshGroup);
579
580   addEnfMeshButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfMeshGroup);
581 //   addEnfMeshButton->setEnabled(false);
582   removeEnfMeshButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfMeshGroup);
583     
584   // QGroupBox* GroupBox2 = new QGroupBox( myEnfMeshGroup );
585   // QLabel* info2 = new QLabel( GroupBox2 );
586   // info2->setText( tr( "GHS3D_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( "GHS3D_ADV_ARGS" ) );
612   tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
613   tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "GHS3D_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 GHS3DPluginGUI_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   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
664   that->checkVertexIsDefined();
665 }
666
667 /** 
668  * This method checks if an enforced vertex is defined;
669 **/
670 void GHS3DPluginGUI_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 GHS3DPluginGUI_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 GHS3DPluginGUI_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 /** GHS3DPluginGUI_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 GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item) {
711 //   MESSAGE("GHS3DPluginGUI_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 GHS3DPluginGUI_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       GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_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 /** GHS3DPluginGUI_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 GHS3DPluginGUI_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   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
875   that->checkVertexIsDefined();
876 }
877
878 /** GHS3DPluginGUI_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 GHS3DPluginGUI_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 /** GHS3DPluginGUI_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 GHS3DPluginGUI_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))) ||
1042         ( !itemEntry.isEmpty() && ( itemEntry == geomEntry.c_str() )))
1043     {
1044       // update size
1045       if (itemSize != size) {
1046         MESSAGE("Size is updated from \"" << itemSize << "\" to \"" << size << "\"");
1047         myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size));
1048       }
1049       // update group name
1050       if (itemGroupName.toStdString() != groupName) {
1051         MESSAGE("Group is updated from \"" << itemGroupName.toStdString() << "\" to \"" << groupName << "\"");
1052         myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
1053       }
1054       okToCreate = false;
1055       break;
1056     } // if
1057   } // for
1058   if (!okToCreate) {
1059     if (geomEntry.empty()) {
1060       MESSAGE("Vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1061     }
1062     else {
1063       MESSAGE("Vertex with entry " << geomEntry << " already exist: dont create again");
1064     }
1065     return;
1066   }
1067     
1068   if (geomEntry.empty()) {
1069     MESSAGE("Vertex with coords " << x << ", " << y << ", " << z<< " is created");
1070   }
1071   else {
1072     MESSAGE("Vertex with geom entry " << geomEntry << " is created");
1073   }
1074
1075   int vertexIndex=0;
1076   int indexRef = -1;
1077   QString myVertexName;
1078   while(indexRef != vertexIndex) {
1079     indexRef = vertexIndex;
1080     if (vertexName.empty())
1081       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1082     else
1083       myVertexName = QString(vertexName.c_str());
1084
1085     for (int row = 0;row<rowCount;row++) {
1086       QString name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString();
1087       if (myVertexName == name) {
1088         vertexIndex++;
1089         break;
1090       }
1091     }
1092   }
1093   
1094   MESSAGE("myVertexName is \"" << myVertexName.toStdString() << "\"");
1095   myEnforcedTableWidget->setRowCount(rowCount+1);
1096   myEnforcedTableWidget->setSortingEnabled(false);
1097   for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1098     MESSAGE("Column: " << col);
1099     QTableWidgetItem* item = new QTableWidgetItem();
1100     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1101     switch (col) {
1102       case ENF_VER_NAME_COLUMN:
1103         item->setData( Qt::EditRole, myVertexName );
1104         if (!geomEntry.empty()) {
1105           if (isCompound)
1106             item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1107           else
1108             item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1109         }
1110         break;
1111       case ENF_VER_X_COLUMN:
1112         if (!isCompound)
1113           item->setData( 0, QVariant(x) );
1114         break;
1115       case ENF_VER_Y_COLUMN:
1116         if (!isCompound)
1117           item->setData( 0, QVariant(y) );
1118         break;
1119       case ENF_VER_Z_COLUMN:
1120         if (!isCompound)
1121           item->setData( 0, QVariant(z) );
1122         break;
1123       case ENF_VER_SIZE_COLUMN:
1124         item->setData( 0, QVariant(size) );
1125         break;
1126       case ENF_VER_ENTRY_COLUMN:
1127         if (!geomEntry.empty())
1128           item->setData( 0, QString(geomEntry.c_str()) );
1129         break;
1130       case ENF_VER_COMPOUND_COLUMN:
1131         item->setData( Qt::CheckStateRole, isCompound );
1132         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1133         break;
1134       case ENF_VER_GROUP_COLUMN:
1135         if (!groupName.empty())
1136           item->setData( 0, QString(groupName.c_str()) );
1137         break;
1138       default:
1139         break;
1140     }
1141     
1142     MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1143     myEnforcedTableWidget->setItem(rowCount,col,item);
1144     MESSAGE("Done");
1145   }
1146
1147   connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this,  SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1148   
1149   myEnforcedTableWidget->setSortingEnabled(true);
1150 //   myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1151   updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1152 }
1153
1154 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1155 This method is called when a item is added into the enforced meshes tree widget
1156 */
1157 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1158 {
1159   MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()");
1160
1161   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1162   
1163   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1164   myEnfMeshWdg->deactivateSelection();
1165
1166   for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1167     myEnforcedMeshTableWidget->resizeColumnToContents(column);
1168
1169   // Vertex selection
1170   int selEnfMeshes = myEnfMeshWdg->NbObjects();
1171   if (selEnfMeshes == 0)
1172     return;
1173
1174   std::string groupName = myMeshGroupName->text().toStdString();
1175 //   if (myGlobalGroupName->isChecked())
1176 //     groupName = myGlobalGroupName->text().toStdString();
1177
1178   if (boost::trim_copy(groupName).empty())
1179     groupName = "";
1180
1181   
1182   int elementType = myEnfMeshConstraint->currentIndex();
1183   
1184   
1185   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1186   _PTR(SObject) aSObj; //SMESH::SMESH_IDSource::_nil;
1187   QString meshEntry = myEnfMeshWdg->GetValue();
1188   MESSAGE("myEnfMeshWdg->GetValue()" << meshEntry.toStdString());
1189   
1190   if (selEnfMeshes == 1)
1191   {
1192     MESSAGE("1 SMESH object selected");
1193 //     myEnfMesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
1194 //     std::string entry = myEnfMeshWdg->GetValue();
1195     aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str());
1196     CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1197     if (!CORBA::is_nil(anObj)) {
1198 //       SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1199       addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1200     }
1201   }
1202   else
1203   {
1204     MESSAGE(selEnfMeshes << " SMESH objects selected");
1205     QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts);
1206     QStringListIterator meshEntriesIt (meshEntries);
1207     while (meshEntriesIt.hasNext()) {
1208       aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str());
1209       CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1210       if (!CORBA::is_nil(anObj)) {
1211 //         SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1212         addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1213       }
1214     }
1215   }
1216
1217   myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil());
1218   
1219   for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1220     myEnforcedMeshTableWidget->resizeColumnToContents(column);  
1221 }
1222
1223
1224 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1225 This method is called when a item is added into the enforced vertices tree widget
1226 */
1227 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1228 {
1229   MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()");
1230
1231   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1232   
1233   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1234   myEnfVertexWdg->deactivateSelection();
1235
1236   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1237     myEnforcedTableWidget->resizeColumnToContents(column);
1238
1239   // Vertex selection
1240   int selEnfVertex = myEnfVertexWdg->NbObjects();
1241   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1242   if ((selEnfVertex == 0) && coordsEmpty)
1243     return;
1244
1245   std::string groupName = myGroupName->text().toStdString();
1246 //   if (myGlobalGroupName->isChecked())
1247 //     groupName = myGlobalGroupName->text().toStdString();
1248
1249   if (boost::trim_copy(groupName).empty())
1250     groupName = "";
1251
1252   double size = mySizeValue->GetValue();
1253   
1254   if (selEnfVertex <= 1)
1255   {
1256     MESSAGE("0 or 1 GEOM object selected");
1257     double x = 0, y = 0, z=0;
1258     if (myXCoord->GetString() != "") {
1259       x = myXCoord->GetValue();
1260       y = myYCoord->GetValue();
1261       z = myZCoord->GetValue();
1262     }
1263     if (selEnfVertex == 1) {
1264       MESSAGE("1 GEOM object selected");
1265       myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1266       std::string entry = "", name = "";
1267       bool isCompound = false;
1268       if ( !myEnfVertex->_is_nil() ) {
1269         entry = SMESH::toStdStr( myEnfVertex->GetStudyEntry() );
1270         name  = SMESH::toStdStr( myEnfVertex->GetName() );
1271         isCompound = ( myEnfVertex->GetShapeType() == GEOM::COMPOUND );
1272       }
1273       addEnforcedVertex(x, y, z, size, name, entry, groupName, isCompound);
1274     }
1275     else {
1276       MESSAGE("0 GEOM object selected");
1277       MESSAGE("Coords: ("<<x<<","<<y<<","<<z<<")");
1278       addEnforcedVertex(x, y, z, size, "", "", groupName);
1279     }
1280   }
1281   else
1282   {
1283     if ( CORBA::is_nil(getGeomEngine()))
1284       return;
1285
1286     GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1287     if (CORBA::is_nil(measureOp))
1288       return;
1289
1290     CORBA::Double x = 0, y = 0,z = 0;
1291     for (int j = 0 ; j < selEnfVertex ; j++)
1292     {
1293       myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1294       if (myEnfVertex == GEOM::GEOM_Object::_nil())
1295         continue;
1296       if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1297         measureOp->PointCoordinates (myEnfVertex, x, y, z);
1298         if ( measureOp->IsDone() )
1299           addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1300       } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1301           addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true);
1302       }
1303     }
1304   }
1305
1306   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1307   
1308   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1309     myEnforcedTableWidget->resizeColumnToContents(column);  
1310 }
1311
1312 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1313 This method is called when a item is removed from the enforced meshes tree widget
1314 */
1315 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1316 {
1317   QList<int> selectedRows;
1318   QList<QTableWidgetItem *> selectedItems = myEnforcedMeshTableWidget->selectedItems();
1319   QTableWidgetItem* item;
1320   int row;
1321   foreach( item, selectedItems ) {
1322     row = item->row();
1323     if (!selectedRows.contains( row ) )
1324       selectedRows.append(row);
1325   }
1326   
1327   qSort( selectedRows );
1328   QListIterator<int> it( selectedRows );
1329   it.toBack();
1330   while ( it.hasPrevious() ) {
1331       row = it.previous();
1332       MESSAGE("delete row #"<< row);
1333       myEnforcedMeshTableWidget->removeRow(row );
1334   }
1335
1336   myEnforcedMeshTableWidget->selectionModel()->clearSelection();
1337 }
1338
1339 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1340 This method is called when a item is removed from the enforced vertices tree widget
1341 */
1342 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1343 {
1344   QList<int> selectedRows;
1345   QList<QTableWidgetItem *> selectedItems = myEnforcedTableWidget->selectedItems();
1346   QTableWidgetItem* item;
1347   int row;
1348   foreach( item, selectedItems ) {
1349     row = item->row();
1350     if (!selectedRows.contains( row ) )
1351       selectedRows.append(row);
1352   }
1353   
1354   qSort( selectedRows );
1355   QListIterator<int> it( selectedRows );
1356   it.toBack();
1357   while ( it.hasPrevious() ) {
1358       row = it.previous();
1359       MESSAGE("delete row #"<< row);
1360       myEnforcedTableWidget->removeRow(row );
1361   }
1362
1363   myEnforcedTableWidget->selectionModel()->clearSelection();
1364 }
1365
1366 void GHS3DPluginGUI_HypothesisCreator::onToMeshHoles(bool isOn)
1367 {
1368   // myToMakeGroupsOfDomains->setEnabled( isOn );
1369   // if ( !isOn )
1370   //   myToMakeGroupsOfDomains->setChecked( false );
1371 }
1372
1373 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
1374 {
1375   QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myAdvWidget->workingDirectoryLineEdit->text(), QString() );
1376   if ( !dir.isEmpty() )
1377     myAdvWidget->workingDirectoryLineEdit->setText( dir );
1378 }
1379
1380 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
1381 {
1382   //myToMakeGroupsOfDomains->setEnabled( myToMeshHolesCheck->isChecked() );
1383   myAdvWidget->maxMemorySpin->setEnabled( myAdvWidget->maxMemoryCheck->isChecked() );
1384   myAdvWidget->initialMemoryCheck->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1385   myAdvWidget->initialMemorySpin->setEnabled( myAdvWidget->initialMemoryCheck->isChecked() && !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1386   myOptimizationLevelCombo->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1387   if ( sender() == myAdvWidget->logInFileCheck ||
1388        sender() == myAdvWidget->keepWorkingFilesCheck )
1389   {
1390     bool logFileRemovable = myAdvWidget->logInFileCheck->isChecked() &&
1391                             !myAdvWidget->keepWorkingFilesCheck->isChecked();
1392                              
1393     myAdvWidget->removeLogOnSuccessCheck->setEnabled( logFileRemovable );
1394   }
1395 }
1396
1397 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
1398 {
1399   MESSAGE("GHS3DPluginGUI_HypothesisCreator::checkParams");
1400
1401   if ( !QFileInfo( myAdvWidget->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
1402     SUIT_MessageBox::warning( dlg(),
1403                               tr( "SMESH_WRN_WARNING" ),
1404                               tr( "GHS3D_PERMISSION_DENIED" ) );
1405     return false;
1406   }
1407
1408   return true;
1409 }
1410
1411 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
1412 {
1413   MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams");
1414   GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1415   GHS3DHypothesisData data;
1416   readParamsFromHypo( data );
1417
1418   if ( myName )
1419     myName->setText( data.myName );
1420   
1421   myToMeshHolesCheck                          ->setChecked    ( data.myToMeshHoles );
1422   myToMakeGroupsOfDomains                     ->setChecked    ( data.myToMakeGroupsOfDomains );
1423   myOptimizationLevelCombo                    ->setCurrentIndex( data.myOptimizationLevel );
1424   myAdvWidget->maxMemoryCheck                 ->setChecked    ( data.myMaximumMemory > 0 );
1425   myAdvWidget->maxMemorySpin                  ->setValue      ( qMax( (int)data.myMaximumMemory,
1426                                                                       myAdvWidget->maxMemorySpin->minimum() ));
1427   myAdvWidget->initialMemoryCheck             ->setChecked    ( data.myInitialMemory > 0 );
1428   myAdvWidget->initialMemorySpin              ->setValue      ( qMax( (int)data.myInitialMemory,
1429                                                                       myAdvWidget->initialMemorySpin->minimum() ));
1430   myAdvWidget->workingDirectoryLineEdit       ->setText       ( data.myWorkingDir );
1431   myAdvWidget->keepWorkingFilesCheck           ->setChecked    ( data.myKeepFiles );
1432   myAdvWidget->verboseLevelSpin               ->setValue      ( data.myVerboseLevel );
1433   myAdvWidget->createNewNodesCheck            ->setChecked    ( data.myToCreateNewNodes );
1434   myAdvWidget->removeInitialCentralPointCheck ->setChecked    ( data.myRemoveInitialCentralPoint );
1435   myAdvWidget->boundaryRecoveryCheck          ->setChecked    ( data.myBoundaryRecovery );
1436   myAdvWidget->FEMCorrectionCheck             ->setChecked    ( data.myFEMCorrection );
1437   myAdvWidget->gradationSpinBox               ->setValue      ( data.myGradation );
1438   myAdvWidget->textOptionLineEdit             ->setText       ( data.myTextOption );
1439   myAdvWidget->logInFileCheck                 ->setChecked    ( !data.myLogInStandardOutput );
1440   myAdvWidget->removeLogOnSuccessCheck        ->setChecked    ( data.myRemoveLogOnSuccess );
1441
1442   TEnfVertexList::const_iterator it;
1443   int rowCount = 0;
1444   myEnforcedTableWidget->clearContents();
1445   myEnforcedTableWidget->setSortingEnabled(false);
1446   myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1447   for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
1448   {
1449     TEnfVertex* enfVertex = (*it);
1450     myEnforcedTableWidget->setRowCount(rowCount+1);
1451
1452     for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1453       MESSAGE("Column: " << col);
1454 //       MESSAGE("enfVertex->isCompound: " << enfVertex->isCompound);
1455       QTableWidgetItem* item = new QTableWidgetItem();
1456       item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1457       switch (col) {
1458         case ENF_VER_NAME_COLUMN:
1459           item->setData( 0, enfVertex->name.c_str() );
1460           if (!enfVertex->geomEntry.empty()) {
1461             if (enfVertex->isCompound)
1462               item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1463             else
1464               item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1465             
1466             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1467           }
1468           break;
1469         case ENF_VER_X_COLUMN:
1470           if (!enfVertex->isCompound) {
1471             item->setData( 0, enfVertex->coords.at(0) );
1472             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1473           }
1474           break;
1475         case ENF_VER_Y_COLUMN:
1476           if (!enfVertex->isCompound) {
1477             item->setData( 0, enfVertex->coords.at(1) );
1478             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1479           }
1480           break;
1481         case ENF_VER_Z_COLUMN:
1482           if (!enfVertex->isCompound) {
1483             item->setData( 0, enfVertex->coords.at(2) );
1484             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1485           }
1486           break;
1487         case ENF_VER_SIZE_COLUMN:
1488           item->setData( 0, enfVertex->size );
1489           MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1490           break;
1491         case ENF_VER_ENTRY_COLUMN:
1492           item->setData( 0, enfVertex->geomEntry.c_str() );
1493           MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1494           break;
1495         case ENF_VER_COMPOUND_COLUMN:
1496           item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1497           item->setData( Qt::CheckStateRole, enfVertex->isCompound );
1498           MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << enfVertex->isCompound);
1499           break;
1500         case ENF_VER_GROUP_COLUMN:
1501           item->setData( 0, enfVertex->groupName.c_str() );
1502           MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1503           break;
1504         default:
1505           break;
1506       }
1507       
1508       myEnforcedTableWidget->setItem(rowCount,col,item);
1509       MESSAGE("Done");
1510     }
1511     that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1512     rowCount++;
1513   }
1514
1515   connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this,  SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1516   myEnforcedTableWidget->setSortingEnabled(true);
1517   
1518   for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1519     myEnforcedTableWidget->resizeColumnToContents(column);
1520
1521   // Update Enforced meshes QTableWidget
1522   TEnfMeshList::const_iterator itMesh;
1523   rowCount = 0;
1524   myEnforcedMeshTableWidget->clearContents();
1525   myEnforcedMeshTableWidget->setSortingEnabled(false);
1526 //   myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1527   for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ )
1528   {
1529     TEnfMesh* enfMesh = (*itMesh);
1530     myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1531
1532     for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1533       MESSAGE("Column: " << col);
1534       if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1535         QComboBox* comboBox = new QComboBox();
1536         QPalette pal = comboBox->palette();
1537         pal.setColor(QPalette::Button, Qt::white);
1538         comboBox->setPalette(pal);
1539         comboBox->insertItems(0,myEnfMeshConstraintLabels);
1540         comboBox->setEditable(false);
1541         comboBox->setCurrentIndex(enfMesh->elementType);
1542         MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << comboBox->currentText().toStdString());
1543         myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1544       }
1545       else {
1546         QTableWidgetItem* item = new QTableWidgetItem();
1547         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1548         switch (col) {
1549           case ENF_MESH_NAME_COLUMN:
1550             item->setData( 0, enfMesh->name.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_ENTRY_COLUMN:
1556             item->setData( 0, enfMesh->entry.c_str() );
1557             item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1558             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1559             myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1560             break;
1561           case ENF_MESH_GROUP_COLUMN:
1562             item->setData( 0, enfMesh->groupName.c_str() );
1563             MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1564             myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1565             break;
1566           default:
1567             break;
1568         }
1569       }
1570       
1571 //       myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1572       MESSAGE("Done");
1573     }
1574 //     that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1575     rowCount++;
1576   }
1577
1578 //   connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this,  SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1579   myEnforcedMeshTableWidget->setSortingEnabled(true);
1580   
1581   for (int col=0;col<ENF_MESH_NB_COLUMNS;col++)
1582     myEnforcedMeshTableWidget->resizeColumnToContents(col);
1583   
1584   that->updateWidgets();
1585   that->checkVertexIsDefined();
1586 }
1587
1588 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
1589 {
1590     MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParams");
1591     GHS3DHypothesisData data;
1592     readParamsFromWidgets( data );
1593     storeParamsToHypo( data );
1594     
1595     QString valStr = "";
1596     
1597     if ( !data.myBoundaryRecovery )
1598         valStr = " --components " + data.myToMeshHoles ? "all" : "outside_components" ;
1599     
1600     if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
1601         const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1602         valStr += " --optimisation_level ";
1603         valStr += level[ data.myOptimizationLevel ];
1604     }
1605     if ( data.myMaximumMemory > 0 ) {
1606         valStr += " --max_memory ";
1607         valStr += QString::number( data.myMaximumMemory );
1608     }
1609     if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
1610         valStr += " --automatic_memory ";
1611         valStr += QString::number( data.myInitialMemory );
1612     }
1613     valStr += " --verbose ";
1614     valStr += QString::number( data.myVerboseLevel );
1615     
1616     if ( !data.myToCreateNewNodes )
1617         valStr += " --no_internal_points";
1618     
1619     if ( data.myRemoveInitialCentralPoint )
1620         valStr += " --no_initial_central_point";
1621     
1622     if ( data.myBoundaryRecovery )
1623         valStr += " -C";
1624     
1625     if ( data.myFEMCorrection )
1626         valStr += " -FEM";
1627     
1628     if ( data.myGradation != 1.05 ) {
1629       valStr += " -Dcpropa=";
1630       valStr += QString::number( data.myGradation );
1631     }
1632     
1633     valStr += " ";
1634     valStr += data.myTextOption;
1635     
1636 //     valStr += " #BEGIN ENFORCED VERTICES#";
1637 //     // Add size map parameters storage
1638 //     for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
1639 //         valStr += " (";
1640 //         double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble();
1641 //         double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble();
1642 //         double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble();
1643 //         double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble();
1644 //         valStr += QString::number( x );
1645 //         valStr += ",";
1646 //         valStr += QString::number( y );
1647 //         valStr += ",";
1648 //         valStr += QString::number( z );
1649 //         valStr += ")=";
1650 //         valStr += QString::number( size );
1651 //         if (i!=mySmpModel->rowCount()-1)
1652 //             valStr += ";";
1653 //     }
1654 //     valStr += " #END ENFORCED VERTICES#";
1655 //     MESSAGE(valStr.toStdString());
1656   return valStr;
1657 }
1658
1659 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
1660 {
1661   MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo");
1662   GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1663     GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1664
1665   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1666   h_data.myName = isCreation() && data ? hypName() : "";
1667
1668   h_data.myToMeshHoles                = h->GetToMeshHoles();
1669   h_data.myToMakeGroupsOfDomains      = /*h->GetToMeshHoles() &&*/ h->GetToMakeGroupsOfDomains();
1670   h_data.myMaximumMemory              = h->GetMaximumMemory();
1671   h_data.myInitialMemory              = h->GetInitialMemory();
1672   h_data.myInitialMemory              = h->GetInitialMemory();
1673   h_data.myOptimizationLevel          = h->GetOptimizationLevel();
1674   h_data.myKeepFiles                  = h->GetKeepFiles();
1675   h_data.myWorkingDir                 = h->GetWorkingDirectory();
1676   h_data.myVerboseLevel               = h->GetVerboseLevel();
1677   h_data.myToCreateNewNodes           = h->GetToCreateNewNodes();
1678   h_data.myRemoveInitialCentralPoint  = h->GetToRemoveCentralPoint();
1679   h_data.myBoundaryRecovery           = h->GetToUseBoundaryRecoveryVersion();
1680   h_data.myFEMCorrection              = h->GetFEMCorrection();
1681   h_data.myGradation                  = h->GetGradation();
1682   h_data.myTextOption                 = h->GetTextOption();
1683   h_data.myLogInStandardOutput        = h->GetStandardOutputLog();
1684   h_data.myRemoveLogOnSuccess         = h->GetRemoveLogOnSuccess();
1685   
1686   GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
1687   MESSAGE("vertices->length(): " << vertices->length());
1688   h_data.myEnforcedVertices.clear();
1689   for (int i=0 ; i<vertices->length() ; i++) {
1690     TEnfVertex* myVertex = new TEnfVertex();
1691     myVertex->name = CORBA::string_dup(vertices[i].name.in());
1692     myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in());
1693     myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in());
1694     myVertex->size = vertices[i].size;
1695     myVertex->isCompound = vertices[i].isCompound;
1696     if (vertices[i].coords.length()) {
1697       for (int c = 0; c < vertices[i].coords.length() ; c++)
1698         myVertex->coords.push_back(vertices[i].coords[c]);
1699       MESSAGE("Add enforced vertex ("<< myVertex->coords.at(0) << ","<< myVertex->coords.at(1) << ","<< myVertex->coords.at(2) << ") ="<< myVertex->size);
1700     }
1701     h_data.myEnforcedVertices.insert(myVertex);
1702   }
1703   
1704   GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes();
1705   MESSAGE("enfMeshes->length(): " << enfMeshes->length());
1706   h_data.myEnforcedMeshes.clear();
1707   for (int i=0 ; i<enfMeshes->length() ; i++) {
1708     TEnfMesh* myEnfMesh = new TEnfMesh();
1709     myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in());
1710     myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in());
1711     myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in());
1712     switch (enfMeshes[i].elementType) {
1713       case SMESH::NODE:
1714         myEnfMesh->elementType = 0;
1715         break;
1716       case SMESH::EDGE:
1717         myEnfMesh->elementType = 1;
1718         break;
1719       case SMESH::FACE:
1720         myEnfMesh->elementType = 2;
1721         break;
1722       default:
1723         break;
1724     }
1725 //     myEnfMesh->elementType = enfMeshes[i].elementType;
1726     h_data.myEnforcedMeshes.insert(myEnfMesh);
1727   }
1728   return true;
1729 }
1730
1731 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
1732 {
1733   MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo");
1734   GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1735     GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
1736
1737   bool ok = true;
1738   try
1739   {
1740     if( isCreation() )
1741       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1742
1743     if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
1744       h->SetToMeshHoles      ( h_data.myToMeshHoles       );
1745     if ( h->GetToMakeGroupsOfDomains() != h_data.myToMakeGroupsOfDomains )
1746       h->SetToMakeGroupsOfDomains( h_data.myToMakeGroupsOfDomains );
1747     if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
1748       h->SetMaximumMemory    ( h_data.myMaximumMemory     );
1749     if ( h->GetInitialMemory() != h_data.myInitialMemory )
1750       h->SetInitialMemory    ( h_data.myInitialMemory     );
1751     if ( h->GetInitialMemory() != h_data.myInitialMemory )
1752       h->SetInitialMemory    ( h_data.myInitialMemory     );
1753     if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
1754       h->SetOptimizationLevel( h_data.myOptimizationLevel );
1755     if ( h->GetKeepFiles() != h_data.myKeepFiles         )
1756       h->SetKeepFiles        ( h_data.myKeepFiles         );
1757     if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
1758       h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
1759     if ( h->GetVerboseLevel() != h_data.myVerboseLevel   )
1760       h->SetVerboseLevel     ( h_data.myVerboseLevel      );
1761     if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
1762       h->SetToCreateNewNodes( h_data.myToCreateNewNodes   );
1763     if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
1764       h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
1765     if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
1766       h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
1767     if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
1768       h->SetFEMCorrection    ( h_data.myFEMCorrection     );
1769     if ( h->GetGradation() != h_data.myGradation         )
1770       h->SetGradation        ( h_data.myGradation         );
1771     if ( h->GetTextOption() != h_data.myTextOption       )
1772       h->SetTextOption       ( h_data.myTextOption.toLatin1().constData() );
1773     if ( h->GetStandardOutputLog() != h_data.myLogInStandardOutput   )
1774       h->SetStandardOutputLog( h_data.myLogInStandardOutput  );
1775      if ( h->GetRemoveLogOnSuccess() != h_data.myRemoveLogOnSuccess   )
1776       h->SetRemoveLogOnSuccess( h_data.myRemoveLogOnSuccess  );
1777     
1778     // Enforced vertices
1779     int nbVertex = (int) h_data.myEnforcedVertices.size();
1780     GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
1781     int nbVertexHyp = vertexHyp->length();
1782     
1783     MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices");
1784     MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp);
1785     
1786     // 1. Clear all enforced vertices in hypothesis
1787     // 2. Add new enforced vertex according to h_data
1788     if ( nbVertexHyp > 0)
1789       h->ClearEnforcedVertices();
1790     
1791     TEnfVertexList::const_iterator it;
1792     double x = 0, y = 0, z = 0;
1793     for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
1794       TEnfVertex* enfVertex = (*it);
1795       x =y =z = 0;
1796       if (enfVertex->coords.size()) {
1797         x = enfVertex->coords.at(0);
1798         y = enfVertex->coords.at(1);
1799         z = enfVertex->coords.at(2);
1800       }
1801       ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound);
1802     } // for
1803     
1804     // Enforced Meshes
1805     int nbEnfMeshes = (int) h_data.myEnforcedMeshes.size();
1806     GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes();
1807     int nbEnfMeshListHyp = enfMeshListHyp->length();
1808     
1809     MESSAGE("Store params for size maps: " << nbEnfMeshes << " enforced meshes");
1810     MESSAGE("h->GetEnforcedMeshes()->length(): " << nbEnfMeshListHyp);
1811     
1812     // 1. Clear all enforced vertices in hypothesis
1813     // 2. Add new enforced vertex according to h_data
1814     if ( nbEnfMeshListHyp > 0)
1815       h->ClearEnforcedMeshes();
1816     
1817     TEnfMeshList::const_iterator itEnfMesh;
1818
1819     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1820
1821     for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) {
1822       TEnfMesh* enfMesh = (*itEnfMesh);
1823
1824       _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str());
1825       SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1826
1827       MESSAGE("enfMesh->elementType: " << enfMesh->elementType);
1828       SMESH::ElementType elementType;
1829       switch(enfMesh->elementType) {
1830         case 0:
1831           elementType = SMESH::NODE;
1832           break;
1833         case 1:
1834           elementType = SMESH::EDGE;
1835           break;
1836         case 2:
1837           elementType = SMESH::FACE;
1838           break;
1839         default:
1840           break;
1841       }
1842     
1843       std::cout << "h->p_SetEnforcedMesh(theSource, "<< elementType <<", \""<< enfMesh->name << "\", \"" << enfMesh->groupName.c_str() <<"\")"<<std::endl;
1844       ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->name.c_str(), enfMesh->groupName.c_str());
1845     } // for
1846   } // try
1847 //   catch(const std::exception& ex) {
1848 //     std::cout << "Exception: " << ex.what() << std::endl;
1849 //     throw ex;
1850 //   }
1851   catch ( const SALOME::SALOME_Exception& ex )
1852   {
1853     SalomeApp_Tools::QtCatchCorbaException( ex );
1854     ok = false;
1855   }
1856   return ok;
1857 }
1858
1859 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
1860 {
1861   MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets");
1862   h_data.myName                       = myName ? myName->text() : "";
1863   h_data.myToMeshHoles                = myToMeshHolesCheck->isChecked();
1864   h_data.myToMakeGroupsOfDomains      = myToMakeGroupsOfDomains->isChecked();
1865   h_data.myMaximumMemory              = myAdvWidget->maxMemoryCheck->isChecked() ? myAdvWidget->maxMemorySpin->value() : -1;
1866   h_data.myInitialMemory              = myAdvWidget->initialMemoryCheck->isChecked() ? myAdvWidget->initialMemorySpin->value() : -1;
1867   h_data.myOptimizationLevel          = myOptimizationLevelCombo->currentIndex();
1868   h_data.myKeepFiles                  = myAdvWidget->keepWorkingFilesCheck->isChecked();
1869   h_data.myWorkingDir                 = myAdvWidget->workingDirectoryLineEdit->text().trimmed();
1870   h_data.myVerboseLevel               = myAdvWidget->verboseLevelSpin->value();
1871   h_data.myToCreateNewNodes           = myAdvWidget->createNewNodesCheck->isChecked();
1872   h_data.myRemoveInitialCentralPoint  = myAdvWidget->removeInitialCentralPointCheck->isChecked();
1873   h_data.myBoundaryRecovery           = myAdvWidget->boundaryRecoveryCheck->isChecked();
1874   h_data.myFEMCorrection              = myAdvWidget->FEMCorrectionCheck->isChecked();
1875   h_data.myGradation                  = myAdvWidget->gradationSpinBox->value();
1876   h_data.myTextOption                 = myAdvWidget->textOptionLineEdit->text();
1877   h_data.myLogInStandardOutput        = !myAdvWidget->logInFileCheck->isChecked();
1878   h_data.myRemoveLogOnSuccess         = myAdvWidget->removeLogOnSuccessCheck->isChecked();
1879   
1880   // Enforced vertices
1881   h_data.myEnforcedVertices.clear();
1882   QVariant valueX, valueY, valueZ;
1883   for (int row=0 ; row<myEnforcedTableWidget->rowCount() ; row++) {
1884     
1885     TEnfVertex *myVertex = new TEnfVertex();
1886     myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1887     MESSAGE("Add new enforced vertex \"" << myVertex->name << "\"" );
1888     myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1889     if (myVertex->geomEntry.size())
1890       MESSAGE("Geom entry is \"" << myVertex->geomEntry << "\"" );
1891     myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1892     if (myVertex->groupName.size())
1893       MESSAGE("Group name is \"" << myVertex->groupName << "\"" );
1894     valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole);
1895     valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole);
1896     valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole);
1897     if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) {
1898       myVertex->coords.push_back(valueX.toDouble());
1899       myVertex->coords.push_back(valueY.toDouble());
1900       myVertex->coords.push_back(valueZ.toDouble());
1901       MESSAGE("Coords are (" << myVertex->coords.at(0) << ", "
1902                              << myVertex->coords.at(1) << ", "
1903                              << myVertex->coords.at(2) << ")");
1904     }
1905     myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble();
1906     MESSAGE("Size is " << myVertex->size);
1907     myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool();
1908     MESSAGE("Is compound ? " << myVertex->isCompound);
1909     h_data.myEnforcedVertices.insert(myVertex);
1910   }
1911   
1912   // Enforced meshes
1913   h_data.myEnforcedMeshes.clear();
1914
1915   for (int row=0 ; row<myEnforcedMeshTableWidget->rowCount() ; row++) {
1916     
1917     TEnfMesh *myEnfMesh = new TEnfMesh();
1918     myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1919     MESSAGE("Add new enforced mesh \"" << myEnfMesh->name << "\"" );
1920     myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1921     MESSAGE("Entry is \"" << myEnfMesh->entry << "\"" );
1922     myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1923     MESSAGE("Group name is \"" << myEnfMesh->groupName << "\"" );
1924     QComboBox* combo = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN));
1925     myEnfMesh->elementType = combo->currentIndex();
1926     MESSAGE("Element type: " << myEnfMesh->elementType);
1927     h_data.myEnforcedMeshes.insert(myEnfMesh);
1928     std::cout << "h_data.myEnforcedMeshes.size(): " << h_data.myEnforcedMeshes.size() << std::endl;
1929   }
1930
1931   return true;
1932 }
1933
1934 QString GHS3DPluginGUI_HypothesisCreator::caption() const
1935 {
1936   return tr( "GHS3D_TITLE" );
1937 }
1938
1939 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
1940 {
1941   return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
1942 }
1943
1944 QString GHS3DPluginGUI_HypothesisCreator::type() const
1945 {
1946   return tr( "GHS3D_HYPOTHESIS" );
1947 }
1948
1949 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
1950 {
1951   return "ghs3d_hypo_page.html";
1952 }