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