1 // Copyright (C) 2004-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 // File : GHS3DPluginGUI_HypothesisCreator.cxx
22 // Author : Michael Zorin
23 // Module : GHS3DPlugin
26 #include "GHS3DPluginGUI_HypothesisCreator.h"
27 // #include "GHS3DPluginGUI_EnforcedDelegates.h"
28 #include "GHS3DPluginGUI_Enums.h"
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_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_FileDlg.h>
44 #include <SalomeApp_Tools.h>
45 #include <SalomeApp_TypeFilter.h>
47 #include <TopoDS_Iterator.hxx>
53 #include <QVBoxLayout>
54 #include <QGridLayout>
59 #include <QPushButton>
63 #include <QTableWidget>
64 #include <QTableWidgetItem>
65 #include <QHeaderView>
68 #include <utilities.h>
70 #include <boost/algorithm/string.hpp>
77 #include <sys/sysinfo.h>
80 int maxAvailableMemory()
83 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
84 MEMORYSTATUSEX statex;
85 statex.dwLength = sizeof (statex);
86 int err = GlobalMemoryStatusEx (&statex);
89 statex.ullTotalPhys / 1024 / 1024 +
90 statex.ullTotalPageFile / 1024 / 1024 +
91 statex.ullTotalVirtual / 1024 / 1024;
92 return (int) ( 0.7 * totMB );
96 int err = sysinfo( &si );
99 si.totalram * si.mem_unit / 1024 / 1024 +
100 si.totalswap * si.mem_unit / 1024 / 1024 ;
101 return (int) ( 0.7 * totMB );
109 // BEGIN EnforcedVertexTableWidgetDelegate
112 EnforcedVertexTableWidgetDelegate::EnforcedVertexTableWidgetDelegate(QObject *parent)
113 : QItemDelegate(parent)
117 QWidget *EnforcedVertexTableWidgetDelegate::createEditor(QWidget *parent,
118 const QStyleOptionViewItem & option ,
119 const QModelIndex & index ) const
121 QModelIndex father = index.parent();
122 QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
124 if (index.column() == ENF_VER_X_COLUMN ||
125 index.column() == ENF_VER_Y_COLUMN ||
126 index.column() == ENF_VER_Z_COLUMN ||
127 index.column() == ENF_VER_SIZE_COLUMN) {
128 SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
129 if (index.column() == ENF_VER_SIZE_COLUMN)
130 editor->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
132 editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
133 editor->setReadOnly(!entry.isEmpty());
134 editor->setDisabled(!entry.isEmpty());
137 // else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
138 // QCheckBox *editor = new QCheckBox(parent);
139 // editor->setDisabled(!entry.isEmpty());
142 else if (index.column() == ENF_VER_GROUP_COLUMN ||
143 index.column() == ENF_VER_NAME_COLUMN) {
145 QLineEdit *editor = new QLineEdit(parent);
146 if (index.column() != ENF_VER_GROUP_COLUMN) {
147 editor->setReadOnly(!entry.isEmpty());
148 editor->setDisabled(!entry.isEmpty());
152 return QItemDelegate::createEditor(parent, option, index);
155 void EnforcedVertexTableWidgetDelegate::setEditorData(QWidget *editor,
156 const QModelIndex &index) const
158 if (index.column() == ENF_VER_X_COLUMN ||
159 index.column() == ENF_VER_Y_COLUMN ||
160 index.column() == ENF_VER_Z_COLUMN ||
161 index.column() == ENF_VER_SIZE_COLUMN)
163 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
164 lineEdit->SetValue(index.data().toDouble());
166 else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
167 QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
168 checkBox->setChecked(index.data().toBool());
171 QItemDelegate::setEditorData(editor, index);
175 void EnforcedVertexTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
176 const QModelIndex &index) const
178 QModelIndex parent = index.parent();
180 QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString();
181 bool isCompound = parent.child(index.row(), ENF_VER_COMPOUND_COLUMN).data(Qt::CheckStateRole).toBool();
183 if (index.column() == ENF_VER_X_COLUMN ||
184 index.column() == ENF_VER_Y_COLUMN ||
185 index.column() == ENF_VER_Z_COLUMN) {
186 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
187 if (!isCompound && !vertexExists(model, index, lineEdit->GetString()))
188 model->setData(index, lineEdit->GetValue(), Qt::EditRole);
190 else if (index.column() == ENF_VER_SIZE_COLUMN)
192 SMESHGUI_SpinBox *lineEdit = qobject_cast<SMESHGUI_SpinBox*>(editor);
193 const double newsize = lineEdit->GetValue();
195 model->setData(index, newsize, Qt::EditRole);
197 else if (index.column() == ENF_VER_NAME_COLUMN) {
198 QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
199 QString value = lineEdit->text();
200 if (entry.isEmpty() && !vertexExists(model, index, value))
201 model->setData(index, value, Qt::EditRole);
203 else if (index.column() == ENF_VER_ENTRY_COLUMN) {
204 QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
205 QString value = lineEdit->text();
206 if (! vertexExists(model, index, value))
207 model->setData(index, value, Qt::EditRole);
209 else if (index.column() == ENF_VER_COMPOUND_COLUMN) {
210 QCheckBox *checkBox = qobject_cast<QCheckBox*>(editor);
211 model->setData(index, checkBox->isChecked(), Qt::CheckStateRole);
214 QItemDelegate::setModelData(editor, model, index);
218 void EnforcedVertexTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
219 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
221 editor->setGeometry(option.rect);
224 bool EnforcedVertexTableWidgetDelegate::vertexExists(QAbstractItemModel *model,
225 const QModelIndex &index,
229 QModelIndex parent = index.parent();
230 int row = index.row();
231 int col = index.column();
233 if (parent.isValid() && !value.isEmpty()) {
234 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
236 if (col == ENF_VER_X_COLUMN) {
237 x = value.toDouble();
238 y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
239 z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
241 if (col == ENF_VER_Y_COLUMN) {
242 y = value.toDouble();
243 x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
244 z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble();
246 if (col == ENF_VER_Z_COLUMN) {
247 z = value.toDouble();
248 x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble();
249 y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble();
251 int nbChildren = model->rowCount(parent);
252 for (int i = 0 ; i < nbChildren ; i++) {
254 double childX = parent.child(i, ENF_VER_X_COLUMN).data().toDouble();
255 double childY = parent.child(i, ENF_VER_Y_COLUMN).data().toDouble();
256 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data().toDouble();
257 if ((childX == x) && (childY == y) && (childZ == z)) {
264 else if (col == ENF_VER_NAME_COLUMN) {
265 QString name = parent.child(row, ENF_VER_NAME_COLUMN).data().toString();
275 // END EnforcedVertexTableWidgetDelegate
279 // BEGIN EnforcedMeshTableWidgetDelegate
282 EnforcedMeshTableWidgetDelegate::EnforcedMeshTableWidgetDelegate(QObject *parent)
283 : QItemDelegate(parent)
287 QWidget *EnforcedMeshTableWidgetDelegate::createEditor(QWidget *parent,
288 const QStyleOptionViewItem & option ,
289 const QModelIndex & index ) const
291 return QItemDelegate::createEditor(parent, option, index);
294 void EnforcedMeshTableWidgetDelegate::setEditorData(QWidget *editor,
295 const QModelIndex &index) const
297 QItemDelegate::setEditorData(editor, index);
300 void EnforcedMeshTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
301 const QModelIndex &index) const
303 QItemDelegate::setModelData(editor, model, index);
307 void EnforcedMeshTableWidgetDelegate::updateEditorGeometry(QWidget *editor,
308 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
310 editor->setGeometry(option.rect);
313 // bool EnforcedMeshTableWidgetDelegate::enfMeshExists(QAbstractItemModel *model,
314 // const QModelIndex &index,
315 // QString value) const
317 // bool exists = false;
318 // QModelIndex parent = index.parent();
319 // int row = index.row();
320 // int col = index.column();
325 // END EnforcedMeshTableWidgetDelegate
329 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
330 : SMESHGUI_GenericHypothesisCreator( theHypType )
332 GeomToolSelected = NULL;
333 GeomToolSelected = getGeomSelectionTool();
335 iconVertex = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
336 iconCompound = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_COMPOUND")));
337 // mySelectionMgr = SMESH::GetSelectionMgr(SMESHGUI::GetSMESHGUI());
338 myEnfMeshConstraintLabels << tr( "GHS3D_ENF_MESH_CONSTRAINT_NODE" ) << tr( "GHS3D_ENF_MESH_CONSTRAINT_EDGE" ) << tr("GHS3D_ENF_MESH_CONSTRAINT_FACE");
341 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
343 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
344 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
345 myEnfMeshWdg->deactivateSelection();
349 * \brief {Get or create the geom selection tool for active study}
351 GeomSelectionTools* GHS3DPluginGUI_HypothesisCreator::getGeomSelectionTool()
353 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
354 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
355 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
356 that->GeomToolSelected = new GeomSelectionTools(aStudy);
358 return that->GeomToolSelected;
361 GEOM::GEOM_Gen_var GHS3DPluginGUI_HypothesisCreator::getGeomEngine()
363 return GeometryGUI::GetGeomGen();
366 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
368 QFrame* fr = new QFrame( 0 );
369 QVBoxLayout* lay = new QVBoxLayout( fr );
371 lay->setSpacing( 0 );
374 QTabWidget* tab = new QTabWidget( fr );
375 tab->setTabShape( QTabWidget::Rounded );
376 tab->setTabPosition( QTabWidget::North );
377 lay->addWidget( tab );
380 myStdGroup = new QWidget();
381 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
382 aStdLayout->setSpacing( 6 );
383 aStdLayout->setMargin( 11 );
389 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
390 myName = new QLineEdit( myStdGroup );
391 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
394 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
395 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
397 aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0, 1, 1 );
398 myOptimizationLevelCombo = new QComboBox( myStdGroup );
399 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
402 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" ) << tr( "LEVEL_STRONG" );
403 myOptimizationLevelCombo->addItems( types );
405 aStdLayout->setRowStretch( row, 10 );
407 // advanced parameters
408 myAdvGroup = new QWidget();
409 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
410 anAdvLayout->setSpacing( 6 );
411 anAdvLayout->setMargin( 11 );
413 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
414 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
415 myMaximumMemorySpin->setMinimum( 1 );
416 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
417 myMaximumMemorySpin->setSingleStep( 10 );
418 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
420 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
421 myInitialMemorySpin = new QSpinBox( myAdvGroup );
422 myInitialMemorySpin->setMinimum( 1 );
423 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
424 myInitialMemorySpin->setSingleStep( 10 );
425 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
427 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
428 myWorkingDir = new QLineEdit( myAdvGroup );
429 //myWorkingDir->setReadOnly( true );
430 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
431 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
433 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
435 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
436 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
437 myVerboseLevelSpin->setMinimum( 0 );
438 myVerboseLevelSpin->setMaximum( 10 );
439 myVerboseLevelSpin->setSingleStep( 1 );
441 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
443 myRemoveInitialCentralPointCheck = new QCheckBox( tr( "NO_INITIAL_CENTRAL_POINT" ), myAdvGroup );
445 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
447 myFEMCorrectionCheck = new QCheckBox( tr( "FEM_CORRECTION" ), myAdvGroup );
449 QLabel* myGradationLabel = new QLabel( tr( "GHS3D_GRADATION" ), myAdvGroup );
450 myGradation = new SMESHGUI_SpinBox(myAdvGroup);
451 myGradation->RangeStepAndValidator(1.05, 5.0, 0.05, "length_precision");
453 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
454 myTextOption = new QLineEdit( myAdvGroup );
457 anAdvLayout->addWidget( myMaximumMemoryCheck, row, 0, 1, 1 );
458 anAdvLayout->addWidget( myMaximumMemorySpin, row, 1, 1, 1 );
459 anAdvLayout->addWidget( aMegabyteLabel, row++, 2, 1, 1 );
460 anAdvLayout->addWidget( myInitialMemoryCheck, row, 0, 1, 1 );
461 anAdvLayout->addWidget( myInitialMemorySpin, row, 1, 1, 1 );
462 anAdvLayout->addWidget( aMegabyteLabel2, row++, 2, 1, 1 );
463 anAdvLayout->addWidget( aWorkinDirLabel, row, 0, 1, 1 );
464 anAdvLayout->addWidget( myWorkingDir, row, 1, 1, 2 );
465 anAdvLayout->addWidget( dirBtn, row++, 3, 1, 1 );
466 anAdvLayout->addWidget( myKeepFiles, row++, 0, 1, 4 );
467 anAdvLayout->addWidget( aVerboseLevelLabel, row, 0, 1, 1 );
468 anAdvLayout->addWidget( myVerboseLevelSpin, row++, 1, 1, 2 );
469 anAdvLayout->addWidget( myToCreateNewNodesCheck, row++, 0, 1, 4 );
470 anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, row++, 0, 1, 4 );
471 anAdvLayout->addWidget( myBoundaryRecoveryCheck, row++, 0, 1, 4 );
472 anAdvLayout->addWidget( myFEMCorrectionCheck, row++, 0, 1, 4 );
473 anAdvLayout->addWidget( myGradationLabel, row, 0, 1, 1 );
474 anAdvLayout->addWidget( myGradation, row++, 1, 1, 2 );
475 anAdvLayout->addWidget( aTextOptionLabel, row, 0, 1, 1 );
476 anAdvLayout->addWidget( myTextOption, row++, 1, 1, 2 );
478 // Enforced vertices parameters
479 myEnfGroup = new QWidget();
480 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
482 myEnforcedTableWidget = new QTableWidget(myEnfGroup);
483 myEnforcedTableWidget ->setMinimumWidth(300);
484 myEnforcedTableWidget->setRowCount( 0 );
485 myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS );
486 myEnforcedTableWidget->setSortingEnabled(true);
487 QStringList enforcedHeaders;
488 enforcedHeaders << tr( "GHS3D_ENF_NAME_COLUMN" )
489 << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" )
490 << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN") << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_ENF_GROUP_COLUMN" );
492 myEnforcedTableWidget->setHorizontalHeaderLabels(enforcedHeaders);
493 myEnforcedTableWidget->verticalHeader()->hide();
494 myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true);
495 myEnforcedTableWidget->setAlternatingRowColors(true);
496 myEnforcedTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
497 myEnforcedTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
498 myEnforcedTableWidget->horizontalHeader()->setResizeMode(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, /*stretch=*/false);
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);
533 // myGlobalGroupName = new QCheckBox(tr("GHS3D_ENF_VER_GROUPS"), myEnfGroup);
534 // myGlobalGroupName->setChecked(false);
536 QGroupBox* GroupBox = new QGroupBox( myEnfGroup );
537 QLabel* info = new QLabel( GroupBox );
538 info->setText( tr( "GHS3D_ENF_VER_INFO" ) );
539 info->setWordWrap( true );
540 QVBoxLayout* GroupBoxVLayout = new QVBoxLayout( GroupBox );
541 GroupBoxVLayout->setSpacing( 6 );
542 GroupBoxVLayout->setMargin( 11 );
543 GroupBoxVLayout->addWidget( info );
546 anEnfLayout->addWidget(GroupBox, ENF_VER_WARNING, 0, 1, 2 );
547 anEnfLayout->addWidget(myEnforcedTableWidget, ENF_VER_VERTEX, 0, ENF_VER_NB_LINES, 1);
549 QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
550 anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2);
551 anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1);
552 anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1);
553 anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1);
554 anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1);
555 anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1);
556 anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1);
557 anEnfLayout2->addWidget(mySizeLabel, ENF_VER_SIZE, 0, 1, 1);
558 anEnfLayout2->addWidget(mySizeValue, ENF_VER_SIZE, 1, 1, 1);
559 anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1);
560 anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1);
561 anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1);
562 anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1);
563 anEnfLayout2->setRowStretch(ENF_VER_NB_LINES, 1);
565 anEnfLayout->addLayout(anEnfLayout2, ENF_VER_VERTEX, 1,ENF_VER_NB_LINES, 1);
566 anEnfLayout->setRowStretch(ENF_VER_VERTEX, 10);
569 // Enforced meshes parameters
570 myEnfMeshGroup = new QWidget();
571 QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup);
573 myEnforcedMeshTableWidget = new QTableWidget(myEnfGroup);
574 myEnforcedMeshTableWidget->setRowCount( 0 );
575 myEnforcedMeshTableWidget->setColumnCount( ENF_MESH_NB_COLUMNS );
576 myEnforcedMeshTableWidget->setSortingEnabled(true);
577 myEnforcedMeshTableWidget->verticalHeader()->hide();
578 QStringList enforcedMeshHeaders;
579 enforcedMeshHeaders << tr( "GHS3D_ENF_NAME_COLUMN" )
580 << tr( "GHS3D_ENF_ENTRY_COLUMN" )
581 << tr( "GHS3D_ENF_MESH_CONSTRAINT_COLUMN" )
582 << tr( "GHS3D_ENF_GROUP_COLUMN" );
583 myEnforcedMeshTableWidget->setHorizontalHeaderLabels(enforcedMeshHeaders);
584 myEnforcedMeshTableWidget->horizontalHeader()->setStretchLastSection(true);
585 myEnforcedMeshTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
586 myEnforcedMeshTableWidget->setAlternatingRowColors(true);
587 myEnforcedMeshTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
588 myEnforcedMeshTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
589 myEnforcedMeshTableWidget->resizeColumnsToContents();
590 myEnforcedMeshTableWidget->hideColumn(ENF_MESH_ENTRY_COLUMN);
592 myEnforcedMeshTableWidget->setItemDelegate(new EnforcedMeshTableWidgetDelegate());
594 // myEnfMesh = SMESH::SMESH_Mesh::_nil();
595 // myEnfMeshArray = new SMESH::mesh_array();
597 myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( SMESH::IDSOURCE, myEnfMeshGroup, /*multiSel=*/true);
598 myEnfMeshWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_MESH"), "QLineEdit { color: grey }");
600 myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
602 QLabel* myMeshConstraintLabel = new QLabel( tr( "GHS3D_ENF_MESH_CONSTRAINT_LABEL" ), myEnfMeshGroup );
603 myEnfMeshConstraint = new QComboBox(myEnfMeshGroup);
604 myEnfMeshConstraint->insertItems(0,myEnfMeshConstraintLabels);
605 myEnfMeshConstraint->setEditable(false);
606 myEnfMeshConstraint->setCurrentIndex(0);
608 QLabel* myMeshGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfMeshGroup );
609 myMeshGroupName = new QLineEdit(myEnfMeshGroup);
611 addEnfMeshButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfMeshGroup);
612 // addEnfMeshButton->setEnabled(false);
613 removeEnfMeshButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfMeshGroup);
615 QGroupBox* GroupBox2 = new QGroupBox( myEnfMeshGroup );
616 QLabel* info2 = new QLabel( GroupBox2 );
617 info2->setText( tr( "GHS3D_ENF_MESH_INFO" ) );
618 info2->setWordWrap( true );
619 QVBoxLayout* GroupBox2VLayout = new QVBoxLayout( GroupBox2 );
620 GroupBox2VLayout->setSpacing( 6 );
621 GroupBox2VLayout->setMargin( 11 );
622 GroupBox2VLayout->addWidget( info2 );
624 anEnfMeshLayout->addWidget( GroupBox2, ENF_MESH_WARNING, 0, 1, 2 );
625 anEnfMeshLayout->addWidget(myEnforcedMeshTableWidget, ENF_MESH_MESH, 0, ENF_MESH_NB_LINES , 1);
627 QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup);
628 anEnfMeshLayout2->addWidget(myEnfMeshWdg, ENF_MESH_MESH, 0, 1, 2);
629 anEnfMeshLayout2->addWidget(myMeshConstraintLabel, ENF_MESH_CONSTRAINT, 0, 1, 1);
630 anEnfMeshLayout2->addWidget(myEnfMeshConstraint, ENF_MESH_CONSTRAINT, 1, 1, 1);
631 anEnfMeshLayout2->addWidget(myMeshGroupNameLabel, ENF_MESH_GROUP, 0, 1, 1);
632 anEnfMeshLayout2->addWidget(myMeshGroupName, ENF_MESH_GROUP, 1, 1, 1);
633 anEnfMeshLayout2->addWidget(addEnfMeshButton, ENF_MESH_BTN, 0, 1, 1);
634 anEnfMeshLayout2->addWidget(removeEnfMeshButton, ENF_MESH_BTN, 1, 1, 1);
635 anEnfMeshLayout2->setRowStretch(ENF_MESH_NB_LINES, 1);
637 anEnfMeshLayout->addLayout(anEnfMeshLayout2, ENF_MESH_MESH, 1, ENF_MESH_NB_LINES, 1);
638 anEnfMeshLayout->setRowStretch(ENF_MESH_MESH, 10);
641 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
642 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
643 tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) );
644 tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "GHS3D_ENFORCED_MESHES" ) );
645 tab->setCurrentIndex( STD_TAB );
648 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
649 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
650 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
651 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
652 connect( myEnforcedTableWidget, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( synchronizeCoords() ) );
653 connect( myEnforcedTableWidget, SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
654 connect( myEnforcedTableWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
655 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertex() ) );
656 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
657 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
658 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
659 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
660 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
661 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
662 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
663 connect( myXCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
664 connect( myYCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
665 connect( myZCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
666 connect( mySizeValue, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
667 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
669 connect( addEnfMeshButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedMesh() ) );
670 connect( removeEnfMeshButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedMesh() ) );
671 // connect( myEnfMeshWdg, SIGNAL( contentModified()), this, SLOT( checkEnfMeshIsDefined() ) );
672 // connect( myEnfMeshConstraint, SIGNAL( currentIndexChanged(int) ), this, SLOT( checkEnfMeshIsDefined() ) );
673 // connect( this, SIGNAL( enfMeshDefined(bool) ), addEnfMeshButton, SLOT( setEnabled(bool) ) );
679 * This method checks if an enforced vertex is defined;
681 void GHS3DPluginGUI_HypothesisCreator::clearEnfVertexSelection()
683 if (myEnfVertexWdg->NbObjects() != 0) {
684 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
685 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
686 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
687 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
688 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
690 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
691 that->checkVertexIsDefined();
695 * This method checks if an enforced vertex is defined;
697 void GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined()
699 bool enfVertexIsDefined = false;
700 enfVertexIsDefined = (!mySizeValue->GetString().isEmpty() &&
701 (!myEnfVertexWdg->NbObjects() == 0 ||
702 (myEnfVertexWdg->NbObjects() == 0 && !myXCoord->GetString().isEmpty()
703 && !myYCoord->GetString().isEmpty()
704 && !myZCoord->GetString().isEmpty())));
705 emit vertexDefined(enfVertexIsDefined);
709 * This method checks if an enforced mesh is defined;
711 void GHS3DPluginGUI_HypothesisCreator::checkEnfMeshIsDefined()
713 emit enfMeshDefined( myEnfVertexWdg->NbObjects() != 0);
717 * This method resets the content of the X, Y, Z, size and GroupName widgets;
719 void GHS3DPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
721 myXCoord->setCleared(true);
722 myYCoord->setCleared(true);
723 myZCoord->setCleared(true);
724 // mySizeValue->setCleared(true);
725 myXCoord->setText("");
726 myYCoord->setText("");
727 myZCoord->setText("");
728 // mySizeValue->setText("");
729 // myGroupName->setText("");
730 addVertexButton->setEnabled(false);
733 /** GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item)
734 This method updates the tooltip of a modified item. The QLineEdit widgets content
735 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
737 void GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item) {
738 // MESSAGE("GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
739 int row = myEnforcedTableWidget->row(item);
741 QVariant vertexName = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole);
742 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
743 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
744 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
745 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
746 QVariant entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
747 QString groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole).toString();
749 clearEnforcedVertexWidgets();
751 if ( !x.isNull() || !entry.isNull()) {
752 QString toolTip = vertexName.toString();
753 toolTip += QString("(");
754 if (entry.isNull() || (!entry.isNull() && entry.toString() == "")) {
755 toolTip += x.toString();
756 toolTip += QString(", ") + y.toString();
757 toolTip += QString(", ") + z.toString();
760 toolTip += entry.toString();
761 toolTip += QString(")");
764 toolTip += QString("=") + size.toString();
766 if (!groupName.isEmpty())
767 toolTip += QString(" [") + groupName + QString("]");
769 // MESSAGE("Tooltip: " << toolTip.toStdString());
770 for (int col=0;col<ENF_VER_NB_COLUMNS;col++)
771 myEnforcedTableWidget->item(row,col)->setToolTip(toolTip);
774 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
775 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
776 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
777 myXCoord->SetValue(x.toDouble());
778 myYCoord->SetValue(y.toDouble());
779 myZCoord->SetValue(z.toDouble());
780 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
781 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
782 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
785 mySizeValue->SetValue(size.toDouble());
787 if (!groupName.isEmpty())
788 myGroupName->setText(groupName);
792 void GHS3DPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
793 int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
794 clearEnforcedVertexWidgets();
795 if (nbSelEnfVertex == 1)
797 if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
800 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
801 if (myEnfVertex == GEOM::GEOM_Object::_nil())
803 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
804 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
805 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
806 if (CORBA::is_nil(measureOp))
810 measureOp->PointCoordinates (myEnfVertex, x, y, z);
811 if ( measureOp->IsDone() )
813 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
814 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
815 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
816 myXCoord->SetValue(x);
817 myYCoord->SetValue(y);
818 myZCoord->SetValue(z);
819 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
820 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
821 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
827 /** GHS3DPluginGUI_HypothesisCreator::synchronizeCoords()
828 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
829 of the enforced vertex clicked in the tree widget.
831 void GHS3DPluginGUI_HypothesisCreator::synchronizeCoords() {
832 clearEnforcedVertexWidgets();
833 QList<QTableWidgetItem *> items = myEnforcedTableWidget->selectedItems();
834 // myEnfVertexWdg->disconnect(SIGNAL(contentModified()));
835 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
836 if (! items.isEmpty()) {
837 QTableWidgetItem *item;
840 if (items.size() == 1) {
842 row = myEnforcedTableWidget->row(item);
843 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
844 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
845 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
846 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
847 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
848 if (!entry.isNull()) {
849 SMESH::string_array_var objIds = new SMESH::string_array;
851 objIds[0] = entry.toString().toStdString().c_str();
852 myEnfVertexWdg->SetObjects(objIds);
855 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
857 QVariant group = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole);
858 if (!x.isNull()/* && entry.isNull()*/) {
859 // disconnect( myXCoord, SIGNAL( textChanged(const QString &)), this, SLOT( onSelectEnforcedVertex() ) );
860 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
861 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
862 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
863 myXCoord->SetValue(x.toDouble());
864 myYCoord->SetValue(y.toDouble());
865 myZCoord->SetValue(z.toDouble());
866 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
867 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
868 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
871 mySizeValue->SetValue(size.toDouble());
873 if (!group.isNull() && (!x.isNull() || !entry.isNull()))
874 myGroupName->setText(group.toString());
877 QList<QString> entryList;
878 for (int i = 0; i < items.size(); ++i) {
880 row = myEnforcedTableWidget->row(item);
881 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
883 entryList << entry.toString();
885 if (entryList.size() > 0) {
886 SMESH::string_array_var objIds = new SMESH::string_array;
887 objIds->length(entryList.size());
888 for (int i = 0; i < entryList.size() ; i++)
889 objIds[i] = entryList.at(i).toStdString().c_str();
890 myEnfVertexWdg->SetObjects(objIds);
893 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
898 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
900 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
901 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
902 that->checkVertexIsDefined();
905 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh( meshName, geomEntry, elemType, size, groupName)
906 This method adds in the tree widget an enforced mesh from mesh, submesh or group with optionally size and and groupName.
908 void GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh(std::string name, std::string entry, int elementType, std::string groupName)
910 MESSAGE("addEnforcedMesh(\"" << name << ", \"" << entry << "\", " << elementType << ", \"" << groupName << "\")");
911 bool okToCreate = true;
912 QString itemEntry = "";
913 int itemElementType = 0;
914 int rowCount = myEnforcedMeshTableWidget->rowCount();
915 bool allColumns = true;
916 for (int row = 0;row<rowCount;row++) {
917 for (int col = 0 ; col < ENF_MESH_NB_COLUMNS ; col++) {
918 MESSAGE("col: " << col);
919 if (col == ENF_MESH_CONSTRAINT_COLUMN){
920 if (qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col)) == 0) {
922 MESSAGE("allColumns = false");
926 else if (myEnforcedMeshTableWidget->item(row, col) == 0) {
928 MESSAGE("allColumns = false");
931 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
932 QComboBox* itemComboBox = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col));
933 itemElementType = itemComboBox->currentIndex();
934 MESSAGE("itemElementType: " << itemElementType);
936 else if (col == ENF_MESH_ENTRY_COLUMN)
937 itemEntry = myEnforcedMeshTableWidget->item(row, col)->data(Qt::EditRole).toString();
943 if (itemEntry == QString(entry.c_str()) && itemElementType == elementType) {
944 // // update group name
945 // if (itemGroupName.toStdString() != groupName) {
946 // MESSAGE("Group is updated from \"" << itemGroupName.toStdString() << "\" to \"" << groupName << "\"");
947 // myEnforcedMeshTableWidget->item(row, ENF_MESH_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
958 MESSAGE("Creation of enforced mesh");
960 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
961 myEnforcedMeshTableWidget->setSortingEnabled(false);
963 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
964 MESSAGE("Column: " << col);
965 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
966 QComboBox* comboBox = new QComboBox();
967 QPalette pal = comboBox->palette();
968 pal.setColor(QPalette::Button, Qt::white);
969 comboBox->setPalette(pal);
970 comboBox->insertItems(0,myEnfMeshConstraintLabels);
971 comboBox->setEditable(false);
972 comboBox->setCurrentIndex(elementType);
973 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << comboBox->currentText().toStdString());
974 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
977 QTableWidgetItem* item = new QTableWidgetItem();
978 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
980 case ENF_MESH_NAME_COLUMN:
981 item->setData( 0, name.c_str() );
982 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
983 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
984 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
986 case ENF_MESH_ENTRY_COLUMN:
987 item->setData( 0, entry.c_str() );
988 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
989 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
990 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
992 case ENF_MESH_GROUP_COLUMN:
993 item->setData( 0, groupName.c_str() );
994 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
995 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1004 // connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1006 myEnforcedMeshTableWidget->setSortingEnabled(true);
1007 // myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1008 // updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1012 /** GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex( x, y, z, size, vertexName, geomEntry, groupName)
1013 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.
1015 void GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z, double size, std::string vertexName, std::string geomEntry, std::string groupName, bool isCompound)
1017 MESSAGE("addEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ", \"" << vertexName << ", \"" << geomEntry << "\", \"" << groupName << "\", " << isCompound << ")");
1018 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1019 bool okToCreate = true;
1020 double itemX,itemY,itemZ,itemSize = 0;
1021 QString itemEntry, itemGroupName = QString("");
1022 // bool itemIsCompound;
1023 int rowCount = myEnforcedTableWidget->rowCount();
1026 for (int row = 0;row<rowCount;row++) {
1028 for (int col = 0 ; col < ENF_VER_NB_COLUMNS ; col++) {
1029 if (myEnforcedTableWidget->item(row, col) == 0) {
1034 data = myEnforcedTableWidget->item(row, col)->data(Qt::EditRole);
1035 if (!data.isNull()) {
1037 case ENF_VER_GROUP_COLUMN:
1038 itemGroupName = data.toString();
1040 case ENF_VER_ENTRY_COLUMN:
1041 itemEntry = data.toString();
1043 // case ENF_VER_COMPOUND_COLUMN:
1044 // itemIsCompound = data.toBool();
1046 case ENF_VER_X_COLUMN:
1047 itemX = data.toDouble();
1049 case ENF_VER_Y_COLUMN:
1050 itemY = data.toDouble();
1052 case ENF_VER_Z_COLUMN:
1053 itemZ = data.toDouble();
1055 case ENF_VER_SIZE_COLUMN:
1056 itemSize = data.toDouble();
1068 if (( !isCompound && ((itemX == x) && (itemY == y) && (itemZ == z))) || /*( (itemEntry.toStdString() != "") && */ (itemEntry.toStdString() == geomEntry)/*)*/) {
1070 if (itemSize != size) {
1071 MESSAGE("Size is updated from \"" << itemSize << "\" to \"" << size << "\"");
1072 myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size));
1074 // update group name
1075 if (itemGroupName.toStdString() != groupName) {
1076 MESSAGE("Group is updated from \"" << itemGroupName.toStdString() << "\" to \"" << groupName << "\"");
1077 myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
1084 if (geomEntry.empty()) {
1085 MESSAGE("Vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1088 MESSAGE("Vertex with entry " << geomEntry << " already exist: dont create again");
1093 if (geomEntry.empty()) {
1094 MESSAGE("Vertex with coords " << x << ", " << y << ", " << z<< " is created");
1097 MESSAGE("Vertex with geom entry " << geomEntry << " is created");
1102 QString myVertexName;
1103 while(indexRef != vertexIndex) {
1104 indexRef = vertexIndex;
1105 if (vertexName.empty())
1106 myVertexName = QString("Vertex #%1").arg(vertexIndex);
1108 myVertexName = QString(vertexName.c_str());
1110 for (int row = 0;row<rowCount;row++) {
1111 QString name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString();
1112 if (myVertexName == name) {
1119 MESSAGE("myVertexName is \"" << myVertexName.toStdString() << "\"");
1120 myEnforcedTableWidget->setRowCount(rowCount+1);
1121 myEnforcedTableWidget->setSortingEnabled(false);
1122 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1123 MESSAGE("Column: " << col);
1124 QTableWidgetItem* item = new QTableWidgetItem();
1125 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1127 case ENF_VER_NAME_COLUMN:
1128 item->setData( Qt::EditRole, myVertexName );
1129 if (!geomEntry.empty()) {
1131 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1133 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1136 case ENF_VER_X_COLUMN:
1138 item->setData( 0, QVariant(x) );
1140 case ENF_VER_Y_COLUMN:
1142 item->setData( 0, QVariant(y) );
1144 case ENF_VER_Z_COLUMN:
1146 item->setData( 0, QVariant(z) );
1148 case ENF_VER_SIZE_COLUMN:
1149 item->setData( 0, QVariant(size) );
1151 case ENF_VER_ENTRY_COLUMN:
1152 if (!geomEntry.empty())
1153 item->setData( 0, QString(geomEntry.c_str()) );
1155 case ENF_VER_COMPOUND_COLUMN:
1156 item->setData( Qt::CheckStateRole, isCompound );
1157 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1159 case ENF_VER_GROUP_COLUMN:
1160 if (!groupName.empty())
1161 item->setData( 0, QString(groupName.c_str()) );
1167 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1168 myEnforcedTableWidget->setItem(rowCount,col,item);
1172 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1174 myEnforcedTableWidget->setSortingEnabled(true);
1175 // myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1176 updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1179 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1180 This method is called when a item is added into the enforced meshes tree widget
1182 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1184 MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()");
1186 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1188 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1189 myEnfMeshWdg->deactivateSelection();
1191 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1192 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1195 int selEnfMeshes = myEnfMeshWdg->NbObjects();
1196 if (selEnfMeshes == 0)
1199 std::string groupName = myMeshGroupName->text().toStdString();
1200 // if (myGlobalGroupName->isChecked())
1201 // groupName = myGlobalGroupName->text().toStdString();
1203 if (boost::trim_copy(groupName).empty())
1207 int elementType = myEnfMeshConstraint->currentIndex();
1210 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1211 _PTR(SObject) aSObj; //SMESH::SMESH_IDSource::_nil;
1212 QString meshEntry = myEnfMeshWdg->GetValue();
1213 MESSAGE("myEnfMeshWdg->GetValue()" << meshEntry.toStdString());
1215 if (selEnfMeshes == 1)
1217 MESSAGE("1 SMESH object selected");
1218 // myEnfMesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
1219 // std::string entry = myEnfMeshWdg->GetValue();
1220 aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str());
1221 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1222 if (!CORBA::is_nil(anObj)) {
1223 // SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1224 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1229 MESSAGE(selEnfMeshes << " SMESH objects selected");
1230 QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts);
1231 QStringListIterator meshEntriesIt (meshEntries);
1232 while (meshEntriesIt.hasNext()) {
1233 aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str());
1234 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
1235 if (!CORBA::is_nil(anObj)) {
1236 // SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1237 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1242 myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil());
1244 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1245 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1249 /** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1250 This method is called when a item is added into the enforced vertices tree widget
1252 void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1254 MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()");
1256 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1258 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1259 myEnfVertexWdg->deactivateSelection();
1261 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1262 myEnforcedTableWidget->resizeColumnToContents(column);
1265 int selEnfVertex = myEnfVertexWdg->NbObjects();
1266 bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1267 if ((selEnfVertex == 0) && coordsEmpty)
1270 std::string groupName = myGroupName->text().toStdString();
1271 // if (myGlobalGroupName->isChecked())
1272 // groupName = myGlobalGroupName->text().toStdString();
1274 if (boost::trim_copy(groupName).empty())
1277 double size = mySizeValue->GetValue();
1279 if (selEnfVertex <= 1)
1281 MESSAGE("0 or 1 GEOM object selected");
1282 double x = 0, y = 0, z=0;
1283 if (myXCoord->GetString() != "") {
1284 x = myXCoord->GetValue();
1285 y = myYCoord->GetValue();
1286 z = myZCoord->GetValue();
1288 if (selEnfVertex == 1) {
1289 MESSAGE("1 GEOM object selected");
1290 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1291 std::string entry = "";
1292 if (myEnfVertex != GEOM::GEOM_Object::_nil())
1293 entry = myEnfVertex->GetStudyEntry();
1294 addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),entry, groupName, myEnfVertex->GetShapeType() == GEOM::COMPOUND);
1297 MESSAGE("0 GEOM object selected");
1298 MESSAGE("Coords: ("<<x<<","<<y<<","<<z<<")");
1299 addEnforcedVertex(x, y, z, size, "", "", groupName);
1304 if ( CORBA::is_nil(getGeomEngine()))
1307 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1308 if (CORBA::is_nil(measureOp))
1311 CORBA::Double x = 0, y = 0,z = 0;
1312 for (int j = 0 ; j < selEnfVertex ; j++)
1314 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1315 if (myEnfVertex == GEOM::GEOM_Object::_nil())
1317 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1318 measureOp->PointCoordinates (myEnfVertex, x, y, z);
1319 if ( measureOp->IsDone() )
1320 addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1321 } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1322 addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true);
1327 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1329 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1330 myEnforcedTableWidget->resizeColumnToContents(column);
1333 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1334 This method is called when a item is removed from the enforced meshes tree widget
1336 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1338 QList<int> selectedRows;
1339 QList<QTableWidgetItem *> selectedItems = myEnforcedMeshTableWidget->selectedItems();
1340 QTableWidgetItem* item;
1342 foreach( item, selectedItems ) {
1344 if (!selectedRows.contains( row ) )
1345 selectedRows.append(row);
1348 qSort( selectedRows );
1349 QListIterator<int> it( selectedRows );
1351 while ( it.hasPrevious() ) {
1352 row = it.previous();
1353 MESSAGE("delete row #"<< row);
1354 myEnforcedMeshTableWidget->removeRow(row );
1357 myEnforcedMeshTableWidget->selectionModel()->clearSelection();
1360 /** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1361 This method is called when a item is removed from the enforced vertices tree widget
1363 void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1365 QList<int> selectedRows;
1366 QList<QTableWidgetItem *> selectedItems = myEnforcedTableWidget->selectedItems();
1367 QTableWidgetItem* item;
1369 foreach( item, selectedItems ) {
1371 if (!selectedRows.contains( row ) )
1372 selectedRows.append(row);
1375 qSort( selectedRows );
1376 QListIterator<int> it( selectedRows );
1378 while ( it.hasPrevious() ) {
1379 row = it.previous();
1380 MESSAGE("delete row #"<< row);
1381 myEnforcedTableWidget->removeRow(row );
1384 myEnforcedTableWidget->selectionModel()->clearSelection();
1387 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
1389 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
1390 if ( !dir.isEmpty() )
1391 myWorkingDir->setText( dir );
1394 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
1396 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
1397 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
1398 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
1399 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
1402 bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
1404 MESSAGE("GHS3DPluginGUI_HypothesisCreator::checkParams");
1406 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
1407 SUIT_MessageBox::warning( dlg(),
1408 tr( "SMESH_WRN_WARNING" ),
1409 tr( "GHS3D_PERMISSION_DENIED" ) );
1416 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
1418 MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams");
1419 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
1420 GHS3DHypothesisData data;
1421 readParamsFromHypo( data );
1424 myName->setText( data.myName );
1426 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
1427 myOptimizationLevelCombo ->setCurrentIndex( data.myOptimizationLevel );
1428 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
1429 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
1430 myMaximumMemorySpin->minimum() ));
1431 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
1432 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
1433 myInitialMemorySpin->minimum() ));
1434 myWorkingDir ->setText ( data.myWorkingDir );
1435 myKeepFiles ->setChecked ( data.myKeepFiles );
1436 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
1437 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
1438 myRemoveInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint );
1439 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
1440 myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection );
1441 myGradation ->setValue ( data.myGradation );
1442 myTextOption ->setText ( data.myTextOption );
1444 TEnfVertexList::const_iterator it;
1446 myEnforcedTableWidget->clearContents();
1447 myEnforcedTableWidget->setSortingEnabled(false);
1448 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1449 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
1451 TEnfVertex* enfVertex = (*it);
1452 myEnforcedTableWidget->setRowCount(rowCount+1);
1454 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1455 MESSAGE("Column: " << col);
1456 // MESSAGE("enfVertex->isCompound: " << enfVertex->isCompound);
1457 QTableWidgetItem* item = new QTableWidgetItem();
1458 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1460 case ENF_VER_NAME_COLUMN:
1461 item->setData( 0, enfVertex->name.c_str() );
1462 if (!enfVertex->geomEntry.empty()) {
1463 if (enfVertex->isCompound)
1464 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1466 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1468 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1471 case ENF_VER_X_COLUMN:
1472 if (!enfVertex->isCompound) {
1473 item->setData( 0, enfVertex->coords.at(0) );
1474 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1477 case ENF_VER_Y_COLUMN:
1478 if (!enfVertex->isCompound) {
1479 item->setData( 0, enfVertex->coords.at(1) );
1480 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1483 case ENF_VER_Z_COLUMN:
1484 if (!enfVertex->isCompound) {
1485 item->setData( 0, enfVertex->coords.at(2) );
1486 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1489 case ENF_VER_SIZE_COLUMN:
1490 item->setData( 0, enfVertex->size );
1491 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1493 case ENF_VER_ENTRY_COLUMN:
1494 item->setData( 0, enfVertex->geomEntry.c_str() );
1495 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1497 case ENF_VER_COMPOUND_COLUMN:
1498 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1499 item->setData( Qt::CheckStateRole, enfVertex->isCompound );
1500 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << enfVertex->isCompound);
1502 case ENF_VER_GROUP_COLUMN:
1503 item->setData( 0, enfVertex->groupName.c_str() );
1504 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1510 myEnforcedTableWidget->setItem(rowCount,col,item);
1513 that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1517 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1518 myEnforcedTableWidget->setSortingEnabled(true);
1520 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1521 myEnforcedTableWidget->resizeColumnToContents(column);
1523 // Update Enforced meshes QTableWidget
1524 TEnfMeshList::const_iterator itMesh;
1526 myEnforcedMeshTableWidget->clearContents();
1527 myEnforcedMeshTableWidget->setSortingEnabled(false);
1528 // myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1529 for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ )
1531 TEnfMesh* enfMesh = (*itMesh);
1532 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1534 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1535 MESSAGE("Column: " << col);
1536 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1537 QComboBox* comboBox = new QComboBox();
1538 QPalette pal = comboBox->palette();
1539 pal.setColor(QPalette::Button, Qt::white);
1540 comboBox->setPalette(pal);
1541 comboBox->insertItems(0,myEnfMeshConstraintLabels);
1542 comboBox->setEditable(false);
1543 comboBox->setCurrentIndex(enfMesh->elementType);
1544 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << comboBox->currentText().toStdString());
1545 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1548 QTableWidgetItem* item = new QTableWidgetItem();
1549 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1551 case ENF_MESH_NAME_COLUMN:
1552 item->setData( 0, enfMesh->name.c_str() );
1553 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1554 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1555 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1557 case ENF_MESH_ENTRY_COLUMN:
1558 item->setData( 0, enfMesh->entry.c_str() );
1559 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1560 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1561 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1563 case ENF_MESH_GROUP_COLUMN:
1564 item->setData( 0, enfMesh->groupName.c_str() );
1565 MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString());
1566 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1573 // myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1576 // that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1580 // connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1581 myEnforcedMeshTableWidget->setSortingEnabled(true);
1583 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++)
1584 myEnforcedMeshTableWidget->resizeColumnToContents(col);
1586 that->updateWidgets();
1587 that->checkVertexIsDefined();
1590 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
1592 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParams");
1593 GHS3DHypothesisData data;
1594 readParamsFromWidgets( data );
1595 storeParamsToHypo( data );
1597 QString valStr = "";
1599 if ( !data.myBoundaryRecovery )
1600 valStr = "-c " + QString::number( !data.myToMeshHoles );
1602 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 5 && !data.myBoundaryRecovery) {
1603 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1605 valStr += level[ data.myOptimizationLevel ];
1607 if ( data.myMaximumMemory > 0 ) {
1609 valStr += QString::number( data.myMaximumMemory );
1611 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
1613 valStr += QString::number( data.myInitialMemory );
1616 valStr += QString::number( data.myVerboseLevel );
1618 if ( !data.myToCreateNewNodes )
1621 if ( data.myRemoveInitialCentralPoint )
1622 valStr += " -no_initial_central_point";
1624 if ( data.myBoundaryRecovery )
1627 if ( data.myFEMCorrection )
1630 if ( data.myGradation != 1.05 ) {
1631 valStr += " -Dcpropa=";
1632 valStr += QString::number( data.myGradation );
1636 valStr += data.myTextOption;
1638 // valStr += " #BEGIN ENFORCED VERTICES#";
1639 // // Add size map parameters storage
1640 // for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
1642 // double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble();
1643 // double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble();
1644 // double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble();
1645 // double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble();
1646 // valStr += QString::number( x );
1648 // valStr += QString::number( y );
1650 // valStr += QString::number( z );
1652 // valStr += QString::number( size );
1653 // if (i!=mySmpModel->rowCount()-1)
1656 // valStr += " #END ENFORCED VERTICES#";
1657 // MESSAGE(valStr.toStdString());
1661 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
1663 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo");
1664 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1665 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1667 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1668 h_data.myName = isCreation() && data ? hypName() : "";
1670 h_data.myToMeshHoles = h->GetToMeshHoles();
1671 h_data.myMaximumMemory = h->GetMaximumMemory();
1672 h_data.myInitialMemory = h->GetInitialMemory();
1673 h_data.myInitialMemory = h->GetInitialMemory();
1674 h_data.myOptimizationLevel = h->GetOptimizationLevel();
1675 h_data.myKeepFiles = h->GetKeepFiles();
1676 h_data.myWorkingDir = h->GetWorkingDirectory();
1677 h_data.myVerboseLevel = h->GetVerboseLevel();
1678 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
1679 h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint();
1680 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
1681 h_data.myFEMCorrection = h->GetFEMCorrection();
1682 h_data.myGradation = h->GetGradation();
1683 h_data.myTextOption = h->GetTextOption();
1685 GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices();
1686 MESSAGE("vertices->length(): " << vertices->length());
1687 h_data.myEnforcedVertices.clear();
1688 for (int i=0 ; i<vertices->length() ; i++) {
1689 TEnfVertex* myVertex = new TEnfVertex();
1690 myVertex->name = CORBA::string_dup(vertices[i].name.in());
1691 myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in());
1692 myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in());
1693 myVertex->size = vertices[i].size;
1694 myVertex->isCompound = vertices[i].isCompound;
1695 if (vertices[i].coords.length()) {
1696 for (int c = 0; c < vertices[i].coords.length() ; c++)
1697 myVertex->coords.push_back(vertices[i].coords[c]);
1698 MESSAGE("Add enforced vertex ("<< myVertex->coords.at(0) << ","<< myVertex->coords.at(1) << ","<< myVertex->coords.at(2) << ") ="<< myVertex->size);
1700 h_data.myEnforcedVertices.insert(myVertex);
1703 GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes();
1704 MESSAGE("enfMeshes->length(): " << enfMeshes->length());
1705 h_data.myEnforcedMeshes.clear();
1706 for (int i=0 ; i<enfMeshes->length() ; i++) {
1707 TEnfMesh* myEnfMesh = new TEnfMesh();
1708 myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in());
1709 myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in());
1710 myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in());
1711 switch (enfMeshes[i].elementType) {
1713 myEnfMesh->elementType = 0;
1716 myEnfMesh->elementType = 1;
1719 myEnfMesh->elementType = 2;
1724 // myEnfMesh->elementType = enfMeshes[i].elementType;
1725 h_data.myEnforcedMeshes.insert(myEnfMesh);
1730 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
1732 MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo");
1733 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
1734 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
1740 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1742 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
1743 h->SetToMeshHoles ( h_data.myToMeshHoles );
1744 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
1745 h->SetMaximumMemory ( h_data.myMaximumMemory );
1746 if ( h->GetInitialMemory() != h_data.myInitialMemory )
1747 h->SetInitialMemory ( h_data.myInitialMemory );
1748 if ( h->GetInitialMemory() != h_data.myInitialMemory )
1749 h->SetInitialMemory ( h_data.myInitialMemory );
1750 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
1751 h->SetOptimizationLevel( h_data.myOptimizationLevel );
1752 if ( h->GetKeepFiles() != h_data.myKeepFiles )
1753 h->SetKeepFiles ( h_data.myKeepFiles );
1754 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
1755 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
1756 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
1757 h->SetVerboseLevel ( h_data.myVerboseLevel );
1758 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
1759 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
1760 if ( h->GetToRemoveCentralPoint() != h_data.myRemoveInitialCentralPoint )
1761 h->SetToRemoveCentralPoint( h_data.myRemoveInitialCentralPoint );
1762 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
1763 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
1764 if ( h->GetFEMCorrection() != h_data.myFEMCorrection )
1765 h->SetFEMCorrection( h_data.myFEMCorrection );
1766 if ( h->GetGradation() != h_data.myGradation )
1767 h->SetGradation ( h_data.myGradation );
1768 if ( h->GetTextOption() != h_data.myTextOption )
1769 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
1771 // Enforced vertices
1772 int nbVertex = (int) h_data.myEnforcedVertices.size();
1773 GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
1774 int nbVertexHyp = vertexHyp->length();
1776 MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices");
1777 MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp);
1779 // 1. Clear all enforced vertices in hypothesis
1780 // 2. Add new enforced vertex according to h_data
1781 if ( nbVertexHyp > 0)
1782 h->ClearEnforcedVertices();
1784 TEnfVertexList::const_iterator it;
1785 double x = 0, y = 0, z = 0;
1786 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
1787 TEnfVertex* enfVertex = (*it);
1789 if (enfVertex->coords.size()) {
1790 x = enfVertex->coords.at(0);
1791 y = enfVertex->coords.at(1);
1792 z = enfVertex->coords.at(2);
1794 ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound);
1798 int nbEnfMeshes = (int) h_data.myEnforcedMeshes.size();
1799 GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes();
1800 int nbEnfMeshListHyp = enfMeshListHyp->length();
1802 MESSAGE("Store params for size maps: " << nbEnfMeshes << " enforced meshes");
1803 MESSAGE("h->GetEnforcedMeshes()->length(): " << nbEnfMeshListHyp);
1805 // 1. Clear all enforced vertices in hypothesis
1806 // 2. Add new enforced vertex according to h_data
1807 if ( nbEnfMeshListHyp > 0)
1808 h->ClearEnforcedMeshes();
1810 TEnfMeshList::const_iterator itEnfMesh;
1812 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1814 for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) {
1815 TEnfMesh* enfMesh = (*itEnfMesh);
1817 _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str());
1818 SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1820 MESSAGE("enfMesh->elementType: " << enfMesh->elementType);
1821 SMESH::ElementType elementType;
1822 switch(enfMesh->elementType) {
1824 elementType = SMESH::NODE;
1827 elementType = SMESH::EDGE;
1830 elementType = SMESH::FACE;
1836 std::cout << "h->p_SetEnforcedMesh(theSource, "<< elementType <<", \""<< enfMesh->name << "\", \"" << enfMesh->groupName.c_str() <<"\")"<<std::endl;
1837 ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->name.c_str(), enfMesh->groupName.c_str());
1840 // catch(const std::exception& ex) {
1841 // std::cout << "Exception: " << ex.what() << std::endl;
1844 catch ( const SALOME::SALOME_Exception& ex )
1846 SalomeApp_Tools::QtCatchCorbaException( ex );
1852 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
1854 MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets");
1855 h_data.myName = myName ? myName->text() : "";
1856 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
1857 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
1858 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
1859 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
1860 h_data.myKeepFiles = myKeepFiles->isChecked();
1861 h_data.myWorkingDir = myWorkingDir->text().trimmed();
1862 h_data.myVerboseLevel = myVerboseLevelSpin->value();
1863 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
1864 h_data.myRemoveInitialCentralPoint = myRemoveInitialCentralPointCheck->isChecked();
1865 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
1866 h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked();
1867 h_data.myGradation = myGradation->value();
1868 h_data.myTextOption = myTextOption->text();
1870 // Enforced vertices
1871 h_data.myEnforcedVertices.clear();
1872 QVariant valueX, valueY, valueZ;
1873 for (int row=0 ; row<myEnforcedTableWidget->rowCount() ; row++) {
1875 TEnfVertex *myVertex = new TEnfVertex();
1876 myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1877 MESSAGE("Add new enforced vertex \"" << myVertex->name << "\"" );
1878 myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1879 if (myVertex->geomEntry.size())
1880 MESSAGE("Geom entry is \"" << myVertex->geomEntry << "\"" );
1881 myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1882 if (myVertex->groupName.size())
1883 MESSAGE("Group name is \"" << myVertex->groupName << "\"" );
1884 valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole);
1885 valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole);
1886 valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole);
1887 if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) {
1888 myVertex->coords.push_back(valueX.toDouble());
1889 myVertex->coords.push_back(valueY.toDouble());
1890 myVertex->coords.push_back(valueZ.toDouble());
1891 MESSAGE("Coords are (" << myVertex->coords.at(0) << ", "
1892 << myVertex->coords.at(1) << ", "
1893 << myVertex->coords.at(2) << ")");
1895 myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble();
1896 MESSAGE("Size is " << myVertex->size);
1897 myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool();
1898 MESSAGE("Is compound ? " << myVertex->isCompound);
1899 h_data.myEnforcedVertices.insert(myVertex);
1903 h_data.myEnforcedMeshes.clear();
1905 for (int row=0 ; row<myEnforcedMeshTableWidget->rowCount() ; row++) {
1907 TEnfMesh *myEnfMesh = new TEnfMesh();
1908 myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1909 MESSAGE("Add new enforced mesh \"" << myEnfMesh->name << "\"" );
1910 myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1911 MESSAGE("Entry is \"" << myEnfMesh->entry << "\"" );
1912 myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1913 MESSAGE("Group name is \"" << myEnfMesh->groupName << "\"" );
1914 QComboBox* combo = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN));
1915 myEnfMesh->elementType = combo->currentIndex();
1916 MESSAGE("Element type: " << myEnfMesh->elementType);
1917 h_data.myEnforcedMeshes.insert(myEnfMesh);
1918 std::cout << "h_data.myEnforcedMeshes.size(): " << h_data.myEnforcedMeshes.size() << std::endl;
1924 QString GHS3DPluginGUI_HypothesisCreator::caption() const
1926 return tr( "GHS3D_TITLE" );
1929 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
1931 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
1934 QString GHS3DPluginGUI_HypothesisCreator::type() const
1936 return tr( "GHS3D_HYPOTHESIS" );
1939 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
1941 return "ghs3d_hypo_page.html";