Salome HOME
Merge from V6_main 11/02/2013
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2012  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.
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
62 #include <QStandardItemModel>
63 #include <QStandardItem>
64 #include <QTreeWidget>
65 #include <QTreeWidgetItem>
66 #include <QModelIndexList>
67
68 #include <LightApp_SelectionMgr.h>
69 #include <SalomeApp_Application.h>
70 #include <SALOME_ListIO.hxx>
71 #include <SALOME_ListIteratorOfListIO.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   SMP_NAME_COLUMN =0,
90   SMP_SIZEMAP_COLUMN,
91   SMP_ENTRY_COLUMN,
92 //  SMP_DIST_COLUMN,
93   SMP_NB_COLUMNS,
94 // Enforced vertices array columns
95   ENF_VER_NAME_COLUMN = 0,
96   ENF_VER_FACE_ENTRY_COLUMN,
97   ENF_VER_X_COLUMN,
98   ENF_VER_Y_COLUMN,
99   ENF_VER_Z_COLUMN,
100   ENF_VER_ENTRY_COLUMN,
101   ENF_VER_GROUP_COLUMN,
102   ENF_VER_NB_COLUMNS
103 };
104
105 enum {
106   SMP_TAB_WDG,
107   SMP_ADD_BTN,
108   SMP_NB_LINES,
109   SMP_STD_TAB = 0,
110   ATT_TAB,
111   SMP_GEOM_BTN_2 = 0,
112   ATT_CHECK,
113   CONST_SIZE_CHECK,
114   SMP_SPACE,
115 //   SMP_PARAMS,
116   SMP_ATT_SHAPE, 
117   SMP_ATT_SIZE,
118   SMP_ATT_DIST,
119   SMP_ATT_RAD
120 };
121   
122 enum {
123   SMP_GEOM_BTN_1,
124   SMP_SIZE,
125   SMP_SPACE2,
126 };
127
128 // Enforced vertices inputs
129 enum {
130   ENF_VER_FACE = 0,
131   ENF_VER_VERTEX,
132   ENF_VER_X_COORD,
133   ENF_VER_Y_COORD,
134   ENF_VER_Z_COORD,
135   ENF_VER_GROUP,
136 //   ENF_VER_GROUP_CHECK,
137 //   ENF_VER_SPACE,
138   ENF_VER_BTN,
139   ENF_VER_SEPARATOR,
140   ENF_VER_INTERNAL_ALL_FACES,
141   ENF_VER_INTERNAL_ALL_FACES_GROUP,
142 //   ENF_VER_VERTEX_BTN,
143 //   ENF_VER_REMOVE_BTN,
144 //   ENF_VER_SEPARATOR,
145   ENF_VER_NB_LINES
146 };
147
148
149 /**************************************************
150  Begin initialization Python structures and objects
151 ***************************************************/
152
153 typedef struct {
154   PyObject_HEAD
155   int softspace;
156   std::string *out;
157   } PyStdOut;
158
159 static void
160 PyStdOut_dealloc(PyStdOut *self)
161 {
162   PyObject_Del(self);
163 }
164
165 static PyObject *
166 PyStdOut_write(PyStdOut *self, PyObject *args)
167 {
168   char *c;
169   int l;
170   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
171     return NULL;
172
173   //std::cerr << c ;
174   *(self->out)=*(self->out)+c;
175
176   Py_INCREF(Py_None);
177   return Py_None;
178 }
179
180 static PyMethodDef PyStdOut_methods[] = { 
181   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
182   PyDoc_STR("write(string) -> None")},
183   {NULL,    NULL}   /* sentinel */
184 };
185
186 static PyMemberDef PyStdOut_memberlist[] = {
187   {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
188    (char*)"flag indicating that a space needs to be printed; used by print"},
189   {NULL} /* Sentinel */
190 };
191
192 static PyTypeObject PyStdOut_Type = {
193   /* The ob_type field must be initialized in the module init function
194    * to be portable to Windows without using C++. */
195   PyObject_HEAD_INIT(NULL)
196   0,                            /*ob_size*/
197   "PyOut",                      /*tp_name*/
198   sizeof(PyStdOut),             /*tp_basicsize*/
199   0,                            /*tp_itemsize*/
200   /* methods */
201   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
202   0,                            /*tp_print*/
203   0,                            /*tp_getattr*/
204   0,                            /*tp_setattr*/
205   0,                            /*tp_compare*/
206   0,                            /*tp_repr*/
207   0,                            /*tp_as_number*/
208   0,                            /*tp_as_sequence*/
209   0,                            /*tp_as_mapping*/
210   0,                            /*tp_hash*/
211   0,                            /*tp_call*/
212   0,                            /*tp_str*/
213   PyObject_GenericGetAttr,      /*tp_getattro*/
214   /* softspace is writable:  we must supply tp_setattro */
215   PyObject_GenericSetAttr,      /* tp_setattro */
216   0,                            /*tp_as_buffer*/
217   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
218   0,                            /*tp_doc*/
219   0,                            /*tp_traverse*/
220   0,                            /*tp_clear*/
221   0,                            /*tp_richcompare*/
222   0,                            /*tp_weaklistoffset*/
223   0,                            /*tp_iter*/
224   0,                            /*tp_iternext*/
225   PyStdOut_methods,             /*tp_methods*/
226   PyStdOut_memberlist,          /*tp_members*/
227   0,                            /*tp_getset*/
228   0,                            /*tp_base*/
229   0,                            /*tp_dict*/
230   0,                            /*tp_descr_get*/
231   0,                            /*tp_descr_set*/
232   0,                            /*tp_dictoffset*/
233   0,                            /*tp_init*/
234   0,                            /*tp_alloc*/
235   0,                            /*tp_new*/
236   0,                            /*tp_free*/
237   0,                            /*tp_is_gc*/
238 };
239
240 PyObject * newPyStdOut( std::string& out )
241 {
242   PyStdOut *self;
243   self = PyObject_New(PyStdOut, &PyStdOut_Type);
244   if (self == NULL)
245     return NULL;
246   self->softspace = 0;
247   self->out=&out;
248   return (PyObject*)self;
249 }
250
251 /*************************************************
252 End initialization Python structures and objects
253 **************************************************/
254
255
256 //
257 // BEGIN EnforcedTreeWidgetDelegate
258 //
259
260 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
261   : QItemDelegate(parent)
262 {
263 }
264
265 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
266                                               const QStyleOptionViewItem & option ,
267                                               const QModelIndex & index ) const
268 {
269   QModelIndex father = index.parent();
270   QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
271   
272   if (index.column() == ENF_VER_X_COLUMN || \
273       index.column() == ENF_VER_Y_COLUMN || \
274       index.column() == ENF_VER_Z_COLUMN)
275   {
276     SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
277     editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278     editor->setReadOnly(!entry.isEmpty());
279     editor->setDisabled(!entry.isEmpty());
280     return editor;
281   }
282   else
283   {
284     QLineEdit *editor = new QLineEdit(parent);
285     if (index.column() != ENF_VER_GROUP_COLUMN) {
286       editor->setReadOnly(!entry.isEmpty());
287       editor->setDisabled(!entry.isEmpty());
288     }
289     return editor;
290   }
291 }
292
293 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
294                                            const QModelIndex &index) const
295 {
296   QString value = index.model()->data(index, Qt::EditRole).toString();
297
298   if (index.column() == ENF_VER_X_COLUMN ||
299       index.column() == ENF_VER_Y_COLUMN ||
300       index.column() == ENF_VER_Z_COLUMN)
301   {
302     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
303     lineEdit->setText(value);
304   }
305   else {
306     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
307     lineEdit->setText(value);
308   }
309 }
310
311 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
312                                           const QModelIndex &index) const
313 {
314   QModelIndex parent = index.parent();
315   QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
316   if (index.column() == ENF_VER_X_COLUMN || index.column() == ENF_VER_Y_COLUMN || index.column() == ENF_VER_Z_COLUMN) {
317     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
318     if (entry.isEmpty() && !vertexExists(model, index, lineEdit->GetString()))
319       model->setData(index, lineEdit->GetValue(), Qt::EditRole);
320   } else if (index.column() == ENF_VER_NAME_COLUMN) {
321     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
322     QString value = lineEdit->text();
323     if (entry.isEmpty() && !vertexExists(model, index, value))
324       model->setData(index, value, Qt::EditRole);
325   } else if (index.column() == ENF_VER_ENTRY_COLUMN) {
326     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
327     QString value = lineEdit->text();
328     if (! vertexExists(model, index, value))
329       model->setData(index, value, Qt::EditRole);
330   } else if (index.column() == ENF_VER_GROUP_COLUMN) {
331     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
332     model->setData(index, lineEdit->text(), Qt::EditRole);
333   }
334 }
335
336 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
337     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
338 {
339   editor->setGeometry(option.rect);
340 }
341
342 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
343     const QModelIndex &index, QString value) const
344 {
345   bool exists = false;
346   QModelIndex parent = index.parent();
347   int row = index.row();
348   int col = index.column();
349
350   if (parent.isValid() && !value.isEmpty()) {
351     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
352       double x, y, z;
353       if (col == ENF_VER_X_COLUMN) {
354         x = value.toDouble();
355         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
356         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
357       }
358       if (col == ENF_VER_Y_COLUMN) {
359         y = value.toDouble();
360         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
361         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
362       }
363       if (col == ENF_VER_Z_COLUMN) {
364         z = value.toDouble();
365         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
366         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
367       }
368       int nbChildren = model->rowCount(parent);
369       for (int i = 0 ; i < nbChildren ; i++) {
370         if (i != row) {
371           double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
372           double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
373           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
374           if ((childX == x) && (childY == y) && (childZ == z)) {
375             exists = true;
376             break;
377           }
378         }
379       }
380     }
381     else if (col == ENF_VER_NAME_COLUMN) {
382       int nbChildren = model->rowCount(parent);
383       for (int i = 0 ; i < nbChildren ; i++) {
384         if (i != row) {
385           QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
386           if (childName == value) {
387             exists = true;
388             break;
389           }
390         }
391       }
392     }
393   }
394
395   return exists;
396 }
397
398 //
399 // END EnforcedTreeWidgetDelegate
400 //
401
402
403 /**
404  * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
405  * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
406  *
407  * */
408 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
409   : SMESHGUI_GenericHypothesisCreator( theHypType )
410 {
411   MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
412   this->mySMPMap.clear();
413
414   GeomToolSelected = NULL;
415   GeomToolSelected = getGeomSelectionTool();
416
417   aSel = GeomToolSelected->selectionMgr();
418
419   /* Initialize the Python interpreter */
420   if (! Py_IsInitialized())
421     throw ("Error: Python interpreter is not initialized");
422   PyGILState_STATE gstate;
423   gstate = PyGILState_Ensure();
424
425   main_mod = NULL;
426   main_mod = PyImport_AddModule("__main__");
427
428   main_dict = NULL;
429   main_dict = PyModule_GetDict(main_mod);
430
431   PyRun_SimpleString("from math import *");
432   PyGILState_Release(gstate);
433
434 }
435
436 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
437 {
438 }
439
440 /**
441  * \brief {Get or create the geom selection tool for active study}
442  * */
443 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
444 {
445   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
446   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
447   if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
448     that->GeomToolSelected = new GeomSelectionTools(aStudy);
449   }
450   return that->GeomToolSelected;
451 }
452
453 GEOM::GEOM_Gen_var BLSURFPluginGUI_HypothesisCreator::getGeomEngine()
454 {
455   return GeometryGUI::GetGeomGen();
456 }
457
458
459 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
460 {
461   MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
462   bool ok = true;
463
464   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
465     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
466
467   if ( ok )
468   {
469     myAdvWidget->myOptionTable->setFocus();
470     QApplication::instance()->processEvents();
471
472     int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
473     for ( ; row < nbRows; ++row )
474     {
475       QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
476       QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
477       if ( !value.isEmpty() ) {
478         try {
479           QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().trimmed();
480           if (optionType == "PRECAD")
481             h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
482           else if (optionType == "BLSURF")
483             h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
484         }
485         catch ( const SALOME::SALOME_Exception& ex )
486         {
487           msg = ex.details.text.in();
488           ok = false;
489         }
490       }
491     }
492   }
493   if ( !ok )
494   {
495     h->SetOptionValues( myOptions ); // restore values
496     h->SetPreCADOptionValues( myPreCADOptions ); // restore values
497   }
498
499   // SizeMap and attractors
500   if ( ok )
501   {
502     mySizeMapTable->setFocus();
503     QApplication::instance()->processEvents();
504
505     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
506     int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
507     std::string e, s;
508     for ( ; row < nbRows; ++row )
509     {
510       QString entry   = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
511       QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
512       MESSAGE("entry ="<<entry.toStdString())
513       if ( !sizeMap.isEmpty() ) {
514         if (that->sizeMapValidationFromRow(row))
515         {
516           try {
517             MESSAGE("entry ="<<entry.toStdString())
518             MESSAGE("sizeMap ="<<sizeMap.toStdString())
519             
520             e = entry.toStdString();
521             s = that->mySMPMap[entry].toStdString();
522             MESSAGE("row = "<<row)
523             MESSAGE("e = "<<e)
524             MESSAGE("s = "<<s)
525             h->SetSizeMapEntry( e.c_str(), s.c_str() );
526           }
527           catch ( const SALOME::SALOME_Exception& ex )
528           {
529             msg = ex.details.text.in();
530             ok = false;
531           }
532         }
533         else {
534           ok = false;
535         }
536       }
537     }
538   }
539
540   // Enforced vertices
541   // TODO
542
543   return ok;
544 }
545
546 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
547 {
548   MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
549
550   QFrame* fr = new QFrame( 0 );
551  // fr-> setMinimumSize(600,400);
552   QVBoxLayout* lay = new QVBoxLayout( fr );
553  // lay->setSizeConstraint(QLayout::SetDefaultConstraint);
554   lay->setMargin( 5 );
555   lay->setSpacing( 0 );
556
557   // tab
558   QTabWidget* tab = new QTabWidget( fr );
559   tab->setTabShape( QTabWidget::Rounded );
560   tab->setTabPosition( QTabWidget::North );
561   lay->addWidget( tab );
562
563   myName = 0;
564   
565   // basic parameters
566   myStdGroup = new QWidget();
567   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
568   aStdLayout->setSpacing( 6 );
569   aStdLayout->setMargin( 11 );
570   
571   if( isCreation() )
572     myName = new QLineEdit( myStdGroup );
573   myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
574   
575   int row = 0;
576   if( isCreation() ) {
577     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ),    0, 0, 1, 1 );
578     aStdLayout->addWidget( myName,                                      row++, 1, 1, 3 );
579   }
580   aStdLayout->addWidget( myStdWidget,                                   row++, 0, 1, 4 );
581   
582   int maxrow = row;
583   row = 0;
584   if( isCreation() )
585     row = 1;
586 //   row = max(row,maxrow)+1;
587   aStdLayout->setRowStretch(row,1);
588   aStdLayout->setColumnStretch(1,1);
589   maxrow = row;
590
591   
592   // advanced parameters
593   myAdvGroup = new QWidget();
594   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
595   anAdvLayout->setSpacing( 6 );
596   anAdvLayout->setMargin( 11 );  
597   myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
598   myAdvWidget->addBtn->setMenu( new QMenu() );
599   anAdvLayout->addWidget( myAdvWidget);
600
601
602   // Size Maps parameters
603
604   mySmpGroup = new QWidget();
605 //   mySmpGroup->setMinimumWidth(500);
606
607   //Layout
608   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
609   
610   // Table
611   mySizeMapTable = new QTreeWidget( mySmpGroup );
612   mySizeMapTable ->setMinimumWidth(200);
613   QStringList sizeMapHeaders;
614   sizeMapHeaders << tr( "SMP_NAME_COLUMN" )<< tr( "SMP_SIZEMAP_COLUMN" )<< tr( "SMP_ENTRY_COLUMN" );// << tr( "SMP_DIST_COLUMN" );
615   mySizeMapTable->setHeaderLabels(sizeMapHeaders);
616   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
617   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
618   mySizeMapTable->hideColumn(SMP_ENTRY_COLUMN);
619   mySizeMapTable->setAlternatingRowColors(true);
620   
621   // tab widget
622   smpTab = new QTabWidget( mySmpGroup );
623   smpTab->setTabShape( QTabWidget::Rounded );
624   smpTab->setTabPosition( QTabWidget::South );
625   lay->addWidget( smpTab );
626   
627   // Filters of selection
628   TColStd_MapOfInteger SM_ShapeTypes, ATT_ShapeTypes;
629   
630   SM_ShapeTypes.Add( TopAbs_VERTEX );
631   SM_ShapeTypes.Add( TopAbs_EDGE );
632   SM_ShapeTypes.Add( TopAbs_FACE );
633   SM_ShapeTypes.Add( TopAbs_COMPOUND );
634   
635   ATT_ShapeTypes.Add( TopAbs_VERTEX );
636   ATT_ShapeTypes.Add( TopAbs_EDGE );
637   ATT_ShapeTypes.Add( TopAbs_WIRE );
638   ATT_ShapeTypes.Add( TopAbs_COMPOUND );
639   
640   SMESH_NumberFilter* myFilter1 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
641   SMESH_NumberFilter* myFilter2 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, ATT_ShapeTypes);
642   SMESH_NumberFilter* myFilter3 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, TopAbs_FACE);
643   
644   // Standard size map tab
645   mySmpStdGroup = new QWidget();
646   QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
647   myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false,/*stretch=*/false);
648   myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
649   mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
650   mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
651   QLabel* mySmpSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),mySmpStdGroup);
652   
653   // Attractor tab
654   myAttractorGroup = new QWidget();
655   QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
656   myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false,/*stretch=*/false);
657   myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
658   myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
659   myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
660   myConstSizeCheck = new QCheckBox(tr("BLSURF_CONST_SIZE"),myAttractorGroup);
661   QFrame* attLine  = new QFrame(myAttractorGroup);
662   attLine->setFrameShape(QFrame::HLine);
663   attLine->setFrameShadow(QFrame::Sunken);
664   myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false,/*stretch=*/false);
665   myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }"); 
666   myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
667   myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
668   myAttSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),myAttractorGroup);
669   myAttDistSpin = new SMESHGUI_SpinBox(myAttractorGroup);
670   myAttDistSpin->RangeStepAndValidator(0., COORD_MAX, 10.0, "length_precision");
671   myAttDistLabel = new QLabel(tr("BLSURF_ATT_DIST"),myAttractorGroup);
672   myAttDistSpin2 = new SMESHGUI_SpinBox(myAttractorGroup);
673   myAttDistSpin2->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
674   myAttDistLabel2 = new QLabel(tr("BLSURF_ATT_RADIUS"),myAttractorGroup);
675   
676   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
677   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
678   
679   // Push buttons
680   
681   addMapButton = new QPushButton(tr("BLSURF_SM_ADD"),mySmpGroup);
682   removeMapButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
683   modifyMapButton = new QPushButton(tr("BLSURF_SM_MODIFY"),mySmpGroup);
684   modifyMapButton->setEnabled(false);
685   
686   // Init SpinBoxes
687   myAttSelWdg->setEnabled(false);
688   myAttSizeSpin->setEnabled(false);
689   myAttSizeLabel->setEnabled(false);
690   myAttDistSpin->setEnabled(false);
691   myAttDistLabel->setEnabled(false);
692   myAttDistSpin2->setEnabled(false);
693   myAttDistLabel2->setEnabled(false);
694   myAttDistSpin->setValue(0.);
695   myAttDistSpin2->setValue(0.);
696   myAttSizeSpin->setValue(0.);
697   mySmpSizeSpin->setValue(0.);
698
699   
700   // ADD WIDGETS (SIZEMAP TAB)
701   anSmpLayout->addWidget(mySizeMapTable,     0,  0, SMP_NB_LINES, 1);
702   anSmpLayout->setColumnStretch(0, 1);
703 //  anSmpLayout->addWidget(line2,              SMP_SEPARATOR2, 1, 2, 2);
704   anSmpLayout->addWidget(smpTab,             SMP_TAB_WDG,     1, 1, 3);
705   anSmpLayout->setRowStretch(SMP_TAB_WDG, 1);
706   anSmpLayout->addWidget(addMapButton,       SMP_ADD_BTN,     1, 1, 1);
707   anSmpLayout->addWidget(removeMapButton,    SMP_ADD_BTN,     2, 1, 1);
708   anSmpLayout->addWidget(modifyMapButton,    SMP_ADD_BTN,     3, 1, 1);
709   
710   // STANDARD TAB
711   anSmpStdLayout->addWidget(myGeomSelWdg1,   SMP_GEOM_BTN_1,  1, 1, 2);
712   anSmpStdLayout->addWidget(mySmpSizeLabel,  SMP_SIZE,        1, 1, 1);
713   anSmpStdLayout->addWidget(mySmpSizeSpin,   SMP_SIZE,        2, 1, 1);
714   anSmpStdLayout->setRowStretch(SMP_SPACE2, 1);
715   
716   // ADVANCED TAB
717   anAttLayout->addWidget(myGeomSelWdg2,      SMP_GEOM_BTN_2,  1, 1, 2);
718   anAttLayout->addWidget(myAttractorCheck,   ATT_CHECK,       1, 1, 2);
719   anAttLayout->addWidget(myConstSizeCheck,   CONST_SIZE_CHECK,1, 1, 2);
720   anAttLayout->addWidget(attLine,            SMP_SPACE,       1, 1, 2);
721   anAttLayout->addWidget(myAttSelWdg,        SMP_ATT_SHAPE,   1, 1, 2);
722   anAttLayout->addWidget(myAttSizeLabel,     SMP_ATT_SIZE,    1, 1, 1);
723   anAttLayout->addWidget(myAttSizeSpin,      SMP_ATT_SIZE,    2, 1, 1);
724   anAttLayout->addWidget(myAttDistLabel,     SMP_ATT_DIST,    1, 1, 1);
725   anAttLayout->addWidget(myAttDistSpin,      SMP_ATT_DIST,    2, 1, 1);
726   anAttLayout->addWidget(myAttDistLabel2,    SMP_ATT_RAD,     1, 1, 1);
727   anAttLayout->addWidget(myAttDistSpin2,     SMP_ATT_RAD,     2, 1, 1);
728   anAttLayout->setRowStretch(SMP_ATT_RAD+1, 1);
729   
730   smpTab->insertTab( SMP_STD_TAB, mySmpStdGroup, tr( "BLSURF_SM_STD_TAB" ) );
731   smpTab->insertTab( ATT_TAB, myAttractorGroup, tr( "BLSURF_SM_ATT_TAB" ) );
732
733   smpTab->setCurrentIndex( SMP_STD_TAB ); 
734
735   // Enforced vertices parameters
736   myEnfGroup = new QWidget();
737   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
738 //
739 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
740 //   anEnfLayout->addWidget(myEnforcedVertexWidget);
741 //   MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
742 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
743
744   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
745   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
746   myEnforcedTreeWidget->setSortingEnabled(true);
747   QStringList enforcedHeaders;
748   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_FACE_ENTRY_COLUMN")
749                   << tr("BLSURF_ENF_VER_X_COLUMN")<< tr("BLSURF_ENF_VER_Y_COLUMN") << tr("BLSURF_ENF_VER_Z_COLUMN")
750                   << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
751
752   myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
753   myEnforcedTreeWidget->header()->setStretchLastSection(true);
754   myEnforcedTreeWidget->setAlternatingRowColors(true);
755   myEnforcedTreeWidget->setUniformRowHeights(true);
756   myEnforcedTreeWidget->setAnimated(true);
757   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
758   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
759   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
760     myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
761     myEnforcedTreeWidget->resizeColumnToContents(column);
762   }
763   myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
764   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
765   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
766   
767 // FACE AND VERTEX SELECTION
768   TColStd_MapOfInteger shapeTypes1, shapeTypes2;
769   shapeTypes1.Add( TopAbs_FACE );
770   shapeTypes1.Add( TopAbs_COMPOUND );
771   shapeTypes2.Add( TopAbs_VERTEX );
772   shapeTypes2.Add( TopAbs_COMPOUND );
773
774   SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
775   myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true, /*stretch=*/false);
776   myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
777
778   SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
779   myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false);
780   myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
781
782   myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
783
784   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
785   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
786   myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
787
788   QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
789   myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
790   myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
791
792   QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
793   myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
794   myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
795
796   QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
797   myGroupName = new QLineEdit(myEnfGroup);
798
799   addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
800   removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
801
802   myInternalEnforcedVerticesAllFaces = new QCheckBox(tr("BLSURF_ENF_VER_INTERNAL_VERTICES"),myEnfGroup);
803
804   QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
805   myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
806
807 //   myGlobalGroupName = new QCheckBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
808 //   myGlobalGroupName->setChecked(false);
809
810   anEnfLayout->addWidget(myEnforcedTreeWidget,     0, 0, ENF_VER_NB_LINES, 1);
811   QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
812 //  FACE AND VERTEX SELECTION
813   anEnfLayout2->addWidget(myEnfFaceWdg,             ENF_VER_FACE, 0, 1, 2);
814   anEnfLayout2->addWidget(myEnfVertexWdg,           ENF_VER_VERTEX, 0, 1, 2);
815   anEnfLayout2->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 0, 1, 1);
816   anEnfLayout2->addWidget(myXCoord,                 ENF_VER_X_COORD, 1, 1, 1);
817   anEnfLayout2->addWidget(myYCoordLabel,            ENF_VER_Y_COORD, 0, 1, 1);
818   anEnfLayout2->addWidget(myYCoord,                 ENF_VER_Y_COORD, 1, 1, 1);
819   anEnfLayout2->addWidget(myZCoordLabel,            ENF_VER_Z_COORD, 0, 1, 1);
820   anEnfLayout2->addWidget(myZCoord,                 ENF_VER_Z_COORD, 1, 1, 1);
821   anEnfLayout2->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 0, 1, 1);
822   anEnfLayout2->addWidget(myGroupName,              ENF_VER_GROUP, 1, 1, 1);
823 //   anEnfLayout2->addWidget(myGlobalGroupName,        ENF_VER_GROUP_CHECK, 0, 1, 2);
824 //   anEnfLayout2->setRowStretch(                      ENF_VER_SPACE, 1);
825   anEnfLayout2->addWidget(addVertexButton,          ENF_VER_BTN, 0, 1, 1);
826   anEnfLayout2->addWidget(removeVertexButton,       ENF_VER_BTN, 1, 1, 1);
827   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
828   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
829   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
830   anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
831 //   anEnfLayout2->addWidget(makeGroupsCheck,          ENF_VER_GROUP_CHECK, 0, 1, 2);
832   anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
833 //   anEnfLayout->setRowStretch(1, 1);
834
835   // ---
836   tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
837   tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
838   tab->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
839   tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
840
841   tab->setCurrentIndex( STD_TAB );
842
843   connect( myAdvWidget->addBtn->menu(), SIGNAL( aboutToShow() ),         this, SLOT( onAddOption() ) );
844   connect( myAdvWidget->addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
845   connect( myAdvWidget->rmBtn,          SIGNAL( clicked()),              this, SLOT( onDeleteOption() ) );
846
847   // Size Maps
848   connect( addMapButton,        SIGNAL( clicked()),                    this,         SLOT( onAddMap() ) );
849   connect( removeMapButton,     SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
850   connect( modifyMapButton,     SIGNAL( clicked()),                    this,         SLOT( onModifyMap() ) );
851 //   connect( mySizeMapTable,      SIGNAL( cellChanged ( int, int  )),    this,         SLOT( onSetSizeMap(int,int ) ) );
852   connect( mySizeMapTable,      SIGNAL( itemClicked (QTreeWidgetItem *, int)),this,  SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
853   connect( myGeomSelWdg2,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
854   connect( myGeomSelWdg1,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
855 //   connect( myAttractorGroup,    SIGNAL( clicked(bool) ),               this,         SLOT( onAttractorGroupClicked(bool) ) );
856   connect( mySizeMapTable,      SIGNAL( itemChanged (QTreeWidgetItem *, int)),this,  SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
857   connect( myAttractorCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onAttractorClicked( int ) ) );
858   connect( myConstSizeCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onConstSizeClicked( int ) ) );
859   connect( smpTab,              SIGNAL( currentChanged ( int )),       this,         SLOT( onSmpTabChanged( int ) ) );
860
861   // Enforced vertices
862   connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this,  SLOT( synchronizeCoords() ) );
863   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
864 //   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( update(QTreeWidgetItem *, int) ) );
865   connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),      this,         SLOT( synchronizeCoords() ) );
866   connect( addVertexButton,     SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
867   connect( removeVertexButton,  SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
868   connect( myEnfVertexWdg,      SIGNAL( contentModified()),            this,         SLOT( onSelectEnforcedVertex() ) );
869   connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this,  SLOT( onInternalVerticesClicked( int ) ) );
870 //   connect( myEnfVertexWdg,     SIGNAL( selectionActivated()),         this,         SLOT( onVertexSelectionActivated() ) );
871 //   connect( myEnfFaceWdg,       SIGNAL( selectionActivated()),         this,         SLOT( onFaceSelectionActivated() ) );
872
873   return fr;
874 }
875
876 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
877 This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
878 */
879 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
880 // {
881 //   if ((now == myXCoord) || (now == myYCoord) || (now == myZCoord)
882 //       || (now = myGroupName) || (now = myGlobalGroupName) || (now = myEnforcedTreeWidget)) {
883 //     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
884 //     that->getGeomSelectionTool()->selectionMgr()->clearFilters();
885 //     myEnfFaceWdg->deactivateSelection();
886 //     myEnfVertexWdg->deactivateSelection();
887 //   }
888 // }
889
890 /** 
891  * This method resets the content of the X, Y, Z widgets;
892 **/
893 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
894 {
895   myXCoord->setCleared(true);
896   myYCoord->setCleared(true);
897   myZCoord->setCleared(true);
898   myXCoord->setText("");
899   myYCoord->setText("");
900   myZCoord->setText("");
901 //   myGroupName->setText("");
902 }
903
904 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
905 This method updates the tooltip of a modified item. The QLineEdit widgets content
906 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
907 */
908 void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
909 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
910   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
911   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
912   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
913   QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
914   QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
915   QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
916   QTreeWidgetItem* parent = item->parent();
917   
918   clearEnforcedVertexWidgets();
919   
920   if (parent && (!x.isNull() || !entry.isNull())) {
921       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
922       QString toolTip = shapeName + QString(": ") + vertexName.toString();
923       if (entry.isNull()) {
924         toolTip += QString("(") + x.toString();
925         toolTip += QString(", ") + y.toString();
926         toolTip += QString(", ") + z.toString();
927         toolTip += QString(")");
928       }
929       
930       if (!groupName.isEmpty())
931         toolTip += QString(" [") + groupName + QString("]");
932
933       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
934
935     if (!x.isNull()) {
936       myXCoord->SetValue(x.toDouble());
937       myYCoord->SetValue(y.toDouble());
938       myZCoord->SetValue(z.toDouble());
939     }
940     
941     if (!groupName.isEmpty())
942       myGroupName->setText(groupName);
943   }
944 }
945
946 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
947   int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
948   clearEnforcedVertexWidgets();
949   if (nbSelEnfVertex == 1)
950   {
951     if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
952     return ;
953
954     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
955     if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
956       BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
957       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
958       if (CORBA::is_nil(measureOp))
959         return;
960       
961       CORBA::Double x,y,z;
962       measureOp->PointCoordinates (myEnfVertex, x, y, z);
963       if ( measureOp->IsDone() )
964       {
965         myXCoord->SetValue(x);
966         myYCoord->SetValue(y);
967         myZCoord->SetValue(z);
968       }
969     }
970   }
971 }
972
973 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
974 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
975 of the enforced vertex clicked in the tree widget.
976 */
977 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
978   clearEnforcedVertexWidgets();
979   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
980   if (! items.isEmpty() && items.size() == 1) {
981     QTreeWidgetItem *item = items[0];
982 //     for (int i=0 ; i < items.size() ; i++) {
983 //       item = items[i];
984       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
985       QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
986       QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
987       QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
988       QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
989       if (!x.isNull()/* && entry.isNull()*/) {
990         myXCoord->SetValue(x.toDouble());
991         myYCoord->SetValue(y.toDouble());
992         myZCoord->SetValue(z.toDouble());
993 //         break;
994       }
995       if (!group.isNull() && (!x.isNull() || !entry.isNull()))
996         myGroupName->setText(group.toString());
997 //     }
998   }
999 }
1000
1001 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1002 This method adds a face containing enforced vertices in the tree widget.
1003 */
1004 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
1005   // Find theFaceEntry item
1006   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1007   QTreeWidgetItem* theItem;
1008   if (theItemList.empty()) {
1009     theItem = new QTreeWidgetItem();
1010     theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1011     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1012     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1013     myEnforcedTreeWidget->addTopLevelItem(theItem);
1014   }
1015   else {
1016     theItem = theItemList[0];
1017   }
1018   return theItem;
1019 }
1020
1021 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1022 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1023 */
1024 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theItem, double x, double y, double z, 
1025                                                           std::string vertexName, std::string geomEntry, std::string groupName) {
1026
1027   std::string theFaceName = theItem->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
1028 //   MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
1029   bool okToCreate = true;
1030
1031   const int nbVert = theItem->childCount();
1032 //   MESSAGE("Number of child rows: " << nbVert);
1033   if (nbVert >0) {
1034     double childValueX,childValueY,childValueZ;
1035     QString childEntry, childGroupName;
1036     QTreeWidgetItem* child;
1037     for (int row = 0;row<nbVert;row++) {
1038       child = theItem->child(row);
1039       childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1040       childEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1041       childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1042       childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1043       childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1044       if (((childValueX == x) && (childValueY == y) && (childValueZ == z)) || ( (childEntry.toStdString() != "") && (childEntry.toStdString() == geomEntry))) {
1045         // update group name
1046         if (childGroupName.toStdString() != groupName) {
1047           MESSAGE("Group is updated from \"" << childGroupName.toStdString() << "\" to \"" << groupName << "\"");
1048           child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1049         }
1050         okToCreate = false;
1051         break;
1052       } // if
1053     } // for
1054   } // if
1055   if (!okToCreate) {
1056     if (geomEntry.empty()) {
1057       MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1058     }
1059     else {
1060       MESSAGE("In " << theFaceName << " vertex with entry " << geomEntry << " already exist: dont create again");
1061     }
1062     return;
1063   }
1064     
1065   if (geomEntry.empty()) {
1066     MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
1067   }
1068   else {
1069     MESSAGE("In " << theFaceName << " vertex with geom entry " << geomEntry << " is created");
1070   }
1071
1072   QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
1073   vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1074   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1075   QSize iconSize = iconSelect.size()*0.7;
1076   
1077   int vertexIndex=myEnforcedTreeWidget->indexOfTopLevelItem(theItem);
1078   QString myVertexName;
1079   int indexRef = -1;
1080   while(indexRef != vertexIndex) {
1081     indexRef = vertexIndex;
1082     if (vertexName.empty())
1083       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1084     else
1085       myVertexName = QString(vertexName.c_str());
1086
1087     for (int row = 0;row<nbVert;row++) {
1088       QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1089       if (myVertexName == name) {
1090         vertexIndex++;
1091         break;
1092       }
1093     }
1094   }
1095   vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1096   if (geomEntry.empty()) {
1097     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1098     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1099     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1100   }
1101   else {
1102     vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1103     vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1104   }
1105   if (groupName != "")
1106     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1107
1108   QString toolTip = QString(theFaceName.c_str())+QString(": ")+myVertexName;
1109   if (geomEntry.empty()) {
1110     toolTip += QString(" (%1, ").arg(x);
1111     toolTip += QString("%1, ").arg(y);
1112     toolTip += QString("%1)").arg(z);
1113   }
1114   if (groupName != "")
1115     toolTip += QString(" [%1]").arg(groupName.c_str());
1116   
1117   vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1118   theItem->setExpanded(true);
1119   myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1120 }
1121
1122 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1123 This method is called when a item is added into the enforced vertices tree widget
1124 */
1125 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
1126 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1127
1128   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1129
1130   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1131   myEnfFaceWdg->deactivateSelection();
1132   myEnfVertexWdg->deactivateSelection();
1133
1134   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1135     myEnforcedTreeWidget->resizeColumnToContents(column);
1136
1137   // Vertex selection
1138   int selEnfFace   = myEnfFaceWdg->NbObjects();
1139   int selEnfVertex = myEnfVertexWdg->NbObjects();
1140   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1141
1142   if (selEnfFace == 0)
1143     return;
1144
1145   if ((selEnfVertex == 0) && coordsEmpty)
1146     return;
1147
1148   string entry, shapeName;
1149
1150   for (int i = 0 ; i < selEnfFace ; i++) {
1151     myEnfFace = myEnfFaceWdg->GetObject< GEOM::GEOM_Object >(i);
1152     entry = myEnfFace->GetStudyEntry();
1153     shapeName = myEnfFace->GetName();
1154     
1155     QTreeWidgetItem * faceItem = addEnforcedFace(entry, shapeName);
1156     
1157     std::string groupName = myGroupName->text().toStdString();
1158
1159     if (boost::trim_copy(groupName).empty())
1160       groupName = "";
1161
1162     if (selEnfVertex <= 1)
1163     {
1164       double x,y,z;
1165       x = myXCoord->GetValue();
1166       y = myYCoord->GetValue();
1167       z = myZCoord->GetValue();
1168       if (selEnfVertex == 1) {
1169         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1170         addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1171       }
1172       else
1173         addEnforcedVertex(faceItem, x, y, z, "", "", groupName);
1174     }
1175     else
1176     {
1177       if ( CORBA::is_nil(getGeomEngine()))
1178         return;
1179
1180       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1181       if (CORBA::is_nil(measureOp))
1182         return;
1183
1184       CORBA::Double x,y,z;
1185       x = y = z = 0.;
1186       for (int j = 0 ; j < selEnfVertex ; j++)
1187       {
1188         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1189         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1190           measureOp->PointCoordinates (myEnfVertex, x, y, z);
1191           if ( measureOp->IsDone() )
1192             addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1193         } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1194             addEnforcedVertex(faceItem, 0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1195         }
1196       }
1197     }
1198   }
1199
1200   myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
1201   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1202   
1203   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1204     myEnforcedTreeWidget->resizeColumnToContents(column);
1205
1206   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1207     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1208     myStdWidget->onPhysicalMeshChanged();
1209   }
1210 }
1211
1212 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1213 This method is called when a item is removed from the enforced vertices tree widget
1214 */
1215 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1216 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1217   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1218   QList<QTreeWidgetItem *> selectedVertices;
1219   QSet<QTreeWidgetItem *> selectedEntries;
1220   QTreeWidgetItem* item;
1221
1222   foreach( item, selectedItems ) {
1223     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1224     if (! value.isNull())
1225       selectedVertices.append(item);
1226     else {
1227       value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1228       if (! value.isNull())
1229         selectedVertices.append(item);
1230       else
1231         selectedEntries.insert(item);
1232     }
1233   }
1234
1235   foreach(item,selectedVertices) {
1236     QTreeWidgetItem* parent = item->parent();
1237 //     MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1238     parent->removeChild(item);
1239     delete item;
1240     if (parent->childCount() == 0) {
1241       if (selectedEntries.contains(parent))
1242         selectedEntries.remove(parent);
1243       delete parent;
1244     }
1245   }
1246
1247   foreach(item,selectedEntries) {
1248 //     MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1249     delete item;
1250   }
1251
1252   myEnforcedTreeWidget->selectionModel()->clearSelection();
1253 }
1254
1255
1256 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1257 {
1258   myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1259 }
1260
1261 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1262 This method updates the GUI widgets with the hypothesis data
1263 */
1264 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1265 {
1266   MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1267   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1268
1269   BlsurfHypothesisData data;
1270   that->readParamsFromHypo( data );
1271
1272   if ( myName ) {
1273     myName->setText( data.myName );
1274     QFontMetrics metrics( myName->font() );
1275     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1276   }
1277   myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1278   myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1279   if (data.myPhySize <= 0)
1280     myStdWidget->myPhySize->setText("");
1281   else
1282     myStdWidget->myPhySize->SetValue( data.myPhySize );
1283   myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1284   if (data.myMinSize < 0)
1285     myStdWidget->myMinSize->setText("");
1286   else
1287     myStdWidget->myMinSize->SetValue( data.myMinSize );
1288   myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1289   if (data.myMaxSize < 0)
1290     myStdWidget->myMaxSize->setText("");
1291   else
1292     myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1293   myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1294   if (data.myGradation <= 0)
1295     myStdWidget->myGradation->setText("");
1296   else
1297     myStdWidget->myGradation->SetValue( data.myGradation );
1298   myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1299   
1300   if (data.myAngleMesh < 0)
1301     myStdWidget->myAngleMesh->setText("");
1302   else
1303     myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1304   if (data.myChordalError <= 0)
1305     myStdWidget->myChordalError->setText("");
1306   else
1307     myStdWidget->myChordalError->SetValue( data.myChordalError );
1308   myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1309   if (data.myAnisotropicRatio <= 0)
1310     myStdWidget->myAnisotropicRatio->setText("");
1311   else
1312     myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1313   myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1314   if (data.myTinyEdgeLength <= 0)
1315     myStdWidget->myTinyEdgeLength->setText("");
1316   else
1317     myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1318   myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1319   if (data.myBadElementAspectRatio <= 0)
1320     myStdWidget->myBadElementAspectRatio->setText("");
1321   else
1322     myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1323   myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1324   myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1325   
1326   myStdWidget->resizeWidgets();  
1327   
1328   myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1329   myAdvWidget->myPreCADGroupBox->setChecked(data.myTopology == PreCAD);
1330   myAdvWidget->myPreCADMergeEdges->setChecked( data.myPreCADMergeEdges );
1331   myAdvWidget->myPreCADProcess3DTopology->setChecked( data.myPreCADProcess3DTopology );
1332   myAdvWidget->myPreCADDiscardInput->setChecked( data.myPreCADDiscardInput );
1333
1334   if ( myOptions.operator->() ) {
1335 //     MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1336     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1337       QString option = that->myOptions[i].in();
1338       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1339       if ( name_value.count() > 1 ) {
1340         QString idStr = QString("%1").arg( i );
1341         int row = myAdvWidget->myOptionTable->rowCount();
1342         myAdvWidget->myOptionTable->setRowCount( row+1 );
1343         myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1344         myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1345         myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "BLSURF" ) );
1346         myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1347         myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1348         myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1349         myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1350         myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1351                                                                                 Qt::ItemIsEditable   |
1352                                                                                 Qt::ItemIsEnabled );
1353       }
1354     }
1355   }
1356   if ( myPreCADOptions.operator->() ) {
1357 //     MESSAGE("retrieveParams():myPreCADOptions->length() = " << myPreCADOptions->length());
1358     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
1359       QString option = that->myPreCADOptions[i].in();
1360       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1361       if ( name_value.count() > 1 ) {
1362         QString idStr = QString("%1").arg( i );
1363         int row = myAdvWidget->myOptionTable->rowCount();
1364         myAdvWidget->myOptionTable->setRowCount( row+1 );
1365         myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1366         myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1367         myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "PRECAD" ) );
1368         myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1369         myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1370         myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1371         myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1372         myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1373                                                                                 Qt::ItemIsEditable   |
1374                                                                                 Qt::ItemIsEnabled );
1375       }
1376     }
1377   }
1378   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1379   myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1380 //   myGMFFileMode->setChecked(data.myGMFFileMode);
1381   
1382   // Sizemaps
1383   MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1384   QMapIterator<QString, QString> i(that->mySMPMap);
1385   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1386   while (i.hasNext()) {
1387     i.next();
1388     const QString entry = i.key();
1389     const QString sizeMap = i.value();
1390     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString()); 
1391     int row = mySizeMapTable->topLevelItemCount();
1392     QTreeWidgetItem* item = new QTreeWidgetItem();
1393     mySizeMapTable->addTopLevelItem( item ); 
1394     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1395     item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1396     item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1397     if (that->myATTMap.contains(entry)){
1398       const QString attEntry = that->myATTMap[entry];
1399       std::string attName = myGeomToolSelected->getNameFromEntry(attEntry.toStdString());
1400       QTreeWidgetItem* child = new QTreeWidgetItem();
1401       item->addChild( child );
1402       item->setExpanded(true);
1403       child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap  ) );
1404       child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attEntry  ) );
1405       child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString( attName ) ) );
1406    
1407       if (that->myAttDistMap[entry] >  std::numeric_limits<double>::epsilon()){
1408         item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Attractor" )  ) ); 
1409       }
1410       else{
1411         item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Constant Size" )  ) );
1412       }
1413     }
1414     else
1415     {
1416       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1417     } 
1418   }
1419   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1420   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1421   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1422
1423   // Enforced vertices
1424   MESSAGE("retrieveParams(): data.entryCoordsListMap.size() = " << data.faceEntryEnfVertexListMap.size());
1425   TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1426
1427   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1428     TEntry entry = (*evmIt).first;
1429     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1430     MESSAGE("Face entry: " << entry);
1431     MESSAGE("Face name: " << shapeName);
1432     
1433     QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1434
1435     TEnfVertexList evs = (*evmIt).second;
1436
1437     TEnfVertexList::const_iterator evsIt = evs.begin();
1438     TEnfVertex *enfVertex;
1439     for ( ; evsIt != evs.end() ; ++evsIt) {
1440       enfVertex = (*evsIt);
1441       MESSAGE("Name: " << enfVertex->name);
1442       double x, y, z = 0;
1443       if (enfVertex->coords.size()) {
1444         x = enfVertex->coords[0];
1445         y = enfVertex->coords[1];
1446         z = enfVertex->coords[2];
1447       }
1448       that->addEnforcedVertex(faceItem, x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1449     }
1450   }
1451   
1452   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1453     myEnforcedTreeWidget->resizeColumnToContents(column);
1454
1455   myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
1456   myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
1457   myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
1458
1459   // update widgets
1460   that->myStdWidget->onPhysicalMeshChanged();
1461   that->myStdWidget->onGeometricMeshChanged();
1462 }
1463
1464 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1465 This method updates the hypothesis data with the GUI widgets content.
1466 */
1467 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1468 {
1469   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1470
1471   BlsurfHypothesisData data;
1472   QString guiHyp = that->readParamsFromWidgets( data );
1473   that->storeParamsToHypo( data );
1474
1475   return guiHyp;
1476 }
1477
1478 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1479 Updates the hypothesis data from hypothesis values.
1480 */
1481 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1482 {
1483   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1484   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1485     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1486
1487   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1488   h_data.myName = isCreation() && data ? hypName() : "";
1489
1490   h_data.myPhysicalMesh           = (int) h->GetPhysicalMesh();
1491   h_data.myGeometricMesh          = (int) h->GetGeometricMesh();
1492   h_data.myPhySize                = h->GetPhySize();
1493   h_data.myPhySizeRel             = h->IsPhySizeRel();
1494   double minSize                  = h->GetMinSize();
1495   double maxSize                  = h->GetMaxSize();
1496   h_data.myMinSize                = minSize > 0 ? minSize : -1.0;
1497   h_data.myMinSizeRel             = h->IsMinSizeRel();
1498   h_data.myMaxSize                = maxSize > 0 ? maxSize : -1.0;
1499   h_data.myMaxSizeRel             = h->IsMaxSizeRel();
1500   h_data.myGradation              = h->GetGradation();
1501   h_data.myAllowQuadrangles       = h->GetQuadAllowed();
1502   double angle                    = h->GetAngleMesh();
1503   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
1504   double chordalError             = h->GetChordalError();
1505   h_data.myChordalError           = chordalError > 0 ? chordalError : -1.0;
1506   h_data.myAnisotropic            = h->GetAnisotropic();
1507   double myAnisotropicRatio       = h->GetAnisotropicRatio();
1508   h_data.myAnisotropicRatio       = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
1509   h_data.myRemoveTinyEdges        = h->GetRemoveTinyEdges();
1510   double myTinyEdgeLength         = h->GetTinyEdgeLength();
1511   h_data.myTinyEdgeLength         = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
1512   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
1513   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
1514   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
1515   h_data.myOptimizeMesh           = h->GetOptimizeMesh();
1516   h_data.myQuadraticMesh          = h->GetQuadraticMesh();
1517   h_data.myVerbosity              = h->GetVerbosity();
1518   h_data.myTopology               = (int) h->GetTopology();
1519   h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
1520   h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
1521   h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
1522
1523
1524   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1525   that->myOptions = h->GetOptionValues();
1526   that->myPreCADOptions = h->GetPreCADOptionValues();
1527   
1528   h_data.myGMFFileName = h->GetGMFFile();
1529 //   h_data.myGMFFileMode = h->GetGMFFileMode();
1530
1531   that->mySMPMap.clear();
1532   that->myATTMap.clear();
1533   that->myAttDistMap.clear();
1534   that->myDistMap.clear();
1535
1536   // classic size maps
1537   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1538 //   MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1539   QString fullSizeMaps;
1540   QStringList fullSizeMapList;
1541   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1542   for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1543     fullSizeMaps =  mySizeMaps[i].in();
1544 //     MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1545     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1546     if ( fullSizeMapList.count() > 1 ) {
1547       string fullSizeMap = fullSizeMapList[1].toStdString();
1548       int pos = fullSizeMap.find("return")+7;
1549 //       MESSAGE("pos:" << pos);
1550       QString sizeMap;
1551       try {
1552         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1553       }
1554       catch (...) {
1555         continue;
1556       }
1557       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1558 //       MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1559       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1560 //       MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1561     }
1562   }
1563
1564   // custom size maps
1565 /*
1566   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1567   MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1568
1569   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1570     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
1571     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1572     if ( fullCustomSizeMapList.count() > 1 ) {
1573       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1574       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1575       MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1576       MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1577     }
1578   }
1579 */
1580   // attractor
1581   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1582 //   MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1583
1584   for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1585     QString myAttractors =  allMyAttractors[i].in();
1586     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1587     if ( myAttractorList.count() > 1 ) {
1588       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1589       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1590 //       MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1591 //       MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1592     }
1593   }
1594   
1595   // attractor new version
1596   MESSAGE("retrieveParams, Attractors")
1597   BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
1598   for ( int i = 0;i<allMyAttractorParams->length(); ++i ) {
1599     BLSURFPlugin::TAttractorParams myAttractorParams =  allMyAttractorParams[i];
1600     QString faceEntry = myAttractorParams.faceEntry.in();
1601     QString attEntry  = myAttractorParams.attEntry.in();
1602     MESSAGE("attEntry = "<<attEntry.toStdString())
1603     double  startSize = myAttractorParams.startSize;
1604     double  endSize   = myAttractorParams.endSize;
1605     double  infDist   = myAttractorParams.infDist;
1606     double  constDist = myAttractorParams.constDist;
1607     that->mySMPMap[faceEntry] = QString::number( startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
1608     that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
1609     that->myATTMap[faceEntry] = attEntry;
1610     that->myAttDistMap[faceEntry] = infDist;
1611     that->myDistMap[faceEntry] = constDist;
1612   }
1613   
1614   // Enforced vertices
1615   h_data.enfVertexList.clear();
1616   h_data.faceEntryEnfVertexListMap.clear();
1617   /* TODO GROUPS
1618   h_data.groupNameEnfVertexListMap.clear();
1619   */
1620
1621   BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
1622   MESSAGE("faceEntryEnfVertexListMap->length() = " << faceEntryEnfVertexListMap->length());
1623
1624   for ( int i = 0;i<faceEntryEnfVertexListMap->length(); ++i ) {
1625     std::string entry =  faceEntryEnfVertexListMap[i].faceEntry.in();
1626 //     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList.in();
1627     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
1628 //     BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1629
1630 //     TEnfVertexList& enfVertexList = h_data.faceEntryEnfVertexListMap[entry];
1631
1632     for (int j=0 ; j<vertexList.length(); ++j) {
1633       TEnfVertex *enfVertex = new TEnfVertex();
1634       
1635       enfVertex->name = CORBA::string_dup(vertexList[j].name.in());
1636       enfVertex->geomEntry = CORBA::string_dup(vertexList[j].geomEntry.in());
1637       enfVertex->grpName = CORBA::string_dup(vertexList[j].grpName.in());
1638       for (int k=0 ; k< vertexList[j].coords.length();k++)
1639         enfVertex->coords.push_back(vertexList[j].coords[k]);
1640
1641       h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
1642
1643       /* TODO GROUPS
1644       if (groupName != "") {
1645         h_data.groupNameEnfVertexListMap[groupName].insert(ev);
1646       }
1647       */
1648     }
1649 //     h_data.enfVertMap[entry] = evs;
1650 //     h_data.entryCoordsListMap[entry] = coordsList;
1651
1652     if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
1653       h_data.faceEntryEnfVertexListMap.erase(entry);
1654     }
1655   }
1656   h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
1657   h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
1658
1659   return true;
1660 }
1661
1662 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1663 Saves the hypothesis data to hypothesis values.
1664 */
1665 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1666 {
1667   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1668   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1669     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1670
1671   bool ok = true;
1672   try
1673   {
1674     if ( isCreation() )
1675       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1676
1677     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
1678       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1679     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1680       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1681
1682     if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
1683       if ( h->GetPhySize()   != h_data.myPhySize ||
1684            h->IsPhySizeRel() != h_data.myPhySizeRel ) {
1685         if ( h_data.myPhySizeRel )
1686           h->SetPhySizeRel( h_data.myPhySize );
1687         else
1688           h->SetPhySize( h_data.myPhySize );
1689       }
1690     }
1691     if (h->GetMinSize()   != h_data.myMinSize ||
1692         h->IsMinSizeRel() != h_data.myMinSizeRel ) {
1693       if ( h_data.myMinSizeRel )
1694         h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1695       else
1696         h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1697     }
1698     if (h->GetMaxSize()   != h_data.myMaxSize ||
1699         h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
1700       if ( h_data.myMaxSizeRel )
1701         h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1702       else
1703         h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1704     }
1705     if ( h->GetGradation() !=  h_data.myGradation )
1706       h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
1707     if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1708       h->SetQuadAllowed( h_data.myAllowQuadrangles );
1709     
1710     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
1711       if ( h->GetAngleMesh() != h_data.myAngleMesh )
1712         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
1713       if ( h->GetChordalError() != h_data.myChordalError )
1714         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
1715     }
1716     
1717     if ( h->GetAnisotropic() != h_data.myAnisotropic )
1718       h->SetAnisotropic( h_data.myAnisotropic );
1719     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
1720       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
1721     
1722     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
1723       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
1724     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
1725       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
1726     
1727     if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
1728       h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
1729     if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
1730       h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
1731     
1732     if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
1733       h->SetOptimizeMesh( h_data.myOptimizeMesh );    
1734     
1735     if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
1736       h->SetQuadraticMesh( h_data.myQuadraticMesh );    
1737
1738     if ( h->GetVerbosity() != h_data.myVerbosity )
1739       h->SetVerbosity( h_data.myVerbosity );
1740     if ( h->GetTopology() != h_data.myTopology )
1741       h->SetTopology( (int) h_data.myTopology );
1742     if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
1743       h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
1744     if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
1745       h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
1746     if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
1747       h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
1748
1749     h->SetOptionValues( myOptions ); // is set in checkParams()
1750     h->SetPreCADOptionValues( myPreCADOptions ); // is set in checkParams()
1751     
1752     if ( h->GetGMFFile() != h_data.myGMFFileName )
1753 //       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
1754 //       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
1755       h->SetGMFFile( h_data.myGMFFileName.c_str());
1756
1757     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1758     QMapIterator<QString,QString> i(that->mySMPMap);
1759     while (i.hasNext()) {
1760       i.next();
1761       const QString entry = i.key();
1762       const QString sizeMap = i.value();
1763
1764       if (sizeMap == "__TO_DELETE__") {
1765         MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1766         h->UnsetEntry(entry.toLatin1().constData());
1767       }
1768       else if (sizeMap.startsWith("ATTRACTOR")) {
1769 //         MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1770         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
1771       }
1772       else if (sizeMap.startsWith("def")) {
1773 //         MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1774 //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1775       }
1776       else {
1777         if (!myATTMap[entry].isEmpty()){
1778           QString att_entry = myATTMap[entry];
1779           double infDist = myAttDistMap[entry];
1780           double constDist = myDistMap[entry];
1781           double phySize = h->GetPhySize();
1782           QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1783           h->SetClassAttractorEntry( entry.toLatin1().constData(), att_entry.toLatin1().constData(), sizeMap.toDouble() , phySize, infDist, constDist ); 
1784           QApplication::restoreOverrideCursor();
1785         }
1786         else {
1787           QString fullSizeMap;
1788           fullSizeMap = QString("");
1789           if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
1790             fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1791           else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
1792             fullSizeMap = QString("def f(t): return ") + sizeMap;
1793           else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1794             fullSizeMap = QString("def f(): return ") + sizeMap;
1795           MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1796           h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1797         }
1798       }
1799     }
1800
1801     // Enforced vertices
1802     bool ret;
1803     double x, y, z = 0;
1804     std::string enfName;
1805     /* TODO GROUPS
1806     std::string groupName = "";
1807     */
1808
1809     TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
1810     // 1. Clear all enforced vertices in hypothesis
1811     // 2. Add new enforced vertex according to h_data
1812     
1813     if ( h->GetAllEnforcedVertices()->length() > 0 )
1814       h->ClearAllEnforcedVertices();
1815     TEnfName faceEntry;
1816     TEnfVertexList evs;
1817     TEnfVertexList::const_iterator evsIt;
1818     for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
1819     {
1820       faceEntry = evmIt->first;
1821       evs = evmIt->second;
1822       MESSAGE("Number of enforced vertices for face entry " << faceEntry << ": " << evs.size());
1823       evsIt = evs.begin();
1824       for ( ; evsIt != evs.end() ; ++evsIt)
1825       {
1826         x =y =z = 0;
1827         if ((*evsIt)->coords.size()) {
1828           x = (*evsIt)->coords[0];
1829           y = (*evsIt)->coords[1];
1830           z = (*evsIt)->coords[2];
1831         }
1832         ret = h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
1833       } // for
1834     } // for
1835
1836     if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
1837       h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
1838     if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
1839       h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
1840
1841   } // try
1842   catch(const std::exception& ex) {
1843     std::cout << "Exception: " << ex.what() << std::endl;
1844     throw ex;
1845   }
1846 //   catch(const SALOME::SALOME_Exception& ex)
1847 //   {
1848 //     throw ex;
1849 // //     SalomeApp_Tools::QtCatchCorbaException(ex);
1850 // //     ok = false;
1851 //   }
1852   return ok;
1853 }
1854
1855 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1856 Stores the widgets content to the hypothesis data.
1857 */
1858 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1859 {
1860   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1861   h_data.myName                  = myName ? myName->text() : "";
1862   h_data.myPhysicalMesh          = myStdWidget->myPhysicalMesh->currentIndex();
1863   h_data.myGeometricMesh         = myStdWidget->myGeometricMesh->currentIndex();
1864   h_data.myPhySize               = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
1865   h_data.myPhySizeRel            = myStdWidget->myPhySizeRel->isChecked();
1866   h_data.myMinSize               = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
1867   h_data.myMinSizeRel            = myStdWidget->myMinSizeRel->isChecked();
1868   h_data.myMaxSize               = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
1869   h_data.myMaxSizeRel            = myStdWidget->myMaxSizeRel->isChecked();
1870   h_data.myGradation             = myStdWidget->myGradation->text().isEmpty() ? -1.0 : myStdWidget->myGradation->GetValue();
1871   h_data.myAllowQuadrangles      = myStdWidget->myAllowQuadrangles->isChecked();
1872   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
1873   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
1874   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
1875   h_data.myAnisotropicRatio      = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
1876   h_data.myRemoveTinyEdges       = myStdWidget->myRemoveTinyEdges->isChecked();
1877   h_data.myTinyEdgeLength        = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
1878   h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
1879   h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
1880   h_data.myOptimizeMesh          = myStdWidget->myOptimizeMesh->isChecked();
1881   h_data.myQuadraticMesh         = myStdWidget->myQuadraticMesh->isChecked();
1882   h_data.myVerbosity             = myAdvWidget->myVerbosity->value();
1883   h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
1884   h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
1885   h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
1886   h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
1887
1888   QString guiHyp;
1889   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1890   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1891   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
1892   guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
1893   guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
1894   guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
1895   guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
1896   guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
1897   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1898   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1899   guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
1900   guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
1901   guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
1902   guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
1903   
1904   
1905   guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
1906   guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
1907   guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
1908   guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
1909   guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
1910   guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
1911   
1912   
1913   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1914   guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
1915   guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
1916   guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
1917
1918   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1919   int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
1920   for ( ; row < nbRows; ++row )
1921   {
1922     int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1923     std::string optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().toStdString();
1924     if ( id >= 0 && ( ( optionType == "BLSURF" && id < myOptions->length() ) || ( optionType == "PRECAD" && id < myPreCADOptions->length() ) ) )
1925     {
1926       QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1927       QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1928       if ( value.isNull() )
1929         value = "";
1930       if (optionType == "PRECAD")
1931         that->myPreCADOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1932       else
1933         that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1934
1935       if ( value != "" ) {
1936         if (optionType == "PRECAD")
1937           guiHyp += "PRECAD_";
1938         guiHyp += name + " = " + value + "; ";
1939       }
1940     }
1941   }
1942   
1943   h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
1944 //   h_data.myGMFFileMode = myGMFFileMode->isChecked();
1945
1946   // SizeMap
1947   row = 0, nbRows = mySizeMapTable->topLevelItemCount();
1948   for ( ; row < nbRows; ++row )
1949   {
1950       QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
1951       if ( that->mySMPMap.contains(entry) )
1952         guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1953   }
1954
1955   // Enforced vertices
1956   h_data.enfVertexList.clear();
1957   h_data.faceEntryEnfVertexListMap.clear();
1958
1959   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1960   int nbEnforcedVertices = 0;
1961   std::string groupName = "";
1962 //   MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1963   for (int i=0 ; i<nbEnforcedShapes ; i++) {
1964     QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1965     if (shapeItem) {
1966       std::string faceEntry = shapeItem->data(ENF_VER_FACE_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1967       nbEnforcedVertices = shapeItem->childCount();
1968       if (nbEnforcedVertices >0) {
1969         double childValueX,childValueY,childValueZ;
1970         std::string childName, vertexEntry;
1971         QTreeWidgetItem* child;
1972         TEnfVertexList evs;
1973         evs.clear();
1974         for (row = 0;row<nbEnforcedVertices;row++) {
1975           child = shapeItem->child(row);
1976           childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
1977           childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1978           childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1979           childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1980           vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1981 //           if (myGlobalGroupName->isChecked())
1982 //             groupName = myGlobalGroupName->text().toStdString();
1983 //           else
1984             groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
1985
1986           TEnfVertex *enfVertex = new TEnfVertex();
1987           enfVertex->name = childName;
1988           if (vertexEntry.empty()) {
1989             enfVertex->coords.push_back(childValueX);
1990             enfVertex->coords.push_back(childValueY);
1991             enfVertex->coords.push_back(childValueZ);
1992           }
1993           else
1994             enfVertex->geomEntry = vertexEntry;
1995           enfVertex->grpName = groupName;
1996 //           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
1997 //           if (it == h_data.enfVertexList.end())
1998           h_data.enfVertexList.insert(enfVertex);
1999           evs.insert(enfVertex);
2000           /* TODO GROUPS
2001           if (groupName != "")
2002             h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2003           */
2004         }
2005         h_data.faceEntryEnfVertexListMap[faceEntry] = evs;
2006       }
2007     }
2008   }
2009
2010   h_data.myInternalEnforcedVerticesAllFaces      = myInternalEnforcedVerticesAllFaces->isChecked();
2011   h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2012
2013   MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
2014   return guiHyp;
2015 }
2016
2017 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2018 {
2019   QMenu* menu = (QMenu*)sender();
2020   // fill popup with option names
2021   menu->clear();
2022   QString name_value, name;
2023   if ( myOptions.operator->() ) {
2024     QMenu* blsurfMenu = menu->addMenu(tr("OPTION_MENU_BLSURF"));
2025     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
2026       name_value = myOptions[i].in();
2027       name = name_value.split( ":", QString::KeepEmptyParts )[0];
2028       blsurfMenu->addAction( name );
2029     }
2030   }
2031   if ( myPreCADOptions.operator->() ) {
2032     QMenu* preCADmenu = menu->addMenu(tr("OPTION_MENU_PRECAD"));
2033     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
2034       name_value = myPreCADOptions[i].in();
2035       name = name_value.split( ":", QString::KeepEmptyParts )[0];
2036       preCADmenu->addAction( name );
2037     }
2038   }
2039 }
2040
2041 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
2042 {
2043   myAdvWidget->myOptionTable->setFocus();
2044   QMenu* menu = (QMenu*)( a->parent() );
2045
2046   int idx = menu->actions().indexOf( a );
2047   QString idStr = QString("%1").arg( idx );
2048   QString option, optionType;
2049   if (menu->title() == tr("OPTION_MENU_BLSURF")) {
2050     option = myOptions[idx].in();
2051     optionType = "BLSURF";
2052   }
2053   else if (menu->title() == tr("OPTION_MENU_PRECAD")) {
2054     option = myPreCADOptions[idx].in();
2055     optionType = "PRECAD";
2056   }
2057   QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
2058
2059   // look for a row with optionName
2060   int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
2061   for ( ; row < nbRows; ++row )
2062     if ( myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
2063       if ( myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text() == optionType )
2064         break;
2065   // add a row if not found
2066   if ( row == nbRows ) {
2067     myAdvWidget->myOptionTable->setRowCount( row+1 );
2068     myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
2069     myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
2070     myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( optionType ) );
2071     myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
2072     myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
2073     myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
2074     myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
2075     myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
2076                                                                             Qt::ItemIsEditable   |
2077                                                                             Qt::ItemIsEnabled );
2078     myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2079   }
2080   myAdvWidget->myOptionTable->clearSelection();
2081   myAdvWidget->myOptionTable->scrollToItem( myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2082   //myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
2083   myAdvWidget->myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
2084   //myAdvWidget->myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2085 }
2086
2087 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
2088 {
2089   // clear option values and remember selected row
2090   QList<int> selectedRows;
2091   QList<QTableWidgetItem*> selected = myAdvWidget->myOptionTable->selectedItems();
2092   QTableWidgetItem* item;
2093   foreach( item, selected ) {
2094     int row = item->row();
2095     if ( !selectedRows.contains( row ) ) {
2096       selectedRows.append( row );
2097       int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
2098       QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text();
2099       if ( id >= 0 )
2100         if (optionType == "BLSURF" && id < myOptions->length() )
2101           myOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2102         else if (optionType == "PRECAD" && id < myPreCADOptions->length() )
2103           myPreCADOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2104     }
2105   }
2106   qSort( selectedRows );
2107   QListIterator<int> it( selectedRows );
2108   it.toBack();
2109   while ( it.hasPrevious() )
2110     myAdvWidget->myOptionTable->removeRow( it.previous() );
2111 }
2112
2113 // **********************
2114 // *** BEGIN SIZE MAP ***
2115 // **********************
2116
2117 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2118 {
2119   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2120   
2121   if ( myGeomSelWdg2->IsObjectSelected() ){ 
2122     mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2123   }
2124   else if ( myGeomSelWdg1->IsObjectSelected() ){
2125     mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2126   }
2127   std::string entry = (string) mySMapObject->GetStudyEntry();
2128   QString qEntry = QString::fromStdString(entry);
2129   if (that->mySMPMap.contains(qEntry) && that->mySMPMap[qEntry] != "__TO_DELETE__" ) {  
2130     addMapButton->setEnabled(false);
2131     modifyMapButton->setEnabled(true);
2132   }
2133   else{
2134     addMapButton->setEnabled(true);
2135     modifyMapButton->setEnabled(false);
2136   }
2137       
2138
2139
2140 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2141
2142   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked("<<col<<")")
2143   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2144   if (col == SMP_SIZEMAP_COLUMN){
2145     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2146     if (!mySMPMap.contains(entry))
2147       return;
2148     QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2149     CORBA::Object_var obj = entryToObject(entry); 
2150     if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")){  // ADVANCED MAPS
2151       smpTab->setCurrentIndex(ATT_TAB);         // Change Tab
2152       double phySize = that->mySMPMap[entry].toDouble();  // Retrieve values of the selected item in the current tab widgets
2153       double infDist = that->myAttDistMap[entry];
2154       double constDist = that->myDistMap[entry];
2155       QString attEntry = that->myATTMap[entry];
2156       CORBA::Object_var attObj = entryToObject(attEntry);
2157       myAttSizeSpin->setValue(phySize);
2158       if (sizeMap.startsWith("Attractor")){     
2159         myAttDistSpin->setValue(infDist);
2160         myAttractorCheck->setChecked(true);
2161       }
2162       else {
2163         myAttractorCheck->setChecked(false);
2164       }
2165       if (sizeMap.startsWith("Constant") || constDist > std::numeric_limits<double>::epsilon()){
2166         myAttDistSpin2->setValue(constDist);
2167         myConstSizeCheck->setChecked(true);
2168       }
2169       else{
2170         myConstSizeCheck->setChecked(false);
2171       }
2172       myGeomSelWdg2->SetObject(obj); 
2173       myAttSelWdg->SetObject(attObj);
2174     }
2175     else {                                                                   // CLASSIC MAPS
2176       smpTab->setCurrentIndex(SMP_STD_TAB);  // Change Tab
2177       myGeomSelWdg1->SetObject(obj);         // Retrieve values of the selected item in the current tab widgets
2178       if (!sizeMap.startsWith("def")){
2179         mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble()); 
2180       }
2181     }  
2182   } 
2183 }
2184
2185 void BLSURFPluginGUI_HypothesisCreator::onSmpTabChanged(int tab)
2186 {
2187   myAttDistSpin->setValue(0.);           // Reinitialize widgets 
2188   myAttSizeSpin->setValue(0.);
2189   myAttDistSpin2->setValue(0.);
2190   mySmpSizeSpin->setValue(0.); 
2191   myGeomSelWdg1->deactivateSelection();
2192   myGeomSelWdg2->deactivateSelection();
2193   myAttSelWdg->deactivateSelection();
2194   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2195   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2196   myAttSelWdg->SetObject(CORBA::Object::_nil());
2197   myAttractorCheck->setChecked(false);
2198   myConstSizeCheck->setChecked(false);
2199 }
2200
2201 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2202 {
2203   if (state == Qt::Checked){
2204     myAttSelWdg->setEnabled(true);
2205     myAttSizeSpin->setEnabled(true);
2206     myAttSizeLabel->setEnabled(true);
2207     myAttDistSpin->setEnabled(true);
2208     myAttDistLabel->setEnabled(true);
2209     if (!myAttSelWdg->IsObjectSelected()){
2210       myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2211     }
2212   }
2213   if (state == Qt::Unchecked){
2214     myAttDistSpin->setEnabled(false);
2215     myAttDistLabel->setEnabled(false);
2216     myAttDistSpin->setValue(0.);
2217     if(myConstSizeCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2218       myAttSelWdg->setEnabled(false);
2219       myAttSizeSpin->setEnabled(false);
2220       myAttSizeLabel->setEnabled(false);
2221       myAttDistSpin2->setEnabled(false);
2222       myAttDistLabel2->setEnabled(false);
2223     }
2224     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2225       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2226     }
2227   }   
2228 }
2229
2230 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2231
2232   if (state == Qt::Checked){
2233     myAttSelWdg->setEnabled(true);
2234     myAttSizeSpin->setEnabled(true);
2235     myAttSizeLabel->setEnabled(true);
2236     myAttDistSpin2->setEnabled(true);
2237     myAttDistLabel2->setEnabled(true);
2238     if (myAttractorCheck->checkState() == Qt::Unchecked &&
2239         !myAttSelWdg->IsObjectSelected()){
2240       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2241     }
2242   }
2243   if (state == Qt::Unchecked){
2244     myAttDistSpin2->setEnabled(false);
2245     myAttDistLabel2->setEnabled(false);
2246     myAttDistSpin2->setValue(0.);
2247     if(myAttractorCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2248         myAttSelWdg->setEnabled(false);
2249         myAttSizeSpin->setEnabled(false);
2250         myAttSizeLabel->setEnabled(false);
2251         myAttDistSpin->setEnabled(false);
2252         myAttDistLabel->setEnabled(false);
2253     }
2254     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2255     myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2256     }
2257   }   
2258 }
2259
2260 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
2261 {
2262   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
2263   QList<int> selectedRows;
2264   QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
2265   QTreeWidgetItem* item;
2266   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2267
2268   qSort( selectedRows );
2269   QListIterator<QTreeWidgetItem*> it( selected );
2270   it.toBack();
2271   while ( it.hasPrevious() ) {
2272       item = it.previous();
2273       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2274       if (that->mySMPMap.contains(entry))
2275         that->mySMPMap[entry] = "__TO_DELETE__";
2276       if (that->mySMPShapeTypeMap.contains(entry))
2277         that->mySMPShapeTypeMap.remove(entry);
2278       if (that->myATTMap.contains(entry))
2279         that->myATTMap.remove(entry);
2280       if (that->myDistMap.contains(entry))
2281         that->myDistMap.remove(entry);
2282       if (that->myAttDistMap.contains(entry))
2283         that->myAttDistMap.remove(entry);
2284       delete item;
2285   }
2286   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
2287   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2288 }
2289
2290 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
2291 {
2292   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< col << ")");
2293   MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2294   if (col == SMP_SIZEMAP_COLUMN) {
2295     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2296     QString entry   = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2297     QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
2298     MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
2299     if (! that->mySMPShapeTypeMap.contains(entry))
2300       MESSAGE("no such entry in mySMPShapeTypeMap")
2301       return;
2302     if (that->mySMPMap.contains(entry))
2303       if (that->mySMPMap[entry] == sizeMap 
2304         || sizeMap.startsWith("Attractor") 
2305         || sizeMap.startsWith("Constant") ){
2306         return;
2307       } 
2308     if (! sizeMap.isEmpty()) {
2309       that->mySMPMap[entry] = sizeMap;
2310       sizeMapValidationFromEntry(entry); 
2311     }
2312     else {
2313       MESSAGE("Size map empty: reverse to precedent value" );
2314       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
2315     }
2316     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2317   }
2318 }
2319
2320 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
2321 {
2322   if ( smpTab->currentIndex() == ATT_TAB ){    
2323     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
2324       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2325       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2326       insertAttractor(mySMapObject, myAttObject);
2327     }
2328   }
2329   if (smpTab->currentIndex() == SMP_STD_TAB  ){
2330     if ( myGeomSelWdg1->IsObjectSelected() ){
2331       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2332       insertElement(mySMapObject);  
2333     }  
2334   }
2335   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;  
2336   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2337   myAttDistSpin->setValue(0.);
2338   myAttSizeSpin->setValue(0.);
2339   myAttDistSpin2->setValue(0.);
2340   mySmpSizeSpin->setValue(0.);
2341   myConstSizeCheck->setChecked(false);
2342   myAttractorCheck->setChecked(false);
2343   myGeomSelWdg1->deactivateSelection();
2344   myGeomSelWdg2->deactivateSelection();
2345   myAttSelWdg->deactivateSelection();
2346   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2347   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2348   myAttSelWdg->SetObject(CORBA::Object::_nil());
2349 }
2350
2351 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
2352 {
2353   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onModifyMap()");
2354   if ( smpTab->currentIndex() == ATT_TAB ){    
2355     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
2356       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2357       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2358       insertAttractor(mySMapObject, myAttObject, /*modify = */true);
2359     }
2360   }
2361   if (smpTab->currentIndex() == SMP_STD_TAB  ){
2362     if ( myGeomSelWdg1->IsObjectSelected() ){
2363       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2364       insertElement(mySMapObject, /*modify = */true);  
2365     }  
2366   }
2367   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;  
2368   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2369   myAttDistSpin->setValue(0.);
2370   myAttSizeSpin->setValue(0.);
2371   myAttDistSpin2->setValue(0.);
2372   mySmpSizeSpin->setValue(0.);
2373   myConstSizeCheck->setChecked(false);
2374   myAttractorCheck->setChecked(false);
2375   myGeomSelWdg1->deactivateSelection();
2376   myGeomSelWdg2->deactivateSelection();
2377   myAttSelWdg->deactivateSelection();
2378   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2379   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2380   myAttSelWdg->SetObject(CORBA::Object::_nil());
2381 }
2382
2383 void BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
2384 {
2385   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElement()");
2386   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2387     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2388
2389   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2390
2391   TopAbs_ShapeEnum shapeType;
2392   string entry, shapeName;
2393   entry = (string) anObject->GetStudyEntry();
2394   MESSAGE("entry = "<<entry);
2395   shapeName = anObject->GetName();
2396   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
2397   // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
2398   // in order to write the size map with the right syntax in StoreParamsToHypo 
2399   // (f(t) for edges, f(u,v) for faces ...)
2400   if (shapeType == TopAbs_COMPOUND){
2401     TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
2402     TopoDS_Shape childShape;
2403     TopoDS_Iterator anIt(theShape);
2404     for(;anIt.More();anIt.Next()){
2405       childShape = anIt.Value();
2406       shapeType = childShape.ShapeType();
2407       if(!childShape.IsNull()){
2408         break;
2409       }
2410     }
2411   }
2412   mySizeMapTable->setFocus();
2413   QString shapeEntry;
2414   shapeEntry = QString::fromStdString(entry);
2415   double phySize = mySmpSizeSpin->value();
2416   std::ostringstream oss;
2417   oss << phySize;
2418   QString sizeMap;
2419   sizeMap  = QString::fromStdString(oss.str());
2420   QTreeWidgetItem* item = new QTreeWidgetItem();
2421   if (modify){
2422     int rowToChange = findRowFromEntry(shapeEntry);
2423     item = mySizeMapTable->topLevelItem( rowToChange );
2424   }
2425   else{
2426     if (that->mySMPMap.contains(shapeEntry)) {  
2427       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2428   //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2429         return;
2430       }
2431     }
2432     mySizeMapTable->addTopLevelItem(item);
2433   }
2434   that->mySMPMap[shapeEntry] = sizeMap;
2435   that->myDistMap[shapeEntry] = 0. ;
2436   that->mySMPShapeTypeMap[shapeEntry] = shapeType;
2437   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
2438   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2439   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
2440   item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2441   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2442   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2443   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2444   mySizeMapTable->clearSelection();
2445
2446   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2447     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2448     myStdWidget->onPhysicalMeshChanged();
2449   }
2450 }
2451
2452 void BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
2453 {
2454   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertAttractor()");
2455   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2456     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2457
2458   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2459
2460   TopAbs_ShapeEnum shapeType;
2461   string entry, attEntry, faceName, attName;
2462   entry = (string) aFace->GetStudyEntry();
2463   attEntry = (string) anAttractor->GetStudyEntry();
2464   faceName = aFace->GetName();
2465   attName = anAttractor->GetName();
2466   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
2467   mySizeMapTable->setFocus();
2468   QString shapeEntry = QString::fromStdString(entry);
2469   QString qAttEntry = QString::fromStdString(attEntry);
2470   
2471   double phySize = h->GetPhySize();
2472   double infDist = 0. ;
2473   double constDist = 0. ;
2474   phySize = myAttSizeSpin->value();
2475   if (myAttractorCheck->isChecked()){
2476     infDist = myAttDistSpin->value();
2477   }
2478   if (myConstSizeCheck->isChecked()){
2479     constDist = myAttDistSpin2->value();
2480   } 
2481   std::ostringstream oss;
2482   std::ostringstream oss2;
2483   std::ostringstream oss3;
2484   oss << phySize;
2485   oss2 << infDist;
2486   oss3 << constDist;
2487   QString sizeMap  = QString::fromStdString(oss.str());
2488   QString infDistString = QString::fromStdString(oss2.str());
2489   QString constDistString = QString::fromStdString(oss3.str());
2490   
2491   QTreeWidgetItem* item; 
2492   QTreeWidgetItem* child; 
2493   if (modify){
2494     int rowToChange = findRowFromEntry(shapeEntry);
2495     item = mySizeMapTable->topLevelItem( rowToChange );
2496     child = item->child( 0 );
2497   }
2498   else{
2499     if (that->mySMPMap.contains(shapeEntry)) {  
2500       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2501     //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2502         return;
2503       }
2504     }
2505     item = new QTreeWidgetItem();
2506     child = new QTreeWidgetItem();
2507     mySizeMapTable->addTopLevelItem(item);
2508     item->addChild(child);
2509   }
2510   that->mySMPMap.insert(shapeEntry,sizeMap);
2511   that->myATTMap.insert(shapeEntry,qAttEntry);
2512   that->myAttDistMap.insert(shapeEntry,infDist);
2513   that->myDistMap.insert(shapeEntry,constDist);
2514   that->mySMPShapeTypeMap.insert(shapeEntry,shapeType);
2515   item->setExpanded(true); 
2516   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2517   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
2518   if (infDist > std::numeric_limits<double>::epsilon()){
2519     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
2520   }
2521   else if (constDist > std::numeric_limits<double>::epsilon()){
2522     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
2523   }
2524   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );    
2525   
2526   child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
2527   child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
2528   child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2529   
2530   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2531   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2532   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2533
2534   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2535     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2536     myStdWidget->onPhysicalMeshChanged();
2537   }
2538   MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2539 }
2540
2541 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
2542 {
2543   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
2544   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2545   for ( ; row < nbRows; ++row )
2546     if (! sizeMapValidationFromRow(row))
2547       return false;
2548   return true;
2549 }
2550
2551 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
2552 {
2553   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(), row = "<<myRow);
2554   QString myEntry   = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2555   bool res = sizeMapValidationFromEntry(myEntry,displayError);
2556   mySizeMapTable->setFocus();
2557   return res;
2558 }
2559
2560 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
2561 {
2562   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
2563   MESSAGE("myEntry = "<<myEntry.toStdString())
2564
2565   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2566
2567   if (! that->mySMPMap.contains(myEntry)) {
2568 //     MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
2569     return false;
2570   }
2571   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
2572 //     MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
2573     return false;
2574   }
2575
2576   string expr;
2577
2578   if (that->mySMPMap[myEntry].startsWith("def")) {
2579 //     MESSAGE("custom function" );
2580     expr = that->mySMPMap[myEntry].toStdString();
2581   }
2582   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
2583 //     MESSAGE("Attractor" );
2584     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)) {
2585
2586       if (displayError)
2587         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])" );
2588       return false;
2589     }
2590     return true;
2591   }
2592   else {
2593     // case size map is empty
2594     if (that->mySMPMap[myEntry].isEmpty()) {
2595       if (displayError)
2596         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
2597       return false;
2598     }
2599     else {
2600       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
2601         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
2602       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
2603         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
2604       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
2605         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
2606     }
2607   }
2608   //assert(Py_IsInitialized());
2609   if (! Py_IsInitialized())
2610     throw ("Erreur: Python interpreter is not initialized");
2611   PyGILState_STATE gstate;
2612   gstate = PyGILState_Ensure();
2613
2614   PyObject * obj = NULL;
2615   PyObject* new_stderr = NULL;
2616   string  err_description="";
2617   obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
2618   if (obj == NULL){
2619     fflush(stderr);
2620     err_description="";
2621     new_stderr=newPyStdOut(err_description);
2622     PySys_SetObject((char*)"stderr", new_stderr);
2623     PyErr_Print();
2624     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2625     Py_DECREF(new_stderr);
2626     if (displayError)
2627       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
2628     PyGILState_Release(gstate);
2629     return false;
2630   }
2631   Py_DECREF(obj);
2632
2633   PyObject * func = NULL;
2634   func = PyObject_GetAttrString(main_mod, "f");
2635   if ( func == NULL){
2636     fflush(stderr);
2637     err_description="";
2638     new_stderr=newPyStdOut(err_description);
2639     PySys_SetObject((char*)"stderr", new_stderr);
2640     PyErr_Print();
2641     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2642     Py_DECREF(new_stderr);
2643     if (displayError)
2644       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
2645     PyGILState_Release(gstate);
2646     return false;
2647   }
2648
2649   PyGILState_Release(gstate);
2650
2651 //   MESSAGE("SizeMap expression "<<expr<<" is valid");
2652
2653   return true;
2654 }
2655
2656 QString BLSURFPluginGUI_HypothesisCreator::caption() const
2657 {
2658   return tr( "BLSURF_TITLE" );
2659 }
2660
2661 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
2662 {
2663   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
2664 }
2665
2666 QString BLSURFPluginGUI_HypothesisCreator::type() const
2667 {
2668   return tr( "BLSURF_HYPOTHESIS" );
2669 }
2670
2671 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
2672 {
2673   return "blsurf_hypo_page.html";
2674 }
2675
2676 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
2677 {
2678
2679   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2680   if( anApp )
2681     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2682   else
2683     return 0;
2684 }
2685
2686 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
2687 {
2688   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
2689   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
2690   CORBA::Object_var obj;
2691   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
2692   if (!aSObj->_is_nil()) {
2693     obj = aSObj->GetObject();
2694     aSObj->UnRegister();
2695   }
2696   return obj;
2697 }
2698
2699 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
2700   QString entryForChecking;
2701   int endRow = mySizeMapTable->topLevelItemCount()-1;
2702   int row = 0;
2703   entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2704   while (entry != entryForChecking && row <= endRow){
2705     row++;
2706     entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2707   }
2708   MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)
2709   return row;
2710 }
2711
2712