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