Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2021  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   int periodicityVisibleColumns = 2;
1014   for (int 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 {
1304   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
1305   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1306   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1307   QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1308   QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1309   QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
1310   QTreeWidgetItem* parent = item->parent();
1311   
1312   clearEnforcedVertexWidgets();
1313   
1314   if (parent && (!x.isNull() || !entry.isNull())) {
1315       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
1316       QString toolTip = shapeName + QString(": ") + vertexName.toString();
1317       if (entry.isNull()) {
1318         toolTip += QString("(") + x.toString();
1319         toolTip += QString(", ") + y.toString();
1320         toolTip += QString(", ") + z.toString();
1321         toolTip += QString(")");
1322       }
1323       
1324       if (!groupName.isEmpty())
1325         toolTip += QString(" [") + groupName + QString("]");
1326
1327       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1328
1329     if (!x.isNull()) {
1330       myXCoord->SetValue(x.toDouble());
1331       myYCoord->SetValue(y.toDouble());
1332       myZCoord->SetValue(z.toDouble());
1333     }
1334     
1335     if (!groupName.isEmpty())
1336       myGroupName->setText(groupName);
1337   }
1338 }
1339
1340 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex()
1341 {
1342   size_t nbSelEnfVertex = myEnfVertexWdg->NbObjects();
1343   clearEnforcedVertexWidgets();
1344   if (nbSelEnfVertex == 1)
1345   {
1346     if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
1347     return ;
1348
1349     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
1350     if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1351       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
1352       if (CORBA::is_nil(measureOp))
1353         return;
1354       
1355       CORBA::Double x,y,z;
1356       measureOp->PointCoordinates (myEnfVertex, x, y, z);
1357       if ( measureOp->IsDone() )
1358       {
1359         myXCoord->SetValue(x);
1360         myYCoord->SetValue(y);
1361         myZCoord->SetValue(z);
1362       }
1363     }
1364   }
1365 }
1366
1367 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1368 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
1369 of the enforced vertex clicked in the tree widget.
1370 */
1371 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1372 {
1373   clearEnforcedVertexWidgets();
1374   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
1375   if (! items.isEmpty() && items.size() == 1) {
1376     QTreeWidgetItem *item = items[0];
1377 //     for (int i=0 ; i < items.size() ; i++) {
1378 //       item = items[i];
1379       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1380       QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1381       QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1382       QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1383       QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
1384       if (!x.isNull()/* && entry.isNull()*/) {
1385         myXCoord->SetValue(x.toDouble());
1386         myYCoord->SetValue(y.toDouble());
1387         myZCoord->SetValue(z.toDouble());
1388 //         break;
1389       }
1390       if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1391         myGroupName->setText(group.toString());
1392 //     }
1393   }
1394 }
1395
1396 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1397 This method adds a face containing enforced vertices in the tree widget.
1398 */
1399 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName)
1400 {
1401   // Find theFaceEntry item
1402   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1403   QTreeWidgetItem* theItem;
1404   if (theItemList.empty()) {
1405     theItem = new QTreeWidgetItem();
1406     theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1407     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1408     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1409     myEnforcedTreeWidget->addTopLevelItem(theItem);
1410   }
1411   else {
1412     theItem = theItemList[0];
1413   }
1414   return theItem;
1415 }
1416
1417 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1418     This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1419 */
1420 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z,
1421                                                           std::string vertexName,
1422                                                           std::string geomEntry,
1423                                                           std::string groupName)
1424 {
1425   bool okToCreate = true;
1426
1427   const int nbVert = myEnforcedTreeWidget->topLevelItemCount();
1428   for (int row = 0; row < nbVert; row++ )
1429   {
1430     QTreeWidgetItem* child = myEnforcedTreeWidget->topLevelItem( row );
1431     QString childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1432     QString childEntry     = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1433     double childX          = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1434     double childY          = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1435     double childZ          = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1436     if (((childEntry.isEmpty()) && (childX == x) && (childY == y) && (childZ == z)) ||
1437         ( !childEntry.isEmpty() && childEntry == geomEntry.c_str() ))
1438     {
1439       // update group name
1440       if ( childGroupName != groupName.c_str() ) {
1441         child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1442       }
1443       okToCreate = false;
1444       break;
1445     } // if
1446   } // for
1447   if (!okToCreate) {
1448     return;
1449   }
1450
1451   QTreeWidgetItem *vertexItem = new QTreeWidgetItem( myEnforcedTreeWidget );
1452   vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1453   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1454   QSize iconSize = iconSelect.size()*0.7;
1455
1456   int vertexIndex=nbVert;
1457   QString myVertexName;
1458   int indexRef = -1;
1459   while(indexRef != vertexIndex) {
1460     indexRef = vertexIndex;
1461     if (vertexName.empty())
1462       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1463     else
1464       myVertexName = QString(vertexName.c_str());
1465
1466     for (int row = 0;row<nbVert;row++) {
1467       QString name = myEnforcedTreeWidget->topLevelItem(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1468       if (myVertexName == name) {
1469         vertexIndex++;
1470         break;
1471       }
1472     }
1473   }
1474   vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1475   if (geomEntry.empty()) {
1476     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1477     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1478     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1479   }
1480   else {
1481     vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1482     vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1483   }
1484   if (groupName != "")
1485     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1486
1487   QString toolTip = myVertexName;
1488   if (geomEntry.empty()) {
1489     toolTip += QString(" (%1, %2, %3").arg(x).arg(y).arg(z);
1490   }
1491   if (groupName != "")
1492     toolTip += QString(" [%1]").arg(groupName.c_str());
1493   
1494   vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1495   myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1496 }
1497
1498 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1499 This method is called when a item is added into the enforced vertices tree widget
1500 */
1501 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1502 {
1503   getGeomSelectionTool()->selectionMgr()->clearFilters();
1504   myEnfVertexWdg->deactivateSelection();
1505
1506   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1507     myEnforcedTreeWidget->resizeColumnToContents(column);
1508
1509   // Vertex selection
1510   size_t selEnfVertex = myEnfVertexWdg->NbObjects();
1511   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1512
1513   if ((selEnfVertex == 0) && coordsEmpty)
1514     return;
1515
1516   string entry, shapeName;
1517   {
1518     std::string groupName = myGroupName->text().simplified().toStdString();
1519
1520     if (selEnfVertex <= 1)
1521     {
1522       double x,y,z;
1523       x = myXCoord->GetValue();
1524       y = myYCoord->GetValue();
1525       z = myZCoord->GetValue();
1526       if (selEnfVertex == 1) {
1527         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1528         addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1529       }
1530       else
1531         addEnforcedVertex(x, y, z, "", "", groupName);
1532     }
1533     else
1534     {
1535       if ( CORBA::is_nil(getGeomEngine()))
1536         return;
1537
1538       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
1539       if (CORBA::is_nil(measureOp))
1540         return;
1541
1542       CORBA::Double x,y,z;
1543       x = y = z = 0.;
1544       for (size_t j = 0 ; j < selEnfVertex ; j++)
1545       {
1546         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1547         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1548           measureOp->PointCoordinates (myEnfVertex, x, y, z);
1549           if ( measureOp->IsDone() )
1550             addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1551         } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1552             addEnforcedVertex(0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1553         }
1554       }
1555     }
1556   }
1557
1558   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1559   
1560   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1561     myEnforcedTreeWidget->resizeColumnToContents(column);
1562
1563   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1564     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1565     myStdWidget->onPhysicalMeshChanged();
1566   }
1567 }
1568
1569 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1570 This method is called when a item is removed from the enforced vertices tree widget
1571 */
1572 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1573 {
1574   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1575   QList<QTreeWidgetItem *> selectedVertices;
1576   QSet<QTreeWidgetItem *> selectedEntries;
1577   QTreeWidgetItem* item;
1578
1579   foreach( item, selectedItems ) {
1580     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1581     if (! value.isNull())
1582       selectedVertices.append(item);
1583     else {
1584       value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1585       if (! value.isNull())
1586         selectedVertices.append(item);
1587       else
1588         selectedEntries.insert(item);
1589     }
1590   }
1591
1592   foreach(item,selectedVertices) {
1593     QTreeWidgetItem* parent = item->parent();
1594     if ( parent )
1595       parent->removeChild(item);
1596     delete item;
1597     if ( parent && parent->childCount() == 0) {
1598       if (selectedEntries.contains(parent))
1599         selectedEntries.remove(parent);
1600       delete parent;
1601     }
1602   }
1603
1604   foreach(item,selectedEntries) {
1605     delete item;
1606   }
1607
1608   myEnforcedTreeWidget->selectionModel()->clearSelection();
1609 }
1610
1611
1612 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1613 {
1614   myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1615 }
1616
1617 /** BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
1618 This method is called when a item is added into the periodicity table widget
1619 */
1620 void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
1621 {
1622   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1623
1624   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1625   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1626   for ( ; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1627     {
1628           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1629           w1->deactivateSelection();
1630     }
1631
1632
1633   // Source-Target selection
1634   size_t selSource = myPeriodicitySourceFaceWdg->NbObjects();
1635   size_t selTarget = myPeriodicityTargetFaceWdg->NbObjects();
1636
1637   if (selSource == 0 || selTarget == 0)
1638     return;
1639
1640   // Vertices selection
1641   if (myPeriodicityGroupBox2->isChecked())
1642     {
1643       size_t P1Ssel = myPeriodicityP1SourceWdg->NbObjects();
1644       size_t P2Ssel = myPeriodicityP2SourceWdg->NbObjects();
1645       size_t P3Ssel = myPeriodicityP3SourceWdg->NbObjects();
1646       size_t P1Tsel = myPeriodicityP1TargetWdg->NbObjects();
1647       //size_t P2Tsel = myPeriodicityP2TargetWdg->NbObjects();
1648       size_t P3Tsel = myPeriodicityP3TargetWdg->NbObjects();
1649
1650       if (P1Ssel!=1 || P2Ssel!=1 || P3Ssel!=1 || P1Tsel!=1 || P3Tsel!=1 || P3Tsel!=1)
1651         {
1652           QString msg = tr("BLSURF_PERIODICITY_WRONG_NUMBER_OF_VERTICES");
1653           SUIT_MessageBox::critical( dlg(),"Error" , msg );
1654           return;
1655         }
1656     }
1657
1658   // Add Source-Target in table
1659   string shapeEntry, sourceEntry, targetEntry;
1660   string shapeName, sourceName, targetName;
1661   GEOM::GEOM_Object_var shape;
1662
1663   QTreeWidgetItem* item = new QTreeWidgetItem();
1664   myPeriodicityTreeWidget->addTopLevelItem(item);
1665
1666   item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
1667
1668
1669   int k=0;
1670   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1671     {
1672       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1673       shape = w1->GetObject< GEOM::GEOM_Object >(0);
1674       shapeName = shape->GetName();
1675       shapeEntry = shape->GetStudyEntry();
1676       item->setData(k, Qt::EditRole, shapeName.c_str() );
1677       item->setData(k, Qt::UserRole, shapeEntry.c_str() );
1678       if (! myPeriodicityGroupBox2->isChecked() && k==1)
1679         break;
1680     }
1681
1682   // Add shape type in tree
1683   string onFace = (myPeriodicityOnFaceRadioButton->isChecked()) ? "1" : "0";
1684   item->setData(PERIODICITY_SHAPE_TYPE, Qt::UserRole, onFace.c_str());
1685
1686   // Blank input fields
1687   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1688     {
1689       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1690       w1->SetObject(GEOM::GEOM_Object::_nil());
1691     }
1692
1693 //  for (int column = 0; column < myPeriodicityTreeWidget->columnCount(); ++column)
1694 //    myPeriodicityTreeWidget->resizeColumnToContents(column);
1695
1696 }
1697
1698 /** BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
1699 This method is called when a item is removed from the periodicity tree widget
1700 */
1701 void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
1702 {
1703   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
1704   QTreeWidgetItem* item;
1705
1706   foreach(item,selectedItems) {
1707     delete item;
1708   }
1709
1710   myEnforcedTreeWidget->selectionModel()->clearSelection();
1711 }
1712
1713 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked()
1714 This method enable clears the field for periodicity by vertices
1715 */
1716 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked(bool checked)
1717 {
1718   if (! checked)
1719     {
1720       for (int k=2; k<myPeriodicitySelectionWidgets.size(); k++)
1721         {
1722           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k] );
1723           w1->deactivateSelection();
1724           w1->SetObject(CORBA::Object::_nil());
1725         }
1726     }
1727 }
1728
1729 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1730 This method enable the proper shape selection widget to Face or Edge shapes
1731 */
1732 //void BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1733 //{
1734 //  if (myPeriodicityOnFaceRadioButton->isChecked())
1735 //    {
1736 //      myPeriodicitySourceEdgeWdg->hide();
1737 //      myPeriodicityTargetEdgeWdg->hide();
1738 //      myPeriodicitySourceFaceWdg->show();
1739 //      myPeriodicityTargetFaceWdg->show();
1740 //    }
1741 //  else
1742 //    {
1743 //      myPeriodicitySourceFaceWdg->hide();
1744 //      myPeriodicityTargetFaceWdg->hide();
1745 //      myPeriodicitySourceEdgeWdg->show();
1746 //      myPeriodicityTargetEdgeWdg->show();
1747 //    }
1748 //}
1749
1750 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityTreeClicked(QTreeWidgetItem* item, int /*row*/)
1751 {
1752   QString shapeName, shapeEntry;
1753   CORBA::Object_var shape;
1754   int k=0;
1755   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1756   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1757     {
1758       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1759
1760       shapeName = item->data(k, Qt::EditRole).toString();
1761       shapeEntry = item->data(k, Qt::UserRole).toString();
1762       if (! shapeEntry.isEmpty())
1763         {
1764           shape = entryToObject(shapeEntry);
1765           w1->SetObject(shape);
1766           w1->deactivateSelection();
1767           if (k==2)
1768             myPeriodicityGroupBox2->setChecked(1);
1769         }
1770       else if(k==2)
1771         myPeriodicityGroupBox2->setChecked(0);
1772     }
1773
1774   if (item->data(PERIODICITY_SHAPE_TYPE, Qt::UserRole) == "1")
1775     myPeriodicityOnFaceRadioButton->setChecked(true);
1776   else
1777     myPeriodicityOnEdgeRadioButton->setChecked(true);
1778
1779
1780 }
1781
1782 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1783 This method gives the focus to the next selection widget when a content is modified in a selection widget.
1784 */
1785 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1786 {
1787   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1788
1789   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1790   int k=0;
1791   // find wich selection widget is activated
1792   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1793     {
1794       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1795       if (w1->IsSelectionActivated() && k<(myPeriodicitySelectionWidgets.size()-1))
1796         {
1797           // don't activate vertex selection if the group box is not checked
1798           if (k==1 && !myPeriodicityGroupBox2->isChecked())
1799             break;
1800           // clear the selection, to avoid to put the same object in the other widget
1801           that->getGeomSelectionTool()->selectionMgr()->clearSelected();
1802           // activate the next widget
1803           StdMeshersGUI_ObjectReferenceParamWdg * w2 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k+1] );
1804           w2->activateSelection();
1805           break;
1806         }
1807     }
1808 }
1809
1810
1811 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1812     This method updates the GUI widgets with the hypothesis data
1813 */
1814 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1815 {
1816   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1817
1818   BlsurfHypothesisData data;
1819   that->readParamsFromHypo( data );
1820
1821   if ( myName ) {
1822     myName->setText( data.myName );
1823     QFontMetrics metrics( myName->font() );
1824     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1825   }
1826   myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1827   myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1828   if (data.myPhySize <= 0)
1829     myStdWidget->myPhySize->setText("");
1830   else
1831     myStdWidget->myPhySize->SetValue( data.myPhySize );
1832   myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1833   if (data.myMinSize < 0)
1834     myStdWidget->myMinSize->setText("");
1835   else
1836     myStdWidget->myMinSize->SetValue( data.myMinSize );
1837   myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1838   if (data.myMaxSize < 0)
1839     myStdWidget->myMaxSize->setText("");
1840   else
1841     myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1842   myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1843   myStdWidget->myUseGradation->setChecked( data.myUseGradation );
1844   if (data.myGradation <= 0 || !data.myUseGradation )
1845     myStdWidget->myGradation->setText("");
1846   else
1847     myStdWidget->myGradation->SetValue( data.myGradation );
1848   myStdWidget->myUseVolumeGradation->setChecked( data.myUseVolumeGradation );
1849   if (data.myVolumeGradation <= 0 || !data.myUseVolumeGradation )
1850     myStdWidget->myVolumeGradation->setText("");
1851   else
1852     myStdWidget->myVolumeGradation->SetValue( data.myVolumeGradation );
1853
1854   foreach (QAbstractButton* button, myStdWidget->myButtonGroupElementType->buttons()) {
1855     if (myStdWidget->myButtonGroupElementType->id(button) == data.myElementType) {
1856       button->setChecked(true);
1857       break;
1858     }
1859   }
1860
1861   myStdWidget->myUseSurfaceProximity->setChecked( data.myUseSurfaceProximity );
1862   myStdWidget->myNbSurfaceProximityLayers->setValue( data.myNbSurfaceProximityLayers );
1863   myStdWidget->mySurfaceProximityRatio->SetValue( data.mySurfaceProximityRatio );
1864   myStdWidget->myUseVolumeProximity->setChecked( data.myUseVolumeProximity );
1865   myStdWidget->myNbVolumeProximityLayers->setValue( data.myNbVolumeProximityLayers );
1866   myStdWidget->myVolumeProximityRatio->SetValue( data.myVolumeProximityRatio );
1867   if ( !data.myUseSurfaceProximity )
1868   {
1869     //myStdWidget->myNbSurfaceProximityLayers->setText("");
1870     myStdWidget->mySurfaceProximityRatio->setText("");
1871   }
1872   if ( !data.myUseVolumeProximity )
1873   {
1874     //myStdWidget->myNbVolumeProximityLayers->setText("");
1875     myStdWidget->myVolumeProximityRatio->setText("");
1876   }
1877
1878   if (data.myAngleMesh < 0)
1879     myStdWidget->myAngleMesh->setText("");
1880   else
1881     myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1882   if (data.myChordalError <= 0)
1883     myStdWidget->myChordalError->setText("");
1884   else
1885     myStdWidget->myChordalError->SetValue( data.myChordalError );
1886   myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1887   if (data.myAnisotropicRatio <= 0)
1888     myStdWidget->myAnisotropicRatio->setText("");
1889   else
1890     myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1891   myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1892   if (data.myTinyEdgeLength <= 0)
1893     myStdWidget->myTinyEdgeLength->setText("");
1894   else
1895     myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1896   myStdWidget->myOptimiseTinyEdges->setChecked( data.myOptimiseTinyEdges );
1897   if (data.myTinyEdgeOptimisLength <= 0)
1898     myStdWidget->myTinyEdgeOptimisLength->setText("");
1899   else
1900     myStdWidget->myTinyEdgeOptimisLength->SetValue( data.myTinyEdgeOptimisLength );
1901   myStdWidget->myCorrectSurfaceIntersection->setChecked( data.myCorrectSurfaceIntersection );
1902   if (data.myCorrectSurfaceIntersectionMaxCost <= 0)
1903     myStdWidget->myCorrectSurfaceIntersectionMaxCost->setText("");
1904   else
1905     myStdWidget->myCorrectSurfaceIntersectionMaxCost->SetValue( data.myCorrectSurfaceIntersectionMaxCost );
1906   myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1907   if (data.myBadElementAspectRatio <= 0)
1908     myStdWidget->myBadElementAspectRatio->setText("");
1909   else
1910     myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1911   myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1912   myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1913   
1914   myStdWidget->resizeWidgets();  
1915   
1916   myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1917
1918   if ( myOptions.operator->() ) {
1919     for ( int i = 0, nb = myOptions->length(); i < nb; ++i )
1920       myAdvWidget->AddOption( TBL_MESHING, that->myOptions[i].in() );
1921   }
1922   if ( myPreCADOptions.operator->() ) {
1923     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i )
1924       myAdvWidget->AddOption( TBL_PRECAD, that->myPreCADOptions[i].in() );
1925   }
1926   if ( myCustomOptions.operator->() ) {
1927     for ( int i = 0, nb = myCustomOptions->length(); i < nb; ++i )
1928       myAdvWidget->AddOption( TBL_CUSTOM, that->myCustomOptions[i].in() );
1929   }
1930   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1931   myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1932 //   myGMFFileMode->setChecked(data.myGMFFileMode);
1933   
1934   // Sizemaps
1935   QMapIterator<QString, QString> i(that->mySMPMap);
1936   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1937   while (i.hasNext()) {
1938     i.next();
1939     const QString entry = i.key();
1940     const QString sizeMap = i.value();
1941     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1942     //int row = mySizeMapTable->topLevelItemCount();
1943     QTreeWidgetItem* item = new QTreeWidgetItem();
1944     mySizeMapTable->addTopLevelItem( item );
1945     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1946     item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1947     item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1948     if (that->myATTMap.contains(entry)) {
1949       TAttractorVec & attVec = that->myATTMap[entry];
1950       for ( size_t i = 0; i < attVec.size(); ++i )
1951       {
1952         std::string attName = myGeomToolSelected->getNameFromEntry( attVec[i].attEntry );
1953         QTreeWidgetItem* child = new QTreeWidgetItem();
1954         item->addChild( child );
1955         item->setExpanded(true);
1956         child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( attVec[i].startSize  ));
1957         child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attVec[i].attEntry.c_str() ));
1958         child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( attName.c_str() ));
1959
1960         if ( attVec[i].infDist >  std::numeric_limits<double>::epsilon()){
1961           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Attractor" ));
1962         }
1963         else{
1964           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Constant Size" ));
1965         }
1966       }
1967     }
1968     else
1969     {
1970       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1971     }
1972   }
1973   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1974   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1975   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1976
1977   // Enforced vertices
1978   TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1979
1980   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1981     TEntry entry = (*evmIt).first;
1982     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1983
1984     //QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1985
1986     TEnfVertexList evs = (*evmIt).second;
1987
1988     TEnfVertexList::const_iterator evsIt = evs.begin();
1989     TEnfVertex *enfVertex;
1990     for ( ; evsIt != evs.end() ; ++evsIt) {
1991       enfVertex = (*evsIt);
1992       double x = 0, y = 0, z = 0;
1993       if (enfVertex->coords.size()) {
1994         x = enfVertex->coords[0];
1995         y = enfVertex->coords[1];
1996         z = enfVertex->coords[2];
1997       }
1998       that->addEnforcedVertex(x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1999     }
2000   }
2001
2002   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
2003     myEnforcedTreeWidget->resizeColumnToContents(column);
2004
2005   myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
2006   myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
2007   myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
2008
2009   // Periodicity
2010
2011   // Add an item in the tree widget for each association
2012   for (size_t i=0 ; i<data.preCadPeriodicityVector.size() ; i++)
2013   {
2014     QTreeWidgetItem* item = new QTreeWidgetItem();
2015     myPeriodicityTreeWidget->addTopLevelItem(item);
2016     item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
2017     TPreCadPeriodicity periodicity_i = data.preCadPeriodicityVector[i];
2018     for (size_t k=0; k<periodicity_i.size(); k++)
2019     {
2020       string shapeEntry = periodicity_i[k];
2021       string shapeName = myGeomToolSelected->getNameFromEntry(shapeEntry);
2022       item->setData((int) k, Qt::EditRole, shapeName.c_str() );
2023       item->setData((int) k, Qt::UserRole, shapeEntry.c_str() );
2024     }
2025   }
2026
2027   // Hyper patches
2028   QString patchEntries;
2029   for ( int i = 0; i < data.hyperpatches.size(); ++i )
2030   {
2031     if ( i < data.hyperEntries.size() )
2032       patchEntries = data.hyperEntries[i];
2033     that->addHyPatchToTable( data.hyperpatches[i], patchEntries );
2034   }
2035   // update widgets
2036   that->myStdWidget->onPhysicalMeshChanged();
2037   that->myStdWidget->onGeometricMeshChanged();
2038   that->onStateChange();
2039 }
2040
2041 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
2042 This method updates the hypothesis data with the GUI widgets content.
2043 */
2044 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
2045 {
2046   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2047
2048   BlsurfHypothesisData data;
2049   QString guiHyp = that->readParamsFromWidgets( data );
2050   that->storeParamsToHypo( data );
2051
2052   return guiHyp;
2053 }
2054
2055 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
2056 Updates the hypothesis data from hypothesis values.
2057 */
2058 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
2059 {
2060   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2061     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
2062
2063   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
2064   h_data.myName = isCreation() && data ? hypName() : "";
2065
2066   h_data.myPhysicalMesh           = (int) h->GetPhysicalMesh();
2067   h_data.myGeometricMesh          = (int) h->GetGeometricMesh();
2068   h_data.myPhySize                = h->GetPhySize();
2069   h_data.myPhySizeRel             = h->IsPhySizeRel();
2070   double minSize                  = h->GetMinSize();
2071   double maxSize                  = h->GetMaxSize();
2072   h_data.myMinSize                = minSize > 0 ? minSize : -1.0;
2073   h_data.myMinSizeRel             = h->IsMinSizeRel();
2074   h_data.myMaxSize                = maxSize > 0 ? maxSize : -1.0;
2075   h_data.myMaxSizeRel             = h->IsMaxSizeRel();
2076   h_data.myUseGradation           = h->GetUseGradation();
2077   h_data.myGradation              = h->GetGradation();
2078   h_data.myUseVolumeGradation     = h->GetUseVolumeGradation();
2079   h_data.myVolumeGradation        = h->GetVolumeGradation();
2080   h_data.myElementType            = h->GetElementType();
2081   double angle                    = h->GetAngleMesh();
2082   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
2083   double chordalError             = h->GetChordalError();
2084   h_data.myChordalError           = chordalError > 0 ? chordalError : -1.0;
2085   h_data.myAnisotropic            = h->GetAnisotropic();
2086   double myAnisotropicRatio       = h->GetAnisotropicRatio();
2087   h_data.myAnisotropicRatio       = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
2088   h_data.myRemoveTinyEdges        = h->GetRemoveTinyEdges();
2089   double myTinyEdgeLength         = h->GetTinyEdgeLength();
2090   h_data.myTinyEdgeLength         = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
2091   h_data.myOptimiseTinyEdges      = h->GetOptimiseTinyEdges();
2092   double myTinyEdgeOptimisLength  = h->GetTinyEdgeOptimisationLength();
2093   h_data.myTinyEdgeOptimisLength  = myTinyEdgeOptimisLength > 0 ? myTinyEdgeOptimisLength : -1.0;
2094   h_data.myCorrectSurfaceIntersection = h->GetCorrectSurfaceIntersection();
2095   double corrSurfaceIntersMaxCost = h->GetCorrectSurfaceIntersectionMaxCost();
2096   h_data.myCorrectSurfaceIntersectionMaxCost = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
2097   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
2098   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
2099   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
2100   h_data.myOptimizeMesh           = h->GetOptimizeMesh();
2101   h_data.myQuadraticMesh          = h->GetQuadraticMesh();
2102   h_data.myVerbosity              = h->GetVerbosity();
2103   //h_data.myTopology               = (int) h->GetTopology();
2104   //h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
2105   // h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
2106   // h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
2107   h_data.myUseSurfaceProximity      = h->GetSurfaceProximity        ();
2108   h_data.myNbSurfaceProximityLayers = h->GetNbSurfaceProximityLayers();
2109   h_data.mySurfaceProximityRatio    = h->GetSurfaceProximityRatio   ();
2110   h_data.myUseVolumeProximity       = h->GetVolumeProximity         ();
2111   h_data.myNbVolumeProximityLayers  = h->GetNbVolumeProximityLayers ();
2112   h_data.myVolumeProximityRatio     = h->GetVolumeProximityRatio    ();
2113
2114   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2115   that->myOptions       = h->GetOptionValues();
2116   that->myPreCADOptions = h->GetPreCADOptionValues();
2117   that->myCustomOptions = h->GetAdvancedOptionValues();
2118
2119   h_data.myGMFFileName = h->GetGMFFile();
2120 //   h_data.myGMFFileMode = h->GetGMFFileMode();
2121
2122   that->mySMPMap.clear();
2123   that->myATTMap.clear();
2124   // that->myAttDistMap.clear();
2125   // that->myDistMap.clear();
2126
2127   // classic size maps
2128   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
2129   QString fullSizeMaps;
2130   QStringList fullSizeMapList;
2131   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
2132   for ( CORBA::ULong i = 0;i<mySizeMaps->length(); ++i ) {
2133     fullSizeMaps =  mySizeMaps[i].in();
2134     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
2135     if ( fullSizeMapList.count() > 1 ) {
2136       string fullSizeMap = fullSizeMapList[1].toStdString();
2137       size_t pos = fullSizeMap.find("return")+7;
2138       QString sizeMap;
2139       try {
2140         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
2141       }
2142       catch (...) {
2143         continue;
2144       }
2145       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
2146       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
2147     }
2148   }
2149
2150   // custom size maps
2151 /*
2152   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
2153
2154   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
2155     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
2156     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
2157     if ( fullCustomSizeMapList.count() > 1 ) {
2158       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
2159       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
2160     }
2161   }
2162 */
2163   // attractor
2164   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
2165
2166   for ( CORBA::ULong i = 0;i<allMyAttractors->length(); ++i ) {
2167     QString myAttractors =  allMyAttractors[i].in();
2168     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
2169     if ( myAttractorList.count() > 1 ) {
2170       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
2171       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
2172     }
2173   }
2174   
2175   // attractor new version
2176   BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
2177   for ( CORBA::ULong i = 0;i<allMyAttractorParams->length(); ++i ) {
2178     BLSURFPlugin::TAttractorParams myAttractorParams =  allMyAttractorParams[i];
2179     QString faceEntry = myAttractorParams.faceEntry.in();
2180     QString attEntry  = myAttractorParams.attEntry.in();
2181     that->mySMPMap[faceEntry] = QString::number( myAttractorParams.startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
2182     that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
2183     that->myATTMap[faceEntry].push_back( TAttractor( myAttractorParams.attEntry.in(),
2184                                                      myAttractorParams.startSize,
2185                                                      myAttractorParams.infDist,
2186                                                      myAttractorParams.constDist ));
2187   }
2188   
2189   // Enforced vertices
2190   h_data.enfVertexList.clear();
2191   h_data.faceEntryEnfVertexListMap.clear();
2192   /* TODO GROUPS
2193   h_data.groupNameEnfVertexListMap.clear();
2194   */
2195
2196   BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
2197
2198   for ( CORBA::ULong i = 0;i<faceEntryEnfVertexListMap->length(); ++i )
2199   {
2200     std::string entry = faceEntryEnfVertexListMap[i].faceEntry.in();
2201     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
2202
2203     for (CORBA::ULong j=0 ; j<vertexList.length(); ++j)
2204     {
2205       TEnfVertex *enfVertex = new TEnfVertex();
2206       enfVertex->name      = vertexList[j].name.in();
2207       enfVertex->geomEntry = vertexList[j].geomEntry.in();
2208       enfVertex->grpName   = vertexList[j].grpName.in();
2209       for (CORBA::ULong k=0 ; k< vertexList[j].coords.length();k++)
2210         enfVertex->coords.push_back(vertexList[j].coords[k]);
2211
2212       h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
2213
2214       /* TODO GROUPS
2215       if (groupName != "") {
2216         h_data.groupNameEnfVertexListMap[groupName].insert(ev);
2217       }
2218       */
2219     }
2220 //     h_data.enfVertMap[entry] = evs;
2221 //     h_data.entryCoordsListMap[entry] = coordsList;
2222
2223     if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
2224       h_data.faceEntryEnfVertexListMap.erase(entry);
2225     }
2226   }
2227   h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
2228   h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
2229
2230   // Periodicity
2231
2232   h_data.preCadPeriodicityVector.clear();
2233
2234   BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector = h->GetPreCadFacesPeriodicityVector();
2235   AddPreCadSequenceToVector(h_data, preCadFacePeriodicityVector, true);
2236
2237   BLSURFPlugin::TPeriodicityList_var preCadEdgePeriodicityVector = h->GetPreCadEdgesPeriodicityVector();
2238   AddPreCadSequenceToVector(h_data, preCadEdgePeriodicityVector, false);
2239
2240   // Hyper Patches
2241
2242   GEOM::GEOM_Object_var geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getMainShapeEntry() );
2243   if ( geom->_is_nil() )
2244     geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getShapeEntry() );
2245
2246   h_data.hyperpatches.clear();
2247   h_data.hyperEntries.clear();
2248   BLSURFPlugin::THyperPatchList_var               patchList = h->GetHyperPatches( geom );
2249   BLSURFPlugin::THyperPatchEntriesList_var patchEntriesList = h->GetHyperPatchShapes();
2250   for ( CORBA::ULong i = 0; i < patchList->length(); ++i )
2251   {
2252     QString tags;
2253     BLSURFPlugin::THyperPatch& patch = patchList[i];
2254     for ( CORBA::ULong j = 0; j < patch.length(); ++j )
2255       tags += QString::number( patch[j] ) + " ";
2256     if ( !tags.isEmpty() )
2257       h_data.hyperpatches.append( tags );
2258
2259     if ( patchEntriesList->length() == patchList->length() )
2260     {
2261       QString entries;
2262       BLSURFPlugin::THyperPatchEntries& patchEntries = patchEntriesList[i];
2263       for ( CORBA::ULong j = 0; j < patchEntries.length(); ++j )
2264         entries += patchEntries[j].in() + QString(" ");
2265       if ( !entries.isEmpty() )
2266         h_data.hyperEntries.append( entries );
2267     }
2268   }
2269   if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() )
2270     h_data.hyperEntries.clear();
2271
2272   return true;
2273 }
2274
2275 void BLSURFPluginGUI_HypothesisCreator::AddPreCadSequenceToVector(BlsurfHypothesisData& h_data,
2276     BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const
2277 {
2278
2279   for (CORBA::ULong i=0; i<preCadFacePeriodicityVector->length(); i++ )
2280     {
2281       TPreCadPeriodicity periodicity_i(PERIODICITY_NB_COLUMN);
2282       periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN] = preCadFacePeriodicityVector[i].shape1Entry.in();
2283       periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN] = preCadFacePeriodicityVector[i].shape2Entry.in();
2284
2285       BLSURFPlugin::TEntryList sourceVertices = preCadFacePeriodicityVector[i].theSourceVerticesEntries;
2286       BLSURFPlugin::TEntryList targetVertices = preCadFacePeriodicityVector[i].theTargetVerticesEntries;
2287
2288       if (sourceVertices.length()!=0)
2289         {
2290           periodicity_i[PERIODICITY_P1_SOURCE_COLUMN] = sourceVertices[0].in();
2291           periodicity_i[PERIODICITY_P2_SOURCE_COLUMN] = sourceVertices[1].in();
2292           if ( onFace )
2293             periodicity_i[PERIODICITY_P3_SOURCE_COLUMN] = sourceVertices[2].in();
2294         }
2295
2296       if (targetVertices.length()!=0)
2297         {
2298           periodicity_i[PERIODICITY_P1_TARGET_COLUMN] = targetVertices[0].in();
2299           periodicity_i[PERIODICITY_P2_TARGET_COLUMN] = targetVertices[1].in();
2300           if ( onFace )
2301             periodicity_i[PERIODICITY_P3_TARGET_COLUMN] = targetVertices[2].in();
2302         }
2303
2304       if (onFace)
2305         periodicity_i[PERIODICITY_SHAPE_TYPE] = "1";
2306       else
2307         periodicity_i[PERIODICITY_SHAPE_TYPE] = "0";
2308
2309       h_data.preCadPeriodicityVector.push_back(periodicity_i);
2310     }
2311 }
2312
2313 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
2314 Saves the hypothesis data to hypothesis values.
2315 */
2316 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
2317 {
2318   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2319     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
2320
2321   bool ok = true;
2322   try
2323   {
2324     if ( isCreation() )
2325       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
2326
2327     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
2328       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
2329     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
2330       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
2331
2332     if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
2333       if ( h->GetPhySize()   != h_data.myPhySize ||
2334            h->IsPhySizeRel() != h_data.myPhySizeRel ) {
2335         if ( h_data.myPhySizeRel )
2336           h->SetPhySizeRel( h_data.myPhySize );
2337         else
2338           h->SetPhySize( h_data.myPhySize );
2339       }
2340     }
2341     if (h->GetMinSize()   != h_data.myMinSize ||
2342         h->IsMinSizeRel() != h_data.myMinSizeRel ) {
2343       if ( h_data.myMinSizeRel )
2344         h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2345       else
2346         h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2347     }
2348     if (h->GetMaxSize()   != h_data.myMaxSize ||
2349         h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
2350       if ( h_data.myMaxSizeRel )
2351         h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2352       else
2353         h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2354     }
2355     if ( h->GetUseGradation() !=  h_data.myUseGradation )
2356       h->SetUseGradation( h_data.myUseGradation );
2357     if ( h->GetGradation() !=  h_data.myGradation )
2358       h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
2359     if ( h->GetUseVolumeGradation() !=  h_data.myUseVolumeGradation )
2360       h->SetUseVolumeGradation( h_data.myUseVolumeGradation );
2361     if ( h->GetVolumeGradation() !=  h_data.myVolumeGradation )
2362       h->SetVolumeGradation( h_data.myVolumeGradation <= 0 ? -1 : h_data.myVolumeGradation );
2363
2364     h->SetSurfaceProximity        ((CORBA::Short) h_data.myUseSurfaceProximity      );
2365     h->SetNbSurfaceProximityLayers((CORBA::Short) h_data.myNbSurfaceProximityLayers );
2366     h->SetSurfaceProximityRatio   ( h_data.mySurfaceProximityRatio    );
2367     h->SetVolumeProximity         ((CORBA::Short) h_data.myUseVolumeProximity       );
2368     h->SetNbVolumeProximityLayers ((CORBA::Short) h_data.myNbVolumeProximityLayers  );
2369     h->SetVolumeProximityRatio    ( h_data.myVolumeProximityRatio     );
2370
2371     if ( h->GetElementType() != h_data.myElementType )
2372       h->SetElementType( h_data.myElementType );
2373
2374     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
2375       if ( h->GetAngleMesh() != h_data.myAngleMesh )
2376         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
2377       if ( h->GetChordalError() != h_data.myChordalError )
2378         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
2379     }
2380
2381     if ( h->GetAnisotropic() != h_data.myAnisotropic )
2382       h->SetAnisotropic( h_data.myAnisotropic );
2383     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
2384       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
2385
2386     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
2387       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
2388     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
2389       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
2390
2391     if ( h->GetOptimiseTinyEdges() != h_data.myOptimiseTinyEdges )
2392       h->SetOptimiseTinyEdges( h_data.myOptimiseTinyEdges );
2393     if ( h_data.myOptimiseTinyEdges && ( h->GetTinyEdgeOptimisationLength() != h_data.myTinyEdgeOptimisLength ) )
2394       h->SetTinyEdgeOptimisationLength( h_data.myTinyEdgeOptimisLength <= 0 ? -1 :h_data.myTinyEdgeOptimisLength );
2395     if ( h->GetCorrectSurfaceIntersection() != h_data.myCorrectSurfaceIntersection )
2396       h->SetCorrectSurfaceIntersection( h_data.myCorrectSurfaceIntersection );
2397     if ( h_data.myCorrectSurfaceIntersection && ( h->GetCorrectSurfaceIntersectionMaxCost() != h_data.myCorrectSurfaceIntersectionMaxCost ) )
2398       h->SetCorrectSurfaceIntersectionMaxCost( h_data.myCorrectSurfaceIntersectionMaxCost <= 0 ? -1 :h_data.myCorrectSurfaceIntersectionMaxCost );
2399     
2400     if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
2401       h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
2402     if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
2403       h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
2404     
2405     if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
2406       h->SetOptimizeMesh( h_data.myOptimizeMesh );    
2407     
2408     if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
2409       h->SetQuadraticMesh( h_data.myQuadraticMesh );
2410
2411     if ( h->GetVerbosity() != h_data.myVerbosity )
2412       h->SetVerbosity((CORBA::Short) h_data.myVerbosity );
2413     // if ( h->GetTopology() != h_data.myTopology )
2414     //   h->SetTopology( (int) h_data.myTopology );
2415     // if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
2416     //   h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
2417     // if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
2418     //   h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
2419     // if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
2420     //   h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
2421
2422     // options are set in checkParams()
2423     //h->SetOptionValues( myOptions ); // is set in readParamsFromWidgets()
2424     //h->SetPreCADOptionValues( myPreCADOptions ); // is set in readParamsFromWidgets()
2425
2426     if ( h->GetGMFFile() != h_data.myGMFFileName )
2427       //       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
2428       //       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
2429       h->SetGMFFile( h_data.myGMFFileName.c_str());
2430
2431     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2432     QMapIterator<QString,QString> i(that->mySMPMap);
2433     while (i.hasNext()) {
2434       i.next();
2435       const QString entry = i.key();
2436       const QString sizeMap = i.value();
2437
2438       if (sizeMap == "__TO_DELETE__") {
2439         h->UnsetEntry(entry.toLatin1().constData());
2440       }
2441       else if (sizeMap.startsWith("ATTRACTOR")) {
2442         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
2443       }
2444       else if (sizeMap.startsWith("def")) {
2445         //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
2446       }
2447       else {
2448         if (!myATTMap[entry].empty()){
2449           const TAttractorVec& attVec = myATTMap[entry];
2450           for ( size_t i = 0; i < attVec.size(); ++i )
2451           {
2452             if ( attVec[i].IsToDelete() )
2453               h->UnsetAttractorEntry( entry.toLatin1().constData(),
2454                                       attVec[i].attEntry.c_str() );
2455             else
2456               h->SetClassAttractorEntry( entry.toLatin1().constData(),
2457                                          attVec[i].attEntry.c_str(),
2458                                          attVec[i].startSize,
2459                                          h->GetPhySize(),
2460                                          attVec[i].infDist,
2461                                          attVec[i].constDist );
2462           }
2463         }
2464         else {
2465           QString fullSizeMap;
2466           fullSizeMap = QString("");
2467           if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
2468             fullSizeMap = QString("def f(u,v): return ") + sizeMap;
2469           else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
2470             fullSizeMap = QString("def f(t): return ") + sizeMap;
2471           else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
2472             fullSizeMap = QString("def f(): return ") + sizeMap;
2473           h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
2474         }
2475       }
2476     }
2477
2478     // Enforced vertices
2479     //bool ret;
2480     double x, y, z = 0;
2481     std::string enfName;
2482     /* TODO GROUPS
2483        std::string groupName = "";
2484     */
2485
2486     TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
2487     // 1. Clear all enforced vertices in hypothesis
2488     // 2. Add new enforced vertex according to h_data
2489
2490     if ( h->GetAllEnforcedVertices()->length() > 0 )
2491       h->ClearAllEnforcedVertices();
2492     TEnfName faceEntry;
2493     TEnfVertexList evs;
2494     TEnfVertexList::const_iterator evsIt;
2495     for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
2496     {
2497       faceEntry = evmIt->first;
2498       evs = evmIt->second;
2499       evsIt = evs.begin();
2500       for ( ; evsIt != evs.end() ; ++evsIt)
2501       {
2502         x =y =z = 0;
2503         if ((*evsIt)->coords.size()) {
2504           x = (*evsIt)->coords[0];
2505           y = (*evsIt)->coords[1];
2506           z = (*evsIt)->coords[2];
2507         }
2508         //ret =
2509         h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
2510       } // for
2511     } // for
2512
2513     if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
2514       h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
2515     if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
2516       h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
2517
2518     // Periodicity
2519     if ( h->GetPreCadFacesPeriodicityVector()->length() > 0 || h->GetPreCadEdgesPeriodicityVector()->length() > 0 )
2520       h->ClearPreCadPeriodicityVectors();
2521
2522     TPreCadPeriodicityVector::const_iterator pIt = h_data.preCadPeriodicityVector.begin();
2523     for ( ; pIt != h_data.preCadPeriodicityVector.end() ; ++pIt)
2524     {
2525       TPreCadPeriodicity periodicity_i = *pIt;
2526       TEntry source = periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN];
2527       TEntry target = periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN];
2528       TEntry p1Source = periodicity_i[PERIODICITY_P1_SOURCE_COLUMN];
2529       TEntry p2Source = periodicity_i[PERIODICITY_P2_SOURCE_COLUMN];
2530       TEntry p3Source = periodicity_i[PERIODICITY_P3_SOURCE_COLUMN];
2531       TEntry p1Target = periodicity_i[PERIODICITY_P1_TARGET_COLUMN];
2532       TEntry p2Target = periodicity_i[PERIODICITY_P2_TARGET_COLUMN];
2533       TEntry p3Target = periodicity_i[PERIODICITY_P3_TARGET_COLUMN];
2534       bool onFace = (periodicity_i[PERIODICITY_SHAPE_TYPE]=="1") ? true : false;
2535
2536       BLSURFPlugin::TEntryList_var sourceVertices = new BLSURFPlugin::TEntryList();
2537       if (! p1Source.empty())
2538       {
2539         sourceVertices->length(3);
2540         sourceVertices[0]=CORBA::string_dup(p1Source.c_str());
2541         sourceVertices[1]=CORBA::string_dup(p2Source.c_str());
2542         sourceVertices[2]=CORBA::string_dup(p3Source.c_str());
2543       }
2544
2545
2546       BLSURFPlugin::TEntryList_var targetVertices = new BLSURFPlugin::TEntryList();
2547       if (! p1Target.empty())
2548       {
2549         targetVertices->length(3);
2550         targetVertices[0]=CORBA::string_dup(p1Target.c_str());
2551         targetVertices[1]=CORBA::string_dup(p2Target.c_str());
2552         targetVertices[2]=CORBA::string_dup(p3Target.c_str());
2553       }
2554
2555       if (onFace)
2556         h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2557       else
2558         h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2559     }
2560
2561     // Hyper-patches
2562     BLSURFPlugin::THyperPatchList_var         hpl = new BLSURFPlugin::THyperPatchList();
2563     BLSURFPlugin::THyperPatchEntriesList_var hpel = new BLSURFPlugin::THyperPatchEntriesList();
2564     hpl ->length( h_data.hyperpatches.size() );
2565     hpel->length( h_data.hyperEntries.size() );
2566
2567     for ( int i = 0; i < h_data.hyperpatches.size(); ++i )
2568     {
2569       QStringList tags = h_data.hyperpatches[i].split(" ",  QString::SkipEmptyParts);
2570       BLSURFPlugin::THyperPatch& patch = hpl[ i ];
2571       patch.length( tags.size() );
2572
2573       for ( int j = 0; j < tags.size(); ++j )
2574         patch[ j ] = tags[ j ].toInt();
2575
2576       if ( i < h_data.hyperEntries.size() )
2577       {
2578         QStringList entries = h_data.hyperEntries[i].split(" ",  QString::SkipEmptyParts);
2579         BLSURFPlugin::THyperPatchEntries& pe = hpel[ i ];
2580         pe.length( entries.size() );
2581
2582         for ( int j = 0; j < entries.size(); ++j )
2583           pe[ j ] = CORBA::string_dup( entries[ j ].toStdString().c_str() );
2584       }
2585     }
2586     if ( h_data.hyperEntries.size() == h_data.hyperpatches.size() )
2587       h->SetHyperPatchEntries( hpel );
2588     else
2589       h->SetHyperPatches( hpl );
2590
2591
2592   } // try
2593   catch(...) {
2594     ok = false;
2595   }
2596
2597   return ok;
2598 }
2599
2600 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
2601     Stores the widgets content to the hypothesis data.
2602 */
2603 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
2604 {
2605   h_data.myName                  = myName ? myName->text() : "";
2606   h_data.myPhysicalMesh          = myStdWidget->myPhysicalMesh->currentIndex();
2607   h_data.myGeometricMesh         = myStdWidget->myGeometricMesh->currentIndex();
2608   h_data.myPhySize               = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
2609   h_data.myPhySizeRel            = myStdWidget->myPhySizeRel->isChecked();
2610   h_data.myMinSize               = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
2611   h_data.myMinSizeRel            = myStdWidget->myMinSizeRel->isChecked();
2612   h_data.myMaxSize               = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
2613   h_data.myMaxSizeRel            = myStdWidget->myMaxSizeRel->isChecked();
2614   h_data.myUseGradation          = myStdWidget->myUseGradation->isChecked() && !myStdWidget->myGradation->text().isEmpty();
2615   h_data.myGradation             = h_data.myUseGradation ? myStdWidget->myGradation->GetValue() : -1.0;
2616   h_data.myUseVolumeGradation    = myStdWidget->myUseVolumeGradation->isChecked() && !myStdWidget->myVolumeGradation->text().isEmpty();
2617   h_data.myVolumeGradation       = h_data.myUseVolumeGradation ? myStdWidget->myVolumeGradation->GetValue() : -1. ;
2618   h_data.myElementType           = myStdWidget->myButtonGroupElementType->checkedId();
2619   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
2620   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
2621   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
2622   h_data.myAnisotropicRatio      = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
2623   h_data.myRemoveTinyEdges       = myStdWidget->myRemoveTinyEdges->isChecked();
2624   h_data.myTinyEdgeLength        = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
2625   h_data.myOptimiseTinyEdges     = myStdWidget->myOptimiseTinyEdges->isChecked();
2626   h_data.myTinyEdgeOptimisLength = myStdWidget->myTinyEdgeOptimisLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeOptimisLength->GetValue();
2627   h_data.myCorrectSurfaceIntersection = myStdWidget->myCorrectSurfaceIntersection->isChecked();
2628   h_data.myCorrectSurfaceIntersectionMaxCost = myStdWidget->myCorrectSurfaceIntersectionMaxCost->text().isEmpty() ? -1.0 : myStdWidget->myCorrectSurfaceIntersectionMaxCost->GetValue();
2629   h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
2630   h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
2631   h_data.myOptimizeMesh          = myStdWidget->myOptimizeMesh->isChecked();
2632   h_data.myQuadraticMesh         = myStdWidget->myQuadraticMesh->isChecked();
2633   h_data.myVerbosity             = myAdvWidget->myVerbosity->value();
2634   //h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
2635   //h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
2636   //h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
2637   //h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
2638   h_data.myUseSurfaceProximity      = myStdWidget->myUseSurfaceProximity     ->isChecked();
2639   h_data.myNbSurfaceProximityLayers = myStdWidget->myNbSurfaceProximityLayers->value();
2640   h_data.mySurfaceProximityRatio    = myStdWidget->mySurfaceProximityRatio   ->value();
2641   h_data.myUseVolumeProximity       = myStdWidget->myUseVolumeProximity      ->isChecked();
2642   h_data.myNbVolumeProximityLayers  = myStdWidget->myNbVolumeProximityLayers ->value();
2643   h_data.myVolumeProximityRatio     = myStdWidget->myVolumeProximityRatio    ->value();
2644
2645   QString guiHyp;
2646   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
2647   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
2648   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
2649   guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
2650   guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
2651   guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
2652   guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
2653   guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
2654   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
2655   guiHyp += tr("BLSURF_ELEMENT_TYPE") + " = " + QString::number(h_data.myElementType) + "; ";
2656   guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
2657   guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
2658   guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
2659   guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
2660   
2661   
2662   guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
2663   guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
2664   guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
2665   guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
2666   guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
2667   guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
2668   
2669   
2670   // guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
2671   // guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
2672   // guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
2673   // guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
2674  
2675   h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
2676 //   h_data.myGMFFileMode = myGMFFileMode->isChecked();
2677
2678   // SizeMap
2679   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2680   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2681   for ( ; row < nbRows; ++row )
2682   {
2683     QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
2684     if ( that->mySMPMap.contains(entry) )
2685       guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
2686   }
2687
2688   // Enforced vertices
2689   h_data.enfVertexList.clear();
2690   h_data.faceEntryEnfVertexListMap.clear();
2691
2692   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
2693   std::string groupName = "", faceEntry = "";
2694   for (int i=0 ; i<nbEnforcedShapes ; i++)
2695   {
2696     double childValueX,childValueY,childValueZ;
2697     std::string childName, vertexEntry;
2698     QTreeWidgetItem* child;
2699
2700     child = myEnforcedTreeWidget->topLevelItem(i);
2701     childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
2702     childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
2703     childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
2704     childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
2705     vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2706     //           if (myGlobalGroupName->isChecked())
2707     //             groupName = myGlobalGroupName->text().toStdString();
2708     //           else
2709     groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
2710
2711     TEnfVertex *enfVertex = new TEnfVertex();
2712     enfVertex->name = childName;
2713     if (vertexEntry.empty()) {
2714       enfVertex->coords.push_back(childValueX);
2715       enfVertex->coords.push_back(childValueY);
2716       enfVertex->coords.push_back(childValueZ);
2717     }
2718     else
2719       enfVertex->geomEntry = vertexEntry;
2720     enfVertex->grpName = groupName;
2721     //           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
2722     //           if (it == h_data.enfVertexList.end())
2723     h_data.enfVertexList.insert(enfVertex);
2724     /* TODO GROUPS
2725        if (groupName != "")
2726        h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2727     */
2728     h_data.faceEntryEnfVertexListMap[faceEntry].insert( enfVertex );
2729   }
2730
2731   h_data.myInternalEnforcedVerticesAllFaces      = myInternalEnforcedVerticesAllFaces->isChecked();
2732   h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2733
2734   // Periodicity
2735   h_data.preCadPeriodicityVector.clear();
2736   // For each tree item, store each value. Shapes are stored as entries.
2737   int nbPeriodicityDescriptions = myPeriodicityTreeWidget->topLevelItemCount();
2738   for (int i=0 ; i<nbPeriodicityDescriptions ; i++) {
2739     QTreeWidgetItem* item = myPeriodicityTreeWidget->topLevelItem(i);
2740     TPreCadPeriodicity periodicity_i;
2741     if (item) {
2742         for (int k=0; k<myPeriodicityTreeWidget->columnCount(); ++k)
2743           {
2744             std::string entry = item->data(k, Qt::UserRole).toString().toStdString();
2745             periodicity_i.push_back(entry);
2746           }
2747         h_data.preCadPeriodicityVector.push_back(periodicity_i);
2748     }
2749     guiHyp += "PERIODICITY = yes; ";
2750   }
2751
2752   // Hyper-patches
2753   h_data.hyperpatches.clear();
2754   h_data.hyperEntries.clear();
2755   for ( int row = 0; row < myHyPatchTable->rowCount(); ++row )
2756   {
2757     QTableWidgetItem* cell = myHyPatchTable->item( row, 0 );
2758     h_data.hyperpatches.append( cell->text() );
2759     if ( cell->data( Qt::UserRole ).isValid() )
2760       h_data.hyperEntries.append( cell->data( Qt::UserRole ).toString() );
2761   }
2762   if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() )
2763     h_data.hyperEntries.clear();
2764
2765   return guiHyp;
2766 }
2767
2768 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2769 {
2770   myAdvWidget->AddOption( TBL_CUSTOM, NULL );
2771 }
2772
2773 void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int /*row*/, int /*column*/ )
2774 {
2775   // if ( column != OPTION_NAME_COLUMN )
2776   //   return;
2777   // myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2778 }
2779
2780 // **********************
2781 // *** BEGIN SIZE MAP ***
2782 // **********************
2783
2784 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2785 {
2786   if ( myGeomSelWdg2->IsObjectSelected() ){
2787     mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2788   }
2789   else if ( myGeomSelWdg1->IsObjectSelected() ){
2790     mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2791   }
2792   else {
2793     mySMapObject = GEOM::GEOM_Object::_nil();
2794   }
2795   bool dataAvailable = !mySMapObject->_is_nil();
2796   QString qEntry;
2797   if ( dataAvailable )
2798     qEntry = SMESH::toQStr( mySMapObject->GetStudyEntry() );
2799
2800   bool mapExists = ( mySMPMap.contains(qEntry) && mySMPMap[qEntry] != "__TO_DELETE__" );
2801   if (( mapExists && myGeomSelWdg2->IsObjectSelected() )  &&
2802       ( dataAvailable = myAttSelWdg->isEnabled() )        &&
2803       ( dataAvailable = myAttSelWdg->IsObjectSelected() ) &&
2804       ( myATTMap.contains( qEntry )))
2805   {
2806     mapExists = false;
2807     QString attEntry = myAttSelWdg->GetValue();
2808     const TAttractorVec& attVec = myATTMap[ qEntry ];
2809     for ( size_t i = 0; i < attVec.size() && !mapExists; ++i )
2810       mapExists = ( attEntry == attVec[i].attEntry.c_str() );
2811   }
2812
2813   addMapButton->setEnabled( !mapExists && dataAvailable );
2814   modifyMapButton->setEnabled( mapExists && dataAvailable );
2815 }
2816
2817 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2818 {
2819   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2820   if (col == SMP_SIZEMAP_COLUMN) {
2821     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2822     QString childEntry;
2823     if (!mySMPMap.contains(entry))
2824     {
2825       if ( QTreeWidgetItem* parent = item->parent() )
2826       {
2827         childEntry = entry;
2828         item = parent;
2829         entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2830       }
2831       if (!mySMPMap.contains(entry))
2832         return;
2833     }
2834     QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2835     CORBA::Object_var obj = entryToObject(entry);
2836     if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")) {  // ADVANCED MAPS
2837       smpTab->setCurrentIndex(ATT_TAB);         // Change Tab
2838       // Retrieve values of the selected item in the current tab widgets
2839       const TAttractorVec& attVec = myATTMap[entry];
2840       if ( !attVec.empty() )
2841       {
2842         size_t iAtt = 0;
2843         if ( !childEntry.isEmpty() )
2844           for ( size_t i = 0; i < attVec.size(); ++i )
2845             if ( childEntry == attVec[i].attEntry.c_str() )
2846             {
2847               iAtt = i;
2848               break;
2849             }
2850         double phySize   = attVec[iAtt].startSize;
2851         double infDist   = attVec[iAtt].infDist;
2852         double constDist = attVec[iAtt].constDist;
2853         QString attEntry = attVec[iAtt].attEntry.c_str();
2854         CORBA::Object_var attObj = entryToObject(attEntry);
2855         myAttSizeSpin->setValue(phySize);
2856         if ( infDist > std::numeric_limits<double>::epsilon() /*sizeMap.startsWith("Attractor")*/){
2857           myAttDistSpin->setValue(infDist);
2858           myAttractorCheck->setChecked(true);
2859         }
2860         else {
2861           myAttractorCheck->setChecked(false);
2862         }
2863         if (/*sizeMap.startsWith("Constant") || */constDist > std::numeric_limits<double>::epsilon()){
2864           myAttDistSpin2->setValue(constDist);
2865           myConstSizeCheck->setChecked(true);
2866         }
2867         else{
2868           myConstSizeCheck->setChecked(false);
2869         }
2870         myGeomSelWdg2->SetObject(obj);
2871         myAttSelWdg->SetObject(attObj);
2872       }
2873     }
2874     else {                                                                   // CLASSIC MAPS
2875       smpTab->setCurrentIndex(SMP_STD_TAB);  // Change Tab
2876       myGeomSelWdg1->SetObject(obj);         // Retrieve values of the selected item in the current tab widgets
2877       if (!sizeMap.startsWith("def")){
2878         mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
2879       }
2880     }
2881   }
2882 }
2883
2884 void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
2885 {
2886   getGeomSelectionTool()->selectionMgr()->clearFilters();
2887   if ( sender() == myTabWidget )
2888   {
2889     myGeomSelWdg1             ->deactivateSelection();
2890     myGeomSelWdg2             ->deactivateSelection();
2891     myAttSelWdg               ->deactivateSelection();
2892     myEnfVertexWdg            ->deactivateSelection();
2893     myPeriodicitySourceFaceWdg->deactivateSelection();
2894     myPeriodicityTargetFaceWdg->deactivateSelection();
2895     myPeriodicityP1SourceWdg  ->deactivateSelection();
2896     myPeriodicityP2SourceWdg  ->deactivateSelection();
2897     myPeriodicityP3SourceWdg  ->deactivateSelection();
2898     myPeriodicityP1TargetWdg  ->deactivateSelection();
2899     myPeriodicityP2TargetWdg  ->deactivateSelection();
2900     myPeriodicityP3TargetWdg  ->deactivateSelection();
2901     if ( myHyPatchFaceSelBtn->isChecked() )
2902       myHyPatchFaceSelBtn->toggle();
2903     if ( myHyPatchGroupSelBtn->isChecked() )
2904       myHyPatchGroupSelBtn->toggle();
2905   }
2906   else if ( sender() == smpTab )
2907   {
2908     myAttDistSpin->setValue(0.);           // Reinitialize widgets
2909     myAttSizeSpin->setValue(0.);
2910     myAttDistSpin2->setValue(0.);
2911     mySmpSizeSpin->setValue(0.);
2912     myGeomSelWdg1->deactivateSelection();
2913     myGeomSelWdg2->deactivateSelection();
2914     myAttSelWdg->deactivateSelection();
2915     myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2916     myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2917     myAttSelWdg->SetObject(CORBA::Object::_nil());
2918     myAttractorCheck->setChecked(false);
2919     myConstSizeCheck->setChecked(false);
2920   }
2921
2922   if ( tab == SMP_TAB ) // [#16954] limit local size by Min and User Size
2923   {
2924     double minSize = 0, maxSize = COORD_MAX;
2925
2926     if ( !myStdWidget->myMinSizeRel->isChecked() &&
2927          !myStdWidget->myMinSize->text().isEmpty() )
2928       minSize = myStdWidget->myMinSize->GetValue();
2929
2930     if ( !myStdWidget->myPhySizeRel->isChecked() &&
2931          !myStdWidget->myPhySize->text().isEmpty() )
2932       maxSize = myStdWidget->myPhySize->GetValue();
2933
2934     mySmpSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
2935     myAttSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
2936   }
2937 }
2938
2939 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2940 {
2941   if (state == Qt::Checked){
2942     myAttSelWdg->setEnabled(true);
2943     myAttSizeSpin->setEnabled(true);
2944     myAttSizeLabel->setEnabled(true);
2945     myAttDistSpin->setEnabled(true);
2946     myAttDistLabel->setEnabled(true);
2947     if (!myAttSelWdg->IsObjectSelected()){
2948       myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2949     }
2950   }
2951   if (state == Qt::Unchecked){
2952     myAttDistSpin->setEnabled(false);
2953     myAttDistLabel->setEnabled(false);
2954     myAttDistSpin->setValue(0.);
2955     if(myConstSizeCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2956       myAttSelWdg->setEnabled(false);
2957       myAttSizeSpin->setEnabled(false);
2958       myAttSizeLabel->setEnabled(false);
2959       myAttDistSpin2->setEnabled(false);
2960       myAttDistLabel2->setEnabled(false);
2961     }
2962     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2963       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2964     }
2965   }
2966   onMapGeomContentModified();
2967 }
2968
2969 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2970
2971   if (state == Qt::Checked){
2972     myAttSelWdg->setEnabled(true);
2973     myAttSizeSpin->setEnabled(true);
2974     myAttSizeLabel->setEnabled(true);
2975     myAttDistSpin2->setEnabled(true);
2976     myAttDistLabel2->setEnabled(true);
2977     if (myAttractorCheck->checkState() == Qt::Unchecked &&
2978         !myAttSelWdg->IsObjectSelected()){
2979       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2980     }
2981   }
2982   if (state == Qt::Unchecked){
2983     myAttDistSpin2->setEnabled(false);
2984     myAttDistLabel2->setEnabled(false);
2985     myAttDistSpin2->setValue(0.);
2986     if(myAttractorCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2987         myAttSelWdg->setEnabled(false);
2988         myAttSizeSpin->setEnabled(false);
2989         myAttSizeLabel->setEnabled(false);
2990         myAttDistSpin->setEnabled(false);
2991         myAttDistLabel->setEnabled(false);
2992     }
2993     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2994     myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2995     }
2996   }   
2997   onMapGeomContentModified();
2998 }
2999
3000 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
3001 {
3002   QList<int> selectedRows;
3003   QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
3004   QTreeWidgetItem* item;
3005   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3006
3007   qSort( selectedRows );
3008   QListIterator<QTreeWidgetItem*> it( selected );
3009   it.toBack();
3010   while ( it.hasPrevious() ) {
3011       item = it.previous();
3012       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
3013       QString parentEntry;
3014       if ( QTreeWidgetItem* parent = item->parent() )
3015         parentEntry = parent->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
3016       if (that->mySMPMap.contains(entry))
3017       {
3018         that->mySMPMap[entry] = "__TO_DELETE__";
3019         if ( myATTMap.contains( entry ))
3020         {
3021           TAttractorVec& attVec = myATTMap[entry];
3022           for ( size_t i = 0; i < attVec.size(); ++i )
3023             attVec[i].SetToDelete();
3024         }          
3025       }
3026       else if ( mySMPMap.contains( parentEntry ) && myATTMap.contains( parentEntry ))
3027       {
3028         TAttractorVec& attVec = myATTMap[parentEntry];
3029         for ( size_t i = 0; i < attVec.size(); ++i )
3030         {
3031           if ( entry == attVec[i].attEntry.c_str() )
3032             attVec[i].SetToDelete();
3033         }
3034       }
3035       if (that->mySMPShapeTypeMap.contains(entry))
3036         that->mySMPShapeTypeMap.remove(entry);
3037       // if (that->myDistMap.contains(entry))
3038       //   that->myDistMap.remove(entry);
3039       // if (that->myAttDistMap.contains(entry))
3040       //   that->myAttDistMap.remove(entry);
3041       delete item;
3042   }
3043   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
3044   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
3045 }
3046
3047 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
3048 {
3049   if (col == SMP_SIZEMAP_COLUMN) {
3050     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3051     QString entry   = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
3052     QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
3053     if (! that->mySMPShapeTypeMap.contains(entry))
3054       return;
3055     if (that->mySMPMap.contains(entry))
3056       if (that->mySMPMap[entry] == sizeMap 
3057         || sizeMap.startsWith("Attractor") 
3058         || sizeMap.startsWith("Constant") ){
3059         return;
3060       } 
3061     if (! sizeMap.isEmpty()) {
3062       that->mySMPMap[entry] = sizeMap;
3063       sizeMapValidationFromEntry(entry); 
3064     }
3065     else {
3066       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
3067     }
3068     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
3069   }
3070 }
3071
3072 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
3073 {
3074   bool res = false;
3075   if ( smpTab->currentIndex() == ATT_TAB ){
3076     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
3077       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3078       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3079       res = insertAttractor(mySMapObject, myAttObject);
3080     }
3081   }
3082   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3083     if ( myGeomSelWdg1->IsObjectSelected() ){
3084       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3085       res = insertElement(mySMapObject);
3086     }
3087   }
3088   if ( !res ) {
3089     // Local size should be more than 0
3090     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3091     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3092     return;
3093   }
3094   getGeomSelectionTool()->selectionMgr()->clearFilters();
3095   myAttDistSpin->setValue(0.);
3096   myAttSizeSpin->setValue(0.);
3097   myAttDistSpin2->setValue(0.);
3098   mySmpSizeSpin->setValue(0.);
3099   myConstSizeCheck->setChecked(false);
3100   myAttractorCheck->setChecked(false);
3101   myGeomSelWdg1->deactivateSelection();
3102   myGeomSelWdg2->deactivateSelection();
3103   myAttSelWdg->deactivateSelection();
3104   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3105   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3106   myAttSelWdg->SetObject(CORBA::Object::_nil());
3107 }
3108
3109 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
3110 {
3111   bool res = false;
3112   if ( smpTab->currentIndex() == ATT_TAB ){    
3113     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
3114       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3115       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3116       res = insertAttractor(mySMapObject, myAttObject, /*modify = */true);
3117     }
3118   }
3119   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3120     if ( myGeomSelWdg1->IsObjectSelected() ){
3121       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3122       res = insertElement(mySMapObject, /*modify = */true);  
3123     }  
3124   }
3125   if ( !res ) {
3126     // Local size should be more than 0
3127     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3128     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3129     return;
3130   }
3131   getGeomSelectionTool()->selectionMgr()->clearFilters();
3132   myAttDistSpin->setValue(0.);
3133   myAttSizeSpin->setValue(0.);
3134   myAttDistSpin2->setValue(0.);
3135   mySmpSizeSpin->setValue(0.);
3136   myConstSizeCheck->setChecked(false);
3137   myAttractorCheck->setChecked(false);
3138   myGeomSelWdg1->deactivateSelection();
3139   myGeomSelWdg2->deactivateSelection();
3140   myAttSelWdg->deactivateSelection();
3141   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3142   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3143   myAttSelWdg->SetObject(CORBA::Object::_nil());
3144 }
3145
3146 bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
3147 {
3148   // BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3149   //   BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3150
3151   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3152
3153   TopAbs_ShapeEnum shapeType;
3154   string entry, shapeName;
3155   entry = (string) anObject->GetStudyEntry();
3156   shapeName = anObject->GetName();
3157   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
3158   // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
3159   // in order to write the size map with the right syntax in StoreParamsToHypo 
3160   // (f(t) for edges, f(u,v) for faces ...)
3161   if (shapeType == TopAbs_COMPOUND){
3162     TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
3163     TopoDS_Shape childShape;
3164     TopoDS_Iterator anIt(theShape);
3165     for(;anIt.More();anIt.Next()){
3166       childShape = anIt.Value();
3167       shapeType = childShape.ShapeType();
3168       if(!childShape.IsNull()){
3169         break;
3170       }
3171     }
3172   }
3173   mySizeMapTable->setFocus();
3174   QString shapeEntry;
3175   shapeEntry = QString::fromStdString(entry);
3176   double phySize = mySmpSizeSpin->value();
3177
3178   if ( phySize == 0 )
3179     return false; // Local size should be more than 0
3180
3181   std::ostringstream oss;
3182   oss << phySize;
3183   QString sizeMap;
3184   sizeMap  = QString::fromStdString(oss.str());
3185   QTreeWidgetItem* item = new QTreeWidgetItem();
3186   if (modify){
3187     int rowToChange = findRowFromEntry(shapeEntry);
3188     item = mySizeMapTable->topLevelItem( rowToChange );
3189   }
3190   else{
3191     if (that->mySMPMap.contains(shapeEntry)) {  
3192       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3193         return false;
3194       }
3195     }
3196     mySizeMapTable->addTopLevelItem(item);
3197   }
3198   that->mySMPMap[shapeEntry] = sizeMap;
3199   //that->myDistMap[shapeEntry] = 0. ;
3200   that->mySMPShapeTypeMap[shapeEntry] = shapeType;
3201   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
3202   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3203   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
3204   item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3205   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3206   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3207   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3208   mySizeMapTable->clearSelection();
3209
3210   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3211     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3212     myStdWidget->onPhysicalMeshChanged();
3213   }
3214   return true;
3215 }
3216
3217 bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
3218 {
3219   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3220     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3221
3222   TopAbs_ShapeEnum shapeType;
3223   string entry, attEntry, faceName, attName;
3224   entry = (string) aFace->GetStudyEntry();
3225   attEntry = (string) anAttractor->GetStudyEntry();
3226   faceName = aFace->GetName();
3227   attName = anAttractor->GetName();
3228   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
3229   mySizeMapTable->setFocus();
3230   QString shapeEntry = QString::fromStdString(entry);
3231   QString qAttEntry = QString::fromStdString(attEntry);
3232   
3233   double phySize = h->GetPhySize();
3234   double infDist = 0. ;
3235   double constDist = 0. ;
3236   phySize = myAttSizeSpin->value();
3237
3238   if ( phySize == 0 )
3239     return false; // Local size should be more than 0
3240
3241   if (myAttractorCheck->isChecked()){
3242     infDist = myAttDistSpin->value();
3243   }
3244   if (myConstSizeCheck->isChecked()){
3245     constDist = myAttDistSpin2->value();
3246   } 
3247   std::ostringstream oss;
3248   std::ostringstream oss2;
3249   std::ostringstream oss3;
3250   oss << phySize;
3251   oss2 << infDist;
3252   oss3 << constDist;
3253   QString sizeMap  = QString::fromStdString(oss.str());
3254   QString infDistString = QString::fromStdString(oss2.str());
3255   QString constDistString = QString::fromStdString(oss3.str());
3256   
3257   QTreeWidgetItem* item; 
3258   QTreeWidgetItem* child = 0;
3259   TAttractor attParams( attEntry.c_str(), phySize, infDist, constDist );
3260   if (modify) {
3261     int rowToChange = findRowFromEntry(shapeEntry);
3262     item = mySizeMapTable->topLevelItem( rowToChange );
3263     
3264     for ( int i = 0, nb = item->childCount(); i < nb; ++i )
3265       if (( child = item->child( i )))
3266         if ( qAttEntry == child->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString() )
3267           break;
3268     TAttractorVec & attVec = myATTMap[shapeEntry];
3269     for ( size_t i = 0; i < attVec.size(); ++i )
3270       if ( attVec[i].attEntry == attEntry )
3271       {
3272         attVec[i] = attParams;
3273         break;
3274       }
3275   }
3276   else{
3277     // if (that->mySMPMap.contains(shapeEntry)) {  
3278     //   if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3279     //     return false;
3280     //   }
3281     // }
3282     int rowToChange = findRowFromEntry(shapeEntry);
3283     if ( rowToChange < mySizeMapTable->topLevelItemCount() )
3284     {
3285       item = mySizeMapTable->topLevelItem( rowToChange );
3286     }
3287     else {
3288       item = new QTreeWidgetItem();
3289       mySizeMapTable->addTopLevelItem(item);
3290     }
3291     child = new QTreeWidgetItem();
3292     item->addChild(child);
3293     bool exists = false;
3294     TAttractorVec & attVec = myATTMap[shapeEntry];
3295     for ( size_t i = 0; i < attVec.size(); ++i )
3296       if ( attVec[i].attEntry == attEntry )
3297       {
3298         attVec[i] = attParams;
3299         exists = true;
3300         break;
3301       }
3302     if ( !exists )
3303       myATTMap[shapeEntry].push_back( attParams );
3304   }
3305   mySMPMap.insert(shapeEntry,sizeMap);
3306   mySMPShapeTypeMap.insert(shapeEntry,shapeType);
3307   item->setExpanded(true); 
3308   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3309   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
3310   if (infDist > std::numeric_limits<double>::epsilon()){
3311     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
3312   }
3313   else if (constDist > std::numeric_limits<double>::epsilon()){
3314     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
3315   }
3316   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );    
3317   
3318   child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
3319   child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
3320   child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3321   
3322   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3323   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3324   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3325
3326   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3327     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3328     myStdWidget->onPhysicalMeshChanged();
3329   }
3330   return true;
3331 }
3332
3333 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
3334 {
3335   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
3336   for ( ; row < nbRows; ++row )
3337     if (! sizeMapValidationFromRow(row))
3338       return false;
3339   return true;
3340 }
3341
3342 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
3343 {
3344   QString myEntry   = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3345   bool res = sizeMapValidationFromEntry(myEntry,displayError);
3346   mySizeMapTable->setFocus();
3347   return res;
3348 }
3349
3350 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
3351 {
3352
3353   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3354
3355   if (! that->mySMPMap.contains(myEntry)) {
3356     return false;
3357   }
3358   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
3359     return false;
3360   }
3361
3362   string expr;
3363
3364   if (that->mySMPMap[myEntry].startsWith("def")) {
3365     expr = that->mySMPMap[myEntry].toStdString();
3366   }
3367   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
3368     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)) {
3369
3370       if (displayError)
3371         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])" );
3372       return false;
3373     }
3374     return true;
3375   }
3376   else {
3377     // case size map is empty
3378     if (that->mySMPMap[myEntry].isEmpty()) {
3379       if (displayError)
3380         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
3381       return false;
3382     }
3383     else {
3384       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
3385         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
3386       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
3387         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
3388       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
3389         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
3390     }
3391   }
3392   //assert(Py_IsInitialized());
3393   if (! Py_IsInitialized())
3394     throw ("Erreur: Python interpreter is not initialized");
3395   PyGILState_STATE gstate;
3396   gstate = PyGILState_Ensure();
3397
3398   string  err_description="";
3399   PyObject* obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
3400   if (obj == NULL){
3401     fflush(stderr);
3402     err_description="";
3403     PyObject* new_stderr = newPyStdOut(err_description);
3404     PyObject* old_stderr = PySys_GetObject((char*)"stderr");
3405     Py_INCREF(old_stderr);
3406     PySys_SetObject((char*)"stderr", new_stderr);
3407     PyErr_Print();
3408     PySys_SetObject((char*)"stderr", old_stderr);
3409     Py_DECREF(new_stderr);
3410     if (displayError)
3411       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
3412     PyGILState_Release(gstate);
3413     return false;
3414   }
3415   Py_DECREF(obj);
3416
3417   PyObject* func = PyObject_GetAttrString(main_mod, "f");
3418   if ( func == NULL){
3419     fflush(stderr);
3420     err_description="";
3421     PyObject* new_stderr = newPyStdOut(err_description);
3422     PyObject* old_stderr = PySys_GetObject((char*)"stderr");
3423     Py_INCREF(old_stderr);
3424     PySys_SetObject((char*)"stderr", new_stderr);
3425     PyErr_Print();
3426     PySys_SetObject((char*)"stderr", old_stderr);
3427     Py_DECREF(new_stderr);
3428     if (displayError)
3429       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
3430     PyGILState_Release(gstate);
3431     return false;
3432   }
3433
3434   PyGILState_Release(gstate);
3435
3436
3437   return true;
3438 }
3439
3440 //================================================================================
3441 /*!
3442  * \brief SLOT: Activate selection of faces in the Viewer
3443  */
3444 //================================================================================
3445
3446 void BLSURFPluginGUI_HypothesisCreator::onHyPatchFaceSelection(bool on)
3447 {
3448   if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
3449   {
3450     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
3451     QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
3452     myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
3453   }
3454   myHyPatchFaceSelector->setVisible( on );  // show its buttons
3455   myHyPatchFaceSelector->ShowPreview( on ); // show faces in the Viewer
3456   // treat selection or not
3457   myHyPatchFaceSelector->ActivateSelection( on || myHyPatchGroupSelBtn->isChecked() );
3458
3459   if ( on )
3460     myHyPatchGroupSelBtn->setChecked( false );
3461 }
3462
3463 //================================================================================
3464 /*!
3465  * \brief SLOT: Deactivate selection of faces in the Viewer
3466  */
3467 //================================================================================
3468
3469 void BLSURFPluginGUI_HypothesisCreator::onHyPatchGroupSelection(bool on)
3470 {
3471   if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
3472   {
3473     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
3474     QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
3475     myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
3476   }
3477   if ( !myHyPatchFaceSelBtn->isChecked() )
3478   {
3479     myHyPatchFaceSelector->setVisible( false ); // show its buttons
3480     myHyPatchFaceSelector->ShowPreview( false ); // show faces in the Viewer
3481   }
3482   // treat selection or not
3483   myHyPatchFaceSelector->ActivateSelection( on || myHyPatchFaceSelBtn->isChecked() );
3484
3485   if ( on )
3486     myHyPatchFaceSelBtn->setChecked( false );
3487 }
3488
3489 //================================================================================
3490 /*!
3491  * \brief SLOT: show IDs of selected faces in Tags LineEdit
3492  */
3493 //================================================================================
3494
3495 void BLSURFPluginGUI_HypothesisCreator::onHyPatchSelectionChanged()
3496 {
3497   QString tagString;
3498   const QList<int>& tags = myHyPatchFaceSelector->GetSelectedIDs();
3499   for ( int i = 0; i < tags.size(); ++i )
3500     tagString += QString::number( tags[i] ) + " ";
3501
3502   myHyPatchTagsLE->setText( tagString );
3503 }
3504
3505 //================================================================================
3506 /*!
3507  * \brief SLOT: Add the Tags to the HyperPatch table
3508  */
3509 //================================================================================
3510
3511 void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
3512 {
3513   QStringList tagList = myHyPatchTagsLE->text().split(" ",  QString::SkipEmptyParts);
3514   if ( tagList.size() > 1 )
3515   {
3516     LightApp_SelectionMgr* selMrg = SMESHGUI::GetSMESHGUI()->selectionMgr();
3517     SALOME_ListIO aList;
3518     selMrg->selectedObjects( aList );
3519     QString entries;
3520     for ( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
3521     {
3522       Handle(SALOME_InteractiveObject) io = anIt.Value();
3523       GEOM::GEOM_Object_var go = myHyPatchFaceSelector->GetGeomObjectByEntry( io->getEntry() );
3524       if ( !CORBA::is_nil( go ))
3525         entries += io->getEntry() + QString(" ");
3526       else
3527       {
3528         entries.clear();
3529         break;
3530       }
3531     }
3532     addHyPatchToTable( myHyPatchTagsLE->text(), entries );
3533     myHyPatchTagsLE->setText("");
3534   }
3535 }
3536
3537 //================================================================================
3538 /*!
3539  * \brief Add a row to myHyPatchTable
3540  */
3541 //================================================================================
3542
3543 void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags,
3544                                                           const QString& entries)
3545 {
3546   if ( tags.isEmpty() ) return;
3547
3548   QTableWidgetItem* cell = new QTableWidgetItem( tags );
3549   cell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
3550   if ( entries.isEmpty() )
3551     cell->setData( Qt::UserRole, QVariant() );
3552   else
3553     cell->setData( Qt::UserRole, entries );
3554
3555   int row = myHyPatchTable->rowCount();
3556   myHyPatchTable->insertRow( row );
3557   myHyPatchTable->setItem( row, 0, cell );
3558 }
3559
3560 //================================================================================
3561 /*!
3562  * \brief SLOT: remove selected rows from the HyperPatch table
3563  */
3564 //================================================================================
3565
3566 void BLSURFPluginGUI_HypothesisCreator::onHyPatchRemove()
3567 {
3568   QList<QTableWidgetItem *> items = myHyPatchTable->selectedItems();
3569   while ( !items.isEmpty() )
3570   {
3571     myHyPatchTable->removeRow( items[0]->row() );
3572     items = myHyPatchTable->selectedItems();
3573   }
3574 }
3575
3576 bool BLSURFPluginGUI_HypothesisCreator::hasGeom() const
3577 {
3578   return hypType() == BLSURFPlugin_Hypothesis::GetHypType(true);
3579 }
3580
3581 QString BLSURFPluginGUI_HypothesisCreator::caption() const
3582 {
3583   return tr( "BLSURF_TITLE" );
3584 }
3585
3586 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
3587 {
3588   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
3589 }
3590
3591 QString BLSURFPluginGUI_HypothesisCreator::type() const
3592 {
3593   return tr( "BLSURF_HYPOTHESIS" );
3594 }
3595
3596 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
3597 {
3598   return "blsurf_hypo_page.html";
3599 }
3600
3601 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
3602 {
3603
3604   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3605   if( anApp )
3606     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3607   else
3608     return 0;
3609 }
3610
3611 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
3612 {
3613   CORBA::Object_var obj;
3614   SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.toStdString().c_str() );
3615   if (!aSObj->_is_nil()) {
3616     obj = aSObj->GetObject();
3617     aSObj->UnRegister();
3618   }
3619   return obj;
3620 }
3621
3622 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
3623   int endRow = mySizeMapTable->topLevelItemCount()-1;
3624   int row = 0;
3625   for ( ; row <= endRow; ++row )
3626   {
3627     QString entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3628     if (entry == entryForChecking )
3629       break;
3630   }
3631   return row;
3632 }
3633
3634