Salome HOME
Copyrights update 2015.
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 "BLSURFPluginGUI_Dlg.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 <QApplication>
44 #include <QCheckBox>
45 #include <QComboBox>
46 #include <QFrame>
47 #include <QHBoxLayout>
48 #include <QHeaderView>
49 #include <QGridLayout>
50 #include <QGroupBox>
51 #include <QLabel>
52 #include <QLineEdit>
53 #include <QMenu>
54 #include <QObject>
55 #include <QPushButton>
56 #include <QRadioButton>
57 #include <QSpinBox>
58 #include <QTableWidget>
59 #include <QTabWidget>
60 #include <QVBoxLayout>
61 #include <QSplitter>
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_LifeCycleCORBA.hxx"
73
74 #include <TopoDS_Shape.hxx>
75 #include <TopoDS_Iterator.hxx>
76 #include <SMESH_Gen_i.hxx>
77 #include <boost/shared_ptr.hpp>
78 #include <boost/algorithm/string.hpp>
79 #include <structmember.h>
80 #include <stdexcept>
81 #include <algorithm>
82
83
84 enum {
85   STD_TAB = 0,
86   ADV_TAB,
87   SMP_TAB,
88   ENF_TAB,
89   PERIODICITY_TAB,
90   SMP_NAME_COLUMN =0,
91   SMP_SIZEMAP_COLUMN,
92   SMP_ENTRY_COLUMN,
93 //  SMP_DIST_COLUMN,
94   SMP_NB_COLUMNS,
95 // Enforced vertices array columns
96   ENF_VER_NAME_COLUMN = 0,
97   ENF_VER_FACE_ENTRY_COLUMN,
98   ENF_VER_X_COLUMN,
99   ENF_VER_Y_COLUMN,
100   ENF_VER_Z_COLUMN,
101   ENF_VER_ENTRY_COLUMN,
102   ENF_VER_GROUP_COLUMN,
103   ENF_VER_NB_COLUMNS,
104 // Periodicity
105   PERIODICITY_OBJ_SOURCE_COLUMN = 0,
106   PERIODICITY_OBJ_TARGET_COLUMN,
107   PERIODICITY_P1_SOURCE_COLUMN,
108   PERIODICITY_P2_SOURCE_COLUMN,
109   PERIODICITY_P3_SOURCE_COLUMN,
110   PERIODICITY_P1_TARGET_COLUMN,
111   PERIODICITY_P2_TARGET_COLUMN,
112   PERIODICITY_P3_TARGET_COLUMN,
113   PERIODICITY_SHAPE_TYPE,
114
115 //  PERIODICITY_OBJ_SOURCE_COLUMN = 0,
116 //  PERIODICITY_ENTRY_SOURCE_COLUMN,
117 //  PERIODICITY_OBJ_TARGET_COLUMN,
118 //  PERIODICITY_ENTRY_TARGET_COLUMN,
119 //  PERIODICITY_P1_SOURCE_COLUMN,
120 //  PERIODICITY_P1_ENTRY_SOURCE_COLUMN,
121 //  PERIODICITY_P2_SOURCE_COLUMN,
122 //  PERIODICITY_P2_ENTRY_SOURCE_COLUMN,
123 //  PERIODICITY_P3_SOURCE_COLUMN,
124 //  PERIODICITY_P3_ENTRY_SOURCE_COLUMN,
125 //  PERIODICITY_P1_TARGET_COLUMN,
126 //  PERIODICITY_P1_ENTRY_TARGET_COLUMN,
127 //  PERIODICITY_P2_TARGET_COLUMN,
128 //  PERIODICITY_P2_ENTRY_TARGET_COLUMN,
129 //  PERIODICITY_P3_TARGET_COLUMN,
130 //  PERIODICITY_P3_ENTRY_TARGET_COLUMN,
131
132   PERIODICITY_NB_COLUMN
133 };
134
135 enum {
136   SMP_TAB_WDG,
137   SMP_ADD_BTN,
138   SMP_NB_LINES,
139   SMP_STD_TAB = 0,
140   ATT_TAB,
141   SMP_GEOM_BTN_2 = 0,
142   ATT_CHECK,
143   CONST_SIZE_CHECK,
144   SMP_SPACE,
145 //   SMP_PARAMS,
146   SMP_ATT_SHAPE, 
147   SMP_ATT_SIZE,
148   SMP_ATT_DIST,
149   SMP_ATT_RAD
150 };
151   
152 enum {
153   SMP_GEOM_BTN_1,
154   SMP_SIZE,
155   SMP_SPACE2,
156 };
157
158 // Enforced vertices inputs
159 enum {
160   ENF_VER_FACE = 0,
161   ENF_VER_VERTEX,
162   ENF_VER_X_COORD,
163   ENF_VER_Y_COORD,
164   ENF_VER_Z_COORD,
165   ENF_VER_GROUP,
166 //   ENF_VER_GROUP_CHECK,
167 //   ENF_VER_SPACE,
168   ENF_VER_BTN,
169   ENF_VER_SEPARATOR,
170   ENF_VER_INTERNAL_ALL_FACES,
171   ENF_VER_INTERNAL_ALL_FACES_GROUP,
172 //   ENF_VER_VERTEX_BTN,
173 //   ENF_VER_REMOVE_BTN,
174 //   ENF_VER_SEPARATOR,
175   ENF_VER_NB_LINES
176 };
177
178
179 /**************************************************
180  Begin initialization Python structures and objects
181 ***************************************************/
182
183 typedef struct {
184   PyObject_HEAD
185   int softspace;
186   std::string *out;
187   } PyStdOut;
188
189 static void
190 PyStdOut_dealloc(PyStdOut *self)
191 {
192   PyObject_Del(self);
193 }
194
195 static PyObject *
196 PyStdOut_write(PyStdOut *self, PyObject *args)
197 {
198   char *c;
199   int l;
200   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
201     return NULL;
202
203   //std::cerr << c ;
204   *(self->out)=*(self->out)+c;
205
206   Py_INCREF(Py_None);
207   return Py_None;
208 }
209
210 static PyMethodDef PyStdOut_methods[] = { 
211   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
212   PyDoc_STR("write(string) -> None")},
213   {NULL,    NULL}   /* sentinel */
214 };
215
216 static PyMemberDef PyStdOut_memberlist[] = {
217   {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
218    (char*)"flag indicating that a space needs to be printed; used by print"},
219   {NULL} /* Sentinel */
220 };
221
222 static PyTypeObject PyStdOut_Type = {
223   /* The ob_type field must be initialized in the module init function
224    * to be portable to Windows without using C++. */
225   PyObject_HEAD_INIT(NULL)
226   0,                            /*ob_size*/
227   "PyOut",                      /*tp_name*/
228   sizeof(PyStdOut),             /*tp_basicsize*/
229   0,                            /*tp_itemsize*/
230   /* methods */
231   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
232   0,                            /*tp_print*/
233   0,                            /*tp_getattr*/
234   0,                            /*tp_setattr*/
235   0,                            /*tp_compare*/
236   0,                            /*tp_repr*/
237   0,                            /*tp_as_number*/
238   0,                            /*tp_as_sequence*/
239   0,                            /*tp_as_mapping*/
240   0,                            /*tp_hash*/
241   0,                            /*tp_call*/
242   0,                            /*tp_str*/
243   PyObject_GenericGetAttr,      /*tp_getattro*/
244   /* softspace is writable:  we must supply tp_setattro */
245   PyObject_GenericSetAttr,      /* tp_setattro */
246   0,                            /*tp_as_buffer*/
247   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
248   0,                            /*tp_doc*/
249   0,                            /*tp_traverse*/
250   0,                            /*tp_clear*/
251   0,                            /*tp_richcompare*/
252   0,                            /*tp_weaklistoffset*/
253   0,                            /*tp_iter*/
254   0,                            /*tp_iternext*/
255   PyStdOut_methods,             /*tp_methods*/
256   PyStdOut_memberlist,          /*tp_members*/
257   0,                            /*tp_getset*/
258   0,                            /*tp_base*/
259   0,                            /*tp_dict*/
260   0,                            /*tp_descr_get*/
261   0,                            /*tp_descr_set*/
262   0,                            /*tp_dictoffset*/
263   0,                            /*tp_init*/
264   0,                            /*tp_alloc*/
265   0,                            /*tp_new*/
266   0,                            /*tp_free*/
267   0,                            /*tp_is_gc*/
268 };
269
270 PyObject * newPyStdOut( std::string& out )
271 {
272   PyStdOut *self;
273   self = PyObject_New(PyStdOut, &PyStdOut_Type);
274   if (self == NULL)
275     return NULL;
276   self->softspace = 0;
277   self->out=&out;
278   return (PyObject*)self;
279 }
280
281 /*************************************************
282 End initialization Python structures and objects
283 **************************************************/
284
285
286 //
287 // BEGIN EnforcedTreeWidgetDelegate
288 //
289
290 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
291   : QItemDelegate(parent)
292 {
293 }
294
295 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
296                                               const QStyleOptionViewItem & option ,
297                                               const QModelIndex & index ) const
298 {
299   QModelIndex father = index.parent();
300   QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
301   
302   if (index.column() == ENF_VER_X_COLUMN || \
303       index.column() == ENF_VER_Y_COLUMN || \
304       index.column() == ENF_VER_Z_COLUMN)
305   {
306     SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
307     editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
308     editor->setReadOnly(!entry.isEmpty());
309     editor->setDisabled(!entry.isEmpty());
310     return editor;
311   }
312   else
313   {
314     QLineEdit *editor = new QLineEdit(parent);
315     if (index.column() != ENF_VER_GROUP_COLUMN) {
316       editor->setReadOnly(!entry.isEmpty());
317       editor->setDisabled(!entry.isEmpty());
318     }
319     return editor;
320   }
321 }
322
323 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
324                                            const QModelIndex &index) const
325 {
326   QString value = index.model()->data(index, Qt::EditRole).toString();
327
328   if (index.column() == ENF_VER_X_COLUMN ||
329       index.column() == ENF_VER_Y_COLUMN ||
330       index.column() == ENF_VER_Z_COLUMN)
331   {
332     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
333     lineEdit->setText(value);
334   }
335   else {
336     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
337     lineEdit->setText(value);
338   }
339 }
340
341 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
342                                           const QModelIndex &index) const
343 {
344   QModelIndex parent = index.parent();
345   QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
346   if (index.column() == ENF_VER_X_COLUMN || index.column() == ENF_VER_Y_COLUMN || index.column() == ENF_VER_Z_COLUMN) {
347     SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
348     if (entry.isEmpty() && !vertexExists(model, index, lineEdit->GetString()))
349       model->setData(index, lineEdit->GetValue(), Qt::EditRole);
350   } else if (index.column() == ENF_VER_NAME_COLUMN) {
351     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
352     QString value = lineEdit->text();
353     if (entry.isEmpty() && !vertexExists(model, index, value))
354       model->setData(index, value, Qt::EditRole);
355   } else if (index.column() == ENF_VER_ENTRY_COLUMN) {
356     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
357     QString value = lineEdit->text();
358     if (!vertexExists(model, index, value))
359       model->setData(index, value, Qt::EditRole);
360   } else if (index.column() == ENF_VER_GROUP_COLUMN) {
361     QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
362     model->setData(index, lineEdit->text(), Qt::EditRole);
363   }
364 }
365
366 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
367     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
368 {
369   editor->setGeometry(option.rect);
370 }
371
372 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
373     const QModelIndex &index, QString value) const
374 {
375   bool exists = false;
376   QModelIndex parent = index.parent();
377   int row = index.row();
378   int col = index.column();
379
380   if (parent.isValid() && !value.isEmpty()) {
381     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
382       double x, y, z;
383       if (col == ENF_VER_X_COLUMN) {
384         x = value.toDouble();
385         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
386         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
387       }
388       if (col == ENF_VER_Y_COLUMN) {
389         y = value.toDouble();
390         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
391         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
392       }
393       if (col == ENF_VER_Z_COLUMN) {
394         z = value.toDouble();
395         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
396         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
397       }
398       int nbChildren = model->rowCount(parent);
399       for (int i = 0 ; i < nbChildren ; i++) {
400         if (i != row) {
401           double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
402           double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
403           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
404           if ((childX == x) && (childY == y) && (childZ == z)) {
405             exists = true;
406             break;
407           }
408         }
409       }
410     }
411     else if (col == ENF_VER_NAME_COLUMN) {
412       int nbChildren = model->rowCount(parent);
413       for (int i = 0 ; i < nbChildren ; i++) {
414         if (i != row) {
415           QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
416           if (childName == value) {
417             exists = true;
418             break;
419           }
420         }
421       }
422     }
423   }
424
425   return exists;
426 }
427
428 //
429 // END EnforcedTreeWidgetDelegate
430 //
431
432
433 /**
434  * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
435  * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
436  *
437  * */
438 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
439   : SMESHGUI_GenericHypothesisCreator( theHypType )
440 {
441   MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
442   this->mySMPMap.clear();
443
444   GeomToolSelected = NULL;
445   GeomToolSelected = getGeomSelectionTool();
446
447   aSel = GeomToolSelected->selectionMgr();
448
449   /* Initialize the Python interpreter */
450   if (! Py_IsInitialized())
451     throw ("Error: Python interpreter is not initialized");
452   PyGILState_STATE gstate;
453   gstate = PyGILState_Ensure();
454
455   main_mod = NULL;
456   main_mod = PyImport_AddModule("__main__");
457
458   main_dict = NULL;
459   main_dict = PyModule_GetDict(main_mod);
460
461   PyRun_SimpleString("from math import *");
462   PyGILState_Release(gstate);
463
464 }
465
466 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
467 {
468 }
469
470 /**
471  * \brief {Get or create the geom selection tool for active study}
472  * */
473 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool() const
474 {
475   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
476   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
477   if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
478     that->GeomToolSelected = new GeomSelectionTools(aStudy);
479   }
480   return that->GeomToolSelected;
481 }
482
483 GEOM::GEOM_Gen_var BLSURFPluginGUI_HypothesisCreator::getGeomEngine()
484 {
485   return GeometryGUI::GetGeomGen();
486 }
487
488 void BLSURFPluginGUI_HypothesisCreator::avoidSimultaneousSelection(ListOfWidgets &selectionWidgets) const
489 {
490   StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
491   ListOfWidgets::const_iterator anIt = selectionWidgets.begin();
492   for ( ; anIt != selectionWidgets.end(); anIt++)
493     {
494       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
495         {
496           StdMeshersGUI_ObjectReferenceParamWdg * w1 =
497               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
498           ListOfWidgets::const_iterator anIt2 = anIt;
499           for ( ++anIt2; anIt2 != selectionWidgets.end(); anIt2++)
500             if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
501               {
502                 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
503                     ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
504                 w1->AvoidSimultaneousSelection( w2 );
505               }
506           if ( !widgetToActivate )
507             widgetToActivate = w1;
508         }
509     }
510   if ( widgetToActivate )
511     widgetToActivate->activateSelection();
512 }
513
514 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
515 {
516   MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
517   bool ok = true;
518
519   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
520     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
521
522   if ( ok )
523   {
524     myAdvWidget->myOptionTable->setFocus();
525     QApplication::instance()->processEvents();
526
527     int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
528     for ( ; row < nbRows; ++row )
529     {
530       QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
531       QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
532       if ( !value.isEmpty() ) {
533         try {
534           QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().trimmed();
535           if (optionType == "PRECAD")
536             h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
537           else if (optionType == "BLSURF")
538             h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
539         }
540         catch ( const SALOME::SALOME_Exception& ex )
541         {
542           msg = ex.details.text.in();
543           ok = false;
544         }
545       }
546     }
547   }
548   if ( !ok )
549   {
550     h->SetOptionValues( myOptions ); // restore values
551     h->SetPreCADOptionValues( myPreCADOptions ); // restore values
552   }
553
554   // SizeMap and attractors
555   if ( ok )
556   {
557     mySizeMapTable->setFocus();
558     QApplication::instance()->processEvents();
559
560     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
561     int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
562     std::string e, s;
563     for ( ; row < nbRows; ++row )
564     {
565       QString entry   = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
566       QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
567       MESSAGE("entry ="<<entry.toStdString())
568       if ( !sizeMap.isEmpty() ) {
569         if (that->sizeMapValidationFromRow(row))
570         {
571           try {
572             MESSAGE("entry ="<<entry.toStdString())
573             MESSAGE("sizeMap ="<<sizeMap.toStdString())
574             
575             e = entry.toStdString();
576             s = that->mySMPMap[entry].toStdString();
577             MESSAGE("row = "<<row)
578             MESSAGE("e = "<<e)
579             MESSAGE("s = "<<s)
580             h->SetSizeMapEntry( e.c_str(), s.c_str() );
581           }
582           catch ( const SALOME::SALOME_Exception& ex )
583           {
584             msg = ex.details.text.in();
585             ok = false;
586           }
587         }
588         else {
589           ok = false;
590         }
591       }
592     }
593   }
594
595   // 22207: BLSURFPLUGIN: The user is allowed to enter 0 as a global or local size.
596   if ( ok )
597   {
598     // In case if not STD_TAB is current tab, then text() of empty spinboxes returns "0" value.
599     // So STD_TAB must be current tab to get correct value of it's spinbox.
600     myTabWidget->setCurrentIndex( STD_TAB );
601   }
602   if ( ok )
603   {
604     if ( !( ok = ( myStdWidget->myPhySize->text().isEmpty() ||
605                    myStdWidget->myPhySize->text().toDouble() > 0.0 )))
606       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_HPHYDEF"));
607   }
608   if ( ok )
609   {
610     if ( !( ok = ( myStdWidget->myMaxSize->text().isEmpty() ||
611                    myStdWidget->myMaxSize->text().toDouble() > 0.0 )))
612       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_MAXSIZE"));
613   }
614   if ( ok )
615   {
616     if ( !( ok = ( myStdWidget->myAngleMesh->text().isEmpty() ||
617                    myStdWidget->myAngleMesh->text().toDouble() > 0.0 )))
618       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_ANGLE_MESH"));
619   }
620   if ( ok )
621   {
622     if ( !( ok = ( myStdWidget->myChordalError->text().isEmpty() ||
623                    myStdWidget->myChordalError->text().toDouble() > 0.0 )))
624       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_CHORDAL_ERROR"));
625   }
626
627   // Enforced vertices
628   // TODO
629
630   return ok;
631 }
632
633 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
634 {
635   MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
636
637   QFrame* fr = new QFrame( 0 );
638  // fr-> setMinimumSize(600,400);
639   QVBoxLayout* lay = new QVBoxLayout( fr );
640  // lay->setSizeConstraint(QLayout::SetDefaultConstraint);
641   lay->setMargin( 5 );
642   lay->setSpacing( 0 );
643
644   // main TabWidget of the dialog
645   myTabWidget = new QTabWidget( fr );
646   myTabWidget->setTabShape( QTabWidget::Rounded );
647   myTabWidget->setTabPosition( QTabWidget::North );
648   lay->addWidget( myTabWidget );
649
650   myName = 0;
651   
652   // basic parameters
653   myStdGroup = new QWidget();
654   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
655   aStdLayout->setSpacing( 6 );
656   aStdLayout->setMargin( 11 );
657   
658   if( isCreation() )
659     myName = new QLineEdit( myStdGroup );
660   myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
661   
662   int row = 0;
663   if( isCreation() ) {
664     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ),    0, 0, 1, 1 );
665     aStdLayout->addWidget( myName,                                      row++, 1, 1, 3 );
666   }
667   aStdLayout->addWidget( myStdWidget,                                   row++, 0, 1, 4 );
668   
669   int maxrow = row;
670   row = 0;
671   if( isCreation() )
672     row = 1;
673 //   row = max(row,maxrow)+1;
674   aStdLayout->setRowStretch(row,1);
675   aStdLayout->setColumnStretch(1,1);
676   maxrow = row;
677
678   
679   // advanced parameters
680   myAdvGroup = new QWidget();
681   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
682   anAdvLayout->setSpacing( 6 );
683   anAdvLayout->setMargin( 11 );  
684   myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
685   myAdvWidget->addBtn->setMenu( new QMenu() );
686   anAdvLayout->addWidget( myAdvWidget);
687
688
689   // Size Maps parameters
690
691   mySmpGroup = new QWidget();
692 //   mySmpGroup->setMinimumWidth(500);
693
694   //Layout
695   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
696   
697   // Table
698   mySizeMapTable = new QTreeWidget( mySmpGroup );
699   mySizeMapTable ->setMinimumWidth(200);
700   QStringList sizeMapHeaders;
701   sizeMapHeaders << tr( "SMP_NAME_COLUMN" )<< tr( "SMP_SIZEMAP_COLUMN" )<< tr( "SMP_ENTRY_COLUMN" );// << tr( "SMP_DIST_COLUMN" );
702   mySizeMapTable->setHeaderLabels(sizeMapHeaders);
703   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
704   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
705   mySizeMapTable->hideColumn(SMP_ENTRY_COLUMN);
706   mySizeMapTable->setAlternatingRowColors(true);
707   
708   // tab widget
709   smpTab = new QTabWidget( mySmpGroup );
710   smpTab->setTabShape( QTabWidget::Rounded );
711   smpTab->setTabPosition( QTabWidget::South );
712   lay->addWidget( smpTab );
713   
714   // Filters of selection
715   TColStd_MapOfInteger SM_ShapeTypes, ATT_ShapeTypes;
716   
717   SM_ShapeTypes.Add( TopAbs_VERTEX );
718   SM_ShapeTypes.Add( TopAbs_EDGE );
719   SM_ShapeTypes.Add( TopAbs_FACE );
720   SM_ShapeTypes.Add( TopAbs_COMPOUND );
721   
722   ATT_ShapeTypes.Add( TopAbs_VERTEX );
723   ATT_ShapeTypes.Add( TopAbs_EDGE );
724   ATT_ShapeTypes.Add( TopAbs_WIRE );
725   ATT_ShapeTypes.Add( TopAbs_COMPOUND );
726   
727   SMESH_NumberFilter* myFilter1 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
728   SMESH_NumberFilter* myFilter2 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, ATT_ShapeTypes);
729   SMESH_NumberFilter* myFilter3 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, TopAbs_FACE);
730   
731   // Standard size map tab
732   mySmpStdGroup = new QWidget();
733   QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
734   myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false,/*stretch=*/false);
735   myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
736   mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
737   mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
738   QLabel* mySmpSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),mySmpStdGroup);
739   
740   // Attractor tab
741   myAttractorGroup = new QWidget();
742   QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
743   myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false,/*stretch=*/false);
744   myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
745   myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
746   myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
747   myConstSizeCheck = new QCheckBox(tr("BLSURF_CONST_SIZE"),myAttractorGroup);
748   QFrame* attLine  = new QFrame(myAttractorGroup);
749   attLine->setFrameShape(QFrame::HLine);
750   attLine->setFrameShadow(QFrame::Sunken);
751   myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false,/*stretch=*/false);
752   myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }"); 
753   myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
754   myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
755   myAttSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),myAttractorGroup);
756   myAttDistSpin = new SMESHGUI_SpinBox(myAttractorGroup);
757   myAttDistSpin->RangeStepAndValidator(0., COORD_MAX, 10.0, "length_precision");
758   myAttDistLabel = new QLabel(tr("BLSURF_ATT_DIST"),myAttractorGroup);
759   myAttDistSpin2 = new SMESHGUI_SpinBox(myAttractorGroup);
760   myAttDistSpin2->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
761   myAttDistLabel2 = new QLabel(tr("BLSURF_ATT_RADIUS"),myAttractorGroup);
762   
763   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
764   myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
765   
766   // Push buttons
767   
768   addMapButton = new QPushButton(tr("BLSURF_SM_ADD"),mySmpGroup);
769   removeMapButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
770   modifyMapButton = new QPushButton(tr("BLSURF_SM_MODIFY"),mySmpGroup);
771   modifyMapButton->setEnabled(false);
772   
773   // Init SpinBoxes
774   myAttSelWdg->setEnabled(false);
775   myAttSizeSpin->setEnabled(false);
776   myAttSizeLabel->setEnabled(false);
777   myAttDistSpin->setEnabled(false);
778   myAttDistLabel->setEnabled(false);
779   myAttDistSpin2->setEnabled(false);
780   myAttDistLabel2->setEnabled(false);
781   myAttDistSpin->setValue(0.);
782   myAttDistSpin2->setValue(0.);
783   myAttSizeSpin->setValue(0.);
784   mySmpSizeSpin->setValue(0.);
785
786   
787   // ADD WIDGETS (SIZEMAP TAB)
788   anSmpLayout->addWidget(mySizeMapTable,     0,  0, SMP_NB_LINES, 1);
789   anSmpLayout->setColumnStretch(0, 1);
790 //  anSmpLayout->addWidget(line2,              SMP_SEPARATOR2, 1, 2, 2);
791   anSmpLayout->addWidget(smpTab,             SMP_TAB_WDG,     1, 1, 3);
792   anSmpLayout->setRowStretch(SMP_TAB_WDG, 1);
793   anSmpLayout->addWidget(addMapButton,       SMP_ADD_BTN,     1, 1, 1);
794   anSmpLayout->addWidget(removeMapButton,    SMP_ADD_BTN,     2, 1, 1);
795   anSmpLayout->addWidget(modifyMapButton,    SMP_ADD_BTN,     3, 1, 1);
796   
797   // STANDARD TAB
798   anSmpStdLayout->addWidget(myGeomSelWdg1,   SMP_GEOM_BTN_1,  1, 1, 2);
799   anSmpStdLayout->addWidget(mySmpSizeLabel,  SMP_SIZE,        1, 1, 1);
800   anSmpStdLayout->addWidget(mySmpSizeSpin,   SMP_SIZE,        2, 1, 1);
801   anSmpStdLayout->setRowStretch(SMP_SPACE2, 1);
802   
803   // ADVANCED TAB
804   anAttLayout->addWidget(myGeomSelWdg2,      SMP_GEOM_BTN_2,  1, 1, 2);
805   anAttLayout->addWidget(myAttractorCheck,   ATT_CHECK,       1, 1, 2);
806   anAttLayout->addWidget(myConstSizeCheck,   CONST_SIZE_CHECK,1, 1, 2);
807   anAttLayout->addWidget(attLine,            SMP_SPACE,       1, 1, 2);
808   anAttLayout->addWidget(myAttSelWdg,        SMP_ATT_SHAPE,   1, 1, 2);
809   anAttLayout->addWidget(myAttSizeLabel,     SMP_ATT_SIZE,    1, 1, 1);
810   anAttLayout->addWidget(myAttSizeSpin,      SMP_ATT_SIZE,    2, 1, 1);
811   anAttLayout->addWidget(myAttDistLabel,     SMP_ATT_DIST,    1, 1, 1);
812   anAttLayout->addWidget(myAttDistSpin,      SMP_ATT_DIST,    2, 1, 1);
813   anAttLayout->addWidget(myAttDistLabel2,    SMP_ATT_RAD,     1, 1, 1);
814   anAttLayout->addWidget(myAttDistSpin2,     SMP_ATT_RAD,     2, 1, 1);
815   anAttLayout->setRowStretch(SMP_ATT_RAD+1, 1);
816   
817   smpTab->insertTab( SMP_STD_TAB, mySmpStdGroup, tr( "BLSURF_SM_STD_TAB" ) );
818   smpTab->insertTab( ATT_TAB, myAttractorGroup, tr( "BLSURF_SM_ATT_TAB" ) );
819
820   smpTab->setCurrentIndex( SMP_STD_TAB ); 
821
822   // Enforced vertices parameters
823   myEnfGroup = new QWidget();
824   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
825 //
826 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
827 //   anEnfLayout->addWidget(myEnforcedVertexWidget);
828 //   MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
829 //   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
830
831   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
832   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
833   myEnforcedTreeWidget->setSortingEnabled(true);
834   QStringList enforcedHeaders;
835   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_FACE_ENTRY_COLUMN")
836                   << tr("BLSURF_ENF_VER_X_COLUMN")<< tr("BLSURF_ENF_VER_Y_COLUMN") << tr("BLSURF_ENF_VER_Z_COLUMN")
837                   << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
838
839   myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
840   myEnforcedTreeWidget->header()->setStretchLastSection(true);
841   myEnforcedTreeWidget->setAlternatingRowColors(true);
842   myEnforcedTreeWidget->setUniformRowHeights(true);
843   myEnforcedTreeWidget->setAnimated(true);
844   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
845   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
846   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
847     myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
848     myEnforcedTreeWidget->resizeColumnToContents(column);
849   }
850   myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
851   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
852   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
853   
854 // FACE AND VERTEX SELECTION
855   TColStd_MapOfInteger shapeTypes1, shapeTypes2;
856   shapeTypes1.Add( TopAbs_FACE );
857   shapeTypes1.Add( TopAbs_COMPOUND );
858   shapeTypes2.Add( TopAbs_VERTEX );
859   shapeTypes2.Add( TopAbs_COMPOUND );
860
861   SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
862   myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true, /*stretch=*/false);
863   myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
864
865   SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
866   myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false);
867   myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
868
869   myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
870
871   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
872   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
873   myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
874
875   QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
876   myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
877   myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
878
879   QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
880   myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
881   myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
882
883   QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
884   myGroupName = new QLineEdit(myEnfGroup);
885
886   addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
887   removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
888
889   myInternalEnforcedVerticesAllFaces = new QCheckBox(tr("BLSURF_ENF_VER_INTERNAL_VERTICES"),myEnfGroup);
890
891   QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
892   myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
893
894 //   myGlobalGroupName = new QCheckBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
895 //   myGlobalGroupName->setChecked(false);
896
897   anEnfLayout->addWidget(myEnforcedTreeWidget,     0, 0, ENF_VER_NB_LINES, 1);
898   QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
899 //  FACE AND VERTEX SELECTION
900   anEnfLayout2->addWidget(myEnfFaceWdg,             ENF_VER_FACE, 0, 1, 2);
901   anEnfLayout2->addWidget(myEnfVertexWdg,           ENF_VER_VERTEX, 0, 1, 2);
902   anEnfLayout2->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 0, 1, 1);
903   anEnfLayout2->addWidget(myXCoord,                 ENF_VER_X_COORD, 1, 1, 1);
904   anEnfLayout2->addWidget(myYCoordLabel,            ENF_VER_Y_COORD, 0, 1, 1);
905   anEnfLayout2->addWidget(myYCoord,                 ENF_VER_Y_COORD, 1, 1, 1);
906   anEnfLayout2->addWidget(myZCoordLabel,            ENF_VER_Z_COORD, 0, 1, 1);
907   anEnfLayout2->addWidget(myZCoord,                 ENF_VER_Z_COORD, 1, 1, 1);
908   anEnfLayout2->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 0, 1, 1);
909   anEnfLayout2->addWidget(myGroupName,              ENF_VER_GROUP, 1, 1, 1);
910 //   anEnfLayout2->addWidget(myGlobalGroupName,        ENF_VER_GROUP_CHECK, 0, 1, 2);
911 //   anEnfLayout2->setRowStretch(                      ENF_VER_SPACE, 1);
912   anEnfLayout2->addWidget(addVertexButton,          ENF_VER_BTN, 0, 1, 1);
913   anEnfLayout2->addWidget(removeVertexButton,       ENF_VER_BTN, 1, 1, 1);
914   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
915   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
916   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
917   anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
918 //   anEnfLayout2->addWidget(makeGroupsCheck,          ENF_VER_GROUP_CHECK, 0, 1, 2);
919   anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
920 //   anEnfLayout->setRowStretch(1, 1);
921
922   // ---
923   // Periodicity parameters
924   myPeriodicityGroup = new QWidget();
925   aPeriodicityLayout1 = new QGridLayout(myPeriodicityGroup);
926
927   myPeriodicitySplitter = new QSplitter(myPeriodicityGroup);
928   myPeriodicitySplitter->setOrientation(Qt::Horizontal);
929   aPeriodicityLayout1->addWidget(myPeriodicitySplitter, 0, 0, 1, 1);
930
931   myPeriodicityTreeWidget = new QTreeWidget(myPeriodicitySplitter);
932
933   QStringList myPeriodicityTreeHeaders;
934   myPeriodicityTreeHeaders << tr("BLSURF_PERIODICITY_OBJ_SOURCE_COLUMN")
935                            << tr("BLSURF_PERIODICITY_OBJ_TARGET_COLUMN")
936                            << tr("BLSURF_PERIODICITY_P1_SOURCE_COLUMN")
937                            << tr("BLSURF_PERIODICITY_P2_SOURCE_COLUMN")
938                            << tr("BLSURF_PERIODICITY_P3_SOURCE_COLUMN")
939                            << tr("BLSURF_PERIODICITY_P1_TARGET_COLUMN")
940                            << tr("BLSURF_PERIODICITY_P2_TARGET_COLUMN")
941                            << tr("BLSURF_PERIODICITY_P3_TARGET_COLUMN")
942                            << tr("BLSURF_PERIODICITY_SHAPE_TYPE");
943   myPeriodicityTreeWidget->setHeaderLabels(myPeriodicityTreeHeaders);
944
945   // Hide the vertex name to make the widget more readable
946   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P1_SOURCE_COLUMN);
947   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P2_SOURCE_COLUMN);
948   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P3_SOURCE_COLUMN);
949   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P1_TARGET_COLUMN);
950   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P2_TARGET_COLUMN);
951   myPeriodicityTreeWidget->hideColumn(PERIODICITY_P3_TARGET_COLUMN);
952   myPeriodicityTreeWidget->hideColumn(PERIODICITY_SHAPE_TYPE);
953
954
955   myPeriodicityTreeWidget->setColumnCount(PERIODICITY_NB_COLUMN);
956   myPeriodicityTreeWidget->setSortingEnabled(true);
957
958   myPeriodicityTreeWidget->setAlternatingRowColors(true);
959   myPeriodicityTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
960   myPeriodicityTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
961   
962   int periodicityVisibleColumns = 2;
963   for (size_t column = 0; column < periodicityVisibleColumns; ++column) {
964       myPeriodicityTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
965       myPeriodicityTreeWidget->resizeColumnToContents(column);
966   }
967   myPeriodicityTreeWidget->header()->setStretchLastSection(true);
968
969   myPeriodicitySplitter->addWidget(myPeriodicityTreeWidget);
970
971   myPeriodicityRightWidget = new QWidget(myPeriodicitySplitter);
972
973   myPeriodicityRightGridLayout = new QGridLayout(myPeriodicityRightWidget);
974   myPeriodicityGroupBox1 = new QGroupBox(tr("BLSURF_PRECAD_PERIODICITY"), myPeriodicityRightWidget);
975   myPeriodicityGroupBox1Layout = new QGridLayout(myPeriodicityGroupBox1);
976
977   myPeriodicityRightGridLayout->addWidget(myPeriodicityGroupBox1, 0, 0, 1, 2);
978
979   myPeriodicityOnFaceRadioButton = new QRadioButton(tr("BLSURF_PERIODICITY_ON_FACE"), myPeriodicityGroupBox1);
980   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityOnFaceRadioButton, 0, 0, 1, 2);
981
982   myPeriodicityOnFaceRadioButton->setChecked(true);
983
984   myPeriodicityOnEdgeRadioButton = new QRadioButton(tr("BLSURF_PERIODICITY_ON_EDGE"), myPeriodicityGroupBox1);
985   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityOnEdgeRadioButton, 0, 2, 1, 2);
986
987
988   // FACE, EDGE AND VERTEX SELECTION
989   TColStd_MapOfInteger shapeTypesFace, shapeTypesEdge;
990   shapeTypesFace.Add( TopAbs_FACE );
991   shapeTypesFace.Add( TopAbs_EDGE );
992   shapeTypesFace.Add( TopAbs_COMPOUND );
993   shapeTypesEdge.Add( TopAbs_EDGE );
994   shapeTypesEdge.Add( TopAbs_COMPOUND );
995
996 //  myPeriodicityEdgeFilter = new SMESH_NumberFilter("GEOM", TopAbs_EDGE, 0, shapeTypesEdge);
997
998   myPeriodicityMainSourceLabel = new QLabel(tr("BLSURF_PERIODICITY_MAIN_SOURCE"), myPeriodicityGroupBox1);
999   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainSourceLabel, 1, 0, 1, 1);
1000
1001   SMESH_NumberFilter* myPeriodicitySourceFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
1002   myPeriodicitySourceFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicitySourceFaceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1003 //  myPeriodicitySourceFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
1004   myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceFaceWdg, 1, 1, 1, 1);
1005
1006 //  myPeriodicitySourceEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1007 //  myPeriodicitySourceEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
1008 //  myPeriodicitySourceEdgeWdg->hide();
1009 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceEdgeWdg, 1, 1, 1, 1);
1010
1011   myPeriodicityMainTargetLabel = new QLabel(tr("BLSURF_PERIODICITY_MAIN_TARGET"), myPeriodicityGroupBox1);
1012   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainTargetLabel, 1, 2, 1, 1);
1013
1014   SMESH_NumberFilter* myPeriodicityTargetFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
1015   myPeriodicityTargetFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityTargetFaceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1016 //  myPeriodicityTargetFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
1017   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetFaceWdg, 1, 3, 1, 1);
1018
1019 //  myPeriodicityTargetEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1020 //  myPeriodicityTargetEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
1021 //  myPeriodicityTargetEdgeWdg->hide();
1022 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetEdgeWdg, 1, 3, 1, 1);
1023
1024   myPeriodicityGroupBox2 = new QGroupBox(tr("BLSURF_PERIODICITY_WITH_VERTICES"), myPeriodicityRightWidget);
1025   myPeriodicityGroupBox2Layout = new QGridLayout(myPeriodicityGroupBox2);
1026   myPeriodicityRightGridLayout->addWidget(myPeriodicityGroupBox2, 1, 0, 1, 2);
1027
1028   myPeriodicityGroupBox2->setCheckable(true);
1029   myPeriodicityGroupBox2->setChecked(false);
1030
1031   myPeriodicitySourceLabel = new QLabel(tr("BLSURF_PERIODICITY_SOURCE"), myPeriodicityGroupBox2);
1032   myPeriodicityGroupBox2Layout->addWidget(myPeriodicitySourceLabel, 0, 0, 1, 2);
1033
1034   myPeriodicityTargetLabel = new QLabel(tr("BLSURF_PERIODICITY_TARGET"), myPeriodicityGroupBox2);
1035   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityTargetLabel, 0, 2, 1, 2);
1036
1037   // P1
1038   myPeriodicityP1SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P1_SOURCE"), myPeriodicityGroupBox2);
1039   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1SourceLabel, 1, 0, 1, 1);
1040
1041
1042   SMESH_NumberFilter* myPeriodicityP1SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1043   myPeriodicityP1SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1044   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1SourceWdg, 1, 1, 1, 1);
1045
1046   // P2
1047   myPeriodicityP2SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P2_SOURCE"), myPeriodicityGroupBox2);
1048   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceLabel, 2, 0, 1, 1);
1049
1050   SMESH_NumberFilter* myPeriodicityP2SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1051   myPeriodicityP2SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1052   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceWdg, 2, 1, 1, 1);
1053
1054   // P3
1055   myPeriodicityP3SourceLabel = new QLabel(tr("BLSURF_PERIODICITY_P3_SOURCE"), myPeriodicityGroupBox2);
1056   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceLabel, 3, 0, 1, 1);
1057
1058   SMESH_NumberFilter* myPeriodicityP3SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1059   myPeriodicityP3SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1060   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceWdg, 3, 1, 1, 1);
1061
1062   // P1
1063   myPeriodicityP1TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P1_TARGET"), myPeriodicityGroupBox2);
1064   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetLabel, 1, 2, 1, 1);
1065
1066   SMESH_NumberFilter* myPeriodicityP1TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1067   myPeriodicityP1TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1068   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetWdg, 1, 3, 1, 1);
1069
1070   // P2
1071   myPeriodicityP2TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P2_TARGET"), myPeriodicityGroupBox2);
1072   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetLabel, 2, 2, 1, 1);
1073
1074   SMESH_NumberFilter* myPeriodicityP2TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1075   myPeriodicityP2TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1076   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetWdg, 2, 3, 1, 1);
1077
1078   // P3
1079   myPeriodicityP3TargetLabel = new QLabel(tr("BLSURF_PERIODICITY_P3_TARGET"), myPeriodicityGroupBox2);
1080   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetLabel, 3, 2, 1, 1);
1081
1082   SMESH_NumberFilter* myPeriodicityP3TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
1083   myPeriodicityP3TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
1084   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetWdg, 3, 3, 1, 1);
1085
1086   myPeriodicityVerticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
1087   myPeriodicityGroupBox2Layout->addItem(myPeriodicityVerticalSpacer, 7, 1, 1, 1);
1088
1089
1090   myPeriodicityAddButton = new QPushButton(tr("BLSURF_PERIODICITY_ADD"),myPeriodicityRightWidget);
1091   myPeriodicityRightGridLayout->addWidget(myPeriodicityAddButton, 2, 0, 1, 1);
1092
1093   myPeriodicityRemoveButton = new QPushButton(tr("BLSURF_PERIODICITY_REMOVE"),myPeriodicityRightWidget);
1094   myPeriodicityRightGridLayout->addWidget(myPeriodicityRemoveButton, 2, 1, 1, 1);
1095
1096   myPeriodicitySplitter->addWidget(myPeriodicityRightWidget);
1097
1098   myPeriodicitySelectionWidgets.clear();
1099   myPeriodicitySelectionWidgets.append(myPeriodicitySourceFaceWdg);
1100   myPeriodicitySelectionWidgets.append(myPeriodicityTargetFaceWdg);
1101   myPeriodicitySelectionWidgets.append(myPeriodicityP1SourceWdg);
1102   myPeriodicitySelectionWidgets.append(myPeriodicityP2SourceWdg);
1103   myPeriodicitySelectionWidgets.append(myPeriodicityP3SourceWdg);
1104   myPeriodicitySelectionWidgets.append(myPeriodicityP1TargetWdg);
1105   myPeriodicitySelectionWidgets.append(myPeriodicityP2TargetWdg);
1106   myPeriodicitySelectionWidgets.append(myPeriodicityP3TargetWdg);
1107   avoidSimultaneousSelection(myPeriodicitySelectionWidgets);
1108
1109   // ---
1110   myTabWidget->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
1111   myTabWidget->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
1112   myTabWidget->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
1113   myTabWidget->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
1114   myTabWidget->insertTab( PERIODICITY_TAB, myPeriodicityGroup, tr( "BLSURF_PERIODICITY" ) );
1115
1116   myTabWidget->setCurrentIndex( STD_TAB );
1117
1118   connect( myAdvWidget->addBtn->menu(), SIGNAL( aboutToShow() ),         this, SLOT( onAddOption() ) );
1119   connect( myAdvWidget->addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
1120   connect( myAdvWidget->rmBtn,          SIGNAL( clicked()),              this, SLOT( onDeleteOption() ) );
1121   connect( myStdWidget->myAllowQuadrangles, SIGNAL( stateChanged( int )),this, SLOT( onStateChange() ));
1122
1123   // Size Maps
1124   connect( addMapButton,        SIGNAL( clicked()),                    this,         SLOT( onAddMap() ) );
1125   connect( removeMapButton,     SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
1126   connect( modifyMapButton,     SIGNAL( clicked()),                    this,         SLOT( onModifyMap() ) );
1127 //   connect( mySizeMapTable,      SIGNAL( cellChanged ( int, int  )),    this,         SLOT( onSetSizeMap(int,int ) ) );
1128   connect( mySizeMapTable,      SIGNAL( itemClicked (QTreeWidgetItem *, int)),this,  SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
1129   connect( myGeomSelWdg2,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1130   connect( myGeomSelWdg1,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1131   connect( myAttSelWdg,         SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
1132 //   connect( myAttractorGroup,    SIGNAL( clicked(bool) ),               this,         SLOT( onAttractorGroupClicked(bool) ) );
1133   connect( mySizeMapTable,      SIGNAL( itemChanged (QTreeWidgetItem *, int)),this,  SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
1134   connect( myAttractorCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onAttractorClicked( int ) ) );
1135   connect( myConstSizeCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onConstSizeClicked( int ) ) );
1136   connect( smpTab,              SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
1137   connect( myTabWidget,         SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
1138
1139   // Enforced vertices
1140   connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this,  SLOT( synchronizeCoords() ) );
1141   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
1142 //   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( update(QTreeWidgetItem *, int) ) );
1143   connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),      this,         SLOT( synchronizeCoords() ) );
1144   connect( addVertexButton,     SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
1145   connect( removeVertexButton,  SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
1146   connect( myEnfVertexWdg,      SIGNAL( contentModified()),            this,         SLOT( onSelectEnforcedVertex() ) );
1147   connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this,  SLOT( onInternalVerticesClicked( int ) ) );
1148 //   connect( myEnfVertexWdg,     SIGNAL( selectionActivated()),         this,         SLOT( onVertexSelectionActivated() ) );
1149 //   connect( myEnfFaceWdg,       SIGNAL( selectionActivated()),         this,         SLOT( onFaceSelectionActivated() ) );
1150
1151   // Periodicity
1152   connect( myPeriodicityAddButton,     SIGNAL( clicked()),                    this,   SLOT( onAddPeriodicity() ) );
1153   connect( myPeriodicityRemoveButton,  SIGNAL( clicked()),                    this,   SLOT( onRemovePeriodicity() ) );
1154   connect( myPeriodicityTreeWidget,    SIGNAL( itemClicked(QTreeWidgetItem*, int)), this, SLOT( onPeriodicityTreeClicked(QTreeWidgetItem *, int) ) );
1155   connect( myPeriodicityGroupBox2,     SIGNAL(toggled(bool)),                 this,   SLOT(onPeriodicityByVerticesChecked(bool)));
1156
1157   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1158   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1159     {
1160       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1161       connect( w1,     SIGNAL(contentModified ()),                 this,   SLOT(onPeriodicityContentModified()));
1162
1163     }
1164 //  connect( myPeriodicitySourceFaceWdg,     SIGNAL(contentModified()),    this,   SLOT(onPeriodicityContentModified()));
1165   return fr;
1166 }
1167
1168 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
1169 This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
1170 */
1171 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
1172 // {
1173 //   if ((now == myXCoord) || (now == myYCoord) || (now == myZCoord)
1174 //       || (now = myGroupName) || (now = myGlobalGroupName) || (now = myEnforcedTreeWidget)) {
1175 //     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1176 //     that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1177 //     myEnfFaceWdg->deactivateSelection();
1178 //     myEnfVertexWdg->deactivateSelection();
1179 //   }
1180 // }
1181
1182 void BLSURFPluginGUI_HypothesisCreator::onStateChange()
1183 {
1184   myStdWidget->myGradation->setEnabled( !myStdWidget->myAllowQuadrangles->isChecked() );
1185 }
1186
1187 /** 
1188  * This method resets the content of the X, Y, Z widgets;
1189 **/
1190 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
1191 {
1192   myXCoord->setCleared(true);
1193   myYCoord->setCleared(true);
1194   myZCoord->setCleared(true);
1195   myXCoord->setText("");
1196   myYCoord->setText("");
1197   myZCoord->setText("");
1198 //   myGroupName->setText("");
1199 }
1200
1201 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
1202 This method updates the tooltip of a modified item. The QLineEdit widgets content
1203 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
1204 */
1205 void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
1206 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
1207   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
1208   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1209   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1210   QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1211   QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1212   QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
1213   QTreeWidgetItem* parent = item->parent();
1214   
1215   clearEnforcedVertexWidgets();
1216   
1217   if (parent && (!x.isNull() || !entry.isNull())) {
1218       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
1219       QString toolTip = shapeName + QString(": ") + vertexName.toString();
1220       if (entry.isNull()) {
1221         toolTip += QString("(") + x.toString();
1222         toolTip += QString(", ") + y.toString();
1223         toolTip += QString(", ") + z.toString();
1224         toolTip += QString(")");
1225       }
1226       
1227       if (!groupName.isEmpty())
1228         toolTip += QString(" [") + groupName + QString("]");
1229
1230       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1231
1232     if (!x.isNull()) {
1233       myXCoord->SetValue(x.toDouble());
1234       myYCoord->SetValue(y.toDouble());
1235       myZCoord->SetValue(z.toDouble());
1236     }
1237     
1238     if (!groupName.isEmpty())
1239       myGroupName->setText(groupName);
1240   }
1241 }
1242
1243 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
1244   int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
1245   clearEnforcedVertexWidgets();
1246   if (nbSelEnfVertex == 1)
1247   {
1248     if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
1249     return ;
1250
1251     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
1252     if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1253       BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1254       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1255       if (CORBA::is_nil(measureOp))
1256         return;
1257       
1258       CORBA::Double x,y,z;
1259       measureOp->PointCoordinates (myEnfVertex, x, y, z);
1260       if ( measureOp->IsDone() )
1261       {
1262         myXCoord->SetValue(x);
1263         myYCoord->SetValue(y);
1264         myZCoord->SetValue(z);
1265       }
1266     }
1267   }
1268 }
1269
1270 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1271 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
1272 of the enforced vertex clicked in the tree widget.
1273 */
1274 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
1275   clearEnforcedVertexWidgets();
1276   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
1277   if (! items.isEmpty() && items.size() == 1) {
1278     QTreeWidgetItem *item = items[0];
1279 //     for (int i=0 ; i < items.size() ; i++) {
1280 //       item = items[i];
1281       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1282       QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1283       QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1284       QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1285       QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
1286       if (!x.isNull()/* && entry.isNull()*/) {
1287         myXCoord->SetValue(x.toDouble());
1288         myYCoord->SetValue(y.toDouble());
1289         myZCoord->SetValue(z.toDouble());
1290 //         break;
1291       }
1292       if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1293         myGroupName->setText(group.toString());
1294 //     }
1295   }
1296 }
1297
1298 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1299 This method adds a face containing enforced vertices in the tree widget.
1300 */
1301 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
1302   // Find theFaceEntry item
1303   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1304   QTreeWidgetItem* theItem;
1305   if (theItemList.empty()) {
1306     theItem = new QTreeWidgetItem();
1307     theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1308     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1309     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1310     myEnforcedTreeWidget->addTopLevelItem(theItem);
1311   }
1312   else {
1313     theItem = theItemList[0];
1314   }
1315   return theItem;
1316 }
1317
1318 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1319 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1320 */
1321 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theItem, double x, double y, double z, 
1322                                                           std::string vertexName, std::string geomEntry, std::string groupName) {
1323
1324   std::string theFaceName = theItem->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
1325 //   MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
1326   bool okToCreate = true;
1327
1328   const int nbVert = theItem->childCount();
1329 //   MESSAGE("Number of child rows: " << nbVert);
1330   if (nbVert >0) {
1331     double childValueX,childValueY,childValueZ;
1332     QString childEntry, childGroupName;
1333     QTreeWidgetItem* child;
1334     for (int row = 0;row<nbVert;row++) {
1335       child = theItem->child(row);
1336       childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1337       childEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1338       childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1339       childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1340       childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1341       if (((childValueX == x) && (childValueY == y) && (childValueZ == z)) || ( (childEntry.toStdString() != "") && (childEntry.toStdString() == geomEntry))) {
1342         // update group name
1343         if (childGroupName.toStdString() != groupName) {
1344           MESSAGE("Group is updated from \"" << childGroupName.toStdString() << "\" to \"" << groupName << "\"");
1345           child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1346         }
1347         okToCreate = false;
1348         break;
1349       } // if
1350     } // for
1351   } // if
1352   if (!okToCreate) {
1353     if (geomEntry.empty()) {
1354       MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1355     }
1356     else {
1357       MESSAGE("In " << theFaceName << " vertex with entry " << geomEntry << " already exist: dont create again");
1358     }
1359     return;
1360   }
1361     
1362   if (geomEntry.empty()) {
1363     MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
1364   }
1365   else {
1366     MESSAGE("In " << theFaceName << " vertex with geom entry " << geomEntry << " is created");
1367   }
1368
1369   QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
1370   vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1371   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1372   QSize iconSize = iconSelect.size()*0.7;
1373   
1374   int vertexIndex=myEnforcedTreeWidget->indexOfTopLevelItem(theItem);
1375   QString myVertexName;
1376   int indexRef = -1;
1377   while(indexRef != vertexIndex) {
1378     indexRef = vertexIndex;
1379     if (vertexName.empty())
1380       myVertexName = QString("Vertex #%1").arg(vertexIndex);
1381     else
1382       myVertexName = QString(vertexName.c_str());
1383
1384     for (int row = 0;row<nbVert;row++) {
1385       QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1386       if (myVertexName == name) {
1387         vertexIndex++;
1388         break;
1389       }
1390     }
1391   }
1392   vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1393   if (geomEntry.empty()) {
1394     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1395     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1396     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1397   }
1398   else {
1399     vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1400     vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1401   }
1402   if (groupName != "")
1403     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1404
1405   QString toolTip = QString(theFaceName.c_str())+QString(": ")+myVertexName;
1406   if (geomEntry.empty()) {
1407     toolTip += QString(" (%1, ").arg(x);
1408     toolTip += QString("%1, ").arg(y);
1409     toolTip += QString("%1)").arg(z);
1410   }
1411   if (groupName != "")
1412     toolTip += QString(" [%1]").arg(groupName.c_str());
1413   
1414   vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1415   theItem->setExpanded(true);
1416   myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1417 }
1418
1419 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1420 This method is called when a item is added into the enforced vertices tree widget
1421 */
1422 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
1423 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1424
1425   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1426
1427   getGeomSelectionTool()->selectionMgr()->clearFilters();
1428   myEnfFaceWdg->deactivateSelection();
1429   myEnfVertexWdg->deactivateSelection();
1430
1431   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1432     myEnforcedTreeWidget->resizeColumnToContents(column);
1433
1434   // Vertex selection
1435   int selEnfFace   = myEnfFaceWdg->NbObjects();
1436   int selEnfVertex = myEnfVertexWdg->NbObjects();
1437   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1438
1439   if (selEnfFace == 0)
1440     return;
1441
1442   if ((selEnfVertex == 0) && coordsEmpty)
1443     return;
1444
1445   string entry, shapeName;
1446
1447   for (int i = 0 ; i < selEnfFace ; i++) {
1448     myEnfFace = myEnfFaceWdg->GetObject< GEOM::GEOM_Object >(i);
1449     entry = myEnfFace->GetStudyEntry();
1450     shapeName = myEnfFace->GetName();
1451     
1452     QTreeWidgetItem * faceItem = addEnforcedFace(entry, shapeName);
1453     
1454     std::string groupName = myGroupName->text().toStdString();
1455
1456     if (boost::trim_copy(groupName).empty())
1457       groupName = "";
1458
1459     if (selEnfVertex <= 1)
1460     {
1461       double x,y,z;
1462       x = myXCoord->GetValue();
1463       y = myYCoord->GetValue();
1464       z = myZCoord->GetValue();
1465       if (selEnfVertex == 1) {
1466         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1467         addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1468       }
1469       else
1470         addEnforcedVertex(faceItem, x, y, z, "", "", groupName);
1471     }
1472     else
1473     {
1474       if ( CORBA::is_nil(getGeomEngine()))
1475         return;
1476
1477       GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1478       if (CORBA::is_nil(measureOp))
1479         return;
1480
1481       CORBA::Double x,y,z;
1482       x = y = z = 0.;
1483       for (int j = 0 ; j < selEnfVertex ; j++)
1484       {
1485         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1486         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1487           measureOp->PointCoordinates (myEnfVertex, x, y, z);
1488           if ( measureOp->IsDone() )
1489             addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1490         } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1491             addEnforcedVertex(faceItem, 0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1492         }
1493       }
1494     }
1495   }
1496
1497   myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
1498   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1499   
1500   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1501     myEnforcedTreeWidget->resizeColumnToContents(column);
1502
1503   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1504     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1505     myStdWidget->onPhysicalMeshChanged();
1506   }
1507 }
1508
1509 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1510 This method is called when a item is removed from the enforced vertices tree widget
1511 */
1512 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1513 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1514   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1515   QList<QTreeWidgetItem *> selectedVertices;
1516   QSet<QTreeWidgetItem *> selectedEntries;
1517   QTreeWidgetItem* item;
1518
1519   foreach( item, selectedItems ) {
1520     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1521     if (! value.isNull())
1522       selectedVertices.append(item);
1523     else {
1524       value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1525       if (! value.isNull())
1526         selectedVertices.append(item);
1527       else
1528         selectedEntries.insert(item);
1529     }
1530   }
1531
1532   foreach(item,selectedVertices) {
1533     QTreeWidgetItem* parent = item->parent();
1534 //     MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1535     parent->removeChild(item);
1536     delete item;
1537     if (parent->childCount() == 0) {
1538       if (selectedEntries.contains(parent))
1539         selectedEntries.remove(parent);
1540       delete parent;
1541     }
1542   }
1543
1544   foreach(item,selectedEntries) {
1545 //     MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1546     delete item;
1547   }
1548
1549   myEnforcedTreeWidget->selectionModel()->clearSelection();
1550 }
1551
1552
1553 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1554 {
1555   myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1556 }
1557
1558 /** BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
1559 This method is called when a item is added into the periodicity table widget
1560 */
1561 void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
1562 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1563
1564   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1565
1566   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1567   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1568   for ( ; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1569     {
1570           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1571           w1->deactivateSelection();
1572     }
1573
1574
1575   // Source-Target selection
1576   int selSource = myPeriodicitySourceFaceWdg->NbObjects();
1577   int selTarget = myPeriodicityTargetFaceWdg->NbObjects();
1578
1579   if (selSource == 0 || selTarget == 0)
1580     return;
1581
1582   // Vertices selection
1583   if (myPeriodicityGroupBox2->isChecked())
1584     {
1585       int P1Ssel = myPeriodicityP1SourceWdg->NbObjects();
1586       int P2Ssel = myPeriodicityP2SourceWdg->NbObjects();
1587       int P3Ssel = myPeriodicityP3SourceWdg->NbObjects();
1588       int P1Tsel = myPeriodicityP1TargetWdg->NbObjects();
1589       int P2Tsel = myPeriodicityP2TargetWdg->NbObjects();
1590       int P3Tsel = myPeriodicityP3TargetWdg->NbObjects();
1591
1592       if (P1Ssel!=1 || P2Ssel!=1 || P3Ssel!=1 || P1Tsel!=1 || P3Tsel!=1 || P3Tsel!=1)
1593         {
1594           QString msg = tr("BLSURF_PERIODICITY_WRONG_NUMBER_OF_VERTICES");
1595           SUIT_MessageBox::critical( dlg(),"Error" , msg );
1596           return;
1597         }
1598     }
1599
1600   // Add Source-Target in table
1601   string shapeEntry, sourceEntry, targetEntry;
1602   string shapeName, sourceName, targetName;
1603   GEOM::GEOM_Object_var shape;
1604
1605   QTreeWidgetItem* item = new QTreeWidgetItem();
1606   myPeriodicityTreeWidget->addTopLevelItem(item);
1607
1608   item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
1609
1610
1611   size_t k=0;
1612   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1613     {
1614       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1615       shape = w1->GetObject< GEOM::GEOM_Object >(0);
1616       shapeName = shape->GetName();
1617       shapeEntry = shape->GetStudyEntry();
1618       item->setData(k, Qt::EditRole, shapeName.c_str() );
1619       item->setData(k, Qt::UserRole, shapeEntry.c_str() );
1620       if (! myPeriodicityGroupBox2->isChecked() && k==1)
1621         break;
1622     }
1623
1624   // Add shape type in tree
1625   string onFace = (myPeriodicityOnFaceRadioButton->isChecked()) ? "1" : "0";
1626   item->setData(PERIODICITY_SHAPE_TYPE, Qt::UserRole, onFace.c_str());
1627
1628   // Blank input fields
1629   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++)
1630     {
1631       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1632       w1->SetObject(GEOM::GEOM_Object::_nil());
1633     }
1634
1635 //  for (int column = 0; column < myPeriodicityTreeWidget->columnCount(); ++column)
1636 //    myPeriodicityTreeWidget->resizeColumnToContents(column);
1637
1638 }
1639
1640 /** BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
1641 This method is called when a item is removed from the periodicity tree widget
1642 */
1643 void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity() {
1644 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1645   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
1646   QTreeWidgetItem* item;
1647
1648   foreach(item,selectedItems) {
1649      MESSAGE("Remove " << item->text(0).toStdString());
1650     delete item;
1651   }
1652
1653   myEnforcedTreeWidget->selectionModel()->clearSelection();
1654 }
1655
1656 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked()
1657 This method enable clears the field for periodicity by vertices
1658 */
1659 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked(bool checked)
1660 {
1661   if (! checked)
1662     {
1663       for (size_t k=2; k<myPeriodicitySelectionWidgets.size(); k++)
1664         {
1665           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k] );
1666           w1->deactivateSelection();
1667           w1->SetObject(CORBA::Object::_nil());
1668         }
1669     }
1670 }
1671
1672 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1673 This method enable the proper shape selection widget to Face or Edge shapes
1674 */
1675 //void BLSURFPluginGUI_HypothesisCreator::onPeriodicityRadioButtonChanged()
1676 //{
1677 //  if (myPeriodicityOnFaceRadioButton->isChecked())
1678 //    {
1679 //      MESSAGE("Show Face");
1680 //      myPeriodicitySourceEdgeWdg->hide();
1681 //      myPeriodicityTargetEdgeWdg->hide();
1682 //      myPeriodicitySourceFaceWdg->show();
1683 //      myPeriodicityTargetFaceWdg->show();
1684 //    }
1685 //  else
1686 //    {
1687 //      MESSAGE("Show Edge");
1688 //      myPeriodicitySourceFaceWdg->hide();
1689 //      myPeriodicityTargetFaceWdg->hide();
1690 //      myPeriodicitySourceEdgeWdg->show();
1691 //      myPeriodicityTargetEdgeWdg->show();
1692 //    }
1693 //}
1694
1695 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityTreeClicked(QTreeWidgetItem* item, int row)
1696 {
1697   QString shapeName, shapeEntry;
1698   CORBA::Object_var shape;
1699   size_t k=0;
1700   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1701   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1702     {
1703       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1704
1705       shapeName = item->data(k, Qt::EditRole).toString();
1706       shapeEntry = item->data(k, Qt::UserRole).toString();
1707       if (! shapeEntry.isEmpty())
1708         {
1709           shape = entryToObject(shapeEntry);
1710           w1->SetObject(shape);
1711           w1->deactivateSelection();
1712           if (k==2)
1713             myPeriodicityGroupBox2->setChecked(1);
1714         }
1715       else if(k==2)
1716         myPeriodicityGroupBox2->setChecked(0);
1717     }
1718
1719   if (item->data(PERIODICITY_SHAPE_TYPE, Qt::UserRole) == "1")
1720     myPeriodicityOnFaceRadioButton->setChecked(true);
1721   else
1722     myPeriodicityOnEdgeRadioButton->setChecked(true);
1723
1724
1725 }
1726
1727 /** BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1728 This method gives the focus to the next selection widget when a content is modified in a selection widget.
1729 */
1730 void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
1731 {
1732   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1733
1734   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
1735   size_t k=0;
1736   // find wich selection widget is activated
1737   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
1738     {
1739       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
1740       if (w1->IsSelectionActivated() && k<(myPeriodicitySelectionWidgets.size()-1))
1741         {
1742           // don't activate vertex selection if the group box is not checked
1743           if (k==1 && !myPeriodicityGroupBox2->isChecked())
1744             break;
1745           // clear the selection, to avoid to put the same object in the other widget
1746           that->getGeomSelectionTool()->selectionMgr()->clearSelected();
1747           // activate the next widget
1748           StdMeshersGUI_ObjectReferenceParamWdg * w2 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k+1] );
1749           w2->activateSelection();
1750           break;
1751         }
1752     }
1753 }
1754
1755
1756 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1757 This method updates the GUI widgets with the hypothesis data
1758 */
1759 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1760 {
1761   MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1762   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1763
1764   BlsurfHypothesisData data;
1765   that->readParamsFromHypo( data );
1766
1767   if ( myName ) {
1768     myName->setText( data.myName );
1769     QFontMetrics metrics( myName->font() );
1770     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1771   }
1772   myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1773   myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1774   if (data.myPhySize <= 0)
1775     myStdWidget->myPhySize->setText("");
1776   else
1777     myStdWidget->myPhySize->SetValue( data.myPhySize );
1778   myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1779   if (data.myMinSize < 0)
1780     myStdWidget->myMinSize->setText("");
1781   else
1782     myStdWidget->myMinSize->SetValue( data.myMinSize );
1783   myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1784   if (data.myMaxSize < 0)
1785     myStdWidget->myMaxSize->setText("");
1786   else
1787     myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1788   myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1789   if (data.myGradation <= 0)
1790     myStdWidget->myGradation->setText("");
1791   else
1792     myStdWidget->myGradation->SetValue( data.myGradation );
1793   myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1794   
1795   if (data.myAngleMesh < 0)
1796     myStdWidget->myAngleMesh->setText("");
1797   else
1798     myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1799   if (data.myChordalError <= 0)
1800     myStdWidget->myChordalError->setText("");
1801   else
1802     myStdWidget->myChordalError->SetValue( data.myChordalError );
1803   myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1804   if (data.myAnisotropicRatio <= 0)
1805     myStdWidget->myAnisotropicRatio->setText("");
1806   else
1807     myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1808   myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1809   if (data.myTinyEdgeLength <= 0)
1810     myStdWidget->myTinyEdgeLength->setText("");
1811   else
1812     myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1813   myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1814   if (data.myBadElementAspectRatio <= 0)
1815     myStdWidget->myBadElementAspectRatio->setText("");
1816   else
1817     myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1818   myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1819   myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1820   
1821   myStdWidget->resizeWidgets();  
1822   
1823   myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1824   myAdvWidget->myPreCADGroupBox->setChecked(data.myTopology == PreCAD);
1825   myAdvWidget->myPreCADMergeEdges->setChecked( data.myPreCADMergeEdges );
1826   myAdvWidget->myPreCADProcess3DTopology->setChecked( data.myPreCADProcess3DTopology );
1827   myAdvWidget->myPreCADDiscardInput->setChecked( data.myPreCADDiscardInput );
1828
1829   if ( myOptions.operator->() ) {
1830 //     MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1831     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1832       QString option = that->myOptions[i].in();
1833       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1834       if ( name_value.count() > 1 ) {
1835         QString idStr = QString("%1").arg( i );
1836         int row = myAdvWidget->myOptionTable->rowCount();
1837         myAdvWidget->myOptionTable->setRowCount( row+1 );
1838         myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1839         myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1840         myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "BLSURF" ) );
1841         myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1842         myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1843         myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1844         myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1845         myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1846                                                                                 Qt::ItemIsEditable   |
1847                                                                                 Qt::ItemIsEnabled );
1848       }
1849     }
1850   }
1851   if ( myPreCADOptions.operator->() ) {
1852 //     MESSAGE("retrieveParams():myPreCADOptions->length() = " << myPreCADOptions->length());
1853     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
1854       QString option = that->myPreCADOptions[i].in();
1855       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1856       if ( name_value.count() > 1 ) {
1857         QString idStr = QString("%1").arg( i );
1858         int row = myAdvWidget->myOptionTable->rowCount();
1859         myAdvWidget->myOptionTable->setRowCount( row+1 );
1860         myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1861         myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1862         myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "PRECAD" ) );
1863         myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1864         myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1865         myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1866         myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1867         myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1868                                                                                 Qt::ItemIsEditable   |
1869                                                                                 Qt::ItemIsEnabled );
1870       }
1871     }
1872   }
1873   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1874   myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1875 //   myGMFFileMode->setChecked(data.myGMFFileMode);
1876   
1877   // Sizemaps
1878   MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1879   QMapIterator<QString, QString> i(that->mySMPMap);
1880   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1881   while (i.hasNext()) {
1882     i.next();
1883     const QString entry = i.key();
1884     const QString sizeMap = i.value();
1885     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1886     int row = mySizeMapTable->topLevelItemCount();
1887     QTreeWidgetItem* item = new QTreeWidgetItem();
1888     mySizeMapTable->addTopLevelItem( item );
1889     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1890     item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1891     item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1892     if (that->myATTMap.contains(entry)) {
1893       TAttractorVec & attVec = that->myATTMap[entry];
1894       for ( size_t i = 0; i < attVec.size(); ++i )
1895       {
1896         std::string attName = myGeomToolSelected->getNameFromEntry( attVec[i].attEntry );
1897         QTreeWidgetItem* child = new QTreeWidgetItem();
1898         item->addChild( child );
1899         item->setExpanded(true);
1900         child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( attVec[i].startSize  ));
1901         child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attVec[i].attEntry.c_str() ));
1902         child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( attName.c_str() ));
1903
1904         if ( attVec[i].infDist >  std::numeric_limits<double>::epsilon()){
1905           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Attractor" ));
1906         }
1907         else{
1908           item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Constant Size" ));
1909         }
1910       }
1911     }
1912     else
1913     {
1914       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1915     } 
1916   }
1917   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1918   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1919   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1920
1921   // Enforced vertices
1922   MESSAGE("retrieveParams(): data.entryCoordsListMap.size() = " << data.faceEntryEnfVertexListMap.size());
1923   TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1924
1925   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1926     TEntry entry = (*evmIt).first;
1927     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1928     MESSAGE("Face entry: " << entry);
1929     MESSAGE("Face name: " << shapeName);
1930     
1931     QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1932
1933     TEnfVertexList evs = (*evmIt).second;
1934
1935     TEnfVertexList::const_iterator evsIt = evs.begin();
1936     TEnfVertex *enfVertex;
1937     for ( ; evsIt != evs.end() ; ++evsIt) {
1938       enfVertex = (*evsIt);
1939       MESSAGE("Name: " << enfVertex->name);
1940       double x, y, z = 0;
1941       if (enfVertex->coords.size()) {
1942         x = enfVertex->coords[0];
1943         y = enfVertex->coords[1];
1944         z = enfVertex->coords[2];
1945       }
1946       that->addEnforcedVertex(faceItem, x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1947     }
1948   }
1949   
1950   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1951     myEnforcedTreeWidget->resizeColumnToContents(column);
1952
1953   myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
1954   myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
1955   myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
1956
1957   // Periodicity
1958   MESSAGE("retrieveParams(): periodicity ");
1959
1960
1961   // Add an item in the tree widget for each association
1962   for (size_t i=0 ; i<data.preCadPeriodicityVector.size() ; i++)
1963     {
1964       QTreeWidgetItem* item = new QTreeWidgetItem();
1965       myPeriodicityTreeWidget->addTopLevelItem(item);
1966       item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
1967       TPreCadPeriodicity periodicity_i = data.preCadPeriodicityVector[i];
1968       for (size_t k=0; k<periodicity_i.size(); k++)
1969         {
1970           string shapeEntry = periodicity_i[k];
1971           string shapeName = myGeomToolSelected->getNameFromEntry(shapeEntry);
1972           item->setData(k, Qt::EditRole, shapeName.c_str() );
1973           item->setData(k, Qt::UserRole, shapeEntry.c_str() );
1974         }
1975     }
1976
1977   // update widgets
1978   that->myStdWidget->onPhysicalMeshChanged();
1979   that->myStdWidget->onGeometricMeshChanged();
1980   that->onStateChange();
1981 }
1982
1983 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1984 This method updates the hypothesis data with the GUI widgets content.
1985 */
1986 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1987 {
1988   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParams");
1989   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1990
1991   BlsurfHypothesisData data;
1992   QString guiHyp = that->readParamsFromWidgets( data );
1993   that->storeParamsToHypo( data );
1994
1995   return guiHyp;
1996 }
1997
1998 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1999 Updates the hypothesis data from hypothesis values.
2000 */
2001 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
2002 {
2003   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
2004   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2005     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
2006
2007   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
2008   h_data.myName = isCreation() && data ? hypName() : "";
2009
2010   h_data.myPhysicalMesh           = (int) h->GetPhysicalMesh();
2011   h_data.myGeometricMesh          = (int) h->GetGeometricMesh();
2012   h_data.myPhySize                = h->GetPhySize();
2013   h_data.myPhySizeRel             = h->IsPhySizeRel();
2014   double minSize                  = h->GetMinSize();
2015   double maxSize                  = h->GetMaxSize();
2016   h_data.myMinSize                = minSize > 0 ? minSize : -1.0;
2017   h_data.myMinSizeRel             = h->IsMinSizeRel();
2018   h_data.myMaxSize                = maxSize > 0 ? maxSize : -1.0;
2019   h_data.myMaxSizeRel             = h->IsMaxSizeRel();
2020   h_data.myGradation              = h->GetGradation();
2021   h_data.myAllowQuadrangles       = h->GetQuadAllowed();
2022   double angle                    = h->GetAngleMesh();
2023   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
2024   double chordalError             = h->GetChordalError();
2025   h_data.myChordalError           = chordalError > 0 ? chordalError : -1.0;
2026   h_data.myAnisotropic            = h->GetAnisotropic();
2027   double myAnisotropicRatio       = h->GetAnisotropicRatio();
2028   h_data.myAnisotropicRatio       = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
2029   h_data.myRemoveTinyEdges        = h->GetRemoveTinyEdges();
2030   double myTinyEdgeLength         = h->GetTinyEdgeLength();
2031   h_data.myTinyEdgeLength         = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
2032   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
2033   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
2034   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
2035   h_data.myOptimizeMesh           = h->GetOptimizeMesh();
2036   h_data.myQuadraticMesh          = h->GetQuadraticMesh();
2037   h_data.myVerbosity              = h->GetVerbosity();
2038   h_data.myTopology               = (int) h->GetTopology();
2039   h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
2040   h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
2041   h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
2042
2043
2044   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2045   that->myOptions = h->GetOptionValues();
2046   that->myPreCADOptions = h->GetPreCADOptionValues();
2047   
2048   h_data.myGMFFileName = h->GetGMFFile();
2049 //   h_data.myGMFFileMode = h->GetGMFFileMode();
2050
2051   that->mySMPMap.clear();
2052   that->myATTMap.clear();
2053   // that->myAttDistMap.clear();
2054   // that->myDistMap.clear();
2055
2056   // classic size maps
2057   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
2058 //   MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
2059   QString fullSizeMaps;
2060   QStringList fullSizeMapList;
2061   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
2062   for ( int i = 0;i<mySizeMaps->length(); ++i ) {
2063     fullSizeMaps =  mySizeMaps[i].in();
2064 //     MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
2065     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
2066     if ( fullSizeMapList.count() > 1 ) {
2067       string fullSizeMap = fullSizeMapList[1].toStdString();
2068       int pos = fullSizeMap.find("return")+7;
2069 //       MESSAGE("pos:" << pos);
2070       QString sizeMap;
2071       try {
2072         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
2073       }
2074       catch (...) {
2075         continue;
2076       }
2077       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
2078 //       MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
2079       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
2080 //       MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
2081     }
2082   }
2083
2084   // custom size maps
2085 /*
2086   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
2087   MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
2088
2089   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
2090     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
2091     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
2092     if ( fullCustomSizeMapList.count() > 1 ) {
2093       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
2094       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
2095       MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
2096       MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
2097     }
2098   }
2099 */
2100   // attractor
2101   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
2102 //   MESSAGE("myAttractors->length() = " << allMyAttractors->length());
2103
2104   for ( int i = 0;i<allMyAttractors->length(); ++i ) {
2105     QString myAttractors =  allMyAttractors[i].in();
2106     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
2107     if ( myAttractorList.count() > 1 ) {
2108       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
2109       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
2110 //       MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
2111 //       MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
2112     }
2113   }
2114   
2115   // attractor new version
2116   MESSAGE("readParamsFromHypo, Attractors")
2117   BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
2118   for ( int i = 0;i<allMyAttractorParams->length(); ++i ) {
2119     BLSURFPlugin::TAttractorParams myAttractorParams =  allMyAttractorParams[i];
2120     QString faceEntry = myAttractorParams.faceEntry.in();
2121     QString attEntry  = myAttractorParams.attEntry.in();
2122     MESSAGE("attEntry = "<<attEntry.toStdString())
2123     that->mySMPMap[faceEntry] = QString::number( myAttractorParams.startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
2124     that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
2125     that->myATTMap[faceEntry].push_back( TAttractor( myAttractorParams.attEntry.in(),
2126                                                      myAttractorParams.startSize,
2127                                                      myAttractorParams.infDist,
2128                                                      myAttractorParams.constDist ));
2129   }
2130   
2131   // Enforced vertices
2132   h_data.enfVertexList.clear();
2133   h_data.faceEntryEnfVertexListMap.clear();
2134   /* TODO GROUPS
2135   h_data.groupNameEnfVertexListMap.clear();
2136   */
2137
2138   BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
2139   MESSAGE("faceEntryEnfVertexListMap->length() = " << faceEntryEnfVertexListMap->length());
2140
2141   for ( int i = 0;i<faceEntryEnfVertexListMap->length(); ++i ) {
2142     std::string entry =  faceEntryEnfVertexListMap[i].faceEntry.in();
2143 //     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList.in();
2144     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
2145 //     BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
2146
2147 //     TEnfVertexList& enfVertexList = h_data.faceEntryEnfVertexListMap[entry];
2148
2149     for (int j=0 ; j<vertexList.length(); ++j) {
2150       TEnfVertex *enfVertex = new TEnfVertex();
2151       
2152       enfVertex->name = CORBA::string_dup(vertexList[j].name.in());
2153       enfVertex->geomEntry = CORBA::string_dup(vertexList[j].geomEntry.in());
2154       enfVertex->grpName = CORBA::string_dup(vertexList[j].grpName.in());
2155       for (int k=0 ; k< vertexList[j].coords.length();k++)
2156         enfVertex->coords.push_back(vertexList[j].coords[k]);
2157
2158       h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
2159
2160       /* TODO GROUPS
2161       if (groupName != "") {
2162         h_data.groupNameEnfVertexListMap[groupName].insert(ev);
2163       }
2164       */
2165     }
2166 //     h_data.enfVertMap[entry] = evs;
2167 //     h_data.entryCoordsListMap[entry] = coordsList;
2168
2169     if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
2170       h_data.faceEntryEnfVertexListMap.erase(entry);
2171     }
2172   }
2173   h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
2174   h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
2175
2176   // Periodicity
2177   MESSAGE("readParamsFromHypo, Periodicity")
2178
2179   h_data.preCadPeriodicityVector.clear();
2180
2181   BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector = h->GetPreCadFacesPeriodicityVector();
2182   AddPreCadSequenceToVector(h_data, preCadFacePeriodicityVector, true);
2183
2184   BLSURFPlugin::TPeriodicityList_var preCadEdgePeriodicityVector = h->GetPreCadEdgesPeriodicityVector();
2185   AddPreCadSequenceToVector(h_data, preCadEdgePeriodicityVector, false);
2186   return true;
2187 }
2188
2189 void BLSURFPluginGUI_HypothesisCreator::AddPreCadSequenceToVector(BlsurfHypothesisData& h_data,
2190     BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const
2191 {
2192
2193   for (size_t i=0; i<preCadFacePeriodicityVector->length(); i++ )
2194     {
2195       TPreCadPeriodicity periodicity_i(PERIODICITY_NB_COLUMN);
2196       periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN] = preCadFacePeriodicityVector[i].shape1Entry.in();
2197       periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN] = preCadFacePeriodicityVector[i].shape2Entry.in();
2198
2199       BLSURFPlugin::TEntryList sourceVertices = preCadFacePeriodicityVector[i].theSourceVerticesEntries;
2200       BLSURFPlugin::TEntryList targetVertices = preCadFacePeriodicityVector[i].theTargetVerticesEntries;
2201
2202       if (sourceVertices.length()!=0)
2203         {
2204           periodicity_i[PERIODICITY_P1_SOURCE_COLUMN] = sourceVertices[0].in();
2205           periodicity_i[PERIODICITY_P2_SOURCE_COLUMN] = sourceVertices[1].in();
2206           periodicity_i[PERIODICITY_P3_SOURCE_COLUMN] = sourceVertices[2].in();
2207         }
2208
2209       if (targetVertices.length()!=0)
2210         {
2211           periodicity_i[PERIODICITY_P1_TARGET_COLUMN] = targetVertices[0].in();
2212           periodicity_i[PERIODICITY_P2_TARGET_COLUMN] = targetVertices[1].in();
2213           periodicity_i[PERIODICITY_P3_TARGET_COLUMN] = targetVertices[2].in();
2214         }
2215
2216       if (onFace)
2217         periodicity_i[PERIODICITY_SHAPE_TYPE] = "1";
2218       else
2219         periodicity_i[PERIODICITY_SHAPE_TYPE] = "0";
2220
2221       h_data.preCadPeriodicityVector.push_back(periodicity_i);
2222     }
2223 }
2224
2225 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
2226 Saves the hypothesis data to hypothesis values.
2227 */
2228 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
2229 {
2230   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
2231   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2232     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
2233
2234   bool ok = true;
2235   try
2236   {
2237     if ( isCreation() )
2238       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
2239
2240     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
2241       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
2242     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
2243       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
2244
2245     if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
2246       if ( h->GetPhySize()   != h_data.myPhySize ||
2247            h->IsPhySizeRel() != h_data.myPhySizeRel ) {
2248         if ( h_data.myPhySizeRel )
2249           h->SetPhySizeRel( h_data.myPhySize );
2250         else
2251           h->SetPhySize( h_data.myPhySize );
2252       }
2253     }
2254     if (h->GetMinSize()   != h_data.myMinSize ||
2255         h->IsMinSizeRel() != h_data.myMinSizeRel ) {
2256       if ( h_data.myMinSizeRel )
2257         h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2258       else
2259         h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
2260     }
2261     if (h->GetMaxSize()   != h_data.myMaxSize ||
2262         h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
2263       if ( h_data.myMaxSizeRel )
2264         h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2265       else
2266         h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
2267     }
2268     if ( h->GetGradation() !=  h_data.myGradation )
2269       h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
2270     if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
2271       h->SetQuadAllowed( h_data.myAllowQuadrangles );
2272     
2273     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
2274       if ( h->GetAngleMesh() != h_data.myAngleMesh )
2275         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
2276       if ( h->GetChordalError() != h_data.myChordalError )
2277         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
2278     }
2279     
2280     if ( h->GetAnisotropic() != h_data.myAnisotropic )
2281       h->SetAnisotropic( h_data.myAnisotropic );
2282     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
2283       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
2284     
2285     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
2286       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
2287     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
2288       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
2289     
2290     if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
2291       h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
2292     if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
2293       h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
2294     
2295     if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
2296       h->SetOptimizeMesh( h_data.myOptimizeMesh );    
2297     
2298     if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
2299       h->SetQuadraticMesh( h_data.myQuadraticMesh );    
2300
2301     if ( h->GetVerbosity() != h_data.myVerbosity )
2302       h->SetVerbosity( h_data.myVerbosity );
2303     if ( h->GetTopology() != h_data.myTopology )
2304       h->SetTopology( (int) h_data.myTopology );
2305     if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
2306       h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
2307     if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
2308       h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
2309     if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
2310       h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
2311
2312     h->SetOptionValues( myOptions ); // is set in checkParams()
2313     h->SetPreCADOptionValues( myPreCADOptions ); // is set in checkParams()
2314     
2315     if ( h->GetGMFFile() != h_data.myGMFFileName )
2316 //       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
2317 //       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
2318       h->SetGMFFile( h_data.myGMFFileName.c_str());
2319
2320     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2321     QMapIterator<QString,QString> i(that->mySMPMap);
2322     while (i.hasNext()) {
2323       i.next();
2324       const QString entry = i.key();
2325       const QString sizeMap = i.value();
2326
2327       if (sizeMap == "__TO_DELETE__") {
2328         MESSAGE("Delete entry " << entry.toStdString() << " from engine");
2329         h->UnsetEntry(entry.toLatin1().constData());
2330       }
2331       else if (sizeMap.startsWith("ATTRACTOR")) {
2332 //         MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
2333         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
2334       }
2335       else if (sizeMap.startsWith("def")) {
2336 //         MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
2337 //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
2338       }
2339       else {
2340         if (!myATTMap[entry].empty()){
2341           const TAttractorVec& attVec = myATTMap[entry];
2342           for ( size_t i = 0; i < attVec.size(); ++i )
2343           {
2344             if ( attVec[i].IsToDelete() )
2345               h->UnsetAttractorEntry( entry.toLatin1().constData(),
2346                                       attVec[i].attEntry.c_str() );
2347             else
2348               h->SetClassAttractorEntry( entry.toLatin1().constData(),
2349                                          attVec[i].attEntry.c_str(),
2350                                          attVec[i].startSize,
2351                                          h->GetPhySize(),
2352                                          attVec[i].infDist,
2353                                          attVec[i].constDist );
2354           }
2355         }
2356         else {
2357           QString fullSizeMap;
2358           fullSizeMap = QString("");
2359           if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
2360             fullSizeMap = QString("def f(u,v): return ") + sizeMap;
2361           else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
2362             fullSizeMap = QString("def f(t): return ") + sizeMap;
2363           else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
2364             fullSizeMap = QString("def f(): return ") + sizeMap;
2365           MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
2366           h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
2367         }
2368       }
2369     }
2370
2371     // Enforced vertices
2372     bool ret;
2373     double x, y, z = 0;
2374     std::string enfName;
2375     /* TODO GROUPS
2376     std::string groupName = "";
2377     */
2378
2379     TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
2380     // 1. Clear all enforced vertices in hypothesis
2381     // 2. Add new enforced vertex according to h_data
2382     
2383     if ( h->GetAllEnforcedVertices()->length() > 0 )
2384       h->ClearAllEnforcedVertices();
2385     TEnfName faceEntry;
2386     TEnfVertexList evs;
2387     TEnfVertexList::const_iterator evsIt;
2388     for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
2389     {
2390       faceEntry = evmIt->first;
2391       evs = evmIt->second;
2392       MESSAGE("Number of enforced vertices for face entry " << faceEntry << ": " << evs.size());
2393       evsIt = evs.begin();
2394       for ( ; evsIt != evs.end() ; ++evsIt)
2395       {
2396         x =y =z = 0;
2397         if ((*evsIt)->coords.size()) {
2398           x = (*evsIt)->coords[0];
2399           y = (*evsIt)->coords[1];
2400           z = (*evsIt)->coords[2];
2401         }
2402         ret = h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
2403       } // for
2404     } // for
2405
2406     if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
2407       h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
2408     if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
2409       h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
2410
2411     // Periodicity
2412     if ( h->GetPreCadFacesPeriodicityVector()->length() > 0 || h->GetPreCadEdgesPeriodicityVector()->length() > 0 )
2413           h->ClearPreCadPeriodicityVectors();
2414
2415     MESSAGE("h_data.preCadPeriodicityVector.size(): " << h_data.preCadPeriodicityVector.size());
2416     TPreCadPeriodicityVector::const_iterator pIt = h_data.preCadPeriodicityVector.begin();
2417     for ( ; pIt != h_data.preCadPeriodicityVector.end() ; ++pIt)
2418       {
2419         TPreCadPeriodicity periodicity_i = *pIt;
2420         TEntry source = periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN];
2421         TEntry target = periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN];
2422         TEntry p1Source = periodicity_i[PERIODICITY_P1_SOURCE_COLUMN];
2423         TEntry p2Source = periodicity_i[PERIODICITY_P2_SOURCE_COLUMN];
2424         TEntry p3Source = periodicity_i[PERIODICITY_P3_SOURCE_COLUMN];
2425         TEntry p1Target = periodicity_i[PERIODICITY_P1_TARGET_COLUMN];
2426         TEntry p2Target = periodicity_i[PERIODICITY_P2_TARGET_COLUMN];
2427         TEntry p3Target = periodicity_i[PERIODICITY_P3_TARGET_COLUMN];
2428         bool onFace = (periodicity_i[PERIODICITY_SHAPE_TYPE]=="1") ? true : false;
2429
2430         BLSURFPlugin::TEntryList_var sourceVertices = new BLSURFPlugin::TEntryList();
2431         if (! p1Source.empty())
2432           {
2433             sourceVertices->length(3);
2434             sourceVertices[0]=CORBA::string_dup(p1Source.c_str());
2435             sourceVertices[1]=CORBA::string_dup(p2Source.c_str());
2436             sourceVertices[2]=CORBA::string_dup(p3Source.c_str());
2437           }
2438
2439
2440         BLSURFPlugin::TEntryList_var targetVertices = new BLSURFPlugin::TEntryList();
2441         if (! p1Target.empty())
2442           {
2443             targetVertices->length(3);
2444             targetVertices[0]=CORBA::string_dup(p1Target.c_str());
2445             targetVertices[1]=CORBA::string_dup(p2Target.c_str());
2446             targetVertices[2]=CORBA::string_dup(p3Target.c_str());
2447           }
2448
2449         if (onFace)
2450           h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2451         else
2452           h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
2453       }
2454
2455     MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo end periodicity");
2456
2457
2458   } // try
2459   catch(const std::exception& ex) {
2460     std::cout << "Exception: " << ex.what() << std::endl;
2461     throw ex;
2462   }
2463 //   catch(const SALOME::SALOME_Exception& ex)
2464 //   {
2465 //     throw ex;
2466 // //     SalomeApp_Tools::QtCatchCorbaException(ex);
2467 // //     ok = false;
2468 //   }
2469   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo end");
2470   return ok;
2471 }
2472
2473 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
2474 Stores the widgets content to the hypothesis data.
2475 */
2476 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
2477 {
2478   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
2479   h_data.myName                  = myName ? myName->text() : "";
2480   h_data.myPhysicalMesh          = myStdWidget->myPhysicalMesh->currentIndex();
2481   h_data.myGeometricMesh         = myStdWidget->myGeometricMesh->currentIndex();
2482   h_data.myPhySize               = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
2483   h_data.myPhySizeRel            = myStdWidget->myPhySizeRel->isChecked();
2484   h_data.myMinSize               = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
2485   h_data.myMinSizeRel            = myStdWidget->myMinSizeRel->isChecked();
2486   h_data.myMaxSize               = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
2487   h_data.myMaxSizeRel            = myStdWidget->myMaxSizeRel->isChecked();
2488   h_data.myGradation             = myStdWidget->myGradation->text().isEmpty() ? -1.0 : myStdWidget->myGradation->GetValue();
2489   h_data.myAllowQuadrangles      = myStdWidget->myAllowQuadrangles->isChecked();
2490   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
2491   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
2492   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
2493   h_data.myAnisotropicRatio      = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
2494   h_data.myRemoveTinyEdges       = myStdWidget->myRemoveTinyEdges->isChecked();
2495   h_data.myTinyEdgeLength        = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
2496   h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
2497   h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
2498   h_data.myOptimizeMesh          = myStdWidget->myOptimizeMesh->isChecked();
2499   h_data.myQuadraticMesh         = myStdWidget->myQuadraticMesh->isChecked();
2500   h_data.myVerbosity             = myAdvWidget->myVerbosity->value();
2501   h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
2502   h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
2503   h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
2504   h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
2505
2506   QString guiHyp;
2507   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
2508   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
2509   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
2510   guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
2511   guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
2512   guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
2513   guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
2514   guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
2515   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
2516   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
2517   guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
2518   guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
2519   guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
2520   guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
2521   
2522   
2523   guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
2524   guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
2525   guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
2526   guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
2527   guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
2528   guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
2529   
2530   
2531   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
2532   guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
2533   guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
2534   guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
2535
2536   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2537   int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
2538   for ( ; row < nbRows; ++row )
2539   {
2540     int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
2541     std::string optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().toStdString();
2542     if ( id >= 0 && ( ( optionType == "BLSURF" && id < myOptions->length() ) || ( optionType == "PRECAD" && id < myPreCADOptions->length() ) ) )
2543     {
2544       QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
2545       QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
2546       if ( value.isNull() )
2547         value = "";
2548       if (optionType == "PRECAD")
2549         that->myPreCADOptions[ id ] = ( name + ":" + value).toLatin1().constData();
2550       else
2551         that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
2552
2553       if ( value != "" ) {
2554         if (optionType == "PRECAD")
2555           guiHyp += "PRECAD_";
2556         guiHyp += name + " = " + value + "; ";
2557       }
2558     }
2559   }
2560   
2561   h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
2562 //   h_data.myGMFFileMode = myGMFFileMode->isChecked();
2563
2564   // SizeMap
2565   row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2566   for ( ; row < nbRows; ++row )
2567   {
2568       QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
2569       if ( that->mySMPMap.contains(entry) )
2570         guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
2571   }
2572
2573   // Enforced vertices
2574   h_data.enfVertexList.clear();
2575   h_data.faceEntryEnfVertexListMap.clear();
2576
2577   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
2578   int nbEnforcedVertices = 0;
2579   std::string groupName = "";
2580 //   MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
2581   for (int i=0 ; i<nbEnforcedShapes ; i++) {
2582     QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
2583     if (shapeItem) {
2584       std::string faceEntry = shapeItem->data(ENF_VER_FACE_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2585       nbEnforcedVertices = shapeItem->childCount();
2586       if (nbEnforcedVertices >0) {
2587         double childValueX,childValueY,childValueZ;
2588         std::string childName, vertexEntry;
2589         QTreeWidgetItem* child;
2590         TEnfVertexList evs;
2591         evs.clear();
2592         for (row = 0;row<nbEnforcedVertices;row++) {
2593           child = shapeItem->child(row);
2594           childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
2595           childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
2596           childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
2597           childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
2598           vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2599 //           if (myGlobalGroupName->isChecked())
2600 //             groupName = myGlobalGroupName->text().toStdString();
2601 //           else
2602             groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
2603
2604           TEnfVertex *enfVertex = new TEnfVertex();
2605           enfVertex->name = childName;
2606           if (vertexEntry.empty()) {
2607             enfVertex->coords.push_back(childValueX);
2608             enfVertex->coords.push_back(childValueY);
2609             enfVertex->coords.push_back(childValueZ);
2610           }
2611           else
2612             enfVertex->geomEntry = vertexEntry;
2613           enfVertex->grpName = groupName;
2614 //           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
2615 //           if (it == h_data.enfVertexList.end())
2616           h_data.enfVertexList.insert(enfVertex);
2617           evs.insert(enfVertex);
2618           /* TODO GROUPS
2619           if (groupName != "")
2620             h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2621           */
2622         }
2623         h_data.faceEntryEnfVertexListMap[faceEntry] = evs;
2624       }
2625     }
2626   }
2627
2628   h_data.myInternalEnforcedVerticesAllFaces      = myInternalEnforcedVerticesAllFaces->isChecked();
2629   h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2630
2631   // Periodicity
2632   h_data.preCadPeriodicityVector.clear();
2633   // For each tree item, store each value. Shapes are stored as entries.
2634   int nbPeriodicityDescriptions = myPeriodicityTreeWidget->topLevelItemCount();
2635   for (size_t i=0 ; i<nbPeriodicityDescriptions ; i++) {
2636     QTreeWidgetItem* item = myPeriodicityTreeWidget->topLevelItem(i);
2637     TPreCadPeriodicity periodicity_i;
2638     if (item) {
2639         for (size_t k=0; k<myPeriodicityTreeWidget->columnCount(); ++k)
2640           {
2641             MESSAGE(k);
2642             std::string entry = item->data(k, Qt::UserRole).toString().toStdString();
2643             MESSAGE(entry);
2644             periodicity_i.push_back(entry);
2645           }
2646         h_data.preCadPeriodicityVector.push_back(periodicity_i);
2647     }
2648     guiHyp += "PERIODICITY = yes; ";
2649   }
2650
2651   MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
2652   return guiHyp;
2653 }
2654
2655 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2656 {
2657   QMenu* menu = (QMenu*)sender();
2658   // fill popup with option names
2659   menu->clear();
2660   QString name_value, name;
2661   if ( myOptions.operator->() ) {
2662     QMenu* blsurfMenu = menu->addMenu(tr("OPTION_MENU_BLSURF"));
2663     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
2664       name_value = myOptions[i].in();
2665       name = name_value.split( ":", QString::KeepEmptyParts )[0];
2666       blsurfMenu->addAction( name );
2667     }
2668   }
2669   if ( myPreCADOptions.operator->() ) {
2670     QMenu* preCADmenu = menu->addMenu(tr("OPTION_MENU_PRECAD"));
2671     for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
2672       name_value = myPreCADOptions[i].in();
2673       name = name_value.split( ":", QString::KeepEmptyParts )[0];
2674       preCADmenu->addAction( name );
2675     }
2676   }
2677 }
2678
2679 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
2680 {
2681   myAdvWidget->myOptionTable->setFocus();
2682   QMenu* menu = (QMenu*)( a->parent() );
2683
2684   int idx = menu->actions().indexOf( a );
2685   QString idStr = QString("%1").arg( idx );
2686   QString option, optionType;
2687   if (menu->title() == tr("OPTION_MENU_BLSURF")) {
2688     option = myOptions[idx].in();
2689     optionType = "BLSURF";
2690   }
2691   else if (menu->title() == tr("OPTION_MENU_PRECAD")) {
2692     option = myPreCADOptions[idx].in();
2693     optionType = "PRECAD";
2694   }
2695   QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
2696
2697   // look for a row with optionName
2698   int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
2699   for ( ; row < nbRows; ++row )
2700     if ( myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
2701       if ( myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text() == optionType )
2702         break;
2703   // add a row if not found
2704   if ( row == nbRows ) {
2705     myAdvWidget->myOptionTable->setRowCount( row+1 );
2706     myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
2707     myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
2708     myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( optionType ) );
2709     myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
2710     myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
2711     myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
2712     myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
2713     myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
2714                                                                             Qt::ItemIsEditable   |
2715                                                                             Qt::ItemIsEnabled );
2716     myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2717   }
2718   myAdvWidget->myOptionTable->clearSelection();
2719   myAdvWidget->myOptionTable->scrollToItem( myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2720   //myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
2721   myAdvWidget->myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
2722   //myAdvWidget->myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2723 }
2724
2725 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
2726 {
2727   // clear option values and remember selected row
2728   QList<int> selectedRows;
2729   QList<QTableWidgetItem*> selected = myAdvWidget->myOptionTable->selectedItems();
2730   QTableWidgetItem* item;
2731   foreach( item, selected ) {
2732     int row = item->row();
2733     if ( !selectedRows.contains( row ) ) {
2734       selectedRows.append( row );
2735       int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
2736       QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text();
2737       if ( id >= 0 )
2738         if (optionType == "BLSURF" && id < myOptions->length() )
2739           myOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2740         else if (optionType == "PRECAD" && id < myPreCADOptions->length() )
2741           myPreCADOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2742     }
2743   }
2744   qSort( selectedRows );
2745   QListIterator<int> it( selectedRows );
2746   it.toBack();
2747   while ( it.hasPrevious() )
2748     myAdvWidget->myOptionTable->removeRow( it.previous() );
2749 }
2750
2751 // **********************
2752 // *** BEGIN SIZE MAP ***
2753 // **********************
2754
2755 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2756 {
2757   if ( myGeomSelWdg2->IsObjectSelected() ){
2758     mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2759   }
2760   else if ( myGeomSelWdg1->IsObjectSelected() ){
2761     mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2762   }
2763   else {
2764     mySMapObject = GEOM::GEOM_Object::_nil();
2765   }
2766   bool dataAvailable = !mySMapObject->_is_nil();
2767   QString qEntry;
2768   if ( dataAvailable )
2769     qEntry = SMESH::toQStr( mySMapObject->GetStudyEntry() );
2770
2771   bool mapExists = ( mySMPMap.contains(qEntry) && mySMPMap[qEntry] != "__TO_DELETE__" );
2772   if (( mapExists && myGeomSelWdg2->IsObjectSelected() )  &&
2773       ( dataAvailable = myAttSelWdg->isEnabled() )        &&
2774       ( dataAvailable = myAttSelWdg->IsObjectSelected() ) &&
2775       ( myATTMap.contains( qEntry )))
2776   {
2777     mapExists = false;
2778     QString attEntry = myAttSelWdg->GetValue();
2779     const TAttractorVec& attVec = myATTMap[ qEntry ];
2780     for ( size_t i = 0; i < attVec.size() && !mapExists; ++i )
2781       mapExists = ( attEntry == attVec[i].attEntry.c_str() );
2782   }
2783
2784   addMapButton->setEnabled( !mapExists && dataAvailable );
2785   modifyMapButton->setEnabled( mapExists && dataAvailable );
2786 }
2787
2788 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2789
2790   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked("<<col<<")")
2791   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2792   if (col == SMP_SIZEMAP_COLUMN) {
2793     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2794     QString childEntry;
2795     if (!mySMPMap.contains(entry))
2796     {
2797       if ( QTreeWidgetItem* parent = item->parent() )
2798       {
2799         childEntry = entry;
2800         item = parent;
2801         entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2802       }
2803       if (!mySMPMap.contains(entry))
2804         return;
2805     }
2806     QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2807     CORBA::Object_var obj = entryToObject(entry);
2808     if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")) {  // ADVANCED MAPS
2809       smpTab->setCurrentIndex(ATT_TAB);         // Change Tab
2810       // Retrieve values of the selected item in the current tab widgets
2811       const TAttractorVec& attVec = myATTMap[entry];
2812       if ( !attVec.empty() )
2813       {
2814         int iAtt = 0;
2815         if ( !childEntry.isEmpty() )
2816           for ( size_t i = 0; i < attVec.size(); ++i )
2817             if ( childEntry == attVec[i].attEntry.c_str() )
2818             {
2819               iAtt = i;
2820               break;
2821             }
2822         double phySize   = attVec[iAtt].startSize;
2823         double infDist   = attVec[iAtt].infDist;
2824         double constDist = attVec[iAtt].constDist;
2825         QString attEntry = attVec[iAtt].attEntry.c_str();
2826         CORBA::Object_var attObj = entryToObject(attEntry);
2827         myAttSizeSpin->setValue(phySize);
2828         if ( infDist > std::numeric_limits<double>::epsilon() /*sizeMap.startsWith("Attractor")*/){
2829           myAttDistSpin->setValue(infDist);
2830           myAttractorCheck->setChecked(true);
2831         }
2832         else {
2833           myAttractorCheck->setChecked(false);
2834         }
2835         if (/*sizeMap.startsWith("Constant") || */constDist > std::numeric_limits<double>::epsilon()){
2836           myAttDistSpin2->setValue(constDist);
2837           myConstSizeCheck->setChecked(true);
2838         }
2839         else{
2840           myConstSizeCheck->setChecked(false);
2841         }
2842         myGeomSelWdg2->SetObject(obj);
2843         myAttSelWdg->SetObject(attObj);
2844       }
2845     }
2846     else {                                                                   // CLASSIC MAPS
2847       smpTab->setCurrentIndex(SMP_STD_TAB);  // Change Tab
2848       myGeomSelWdg1->SetObject(obj);         // Retrieve values of the selected item in the current tab widgets
2849       if (!sizeMap.startsWith("def")){
2850         mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
2851       }
2852     }
2853   }
2854 }
2855
2856 void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
2857 {
2858   getGeomSelectionTool()->selectionMgr()->clearFilters();
2859   if ( sender() == myTabWidget )
2860   {
2861     myGeomSelWdg1             ->deactivateSelection();
2862     myGeomSelWdg2             ->deactivateSelection();
2863     myAttSelWdg               ->deactivateSelection();
2864     myEnfFaceWdg              ->deactivateSelection();
2865     myEnfVertexWdg            ->deactivateSelection();
2866     myPeriodicitySourceFaceWdg->deactivateSelection();
2867     myPeriodicityTargetFaceWdg->deactivateSelection();
2868     myPeriodicityP1SourceWdg  ->deactivateSelection();
2869     myPeriodicityP2SourceWdg  ->deactivateSelection();
2870     myPeriodicityP3SourceWdg  ->deactivateSelection();
2871     myPeriodicityP1TargetWdg  ->deactivateSelection();
2872     myPeriodicityP2TargetWdg  ->deactivateSelection();
2873     myPeriodicityP3TargetWdg  ->deactivateSelection();
2874     return;
2875   }
2876   else if ( sender() == smpTab )
2877   {
2878     myAttDistSpin->setValue(0.);           // Reinitialize widgets
2879     myAttSizeSpin->setValue(0.);
2880     myAttDistSpin2->setValue(0.);
2881     mySmpSizeSpin->setValue(0.);
2882     myGeomSelWdg1->deactivateSelection();
2883     myGeomSelWdg2->deactivateSelection();
2884     myAttSelWdg->deactivateSelection();
2885     myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2886     myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2887     myAttSelWdg->SetObject(CORBA::Object::_nil());
2888     myAttractorCheck->setChecked(false);
2889     myConstSizeCheck->setChecked(false);
2890   }
2891 }
2892
2893 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2894 {
2895   if (state == Qt::Checked){
2896     myAttSelWdg->setEnabled(true);
2897     myAttSizeSpin->setEnabled(true);
2898     myAttSizeLabel->setEnabled(true);
2899     myAttDistSpin->setEnabled(true);
2900     myAttDistLabel->setEnabled(true);
2901     if (!myAttSelWdg->IsObjectSelected()){
2902       myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2903     }
2904   }
2905   if (state == Qt::Unchecked){
2906     myAttDistSpin->setEnabled(false);
2907     myAttDistLabel->setEnabled(false);
2908     myAttDistSpin->setValue(0.);
2909     if(myConstSizeCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2910       myAttSelWdg->setEnabled(false);
2911       myAttSizeSpin->setEnabled(false);
2912       myAttSizeLabel->setEnabled(false);
2913       myAttDistSpin2->setEnabled(false);
2914       myAttDistLabel2->setEnabled(false);
2915     }
2916     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2917       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2918     }
2919   }
2920   onMapGeomContentModified();
2921 }
2922
2923 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2924
2925   if (state == Qt::Checked){
2926     myAttSelWdg->setEnabled(true);
2927     myAttSizeSpin->setEnabled(true);
2928     myAttSizeLabel->setEnabled(true);
2929     myAttDistSpin2->setEnabled(true);
2930     myAttDistLabel2->setEnabled(true);
2931     if (myAttractorCheck->checkState() == Qt::Unchecked &&
2932         !myAttSelWdg->IsObjectSelected()){
2933       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2934     }
2935   }
2936   if (state == Qt::Unchecked){
2937     myAttDistSpin2->setEnabled(false);
2938     myAttDistLabel2->setEnabled(false);
2939     myAttDistSpin2->setValue(0.);
2940     if(myAttractorCheck->checkState() == Qt::Unchecked){  // No predefined map selected
2941         myAttSelWdg->setEnabled(false);
2942         myAttSizeSpin->setEnabled(false);
2943         myAttSizeLabel->setEnabled(false);
2944         myAttDistSpin->setEnabled(false);
2945         myAttDistLabel->setEnabled(false);
2946     }
2947     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
2948     myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2949     }
2950   }   
2951   onMapGeomContentModified();
2952 }
2953
2954 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
2955 {
2956   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
2957   QList<int> selectedRows;
2958   QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
2959   QTreeWidgetItem* item;
2960   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2961
2962   qSort( selectedRows );
2963   QListIterator<QTreeWidgetItem*> it( selected );
2964   it.toBack();
2965   while ( it.hasPrevious() ) {
2966       item = it.previous();
2967       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2968       QString parentEntry;
2969       if ( QTreeWidgetItem* parent = item->parent() )
2970         parentEntry = parent->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2971       if (that->mySMPMap.contains(entry))
2972       {
2973         that->mySMPMap[entry] = "__TO_DELETE__";
2974         if ( myATTMap.contains( entry ))
2975         {
2976           TAttractorVec& attVec = myATTMap[entry];
2977           for ( size_t i = 0; i < attVec.size(); ++i )
2978             attVec[i].SetToDelete();
2979         }          
2980       }
2981       else if ( mySMPMap.contains( parentEntry ) && myATTMap.contains( parentEntry ))
2982       {
2983         TAttractorVec& attVec = myATTMap[parentEntry];
2984         for ( size_t i = 0; i < attVec.size(); ++i )
2985         {
2986           if ( entry == attVec[i].attEntry.c_str() )
2987             attVec[i].SetToDelete();
2988         }
2989       }
2990       if (that->mySMPShapeTypeMap.contains(entry))
2991         that->mySMPShapeTypeMap.remove(entry);
2992       // if (that->myDistMap.contains(entry))
2993       //   that->myDistMap.remove(entry);
2994       // if (that->myAttDistMap.contains(entry))
2995       //   that->myAttDistMap.remove(entry);
2996       delete item;
2997   }
2998   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
2999   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
3000 }
3001
3002 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
3003 {
3004   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< col << ")");
3005   MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
3006   if (col == SMP_SIZEMAP_COLUMN) {
3007     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3008     QString entry   = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
3009     QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
3010     MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
3011     if (! that->mySMPShapeTypeMap.contains(entry))
3012       MESSAGE("no such entry in mySMPShapeTypeMap")
3013       return;
3014     if (that->mySMPMap.contains(entry))
3015       if (that->mySMPMap[entry] == sizeMap 
3016         || sizeMap.startsWith("Attractor") 
3017         || sizeMap.startsWith("Constant") ){
3018         return;
3019       } 
3020     if (! sizeMap.isEmpty()) {
3021       that->mySMPMap[entry] = sizeMap;
3022       sizeMapValidationFromEntry(entry); 
3023     }
3024     else {
3025       MESSAGE("Size map empty: reverse to precedent value" );
3026       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
3027     }
3028     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
3029   }
3030 }
3031
3032 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
3033 {
3034   bool res = false;
3035   if ( smpTab->currentIndex() == ATT_TAB ){
3036     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
3037       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3038       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3039       res = insertAttractor(mySMapObject, myAttObject);
3040     }
3041   }
3042   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3043     if ( myGeomSelWdg1->IsObjectSelected() ){
3044       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3045       res = insertElement(mySMapObject);
3046     }
3047   }
3048   if ( !res ) {
3049     // Local size should be more than 0
3050     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3051     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3052     return;
3053   }
3054   getGeomSelectionTool()->selectionMgr()->clearFilters();
3055   myAttDistSpin->setValue(0.);
3056   myAttSizeSpin->setValue(0.);
3057   myAttDistSpin2->setValue(0.);
3058   mySmpSizeSpin->setValue(0.);
3059   myConstSizeCheck->setChecked(false);
3060   myAttractorCheck->setChecked(false);
3061   myGeomSelWdg1->deactivateSelection();
3062   myGeomSelWdg2->deactivateSelection();
3063   myAttSelWdg->deactivateSelection();
3064   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3065   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3066   myAttSelWdg->SetObject(CORBA::Object::_nil());
3067 }
3068
3069 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
3070 {
3071   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onModifyMap()");
3072   bool res = false;
3073   if ( smpTab->currentIndex() == ATT_TAB ){    
3074     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
3075       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
3076       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
3077       res = insertAttractor(mySMapObject, myAttObject, /*modify = */true);
3078     }
3079   }
3080   if (smpTab->currentIndex() == SMP_STD_TAB  ){
3081     if ( myGeomSelWdg1->IsObjectSelected() ){
3082       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
3083       res = insertElement(mySMapObject, /*modify = */true);  
3084     }  
3085   }
3086   if ( !res ) {
3087     // Local size should be more than 0
3088     QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
3089     SUIT_MessageBox::critical( dlg(),"Error" , msg );
3090     return;
3091   }
3092   getGeomSelectionTool()->selectionMgr()->clearFilters();
3093   myAttDistSpin->setValue(0.);
3094   myAttSizeSpin->setValue(0.);
3095   myAttDistSpin2->setValue(0.);
3096   mySmpSizeSpin->setValue(0.);
3097   myConstSizeCheck->setChecked(false);
3098   myAttractorCheck->setChecked(false);
3099   myGeomSelWdg1->deactivateSelection();
3100   myGeomSelWdg2->deactivateSelection();
3101   myAttSelWdg->deactivateSelection();
3102   myGeomSelWdg1->SetObject(CORBA::Object::_nil());
3103   myGeomSelWdg2->SetObject(CORBA::Object::_nil());
3104   myAttSelWdg->SetObject(CORBA::Object::_nil());
3105 }
3106
3107 bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
3108 {
3109   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElement()");
3110   // BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3111   //   BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3112
3113   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3114
3115   TopAbs_ShapeEnum shapeType;
3116   string entry, shapeName;
3117   entry = (string) anObject->GetStudyEntry();
3118   MESSAGE("entry = "<<entry);
3119   shapeName = anObject->GetName();
3120   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
3121   // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
3122   // in order to write the size map with the right syntax in StoreParamsToHypo 
3123   // (f(t) for edges, f(u,v) for faces ...)
3124   if (shapeType == TopAbs_COMPOUND){
3125     TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
3126     TopoDS_Shape childShape;
3127     TopoDS_Iterator anIt(theShape);
3128     for(;anIt.More();anIt.Next()){
3129       childShape = anIt.Value();
3130       shapeType = childShape.ShapeType();
3131       if(!childShape.IsNull()){
3132         break;
3133       }
3134     }
3135   }
3136   mySizeMapTable->setFocus();
3137   QString shapeEntry;
3138   shapeEntry = QString::fromStdString(entry);
3139   double phySize = mySmpSizeSpin->value();
3140
3141   if ( phySize == 0 )
3142     return false; // Local size should be more than 0
3143
3144   std::ostringstream oss;
3145   oss << phySize;
3146   QString sizeMap;
3147   sizeMap  = QString::fromStdString(oss.str());
3148   QTreeWidgetItem* item = new QTreeWidgetItem();
3149   if (modify){
3150     int rowToChange = findRowFromEntry(shapeEntry);
3151     item = mySizeMapTable->topLevelItem( rowToChange );
3152   }
3153   else{
3154     if (that->mySMPMap.contains(shapeEntry)) {  
3155       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3156   //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
3157         return false;
3158       }
3159     }
3160     mySizeMapTable->addTopLevelItem(item);
3161   }
3162   that->mySMPMap[shapeEntry] = sizeMap;
3163   //that->myDistMap[shapeEntry] = 0. ;
3164   that->mySMPShapeTypeMap[shapeEntry] = shapeType;
3165   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
3166   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3167   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
3168   item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3169   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3170   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3171   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3172   mySizeMapTable->clearSelection();
3173
3174   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3175     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3176     myStdWidget->onPhysicalMeshChanged();
3177   }
3178   return true;
3179 }
3180
3181 bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
3182 {
3183   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertAttractor()");
3184   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
3185     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
3186
3187   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3188
3189   TopAbs_ShapeEnum shapeType;
3190   string entry, attEntry, faceName, attName;
3191   entry = (string) aFace->GetStudyEntry();
3192   attEntry = (string) anAttractor->GetStudyEntry();
3193   faceName = aFace->GetName();
3194   attName = anAttractor->GetName();
3195   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
3196   mySizeMapTable->setFocus();
3197   QString shapeEntry = QString::fromStdString(entry);
3198   QString qAttEntry = QString::fromStdString(attEntry);
3199   
3200   double phySize = h->GetPhySize();
3201   double infDist = 0. ;
3202   double constDist = 0. ;
3203   phySize = myAttSizeSpin->value();
3204
3205   if ( phySize == 0 )
3206     return false; // Local size should be more than 0
3207
3208   if (myAttractorCheck->isChecked()){
3209     infDist = myAttDistSpin->value();
3210   }
3211   if (myConstSizeCheck->isChecked()){
3212     constDist = myAttDistSpin2->value();
3213   } 
3214   std::ostringstream oss;
3215   std::ostringstream oss2;
3216   std::ostringstream oss3;
3217   oss << phySize;
3218   oss2 << infDist;
3219   oss3 << constDist;
3220   QString sizeMap  = QString::fromStdString(oss.str());
3221   QString infDistString = QString::fromStdString(oss2.str());
3222   QString constDistString = QString::fromStdString(oss3.str());
3223   
3224   QTreeWidgetItem* item; 
3225   QTreeWidgetItem* child;
3226   TAttractor attParams( attEntry.c_str(), phySize, infDist, constDist );
3227   if (modify) {
3228     int rowToChange = findRowFromEntry(shapeEntry);
3229     item = mySizeMapTable->topLevelItem( rowToChange );
3230     
3231     for ( int i = 0, nb = item->childCount(); i < nb; ++i )
3232       if (( child = item->child( i )))
3233         if ( qAttEntry == child->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString() )
3234           break;
3235     TAttractorVec & attVec = myATTMap[shapeEntry];
3236     for ( size_t i = 0; i < attVec.size(); ++i )
3237       if ( attVec[i].attEntry == attEntry )
3238       {
3239         attVec[i] = attParams;
3240         break;
3241       }
3242   }
3243   else{
3244     // if (that->mySMPMap.contains(shapeEntry)) {  
3245     //   if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
3246     // //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
3247     //     return false;
3248     //   }
3249     // }
3250     int rowToChange = findRowFromEntry(shapeEntry);
3251     if ( rowToChange < mySizeMapTable->topLevelItemCount() )
3252     {
3253       item = mySizeMapTable->topLevelItem( rowToChange );
3254     }
3255     else {
3256       item = new QTreeWidgetItem();
3257       mySizeMapTable->addTopLevelItem(item);
3258     }
3259     child = new QTreeWidgetItem();
3260     item->addChild(child);
3261     bool exists = false;
3262     TAttractorVec & attVec = myATTMap[shapeEntry];
3263     for ( size_t i = 0; i < attVec.size(); ++i )
3264       if ( attVec[i].attEntry == attEntry )
3265       {
3266         attVec[i] = attParams;
3267         exists = true;
3268         break;
3269       }
3270     if ( !exists )
3271       myATTMap[shapeEntry].push_back( attParams );
3272   }
3273   mySMPMap.insert(shapeEntry,sizeMap);
3274   mySMPShapeTypeMap.insert(shapeEntry,shapeType);
3275   item->setExpanded(true); 
3276   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
3277   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
3278   if (infDist > std::numeric_limits<double>::epsilon()){
3279     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
3280   }
3281   else if (constDist > std::numeric_limits<double>::epsilon()){
3282     item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
3283   }
3284   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );    
3285   
3286   child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
3287   child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
3288   child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
3289   
3290   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
3291   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
3292   mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
3293
3294   if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
3295     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
3296     myStdWidget->onPhysicalMeshChanged();
3297   }
3298   MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
3299   return true;
3300 }
3301
3302 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
3303 {
3304   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
3305   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
3306   for ( ; row < nbRows; ++row )
3307     if (! sizeMapValidationFromRow(row))
3308       return false;
3309   return true;
3310 }
3311
3312 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
3313 {
3314   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(), row = "<<myRow);
3315   QString myEntry   = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3316   bool res = sizeMapValidationFromEntry(myEntry,displayError);
3317   mySizeMapTable->setFocus();
3318   return res;
3319 }
3320
3321 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
3322 {
3323   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
3324   MESSAGE("myEntry = "<<myEntry.toStdString())
3325
3326   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
3327
3328   if (! that->mySMPMap.contains(myEntry)) {
3329 //     MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
3330     return false;
3331   }
3332   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
3333 //     MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
3334     return false;
3335   }
3336
3337   string expr;
3338
3339   if (that->mySMPMap[myEntry].startsWith("def")) {
3340 //     MESSAGE("custom function" );
3341     expr = that->mySMPMap[myEntry].toStdString();
3342   }
3343   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
3344 //     MESSAGE("Attractor" );
3345     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)) {
3346
3347       if (displayError)
3348         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])" );
3349       return false;
3350     }
3351     return true;
3352   }
3353   else {
3354     // case size map is empty
3355     if (that->mySMPMap[myEntry].isEmpty()) {
3356       if (displayError)
3357         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
3358       return false;
3359     }
3360     else {
3361       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
3362         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
3363       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
3364         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
3365       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
3366         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
3367     }
3368   }
3369   //assert(Py_IsInitialized());
3370   if (! Py_IsInitialized())
3371     throw ("Erreur: Python interpreter is not initialized");
3372   PyGILState_STATE gstate;
3373   gstate = PyGILState_Ensure();
3374
3375   PyObject * obj = NULL;
3376   PyObject* new_stderr = NULL;
3377   string  err_description="";
3378   obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
3379   if (obj == NULL){
3380     fflush(stderr);
3381     err_description="";
3382     new_stderr=newPyStdOut(err_description);
3383     PySys_SetObject((char*)"stderr", new_stderr);
3384     PyErr_Print();
3385     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
3386     Py_DECREF(new_stderr);
3387     if (displayError)
3388       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
3389     PyGILState_Release(gstate);
3390     return false;
3391   }
3392   Py_DECREF(obj);
3393
3394   PyObject * func = NULL;
3395   func = PyObject_GetAttrString(main_mod, "f");
3396   if ( func == NULL){
3397     fflush(stderr);
3398     err_description="";
3399     new_stderr=newPyStdOut(err_description);
3400     PySys_SetObject((char*)"stderr", new_stderr);
3401     PyErr_Print();
3402     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
3403     Py_DECREF(new_stderr);
3404     if (displayError)
3405       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
3406     PyGILState_Release(gstate);
3407     return false;
3408   }
3409
3410   PyGILState_Release(gstate);
3411
3412 //   MESSAGE("SizeMap expression "<<expr<<" is valid");
3413
3414   return true;
3415 }
3416
3417 QString BLSURFPluginGUI_HypothesisCreator::caption() const
3418 {
3419   return tr( "BLSURF_TITLE" );
3420 }
3421
3422 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
3423 {
3424   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
3425 }
3426
3427 QString BLSURFPluginGUI_HypothesisCreator::type() const
3428 {
3429   return tr( "BLSURF_HYPOTHESIS" );
3430 }
3431
3432 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
3433 {
3434   return "blsurf_hypo_page.html";
3435 }
3436
3437 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
3438 {
3439
3440   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3441   if( anApp )
3442     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3443   else
3444     return 0;
3445 }
3446
3447 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
3448 {
3449   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
3450   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
3451   CORBA::Object_var obj;
3452   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
3453   if (!aSObj->_is_nil()) {
3454     obj = aSObj->GetObject();
3455     aSObj->UnRegister();
3456   }
3457   return obj;
3458 }
3459
3460 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
3461   int endRow = mySizeMapTable->topLevelItemCount()-1;
3462   int row = 0;
3463   for ( ; row <= endRow; ++row )
3464   {
3465     QString entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
3466     if (entry == entryForChecking )
3467       break;
3468   }
3469   MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)
3470   return row;
3471 }
3472
3473