1 // Copyright (C) 2004-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
20 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 // File : GHS3DPluginGUI_HypothesisCreator.cxx
22 // Author : Michael Zorin
23 // Module : GHS3DPlugin
25 #include "GHS3DPluginGUI_HypothesisCreator.h"
26 #include "GHS3DPluginGUI_Enums.h"
27 #include "GHS3DPluginGUI_Dlg.h"
28 #include "GHS3DPlugin_OptimizerHypothesis.hxx"
30 #include <GeometryGUI.h>
32 #include <SMESHGUI_Utils.h>
33 #include <SMESHGUI_SpinBox.h>
34 #include <SMESHGUI_HypothesesUtils.h>
35 #include <SMESH_NumberFilter.hxx>
36 #include <SMESH_TypeFilter.hxx>
37 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SalomeApp_IntSpinBox.h>
45 #include <SalomeApp_Tools.h>
46 #include <SalomeApp_TypeFilter.h>
52 #include <QGridLayout>
54 #include <QHeaderView>
58 #include <QPushButton>
61 #include <QTableWidget>
62 #include <QTableWidgetItem>
63 #include <QVBoxLayout>
66 #include <utilities.h>
70 QComboBox* getModeCombo( QWidget* parent, bool isPThreadCombo )
72 QComboBox* combo = new QComboBox( parent );
75 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::SAFE, QObject::tr("MODE_SAFE"));
76 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::AGGRESSIVE, QObject::tr("MODE_AGGRESSIVE"));
77 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::NONE, QObject::tr("MODE_NONE"));
81 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::NO, QObject::tr("MODE_NO"));
82 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::YES, QObject::tr("MODE_YES"));
83 combo->insertItem((int) GHS3DPlugin_OptimizerHypothesis::ONLY, QObject::tr("MODE_ONLY"));
90 // BEGIN EnforcedVertexTableWidgetDelegate
93 EnforcedVertexTableWidgetDelegate::EnforcedVertexTableWidgetDelegate(QObject *parent)
94 : QItemDelegate(parent)
98 QWidget *EnforcedVertexTableWidgetDelegate::createEditor(QWidget *parent,
99 const QStyleOptionViewItem & option ,
100 const QModelIndex & index ) const
102 QModelIndex father = index.parent();
103 QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
105 if (index.column() == ENF_VER_X_COLUMN ||
106 index.column() == ENF_VER_Y_COLUMN ||
107 index.column() == ENF_VER_Z_COLUMN ||
108 index.column() == ENF_VER_SIZE_COLUMN) {
109 SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
110 if (index.column() == ENF_VER_SIZE_COLUMN)
111 editor->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
113 editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
114 editor->setReadOnly(!entry.isEmpty());
115 editor->setDisabled(!entry.isEmpty());
118 else if (index.column() == ENF_VER_GROUP_COLUMN ||
119 index.column() == ENF_VER_NAME_COLUMN) {
121 QLineEdit *editor = new QLineEdit(parent);
122 if (index.column() != ENF_VER_GROUP_COLUMN) {
123 editor->setReadOnly(!entry.isEmpty());
124 editor->setDisabled(!entry.isEmpty());
128 return QItemDelegate::createEditor(parent, option, index);
131 void EnforcedVertexTableWidgetDelegate::setEditorData(QWidget *editor,
132 const QModelIndex &index) const
134 if (index.column() == ENF_VER_X_COLUMN ||
135 index.column() == ENF_VER_Y_COLUMN ||
136 index.column() == ENF_VER_Z_COLUMN ||
137 index.column() == ENF_VER_SIZE_COLUMN)
139 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
140 lineEdit->SetValue(index.data().toDouble());
142 else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
143 QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
144 checkBox->setChecked(index.data().toBool());
147 QItemDelegate::setEditorData(editor, index);
151 void EnforcedVertexTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
152 const QModelIndex &index) const
154 QModelIndex parent = index.parent();
156 QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
157 bool isCompound = parent.child(index.row(), ENF_VER_COMPOUND_COLUMN).data(Qt::CheckStateRole).toBool();
159 if (index.column() == ENF_VER_X_COLUMN ||
160 index.column() == ENF_VER_Y_COLUMN ||
161 index.column() == ENF_VER_Z_COLUMN) {
162 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
163 if (!isCompound && !vertexExists(model, index, lineEdit->GetString()))
164 model->setData(index, lineEdit->GetValue(), Qt::EditRole);
166 else if (index.column() == ENF_VER_SIZE_COLUMN)
168 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
169 const double newsize = lineEdit->GetValue();
171 model->setData(index, newsize, Qt::EditRole);
173 else if (index.column() == ENF_VER_NAME_COLUMN) {
174 QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
175 QString value = lineEdit->text();
176 if (entry.isEmpty() && !vertexExists(model, index, value))
177 model->setData(index, value, Qt::EditRole);
179 else if (index.column() == ENF_VER_ENTRY_COLUMN) {
180 QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
181 QString value = lineEdit->text();
182 if (! vertexExists(model, index, value))
183 model->setData(index, value, Qt::EditRole);
185 else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
186 QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
187 model->setData(index, checkBox->isChecked(), Qt::CheckStateRole);
190 QItemDelegate::setModelData(editor, model, index);
194 void EnforcedVertexTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
195 const QStyleOptionViewItem &option,
196 const QModelIndex &/* index */) const
198 editor->setGeometry(option.rect);
201 bool EnforcedVertexTableWidgetDelegate::vertexExists(QAbstractItemModel *model,
202 const QModelIndex &index,
206 QModelIndex parent = index.parent();
207 int row = index.row();
208 int col = index.column();
210 if (parent.isValid() && !value.isEmpty()) {
211 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
213 if (col == ENF_VER_X_COLUMN) {
214 x = value.toDouble();
215 y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
216 z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
218 if (col == ENF_VER_Y_COLUMN) {
219 y = value.toDouble();
220 x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
221 z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
223 if (col == ENF_VER_Z_COLUMN) {
224 z = value.toDouble();
225 x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
226 y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
228 int nbChildren = model->rowCount(parent);
229 for (int i = 0 ; i < nbChildren ; i++) {
231 double childX = parent.child(i, ENF_VER_X_COLUMN).data().toDouble();
232 double childY = parent.child(i, ENF_VER_Y_COLUMN).data().toDouble();
233 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data().toDouble();
234 if ((childX == x) && (childY == y) && (childZ == z)) {
241 else if (col == ENF_VER_NAME_COLUMN) {
242 QString name = parent.child(row, ENF_VER_NAME_COLUMN).data().toString();
252 // END EnforcedVertexTableWidgetDelegate
256 // BEGIN EnforcedMeshTableWidgetDelegate
259 EnforcedMeshTableWidgetDelegate::EnforcedMeshTableWidgetDelegate(QObject *parent)
260 : QItemDelegate(parent)
264 QWidget *EnforcedMeshTableWidgetDelegate::createEditor(QWidget *parent,
265 const QStyleOptionViewItem & option ,
266 const QModelIndex & index ) const
268 return QItemDelegate::createEditor(parent, option, index);
271 void EnforcedMeshTableWidgetDelegate::setEditorData(QWidget *editor,
272 const QModelIndex &index) const
274 QItemDelegate::setEditorData(editor, index);
277 void EnforcedMeshTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
278 const QModelIndex &index) const
280 QItemDelegate::setModelData(editor, model, index);
284 void EnforcedMeshTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
285 const QStyleOptionViewItem &option,
286 const QModelIndex &/* index */) const
288 editor->setGeometry(option.rect);
292 // END EnforcedMeshTableWidgetDelegate
296 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
297 : SMESHGUI_GenericHypothesisCreator( theHypType )
299 GeomToolSelected = NULL;
300 GeomToolSelected = getGeomSelectionTool();
302 iconVertex = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
303 iconCompound = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_COMPOUND")));
304 // mySelectionMgr = SMESH::GetSelectionMgr(SMESHGUI::GetSMESHGUI());
305 myEnfMeshConstraintLabels << tr( "GHS3D_ENF_MESH_CONSTRAINT_NODE" ) << tr( "GHS3D_ENF_MESH_CONSTRAINT_EDGE" ) << tr("GHS3D_ENF_MESH_CONSTRAINT_FACE");
308 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
310 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
311 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
312 myEnfMeshWdg->deactivateSelection();
316 * \brief {Get or create the geom selection tool for active study}
318 GeomSelectionTools* GHS3DPluginGUI_HypothesisCreator::getGeomSelectionTool()
320 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
321 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
322 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
323 that->GeomToolSelected = new GeomSelectionTools(aStudy);
325 return that->GeomToolSelected;
328 GEOM::GEOM_Gen_var GHS3DPluginGUI_HypothesisCreator::getGeomEngine()
330 return GeometryGUI::GetGeomGen();
333 bool GHS3DPluginGUI_HypothesisCreator::isOptimization() const
335 return ( hypType() == GHS3DPlugin_OptimizerHypothesis::GetHypType() );
338 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
340 QFrame* fr = new QFrame( 0 );
341 QVBoxLayout* lay = new QVBoxLayout( fr );
343 lay->setSpacing( 0 );
346 QTabWidget* tab = new QTabWidget( fr );
347 tab->setTabShape( QTabWidget::Rounded );
348 tab->setTabPosition( QTabWidget::North );
349 lay->addWidget( tab );
352 myStdGroup = new QWidget();
353 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
354 aStdLayout->setSpacing( 6 );
355 aStdLayout->setMargin( 11 );
361 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
362 myName = new QLineEdit( myStdGroup );
363 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
366 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
367 aStdLayout->addWidget( myToMeshHolesCheck, row, 0, 1, 1 );
368 myToMakeGroupsOfDomains = new QCheckBox( tr( "GHS3D_TO_MAKE_DOMAIN_GROUPS" ), myStdGroup );
369 aStdLayout->addWidget( myToMakeGroupsOfDomains, row++, 1, 1, 1 );
371 QLabel* optimizationLbl = new QLabel( tr( "GHS3D_OPTIMIZATION" ), myStdGroup );
372 aStdLayout->addWidget( optimizationLbl, row, 0, 1, 1 );
373 myOptimizationCombo = getModeCombo( myStdGroup, false );
374 aStdLayout->addWidget( myOptimizationCombo, row++, 1, 1, 1 );
376 QLabel* optimizatiolLevelLbl = new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup );
377 aStdLayout->addWidget( optimizatiolLevelLbl, row, 0, 1, 1 );
378 myOptimizationLevelCombo = new QComboBox( myStdGroup );
379 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
381 QLabel* splitOverconstrainedLbl = new QLabel( tr("GHS3D_SPLIT_OVERCONSTRAINED"), myStdGroup );
382 aStdLayout->addWidget( splitOverconstrainedLbl, row, 0, 1, 1 );
383 mySplitOverConstrainedCombo = getModeCombo( myStdGroup, false );
384 aStdLayout->addWidget( mySplitOverConstrainedCombo, row++, 1, 1, 1 );
386 QLabel* pthreadsModeLbl = new QLabel( tr( "GHS3D_PTHREADS_MODE" ), myStdGroup);
387 aStdLayout->addWidget( pthreadsModeLbl, row, 0, 1, 1 );
388 myPThreadsModeCombo = getModeCombo( myStdGroup, true );
389 aStdLayout->addWidget( myPThreadsModeCombo, row++, 1, 1, 1 );
391 QLabel* nbThreadsLbl = new QLabel( tr( "GHS3D_NB_THREADS" ), myStdGroup);
392 aStdLayout->addWidget( nbThreadsLbl, row, 0, 1, 1 );
393 myNumberOfThreadsSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, myStdGroup );
394 aStdLayout->addWidget( myNumberOfThreadsSpin, row++, 1, 1, 1 );
396 mySmoothOffSliversCheck = new QCheckBox( tr( "GHS3D_SMOOTH_OFF_SLIVERS" ), myStdGroup );
397 aStdLayout->addWidget( mySmoothOffSliversCheck, row, 0, 1, 1 );
398 myCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myStdGroup );
399 aStdLayout->addWidget( myCreateNewNodesCheck, row++, 1, 1, 1 );
401 myOptimizationLevelCombo->addItems( QStringList()
402 << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" )
403 << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" )
404 << tr( "LEVEL_STRONG" ));
405 aStdLayout->setRowStretch( row, 10 );
407 if ( isOptimization() )
409 myToMeshHolesCheck->hide();
410 myToMakeGroupsOfDomains->hide();
414 optimizationLbl->hide();
415 myOptimizationCombo->hide();
416 splitOverconstrainedLbl->hide();
417 mySplitOverConstrainedCombo->hide();
418 pthreadsModeLbl->hide();
419 myPThreadsModeCombo->hide();
420 nbThreadsLbl->hide();
421 myNumberOfThreadsSpin->hide();
422 mySmoothOffSliversCheck->hide();
423 myCreateNewNodesCheck->hide();
426 // advanced parameters
427 myAdvGroup = new QWidget();
428 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
429 anAdvLayout->setSpacing( 6 );
430 anAdvLayout->setMargin( 11 );
431 myAdvWidget = new GHS3DPluginGUI_AdvWidget(myAdvGroup);
432 anAdvLayout->addWidget( myAdvWidget);
434 myAdvWidget->maxMemoryCheck->setText(tr( "MAX_MEMORY_SIZE" ));
435 myAdvWidget->initialMemoryCheck->setText(tr( "INIT_MEMORY_SIZE" ));
437 myAdvWidget->maxMemorySpin->stepBy(10);
438 myAdvWidget->maxMemorySpin->setValue( 128 );
440 myAdvWidget->initialMemorySpin->stepBy(10);
441 myAdvWidget->initialMemorySpin->setValue( 100 );
443 myAdvWidget->initialMemoryLabel ->setText (tr( "MEGABYTE" ));
444 myAdvWidget->maxMemoryLabel ->setText (tr( "MEGABYTE" ));
446 myAdvWidget->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
447 myAdvWidget->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
448 myAdvWidget->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
449 myAdvWidget->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
450 myAdvWidget->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
451 myAdvWidget->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
453 myAdvWidget->memoryGroupBox ->setTitle(tr( "MEMORY_GROUP_TITLE" ));
454 myAdvWidget->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
455 myAdvWidget->advancedMeshingGroupBox ->setTitle(tr( "ADVANCED_MESHING_GROUP_TITLE" ));
457 myAdvWidget->createNewNodesCheck ->setText (tr( "TO_ADD_NODES" ));
458 myAdvWidget->removeInitialCentralPointCheck->setText (tr( "NO_INITIAL_CENTRAL_POINT" ));
459 myAdvWidget->boundaryRecoveryCheck ->setText (tr( "RECOVERY_VERSION" ));
460 myAdvWidget->FEMCorrectionCheck ->setText (tr( "FEM_CORRECTION" ));
461 myAdvWidget->gradationLabel ->setText (tr( "GHS3D_GRADATION" ));
462 myAdvWidget->gradationSpinBox->RangeStepAndValidator(0.0, 5.0, 0.05, "length_precision");
464 if ( isOptimization() )
466 myAdvWidget->createNewNodesCheck->hide();
467 myAdvWidget->removeInitialCentralPointCheck->hide();
468 myAdvWidget->boundaryRecoveryCheck->hide();
469 myAdvWidget->FEMCorrectionCheck->hide();
470 myAdvWidget->gradationLabel->hide();
471 myAdvWidget->gradationSpinBox->hide();
474 // Enforced vertices parameters
475 myEnfGroup = new QWidget();
476 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
478 myEnforcedTableWidget = new QTableWidget(myEnfGroup);
479 myEnforcedTableWidget ->setMinimumWidth(300);
480 myEnforcedTableWidget->setRowCount( 0 );
481 myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS );
482 myEnforcedTableWidget->setSortingEnabled(true);
483 myEnforcedTableWidget->setHorizontalHeaderLabels
485 << tr( "GHS3D_ENF_NAME_COLUMN" ) << tr( "GHS3D_ENF_VER_X_COLUMN" )
486 << tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" )
487 << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN")
488 << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_ENF_GROUP_COLUMN" ));
489 myEnforcedTableWidget->verticalHeader()->hide();
490 myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true);
491 myEnforcedTableWidget->setAlternatingRowColors(true);
492 myEnforcedTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
493 myEnforcedTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
494 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
495 myEnforcedTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
497 myEnforcedTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
499 myEnforcedTableWidget->resizeColumnsToContents();
500 myEnforcedTableWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
501 myEnforcedTableWidget->hideColumn(ENF_VER_COMPOUND_COLUMN);
503 myEnforcedTableWidget->setItemDelegate(new EnforcedVertexTableWidgetDelegate());
506 TColStd_MapOfInteger shapeTypes;
507 shapeTypes.Add( TopAbs_VERTEX );
508 shapeTypes.Add( TopAbs_COMPOUND );
510 SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes);
511 myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true);
512 myEnfVertexWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_VERTEX"), "QLineEdit { color: grey }");
514 QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_X_LABEL" ), myEnfGroup );
515 myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
516 myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
517 QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Y_LABEL" ), myEnfGroup );
518 myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
519 myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
520 QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Z_LABEL" ), myEnfGroup );
521 myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
522 myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
523 QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_SIZE_LABEL" ), myEnfGroup );
524 mySizeValue = new SMESHGUI_SpinBox(myEnfGroup);
525 mySizeValue->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
527 QLabel* myGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfGroup );
528 myGroupName = new QLineEdit(myEnfGroup);
530 addVertexButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfGroup);
531 addVertexButton->setEnabled(false);
532 removeVertexButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfGroup);
534 anEnfLayout->addWidget(myEnforcedTableWidget, ENF_VER_VERTEX, 0, ENF_VER_NB_LINES, 1);
536 QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
537 anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2);
538 anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1);
539 anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1);
540 anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1);
541 anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1);
542 anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1);
543 anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1);
544 anEnfLayout2->addWidget(mySizeLabel, ENF_VER_SIZE, 0, 1, 1);
545 anEnfLayout2->addWidget(mySizeValue, ENF_VER_SIZE, 1, 1, 1);
546 anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1);
547 anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1);
548 anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1);
549 anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1);
550 anEnfLayout2->setRowStretch(ENF_VER_NB_LINES, 1);
552 anEnfLayout->addLayout(anEnfLayout2, ENF_VER_VERTEX, 1,ENF_VER_NB_LINES, 1);
553 anEnfLayout->setRowStretch(ENF_VER_VERTEX, 10);
556 // Enforced meshes parameters
557 myEnfMeshGroup = new QWidget();
558 QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup);
560 myEnforcedMeshTableWidget = new QTableWidget(myEnfGroup);
561 myEnforcedMeshTableWidget->setRowCount( 0 );
562 myEnforcedMeshTableWidget->setColumnCount( ENF_MESH_NB_COLUMNS );
563 myEnforcedMeshTableWidget->setSortingEnabled(true);
564 myEnforcedMeshTableWidget->verticalHeader()->hide();
565 QStringList enforcedMeshHeaders;
566 enforcedMeshHeaders << tr( "GHS3D_ENF_NAME_COLUMN" )
567 << tr( "GHS3D_ENF_ENTRY_COLUMN" )
568 << tr( "GHS3D_ENF_MESH_CONSTRAINT_COLUMN" )
569 << tr( "GHS3D_ENF_GROUP_COLUMN" );
570 myEnforcedMeshTableWidget->setHorizontalHeaderLabels(enforcedMeshHeaders);
571 myEnforcedMeshTableWidget->horizontalHeader()->setStretchLastSection(true);
572 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
573 myEnforcedMeshTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
575 myEnforcedMeshTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
577 myEnforcedMeshTableWidget->setAlternatingRowColors(true);
578 myEnforcedMeshTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
579 myEnforcedMeshTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
580 myEnforcedMeshTableWidget->resizeColumnsToContents();
581 myEnforcedMeshTableWidget->hideColumn(ENF_MESH_ENTRY_COLUMN);
583 myEnforcedMeshTableWidget->setItemDelegate(new EnforcedMeshTableWidgetDelegate());
585 myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( SMESH::IDSOURCE, myEnfMeshGroup, /*multiSel=*/true);
586 myEnfMeshWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_MESH"), "QLineEdit { color: grey }");
588 myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
590 QLabel* myMeshConstraintLabel = new QLabel( tr( "GHS3D_ENF_MESH_CONSTRAINT_LABEL" ), myEnfMeshGroup );
591 myEnfMeshConstraint = new QComboBox(myEnfMeshGroup);
592 myEnfMeshConstraint->insertItems(0,myEnfMeshConstraintLabels);
593 myEnfMeshConstraint->setEditable(false);
594 myEnfMeshConstraint->setCurrentIndex(0);
596 QLabel* myMeshGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfMeshGroup );
597 myMeshGroupName = new QLineEdit(myEnfMeshGroup);
599 addEnfMeshButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfMeshGroup);
600 removeEnfMeshButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfMeshGroup);
602 anEnfMeshLayout->addWidget(myEnforcedMeshTableWidget, ENF_MESH_MESH, 0, ENF_MESH_NB_LINES , 1);
604 QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup);
605 anEnfMeshLayout2->addWidget(myEnfMeshWdg, ENF_MESH_MESH, 0, 1, 2);
606 anEnfMeshLayout2->addWidget(myMeshConstraintLabel, ENF_MESH_CONSTRAINT, 0, 1, 1);
607 anEnfMeshLayout2->addWidget(myEnfMeshConstraint, ENF_MESH_CONSTRAINT, 1, 1, 1);
608 anEnfMeshLayout2->addWidget(myMeshGroupNameLabel, ENF_MESH_GROUP, 0, 1, 1);
609 anEnfMeshLayout2->addWidget(myMeshGroupName, ENF_MESH_GROUP, 1, 1, 1);
610 anEnfMeshLayout2->addWidget(addEnfMeshButton, ENF_MESH_BTN, 0, 1, 1);
611 anEnfMeshLayout2->addWidget(removeEnfMeshButton, ENF_MESH_BTN, 1, 1, 1);
612 anEnfMeshLayout2->setRowStretch(ENF_MESH_NB_LINES, 1);
614 anEnfMeshLayout->addLayout(anEnfMeshLayout2, ENF_MESH_MESH, 1, ENF_MESH_NB_LINES, 1);
615 anEnfMeshLayout->setRowStretch(ENF_MESH_MESH, 10);
618 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
619 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
620 if ( !isOptimization() )
622 tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
623 tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "GHS3D_ENFORCED_MESHES" ) );
625 tab->setCurrentIndex( STD_TAB );
627 connect( myAdvWidget->maxMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
628 connect( myAdvWidget->initialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
629 connect( myAdvWidget->boundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
630 connect( myAdvWidget->logInFileCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
631 connect( myAdvWidget->keepWorkingFilesCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
632 connect( myAdvWidget->workingDirectoryPushButton, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
634 connect( myEnforcedTableWidget, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( synchronizeCoords() ) );
635 connect( myEnforcedTableWidget, SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
636 connect( myEnforcedTableWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
637 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertex() ) );
638 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
639 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
640 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
641 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
642 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
643 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
644 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
645 connect( myXCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
646 connect( myYCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
647 connect( myZCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
648 connect( mySizeValue, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
649 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
651 connect( addEnfMeshButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedMesh() ) );
652 connect( removeEnfMeshButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedMesh() ) );
658 * This method checks if an enforced vertex is defined;
660 void GHS3DPluginGUI_HypothesisCreator::clearEnfVertexSelection()
662 if (myEnfVertexWdg->NbObjects() != 0) {
663 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
664 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
665 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
666 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
667 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
669 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
670 that->checkVertexIsDefined();
674 * This method checks if an enforced vertex is defined;
676 void GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined()
678 bool enfVertexIsDefined = false;
679 enfVertexIsDefined = (!mySizeValue->GetString().isEmpty() &&
680 (!myEnfVertexWdg->NbObjects() == 0 ||
681 (myEnfVertexWdg->NbObjects() == 0 && !myXCoord->GetString().isEmpty()
682 && !myYCoord->GetString().isEmpty()
683 && !myZCoord->GetString().isEmpty())));
684 emit vertexDefined(enfVertexIsDefined);
688 * This method checks if an enforced mesh is defined;
690 void GHS3DPluginGUI_HypothesisCreator::checkEnfMeshIsDefined()
692 emit enfMeshDefined( myEnfVertexWdg->NbObjects() != 0);
696 * This method resets the content of the X, Y, Z, size and GroupName widgets;
698 void GHS3DPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
700 myXCoord->setCleared(true);
701 myYCoord->setCleared(true);
702 myZCoord->setCleared(true);
703 myXCoord->setText("");
704 myYCoord->setText("");
705 myZCoord->setText("");
706 addVertexButton->setEnabled(false);
709 /** GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item)
710 This method updates the tooltip of a modified item. The QLineEdit widgets content
711 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
713 void GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item)
715 int row = myEnforcedTableWidget->row(item);
717 QVariant vertexName = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole);
718 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
719 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
720 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
721 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
722 QVariant entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
723 QString groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole).toString();
725 clearEnforcedVertexWidgets();
727 if ( !x.isNull() || !entry.isNull()) {
728 QString toolTip = vertexName.toString();
729 toolTip += QString("(");
730 if (entry.isNull() || (!entry.isNull() && entry.toString() == "")) {
731 toolTip += x.toString();
732 toolTip += QString(", ") + y.toString();
733 toolTip += QString(", ") + z.toString();
736 toolTip += entry.toString();
737 toolTip += QString(")");
740 toolTip += QString("=") + size.toString();
742 if (!groupName.isEmpty())
743 toolTip += QString(" [") + groupName + QString("]");
745 for (int col=0;col<ENF_VER_NB_COLUMNS;col++)
746 myEnforcedTableWidget->item(row,col)->setToolTip(toolTip);
749 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
750 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
751 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
752 myXCoord->SetValue(x.toDouble());
753 myYCoord->SetValue(y.toDouble());
754 myZCoord->SetValue(z.toDouble());
755 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
756 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
757 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
760 mySizeValue->SetValue(size.toDouble());
762 if (!groupName.isEmpty())
763 myGroupName->setText(groupName);
767 void GHS3DPluginGUI_HypothesisCreator::onSelectEnforcedVertex()
769 int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
770 clearEnforcedVertexWidgets();
771 if (nbSelEnfVertex == 1)
773 if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
776 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
777 if (myEnfVertex == GEOM::GEOM_Object::_nil())
779 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
780 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
781 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
782 if (CORBA::is_nil(measureOp))
786 measureOp->PointCoordinates (myEnfVertex, x, y, z);
787 if ( measureOp->IsDone() )
789 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
790 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
791 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
792 myXCoord->SetValue(x);
793 myYCoord->SetValue(y);
794 myZCoord->SetValue(z);
795 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
796 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
797 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
803 /** GHS3DPluginGUI_HypothesisCreator::synchronizeCoords()
804 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
805 of the enforced vertex clicked in the tree widget.
807 void GHS3DPluginGUI_HypothesisCreator::synchronizeCoords()
809 clearEnforcedVertexWidgets();
810 QList<QTableWidgetItem *> items = myEnforcedTableWidget->selectedItems();
811 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
812 if (! items.isEmpty()) {
813 QTableWidgetItem *item;
816 if (items.size() == 1) {
818 row = myEnforcedTableWidget->row(item);
819 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
820 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
821 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
822 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
823 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
824 if (!entry.isNull()) {
825 SMESH::string_array_var objIds = new SMESH::string_array;
827 objIds[0] = entry.toString().toStdString().c_str();
828 myEnfVertexWdg->SetObjects(objIds);
831 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
833 QVariant group = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole);
834 if (!x.isNull()/* && entry.isNull()*/) {
835 // disconnect( myXCoord, SIGNAL( textChanged(const QString &)), this, SLOT( onSelectEnforcedVertex() ) );
836 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
837 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
838 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
839 myXCoord->SetValue(x.toDouble());
840 myYCoord->SetValue(y.toDouble());
841 myZCoord->SetValue(z.toDouble());
842 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
843 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
844 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
847 mySizeValue->SetValue(size.toDouble());
849 if (!group.isNull() && (!x.isNull() || !entry.isNull()))
850 myGroupName->setText(group.toString());
853 QList<QString> entryList;
854 for (int i = 0; i < items.size(); ++i) {
856 row = myEnforcedTableWidget->row(item);
857 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
859 entryList << entry.toString();
861 if (entryList.size() > 0) {
862 SMESH::string_array_var objIds = new SMESH::string_array;
863 objIds->length(entryList.size());
864 for (int i = 0; i < entryList.size() ; i++)
865 objIds[i] = entryList.at(i).toStdString().c_str();
866 myEnfVertexWdg->SetObjects(objIds);
869 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
874 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
876 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
877 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
878 that->checkVertexIsDefined();
881 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh( meshName, geomEntry, elemType, size, groupName)
882 This method adds in the tree widget an enforced mesh from mesh, submesh or group with optionally size and and groupName.
884 void GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh(std::string name,
887 std::string groupName)
889 bool okToCreate = true;
890 QString itemEntry = "";
891 int itemElementType = 0;
892 int rowCount = myEnforcedMeshTableWidget->rowCount();
893 bool allColumns = true;
894 for (int row = 0;row<rowCount;row++) {
895 for (int col = 0 ; col < ENF_MESH_NB_COLUMNS ; col++) {
896 if (col == ENF_MESH_CONSTRAINT_COLUMN){
897 if (qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col)) == 0) {
902 else if (myEnforcedMeshTableWidget->item(row, col) == 0) {
906 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
907 QComboBox* itemComboBox = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col));
908 itemElementType = itemComboBox->currentIndex();
910 else if (col == ENF_MESH_ENTRY_COLUMN)
911 itemEntry = myEnforcedMeshTableWidget->item(row, col)->data(Qt::EditRole).toString();
917 if (itemEntry == QString(entry.c_str()) && itemElementType == elementType) {
927 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
928 myEnforcedMeshTableWidget->setSortingEnabled(false);
930 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
931 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
932 QComboBox* comboBox = new QComboBox();
933 QPalette pal = comboBox->palette();
934 pal.setColor(QPalette::Button, Qt::white);
935 comboBox->setPalette(pal);
936 comboBox->insertItems(0,myEnfMeshConstraintLabels);
937 comboBox->setEditable(false);
938 comboBox->setCurrentIndex(elementType);
939 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
942 QTableWidgetItem* item = new QTableWidgetItem();
943 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
945 case ENF_MESH_NAME_COLUMN:
946 item->setData( 0, name.c_str() );
947 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
948 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
950 case ENF_MESH_ENTRY_COLUMN:
951 item->setData( 0, entry.c_str() );
952 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
953 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
955 case ENF_MESH_GROUP_COLUMN:
956 item->setData( 0, groupName.c_str() );
957 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
964 myEnforcedMeshTableWidget->setSortingEnabled(true);
967 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex( x, y, z, size, vertexName, geomEntry, groupName)
968 This method adds in the tree widget an enforced vertex with given size and coords (x,y,z) or GEOM vertex or compound and with optionally groupName.
970 void GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z, double size, std::string vertexName, std::string geomEntry, std::string groupName, bool isCompound)
972 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
973 bool okToCreate = true;
974 double itemX,itemY,itemZ,itemSize = 0;
975 QString itemEntry, itemGroupName = QString("");
976 // bool itemIsCompound;
977 int rowCount = myEnforcedTableWidget->rowCount();
980 for (int row = 0;row<rowCount;row++) {
982 for (int col = 0 ; col < ENF_VER_NB_COLUMNS ; col++) {
983 if (myEnforcedTableWidget->item(row, col) == 0) {
988 data = myEnforcedTableWidget->item(row, col)->data(Qt::EditRole);
989 if (!data.isNull()) {
991 case ENF_VER_GROUP_COLUMN:
992 itemGroupName = data.toString();
994 case ENF_VER_ENTRY_COLUMN:
995 itemEntry = data.toString();
997 case ENF_VER_X_COLUMN:
998 itemX = data.toDouble();
1000 case ENF_VER_Y_COLUMN:
1001 itemY = data.toDouble();
1003 case ENF_VER_Z_COLUMN:
1004 itemZ = data.toDouble();
1006 case ENF_VER_SIZE_COLUMN:
1007 itemSize = data.toDouble();
1019 if (( !isCompound && ((itemX == x) && (itemY == y) && (itemZ == z))) ||
1020 ( !itemEntry.isEmpty() && ( itemEntry == geomEntry.c_str() )))
1023 if (itemSize != size) {
1024 myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size));
1026 // update group name
1027 if (itemGroupName.toStdString() != groupName) {
1028 myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
1035 if (geomEntry.empty()) {
1044 QString myVertexName;
1045 while(indexRef != vertexIndex) {
1046 indexRef = vertexIndex;
1047 if (vertexName.empty())
1048 myVertexName = QString("Vertex #%1").arg(vertexIndex);
1050 myVertexName = QString(vertexName.c_str());
1052 for (int row = 0;row<rowCount;row++) {
1053 QString name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString();
1054 if (myVertexName == name) {
1061 myEnforcedTableWidget->setRowCount(rowCount+1);
1062 myEnforcedTableWidget->setSortingEnabled(false);
1063 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1064 QTableWidgetItem* item = new QTableWidgetItem();
1065 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1067 case ENF_VER_NAME_COLUMN:
1068 item->setData( Qt::EditRole, myVertexName );
1069 if (!geomEntry.empty()) {
1071 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1073 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1076 case ENF_VER_X_COLUMN:
1078 item->setData( 0, QVariant(x) );
1080 case ENF_VER_Y_COLUMN:
1082 item->setData( 0, QVariant(y) );
1084 case ENF_VER_Z_COLUMN:
1086 item->setData( 0, QVariant(z) );
1088 case ENF_VER_SIZE_COLUMN:
1089 item->setData( 0, QVariant(size) );
1091 case ENF_VER_ENTRY_COLUMN:
1092 if (!geomEntry.empty())
1093 item->setData( 0, QString(geomEntry.c_str()) );
1095 case ENF_VER_COMPOUND_COLUMN:
1096 item->setData( Qt::CheckStateRole, isCompound );
1097 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1099 case ENF_VER_GROUP_COLUMN:
1100 if (!groupName.empty())
1101 item->setData( 0, QString(groupName.c_str()) );
1107 myEnforcedTableWidget->setItem(rowCount,col,item);
1110 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1112 myEnforcedTableWidget->setSortingEnabled(true);
1113 // myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1114 updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1117 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1118 This method is called when a item is added into the enforced meshes tree widget
1120 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1122 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1124 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1125 myEnfMeshWdg->deactivateSelection();
1127 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1128 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1131 int selEnfMeshes = myEnfMeshWdg->NbObjects();
1132 if (selEnfMeshes == 0)
1135 std::string groupName = myMeshGroupName->text().simplified().toStdString();
1137 int elementType = myEnfMeshConstraint->currentIndex();
1140 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1141 _PTR(SObject) aSObj;
1142 QString meshEntry = myEnfMeshWdg->GetValue();
1144 if (selEnfMeshes == 1)
1146 aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str());
1147 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1148 if (!CORBA::is_nil(anObj))
1149 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1153 QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts);
1154 QStringListIterator meshEntriesIt (meshEntries);
1155 while (meshEntriesIt.hasNext()) {
1156 aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str());
1157 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1158 if (!CORBA::is_nil(anObj)) {
1159 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1164 myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil());
1166 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1167 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1171 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1172 This method is called when a item is added into the enforced vertices tree widget
1174 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1176 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1178 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1179 myEnfVertexWdg->deactivateSelection();
1181 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1182 myEnforcedTableWidget->resizeColumnToContents(column);
1185 int selEnfVertex = myEnfVertexWdg->NbObjects();
1186 bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1187 if ((selEnfVertex == 0) && coordsEmpty)
1190 std::string groupName = myGroupName->text().simplified().toStdString();
1192 double size = mySizeValue->GetValue();
1194 if (selEnfVertex <= 1)
1196 double x = 0, y = 0, z=0;
1197 if (myXCoord->GetString() != "") {
1198 x = myXCoord->GetValue();
1199 y = myYCoord->GetValue();
1200 z = myZCoord->GetValue();
1202 if (selEnfVertex == 1) {
1203 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1204 std::string entry = "", name = "";
1205 bool isCompound = false;
1206 if ( !myEnfVertex->_is_nil() ) {
1207 entry = SMESH::toStdStr( myEnfVertex->GetStudyEntry() );
1208 name = SMESH::toStdStr( myEnfVertex->GetName() );
1209 isCompound = ( myEnfVertex->GetShapeType() == GEOM::COMPOUND );
1211 addEnforcedVertex(x, y, z, size, name, entry, groupName, isCompound);
1214 addEnforcedVertex(x, y, z, size, "", "", groupName);
1219 if ( CORBA::is_nil(getGeomEngine()))
1222 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1223 if (CORBA::is_nil(measureOp))
1226 CORBA::Double x = 0, y = 0,z = 0;
1227 for (int j = 0 ; j < selEnfVertex ; j++)
1229 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1230 if (myEnfVertex == GEOM::GEOM_Object::_nil())
1232 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1233 measureOp->PointCoordinates (myEnfVertex, x, y, z);
1234 if ( measureOp->IsDone() )
1235 addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1236 } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1237 addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true);
1242 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1244 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1245 myEnforcedTableWidget->resizeColumnToContents(column);
1248 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1249 This method is called when a item is removed from the enforced meshes tree widget
1251 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1253 QList<int> selectedRows;
1254 QList<QTableWidgetItem *> selectedItems = myEnforcedMeshTableWidget->selectedItems();
1255 QTableWidgetItem* item;
1257 foreach( item, selectedItems ) {
1259 if (!selectedRows.contains( row ) )
1260 selectedRows.append(row);
1263 qSort( selectedRows );
1264 QListIterator<int> it( selectedRows );
1266 while ( it.hasPrevious() ) {
1267 row = it.previous();
1268 myEnforcedMeshTableWidget->removeRow(row );
1271 myEnforcedMeshTableWidget->selectionModel()->clearSelection();
1274 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1275 This method is called when a item is removed from the enforced vertices tree widget
1277 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1279 QList<int> selectedRows;
1280 QList<QTableWidgetItem *> selectedItems = myEnforcedTableWidget->selectedItems();
1281 QTableWidgetItem* item;
1283 foreach( item, selectedItems ) {
1285 if (!selectedRows.contains( row ) )
1286 selectedRows.append(row);
1289 qSort( selectedRows );
1290 QListIterator<int> it( selectedRows );
1292 while ( it.hasPrevious() ) {
1293 row = it.previous();
1294 myEnforcedTableWidget->removeRow(row );
1297 myEnforcedTableWidget->selectionModel()->clearSelection();
1300 void GHS3DPluginGUI_HypothesisCreator::onToMeshHoles(bool isOn)
1302 // myToMakeGroupsOfDomains->setEnabled( isOn );
1304 // myToMakeGroupsOfDomains->setChecked( false );
1307 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
1309 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myAdvWidget->workingDirectoryLineEdit->text(), QString() );
1310 if ( !dir.isEmpty() )
1311 myAdvWidget->workingDirectoryLineEdit->setText( dir );
1314 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
1316 //myToMakeGroupsOfDomains->setEnabled( myToMeshHolesCheck->isChecked() );
1317 myAdvWidget->maxMemorySpin->setEnabled( myAdvWidget->maxMemoryCheck->isChecked() );
1318 myAdvWidget->initialMemoryCheck->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1319 myAdvWidget->initialMemorySpin->setEnabled( myAdvWidget->initialMemoryCheck->isChecked() && !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1320 myOptimizationLevelCombo->setEnabled( !myAdvWidget->boundaryRecoveryCheck->isChecked() );
1321 if ( sender() == myAdvWidget->logInFileCheck ||
1322 sender() == myAdvWidget->keepWorkingFilesCheck )
1324 bool logFileRemovable = myAdvWidget->logInFileCheck->isChecked() &&
1325 !myAdvWidget->keepWorkingFilesCheck->isChecked();
1327 myAdvWidget->removeLogOnSuccessCheck->setEnabled( logFileRemovable );
1331 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
1333 if ( !QFileInfo( myAdvWidget->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
1334 SUIT_MessageBox::warning( dlg(),
1335 tr( "SMESH_WRN_WARNING" ),
1336 tr( "GHS3D_PERMISSION_DENIED" ) );
1343 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
1345 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1346 GHS3DHypothesisData data;
1347 readParamsFromHypo( data );
1351 myName->setText( data.myName );
1353 int width = QFontMetrics( myName->font() ).width( data.myName );
1354 QGridLayout* aStdLayout = (QGridLayout*) myStdGroup->layout();
1355 aStdLayout->setColumnMinimumWidth( 1, width + 10 );
1357 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
1358 myToMakeGroupsOfDomains ->setChecked ( data.myToMakeGroupsOfDomains );
1359 myOptimizationLevelCombo ->setCurrentIndex( data.myOptimizationLevel );
1360 myOptimizationCombo ->setCurrentIndex( data.myOptimization );
1361 mySplitOverConstrainedCombo ->setCurrentIndex( data.mySplitOverConstrained );
1362 myPThreadsModeCombo ->setCurrentIndex( data.myPThreadsMode );
1363 myNumberOfThreadsSpin ->setValue ( data.myNumberOfThreads );
1364 mySmoothOffSliversCheck ->setChecked ( data.mySmoothOffSlivers );
1365 myCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
1367 myAdvWidget->maxMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
1368 myAdvWidget->maxMemorySpin ->setValue ( qMax( (int)data.myMaximumMemory,
1369 myAdvWidget->maxMemorySpin->minimum() ));
1370 myAdvWidget->initialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
1371 myAdvWidget->initialMemorySpin ->setValue ( qMax( (int)data.myInitialMemory,
1372 myAdvWidget->initialMemorySpin->minimum() ));
1373 myAdvWidget->workingDirectoryLineEdit ->setText ( data.myWorkingDir );
1374 myAdvWidget->keepWorkingFilesCheck ->setChecked ( data.myKeepFiles );
1375 myAdvWidget->verboseLevelSpin ->setValue ( data.myVerboseLevel );
1376 myAdvWidget->createNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
1377 myAdvWidget->removeInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint );
1378 myAdvWidget->boundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
1379 myAdvWidget->FEMCorrectionCheck ->setChecked ( data.myFEMCorrection );
1380 myAdvWidget->gradationSpinBox ->setValue ( data.myGradation );
1381 myAdvWidget->advOptionTable ->SetCustomOptions( data.myTextOption );
1382 myAdvWidget->logInFileCheck ->setChecked ( !data.myLogInStandardOutput );
1383 myAdvWidget->removeLogOnSuccessCheck ->setChecked ( data.myRemoveLogOnSuccess );
1385 TEnfVertexList::const_iterator it;
1387 myEnforcedTableWidget->clearContents();
1388 myEnforcedTableWidget->setSortingEnabled(false);
1389 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1390 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
1392 TEnfVertex* enfVertex = (*it);
1393 myEnforcedTableWidget->setRowCount(rowCount+1);
1395 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1396 QTableWidgetItem* item = new QTableWidgetItem();
1397 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1399 case ENF_VER_NAME_COLUMN:
1400 item->setData( 0, enfVertex->name.c_str() );
1401 if (!enfVertex->geomEntry.empty()) {
1402 if (enfVertex->isCompound)
1403 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1405 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1409 case ENF_VER_X_COLUMN:
1410 if (!enfVertex->isCompound) {
1411 item->setData( 0, enfVertex->coords.at(0) );
1414 case ENF_VER_Y_COLUMN:
1415 if (!enfVertex->isCompound) {
1416 item->setData( 0, enfVertex->coords.at(1) );
1419 case ENF_VER_Z_COLUMN:
1420 if (!enfVertex->isCompound) {
1421 item->setData( 0, enfVertex->coords.at(2) );
1424 case ENF_VER_SIZE_COLUMN:
1425 item->setData( 0, enfVertex->size );
1427 case ENF_VER_ENTRY_COLUMN:
1428 item->setData( 0, enfVertex->geomEntry.c_str() );
1430 case ENF_VER_COMPOUND_COLUMN:
1431 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1432 item->setData( Qt::CheckStateRole, enfVertex->isCompound );
1434 case ENF_VER_GROUP_COLUMN:
1435 item->setData( 0, enfVertex->groupName.c_str() );
1441 myEnforcedTableWidget->setItem(rowCount,col,item);
1443 that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1447 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1448 myEnforcedTableWidget->setSortingEnabled(true);
1450 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1451 myEnforcedTableWidget->resizeColumnToContents(column);
1453 // Update Enforced meshes QTableWidget
1454 TEnfMeshList::const_iterator itMesh;
1456 myEnforcedMeshTableWidget->clearContents();
1457 myEnforcedMeshTableWidget->setSortingEnabled(false);
1458 // myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1459 for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ )
1461 TEnfMesh* enfMesh = (*itMesh);
1462 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1464 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1465 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1466 QComboBox* comboBox = new QComboBox();
1467 QPalette pal = comboBox->palette();
1468 pal.setColor(QPalette::Button, Qt::white);
1469 comboBox->setPalette(pal);
1470 comboBox->insertItems(0,myEnfMeshConstraintLabels);
1471 comboBox->setEditable(false);
1472 comboBox->setCurrentIndex(enfMesh->elementType);
1473 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1476 QTableWidgetItem* item = new QTableWidgetItem();
1477 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1479 case ENF_MESH_NAME_COLUMN:
1480 item->setData( 0, enfMesh->name.c_str() );
1481 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1482 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1484 case ENF_MESH_ENTRY_COLUMN:
1485 item->setData( 0, enfMesh->entry.c_str() );
1486 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1487 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1489 case ENF_MESH_GROUP_COLUMN:
1490 item->setData( 0, enfMesh->groupName.c_str() );
1491 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1502 myEnforcedMeshTableWidget->setSortingEnabled(true);
1504 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++)
1505 myEnforcedMeshTableWidget->resizeColumnToContents(col);
1507 that->updateWidgets();
1508 that->checkVertexIsDefined();
1511 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
1513 GHS3DHypothesisData data;
1514 readParamsFromWidgets( data );
1515 storeParamsToHypo( data );
1517 QString valStr = "";
1519 if ( !data.myBoundaryRecovery )
1520 valStr = " --components " + data.myToMeshHoles ? "all" : "outside_components" ;
1522 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
1523 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1524 valStr += " --optimisation_level ";
1525 valStr += level[ data.myOptimizationLevel ];
1527 if ( data.myMaximumMemory > 0 ) {
1528 valStr += " --max_memory ";
1529 valStr += QString::number( data.myMaximumMemory );
1531 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
1532 valStr += " --automatic_memory ";
1533 valStr += QString::number( data.myInitialMemory );
1535 valStr += " --verbose ";
1536 valStr += QString::number( data.myVerboseLevel );
1538 if ( !data.myToCreateNewNodes )
1539 valStr += " --no_internal_points";
1541 if ( data.myRemoveInitialCentralPoint )
1542 valStr += " --no_initial_central_point";
1544 if ( data.myBoundaryRecovery )
1547 if ( data.myFEMCorrection )
1550 if ( data.myGradation != 1.05 ) {
1551 valStr += " -Dcpropa=";
1552 valStr += QString::number( data.myGradation );
1556 valStr += data.myTextOption;
1561 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
1563 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1564 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1565 GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis_var opt =
1566 GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis::_narrow( initParamsHypothesis() );
1568 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1569 h_data.myName = isCreation() && data ? hypName() : "";
1571 if ( !opt->_is_nil() )
1573 h_data.myOptimization = opt->GetOptimization();
1574 h_data.mySplitOverConstrained = opt->GetSplitOverConstrained();
1575 h_data.myPThreadsMode = opt->GetPThreadsMode();
1576 h_data.myNumberOfThreads = opt->GetMaximalNumberOfThreads();
1577 h_data.mySmoothOffSlivers = opt->GetSmoothOffSlivers();
1579 h_data.myToMeshHoles = h->GetToMeshHoles();
1580 h_data.myToMakeGroupsOfDomains = h->GetToMakeGroupsOfDomains();
1581 h_data.myMaximumMemory = h->GetMaximumMemory();
1582 h_data.myInitialMemory = h->GetInitialMemory();
1583 h_data.myInitialMemory = h->GetInitialMemory();
1584 h_data.myOptimizationLevel = h->GetOptimizationLevel();
1585 h_data.myKeepFiles = h->GetKeepFiles();
1586 h_data.myWorkingDir = h->GetWorkingDirectory();
1587 h_data.myVerboseLevel = h->GetVerboseLevel();
1588 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
1589 h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint();
1590 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
1591 h_data.myFEMCorrection = h->GetFEMCorrection();
1592 h_data.myGradation = h->GetGradation();
1593 h_data.myTextOption = h->GetAdvancedOption();
1594 h_data.myLogInStandardOutput = h->GetStandardOutputLog();
1595 h_data.myRemoveLogOnSuccess = h->GetRemoveLogOnSuccess();
1597 GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
1598 h_data.myEnforcedVertices.clear();
1599 for (CORBA::ULong i=0 ; i<vertices->length() ; i++) {
1600 TEnfVertex* myVertex = new TEnfVertex();
1601 myVertex->name = CORBA::string_dup(vertices[i].name.in());
1602 myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in());
1603 myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in());
1604 myVertex->size = vertices[i].size;
1605 myVertex->isCompound = vertices[i].isCompound;
1606 if (vertices[i].coords.length()) {
1607 for (CORBA::ULong c = 0; c < vertices[i].coords.length() ; c++)
1608 myVertex->coords.push_back(vertices[i].coords[c]);
1610 h_data.myEnforcedVertices.insert(myVertex);
1613 GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes();
1614 h_data.myEnforcedMeshes.clear();
1615 for (CORBA::ULong i=0 ; i<enfMeshes->length() ; i++) {
1616 TEnfMesh* myEnfMesh = new TEnfMesh();
1617 myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in());
1618 myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in());
1619 myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in());
1620 switch (enfMeshes[i].elementType) {
1622 myEnfMesh->elementType = 0;
1625 myEnfMesh->elementType = 1;
1628 myEnfMesh->elementType = 2;
1633 // myEnfMesh->elementType = enfMeshes[i].elementType;
1634 h_data.myEnforcedMeshes.insert(myEnfMesh);
1639 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
1641 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1642 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
1643 GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis_var opt =
1644 GHS3DPlugin::GHS3DPlugin_OptimizerHypothesis::_narrow( initParamsHypothesis() );
1650 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1652 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
1653 h->SetToMeshHoles ( h_data.myToMeshHoles );
1654 if ( h->GetToMakeGroupsOfDomains() != h_data.myToMakeGroupsOfDomains )
1655 h->SetToMakeGroupsOfDomains( h_data.myToMakeGroupsOfDomains );
1656 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
1657 h->SetMaximumMemory ( h_data.myMaximumMemory );
1658 if ( h->GetInitialMemory() != h_data.myInitialMemory )
1659 h->SetInitialMemory ( h_data.myInitialMemory );
1660 if ( h->GetInitialMemory() != h_data.myInitialMemory )
1661 h->SetInitialMemory ( h_data.myInitialMemory );
1662 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
1663 h->SetOptimizationLevel( h_data.myOptimizationLevel );
1664 if ( h->GetKeepFiles() != h_data.myKeepFiles )
1665 h->SetKeepFiles ( h_data.myKeepFiles );
1666 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
1667 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
1668 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
1669 h->SetVerboseLevel ( h_data.myVerboseLevel );
1670 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
1671 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
1672 if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
1673 h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
1674 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
1675 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
1676 if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
1677 h->SetFEMCorrection ( h_data.myFEMCorrection );
1678 if ( h->GetGradation() != h_data.myGradation )
1679 h->SetGradation ( h_data.myGradation );
1680 if ( h->GetAdvancedOption() != h_data.myTextOption )
1681 h->SetAdvancedOption ( h_data.myTextOption.toLatin1().constData() );
1682 if ( h->GetStandardOutputLog() != h_data.myLogInStandardOutput )
1683 h->SetStandardOutputLog( h_data.myLogInStandardOutput );
1684 if ( h->GetRemoveLogOnSuccess() != h_data.myRemoveLogOnSuccess )
1685 h->SetRemoveLogOnSuccess( h_data.myRemoveLogOnSuccess );
1687 if ( !opt->_is_nil() )
1689 opt->SetOptimization ( (GHS3DPlugin::Mode) h_data.myOptimization );
1690 opt->SetSplitOverConstrained ( (GHS3DPlugin::Mode) h_data.mySplitOverConstrained );
1691 opt->SetPThreadsMode ( (GHS3DPlugin::PThreadsMode) h_data.myPThreadsMode );
1692 opt->SetSmoothOffSlivers ( h_data.mySmoothOffSlivers );
1693 opt->SetMaximalNumberOfThreads( h_data.myNumberOfThreads );
1696 // Enforced vertices
1697 GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
1698 int nbVertexHyp = vertexHyp->length();
1700 // 1. Clear all enforced vertices in hypothesis
1701 // 2. Add new enforced vertex according to h_data
1702 if ( nbVertexHyp > 0)
1703 h->ClearEnforcedVertices();
1705 TEnfVertexList::const_iterator it;
1706 double x = 0, y = 0, z = 0;
1707 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
1708 TEnfVertex* enfVertex = (*it);
1710 if (enfVertex->coords.size()) {
1711 x = enfVertex->coords.at(0);
1712 y = enfVertex->coords.at(1);
1713 z = enfVertex->coords.at(2);
1715 ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound);
1719 GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes();
1720 int nbEnfMeshListHyp = enfMeshListHyp->length();
1722 // 1. Clear all enforced vertices in hypothesis
1723 // 2. Add new enforced vertex according to h_data
1724 if ( nbEnfMeshListHyp > 0)
1725 h->ClearEnforcedMeshes();
1727 TEnfMeshList::const_iterator itEnfMesh;
1729 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1731 for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) {
1732 TEnfMesh* enfMesh = (*itEnfMesh);
1734 _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str());
1735 SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1737 SMESH::ElementType elementType;
1738 switch(enfMesh->elementType) {
1740 elementType = SMESH::NODE;
1743 elementType = SMESH::EDGE;
1746 elementType = SMESH::FACE;
1752 ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->name.c_str(), enfMesh->groupName.c_str());
1755 catch ( const SALOME::SALOME_Exception& ex )
1757 SalomeApp_Tools::QtCatchCorbaException( ex );
1763 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
1765 h_data.myName = myName ? myName->text() : "";
1766 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
1767 h_data.myToMakeGroupsOfDomains = myToMakeGroupsOfDomains->isChecked();
1768 h_data.myOptimization = myOptimizationCombo->currentIndex();
1769 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
1770 h_data.mySplitOverConstrained = mySplitOverConstrainedCombo->currentIndex();
1771 h_data.myPThreadsMode = myPThreadsModeCombo->currentIndex();
1772 h_data.myNumberOfThreads = myNumberOfThreadsSpin->value();
1773 h_data.mySmoothOffSlivers = mySmoothOffSliversCheck->isChecked();
1774 h_data.myMaximumMemory = myAdvWidget->maxMemoryCheck->isChecked() ? myAdvWidget->maxMemorySpin->value() : -1;
1775 h_data.myInitialMemory = myAdvWidget->initialMemoryCheck->isChecked() ? myAdvWidget->initialMemorySpin->value() : -1;
1776 h_data.myKeepFiles = myAdvWidget->keepWorkingFilesCheck->isChecked();
1777 h_data.myWorkingDir = myAdvWidget->workingDirectoryLineEdit->text().trimmed();
1778 h_data.myVerboseLevel = myAdvWidget->verboseLevelSpin->value();
1779 h_data.myRemoveInitialCentralPoint = myAdvWidget->removeInitialCentralPointCheck->isChecked();
1780 h_data.myBoundaryRecovery = myAdvWidget->boundaryRecoveryCheck->isChecked();
1781 h_data.myFEMCorrection = myAdvWidget->FEMCorrectionCheck->isChecked();
1782 h_data.myGradation = myAdvWidget->gradationSpinBox->value();
1783 h_data.myTextOption = myAdvWidget->advOptionTable->GetCustomOptions();
1784 h_data.myLogInStandardOutput = !myAdvWidget->logInFileCheck->isChecked();
1785 h_data.myRemoveLogOnSuccess = myAdvWidget->removeLogOnSuccessCheck->isChecked();
1786 if ( isOptimization() )
1787 h_data.myToCreateNewNodes = myCreateNewNodesCheck->isChecked();
1789 h_data.myToCreateNewNodes = myAdvWidget->createNewNodesCheck->isChecked();
1791 // Enforced vertices
1792 h_data.myEnforcedVertices.clear();
1793 QVariant valueX, valueY, valueZ;
1794 for (int row=0 ; row<myEnforcedTableWidget->rowCount() ; row++)
1796 TEnfVertex *myVertex = new TEnfVertex();
1797 myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1798 myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1799 myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1800 valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole);
1801 valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole);
1802 valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole);
1803 if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) {
1804 myVertex->coords.push_back(valueX.toDouble());
1805 myVertex->coords.push_back(valueY.toDouble());
1806 myVertex->coords.push_back(valueZ.toDouble());
1808 myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble();
1809 myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool();
1810 h_data.myEnforcedVertices.insert(myVertex);
1814 h_data.myEnforcedMeshes.clear();
1816 for (int row=0 ; row<myEnforcedMeshTableWidget->rowCount() ; row++)
1818 TEnfMesh *myEnfMesh = new TEnfMesh();
1819 myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1820 myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1821 myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1822 QComboBox* combo = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN));
1823 myEnfMesh->elementType = combo->currentIndex();
1824 h_data.myEnforcedMeshes.insert(myEnfMesh);
1830 QString GHS3DPluginGUI_HypothesisCreator::caption() const
1832 return tr( "GHS3D_TITLE" );
1835 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
1837 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
1840 QString GHS3DPluginGUI_HypothesisCreator::type() const
1842 return tr( isOptimization() ? "GHS3D_OPTIMIZATIOL_HYPOTHESIS" : "GHS3D_HYPOTHESIS" );
1845 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
1847 return isOptimization() ? "optimization_page.html" : "ghs3d_hypo_page.html";