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