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