1 // Copyright (C) 2009-2024 CEA, EDF
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
20 // HEXABLOCKPlugin GUI: GUI for plugged-in mesher HEXABLOCKPlugin
21 // File : HEXABLOCKPluginGUI_HypothesisCreator.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
23 // Module : HEXABLOCKPlugin
26 #include "HEXABLOCKPluginGUI_HypothesisCreator.h"
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_FileDlg.h>
35 #include <SalomeApp_Tools.h>
36 #include <SalomeApp_TypeFilter.h>
41 #include <QVBoxLayout>
42 #include <QGridLayout>
47 #include <QPushButton>
50 #include <QTableWidget>
51 #include <QStandardItemModel>
52 #include <QStandardItem>
53 #include <QHeaderView>
54 #include <QModelIndexList>
57 #include <utilities.h>
67 // Enforced vertices array columns
76 // Enforced vertices inputs
92 #elif !defined(__APPLE__)
93 #include <sys/sysinfo.h>
96 int maxAvailableMemory()
99 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
100 MEMORYSTATUSEX statex;
101 statex.dwLength = sizeof (statex);
102 int err = GlobalMemoryStatusEx (&statex);
105 statex.ullTotalPhys / 1024 / 1024 +
106 statex.ullTotalPageFile / 1024 / 1024 +
107 statex.ullTotalVirtual / 1024 / 1024;
108 return (int) ( 0.7 * totMB );
110 #elif !defined(__APPLE__)
112 int err = sysinfo( &si );
115 si.totalram * si.mem_unit / 1024 / 1024 +
116 si.totalswap * si.mem_unit / 1024 / 1024 ;
117 return (int) ( 0.7 * totMB );
124 class QDoubleValidator;
127 // BEGIN DoubleLineEditDelegate
130 DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent)
131 : QItemDelegate(parent)
135 QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent,
136 const QStyleOptionViewItem &/* option */,
137 const QModelIndex &/* index */) const
139 QLineEdit *editor = new QLineEdit(parent);
140 editor->setValidator(new QDoubleValidator(parent));
145 void DoubleLineEditDelegate::setEditorData(QWidget *editor,
146 const QModelIndex &index) const
148 QString value = index.model()->data(index, Qt::EditRole).toString();
150 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
151 lineEdit->setText(value);
154 void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
155 const QModelIndex &index) const
157 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
159 double value = lineEdit->text().toDouble(&ok);
162 model->setData(index, value, Qt::EditRole);
163 MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")");
167 void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor,
168 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
170 editor->setGeometry(option.rect);
174 // END DoubleLineEditDelegate
177 HEXABLOCKPluginGUI_HypothesisCreator::HEXABLOCKPluginGUI_HypothesisCreator( const QString& theHypType )
178 : SMESHGUI_GenericHypothesisCreator( theHypType )
182 HEXABLOCKPluginGUI_HypothesisCreator::~HEXABLOCKPluginGUI_HypothesisCreator()
186 QFrame* HEXABLOCKPluginGUI_HypothesisCreator::buildFrame()
188 QFrame* fr = new QFrame( 0 );
189 QVBoxLayout* lay = new QVBoxLayout( fr );
191 lay->setSpacing( 0 );
194 QTabWidget* tab = new QTabWidget( fr );
195 tab->setTabShape( QTabWidget::Rounded );
196 tab->setTabPosition( QTabWidget::North );
197 lay->addWidget( tab );
200 myStdGroup = new QWidget();
201 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
202 aStdLayout->setSpacing( 6 );
203 aStdLayout->setMargin( 11 );
209 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
210 myName = new QLineEdit( myStdGroup );
211 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
214 myToMeshHolesCheck = new QCheckBox( tr( "HEXABLOCK_TO_MESH_HOLES" ), myStdGroup );
215 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
217 aStdLayout->addWidget( new QLabel( tr( "HEXABLOCK_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 );
218 myOptimizationLevelCombo = new QComboBox( myStdGroup );
219 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
222 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" ) << tr( "LEVEL_STRONG" );
223 myOptimizationLevelCombo->addItems( types );
225 aStdLayout->setRowStretch( row, 5 );
227 // advanced parameters
228 myAdvGroup = new QWidget();
229 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
230 anAdvLayout->setSpacing( 6 );
231 anAdvLayout->setMargin( 11 );
233 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
234 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
235 myMaximumMemorySpin->setMinimum( 1 );
236 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
237 myMaximumMemorySpin->setSingleStep( 10 );
238 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
240 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
241 myInitialMemorySpin = new QSpinBox( myAdvGroup );
242 myInitialMemorySpin->setMinimum( 1 );
243 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
244 myInitialMemorySpin->setSingleStep( 10 );
245 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
247 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
248 myWorkingDir = new QLineEdit( myAdvGroup );
249 //myWorkingDir->setReadOnly( true );
250 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
251 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
253 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
255 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
256 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
257 myVerboseLevelSpin->setMinimum( 0 );
258 myVerboseLevelSpin->setMaximum( 10 );
259 myVerboseLevelSpin->setSingleStep( 1 );
261 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
263 myRemoveInitialCentralPointCheck = new QCheckBox( tr( "NO_INITIAL_CENTRAL_POINT" ), myAdvGroup );
265 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
267 myFEMCorrectionCheck = new QCheckBox( tr( "FEM_CORRECTION" ), myAdvGroup );
269 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
270 myTextOption = new QLineEdit( myAdvGroup );
272 anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 );
273 anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 );
274 anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 );
275 anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 );
276 anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 );
277 anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 );
278 anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 );
279 anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 );
280 anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 );
281 anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 );
282 anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 );
283 anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 );
284 anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 );
285 anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, 6, 0, 1, 4 );
286 anAdvLayout->addWidget( myBoundaryRecoveryCheck, 7, 0, 1, 4 );
287 anAdvLayout->addWidget( myFEMCorrectionCheck, 8, 0, 1, 4 );
288 anAdvLayout->addWidget( aTextOptionLabel, 9, 0, 1, 1 );
289 anAdvLayout->addWidget( myTextOption, 9, 1, 1, 2 );
291 // Size Maps parameters
292 myEnfGroup = new QWidget();
293 QGridLayout* anSmpLayout = new QGridLayout(myEnfGroup);
295 mySmpModel = new QStandardItemModel(0, ENF_VER_NB_COLUMNS);
296 myEnforcedTableView = new QTableView(myEnfGroup);
297 myEnforcedTableView->setModel(mySmpModel);
298 myEnforcedTableView->setSortingEnabled(true);
299 myEnforcedTableView->setItemDelegateForColumn(ENF_VER_SIZE_COLUMN,new DoubleLineEditDelegate(this));
300 anSmpLayout->addWidget(myEnforcedTableView, 1, 0, 9, 1);
301 QStringList enforcedHeaders;
302 enforcedHeaders << tr( "HEXABLOCK_ENF_VER_X_COLUMN" )<< tr( "HEXABLOCK_ENF_VER_Y_COLUMN" ) << tr( "HEXABLOCK_ENF_VER_Z_COLUMN" ) << tr( "HEXABLOCK_ENF_VER_SIZE_COLUMN" );
303 mySmpModel->setHorizontalHeaderLabels(enforcedHeaders);
304 myEnforcedTableView->setAlternatingRowColors(true);
305 myEnforcedTableView->verticalHeader()->hide();
306 myEnforcedTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
308 QLabel* myXCoordLabel = new QLabel( tr( "HEXABLOCK_ENF_VER_X_LABEL" ), myEnfGroup );
309 anSmpLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
310 myXCoord = new QLineEdit(myEnfGroup);
311 myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
312 anSmpLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
313 QLabel* myYCoordLabel = new QLabel( tr( "HEXABLOCK_ENF_VER_Y_LABEL" ), myEnfGroup );
314 anSmpLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
315 myYCoord = new QLineEdit(myEnfGroup);
316 myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
317 anSmpLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
318 QLabel* myZCoordLabel = new QLabel( tr( "HEXABLOCK_ENF_VER_Z_LABEL" ), myEnfGroup );
319 anSmpLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
320 myZCoord = new QLineEdit(myEnfGroup);
321 myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
322 anSmpLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
323 QLabel* mySizeLabel = new QLabel( tr( "HEXABLOCK_ENF_VER_SIZE_LABEL" ), myEnfGroup );
324 anSmpLayout->addWidget(mySizeLabel, ENF_VER_SIZE, 1, 1, 1);
325 mySizeValue = new QLineEdit(myEnfGroup);
326 mySizeValue->setValidator(new QDoubleValidator(myEnfGroup));
327 anSmpLayout->addWidget(mySizeValue, ENF_VER_SIZE, 2, 1, 1);
329 addVertexButton = new QPushButton(tr("HEXABLOCK_ENF_VER_VERTEX"),myEnfGroup);
330 anSmpLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
331 addVertexButton->setEnabled(false);
333 QFrame *line = new QFrame(myEnfGroup);
334 line->setFrameShape(QFrame::HLine);
335 line->setFrameShadow(QFrame::Sunken);
336 anSmpLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
338 removeVertexButton = new QPushButton(tr("HEXABLOCK_ENF_VER_REMOVE"),myEnfGroup);
339 anSmpLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
342 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
343 tab->insertTab( ADV_TAB, myAdvGroup, tr( "HEXABLOCK_ADV_ARGS" ) );
344 tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "HEXABLOCK_ENFORCED_VERTICES" ) );
345 tab->setCurrentIndex( STD_TAB );
348 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
349 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
350 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
351 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
352 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
353 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
354 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
355 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
356 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
357 connect( addVertexButton, SIGNAL( clicked() ), this, SLOT( onVertexBtnClicked() ) );
358 connect( removeVertexButton, SIGNAL( clicked() ), this, SLOT( onRemoveVertexBtnClicked() ) );
365 bool HEXABLOCKPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, double z) const
367 const int rowCount = mySmpModel->rowCount();
368 for (int i=0 ; i < rowCount ; i++) {
369 double myX = mySmpModel->data(mySmpModel->index(i, ENF_VER_X_COLUMN)).toDouble();
371 // MESSAGE("Found x value " << x << " at row " << i);
372 double myY = mySmpModel->data(mySmpModel->index(i, ENF_VER_Y_COLUMN)).toDouble();
374 // MESSAGE("Found y value " << y << " at row " << i);
375 double myZ = mySmpModel->data(mySmpModel->index(i, ENF_VER_Z_COLUMN)).toDouble();
377 MESSAGE("Found x value " << x << " at row " << i);
378 MESSAGE("Found y value " << y << " at row " << i);
379 MESSAGE("Found z value " << z << " at row " << i);
386 // MESSAGE("Not found x,y,z values: " << x << " " << y << " " << z);
390 bool HEXABLOCKPluginGUI_HypothesisCreator::checkVertexIsDefined()
392 bool val = (!myXCoord->text().isEmpty())&&(!myYCoord->text().isEmpty())&&(!myZCoord->text().isEmpty())&&(!mySizeValue->text().isEmpty());
393 bool isDefined = val;
395 isDefined = ! smpVertexExists(myXCoord->text().toDouble(),myYCoord->text().toDouble(),myZCoord->text().toDouble());
397 emit vertexDefined(isDefined);
401 void HEXABLOCKPluginGUI_HypothesisCreator::onVertexBtnClicked()
403 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::onVertexBtnClicked()");
404 const int row = mySmpModel->rowCount() ;
405 double x = myXCoord->text().toDouble();
406 double y = myYCoord->text().toDouble();
407 double z = myZCoord->text().toDouble();
408 double size = mySizeValue->text().toDouble();
410 if (smpVertexExists(x,y,z)) return;
412 // double size = 10.0;
414 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
415 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
416 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
418 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
419 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
420 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
422 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
423 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
424 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
425 // ENF_VER_SIZE_COLUMN
426 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
427 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) );
429 myEnforcedTableView->clearSelection();
430 myEnforcedTableView->scrollTo( mySmpModel->item( row, ENF_VER_SIZE_COLUMN )->index() );
431 checkVertexIsDefined();
434 void HEXABLOCKPluginGUI_HypothesisCreator::onRemoveVertexBtnClicked()
436 QList<int> selectedRows;
437 QList<QModelIndex> selectedIndex = myEnforcedTableView->selectionModel()->selectedIndexes();
440 foreach( index, selectedIndex ) {
442 if ( !selectedRows.contains( row ) )
443 selectedRows.append( row );
445 qSort( selectedRows );
446 QListIterator<int> it( selectedRows );
448 while ( it.hasPrevious() ) {
450 MESSAGE("delete row #"<< row);
451 mySmpModel->removeRow(row );
453 myEnforcedTableView->clearSelection();
455 void HEXABLOCKPluginGUI_HypothesisCreator::onDirBtnClicked()
457 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
458 if ( !dir.isEmpty() )
459 myWorkingDir->setText( dir );
462 void HEXABLOCKPluginGUI_HypothesisCreator::updateWidgets()
464 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
465 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
466 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
467 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
470 bool HEXABLOCKPluginGUI_HypothesisCreator::checkParams(QString& msg) const
472 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::checkParams");
474 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
475 SUIT_MessageBox::warning( dlg(),
476 tr( "SMESH_WRN_WARNING" ),
477 tr( "HEXABLOCK_PERMISSION_DENIED" ) );
484 void HEXABLOCKPluginGUI_HypothesisCreator::retrieveParams() const
486 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::retrieveParams");
487 HEXABLOCKHypothesisData data;
488 readParamsFromHypo( data );
491 myName->setText( data.myName );
493 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
494 myOptimizationLevelCombo ->setCurrentIndex( data.myOptimizationLevel );
495 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
496 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
497 myMaximumMemorySpin->minimum() ));
498 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
499 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
500 myInitialMemorySpin->minimum() ));
501 myWorkingDir ->setText ( data.myWorkingDir );
502 myKeepFiles ->setChecked ( data.myKeepFiles );
503 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
504 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
505 myRemoveInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint );
506 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
507 myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection );
508 myTextOption ->setText ( data.myTextOption );
510 TEnforcedVertexValues::const_iterator it;
512 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
514 double x = it->at(0);
515 double y = it->at(1);
516 double z = it->at(2);
517 double size = it->at(3);
519 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
520 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
521 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
523 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
524 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
525 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
527 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
528 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
529 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
530 // ENF_VER_SIZE_COLUMN
531 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
532 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) );
534 MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size);
538 HEXABLOCKPluginGUI_HypothesisCreator* that = (HEXABLOCKPluginGUI_HypothesisCreator*)this;
539 that->updateWidgets();
542 QString HEXABLOCKPluginGUI_HypothesisCreator::storeParams() const
544 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::storeParams");
545 HEXABLOCKHypothesisData data;
546 readParamsFromWidgets( data );
547 storeParamsToHypo( data );
551 if ( !data.myBoundaryRecovery )
552 valStr = "-c " + QString::number( !data.myToMeshHoles );
554 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
555 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
557 valStr += level[ data.myOptimizationLevel ];
559 if ( data.myMaximumMemory > 0 ) {
561 valStr += QString::number( data.myMaximumMemory );
563 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
565 valStr += QString::number( data.myInitialMemory );
568 valStr += QString::number( data.myVerboseLevel );
570 if ( !data.myToCreateNewNodes )
573 if ( data.myRemoveInitialCentralPoint )
574 valStr += " -no_initial_central_point";
576 if ( data.myBoundaryRecovery )
579 if ( data.myFEMCorrection )
583 valStr += data.myTextOption;
585 valStr += " #BEGIN ENFORCED VERTICES#";
586 // Add size map parameters storage
587 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
589 double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble();
590 double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble();
591 double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble();
592 double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble();
593 valStr += QString::number( x );
595 valStr += QString::number( y );
597 valStr += QString::number( z );
599 valStr += QString::number( size );
600 if (i!=mySmpModel->rowCount()-1)
603 valStr += " #END ENFORCED VERTICES#";
604 MESSAGE(valStr.toStdString());
608 bool HEXABLOCKPluginGUI_HypothesisCreator::readParamsFromHypo( HEXABLOCKHypothesisData& h_data ) const
610 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::readParamsFromHypo");
611 HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var h =
612 HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow( initParamsHypothesis() );
614 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
615 h_data.myName = isCreation() && data ? hypName() : "";
618 h_data.myToMeshHoles = h->GetToMeshHoles();
619 h_data.myMaximumMemory = h->GetMaximumMemory();
620 h_data.myInitialMemory = h->GetInitialMemory();
621 h_data.myInitialMemory = h->GetInitialMemory();
622 h_data.myOptimizationLevel = h->GetOptimizationLevel();
623 h_data.myKeepFiles = h->GetKeepFiles();
624 h_data.myWorkingDir = h->GetWorkingDirectory();
625 h_data.myVerboseLevel = h->GetVerboseLevel();
626 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
627 h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint();
628 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
629 h_data.myFEMCorrection = h->GetFEMCorrection();
630 h_data.myTextOption = h->GetTextOption();
632 HEXABLOCKPlugin::HEXABLOCKEnforcedVertexList_var vertices = h->GetEnforcedVertices();
633 MESSAGE("vertices->length(): " << vertices->length());
634 h_data.myEnforcedVertices.clear();
635 for (int i=0 ; i<vertices->length() ; i++) {
636 HEXABLOCKEnforcedVertex myVertex;
637 myVertex.push_back(vertices[i].x);
638 myVertex.push_back(vertices[i].y);
639 myVertex.push_back(vertices[i].z);
640 myVertex.push_back(vertices[i].size);
641 MESSAGE("Add enforced vertex ("<< myVertex[0] << ","<< myVertex[1] << ","<< myVertex[2] << ") ="<< myVertex[3]);
642 h_data.myEnforcedVertices.push_back(myVertex);
649 bool HEXABLOCKPluginGUI_HypothesisCreator::storeParamsToHypo( const HEXABLOCKHypothesisData& h_data ) const
651 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::storeParamsToHypo");
652 HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var h =
653 HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow( hypothesis() );
659 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
662 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
663 h->SetToMeshHoles ( h_data.myToMeshHoles );
664 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
665 h->SetMaximumMemory ( h_data.myMaximumMemory );
666 if ( h->GetInitialMemory() != h_data.myInitialMemory )
667 h->SetInitialMemory ( h_data.myInitialMemory );
668 if ( h->GetInitialMemory() != h_data.myInitialMemory )
669 h->SetInitialMemory ( h_data.myInitialMemory );
670 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
671 h->SetOptimizationLevel( h_data.myOptimizationLevel );
672 if ( h->GetKeepFiles() != h_data.myKeepFiles )
673 h->SetKeepFiles ( h_data.myKeepFiles );
674 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
675 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
676 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
677 h->SetVerboseLevel ( h_data.myVerboseLevel );
678 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
679 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
680 if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
681 h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
682 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
683 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
684 if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
685 h->SetFEMCorrection( h_data.myFEMCorrection );
686 if ( h->GetTextOption() != h_data.myTextOption )
687 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
689 int nbVertex = (int) h_data.myEnforcedVertices.size();
690 HEXABLOCKPlugin::HEXABLOCKEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
691 int nbVertexHyp = vertexHyp->length();
693 MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices");
694 MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp);
696 // Some vertices were removed
697 if (nbVertex < nbVertexHyp) {
698 // if (nbVertex == 0)
699 // h->ClearEnforcedVertices();
701 // iterate over vertices of hypo
702 for(int i = 0 ; i <nbVertexHyp ; i++) {
703 double x = vertexHyp[i].x;
704 double y = vertexHyp[i].y;
705 double z = vertexHyp[i].z;
707 if (!smpVertexExists(x,y,z))
708 h->RemoveEnforcedVertex(x,y,z);
713 TEnforcedVertexValues::const_iterator it;
714 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
715 double x = it->at(0);
716 double y = it->at(1);
717 double z = it->at(2);
718 double size = it->at(3);
719 MESSAGE("(" << x << ", "
725 mySize = h->GetEnforcedVertex(x,y,z);
726 MESSAGE("Old size: " << mySize);
727 if (mySize != size) {
728 MESSAGE("Setting new size: " << size);
729 h->SetEnforcedVertex(x,y,z,size);
733 MESSAGE("Setting new size: " << size);
734 h->SetEnforcedVertex(x,y,z,size);
739 catch ( const SALOME::SALOME_Exception& ex )
741 SalomeApp_Tools::QtCatchCorbaException( ex );
747 bool HEXABLOCKPluginGUI_HypothesisCreator::readParamsFromWidgets( HEXABLOCKHypothesisData& h_data ) const
749 MESSAGE("HEXABLOCKPluginGUI_HypothesisCreator::readParamsFromWidgets");
750 h_data.myName = myName ? myName->text() : "";
751 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
752 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
753 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
754 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
755 h_data.myKeepFiles = myKeepFiles->isChecked();
756 h_data.myWorkingDir = myWorkingDir->text().trimmed();
757 h_data.myVerboseLevel = myVerboseLevelSpin->value();
758 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
759 h_data.myRemoveInitialCentralPoint = myRemoveInitialCentralPointCheck->isChecked();
760 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
761 h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked();
762 h_data.myTextOption = myTextOption->text();
763 h_data.myEnforcedVertices.clear();
765 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
766 HEXABLOCKEnforcedVertex myVertex;
767 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble());
768 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble());
769 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble());
770 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble());
771 MESSAGE("Add new enforced vertex (" << myVertex[0] << ", "
772 << myVertex[1] << ", "
773 << myVertex[2] << ") = "
775 h_data.myEnforcedVertices.push_back(myVertex);
781 QString HEXABLOCKPluginGUI_HypothesisCreator::caption() const
783 return tr( "HEXABLOCK_TITLE" );
786 QPixmap HEXABLOCKPluginGUI_HypothesisCreator::icon() const
788 return SUIT_Session::session()->resourceMgr()->loadPixmap( "HEXABLOCKPlugin", tr( "ICON_DLG_HEXABLOCK_PARAMETERS" ) );
791 QString HEXABLOCKPluginGUI_HypothesisCreator::type() const
793 return tr( "HEXABLOCK_HYPOTHESIS" );
796 QString HEXABLOCKPluginGUI_HypothesisCreator::helpPage() const
798 return "HEXABLOCK_hypo_page.html";
801 //=============================================================================
802 /*! GetHypothesisCreator
805 //=============================================================================
808 HEXABLOCKPLUGINGUI_EXPORT
809 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
811 if ( aHypType == "HEXABLOCK_Parameters" )
812 return new HEXABLOCKPluginGUI_HypothesisCreator( aHypType );