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