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