]> SALOME platform Git repositories - plugins/netgenplugin.git/blob - src/GUI/NETGENPluginGUI_HypothesisCreator.cxx
Salome HOME
21676: EDF 2283 NETGENPLUGIN: Improve Netgen 1D-2D-3D to generate pyramids in case...
[plugins/netgenplugin.git] / src / GUI / NETGENPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2013  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.
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 <SUIT_Session.h>
38 #include <SUIT_ResourceMgr.h>
39
40 #include <SalomeApp_Tools.h>
41 #include <LightApp_SelectionMgr.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
43
44 #include <QComboBox>
45 #include <QLabel>
46 #include <QGroupBox>
47 #include <QFrame>
48 #include <QLayout>
49 #include <QLineEdit>
50 #include <QCheckBox>
51 #include <QPixmap>
52 #include <QTableWidget>
53 #include <QHeaderView>
54 #include <QPushButton>
55
56 enum Fineness
57   {
58     VeryCoarse,
59     Coarse,
60     Moderate,
61     Fine,
62     VeryFine,
63     UserDefined
64   };
65
66 enum {
67   STD_TAB = 0,
68   LSZ_TAB
69 };
70
71 enum {
72   LSZ_ENTRY_COLUMN = 0,
73   LSZ_NAME_COLUMN,
74   LSZ_LOCALSIZE_COLUMN,
75   LSZ_NB_COLUMNS
76 };
77
78 enum {
79   LSZ_BTNS = 0,
80   LSZ_VERTEX_BTN,
81   LSZ_EDGE_BTN,
82   LSZ_FACE_BTN,
83   LSZ_SEPARATOR2,
84   LSZ_REMOVE_BTN
85 };
86
87 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
88   : SMESHGUI_GenericHypothesisCreator( theHypType )
89 {
90   myGeomSelectionTools = NULL;
91   myLocalSizeMap.clear();
92   myIs2D = ( theHypType.startsWith("NETGEN_Parameters_2D"));
93   myIsONLY = ( theHypType == "NETGEN_Parameters_2D_ONLY" ||
94                theHypType == "NETGEN_Parameters_3D");
95 }
96
97 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
98 {
99 }
100
101 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
102 {
103   NetgenHypothesisData data_old, data_new;
104   readParamsFromHypo( data_old );
105   readParamsFromWidgets( data_new );
106   bool res = storeParamsToHypo( data_new );
107   //storeParamsToHypo( data_old ); -- issue 0021364: Dump of netgen parameters has duplicate lines
108   
109   res = myMaxSize->isValid(msg,true) && res;
110   res = myMinSize->isValid(msg,true) && res;
111   res = myGrowthRate->isValid(msg,true) && res; ;
112   if ( myNbSegPerEdge )
113     res = myNbSegPerEdge->isValid(msg,true) && res;
114   if ( myNbSegPerRadius )
115     res = myNbSegPerRadius->isValid(msg,true) && res;
116
117   if ( !res ) //  -- issue 0021364: Dump of netgen parameters has duplicate lines
118     storeParamsToHypo( data_old );
119
120   return res;
121 }
122
123 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
124 {
125   QFrame* fr = new QFrame( 0 );
126   fr->setObjectName( "myframe" );
127   QVBoxLayout* lay = new QVBoxLayout( fr );
128   lay->setMargin( 5 );
129   lay->setSpacing( 0 );
130
131   QTabWidget* tab = new QTabWidget( fr );
132   tab->setTabShape( QTabWidget::Rounded );
133   tab->setTabPosition( QTabWidget::North );
134   lay->addWidget( tab );
135   QWidget* GroupC1 = new QWidget();
136   tab->insertTab( STD_TAB, GroupC1, tr( "SMESH_ARGUMENTS" ) );
137   
138   QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
139   aGroupLayout->setSpacing( 6 );
140   aGroupLayout->setMargin( 11 );
141   
142   int row = 0;
143   myName = 0;
144   if( isCreation() )
145   {
146     aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
147     myName = new QLineEdit( GroupC1 );
148     myName->setMinimumWidth(160);
149     aGroupLayout->addWidget( myName, row, 1 );
150     row++;
151   }
152
153   aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
154   myMaxSize = new SMESHGUI_SpinBox( GroupC1 );
155   myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" );
156   aGroupLayout->addWidget( myMaxSize, row, 1 );
157   row++;
158
159   aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MIN_SIZE" ), GroupC1 ), row, 0 );
160   myMinSize = new SMESHGUI_SpinBox( GroupC1 );
161   myMinSize->RangeStepAndValidator( 0.0, 1e+06, 10., "length_precision" );
162   aGroupLayout->addWidget( myMinSize, row, 1 );
163   row++;
164
165   mySecondOrder = 0;
166   if ( !myIsONLY )
167   {
168     mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
169     aGroupLayout->addWidget( mySecondOrder, row, 0 );
170     row++;
171   }
172
173   aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
174   myFineness = new QComboBox( GroupC1 );
175   QStringList types;
176   types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" )   << tr( "NETGEN_MODERATE" ) <<
177            tr( "NETGEN_FINE" )       << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
178   myFineness->addItems( types );
179   aGroupLayout->addWidget( myFineness, row, 1 );
180   row++;
181
182   aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
183   myGrowthRate = new SMESHGUI_SpinBox( GroupC1 );
184   myGrowthRate->RangeStepAndValidator( .0001, 10., .1, "parametric_precision" );
185   aGroupLayout->addWidget( myGrowthRate, row, 1 );
186   row++;
187
188   myNbSegPerEdge = 0;
189   myNbSegPerRadius = 0;
190   if ( !myIsONLY )
191   {
192     const double VALUE_MAX = 1.0e+6;
193
194     aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
195     myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 );
196     myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
197     aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
198     row++;
199
200     aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
201     myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 );
202     myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
203     aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
204     row++;
205   }
206   myAllowQuadrangles = 0;
207   if ( myIs2D || !myIsONLY ) // issue 0021676
208   {
209     myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
210     aGroupLayout->addWidget( myAllowQuadrangles, row, 0 );
211     row++;
212   }
213
214   myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
215   aGroupLayout->addWidget( myOptimize, row, 0 );
216   row++;
217
218   connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
219
220   myLocalSizeTable = 0;
221   if ( !myIsONLY )
222   {
223     QWidget* localSizeGroup = new QWidget();
224     QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup);
225
226     myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup);
227     localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1);
228     QStringList localSizeHeaders;
229     localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" );
230     myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders);
231     myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN);
232     myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
233     myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
234     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
235     myLocalSizeTable->setAlternatingRowColors(true);
236     myLocalSizeTable->verticalHeader()->hide();
237
238     QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup);
239     localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1);
240     QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup);
241     localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1);
242     QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup);
243     localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1);
244
245     QFrame *line2 = new QFrame(localSizeGroup);
246     line2->setFrameShape(QFrame::HLine);
247     line2->setFrameShadow(QFrame::Sunken);
248     localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1);
249
250     QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup);
251     localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1);
252
253     connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex()));
254     connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge()));
255     connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace()));
256     connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape()));
257     connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int)));
258
259     tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE"));
260   }
261   return fr;
262 }
263
264 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
265 {
266   NetgenHypothesisData data;
267   readParamsFromHypo( data );
268
269   if( myName )
270     myName->setText( data.myName );
271   if(data.myMaxSizeVar.isEmpty())
272     myMaxSize->setValue( data.myMaxSize );
273   else
274     myMaxSize->setText( data.myMaxSizeVar );
275
276   if(data.myMinSizeVar.isEmpty())
277     myMinSize->setValue( data.myMinSize );
278   else
279     myMinSize->setText( data.myMinSizeVar );
280
281   if ( mySecondOrder )
282     mySecondOrder->setChecked( data.mySecondOrder );
283   if ( myOptimize )
284     myOptimize->setChecked( data.myOptimize );
285   myFineness->setCurrentIndex( data.myFineness );
286
287   if(data.myGrowthRateVar.isEmpty())
288     myGrowthRate->setValue( data.myGrowthRate );
289   else
290     myGrowthRate->setText( data.myGrowthRateVar );
291
292   if ( myNbSegPerEdge )
293   {
294     if(data.myNbSegPerEdgeVar.isEmpty())
295       myNbSegPerEdge->setValue( data.myNbSegPerEdge );
296     else
297       myNbSegPerEdge->setText( data.myNbSegPerEdgeVar );
298   }
299   if ( myNbSegPerRadius )
300   {
301     if(data.myNbSegPerRadiusVar.isEmpty())
302       myNbSegPerRadius->setValue( data.myNbSegPerRadius );
303     else
304       myNbSegPerRadius->setText( data.myNbSegPerRadiusVar );
305   }  
306   if (myAllowQuadrangles)
307     myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
308
309   // update widgets
310   bool isCustom = (myFineness->currentIndex() == UserDefined);
311   myGrowthRate->setEnabled(isCustom);
312   if ( myNbSegPerEdge )
313     myNbSegPerEdge->setEnabled(isCustom);
314   if ( myNbSegPerRadius )
315     myNbSegPerRadius->setEnabled(isCustom);
316
317   if ( myLocalSizeTable )
318   {
319     NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
320     QMapIterator<QString, QString> i(myLocalSizeMap);
321     GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
322     while (i.hasNext()) {
323       i.next();
324       const QString entry = i.key();
325       std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
326       const QString localSize = i.value();
327       int row = myLocalSizeTable->rowCount();
328       myLocalSizeTable->setRowCount(row+1);
329       myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry));
330       myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0);
331       myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
332       myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0);
333       myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
334       myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
335     }
336     myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
337     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
338   }
339 }
340
341 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
342 {
343   NetgenHypothesisData data;
344   readParamsFromWidgets( data );
345   storeParamsToHypo( data );
346   
347   QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
348   valStr += tr("NETGEN_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
349   if ( data.mySecondOrder )
350     valStr +=  tr("NETGEN_SECOND_ORDER") + "; ";
351   if ( data.myOptimize )
352     valStr +=  tr("NETGEN_OPTIMIZE") + "; ";
353   valStr += myFineness->currentText() + "(" +  QString::number( data.myGrowthRate )     + ", " +
354                                                QString::number( data.myNbSegPerEdge )   + ", " +
355                                                QString::number( data.myNbSegPerRadius ) + ")";
356
357   if ( myIs2D && data.myAllowQuadrangles )
358     valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
359   
360   return valStr;
361 }
362
363 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
364 {
365   NETGENPlugin::NETGENPlugin_Hypothesis_var h =
366     NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
367
368   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
369   h_data.myName = isCreation() && data ? data->Label : "";
370
371   h_data.myMaxSize = h->GetMaxSize();
372   h_data.myMaxSizeVar = getVariableName("SetMaxSize");
373   h_data.mySecondOrder = h->GetSecondOrder();
374   h_data.myOptimize = h->GetOptimize();
375
376   h_data.myFineness = (int) h->GetFineness();
377   h_data.myGrowthRate = h->GetGrowthRate();
378   h_data.myGrowthRateVar = getVariableName("SetGrowthRate");
379   h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
380   h_data.myNbSegPerEdgeVar  = getVariableName("SetNbSegPerEdge");
381   h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
382   h_data.myNbSegPerRadiusVar = getVariableName("SetNbSegPerRadius");
383   h_data.myMinSize = h->GetMinSize();
384   h_data.myMinSizeVar = getVariableName("SetMinSize");
385
386   //if ( myIs2D )
387     {
388       NETGENPlugin::NETGENPlugin_Hypothesis_var h =
389         NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
390
391       if ( !h->_is_nil() )
392         h_data.myAllowQuadrangles = h->GetQuadAllowed();
393     }
394   
395   NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
396   NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries();
397   for ( int i=0 ; i<myEntries->length() ; i++ )
398     {
399       QString entry = myEntries[i].in();
400       double val = h->GetLocalSizeOnEntry(entry.toStdString().c_str());
401       std::ostringstream tmp;
402       tmp << val;
403       QString valstring = QString::fromStdString(tmp.str());
404       if (myLocalSizeMap.contains(entry))
405         {
406           if (myLocalSizeMap[entry] == "__TO_DELETE__")
407             {
408               continue;
409             }
410         }
411       that->myLocalSizeMap[entry] = valstring;
412     }
413
414   return true;
415 }
416
417 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
418 {
419   NETGENPlugin::NETGENPlugin_Hypothesis_var h =
420     NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
421
422   bool ok = true;
423   try
424   {
425     if( isCreation() )
426       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
427     h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
428     h->SetMaxSize( h_data.myMaxSize );
429     h->SetSecondOrder( h_data.mySecondOrder );
430     h->SetOptimize( h_data.myOptimize );
431     int fineness = h_data.myFineness;
432     h->SetFineness( fineness );
433
434     if( fineness==UserDefined )
435       {
436         h->SetVarParameter( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate");
437         h->SetGrowthRate( h_data.myGrowthRate );
438         h->SetVarParameter( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge");
439         h->SetNbSegPerEdge( h_data.myNbSegPerEdge );
440         h->SetVarParameter( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius");
441         h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
442       }
443     h->SetVarParameter( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
444     h->SetMinSize( h_data.myMinSize );
445     
446     //if ( myIs2D )
447       {
448         // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
449         //   NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
450         
451         // if ( !h_2d->_is_nil() )
452         //   h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
453         h->SetQuadAllowed( h_data.myAllowQuadrangles );
454       }
455
456     QMapIterator<QString,QString> i(myLocalSizeMap);
457     while (i.hasNext()) {
458       i.next();
459       const QString entry = i.key();
460       const QString localSize = i.value();
461       if (localSize == "__TO_DELETE__")
462         {
463           h->UnsetLocalSizeOnEntry(entry.toLatin1().constData());
464         }
465       else
466         {
467           std::istringstream tmp(localSize.toLatin1().constData());
468           double val;
469           tmp >> val;
470           h->SetLocalSizeOnEntry(entry.toLatin1().constData(), val);
471         }
472     }
473   }
474   catch(const SALOME::SALOME_Exception& ex)
475   {
476     SalomeApp_Tools::QtCatchCorbaException(ex);
477     ok = false;
478   }
479   return ok;
480 }
481
482 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
483 {
484   h_data.myName           = myName ? myName->text() : "";
485   h_data.myMaxSize        = myMaxSize->value();
486   h_data.myMaxSizeVar     = myMaxSize->text();
487   h_data.myMinSize        = myMinSize->value();
488   h_data.myMinSizeVar     = myMinSize->text();
489   if ( mySecondOrder )
490     h_data.mySecondOrder  = mySecondOrder->isChecked();
491   if ( myOptimize )
492     h_data.myOptimize     = myOptimize->isChecked();
493   h_data.myFineness       = myFineness->currentIndex();
494   h_data.myGrowthRate     = myGrowthRate->value();
495   if ( myNbSegPerEdge )
496     h_data.myNbSegPerEdge = myNbSegPerEdge->value();
497   if ( myNbSegPerRadius )
498     h_data.myNbSegPerRadius = myNbSegPerRadius->value();
499
500   h_data.myGrowthRateVar  = myGrowthRate->text();
501   if ( myNbSegPerEdge )
502     h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
503   if ( myNbSegPerRadius )
504     h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
505
506   
507   if ( myAllowQuadrangles )
508     h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
509
510   if ( myLocalSizeTable )
511   {
512     NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
513     int nbRows = myLocalSizeTable->rowCount();
514     for(int row=0 ; row < nbRows ; row++)
515     {
516       QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
517       QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
518       that->myLocalSizeMap[entry] = localSize;
519     }
520   }
521   return true;
522 }
523
524 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
525 {
526   bool isCustom = (myFineness->currentIndex() == UserDefined);
527   
528   myGrowthRate->setEnabled(isCustom);
529   if ( myNbSegPerEdge )
530     myNbSegPerEdge->setEnabled(isCustom);
531   if ( myNbSegPerRadius )
532     myNbSegPerRadius->setEnabled(isCustom);
533
534   if (!isCustom)
535     {
536       double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
537       
538       switch ( myFineness->currentIndex() )
539         {
540         case VeryCoarse:
541           aGrowthRate = 0.7;
542           aNbSegPerEdge = 0.3;
543           aNbSegPerRadius = 1;
544           break;
545         case Coarse:
546           aGrowthRate = 0.5;
547           aNbSegPerEdge = 0.5;
548           aNbSegPerRadius = 1.5;
549           break;
550         case Fine:
551           aGrowthRate = 0.2;
552           aNbSegPerEdge = 2;
553           aNbSegPerRadius = 3;
554           break;
555         case VeryFine:
556           aGrowthRate = 0.1;
557           aNbSegPerEdge = 3;
558           aNbSegPerRadius = 5;
559           break;
560         case Moderate:
561         default:
562           aGrowthRate = 0.3;
563           aNbSegPerEdge = 1;
564           aNbSegPerRadius = 2;
565           break;
566         }
567       
568       myGrowthRate->setValue( aGrowthRate );
569       if ( myNbSegPerEdge )
570         myNbSegPerEdge->setValue( aNbSegPerEdge );
571       if ( myNbSegPerRadius )
572         myNbSegPerRadius->setValue( aNbSegPerRadius );
573     }
574 }
575
576 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnVertex()
577 {
578   addLocalSizeOnShape(TopAbs_VERTEX);
579 }
580
581 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnEdge()
582 {
583   addLocalSizeOnShape(TopAbs_EDGE);
584 }
585
586 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnFace()
587 {
588   addLocalSizeOnShape(TopAbs_FACE);
589 }
590
591 void NETGENPluginGUI_HypothesisCreator::addLocalSizeOnShape(TopAbs_ShapeEnum typeShapeAsked)
592 {
593   NETGENPlugin::NETGENPlugin_Hypothesis_var h = NETGENPlugin::NETGENPlugin_Hypothesis::_narrow(initParamsHypothesis());
594   GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
595   LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
596   SALOME_ListIO ListSelectedObjects;
597   mySel->selectedObjects(ListSelectedObjects, NULL, false );
598   SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
599   for (Object_It ; Object_It.More() ; Object_It.Next())
600     {
601       Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
602       std::string entry, shapeName;
603       entry = geomSelectionTools->getEntryOfObject(anObject);
604       shapeName = anObject->getName();
605       TopAbs_ShapeEnum shapeType;
606       shapeType = geomSelectionTools->entryToShapeType(entry);
607       if (shapeType == TopAbs_SHAPE)
608         {
609           // E.A. if shapeType == TopAbs_SHAPE, it is NOT a TopoDS_Shape !!!
610           continue;
611         }
612       // --
613       if(shapeType != typeShapeAsked)
614         {
615           continue;
616         }
617       // --
618       myLocalSizeTable->setFocus();
619       QString shapeEntry;
620       shapeEntry = QString::fromStdString(entry);
621       if (myLocalSizeMap.contains(shapeEntry))
622         {
623           if (myLocalSizeMap[shapeEntry] != "__TO_DELETE__")
624             {
625               continue;
626             }
627         }
628       double phySize = h->GetMaxSize();
629       std::ostringstream oss;
630       oss << phySize;
631       QString localSize;
632       localSize  = QString::fromStdString(oss.str());
633       // --
634       int row = myLocalSizeTable->rowCount() ;
635       myLocalSizeTable->setRowCount(row+1);
636       myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(shapeEntry));
637       myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN )->setFlags(0);
638       myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
639       myLocalSizeTable->item(row, LSZ_NAME_COLUMN )->setFlags(0);
640       myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
641       myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
642       myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
643       myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
644       myLocalSizeTable->clearSelection();
645       myLocalSizeTable->scrollToItem( myLocalSizeTable->item( row, LSZ_LOCALSIZE_COLUMN ) );
646       // --
647     }
648 }
649
650 void NETGENPluginGUI_HypothesisCreator::onRemoveLocalSizeOnShape()
651 {
652   QList<int> selectedRows;
653   QList<QTableWidgetItem*> selected = myLocalSizeTable->selectedItems();
654   QTableWidgetItem* item;
655   int row;
656   foreach(item, selected) {
657     row = item->row();
658     if (!selectedRows.contains(row))
659       selectedRows.append( row );
660   }
661   qSort( selectedRows );
662   QListIterator<int> it( selectedRows );
663   it.toBack();
664   while (it.hasPrevious())
665     {
666       row = it.previous();
667       QString entry = myLocalSizeTable->item(row,LSZ_ENTRY_COLUMN)->text();
668       if (myLocalSizeMap.contains(entry))
669         {
670           myLocalSizeMap[entry] = "__TO_DELETE__";
671         }
672       myLocalSizeTable->removeRow(row );
673     }
674   myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
675   myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
676 }
677
678 void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col)
679 {
680   if (col == LSZ_LOCALSIZE_COLUMN) {
681     QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
682     QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
683     myLocalSizeMap[entry] = localSize;
684     myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
685   }
686 }
687
688 GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools()
689 {
690   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
691   if (myGeomSelectionTools == NULL || myGeomSelectionTools->getMyStudy() != aStudy) {
692     delete myGeomSelectionTools;
693     myGeomSelectionTools = new GeomSelectionTools(aStudy);
694   }
695   return myGeomSelectionTools;
696 }
697
698 QString NETGENPluginGUI_HypothesisCreator::caption() const
699 {
700   return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
701 }
702
703 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
704 {
705   QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
706   return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
707 }
708
709 QString NETGENPluginGUI_HypothesisCreator::type() const
710 {
711   return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
712 }
713
714 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
715 {
716   return "netgen_2d_3d_hypo_page.html";
717 }