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