Salome HOME
Update copyrights
[plugins/netgenplugin.git] / src / GUI / NETGENPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  NETGENPlugin GUI: GUI for plugged-in mesher NETGENPlugin
24 //  File   : NETGENPluginGUI_HypothesisCreator.cxx
25 //  Author : Michael Zorin
26 //  Module : NETGENPlugin
27 //
28 #include "NETGENPluginGUI_HypothesisCreator.h"
29
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_SpinBox.h>
33 #include <GeomSelectionTools.h>
34
35 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
36
37 #include <LightApp_SelectionMgr.h>
38 #include <SALOME_ListIO.hxx>
39 #include <SUIT_FileDlg.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Session.h>
42 #include <SalomeApp_IntSpinBox.h>
43 #include <SalomeApp_Tools.h>
44
45 #include <QComboBox>
46 #include <QLabel>
47 #include <QGroupBox>
48 #include <QFrame>
49 #include <QLayout>
50 #include <QLineEdit>
51 #include <QCheckBox>
52 #include <QPixmap>
53 #include <QTableWidget>
54 #include <QHeaderView>
55 #include <QPushButton>
56
57 enum Fineness {
58   VeryCoarse,
59   Coarse,
60   Moderate,
61   Fine,
62   VeryFine,
63   UserDefined
64 };
65
66 enum {
67   STD_TAB = 0,
68   STL_TAB,
69   LSZ_TAB,
70   ADV_TAB
71 };
72
73 enum {
74   LSZ_ENTRY_COLUMN = 0,
75   LSZ_NAME_COLUMN,
76   LSZ_LOCALSIZE_COLUMN,
77   LSZ_NB_COLUMNS
78 };
79
80 enum {
81   LSZ_BTNS = 0,
82   LSZ_VERTEX_BTN,
83   LSZ_EDGE_BTN,
84   LSZ_FACE_BTN,
85   LSZ_SOLID_BTN,
86   LSZ_SEPARATOR2,
87   LSZ_REMOVE_BTN,
88   LSZ_FILE_LE = 9
89 };
90
91 template<class SPINBOX, typename VALUETYPE>
92 void setTextOrVar( SPINBOX* spin, VALUETYPE value, const QString& variable )
93 {
94   if ( spin )
95   {
96     if ( variable.isEmpty() )
97       spin->setValue( value );
98     else
99       spin->setText( variable );
100   }
101 }
102
103 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
104   : SMESHGUI_GenericHypothesisCreator( theHypType )
105 {
106   myGeomSelectionTools = NULL;
107   myLocalSizeMap.clear();
108   myIs2D   = ( theHypType.startsWith("NETGEN_Parameters_2D") ||
109                theHypType == "NETGEN_RemesherParameters_2D");
110   myIsONLY = ( theHypType == "NETGEN_Parameters_2D_ONLY" ||
111                theHypType == "NETGEN_Parameters_3D" ||
112                theHypType == "NETGEN_RemesherParameters_2D");
113 }
114
115 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
116 {
117 }
118
119 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
120 {
121   NetgenHypothesisData data_old, data_new;
122   readParamsFromHypo( data_old );
123   readParamsFromWidgets( data_new );
124   bool res = storeParamsToHypo( data_new );
125
126   if ( !res ) //  -- issue 0021364: Dump of netgen parameters has duplicate lines
127     storeParamsToHypo( data_old );
128
129   return res;
130 }
131
132 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
133 {
134   const bool isRemesher = ( hypType() == "NETGEN_RemesherParameters_2D" );
135
136   QFrame* fr = new QFrame( 0 );
137   fr->setObjectName( "myframe" );
138   QVBoxLayout* lay = new QVBoxLayout( fr );
139   lay->setMargin( 5 );
140   lay->setSpacing( 0 );
141
142   QTabWidget* tab = new QTabWidget( fr );
143   tab->setTabShape( QTabWidget::Rounded );
144   tab->setTabPosition( QTabWidget::North );
145   lay->addWidget( tab );
146
147   // ==============
148   // Arguments TAB
149   // ==============
150
151   QWidget* GroupC1 = new QWidget();
152   tab->insertTab( STD_TAB, GroupC1, tr( "SMESH_ARGUMENTS" ) );
153
154   QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
155   aGroupLayout->setMargin( 6 );
156   aGroupLayout->setSpacing( 11 );
157
158   int row0 = 0;
159   myName = 0;
160   if ( isCreation() )
161   {
162     aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row0, 0 );
163     myName = new QLineEdit( GroupC1 );
164     myName->setMinimumWidth(160);
165     aGroupLayout->addWidget( myName, row0, 1 );
166     row0++;
167   }
168
169   // Mesh size group
170   // ----------------
171   {
172     QGroupBox* aSizeBox = new QGroupBox( tr("NETGEN_MESH_SIZE"), GroupC1 );
173     aGroupLayout->addWidget( aSizeBox, row0, 0, 1, 2 );
174     row0++;
175
176     QGridLayout* aSizeLayout = new QGridLayout( aSizeBox );
177     aSizeLayout->setSpacing( 6 );
178     aSizeLayout->setMargin( 11 );
179     int row = 0;
180
181     aSizeLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), aSizeBox ), row, 0 );
182     myMaxSize = new SMESHGUI_SpinBox( aSizeBox );
183     myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" );
184     aSizeLayout->addWidget( myMaxSize, row, 1 );
185     row++;
186
187     aSizeLayout->addWidget( new QLabel( tr( "NETGEN_MIN_SIZE" ), aSizeBox ), row, 0 );
188     myMinSize = new SMESHGUI_SpinBox( aSizeBox );
189     myMinSize->RangeStepAndValidator( 0.0, 1e+06, 10., "length_precision" );
190     aSizeLayout->addWidget( myMinSize, row, 1 );
191     row++;
192
193     aSizeLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), aSizeBox ), row, 0 );
194     myFineness = new QComboBox( aSizeBox );
195     QStringList types;
196     types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" )   << tr( "NETGEN_MODERATE" ) <<
197       tr( "NETGEN_FINE" )       << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
198     myFineness->addItems( types );
199     aSizeLayout->addWidget( myFineness, row, 1 );
200     connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
201     row++;
202
203     aSizeLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), aSizeBox ), row, 0 );
204     myGrowthRate = new SMESHGUI_SpinBox( aSizeBox );
205     myGrowthRate->RangeStepAndValidator( .0001, 10., .1, "parametric_precision" );
206     aSizeLayout->addWidget( myGrowthRate, row, 1 );
207     row++;
208
209     myNbSegPerEdge = 0;
210     myNbSegPerRadius = 0;
211     if ( !myIsONLY )
212     {
213       const double VALUE_MAX = 1.0e+6;
214
215       aSizeLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), aSizeBox ), row, 0 );
216       myNbSegPerEdge = new SMESHGUI_SpinBox( aSizeBox );
217       myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
218       aSizeLayout->addWidget( myNbSegPerEdge, row, 1 );
219       row++;
220
221       aSizeLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), aSizeBox ), row, 0 );
222       myNbSegPerRadius = new SMESHGUI_SpinBox( aSizeBox );
223       myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
224       aSizeLayout->addWidget( myNbSegPerRadius, row, 1 );
225       row++;
226     }
227
228     myChordalErrorEnabled = 0;
229     myChordalError = 0;
230     if (( myIs2D && !isRemesher ) || !myIsONLY )
231     {
232       myChordalErrorEnabled = new QCheckBox( tr( "NETGEN_CHORDAL_ERROR" ), aSizeBox );
233       aSizeLayout->addWidget( myChordalErrorEnabled, row, 0 );
234       myChordalError = new SMESHGUI_SpinBox( aSizeBox );
235       myChordalError->RangeStepAndValidator( COORD_MIN, COORD_MAX, .1, "length_precision" );
236       aSizeLayout->addWidget( myChordalError, row, 1 );
237       connect( myChordalErrorEnabled, SIGNAL( stateChanged(int)), SLOT( onChordalErrorEnabled()));
238       row++;
239     }
240
241     mySurfaceCurvature = 0;
242     if (( myIs2D && !isRemesher ) || !myIsONLY )
243     {
244       mySurfaceCurvature = new QCheckBox( tr( "NETGEN_SURFACE_CURVATURE" ), aSizeBox );
245       aSizeLayout->addWidget( mySurfaceCurvature, row, 0, 1, 2 );
246       connect( mySurfaceCurvature, SIGNAL( stateChanged( int ) ), this, SLOT( onSurfaceCurvatureChanged() ) );
247       row++;
248     }
249   } // end Mesh Size box
250
251   myAllowQuadrangles = 0;
252   if ( myIs2D || !myIsONLY ) // disable only for NETGEN 3D
253   {
254     myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
255     aGroupLayout->addWidget( myAllowQuadrangles, row0, 0, 1, 2 );
256     row0++;
257   }
258
259   mySecondOrder = 0;
260   if ( !myIsONLY )
261   {
262     mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
263     aGroupLayout->addWidget( mySecondOrder, row0, 0, 1, 2 );
264     row0++;
265   }
266
267   myOptimize = 0;
268   // if ( !isRemesher ) ???
269   {
270     myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
271     aGroupLayout->addWidget( myOptimize, row0, 0, 1, 2 );
272     row0++;
273   }
274
275   myKeepExistingEdges = myMakeGroupsOfSurfaces = 0;
276   if ( isRemesher )
277   {
278     myKeepExistingEdges = new QCheckBox( tr( "NETGEN_KEEP_EXISTING_EDGES" ), GroupC1 );
279     aGroupLayout->addWidget( myKeepExistingEdges, row0, 0, 1, 2 );
280     row0++;
281
282     myMakeGroupsOfSurfaces = new QCheckBox( tr( "NETGEN_MAKE_SURFACE_GROUPS" ), GroupC1 );
283     aGroupLayout->addWidget( myMakeGroupsOfSurfaces, row0, 0, 1, 2 );
284     row0++;
285   }
286
287   aGroupLayout->setRowStretch( row0, 1 );
288
289   // ========
290   // STL TAB
291   // ========
292
293   QWidget* stlGroup = new QWidget();
294   QVBoxLayout* stlLay = new QVBoxLayout( stlGroup );
295   stlLay->setMargin( 5 );
296   stlLay->setSpacing( 10 );
297
298   // Charts group
299   {
300     QGroupBox* chaGroup = new QGroupBox( tr("NETGEN_STL_CHARTS"), stlGroup );
301     stlLay->addWidget( chaGroup );
302
303     QGridLayout* chaLayout = new QGridLayout( chaGroup );
304     chaLayout->setMargin( 6 );
305     chaLayout->setSpacing( 6 );
306
307     int row = 0;
308     chaLayout->addWidget( new QLabel( tr( "NETGEN_RIDGE_ANGLE" ), chaGroup ), row, 0 );
309     myRidgeAngle = new SMESHGUI_SpinBox( chaGroup );
310     myRidgeAngle->RangeStepAndValidator( 0, 90, 10, "angle_precision" );
311     chaLayout->addWidget( myRidgeAngle, row, 1 );
312     row++;
313
314     chaLayout->addWidget( new QLabel( tr( "NETGEN_EDGE_CORNER_ANGLE" ), chaGroup ), row, 0 );
315     myEdgeCornerAngle = new SMESHGUI_SpinBox( chaGroup );
316     myEdgeCornerAngle->RangeStepAndValidator( 0., 180., 20., "angle_precision" );
317     chaLayout->addWidget( myEdgeCornerAngle, row, 1 );
318     row++;
319
320     chaLayout->addWidget( new QLabel( tr( "NETGEN_CHART_ANGLE" ), chaGroup ), row, 0 );
321     myChartAngle = new SMESHGUI_SpinBox( chaGroup );
322     myChartAngle->RangeStepAndValidator( 0., 180., 20., "angle_precision" );
323     chaLayout->addWidget( myChartAngle, row, 1 );
324     row++;
325
326     chaLayout->addWidget( new QLabel( tr( "NETGEN_OUTER_CHART_ANGLE" ), chaGroup ), row, 0 );
327     myOuterChartAngle = new SMESHGUI_SpinBox( chaGroup );
328     myOuterChartAngle->RangeStepAndValidator( 0., 180., 20., "angle_precision" );
329     chaLayout->addWidget( myOuterChartAngle, row, 1 );
330     row++;
331   }
332   // STL size group
333   {
334     QGroupBox* sizeGroup = new QGroupBox( tr("NETGEN_STL_SIZE"), stlGroup );
335     stlLay->addWidget( sizeGroup );
336
337     QGridLayout* sizeLayout = new QGridLayout( sizeGroup );
338     sizeLayout->setMargin( 6 );
339     sizeLayout->setSpacing( 6 );
340
341     int row = 0;
342     myRestHChartDistEnable = new QCheckBox( tr("NETGEN_RESTH_CHART_DIST"), sizeGroup );
343     sizeLayout->addWidget( myRestHChartDistEnable, row, 0 );
344     myRestHChartDistFactor = new SMESHGUI_SpinBox( sizeGroup );
345     myRestHChartDistFactor->RangeStepAndValidator( 0.2, 5., 0.1, "length_precision" );
346     sizeLayout->addWidget( myRestHChartDistFactor, row, 1 );
347     row++;
348
349     myRestHLineLengthEnable = new QCheckBox( tr("NETGEN_RESTH_LINE_LENGTH"), sizeGroup );
350     sizeLayout->addWidget( myRestHLineLengthEnable, row, 0 );
351     myRestHLineLengthFactor = new SMESHGUI_SpinBox( sizeGroup );
352     myRestHLineLengthFactor->RangeStepAndValidator( 0.2, 5., 0.1, "length_precision" );
353     sizeLayout->addWidget( myRestHLineLengthFactor, row, 1 );
354     row++;
355
356     myRestHCloseEdgeEnable = new QCheckBox( tr("NETGEN_RESTH_CLOSE_EDGE"), sizeGroup );
357     sizeLayout->addWidget( myRestHCloseEdgeEnable, row, 0 );
358     myRestHCloseEdgeFactor = new SMESHGUI_SpinBox( sizeGroup );
359     myRestHCloseEdgeFactor->RangeStepAndValidator( 0.2, 8., 0.1, "length_precision" );
360     sizeLayout->addWidget( myRestHCloseEdgeFactor, row, 1 );
361     row++;
362
363     myRestHSurfCurvEnable = new QCheckBox( tr("NETGEN_RESTH_SURF_CURV"), sizeGroup );
364     sizeLayout->addWidget( myRestHSurfCurvEnable, row, 0 );
365     myRestHSurfCurvFactor = new SMESHGUI_SpinBox( sizeGroup );
366     myRestHSurfCurvFactor->RangeStepAndValidator( 0.2, 5., 0.1, "length_precision" );
367     sizeLayout->addWidget( myRestHSurfCurvFactor, row, 1 );
368     row++;
369
370     myRestHEdgeAngleEnable = new QCheckBox( tr("NETGEN_RESTH_EDGE_ANGLE"), sizeGroup );
371     sizeLayout->addWidget( myRestHEdgeAngleEnable, row, 0 );
372     myRestHEdgeAngleFactor = new SMESHGUI_SpinBox( sizeGroup );
373     myRestHEdgeAngleFactor->RangeStepAndValidator( 0.2, 5., 0.1, "length_precision" );
374     sizeLayout->addWidget( myRestHEdgeAngleFactor, row, 1 );
375     row++;
376
377     myRestHSurfMeshCurvEnable = new QCheckBox( tr("NETGEN_RESTH_SURF_MESH_CURV"), sizeGroup );
378     sizeLayout->addWidget( myRestHSurfMeshCurvEnable, row, 0 );
379     myRestHSurfMeshCurvFactor = new SMESHGUI_SpinBox( sizeGroup );
380     myRestHSurfMeshCurvFactor->RangeStepAndValidator( 0.2, 5., 0.1, "length_precision" );
381     sizeLayout->addWidget( myRestHSurfMeshCurvFactor, row, 1 );
382     row++;
383   }
384   if ( isRemesher )
385   {
386     tab->insertTab( STL_TAB, stlGroup, tr( "NETGEN_STL" ));
387     connect( myRestHChartDistEnable   , SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
388     connect( myRestHLineLengthEnable  , SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
389     connect( myRestHCloseEdgeEnable   , SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
390     connect( myRestHSurfCurvEnable    , SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
391     connect( myRestHEdgeAngleEnable   , SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
392     connect( myRestHSurfMeshCurvEnable, SIGNAL( toggled(bool) ), this, SLOT( onSTLEnable() ));
393   }
394   else
395   {
396     delete stlGroup;
397     myRidgeAngle = 0;
398   }
399
400   // ===============
401   // Local Size TAB
402   // ===============
403
404   myLocalSizeTable = 0;
405   //if ( !myIsONLY )
406   {
407     QWidget* localSizeGroup = new QWidget();
408     QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup);
409
410     myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup);
411     localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 2);
412     QStringList localSizeHeaders;
413     localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" );
414     myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders);
415     myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN);
416 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
417     myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
418 #else
419     myLocalSizeTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
420 #endif
421     myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
422     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
423     myLocalSizeTable->setAlternatingRowColors(true);
424     myLocalSizeTable->verticalHeader()->hide();
425
426     QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup);
427     localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 2, 1, 1);
428     QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup);
429     localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 2, 1, 1);
430     QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup);
431     localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 2, 1, 1);
432     QPushButton* addSolidButton = new QPushButton(tr("NETGEN_LSZ_SOLID"), localSizeGroup);
433     localSizeLayout->addWidget(addSolidButton, LSZ_SOLID_BTN, 2, 1, 1);
434
435     QFrame *line2 = new QFrame(localSizeGroup);
436     line2->setFrameShape(QFrame::HLine);
437     line2->setFrameShadow(QFrame::Sunken);
438     localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 2, 1, 1);
439
440     QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup);
441     localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 2, 1, 1);
442
443     QPushButton* fileBtn = new QPushButton(tr("NETGEN_LSZ_FILE"), localSizeGroup);
444     myMeshSizeFile = new QLineEdit(localSizeGroup);
445     myMeshSizeFile->setReadOnly( true );
446     localSizeLayout->addWidget( fileBtn, LSZ_FILE_LE, 0, 1, 1);
447     localSizeLayout->addWidget( myMeshSizeFile, LSZ_FILE_LE, 1, 1, 2);
448
449     connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex()));
450     connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge()));
451     connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace()));
452     connect( addSolidButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnSolid()));
453     connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape()));
454     connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int)));
455     connect( fileBtn, SIGNAL(clicked()), this, SLOT(onSetSizeFile()));
456
457     tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE"));
458   }
459
460   // =============
461   // Advanced TAB
462   // =============
463
464   QWidget* advGroup = new QWidget();
465   tab->insertTab( ADV_TAB, advGroup, tr( "SMESH_ADVANCED" ));
466   QVBoxLayout* advLay = new QVBoxLayout( advGroup );
467   advLay->setSpacing( 6 );
468   advLay->setMargin( 5 );
469
470   // Optimizer group
471   // ----------------
472   {
473     QGroupBox* optBox = new QGroupBox( tr("NETGEN_OPTIMIZER"), advGroup );
474     advLay->addWidget( optBox );
475
476     QGridLayout* optLayout = new QGridLayout( optBox );
477     optLayout->setMargin( 6 );
478     optLayout->setSpacing( 6 );
479
480     int row = 0;
481     myElemSizeWeight = 0;
482     myNbSurfOptSteps = 0;
483     if ( myIs2D || !myIsONLY ) // 2D options
484     {
485       optLayout->addWidget( new QLabel( tr( "NETGEN_ELEM_SIZE_WEIGHT" ), optBox ), row, 0 );
486       myElemSizeWeight = new SMESHGUI_SpinBox( optBox );
487       myElemSizeWeight->RangeStepAndValidator( 0., 1., 0.1, "parametric_precision" );
488       optLayout->addWidget( myElemSizeWeight, row, 1 );
489       row++;
490
491       optLayout->addWidget( new QLabel( tr( "NETGEN_NB_SURF_OPT_STEPS" ), optBox ), row, 0 );
492       myNbSurfOptSteps = new SalomeApp_IntSpinBox( optBox );
493       myNbSurfOptSteps->setMinimum( 0 );
494       myNbSurfOptSteps->setMaximum( 99 );
495       optLayout->addWidget( myNbSurfOptSteps, row, 1 );
496       row++;
497     }
498
499     myNbVolOptSteps = 0;
500     if ( !myIs2D )
501     {
502       optLayout->addWidget( new QLabel( tr( "NETGEN_NB_VOL_OPT_STEPS" ), optBox ), row, 0 );
503       myNbVolOptSteps = new SalomeApp_IntSpinBox( optBox );
504       myNbVolOptSteps->setMinimum( 0 );
505       myNbVolOptSteps->setMaximum( 99 );
506       optLayout->addWidget( myNbVolOptSteps, row, 1 );
507     }
508   }
509   // Insider group
510   {
511     QGroupBox* insGroup = new QGroupBox( tr("NETGEN_INSIDER"), advGroup );
512     advLay->addWidget( insGroup );
513
514     QGridLayout* insLayout = new QGridLayout( insGroup );
515     insLayout->setMargin( 6 );
516     insLayout->setSpacing( 6 );
517
518     int row = 0;
519     myWorstElemMeasure = 0;
520     myUseDelauney = 0;
521     if ( !myIs2D )
522     {
523       insLayout->addWidget( new QLabel( tr( "NETGEN_WORST_ELEM_MEASURE" ), insGroup ), row, 0 );
524       myWorstElemMeasure = new SalomeApp_IntSpinBox( insGroup );
525       myWorstElemMeasure->setMinimum( 1 );
526       myWorstElemMeasure->setMaximum( 10 );
527       insLayout->addWidget( myWorstElemMeasure, row, 1, 1, 2 );
528       row++;
529
530       myUseDelauney = new QCheckBox( tr( "NETGEN_USE_DELAUNEY" ), insGroup );
531       insLayout->addWidget( myUseDelauney, row, 0, 1, 2 );
532       row++;
533     }
534
535     myCheckOverlapping = 0;
536     if ( myIs2D || !myIsONLY ) // 2D options
537     {
538       myCheckOverlapping = new QCheckBox( tr( "NETGEN_CHECK_OVERLAPPING" ), insGroup );
539       insLayout->addWidget( myCheckOverlapping, row, 0, 1, 2 );
540       row++;
541     }
542
543     myCheckChartBoundary = 0;
544     if ( isRemesher )
545     {
546       myCheckChartBoundary = new QCheckBox( tr( "NETGEN_CHECK_CHART_BOUNDARY" ), insGroup );
547       insLayout->addWidget( myCheckChartBoundary, row, 0, 1, 2 );
548       row++;
549     }
550
551     myFuseEdges = 0;
552     if ( !myIsONLY && !isRemesher )
553     {
554       myFuseEdges = new QCheckBox( tr( "NETGEN_FUSE_EDGES" ), insGroup );
555       insLayout->addWidget( myFuseEdges, row, 0, 1, 2 );
556       row++;
557     }
558     insLayout->setRowStretch( row, 1 );
559   }
560
561   return fr;
562 }
563
564 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
565 {
566   NetgenHypothesisData data;
567   readParamsFromHypo( data );
568
569   if( myName )
570     myName->setText( data.myName );
571
572   setTextOrVar( myMaxSize, data.myMaxSize, data.myMaxSizeVar );
573   setTextOrVar( myMinSize, data.myMinSize, data.myMinSizeVar );
574   if ( mySecondOrder )
575     mySecondOrder->setChecked( data.mySecondOrder );
576   if ( myOptimize )
577     myOptimize->setChecked( data.myOptimize );
578   myFineness->setCurrentIndex( data.myFineness );
579   setTextOrVar( myGrowthRate, data.myGrowthRate, data.myGrowthRateVar );
580   setTextOrVar( myNbSegPerEdge, data.myNbSegPerEdge, data.myNbSegPerEdgeVar );
581   setTextOrVar( myNbSegPerRadius, data.myNbSegPerRadius, data.myNbSegPerRadiusVar );
582
583   if ( myChordalError )
584   {
585     myChordalErrorEnabled->setChecked( data.myChordalErrorEnabled && data.myChordalError > 0 );
586     setTextOrVar( myChordalError, data.myChordalError, data.myChordalErrorVar );
587     myChordalError->setEnabled( myChordalErrorEnabled->isChecked() );
588   }
589   if (myAllowQuadrangles)
590     myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
591   if (mySurfaceCurvature)
592     mySurfaceCurvature->setChecked( data.mySurfaceCurvature );
593
594   if ( myKeepExistingEdges )
595   {
596     myKeepExistingEdges->setChecked( data.myKeepExistingEdges );
597     myMakeGroupsOfSurfaces->setChecked( data.myMakeGroupsOfSurfaces );
598   }
599
600   setTextOrVar( myElemSizeWeight, data.myElemSizeWeight, data.myElemSizeWeightVar );
601   setTextOrVar( myNbSurfOptSteps, data.myNbSurfOptSteps, data.myNbSurfOptStepsVar );
602   setTextOrVar( myNbVolOptSteps,  data.myNbVolOptSteps,  data.myNbVolOptStepsVar );
603
604   if (myFuseEdges)
605     myFuseEdges->setChecked( data.myFuseEdges );
606   setTextOrVar( myWorstElemMeasure, data.myWorstElemMeasure, data.myWorstElemMeasureVar );
607   if ( myUseDelauney )
608     myUseDelauney->setChecked( data.myUseDelauney );
609   if ( myCheckOverlapping )
610     myCheckOverlapping->setChecked( data.myCheckOverlapping );
611   if ( myCheckChartBoundary )
612     myCheckChartBoundary->setChecked( data.myCheckChartBoundary );
613
614   if ( myRidgeAngle )
615   {
616     setTextOrVar( myRidgeAngle, data.myRidgeAngle, data.myRidgeAngleVar );
617     setTextOrVar( myEdgeCornerAngle, data.myEdgeCornerAngle, data.myEdgeCornerAngleVar );
618     setTextOrVar( myChartAngle, data.myChartAngle, data.myChartAngleVar );
619     setTextOrVar( myOuterChartAngle, data.myOuterChartAngle, data.myOuterChartAngleVar );
620     setTextOrVar( myRestHChartDistFactor, data.myRestHChartDistFactor,
621                   data.myRestHChartDistFactorVar );
622     setTextOrVar( myRestHLineLengthFactor, data.myRestHLineLengthFactor,
623                   data.myRestHLineLengthFactorVar );
624     setTextOrVar( myRestHCloseEdgeFactor, data.myRestHCloseEdgeFactor,
625                   data.myRestHCloseEdgeFactorVar );
626     setTextOrVar( myRestHSurfCurvFactor, data.myRestHSurfCurvFactor,
627                   data.myRestHSurfCurvFactorVar );
628     setTextOrVar( myRestHEdgeAngleFactor, data.myRestHEdgeAngleFactor,
629                   data.myRestHEdgeAngleFactorVar );
630     setTextOrVar( myRestHSurfMeshCurvFactor, data.myRestHSurfMeshCurvFactor,
631                   data.myRestHSurfMeshCurvFactorVar );
632
633     myRestHChartDistEnable->setChecked( data.myRestHChartDistEnable );
634     myRestHLineLengthEnable->setChecked( data.myRestHLineLengthEnable );
635     myRestHCloseEdgeEnable->setChecked( data.myRestHCloseEdgeEnable );
636     myRestHSurfCurvEnable->setChecked( data.myRestHSurfCurvEnable );
637     myRestHEdgeAngleEnable->setChecked( data.myRestHEdgeAngleEnable );
638     myRestHSurfMeshCurvEnable->setChecked( data.myRestHSurfMeshCurvEnable );
639   }
640
641   // update widgets
642   ((NETGENPluginGUI_HypothesisCreator*) this )-> onSurfaceCurvatureChanged();
643
644   if ( myLocalSizeTable )
645   {
646     NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
647     QMapIterator<QString, QString> i(myLocalSizeMap);
648     GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
649     while (i.hasNext()) {
650       i.next();
651       const QString entry = i.key();
652       std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
653       const QString localSize = i.value();
654       int row = myLocalSizeTable->rowCount();
655       myLocalSizeTable->setRowCount(row+1);
656       myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry));
657       myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0);
658       myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
659       myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0);
660       myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
661       myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
662     }
663     myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
664     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
665
666     myMeshSizeFile->setText( data.myMeshSizeFile );
667   }
668 }
669
670 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
671 {
672   NetgenHypothesisData data;
673   readParamsFromWidgets( data );
674   storeParamsToHypo( data );
675
676   return QString();
677 }
678
679 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
680 {
681   NETGENPlugin::NETGENPlugin_Hypothesis_var h =
682     NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
683
684   h_data.myName = isCreation() ? hypName() : "";
685
686   h_data.myMaxSize             = h->GetMaxSize();
687   h_data.myMaxSizeVar          = getVariableName("SetMaxSize");
688   h_data.myMinSize             = h->GetMinSize();
689   h_data.myMinSizeVar          = getVariableName("SetMinSize");
690   h_data.mySecondOrder         = h->GetSecondOrder();
691   h_data.myOptimize            = h->GetOptimize();
692
693   h_data.myFineness            = (int) h->GetFineness();
694   h_data.myGrowthRate          = h->GetGrowthRate();
695   h_data.myGrowthRateVar       = getVariableName("SetGrowthRate");
696   h_data.myNbSegPerEdge        = h->GetNbSegPerEdge();
697   h_data.myNbSegPerEdgeVar     = getVariableName("SetNbSegPerEdge");
698   h_data.myNbSegPerRadius      = h->GetNbSegPerRadius();
699   h_data.myNbSegPerRadiusVar   = getVariableName("SetNbSegPerRadius");
700   h_data.myChordalError        = h->GetChordalError();
701   h_data.myChordalErrorVar     = getVariableName("SetChordalError");
702   h_data.myChordalErrorEnabled = h->GetChordalErrorEnabled();
703   h_data.mySurfaceCurvature    = h->GetUseSurfaceCurvature();
704
705   h_data.myElemSizeWeight      = h->GetElemSizeWeight    ();
706   h_data.myElemSizeWeightVar   = getVariableName("SetElemSizeWeight");
707   h_data.myNbSurfOptSteps      = h->GetNbSurfOptSteps    ();
708   h_data.myNbSurfOptStepsVar   = getVariableName("SetNbSurfOptSteps");
709   h_data.myNbVolOptSteps       = h->GetNbVolOptSteps     ();
710   h_data.myNbVolOptStepsVar    = getVariableName("SetNbVolOptSteps");
711   h_data.myFuseEdges           = h->GetFuseEdges();
712   h_data.myWorstElemMeasure    = h->GetWorstElemMeasure  ();
713   h_data.myWorstElemMeasureVar = getVariableName("SetWorstElemMeasure");
714   h_data.myUseDelauney         = h->GetUseDelauney       ();
715   h_data.myCheckOverlapping    = h->GetCheckOverlapping  ();
716   h_data.myCheckChartBoundary  = h->GetCheckChartBoundary();
717
718   h_data.myMeshSizeFile        = h->GetMeshSizeFile();
719
720   //if ( myIs2D )
721   {
722     // NETGENPlugin::NETGENPlugin_Hypothesis_var h =
723     //   NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
724
725     if ( !h->_is_nil() )
726       h_data.myAllowQuadrangles = h->GetQuadAllowed();
727   }
728   if ( myIs2D )
729   {
730     NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D_var rh =
731       NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D::_narrow( h );
732     if ( !rh->_is_nil() )
733     {
734       h_data.myRidgeAngle                 = rh->GetRidgeAngle();
735       h_data.myRidgeAngleVar              = getVariableName("SetRidgeAngle");
736       h_data.myEdgeCornerAngle            = rh->GetEdgeCornerAngle        ();
737       h_data.myEdgeCornerAngleVar         = getVariableName("SetEdgeCornerAngle");
738       h_data.myChartAngle                 = rh->GetChartAngle             ();
739       h_data.myChartAngleVar              = getVariableName("SetChartAngle");
740       h_data.myOuterChartAngle            = rh->GetOuterChartAngle        ();
741       h_data.myOuterChartAngleVar         = getVariableName("SetOuterChartAngle");
742       h_data.myRestHChartDistFactor       = rh->GetRestHChartDistFactor   ();
743       h_data.myRestHChartDistFactorVar    = getVariableName("SetRestHChartDistFactor");
744       h_data.myRestHLineLengthFactor      = rh->GetRestHLineLengthFactor  ();
745       h_data.myRestHLineLengthFactorVar   = getVariableName("SetRestHLineLengthFactor");
746       h_data.myRestHCloseEdgeFactor       = rh->GetRestHCloseEdgeFactor   ();
747       h_data.myRestHCloseEdgeFactorVar    = getVariableName("SetRestHCloseEdgeFactor");
748       h_data.myRestHSurfCurvFactor        = rh->GetRestHSurfCurvFactor    ();
749       h_data.myRestHSurfCurvFactorVar     = getVariableName("SetRestHSurfCurvFactor");
750       h_data.myRestHEdgeAngleFactor       = rh->GetRestHEdgeAngleFactor   ();
751       h_data.myRestHEdgeAngleFactorVar    = getVariableName("SetRestHEdgeAngleFactor");
752       h_data.myRestHSurfMeshCurvFactor    = rh->GetRestHSurfMeshCurvFactor();
753       h_data.myRestHSurfMeshCurvFactorVar = getVariableName("SetRestHSurfMeshCurvFactor");
754       h_data.myRestHChartDistEnable       = rh->GetRestHChartDistEnable   ();
755       h_data.myRestHLineLengthEnable      = rh->GetRestHLineLengthEnable  ();
756       h_data.myRestHCloseEdgeEnable       = rh->GetRestHCloseEdgeEnable   ();
757       h_data.myRestHSurfCurvEnable        = rh->GetRestHSurfCurvEnable    ();
758       h_data.myRestHEdgeAngleEnable       = rh->GetRestHEdgeAngleEnable   ();
759       h_data.myRestHSurfMeshCurvEnable    = rh->GetRestHSurfMeshCurvEnable();
760       h_data.myKeepExistingEdges          = rh->GetKeepExistingEdges      ();
761       h_data.myMakeGroupsOfSurfaces       = rh->GetMakeGroupsOfSurfaces   ();
762     }
763   }
764
765   NETGENPluginGUI_HypothesisCreator*  that = (NETGENPluginGUI_HypothesisCreator*)this;
766   NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries();
767   for ( size_t i = 0; i < myEntries->length(); i++ )
768   {
769     QString entry = myEntries[i].in();
770     if (myLocalSizeMap.contains(entry) &&
771         myLocalSizeMap[entry] == "__TO_DELETE__")
772       continue;
773     double val = h->GetLocalSizeOnEntry( myEntries[i] );
774     std::ostringstream tmp;
775     tmp << val;
776     that->myLocalSizeMap[entry] = tmp.str().c_str();
777   }
778
779   return true;
780 }
781
782 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
783 {
784   NETGENPlugin::NETGENPlugin_Hypothesis_var h =
785     NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
786
787   bool ok = true;
788   try
789   {
790     if ( isCreation() )
791       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
792     h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
793     h->SetMaxSize     ( h_data.myMaxSize );
794     h->SetVarParameter( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
795     h->SetMinSize     ( h_data.myMinSize );
796     if ( mySecondOrder )
797       h->SetSecondOrder ( h_data.mySecondOrder );
798     if ( myOptimize )
799       h->SetOptimize    ( h_data.myOptimize );
800     h->SetFineness    ( h_data.myFineness );
801
802     if ( h_data.myFineness == UserDefined )
803     {
804       h->SetVarParameter  ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate");
805       h->SetGrowthRate    ( h_data.myGrowthRate );
806       if ( myNbSegPerEdge )
807       {
808         h->SetVarParameter  ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge");
809         h->SetNbSegPerEdge  ( h_data.myNbSegPerEdge );
810       }
811       if ( myNbSegPerRadius )
812       {
813         h->SetVarParameter  ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius");
814         h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
815       }
816     }
817     if ( myChordalError )
818     {
819       h->SetVarParameter       ( h_data.myChordalErrorVar.toLatin1().constData(), "SetChordalError");
820       h->SetChordalError       ( h_data.myChordalError );
821       h->SetChordalErrorEnabled( h_data.myChordalErrorEnabled );
822     }
823     if ( mySurfaceCurvature )
824       h->SetUseSurfaceCurvature( h_data.mySurfaceCurvature );
825     h->SetMeshSizeFile         ( h_data.myMeshSizeFile.toUtf8().constData() );
826
827     h->SetVarParameter  ( h_data.myElemSizeWeightVar.toLatin1().constData(), "SetElemSizeWeight");
828     h->SetElemSizeWeight( h_data.myElemSizeWeight );
829     if ( myNbSurfOptSteps )
830     {
831       h->SetVarParameter  ( h_data.myNbSurfOptStepsVar.toLatin1().constData(), "SetNbSurfOptSteps");
832       h->SetNbSurfOptSteps( h_data.myNbSurfOptSteps );
833     }
834     if ( myNbVolOptSteps )
835     {
836       h->SetVarParameter ( h_data.myNbVolOptStepsVar.toLatin1().constData(), "SetNbVolOptSteps");
837       h->SetNbVolOptSteps( h_data.myNbVolOptSteps );
838     }
839     if ( myFuseEdges )
840       h->SetFuseEdges( h_data.myFuseEdges );
841     h->SetVarParameter    ( h_data.myWorstElemMeasureVar.toLatin1().constData(), "SetWorstElemMeasure");
842     h->SetWorstElemMeasure( h_data.myWorstElemMeasure );
843
844     h->SetUseDelauney( h_data.myUseDelauney );
845     h->SetCheckOverlapping( h_data.myCheckOverlapping );
846     h->SetCheckChartBoundary( h_data.myCheckChartBoundary );
847     
848     //if ( myIs2D )
849     {
850       // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
851       //   NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
852       // if ( !h_2d->_is_nil() )
853       //   h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
854       if ( myAllowQuadrangles )
855         h->SetQuadAllowed( h_data.myAllowQuadrangles );
856     }
857     if ( myIs2D )
858     {
859       NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D_var rh =
860         NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D::_narrow( h );
861       if ( !rh->_is_nil() )
862       {
863         rh->SetVarParameter   ( h_data.myRidgeAngleVar.toLatin1().constData(), "SetRidgeAngle");
864         rh->SetRidgeAngle     ( h_data.myRidgeAngle );
865         rh->SetVarParameter   ( h_data.myEdgeCornerAngleVar.toLatin1().constData(), "SetEdgeCornerAngle");
866         rh->SetEdgeCornerAngle( h_data.myEdgeCornerAngle );
867         rh->SetVarParameter   ( h_data.myChartAngleVar.toLatin1().constData(), "SetChartAngle");
868         rh->SetChartAngle     ( h_data.myChartAngle );
869         rh->SetVarParameter   ( h_data.myOuterChartAngleVar.toLatin1().constData(), "SetOuterChartAngle");
870         rh->SetOuterChartAngle( h_data.myOuterChartAngle );
871
872         rh->SetVarParameter           ( h_data.myRestHChartDistFactorVar.toLatin1().constData(), "SetRestHChartDistFactor");
873         rh->SetRestHChartDistFactor   ( h_data.myRestHChartDistFactor );
874         rh->SetVarParameter           ( h_data.myRestHLineLengthFactorVar.toLatin1().constData(), "SetRestHLineLengthFactor");
875         rh->SetRestHLineLengthFactor  ( h_data.myRestHLineLengthFactor );
876         rh->SetVarParameter           ( h_data.myRestHCloseEdgeFactorVar.toLatin1().constData(), "SetRestHCloseEdgeFactor");
877         rh->SetRestHCloseEdgeFactor   ( h_data.myRestHCloseEdgeFactor );
878         rh->SetVarParameter           ( h_data.myRestHSurfCurvFactorVar.toLatin1().constData(), "SetRestHSurfCurvFactor");
879         rh->SetRestHSurfCurvFactor    ( h_data.myRestHSurfCurvFactor );
880         rh->SetVarParameter           ( h_data.myRestHEdgeAngleFactorVar.toLatin1().constData(), "SetRestHEdgeAngleFactor");
881         rh->SetRestHEdgeAngleFactor   ( h_data.myRestHEdgeAngleFactor );
882         rh->SetVarParameter           ( h_data.myRestHSurfMeshCurvFactorVar.toLatin1().constData(), "SetRestHSurfMeshCurvFactor");
883         rh->SetRestHSurfMeshCurvFactor( h_data.myRestHSurfMeshCurvFactor );
884
885         rh->SetRestHChartDistEnable   ( h_data.myRestHChartDistEnable );
886         rh->SetRestHLineLengthEnable  ( h_data.myRestHLineLengthEnable );
887         rh->SetRestHCloseEdgeEnable   ( h_data.myRestHCloseEdgeEnable );
888         rh->SetRestHSurfCurvEnable    ( h_data.myRestHSurfCurvEnable );
889         rh->SetRestHEdgeAngleEnable   ( h_data.myRestHEdgeAngleEnable );
890         rh->SetRestHSurfMeshCurvEnable( h_data.myRestHSurfMeshCurvEnable );
891
892         rh->SetKeepExistingEdges      ( h_data.myKeepExistingEdges );
893         rh->SetMakeGroupsOfSurfaces   ( h_data.myMakeGroupsOfSurfaces );
894         rh->SetFixedEdgeGroup         ( 0 );
895       }
896     }
897     for ( QMapIterator<QString,QString> i(myLocalSizeMap); i.hasNext(); )
898     {
899       i.next();
900       const QString&     entry = i.key();
901       const QString& localSize = i.value();
902       if (localSize == "__TO_DELETE__")
903       {
904         h->UnsetLocalSizeOnEntry(entry.toLatin1().constData());
905       }
906       else
907       {
908         h->SetLocalSizeOnEntry(entry.toLatin1().constData(), localSize.toDouble());
909       }
910     }
911   }
912   catch(const SALOME::SALOME_Exception& ex)
913   {
914     SalomeApp_Tools::QtCatchCorbaException(ex);
915     ok = false;
916   }
917   return ok;
918 }
919
920 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
921 {
922   h_data.myName           = myName ? myName->text() : "";
923   h_data.myMaxSize        = myMaxSize->value();
924   h_data.myMaxSizeVar     = myMaxSize->text();
925   h_data.myMinSize        = myMinSize->value();
926   h_data.myMinSizeVar     = myMinSize->text();
927   if ( mySecondOrder )
928     h_data.mySecondOrder  = mySecondOrder->isChecked();
929   if ( myOptimize )
930     h_data.myOptimize     = myOptimize->isChecked();
931   h_data.myFineness       = myFineness->currentIndex();
932   h_data.myGrowthRate     = myGrowthRate->value();
933   if ( myNbSegPerEdge )
934     h_data.myNbSegPerEdge = myNbSegPerEdge->value();
935   if ( myNbSegPerRadius )
936     h_data.myNbSegPerRadius = myNbSegPerRadius->value();
937
938   h_data.myGrowthRateVar  = myGrowthRate->text();
939   if ( myNbSegPerEdge )
940     h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
941   if ( myNbSegPerRadius )
942     h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
943   if ( myChordalError )
944   {
945     h_data.myChordalErrorVar = myChordalError->text();
946     h_data.myChordalError    = myChordalError->value();
947     h_data.myChordalErrorEnabled = myChordalError->isEnabled();
948   }
949   if ( myAllowQuadrangles )
950     h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
951
952   if ( mySurfaceCurvature )
953     h_data.mySurfaceCurvature = mySurfaceCurvature->isChecked();
954
955   if ( myFuseEdges )
956     h_data.myFuseEdges = myFuseEdges->isChecked();
957
958   if ( myElemSizeWeight )
959   {
960     h_data.myElemSizeWeight    = myElemSizeWeight->value();
961     h_data.myElemSizeWeightVar = myElemSizeWeight->text();
962   }
963   if ( myNbSurfOptSteps )
964   {
965     h_data.myNbSurfOptSteps    = myNbSurfOptSteps->value();
966     h_data.myNbSurfOptStepsVar = myNbSurfOptSteps->text();
967   }
968   if ( myNbVolOptSteps )
969   {
970     h_data.myNbVolOptSteps    = myNbVolOptSteps->value();
971     h_data.myNbVolOptStepsVar = myNbVolOptSteps->text();
972   }
973   if ( myWorstElemMeasure )
974   {
975     h_data.myWorstElemMeasure    = myWorstElemMeasure->value();
976     h_data.myWorstElemMeasureVar = myWorstElemMeasure->text();
977   }
978   if ( myUseDelauney )
979     h_data.myUseDelauney        = myUseDelauney->isChecked();
980
981   if ( myCheckOverlapping )
982     h_data.myCheckOverlapping   = myCheckOverlapping->isChecked();
983
984   if ( myCheckChartBoundary )
985     h_data.myCheckChartBoundary = myCheckChartBoundary->isChecked();
986
987   if ( myRidgeAngle )
988   {
989     h_data.myRidgeAngle                 = myRidgeAngle             ->value();
990     h_data.myRidgeAngleVar              = myRidgeAngle             ->text();
991     h_data.myEdgeCornerAngle            = myEdgeCornerAngle        ->value();
992     h_data.myEdgeCornerAngleVar         = myEdgeCornerAngle        ->text();
993     h_data.myChartAngle                 = myChartAngle             ->value();
994     h_data.myChartAngleVar              = myChartAngle             ->text();
995     h_data.myOuterChartAngle            = myOuterChartAngle        ->value();
996     h_data.myOuterChartAngleVar         = myOuterChartAngle        ->text();
997     h_data.myRestHChartDistFactor       = myRestHChartDistFactor   ->value();
998     h_data.myRestHChartDistFactorVar    = myRestHChartDistFactor   ->text();
999     h_data.myRestHLineLengthFactor      = myRestHLineLengthFactor  ->value();
1000     h_data.myRestHLineLengthFactorVar   = myRestHLineLengthFactor  ->text();
1001     h_data.myRestHCloseEdgeFactor       = myRestHCloseEdgeFactor   ->value();
1002     h_data.myRestHCloseEdgeFactorVar    = myRestHCloseEdgeFactor   ->text();
1003     h_data.myRestHSurfCurvFactor        = myRestHSurfCurvFactor    ->value();
1004     h_data.myRestHSurfCurvFactorVar     = myRestHSurfCurvFactor    ->text();
1005     h_data.myRestHEdgeAngleFactor       = myRestHEdgeAngleFactor   ->value();
1006     h_data.myRestHEdgeAngleFactorVar    = myRestHEdgeAngleFactor   ->text();
1007     h_data.myRestHSurfMeshCurvFactor    = myRestHSurfMeshCurvFactor->value();
1008     h_data.myRestHSurfMeshCurvFactorVar = myRestHSurfMeshCurvFactor->text();
1009     h_data.myRestHChartDistEnable       = myRestHChartDistEnable   ->isChecked();
1010     h_data.myRestHLineLengthEnable      = myRestHLineLengthEnable  ->isChecked();
1011     h_data.myRestHCloseEdgeEnable       = myRestHCloseEdgeEnable   ->isChecked();
1012     h_data.myRestHSurfCurvEnable        = myRestHSurfCurvEnable    ->isChecked();
1013     h_data.myRestHEdgeAngleEnable       = myRestHEdgeAngleEnable   ->isChecked();
1014     h_data.myRestHSurfMeshCurvEnable    = myRestHSurfMeshCurvEnable->isChecked();
1015     h_data.myKeepExistingEdges          = myKeepExistingEdges      ->isChecked();
1016     h_data.myMakeGroupsOfSurfaces       = myMakeGroupsOfSurfaces   ->isChecked();
1017   }
1018
1019   if ( myLocalSizeTable )
1020   {
1021     NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
1022     int nbRows = myLocalSizeTable->rowCount();
1023     for(int row=0 ; row < nbRows ; row++)
1024     {
1025       QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
1026       QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
1027       that->myLocalSizeMap[entry] = localSize;
1028     }
1029     h_data.myMeshSizeFile = myMeshSizeFile->text();
1030   }
1031   return true;
1032 }
1033
1034 void NETGENPluginGUI_HypothesisCreator::onChordalErrorEnabled()
1035 {
1036   myChordalError->setEnabled( myChordalErrorEnabled->isChecked() );
1037 }
1038
1039 void NETGENPluginGUI_HypothesisCreator::onSurfaceCurvatureChanged()
1040 {
1041   bool isSurfaceCurvature = (mySurfaceCurvature ? mySurfaceCurvature->isChecked() : true);
1042   bool isCustom           = (myFineness->currentIndex() == UserDefined);
1043   //myFineness->setEnabled(isSurfaceCurvature);
1044   myGrowthRate->setEnabled(isCustom);
1045   if ( myNbSegPerEdge )
1046     myNbSegPerEdge->setEnabled(isCustom && isSurfaceCurvature);
1047   if ( myNbSegPerRadius )
1048     myNbSegPerRadius->setEnabled(isCustom && isSurfaceCurvature);
1049   // if ( myChordalError )
1050   // {
1051   //   myChordalError->setEnabled( isSurfaceCurvature );
1052   //   myChordalErrorEnabled->setEnabled( isSurfaceCurvature );
1053   // }
1054 }
1055
1056 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
1057 {
1058   bool isCustom = (myFineness->currentIndex() == UserDefined);
1059
1060   myGrowthRate->setEnabled(isCustom);
1061   if ( myNbSegPerEdge )
1062     myNbSegPerEdge->setEnabled(isCustom);
1063   if ( myNbSegPerRadius )
1064     myNbSegPerRadius->setEnabled(isCustom);
1065
1066   if (!isCustom)
1067   {
1068     double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
1069
1070     switch ( myFineness->currentIndex() )
1071     {
1072     case VeryCoarse:
1073       aGrowthRate     = 0.7;
1074       aNbSegPerEdge   = 0.3;
1075       aNbSegPerRadius = 1;
1076       break;
1077     case Coarse:
1078       aGrowthRate     = 0.5;
1079       aNbSegPerEdge   = 0.5;
1080       aNbSegPerRadius = 1.5;
1081       break;
1082     case Fine:
1083       aGrowthRate     = 0.2;
1084       aNbSegPerEdge   = 2;
1085       aNbSegPerRadius = 3;
1086       break;
1087     case VeryFine:
1088       aGrowthRate     = 0.1;
1089       aNbSegPerEdge   = 3;
1090       aNbSegPerRadius = 5;
1091       break;
1092     case Moderate:
1093     default:
1094       aGrowthRate     = 0.3;
1095       aNbSegPerEdge   = 1;
1096       aNbSegPerRadius = 2;
1097       break;
1098     }
1099
1100     myGrowthRate->setValue( aGrowthRate );
1101     if ( myNbSegPerEdge )
1102       myNbSegPerEdge->setValue( aNbSegPerEdge );
1103     if ( myNbSegPerRadius )
1104       myNbSegPerRadius->setValue( aNbSegPerRadius );
1105   }
1106 }
1107
1108 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnVertex()
1109 {
1110   addLocalSizeOnShape(TopAbs_VERTEX);
1111 }
1112
1113 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnEdge()
1114 {
1115   addLocalSizeOnShape(TopAbs_EDGE);
1116 }
1117
1118 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnFace()
1119 {
1120   addLocalSizeOnShape(TopAbs_FACE);
1121 }
1122
1123 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnSolid()
1124 {
1125   addLocalSizeOnShape(TopAbs_SOLID);
1126 }
1127
1128 void NETGENPluginGUI_HypothesisCreator::addLocalSizeOnShape(TopAbs_ShapeEnum typeShapeAsked)
1129 {
1130   NETGENPlugin::NETGENPlugin_Hypothesis_var h = NETGENPlugin::NETGENPlugin_Hypothesis::_narrow(initParamsHypothesis());
1131   GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
1132   LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
1133   SALOME_ListIO ListSelectedObjects;
1134   mySel->selectedObjects(ListSelectedObjects, NULL, false );
1135   SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1136   for ( ; Object_It.More() ; Object_It.Next())
1137   {
1138     Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1139     std::string          entry = geomSelectionTools->getEntryOfObject(anObject);
1140     std::string      shapeName = anObject->getName();
1141     TopAbs_ShapeEnum shapeType = geomSelectionTools->entryToShapeType(entry);
1142     if (shapeType == TopAbs_SHAPE)
1143     {
1144       // E.A. if shapeType == TopAbs_SHAPE, it is NOT a TopoDS_Shape !!!
1145       continue;
1146     }
1147     // --
1148     if(shapeType != typeShapeAsked)
1149     {
1150       continue;
1151     }
1152     // --
1153     myLocalSizeTable->setFocus();
1154     QString shapeEntry = QString::fromStdString(entry);
1155     if (myLocalSizeMap.contains(shapeEntry) &&
1156         myLocalSizeMap[shapeEntry] != "__TO_DELETE__")
1157       continue;
1158
1159     double phySize = h->GetMaxSize();
1160     std::ostringstream oss;
1161     oss << phySize;
1162     QString localSize;
1163     localSize  = QString::fromStdString(oss.str());
1164     // --
1165     int row = myLocalSizeTable->rowCount() ;
1166     myLocalSizeTable->setRowCount(row+1);
1167     myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(shapeEntry));
1168     myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN )->setFlags(0);
1169     myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
1170     myLocalSizeTable->item(row, LSZ_NAME_COLUMN )->setFlags(0);
1171     myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
1172     myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
1173     myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
1174     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
1175     myLocalSizeTable->clearSelection();
1176     myLocalSizeTable->scrollToItem( myLocalSizeTable->item( row, LSZ_LOCALSIZE_COLUMN ) );
1177     // --
1178   }
1179 }
1180
1181 void NETGENPluginGUI_HypothesisCreator::onRemoveLocalSizeOnShape()
1182 {
1183   QList<int> selectedRows;
1184   QList<QTableWidgetItem*> selected = myLocalSizeTable->selectedItems();
1185   QTableWidgetItem* item;
1186   int row;
1187   foreach(item, selected) {
1188     row = item->row();
1189     if (!selectedRows.contains(row))
1190       selectedRows.append( row );
1191   }
1192   qSort( selectedRows );
1193   QListIterator<int> it( selectedRows );
1194   it.toBack();
1195   while (it.hasPrevious())
1196   {
1197     row = it.previous();
1198     QString entry = myLocalSizeTable->item(row,LSZ_ENTRY_COLUMN)->text();
1199     if (myLocalSizeMap.contains(entry))
1200     {
1201       myLocalSizeMap[entry] = "__TO_DELETE__";
1202     }
1203     myLocalSizeTable->removeRow(row );
1204   }
1205   myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
1206   myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
1207 }
1208
1209 void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col)
1210 {
1211   if (col == LSZ_LOCALSIZE_COLUMN) {
1212     QString     entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
1213     QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
1214     myLocalSizeMap[entry] = localSize;
1215     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
1216   }
1217 }
1218
1219 void NETGENPluginGUI_HypothesisCreator::onSetSizeFile()
1220 {
1221   QString dir = SUIT_FileDlg::getFileName( dlg(), QString(),
1222                                            QStringList() << tr( "ALL_FILES_FILTER" ) + "  (*)");
1223   myMeshSizeFile->setText( dir );
1224 }
1225
1226 void NETGENPluginGUI_HypothesisCreator::onSTLEnable()
1227 {
1228   myRestHChartDistFactor   ->setEnabled( myRestHChartDistEnable   ->isChecked() );
1229   myRestHLineLengthFactor  ->setEnabled( myRestHLineLengthEnable  ->isChecked() );
1230   myRestHCloseEdgeFactor   ->setEnabled( myRestHCloseEdgeEnable   ->isChecked() );
1231   myRestHSurfCurvFactor    ->setEnabled( myRestHSurfCurvEnable    ->isChecked() );
1232   myRestHEdgeAngleFactor   ->setEnabled( myRestHEdgeAngleEnable   ->isChecked() );
1233   myRestHSurfMeshCurvFactor->setEnabled( myRestHSurfMeshCurvEnable->isChecked() );
1234 }
1235
1236 GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools()
1237 {
1238   if (myGeomSelectionTools == NULL) {
1239     delete myGeomSelectionTools;
1240     myGeomSelectionTools = new GeomSelectionTools();
1241   }
1242   return myGeomSelectionTools;
1243 }
1244
1245 QString NETGENPluginGUI_HypothesisCreator::caption() const
1246 {
1247   return tr( myIs2D ? "NETGEN_2D_TITLE" : "NETGEN_3D_TITLE");
1248 }
1249
1250 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
1251 {
1252   QString hypIconName = tr( myIs2D ?
1253                             "ICON_DLG_NETGEN_PARAMETERS_2D" :
1254                             "ICON_DLG_NETGEN_PARAMETERS");
1255   return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
1256 }
1257
1258 QString NETGENPluginGUI_HypothesisCreator::type() const
1259 {
1260   return tr( myIs2D ? "NETGEN_2D_HYPOTHESIS" : "NETGEN_3D_HYPOTHESIS");
1261 }
1262
1263 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
1264 {
1265   return "netgen_2d_3d_hypo_page.html";
1266 }