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