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