Salome HOME
remove "using namespace std" from SMESH headers
[plugins/hexoticplugin.git] / src / GUI / HexoticPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2015  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   VL_TAB
63 };
64
65 // Size maps tab, table columns order
66 enum {
67   ENTRY_COL = 0,
68   NAME_COL,
69   SIZE_COL
70 };
71
72 //
73 // Size map table widget delegate
74 //
75
76 SizeMapsTableWidgetDelegate::SizeMapsTableWidgetDelegate(QObject *parent)
77      : QItemDelegate(parent)
78 {
79 }
80
81 QWidget* SizeMapsTableWidgetDelegate::createEditor(QWidget *parent,
82                                                    const QStyleOptionViewItem &/* option */,
83                                                    const QModelIndex &/* index */) const
84 {
85   SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
86   editor->RangeStepAndValidator(0.0, COORD_MAX, 10.0, "length_precision");
87   return editor;
88 }
89
90 void SizeMapsTableWidgetDelegate::setEditorData(QWidget *editor,
91                                                 const QModelIndex &index) const
92 {
93   double value = index.model()->data(index, Qt::EditRole).toDouble();
94   SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
95   spinBox->setValue(value);
96 }
97
98 void SizeMapsTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
99                                                const QModelIndex &index) const
100 {
101   SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
102   spinBox->interpretText();
103   double value = spinBox->value();
104   if ( value == 0 ) 
105     SUIT_MessageBox::critical( spinBox, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) ); 
106   else
107     model->setData(index, value, Qt::EditRole);
108 }
109
110 void SizeMapsTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
111                                                        const QStyleOptionViewItem &option, 
112                                                        const QModelIndex &/* index */) const
113 {
114   editor->setGeometry(option.rect);
115 }
116
117 // END Delegate
118
119
120
121 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
122 : SMESHGUI_GenericHypothesisCreator( theHypType ),
123   myIs3D( true ),
124   mySizeMapsToRemove()
125 {
126 }
127
128 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
129 {
130 }
131
132 bool HexoticPluginGUI_HypothesisCreator::checkParams(QString& msg) const
133 {
134   msg.clear();
135
136   HexoticHypothesisData data_old, data_new;
137   readParamsFromHypo( data_old );
138   
139   bool res = readParamsFromWidgets( data_new );
140   if ( !res ){
141     return res;
142   }
143
144   res = storeParamsToHypo( data_new );
145   if ( !res ) {
146     storeParamsToHypo( data_old );
147     return res;
148   }
149
150   res = data_new.myMinSize <= data_new.myMaxSize;
151   if ( !res ) {
152     msg = tr(QString("Min size (%1) is higher than max size (%2)").arg(data_new.myMinSize).arg(data_new.myMaxSize).toStdString().c_str());
153     return res;
154   }
155
156   res = data_new.myHexesMinLevel == 0  || \
157       ( data_new.myHexesMinLevel != 0  && (data_new.myHexesMinLevel < data_new.myHexesMaxLevel) );
158   if ( !res ) {
159     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());
160     return res;
161   }
162
163   return true;
164 }
165
166 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
167 {
168   QFrame* fr = new QFrame( 0 );
169   QVBoxLayout* lay = new QVBoxLayout( fr );
170   lay->setMargin( 0 );
171   lay->setSpacing( 6 );
172   
173   // main TabWidget of the dialog
174   QTabWidget* aTabWidget = new QTabWidget( fr );
175   aTabWidget->setTabShape( QTabWidget::Rounded );
176   aTabWidget->setTabPosition( QTabWidget::North );
177   lay->addWidget( aTabWidget );
178
179   // Standard arguments tab
180   QWidget* aStdGroup = new QWidget();
181   QGridLayout* l = new QGridLayout( aStdGroup );
182   l->setSpacing( 6 );
183   l->setMargin( 11 );
184  
185   int row = 0;
186   myName = 0;
187   if( isCreation() ) {
188     l->addWidget( new QLabel( tr( "SMESH_NAME" ), aStdGroup ), row, 0, 1, 1 );
189     myName = new QLineEdit( aStdGroup );
190     l->addWidget( myName, row++, 1, 1, 2 );
191     myName->setMinimumWidth( 150 );
192   }
193
194   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
195   HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
196   
197   myStdWidget = new HexoticPluginGUI_StdWidget(aStdGroup);
198 #ifdef WIN32
199   myStdWidget->label_6->hide();
200   myStdWidget->myHexoticNbProc->hide();
201 #endif
202   l->addWidget( myStdWidget, row++, 0, 1, 3 );
203   myStdWidget->onSdModeSelected(SD_MODE_4);
204
205   
206   // SIZE MAPS TAB
207   QWidget* aSmpGroup = new QWidget();
208   lay->addWidget( aSmpGroup );
209   
210   // Size map widget creation and initialisation
211   mySmpWidget = new HexoticPluginGUI_SizeMapsWidget(aSmpGroup);
212   mySmpWidget->doubleSpinBox->RangeStepAndValidator(0.0, COORD_MAX, 1.0, "length_precision");
213   mySmpWidget->doubleSpinBox->setValue(0.0);
214   
215   // Filters of selection
216   TColStd_MapOfInteger SM_ShapeTypes; 
217   SM_ShapeTypes.Add( TopAbs_VERTEX );
218   SM_ShapeTypes.Add( TopAbs_EDGE );
219   SM_ShapeTypes.Add( TopAbs_WIRE );
220   SM_ShapeTypes.Add( TopAbs_FACE );
221   SM_ShapeTypes.Add( TopAbs_SOLID );
222   SM_ShapeTypes.Add( TopAbs_COMPOUND );  
223   SMESH_NumberFilter* aFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
224   
225   // Selection widget
226   myGeomSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( aFilter, mySmpWidget, /*multiSel=*/false);
227   myGeomSelWdg->SetDefaultText(tr("Hexotic_SEL_SHAPE"), "QLineEdit { color: grey }");
228   mySmpWidget->gridLayout->addWidget(myGeomSelWdg, 0, 1);
229   
230   // Configuration of the table widget
231   QStringList headerLabels;
232   headerLabels << tr("Hexotic_ENTRY")<< tr("Hexotic_NAME")<< tr("Hexotic_SIZE");
233   mySmpWidget->tableWidget->setHorizontalHeaderLabels(headerLabels);
234   mySmpWidget->tableWidget->resizeColumnsToContents();
235   mySmpWidget->tableWidget->hideColumn( 0 );
236   mySmpWidget->label->setText(tr("LOCAL_SIZE"));
237   mySmpWidget->pushButton_1->setText(tr("Hexotic_ADD"));
238   mySmpWidget->pushButton_2->setText(tr("Hexotic_REMOVE"));
239   
240   // Setting a custom delegate for the size column
241   SizeMapsTableWidgetDelegate* delegate = new SizeMapsTableWidgetDelegate();
242   mySmpWidget->tableWidget->setItemDelegateForColumn(SIZE_COL, delegate);
243   
244   // Add the size maps widget to a layout
245   QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup );
246   aSmpLayout->setMargin( 0 );
247   aSmpLayout->addWidget( mySmpWidget);
248   
249   // Viscous Layers tab
250   QWidget* aVLGroup = new QWidget();
251   lay->addWidget( aVLGroup );
252
253   // Viscous layers widget creation and initialisation
254   myVLWidget = new HexoticPluginGUI_ViscousLayersWidget(aVLGroup);
255
256   QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
257   QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
258
259   if ( !aMainEntry.isEmpty() )
260   {
261     myVLWidget->myFacesWithLayers->SetGeomShapeEntry( aSubEntry, aMainEntry );
262     myVLWidget->myImprintedFaces->SetGeomShapeEntry( aSubEntry, aMainEntry );
263   }
264   else
265   {
266         myVLWidget->labelFacesWithLayers->setVisible(false);
267     myVLWidget->myFacesWithLayers->setVisible(false);
268     myVLWidget->labelImprintedFaces->setVisible(false);
269     myVLWidget->myImprintedFaces->setVisible(false);
270   }
271
272   // Add the viscous layers widget to a layout
273   QHBoxLayout* aVLLayout = new QHBoxLayout( aVLGroup );
274   aVLLayout->setSpacing( 6 );
275   aVLLayout->setMargin( 11 );
276   aVLLayout->addWidget( myVLWidget );
277
278 //  resizeEvent();
279   
280   aTabWidget->insertTab( STD_TAB, aStdGroup, tr( "SMESH_ARGUMENTS" ) );
281   aTabWidget->insertTab( SMP_TAB, aSmpGroup, tr( "LOCAL_SIZE" ) );
282   aTabWidget->insertTab( VL_TAB, aVLGroup, tr( "Hexotic_VISCOUS_LAYERS") );
283   
284   myIs3D = true;
285   
286   // Size Maps
287   mySizeMapsToRemove.clear();
288   connect( mySmpWidget->pushButton_1, SIGNAL( clicked() ),          this, SLOT( onAddLocalSize() ) );
289   connect( mySmpWidget->pushButton_2, SIGNAL( clicked() ),          this, SLOT( onRemoveLocalSize() ) );
290   connect( aTabWidget,                SIGNAL( currentChanged(int)), this, SLOT( onTabChanged( int ) ) );
291   return fr;
292 }
293
294 void HexoticPluginGUI_HypothesisCreator::onAddLocalSize()
295 {
296   int rowCount = mySmpWidget->tableWidget->rowCount();
297   //int columnCount = mySmpWidget->tableWidget->columnCount();
298   
299   // Get the selected object properties
300   GEOM::GEOM_Object_var sizeMapObject = myGeomSelWdg->GetObject< GEOM::GEOM_Object >(0);
301   if (sizeMapObject->_is_nil())
302     return;
303   
304   std::string entry, shapeName;
305   entry = (std::string) sizeMapObject->GetStudyEntry();
306   shapeName = sizeMapObject->GetName();
307   
308   // Check if the object is already in the widget
309   QList<QTableWidgetItem *> listFound = mySmpWidget->tableWidget
310                                         ->findItems( QString(entry.c_str()), Qt::MatchExactly );
311   if ( !listFound.isEmpty() )
312     return;
313   
314   // Get the size value
315   double size = mySmpWidget->doubleSpinBox->value();
316   if (size == 0)
317   {
318     SUIT_MessageBox::critical( mySmpWidget, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) );
319     return;
320   }
321   
322   // Set items for the inserted row
323   insertLocalSizeInWidget( entry, shapeName, size, rowCount );
324 }
325
326 void HexoticPluginGUI_HypothesisCreator::insertLocalSizeInWidget( std::string entry, 
327                                                                   std::string shapeName, 
328                                                                   double size, 
329                                                                   int row ) const
330 {
331   MESSAGE("HexoticPluginGUI_HypothesisCreator:insertLocalSizeInWidget")
332   int columnCount = mySmpWidget->tableWidget->columnCount();
333   
334   // Add a row at the end of the table
335   mySmpWidget->tableWidget->insertRow(row);
336   
337   QVariant value;
338   for (int col = 0; col<columnCount; col++)
339   {
340     QTableWidgetItem* item = new QTableWidgetItem();
341     switch ( col )
342     {
343       case ENTRY_COL:
344         item->setFlags( 0 );
345         value = QVariant( entry.c_str() );
346         item->setData(Qt::DisplayRole, value );
347         break;  
348       case NAME_COL:
349         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
350         value = QVariant( shapeName.c_str() );
351         item->setData(Qt::DisplayRole, value );
352         break;
353       case SIZE_COL:
354         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
355         value = QVariant( size );
356         item->setData(Qt::EditRole, value );
357         break;
358     }       
359     mySmpWidget->tableWidget->setItem(row,col,item);
360   }
361 }
362
363 void HexoticPluginGUI_HypothesisCreator::onRemoveLocalSize()
364 {
365   // Remove the selected rows in the table
366   QList<QTableWidgetSelectionRange> ranges = mySmpWidget->tableWidget->selectedRanges();
367   if ( ranges.isEmpty() ) // If none is selected remove the last one
368   {
369     int lastRow = mySmpWidget->tableWidget->rowCount() - 1;
370     std::string entry = mySmpWidget->tableWidget->item( lastRow, ENTRY_COL )->text().toStdString();
371     mySizeMapsToRemove.push_back(entry);
372     mySmpWidget->tableWidget->removeRow( lastRow ); 
373   }
374   else
375   {
376     QList<QTableWidgetSelectionRange>::iterator it;
377     for ( it = ranges.begin(); it != ranges.end(); ++it )
378     {
379       for ( int row = it->topRow(); row <= it->bottomRow(); row++ )
380       {
381         std::string entry = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
382         mySizeMapsToRemove.push_back(entry);
383         MESSAGE("ADDING entry : "<<entry<<"to the Size Maps to remove")
384       }
385       mySmpWidget->tableWidget->model()->removeRows(it->topRow(), it->rowCount());
386     }
387   }
388 }
389
390 //=================================================================================
391 // function : resizeEvent [REDEFINED]
392 // purpose  :
393 //=================================================================================
394 void HexoticPluginGUI_HypothesisCreator::resizeEvent(QResizeEvent */*event*/) {
395     QSize scaledSize = myStdWidget->imageSdMode.size();
396     scaledSize.scale(myStdWidget->sdModeLabel->size(), Qt::KeepAspectRatioByExpanding);
397     if (!myStdWidget->sdModeLabel->pixmap() || scaledSize != myStdWidget->sdModeLabel->pixmap()->size())
398       myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(),
399       Qt::KeepAspectRatio,
400       Qt::SmoothTransformation));
401 }
402
403 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
404 {
405   HexoticHypothesisData data;
406   readParamsFromHypo( data );
407   printData(data);
408
409   if( myName )
410     myName->setText( data.myName );
411
412   myStdWidget->myMinSize->setCleared(data.myMinSize == 0);
413   if (data.myMinSize == 0)
414     myStdWidget->myMinSize->setText("");
415   else
416     myStdWidget->myMinSize->setValue( data.myMinSize );
417
418   myStdWidget->myMaxSize->setCleared(data.myMaxSize == 0);
419   if (data.myMaxSize == 0)
420     myStdWidget->myMaxSize->setText("");
421   else
422     myStdWidget->myMaxSize->setValue( data.myMaxSize );
423
424   myStdWidget->myHexesMinLevel->setCleared(data.myHexesMinLevel == 0);
425   if (data.myHexesMinLevel == 0)
426     myStdWidget->myHexesMinLevel->setText("");
427   else
428     myStdWidget->myHexesMinLevel->setValue( data.myHexesMinLevel );
429
430   myStdWidget->myHexesMaxLevel->setCleared(data.myHexesMaxLevel == 0);
431   if (data.myHexesMaxLevel == 0)
432     myStdWidget->myHexesMaxLevel->setText("");
433   else
434     myStdWidget->myHexesMaxLevel->setValue( data.myHexesMaxLevel );
435
436   myStdWidget->myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
437   myStdWidget->myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
438   
439   myStdWidget->myHexoticSharpAngleThreshold->setCleared(data.myHexoticSharpAngleThreshold == 0);
440   if (data.myHexoticSharpAngleThreshold == 0)
441     myStdWidget->myHexoticSharpAngleThreshold->setText("");
442   else
443     myStdWidget->myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
444 #ifndef WIN32
445   myStdWidget->myHexoticNbProc->setValue( data.myHexoticNbProc );
446 #endif
447   myStdWidget->myHexoticWorkingDir->setText( data.myHexoticWorkingDir );
448
449   myStdWidget->myHexoticVerbosity->setValue( data.myHexoticVerbosity );
450
451   myStdWidget->myHexoticMaxMemory->setValue( data.myHexoticMaxMemory );
452
453   myStdWidget->myHexoticSdMode->setCurrentIndex(data.myHexoticSdMode);
454   
455   myStdWidget->myTextOptions->setText(data.myTextOptions);
456
457   HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = data.mySizeMaps.begin();
458   for ( int row = 0; it != data.mySizeMaps.end(); it++, row++ )
459   {
460     std::string entry = it->first;
461     double size = it->second;
462     GEOM::GEOM_Object_var anObject = entryToObject( entry );
463     std::string shapeName = anObject->GetName();
464
465     MESSAGE(" Insert local size, entry : "<<entry<<", size : "<<size<<", at row : "<<row) 
466     insertLocalSizeInWidget( entry, shapeName, size , row );
467   }
468
469   myVLWidget->myNbLayers->setCleared(data.myNbLayers == 0);
470   if (data.myNbLayers == 0)
471     myVLWidget->myNbLayers->setText("");
472   else
473     myVLWidget->myNbLayers->setValue( data.myNbLayers );
474
475   myVLWidget->myFirstLayerSize->setCleared(data.myFirstLayerSize == 0);
476   if (data.myFirstLayerSize == 0)
477     myVLWidget->myFirstLayerSize->setText("");
478   else
479     myVLWidget->myFirstLayerSize->setValue( data.myFirstLayerSize );
480
481   myVLWidget->myDirection->setCurrentIndex( data.myDirection ? 0 : 1 );
482   myVLWidget->myGrowth->setCleared(data.myGrowth == 0);
483   if (data.myGrowth == 0)
484     myVLWidget->myGrowth->setText("");
485   else
486     myVLWidget->myGrowth->setValue( data.myGrowth );
487
488   std::vector<int> vector = data.myFacesWithLayers;
489   SMESH::long_array_var aVec = new SMESH::long_array;
490   aVec->length(vector.size());
491   for (size_t i = 0; i < vector.size(); i++)
492     aVec[i]=vector.at(i);
493   myVLWidget->myFacesWithLayers->SetListOfIDs(aVec);
494   vector = data.myImprintedFaces;
495   aVec = new SMESH::long_array;
496   aVec->length(vector.size());
497   for (size_t i = 0; i < vector.size(); i++)
498     aVec[i]=vector.at(i);
499   myVLWidget->myImprintedFaces->SetListOfIDs(aVec);
500
501
502   std::cout << "myStdWidget->myMinSize->value(): " << myStdWidget->myMinSize->value() << std::endl;
503   std::cout << "myStdWidget->myMaxSize->value(): " << myStdWidget->myMaxSize->value() << std::endl;
504   std::cout << "myStdWidget->myHexesMinLevel->value(): " << myStdWidget->myHexesMinLevel->value() << std::endl;
505   std::cout << "myStdWidget->myHexesMaxLevel->value(): " << myStdWidget->myHexesMaxLevel->value() << std::endl;
506   std::cout << "myStdWidget->myHexoticSharpAngleThreshold->value(): " << myStdWidget->myHexoticSharpAngleThreshold->value() << std::endl;
507
508 }
509
510 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
511 {
512   QString valStr;
513   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
514   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
515   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
516   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
517   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
518   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
519   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
520   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
521   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
522   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity ) + "; ";
523   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
524   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode ) + "; ";
525   valStr += tr("Hexotic_TEXT_OPTIONS") + " = " + data.myTextOptions + ";";
526
527   std::cout << "Data: " << valStr.toStdString() << std::endl;
528 }
529
530 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
531 {
532   HexoticHypothesisData data;
533   readParamsFromWidgets( data );
534   storeParamsToHypo( data );
535
536   QString valStr;
537   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
538   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
539   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
540   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
541   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
542   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
543   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
544   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
545   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
546   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity) + "; ";
547   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
548   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode) + "; ";
549   valStr += tr("Hexotic_TEXT_OPTIONS") + " = " + data.myTextOptions + "; ";
550
551   valStr += tr("Hexotic_NB_LAYERS") + " = " + QString::number(data.myNbLayers) + ";";
552   valStr += tr("Hexotic_FIRST_LAYER_SIZE") + " = " + QString::number(data.myFirstLayerSize) + ";";
553   valStr += tr("Hexotic_DIRECTION") + " = " + QString::number(data.myDirection) + ";";
554   valStr += tr("Hexotic_GROWTH") + " = " + QString::number(data.myGrowth) + ";";
555
556 //  std::cout << "Data: " << valStr.toStdString() << std::endl;
557
558   return valStr;
559 }
560
561 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
562 {
563   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
564     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
565
566   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
567   h_data.myName = isCreation() && data ? data->Label : "";
568   h_data.myMinSize = h->GetMinSize();
569   h_data.myMaxSize = h->GetMaxSize();
570   h_data.myHexesMinLevel = h->GetHexesMinLevel();
571   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
572   h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
573   h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
574   h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
575   h_data.myHexoticNbProc = h->GetHexoticNbProc();
576   h_data.myHexoticWorkingDir = h->GetHexoticWorkingDirectory();
577   h_data.myHexoticVerbosity = h->GetHexoticVerbosity();
578   h_data.myHexoticMaxMemory = h->GetHexoticMaxMemory();
579   h_data.myHexoticSdMode = h->GetHexoticSdMode()-1;
580   h_data.myTextOptions = h->GetTextOptions();
581   
582   // Size maps
583   HexoticPlugin::HexoticPluginSizeMapsList_var sizeMaps = h->GetSizeMaps();
584   for ( CORBA::ULong i = 0 ; i < sizeMaps->length() ; i++) 
585   {
586     HexoticPlugin::HexoticPluginSizeMap aSizeMap = sizeMaps[i];
587     std::string entry = CORBA::string_dup(aSizeMap.entry.in());
588     double size = aSizeMap.size;
589     h_data.mySizeMaps[ entry ] = size;
590     MESSAGE("READING Size map : entry "<<entry<<" size : "<<size)
591   }
592   
593   // Viscous layers
594   h_data.myNbLayers = h->GetNbLayers();
595   h_data.myFirstLayerSize = h->GetFirstLayerSize();
596   h_data.myDirection = h->GetDirection();
597   h_data.myGrowth = h->GetGrowth();
598   SMESH::long_array_var vector = h->GetFacesWithLayers();
599   for ( CORBA::ULong i = 0; i < vector->length(); i++)
600     h_data.myFacesWithLayers.push_back(vector[i]);
601   vector = h->GetImprintedFaces();
602   for ( CORBA::ULong i = 0; i < vector->length(); i++)
603     h_data.myImprintedFaces.push_back(vector[i]);
604
605   return true;
606 }
607
608 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
609 {
610   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
611     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
612
613   bool ok = true;
614
615   try
616   {
617     if( isCreation() )
618       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
619
620     h->SetMinSize( h_data.myMinSize );
621     h->SetMaxSize( h_data.myMaxSize );
622     h->SetHexesMinLevel( h_data.myHexesMinLevel );
623     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
624     h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
625     h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
626     h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
627     h->SetHexoticNbProc( h_data.myHexoticNbProc );
628     h->SetHexoticWorkingDirectory( h_data.myHexoticWorkingDir.toLatin1().constData() );
629     h->SetHexoticVerbosity( h_data.myHexoticVerbosity );
630     h->SetHexoticMaxMemory( h_data.myHexoticMaxMemory );
631     h->SetHexoticSdMode( h_data.myHexoticSdMode+1 );
632     h->SetTextOptions( h_data.myTextOptions.toLatin1().constData() );
633     
634     HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it;
635     
636     for ( it =  h_data.mySizeMaps.begin(); it !=  h_data.mySizeMaps.end(); it++ )
637     {
638       h->SetSizeMapEntry( it->first.c_str(), it->second );
639       MESSAGE("STORING Size map : entry "<<it->first.c_str()<<" size : "<<it->second)
640     }
641     std::vector< std::string >::const_iterator entry_it;
642     for ( entry_it = mySizeMapsToRemove.begin(); entry_it!= mySizeMapsToRemove.end(); entry_it++ )
643     {
644       h->UnsetSizeMapEntry(entry_it->c_str());
645     }
646
647     // Viscous layers
648     h->SetNbLayers( h_data.myNbLayers );
649     h->SetFirstLayerSize( h_data.myFirstLayerSize );
650     h->SetDirection( h_data.myDirection );
651     h->SetGrowth( h_data.myGrowth );
652     
653     std::vector<int> vector = h_data.myFacesWithLayers;
654     SMESH::long_array_var aVec = new SMESH::long_array;
655     aVec->length(vector.size());
656     for ( size_t i = 0; i < vector.size(); i++)
657       aVec[i]=vector.at(i);
658     h->SetFacesWithLayers( aVec );
659     
660     vector = h_data.myImprintedFaces;
661     aVec = new SMESH::long_array;
662     aVec->length(vector.size());
663     for ( size_t i = 0; i < vector.size(); i++)
664       aVec[i]=vector.at(i);
665     h->SetImprintedFaces( aVec );
666   }
667   catch(const SALOME::SALOME_Exception& ex)
668   {
669     SalomeApp_Tools::QtCatchCorbaException(ex);
670     ok = false;
671   }
672   return ok;
673 }
674
675 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
676 {
677   h_data.myName    = myName ? myName->text() : "";
678
679   h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
680   h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
681 #ifndef WIN32
682   h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
683 #endif
684   h_data.myHexoticWorkingDir = myStdWidget->myHexoticWorkingDir->text();
685   h_data.myHexoticVerbosity = myStdWidget->myHexoticVerbosity->value();
686   h_data.myHexoticMaxMemory = myStdWidget->myHexoticMaxMemory->value();
687   h_data.myHexoticSdMode = myStdWidget->myHexoticSdMode->currentIndex();
688   h_data.myTextOptions = myStdWidget->myTextOptions->text();
689
690   h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? 0.0 : myStdWidget->myMinSize->value();
691   h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? 0.0 : myStdWidget->myMaxSize->value();
692   h_data.myHexesMinLevel = myStdWidget->myHexesMinLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMinLevel->value();
693   h_data.myHexesMaxLevel = myStdWidget->myHexesMaxLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMaxLevel->value();
694   h_data.myHexoticSharpAngleThreshold = myStdWidget->myHexoticSharpAngleThreshold->text().isEmpty() ? 0 : myStdWidget->myHexoticSharpAngleThreshold->value();
695
696   // Size maps reading
697   bool ok = readSizeMapsFromWidgets( h_data );
698   if ( !ok )
699     return false;
700   
701   h_data.myNbLayers = myVLWidget->myNbLayers->text().isEmpty() ? 0.0 : myVLWidget->myNbLayers->value();
702   h_data.myFirstLayerSize = myVLWidget->myFirstLayerSize->text().isEmpty() ? 0.0 : myVLWidget->myFirstLayerSize->value();
703   h_data.myDirection = myVLWidget->myDirection->currentIndex() == 0 ? true : false;
704   h_data.myGrowth = myVLWidget->myGrowth->text().isEmpty() ? 0.0 : myVLWidget->myGrowth->value();
705   SMESH::long_array_var ids = myVLWidget->myFacesWithLayers->GetListOfIDs();
706   for ( CORBA::ULong i = 0; i < ids->length(); i++)
707     h_data.myFacesWithLayers.push_back( ids[i] );
708   ids = myVLWidget->myImprintedFaces->GetListOfIDs();
709   for ( CORBA::ULong i = 0; i < ids->length(); i++)
710     h_data.myImprintedFaces.push_back( ids[i] );
711
712   printData(h_data);
713
714   return true;
715 }
716
717 bool HexoticPluginGUI_HypothesisCreator::readSizeMapsFromWidgets( HexoticHypothesisData& h_data ) const
718 {
719   int rowCount = mySmpWidget->tableWidget->rowCount();
720   for ( int row = 0; row <  rowCount; row++ )
721   {
722     std::string entry     = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
723     QVariant size_variant = mySmpWidget->tableWidget->item( row, SIZE_COL )->data(Qt::DisplayRole);
724     
725     // Convert the size to double
726     bool ok = false;
727     double size = size_variant.toDouble(&ok);
728     if (!ok)
729       return false;
730     
731     // Set the size maps
732     h_data.mySizeMaps[ entry ] = size;
733     MESSAGE("READING Size map from WIDGET: entry "<<entry<<" size : "<<size)
734   }
735   return true;
736 }
737
738 GEOM::GEOM_Object_var HexoticPluginGUI_HypothesisCreator::entryToObject( std::string entry) const
739 {
740   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
741   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
742   GEOM::GEOM_Object_var aGeomObj;
743   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
744   if (!aSObj->_is_nil()) {
745     CORBA::Object_var obj = aSObj->GetObject();
746     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
747     aSObj->UnRegister();
748   }
749   return aGeomObj;
750 }
751
752 QString HexoticPluginGUI_HypothesisCreator::caption() const
753 {
754   return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
755 }
756
757 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
758 {
759   QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
760   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
761 }
762
763 QString HexoticPluginGUI_HypothesisCreator::type() const
764 {
765   return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
766 }
767
768 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
769 {
770   return "hexotic_hypo_page.html";
771 }
772
773 void HexoticPluginGUI_HypothesisCreator::onTabChanged(int i)
774 {
775   myVLWidget->myFacesWithLayers->ShowPreview( i == VL_TAB );
776   myVLWidget->myImprintedFaces->ShowPreview( false );
777 }