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