1 // Copyright (C) 2004-2010 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.
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 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 // File : GHS3DPluginGUI_HypothesisCreator.cxx
22 // Author : Michael Zorin
23 // Module : GHS3DPlugin
26 #include "GHS3DPluginGUI_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>
66 // Enforced vertices array columns
75 // Enforced vertices inputs
92 #include <sys/sysinfo.h>
95 int maxAvailableMemory()
98 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
99 MEMORYSTATUSEX statex;
100 statex.dwLength = sizeof (statex);
101 int err = GlobalMemoryStatusEx (&statex);
104 statex.ullTotalPhys / 1024 / 1024 +
105 statex.ullTotalPageFile / 1024 / 1024 +
106 statex.ullTotalVirtual / 1024 / 1024;
107 return (int) ( 0.7 * totMB );
111 int err = sysinfo( &si );
114 si.totalram * si.mem_unit / 1024 / 1024 +
115 si.totalswap * si.mem_unit / 1024 / 1024 ;
116 return (int) ( 0.7 * totMB );
123 class QDoubleValidator;
126 // BEGIN DoubleLineEditDelegate
129 DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent)
130 : QItemDelegate(parent)
134 QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent,
135 const QStyleOptionViewItem &/* option */,
136 const QModelIndex &/* index */) const
138 QLineEdit *editor = new QLineEdit(parent);
139 editor->setValidator(new QDoubleValidator(parent));
144 void DoubleLineEditDelegate::setEditorData(QWidget *editor,
145 const QModelIndex &index) const
147 QString value = index.model()->data(index, Qt::EditRole).toString();
149 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
150 lineEdit->setText(value);
153 void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
154 const QModelIndex &index) const
156 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
158 double value = lineEdit->text().toDouble(&ok);
161 model->setData(index, value, Qt::EditRole);
162 MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")");
166 void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor,
167 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
169 editor->setGeometry(option.rect);
173 // END DoubleLineEditDelegate
176 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
177 : SMESHGUI_GenericHypothesisCreator( theHypType )
181 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
185 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
187 QFrame* fr = new QFrame( 0 );
188 QVBoxLayout* lay = new QVBoxLayout( fr );
190 lay->setSpacing( 0 );
193 QTabWidget* tab = new QTabWidget( fr );
194 tab->setTabShape( QTabWidget::Rounded );
195 tab->setTabPosition( QTabWidget::North );
196 lay->addWidget( tab );
199 myStdGroup = new QWidget();
200 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
201 aStdLayout->setSpacing( 6 );
202 aStdLayout->setMargin( 11 );
208 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
209 myName = new QLineEdit( myStdGroup );
210 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
213 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
214 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
216 aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 );
217 myOptimizationLevelCombo = new QComboBox( myStdGroup );
218 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
221 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" ) << tr( "LEVEL_STRONG" );
222 myOptimizationLevelCombo->addItems( types );
224 aStdLayout->setRowStretch( row, 5 );
226 // advanced parameters
227 myAdvGroup = new QWidget();
228 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
229 anAdvLayout->setSpacing( 6 );
230 anAdvLayout->setMargin( 11 );
232 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
233 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
234 myMaximumMemorySpin->setMinimum( 1 );
235 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
236 myMaximumMemorySpin->setSingleStep( 10 );
237 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
239 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
240 myInitialMemorySpin = new QSpinBox( myAdvGroup );
241 myInitialMemorySpin->setMinimum( 1 );
242 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
243 myInitialMemorySpin->setSingleStep( 10 );
244 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
246 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
247 myWorkingDir = new QLineEdit( myAdvGroup );
248 //myWorkingDir->setReadOnly( true );
249 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
250 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
252 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
254 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
255 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
256 myVerboseLevelSpin->setMinimum( 0 );
257 myVerboseLevelSpin->setMaximum( 10 );
258 myVerboseLevelSpin->setSingleStep( 1 );
260 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
262 myRemoveInitialCentralPointCheck = new QCheckBox( tr( "NO_INITIAL_CENTRAL_POINT" ), myAdvGroup );
264 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
266 myFEMCorrectionCheck = new QCheckBox( tr( "FEM_CORRECTION" ), myAdvGroup );
268 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
269 myTextOption = new QLineEdit( myAdvGroup );
271 anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 );
272 anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 );
273 anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 );
274 anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 );
275 anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 );
276 anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 );
277 anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 );
278 anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 );
279 anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 );
280 anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 );
281 anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 );
282 anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 );
283 anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 );
284 anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, 6, 0, 1, 4 );
285 anAdvLayout->addWidget( myBoundaryRecoveryCheck, 7, 0, 1, 4 );
286 anAdvLayout->addWidget( myFEMCorrectionCheck, 8, 0, 1, 4 );
287 anAdvLayout->addWidget( aTextOptionLabel, 9, 0, 1, 1 );
288 anAdvLayout->addWidget( myTextOption, 9, 1, 1, 2 );
290 // Size Maps parameters
291 myEnfGroup = new QWidget();
292 QGridLayout* anSmpLayout = new QGridLayout(myEnfGroup);
294 mySmpModel = new QStandardItemModel(0, ENF_VER_NB_COLUMNS);
295 myEnforcedTableView = new QTableView(myEnfGroup);
296 myEnforcedTableView->setModel(mySmpModel);
297 myEnforcedTableView->setSortingEnabled(true);
298 myEnforcedTableView->setItemDelegateForColumn(ENF_VER_SIZE_COLUMN,new DoubleLineEditDelegate(this));
299 anSmpLayout->addWidget(myEnforcedTableView, 1, 0, 9, 1);
300 QStringList enforcedHeaders;
301 enforcedHeaders << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" ) << tr( "GHS3D_ENF_VER_SIZE_COLUMN" );
302 mySmpModel->setHorizontalHeaderLabels(enforcedHeaders);
303 myEnforcedTableView->setAlternatingRowColors(true);
304 myEnforcedTableView->verticalHeader()->hide();
305 myEnforcedTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
307 QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_X_LABEL" ), myEnfGroup );
308 anSmpLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
309 myXCoord = new QLineEdit(myEnfGroup);
310 myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
311 anSmpLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
312 QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Y_LABEL" ), myEnfGroup );
313 anSmpLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
314 myYCoord = new QLineEdit(myEnfGroup);
315 myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
316 anSmpLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
317 QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Z_LABEL" ), myEnfGroup );
318 anSmpLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
319 myZCoord = new QLineEdit(myEnfGroup);
320 myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
321 anSmpLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
322 QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_VER_SIZE_LABEL" ), myEnfGroup );
323 anSmpLayout->addWidget(mySizeLabel, ENF_VER_SIZE, 1, 1, 1);
324 mySizeValue = new QLineEdit(myEnfGroup);
325 mySizeValue->setValidator(new QDoubleValidator(myEnfGroup));
326 anSmpLayout->addWidget(mySizeValue, ENF_VER_SIZE, 2, 1, 1);
328 addVertexButton = new QPushButton(tr("GHS3D_ENF_VER_VERTEX"),myEnfGroup);
329 anSmpLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
330 addVertexButton->setEnabled(false);
332 QFrame *line = new QFrame(myEnfGroup);
333 line->setFrameShape(QFrame::HLine);
334 line->setFrameShadow(QFrame::Sunken);
335 anSmpLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
337 removeVertexButton = new QPushButton(tr("GHS3D_ENF_VER_REMOVE"),myEnfGroup);
338 anSmpLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
341 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
342 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
343 tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
344 tab->setCurrentIndex( STD_TAB );
347 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
348 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
349 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
350 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
351 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
352 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
353 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
354 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
355 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
356 connect( addVertexButton, SIGNAL( clicked() ), this, SLOT( onVertexBtnClicked() ) );
357 connect( removeVertexButton, SIGNAL( clicked() ), this, SLOT( onRemoveVertexBtnClicked() ) );
364 bool GHS3DPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, double z) const
366 const int rowCount = mySmpModel->rowCount();
367 for (int i=0 ; i < rowCount ; i++) {
368 double myX = mySmpModel->data(mySmpModel->index(i, ENF_VER_X_COLUMN)).toDouble();
370 // MESSAGE("Found x value " << x << " at row " << i);
371 double myY = mySmpModel->data(mySmpModel->index(i, ENF_VER_Y_COLUMN)).toDouble();
373 // MESSAGE("Found y value " << y << " at row " << i);
374 double myZ = mySmpModel->data(mySmpModel->index(i, ENF_VER_Z_COLUMN)).toDouble();
376 MESSAGE("Found x value " << x << " at row " << i);
377 MESSAGE("Found y value " << y << " at row " << i);
378 MESSAGE("Found z value " << z << " at row " << i);
384 // MESSAGE("Not found x,y,z values: " << x << " " << y << " " << z);
388 bool GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined()
390 bool val = (!myXCoord->text().isEmpty())&&(!myYCoord->text().isEmpty())&&(!myZCoord->text().isEmpty())&&(!mySizeValue->text().isEmpty());
391 bool isDefined = val;
393 isDefined = ! smpVertexExists(myXCoord->text().toDouble(),myYCoord->text().toDouble(),myZCoord->text().toDouble());
395 emit vertexDefined(isDefined);
399 void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()
401 MESSAGE("GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()");
402 const int row = mySmpModel->rowCount() ;
403 double x = myXCoord->text().toDouble();
404 double y = myYCoord->text().toDouble();
405 double z = myZCoord->text().toDouble();
406 double size = mySizeValue->text().toDouble();
408 if (smpVertexExists(x,y,z)) return;
410 // double size = 10.0;
412 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
413 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
414 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
416 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
417 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
418 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
420 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
421 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
422 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
423 // ENF_VER_SIZE_COLUMN
424 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
425 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) );
427 myEnforcedTableView->clearSelection();
428 myEnforcedTableView->scrollTo( mySmpModel->item( row, ENF_VER_SIZE_COLUMN )->index() );
429 checkVertexIsDefined();
432 void GHS3DPluginGUI_HypothesisCreator::onRemoveVertexBtnClicked()
434 QList<int> selectedRows;
435 QList<QModelIndex> selectedIndex = myEnforcedTableView->selectionModel()->selectedIndexes();
438 foreach( index, selectedIndex ) {
440 if ( !selectedRows.contains( row ) )
441 selectedRows.append( row );
443 qSort( selectedRows );
444 QListIterator<int> it( selectedRows );
446 while ( it.hasPrevious() ) {
448 MESSAGE("delete row #"<< row);
449 mySmpModel->removeRow(row );
451 myEnforcedTableView->clearSelection();
453 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
455 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
456 if ( !dir.isEmpty() )
457 myWorkingDir->setText( dir );
460 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
462 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
463 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
464 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
465 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
468 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
470 MESSAGE("GHS3DPluginGUI_HypothesisCreator::checkParams");
472 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
473 SUIT_MessageBox::warning( dlg(),
474 tr( "SMESH_WRN_WARNING" ),
475 tr( "GHS3D_PERMISSION_DENIED" ) );
482 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
484 MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams");
485 GHS3DHypothesisData data;
486 readParamsFromHypo( data );
489 myName->setText( data.myName );
491 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
492 myOptimizationLevelCombo ->setCurrentIndex( data.myOptimizationLevel );
493 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
494 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
495 myMaximumMemorySpin->minimum() ));
496 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
497 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
498 myInitialMemorySpin->minimum() ));
499 myWorkingDir ->setText ( data.myWorkingDir );
500 myKeepFiles ->setChecked ( data.myKeepFiles );
501 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
502 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
503 myRemoveInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint );
504 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
505 myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection );
506 myTextOption ->setText ( data.myTextOption );
508 TEnforcedVertexValues::const_iterator it;
510 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
512 double x = it->at(0);
513 double y = it->at(1);
514 double z = it->at(2);
515 double size = it->at(3);
517 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
518 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
519 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
521 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
522 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
523 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
525 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
526 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
527 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
528 // ENF_VER_SIZE_COLUMN
529 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
530 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) );
532 MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size);
536 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
537 that->updateWidgets();
540 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
542 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParams");
543 GHS3DHypothesisData data;
544 readParamsFromWidgets( data );
545 storeParamsToHypo( data );
549 if ( !data.myBoundaryRecovery )
550 valStr = "-c " + QString::number( !data.myToMeshHoles );
552 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
553 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
555 valStr += level[ data.myOptimizationLevel ];
557 if ( data.myMaximumMemory > 0 ) {
559 valStr += QString::number( data.myMaximumMemory );
561 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
563 valStr += QString::number( data.myInitialMemory );
566 valStr += QString::number( data.myVerboseLevel );
568 if ( !data.myToCreateNewNodes )
571 if ( data.myRemoveInitialCentralPoint )
572 valStr += " -no_initial_central_point";
574 if ( data.myBoundaryRecovery )
577 if ( data.myFEMCorrection )
581 valStr += data.myTextOption;
583 valStr += " #BEGIN ENFORCED VERTICES#";
584 // Add size map parameters storage
585 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
587 double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble();
588 double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble();
589 double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble();
590 double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble();
591 valStr += QString::number( x );
593 valStr += QString::number( y );
595 valStr += QString::number( z );
597 valStr += QString::number( size );
598 if (i!=mySmpModel->rowCount()-1)
601 valStr += " #END ENFORCED VERTICES#";
602 MESSAGE(valStr.toStdString());
606 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
608 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo");
609 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
610 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
612 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
613 h_data.myName = isCreation() && data ? hypName() : "";
615 h_data.myToMeshHoles = h->GetToMeshHoles();
616 h_data.myMaximumMemory = h->GetMaximumMemory();
617 h_data.myInitialMemory = h->GetInitialMemory();
618 h_data.myInitialMemory = h->GetInitialMemory();
619 h_data.myOptimizationLevel = h->GetOptimizationLevel();
620 h_data.myKeepFiles = h->GetKeepFiles();
621 h_data.myWorkingDir = h->GetWorkingDirectory();
622 h_data.myVerboseLevel = h->GetVerboseLevel();
623 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
624 h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint();
625 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
626 h_data.myFEMCorrection = h->GetFEMCorrection();
627 h_data.myTextOption = h->GetTextOption();
629 GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
630 MESSAGE("vertices->length(): " << vertices->length());
631 h_data.myEnforcedVertices.clear();
632 for (int i=0 ; i<vertices->length() ; i++) {
633 GHS3DEnforcedVertex myVertex;
634 myVertex.push_back(vertices[i].x);
635 myVertex.push_back(vertices[i].y);
636 myVertex.push_back(vertices[i].z);
637 myVertex.push_back(vertices[i].size);
638 MESSAGE("Add enforced vertex ("<< myVertex[0] << ","<< myVertex[1] << ","<< myVertex[2] << ") ="<< myVertex[3]);
639 h_data.myEnforcedVertices.push_back(myVertex);
644 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
646 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo");
647 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
648 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
654 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
656 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
657 h->SetToMeshHoles ( h_data.myToMeshHoles );
658 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
659 h->SetMaximumMemory ( h_data.myMaximumMemory );
660 if ( h->GetInitialMemory() != h_data.myInitialMemory )
661 h->SetInitialMemory ( h_data.myInitialMemory );
662 if ( h->GetInitialMemory() != h_data.myInitialMemory )
663 h->SetInitialMemory ( h_data.myInitialMemory );
664 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
665 h->SetOptimizationLevel( h_data.myOptimizationLevel );
666 if ( h->GetKeepFiles() != h_data.myKeepFiles )
667 h->SetKeepFiles ( h_data.myKeepFiles );
668 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
669 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
670 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
671 h->SetVerboseLevel ( h_data.myVerboseLevel );
672 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
673 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
674 if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
675 h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
676 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
677 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
678 if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
679 h->SetFEMCorrection( h_data.myFEMCorrection );
680 if ( h->GetTextOption() != h_data.myTextOption )
681 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
683 int nbVertex = (int) h_data.myEnforcedVertices.size();
684 GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
685 int nbVertexHyp = vertexHyp->length();
687 MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices");
688 MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp);
690 // Some vertices were removed
691 if (nbVertex < nbVertexHyp) {
692 // if (nbVertex == 0)
693 // h->ClearEnforcedVertices();
695 // iterate over vertices of hypo
696 for(int i = 0 ; i <nbVertexHyp ; i++) {
697 double x = vertexHyp[i].x;
698 double y = vertexHyp[i].y;
699 double z = vertexHyp[i].z;
701 if (!smpVertexExists(x,y,z))
702 h->RemoveEnforcedVertex(x,y,z);
707 TEnforcedVertexValues::const_iterator it;
708 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
709 double x = it->at(0);
710 double y = it->at(1);
711 double z = it->at(2);
712 double size = it->at(3);
713 MESSAGE("(" << x << ", "
719 mySize = h->GetEnforcedVertex(x,y,z);
720 MESSAGE("Old size: " << mySize);
721 if (mySize != size) {
722 MESSAGE("Setting new size: " << size);
723 h->SetEnforcedVertex(x,y,z,size);
727 MESSAGE("Setting new size: " << size);
728 h->SetEnforcedVertex(x,y,z,size);
732 catch ( const SALOME::SALOME_Exception& ex )
734 SalomeApp_Tools::QtCatchCorbaException( ex );
740 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
742 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets");
743 h_data.myName = myName ? myName->text() : "";
744 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
745 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
746 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
747 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
748 h_data.myKeepFiles = myKeepFiles->isChecked();
749 h_data.myWorkingDir = myWorkingDir->text().trimmed();
750 h_data.myVerboseLevel = myVerboseLevelSpin->value();
751 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
752 h_data.myRemoveInitialCentralPoint = myRemoveInitialCentralPointCheck->isChecked();
753 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
754 h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked();
755 h_data.myTextOption = myTextOption->text();
756 h_data.myEnforcedVertices.clear();
758 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
759 GHS3DEnforcedVertex myVertex;
760 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble());
761 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble());
762 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble());
763 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble());
764 MESSAGE("Add new enforced vertex (" << myVertex[0] << ", "
765 << myVertex[1] << ", "
766 << myVertex[2] << ") = "
768 h_data.myEnforcedVertices.push_back(myVertex);
774 QString GHS3DPluginGUI_HypothesisCreator::caption() const
776 return tr( "GHS3D_TITLE" );
779 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
781 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
784 QString GHS3DPluginGUI_HypothesisCreator::type() const
786 return tr( "GHS3D_HYPOTHESIS" );
789 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
791 return "ghs3d_hypo_page.html";
794 //=============================================================================
795 /*! GetHypothesisCreator
798 //=============================================================================
801 GHS3DPLUGINGUI_EXPORT
802 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
804 if ( aHypType == "GHS3D_Parameters" )
805 return new GHS3DPluginGUI_HypothesisCreator( aHypType );