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