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