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