Salome HOME
0023102: [CEA 1486 ] Add the parameters for defining the boundary layers
[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   HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = data.mySizeMaps.begin();
456   for ( int row = 0; it != data.mySizeMaps.end(); it++, row++ )
457   {
458     std::string entry = it->first;
459     double size = it->second;
460     GEOM::GEOM_Object_var anObject = entryToObject( entry );
461     std::string shapeName = anObject->GetName();
462
463     MESSAGE(" Insert local size, entry : "<<entry<<", size : "<<size<<", at row : "<<row) 
464     insertLocalSizeInWidget( entry, shapeName, size , row );
465   }
466
467   myVLWidget->myNbLayers->setCleared(data.myNbLayers == 0);
468   if (data.myNbLayers == 0)
469     myVLWidget->myNbLayers->setText("");
470   else
471     myVLWidget->myNbLayers->setValue( data.myNbLayers );
472
473   myVLWidget->myFirstLayerSize->setCleared(data.myFirstLayerSize == 0);
474   if (data.myFirstLayerSize == 0)
475     myVLWidget->myFirstLayerSize->setText("");
476   else
477     myVLWidget->myFirstLayerSize->setValue( data.myFirstLayerSize );
478
479   myVLWidget->myDirection->setCurrentIndex( data.myDirection ? 0 : 1 );
480   myVLWidget->myGrowth->setCleared(data.myGrowth == 0);
481   if (data.myGrowth == 0)
482     myVLWidget->myGrowth->setText("");
483   else
484     myVLWidget->myGrowth->setValue( data.myGrowth );
485
486   std::vector<int> vector = data.myFacesWithLayers;
487   SMESH::long_array_var aVec = new SMESH::long_array;
488   aVec->length(vector.size());
489   for (int i = 0; i < vector.size(); i++)
490     aVec[i]=vector.at(i);
491   myVLWidget->myFacesWithLayers->SetListOfIDs(aVec);
492   vector = data.myImprintedFaces;
493   aVec = new SMESH::long_array;
494   aVec->length(vector.size());
495   for (int i = 0; i < vector.size(); i++)
496     aVec[i]=vector.at(i);
497   myVLWidget->myImprintedFaces->SetListOfIDs(aVec);
498
499
500   std::cout << "myStdWidget->myMinSize->value(): " << myStdWidget->myMinSize->value() << std::endl;
501   std::cout << "myStdWidget->myMaxSize->value(): " << myStdWidget->myMaxSize->value() << std::endl;
502   std::cout << "myStdWidget->myHexesMinLevel->value(): " << myStdWidget->myHexesMinLevel->value() << std::endl;
503   std::cout << "myStdWidget->myHexesMaxLevel->value(): " << myStdWidget->myHexesMaxLevel->value() << std::endl;
504   std::cout << "myStdWidget->myHexoticSharpAngleThreshold->value(): " << myStdWidget->myHexoticSharpAngleThreshold->value() << std::endl;
505
506 }
507
508 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
509 {
510   QString valStr;
511   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
512   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
513   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
514   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
515   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
516   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
517   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
518   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
519   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
520   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity ) + "; ";
521   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
522   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode ) + "; ";
523
524   std::cout << "Data: " << valStr.toStdString() << std::endl;
525 }
526
527 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
528 {
529   HexoticHypothesisData data;
530   readParamsFromWidgets( data );
531   storeParamsToHypo( data );
532
533   QString valStr;
534   valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize )   + "; ";
535   valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
536   valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
537   valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
538   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
539   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
540   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
541   valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
542   valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
543   valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity) + "; ";
544   valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
545   valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode) + "; ";
546
547   valStr += tr("Hexotic_NB_LAYERS") + " = " + QString::number(data.myNbLayers) + ";";
548   valStr += tr("Hexotic_FIRST_LAYER_SIZE") + " = " + QString::number(data.myFirstLayerSize) + ";";
549   valStr += tr("Hexotic_DIRECTION") + " = " + QString::number(data.myDirection) + ";";
550   valStr += tr("Hexotic_GROWTH") + " = " + QString::number(data.myGrowth) + ";";
551
552 //  std::cout << "Data: " << valStr.toStdString() << std::endl;
553
554   return valStr;
555 }
556
557 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
558 {
559   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
560     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
561
562   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
563   h_data.myName = isCreation() && data ? data->Label : "";
564   h_data.myMinSize = h->GetMinSize();
565   h_data.myMaxSize = h->GetMaxSize();
566   h_data.myHexesMinLevel = h->GetHexesMinLevel();
567   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
568   h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
569   h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
570   h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
571   h_data.myHexoticNbProc = h->GetHexoticNbProc();
572   h_data.myHexoticWorkingDir = h->GetHexoticWorkingDirectory();
573   h_data.myHexoticVerbosity = h->GetHexoticVerbosity();
574   h_data.myHexoticMaxMemory = h->GetHexoticMaxMemory();
575   h_data.myHexoticSdMode = h->GetHexoticSdMode()-1;
576   
577   // Size maps
578   HexoticPlugin::HexoticPluginSizeMapsList_var sizeMaps = h->GetSizeMaps();
579   for ( int i = 0 ; i < sizeMaps->length() ; i++) 
580   {
581     HexoticPlugin::HexoticPluginSizeMap aSizeMap = sizeMaps[i];
582     std::string entry = CORBA::string_dup(aSizeMap.entry.in());
583     double size = aSizeMap.size;
584     h_data.mySizeMaps[ entry ] = size;
585     MESSAGE("READING Size map : entry "<<entry<<" size : "<<size)
586   }
587   
588   // Viscous layers
589   h_data.myNbLayers = h->GetNbLayers();
590   h_data.myFirstLayerSize = h->GetFirstLayerSize();
591   h_data.myDirection = h->GetDirection();
592   h_data.myGrowth = h->GetGrowth();
593   SMESH::long_array_var vector = h->GetFacesWithLayers();
594   for (int i = 0; i < vector->length(); i++)
595     h_data.myFacesWithLayers.push_back(vector[i]);
596   vector = h->GetImprintedFaces();
597   for (int i = 0; i < vector->length(); i++)
598     h_data.myImprintedFaces.push_back(vector[i]);
599
600   return true;
601 }
602
603 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
604 {
605   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
606     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
607
608   bool ok = true;
609
610   try
611   {
612     if( isCreation() )
613       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
614
615     h->SetMinSize( h_data.myMinSize );
616     h->SetMaxSize( h_data.myMaxSize );
617     h->SetHexesMinLevel( h_data.myHexesMinLevel );
618     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
619     h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
620     h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
621     h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
622     h->SetHexoticNbProc( h_data.myHexoticNbProc );
623     h->SetHexoticWorkingDirectory( h_data.myHexoticWorkingDir.toLatin1().constData() );
624     h->SetHexoticVerbosity( h_data.myHexoticVerbosity );
625     h->SetHexoticMaxMemory( h_data.myHexoticMaxMemory );
626     h->SetHexoticSdMode( h_data.myHexoticSdMode+1 );
627     
628     HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it;
629     
630     for ( it =  h_data.mySizeMaps.begin(); it !=  h_data.mySizeMaps.end(); it++ )
631     {
632       h->SetSizeMapEntry( it->first.c_str(), it->second );
633       MESSAGE("STORING Size map : entry "<<it->first.c_str()<<" size : "<<it->second)
634     }
635     std::vector< std::string >::const_iterator entry_it;
636     for ( entry_it = mySizeMapsToRemove.begin(); entry_it!= mySizeMapsToRemove.end(); entry_it++ )
637     {
638       h->UnsetSizeMapEntry(entry_it->c_str());
639     }
640
641     // Viscous layers
642     h->SetNbLayers( h_data.myNbLayers );
643     h->SetFirstLayerSize( h_data.myFirstLayerSize );
644     h->SetDirection( h_data.myDirection );
645     h->SetGrowth( h_data.myGrowth );
646     
647     std::vector<int> vector = h_data.myFacesWithLayers;
648     SMESH::long_array_var aVec = new SMESH::long_array;
649     aVec->length(vector.size());
650     for (int i = 0; i < vector.size(); i++)
651       aVec[i]=vector.at(i);
652     h->SetFacesWithLayers( aVec );
653     
654     vector = h_data.myImprintedFaces;
655     aVec = new SMESH::long_array;
656     aVec->length(vector.size());
657     for (int i = 0; i < vector.size(); i++)
658       aVec[i]=vector.at(i);
659     h->SetImprintedFaces( aVec );
660   }
661   catch(const SALOME::SALOME_Exception& ex)
662   {
663     SalomeApp_Tools::QtCatchCorbaException(ex);
664     ok = false;
665   }
666   return ok;
667 }
668
669 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
670 {
671   h_data.myName    = myName ? myName->text() : "";
672
673   h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
674   h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
675 #ifndef WIN32
676   h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
677 #endif
678   h_data.myHexoticWorkingDir = myStdWidget->myHexoticWorkingDir->text();
679   h_data.myHexoticVerbosity = myStdWidget->myHexoticVerbosity->value();
680   h_data.myHexoticMaxMemory = myStdWidget->myHexoticMaxMemory->value();
681   h_data.myHexoticSdMode = myStdWidget->myHexoticSdMode->currentIndex();
682
683   h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? 0.0 : myStdWidget->myMinSize->value();
684   h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? 0.0 : myStdWidget->myMaxSize->value();
685   h_data.myHexesMinLevel = myStdWidget->myHexesMinLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMinLevel->value();
686   h_data.myHexesMaxLevel = myStdWidget->myHexesMaxLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMaxLevel->value();
687   h_data.myHexoticSharpAngleThreshold = myStdWidget->myHexoticSharpAngleThreshold->text().isEmpty() ? 0 : myStdWidget->myHexoticSharpAngleThreshold->value();
688
689   // Size maps reading
690   bool ok = readSizeMapsFromWidgets( h_data );
691   if ( !ok )
692     return false;
693   
694   h_data.myNbLayers = myVLWidget->myNbLayers->text().isEmpty() ? 0.0 : myVLWidget->myNbLayers->value();
695   h_data.myFirstLayerSize = myVLWidget->myFirstLayerSize->text().isEmpty() ? 0.0 : myVLWidget->myFirstLayerSize->value();
696   h_data.myDirection = myVLWidget->myDirection->currentIndex() == 0 ? true : false;
697   h_data.myGrowth = myVLWidget->myGrowth->text().isEmpty() ? 0.0 : myVLWidget->myGrowth->value();
698   SMESH::long_array_var ids = myVLWidget->myFacesWithLayers->GetListOfIDs();
699   for (int i = 0; i < ids->length(); i++)
700     h_data.myFacesWithLayers.push_back( ids[i] );
701   ids = myVLWidget->myImprintedFaces->GetListOfIDs();
702   for (int i = 0; i < ids->length(); i++)
703     h_data.myImprintedFaces.push_back( ids[i] );
704
705   printData(h_data);
706
707   return true;
708 }
709
710 bool HexoticPluginGUI_HypothesisCreator::readSizeMapsFromWidgets( HexoticHypothesisData& h_data ) const
711 {
712   int rowCount = mySmpWidget->tableWidget->rowCount();
713   for ( int row = 0; row <  rowCount; row++ )
714   {
715     std::string entry     = mySmpWidget->tableWidget->item( row, ENTRY_COL )->text().toStdString();
716     QVariant size_variant = mySmpWidget->tableWidget->item( row, SIZE_COL )->data(Qt::DisplayRole);
717     
718     // Convert the size to double
719     bool ok = false;
720     double size = size_variant.toDouble(&ok);
721     if (!ok)
722       return false;
723     
724     // Set the size maps
725     h_data.mySizeMaps[ entry ] = size;
726     MESSAGE("READING Size map from WIDGET: entry "<<entry<<" size : "<<size)
727   }
728   return true;
729 }
730
731 GEOM::GEOM_Object_var HexoticPluginGUI_HypothesisCreator::entryToObject( std::string entry) const
732 {
733   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
734   SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
735   GEOM::GEOM_Object_var aGeomObj;
736   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
737   if (!aSObj->_is_nil()) {
738     CORBA::Object_var obj = aSObj->GetObject();
739     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
740     aSObj->UnRegister();
741   }
742   return aGeomObj;
743 }
744
745 QString HexoticPluginGUI_HypothesisCreator::caption() const
746 {
747   return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
748 }
749
750 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
751 {
752   QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
753   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
754 }
755
756 QString HexoticPluginGUI_HypothesisCreator::type() const
757 {
758   return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
759 }
760
761 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
762 {
763   return "hexotic_hypo_page.html";
764 }
765
766 void HexoticPluginGUI_HypothesisCreator::onTabChanged(int i)
767 {
768   myVLWidget->myFacesWithLayers->ShowPreview( i == VL_TAB );
769   myVLWidget->myImprintedFaces->ShowPreview( false );
770 }