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