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