Salome HOME
#18963 Minimize compiler warnings
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2020  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 // ---
21 // File    : BLSURFPluginGUI_HypothesisCreator.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #include "BLSURFPluginGUI_HypothesisCreator.h"
28 #include "BLSURFPluginGUI_Dlg.h"
29 #include "BLSURFPlugin_Hypothesis.hxx"
30
31 #include <GeometryGUI.h>
32
33 #include <SMESHGUI_Dialog.h>
34 #include <SMESHGUI_HypothesesUtils.h>
35 #include <SMESHGUI_IdValidator.h>
36 #include <SMESHGUI_SpinBox.h>
37 #include <SMESHGUI_Utils.h>
38 #include <SMESH_Gen_i.hxx>
39 #include <SMESH_NumberFilter.hxx>
40 #include <StdMeshersGUI_SubShapeSelectorWdg.h>
41
42 #include <LightApp_SelectionMgr.h>
43 #include <SALOME_ListIO.hxx>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SalomeApp_Application.h>
48 #include <SalomeApp_Tools.h>
49
50 #include <QApplication>
51 #include <QCheckBox>
52 #include <QComboBox>
53 #include <QFrame>
54 #include <QGridLayout>
55 #include <QGroupBox>
56 #include <QHBoxLayout>
57 #include <QHeaderView>
58 #include <QLabel>
59 #include <QLineEdit>
60 #include <QMenu>
61 #include <QModelIndexList>
62 #include <QObject>
63 #include <QPushButton>
64 #include <QRadioButton>
65 #include <QSpinBox>
66 #include <QSplitter>
67 #include <QStandardItem>
68 #include <QStandardItemModel>
69 #include <QTabWidget>
70 #include <QTableWidget>
71 #include <QTreeWidget>
72 #include <QTreeWidgetItem>
73 #include <QVBoxLayout>
74
75 #include <TopoDS_Shape.hxx>
76 #include <TopoDS_Iterator.hxx>
77
78 #include <structmember.h> // Python
79
80 using namespace std;
81
82 enum {
83   STD_TAB = 0,
84   ADV_TAB,
85   SMP_TAB,
86   ENF_TAB,
87   PERIODICITY_TAB,
88   HYPERPATCH_TAB,
89   SMP_NAME_COLUMN =0,
90   SMP_SIZEMAP_COLUMN,
91   SMP_ENTRY_COLUMN,
92 //  SMP_DIST_COLUMN,
93   SMP_NB_COLUMNS,
94
95   // Adv tables
96   TBL_MESHING = 0, TBL_PRECAD, TBL_CUSTOM,
97
98   // Enforced vertices array columns
99   ENF_VER_NAME_COLUMN = 0,
100   ENF_VER_FACE_ENTRY_COLUMN,
101   ENF_VER_X_COLUMN,
102   ENF_VER_Y_COLUMN,
103   ENF_VER_Z_COLUMN,
104   ENF_VER_ENTRY_COLUMN,
105   ENF_VER_GROUP_COLUMN,
106   ENF_VER_NB_COLUMNS,
107 // Periodicity
108   PERIODICITY_OBJ_SOURCE_COLUMN = 0,
109   PERIODICITY_OBJ_TARGET_COLUMN,
110   PERIODICITY_P1_SOURCE_COLUMN,
111   PERIODICITY_P2_SOURCE_COLUMN,
112   PERIODICITY_P3_SOURCE_COLUMN,
113   PERIODICITY_P1_TARGET_COLUMN,
114   PERIODICITY_P2_TARGET_COLUMN,
115   PERIODICITY_P3_TARGET_COLUMN,
116   PERIODICITY_SHAPE_TYPE,
117
118 //  PERIODICITY_OBJ_SOURCE_COLUMN = 0,
119 //  PERIODICITY_ENTRY_SOURCE_COLUMN,
120 //  PERIODICITY_OBJ_TARGET_COLUMN,
121 //  PERIODICITY_ENTRY_TARGET_COLUMN,
122 //  PERIODICITY_P1_SOURCE_COLUMN,
123 //  PERIODICITY_P1_ENTRY_SOURCE_COLUMN,
124 //  PERIODICITY_P2_SOURCE_COLUMN,
125 //  PERIODICITY_P2_ENTRY_SOURCE_COLUMN,
126 //  PERIODICITY_P3_SOURCE_COLUMN,
127 //  PERIODICITY_P3_ENTRY_SOURCE_COLUMN,
128 //  PERIODICITY_P1_TARGET_COLUMN,
129 //  PERIODICITY_P1_ENTRY_TARGET_COLUMN,
130 //  PERIODICITY_P2_TARGET_COLUMN,
131 //  PERIODICITY_P2_ENTRY_TARGET_COLUMN,
132 //  PERIODICITY_P3_TARGET_COLUMN,
133 //  PERIODICITY_P3_ENTRY_TARGET_COLUMN,
134
135   PERIODICITY_NB_COLUMN
136 };
137
138 enum {
139   SMP_TAB_WDG,
140   SMP_ADD_BTN,
141   SMP_NB_LINES,
142   SMP_STD_TAB = 0,
143   ATT_TAB,
144   SMP_GEOM_BTN_2 = 0,
145   ATT_CHECK,
146   CONST_SIZE_CHECK,
147   SMP_SPACE,
148 //   SMP_PARAMS,
149   SMP_ATT_SHAPE, 
150   SMP_ATT_SIZE,
151   SMP_ATT_DIST,
152   SMP_ATT_RAD
153 };
154   
155 enum {
156   SMP_GEOM_BTN_1,
157   SMP_SIZE,
158   SMP_SPACE2,
159 };
160
161 // Enforced vertices inputs
162 enum {
163   ENF_VER_FACE = 0,
164   ENF_VER_VERTEX = 0,
165   ENF_VER_X_COORD,
166   ENF_VER_Y_COORD,
167   ENF_VER_Z_COORD,
168   ENF_VER_GROUP,
169 //   ENF_VER_GROUP_CHECK,
170 //   ENF_VER_SPACE,
171   ENF_VER_BTN,
172   ENF_VER_SEPARATOR,
173   ENF_VER_INTERNAL_ALL_FACES,
174   ENF_VER_INTERNAL_ALL_FACES_GROUP,
175 //   ENF_VER_VERTEX_BTN,
176 //   ENF_VER_REMOVE_BTN,
177 //   ENF_VER_SEPARATOR,
178   ENF_VER_NB_LINES
179 };
180
181
182 /**************************************************
183  Begin initialization Python structures and objects
184 ***************************************************/
185
186 namespace {
187   typedef struct {
188     PyObject_HEAD
189     int softspace;
190     std::string *out;
191     } PyStdOut;
192
193   static void
194   PyStdOut_dealloc(PyStdOut *self)
195   {
196     PyObject_Del(self);
197   }
198
199   static PyObject *
200   PyStdOut_write(PyStdOut *self, PyObject *args)
201   {
202     char *c;
203     int l;
204     if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
205       return NULL;
206
207     *(self->out)=*(self->out)+c;
208
209     Py_INCREF(Py_None);
210     return Py_None;
211   }
212
213   static PyMethodDef PyStdOut_methods[] = {
214     {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
215     PyDoc_STR("write(string) -> None")},
216     {0, 0, 0, 0}   /* sentinel */
217   };
218
219   static PyMemberDef PyStdOut_memberlist[] = {
220     {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
221      (char*)"flag indicating that a space needs to be printed; used by print"},
222     {0, 0, 0, 0, 0} /* Sentinel */
223   };
224
225   static PyTypeObject PyStdOut_Type = {
226     /* The ob_type field must be initialized in the module init function
227      * to be portable to Windows without using C++. */
228     PyVarObject_HEAD_INIT(NULL, 0)
229     "PyOut",                      /*tp_name*/
230     sizeof(PyStdOut),             /*tp_basicsize*/
231     0,                            /*tp_itemsize*/
232     /* methods */
233     (destructor)PyStdOut_dealloc, /*tp_dealloc*/
234     0,                            /*tp_print*/
235     0,                            /*tp_getattr*/
236     0,                            /*tp_setattr*/
237     0,                            /*tp_compare*/
238     0,                            /*tp_repr*/
239     0,                            /*tp_as_number*/
240     0,                            /*tp_as_sequence*/
241     0,                            /*tp_as_mapping*/
242     0,                            /*tp_hash*/
243     0,                            /*tp_call*/
244     0,                            /*tp_str*/
245     PyObject_GenericGetAttr,      /*tp_getattro*/
246     /* softspace is writable:  we must supply tp_setattro */
247     PyObject_GenericSetAttr,      /* tp_setattro */
248     0,                            /*tp_as_buffer*/
249     Py_TPFLAGS_DEFAULT,           /*tp_flags*/
250     0,                            /*tp_doc*/
251     0,                            /*tp_traverse*/
252     0,                            /*tp_clear*/
253     0,                            /*tp_richcompare*/
254     0,                            /*tp_weaklistoffset*/
255     0,                            /*tp_iter*/
256     0,                            /*tp_iternext*/
257     PyStdOut_methods,             /*tp_methods*/
258     PyStdOut_memberlist,          /*tp_members*/
259     0,                            /*tp_getset*/
260     0,                            /*tp_base*/
261     0,                            /*tp_dict*/
262     0,                            /*tp_descr_get*/
263     0,                            /*tp_descr_set*/
264     0,                            /*tp_dictoffset*/
265     0,                            /*tp_init*/
266     0,                            /*tp_alloc*/
267     0,                            /*tp_new*/
268     0,                            /*tp_free*/
269     0,                            /*tp_is_gc*/
270     0,                            /*tp_bases*/
271     0,                            /*tp_mro*/
272     0,                            /*tp_cache*/
273     0,                            /*tp_subclasses*/
274     0,                            /*tp_weaklist*/
275     0,                            /*tp_del*/
276     0,                            /*tp_version_tag*/
277     0,                            /*tp_finalize*/
278   };
279
280   PyObject * newPyStdOut( std::string& out )
281   {
282     PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type);
283     if (self) {
284       self->softspace = 0;
285       self->out=&out;
286     }
287     return (PyObject*)self;
288   }
289 }
290
291 /*************************************************
292 End initialization Python structures and objects
293 **************************************************/
294
295
296 //
297 // BEGIN EnforcedTreeWidgetDelegate
298 //
299
300 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
301   : QItemDelegate(parent)
302 {
303 }
304
305 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
306                                               const QStyleOptionViewItem & /*option*/ ,
307                                               const QModelIndex & index ) const
308 {
309   QModelIndex father = index.parent();
310   QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
311   
312   if (index.column() == ENF_VER_X_COLUMN || \
313       index.column() == ENF_VER_Y_COLUMN || \
314       index.column() == ENF_VER_Z_COLUMN)
315   {
316     SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
317     editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
318     editor->setReadOnly(!entry.isEmpty());
319     editor->setDisabled(!entry.isEmpty());
320     return editor;
321   }
322   else
323   {
324     QLineEdit *editor = new QLineEdit(parent);
325     if (index.column() != ENF_VER_GROUP_COLUMN) {
326       editor->setReadOnly(!entry.isEmpty());
327       editor->setDisabled(!entry.isEmpty());
328     }
329     return editor;
330   }
331 }
332
333 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
334                                            const QModelIndex &index) const
335 {
336   QString value = index.model()->data(index, Qt::EditRole).toString();
337
338   if (index.column() == ENF_VER_X_COLUMN ||
339       index.column() == ENF_VER_Y_COLUMN ||
340       index.column() == ENF_VER_Z_COLUMN)
341   {
342     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
343     lineEdit->setText(value);
344   }
345   else {
346     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
347     lineEdit->setText(value);
348   }
349 }
350
351 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
352                                           const QModelIndex &index) const
353 {
354   QModelIndex parent = index.parent();
355   QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
356   if (index.column() == ENF_VER_X_COLUMN || index.column() == ENF_VER_Y_COLUMN || index.column() == ENF_VER_Z_COLUMN) {
357     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
358     if (entry.isEmpty() && !vertexExists(model, index, lineEdit->GetString()))
359       model->setData(index, lineEdit->GetValue(), Qt::EditRole);
360   } else if (index.column() == ENF_VER_NAME_COLUMN) {
361     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
362     QString value = lineEdit->text();
363     if (entry.isEmpty() && !vertexExists(model, index, value))
364       model->setData(index, value, Qt::EditRole);
365   } else if (index.column() == ENF_VER_ENTRY_COLUMN) {
366     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
367     QString value = lineEdit->text();
368     if (!vertexExists(model, index, value))
369       model->setData(index, value, Qt::EditRole);
370   } else if (index.column() == ENF_VER_GROUP_COLUMN) {
371     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
372     model->setData(index, lineEdit->text(), Qt::EditRole);
373   }
374 }
375
376 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
377     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
378 {
379   editor->setGeometry(option.rect);
380 }
381
382 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
383     const QModelIndex &index, QString value) const
384 {
385   bool exists = false;
386   QModelIndex parent = index.parent();
387   int row = index.row();
388   int col = index.column();
389
390   if (parent.isValid() && !value.isEmpty()) {
391     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
392       double x, y, z;
393       if (col == ENF_VER_X_COLUMN) {
394         x = value.toDouble();
395         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
396         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
397       }
398       if (col == ENF_VER_Y_COLUMN) {
399         y = value.toDouble();
400         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
401         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
402       }
403       if (col == ENF_VER_Z_COLUMN) {
404         z = value.toDouble();
405         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
406         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
407       }
408       int nbChildren = model->rowCount(parent);
409       for (int i = 0 ; i < nbChildren ; i++) {
410         if (i != row) {
411           double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
412           double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
413           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
414           if ((childX == x) && (childY == y) && (childZ == z)) {
415             exists = true;
416             break;
417           }
418         }
419       }
420     }
421     else if (col == ENF_VER_NAME_COLUMN) {
422       int nbChildren = model->rowCount(parent);
423       for (int i = 0 ; i < nbChildren ; i++) {
424         if (i != row) {
425           QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
426           if (childName == value) {
427             exists = true;
428             break;
429           }
430         }
431       }
432     }
433   }
434
435   return exists;
436 }
437
438 //
439 // END EnforcedTreeWidgetDelegate
440 //
441
442
443 /**
444  * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
445  * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
446  *
447  * */
448 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
449   : SMESHGUI_GenericHypothesisCreator( theHypType )
450 {
451   this->mySMPMap.clear();
452
453   GeomToolSelected = NULL;
454   GeomToolSelected = getGeomSelectionTool();
455
456   aSel = GeomToolSelected->selectionMgr();
457
458   /* Initialize the Python interpreter */
459   if (! Py_IsInitialized())
460     throw ("Error: Python interpreter is not initialized");
461   PyGILState_STATE gstate;
462   gstate = PyGILState_Ensure();
463
464   main_mod = NULL;
465   main_mod = PyImport_AddModule("__main__");
466
467   main_dict = NULL;
468   main_dict = PyModule_GetDict(main_mod);
469
470   PyRun_SimpleString("from math import *");
471   PyGILState_Release(gstate);
472
473 }
474
475 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
476 {
477 }
478
479 /**
480  * \brief {Get or create the geom selection tool for active study}
481  * */
482 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool() const
483 {
484   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
485   if (that->GeomToolSelected == NULL) {
486     that->GeomToolSelected = new GeomSelectionTools();
487   }
488   return that->GeomToolSelected;
489 }
490
491 GEOM::GEOM_Gen_var BLSURFPluginGUI_HypothesisCreator::getGeomEngine()
492 {
493   return GeometryGUI::GetGeomGen();
494 }
495
496 void BLSURFPluginGUI_HypothesisCreator::avoidSimultaneousSelection(ListOfWidgets &selectionWidgets) const
497 {
498   StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
499   ListOfWidgets::const_iterator anIt = selectionWidgets.begin();
500   for ( ; anIt != selectionWidgets.end(); anIt++)
501     {
502       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
503         {
504           StdMeshersGUI_ObjectReferenceParamWdg * w1 =
505               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
506           ListOfWidgets::const_iterator anIt2 = anIt;
507           for ( ++anIt2; anIt2 != selectionWidgets.end(); anIt2++)
508             if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
509               {
510                 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
511                     ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
512                 w1->AvoidSimultaneousSelection( w2 );
513               }
514           if ( !widgetToActivate )
515             widgetToActivate = w1;
516         }
517     }
518   if ( widgetToActivate )
519     widgetToActivate->activateSelection();
520 }
521
522 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
523 {
524   bool ok = true;
525
526   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
527     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
528
529   if ( ok )
530   {
531     myAdvWidget->myOptionTable->setFocus();
532     QApplication::instance()->processEvents();
533
534     QString name, value;
535     bool isDefault;
536     int iTbl = 0, nbTbl = myAdvWidget->myOptionTable->topLevelItemCount();
537     for ( ; iTbl < nbTbl; ++iTbl )
538     {
539       QTreeWidgetItem* table = myAdvWidget->myOptionTable->topLevelItem( iTbl );
540       int nbRows = table->childCount();
541       for ( int iRow = 0; iRow < nbRows; ++iRow )
542       {
543         QTreeWidgetItem* row = table->child( iRow );
544         myAdvWidget->GetOptionAndValue( row, name, value, isDefault );
545
546         if ( name.simplified().isEmpty() )
547           continue; // invalid custom option
548
549         if ( isDefault ) // not selected option
550           value.clear();
551
552         try {
553           switch ( iTbl )
554           {
555           case TBL_MESHING:
556             h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
557             break;
558           case TBL_PRECAD:
559             h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
560             break;
561           case TBL_CUSTOM:
562             h->AddOption( name.toLatin1().constData(), value.toLatin1().constData() );
563             break;
564           }
565         }
566         catch ( const SALOME::SALOME_Exception& ex )
567         {
568           msg = ex.details.text.in();
569           ok = false;
570           break;
571         }
572       }
573     }
574   }
575
576   // SizeMap and attractors
577   if ( ok )
578   {
579     mySizeMapTable->setFocus();
580     QApplication::instance()->processEvents();
581
582     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
583     int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
584     std::string e, s;
585     for ( ; row < nbRows; ++row )
586     {
587       QString entry   = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
588       QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
589       if ( !sizeMap.isEmpty() ) {
590         if (that->sizeMapValidationFromRow(row))
591         {
592           try {
593             e = entry.toStdString();
594             s = that->mySMPMap[entry].toStdString();
595             //h->SetSizeMapEntry( e.c_str(), s.c_str() );
596           }
597           catch ( const SALOME::SALOME_Exception& ex )
598           {
599             msg = ex.details.text.in();
600             ok = false;
601           }
602         }
603         else {
604           ok = false;
605         }
606       }
607     }
608   }
609
610   // 22207: BLSURFPLUGIN: The user is allowed to enter 0 as a global or local size.
611   if ( ok )
612   {
613     // In case if not STD_TAB is current tab, then text() of empty spinboxes returns "0" value.
614     // So STD_TAB must be current tab to get correct value of it's spinbox.
615     myTabWidget->setCurrentIndex( STD_TAB );
616   }
617   if ( ok )
618   {
619     if ( !( ok = ( myStdWidget->myPhySize->text().isEmpty() ||
620                    myStdWidget->myPhySize->text().toDouble() > 0.0 )))
621       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_HPHYDEF"));
622   }
623   if ( ok )
624   {
625     if ( !( ok = ( myStdWidget->myMaxSize->text().isEmpty() ||
626                    myStdWidget->myMaxSize->text().toDouble() > 0.0 )))
627       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_MAXSIZE"));
628   }
629   if ( ok )
630   {
631     if ( !( ok = ( myStdWidget->myAngleMesh->text().isEmpty() ||
632                    myStdWidget->myAngleMesh->text().toDouble() > 0.0 )))
633       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_ANGLE_MESH"));
634   }
635   if ( ok )
636   {
637     if ( !( ok = ( myStdWidget->myChordalError->text().isEmpty() ||
638                    myStdWidget->myChordalError->text().toDouble() > 0.0 )))
639       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_CHORDAL_ERROR"));
640   }
641
642   // #16954 EDF 19466 - localsize
643   // Warn the user if local size is less than Min Size
644   if ( ok &&
645        !myStdWidget->myMinSizeRel->isChecked() &&
646        !myStdWidget->myMinSize->text().isEmpty() )
647   {
648     const double minSize = myStdWidget->myMinSize->GetValue();
649     bool isValue;
650     for ( QMapIterator<QString,QString> i( mySMPMap ); i.hasNext() &&  ok ; )
651     {
652       i.next();
653       double size = i.value().toDouble( &isValue );
654       ok = ( !isValue || size >= minSize );
655     }
656     for ( QMapIterator<QString, TAttractorVec > i( myATTMap ); i.hasNext() &&  ok ; )
657     {
658       i.next();
659       const TAttractorVec& attVec = i.value();
660       for ( size_t i = 0; i < attVec.size(); ++i )
661         ok = ( attVec[i].IsToDelete()  || attVec[i].startSize >= minSize );
662     }
663     if ( !ok )
664       msg = tr( "TOO_SMALL_LOCAL_SIZE" );
665   }
666   // Warn the user if local size is more than User Size
667   if ( ok &&
668        !myStdWidget->myPhySizeRel->isChecked() &&
669        !myStdWidget->myPhySize->text().isEmpty() )
670   {
671     const double userSize = myStdWidget->myPhySize->GetValue();
672     bool isValue;
673     for ( QMapIterator<QString,QString> i( mySMPMap ); i.hasNext() &&  ok ; )
674     {
675       i.next();
676       double size = i.value().toDouble( &isValue );
677       ok = ( !isValue || size <= userSize );
678     }
679     for ( QMapIterator<QString, TAttractorVec > i( myATTMap ); i.hasNext() &&  ok ; )
680     {
681       i.next();
682       const TAttractorVec& attVec = i.value();
683       for ( size_t i = 0; i < attVec.size(); ++i )
684         ok = ( attVec[i].IsToDelete()  || attVec[i].startSize <= userSize );
685     }
686     if ( !ok )
687       msg = tr( "TOO_LARGE_LOCAL_SIZE" );
688   }
689
690   // Enforced vertices
691   // TODO
692
693   if ( !ok )
694   {
695     h->SetOptionValues( myOptions ); // restore values
696     h->SetPreCADOptionValues( myPreCADOptions ); // restore values
697   }
698
699   return ok;
700 }
701
702 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
703 {
704   QFrame* fr = new QFrame( 0 );
705   QVBoxLayout* lay = new QVBoxLayout( fr );
706   lay->setMargin( 5 );
707   lay->setSpacing( 0 );
708
709   // main TabWidget of the dialog
710   myTabWidget = new QTabWidget( fr );
711   myTabWidget->setTabShape( QTabWidget::Rounded );
712   myTabWidget->setTabPosition( QTabWidget::North );
713   lay->addWidget( myTabWidget );
714
715   myName = 0;
716   
717   // basic parameters
718   myStdGroup = new QWidget();
719   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
720   aStdLayout->setSpacing( 6 );
721   aStdLayout->setMargin( 11 );
722   
723   if( isCreation() )
724     myName = new QLineEdit( myStdGroup );
725   myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
726   if ( !hasGeom() ) {
727     myStdWidget->myPhysicalMesh->removeItem( PhysicalLocalSize );
728   }
729   
730   int row = 0;
731   if( isCreation() ) {
732     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ),    0, 0, 1, 1 );
733     aStdLayout->addWidget( myName,                                      row++, 1, 1, 3 );
734   }
735   aStdLayout->addWidget( myStdWidget,                                   row++, 0, 1, 4 );
736   
737   row = 0;
738   if( isCreation() )
739     row = 1;
740   aStdLayout->setRowStretch(row,1);
741   aStdLayout->setColumnStretch(1,1);
742
743   
744   // advanced parameters
745   myAdvGroup = new QWidget();
746   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
747   anAdvLayout->setSpacing( 6 );
748   anAdvLayout->setMargin( 11 );  
749   myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
750   anAdvLayout->addWidget( myAdvWidget );
751
752
753   // Size Maps parameters
754
755   mySmpGroup = new QWidget( dlg() );
756
757   //Layout
758   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
759   
760   // Table
761   mySizeMapTable = new QTreeWidget( mySmpGroup );
762   mySizeMapTable ->setMinimumWidth(200);
763   QStringList sizeMapHeaders;
764   sizeMapHeaders << tr( "SMP_NAME_COLUMN" )<< tr( "SMP_SIZEMAP_COLUMN" )<< tr( "SMP_ENTRY_COLUMN" );// << tr( "SMP_DIST_COLUMN" );
765   mySizeMapTable->setHeaderLabels(sizeMapHeaders);
766   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
767   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
768   mySizeMapTable->hideColumn(SMP_ENTRY_COLUMN);
769   mySizeMapTable->setAlternatingRowColors(true);
770   
771   // tab widget
772   smpTab = new QTabWidget( mySmpGroup );
773   smpTab->setTabShape( QTabWidget::Rounded );
774   smpTab->setTabPosition( QTabWidget::South );
775   lay->addWidget( smpTab );
776   
777   // Filters of selection
778   TColStd_MapOfInteger SM_ShapeTypes, ATT_ShapeTypes;
779   
780   SM_ShapeTypes.Add( TopAbs_VERTEX );
781   SM_ShapeTypes.Add( TopAbs_EDGE );
782   SM_ShapeTypes.Add( TopAbs_FACE );
783   SM_ShapeTypes.Add( TopAbs_COMPOUND );
784   
785   ATT_ShapeTypes.Add( TopAbs_VERTEX );
786   ATT_ShapeTypes.Add( TopAbs_EDGE );
787   ATT_ShapeTypes.Add( TopAbs_WIRE );
788   ATT_ShapeTypes.Add( TopAbs_COMPOUND );
789   
790   SMESH_NumberFilter* myFilter1 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
791   SMESH_NumberFilter* myFilter2 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, ATT_ShapeTypes);
792   SMESH_NumberFilter* myFilter3 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, TopAbs_FACE);
793   
794   // Standard size map tab
795   mySmpStdGroup = new QWidget();
796   QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
797   myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false);
798   myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
799   mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
800   mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
801   QLabel* mySmpSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),mySmpStdGroup);
802   
803   // Attractor tab
804   myAttractorGroup = new QWidget();
805   QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
806   myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false);
807   myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
808   myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
809   myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
810   myConstSizeCheck = new QCheckBox(tr("BLSURF_CONST_SIZE"),myAttractorGroup);
811   QFrame* attLine  = new QFrame(myAttractorGroup);
812   attLine->setFrameShape(QFrame::HLine);
813   attLine->setFrameShadow(QFrame::Sunken);
814   myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false);
815   myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }"); 
816   myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
817   myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
818   myAttSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),myAttractorGroup);
819   myAttDistSpin = new SMESHGUI_SpinBox(myAttractorGroup);
820   myAttDistSpin->RangeStepAndValidator(0., COORD_MAX, 10.0, "length_precision");
821   myAttDistLabel = new QLabel(tr("BLSURF_ATT_DIST"),myAttractorGroup);
822   myAttDistSpin2 = new SMESHGUI_SpinBox(myAttractorGroup);
823   myAttDistSpin2->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
824   myAttDistLabel2 = new QLabel(tr("BLSURF_ATT_RADIUS"),myAttractorGroup);
825   
826   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
827   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
828   
829   // Push buttons
830   
831   addMapButton = new QPushButton(tr("BLSURF_SM_ADD"),mySmpGroup);
832   removeMapButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
833   modifyMapButton = new QPushButton(tr("BLSURF_SM_MODIFY"),mySmpGroup);
834   modifyMapButton->setEnabled(false);
835   
836   // Init SpinBoxes
837   myAttSelWdg->setEnabled(false);
838   myAttSizeSpin->setEnabled(false);
839   myAttSizeLabel->setEnabled(false);
840   myAttDistSpin->setEnabled(false);
841   myAttDistLabel->setEnabled(false);
842   myAttDistSpin2->setEnabled(false);
843   myAttDistLabel2->setEnabled(false);
844   myAttDistSpin->setValue(0.);
845   myAttDistSpin2->setValue(0.);
846   myAttSizeSpin->setValue(0.);
847   mySmpSizeSpin->setValue(0.);
848
849   
850   // ADD WIDGETS (SIZEMAP TAB)
851   anSmpLayout->addWidget(mySizeMapTable,     0,  0, SMP_NB_LINES, 1);
852   anSmpLayout->setColumnStretch(0, 1);
853 //  anSmpLayout->addWidget(line2,              SMP_SEPARATOR2, 1, 2, 2);
854   anSmpLayout->addWidget(smpTab,             SMP_TAB_WDG,     1, 1, 3);
855   anSmpLayout->setRowStretch(SMP_TAB_WDG, 1);
856   anSmpLayout->addWidget(addMapButton,       SMP_ADD_BTN,     1, 1, 1);
857   anSmpLayout->addWidget(removeMapButton,    SMP_ADD_BTN,     2, 1, 1);
858   anSmpLayout->addWidget(modifyMapButton,    SMP_ADD_BTN,     3, 1, 1);
859   
860   // STANDARD TAB
861   anSmpStdLayout->addWidget(myGeomSelWdg1,   SMP_GEOM_BTN_1,  1, 1, 2);
862   anSmpStdLayout->addWidget(mySmpSizeLabel,  SMP_SIZE,        1, 1, 1);
863   anSmpStdLayout->addWidget(mySmpSizeSpin,   SMP_SIZE,        2, 1, 1);
864   anSmpStdLayout->setRowStretch(SMP_SPACE2, 1);
865   
866   // ADVANCED TAB
867   anAttLayout->addWidget(myGeomSelWdg2,      SMP_GEOM_BTN_2,  1, 1, 2);
868   anAttLayout->addWidget(myAttractorCheck,   ATT_CHECK,       1, 1, 2);
869   anAttLayout->addWidget(myConstSizeCheck,   CONST_SIZE_CHECK,1, 1, 2);
870   anAttLayout->addWidget(attLine,            SMP_SPACE,       1, 1, 2);
871   anAttLayout->addWidget(myAttSelWdg,        SMP_ATT_SHAPE,   1, 1, 2);
872   anAttLayout->addWidget(myAttSizeLabel,     SMP_ATT_SIZE,    1, 1, 1);
873   anAttLayout->addWidget(myAttSizeSpin,      SMP_ATT_SIZE,    2, 1, 1);
874   anAttLayout->addWidget(myAttDistLabel,     SMP_ATT_DIST,    1, 1, 1);
875   anAttLayout->addWidget(myAttDistSpin,      SMP_ATT_DIST,    2, 1, 1);
876   anAttLayout->addWidget(myAttDistLabel2,    SMP_ATT_RAD,     1, 1, 1);
877   anAttLayout->addWidget(myAttDistSpin2,     SMP_ATT_RAD,     2, 1, 1);
878   anAttLayout->setRowStretch(SMP_ATT_RAD+1, 1);
879   
880   smpTab->insertTab( SMP_STD_TAB, mySmpStdGroup, tr( "BLSURF_SM_STD_TAB" ) );
881   smpTab->insertTab( ATT_TAB, myAttractorGroup, tr( "BLSURF_SM_ATT_TAB" ) );
882
883   smpTab->setCurrentIndex( SMP_STD_TAB ); 
884
885   // Enforced vertices parameters
886   myEnfGroup = new QWidget( dlg() );
887   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
888
889   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
890   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
891   myEnforcedTreeWidget->setSortingEnabled(true);
892   QStringList enforcedHeaders;
893   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_FACE_ENTRY_COLUMN")
894                   << tr("BLSURF_ENF_VER_X_COLUMN")<< tr("BLSURF_ENF_VER_Y_COLUMN") << tr("BLSURF_ENF_VER_Z_COLUMN")
895                   << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
896
897   myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
898   myEnforcedTreeWidget->header()->setStretchLastSection(true);
899   myEnforcedTreeWidget->setAlternatingRowColors(true);
900   myEnforcedTreeWidget->setUniformRowHeights(true);
901   myEnforcedTreeWidget->setAnimated(true);
902   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
903   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
904   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
905     myEnforcedTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
906     myEnforcedTreeWidget->resizeColumnToContents(column);
907   }
908   myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
909   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
910   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
911   
912   // FACE AND VERTEX SELECTION
913   TColStd_MapOfInteger shapeTypes1, shapeTypes2;
914   shapeTypes1.Add( TopAbs_FACE );
915   shapeTypes1.Add( TopAbs_COMPOUND );
916   shapeTypes2.Add( TopAbs_VERTEX );
917   shapeTypes2.Add( TopAbs_COMPOUND );
918
919   // SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
920   // myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true);
921   // myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
922
923   SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
924   myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true);
925   myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
926
927   //myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
928
929   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
930   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
931   myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
932
933   QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
934   myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
935   myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
936
937   QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
938   myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
939   myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
940
941   QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
942   myGroupName = new QLineEdit(myEnfGroup);
943
944   addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
945   removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
946
947   myInternalEnforcedVerticesAllFaces = new QCheckBox(tr("BLSURF_ENF_VER_INTERNAL_VERTICES"),myEnfGroup);
948
949   QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
950   myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
951
952   anEnfLayout->addWidget(myEnforcedTreeWidget,     0, 0, ENF_VER_NB_LINES, 1);
953   QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
954 //  FACE AND VERTEX SELECTION
955   //anEnfLayout2->addWidget(myEnfFaceWdg,             ENF_VER_FACE, 0, 1, 2);
956   anEnfLayout2->addWidget(myEnfVertexWdg,           ENF_VER_VERTEX, 0, 1, 2);
957   anEnfLayout2->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 0, 1, 1);
958   anEnfLayout2->addWidget(myXCoord,                 ENF_VER_X_COORD, 1, 1, 1);
959   anEnfLayout2->addWidget(myYCoordLabel,            ENF_VER_Y_COORD, 0, 1, 1);
960   anEnfLayout2->addWidget(myYCoord,                 ENF_VER_Y_COORD, 1, 1, 1);
961   anEnfLayout2->addWidget(myZCoordLabel,            ENF_VER_Z_COORD, 0, 1, 1);
962   anEnfLayout2->addWidget(myZCoord,                 ENF_VER_Z_COORD, 1, 1, 1);
963   anEnfLayout2->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 0, 1, 1);
964   anEnfLayout2->addWidget(myGroupName,              ENF_VER_GROUP, 1, 1, 1);
965   anEnfLayout2->addWidget(addVertexButton,          ENF_VER_BTN, 0, 1, 1);
966   anEnfLayout2->addWidget(removeVertexButton,       ENF_VER_BTN, 1, 1, 1);
967   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
968   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
969   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
970   anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
971   anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
972
973   // ---
974   // Periodicity parameters
975   myPeriodicityGroup = new QWidget( dlg() );
976   aPeriodicityLayout1 = new QGridLayout(myPeriodicityGroup);
977
978   myPeriodicitySplitter = new QSplitter(myPeriodicityGroup);
979   myPeriodicitySplitter->setOrientation(Qt::Horizontal);
980   aPeriodicityLayout1->addWidget(myPeriodicitySplitter, 0, 0, 1, 1);
981
982   myPeriodicityTreeWidget = new QTreeWidget(myPeriodicitySplitter);
983
984   QStringList myPeriodicityTreeHeaders;
985   myPeriodicityTreeHeaders << tr("BLSURF_PERIODICITY_OBJ_SOURCE_COLUMN")
986                            << tr("BLSURF_PERIODICITY_OBJ_TARGET_COLUMN")
987                            << tr("BLSURF_PERIODICITY_P1_SOURCE_COLUMN")
988                            << tr("BLSURF_PERIODICITY_P2_SOURCE_COLUMN")
989                            << tr("BLSURF_PERIODICITY_P3_SOURCE_COLUMN")
990                            << tr("BLSURF_PERIODICITY_P1_TARGET_COLUMN")
991                            << tr("BLSURF_PERIODICITY_P2_TARGET_COLUMN")
992                            << tr("BLSURF_PERIODICITY_P3_TARGET_COLUMN")
993                            << tr("BLSURF_PERIODICITY_SHAPE_TYPE");
994   myPeriodicityTreeWidget->setHeaderLabels(myPeriodicityTreeHeaders);
995
996   // Hide the vertex name to make the widget more readable
997   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P1_SOURCE_COLUMN);
998   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P2_SOURCE_COLUMN);
999   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P3_SOURCE_COLUMN);
1000   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P1_TARGET_COLUMN);
1001   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P2_TARGET_COLUMN);
1002   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P3_TARGET_COLUMN);
1003   myPeriodicityTreeWidget->hideColumn(PERIODICITY_SHAPE_TYPE);
1004
1005
1006   myPeriodicityTreeWidget->setColumnCount(PERIODICITY_NB_COLUMN);
1007   myPeriodicityTreeWidget->setSortingEnabled(true);
1008
1009   myPeriodicityTreeWidget->setAlternatingRowColors(true);
1010   myPeriodicityTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
1011   myPeriodicityTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
1012   
1013   size_t periodicityVisibleColumns = 2;
1014   for (size_t column = 0; column < periodicityVisibleColumns; ++column) {
1015       myPeriodicityTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
1016       myPeriodicityTreeWidget->resizeColumnToContents(column);
1017   }
1018   myPeriodicityTreeWidget->header()->setStretchLastSection(true);
1019
1020   myPeriodicitySplitter->addWidget(myPeriodicityTreeWidget);
1021
1022   myPeriodicityRightWidget = new QWidget(myPeriodicitySplitter);
1023
1024   myPeriodicityRightGridLayout = new QGridLayout(myPeriodicityRightWidget);
1025   myPeriodicityGroupBox1 = new QGroupBox(tr("BLSURF_PRECAD_PERIODICITY"), myPeriodicityRightWidget);
1026   myPeriodicityGroupBox1Layout = new QGridLayout(myPeriodicityGroupBox1);
1027
1028   myPeriodicityRightGridLayout->addWidget(myPeriodicityGroupBox1, 0, 0, 1, 2);
1029
1030   myPeriodicityOnFaceRadioButton = new QRadioButton(tr("BLSURF_PERIODICITY_ON_FACE"), myPeriodicityGroupBox1);
1031   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityOnFaceRadioButton, 0, 0, 1, 2);
1032
1033   myPeriodicityOnFaceRadioButton->setChecked(true);
1034
1035   myPeriodicityOnEdgeRadioButton = new QRadioButton(tr("BLSURF_PERIODICITY_ON_EDGE"), myPeriodicityGroupBox1);
1036   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityOnEdgeRadioButton, 0, 2, 1, 2);
1037
1038
1039   // FACE, EDGE AND VERTEX SELECTION
1040   TColStd_MapOfInteger shapeTypesFace, shapeTypesEdge;
1041   shapeTypesFace.Add( TopAbs_FACE );
1042   shapeTypesFace.Add( TopAbs_EDGE );
1043   shapeTypesFace.Add( TopAbs_COMPOUND );
1044   shapeTypesEdge.Add( TopAbs_EDGE );
1045   shapeTypesEdge.Add( TopAbs_COMPOUND );
1046
1047 //  myPeriodicityEdgeFilter = new SMESH_NumberFilter("GEOM", TopAbs_EDGE, 0, shapeTypesEdge);
1048
1049   myPeriodicityMainSourceLabel = new QLabel(tr("BLSURF_PERIODICITY_MAIN_SOURCE"), myPeriodicityGroupBox1);
1050   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainSourceLabel, 1, 0, 1, 1);
1051
1052   SMESH_NumberFilter* myPeriodicitySourceFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
1053   myPeriodicitySourceFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicitySourceFaceFilter, 0, /*multiSel=*/false);
1054 //  myPeriodicitySourceFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
1055   myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceFaceWdg, 1, 1, 1, 1);
1056
1057 //  myPeriodicitySourceEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false);
1058 //  myPeriodicitySourceEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
1059 //  myPeriodicitySourceEdgeWdg->hide();
1060 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceEdgeWdg, 1, 1, 1, 1);
1061
1062   myPeriodicityMainTargetLabel = new QLabel(tr("BLSURF_PERIODICITY_MAIN_TARGET"), myPeriodicityGroupBox1);
1063   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainTargetLabel, 1, 2, 1, 1);
1064
1065   SMESH_NumberFilter* myPeriodicityTargetFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
1066   myPeriodicityTargetFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityTargetFaceFilter, 0, /*multiSel=*/false);
1067 //  myPeriodicityTargetFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
1068   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetFaceWdg, 1, 3, 1, 1);
1069
1070 //  myPeriodicityTargetEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false);
1071 //  myPeriodicityTargetEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
1072 //  myPeriodicityTargetEdgeWdg->hide();
1073 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetEdgeWdg, 1, 3, 1, 1);
1074
1075   myPeriodicityGroupBox2 = new QGroupBox(tr("BLSURF_PERIODICITY_WITH_VERTICES"), myPeriodicityRightWidget);
1076   myPeriodicityGroupBox2Layout = new QGridLayout(myPeriodicityGroupBox2);
1077   myPeriodicityRightGridLayout->addWidget(myPeriodicityGroupBox2, 1, 0, 1, 2);
1078
1079   myPeriodicityGroupBox2->setCheckable(true);
1080   myPeriodicityGroupBox2->setChecked(false);
1081
1082   myPeriodicitySourceLabel = new QLabel(tr("BLSURF_PERIODICITY_SOURCE"), myPeriodicityGroupBox2);
1083   myPeriodicityGroupBox2Layout->addWidget(myPeriodicitySourceLabel, 0, 0, 1, 2);
1084
1085   myPeriodicityTargetLabel = new QLabel(tr("BLSURF_PERIODICITY_TARGET"), myPeriodicityGroupBox2);
1086   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityTargetLabel, 0, 2, 1, 2);
1087
1088   // P1
1089   myPeriodicityP1SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P1_SOURCE"), myPeriodicityGroupBox2);
1090   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1SourceLabel, 1, 0, 1, 1);
1091
1092
1093   SMESH_NumberFilter* myPeriodicityP1SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1094   myPeriodicityP1SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1SourceFilter, 0, /*multiSel=*/false);
1095   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1SourceWdg, 1, 1, 1, 1);
1096
1097   // P2
1098   myPeriodicityP2SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P2_SOURCE"), myPeriodicityGroupBox2);
1099   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceLabel, 2, 0, 1, 1);
1100
1101   SMESH_NumberFilter* myPeriodicityP2SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1102   myPeriodicityP2SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2SourceFilter, 0, /*multiSel=*/false);
1103   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceWdg, 2, 1, 1, 1);
1104
1105   // P3
1106   myPeriodicityP3SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P3_SOURCE"), myPeriodicityGroupBox2);
1107   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceLabel, 3, 0, 1, 1);
1108
1109   SMESH_NumberFilter* myPeriodicityP3SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1110   myPeriodicityP3SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3SourceFilter, 0, /*multiSel=*/false);
1111   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceWdg, 3, 1, 1, 1);
1112
1113   // P1
1114   myPeriodicityP1TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P1_TARGET"), myPeriodicityGroupBox2);
1115   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetLabel, 1, 2, 1, 1);
1116
1117   SMESH_NumberFilter* myPeriodicityP1TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1118   myPeriodicityP1TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1TargetFilter, 0, /*multiSel=*/false);
1119   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetWdg, 1, 3, 1, 1);
1120
1121   // P2
1122   myPeriodicityP2TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P2_TARGET"), myPeriodicityGroupBox2);
1123   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetLabel, 2, 2, 1, 1);
1124
1125   SMESH_NumberFilter* myPeriodicityP2TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1126   myPeriodicityP2TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2TargetFilter, 0, /*multiSel=*/false);
1127   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetWdg, 2, 3, 1, 1);
1128
1129   // P3
1130   myPeriodicityP3TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P3_TARGET"), myPeriodicityGroupBox2);
1131   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetLabel, 3, 2, 1, 1);
1132
1133   SMESH_NumberFilter* myPeriodicityP3TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1134   myPeriodicityP3TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3TargetFilter, 0, /*multiSel=*/false);
1135   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetWdg, 3, 3, 1, 1);
1136
1137   myPeriodicityVerticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
1138   myPeriodicityGroupBox2Layout->addItem(myPeriodicityVerticalSpacer, 7, 1, 1, 1);
1139
1140
1141   myPeriodicityAddButton = new QPushButton(tr("BLSURF_PERIODICITY_ADD"),myPeriodicityRightWidget);
1142   myPeriodicityRightGridLayout->addWidget(myPeriodicityAddButton, 2, 0, 1, 1);
1143
1144   myPeriodicityRemoveButton = new QPushButton(tr("BLSURF_PERIODICITY_REMOVE"),myPeriodicityRightWidget);
1145   myPeriodicityRightGridLayout->addWidget(myPeriodicityRemoveButton, 2, 1, 1, 1);
1146
1147   myPeriodicitySplitter->addWidget(myPeriodicityRightWidget);
1148
1149   myPeriodicitySelectionWidgets.clear();
1150   myPeriodicitySelectionWidgets.append(myPeriodicitySourceFaceWdg);
1151   myPeriodicitySelectionWidgets.append(myPeriodicityTargetFaceWdg);
1152   myPeriodicitySelectionWidgets.append(myPeriodicityP1SourceWdg);
1153   myPeriodicitySelectionWidgets.append(myPeriodicityP2SourceWdg);
1154   myPeriodicitySelectionWidgets.append(myPeriodicityP3SourceWdg);
1155   myPeriodicitySelectionWidgets.append(myPeriodicityP1TargetWdg);
1156   myPeriodicitySelectionWidgets.append(myPeriodicityP2TargetWdg);
1157   myPeriodicitySelectionWidgets.append(myPeriodicityP3TargetWdg);
1158   avoidSimultaneousSelection(myPeriodicitySelectionWidgets);
1159
1160   // HyperPatch parameters
1161
1162   QWidget*      hpGroup = new QWidget();
1163   QGridLayout* hpLayout = new QGridLayout(hpGroup);
1164
1165   myHyPatchTable = new QTableWidget( hpGroup );
1166   myHyPatchTable->setColumnCount(1);
1167   myHyPatchTable->setHorizontalHeaderLabels( QStringList() << tr("BLSURF_HYPATCH_TBL_HEADER") );
1168   myHyPatchTable->setAlternatingRowColors(true);
1169   myHyPatchTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
1170
1171
1172   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1173   myHyPatchFaceSelBtn  = new QPushButton( iconSelect, tr("BLSURF_HYPATCH_SEL_FACE"), hpGroup );
1174   myHyPatchGroupSelBtn = new QPushButton( iconSelect, tr("BLSURF_HYPATCH_SEL_GROUP"), hpGroup );
1175   myHyPatchFaceSelBtn->setCheckable( true );
1176   myHyPatchGroupSelBtn->setCheckable( true );
1177
1178   myHyPatchFaceSelector = new StdMeshersGUI_SubShapeSelectorWdg( hpGroup, TopAbs_FACE, /*toShowList=*/false );
1179
1180   QLabel* hpTagsLbl = new QLabel( tr("BLSURF_TAGS"), hpGroup );
1181   myHyPatchTagsLE   = new QLineEdit( hpGroup );
1182   myHyPatchTagsLE->setValidator( new SMESHGUI_IdValidator( hpGroup ));
1183
1184   QPushButton* hpAddBtn = new QPushButton( tr("BLSURF_SM_ADD"), hpGroup );
1185   QPushButton* hpRemBtn = new QPushButton( tr("BLSURF_SM_REMOVE"), hpGroup );
1186
1187   hpLayout->addWidget( myHyPatchTable,        0, 0, 5, 1 );
1188   hpLayout->addWidget( myHyPatchFaceSelBtn,   0, 1, 1, 2 );
1189   hpLayout->addWidget( myHyPatchGroupSelBtn,  0, 3, 1, 2 );
1190   hpLayout->addWidget( hpTagsLbl,             1, 1, 1, 1 );
1191   hpLayout->addWidget( myHyPatchTagsLE,       1, 2, 1, 3 );
1192   hpLayout->addWidget( hpAddBtn,              2, 1, 1, 2 );
1193   hpLayout->addWidget( hpRemBtn,              2, 3, 1, 2 );
1194   hpLayout->addWidget( myHyPatchFaceSelector, 3, 1, 1, 4 );
1195
1196
1197
1198   // ---
1199   myTabWidget->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
1200   myTabWidget->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
1201   if ( hasGeom() ) {
1202     myTabWidget->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
1203     myTabWidget->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
1204     myTabWidget->insertTab( PERIODICITY_TAB, myPeriodicityGroup, tr( "BLSURF_PERIODICITY" ) );
1205     myTabWidget->insertTab( HYPERPATCH_TAB, hpGroup, tr( "BLSURF_HYPERPATCH_TAB" ));
1206   }
1207   else
1208   {
1209     mySmpGroup->hide();
1210     myEnfGroup->hide();
1211     myPeriodicityGroup->hide();
1212     hpGroup->hide();
1213   }
1214   myTabWidget->setCurrentIndex( STD_TAB );
1215
1216   connect( myAdvWidget->addBtn, SIGNAL( clicked() ),           this, SLOT( onAddOption() ) );
1217
1218   // Size Maps
1219   connect( addMapButton,        SIGNAL( clicked()),                    this,         SLOT( onAddMap() ) );
1220   connect( removeMapButton,     SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
1221   connect( modifyMapButton,     SIGNAL( clicked()),                    this,         SLOT( onModifyMap() ) );
1222   connect( mySizeMapTable,      SIGNAL( itemClicked (QTreeWidgetItem *, int)),this,  SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
1223   connect( myGeomSelWdg2,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1224   connect( myGeomSelWdg1,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1225   connect( myAttSelWdg,         SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1226   connect( mySizeMapTable,      SIGNAL( itemChanged (QTreeWidgetItem *, int)),this,  SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
1227   connect( myAttractorCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onAttractorClicked( int ) ) );
1228   connect( myConstSizeCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onConstSizeClicked( int ) ) );
1229   connect( smpTab,              SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
1230   connect( myTabWidget,         SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
1231
1232   // Enforced vertices
1233   connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this,  SLOT( synchronizeCoords() ) );
1234   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
1235   connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),      this,         SLOT( synchronizeCoords() ) );
1236   connect( addVertexButton,     SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
1237   connect( removeVertexButton,  SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
1238   connect( myEnfVertexWdg,      SIGNAL( contentModified()),            this,         SLOT( onSelectEnforcedVertex() ) );
1239   connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this,  SLOT( onInternalVerticesClicked( int ) ) );
1240
1241   // Periodicity
1242   connect( myPeriodicityAddButton,     SIGNAL( clicked()),                    this,   SLOT( onAddPeriodicity() ) );
1243   connect( myPeriodicityRemoveButton,  SIGNAL( clicked()),                    this,   SLOT( onRemovePeriodicity() ) );
1244   connect( myPeriodicityTreeWidget,    SIGNAL( itemClicked(QTreeWidgetItem*, int)), this, SLOT( onPeriodicityTreeClicked(QTreeWidgetItem *, int) ) );
1245   connect( myPeriodicityGroupBox2,     SIGNAL(toggled(bool)),                 this,   SLOT(onPeriodicityByVerticesChecked(bool)));
1246
1247   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1248   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1249   {
1250     StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1251     connect( w1,     SIGNAL(contentModified ()),                 this,   SLOT(onPeriodicityContentModified()));
1252
1253   }
1254
1255   // HyperPatch
1256   connect( myHyPatchFaceSelBtn,   SIGNAL( toggled(bool) ),   SLOT( onHyPatchFaceSelection(bool) ));
1257   connect( myHyPatchGroupSelBtn,  SIGNAL( toggled(bool) ),   SLOT( onHyPatchGroupSelection(bool) ));
1258   connect( myHyPatchFaceSelector, SIGNAL( shapeSelected() ), SLOT( onHyPatchSelectionChanged()));
1259   connect( hpAddBtn,              SIGNAL( clicked() ),       SLOT( onHyPatchAdd()));
1260   connect( hpRemBtn,              SIGNAL( clicked() ),       SLOT( onHyPatchRemove()));
1261
1262   return fr;
1263 }
1264
1265 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
1266     This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
1267 */
1268 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
1269 // {
1270 //   if ((now == myXCoord) || (now == myYCoord) || (now == myZCoord)
1271 //       || (now = myGroupName) || (now = myGlobalGroupName) || (now = myEnforcedTreeWidget)) {
1272 //     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1273 //     that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1274 //     myEnfFaceWdg->deactivateSelection();
1275 //     myEnfVertexWdg->deactivateSelection();
1276 //   }
1277 // }
1278
1279 void BLSURFPluginGUI_HypothesisCreator::onStateChange()
1280 {
1281   myStdWidget->onPhysicalMeshChanged();
1282 }
1283
1284 /**
1285  * This method resets the content of the X, Y, Z widgets;
1286  **/
1287 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
1288 {
1289   myXCoord->setCleared(true);
1290   myYCoord->setCleared(true);
1291   myZCoord->setCleared(true);
1292   myXCoord->setText("");
1293   myYCoord->setText("");
1294   myZCoord->setText("");
1295   //   myGroupName->setText("");
1296 }
1297
1298 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
1299     This method updates the tooltip of a modified item. The QLineEdit widgets content
1300     is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
1301 */
1302 void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int /*column*/) {
1303   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
1304   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1305   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1306   QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1307   QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1308   QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
1309   QTreeWidgetItem* parent = item->parent();
1310   
1311   clearEnforcedVertexWidgets();
1312   
1313   if (parent && (!x.isNull() || !entry.isNull())) {
1314       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
1315       QString toolTip = shapeName + QString(": ") + vertexName.toString();
1316       if (entry.isNull()) {
1317         toolTip += QString("(") + x.toString();
1318         toolTip += QString(", ") + y.toString();
1319         toolTip += QString(", ") + z.toString();
1320         toolTip += QString(")");
1321       }
1322       
1323       if (!groupName.isEmpty())
1324         toolTip += QString(" [") + groupName + QString("]");
1325
1326       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1327
1328     if (!x.isNull()) {
1329       myXCoord->SetValue(x.toDouble());
1330       myYCoord->SetValue(y.toDouble());
1331       myZCoord->SetValue(z.toDouble());
1332     }
1333     
1334     if (!groupName.isEmpty())
1335       myGroupName->setText(groupName);
1336   }
1337 }
1338
1339 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
1340   int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
1341   clearEnforcedVertexWidgets();
1342   if (nbSelEnfVertex == 1)
1343   {
1344     if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
1345     return ;
1346
1347     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
1348     if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1349       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
1350       if (CORBA::is_nil(measureOp))
1351         return;
1352       
1353       CORBA::Double x,y,z;
1354       measureOp->PointCoordinates (myEnfVertex, x, y, z);
1355       if ( measureOp->IsDone() )
1356       {
1357         myXCoord->SetValue(x);
1358         myYCoord->SetValue(y);
1359         myZCoord->SetValue(z);
1360       }
1361     }
1362   }
1363 }
1364
1365 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1366 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
1367 of the enforced vertex clicked in the tree widget.
1368 */
1369 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
1370   clearEnforcedVertexWidgets();
1371   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
1372   if (! items.isEmpty() && items.size() == 1) {
1373     QTreeWidgetItem *item = items[0];
1374 //     for (int i=0 ; i < items.size() ; i++) {
1375 //       item = items[i];
1376       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1377       QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1378       QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1379       QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1380       QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
1381       if (!x.isNull()/* && entry.isNull()*/) {
1382         myXCoord->SetValue(x.toDouble());
1383         myYCoord->SetValue(y.toDouble());
1384         myZCoord->SetValue(z.toDouble());
1385 //         break;
1386       }
1387       if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1388         myGroupName->setText(group.toString());
1389 //     }
1390   }
1391 }
1392
1393 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1394 This method adds a face containing enforced vertices in the tree widget.
1395 */
1396 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
1397   // Find theFaceEntry item
1398   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1399   QTreeWidgetItem* theItem;
1400   if (theItemList.empty()) {
1401     theItem = new QTreeWidgetItem();
1402     theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1403     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1404     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1405     myEnforcedTreeWidget->addTopLevelItem(theItem);
1406   }
1407   else {
1408     theItem = theItemList[0];
1409   }
1410   return theItem;
1411 }
1412
1413 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1414     This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1415 */
1416 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z,
1417                                                           std::string vertexName,
1418                                                           std::string geomEntry,
1419                                                           std::string groupName)
1420 {
1421   bool okToCreate = true;
1422
1423   const int nbVert = myEnforcedTreeWidget->topLevelItemCount();
1424   for (int row = 0; row < nbVert; row++ )
1425   {
1426     QTreeWidgetItem* child = myEnforcedTreeWidget->topLevelItem( row );
1427     QString childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1428     QString childEntry     = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1429     double childX          = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1430     double childY          = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1431     double childZ          = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1432     if (((childEntry.isEmpty()) && (childX == x) && (childY == y) && (childZ == z)) ||
1433         ( !childEntry.isEmpty() && childEntry == geomEntry.c_str() ))
1434     {
1435       // update group name
1436       if ( childGroupName != groupName.c_str() ) {
1437         child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1438       }
1439       okToCreate = false;
1440       break;
1441     } // if
1442   } // for
1443   if (!okToCreate) {
1444     return;
1445   }
1446
1447   QTreeWidgetItem *vertexItem = new QTreeWidgetItem( myEnforcedTreeWidget );
1448   vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1449   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1450   QSize iconSize = iconSelect.size()*0.7;
1451
1452   int vertexIndex=nbVert;
1453   QString myVertexName;
1454   int indexRef = -1;
1455   while(indexRef != vertexIndex) {
1456     indexRef = vertexIndex;
1457     if (vertexName.empty())
1458       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1459     else
1460       myVertexName = QString(vertexName.c_str());
1461
1462     for (int row = 0;row<nbVert;row++) {
1463       QString name = myEnforcedTreeWidget->topLevelItem(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1464       if (myVertexName == name) {
1465         vertexIndex++;
1466         break;
1467       }
1468     }
1469   }
1470   vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1471   if (geomEntry.empty()) {
1472     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1473     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1474     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1475   }
1476   else {
1477     vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1478     vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1479   }
1480   if (groupName != "")
1481     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1482
1483   QString toolTip = myVertexName;
1484   if (geomEntry.empty()) {
1485     toolTip += QString(" (%1, %2, %3").arg(x).arg(y).arg(z);
1486   }
1487   if (groupName != "")
1488     toolTip += QString(" [%1]").arg(groupName.c_str());
1489   
1490   vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1491   myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1492 }
1493
1494 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1495 This method is called when a item is added into the enforced vertices tree widget
1496 */
1497 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1498 {
1499   getGeomSelectionTool()->selectionMgr()->clearFilters();
1500   myEnfVertexWdg->deactivateSelection();
1501
1502   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1503     myEnforcedTreeWidget->resizeColumnToContents(column);
1504
1505   // Vertex selection
1506   int selEnfVertex = myEnfVertexWdg->NbObjects();
1507   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1508
1509   if ((selEnfVertex == 0) && coordsEmpty)
1510     return;
1511
1512   string entry, shapeName;
1513   {
1514     std::string groupName = myGroupName->text().simplified().toStdString();
1515
1516     if (selEnfVertex <= 1)
1517     {
1518       double x,y,z;
1519       x = myXCoord->GetValue();
1520       y = myYCoord->GetValue();
1521       z = myZCoord->GetValue();
1522       if (selEnfVertex == 1) {
1523         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1524         addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1525       }
1526       else
1527         addEnforcedVertex(x, y, z, "", "", groupName);
1528     }
1529     else
1530     {
1531       if ( CORBA::is_nil(getGeomEngine()))
1532         return;
1533
1534       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
1535       if (CORBA::is_nil(measureOp))
1536         return;
1537
1538       CORBA::Double x,y,z;
1539       x = y = z = 0.;
1540       for (int j = 0 ; j < selEnfVertex ; j++)
1541       {
1542         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1543         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1544           measureOp->PointCoordinates (myEnfVertex, x, y, z);
1545           if ( measureOp->IsDone() )
1546             addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1547         } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1548             addEnforcedVertex(0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1549         }
1550       }
1551     }
1552   }
1553
1554   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1555   
1556   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1557     myEnforcedTreeWidget->resizeColumnToContents(column);
1558
1559   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1560     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1561     myStdWidget->onPhysicalMeshChanged();
1562   }
1563 }
1564
1565 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1566 This method is called when a item is removed from the enforced vertices tree widget
1567 */
1568 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1569   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1570   QList<QTreeWidgetItem *> selectedVertices;
1571   QSet<QTreeWidgetItem *> selectedEntries;
1572   QTreeWidgetItem* item;
1573
1574   foreach( item, selectedItems ) {
1575     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1576     if (! value.isNull())
1577       selectedVertices.append(item);
1578     else {
1579       value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1580       if (! value.isNull())
1581         selectedVertices.append(item);
1582       else
1583         selectedEntries.insert(item);
1584     }
1585   }
1586
1587   foreach(item,selectedVertices) {
1588     QTreeWidgetItem* parent = item->parent();
1589     if ( parent )
1590       parent->removeChild(item);
1591     delete item;
1592     if ( parent && parent->childCount() == 0) {
1593       if (selectedEntries.contains(parent))
1594         selectedEntries.remove(parent);
1595       delete parent;
1596     }
1597   }
1598
1599   foreach(item,selectedEntries) {
1600     delete item;
1601   }
1602
1603   myEnforcedTreeWidget->selectionModel()->clearSelection();
1604 }
1605
1606
1607 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1608 {
1609   myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1610 }
1611
1612 /** BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
1613 This method is called when a item is added into the periodicity table widget
1614 */
1615 void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
1616
1617   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1618
1619   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1620   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1621   for ( ; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1622     {
1623           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1624           w1->deactivateSelection();
1625     }
1626
1627
1628   // Source-Target selection
1629   int selSource = myPeriodicitySourceFaceWdg->NbObjects();
1630   int selTarget = myPeriodicityTargetFaceWdg->NbObjects();
1631
1632   if (selSource == 0 || selTarget == 0)
1633     return;
1634
1635   // Vertices selection
1636   if (myPeriodicityGroupBox2->isChecked())
1637     {
1638       int P1Ssel = myPeriodicityP1SourceWdg->NbObjects();
1639       int P2Ssel = myPeriodicityP2SourceWdg->NbObjects();
1640       int P3Ssel = myPeriodicityP3SourceWdg->NbObjects();
1641       int P1Tsel = myPeriodicityP1TargetWdg->NbObjects();
1642       //int P2Tsel = myPeriodicityP2TargetWdg->NbObjects();
1643       int P3Tsel = myPeriodicityP3TargetWdg->NbObjects();
1644
1645       if (P1Ssel!=1 || P2Ssel!=1 || P3Ssel!=1 || P1Tsel!=1 || P3Tsel!=1 || P3Tsel!=1)
1646         {
1647           QString msg = tr("BLSURF_PERIODICITY_WRONG_NUMBER_OF_VERTICES");
1648           SUIT_MessageBox::critical( dlg(),"Error" , msg );
1649           return;
1650         }
1651     }
1652
1653   // Add Source-Target in table
1654   string shapeEntry, sourceEntry, targetEntry;
1655   string shapeName, sourceName, targetName;
1656   GEOM::GEOM_Object_var shape;
1657
1658   QTreeWidgetItem* item = new QTreeWidgetItem();
1659   myPeriodicityTreeWidget->addTopLevelItem(item);
1660
1661   item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
1662
1663
1664   size_t k=0;
1665   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1666     {
1667       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1668       shape = w1->GetObject< GEOM::GEOM_Object >(0);
1669       shapeName = shape->GetName();
1670       shapeEntry = shape->GetStudyEntry();
1671       item->setData(k, Qt::EditRole, shapeName.c_str() );
1672       item->setData(k, Qt::UserRole, shapeEntry.c_str() );
1673       if (! myPeriodicityGroupBox2->isChecked() && k==1)
1674         break;
1675     }
1676
1677   // Add shape type in tree
1678   string onFace = (myPeriodicityOnFaceRadioButton->isChecked()) ? "1" : "0";
1679   item->setData(PERIODICITY_SHAPE_TYPE, Qt::UserRole, onFace.c_str());
1680
1681   // Blank input fields
1682   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1683     {
1684       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1685       w1->SetObject(GEOM::GEOM_Object::_nil());
1686     }
1687
1688 //  for (int column = 0; column < myPeriodicityTreeWidget->columnCount(); ++column)
1689 //    myPeriodicityTreeWidget->resizeColumnToContents(column);
1690
1691 }
1692
1693 /** BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
1694 This method is called when a item is removed from the periodicity tree widget
1695 */
1696 void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity() {
1697   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
1698   QTreeWidgetItem* item;
1699
1700   foreach(item,selectedItems) {
1701     delete item;
1702   }
1703
1704   myEnforcedTreeWidget->selectionModel()->clearSelection();
1705 }
1706
1707 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked()
1708 This method enable clears the field for periodicity by vertices
1709 */
1710 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked(bool checked)
1711 {
1712   if (! checked)
1713     {
1714       for (int k=2; k<myPeriodicitySelectionWidgets.size(); k++)
1715         {
1716           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k] );
1717           w1->deactivateSelection();
1718           w1->SetObject(CORBA::Object::_nil());
1719         }
1720     }
1721 }
1722
1723 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1724 This method enable the proper shape selection widget to Face or Edge shapes
1725 */
1726 //void BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1727 //{
1728 //  if (myPeriodicityOnFaceRadioButton->isChecked())
1729 //    {
1730 //      myPeriodicitySourceEdgeWdg->hide();
1731 //      myPeriodicityTargetEdgeWdg->hide();
1732 //      myPeriodicitySourceFaceWdg->show();
1733 //      myPeriodicityTargetFaceWdg->show();
1734 //    }
1735 //  else
1736 //    {
1737 //      myPeriodicitySourceFaceWdg->hide();
1738 //      myPeriodicityTargetFaceWdg->hide();
1739 //      myPeriodicitySourceEdgeWdg->show();
1740 //      myPeriodicityTargetEdgeWdg->show();
1741 //    }
1742 //}
1743
1744 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityTreeClicked(QTreeWidgetItem* item, int /*row*/)
1745 {
1746   QString shapeName, shapeEntry;
1747   CORBA::Object_var shape;
1748   size_t k=0;
1749   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1750   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1751     {
1752       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1753
1754       shapeName = item->data(k, Qt::EditRole).toString();
1755       shapeEntry = item->data(k, Qt::UserRole).toString();
1756       if (! shapeEntry.isEmpty())
1757         {
1758           shape = entryToObject(shapeEntry);
1759           w1->SetObject(shape);
1760           w1->deactivateSelection();
1761           if (k==2)
1762             myPeriodicityGroupBox2->setChecked(1);
1763         }
1764       else if(k==2)
1765         myPeriodicityGroupBox2->setChecked(0);
1766     }
1767
1768   if (item->data(PERIODICITY_SHAPE_TYPE, Qt::UserRole) == "1")
1769     myPeriodicityOnFaceRadioButton->setChecked(true);
1770   else
1771     myPeriodicityOnEdgeRadioButton->setChecked(true);
1772
1773
1774 }
1775
1776 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1777 This method gives the focus to the next selection widget when a content is modified in a selection widget.
1778 */
1779 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1780 {
1781   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1782
1783   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1784   int k=0;
1785   // find wich selection widget is activated
1786   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1787     {
1788       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1789       if (w1->IsSelectionActivated() && k<(myPeriodicitySelectionWidgets.size()-1))
1790         {
1791           // don't activate vertex selection if the group box is not checked
1792           if (k==1 && !myPeriodicityGroupBox2->isChecked())
1793             break;
1794           // clear the selection, to avoid to put the same object in the other widget
1795           that->getGeomSelectionTool()->selectionMgr()->clearSelected();
1796           // activate the next widget
1797           StdMeshersGUI_ObjectReferenceParamWdg * w2 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k+1] );
1798           w2->activateSelection();
1799           break;
1800         }
1801     }
1802 }
1803
1804
1805 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1806     This method updates the GUI widgets with the hypothesis data
1807 */
1808 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1809 {
1810   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1811
1812   BlsurfHypothesisData data;
1813   that->readParamsFromHypo( data );
1814
1815   if ( myName ) {
1816     myName->setText( data.myName );
1817     QFontMetrics metrics( myName->font() );
1818     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1819   }
1820   myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1821   myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1822   if (data.myPhySize <= 0)
1823     myStdWidget->myPhySize->setText("");
1824   else
1825     myStdWidget->myPhySize->SetValue( data.myPhySize );
1826   myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1827   if (data.myMinSize < 0)
1828     myStdWidget->myMinSize->setText("");
1829   else
1830     myStdWidget->myMinSize->SetValue( data.myMinSize );
1831   myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1832   if (data.myMaxSize < 0)
1833     myStdWidget->myMaxSize->setText("");
1834   else
1835     myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1836   myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1837   myStdWidget->myUseGradation->setChecked( data.myUseGradation );
1838   if (data.myGradation <= 0 || !data.myUseGradation )
1839     myStdWidget->myGradation->setText("");
1840   else
1841     myStdWidget->myGradation->SetValue( data.myGradation );
1842   myStdWidget->myUseVolumeGradation->setChecked( data.myUseVolumeGradation );
1843   if (data.myVolumeGradation <= 0 || !data.myUseVolumeGradation )
1844     myStdWidget->myVolumeGradation->setText("");
1845   else
1846     myStdWidget->myVolumeGradation->SetValue( data.myVolumeGradation );
1847
1848   foreach (QAbstractButton* button, myStdWidget->myButtonGroupElementType->buttons()) {
1849     if (myStdWidget->myButtonGroupElementType->id(button) == data.myElementType) {
1850       button->setChecked(true);
1851       break;
1852     }
1853   }
1854
1855   myStdWidget->myUseSurfaceProximity->setChecked( data.myUseSurfaceProximity );
1856   myStdWidget->myNbSurfaceProximityLayers->setValue( data.myNbSurfaceProximityLayers );
1857   myStdWidget->mySurfaceProximityRatio->SetValue( data.mySurfaceProximityRatio );
1858   myStdWidget->myUseVolumeProximity->setChecked( data.myUseVolumeProximity );
1859   myStdWidget->myNbVolumeProximityLayers->setValue( data.myNbVolumeProximityLayers );
1860   myStdWidget->myVolumeProximityRatio->SetValue( data.myVolumeProximityRatio );
1861   if ( !data.myUseSurfaceProximity )
1862   {
1863     //myStdWidget->myNbSurfaceProximityLayers->setText("");
1864     myStdWidget->mySurfaceProximityRatio->setText("");
1865   }
1866   if ( !data.myUseVolumeProximity )
1867   {
1868     //myStdWidget->myNbVolumeProximityLayers->setText("");
1869     myStdWidget->myVolumeProximityRatio->setText("");
1870   }
1871
1872   if (data.myAngleMesh < 0)
1873     myStdWidget->myAngleMesh->setText("");
1874   else
1875     myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1876   if (data.myChordalError <= 0)
1877     myStdWidget->myChordalError->setText("");
1878   else
1879     myStdWidget->myChordalError->SetValue( data.myChordalError );
1880   myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1881   if (data.myAnisotropicRatio <= 0)
1882     myStdWidget->myAnisotropicRatio->setText("");
1883   else
1884     myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1885   myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1886   if (data.myTinyEdgeLength <= 0)
1887     myStdWidget->myTinyEdgeLength->setText("");
1888   else
1889     myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1890   myStdWidget->myOptimiseTinyEdges->setChecked( data.myOptimiseTinyEdges );
1891   if (data.myTinyEdgeOptimisLength <= 0)
1892     myStdWidget->myTinyEdgeOptimisLength->setText("");
1893   else
1894     myStdWidget->myTinyEdgeOptimisLength->SetValue( data.myTinyEdgeOptimisLength );
1895   myStdWidget->myCorrectSurfaceIntersection->setChecked( data.myCorrectSurfaceIntersection );
1896   if (data.myCorrectSurfaceIntersectionMaxCost <= 0)
1897     myStdWidget->myCorrectSurfaceIntersectionMaxCost->setText("");
1898   else
1899     myStdWidget->myCorrectSurfaceIntersectionMaxCost->SetValue( data.myCorrectSurfaceIntersectionMaxCost );
1900   myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1901   if (data.myBadElementAspectRatio <= 0)
1902     myStdWidget->myBadElementAspectRatio->setText("");
1903   else
1904     myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1905   myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1906   myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1907   
1908   myStdWidget->resizeWidgets();  
1909   
1910   myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1911
1912   if ( myOptions.operator->() ) {
1913     for ( int i = 0, nb = myOptions->length(); i < nb; ++i )
1914       myAdvWidget->AddOption( TBL_MESHING, that->myOptions[i].in() );
1915   }
1916   if ( myPreCADOptions.operator->() ) {
1917     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i )
1918       myAdvWidget->AddOption( TBL_PRECAD, that->myPreCADOptions[i].in() );
1919   }
1920   if ( myCustomOptions.operator->() ) {
1921     for ( int i = 0, nb = myCustomOptions->length(); i < nb; ++i )
1922       myAdvWidget->AddOption( TBL_CUSTOM, that->myCustomOptions[i].in() );
1923   }
1924   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1925   myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1926 //   myGMFFileMode->setChecked(data.myGMFFileMode);
1927   
1928   // Sizemaps
1929   QMapIterator<QString, QString> i(that->mySMPMap);
1930   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1931   while (i.hasNext()) {
1932     i.next();
1933     const QString entry = i.key();
1934     const QString sizeMap = i.value();
1935     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1936     //int row = mySizeMapTable->topLevelItemCount();
1937     QTreeWidgetItem* item = new QTreeWidgetItem();
1938     mySizeMapTable->addTopLevelItem( item );
1939     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1940     item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1941     item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1942     if (that->myATTMap.contains(entry)) {
1943       TAttractorVec & attVec = that->myATTMap[entry];
1944       for ( size_t i = 0; i < attVec.size(); ++i )
1945       {
1946         std::string attName = myGeomToolSelected->getNameFromEntry( attVec[i].attEntry );
1947         QTreeWidgetItem* child = new QTreeWidgetItem();
1948         item->addChild( child );
1949         item->setExpanded(true);
1950         child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( attVec[i].startSize  ));
1951         child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attVec[i].attEntry.c_str() ));
1952         child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( attName.c_str() ));
1953
1954         if ( attVec[i].infDist >  std::numeric_limits<double>::epsilon()){
1955           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Attractor" ));
1956         }
1957         else{
1958           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Constant Size" ));
1959         }
1960       }
1961     }
1962     else
1963     {
1964       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1965     }
1966   }
1967   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1968   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1969   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1970
1971   // Enforced vertices
1972   TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1973
1974   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1975     TEntry entry = (*evmIt).first;
1976     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1977
1978     //QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1979
1980     TEnfVertexList evs = (*evmIt).second;
1981
1982     TEnfVertexList::const_iterator evsIt = evs.begin();
1983     TEnfVertex *enfVertex;
1984     for ( ; evsIt != evs.end() ; ++evsIt) {
1985       enfVertex = (*evsIt);
1986       double x = 0, y = 0, z = 0;
1987       if (enfVertex->coords.size()) {
1988         x = enfVertex->coords[0];
1989         y = enfVertex->coords[1];
1990         z = enfVertex->coords[2];
1991       }
1992       that->addEnforcedVertex(x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1993     }
1994   }
1995
1996   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1997     myEnforcedTreeWidget->resizeColumnToContents(column);
1998
1999   myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
2000   myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
2001   myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
2002
2003   // Periodicity
2004
2005   // Add an item in the tree widget for each association
2006   for (size_t i=0 ; i<data.preCadPeriodicityVector.size() ; i++)
2007   {
2008     QTreeWidgetItem* item = new QTreeWidgetItem();
2009     myPeriodicityTreeWidget->addTopLevelItem(item);
2010     item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
2011     TPreCadPeriodicity periodicity_i = data.preCadPeriodicityVector[i];
2012     for (size_t k=0; k<periodicity_i.size(); k++)
2013     {
2014       string shapeEntry = periodicity_i[k];
2015       string shapeName = myGeomToolSelected->getNameFromEntry(shapeEntry);
2016       item->setData(k, Qt::EditRole, shapeName.c_str() );
2017       item->setData(k, Qt::UserRole, shapeEntry.c_str() );
2018     }
2019   }
2020
2021   // Hyper patches
2022   for ( int i = 0; i < data.hyperpatches.size(); ++i )
2023     that->addHyPatchToTable( data.hyperpatches[i] );
2024
2025   // update widgets
2026   that->myStdWidget->onPhysicalMeshChanged();
2027   that->myStdWidget->onGeometricMeshChanged();
2028   that->onStateChange();
2029 }
2030
2031 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
2032 This method updates the hypothesis data with the GUI widgets content.
2033 */
2034 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
2035 {
2036   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2037
2038   BlsurfHypothesisData data;
2039   QString guiHyp = that->readParamsFromWidgets( data );
2040   that->storeParamsToHypo( data );
2041
2042   return guiHyp;
2043 }
2044
2045 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
2046 Updates the hypothesis data from hypothesis values.
2047 */
2048 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
2049 {
2050   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2051     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
2052
2053   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
2054   h_data.myName = isCreation() && data ? hypName() : "";
2055
2056   h_data.myPhysicalMesh           = (int) h->GetPhysicalMesh();
2057   h_data.myGeometricMesh          = (int) h->GetGeometricMesh();
2058   h_data.myPhySize                = h->GetPhySize();
2059   h_data.myPhySizeRel             = h->IsPhySizeRel();
2060   double minSize                  = h->GetMinSize();
2061   double maxSize                  = h->GetMaxSize();
2062   h_data.myMinSize                = minSize > 0 ? minSize : -1.0;
2063   h_data.myMinSizeRel             = h->IsMinSizeRel();
2064   h_data.myMaxSize                = maxSize > 0 ? maxSize : -1.0;
2065   h_data.myMaxSizeRel             = h->IsMaxSizeRel();
2066   h_data.myUseGradation           = h->GetUseGradation();
2067   h_data.myGradation              = h->GetGradation();
2068   h_data.myUseVolumeGradation     = h->GetUseVolumeGradation();
2069   h_data.myVolumeGradation        = h->GetVolumeGradation();
2070   h_data.myElementType            = h->GetElementType();
2071   double angle                    = h->GetAngleMesh();
2072   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
2073   double chordalError             = h->GetChordalError();
2074   h_data.myChordalError           = chordalError > 0 ? chordalError : -1.0;
2075   h_data.myAnisotropic            = h->GetAnisotropic();
2076   double myAnisotropicRatio       = h->GetAnisotropicRatio();
2077   h_data.myAnisotropicRatio       = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
2078   h_data.myRemoveTinyEdges        = h->GetRemoveTinyEdges();
2079   double myTinyEdgeLength         = h->GetTinyEdgeLength();
2080   h_data.myTinyEdgeLength         = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
2081   h_data.myOptimiseTinyEdges      = h->GetOptimiseTinyEdges();
2082   double myTinyEdgeOptimisLength  = h->GetTinyEdgeOptimisationLength();
2083   h_data.myTinyEdgeOptimisLength  = myTinyEdgeOptimisLength > 0 ? myTinyEdgeOptimisLength : -1.0;
2084   h_data.myCorrectSurfaceIntersection = h->GetCorrectSurfaceIntersection();
2085   double corrSurfaceIntersMaxCost = h->GetCorrectSurfaceIntersectionMaxCost();
2086   h_data.myCorrectSurfaceIntersectionMaxCost = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
2087   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
2088   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
2089   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
2090   h_data.myOptimizeMesh           = h->GetOptimizeMesh();
2091   h_data.myQuadraticMesh          = h->GetQuadraticMesh();
2092   h_data.myVerbosity              = h->GetVerbosity();
2093   //h_data.myTopology               = (int) h->GetTopology();
2094   //h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
2095   // h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
2096   // h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
2097   h_data.myUseSurfaceProximity      = h->GetSurfaceProximity        ();
2098   h_data.myNbSurfaceProximityLayers = h->GetNbSurfaceProximityLayers();
2099   h_data.mySurfaceProximityRatio    = h->GetSurfaceProximityRatio   ();
2100   h_data.myUseVolumeProximity       = h->GetVolumeProximity         ();
2101   h_data.myNbVolumeProximityLayers  = h->GetNbVolumeProximityLayers ();
2102   h_data.myVolumeProximityRatio     = h->GetVolumeProximityRatio    ();
2103
2104   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2105   that->myOptions       = h->GetOptionValues();
2106   that->myPreCADOptions = h->GetPreCADOptionValues();
2107   that->myCustomOptions = h->GetAdvancedOptionValues();
2108
2109   h_data.myGMFFileName = h->GetGMFFile();
2110 //   h_data.myGMFFileMode = h->GetGMFFileMode();
2111
2112   that->mySMPMap.clear();
2113   that->myATTMap.clear();
2114   // that->myAttDistMap.clear();
2115   // that->myDistMap.clear();
2116
2117   // classic size maps
2118   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
2119   QString fullSizeMaps;
2120   QStringList fullSizeMapList;
2121   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
2122   for ( CORBA::ULong i = 0;i<mySizeMaps->length(); ++i ) {
2123     fullSizeMaps =  mySizeMaps[i].in();
2124     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
2125     if ( fullSizeMapList.count() > 1 ) {
2126       string fullSizeMap = fullSizeMapList[1].toStdString();
2127       int pos = fullSizeMap.find("return")+7;
2128       QString sizeMap;
2129       try {
2130         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
2131       }
2132       catch (...) {
2133         continue;
2134       }
2135       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
2136       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
2137     }
2138   }
2139
2140   // custom size maps
2141 /*
2142   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
2143
2144   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
2145     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
2146     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
2147     if ( fullCustomSizeMapList.count() > 1 ) {
2148       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
2149       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
2150     }
2151   }
2152 */
2153   // attractor
2154   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
2155
2156   for ( CORBA::ULong i = 0;i<allMyAttractors->length(); ++i ) {
2157     QString myAttractors =  allMyAttractors[i].in();
2158     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
2159     if ( myAttractorList.count() > 1 ) {
2160       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
2161       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
2162     }
2163   }
2164   
2165   // attractor new version
2166   BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
2167   for ( CORBA::ULong i = 0;i<allMyAttractorParams->length(); ++i ) {
2168     BLSURFPlugin::TAttractorParams myAttractorParams =  allMyAttractorParams[i];
2169     QString faceEntry = myAttractorParams.faceEntry.in();
2170     QString attEntry  = myAttractorParams.attEntry.in();
2171     that->mySMPMap[faceEntry] = QString::number( myAttractorParams.startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
2172     that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
2173     that->myATTMap[faceEntry].push_back( TAttractor( myAttractorParams.attEntry.in(),
2174                                                      myAttractorParams.startSize,
2175                                                      myAttractorParams.infDist,
2176                                                      myAttractorParams.constDist ));
2177   }
2178   
2179   // Enforced vertices
2180   h_data.enfVertexList.clear();
2181   h_data.faceEntryEnfVertexListMap.clear();
2182   /* TODO GROUPS
2183   h_data.groupNameEnfVertexListMap.clear();
2184   */
2185
2186   BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
2187
2188   for ( CORBA::ULong i = 0;i<faceEntryEnfVertexListMap->length(); ++i )
2189   {
2190     std::string entry = faceEntryEnfVertexListMap[i].faceEntry.in();
2191     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
2192
2193     for (CORBA::ULong j=0 ; j<vertexList.length(); ++j)
2194     {
2195       TEnfVertex *enfVertex = new TEnfVertex();
2196       enfVertex->name      = vertexList[j].name.in();
2197       enfVertex->geomEntry = vertexList[j].geomEntry.in();
2198       enfVertex->grpName   = vertexList[j].grpName.in();
2199       for (CORBA::ULong k=0 ; k< vertexList[j].coords.length();k++)
2200         enfVertex->coords.push_back(vertexList[j].coords[k]);
2201
2202       h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
2203
2204       /* TODO GROUPS
2205       if (groupName != "") {
2206         h_data.groupNameEnfVertexListMap[groupName].insert(ev);
2207       }
2208       */
2209     }
2210 //     h_data.enfVertMap[entry] = evs;
2211 //     h_data.entryCoordsListMap[entry] = coordsList;
2212
2213     if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
2214       h_data.faceEntryEnfVertexListMap.erase(entry);
2215     }
2216   }
2217   h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
2218   h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
2219
2220   // Periodicity
2221
2222   h_data.preCadPeriodicityVector.clear();
2223
2224   BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector = h->GetPreCadFacesPeriodicityVector();
2225   AddPreCadSequenceToVector(h_data, preCadFacePeriodicityVector, true);
2226
2227   BLSURFPlugin::TPeriodicityList_var preCadEdgePeriodicityVector = h->GetPreCadEdgesPeriodicityVector();
2228   AddPreCadSequenceToVector(h_data, preCadEdgePeriodicityVector, false);
2229
2230   // Hyper Patches
2231
2232   h_data.hyperpatches.clear();
2233   BLSURFPlugin::THyperPatchList_var patchList = h->GetHyperPatches();
2234   for ( CORBA::ULong i = 0; i < patchList->length(); ++i )
2235   {
2236     QString tags;
2237     BLSURFPlugin::THyperPatch& patch = patchList[i];
2238     for ( CORBA::ULong j = 0; j < patch.length(); ++j )
2239       tags += QString::number( patch[j] ) + " ";
2240     if ( !tags.isEmpty() )
2241       h_data.hyperpatches.append( tags );
2242   }
2243
2244   return true;
2245 }
2246
2247 void BLSURFPluginGUI_HypothesisCreator::AddPreCadSequenceToVector(BlsurfHypothesisData& h_data,
2248     BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const
2249 {
2250
2251   for (size_t i=0; i<preCadFacePeriodicityVector->length(); i++ )
2252     {
2253       TPreCadPeriodicity periodicity_i(PERIODICITY_NB_COLUMN);
2254       periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN] = preCadFacePeriodicityVector[i].shape1Entry.in();
2255       periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN] = preCadFacePeriodicityVector[i].shape2Entry.in();
2256
2257       BLSURFPlugin::TEntryList sourceVertices = preCadFacePeriodicityVector[i].theSourceVerticesEntries;
2258       BLSURFPlugin::TEntryList targetVertices = preCadFacePeriodicityVector[i].theTargetVerticesEntries;
2259
2260       if (sourceVertices.length()!=0)
2261         {
2262           periodicity_i[PERIODICITY_P1_SOURCE_COLUMN] = sourceVertices[0].in();
2263           periodicity_i[PERIODICITY_P2_SOURCE_COLUMN] = sourceVertices[1].in();
2264           if ( onFace )
2265             periodicity_i[PERIODICITY_P3_SOURCE_COLUMN] = sourceVertices[2].in();
2266         }
2267
2268       if (targetVertices.length()!=0)
2269         {
2270           periodicity_i[PERIODICITY_P1_TARGET_COLUMN] = targetVertices[0].in();
2271           periodicity_i[PERIODICITY_P2_TARGET_COLUMN] = targetVertices[1].in();
2272           if ( onFace )
2273             periodicity_i[PERIODICITY_P3_TARGET_COLUMN] = targetVertices[2].in();
2274         }
2275
2276       if (onFace)
2277         periodicity_i[PERIODICITY_SHAPE_TYPE] = "1";
2278       else
2279         periodicity_i[PERIODICITY_SHAPE_TYPE] = "0";
2280
2281       h_data.preCadPeriodicityVector.push_back(periodicity_i);
2282     }
2283 }
2284
2285 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
2286 Saves the hypothesis data to hypothesis values.
2287 */
2288 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
2289 {
2290   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2291     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
2292
2293   bool ok = true;
2294   try
2295   {
2296     if ( isCreation() )
2297       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
2298
2299     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
2300       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
2301     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
2302       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
2303
2304     if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
2305       if ( h->GetPhySize()   != h_data.myPhySize ||
2306            h->IsPhySizeRel() != h_data.myPhySizeRel ) {
2307         if ( h_data.myPhySizeRel )
2308           h->SetPhySizeRel( h_data.myPhySize );
2309         else
2310           h->SetPhySize( h_data.myPhySize );
2311       }
2312     }
2313     if (h->GetMinSize()   != h_data.myMinSize ||
2314         h->IsMinSizeRel() != h_data.myMinSizeRel ) {
2315       if ( h_data.myMinSizeRel )
2316         h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2317       else
2318         h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2319     }
2320     if (h->GetMaxSize()   != h_data.myMaxSize ||
2321         h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
2322       if ( h_data.myMaxSizeRel )
2323         h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2324       else
2325         h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2326     }
2327     if ( h->GetUseGradation() !=  h_data.myUseGradation )
2328       h->SetUseGradation( h_data.myUseGradation );
2329     if ( h->GetGradation() !=  h_data.myGradation )
2330       h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
2331     if ( h->GetUseVolumeGradation() !=  h_data.myUseVolumeGradation )
2332       h->SetUseVolumeGradation( h_data.myUseVolumeGradation );
2333     if ( h->GetVolumeGradation() !=  h_data.myVolumeGradation )
2334       h->SetVolumeGradation( h_data.myVolumeGradation <= 0 ? -1 : h_data.myVolumeGradation );
2335
2336     h->SetSurfaceProximity        ( h_data.myUseSurfaceProximity      );
2337     h->SetNbSurfaceProximityLayers( h_data.myNbSurfaceProximityLayers );
2338     h->SetSurfaceProximityRatio   ( h_data.mySurfaceProximityRatio    );
2339     h->SetVolumeProximity         ( h_data.myUseVolumeProximity       );
2340     h->SetNbVolumeProximityLayers ( h_data.myNbVolumeProximityLayers  );
2341     h->SetVolumeProximityRatio    ( h_data.myVolumeProximityRatio     );
2342
2343     if ( h->GetElementType() != h_data.myElementType )
2344       h->SetElementType( h_data.myElementType );
2345
2346     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
2347       if ( h->GetAngleMesh() != h_data.myAngleMesh )
2348         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
2349       if ( h->GetChordalError() != h_data.myChordalError )
2350         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
2351     }
2352
2353     if ( h->GetAnisotropic() != h_data.myAnisotropic )
2354       h->SetAnisotropic( h_data.myAnisotropic );
2355     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
2356       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
2357
2358     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
2359       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
2360     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
2361       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
2362
2363     if ( h->GetOptimiseTinyEdges() != h_data.myOptimiseTinyEdges )
2364       h->SetOptimiseTinyEdges( h_data.myOptimiseTinyEdges );
2365     if ( h_data.myOptimiseTinyEdges && ( h->GetTinyEdgeOptimisationLength() != h_data.myTinyEdgeOptimisLength ) )
2366       h->SetTinyEdgeOptimisationLength( h_data.myTinyEdgeOptimisLength <= 0 ? -1 :h_data.myTinyEdgeOptimisLength );
2367     if ( h->GetCorrectSurfaceIntersection() != h_data.myCorrectSurfaceIntersection )
2368       h->SetCorrectSurfaceIntersection( h_data.myCorrectSurfaceIntersection );
2369     if ( h_data.myCorrectSurfaceIntersection && ( h->GetCorrectSurfaceIntersectionMaxCost() != h_data.myCorrectSurfaceIntersectionMaxCost ) )
2370       h->SetCorrectSurfaceIntersectionMaxCost( h_data.myCorrectSurfaceIntersectionMaxCost <= 0 ? -1 :h_data.myCorrectSurfaceIntersectionMaxCost );
2371     
2372     if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
2373       h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
2374     if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
2375       h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
2376     
2377     if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
2378       h->SetOptimizeMesh( h_data.myOptimizeMesh );    
2379     
2380     if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
2381       h->SetQuadraticMesh( h_data.myQuadraticMesh );
2382
2383     if ( h->GetVerbosity() != h_data.myVerbosity )
2384       h->SetVerbosity( h_data.myVerbosity );
2385     // if ( h->GetTopology() != h_data.myTopology )
2386     //   h->SetTopology( (int) h_data.myTopology );
2387     // if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
2388     //   h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
2389     // if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
2390     //   h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
2391     // if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
2392     //   h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
2393
2394     // options are set in checkParams()
2395     //h->SetOptionValues( myOptions ); // is set in readParamsFromWidgets()
2396     //h->SetPreCADOptionValues( myPreCADOptions ); // is set in readParamsFromWidgets()
2397
2398     if ( h->GetGMFFile() != h_data.myGMFFileName )
2399       //       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
2400       //       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
2401       h->SetGMFFile( h_data.myGMFFileName.c_str());
2402
2403     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2404     QMapIterator<QString,QString> i(that->mySMPMap);
2405     while (i.hasNext()) {
2406       i.next();
2407       const QString entry = i.key();
2408       const QString sizeMap = i.value();
2409
2410       if (sizeMap == "__TO_DELETE__") {
2411         h->UnsetEntry(entry.toLatin1().constData());
2412       }
2413       else if (sizeMap.startsWith("ATTRACTOR")) {
2414         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
2415       }
2416       else if (sizeMap.startsWith("def")) {
2417         //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
2418       }
2419       else {
2420         if (!myATTMap[entry].empty()){
2421           const TAttractorVec& attVec = myATTMap[entry];
2422           for ( size_t i = 0; i < attVec.size(); ++i )
2423           {
2424             if ( attVec[i].IsToDelete() )
2425               h->UnsetAttractorEntry( entry.toLatin1().constData(),
2426                                       attVec[i].attEntry.c_str() );
2427             else
2428               h->SetClassAttractorEntry( entry.toLatin1().constData(),
2429                                          attVec[i].attEntry.c_str(),
2430                                          attVec[i].startSize,
2431                                          h->GetPhySize(),
2432                                          attVec[i].infDist,
2433                                          attVec[i].constDist );
2434           }
2435         }
2436         else {
2437           QString fullSizeMap;
2438           fullSizeMap = QString("");
2439           if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
2440             fullSizeMap = QString("def f(u,v): return ") + sizeMap;
2441           else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
2442             fullSizeMap = QString("def f(t): return ") + sizeMap;
2443           else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
2444             fullSizeMap = QString("def f(): return ") + sizeMap;
2445           h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
2446         }
2447       }
2448     }
2449
2450     // Enforced vertices
2451     //bool ret;
2452     double x, y, z = 0;
2453     std::string enfName;
2454     /* TODO GROUPS
2455        std::string groupName = "";
2456     */
2457
2458     TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
2459     // 1. Clear all enforced vertices in hypothesis
2460     // 2. Add new enforced vertex according to h_data
2461
2462     if ( h->GetAllEnforcedVertices()->length() > 0 )
2463       h->ClearAllEnforcedVertices();
2464     TEnfName faceEntry;
2465     TEnfVertexList evs;
2466     TEnfVertexList::const_iterator evsIt;
2467     for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
2468     {
2469       faceEntry = evmIt->first;
2470       evs = evmIt->second;
2471       evsIt = evs.begin();
2472       for ( ; evsIt != evs.end() ; ++evsIt)
2473       {
2474         x =y =z = 0;
2475         if ((*evsIt)->coords.size()) {
2476           x = (*evsIt)->coords[0];
2477           y = (*evsIt)->coords[1];
2478           z = (*evsIt)->coords[2];
2479         }
2480         //ret =
2481         h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
2482       } // for
2483     } // for
2484
2485     if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
2486       h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
2487     if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
2488       h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
2489
2490     // Periodicity
2491     if ( h->GetPreCadFacesPeriodicityVector()->length() > 0 || h->GetPreCadEdgesPeriodicityVector()->length() > 0 )
2492       h->ClearPreCadPeriodicityVectors();
2493
2494     TPreCadPeriodicityVector::const_iterator pIt = h_data.preCadPeriodicityVector.begin();
2495     for ( ; pIt != h_data.preCadPeriodicityVector.end() ; ++pIt)
2496     {
2497       TPreCadPeriodicity periodicity_i = *pIt;
2498       TEntry source = periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN];
2499       TEntry target = periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN];
2500       TEntry p1Source = periodicity_i[PERIODICITY_P1_SOURCE_COLUMN];
2501       TEntry p2Source = periodicity_i[PERIODICITY_P2_SOURCE_COLUMN];
2502       TEntry p3Source = periodicity_i[PERIODICITY_P3_SOURCE_COLUMN];
2503       TEntry p1Target = periodicity_i[PERIODICITY_P1_TARGET_COLUMN];
2504       TEntry p2Target = periodicity_i[PERIODICITY_P2_TARGET_COLUMN];
2505       TEntry p3Target = periodicity_i[PERIODICITY_P3_TARGET_COLUMN];
2506       bool onFace = (periodicity_i[PERIODICITY_SHAPE_TYPE]=="1") ? true : false;
2507
2508       BLSURFPlugin::TEntryList_var sourceVertices = new BLSURFPlugin::TEntryList();
2509       if (! p1Source.empty())
2510       {
2511         sourceVertices->length(3);
2512         sourceVertices[0]=CORBA::string_dup(p1Source.c_str());
2513         sourceVertices[1]=CORBA::string_dup(p2Source.c_str());
2514         sourceVertices[2]=CORBA::string_dup(p3Source.c_str());
2515       }
2516
2517
2518       BLSURFPlugin::TEntryList_var targetVertices = new BLSURFPlugin::TEntryList();
2519       if (! p1Target.empty())
2520       {
2521         targetVertices->length(3);
2522         targetVertices[0]=CORBA::string_dup(p1Target.c_str());
2523         targetVertices[1]=CORBA::string_dup(p2Target.c_str());
2524         targetVertices[2]=CORBA::string_dup(p3Target.c_str());
2525       }
2526
2527       if (onFace)
2528         h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2529       else
2530         h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2531     }
2532
2533     // Hyper-patches
2534     BLSURFPlugin::THyperPatchList_var hpl = new BLSURFPlugin::THyperPatchList();
2535     hpl->length( h_data.hyperpatches.size() );
2536
2537     for ( int i = 0; i < h_data.hyperpatches.size(); ++i )
2538     {
2539       QStringList tags = h_data.hyperpatches[i].split(" ",  QString::SkipEmptyParts);
2540       BLSURFPlugin::THyperPatch& patch = hpl[ i ];
2541       patch.length( tags.size() );
2542
2543       for ( int j = 0; j < tags.size(); ++j )
2544         patch[ j ] = tags[ j ].toDouble();
2545     }
2546     h->SetHyperPatches( hpl );
2547
2548
2549   } // try
2550   catch(...) {
2551     ok = false;
2552   }
2553
2554   return ok;
2555 }
2556
2557 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
2558     Stores the widgets content to the hypothesis data.
2559 */
2560 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
2561 {
2562   h_data.myName                  = myName ? myName->text() : "";
2563   h_data.myPhysicalMesh          = myStdWidget->myPhysicalMesh->currentIndex();
2564   h_data.myGeometricMesh         = myStdWidget->myGeometricMesh->currentIndex();
2565   h_data.myPhySize               = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
2566   h_data.myPhySizeRel            = myStdWidget->myPhySizeRel->isChecked();
2567   h_data.myMinSize               = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
2568   h_data.myMinSizeRel            = myStdWidget->myMinSizeRel->isChecked();
2569   h_data.myMaxSize               = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
2570   h_data.myMaxSizeRel            = myStdWidget->myMaxSizeRel->isChecked();
2571   h_data.myUseGradation          = myStdWidget->myUseGradation->isChecked() && !myStdWidget->myGradation->text().isEmpty();
2572   h_data.myGradation             = h_data.myUseGradation ? myStdWidget->myGradation->GetValue() : -1.0;
2573   h_data.myUseVolumeGradation    = myStdWidget->myUseVolumeGradation->isChecked() && !myStdWidget->myVolumeGradation->text().isEmpty();
2574   h_data.myVolumeGradation       = h_data.myUseVolumeGradation ? myStdWidget->myVolumeGradation->GetValue() : -1. ;
2575   h_data.myElementType           = myStdWidget->myButtonGroupElementType->checkedId();
2576   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
2577   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
2578   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
2579   h_data.myAnisotropicRatio      = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
2580   h_data.myRemoveTinyEdges       = myStdWidget->myRemoveTinyEdges->isChecked();
2581   h_data.myTinyEdgeLength        = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
2582   h_data.myOptimiseTinyEdges     = myStdWidget->myOptimiseTinyEdges->isChecked();
2583   h_data.myTinyEdgeOptimisLength = myStdWidget->myTinyEdgeOptimisLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeOptimisLength->GetValue();
2584   h_data.myCorrectSurfaceIntersection = myStdWidget->myCorrectSurfaceIntersection->isChecked();
2585   h_data.myCorrectSurfaceIntersectionMaxCost = myStdWidget->myCorrectSurfaceIntersectionMaxCost->text().isEmpty() ? -1.0 : myStdWidget->myCorrectSurfaceIntersectionMaxCost->GetValue();
2586   h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
2587   h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
2588   h_data.myOptimizeMesh          = myStdWidget->myOptimizeMesh->isChecked();
2589   h_data.myQuadraticMesh         = myStdWidget->myQuadraticMesh->isChecked();
2590   h_data.myVerbosity             = myAdvWidget->myVerbosity->value();
2591   //h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
2592   //h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
2593   //h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
2594   //h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
2595   h_data.myUseSurfaceProximity      = myStdWidget->myUseSurfaceProximity     ->isChecked();
2596   h_data.myNbSurfaceProximityLayers = myStdWidget->myNbSurfaceProximityLayers->value();
2597   h_data.mySurfaceProximityRatio    = myStdWidget->mySurfaceProximityRatio   ->value();
2598   h_data.myUseVolumeProximity       = myStdWidget->myUseVolumeProximity      ->isChecked();
2599   h_data.myNbVolumeProximityLayers  = myStdWidget->myNbVolumeProximityLayers ->value();
2600   h_data.myVolumeProximityRatio     = myStdWidget->myVolumeProximityRatio    ->value();
2601
2602   QString guiHyp;
2603   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
2604   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
2605   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
2606   guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
2607   guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
2608   guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
2609   guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
2610   guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
2611   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
2612   guiHyp += tr("BLSURF_ELEMENT_TYPE") + " = " + QString::number(h_data.myElementType) + "; ";
2613   guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
2614   guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
2615   guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
2616   guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
2617   
2618   
2619   guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
2620   guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
2621   guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
2622   guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
2623   guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
2624   guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
2625   
2626   
2627   // guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
2628   // guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
2629   // guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
2630   // guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
2631  
2632   h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
2633 //   h_data.myGMFFileMode = myGMFFileMode->isChecked();
2634
2635   // SizeMap
2636   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2637   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2638   for ( ; row < nbRows; ++row )
2639   {
2640     QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
2641     if ( that->mySMPMap.contains(entry) )
2642       guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
2643   }
2644
2645   // Enforced vertices
2646   h_data.enfVertexList.clear();
2647   h_data.faceEntryEnfVertexListMap.clear();
2648
2649   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
2650   std::string groupName = "", faceEntry = "";
2651   for (int i=0 ; i<nbEnforcedShapes ; i++)
2652   {
2653     double childValueX,childValueY,childValueZ;
2654     std::string childName, vertexEntry;
2655     QTreeWidgetItem* child;
2656
2657     child = myEnforcedTreeWidget->topLevelItem(i);
2658     childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
2659     childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
2660     childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
2661     childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
2662     vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2663     //           if (myGlobalGroupName->isChecked())
2664     //             groupName = myGlobalGroupName->text().toStdString();
2665     //           else
2666     groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
2667
2668     TEnfVertex *enfVertex = new TEnfVertex();
2669     enfVertex->name = childName;
2670     if (vertexEntry.empty()) {
2671       enfVertex->coords.push_back(childValueX);
2672       enfVertex->coords.push_back(childValueY);
2673       enfVertex->coords.push_back(childValueZ);
2674     }
2675     else
2676       enfVertex->geomEntry = vertexEntry;
2677     enfVertex->grpName = groupName;
2678     //           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
2679     //           if (it == h_data.enfVertexList.end())
2680     h_data.enfVertexList.insert(enfVertex);
2681     /* TODO GROUPS
2682        if (groupName != "")
2683        h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2684     */
2685     h_data.faceEntryEnfVertexListMap[faceEntry].insert( enfVertex );
2686   }
2687
2688   h_data.myInternalEnforcedVerticesAllFaces      = myInternalEnforcedVerticesAllFaces->isChecked();
2689   h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2690
2691   // Periodicity
2692   h_data.preCadPeriodicityVector.clear();
2693   // For each tree item, store each value. Shapes are stored as entries.
2694   int nbPeriodicityDescriptions = myPeriodicityTreeWidget->topLevelItemCount();
2695   for (int i=0 ; i<nbPeriodicityDescriptions ; i++) {
2696     QTreeWidgetItem* item = myPeriodicityTreeWidget->topLevelItem(i);
2697     TPreCadPeriodicity periodicity_i;
2698     if (item) {
2699         for (int k=0; k<myPeriodicityTreeWidget->columnCount(); ++k)
2700           {
2701             std::string entry = item->data(k, Qt::UserRole).toString().toStdString();
2702             periodicity_i.push_back(entry);
2703           }
2704         h_data.preCadPeriodicityVector.push_back(periodicity_i);
2705     }
2706     guiHyp += "PERIODICITY = yes; ";
2707   }
2708
2709   // Hyper-patches
2710   h_data.hyperpatches.clear();
2711   for ( int row = 0; row < myHyPatchTable->rowCount(); ++row )
2712     h_data.hyperpatches.append( myHyPatchTable->item( row, 0 )->text() );
2713
2714   return guiHyp;
2715 }
2716
2717 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2718 {
2719   myAdvWidget->AddOption( TBL_CUSTOM, NULL );
2720 }
2721
2722 void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int /*row*/, int /*column*/ )
2723 {
2724   // if ( column != OPTION_NAME_COLUMN )
2725   //   return;
2726   // myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2727 }
2728
2729 // **********************
2730 // *** BEGIN SIZE MAP ***
2731 // **********************
2732
2733 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2734 {
2735   if ( myGeomSelWdg2->IsObjectSelected() ){
2736     mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2737   }
2738   else if ( myGeomSelWdg1->IsObjectSelected() ){
2739     mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2740   }
2741   else {
2742     mySMapObject = GEOM::GEOM_Object::_nil();
2743   }
2744   bool dataAvailable = !mySMapObject->_is_nil();
2745   QString qEntry;
2746   if ( dataAvailable )
2747     qEntry = SMESH::toQStr( mySMapObject->GetStudyEntry() );
2748
2749   bool mapExists = ( mySMPMap.contains(qEntry) && mySMPMap[qEntry] != "__TO_DELETE__" );
2750   if (( mapExists && myGeomSelWdg2->IsObjectSelected() )  &&
2751       ( dataAvailable = myAttSelWdg->isEnabled() )        &&
2752       ( dataAvailable = myAttSelWdg->IsObjectSelected() ) &&
2753       ( myATTMap.contains( qEntry )))
2754   {
2755     mapExists = false;
2756     QString attEntry = myAttSelWdg->GetValue();
2757     const TAttractorVec& attVec = myATTMap[ qEntry ];
2758     for ( size_t i = 0; i < attVec.size() && !mapExists; ++i )
2759       mapExists = ( attEntry == attVec[i].attEntry.c_str() );
2760   }
2761
2762   addMapButton->setEnabled( !mapExists && dataAvailable );
2763   modifyMapButton->setEnabled( mapExists && dataAvailable );
2764 }
2765
2766 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2767
2768   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2769   if (col == SMP_SIZEMAP_COLUMN) {
2770     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2771     QString childEntry;
2772     if (!mySMPMap.contains(entry))
2773     {
2774       if ( QTreeWidgetItem* parent = item->parent() )
2775       {
2776         childEntry = entry;
2777         item = parent;
2778         entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2779       }
2780       if (!mySMPMap.contains(entry))
2781         return;
2782     }
2783     QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2784     CORBA::Object_var obj = entryToObject(entry);
2785     if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")) {  // ADVANCED MAPS
2786       smpTab->setCurrentIndex(ATT_TAB);         // Change Tab
2787       // Retrieve values of the selected item in the current tab widgets
2788       const TAttractorVec& attVec = myATTMap[entry];
2789       if ( !attVec.empty() )
2790       {
2791         int iAtt = 0;
2792         if ( !childEntry.isEmpty() )
2793           for ( size_t i = 0; i < attVec.size(); ++i )
2794             if ( childEntry == attVec[i].attEntry.c_str() )
2795             {
2796               iAtt = i;
2797               break;
2798             }
2799         double phySize   = attVec[iAtt].startSize;
2800         double infDist   = attVec[iAtt].infDist;
2801         double constDist = attVec[iAtt].constDist;
2802         QString attEntry = attVec[iAtt].attEntry.c_str();
2803         CORBA::Object_var attObj = entryToObject(attEntry);
2804         myAttSizeSpin->setValue(phySize);
2805         if ( infDist > std::numeric_limits<double>::epsilon() /*sizeMap.startsWith("Attractor")*/){
2806           myAttDistSpin->setValue(infDist);
2807           myAttractorCheck->setChecked(true);
2808         }
2809         else {
2810           myAttractorCheck->setChecked(false);
2811         }
2812         if (/*sizeMap.startsWith("Constant") || */constDist > std::numeric_limits<double>::epsilon()){
2813           myAttDistSpin2->setValue(constDist);
2814           myConstSizeCheck->setChecked(true);
2815         }
2816         else{
2817           myConstSizeCheck->setChecked(false);
2818         }
2819         myGeomSelWdg2->SetObject(obj);
2820         myAttSelWdg->SetObject(attObj);
2821       }
2822     }
2823     else {                                                                   // CLASSIC MAPS
2824       smpTab->setCurrentIndex(SMP_STD_TAB);  // Change Tab
2825       myGeomSelWdg1->SetObject(obj);         // Retrieve values of the selected item in the current tab widgets
2826       if (!sizeMap.startsWith("def")){
2827         mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
2828       }
2829     }
2830   }
2831 }
2832
2833 void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
2834 {
2835   getGeomSelectionTool()->selectionMgr()->clearFilters();
2836   if ( sender() == myTabWidget )
2837   {
2838     myGeomSelWdg1             ->deactivateSelection();
2839     myGeomSelWdg2             ->deactivateSelection();
2840     myAttSelWdg               ->deactivateSelection();
2841     myEnfVertexWdg            ->deactivateSelection();
2842     myPeriodicitySourceFaceWdg->deactivateSelection();
2843     myPeriodicityTargetFaceWdg->deactivateSelection();
2844     myPeriodicityP1SourceWdg  ->deactivateSelection();
2845     myPeriodicityP2SourceWdg  ->deactivateSelection();
2846     myPeriodicityP3SourceWdg  ->deactivateSelection();
2847     myPeriodicityP1TargetWdg  ->deactivateSelection();
2848     myPeriodicityP2TargetWdg  ->deactivateSelection();
2849     myPeriodicityP3TargetWdg  ->deactivateSelection();
2850     if ( myHyPatchFaceSelBtn->isChecked() )
2851       myHyPatchFaceSelBtn->toggle();
2852     if ( myHyPatchGroupSelBtn->isChecked() )
2853       myHyPatchGroupSelBtn->toggle();
2854   }
2855   else if ( sender() == smpTab )
2856   {
2857     myAttDistSpin->setValue(0.);           // Reinitialize widgets
2858     myAttSizeSpin->setValue(0.);
2859     myAttDistSpin2->setValue(0.);
2860     mySmpSizeSpin->setValue(0.);
2861     myGeomSelWdg1->deactivateSelection();
2862     myGeomSelWdg2->deactivateSelection();
2863     myAttSelWdg->deactivateSelection();
2864     myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2865     myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2866     myAttSelWdg->SetObject(CORBA::Object::_nil());
2867     myAttractorCheck->setChecked(false);
2868     myConstSizeCheck->setChecked(false);
2869   }
2870
2871   if ( tab == SMP_TAB ) // [#16954] limit local size by Min and User Size
2872   {
2873     double minSize = 0, maxSize = COORD_MAX;
2874
2875     if ( !myStdWidget->myMinSizeRel->isChecked() &&
2876          !myStdWidget->myMinSize->text().isEmpty() )
2877       minSize = myStdWidget->myMinSize->GetValue();
2878
2879     if ( !myStdWidget->myPhySizeRel->isChecked() &&
2880          !myStdWidget->myPhySize->text().isEmpty() )
2881       maxSize = myStdWidget->myPhySize->GetValue();
2882
2883     mySmpSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
2884     myAttSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
2885   }
2886 }
2887
2888 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2889 {
2890   if (state == Qt::Checked){
2891     myAttSelWdg->setEnabled(true);
2892     myAttSizeSpin->setEnabled(true);
2893     myAttSizeLabel->setEnabled(true);
2894     myAttDistSpin->setEnabled(true);
2895     myAttDistLabel->setEnabled(true);
2896     if (!myAttSelWdg->IsObjectSelected()){
2897       myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2898     }
2899   }
2900   if (state == Qt::Unchecked){
2901     myAttDistSpin->setEnabled(false);
2902     myAttDistLabel->setEnabled(false);
2903     myAttDistSpin->setValue(0.);
2904     if(myConstSizeCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2905       myAttSelWdg->setEnabled(false);
2906       myAttSizeSpin->setEnabled(false);
2907       myAttSizeLabel->setEnabled(false);
2908       myAttDistSpin2->setEnabled(false);
2909       myAttDistLabel2->setEnabled(false);
2910     }
2911     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2912       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2913     }
2914   }
2915   onMapGeomContentModified();
2916 }
2917
2918 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2919
2920   if (state == Qt::Checked){
2921     myAttSelWdg->setEnabled(true);
2922     myAttSizeSpin->setEnabled(true);
2923     myAttSizeLabel->setEnabled(true);
2924     myAttDistSpin2->setEnabled(true);
2925     myAttDistLabel2->setEnabled(true);
2926     if (myAttractorCheck->checkState() == Qt::Unchecked &&
2927         !myAttSelWdg->IsObjectSelected()){
2928       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2929     }
2930   }
2931   if (state == Qt::Unchecked){
2932     myAttDistSpin2->setEnabled(false);
2933     myAttDistLabel2->setEnabled(false);
2934     myAttDistSpin2->setValue(0.);
2935     if(myAttractorCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2936         myAttSelWdg->setEnabled(false);
2937         myAttSizeSpin->setEnabled(false);
2938         myAttSizeLabel->setEnabled(false);
2939         myAttDistSpin->setEnabled(false);
2940         myAttDistLabel->setEnabled(false);
2941     }
2942     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2943     myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2944     }
2945   }   
2946   onMapGeomContentModified();
2947 }
2948
2949 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
2950 {
2951   QList<int> selectedRows;
2952   QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
2953   QTreeWidgetItem* item;
2954   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2955
2956   qSort( selectedRows );
2957   QListIterator<QTreeWidgetItem*> it( selected );
2958   it.toBack();
2959   while ( it.hasPrevious() ) {
2960       item = it.previous();
2961       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2962       QString parentEntry;
2963       if ( QTreeWidgetItem* parent = item->parent() )
2964         parentEntry = parent->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2965       if (that->mySMPMap.contains(entry))
2966       {
2967         that->mySMPMap[entry] = "__TO_DELETE__";
2968         if ( myATTMap.contains( entry ))
2969         {
2970           TAttractorVec& attVec = myATTMap[entry];
2971           for ( size_t i = 0; i < attVec.size(); ++i )
2972             attVec[i].SetToDelete();
2973         }          
2974       }
2975       else if ( mySMPMap.contains( parentEntry ) && myATTMap.contains( parentEntry ))
2976       {
2977         TAttractorVec& attVec = myATTMap[parentEntry];
2978         for ( size_t i = 0; i < attVec.size(); ++i )
2979         {
2980           if ( entry == attVec[i].attEntry.c_str() )
2981             attVec[i].SetToDelete();
2982         }
2983       }
2984       if (that->mySMPShapeTypeMap.contains(entry))
2985         that->mySMPShapeTypeMap.remove(entry);
2986       // if (that->myDistMap.contains(entry))
2987       //   that->myDistMap.remove(entry);
2988       // if (that->myAttDistMap.contains(entry))
2989       //   that->myAttDistMap.remove(entry);
2990       delete item;
2991   }
2992   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
2993   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2994 }
2995
2996 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
2997 {
2998   if (col == SMP_SIZEMAP_COLUMN) {
2999     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3000     QString entry   = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
3001     QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
3002     if (! that->mySMPShapeTypeMap.contains(entry))
3003       return;
3004     if (that->mySMPMap.contains(entry))
3005       if (that->mySMPMap[entry] == sizeMap 
3006         || sizeMap.startsWith("Attractor") 
3007         || sizeMap.startsWith("Constant") ){
3008         return;
3009       } 
3010     if (! sizeMap.isEmpty()) {
3011       that->mySMPMap[entry] = sizeMap;
3012       sizeMapValidationFromEntry(entry); 
3013     }
3014     else {
3015       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
3016     }
3017     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
3018   }
3019 }
3020
3021 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
3022 {
3023   bool res = false;
3024   if ( smpTab->currentIndex() == ATT_TAB ){
3025     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
3026       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3027       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3028       res = insertAttractor(mySMapObject, myAttObject);
3029     }
3030   }
3031   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3032     if ( myGeomSelWdg1->IsObjectSelected() ){
3033       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3034       res = insertElement(mySMapObject);
3035     }
3036   }
3037   if ( !res ) {
3038     // Local size should be more than 0
3039     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3040     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3041     return;
3042   }
3043   getGeomSelectionTool()->selectionMgr()->clearFilters();
3044   myAttDistSpin->setValue(0.);
3045   myAttSizeSpin->setValue(0.);
3046   myAttDistSpin2->setValue(0.);
3047   mySmpSizeSpin->setValue(0.);
3048   myConstSizeCheck->setChecked(false);
3049   myAttractorCheck->setChecked(false);
3050   myGeomSelWdg1->deactivateSelection();
3051   myGeomSelWdg2->deactivateSelection();
3052   myAttSelWdg->deactivateSelection();
3053   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3054   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3055   myAttSelWdg->SetObject(CORBA::Object::_nil());
3056 }
3057
3058 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
3059 {
3060   bool res = false;
3061   if ( smpTab->currentIndex() == ATT_TAB ){    
3062     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
3063       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3064       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3065       res = insertAttractor(mySMapObject, myAttObject, /*modify = */true);
3066     }
3067   }
3068   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3069     if ( myGeomSelWdg1->IsObjectSelected() ){
3070       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3071       res = insertElement(mySMapObject, /*modify = */true);  
3072     }  
3073   }
3074   if ( !res ) {
3075     // Local size should be more than 0
3076     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3077     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3078     return;
3079   }
3080   getGeomSelectionTool()->selectionMgr()->clearFilters();
3081   myAttDistSpin->setValue(0.);
3082   myAttSizeSpin->setValue(0.);
3083   myAttDistSpin2->setValue(0.);
3084   mySmpSizeSpin->setValue(0.);
3085   myConstSizeCheck->setChecked(false);
3086   myAttractorCheck->setChecked(false);
3087   myGeomSelWdg1->deactivateSelection();
3088   myGeomSelWdg2->deactivateSelection();
3089   myAttSelWdg->deactivateSelection();
3090   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3091   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3092   myAttSelWdg->SetObject(CORBA::Object::_nil());
3093 }
3094
3095 bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
3096 {
3097   // BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3098   //   BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3099
3100   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3101
3102   TopAbs_ShapeEnum shapeType;
3103   string entry, shapeName;
3104   entry = (string) anObject->GetStudyEntry();
3105   shapeName = anObject->GetName();
3106   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
3107   // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
3108   // in order to write the size map with the right syntax in StoreParamsToHypo 
3109   // (f(t) for edges, f(u,v) for faces ...)
3110   if (shapeType == TopAbs_COMPOUND){
3111     TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
3112     TopoDS_Shape childShape;
3113     TopoDS_Iterator anIt(theShape);
3114     for(;anIt.More();anIt.Next()){
3115       childShape = anIt.Value();
3116       shapeType = childShape.ShapeType();
3117       if(!childShape.IsNull()){
3118         break;
3119       }
3120     }
3121   }
3122   mySizeMapTable->setFocus();
3123   QString shapeEntry;
3124   shapeEntry = QString::fromStdString(entry);
3125   double phySize = mySmpSizeSpin->value();
3126
3127   if ( phySize == 0 )
3128     return false; // Local size should be more than 0
3129
3130   std::ostringstream oss;
3131   oss << phySize;
3132   QString sizeMap;
3133   sizeMap  = QString::fromStdString(oss.str());
3134   QTreeWidgetItem* item = new QTreeWidgetItem();
3135   if (modify){
3136     int rowToChange = findRowFromEntry(shapeEntry);
3137     item = mySizeMapTable->topLevelItem( rowToChange );
3138   }
3139   else{
3140     if (that->mySMPMap.contains(shapeEntry)) {  
3141       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3142         return false;
3143       }
3144     }
3145     mySizeMapTable->addTopLevelItem(item);
3146   }
3147   that->mySMPMap[shapeEntry] = sizeMap;
3148   //that->myDistMap[shapeEntry] = 0. ;
3149   that->mySMPShapeTypeMap[shapeEntry] = shapeType;
3150   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
3151   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3152   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
3153   item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3154   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3155   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3156   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3157   mySizeMapTable->clearSelection();
3158
3159   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3160     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3161     myStdWidget->onPhysicalMeshChanged();
3162   }
3163   return true;
3164 }
3165
3166 bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
3167 {
3168   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3169     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3170
3171   TopAbs_ShapeEnum shapeType;
3172   string entry, attEntry, faceName, attName;
3173   entry = (string) aFace->GetStudyEntry();
3174   attEntry = (string) anAttractor->GetStudyEntry();
3175   faceName = aFace->GetName();
3176   attName = anAttractor->GetName();
3177   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
3178   mySizeMapTable->setFocus();
3179   QString shapeEntry = QString::fromStdString(entry);
3180   QString qAttEntry = QString::fromStdString(attEntry);
3181   
3182   double phySize = h->GetPhySize();
3183   double infDist = 0. ;
3184   double constDist = 0. ;
3185   phySize = myAttSizeSpin->value();
3186
3187   if ( phySize == 0 )
3188     return false; // Local size should be more than 0
3189
3190   if (myAttractorCheck->isChecked()){
3191     infDist = myAttDistSpin->value();
3192   }
3193   if (myConstSizeCheck->isChecked()){
3194     constDist = myAttDistSpin2->value();
3195   } 
3196   std::ostringstream oss;
3197   std::ostringstream oss2;
3198   std::ostringstream oss3;
3199   oss << phySize;
3200   oss2 << infDist;
3201   oss3 << constDist;
3202   QString sizeMap  = QString::fromStdString(oss.str());
3203   QString infDistString = QString::fromStdString(oss2.str());
3204   QString constDistString = QString::fromStdString(oss3.str());
3205   
3206   QTreeWidgetItem* item; 
3207   QTreeWidgetItem* child = 0;
3208   TAttractor attParams( attEntry.c_str(), phySize, infDist, constDist );
3209   if (modify) {
3210     int rowToChange = findRowFromEntry(shapeEntry);
3211     item = mySizeMapTable->topLevelItem( rowToChange );
3212     
3213     for ( int i = 0, nb = item->childCount(); i < nb; ++i )
3214       if (( child = item->child( i )))
3215         if ( qAttEntry == child->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString() )
3216           break;
3217     TAttractorVec & attVec = myATTMap[shapeEntry];
3218     for ( size_t i = 0; i < attVec.size(); ++i )
3219       if ( attVec[i].attEntry == attEntry )
3220       {
3221         attVec[i] = attParams;
3222         break;
3223       }
3224   }
3225   else{
3226     // if (that->mySMPMap.contains(shapeEntry)) {  
3227     //   if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3228     //     return false;
3229     //   }
3230     // }
3231     int rowToChange = findRowFromEntry(shapeEntry);
3232     if ( rowToChange < mySizeMapTable->topLevelItemCount() )
3233     {
3234       item = mySizeMapTable->topLevelItem( rowToChange );
3235     }
3236     else {
3237       item = new QTreeWidgetItem();
3238       mySizeMapTable->addTopLevelItem(item);
3239     }
3240     child = new QTreeWidgetItem();
3241     item->addChild(child);
3242     bool exists = false;
3243     TAttractorVec & attVec = myATTMap[shapeEntry];
3244     for ( size_t i = 0; i < attVec.size(); ++i )
3245       if ( attVec[i].attEntry == attEntry )
3246       {
3247         attVec[i] = attParams;
3248         exists = true;
3249         break;
3250       }
3251     if ( !exists )
3252       myATTMap[shapeEntry].push_back( attParams );
3253   }
3254   mySMPMap.insert(shapeEntry,sizeMap);
3255   mySMPShapeTypeMap.insert(shapeEntry,shapeType);
3256   item->setExpanded(true); 
3257   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3258   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
3259   if (infDist > std::numeric_limits<double>::epsilon()){
3260     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
3261   }
3262   else if (constDist > std::numeric_limits<double>::epsilon()){
3263     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
3264   }
3265   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );    
3266   
3267   child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
3268   child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
3269   child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3270   
3271   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3272   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3273   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3274
3275   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3276     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3277     myStdWidget->onPhysicalMeshChanged();
3278   }
3279   return true;
3280 }
3281
3282 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
3283 {
3284   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
3285   for ( ; row < nbRows; ++row )
3286     if (! sizeMapValidationFromRow(row))
3287       return false;
3288   return true;
3289 }
3290
3291 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
3292 {
3293   QString myEntry   = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3294   bool res = sizeMapValidationFromEntry(myEntry,displayError);
3295   mySizeMapTable->setFocus();
3296   return res;
3297 }
3298
3299 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
3300 {
3301
3302   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3303
3304   if (! that->mySMPMap.contains(myEntry)) {
3305     return false;
3306   }
3307   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
3308     return false;
3309   }
3310
3311   string expr;
3312
3313   if (that->mySMPMap[myEntry].startsWith("def")) {
3314     expr = that->mySMPMap[myEntry].toStdString();
3315   }
3316   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
3317     if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)(?:;(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+))?\\)$")) != 1)) {
3318
3319       if (displayError)
3320         SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False[;d])" );
3321       return false;
3322     }
3323     return true;
3324   }
3325   else {
3326     // case size map is empty
3327     if (that->mySMPMap[myEntry].isEmpty()) {
3328       if (displayError)
3329         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
3330       return false;
3331     }
3332     else {
3333       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
3334         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
3335       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
3336         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
3337       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
3338         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
3339     }
3340   }
3341   //assert(Py_IsInitialized());
3342   if (! Py_IsInitialized())
3343     throw ("Erreur: Python interpreter is not initialized");
3344   PyGILState_STATE gstate;
3345   gstate = PyGILState_Ensure();
3346
3347   string  err_description="";
3348   PyObject* obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
3349   if (obj == NULL){
3350     fflush(stderr);
3351     err_description="";
3352     PyObject* new_stderr = newPyStdOut(err_description);
3353     PyObject* old_stderr = PySys_GetObject((char*)"stderr");
3354     Py_INCREF(old_stderr);
3355     PySys_SetObject((char*)"stderr", new_stderr);
3356     PyErr_Print();
3357     PySys_SetObject((char*)"stderr", old_stderr);
3358     Py_DECREF(new_stderr);
3359     if (displayError)
3360       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
3361     PyGILState_Release(gstate);
3362     return false;
3363   }
3364   Py_DECREF(obj);
3365
3366   PyObject* func = PyObject_GetAttrString(main_mod, "f");
3367   if ( func == NULL){
3368     fflush(stderr);
3369     err_description="";
3370     PyObject* new_stderr = newPyStdOut(err_description);
3371     PyObject* old_stderr = PySys_GetObject((char*)"stderr");
3372     Py_INCREF(old_stderr);
3373     PySys_SetObject((char*)"stderr", new_stderr);
3374     PyErr_Print();
3375     PySys_SetObject((char*)"stderr", old_stderr);
3376     Py_DECREF(new_stderr);
3377     if (displayError)
3378       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
3379     PyGILState_Release(gstate);
3380     return false;
3381   }
3382
3383   PyGILState_Release(gstate);
3384
3385
3386   return true;
3387 }
3388
3389 //================================================================================
3390 /*!
3391  * \brief SLOT: Activate selection of faces in the Viewer
3392  */
3393 //================================================================================
3394
3395 void BLSURFPluginGUI_HypothesisCreator::onHyPatchFaceSelection(bool on)
3396 {
3397   if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
3398   {
3399     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
3400     QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
3401     myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
3402   }
3403   myHyPatchFaceSelector->setVisible( on );  // show its buttons
3404   myHyPatchFaceSelector->ShowPreview( on ); // show faces in the Viewer
3405   // treat selection or not
3406   myHyPatchFaceSelector->ActivateSelection( on || myHyPatchGroupSelBtn->isChecked() );
3407
3408   if ( on )
3409     myHyPatchGroupSelBtn->setChecked( false );
3410 }
3411
3412 //================================================================================
3413 /*!
3414  * \brief SLOT: Deactivate selection of faces in the Viewer
3415  */
3416 //================================================================================
3417
3418 void BLSURFPluginGUI_HypothesisCreator::onHyPatchGroupSelection(bool on)
3419 {
3420   if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
3421   {
3422     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
3423     QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
3424     myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
3425   }
3426   if ( !myHyPatchFaceSelBtn->isChecked() )
3427   {
3428     myHyPatchFaceSelector->setVisible( false ); // show its buttons
3429     myHyPatchFaceSelector->ShowPreview( false ); // show faces in the Viewer
3430   }
3431   // treat selection or not
3432   myHyPatchFaceSelector->ActivateSelection( on || myHyPatchFaceSelBtn->isChecked() );
3433
3434   if ( on )
3435     myHyPatchFaceSelBtn->setChecked( false );
3436 }
3437
3438 //================================================================================
3439 /*!
3440  * \brief SLOT: show IDs of selected faces in Tags LineEdit
3441  */
3442 //================================================================================
3443
3444 void BLSURFPluginGUI_HypothesisCreator::onHyPatchSelectionChanged()
3445 {
3446   QString tagString;
3447   const QList<int>& tags = myHyPatchFaceSelector->GetSelectedIDs();
3448   for ( int i = 0; i < tags.size(); ++i )
3449     tagString += QString::number( tags[i] ) + " ";
3450
3451   myHyPatchTagsLE->setText( tagString );
3452 }
3453
3454 //================================================================================
3455 /*!
3456  * \brief SLOT: Add the Tags to the HyperPatch table
3457  */
3458 //================================================================================
3459
3460 void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
3461 {
3462   QStringList tagList = myHyPatchTagsLE->text().split(" ",  QString::SkipEmptyParts);
3463   if ( tagList.size() > 1 )
3464   {
3465     addHyPatchToTable( myHyPatchTagsLE->text() );
3466     myHyPatchTagsLE->setText("");
3467   }
3468 }
3469
3470 //================================================================================
3471 /*!
3472  * \brief Add a row to myHyPatchTable
3473  */
3474 //================================================================================
3475
3476 void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags)
3477 {
3478   if ( tags.isEmpty() ) return;
3479
3480   QTableWidgetItem* cell = new QTableWidgetItem( tags );
3481   cell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
3482
3483   int row = myHyPatchTable->rowCount();
3484   myHyPatchTable->insertRow( row );
3485   myHyPatchTable->setItem( row, 0, cell );
3486 }
3487
3488 //================================================================================
3489 /*!
3490  * \brief SLOT: remove selected rows from the HyperPatch table
3491  */
3492 //================================================================================
3493
3494 void BLSURFPluginGUI_HypothesisCreator::onHyPatchRemove()
3495 {
3496   QList<QTableWidgetItem *> items = myHyPatchTable->selectedItems();
3497   while ( !items.isEmpty() )
3498   {
3499     myHyPatchTable->removeRow( items[0]->row() );
3500     items = myHyPatchTable->selectedItems();
3501   }
3502 }
3503
3504 bool BLSURFPluginGUI_HypothesisCreator::hasGeom() const
3505 {
3506   return hypType() == BLSURFPlugin_Hypothesis::GetHypType(true);
3507 }
3508
3509 QString BLSURFPluginGUI_HypothesisCreator::caption() const
3510 {
3511   return tr( "BLSURF_TITLE" );
3512 }
3513
3514 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
3515 {
3516   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
3517 }
3518
3519 QString BLSURFPluginGUI_HypothesisCreator::type() const
3520 {
3521   return tr( "BLSURF_HYPOTHESIS" );
3522 }
3523
3524 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
3525 {
3526   return "blsurf_hypo_page.html";
3527 }
3528
3529 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
3530 {
3531
3532   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3533   if( anApp )
3534     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3535   else
3536     return 0;
3537 }
3538
3539 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
3540 {
3541   CORBA::Object_var obj;
3542   SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.toStdString().c_str() );
3543   if (!aSObj->_is_nil()) {
3544     obj = aSObj->GetObject();
3545     aSObj->UnRegister();
3546   }
3547   return obj;
3548 }
3549
3550 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
3551   int endRow = mySizeMapTable->topLevelItemCount()-1;
3552   int row = 0;
3553   for ( ; row <= endRow; ++row )
3554   {
3555     QString entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3556     if (entry == entryForChecking )
3557       break;
3558   }
3559   return row;
3560 }
3561
3562