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