]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
Salome HOME
merge from branch V5_1_sizemap tag mergeto_V5_1_main_8oct09
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1         //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // ---
20 // File    : BLSURFPluginGUI_HypothesisCreator.cxx
21 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
22 //           & Aurelien ALLEAUME (DISTENE)
23 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
24 // ---
25 //
26 #include "BLSURFPluginGUI_HypothesisCreator.h"
27
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_Dialog.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Tools.h>
36 #include <SalomeApp_DoubleSpinBox.h>
37
38 #include <QComboBox>
39 #include <QLabel>
40 #include <QGroupBox>
41 #include <QFrame>
42 #include <QVBoxLayout>
43 #include <QHBoxLayout>
44 #include <QGridLayout>
45 #include <QLineEdit>
46 #include <QCheckBox>
47 #include <QTabWidget>
48 #include <QSpinBox>
49 #include <QPushButton>
50 #include <QMenu>
51 #include <QTableWidget>
52 #include <QHeaderView>
53 #include <QApplication>
54 #include <QRadioButton>
55
56 #include <QStandardItemModel>
57 #include <QStandardItem>
58 #include <QTreeWidget>
59 #include <QTreeWidgetItem>
60 #include <QModelIndexList>
61
62 #include <LightApp_SelectionMgr.h>
63 #include <SalomeApp_Application.h>
64 #include <SALOME_ListIO.hxx>
65 #include <SALOME_ListIteratorOfListIO.hxx>
66
67 #include <GEOM_Client.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <SMESH_Gen_i.hxx>
70 #include <boost/shared_ptr.hpp>
71 #include <structmember.h>
72
73 // #include <GeomSelectionTools.h>
74 #define WITH_SIZE_BOUNDARIES
75
76 enum Topology {
77     FromCAD,
78     Process,
79     Process2
80   } ;
81
82 enum PhysicalMesh
83   {
84     DefaultSize = 0,
85     PhysicalUserDefined,
86     SizeMap
87   };
88
89 enum GeometricMesh
90   {
91     DefaultGeom = 0,
92     UserDefined
93   };
94
95 enum {
96   STD_TAB = 0,
97   ADV_TAB,
98   SMP_TAB,
99   ENF_TAB,
100   OPTION_ID_COLUMN = 0,
101   OPTION_NAME_COLUMN,
102   OPTION_VALUE_COLUMN,
103   NB_COLUMNS,
104   SMP_ENTRY_COLUMN = 0,
105   SMP_NAME_COLUMN,
106   SMP_SIZEMAP_COLUMN,
107   SMP_NB_COLUMNS
108 };
109
110 enum {
111   SMP_BTNS = 0,
112 //   SMP_ATTRACTOR_BTN,
113 //   SMP_SEPARATOR1,
114   SMP_POINT_BTN,
115   SMP_EDGE_BTN,
116   SMP_SURFACE_BTN,
117   SMP_SEPARATOR2,
118   SMP_REMOVE_BTN,
119 };
120
121 // Enforced vertices inputs
122 enum {
123   ENF_VER_BTNS = 0,
124   ENF_VER_X_COORD = 0,
125   ENF_VER_Y_COORD,
126   ENF_VER_Z_COORD,
127   ENF_VER_VERTEX_BTN,
128   ENF_VER_SEPARATOR,
129   ENF_VER_REMOVE_BTN,
130 };
131
132 // Enforced vertices array columns
133 enum {
134   ENF_VER_NAME_COLUMN = 0,
135   ENF_VER_ENTRY_COLUMN,
136   ENF_VER_X_COLUMN,
137   ENF_VER_Y_COLUMN,
138   ENF_VER_Z_COLUMN,
139   ENF_VER_NB_COLUMNS
140 };
141
142
143 /**************************************************
144  Begin initialization Python structures and objects
145 ***************************************************/
146
147 typedef struct {
148   PyObject_HEAD
149   int softspace;
150   std::string *out;
151   } PyStdOut;
152
153 static void
154 PyStdOut_dealloc(PyStdOut *self)
155 {
156   PyObject_Del(self);
157 }
158
159 static PyObject *
160 PyStdOut_write(PyStdOut *self, PyObject *args)
161 {
162   char *c;
163   int l;
164   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
165     return NULL;
166
167   //std::cerr << c ;
168   *(self->out)=*(self->out)+c;
169
170   Py_INCREF(Py_None);
171   return Py_None;
172 }
173
174 static PyMethodDef PyStdOut_methods[] = {
175   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
176     PyDoc_STR("write(string) -> None")},
177   {NULL,    NULL}   /* sentinel */
178 };
179
180 static PyMemberDef PyStdOut_memberlist[] = {
181   {"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
182    "flag indicating that a space needs to be printed; used by print"},
183   {NULL} /* Sentinel */
184 };
185
186 static PyTypeObject PyStdOut_Type = {
187   /* The ob_type field must be initialized in the module init function
188    * to be portable to Windows without using C++. */
189   PyObject_HEAD_INIT(NULL)
190   0,                            /*ob_size*/
191   "PyOut",                      /*tp_name*/
192   sizeof(PyStdOut),             /*tp_basicsize*/
193   0,                            /*tp_itemsize*/
194   /* methods */
195   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
196   0,                            /*tp_print*/
197   0,                            /*tp_getattr*/
198   0,                            /*tp_setattr*/
199   0,                            /*tp_compare*/
200   0,                            /*tp_repr*/
201   0,                            /*tp_as_number*/
202   0,                            /*tp_as_sequence*/
203   0,                            /*tp_as_mapping*/
204   0,                            /*tp_hash*/
205   0,                            /*tp_call*/
206   0,                            /*tp_str*/
207   PyObject_GenericGetAttr,      /*tp_getattro*/
208   /* softspace is writable:  we must supply tp_setattro */
209   PyObject_GenericSetAttr,      /* tp_setattro */
210   0,                            /*tp_as_buffer*/
211   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
212   0,                            /*tp_doc*/
213   0,                            /*tp_traverse*/
214   0,                            /*tp_clear*/
215   0,                            /*tp_richcompare*/
216   0,                            /*tp_weaklistoffset*/
217   0,                            /*tp_iter*/
218   0,                            /*tp_iternext*/
219   PyStdOut_methods,             /*tp_methods*/
220   PyStdOut_memberlist,          /*tp_members*/
221   0,                            /*tp_getset*/
222   0,                            /*tp_base*/
223   0,                            /*tp_dict*/
224   0,                            /*tp_descr_get*/
225   0,                            /*tp_descr_set*/
226   0,                            /*tp_dictoffset*/
227   0,                            /*tp_init*/
228   0,                            /*tp_alloc*/
229   0,                            /*tp_new*/
230   0,                            /*tp_free*/
231   0,                            /*tp_is_gc*/
232 };
233
234 PyObject * newPyStdOut( std::string& out )
235 {
236   PyStdOut *self;
237   self = PyObject_New(PyStdOut, &PyStdOut_Type);
238   if (self == NULL)
239     return NULL;
240   self->softspace = 0;
241   self->out=&out;
242   return (PyObject*)self;
243 }
244
245 /*************************************************
246 End initialization Python structures and objects
247 **************************************************/
248
249
250 class QDoubleValidator;
251
252 //
253 // BEGIN EnforcedTreeWidgetDelegate
254 //
255
256 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
257   : QItemDelegate(parent)
258 {
259 }
260
261 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
262                                               const QStyleOptionViewItem & option ,
263                                               const QModelIndex & index ) const
264 {
265   QLineEdit *editor = new QLineEdit(parent);
266   if (index.column() == ENF_VER_X_COLUMN || \
267     index.column() == ENF_VER_Y_COLUMN || \
268     index.column() == ENF_VER_Z_COLUMN)
269     editor->setValidator(new QDoubleValidator(parent));
270
271   return editor;
272 }
273
274 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
275                                            const QModelIndex &index) const
276 {
277   QString value = index.model()->data(index, Qt::EditRole).toString();
278
279   QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
280   lineEdit->setText(value);
281 }
282
283 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
284                                           const QModelIndex &index) const
285 {
286   QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
287
288   if (index.column() == ENF_VER_X_COLUMN || \
289     index.column() == ENF_VER_Y_COLUMN || \
290     index.column() == ENF_VER_Z_COLUMN)
291   {
292     if (not vertexExists(model, index, lineEdit->text())) {
293       bool ok;
294       double value = lineEdit->text().toDouble(&ok);
295       if (ok)
296         model->setData(index, value, Qt::EditRole);
297     }
298   }
299   else if (index.column() == ENF_VER_NAME_COLUMN) {
300     QString value = lineEdit->text();
301     if (not vertexExists(model, index, value))
302       model->setData(index, value, Qt::EditRole);
303 //     MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")");
304   }
305 }
306
307 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
308     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
309 {
310   editor->setGeometry(option.rect);
311 }
312
313 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
314     const QModelIndex &index, QString value) const
315 {
316   bool exists = false;
317   QModelIndex parent = index.parent();
318   int row = index.row();
319   int col = index.column();
320   
321   if (parent.isValid()) {
322     if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
323       double x, y, z;
324       if (col == ENF_VER_X_COLUMN) {
325         x = value.toDouble();
326         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
327         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
328       }
329       if (col == ENF_VER_Y_COLUMN) {
330         y = value.toDouble();
331         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
332         z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
333       }
334       if (col == ENF_VER_Z_COLUMN) {
335         z = value.toDouble();
336         x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
337         y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
338       }
339       // MESSAGE("Checking for existing vertex " << x << ", " << y << "," << z);
340       int nbChildren = model->rowCount(parent);
341       for (int i = 0 ; i < nbChildren ; i++) {
342         if (i != row) {
343           double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
344           double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
345           double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
346 //           MESSAGE("Vertex: " << childX << ", " << childY << "," << childZ);
347           if ((childX == x) && (childY == y) && (childZ == z)) {
348 //             MESSAGE("Found !");
349             exists = true;
350             break;
351           }
352         }
353       }
354     }
355     else if (index.column() == ENF_VER_NAME_COLUMN) {
356       int nbChildren = model->rowCount(parent);
357       for (int i = 0 ; i < nbChildren ; i++) {
358         if (i != row) {
359           QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
360           if (childName == value) {
361             exists = true;
362             break;
363           }
364         }
365       }
366     }
367   }
368
369   return exists;
370 }
371
372 //
373 // END EnforcedTreeWidgetDelegate
374 //
375
376
377 /**
378  * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
379  * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
380  *
381  * */
382 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
383   : SMESHGUI_GenericHypothesisCreator( theHypType )
384 {
385   MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
386   this->mySMPMap.clear();
387
388   GeomToolSelected = NULL;
389   GeomToolSelected = getGeomSelectionTool();
390
391   aSel = GeomToolSelected->selectionMgr();
392
393   /* Initialize the Python interpreter */
394   if (! Py_IsInitialized())
395     throw ("Error: Python interpreter is not initialized");
396   PyGILState_STATE gstate;
397   gstate = PyGILState_Ensure();
398
399   main_mod = NULL;
400   main_mod = PyImport_AddModule("__main__");
401
402   main_dict = NULL;
403   main_dict = PyModule_GetDict(main_mod);
404
405   PyRun_SimpleString("from math import *");
406   PyGILState_Release(gstate);
407   
408 }
409
410 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
411 {
412 }
413
414 /**
415  * \brief {Get or create the geom selection tool for active study}
416  * */
417 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
418 {
419 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool");
420   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
421   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
422 //   MESSAGE("aStudy->StudyId(): " << aStudy->StudyId());
423   if (that->GeomToolSelected == NULL or that->GeomToolSelected->getMyStudy() != aStudy) {
424 //     MESSAGE("GeomToolSelected is created");
425     that->GeomToolSelected = new GeomSelectionTools(aStudy);
426   }
427 //   else
428 //     MESSAGE("GeomToolSelected already exists");
429 //   MESSAGE("that->GeomToolSelected->getMyStudy()->StudyId(): " << that->GeomToolSelected->getMyStudy()->StudyId());
430   return that->GeomToolSelected;
431 }
432
433 namespace {
434   inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
435     QString str = theText.trimmed();
436     bool isOk = true;
437     if ( !str.isEmpty() )
438       str.toDouble(&isOk);
439     else
440       isOk = emptyOK;
441     return isOk;
442   }
443 }
444
445
446 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
447 {
448   MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
449   bool ok = true;
450   if ( !isDouble( myPhySize->text(), false )) {
451     if ( myPhySize->text().isEmpty() )
452       myPhySize->setText(tr("OBLIGATORY_VALUE"));
453     myPhySize->selectAll();
454     ok = false;
455   }
456   if ( !isDouble( myPhyMin->text(), true )) {
457     myPhyMin->selectAll();
458     ok = false;
459   }
460   if ( !isDouble( myPhyMax->text(), true )) {
461     myPhyMax->selectAll();
462     ok = false;
463   }
464   if ( !isDouble( myGeoMin->text(), true )) {
465     myGeoMin->selectAll();
466     ok = false;
467   }
468   if ( !isDouble( myGeoMin->text(), true )) {
469     myGeoMin->selectAll();
470     ok = false;
471   }
472   if ( ok )
473   {
474     myOptionTable->setFocus();
475     QApplication::instance()->processEvents();
476
477     BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
478       BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
479
480     int row = 0, nbRows = myOptionTable->rowCount();
481     for ( ; row < nbRows; ++row )
482     {
483       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
484       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
485       if ( !value.isEmpty() ) {
486         try {
487           h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
488         }
489         catch ( const SALOME::SALOME_Exception& ex )
490         {
491           SUIT_MessageBox::critical( dlg(),
492                                      tr("SMESH_ERROR"),
493                                      ex.details.text.in() );
494           ok = false;
495         }
496       }
497     }
498     h->SetOptionValues( myOptions ); // restore values
499   }
500
501   // SizeMap and attractors
502   if ( ok )
503   {
504     mySizeMapTable->setFocus();
505     QApplication::instance()->processEvents();
506
507     BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
508     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
509
510     int row = 0, nbRows = mySizeMapTable->rowCount();
511     for ( ; row < nbRows; ++row )
512     {
513       QString entry   = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
514       QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
515       if ( !sizeMap.isEmpty() ) {
516         if (that->sizeMapValidationFromRow(row))
517         {
518           try {
519             const char* e = entry.toLatin1().constData();
520             const char* s = that->mySMPMap[entry].toLatin1().constData();
521             h->SetSizeMapEntry( e, s );
522           }
523           catch ( const SALOME::SALOME_Exception& ex )
524           {
525             SUIT_MessageBox::critical( dlg(),
526                                        tr("SMESH_ERROR"),
527                                        ex.details.text.in() );
528             ok = false;
529           }
530         }
531         else {
532           ok = false;
533         }
534       }
535     }
536   }
537
538   // Enforced vertices
539   // TODO
540   
541   return ok;
542 }
543
544 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
545 {
546   MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
547   QFrame* fr = new QFrame( 0 );
548   QVBoxLayout* lay = new QVBoxLayout( fr );
549   lay->setMargin( 5 );
550   lay->setSpacing( 0 );
551
552   // tab
553   QTabWidget* tab = new QTabWidget( fr );
554   tab->setTabShape( QTabWidget::Rounded );
555   tab->setTabPosition( QTabWidget::North );
556   lay->addWidget( tab );
557
558   // basic parameters
559   myStdGroup = new QWidget();
560   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
561   aStdLayout->setSpacing( 6 );
562   aStdLayout->setMargin( 11 );
563
564   int row = 0;
565   myName = 0;
566   if( isCreation() ) {
567     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
568     myName = new QLineEdit( myStdGroup );
569     aStdLayout->addWidget( myName, row++, 1, 1, 1 );
570   }
571
572   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
573   myGradation = new SalomeApp_DoubleSpinBox( myStdGroup );
574   aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
575   myGradation->setMinimum( 1.1 );
576   myGradation->setMaximum( 2.5 );
577   myGradation->setSingleStep( 0.1 );
578
579   aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
580   myPhysicalMesh = new QComboBox( myStdGroup );
581   aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
582   QStringList physicalTypes;
583   physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
584   myPhysicalMesh->addItems( physicalTypes );
585
586   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
587   myPhySize = new QLineEdit( myStdGroup );
588   aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
589
590 #ifdef WITH_SIZE_BOUNDARIES
591   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
592   myPhyMin = new QLineEdit( myStdGroup );
593   aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
594
595   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
596   myPhyMax = new QLineEdit( myStdGroup );
597   aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
598 #endif
599
600   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
601   myGeometricMesh = new QComboBox( myStdGroup );
602   aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
603   QStringList types;
604   types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
605   myGeometricMesh->addItems( types );
606
607   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
608   myAngleMeshS = new SalomeApp_DoubleSpinBox( myStdGroup );
609   aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
610   myAngleMeshS->setMinimum( 0 );
611   myAngleMeshS->setMaximum( 16 );
612   myAngleMeshS->setSingleStep( 0.5 );
613
614   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
615   myAngleMeshC = new SalomeApp_DoubleSpinBox( myStdGroup );
616   aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
617   myAngleMeshC->setMinimum( 0 );
618   myAngleMeshC->setMaximum( 16 );
619   myAngleMeshC->setSingleStep( 0.5 );
620
621 #ifdef WITH_SIZE_BOUNDARIES
622   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
623   myGeoMin = new QLineEdit( myStdGroup );
624   aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
625
626   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
627   myGeoMax = new QLineEdit( myStdGroup );
628   aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
629 #endif
630
631   myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
632   aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
633
634   myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
635   aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
636
637   // advanced parameters
638   myAdvGroup = new QWidget();
639   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
640   anAdvLayout->setSpacing( 6 );
641   anAdvLayout->setMargin( 11 );
642
643   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
644   myTopology = new QComboBox( myAdvGroup );
645   anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
646   QStringList topologyTypes;
647   topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
648   myTopology->addItems( topologyTypes );
649
650   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
651   myVerbosity = new QSpinBox( myAdvGroup );
652   anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
653   myVerbosity->setMinimum( 0 );
654   myVerbosity->setMaximum( 100 );
655   myVerbosity->setSingleStep( 5 );
656
657   myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
658   anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
659   QStringList headers;
660   headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
661   myOptionTable->setHorizontalHeaderLabels( headers );
662   myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
663   //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
664   //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
665   myOptionTable->verticalHeader()->hide();
666   //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
667
668   QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"),  myAdvGroup );
669   anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
670   addBtn->setMenu( new QMenu() );
671
672   QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
673   anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
674
675   anAdvLayout->setRowStretch( 4, 5 );
676   anAdvLayout->setColumnStretch( 1, 5 );
677
678   // Size Maps parameters
679
680   mySmpGroup = new QWidget();
681   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
682
683   mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
684   anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
685   QStringList sizeMapHeaders;
686   sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
687   mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
688   mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
689 //   mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
690   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
691   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
692   mySizeMapTable->setAlternatingRowColors(true);
693   mySizeMapTable->verticalHeader()->hide();
694
695 /*
696   addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
697   anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
698
699   QFrame *line = new QFrame(mySmpGroup);
700   line->setFrameShape(QFrame::HLine);
701   line->setFrameShadow(QFrame::Sunken);
702   anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
703 */
704   addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
705   anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
706
707   addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
708   anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
709
710   addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
711   anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
712
713   QFrame *line2 = new QFrame(mySmpGroup);
714   line2->setFrameShape(QFrame::HLine);
715   line2->setFrameShadow(QFrame::Sunken);
716   anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
717
718   removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
719   anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
720
721   // Enforced vertices parameters
722
723   myEnfGroup = new QWidget();
724   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
725
726   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
727   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
728   myEnforcedTreeWidget->setSortingEnabled(true);
729   QStringList enforcedHeaders;
730   enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_X_COLUMN" )<< tr( "BLSURF_ENF_VER_Y_COLUMN" ) << tr( "BLSURF_ENF_VER_Z_COLUMN" ) ;
731   myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
732   myEnforcedTreeWidget->setAlternatingRowColors(true);
733   myEnforcedTreeWidget->setUniformRowHeights(true);
734   myEnforcedTreeWidget->setAnimated(true);
735   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
736   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
737   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
738     myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
739     myEnforcedTreeWidget->resizeColumnToContents(column);
740   }
741   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
742   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
743   anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, 8, 1);
744
745   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
746   anEnfLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
747   myXCoord = new QLineEdit(myEnfGroup);
748   myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
749   anEnfLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
750   
751   QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
752   anEnfLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
753   myYCoord = new QLineEdit(myEnfGroup);
754   myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
755   anEnfLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
756   
757   QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
758   anEnfLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
759   myZCoord = new QLineEdit(myEnfGroup);
760   myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
761   anEnfLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
762
763   addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
764   anEnfLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
765
766   QFrame *line = new QFrame(myEnfGroup);
767   line->setFrameShape(QFrame::HLine);
768   line->setFrameShadow(QFrame::Sunken);
769   anEnfLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
770
771   removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
772   anEnfLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
773
774   // ---
775   tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
776   tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
777   tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
778   tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
779
780   tab->setCurrentIndex( STD_TAB );
781
782   // ---
783   connect( myGeometricMesh,    SIGNAL( activated( int ) ),            this,         SLOT( onGeometricMeshChanged() ) );
784   connect( myPhysicalMesh,     SIGNAL( activated( int ) ),            this,         SLOT( onPhysicalMeshChanged() ) );
785   connect( addBtn->menu(),     SIGNAL( aboutToShow() ),               this,         SLOT( onAddOption() ) );
786   connect( addBtn->menu(),     SIGNAL( triggered( QAction* ) ),       this,         SLOT( onOptionChosenInPopup( QAction* ) ) );
787   connect( rmBtn,              SIGNAL( clicked()),                    this,         SLOT( onDeleteOption() ) );
788
789   connect( addSurfaceButton,   SIGNAL( clicked()),                    this,         SLOT( onAddMapOnSurface() ) );
790   connect( addEdgeButton,      SIGNAL( clicked()),                    this,         SLOT( onAddMapOnEdge() ) );
791   connect( addPointButton,     SIGNAL( clicked()),                    this,         SLOT( onAddMapOnPoint() ) );
792   connect( removeButton,       SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
793   connect( mySizeMapTable,     SIGNAL( cellChanged ( int, int  )),    this,         SLOT( onSetSizeMap(int,int ) ) );
794
795   connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
796   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
797   connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),     this,         SLOT( synchronizeCoords() ) );
798   connect( addVertexButton,    SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
799   connect( removeVertexButton, SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
800
801   return fr;
802 }
803
804 /** BLSURFPluginGUI_HypothesisCreator::update(item, column)
805 This method updates the tooltip of a modified item. The QLineEdit widgets content
806 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
807 */
808 void BLSURFPluginGUI_HypothesisCreator::update(QTreeWidgetItem* item, int column) {
809 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateVertexList");
810   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
811   if (not x.isNull()) {
812     QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
813     QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
814     QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
815     
816     QTreeWidgetItem* parent = item->parent();
817     if (parent) {
818       QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
819       QString toolTip = shapeName + QString(": ") + vertexName.toString();
820       toolTip += QString("(") + x.toString();
821       toolTip += QString(", ") + y.toString();
822       toolTip += QString(", ") + z.toString();
823       toolTip += QString(")");
824       item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
825     }
826     
827     myXCoord->setText(x.toString());
828     myYCoord->setText(y.toString());
829     myZCoord->setText(z.toString());
830   }
831 }
832
833 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
834 This method synchronizes the QLineEdit widgets content with the coordinates
835 of the enforced vertex clicked in the tree widget.
836 */
837 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
838 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::synchronizeCoords");
839   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
840   if (not items.isEmpty()) {
841     QTreeWidgetItem *item;
842     for (int i=0 ; i < items.size() ; i++) {
843       item = items[i];
844       QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
845       if (not x.isNull()) {
846         QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
847         QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
848         myXCoord->setText(x.toString());
849         myYCoord->setText(y.toString());
850         myZCoord->setText(z.toString());
851         break;
852       }
853     }
854   }
855 }
856
857 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
858 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
859 */
860 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std::string shapeName, double x, double y, double z) {
861   // Find entry item
862   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(entry.c_str()),Qt::MatchExactly,ENF_VER_ENTRY_COLUMN);
863   QTreeWidgetItem* theItem;
864   if (theItemList.empty()) {
865     theItem = new QTreeWidgetItem();
866     theItem->setData(ENF_VER_ENTRY_COLUMN, Qt::EditRole, QVariant(entry.c_str()));
867     theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(shapeName.c_str()));
868     theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(entry.c_str()));
869     myEnforcedTreeWidget->addTopLevelItem(theItem);
870   }
871   else {
872     theItem = theItemList[0];
873   }
874
875 //   MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
876   bool okToCreate = true;
877
878   const int nbVert = theItem->childCount();
879 //   MESSAGE("Number of child rows: " << nbVert);
880   if (nbVert >0) {
881     double childValueX,childValueY,childValueZ;
882     QTreeWidgetItem* child;
883     for (int row = 0;row<nbVert;row++) {
884       child = theItem->child(row);
885       childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
886       childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
887       childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
888       if ((childValueX == x) and (childValueY == y) and (childValueZ == z)) {
889         okToCreate = false;
890         break;
891       }
892     }
893   }
894   if (okToCreate) {
895     MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
896     
897     QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
898     vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
899     int vertexIndex=1;
900     QString vertexName;
901     int indexRef = 0;
902     while(indexRef != vertexIndex) {
903       indexRef = vertexIndex;
904       vertexName = QString("Vertex #%1").arg(vertexIndex);
905       for (int row = 0;row<nbVert;row++) {
906         QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
907         if (vertexName == name) {
908           vertexIndex++;
909           break;
910         }
911       }
912     }
913     vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, vertexName );
914     vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
915     vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
916     vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
917     QString toolTip = QString(shapeName.c_str())+QString(": ")+vertexName;
918     toolTip += QString(" (%1, ").arg(x);
919     toolTip += QString("%1, ").arg(y);
920     toolTip += QString("%1)").arg(z);
921     vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
922     theItem->setExpanded(true);
923     myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
924   }
925   else
926     MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " already exist: dont create again");
927 }
928
929 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
930 This method is called when a item is added into the enforced vertices tree widget
931 */
932 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
933 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
934
935   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
936     myEnforcedTreeWidget->resizeColumnToContents(column);
937   
938   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
939   
940   if ((myXCoord->text().isEmpty()) or (myYCoord->text().isEmpty()) or (myZCoord->text().isEmpty())) return;
941   
942   double x = myXCoord->text().toDouble();
943   double y = myYCoord->text().toDouble();
944   double z = myZCoord->text().toDouble();
945   
946   TopAbs_ShapeEnum shapeType;
947   string entry, shapeName;
948   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
949   LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
950   SALOME_ListIO ListSelectedObjects;
951   mySel->selectedObjects(ListSelectedObjects, NULL, false );
952   if (!ListSelectedObjects.IsEmpty()) {
953     SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
954     for (; Object_It.More(); Object_It.Next()) {
955       Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
956       entry     = myGeomToolSelected->getEntryOfObject(anObject);
957       shapeName = anObject->getName();
958       shapeType = myGeomToolSelected->entryToShapeType(entry);
959 //       MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
960       if (shapeType == TopAbs_FACE) {
961         addEnforcedVertex(entry, shapeName, x, y, z);
962       }
963     }
964   }
965   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
966     myEnforcedTreeWidget->resizeColumnToContents(column);
967   
968   if ( myPhysicalMesh->currentIndex() != SizeMap ) {
969     myPhysicalMesh->setCurrentIndex( SizeMap );
970     onPhysicalMeshChanged();
971   }
972 }
973
974 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
975 This method is called when a item is removed from the enforced vertices tree widget
976 */
977 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
978 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
979   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
980   QList<QTreeWidgetItem *> selectedVertices;
981   QSet<QTreeWidgetItem *> selectedEntries;
982   QTreeWidgetItem* item;
983
984   foreach( item, selectedItems ) {
985     QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
986     if (not value.isNull())
987       selectedVertices.append(item);
988     else
989       selectedEntries.insert(item);
990   }
991
992   foreach(item,selectedVertices) {
993     QTreeWidgetItem* parent = item->parent();
994 //     MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
995     parent->removeChild(item);
996     delete item;
997     if (parent->childCount() == 0) {
998       if (selectedEntries.contains(parent))
999         selectedEntries.remove(parent);
1000       delete parent;
1001     }
1002   }
1003
1004   foreach(item,selectedEntries) {
1005 //     MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1006     delete item;
1007   }
1008
1009   myEnforcedTreeWidget->selectionModel()->clearSelection();
1010 }
1011
1012 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1013 This method updates the GUI widgets with the hypothesis data
1014 */
1015 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1016 {
1017   MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1018   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1019
1020   BlsurfHypothesisData data;
1021   that->readParamsFromHypo( data );
1022
1023   if ( myName ) {
1024     myName->setText( data.myName );
1025     QFontMetrics metrics( myName->font() );
1026     myName->setMinimumWidth( metrics.width( data.myName )+5 );
1027   }
1028   myTopology->setCurrentIndex( data.myTopology );
1029   myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1030   myPhySize->setText( data.myPhySize );
1031 #ifdef WITH_SIZE_BOUNDARIES
1032   myPhyMin->setText( data.myPhyMin );
1033   myPhyMax->setText( data.myPhyMax );
1034   myGeoMin->setText( data.myGeoMin );
1035   myGeoMax->setText( data.myGeoMax );
1036 #endif
1037   myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1038   myAngleMeshS->setValue( data.myAngleMeshS );
1039   myAngleMeshC->setValue( data.myAngleMeshC );
1040   myGradation->setValue( data.myGradation );
1041   myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1042   myDecimesh->setChecked( data.myDecimesh );
1043   myVerbosity->setValue( data.myVerbosity );
1044
1045   if ( myOptions.operator->() ) {
1046 //     MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1047     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1048       QString option = that->myOptions[i].in();
1049       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1050       if ( name_value.count() > 1 ) {
1051         QString idStr = QString("%1").arg( i );
1052         int row = myOptionTable->rowCount();
1053         myOptionTable->setRowCount( row+1 );
1054         myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1055         myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1056         myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1057         myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1058         myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1059         myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1060                                                                    Qt::ItemIsEditable   |
1061                                                                    Qt::ItemIsEnabled );
1062       }
1063     }
1064   }
1065   myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1066
1067   // Sizemaps
1068 //   MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1069   QMapIterator<QString, QString> i(that->mySMPMap);
1070   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1071   while (i.hasNext()) {
1072     i.next();
1073     const QString entry = i.key();
1074     string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1075     const QString sizeMap = i.value();
1076     int row = mySizeMapTable->rowCount();
1077     mySizeMapTable->setRowCount( row+1 );
1078     mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
1079     mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1080     mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1081     mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1082     mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1083     mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
1084                                                                Qt::ItemIsEditable   |
1085                                                                Qt::ItemIsEnabled );
1086     }
1087
1088   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1089   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1090
1091   // Enforced vertices
1092 //   MESSAGE("retrieveParams(): data.enfVertMap.size() = " << data.enfVertMap.size());
1093   std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = data.enfVertMap.begin();
1094   for ( ; evmIt != data.enfVertMap.end() ; ++evmIt) {
1095     std::string entry = (*evmIt).first;
1096     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1097
1098     std::set<std::vector<double> > evs;
1099     std::set<std::vector<double> >::const_iterator evsIt;
1100     try  {
1101       evs = (*evmIt).second;
1102     }
1103     catch(...) {
1104 //       MESSAGE("evs = (*evmIt)[entry]: FAIL");
1105       break;
1106     }
1107
1108     evsIt = evs.begin();
1109     for ( ; evsIt != evs.end() ; ++evsIt) {
1110       double x, y, z;
1111       x = (*evsIt)[0];
1112       y = (*evsIt)[1];
1113       z = (*evsIt)[2];
1114       that->addEnforcedVertex(entry, shapeName, x, y, z);
1115     }
1116   }
1117   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1118     myEnforcedTreeWidget->resizeColumnToContents(column);
1119   
1120   // update widgets
1121   that->onPhysicalMeshChanged();
1122   that->onGeometricMeshChanged();
1123 }
1124
1125 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1126 This method updates the hypothesis data with the GUI widgets content.
1127 */
1128 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1129 {
1130   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1131
1132   BlsurfHypothesisData data;
1133   QString guiHyp = that->readParamsFromWidgets( data );
1134   that->storeParamsToHypo( data );
1135
1136   return guiHyp;
1137 }
1138
1139 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1140 Updates the hypothesis data from hypothesis values.
1141 */
1142 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1143 {
1144   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1145   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1146     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1147
1148   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1149   h_data.myName = isCreation() && data ? hypName() : "";
1150
1151   h_data.myTopology         = (int) h->GetTopology();
1152   h_data.myPhysicalMesh     = (int) h->GetPhysicalMesh();
1153   h_data.myPhySize          = QString::number( h->GetPhySize() );
1154   h_data.myGeometricMesh    = (int) h->GetGeometricMesh();
1155   h_data.myAngleMeshS       = h->GetAngleMeshS();
1156   h_data.myAngleMeshC       = h->GetAngleMeshC();
1157   h_data.myGradation        = h->GetGradation();
1158   h_data.myAllowQuadrangles = h->GetQuadAllowed();
1159   h_data.myDecimesh         = h->GetDecimesh();
1160   h_data.myVerbosity        = h->GetVerbosity();
1161
1162 #ifdef WITH_SIZE_BOUNDARIES
1163   double PhyMin = h->GetPhyMin();
1164   double PhyMax = h->GetPhyMax();
1165   double GeoMin = h->GetGeoMin();
1166   double GeoMax = h->GetGeoMax();
1167   if ( PhyMin > 0 )
1168   h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
1169   h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
1170   h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
1171   h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
1172 #endif
1173
1174   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1175   that->myOptions = h->GetOptionValues();
1176
1177   that->mySMPMap.clear();
1178
1179   // classic size maps
1180   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1181 //   MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1182   QString fullSizeMaps;
1183   QStringList fullSizeMapList;
1184   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1185   for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1186     fullSizeMaps =  mySizeMaps[i].in();
1187 //     MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1188     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1189     if ( fullSizeMapList.count() > 1 ) {
1190       string fullSizeMap = fullSizeMapList[1].toStdString();
1191       int pos = fullSizeMap.find("return")+7;
1192 //       MESSAGE("pos:" << pos);
1193       QString sizeMap;
1194       try {
1195         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1196       }
1197       catch (...) {
1198         continue;
1199       }
1200       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1201 //       MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1202       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1203 //       MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1204     }
1205   }
1206
1207   // custom size maps
1208 /*
1209   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1210   MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1211
1212   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1213     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
1214     QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1215     if ( fullCustomSizeMapList.count() > 1 ) {
1216       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1217       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1218       MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1219       MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1220     }
1221   }
1222 */
1223   // attractor
1224   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1225 //   MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1226
1227   for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1228     QString myAttractors =  allMyAttractors[i].in();
1229     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1230     if ( myAttractorList.count() > 1 ) {
1231       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1232       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1233 //       MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1234 //       MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1235     }
1236   }
1237   
1238   // Enforced vertices
1239   BLSURFPlugin::TEnforcedVertexMap_var enforcedVertexMap = h->GetAllEnforcedVertices();
1240 //   MESSAGE("enforcedVertexMap->length() = " << enforcedVertexMap->length());
1241   
1242   for ( int i = 0;i<enforcedVertexMap->length(); ++i ) {
1243     std::string entry =  enforcedVertexMap[i].entry.in();
1244 //     BLSURFPlugin::TEnforcedVertexList_var vertexList = enforcedVertexMap[i].vertexList;
1245     BLSURFPlugin::TEnforcedVertexList vertexList = enforcedVertexMap[i].vertexList;
1246     std::set<std::vector<double> > evs;
1247     for (int j=0 ; j<vertexList.length(); ++j) {
1248       double x = vertexList[j][0];
1249       double y = vertexList[j][1];
1250       double z = vertexList[j][2];
1251       std::vector<double> ev;
1252       ev.push_back(x);
1253       ev.push_back(y);
1254       ev.push_back(z);
1255       evs.insert(ev);
1256 //       MESSAGE("New enf vertex for entry " << entry << ": " << x << ", " << y << ", " << z);
1257     }
1258     h_data.enfVertMap[entry] = evs;
1259     if (evs.size() == 0) {
1260 //       MESSAGE("No enf vertex for entry " << entry << ": key is erased");
1261       h_data.enfVertMap.erase(entry);
1262     }
1263   }
1264   
1265   return true;
1266 }
1267
1268 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1269 Saves the hypothesis data to hypothesis values.
1270 */
1271 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1272 {
1273   MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1274   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1275     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1276
1277   bool ok = true;
1278   try
1279   {
1280     if( isCreation() )
1281       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1282
1283     if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
1284       h->SetTopology( (int) h_data.myTopology );
1285     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
1286       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1287     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1288       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1289     if ( h->GetGradation() !=  h_data.myGradation )
1290       h->SetGradation( h_data.myGradation );
1291     if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1292       h->SetQuadAllowed( h_data.myAllowQuadrangles );
1293     if ( h->GetDecimesh() != h_data.myDecimesh )
1294       h->SetDecimesh( h_data.myDecimesh );
1295     if ( h->GetVerbosity() != h_data.myVerbosity )
1296       h->SetVerbosity( h_data.myVerbosity );
1297
1298     if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
1299       if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
1300         h->SetPhySize( h_data.myPhySize.toDouble() );
1301     }
1302     if( (int) h_data.myGeometricMesh == UserDefined ) {
1303       if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
1304         h->SetAngleMeshS( h_data.myAngleMeshS );
1305       if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
1306         h->SetAngleMeshC( h_data.myAngleMeshC );
1307     }
1308 #ifdef WITH_SIZE_BOUNDARIES
1309     if ( !isDouble( h_data.myPhyMin ))
1310       h->SetPhyMin( -1 );
1311     else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
1312       h->SetPhyMin( h_data.myPhyMin.toDouble() );
1313     if ( !isDouble( h_data.myPhyMax ))
1314       h->SetPhyMax( -1 );
1315     else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
1316       h->SetPhyMax( h_data.myPhyMax.toDouble() );
1317     if ( !isDouble( h_data.myGeoMin ))
1318       h->SetGeoMin( -1 );
1319     else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
1320       h->SetGeoMin( h_data.myGeoMin.toDouble() );
1321     if ( !isDouble( h_data.myGeoMax ))
1322       h->SetGeoMax( -1 );
1323     else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
1324       h->SetGeoMax( h_data.myGeoMax.toDouble() );
1325 #endif
1326
1327     //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
1328     h->SetOptionValues( myOptions ); // is set in checkParams()
1329
1330     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1331     QMapIterator<QString,QString> i(that->mySMPMap);
1332     // Iterate over each size map
1333     while (i.hasNext()) {
1334       i.next();
1335       const QString entry = i.key();
1336       const QString sizeMap = i.value();
1337
1338       if (sizeMap == "__TO_DELETE__") {
1339 //         MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1340         h->UnsetEntry(entry.toLatin1().constData());
1341       }
1342       else if (sizeMap.startsWith("ATTRACTOR")) {
1343 //         MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1344         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1345       }
1346       else if (sizeMap.startsWith("def")) {
1347 //         MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1348 //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1349       }
1350       else {
1351         QString fullSizeMap;
1352         fullSizeMap = QString("");
1353         if (that->mySMPShapeTypeMap[entry]  == TopAbs_FACE)
1354           fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1355         else if (that->mySMPShapeTypeMap[entry]  == TopAbs_EDGE)
1356           fullSizeMap = QString("def f(t): return ") + sizeMap;
1357         else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1358           fullSizeMap = QString("def f(): return ") + sizeMap;
1359
1360 //         MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1361         h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1362       }
1363     }
1364     
1365     // Enforced vertices
1366     std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = h_data.enfVertMap.begin();
1367     for ( ; evmIt != h_data.enfVertMap.end() ; ++evmIt) {
1368       std::string entry = evmIt->first;
1369       std::set<std::vector<double> > evs;
1370       std::set<std::vector<double> >::const_iterator evsIt;
1371       double x, y, z;
1372       BLSURFPlugin::TEnforcedVertexList_var hypVertexList;
1373       int hypNbVertex = 0;
1374       try {
1375         hypVertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1376         hypNbVertex = hypVertexList->length();
1377       }
1378       catch(...) {
1379       }
1380       evs = evmIt->second;
1381       evsIt = evs.begin();
1382       for ( ; evsIt != evs.end() ; ++evsIt) {
1383         x = (*evsIt)[0];
1384         y = (*evsIt)[1];
1385         z = (*evsIt)[2];
1386 //         MESSAGE("SetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1387         h->SetEnforcedVertexEntry( entry.c_str(), x, y, z );
1388       }
1389       // Remove old vertices
1390       if (hypNbVertex >0) {
1391         for (int i =0 ; i<hypNbVertex ; i++) {
1392           x = hypVertexList[i][0];
1393           y = hypVertexList[i][1];
1394           z = hypVertexList[i][2];
1395           std::vector<double> vertex;
1396           vertex.push_back(x);
1397           vertex.push_back(y);
1398           vertex.push_back(z);
1399           if (evs.find(vertex) == evs.end()) {
1400 //             MESSAGE("UnsetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1401             h->UnsetEnforcedVertexEntry( entry.c_str(), x, y, z );
1402           }
1403         }
1404       }
1405     }
1406   }
1407   catch(const SALOME::SALOME_Exception& ex)
1408   {
1409     SalomeApp_Tools::QtCatchCorbaException(ex);
1410     ok = false;
1411   }
1412   return ok;
1413 }
1414
1415 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1416 Stores the widgets content to the hypothesis data.
1417 */
1418 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1419 {
1420   MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1421   h_data.myName             = myName ? myName->text() : "";
1422   h_data.myTopology         = myTopology->currentIndex();
1423   h_data.myPhysicalMesh     = myPhysicalMesh->currentIndex();
1424   h_data.myPhySize          = myPhySize->text();
1425 #ifdef WITH_SIZE_BOUNDARIES
1426   h_data.myPhyMin           = myPhyMin->text();
1427   h_data.myPhyMax           = myPhyMax->text();
1428   h_data.myGeoMin           = myGeoMin->text();
1429   h_data.myGeoMax           = myGeoMax->text();
1430 #endif
1431   h_data.myGeometricMesh    = myGeometricMesh->currentIndex();
1432   h_data.myAngleMeshS       = myAngleMeshS->value();
1433   h_data.myAngleMeshC       = myAngleMeshC->value();
1434   h_data.myGradation        = myGradation->value();
1435   h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
1436   h_data.myDecimesh         = myDecimesh->isChecked();
1437   h_data.myVerbosity        = myVerbosity->value();
1438
1439   QString guiHyp;
1440   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1441   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1442   guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
1443   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1444   guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
1445   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1446   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1447   guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
1448 #ifdef WITH_SIZE_BOUNDARIES
1449   if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
1450   if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
1451   if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
1452   if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
1453 #endif
1454
1455   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1456   int row = 0, nbRows = myOptionTable->rowCount();
1457   for ( ; row < nbRows; ++row )
1458   {
1459     int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1460     if ( id >= 0 && id < myOptions->length() )
1461     {
1462       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1463       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1464       if ( value.isNull() )
1465         value = "";
1466       that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1467       if ( value != "" )
1468         guiHyp += name + " = " + value + "; ";
1469     }
1470   }
1471
1472   // SizeMap
1473   row = 0, nbRows = mySizeMapTable->rowCount();
1474   for ( ; row < nbRows; ++row )
1475   {
1476       QString entry   = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
1477       if ( that->mySMPMap.contains(entry) )
1478         guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1479   }
1480
1481   // Enforced vertices
1482   // h_data.enfVertMap
1483
1484   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1485   int nbEnforcedVertices = 0;
1486 //   MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1487   for (int i=0 ; i<nbEnforcedShapes ; i++) {
1488     QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1489     if (shapeItem) {
1490       std::string entry = shapeItem->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1491       nbEnforcedVertices = shapeItem->childCount();
1492       if (nbEnforcedVertices >0) {
1493         double childValueX,childValueY,childValueZ;
1494         QTreeWidgetItem* child;
1495         std::set<std::vector<double> > evs;
1496         for (row = 0;row<nbEnforcedVertices;row++) {
1497           child = shapeItem->child(row);
1498           childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1499           childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1500           childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1501           std::vector<double> vertex;
1502           vertex.push_back(childValueX);
1503           vertex.push_back(childValueY);
1504           vertex.push_back(childValueZ);
1505           evs.insert(vertex);
1506         }
1507         h_data.enfVertMap[entry] = evs;
1508       }
1509     }
1510   }
1511
1512   MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
1513   return guiHyp;
1514 }
1515
1516 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
1517   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
1518   bool isPhysicalUserDefined = (myPhysicalMesh->currentIndex() == PhysicalUserDefined);
1519   bool isSizeMap = (myPhysicalMesh->currentIndex() == SizeMap);
1520   bool isCustom = (isPhysicalUserDefined || isSizeMap) ;
1521   bool geomIsCustom = (myGeometricMesh->currentIndex() == UserDefined);
1522   
1523   myGradation->setEnabled(not isPhysicalUserDefined || geomIsCustom);
1524   myPhySize->setEnabled(isCustom);
1525   myPhyMax->setEnabled(isCustom);
1526   myPhyMin->setEnabled(isCustom);
1527
1528   if ( !isSizeMap) {
1529     double gradation;
1530     switch( myPhysicalMesh->currentIndex() ) {
1531       case DefaultSize:
1532       default:
1533         gradation = 1.1;
1534         break;
1535     }
1536     myGradation->setValue( gradation );
1537   }
1538       
1539   if ( !isCustom ) {
1540     QString aPhySize = "";
1541     switch( myPhysicalMesh->currentIndex() ) {
1542       case DefaultSize:
1543       default:
1544         aPhySize = "10";
1545         break;
1546       }
1547     myPhySize->setText( aPhySize );
1548     if ( !isDouble( myPhyMin->text(), true ))
1549       myPhyMin->setText("");
1550     if ( !isDouble( myPhyMax->text(), true ))
1551       myPhyMax->setText("");
1552     if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
1553       myGeometricMesh->setCurrentIndex( UserDefined );
1554       onGeometricMeshChanged();
1555     }
1556   }
1557 }
1558
1559 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
1560   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
1561   bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
1562   bool phyIsSizemap = (myPhysicalMesh->currentIndex() == SizeMap);
1563   
1564   myAngleMeshS->setEnabled(isCustom);
1565   myAngleMeshC->setEnabled(isCustom);
1566   myGradation->setEnabled(isCustom || phyIsSizemap);
1567   myGeoMax->setEnabled(isCustom);
1568   myGeoMin->setEnabled(isCustom);
1569
1570   if ( ! isCustom ) {
1571     double aAngleMeshS;
1572     switch( myGeometricMesh->currentIndex() ) {
1573       case DefaultGeom:
1574       default:
1575         aAngleMeshS = 8;
1576         break;
1577       }
1578     myAngleMeshS->setValue( aAngleMeshS );
1579     myAngleMeshC->setValue( aAngleMeshS );
1580     if ( !isDouble( myGeoMin->text(), true ))
1581       myGeoMin->setText("");
1582     if ( !isDouble( myGeoMax->text(), true ))
1583       myGeoMax->setText("");
1584     //  hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
1585     if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
1586       myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
1587       onPhysicalMeshChanged();
1588     }
1589   }
1590 }
1591
1592 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
1593 {
1594   QMenu* menu = (QMenu*)sender();
1595   // fill popup with option names
1596   menu->clear();
1597   if ( myOptions.operator->() ) {
1598     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1599       QString name_value = myOptions[i].in();
1600       QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1601       menu->addAction( name );
1602     }
1603   }
1604 }
1605
1606 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1607 {
1608   myOptionTable->setFocus();
1609   QMenu* menu = (QMenu*)( a->parent() );
1610
1611   int idx = menu->actions().indexOf( a );
1612   QString idStr = QString("%1").arg( idx );
1613   QString option = myOptions[idx].in();
1614   QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1615
1616   // look for a row with optionName
1617   int row = 0, nbRows = myOptionTable->rowCount();
1618   for ( ; row < nbRows; ++row )
1619     if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1620       break;
1621   // add a row if not found
1622   if ( row == nbRows ) {
1623     myOptionTable->setRowCount( row+1 );
1624     myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1625     myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1626     myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1627     myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1628     myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1629     myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1630                                                                Qt::ItemIsEditable   |
1631                                                                Qt::ItemIsEnabled );
1632     myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1633   }
1634   myOptionTable->clearSelection();
1635   myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1636   //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1637   myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1638   //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1639 }
1640
1641 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1642 {
1643   // clear option values and remember selected row
1644   QList<int> selectedRows;
1645   QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1646   QTableWidgetItem* item;
1647   foreach( item, selected ) {
1648     int row = item->row();
1649     if ( !selectedRows.contains( row ) ) {
1650       selectedRows.append( row );
1651       int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1652       if ( id >= 0 && id < myOptions->length() )
1653         myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1654     }
1655   }
1656   qSort( selectedRows );
1657   QListIterator<int> it( selectedRows );
1658   it.toBack();
1659   while ( it.hasPrevious() )
1660     myOptionTable->removeRow( it.previous() );
1661 }
1662
1663 // **********************
1664 // *** BEGIN SIZE MAP ***
1665 // **********************
1666
1667
1668 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1669 {
1670   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1671   QList<int> selectedRows;
1672   QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1673   QTableWidgetItem* item;
1674   int row;
1675   foreach( item, selected ) {
1676     row = item->row();
1677     if ( !selectedRows.contains( row ) )
1678       selectedRows.append( row );
1679   }
1680
1681   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1682
1683   qSort( selectedRows );
1684   QListIterator<int> it( selectedRows );
1685   it.toBack();
1686   while ( it.hasPrevious() ) {
1687       row = it.previous();
1688       QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1689       if (that->mySMPMap.contains(entry))
1690         that->mySMPMap[entry] = "__TO_DELETE__";
1691       if (that->mySMPShapeTypeMap.contains(entry))
1692         that->mySMPShapeTypeMap.remove(entry);
1693       mySizeMapTable->removeRow(row );
1694   }
1695   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1696   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1697 }
1698
1699 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1700 {
1701   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1702   if (col == SMP_SIZEMAP_COLUMN) {
1703     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1704     QString entry   = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1705     QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1706 //     MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1707     if (not that->mySMPShapeTypeMap.contains(entry))
1708       return;
1709     if (that->mySMPMap.contains(entry))
1710       if (that->mySMPMap[entry] == sizeMap)
1711         return;
1712     QColor* bgColor = new QColor("white");
1713     QColor* fgColor = new QColor("black");
1714     if (! sizeMap.isEmpty()) {
1715       that->mySMPMap[entry] = sizeMap;
1716       if (! sizeMapValidationFromRow(row)) {
1717         bgColor->setRgb(255,0,0);
1718         fgColor->setRgb(255,255,255);
1719       }
1720     }
1721     else {
1722 //       MESSAGE("Size map empty: reverse to precedent value" );
1723       that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1724     }
1725     that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1726     that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1727     that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1728     that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1729     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1730   }
1731 }
1732
1733 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1734 {
1735  insertElementType(TopAbs_FACE);
1736 }
1737
1738 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1739 {
1740  insertElementType(TopAbs_EDGE);
1741 }
1742
1743 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1744 {
1745  insertElementType(TopAbs_VERTEX);
1746 }
1747
1748 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1749 {
1750 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1751
1752   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1753     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1754
1755   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1756
1757   TopAbs_ShapeEnum shapeType;
1758   string entry, shapeName;
1759   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1760
1761   LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1762
1763   SALOME_ListIO ListSelectedObjects;
1764   mySel->selectedObjects(ListSelectedObjects, NULL, false );
1765   if (!ListSelectedObjects.IsEmpty())
1766   {
1767     SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1768     for (; Object_It.More(); Object_It.Next())
1769     {
1770       Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1771       entry     = myGeomToolSelected->getEntryOfObject(anObject);
1772       shapeName = anObject->getName();
1773       shapeType         = myGeomToolSelected->entryToShapeType(entry);
1774 //       MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
1775       if (shapeType == typeShapeAsked)
1776       {
1777         mySizeMapTable->setFocus();
1778         QString shapeEntry;
1779         shapeEntry = QString::fromStdString(entry);
1780         double phySize = h->GetPhySize();
1781         std::ostringstream oss;
1782         oss << phySize;
1783         QString sizeMap;
1784         sizeMap  = QString::fromStdString(oss.str());
1785         if (that->mySMPMap.contains(shapeEntry)) {
1786           if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1787 //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1788             break;
1789           }
1790         }
1791         that->mySMPMap[shapeEntry] = sizeMap;
1792         that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1793         int row = mySizeMapTable->rowCount() ;
1794         mySizeMapTable->setRowCount( row+1 );
1795         mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1796         mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1797         mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1798         mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1799         mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1800         mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
1801         mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1802         mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1803         mySizeMapTable->clearSelection();
1804         mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1805
1806         if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1807           myPhysicalMesh->setCurrentIndex( SizeMap );
1808           onPhysicalMeshChanged();
1809         }
1810       }
1811     }
1812   }
1813 }
1814
1815 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1816 {
1817 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
1818   int row = 0, nbRows = mySizeMapTable->rowCount();
1819   for ( ; row < nbRows; ++row )
1820     if (! sizeMapValidationFromRow(row))
1821       return false;
1822   return true;
1823 }
1824
1825 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1826 {
1827 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
1828   QString myEntry   = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1829   bool res = sizeMapValidationFromEntry(myEntry,displayError);
1830   mySizeMapTable->setFocus();
1831   return res;
1832 }
1833
1834 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1835 {
1836 //   MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
1837
1838   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1839
1840   if (not that->mySMPMap.contains(myEntry)) {
1841 //     MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
1842     return false;
1843   }
1844   if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1845 //     MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
1846     return false;
1847   }
1848
1849   string expr;
1850
1851   if (that->mySMPMap[myEntry].startsWith("def")) {
1852 //     MESSAGE("custom function" );
1853     expr = that->mySMPMap[myEntry].toStdString();
1854   }
1855   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1856 //     MESSAGE("Attractor" );
1857     if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)\\)$")) != 1)) {
1858 //     if ((that->mySMPMap[myEntry].count('(') != 1) or
1859 //         (that->mySMPMap[myEntry].count(')') != 1) or
1860 //         (that->mySMPMap[myEntry].count(';') != 4) or
1861 //         (that->mySMPMap[myEntry].size() == 15)){
1862       if (displayError)
1863         SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False)" );
1864       return false;
1865     }
1866     return true;
1867   }
1868   else {
1869     // case size map is empty
1870     if (that->mySMPMap[myEntry].isEmpty()) {
1871       if (displayError)
1872         SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1873       return false;
1874     }
1875     else {
1876       if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1877         expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1878       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1879         expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1880       else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1881         expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1882     }
1883   }
1884   //assert(Py_IsInitialized());
1885   if (! Py_IsInitialized())
1886     throw ("Erreur: Python interpreter is not initialized");
1887   PyGILState_STATE gstate;
1888   gstate = PyGILState_Ensure();
1889
1890   PyObject * obj = NULL;
1891   PyObject* new_stderr = NULL;
1892   string  err_description="";
1893   obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1894   if (obj == NULL){
1895     fflush(stderr);
1896     err_description="";
1897     new_stderr=newPyStdOut(err_description);
1898     PySys_SetObject("stderr", new_stderr);
1899     PyErr_Print();
1900     PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1901     Py_DECREF(new_stderr);
1902     if (displayError)
1903       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1904     PyGILState_Release(gstate);
1905     return false;
1906   }
1907   Py_DECREF(obj);
1908
1909   PyObject * func = NULL;
1910   func = PyObject_GetAttrString(main_mod, "f");
1911   if ( func == NULL){
1912     fflush(stderr);
1913     err_description="";
1914     new_stderr=newPyStdOut(err_description);
1915     PySys_SetObject("stderr", new_stderr);
1916     PyErr_Print();
1917     PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1918     Py_DECREF(new_stderr);
1919     if (displayError)
1920       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1921     PyGILState_Release(gstate);
1922     return false;
1923   }
1924
1925   PyGILState_Release(gstate);
1926
1927 //   MESSAGE("SizeMap expression "<<expr<<" is valid");
1928
1929   return true;
1930 }
1931
1932 /*
1933 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1934   int myRow = index->row();
1935   int myColumn = index->column();
1936
1937   if (myColumn == 2){
1938      if (!myEditor) {
1939          myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1940          connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1941      }
1942      myEditor->exec();
1943 //      myEditor->show();
1944 //      myEditor->raise();
1945 //      myEditor->activateWindow();
1946
1947
1948 //     BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1949 //     myEditor->exec();
1950      QString myFunction = myEditor->GetFunctionText();
1951      // FIN RECUPERATION FONCTION
1952
1953      if (! myFunction.isEmpty()) {
1954
1955      // MAJ DE LA MAP
1956
1957      BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1958        BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1959
1960 //     h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1961 //                        item->text().toLatin1().constData());
1962      h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1963                         myFunction.toLatin1().constData());
1964      // FIN MAJ DE LA MAP
1965      }
1966   }
1967 }*/
1968
1969 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1970 {
1971   return tr( "BLSURF_TITLE" );
1972 }
1973
1974 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1975 {
1976   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1977 }
1978
1979 QString BLSURFPluginGUI_HypothesisCreator::type() const
1980 {
1981   return tr( "BLSURF_HYPOTHESIS" );
1982 }
1983
1984 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1985 {
1986   return "blsurf_hypo_page.html";
1987 }
1988
1989 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1990 {
1991
1992   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1993   if( anApp )
1994     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1995   else
1996     return 0;
1997 }
1998
1999