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