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