Salome HOME
76d15bc7e7a16670d10fa6c7ec7f5a2b9d3a7cfd
[plugins/hexoticplugin.git] / src / GUI / HexoticPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #ifdef WIN32
198   myStdWidget->label_6->hide();
199   myStdWidget->myHexoticNbProc->hide();
200 #endif
201   l->addWidget( myStdWidget, row++, 0, 1, 3 );
202   myStdWidget->onSdModeSelected(SD_MODE_4);
203
204   
205   // SIZE MAPS TAB
206   QWidget* aSmpGroup = new QWidget();
207   lay->addWidget( aSmpGroup );
208   
209   // Size map widget creation and initialisation
210   mySmpWidget = new HexoticPluginGUI_SizeMapsWidget(aSmpGroup);
211   mySmpWidget->doubleSpinBox->RangeStepAndValidator(0.0, COORD_MAX, 1.0, "length_precision");
212   mySmpWidget->doubleSpinBox->setValue(0.0);
213   
214   // Filters of selection
215   TColStd_MapOfInteger SM_ShapeTypes; 
216   SM_ShapeTypes.Add( TopAbs_VERTEX );
217   SM_ShapeTypes.Add( TopAbs_EDGE );
218   SM_ShapeTypes.Add( TopAbs_WIRE );
219   SM_ShapeTypes.Add( TopAbs_FACE );
220   SM_ShapeTypes.Add( TopAbs_SOLID );
221   SM_ShapeTypes.Add( TopAbs_COMPOUND );  
222   SMESH_NumberFilter* aFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
223   
224   // Selection widget
225   myGeomSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( aFilter, mySmpWidget, /*multiSel=*/false,/*stretch=*/false);
226   myGeomSelWdg->SetDefaultText(tr("Hexotic_SEL_SHAPE"), "QLineEdit { color: grey }");
227   mySmpWidget->gridLayout->addWidget(myGeomSelWdg, 0, 1);
228   
229   // Configuration of the table widget
230   QStringList headerLabels;
231   headerLabels << tr("Hexotic_ENTRY")<< tr("Hexotic_NAME")<< tr("Hexotic_SIZE");
232   mySmpWidget->tableWidget->setHorizontalHeaderLabels(headerLabels);
233   mySmpWidget->tableWidget->resizeColumnsToContents();
234   mySmpWidget->tableWidget->hideColumn( 0 );
235   mySmpWidget->label->setText(tr("LOCAL_SIZE"));
236   mySmpWidget->pushButton_1->setText(tr("Hexotic_ADD"));
237   mySmpWidget->pushButton_2->setText(tr("Hexotic_REMOVE"));
238   
239   // Setting a custom delegate for the size column
240   SizeMapsTableWidgetDelegate* delegate = new SizeMapsTableWidgetDelegate();
241   mySmpWidget->tableWidget->setItemDelegateForColumn(SIZE_COL, delegate);
242   
243   // Add the size maps widget to a layout
244   QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup );
245   aSmpLayout->setMargin( 0 );
246   aSmpLayout->addWidget( mySmpWidget);
247   
248  
249 //  resizeEvent();
250   
251   aTabWidget->insertTab( STD_TAB, aStdGroup, tr( "SMESH_ARGUMENTS" ) );
252   aTabWidget->insertTab( SMP_TAB, aSmpGroup, tr( "LOCAL_SIZE" ) );
253   
254   myIs3D = true;
255   
256   // Size Maps
257   mySizeMapsToRemove.clear();
258   connect( mySmpWidget->pushButton_1,  SIGNAL( clicked() ),                              this,  SLOT( onAddLocalSize() ) );
259   connect( mySmpWidget->pushButton_2,  SIGNAL( clicked() ),                              this,  SLOT( onRemoveLocalSize() ) );
260   
261   return fr;
262 }
263
264 void HexoticPluginGUI_HypothesisCreator::onAddLocalSize()
265 {
266   int rowCount = mySmpWidget->tableWidget->rowCount();
267   int columnCount = mySmpWidget->tableWidget->columnCount();
268   
269   // Get the selected object properties
270   GEOM::GEOM_Object_var sizeMapObject = myGeomSelWdg->GetObject< GEOM::GEOM_Object >(0);
271   if (sizeMapObject->_is_nil())
272     return;
273   
274   std::string entry, shapeName;
275   entry = (std::string) sizeMapObject->GetStudyEntry();
276   shapeName = sizeMapObject->GetName();
277   
278   // Check if the object is already in the widget
279   QList<QTableWidgetItem *> listFound = mySmpWidget->tableWidget
280                                         ->findItems( QString(entry.c_str()), Qt::MatchExactly );
281   if ( !listFound.isEmpty() )
282     return;
283   
284   // Get the size value
285   double size = mySmpWidget->doubleSpinBox->value();
286   if (size == 0)
287   {
288     SUIT_MessageBox::critical( mySmpWidget, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) );
289     return;
290   }
291   
292   // Set items for the inserted row
293   insertLocalSizeInWidget( entry, shapeName, size, rowCount );
294 }
295
296 void HexoticPluginGUI_HypothesisCreator::insertLocalSizeInWidget( std::string entry, 
297                                                                   std::string shapeName, 
298                                                                   double size, 
299                                                                   int row ) const
300 {
301   MESSAGE("HexoticPluginGUI_HypothesisCreator:insertLocalSizeInWidget")
302   int columnCount = mySmpWidget->tableWidget->columnCount();
303   
304   // Add a row at the end of the table
305   mySmpWidget->tableWidget->insertRow(row);
306   
307   QVariant value;
308   for (int col = 0; col<columnCount; col++)
309   {
310     QTableWidgetItem* item = new QTableWidgetItem();
311     switch ( col )
312     {
313       case ENTRY_COL:
314         item->setFlags( 0 );
315         value = QVariant( entry.c_str() );
316         item->setData(Qt::DisplayRole, value );
317         break;  
318       case NAME_COL:
319         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
320         value = QVariant( shapeName.c_str() );
321         item->setData(Qt::DisplayRole, value );
322         break;
323       case SIZE_COL:
324         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
325         value = QVariant( size );
326         item->setData(Qt::EditRole, value );
327         break;
328     }       
329     mySmpWidget->tableWidget->setItem(row,col,item);
330   }
331 }
332
333 void HexoticPluginGUI_HypothesisCreator::onRemoveLocalSize()
334 {
335   // Remove the selected rows in the table
336   QList<QTableWidgetSelectionRange> ranges = mySmpWidget->tableWidget->selectedRanges();
337   if ( ranges.isEmpty() ) // If none is selected remove the last one
338   {
339     int lastRow = mySmpWidget->tableWidget->rowCount() - 1;
340     std::string entry = mySmpWidget->tableWidget->item( lastRow, ENTRY_COL )->text().toStdString();
341     mySizeMapsToRemove.push_back(entry);
342     mySmpWidget->tableWidget->removeRow( lastRow ); 
343   }
344   else
345   {
346     QList<QTableWidgetSelectionRange>::iterator it;
347     for ( it = ranges.begin(); it != ranges.end(); ++it )
348     {
349       for ( int row = it->topRow(); row <= it->bottomRow(); row++ )
350       {
351         std::string entry = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
352         mySizeMapsToRemove.push_back(entry);
353         MESSAGE("ADDING entry : "<<entry<<"to the Size Maps to remove")
354       }
355       mySmpWidget->tableWidget->model()->removeRows(it->topRow(), it->rowCount());
356     }
357   }
358 }
359
360 //=================================================================================
361 // function : resizeEvent [REDEFINED]
362 // purpose  :
363 //=================================================================================
364 void HexoticPluginGUI_HypothesisCreator::resizeEvent(QResizeEvent */*event*/) {
365     QSize scaledSize = myStdWidget->imageSdMode.size();
366     scaledSize.scale(myStdWidget->sdModeLabel->size(), Qt::KeepAspectRatioByExpanding);
367     if (!myStdWidget->sdModeLabel->pixmap() || scaledSize != myStdWidget->sdModeLabel->pixmap()->size())
368       myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(),
369       Qt::KeepAspectRatio,
370       Qt::SmoothTransformation));
371 }
372
373 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
374 {
375   HexoticHypothesisData data;
376   readParamsFromHypo( data );
377   printData(data);
378
379   if( myName )
380     myName->setText( data.myName );
381
382   myStdWidget->myMinSize->setCleared(data.myMinSize == 0);
383   if (data.myMinSize == 0)
384     myStdWidget->myMinSize->setText("");
385   else
386     myStdWidget->myMinSize->setValue( data.myMinSize );
387
388   myStdWidget->myMaxSize->setCleared(data.myMaxSize == 0);
389   if (data.myMaxSize == 0)
390     myStdWidget->myMaxSize->setText("");
391   else
392     myStdWidget->myMaxSize->setValue( data.myMaxSize );
393
394   myStdWidget->myHexesMinLevel->setCleared(data.myHexesMinLevel == 0);
395   if (data.myHexesMinLevel == 0)
396     myStdWidget->myHexesMinLevel->setText("");
397   else
398     myStdWidget->myHexesMinLevel->setValue( data.myHexesMinLevel );
399
400   myStdWidget->myHexesMaxLevel->setCleared(data.myHexesMaxLevel == 0);
401   if (data.myHexesMaxLevel == 0)
402     myStdWidget->myHexesMaxLevel->setText("");
403   else
404     myStdWidget->myHexesMaxLevel->setValue( data.myHexesMaxLevel );
405
406   myStdWidget->myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
407   myStdWidget->myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
408   
409   myStdWidget->myHexoticSharpAngleThreshold->setCleared(data.myHexoticSharpAngleThreshold == 0);
410   if (data.myHexoticSharpAngleThreshold == 0)
411     myStdWidget->myHexoticSharpAngleThreshold->setText("");
412   else
413     myStdWidget->myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
414 #ifndef WIN32
415   myStdWidget->myHexoticNbProc->setValue( data.myHexoticNbProc );
416 #endif
417   myStdWidget->myHexoticWorkingDir->setText( data.myHexoticWorkingDir );
418
419   myStdWidget->myHexoticVerbosity->setValue( data.myHexoticVerbosity );
420
421   myStdWidget->myHexoticMaxMemory->setValue( data.myHexoticMaxMemory );
422
423   myStdWidget->myHexoticSdMode->setCurrentIndex(data.myHexoticSdMode);
424   
425   HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = data.mySizeMaps.begin();
426   for ( int row = 0; it != data.mySizeMaps.end(); it++, row++ )
427   {
428     std::string entry = it->first;
429     double size = it->second;
430     GEOM::GEOM_Object_var anObject = entryToObject( entry );
431     std::string shapeName = anObject->GetName();
432
433     MESSAGE(" Insert local size, entry : "<<entry<<", size : "<<size<<", at row : "<<row) 
434     insertLocalSizeInWidget( entry, shapeName, size , row );
435   }
436
437   std::cout << "myStdWidget->myMinSize->value(): " << myStdWidget->myMinSize->value() << std::endl;
438   std::cout << "myStdWidget->myMaxSize->value(): " << myStdWidget->myMaxSize->value() << std::endl;
439   std::cout << "myStdWidget->myHexesMinLevel->value(): " << myStdWidget->myHexesMinLevel->value() << std::endl;
440   std::cout << "myStdWidget->myHexesMaxLevel->value(): " << myStdWidget->myHexesMaxLevel->value() << std::endl;
441   std::cout << "myStdWidget->myHexoticSharpAngleThreshold->value(): " << myStdWidget->myHexoticSharpAngleThreshold->value() << std::endl;
442
443 }
444
445 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
446 {
447   QString valStr;
448   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
449   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
450   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
451   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
452   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
453   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
454   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
455   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
456   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
457   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity ) + "; ";
458   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
459   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode ) + "; ";
460
461   std::cout << "Data: " << valStr.toStdString() << std::endl;
462 }
463
464 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
465 {
466   HexoticHypothesisData data;
467   readParamsFromWidgets( data );
468   storeParamsToHypo( data );
469
470   QString valStr;
471   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
472   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
473   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
474   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
475   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
476   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
477   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
478   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
479   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
480   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity) + "; ";
481   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
482   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode) + "; ";
483
484 //  std::cout << "Data: " << valStr.toStdString() << std::endl;
485
486   return valStr;
487 }
488
489 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
490 {
491   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
492     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
493
494   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
495   h_data.myName = isCreation() && data ? data->Label : "";
496   h_data.myMinSize = h->GetMinSize();
497   h_data.myMaxSize = h->GetMaxSize();
498   h_data.myHexesMinLevel = h->GetHexesMinLevel();
499   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
500   h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
501   h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
502   h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
503   h_data.myHexoticNbProc = h->GetHexoticNbProc();
504   h_data.myHexoticWorkingDir = h->GetHexoticWorkingDirectory();
505   h_data.myHexoticVerbosity = h->GetHexoticVerbosity();
506   h_data.myHexoticMaxMemory = h->GetHexoticMaxMemory();
507   h_data.myHexoticSdMode = h->GetHexoticSdMode()-1;
508   
509   // Size maps
510   HexoticPlugin::HexoticPluginSizeMapsList_var sizeMaps = h->GetSizeMaps();
511   for ( int i = 0 ; i < sizeMaps->length() ; i++) 
512   {
513     HexoticPlugin::HexoticPluginSizeMap aSizeMap = sizeMaps[i];
514     std::string entry = CORBA::string_dup(aSizeMap.entry.in());
515     double size = aSizeMap.size;
516     h_data.mySizeMaps[ entry ] = size;
517     MESSAGE("READING Size map : entry "<<entry<<" size : "<<size)
518   }
519   
520   return true;
521 }
522
523 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
524 {
525   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
526     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
527
528   bool ok = true;
529
530   try
531   {
532     if( isCreation() )
533       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
534
535     h->SetMinSize( h_data.myMinSize );
536     h->SetMaxSize( h_data.myMaxSize );
537     h->SetHexesMinLevel( h_data.myHexesMinLevel );
538     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
539     h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
540     h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
541     h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
542     h->SetHexoticNbProc( h_data.myHexoticNbProc );
543     h->SetHexoticWorkingDirectory( h_data.myHexoticWorkingDir.toLatin1().constData() );
544     h->SetHexoticVerbosity( h_data.myHexoticVerbosity );
545     h->SetHexoticMaxMemory( h_data.myHexoticMaxMemory );
546     h->SetHexoticSdMode( h_data.myHexoticSdMode+1 );
547     
548     HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it;
549     
550     for ( it =  h_data.mySizeMaps.begin(); it !=  h_data.mySizeMaps.end(); it++ )
551     {
552       h->SetSizeMapEntry( it->first.c_str(), it->second );
553       MESSAGE("STORING Size map : entry "<<it->first.c_str()<<" size : "<<it->second)
554     }
555     std::vector< std::string >::const_iterator entry_it;
556     for ( entry_it = mySizeMapsToRemove.begin(); entry_it!= mySizeMapsToRemove.end(); entry_it++ )
557     {
558       h->UnsetSizeMapEntry(entry_it->c_str());
559     }
560   }
561   catch(const SALOME::SALOME_Exception& ex)
562   {
563     SalomeApp_Tools::QtCatchCorbaException(ex);
564     ok = false;
565   }
566   return ok;
567 }
568
569 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
570 {
571   h_data.myName    = myName ? myName->text() : "";
572
573   h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
574   h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
575 #ifndef WIN32
576   h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
577 #endif
578   h_data.myHexoticWorkingDir = myStdWidget->myHexoticWorkingDir->text();
579   h_data.myHexoticVerbosity = myStdWidget->myHexoticVerbosity->value();
580   h_data.myHexoticMaxMemory = myStdWidget->myHexoticMaxMemory->value();
581   h_data.myHexoticSdMode = myStdWidget->myHexoticSdMode->currentIndex();
582
583   h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? 0.0 : myStdWidget->myMinSize->value();
584   h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? 0.0 : myStdWidget->myMaxSize->value();
585   h_data.myHexesMinLevel = myStdWidget->myHexesMinLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMinLevel->value();
586   h_data.myHexesMaxLevel = myStdWidget->myHexesMaxLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMaxLevel->value();
587   h_data.myHexoticSharpAngleThreshold = myStdWidget->myHexoticSharpAngleThreshold->text().isEmpty() ? 0 : myStdWidget->myHexoticSharpAngleThreshold->value();
588
589   // Size maps reading
590   bool ok = readSizeMapsFromWidgets( h_data );
591   if ( !ok )
592     return false;
593   
594   printData(h_data);
595
596   return true;
597 }
598
599 bool HexoticPluginGUI_HypothesisCreator::readSizeMapsFromWidgets( HexoticHypothesisData& h_data ) const
600 {
601   int rowCount = mySmpWidget->tableWidget->rowCount();
602   for ( int row = 0; row <  rowCount; row++ )
603   {
604     std::string entry     = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
605     QVariant size_variant = mySmpWidget->tableWidget->item( row, SIZE_COL )->data(Qt::DisplayRole);
606     
607     // Convert the size to double
608     bool ok = false;
609     double size = size_variant.toDouble(&ok);
610     if (!ok)
611       return false;
612     
613     // Set the size maps
614     h_data.mySizeMaps[ entry ] = size;
615     MESSAGE("READING Size map from WIDGET: entry "<<entry<<" size : "<<size)
616   }
617   return true;
618 }
619
620 GEOM::GEOM_Object_var HexoticPluginGUI_HypothesisCreator::entryToObject( std::string entry) const
621 {
622   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
623   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
624   GEOM::GEOM_Object_var aGeomObj;
625   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
626   if (!aSObj->_is_nil()) {
627     CORBA::Object_var obj = aSObj->GetObject();
628     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
629     aSObj->UnRegister();
630   }
631   return aGeomObj;
632 }
633
634 QString HexoticPluginGUI_HypothesisCreator::caption() const
635 {
636   return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
637 }
638
639 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
640 {
641   QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
642   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
643 }
644
645 QString HexoticPluginGUI_HypothesisCreator::type() const
646 {
647   return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
648 }
649
650 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
651 {
652   return "hexotic_hypo_page.html";
653 }