1 // Copyright (C) 2004-2008 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
19 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
20 // File : GHS3DPluginGUI_HypothesisCreator.cxx
21 // Author : Michael Zorin
22 // Module : GHS3DPlugin
25 #include "GHS3DPluginGUI_HypothesisCreator.h"
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_FileDlg.h>
34 #include <SalomeApp_Tools.h>
35 #include <SalomeApp_TypeFilter.h>
40 #include <QVBoxLayout>
41 #include <QGridLayout>
46 #include <QPushButton>
49 #include <QTableWidget>
50 #include <QStandardItemModel>
51 #include <QStandardItem>
52 #include <QHeaderView>
53 #include <QModelIndexList>
56 #include <utilities.h>
65 // Enforced vertices array columns
74 // Enforced vertices inputs
91 #include <sys/sysinfo.h>
94 int maxAvailableMemory()
97 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
98 MEMORYSTATUSEX statex;
99 statex.dwLength = sizeof (statex);
100 int err = GlobalMemoryStatusEx (&statex);
103 statex.ullTotalPhys / 1024 / 1024 +
104 statex.ullTotalPageFile / 1024 / 1024 +
105 statex.ullTotalVirtual / 1024 / 1024;
106 return (int) ( 0.7 * totMB );
110 int err = sysinfo( &si );
113 si.totalram * si.mem_unit / 1024 / 1024 +
114 si.totalswap * si.mem_unit / 1024 / 1024 ;
115 return (int) ( 0.7 * totMB );
121 class QDoubleValidator;
124 // BEGIN DoubleLineEditDelegate
127 DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent)
128 : QItemDelegate(parent)
132 QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent,
133 const QStyleOptionViewItem &/* option */,
134 const QModelIndex &/* index */) const
136 QLineEdit *editor = new QLineEdit(parent);
137 editor->setValidator(new QDoubleValidator(parent));
142 void DoubleLineEditDelegate::setEditorData(QWidget *editor,
143 const QModelIndex &index) const
145 QString value = index.model()->data(index, Qt::EditRole).toString();
147 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
148 lineEdit->setText(value);
151 void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
152 const QModelIndex &index) const
154 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
156 double value = lineEdit->text().toDouble(&ok);
159 model->setData(index, value, Qt::EditRole);
160 MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")");
164 void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor,
165 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
167 editor->setGeometry(option.rect);
171 // END DoubleLineEditDelegate
174 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
175 : SMESHGUI_GenericHypothesisCreator( theHypType )
179 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
183 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
185 QFrame* fr = new QFrame( 0 );
186 QVBoxLayout* lay = new QVBoxLayout( fr );
188 lay->setSpacing( 0 );
191 QTabWidget* tab = new QTabWidget( fr );
192 tab->setTabShape( QTabWidget::Rounded );
193 tab->setTabPosition( QTabWidget::North );
194 lay->addWidget( tab );
197 myStdGroup = new QWidget();
198 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
199 aStdLayout->setSpacing( 6 );
200 aStdLayout->setMargin( 11 );
206 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
207 myName = new QLineEdit( myStdGroup );
208 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
211 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
212 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
214 aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 );
215 myOptimizationLevelCombo = new QComboBox( myStdGroup );
216 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
219 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" ) << tr( "LEVEL_STRONG" );
220 myOptimizationLevelCombo->addItems( types );
222 aStdLayout->setRowStretch( row, 5 );
224 // advanced parameters
225 myAdvGroup = new QWidget();
226 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
227 anAdvLayout->setSpacing( 6 );
228 anAdvLayout->setMargin( 11 );
230 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
231 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
232 myMaximumMemorySpin->setMinimum( 1 );
233 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
234 myMaximumMemorySpin->setSingleStep( 10 );
235 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
237 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
238 myInitialMemorySpin = new QSpinBox( myAdvGroup );
239 myInitialMemorySpin->setMinimum( 1 );
240 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
241 myInitialMemorySpin->setSingleStep( 10 );
242 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
244 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
245 myWorkingDir = new QLineEdit( myAdvGroup );
246 //myWorkingDir->setReadOnly( true );
247 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
248 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
250 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
252 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
253 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
254 myVerboseLevelSpin->setMinimum( 0 );
255 myVerboseLevelSpin->setMaximum( 10 );
256 myVerboseLevelSpin->setSingleStep( 1 );
258 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
260 myRemoveInitialCentralPointCheck = new QCheckBox( tr( "NO_INITIAL_CENTRAL_POINT" ), myAdvGroup );
262 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
264 myFEMCorrectionCheck = new QCheckBox( tr( "FEM_CORRECTION" ), myAdvGroup );
266 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
267 myTextOption = new QLineEdit( myAdvGroup );
269 anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 );
270 anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 );
271 anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 );
272 anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 );
273 anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 );
274 anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 );
275 anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 );
276 anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 );
277 anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 );
278 anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 );
279 anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 );
280 anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 );
281 anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 );
282 anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, 6, 0, 1, 4 );
283 anAdvLayout->addWidget( myBoundaryRecoveryCheck, 7, 0, 1, 4 );
284 anAdvLayout->addWidget( myFEMCorrectionCheck, 8, 0, 1, 4 );
285 anAdvLayout->addWidget( aTextOptionLabel, 9, 0, 1, 1 );
286 anAdvLayout->addWidget( myTextOption, 9, 1, 1, 2 );
288 // Size Maps parameters
289 myEnfGroup = new QWidget();
290 QGridLayout* anSmpLayout = new QGridLayout(myEnfGroup);
292 mySmpModel = new QStandardItemModel(0, ENF_VER_NB_COLUMNS);
293 myEnforcedTableView = new QTableView(myEnfGroup);
294 myEnforcedTableView->setModel(mySmpModel);
295 myEnforcedTableView->setSortingEnabled(true);
296 myEnforcedTableView->setItemDelegateForColumn(ENF_VER_SIZE_COLUMN,new DoubleLineEditDelegate(this));
297 anSmpLayout->addWidget(myEnforcedTableView, 1, 0, 9, 1);
298 QStringList enforcedHeaders;
299 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" );
300 mySmpModel->setHorizontalHeaderLabels(enforcedHeaders);
301 myEnforcedTableView->setAlternatingRowColors(true);
302 myEnforcedTableView->verticalHeader()->hide();
303 myEnforcedTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
305 QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_X_LABEL" ), myEnfGroup );
306 anSmpLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
307 myXCoord = new QLineEdit(myEnfGroup);
308 myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
309 anSmpLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
310 QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Y_LABEL" ), myEnfGroup );
311 anSmpLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
312 myYCoord = new QLineEdit(myEnfGroup);
313 myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
314 anSmpLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
315 QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Z_LABEL" ), myEnfGroup );
316 anSmpLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
317 myZCoord = new QLineEdit(myEnfGroup);
318 myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
319 anSmpLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
320 QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_VER_SIZE_LABEL" ), myEnfGroup );
321 anSmpLayout->addWidget(mySizeLabel, ENF_VER_SIZE, 1, 1, 1);
322 mySizeValue = new QLineEdit(myEnfGroup);
323 mySizeValue->setValidator(new QDoubleValidator(myEnfGroup));
324 anSmpLayout->addWidget(mySizeValue, ENF_VER_SIZE, 2, 1, 1);
326 addVertexButton = new QPushButton(tr("GHS3D_ENF_VER_VERTEX"),myEnfGroup);
327 anSmpLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
328 addVertexButton->setEnabled(false);
330 QFrame *line = new QFrame(myEnfGroup);
331 line->setFrameShape(QFrame::HLine);
332 line->setFrameShadow(QFrame::Sunken);
333 anSmpLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
335 removeVertexButton = new QPushButton(tr("GHS3D_ENF_VER_REMOVE"),myEnfGroup);
336 anSmpLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
339 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
340 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
341 tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
342 tab->setCurrentIndex( STD_TAB );
345 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
346 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
347 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
348 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
349 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
350 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
351 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
352 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
353 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
354 connect( addVertexButton, SIGNAL( clicked() ), this, SLOT( onVertexBtnClicked() ) );
355 connect( removeVertexButton, SIGNAL( clicked() ), this, SLOT( onRemoveVertexBtnClicked() ) );
362 bool GHS3DPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, double z) const
364 const int rowCount = mySmpModel->rowCount();
365 for (int i=0 ; i < rowCount ; i++) {
366 double myX = mySmpModel->data(mySmpModel->index(i, ENF_VER_X_COLUMN)).toDouble();
368 // MESSAGE("Found x value " << x << " at row " << i);
369 double myY = mySmpModel->data(mySmpModel->index(i, ENF_VER_Y_COLUMN)).toDouble();
371 // MESSAGE("Found y value " << y << " at row " << i);
372 double myZ = mySmpModel->data(mySmpModel->index(i, ENF_VER_Z_COLUMN)).toDouble();
374 MESSAGE("Found x value " << x << " at row " << i);
375 MESSAGE("Found y value " << y << " at row " << i);
376 MESSAGE("Found z value " << z << " at row " << i);
382 // MESSAGE("Not found x,y,z values: " << x << " " << y << " " << z);
386 bool GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined()
388 bool val = (!myXCoord->text().isEmpty())&&(!myYCoord->text().isEmpty())&&(!myZCoord->text().isEmpty())&&(!mySizeValue->text().isEmpty());
389 bool isDefined = val;
391 isDefined = ! smpVertexExists(myXCoord->text().toDouble(),myYCoord->text().toDouble(),myZCoord->text().toDouble());
393 emit vertexDefined(isDefined);
397 void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()
399 MESSAGE("GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()");
400 const int row = mySmpModel->rowCount() ;
401 double x = myXCoord->text().toDouble();
402 double y = myYCoord->text().toDouble();
403 double z = myZCoord->text().toDouble();
404 double size = mySizeValue->text().toDouble();
406 if (smpVertexExists(x,y,z)) return;
408 // double size = 10.0;
410 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
411 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
412 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
414 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
415 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
416 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
418 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
419 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
420 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
421 // ENF_VER_SIZE_COLUMN
422 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
423 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) );
425 myEnforcedTableView->clearSelection();
426 myEnforcedTableView->scrollTo( mySmpModel->item( row, ENF_VER_SIZE_COLUMN )->index() );
427 checkVertexIsDefined();
430 void GHS3DPluginGUI_HypothesisCreator::onRemoveVertexBtnClicked()
432 QList<int> selectedRows;
433 QList<QModelIndex> selectedIndex = myEnforcedTableView->selectionModel()->selectedIndexes();
436 foreach( index, selectedIndex ) {
438 if ( !selectedRows.contains( row ) )
439 selectedRows.append( row );
441 qSort( selectedRows );
442 QListIterator<int> it( selectedRows );
444 while ( it.hasPrevious() ) {
446 MESSAGE("delete row #"<< row);
447 mySmpModel->removeRow(row );
449 myEnforcedTableView->clearSelection();
451 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
453 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
454 if ( !dir.isEmpty() )
455 myWorkingDir->setText( dir );
458 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
460 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
461 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
462 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
463 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
466 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
468 MESSAGE("GHS3DPluginGUI_HypothesisCreator::checkParams");
470 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
471 SUIT_MessageBox::warning( dlg(),
472 tr( "SMESH_WRN_WARNING" ),
473 tr( "GHS3D_PERMISSION_DENIED" ) );
480 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
482 MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams");
483 GHS3DHypothesisData data;
484 readParamsFromHypo( data );
487 myName->setText( data.myName );
489 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
490 myOptimizationLevelCombo ->setCurrentIndex( data.myOptimizationLevel );
491 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
492 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
493 myMaximumMemorySpin->minimum() ));
494 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
495 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
496 myInitialMemorySpin->minimum() ));
497 myWorkingDir ->setText ( data.myWorkingDir );
498 myKeepFiles ->setChecked ( data.myKeepFiles );
499 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
500 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
501 myRemoveInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint );
502 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
503 myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection );
504 myTextOption ->setText ( data.myTextOption );
506 TEnforcedVertexValues::const_iterator it;
508 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
510 double x = it->at(0);
511 double y = it->at(1);
512 double z = it->at(2);
513 double size = it->at(3);
515 mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x);
516 mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) );
517 mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable );
519 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y);
520 mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) );
521 mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable );
523 mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z);
524 mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) );
525 mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable );
526 // ENF_VER_SIZE_COLUMN
527 mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size);
528 mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) );
530 MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size);
534 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
535 that->updateWidgets();
538 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
540 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParams");
541 GHS3DHypothesisData data;
542 readParamsFromWidgets( data );
543 storeParamsToHypo( data );
547 if ( !data.myBoundaryRecovery )
548 valStr = "-c " + QString::number( !data.myToMeshHoles );
550 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
551 char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
553 valStr += level[ data.myOptimizationLevel ];
555 if ( data.myMaximumMemory > 0 ) {
557 valStr += QString::number( data.myMaximumMemory );
559 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
561 valStr += QString::number( data.myInitialMemory );
564 valStr += QString::number( data.myVerboseLevel );
566 if ( !data.myToCreateNewNodes )
569 if ( data.myRemoveInitialCentralPoint )
570 valStr += " -no_initial_central_point";
572 if ( data.myBoundaryRecovery )
575 if ( data.myFEMCorrection )
579 valStr += data.myTextOption;
581 valStr += " #BEGIN ENFORCED VERTICES#";
582 // Add size map parameters storage
583 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
585 double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble();
586 double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble();
587 double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble();
588 double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble();
589 valStr += QString::number( x );
591 valStr += QString::number( y );
593 valStr += QString::number( z );
595 valStr += QString::number( size );
596 if (i!=mySmpModel->rowCount()-1)
599 valStr += " #END ENFORCED VERTICES#";
600 MESSAGE(valStr.toStdString());
604 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
606 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo");
607 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
608 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
610 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
611 h_data.myName = isCreation() && data ? hypName() : "";
613 h_data.myToMeshHoles = h->GetToMeshHoles();
614 h_data.myMaximumMemory = h->GetMaximumMemory();
615 h_data.myInitialMemory = h->GetInitialMemory();
616 h_data.myInitialMemory = h->GetInitialMemory();
617 h_data.myOptimizationLevel = h->GetOptimizationLevel();
618 h_data.myKeepFiles = h->GetKeepFiles();
619 h_data.myWorkingDir = h->GetWorkingDirectory();
620 h_data.myVerboseLevel = h->GetVerboseLevel();
621 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
622 h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint();
623 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
624 h_data.myFEMCorrection = h->GetFEMCorrection();
625 h_data.myTextOption = h->GetTextOption();
627 GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
628 MESSAGE("vertices->length(): " << vertices->length());
629 h_data.myEnforcedVertices.clear();
630 for (int i=0 ; i<vertices->length() ; i++) {
631 GHS3DEnforcedVertex myVertex;
632 myVertex.push_back(vertices[i].x);
633 myVertex.push_back(vertices[i].y);
634 myVertex.push_back(vertices[i].z);
635 myVertex.push_back(vertices[i].size);
636 MESSAGE("Add enforced vertex ("<< myVertex[0] << ","<< myVertex[1] << ","<< myVertex[2] << ") ="<< myVertex[3]);
637 h_data.myEnforcedVertices.push_back(myVertex);
642 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
644 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo");
645 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
646 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
652 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
654 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
655 h->SetToMeshHoles ( h_data.myToMeshHoles );
656 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
657 h->SetMaximumMemory ( h_data.myMaximumMemory );
658 if ( h->GetInitialMemory() != h_data.myInitialMemory )
659 h->SetInitialMemory ( h_data.myInitialMemory );
660 if ( h->GetInitialMemory() != h_data.myInitialMemory )
661 h->SetInitialMemory ( h_data.myInitialMemory );
662 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
663 h->SetOptimizationLevel( h_data.myOptimizationLevel );
664 if ( h->GetKeepFiles() != h_data.myKeepFiles )
665 h->SetKeepFiles ( h_data.myKeepFiles );
666 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
667 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
668 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
669 h->SetVerboseLevel ( h_data.myVerboseLevel );
670 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
671 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
672 if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
673 h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
674 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
675 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
676 if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
677 h->SetFEMCorrection( h_data.myFEMCorrection );
678 if ( h->GetTextOption() != h_data.myTextOption )
679 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
681 int nbVertex = (int) h_data.myEnforcedVertices.size();
682 GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
683 int nbVertexHyp = vertexHyp->length();
685 MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices");
686 MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp);
688 // Some vertices were removed
689 if (nbVertex < nbVertexHyp) {
690 // if (nbVertex == 0)
691 // h->ClearEnforcedVertices();
693 // iterate over vertices of hypo
694 for(int i = 0 ; i <nbVertexHyp ; i++) {
695 double x = vertexHyp[i].x;
696 double y = vertexHyp[i].y;
697 double z = vertexHyp[i].z;
699 if (!smpVertexExists(x,y,z))
700 h->RemoveEnforcedVertex(x,y,z);
705 TEnforcedVertexValues::const_iterator it;
706 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
707 double x = it->at(0);
708 double y = it->at(1);
709 double z = it->at(2);
710 double size = it->at(3);
711 MESSAGE("(" << x << ", "
717 mySize = h->GetEnforcedVertex(x,y,z);
718 MESSAGE("Old size: " << mySize);
719 if (mySize != size) {
720 MESSAGE("Setting new size: " << size);
721 h->SetEnforcedVertex(x,y,z,size);
725 MESSAGE("Setting new size: " << size);
726 h->SetEnforcedVertex(x,y,z,size);
730 catch ( const SALOME::SALOME_Exception& ex )
732 SalomeApp_Tools::QtCatchCorbaException( ex );
738 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
740 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets");
741 h_data.myName = myName ? myName->text() : "";
742 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
743 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
744 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
745 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
746 h_data.myKeepFiles = myKeepFiles->isChecked();
747 h_data.myWorkingDir = myWorkingDir->text().trimmed();
748 h_data.myVerboseLevel = myVerboseLevelSpin->value();
749 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
750 h_data.myRemoveInitialCentralPoint = myRemoveInitialCentralPointCheck->isChecked();
751 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
752 h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked();
753 h_data.myTextOption = myTextOption->text();
754 h_data.myEnforcedVertices.clear();
756 for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
757 GHS3DEnforcedVertex myVertex;
758 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble());
759 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble());
760 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble());
761 myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble());
762 MESSAGE("Add new enforced vertex (" << myVertex[0] << ", "
763 << myVertex[1] << ", "
764 << myVertex[2] << ") = "
766 h_data.myEnforcedVertices.push_back(myVertex);
772 QString GHS3DPluginGUI_HypothesisCreator::caption() const
774 return tr( "GHS3D_TITLE" );
777 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
779 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
782 QString GHS3DPluginGUI_HypothesisCreator::type() const
784 return tr( "GHS3D_HYPOTHESIS" );
787 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
789 return "ghs3d_hypo_page.html";
792 //=============================================================================
793 /*! GetHypothesisCreator
796 //=============================================================================
799 GHS3DPLUGINGUI_EXPORT
800 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
802 if ( aHypType == "GHS3D_Parameters" )
803 return new GHS3DPluginGUI_HypothesisCreator( aHypType );