Salome HOME
BUG: HexoticPlugin: checkParams returned false when no size map was selected in the...
[plugins/hexoticplugin.git] / src / GUI / HexoticPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : HexoticPluginGUI_HypothesisCreator.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
23 // ---
24 //
25 #include "HexoticPluginGUI_HypothesisCreator.h"
26 #include "HexoticPluginGUI_Dlg.h"
27
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include "SMESH_NumberFilter.hxx"
31
32 #include "utilities.h"
33
34 #include CORBA_SERVER_HEADER(HexoticPlugin_Algorithm)
35
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_FileDlg.h>
40 #include <SalomeApp_Tools.h>
41 #include <QtxIntSpinBox.h>
42
43 #include <QFrame>
44 #include <QGroupBox>
45 #include <QVBoxLayout>
46 #include <QGridLayout>
47 #include <QLineEdit>
48 #include <QLabel>
49 #include <QCheckBox>
50 #include <QPushButton>
51
52 #include "SMESH_Gen_i.hxx"
53
54 // OCC includes
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TopAbs.hxx>
57
58 // Main widget tabs identification
59 enum {
60   STD_TAB = 0,
61   SMP_TAB
62 };
63
64 // Size maps tab, table columns order
65 enum {
66   ENTRY_COL = 0,
67   NAME_COL,
68   SIZE_COL
69 };
70
71 //
72 // Size map table widget delegate
73 //
74
75 SizeMapsTableWidgetDelegate::SizeMapsTableWidgetDelegate(QObject *parent)
76      : QItemDelegate(parent)
77 {
78 }
79
80 QWidget* SizeMapsTableWidgetDelegate::createEditor(QWidget *parent,
81                                                    const QStyleOptionViewItem &/* option */,
82                                                    const QModelIndex &/* index */) const
83 {
84   SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
85   editor->RangeStepAndValidator(0.0, COORD_MAX, 10.0, "length_precision");
86   return editor;
87 }
88
89 void SizeMapsTableWidgetDelegate::setEditorData(QWidget *editor,
90                                                 const QModelIndex &index) const
91 {
92   double value = index.model()->data(index, Qt::EditRole).toDouble();
93   SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
94   spinBox->setValue(value);
95 }
96
97 void SizeMapsTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
98                                                const QModelIndex &index) const
99 {
100   SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
101   spinBox->interpretText();
102   double value = spinBox->value();
103   if ( value == 0 ) 
104     SUIT_MessageBox::critical( spinBox, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) ); 
105   else
106     model->setData(index, value, Qt::EditRole);
107 }
108
109 void SizeMapsTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
110                                                        const QStyleOptionViewItem &option, 
111                                                        const QModelIndex &/* index */) const
112 {
113   editor->setGeometry(option.rect);
114 }
115
116 // END Delegate
117
118
119
120 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
121 : SMESHGUI_GenericHypothesisCreator( theHypType ),
122   myIs3D( true ),
123   mySizeMapsToRemove()
124 {
125 }
126
127 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
128 {
129 }
130
131 bool HexoticPluginGUI_HypothesisCreator::checkParams(QString& msg) const
132 {
133   msg.clear();
134
135   HexoticHypothesisData data_old, data_new;
136   readParamsFromHypo( data_old );
137   
138   bool res = readParamsFromWidgets( data_new );
139   if ( !res ){
140     return res;
141   }
142
143   res = storeParamsToHypo( data_new );
144   if ( !res ) {
145     storeParamsToHypo( data_old );
146     return res;
147   }
148
149   res = data_new.myMinSize <= data_new.myMaxSize;
150   if ( !res ) {
151     msg = tr(QString("Min size (%1) is higher than max size (%2)").arg(data_new.myMinSize).arg(data_new.myMaxSize).toStdString().c_str());
152     return res;
153   }
154
155   res = data_new.myHexesMinLevel == 0  || \
156       ( data_new.myHexesMinLevel != 0  && (data_new.myHexesMinLevel < data_new.myHexesMaxLevel) );
157   if ( !res ) {
158     msg = tr(QString("Min hexes level (%1) is higher than max hexes level (%2)").arg(data_new.myHexesMinLevel).arg(data_new.myHexesMaxLevel).toStdString().c_str());
159     return res;
160   }
161
162   return true;
163 }
164
165 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
166 {
167   QFrame* fr = new QFrame( 0 );
168   QVBoxLayout* lay = new QVBoxLayout( fr );
169   lay->setMargin( 0 );
170   lay->setSpacing( 6 );
171   
172   // main TabWidget of the dialog
173   QTabWidget* aTabWidget = new QTabWidget( fr );
174   aTabWidget->setTabShape( QTabWidget::Rounded );
175   aTabWidget->setTabPosition( QTabWidget::North );
176   lay->addWidget( aTabWidget );
177
178   // Standard arguments tab
179   QWidget* aStdGroup = new QWidget();
180   QGridLayout* l = new QGridLayout( aStdGroup );
181   l->setSpacing( 6 );
182   l->setMargin( 11 );
183  
184   int row = 0;
185   myName = 0;
186   if( isCreation() ) {
187     l->addWidget( new QLabel( tr( "SMESH_NAME" ), aStdGroup ), row, 0, 1, 1 );
188     myName = new QLineEdit( aStdGroup );
189     l->addWidget( myName, row++, 1, 1, 2 );
190     myName->setMinimumWidth( 150 );
191   }
192
193   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
194   HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
195   
196   myStdWidget = new HexoticPluginGUI_StdWidget(aStdGroup);
197   l->addWidget( myStdWidget, row++, 0, 1, 3 );
198   myStdWidget->onSdModeSelected(SD_MODE_4);
199
200   
201   // SIZE MAPS TAB
202   QWidget* aSmpGroup = new QWidget();
203   lay->addWidget( aSmpGroup );
204   
205   // Size map widget creation and initialisation
206   mySmpWidget = new HexoticPluginGUI_SizeMapsWidget(aSmpGroup);
207   mySmpWidget->doubleSpinBox->RangeStepAndValidator(0.0, COORD_MAX, 1.0, "length_precision");
208   mySmpWidget->doubleSpinBox->setValue(0.0);
209   
210   // Filters of selection
211   TColStd_MapOfInteger SM_ShapeTypes; 
212   SM_ShapeTypes.Add( TopAbs_VERTEX );
213   SM_ShapeTypes.Add( TopAbs_EDGE );
214   SM_ShapeTypes.Add( TopAbs_WIRE );
215   SM_ShapeTypes.Add( TopAbs_FACE );
216   SM_ShapeTypes.Add( TopAbs_SOLID );
217   SM_ShapeTypes.Add( TopAbs_COMPOUND );  
218   SMESH_NumberFilter* aFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
219   
220   // Selection widget
221   myGeomSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( aFilter, mySmpWidget, /*multiSel=*/false,/*stretch=*/false);
222   myGeomSelWdg->SetDefaultText(tr("Hexotic_SEL_SHAPE"), "QLineEdit { color: grey }");
223   mySmpWidget->gridLayout->addWidget(myGeomSelWdg, 0, 1);
224   
225   // Configuration of the table widget
226   QStringList headerLabels;
227   headerLabels << tr("Hexotic_ENTRY")<< tr("Hexotic_NAME")<< tr("Hexotic_SIZE");
228   mySmpWidget->tableWidget->setHorizontalHeaderLabels(headerLabels);
229   mySmpWidget->tableWidget->resizeColumnsToContents();
230   mySmpWidget->tableWidget->hideColumn( 0 );
231   mySmpWidget->label->setText(tr("LOCAL_SIZE"));
232   mySmpWidget->pushButton_1->setText(tr("Hexotic_ADD"));
233   mySmpWidget->pushButton_2->setText(tr("Hexotic_REMOVE"));
234   
235   // Setting a custom delegate for the size column
236   SizeMapsTableWidgetDelegate* delegate = new SizeMapsTableWidgetDelegate();
237   mySmpWidget->tableWidget->setItemDelegateForColumn(SIZE_COL, delegate);
238   
239   // Add the size maps widget to a layout
240   QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup );
241   aSmpLayout->setMargin( 0 );
242   aSmpLayout->addWidget( mySmpWidget);
243   
244  
245 //  resizeEvent();
246   
247   aTabWidget->insertTab( STD_TAB, aStdGroup, tr( "SMESH_ARGUMENTS" ) );
248   aTabWidget->insertTab( SMP_TAB, aSmpGroup, tr( "LOCAL_SIZE" ) );
249   
250   myIs3D = true;
251   
252   // Size Maps
253   mySizeMapsToRemove.clear();
254   connect( mySmpWidget->pushButton_1,  SIGNAL( clicked() ),                              this,  SLOT( onAddLocalSize() ) );
255   connect( mySmpWidget->pushButton_2,  SIGNAL( clicked() ),                              this,  SLOT( onRemoveLocalSize() ) );
256   
257   return fr;
258 }
259
260 void HexoticPluginGUI_HypothesisCreator::onAddLocalSize()
261 {
262   int rowCount = mySmpWidget->tableWidget->rowCount();
263   int columnCount = mySmpWidget->tableWidget->columnCount();
264   
265   // Get the selected object properties
266   GEOM::GEOM_Object_var sizeMapObject = myGeomSelWdg->GetObject< GEOM::GEOM_Object >(0);
267   if (sizeMapObject->_is_nil())
268     return;
269   
270   std::string entry, shapeName;
271   entry = (std::string) sizeMapObject->GetStudyEntry();
272   shapeName = sizeMapObject->GetName();
273   
274   // Check if the object is already in the widget
275   QList<QTableWidgetItem *> listFound = mySmpWidget->tableWidget
276                                         ->findItems( QString(entry.c_str()), Qt::MatchExactly );
277   if ( !listFound.isEmpty() )
278     return;
279   
280   // Get the size value
281   double size = mySmpWidget->doubleSpinBox->value();
282   if (size == 0)
283   {
284     SUIT_MessageBox::critical( mySmpWidget, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) );
285     return;
286   }
287   
288   // Set items for the inserted row
289   insertLocalSizeInWidget( entry, shapeName, size, rowCount );
290 }
291
292 void HexoticPluginGUI_HypothesisCreator::insertLocalSizeInWidget( std::string entry, 
293                                                                   std::string shapeName, 
294                                                                   double size, 
295                                                                   int row ) const
296 {
297   MESSAGE("HexoticPluginGUI_HypothesisCreator:insertLocalSizeInWidget")
298   int columnCount = mySmpWidget->tableWidget->columnCount();
299   
300   // Add a row at the end of the table
301   mySmpWidget->tableWidget->insertRow(row);
302   
303   QVariant value;
304   for (int col = 0; col<columnCount; col++)
305   {
306     QTableWidgetItem* item = new QTableWidgetItem();
307     switch ( col )
308     {
309       case ENTRY_COL:
310         item->setFlags( 0 );
311         value = QVariant( entry.c_str() );
312         item->setData(Qt::DisplayRole, value );
313         break;  
314       case NAME_COL:
315         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
316         value = QVariant( shapeName.c_str() );
317         item->setData(Qt::DisplayRole, value );
318         break;
319       case SIZE_COL:
320         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
321         value = QVariant( size );
322         item->setData(Qt::EditRole, value );
323         break;
324     }       
325     mySmpWidget->tableWidget->setItem(row,col,item);
326   }
327 }
328
329 void HexoticPluginGUI_HypothesisCreator::onRemoveLocalSize()
330 {
331   // Remove the selected rows in the table
332   QList<QTableWidgetSelectionRange> ranges = mySmpWidget->tableWidget->selectedRanges();
333   if ( ranges.isEmpty() ) // If none is selected remove the last one
334   {
335     int lastRow = mySmpWidget->tableWidget->rowCount() - 1;
336     std::string entry = mySmpWidget->tableWidget->item( lastRow, ENTRY_COL )->text().toStdString();
337     mySizeMapsToRemove.push_back(entry);
338     mySmpWidget->tableWidget->removeRow( lastRow ); 
339   }
340   else
341   {
342     QTableWidgetSelectionRange& range = ranges.first();
343     for ( int row = range.topRow(); row < range.rowCount(); row++ )
344     {
345       std::string entry = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
346       mySizeMapsToRemove.push_back(entry);
347     }
348     mySmpWidget->tableWidget->model()->removeRows(range.topRow(), range.rowCount());
349   }
350 }
351
352 //=================================================================================
353 // function : resizeEvent [REDEFINED]
354 // purpose  :
355 //=================================================================================
356 void HexoticPluginGUI_HypothesisCreator::resizeEvent(QResizeEvent */*event*/) {
357     QSize scaledSize = myStdWidget->imageSdMode.size();
358     scaledSize.scale(myStdWidget->sdModeLabel->size(), Qt::KeepAspectRatioByExpanding);
359     if (!myStdWidget->sdModeLabel->pixmap() || scaledSize != myStdWidget->sdModeLabel->pixmap()->size())
360       myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(),
361       Qt::KeepAspectRatio,
362       Qt::SmoothTransformation));
363 }
364
365 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
366 {
367   HexoticHypothesisData data;
368   readParamsFromHypo( data );
369   printData(data);
370
371   if( myName )
372     myName->setText( data.myName );
373
374   myStdWidget->myMinSize->setCleared(data.myMinSize == 0);
375   if (data.myMinSize == 0)
376     myStdWidget->myMinSize->setText("");
377   else
378     myStdWidget->myMinSize->setValue( data.myMinSize );
379
380   myStdWidget->myMaxSize->setCleared(data.myMaxSize == 0);
381   if (data.myMaxSize == 0)
382     myStdWidget->myMaxSize->setText("");
383   else
384     myStdWidget->myMaxSize->setValue( data.myMaxSize );
385
386   myStdWidget->myHexesMinLevel->setCleared(data.myHexesMinLevel == 0);
387   if (data.myHexesMinLevel == 0)
388     myStdWidget->myHexesMinLevel->setText("");
389   else
390     myStdWidget->myHexesMinLevel->setValue( data.myHexesMinLevel );
391
392   myStdWidget->myHexesMaxLevel->setCleared(data.myHexesMaxLevel == 0);
393   if (data.myHexesMaxLevel == 0)
394     myStdWidget->myHexesMaxLevel->setText("");
395   else
396     myStdWidget->myHexesMaxLevel->setValue( data.myHexesMaxLevel );
397
398   myStdWidget->myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
399   myStdWidget->myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
400   
401   myStdWidget->myHexoticSharpAngleThreshold->setCleared(data.myHexoticSharpAngleThreshold == 0);
402   if (data.myHexoticSharpAngleThreshold == 0)
403     myStdWidget->myHexoticSharpAngleThreshold->setText("");
404   else
405     myStdWidget->myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
406
407   myStdWidget->myHexoticNbProc->setValue( data.myHexoticNbProc );
408   myStdWidget->myHexoticWorkingDir->setText( data.myHexoticWorkingDir );
409
410   myStdWidget->myHexoticVerbosity->setValue( data.myHexoticVerbosity );
411
412   myStdWidget->myHexoticMaxMemory->setValue( data.myHexoticMaxMemory );
413
414   myStdWidget->myHexoticSdMode->setCurrentIndex(data.myHexoticSdMode);
415   
416   HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = data.mySizeMaps.begin();
417   for ( int row = 0; it != data.mySizeMaps.end(); it++, row++ )
418   {
419     std::string entry = it->first;
420     double size = it->second;
421     GEOM::GEOM_Object_var anObject = entryToObject( entry );
422     std::string shapeName = anObject->GetName();
423
424     MESSAGE(" Insert local size, entry : "<<entry<<", size : "<<size<<", at row : "<<row) 
425     insertLocalSizeInWidget( entry, shapeName, size , row );
426   }
427
428   std::cout << "myStdWidget->myMinSize->value(): " << myStdWidget->myMinSize->value() << std::endl;
429   std::cout << "myStdWidget->myMaxSize->value(): " << myStdWidget->myMaxSize->value() << std::endl;
430   std::cout << "myStdWidget->myHexesMinLevel->value(): " << myStdWidget->myHexesMinLevel->value() << std::endl;
431   std::cout << "myStdWidget->myHexesMaxLevel->value(): " << myStdWidget->myHexesMaxLevel->value() << std::endl;
432   std::cout << "myStdWidget->myHexoticSharpAngleThreshold->value(): " << myStdWidget->myHexoticSharpAngleThreshold->value() << std::endl;
433
434 }
435
436 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
437 {
438   QString valStr;
439   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
440   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
441   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
442   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
443   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
444   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
445   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
446   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
447   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
448   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity ) + "; ";
449   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
450   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode ) + "; ";
451
452   std::cout << "Data: " << valStr.toStdString() << std::endl;
453 }
454
455 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
456 {
457   HexoticHypothesisData data;
458   readParamsFromWidgets( data );
459   storeParamsToHypo( data );
460
461   QString valStr;
462   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
463   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
464   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
465   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
466   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
467   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
468   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
469   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
470   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
471   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity) + "; ";
472   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
473   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode) + "; ";
474
475 //  std::cout << "Data: " << valStr.toStdString() << std::endl;
476
477   return valStr;
478 }
479
480 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
481 {
482   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
483     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
484
485   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
486   h_data.myName = isCreation() && data ? data->Label : "";
487   h_data.myMinSize = h->GetMinSize();
488   h_data.myMaxSize = h->GetMaxSize();
489   h_data.myHexesMinLevel = h->GetHexesMinLevel();
490   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
491   h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
492   h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
493   h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
494   h_data.myHexoticNbProc = h->GetHexoticNbProc();
495   h_data.myHexoticWorkingDir = h->GetHexoticWorkingDirectory();
496   h_data.myHexoticVerbosity = h->GetHexoticVerbosity();
497   h_data.myHexoticMaxMemory = h->GetHexoticMaxMemory();
498   h_data.myHexoticSdMode = h->GetHexoticSdMode()-1;
499   
500   // Size maps
501   HexoticPlugin::HexoticPluginSizeMapsList_var sizeMaps = h->GetSizeMaps();
502   for ( int i = 0 ; i < sizeMaps->length() ; i++) 
503   {
504     HexoticPlugin::HexoticPluginSizeMap aSizeMap = sizeMaps[i];
505     std::string entry = CORBA::string_dup(aSizeMap.entry.in());
506     double size = aSizeMap.size;
507     h_data.mySizeMaps[ entry ] = size;
508     MESSAGE("READING Size map : entry "<<entry<<" size : "<<size)
509   }
510   
511   return true;
512 }
513
514 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
515 {
516   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
517     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
518
519   bool ok = true;
520
521   try
522   {
523     if( isCreation() )
524       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
525
526     h->SetMinSize( h_data.myMinSize );
527     h->SetMaxSize( h_data.myMaxSize );
528     h->SetHexesMinLevel( h_data.myHexesMinLevel );
529     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
530     h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
531     h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
532     h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
533     h->SetHexoticNbProc( h_data.myHexoticNbProc );
534     h->SetHexoticWorkingDirectory( h_data.myHexoticWorkingDir.toLatin1().constData() );
535     h->SetHexoticVerbosity( h_data.myHexoticVerbosity );
536     h->SetHexoticMaxMemory( h_data.myHexoticMaxMemory );
537     h->SetHexoticSdMode( h_data.myHexoticSdMode+1 );
538     
539     HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it;
540     
541     for ( it =  h_data.mySizeMaps.begin(); it !=  h_data.mySizeMaps.end(); it++ )
542     {
543       h->SetSizeMapEntry( it->first.c_str(), it->second );
544       MESSAGE("STORING Size map : entry "<<it->first.c_str()<<" size : "<<it->second)
545     }
546     std::vector< std::string >::const_iterator entry_it;
547     for ( entry_it = mySizeMapsToRemove.begin(); entry_it!= mySizeMapsToRemove.end(); entry_it++ )
548     {
549       h->UnsetSizeMapEntry(entry_it->c_str());
550     }
551   }
552   catch(const SALOME::SALOME_Exception& ex)
553   {
554     SalomeApp_Tools::QtCatchCorbaException(ex);
555     ok = false;
556   }
557   return ok;
558 }
559
560 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
561 {
562   h_data.myName    = myName ? myName->text() : "";
563
564   h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
565   h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
566
567   h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
568   h_data.myHexoticWorkingDir = myStdWidget->myHexoticWorkingDir->text();
569   h_data.myHexoticVerbosity = myStdWidget->myHexoticVerbosity->value();
570   h_data.myHexoticMaxMemory = myStdWidget->myHexoticMaxMemory->value();
571   h_data.myHexoticSdMode = myStdWidget->myHexoticSdMode->currentIndex();
572
573   h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? 0.0 : myStdWidget->myMinSize->value();
574   h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? 0.0 : myStdWidget->myMaxSize->value();
575   h_data.myHexesMinLevel = myStdWidget->myHexesMinLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMinLevel->value();
576   h_data.myHexesMaxLevel = myStdWidget->myHexesMaxLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMaxLevel->value();
577   h_data.myHexoticSharpAngleThreshold = myStdWidget->myHexoticSharpAngleThreshold->text().isEmpty() ? 0 : myStdWidget->myHexoticSharpAngleThreshold->value();
578
579   // Size maps reading
580   bool ok = readSizeMapsFromWidgets( h_data );
581   if ( !ok )
582     return false;
583   
584   printData(h_data);
585
586   return true;
587 }
588
589 bool HexoticPluginGUI_HypothesisCreator::readSizeMapsFromWidgets( HexoticHypothesisData& h_data ) const
590 {
591   int rowCount = mySmpWidget->tableWidget->rowCount();
592   for ( int row = 0; row <  rowCount; row++ )
593   {
594     std::string entry     = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
595     QVariant size_variant = mySmpWidget->tableWidget->item( row, SIZE_COL )->data(Qt::DisplayRole);
596     
597     // Convert the size to double
598     bool ok = false;
599     double size = size_variant.toDouble(&ok);
600     if (!ok)
601       return false;
602     
603     // Set the size maps
604     h_data.mySizeMaps[ entry ] = size;
605     MESSAGE("READING Size map from WIDGET: entry "<<entry<<" size : "<<size)
606   }
607   return true;
608 }
609
610 GEOM::GEOM_Object_var HexoticPluginGUI_HypothesisCreator::entryToObject( std::string entry) const
611 {
612   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
613   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
614   GEOM::GEOM_Object_var aGeomObj;
615   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
616   if (!aSObj->_is_nil()) {
617     CORBA::Object_var obj = aSObj->GetObject();
618     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
619     aSObj->UnRegister();
620   }
621   return aGeomObj;
622 }
623
624 QString HexoticPluginGUI_HypothesisCreator::caption() const
625 {
626   return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
627 }
628
629 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
630 {
631   QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
632   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
633 }
634
635 QString HexoticPluginGUI_HypothesisCreator::type() const
636 {
637   return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
638 }
639
640 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
641 {
642   return "hexotic_hypo_page.html";
643 }