Salome HOME
1a3758e10eae12277298fa7c49706c8c81d7476f
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File    : BLSURFPluginGUI_HypothesisCreator.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #include "BLSURFPluginGUI_HypothesisCreator.h"
28 // #include <DlgBlSurfHyp_Enforced.h>
29
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_Dialog.h>
33 #include "SMESHGUI_SpinBox.h"
34
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SalomeApp_Tools.h>
39
40 #include <QComboBox>
41 #include <QLabel>
42 #include <QGroupBox>
43 #include <QFrame>
44 #include <QVBoxLayout>
45 #include <QHBoxLayout>
46 #include <QGridLayout>
47 #include <QLineEdit>
48 #include <QCheckBox>
49 #include <QTabWidget>
50 #include <QSpinBox>
51 #include <QPushButton>
52 #include <QMenu>
53 #include <QTableWidget>
54 #include <QHeaderView>
55 #include <QApplication>
56 #include <QRadioButton>
57
58 #include <QStandardItemModel>
59 #include <QStandardItem>
60 #include <QTreeWidget>
61 #include <QTreeWidgetItem>
62 #include <QModelIndexList>
63
64 #include <LightApp_SelectionMgr.h>
65 #include <SalomeApp_Application.h>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_ListIteratorOfListIO.hxx>
68
69 #include <GEOM_Client.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <SMESH_Gen_i.hxx>
72 #include <boost/shared_ptr.hpp>
73 #include <boost/algorithm/string.hpp>
74 #include <structmember.h>
75
76 #define WITH_SIZE_BOUNDARIES
77
78 enum Topology {
79     FromCAD,
80     Process,
81     Process2
82   } ;
83
84 enum PhysicalMesh
85   {
86     DefaultSize = 0,
87     PhysicalUserDefined,
88     SizeMap
89   };
90
91 enum GeometricMesh
92   {
93     DefaultGeom = 0,
94     UserDefined
95   };
96
97 enum {
98   STD_TAB = 0,
99   ADV_TAB,
100   SMP_TAB,
101   ENF_TAB,
102   OPTION_ID_COLUMN = 0,
103   OPTION_NAME_COLUMN,
104   OPTION_VALUE_COLUMN,
105   NB_COLUMNS,
106   SMP_ENTRY_COLUMN = 0,
107   SMP_NAME_COLUMN,
108   SMP_SIZEMAP_COLUMN,
109   SMP_NB_COLUMNS,
110 // Enforced vertices array columns
111   ENF_VER_NAME_COLUMN = 0,
112   ENF_VER_ENTRY_COLUMN,
113   ENF_VER_X_COLUMN,
114   ENF_VER_Y_COLUMN,
115   ENF_VER_Z_COLUMN,
116 //   ENF_VER_GROUP_COLUMN,
117   ENF_VER_NB_COLUMNS
118 };
119
120 enum {
121   SMP_BTNS = 0,
122 //   SMP_ATTRACTOR_BTN,
123 //   SMP_SEPARATOR1,
124   SMP_POINT_BTN,
125   SMP_EDGE_BTN,
126   SMP_SURFACE_BTN,
127   SMP_SEPARATOR2,
128   SMP_REMOVE_BTN,
129   SMP_NB_LINES
130 };
131
132 // Enforced vertices inputs
133 enum {
134 //   ENF_VER_FACE = 0,
135 //   ENF_VER_VERTEX,
136   ENF_VER_X_COORD = 0,
137   ENF_VER_Y_COORD,
138   ENF_VER_Z_COORD,
139 //   ENF_VER_GROUP,
140   ENF_VER_VERTEX_BTN,
141   ENF_VER_REMOVE_BTN,
142 //   ENF_VER_SEPARATOR,
143 //   ENF_VER_GROUP_CHECK,
144   ENF_VER_NB_LINES
145 };
146
147
148 /**************************************************
149  Begin initialization Python structures and objects
150 ***************************************************/
151
152 typedef struct {
153   PyObject_HEAD
154   int softspace;
155   std::string *out;
156   } PyStdOut;
157
158 static void
159 PyStdOut_dealloc(PyStdOut *self)
160 {
161   PyObject_Del(self);
162 }
163
164 static PyObject *
165 PyStdOut_write(PyStdOut *self, PyObject *args)
166 {
167   char *c;
168   int l;
169   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
170     return NULL;
171
172   //std::cerr << c ;
173   *(self->out)=*(self->out)+c;
174
175   Py_INCREF(Py_None);
176   return Py_None;
177 }
178
179 static PyMethodDef PyStdOut_methods[] = {
180   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
181     PyDoc_STR("write(string) -> None")},
182   {NULL,    NULL}   /* sentinel */
183 };
184
185 static PyMemberDef PyStdOut_memberlist[] = {
186   {"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
187    "flag indicating that a space needs to be printed; used by print"},
188   {NULL} /* Sentinel */
189 };
190
191 static PyTypeObject PyStdOut_Type = {
192   /* The ob_type field must be initialized in the module init function
193    * to be portable to Windows without using C++. */
194   PyObject_HEAD_INIT(NULL)
195   0,                            /*ob_size*/
196   "PyOut",                      /*tp_name*/
197   sizeof(PyStdOut),             /*tp_basicsize*/
198   0,                            /*tp_itemsize*/
199   /* methods */
200   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
201   0,                            /*tp_print*/
202   0,                            /*tp_getattr*/
203   0,                            /*tp_setattr*/
204   0,                            /*tp_compare*/
205   0,                            /*tp_repr*/
206   0,                            /*tp_as_number*/
207   0,                            /*tp_as_sequence*/
208   0,                            /*tp_as_mapping*/
209   0,                            /*tp_hash*/
210   0,                            /*tp_call*/
211   0,                            /*tp_str*/
212   PyObject_GenericGetAttr,      /*tp_getattro*/
213   /* softspace is writable:  we must supply tp_setattro */
214   PyObject_GenericSetAttr,      /* tp_setattro */
215   0,                            /*tp_as_buffer*/
216   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
217   0,                            /*tp_doc*/
218   0,                            /*tp_traverse*/
219   0,                            /*tp_clear*/
220   0,                            /*tp_richcompare*/
221   0,                            /*tp_weaklistoffset*/
222   0,                            /*tp_iter*/
223   0,                            /*tp_iternext*/
224   PyStdOut_methods,             /*tp_methods*/
225   PyStdOut_memberlist,          /*tp_members*/
226   0,                            /*tp_getset*/
227   0,                            /*tp_base*/
228   0,                            /*tp_dict*/
229   0,                            /*tp_descr_get*/
230   0,                            /*tp_descr_set*/
231   0,                            /*tp_dictoffset*/
232   0,                            /*tp_init*/
233   0,                            /*tp_alloc*/
234   0,                            /*tp_new*/
235   0,                            /*tp_free*/
236   0,                            /*tp_is_gc*/
237 };
238
239 PyObject * newPyStdOut( std::string& out )
240 {
241   PyStdOut *self;
242   self = PyObject_New(PyStdOut, &PyStdOut_Type);
243   if (self == NULL)
244     return NULL;
245   self->softspace = 0;
246   self->out=&out;
247   return (PyObject*)self;
248 }
249
250 /*************************************************
251 End initialization Python structures and objects
252 **************************************************/
253
254
255 class QDoubleValidator;
256
257 //
258 // BEGIN EnforcedTreeWidgetDelegate
259 //
260
261 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
262   : QItemDelegate(parent)
263 {
264 }
265
266 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
267                                               const QStyleOptionViewItem & option ,
268                                               const QModelIndex & index ) const
269 {
270 //   QLineEdit *editor = new QLineEdit(parent);
271   if (index.column() == ENF_VER_X_COLUMN || \
272     index.column() == ENF_VER_Y_COLUMN || \
273     index.column() == ENF_VER_Z_COLUMN)
274   {
275     SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
276     editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277     return editor;
278   }
279 //     editor->setValidator(new QDoubleValidator(parent));
280   else
281   {
282     QLineEdit *editor = new QLineEdit(parent);
283     return editor;
284   }
285
286 //   return editor;
287 }
288
289 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
290                                            const QModelIndex &index) const
291 {
292   QString value = index.model()->data(index, Qt::EditRole).toString();
293   if (index.column() == ENF_VER_X_COLUMN || \
294     index.column() == ENF_VER_Y_COLUMN || \
295     index.column() == ENF_VER_Z_COLUMN) {
296     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
297     lineEdit->setText(value);
298 //     lineEdit->editor()->setText(value);
299   }
300   else {
301     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
302     lineEdit->setText(value);
303   }
304 }
305
306 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
307                                           const QModelIndex &index) const
308 {
309 //   QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
310
311   if (index.column() == ENF_VER_X_COLUMN || \
312     index.column() == ENF_VER_Y_COLUMN || \
313     index.column() == ENF_VER_Z_COLUMN)
314   {
315     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
316     if (! vertexExists(model, index, lineEdit->GetString())) {
317       model->setData(index, lineEdit->GetValue(), Qt::EditRole);
318     }
319   }
320   else if (index.column() == ENF_VER_NAME_COLUMN) {
321     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
322     QString value = lineEdit->text();
323     if (! vertexExists(model, index, value)) {
324       model->setData(index, value, Qt::EditRole);
325     }
326 //     MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")");
327   }
328   /* TODO GROUPS
329   else if (index.column() == ENF_VER_GROUP_COLUMN) {
330     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
331     model->setData(index, lineEdit->text(), Qt::EditRole);
332 //     MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")");
333   }
334   */
335 }
336
337 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
338     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
339 {
340   editor->setGeometry(option.rect);
341 }
342
343 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
344     const QModelIndex &index, QString value) const
345 {
346   bool exists = false;
347   QModelIndex parent = index.parent();
348   int row = index.row();
349   int col = index.column();
350   
351   if (parent.isValid()) {
352     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
353       double x, y, z;
354       if (col == ENF_VER_X_COLUMN) {
355         x = value.toDouble();
356         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
357         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
358       }
359       if (col == ENF_VER_Y_COLUMN) {
360         y = value.toDouble();
361         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
362         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
363       }
364       if (col == ENF_VER_Z_COLUMN) {
365         z = value.toDouble();
366         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
367         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
368       }
369       // MESSAGE("Checking for existing vertex " << x << ", " << y << "," << z);
370       int nbChildren = model->rowCount(parent);
371       for (int i = 0 ; i < nbChildren ; i++) {
372         if (i != row) {
373           double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
374           double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
375           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
376 //           MESSAGE("Vertex: " << childX << ", " << childY << "," << childZ);
377           if ((childX == x) && (childY == y) && (childZ == z)) {
378 //             MESSAGE("Found !");
379             exists = true;
380             break;
381           }
382         }
383       }
384     }
385     else if (index.column() == ENF_VER_NAME_COLUMN) {
386       int nbChildren = model->rowCount(parent);
387       for (int i = 0 ; i < nbChildren ; i++) {
388         if (i != row) {
389           QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
390           if (childName == value) {
391             exists = true;
392             break;
393           }
394         }
395       }
396     }
397   }
398
399   return exists;
400 }
401
402 //
403 // END EnforcedTreeWidgetDelegate
404 //
405
406
407 /**
408  * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
409  * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
410  *
411  * */
412 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
413   : SMESHGUI_GenericHypothesisCreator( theHypType )
414 {
415   MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
416   this->mySMPMap.clear();
417
418   GeomToolSelected = NULL;
419   GeomToolSelected = getGeomSelectionTool();
420
421   aSel = GeomToolSelected->selectionMgr();
422
423   /* Initialize the Python interpreter */
424   if (! Py_IsInitialized())
425     throw ("Error: Python interpreter is not initialized");
426   PyGILState_STATE gstate;
427   gstate = PyGILState_Ensure();
428
429   main_mod = NULL;
430   main_mod = PyImport_AddModule("__main__");
431
432   main_dict = NULL;
433   main_dict = PyModule_GetDict(main_mod);
434
435   PyRun_SimpleString("from math import *");
436   PyGILState_Release(gstate);
437   
438 }
439
440 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
441 {
442 }
443
444 /**
445  * \brief {Get or create the geom selection tool for active study}
446  * */
447 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
448 {
449 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool");
450   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
451   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
452 //   MESSAGE("aStudy->StudyId(): " << aStudy->StudyId());
453   if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
454 //     MESSAGE("GeomToolSelected is created");
455     that->GeomToolSelected = new GeomSelectionTools(aStudy);
456   }
457 //   else
458 //     MESSAGE("GeomToolSelected already exists");
459 //   MESSAGE("that->GeomToolSelected->getMyStudy()->StudyId(): " << that->GeomToolSelected->getMyStudy()->StudyId());
460   return that->GeomToolSelected;
461 }
462
463 namespace {
464   inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
465     QString str = theText.trimmed();
466     bool isOk = true;
467     if ( !str.isEmpty() )
468       str.toDouble(&isOk);
469     else
470       isOk = emptyOK;
471     return isOk;
472   }
473 }
474
475
476 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
477 {
478   MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
479   bool ok = true;
480 //   if ( !isDouble( myPhySize->text(), false )) {
481 //     if ( myPhySize->text().isEmpty() )
482 //       myPhySize->setText(tr("OBLIGATORY_VALUE"));
483 //     myPhySize->selectAll();
484 //     ok = false;
485 //   }
486 //   if ( !isDouble( myPhyMin->text(), true )) {
487 //     myPhyMin->selectAll();
488 //     ok = false;
489 //   }
490 //   if ( !isDouble( myPhyMax->text(), true )) {
491 //     myPhyMax->selectAll();
492 //     ok = false;
493 //   }
494 //   if ( !isDouble( myGeoMin->text(), true )) {
495 //     myGeoMin->selectAll();
496 //     ok = false;
497 //   }
498 //   if ( !isDouble( myGeoMin->text(), true )) {
499 //     myGeoMin->selectAll();
500 //     ok = false;
501 //   }
502   if ( ok )
503   {
504     myOptionTable->setFocus();
505     QApplication::instance()->processEvents();
506
507     BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
508       BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
509
510     int row = 0, nbRows = myOptionTable->rowCount();
511     for ( ; row < nbRows; ++row )
512     {
513       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
514       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
515       if ( !value.isEmpty() ) {
516         try {
517           h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
518         }
519         catch ( const SALOME::SALOME_Exception& ex )
520         {
521           SUIT_MessageBox::critical( dlg(),
522                                      tr("SMESH_ERROR"),
523                                      ex.details.text.in() );
524           ok = false;
525         }
526       }
527     }
528     h->SetOptionValues( myOptions ); // restore values
529   }
530
531   // SizeMap and attractors
532   if ( ok )
533   {
534     mySizeMapTable->setFocus();
535     QApplication::instance()->processEvents();
536
537     BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
538     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
539
540     int row = 0, nbRows = mySizeMapTable->rowCount();
541     for ( ; row < nbRows; ++row )
542     {
543       QString entry   = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
544       QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
545       if ( !sizeMap.isEmpty() ) {
546         if (that->sizeMapValidationFromRow(row))
547         {
548           try {
549             const char* e = entry.toLatin1().constData();
550             const char* s = that->mySMPMap[entry].toLatin1().constData();
551             h->SetSizeMapEntry( e, s );
552           }
553           catch ( const SALOME::SALOME_Exception& ex )
554           {
555             SUIT_MessageBox::critical( dlg(),
556                                        tr("SMESH_ERROR"),
557                                        ex.details.text.in() );
558             ok = false;
559           }
560         }
561         else {
562           ok = false;
563         }
564       }
565     }
566   }
567
568   // Enforced vertices
569   // TODO
570   
571   return ok;
572 }
573
574 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
575 {
576   MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
577   
578   QFrame* fr = new QFrame( 0 );
579   QVBoxLayout* lay = new QVBoxLayout( fr );
580   lay->setMargin( 5 );
581   lay->setSpacing( 0 );
582
583   // tab
584   QTabWidget* tab = new QTabWidget( fr );
585   tab->setTabShape( QTabWidget::Rounded );
586   tab->setTabPosition( QTabWidget::North );
587   lay->addWidget( tab );
588
589   // basic parameters
590   myStdGroup = new QWidget();
591   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
592   aStdLayout->setSpacing( 6 );
593   aStdLayout->setMargin( 11 );
594
595   myName = 0;
596   if( isCreation() )
597     myName = new QLineEdit( myStdGroup );
598
599   myGradation = new SMESHGUI_SpinBox( myStdGroup );
600   myGradation->RangeStepAndValidator(1.1, 2.5, 0.1, "length_precision");
601
602   myPhysicalMesh = new QComboBox( myStdGroup );
603   QStringList physicalTypes;
604   physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
605   myPhysicalMesh->addItems( physicalTypes );
606
607   myPhySize = new SMESHGUI_SpinBox( myStdGroup );
608   myPhySize->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
609
610 #ifdef WITH_SIZE_BOUNDARIES
611   myPhyMin = new SMESHGUI_SpinBox( myStdGroup );
612   myPhyMin->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
613   myPhyMin->setText("");
614   myPhyMax = new SMESHGUI_SpinBox( myStdGroup );
615   myPhyMax->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
616   myPhyMax->setText("");
617 #endif
618
619   myGeometricMesh = new QComboBox( myStdGroup );
620   QStringList types;
621   types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
622   myGeometricMesh->addItems( types );
623
624   myAngleMeshS = new SMESHGUI_SpinBox( myStdGroup );
625   myAngleMeshS->RangeStepAndValidator(0, 16, 0.5, "angular_precision");
626
627   myAngleMeshC = new SMESHGUI_SpinBox( myStdGroup );
628   myAngleMeshC->RangeStepAndValidator(0, 16, 0.5, "angular_precision");
629
630 #ifdef WITH_SIZE_BOUNDARIES
631   myGeoMin = new SMESHGUI_SpinBox( myStdGroup );
632   myGeoMin->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
633   myGeoMin->setText("");
634   myGeoMax = new SMESHGUI_SpinBox( myStdGroup );
635   myGeoMax->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
636   myGeoMax->setText("");
637 #endif
638   myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
639   myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
640   
641   // ADD WIDGETS (STANDARD TAB)
642   int row = 0;
643   if( isCreation() ) {
644     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ),        row, 0, 1, 1 );
645     aStdLayout->addWidget( myName,                                              row++, 1, 1, 1 );
646   }
647   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ),    row, 0, 1, 1 );
648   aStdLayout->addWidget( myGradation,                                           row++, 1, 1, 1 );
649   aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ),     row, 0, 1, 1 );
650   aStdLayout->addWidget( myPhysicalMesh,                                        row++, 1, 1, 1 );
651   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup),       row, 0, 1, 1 );
652   aStdLayout->addWidget( myPhySize,                                             row++, 1, 1, 1 );
653 #ifdef WITH_SIZE_BOUNDARIES
654   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ),      row, 0, 1, 1 );
655   aStdLayout->addWidget( myPhyMin,                                              row++, 1, 1, 1 );
656   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ),      row, 0, 1, 1 );
657   aStdLayout->addWidget( myPhyMax,                                              row++, 1, 1, 1 );
658 #endif
659   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ),    row, 0, 1, 1 );
660   aStdLayout->addWidget( myGeometricMesh,                                       row++, 1, 1, 1 );
661   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
662   aStdLayout->addWidget( myAngleMeshS,                                          row++, 1, 1, 1 );
663   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
664   aStdLayout->addWidget( myAngleMeshC,                                          row++, 1, 1, 1 );
665 #ifdef WITH_SIZE_BOUNDARIES
666   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ),      row, 0, 1, 1 );
667   aStdLayout->addWidget( myGeoMin,                                              row++, 1, 1, 1 );
668   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ),      row, 0, 1, 1 );
669   aStdLayout->addWidget( myGeoMax,                                              row++, 1, 1, 1 );
670 #endif
671   aStdLayout->addWidget( myAllowQuadrangles,                                    row++, 0, 1, 2 );
672   aStdLayout->addWidget( myDecimesh,                                            row++, 0, 1, 2 );
673
674   // advanced parameters
675   myAdvGroup = new QWidget();
676   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
677   anAdvLayout->setSpacing( 6 );
678   anAdvLayout->setMargin( 11 );
679   anAdvLayout->setRowStretch( 4, 5 );
680   anAdvLayout->setColumnStretch( 1, 5 );
681
682   myTopology = new QComboBox( myAdvGroup );
683   QStringList topologyTypes;
684   topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
685   myTopology->addItems( topologyTypes );
686
687   myVerbosity = new QSpinBox( myAdvGroup );
688   myVerbosity->setMinimum( 0 );
689   myVerbosity->setMaximum( 100 );
690   myVerbosity->setSingleStep( 5 );
691
692   myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
693   QStringList headers;
694   headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
695   myOptionTable->setHorizontalHeaderLabels( headers );
696   myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
697   //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
698   //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
699   myOptionTable->verticalHeader()->hide();
700   //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
701
702   QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"),  myAdvGroup );
703   addBtn->setMenu( new QMenu() );
704   QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
705     
706   
707   // ADD WIDGETS (ADVANCED TAB)
708   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ),  0, 0, 1, 1 );
709   anAdvLayout->addWidget( myTopology,                                         0, 1, 1, 1 );
710   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
711   anAdvLayout->addWidget( myVerbosity,                                        1, 1, 1, 1 );
712   anAdvLayout->addWidget( myOptionTable,                                      2, 0, 3, 2 );
713   anAdvLayout->addWidget( addBtn,                                             2, 2, 1, 1 );
714   anAdvLayout->addWidget( rmBtn,                                              3, 2, 1, 1 );
715
716
717   // Size Maps parameters
718
719   mySmpGroup = new QWidget();
720   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
721
722   mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
723   QStringList sizeMapHeaders;
724   sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
725   mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
726   mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
727   mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
728   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
729   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
730   mySizeMapTable->setAlternatingRowColors(true);
731   mySizeMapTable->verticalHeader()->hide();
732 /*
733   addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
734   QFrame *line = new QFrame(mySmpGroup);
735   line->setFrameShape(QFrame::HLine);
736   line->setFrameShadow(QFrame::Sunken);
737 */
738   addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
739   addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
740   addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
741   QFrame *line2 = new QFrame(mySmpGroup);
742   line2->setFrameShape(QFrame::HLine);
743   line2->setFrameShadow(QFrame::Sunken);
744   removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
745     
746     
747   // ADD WIDGETS (SIZEMAP TAB)
748   anSmpLayout->addWidget(mySizeMapTable,     SMP_POINT_BTN, 0, SMP_NB_LINES+1, 1);
749 //   anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
750 //   anSmpLayout->addWidget(line,               SMP_SEPARATOR1, 1, 1, 1);
751   anSmpLayout->addWidget(addPointButton,     SMP_POINT_BTN, 1, 1, 1);
752   anSmpLayout->addWidget(addEdgeButton,      SMP_EDGE_BTN, 1, 1, 1);
753   anSmpLayout->addWidget(addSurfaceButton,   SMP_SURFACE_BTN, 1, 1, 1);
754   anSmpLayout->addWidget(line2,              SMP_SEPARATOR2, 1, 1, 1);
755   anSmpLayout->addWidget(removeButton,       SMP_REMOVE_BTN, 1, 1, 1);
756
757
758   // Enforced vertices parameters
759   myEnfGroup = new QWidget();
760   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
761 // 
762 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
763 //   anEnfLayout->addWidget(myEnforcedVertexWidget);
764 //   MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
765 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
766     
767   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
768   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
769   myEnforcedTreeWidget->setSortingEnabled(true);
770   QStringList enforcedHeaders;
771   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_X_COLUMN" )<< tr( "BLSURF_ENF_VER_Y_COLUMN" ) << tr( "BLSURF_ENF_VER_Z_COLUMN" );
772   /* TODO GROUPS
773   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_X_COLUMN" )<< tr( "BLSURF_ENF_VER_Y_COLUMN" ) << tr( "BLSURF_ENF_VER_Z_COLUMN" ) << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
774   */
775   myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
776   myEnforcedTreeWidget->setAlternatingRowColors(true);
777   myEnforcedTreeWidget->setUniformRowHeights(true);
778   myEnforcedTreeWidget->setAnimated(true);
779   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
780   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
781   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
782     myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
783     myEnforcedTreeWidget->resizeColumnToContents(column);
784   }
785   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
786   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
787
788   /* TODO FACE AND VERTEX SELECTION
789   selectFaceButton = new QPushButton(myEnfGroup);
790   QPixmap imageSel1(SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "BLSURF_ICON_SELECT")));
791   selectFaceButton->setIcon(imageSel1);
792   
793   mySelectedFace = new QLineEdit(myEnfGroup);
794   mySelectedFace->setReadOnly(true);
795   mySelectedFace->setText(tr( "BLSURF_ENF_SELECT_FACE"));
796   mySelectedFace->setStyleSheet("QLineEdit { color: grey }");
797     
798   selectVertexButton = new QPushButton(myEnfGroup);
799   QPixmap imageSel2(SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "BLSURF_ICON_SELECT")));
800   selectVertexButton->setIcon(imageSel2);
801     
802   mySelectedEnforcedVertex = new QLineEdit(myEnfGroup);
803   mySelectedEnforcedVertex->setReadOnly(true);
804   mySelectedEnforcedVertex->setText(tr( "BLSURF_ENF_SELECT_VERTEX"));
805   mySelectedEnforcedVertex->setStyleSheet("QLineEdit { color: grey }");
806   */
807   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
808   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
809   myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
810   
811   QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
812   myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
813   myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
814   
815   QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
816   myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
817   myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
818
819   /* TODO GROUPS
820   QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
821   myGroupName = new QLineEdit(myEnfGroup);
822   */
823   
824   addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
825 //   QFrame *line = new QFrame(myEnfGroup);
826 //   line->setFrameShape(QFrame::HLine);
827 //   line->setFrameShadow(QFrame::Sunken);
828   removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
829
830   /* TODO GROUPS
831   // CheckBox for groups generation
832   makeGroupsCheck = new QGroupBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
833   makeGroupsCheck->setCheckable(true);
834   makeGroupsCheck->setChecked(false);
835   QGridLayout* aGroupLayout = new QGridLayout(makeGroupsCheck);
836   myGlobalGroupName = new QLineEdit(makeGroupsCheck);
837   aGroupLayout->addWidget(myGlobalGroupName);
838   */
839     
840     
841   anEnfLayout->addWidget(myEnforcedTreeWidget,     0, 0, ENF_VER_NB_LINES+1, 1);
842   /* TODO FACE AND VERTEX SELECTION
843   anEnfLayout->addWidget(selectFaceButton,         ENF_VER_FACE, 1, 1, 1);
844   anEnfLayout->addWidget(mySelectedFace,           ENF_VER_FACE, 2, 1, 1);
845   anEnfLayout->addWidget(selectVertexButton,       ENF_VER_VERTEX, 1, 1, 1);
846   anEnfLayout->addWidget(mySelectedEnforcedVertex, ENF_VER_VERTEX, 2, 1, 1);
847   */
848   anEnfLayout->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 1, 1, 1);
849   anEnfLayout->addWidget(myXCoord,                 ENF_VER_X_COORD, 2, 1, 1);
850   anEnfLayout->addWidget(myYCoordLabel,            ENF_VER_Y_COORD, 1, 1, 1);
851   anEnfLayout->addWidget(myYCoord,                 ENF_VER_Y_COORD, 2, 1, 1);
852   anEnfLayout->addWidget(myZCoordLabel,            ENF_VER_Z_COORD, 1, 1, 1);
853   anEnfLayout->addWidget(myZCoord,                 ENF_VER_Z_COORD, 2, 1, 1);
854   /* TODO GROUPS
855   anEnfLayout->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 1, 1, 1);
856   anEnfLayout->addWidget(myGroupName,              ENF_VER_GROUP, 2, 1, 1);
857   */
858   anEnfLayout->addWidget(addVertexButton,          ENF_VER_VERTEX_BTN, 1, 1, 2);
859   anEnfLayout->addWidget(removeVertexButton,       ENF_VER_REMOVE_BTN, 1, 1, 2);
860 //   anEnfLayout->addWidget(line,                     ENF_VER_SEPARATOR, 1, 1, 2);
861   /* TODO GROUPS
862   anEnfLayout->addWidget(makeGroupsCheck,          ENF_VER_GROUP_CHECK, 1, 1, 2);
863   */
864     
865   // ---
866   tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
867   tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
868   tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
869   tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
870 //   tab->insertTab( ENF_TAB, myEnforcedVertexWidget, tr( "BLSURF_ENF_VER" ) );
871
872   tab->setCurrentIndex( STD_TAB );
873
874   // ---
875   connect( myGeometricMesh,    SIGNAL( activated( int ) ),            this,         SLOT( onGeometricMeshChanged() ) );
876   connect( myPhysicalMesh,     SIGNAL( activated( int ) ),            this,         SLOT( onPhysicalMeshChanged() ) );
877   connect( addBtn->menu(),     SIGNAL( aboutToShow() ),               this,         SLOT( onAddOption() ) );
878   connect( addBtn->menu(),     SIGNAL( triggered( QAction* ) ),       this,         SLOT( onOptionChosenInPopup( QAction* ) ) );
879   connect( rmBtn,              SIGNAL( clicked()),                    this,         SLOT( onDeleteOption() ) );
880
881   connect( addSurfaceButton,   SIGNAL( clicked()),                    this,         SLOT( onAddMapOnSurface() ) );
882   connect( addEdgeButton,      SIGNAL( clicked()),                    this,         SLOT( onAddMapOnEdge() ) );
883   connect( addPointButton,     SIGNAL( clicked()),                    this,         SLOT( onAddMapOnPoint() ) );
884   connect( removeButton,       SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
885   connect( mySizeMapTable,     SIGNAL( cellChanged ( int, int  )),    this,         SLOT( onSetSizeMap(int,int ) ) );
886
887   connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
888   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
889   connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),     this,         SLOT( synchronizeCoords() ) );
890   connect( addVertexButton,    SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
891   connect( removeVertexButton, SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
892
893   return fr;
894 }
895
896 /** BLSURFPluginGUI_HypothesisCreator::update(item, column)
897 This method updates the tooltip of a modified item. The QLineEdit widgets content
898 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
899 */
900 void BLSURFPluginGUI_HypothesisCreator::update(QTreeWidgetItem* item, int column) {
901 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateVertexList");
902   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
903   if (! x.isNull()) {
904     QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
905     QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
906     QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
907     /* TODO GROUPS
908     QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
909     */
910     
911     QTreeWidgetItem* parent = item->parent();
912     if (parent) {
913       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
914       QString toolTip = shapeName + QString(": ") + vertexName.toString();
915       toolTip += QString("(") + x.toString();
916       toolTip += QString(", ") + y.toString();
917       toolTip += QString(", ") + z.toString();
918       toolTip += QString(")");
919       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
920     }
921     myXCoord->SetValue(x.toDouble());
922     myYCoord->SetValue(y.toDouble());
923     myZCoord->SetValue(z.toDouble());
924     /* TODO GROUPS
925     myGroupName->setText(groupName);
926     */
927   }
928 }
929
930 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
931 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
932 of the enforced vertex clicked in the tree widget.
933 */
934 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
935 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::synchronizeCoords");
936   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
937   if (! items.isEmpty()) {
938     QTreeWidgetItem *item;
939     for (int i=0 ; i < items.size() ; i++) {
940       item = items[i];
941       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
942       if (! x.isNull()) {
943         QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
944         QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
945         myXCoord->SetValue(x.toDouble());
946         myYCoord->SetValue(y.toDouble());
947         myZCoord->SetValue(z.toDouble());
948         /* TODO GROUPS
949         myGroupName->setText(item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString());
950         */
951         break;
952       }
953     }
954   }
955 }
956
957 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
958 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
959 */
960 /* TODO GROUPS
961 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std::string shapeName,
962     double x, double y, double z, std::string groupName) {
963 */
964 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std::string shapeName,
965     double x, double y, double z) {
966   // Find entry item
967   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(entry.c_str()),Qt::MatchExactly,ENF_VER_ENTRY_COLUMN);
968   QTreeWidgetItem* theItem;
969   if (theItemList.empty()) {
970     theItem = new QTreeWidgetItem();
971     theItem->setData(ENF_VER_ENTRY_COLUMN, Qt::EditRole, QVariant(entry.c_str()));
972     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(shapeName.c_str()));
973     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(entry.c_str()));
974     myEnforcedTreeWidget->addTopLevelItem(theItem);
975   }
976   else {
977     theItem = theItemList[0];
978   }
979
980 //   MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
981   bool okToCreate = true;
982
983   const int nbVert = theItem->childCount();
984 //   MESSAGE("Number of child rows: " << nbVert);
985   if (nbVert >0) {
986     double childValueX,childValueY,childValueZ;
987 //     QString childGrouName;
988     QTreeWidgetItem* child;
989     for (int row = 0;row<nbVert;row++) {
990       child = theItem->child(row);
991       childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
992       childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
993       childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
994       if ((childValueX == x) && (childValueY == y) && (childValueZ == z)) {
995         /* TODO GROUPS
996         // update group name
997         child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
998         */
999         okToCreate = false;
1000         break;
1001       }
1002     }
1003   }
1004   if (okToCreate) {
1005     MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
1006     
1007     QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
1008     vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1009     int vertexIndex=1;
1010     QString vertexName;
1011     int indexRef = 0;
1012     while(indexRef != vertexIndex) {
1013       indexRef = vertexIndex;
1014       vertexName = QString("Vertex #%1").arg(vertexIndex);
1015       for (int row = 0;row<nbVert;row++) {
1016         QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1017         if (vertexName == name) {
1018           vertexIndex++;
1019           break;
1020         }
1021       }
1022     }
1023     vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, vertexName );
1024     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1025     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1026     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1027     /* TODO GROUPS
1028     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1029     */
1030     QString toolTip = QString(shapeName.c_str())+QString(": ")+vertexName;
1031     toolTip += QString(" (%1, ").arg(x);
1032     toolTip += QString("%1, ").arg(y);
1033     toolTip += QString("%1)").arg(z);
1034     vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1035     theItem->setExpanded(true);
1036     myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1037   }
1038   else
1039     /* TODO GROUPS
1040     MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z <<
1041         " already exist: dont create again, only group name is updated with " << groupName);
1042     */
1043     MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1044 }
1045
1046 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1047 This method is called when a item is added into the enforced vertices tree widget
1048 */
1049 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
1050 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1051
1052   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1053     myEnforcedTreeWidget->resizeColumnToContents(column);
1054   
1055   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1056   
1057   if ((myXCoord->text().isEmpty()) ||
1058       (myYCoord->text().isEmpty()) ||
1059       (myZCoord->text().isEmpty())) return;
1060
1061   double x = myXCoord->GetValue();
1062   double y = myYCoord->GetValue();
1063   double z = myZCoord->GetValue();
1064
1065   /* TODO GROUPS
1066   std::string groupName = myGroupName->text().toStdString();
1067   if (makeGroupsCheck->isChecked())
1068     groupName = myGlobalGroupName->text().toStdString();
1069
1070   if (boost::trim_copy(groupName) == "")
1071     groupName = "";
1072   */
1073   
1074   TopAbs_ShapeEnum shapeType;
1075   string entry, shapeName;
1076   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1077   LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1078   SALOME_ListIO ListSelectedObjects;
1079   mySel->selectedObjects(ListSelectedObjects, NULL, false );
1080   if (!ListSelectedObjects.IsEmpty()) {
1081     SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1082     for (; Object_It.More(); Object_It.Next()) {
1083       Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1084       entry     = myGeomToolSelected->getEntryOfObject(anObject);
1085       shapeName = anObject->getName();
1086       shapeType = myGeomToolSelected->entryToShapeType(entry);
1087 //       MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
1088       if (shapeType == TopAbs_FACE) {
1089         /* TODO GROUPS
1090         addEnforcedVertex(entry, shapeName, x, y, z, groupName);
1091         */
1092         addEnforcedVertex(entry, shapeName, x, y, z);
1093       }
1094     }
1095   }
1096   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1097     myEnforcedTreeWidget->resizeColumnToContents(column);
1098   
1099   if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1100     myPhysicalMesh->setCurrentIndex( SizeMap );
1101     onPhysicalMeshChanged();
1102   }
1103 }
1104
1105 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1106 This method is called when a item is removed from the enforced vertices tree widget
1107 */
1108 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1109 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1110   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1111   QList<QTreeWidgetItem *> selectedVertices;
1112   QSet<QTreeWidgetItem *> selectedEntries;
1113   QTreeWidgetItem* item;
1114
1115   foreach( item, selectedItems ) {
1116     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1117     if (! value.isNull())
1118       selectedVertices.append(item);
1119     else
1120       selectedEntries.insert(item);
1121   }
1122
1123   foreach(item,selectedVertices) {
1124     QTreeWidgetItem* parent = item->parent();
1125 //     MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1126     parent->removeChild(item);
1127     delete item;
1128     if (parent->childCount() == 0) {
1129       if (selectedEntries.contains(parent))
1130         selectedEntries.remove(parent);
1131       delete parent;
1132     }
1133   }
1134
1135   foreach(item,selectedEntries) {
1136 //     MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1137     delete item;
1138   }
1139
1140   myEnforcedTreeWidget->selectionModel()->clearSelection();
1141 }
1142
1143 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1144 This method updates the GUI widgets with the hypothesis data
1145 */
1146 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1147 {
1148   MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1149   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1150
1151   BlsurfHypothesisData data;
1152   that->readParamsFromHypo( data );
1153
1154   if ( myName ) {
1155     myName->setText( data.myName );
1156     QFontMetrics metrics( myName->font() );
1157     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1158   }
1159   myTopology->setCurrentIndex( data.myTopology );
1160   myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1161   myPhySize->SetValue( data.myPhySize );
1162 #ifdef WITH_SIZE_BOUNDARIES
1163   MESSAGE("data.myPhyMin: "<<data.myPhyMin)
1164   if (data.myPhyMin < 0)
1165     myPhyMin->setText("");
1166   else
1167     myPhyMin->SetValue( data.myPhyMin );
1168   MESSAGE("data.myPhyMax: "<<data.myPhyMax)
1169   if (data.myPhyMax < 0)
1170     myPhyMax->setText("");
1171   else
1172     myPhyMax->SetValue( data.myPhyMax );
1173   MESSAGE("data.myGeoMin: "<<data.myGeoMin)
1174   if (data.myGeoMin < 0)
1175     myGeoMin->setText("");
1176   else
1177     myGeoMin->SetValue( data.myGeoMin );
1178   MESSAGE("data.myGeoMax: "<<data.myGeoMax)
1179   if (data.myGeoMax < 0)
1180     myGeoMax->setText("");
1181   else
1182     myGeoMax->SetValue( data.myGeoMax );
1183 #endif
1184   myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1185 //   myAngleMeshS->setValue( data.myAngleMeshS );
1186 //   myAngleMeshC->setValue( data.myAngleMeshC );
1187 //   myGradation->setValue( data.myGradation );
1188   myAngleMeshS->SetValue( data.myAngleMeshS );
1189   myAngleMeshC->SetValue( data.myAngleMeshC );
1190   myGradation->SetValue( data.myGradation );
1191   myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1192   myDecimesh->setChecked( data.myDecimesh );
1193   myVerbosity->setValue( data.myVerbosity );
1194
1195   if ( myOptions.operator->() ) {
1196 //     MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1197     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1198       QString option = that->myOptions[i].in();
1199       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1200       if ( name_value.count() > 1 ) {
1201         QString idStr = QString("%1").arg( i );
1202         int row = myOptionTable->rowCount();
1203         myOptionTable->setRowCount( row+1 );
1204         myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1205         myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1206         myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1207         myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1208         myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1209         myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1210                                                                    Qt::ItemIsEditable   |
1211                                                                    Qt::ItemIsEnabled );
1212       }
1213     }
1214   }
1215   myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1216
1217   // Sizemaps
1218 //   MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1219   QMapIterator<QString, QString> i(that->mySMPMap);
1220   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1221   while (i.hasNext()) {
1222     i.next();
1223     const QString entry = i.key();
1224     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1225     const QString sizeMap = i.value();
1226     int row = mySizeMapTable->rowCount();
1227     mySizeMapTable->setRowCount( row+1 );
1228     mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
1229     mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1230     mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1231     mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1232     mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1233     mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
1234                                                                Qt::ItemIsEditable   |
1235                                                                Qt::ItemIsEnabled );
1236     }
1237
1238   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1239   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1240
1241   // Enforced vertices
1242 //   MESSAGE("retrieveParams(): data.entryEnfVertexListMap.size() = " << data.entryEnfVertexListMap.size());
1243   std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = data.entryEnfVertexListMap.begin();
1244   for ( ; evmIt != data.entryEnfVertexListMap.end() ; ++evmIt) {
1245     std::string entry = (*evmIt).first;
1246     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1247
1248     std::set<std::vector<double> > evs;
1249     std::set<std::vector<double> >::const_iterator evsIt;
1250     try  {
1251       evs = (*evmIt).second;
1252     }
1253     catch(...) {
1254 //       MESSAGE("evs = (*evmIt)[entry]: FAIL");
1255       break;
1256     }
1257
1258     evsIt = evs.begin();
1259     for ( ; evsIt != evs.end() ; ++evsIt) {
1260       double x, y, z;
1261       x = (*evsIt)[0];
1262       y = (*evsIt)[1];
1263       z = (*evsIt)[2];
1264       /* TODO GROUPS
1265       std::string groupName = data.enfVertexGroupNameMap[(*evsIt)];
1266       MESSAGE("Vertex "<<x<<" "<<y<<" "<<z<<" has group name "<<groupName);
1267       that->addEnforcedVertex(entry, shapeName, x, y, z, groupName);
1268       */
1269       that->addEnforcedVertex(entry, shapeName, x, y, z);
1270     }
1271   }
1272   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1273     myEnforcedTreeWidget->resizeColumnToContents(column);
1274   
1275   // update widgets
1276   that->onPhysicalMeshChanged();
1277   that->onGeometricMeshChanged();
1278 }
1279
1280 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1281 This method updates the hypothesis data with the GUI widgets content.
1282 */
1283 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1284 {
1285   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1286
1287   BlsurfHypothesisData data;
1288   QString guiHyp = that->readParamsFromWidgets( data );
1289   that->storeParamsToHypo( data );
1290
1291   return guiHyp;
1292 }
1293
1294 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1295 Updates the hypothesis data from hypothesis values.
1296 */
1297 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1298 {
1299   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1300   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1301     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1302
1303   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1304   h_data.myName = isCreation() && data ? hypName() : "";
1305
1306   h_data.myTopology         = (int) h->GetTopology();
1307   h_data.myPhysicalMesh     = (int) h->GetPhysicalMesh();
1308   h_data.myPhySize          = h->GetPhySize();
1309   h_data.myGeometricMesh    = (int) h->GetGeometricMesh();
1310   h_data.myAngleMeshS       = h->GetAngleMeshS();
1311   h_data.myAngleMeshC       = h->GetAngleMeshC();
1312   h_data.myGradation        = h->GetGradation();
1313   h_data.myAllowQuadrangles = h->GetQuadAllowed();
1314   h_data.myDecimesh         = h->GetDecimesh();
1315   h_data.myVerbosity        = h->GetVerbosity();
1316
1317 #ifdef WITH_SIZE_BOUNDARIES
1318   double PhyMin = h->GetPhyMin();
1319   double PhyMax = h->GetPhyMax();
1320   double GeoMin = h->GetGeoMin();
1321   double GeoMax = h->GetGeoMax();
1322 //   if ( PhyMin > 0 )
1323 //   h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
1324 //   h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
1325 //   h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
1326 //   h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
1327   h_data.myPhyMin = PhyMin > 0 ? PhyMin : -1.0;
1328   h_data.myPhyMax = PhyMax > 0 ? PhyMax : -1.0;
1329   h_data.myGeoMin = GeoMin > 0 ? GeoMin : -1.0;
1330   h_data.myGeoMax = GeoMax > 0 ? GeoMax : -1.0;
1331 #endif
1332
1333   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1334   that->myOptions = h->GetOptionValues();
1335
1336   that->mySMPMap.clear();
1337
1338   // classic size maps
1339   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1340 //   MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1341   QString fullSizeMaps;
1342   QStringList fullSizeMapList;
1343   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1344   for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1345     fullSizeMaps =  mySizeMaps[i].in();
1346 //     MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1347     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1348     if ( fullSizeMapList.count() > 1 ) {
1349       string fullSizeMap = fullSizeMapList[1].toStdString();
1350       int pos = fullSizeMap.find("return")+7;
1351 //       MESSAGE("pos:" << pos);
1352       QString sizeMap;
1353       try {
1354         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1355       }
1356       catch (...) {
1357         continue;
1358       }
1359       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1360 //       MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1361       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1362 //       MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1363     }
1364   }
1365
1366   // custom size maps
1367 /*
1368   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1369   MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1370
1371   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1372     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
1373     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1374     if ( fullCustomSizeMapList.count() > 1 ) {
1375       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1376       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1377       MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1378       MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1379     }
1380   }
1381 */
1382   // attractor
1383   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1384 //   MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1385
1386   for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1387     QString myAttractors =  allMyAttractors[i].in();
1388     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1389     if ( myAttractorList.count() > 1 ) {
1390       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1391       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1392 //       MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1393 //       MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1394     }
1395   }
1396   
1397   // Enforced vertices
1398   h_data.enfVertexList.clear();
1399   h_data.entryEnfVertexListMap.clear();
1400   /* TODO GROUPS
1401   h_data.groupNameEnfVertexListMap.clear();
1402 //   h_data.enfVertexGroupNameMap.clear();
1403   */
1404   
1405   BLSURFPlugin::TEntryEnfVertexListMap_var entryEnfVertexListMap = h->GetAllEnforcedVertices();
1406 //   MESSAGE("entryEnfVertexListMap->length() = " << entryEnfVertexListMap->length());
1407
1408   for ( int i = 0;i<entryEnfVertexListMap->length(); ++i ) {
1409     std::string entry =  entryEnfVertexListMap[i].entry.in();
1410     BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1411     std::set<std::vector<double> > evs;
1412     /* TODO GROUPS
1413     std::string groupName = "";
1414     */
1415     for (int j=0 ; j<vertexList->length(); ++j) {
1416       double x = vertexList[j][0];
1417       double y = vertexList[j][1];
1418       double z = vertexList[j][2];
1419       std::vector<double> ev;
1420       ev.push_back(x);
1421       ev.push_back(y);
1422       ev.push_back(z);
1423       evs.insert(ev);
1424       h_data.enfVertexList.insert(ev);
1425       /* TODO GROUPS
1426       groupName.assign(h->GetEnforcedVertexGroupName(x, y, z));
1427       MESSAGE("readParamsFromHypo, groupName = "<<groupName)
1428       h_data.enfVertexGroupNameMap[ev] = groupName;
1429       if (groupName != "") {
1430         h_data.groupNameEnfVertexListMap[groupName].insert(ev);
1431       }
1432       */
1433 //       MESSAGE("New enf vertex for entry " << entry << ": " << x << ", " << y << ", " << z);
1434     }
1435 //     h_data.enfVertMap[entry] = evs;
1436     h_data.entryEnfVertexListMap[entry] = evs;
1437     if (evs.size() == 0) {
1438 //       MESSAGE("No enf vertex for entry " << entry << ": key is erased");
1439 //       h_data.enfVertMap.erase(entry);
1440       h_data.entryEnfVertexListMap.erase(entry);
1441     }
1442   }
1443   
1444   return true;
1445 }
1446
1447 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1448 Saves the hypothesis data to hypothesis values.
1449 */
1450 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1451 {
1452   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1453   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1454     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1455
1456   bool ok = true;
1457   try
1458   {
1459     if( isCreation() )
1460       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1461
1462     if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
1463       h->SetTopology( (int) h_data.myTopology );
1464     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
1465       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1466     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1467       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1468     if ( h->GetGradation() !=  h_data.myGradation )
1469       h->SetGradation( h_data.myGradation );
1470     if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1471       h->SetQuadAllowed( h_data.myAllowQuadrangles );
1472     if ( h->GetDecimesh() != h_data.myDecimesh )
1473       h->SetDecimesh( h_data.myDecimesh );
1474     if ( h->GetVerbosity() != h_data.myVerbosity )
1475       h->SetVerbosity( h_data.myVerbosity );
1476
1477     if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
1478       if ( h->GetPhySize() != h_data.myPhySize )
1479         h->SetPhySize( h_data.myPhySize );
1480     }
1481     if( (int) h_data.myGeometricMesh == UserDefined ) {
1482       if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
1483         h->SetAngleMeshS( h_data.myAngleMeshS );
1484       if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
1485         h->SetAngleMeshC( h_data.myAngleMeshC );
1486     }
1487 #ifdef WITH_SIZE_BOUNDARIES
1488 //     if ( !isDouble( h_data.myPhyMin ))
1489 //       h->SetPhyMin( -1 );
1490 //     else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
1491 //       h->SetPhyMin( h_data.myPhyMin.toDouble() );
1492 //     if ( !isDouble( h_data.myPhyMax ))
1493 //       h->SetPhyMax( -1 );
1494 //     else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
1495 //       h->SetPhyMax( h_data.myPhyMax.toDouble() );
1496 //     if ( !isDouble( h_data.myGeoMin ))
1497 //       h->SetGeoMin( -1 );
1498 //     else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
1499 //       h->SetGeoMin( h_data.myGeoMin.toDouble() );
1500 //     if ( !isDouble( h_data.myGeoMax ))
1501 //       h->SetGeoMax( -1 );
1502 //     else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
1503 //       h->SetGeoMax( h_data.myGeoMax.toDouble() );
1504     if (h_data.myPhyMin > 0)
1505       h->SetPhyMin( h_data.myPhyMin );
1506     if (h_data.myPhyMax > 0)
1507       h->SetPhyMax( h_data.myPhyMax );
1508     if (h_data.myGeoMin > 0)
1509       h->SetGeoMin( h_data.myGeoMin );
1510     if (h_data.myGeoMax > 0)
1511       h->SetGeoMax( h_data.myGeoMax );
1512 #endif
1513
1514     //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
1515     h->SetOptionValues( myOptions ); // is set in checkParams()
1516
1517     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1518     QMapIterator<QString,QString> i(that->mySMPMap);
1519     // Iterate over each size map
1520     while (i.hasNext()) {
1521       i.next();
1522       const QString entry = i.key();
1523       const QString sizeMap = i.value();
1524
1525       if (sizeMap == "__TO_DELETE__") {
1526 //         MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1527         h->UnsetEntry(entry.toLatin1().constData());
1528       }
1529       else if (sizeMap.startsWith("ATTRACTOR")) {
1530 //         MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1531         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1532       }
1533       else if (sizeMap.startsWith("def")) {
1534 //         MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1535 //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1536       }
1537       else {
1538         QString fullSizeMap;
1539         fullSizeMap = QString("");
1540         if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
1541           fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1542         else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
1543           fullSizeMap = QString("def f(t): return ") + sizeMap;
1544         else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1545           fullSizeMap = QString("def f(): return ") + sizeMap;
1546
1547 //         MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1548         h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1549       }
1550     }
1551     
1552     // Enforced vertices
1553     std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = h_data.entryEnfVertexListMap.begin();
1554     for ( ; evmIt != h_data.entryEnfVertexListMap.end() ; ++evmIt) {
1555       std::string entry = evmIt->first;
1556       std::set<std::vector<double> > evs;
1557       std::set<std::vector<double> >::const_iterator evsIt;
1558       double x, y, z;
1559       /* TODO GROUPS
1560       std::string groupName = "";
1561       */
1562       BLSURFPlugin::TEnfVertexList_var hypVertexList;
1563       int hypNbVertex = 0;
1564       try {
1565         hypVertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1566         hypNbVertex = hypVertexList->length();
1567       }
1568       catch(...) {
1569       }
1570       evs = evmIt->second;
1571       evsIt = evs.begin();
1572       for ( ; evsIt != evs.end() ; ++evsIt) {
1573         x = (*evsIt)[0];
1574         y = (*evsIt)[1];
1575         z = (*evsIt)[2];
1576
1577         /* TODO GROUPS
1578         std::map<std::vector<double> , std::string >::const_iterator grpIt = h_data.enfVertexGroupNameMap.find(*evsIt);
1579         if (grpIt != h_data.enfVertexGroupNameMap.end())
1580           groupName = grpIt->second;
1581 //         MESSAGE("SetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1582         h->SetEnforcedVertexEntryWithGroup( entry.c_str(), x, y, z, groupName.c_str() );
1583         */
1584         h->SetEnforcedVertexEntry( entry.c_str(), x, y, z );
1585       }
1586       // Remove old vertices
1587       if (hypNbVertex >0) {
1588         for (int i =0 ; i<hypNbVertex ; i++) {
1589           x = hypVertexList[i][0];
1590           y = hypVertexList[i][1];
1591           z = hypVertexList[i][2];
1592           std::vector<double> vertex;
1593           vertex.push_back(x);
1594           vertex.push_back(y);
1595           vertex.push_back(z);
1596           if (evs.find(vertex) == evs.end()) {
1597 //             MESSAGE("UnsetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1598             h->UnsetEnforcedVertexEntry( entry.c_str(), x, y, z );
1599           }
1600         }
1601       }
1602     }
1603   }
1604   catch(const SALOME::SALOME_Exception& ex)
1605   {
1606     SalomeApp_Tools::QtCatchCorbaException(ex);
1607     ok = false;
1608   }
1609   return ok;
1610 }
1611
1612 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1613 Stores the widgets content to the hypothesis data.
1614 */
1615 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1616 {
1617   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1618   h_data.myName             = myName ? myName->text() : "";
1619   h_data.myTopology         = myTopology->currentIndex();
1620   h_data.myPhysicalMesh     = myPhysicalMesh->currentIndex();
1621   h_data.myPhySize          = myPhySize->GetValue();
1622 #ifdef WITH_SIZE_BOUNDARIES
1623   h_data.myPhyMin           = myPhyMin->GetValue();
1624   h_data.myPhyMax           = myPhyMax->GetValue();
1625   h_data.myGeoMin           = myGeoMin->GetValue();
1626   h_data.myGeoMax           = myGeoMax->GetValue();
1627 #endif
1628   h_data.myGeometricMesh    = myGeometricMesh->currentIndex();
1629   h_data.myAngleMeshS       = myAngleMeshS->GetValue();
1630   h_data.myAngleMeshC       = myAngleMeshC->GetValue();
1631   h_data.myGradation        = myGradation->GetValue();
1632   h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
1633   h_data.myDecimesh         = myDecimesh->isChecked();
1634   h_data.myVerbosity        = myVerbosity->value();
1635
1636   QString guiHyp;
1637   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1638   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1639   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
1640   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1641   guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
1642   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1643   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1644   guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
1645 #ifdef WITH_SIZE_BOUNDARIES
1646   guiHyp += "hphymin = " + QString::number( h_data.myPhyMin ) + "; ";
1647   guiHyp += "hphymax = " + QString::number( h_data.myPhyMax ) + "; ";
1648   guiHyp += "hgeomin = " + QString::number( h_data.myGeoMin ) + "; ";
1649   guiHyp += "hgeomax = " + QString::number( h_data.myGeoMax ) + "; ";
1650 #endif
1651
1652   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1653   int row = 0, nbRows = myOptionTable->rowCount();
1654   for ( ; row < nbRows; ++row )
1655   {
1656     int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1657     if ( id >= 0 && id < myOptions->length() )
1658     {
1659       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1660       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1661       if ( value.isNull() )
1662         value = "";
1663       that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1664       if ( value != "" )
1665         guiHyp += name + " = " + value + "; ";
1666     }
1667   }
1668
1669   // SizeMap
1670   row = 0, nbRows = mySizeMapTable->rowCount();
1671   for ( ; row < nbRows; ++row )
1672   {
1673       QString entry   = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
1674       if ( that->mySMPMap.contains(entry) )
1675         guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1676   }
1677
1678   // Enforced vertices
1679   h_data.enfVertexList.clear();
1680   h_data.entryEnfVertexListMap.clear();
1681   /* TODO GROUPS
1682   h_data.groupNameEnfVertexListMap.clear();
1683   h_data.enfVertexGroupNameMap.clear();
1684   */
1685   
1686   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1687   int nbEnforcedVertices = 0;
1688   std::string groupName = "";
1689 //   MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1690   for (int i=0 ; i<nbEnforcedShapes ; i++) {
1691     QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1692     if (shapeItem) {
1693       std::string entry = shapeItem->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1694       nbEnforcedVertices = shapeItem->childCount();
1695       if (nbEnforcedVertices >0) {
1696         double childValueX,childValueY,childValueZ;
1697         QTreeWidgetItem* child;
1698         std::set<std::vector<double> > evs;
1699         for (row = 0;row<nbEnforcedVertices;row++) {
1700           child = shapeItem->child(row);
1701           childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1702           childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1703           childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1704           std::vector<double> vertex;
1705           vertex.push_back(childValueX);
1706           vertex.push_back(childValueY);
1707           vertex.push_back(childValueZ);
1708           evs.insert(vertex);
1709           h_data.enfVertexList.insert(vertex);
1710           /* TODO GROUPS
1711           groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
1712           // Group
1713           if (makeGroupsCheck->isChecked())
1714             groupName = myGlobalGroupName->text().toStdString();
1715           h_data.enfVertexGroupNameMap[vertex] = groupName;
1716           if (groupName != "")
1717             h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
1718           */
1719         }
1720         h_data.entryEnfVertexListMap[entry] = evs;
1721       }
1722     }
1723   }
1724
1725   MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
1726   return guiHyp;
1727 }
1728
1729 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
1730   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
1731   bool isPhysicalUserDefined = (myPhysicalMesh->currentIndex() == PhysicalUserDefined);
1732   bool isSizeMap = (myPhysicalMesh->currentIndex() == SizeMap);
1733   bool isCustom = (isPhysicalUserDefined || isSizeMap) ;
1734   bool geomIsCustom = (myGeometricMesh->currentIndex() == UserDefined);
1735   
1736   myGradation->setEnabled(!isPhysicalUserDefined || geomIsCustom);
1737   myPhySize->setEnabled(isCustom);
1738   myPhyMax->setEnabled(isCustom);
1739   myPhyMin->setEnabled(isCustom);
1740
1741   if ( !myGradation->isEnabled())
1742 //     myGradation->setValue( 1.1 );
1743     myGradation->SetValue( 1.1 );
1744
1745   if ( !isCustom ) {
1746 //     QString aPhySize = "";
1747 //     switch( myPhysicalMesh->currentIndex() ) {
1748 //       case DefaultSize:
1749 //       default:
1750 //         aPhySize = "10";
1751 //         break;
1752 //       }
1753 //     myPhySize->setText( aPhySize );
1754 //     if ( !isDouble( myPhyMin->text(), true ))
1755 //       myPhyMin->setText("");
1756 //     if ( !isDouble( myPhyMax->text(), true ))
1757 //       myPhyMax->setText("");
1758     if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
1759       myGeometricMesh->setCurrentIndex( UserDefined );
1760       onGeometricMeshChanged();
1761     }
1762   }
1763 }
1764
1765 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
1766   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
1767   bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
1768   bool phyIsSizemap = (myPhysicalMesh->currentIndex() == SizeMap);
1769   
1770   myAngleMeshS->setEnabled(isCustom);
1771   myAngleMeshC->setEnabled(isCustom);
1772   myGradation->setEnabled(isCustom || phyIsSizemap);
1773   myGeoMax->setEnabled(isCustom);
1774   myGeoMin->setEnabled(isCustom);
1775
1776   if ( !myGradation->isEnabled())
1777     myGradation->SetValue( 1.1 );
1778
1779   if ( ! isCustom ) {
1780 //     double aAngleMeshS;
1781 //     switch( myGeometricMesh->currentIndex() ) {
1782 //       case DefaultGeom:
1783 //       default:
1784 //         aAngleMeshS = 8;
1785 //         break;
1786 //       }
1787 //     myAngleMeshS->SetValue( aAngleMeshS );
1788 //     myAngleMeshC->SetValue( aAngleMeshS );
1789 //     if ( !isDouble( myGeoMin->text(), true ))
1790 //       myGeoMin->setText("");
1791 //     if ( !isDouble( myGeoMax->text(), true ))
1792 //       myGeoMax->setText("");
1793     //  hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
1794     if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
1795       myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
1796       onPhysicalMeshChanged();
1797     }
1798   }
1799 }
1800
1801 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
1802 {
1803   QMenu* menu = (QMenu*)sender();
1804   // fill popup with option names
1805   menu->clear();
1806   if ( myOptions.operator->() ) {
1807     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1808       QString name_value = myOptions[i].in();
1809       QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1810       menu->addAction( name );
1811     }
1812   }
1813 }
1814
1815 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1816 {
1817   myOptionTable->setFocus();
1818   QMenu* menu = (QMenu*)( a->parent() );
1819
1820   int idx = menu->actions().indexOf( a );
1821   QString idStr = QString("%1").arg( idx );
1822   QString option = myOptions[idx].in();
1823   QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1824
1825   // look for a row with optionName
1826   int row = 0, nbRows = myOptionTable->rowCount();
1827   for ( ; row < nbRows; ++row )
1828     if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1829       break;
1830   // add a row if not found
1831   if ( row == nbRows ) {
1832     myOptionTable->setRowCount( row+1 );
1833     myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1834     myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1835     myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1836     myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1837     myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1838     myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1839                                                                Qt::ItemIsEditable   |
1840                                                                Qt::ItemIsEnabled );
1841     myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1842   }
1843   myOptionTable->clearSelection();
1844   myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1845   //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1846   myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1847   //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1848 }
1849
1850 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1851 {
1852   // clear option values and remember selected row
1853   QList<int> selectedRows;
1854   QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1855   QTableWidgetItem* item;
1856   foreach( item, selected ) {
1857     int row = item->row();
1858     if ( !selectedRows.contains( row ) ) {
1859       selectedRows.append( row );
1860       int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1861       if ( id >= 0 && id < myOptions->length() )
1862         myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1863     }
1864   }
1865   qSort( selectedRows );
1866   QListIterator<int> it( selectedRows );
1867   it.toBack();
1868   while ( it.hasPrevious() )
1869     myOptionTable->removeRow( it.previous() );
1870 }
1871
1872 // **********************
1873 // *** BEGIN SIZE MAP ***
1874 // **********************
1875
1876
1877 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1878 {
1879   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1880   QList<int> selectedRows;
1881   QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1882   QTableWidgetItem* item;
1883   int row;
1884   foreach( item, selected ) {
1885     row = item->row();
1886     if ( !selectedRows.contains( row ) )
1887       selectedRows.append( row );
1888   }
1889
1890   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1891
1892   qSort( selectedRows );
1893   QListIterator<int> it( selectedRows );
1894   it.toBack();
1895   while ( it.hasPrevious() ) {
1896       row = it.previous();
1897       QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1898       if (that->mySMPMap.contains(entry))
1899         that->mySMPMap[entry] = "__TO_DELETE__";
1900       if (that->mySMPShapeTypeMap.contains(entry))
1901         that->mySMPShapeTypeMap.remove(entry);
1902       mySizeMapTable->removeRow(row );
1903   }
1904   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1905   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1906 }
1907
1908 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1909 {
1910   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1911   if (col == SMP_SIZEMAP_COLUMN) {
1912     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1913     QString entry   = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1914     QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1915 //     MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1916     if (! that->mySMPShapeTypeMap.contains(entry))
1917       return;
1918     if (that->mySMPMap.contains(entry))
1919       if (that->mySMPMap[entry] == sizeMap)
1920         return;
1921     QColor* bgColor = new QColor("white");
1922     QColor* fgColor = new QColor("black");
1923     if (! sizeMap.isEmpty()) {
1924       that->mySMPMap[entry] = sizeMap;
1925       if (! sizeMapValidationFromRow(row)) {
1926         bgColor->setRgb(255,0,0);
1927         fgColor->setRgb(255,255,255);
1928       }
1929     }
1930     else {
1931 //       MESSAGE("Size map empty: reverse to precedent value" );
1932       that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1933     }
1934     that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1935     that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1936     that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1937     that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1938     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1939   }
1940 }
1941
1942 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1943 {
1944  insertElementType(TopAbs_FACE);
1945 }
1946
1947 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1948 {
1949  insertElementType(TopAbs_EDGE);
1950 }
1951
1952 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1953 {
1954  insertElementType(TopAbs_VERTEX);
1955 }
1956
1957 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1958 {
1959 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1960
1961   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1962     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1963
1964   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1965
1966   TopAbs_ShapeEnum shapeType;
1967   string entry, shapeName;
1968   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1969
1970   LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1971
1972   SALOME_ListIO ListSelectedObjects;
1973   mySel->selectedObjects(ListSelectedObjects, NULL, false );
1974   if (!ListSelectedObjects.IsEmpty())
1975   {
1976     SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1977     for (; Object_It.More(); Object_It.Next())
1978     {
1979       Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1980       entry     = myGeomToolSelected->getEntryOfObject(anObject);
1981       shapeName = anObject->getName();
1982       shapeType         = myGeomToolSelected->entryToShapeType(entry);
1983 //       MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
1984       if (shapeType == typeShapeAsked)
1985       {
1986         mySizeMapTable->setFocus();
1987         QString shapeEntry;
1988         shapeEntry = QString::fromStdString(entry);
1989         double phySize = h->GetPhySize();
1990         std::ostringstream oss;
1991         oss << phySize;
1992         QString sizeMap;
1993         sizeMap  = QString::fromStdString(oss.str());
1994         if (that->mySMPMap.contains(shapeEntry)) {
1995           if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1996 //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1997             break;
1998           }
1999         }
2000         that->mySMPMap[shapeEntry] = sizeMap;
2001         that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
2002         int row = mySizeMapTable->rowCount() ;
2003         mySizeMapTable->setRowCount( row+1 );
2004         mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
2005         mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
2006         mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
2007         mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
2008         mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
2009         mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
2010         mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2011         mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2012         mySizeMapTable->clearSelection();
2013         mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
2014
2015         if ( myPhysicalMesh->currentIndex() != SizeMap ) {
2016           myPhysicalMesh->setCurrentIndex( SizeMap );
2017           onPhysicalMeshChanged();
2018         }
2019       }
2020     }
2021   }
2022 }
2023
2024 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
2025 {
2026 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
2027   int row = 0, nbRows = mySizeMapTable->rowCount();
2028   for ( ; row < nbRows; ++row )
2029     if (! sizeMapValidationFromRow(row))
2030       return false;
2031   return true;
2032 }
2033
2034 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
2035 {
2036 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
2037   QString myEntry   = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
2038   bool res = sizeMapValidationFromEntry(myEntry,displayError);
2039   mySizeMapTable->setFocus();
2040   return res;
2041 }
2042
2043 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
2044 {
2045 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
2046
2047   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2048
2049   if (! that->mySMPMap.contains(myEntry)) {
2050 //     MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
2051     return false;
2052   }
2053   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
2054 //     MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
2055     return false;
2056   }
2057
2058   string expr;
2059
2060   if (that->mySMPMap[myEntry].startsWith("def")) {
2061 //     MESSAGE("custom function" );
2062     expr = that->mySMPMap[myEntry].toStdString();
2063   }
2064   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
2065 //     MESSAGE("Attractor" );
2066     if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)\\)$")) != 1)) {
2067 //     if ((that->mySMPMap[myEntry].count('(') != 1) or
2068 //         (that->mySMPMap[myEntry].count(')') != 1) or
2069 //         (that->mySMPMap[myEntry].count(';') != 4) or
2070 //         (that->mySMPMap[myEntry].size() == 15)){
2071       if (displayError)
2072         SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False)" );
2073       return false;
2074     }
2075     return true;
2076   }
2077   else {
2078     // case size map is empty
2079     if (that->mySMPMap[myEntry].isEmpty()) {
2080       if (displayError)
2081         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
2082       return false;
2083     }
2084     else {
2085       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
2086         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
2087       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
2088         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
2089       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
2090         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
2091     }
2092   }
2093   //assert(Py_IsInitialized());
2094   if (! Py_IsInitialized())
2095     throw ("Erreur: Python interpreter is not initialized");
2096   PyGILState_STATE gstate;
2097   gstate = PyGILState_Ensure();
2098
2099   PyObject * obj = NULL;
2100   PyObject* new_stderr = NULL;
2101   string  err_description="";
2102   obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
2103   if (obj == NULL){
2104     fflush(stderr);
2105     err_description="";
2106     new_stderr=newPyStdOut(err_description);
2107     PySys_SetObject("stderr", new_stderr);
2108     PyErr_Print();
2109     PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
2110     Py_DECREF(new_stderr);
2111     if (displayError)
2112       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
2113     PyGILState_Release(gstate);
2114     return false;
2115   }
2116   Py_DECREF(obj);
2117
2118   PyObject * func = NULL;
2119   func = PyObject_GetAttrString(main_mod, "f");
2120   if ( func == NULL){
2121     fflush(stderr);
2122     err_description="";
2123     new_stderr=newPyStdOut(err_description);
2124     PySys_SetObject("stderr", new_stderr);
2125     PyErr_Print();
2126     PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
2127     Py_DECREF(new_stderr);
2128     if (displayError)
2129       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
2130     PyGILState_Release(gstate);
2131     return false;
2132   }
2133
2134   PyGILState_Release(gstate);
2135
2136 //   MESSAGE("SizeMap expression "<<expr<<" is valid");
2137
2138   return true;
2139 }
2140
2141 /*
2142 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
2143   int myRow = index->row();
2144   int myColumn = index->column();
2145
2146   if (myColumn == 2){
2147      if (!myEditor) {
2148          myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
2149          connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
2150      }
2151      myEditor->exec();
2152 //      myEditor->show();
2153 //      myEditor->raise();
2154 //      myEditor->activateWindow();
2155
2156
2157 //     BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
2158 //     myEditor->exec();
2159      QString myFunction = myEditor->GetFunctionText();
2160      // FIN RECUPERATION FONCTION
2161
2162      if (! myFunction.isEmpty()) {
2163
2164      // MAJ DE LA MAP
2165
2166      BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2167        BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2168
2169 //     h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
2170 //                        item->text().toLatin1().constData());
2171      h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
2172                         myFunction.toLatin1().constData());
2173      // FIN MAJ DE LA MAP
2174      }
2175   }
2176 }*/
2177
2178 QString BLSURFPluginGUI_HypothesisCreator::caption() const
2179 {
2180   return tr( "BLSURF_TITLE" );
2181 }
2182
2183 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
2184 {
2185   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
2186 }
2187
2188 QString BLSURFPluginGUI_HypothesisCreator::type() const
2189 {
2190   return tr( "BLSURF_HYPOTHESIS" );
2191 }
2192
2193 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
2194 {
2195   return "blsurf_hypo_page.html";
2196 }
2197
2198 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
2199 {
2200
2201   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2202   if( anApp )
2203     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2204   else
2205     return 0;
2206 }
2207
2208