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