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