1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HexoticPluginGUI_HypothesisCreator.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
25 #include "HexoticPluginGUI_HypothesisCreator.h"
26 #include "HexoticPluginGUI_Dlg.h"
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESH_NumberFilter.hxx>
31 #include <SMESH_AdvOptionsWdg.h>
33 #include "utilities.h"
35 #include CORBA_SERVER_HEADER(HexoticPlugin_Algorithm)
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>
46 #include <QVBoxLayout>
47 #include <QGridLayout>
51 #include <QPushButton>
53 #include "SMESH_Gen_i.hxx"
56 #include <TColStd_MapOfInteger.hxx>
59 // Main widget tabs identification
67 // Size maps tab, table columns order
75 // Size map table widget delegate
78 SizeMapsTableWidgetDelegate::SizeMapsTableWidgetDelegate(QObject *parent)
79 : QItemDelegate(parent)
83 QWidget* SizeMapsTableWidgetDelegate::createEditor(QWidget *parent,
84 const QStyleOptionViewItem &/* option */,
85 const QModelIndex &/* index */) const
87 SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
88 editor->RangeStepAndValidator(0.0, COORD_MAX, 10.0, "length_precision");
92 void SizeMapsTableWidgetDelegate::setEditorData(QWidget *editor,
93 const QModelIndex &index) const
95 double value = index.model()->data(index, Qt::EditRole).toDouble();
96 SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
97 spinBox->setValue(value);
100 void SizeMapsTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
101 const QModelIndex &index) const
103 SMESHGUI_SpinBox *spinBox = static_cast<SMESHGUI_SpinBox*>(editor);
104 spinBox->interpretText();
105 double value = spinBox->value();
107 SUIT_MessageBox::critical( spinBox, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) );
109 model->setData(index, value, Qt::EditRole);
112 void SizeMapsTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
113 const QStyleOptionViewItem &option,
114 const QModelIndex &/* index */) const
116 editor->setGeometry(option.rect);
123 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
124 : SMESHGUI_GenericHypothesisCreator( theHypType ),
130 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
134 bool HexoticPluginGUI_HypothesisCreator::checkParams(QString& msg) const
138 HexoticHypothesisData data_old, data_new;
139 readParamsFromHypo( data_old );
141 bool res = readParamsFromWidgets( data_new );
146 res = storeParamsToHypo( data_new );
148 storeParamsToHypo( data_old );
152 res = data_new.myMinSize <= data_new.myMaxSize;
154 msg = tr(QString("Min size (%1) is higher than max size (%2)").arg(data_new.myMinSize).arg(data_new.myMaxSize).toStdString().c_str());
158 res = data_new.myHexesMinLevel == 0 || \
159 ( data_new.myHexesMinLevel != 0 && (data_new.myHexesMinLevel < data_new.myHexesMaxLevel) );
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());
168 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
170 QFrame* fr = new QFrame( 0 );
171 QVBoxLayout* lay = new QVBoxLayout( fr );
173 lay->setSpacing( 6 );
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 );
181 // Standard arguments tab
182 QWidget* aStdGroup = new QWidget();
183 QGridLayout* l = new QGridLayout( aStdGroup );
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 );
196 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
197 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
199 myStdWidget = new HexoticPluginGUI_StdWidget(aStdGroup);
201 myStdWidget->label_6->hide();
202 myStdWidget->myHexoticNbProc->hide();
204 l->addWidget( myStdWidget, row++, 0, 1, 3 );
205 myStdWidget->onSdModeSelected(SD_MODE_4);
207 myAdvWidget = new SMESH_AdvOptionsWdg( aTabWidget );
210 QWidget* aSmpGroup = new QWidget();
211 lay->addWidget( aSmpGroup );
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);
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);
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);
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"));
243 // Setting a custom delegate for the size column
244 SizeMapsTableWidgetDelegate* delegate = new SizeMapsTableWidgetDelegate();
245 mySmpWidget->tableWidget->setItemDelegateForColumn(SIZE_COL, delegate);
247 // Add the size maps widget to a layout
248 QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup );
249 aSmpLayout->setMargin( 0 );
250 aSmpLayout->addWidget( mySmpWidget);
252 // Viscous Layers tab
253 QWidget* aVLGroup = new QWidget();
254 lay->addWidget( aVLGroup );
256 // Viscous layers widget creation and initialisation
257 myVLWidget = new HexoticPluginGUI_ViscousLayersWidget(aVLGroup);
259 QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
260 QString aSubEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
262 if ( !aMainEntry.isEmpty() )
264 myVLWidget->myFacesWithLayers->SetGeomShapeEntry( aSubEntry, aMainEntry );
265 myVLWidget->myImprintedFaces->SetGeomShapeEntry( aSubEntry, aMainEntry );
269 myVLWidget->labelFacesWithLayers->setVisible(false);
270 myVLWidget->myFacesWithLayers->setVisible(false);
271 myVLWidget->labelImprintedFaces->setVisible(false);
272 myVLWidget->myImprintedFaces->setVisible(false);
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 );
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"));
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 ) ) );
298 void HexoticPluginGUI_HypothesisCreator::onAddLocalSize()
300 int rowCount = mySmpWidget->tableWidget->rowCount();
301 //int columnCount = mySmpWidget->tableWidget->columnCount();
303 // Get the selected object properties
304 GEOM::GEOM_Object_var sizeMapObject = myGeomSelWdg->GetObject< GEOM::GEOM_Object >(0);
305 if (sizeMapObject->_is_nil())
308 std::string entry, shapeName;
309 entry = (std::string) sizeMapObject->GetStudyEntry();
310 shapeName = sizeMapObject->GetName();
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() )
318 // Get the size value
319 double size = mySmpWidget->doubleSpinBox->value();
322 SUIT_MessageBox::critical( mySmpWidget, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) );
326 // Set items for the inserted row
327 insertLocalSizeInWidget( entry, shapeName, size, rowCount );
330 void HexoticPluginGUI_HypothesisCreator::insertLocalSizeInWidget( std::string entry,
331 std::string shapeName,
335 MESSAGE("HexoticPluginGUI_HypothesisCreator:insertLocalSizeInWidget")
336 int columnCount = mySmpWidget->tableWidget->columnCount();
338 // Add a row at the end of the table
339 mySmpWidget->tableWidget->insertRow(row);
342 for (int col = 0; col<columnCount; col++)
344 QTableWidgetItem* item = new QTableWidgetItem();
349 value = QVariant( entry.c_str() );
350 item->setData(Qt::DisplayRole, value );
353 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
354 value = QVariant( shapeName.c_str() );
355 item->setData(Qt::DisplayRole, value );
358 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
359 value = QVariant( size );
360 item->setData(Qt::EditRole, value );
363 mySmpWidget->tableWidget->setItem(row,col,item);
367 void HexoticPluginGUI_HypothesisCreator::onRemoveLocalSize()
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
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 );
380 QList<QTableWidgetSelectionRange>::iterator it;
381 for ( it = ranges.begin(); it != ranges.end(); ++it )
383 for ( int row = it->topRow(); row <= it->bottomRow(); row++ )
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")
389 mySmpWidget->tableWidget->model()->removeRows(it->topRow(), it->rowCount());
394 //=================================================================================
395 // function : resizeEvent [REDEFINED]
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(),
404 Qt::SmoothTransformation));
407 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
409 HexoticHypothesisData data;
410 readParamsFromHypo( data );
414 myName->setText( data.myName );
416 myStdWidget->myMinSize->setCleared(data.myMinSize == 0);
417 if (data.myMinSize == 0)
418 myStdWidget->myMinSize->setText("");
420 myStdWidget->myMinSize->setValue( data.myMinSize );
422 myStdWidget->myMaxSize->setCleared(data.myMaxSize == 0);
423 if (data.myMaxSize == 0)
424 myStdWidget->myMaxSize->setText("");
426 myStdWidget->myMaxSize->setValue( data.myMaxSize );
428 myStdWidget->myHexesMinLevel->setCleared(data.myHexesMinLevel == 0);
429 if (data.myHexesMinLevel == 0)
430 myStdWidget->myHexesMinLevel->setText("");
432 myStdWidget->myHexesMinLevel->setValue( data.myHexesMinLevel );
434 myStdWidget->myHexesMaxLevel->setCleared(data.myHexesMaxLevel == 0);
435 if (data.myHexesMaxLevel == 0)
436 myStdWidget->myHexesMaxLevel->setText("");
438 myStdWidget->myHexesMaxLevel->setValue( data.myHexesMaxLevel );
440 myStdWidget->myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
441 myStdWidget->myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
443 myStdWidget->myHexoticSharpAngleThreshold->setCleared(data.myHexoticSharpAngleThreshold == 0);
444 if (data.myHexoticSharpAngleThreshold == 0)
445 myStdWidget->myHexoticSharpAngleThreshold->setText("");
447 myStdWidget->myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
449 myStdWidget->myHexoticNbProc->setValue( data.myHexoticNbProc );
451 myStdWidget->myHexoticWorkingDir->setText( data.myHexoticWorkingDir );
453 myStdWidget->myHexoticVerbosity->setValue( data.myHexoticVerbosity );
455 myStdWidget->myHexoticMaxMemory->setValue( data.myHexoticMaxMemory );
457 myStdWidget->myHexoticSdMode->setCurrentIndex(data.myHexoticSdMode);
459 myAdvWidget->SetCustomOptions(data.myTextOptions);
461 HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = data.mySizeMaps.begin();
462 for ( int row = 0; it != data.mySizeMaps.end(); it++, row++ )
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();
469 MESSAGE(" Insert local size, entry : "<<entry<<", size : "<<size<<", at row : "<<row)
470 insertLocalSizeInWidget( entry, shapeName, size , row );
473 myVLWidget->myNbLayers->setCleared(data.myNbLayers == 0);
474 if (data.myNbLayers == 0)
475 myVLWidget->myNbLayers->setText("");
477 myVLWidget->myNbLayers->setValue( data.myNbLayers );
479 myVLWidget->myFirstLayerSize->setCleared(data.myFirstLayerSize == 0);
480 if (data.myFirstLayerSize == 0)
481 myVLWidget->myFirstLayerSize->setText("");
483 myVLWidget->myFirstLayerSize->setValue( data.myFirstLayerSize );
485 myVLWidget->myDirection->setCurrentIndex( data.myDirection ? 0 : 1 );
486 myVLWidget->myGrowth->setCleared(data.myGrowth == 0);
487 if (data.myGrowth == 0)
488 myVLWidget->myGrowth->setText("");
490 myVLWidget->myGrowth->setValue( data.myGrowth );
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);
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;
514 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
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 + ";";
531 std::cout << "Data: " << valStr.toStdString() << std::endl;
534 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
536 HexoticHypothesisData data;
537 readParamsFromWidgets( data );
538 storeParamsToHypo( data );
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 + "; ";
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) + ";";
560 // std::cout << "Data: " << valStr.toStdString() << std::endl;
565 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
567 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
568 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
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();
587 HexoticPlugin::HexoticPluginSizeMapsList_var sizeMaps = h->GetSizeMaps();
588 for ( CORBA::ULong i = 0 ; i < sizeMaps->length() ; i++)
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)
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]);
612 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
614 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
615 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
622 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
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() );
638 HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it;
640 for ( it = h_data.mySizeMaps.begin(); it != h_data.mySizeMaps.end(); it++ )
642 h->SetSizeMapEntry( it->first.c_str(), it->second );
643 MESSAGE("STORING Size map : entry "<<it->first.c_str()<<" size : "<<it->second)
645 std::vector< std::string >::const_iterator entry_it;
646 for ( entry_it = mySizeMapsToRemove.begin(); entry_it!= mySizeMapsToRemove.end(); entry_it++ )
648 h->UnsetSizeMapEntry(entry_it->c_str());
652 h->SetNbLayers( h_data.myNbLayers );
653 h->SetFirstLayerSize( h_data.myFirstLayerSize );
654 h->SetDirection( h_data.myDirection );
655 h->SetGrowth( h_data.myGrowth );
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 );
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 );
671 catch(const SALOME::SALOME_Exception& ex)
673 SalomeApp_Tools::QtCatchCorbaException(ex);
679 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
681 h_data.myName = myName ? myName->text() : "";
683 h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
684 h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
686 h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
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();
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();
701 bool ok = readSizeMapsFromWidgets( h_data );
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] );
721 bool HexoticPluginGUI_HypothesisCreator::readSizeMapsFromWidgets( HexoticHypothesisData& h_data ) const
723 int rowCount = mySmpWidget->tableWidget->rowCount();
724 for ( int row = 0; row < rowCount; row++ )
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);
729 // Convert the size to double
731 double size = size_variant.toDouble(&ok);
736 h_data.mySizeMaps[ entry ] = size;
737 MESSAGE("READING Size map from WIDGET: entry "<<entry<<" size : "<<size)
742 GEOM::GEOM_Object_var HexoticPluginGUI_HypothesisCreator::entryToObject( std::string entry) const
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);
754 QString HexoticPluginGUI_HypothesisCreator::caption() const
756 return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
759 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
761 QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
762 return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
765 QString HexoticPluginGUI_HypothesisCreator::type() const
767 return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
770 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
772 return "hexotic_hypo_page.html";
775 void HexoticPluginGUI_HypothesisCreator::onTabChanged(int i)
777 myVLWidget->myFacesWithLayers->ShowPreview( i == VL_TAB );
778 myVLWidget->myImprintedFaces->ShowPreview( false );