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