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