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