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