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