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