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