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