1 // Copyright (C) 2007-2020 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
21 // File : HYBRIDPluginGUI_HypothesisCreator.cxx
22 // Author : Christian VAN WAMBEKE (CEA)
25 #include "HYBRIDPluginGUI_HypothesisCreator.h"
26 #include "HYBRIDPluginGUI_Enums.h"
27 #include "HYBRIDPluginGUI_Dlg.h"
29 #include <GeometryGUI.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_SpinBox.h>
33 #include <SMESHGUI_Utils.h>
34 #include <SMESH_NumberFilter.hxx>
35 #include <SMESH_TypeFilter.hxx>
36 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
37 #include <StdMeshersGUI_SubShapeSelectorWdg.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>
75 // #include <windows.h>
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 HYBRIDPluginGUI_HypothesisCreator::HYBRIDPluginGUI_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( "HYBRID_ENF_MESH_CONSTRAINT_NODE" ) << tr( "HYBRID_ENF_MESH_CONSTRAINT_EDGE" ) << tr("HYBRID_ENF_MESH_CONSTRAINT_FACE");
341 HYBRIDPluginGUI_HypothesisCreator::~HYBRIDPluginGUI_HypothesisCreator()
343 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
344 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
345 myEnfMeshWdg->deactivateSelection();
349 * \brief {Get or create the geom selection tool for active study}
351 GeomSelectionTools* HYBRIDPluginGUI_HypothesisCreator::getGeomSelectionTool()
353 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
354 if (that->GeomToolSelected == NULL) {
355 that->GeomToolSelected = new GeomSelectionTools();
357 return that->GeomToolSelected;
360 GEOM::GEOM_Gen_var HYBRIDPluginGUI_HypothesisCreator::getGeomEngine()
362 return GeometryGUI::GetGeomGen();
365 QFrame* HYBRIDPluginGUI_HypothesisCreator::buildFrame()
367 QFrame* fr = new QFrame( 0 );
368 QVBoxLayout* lay = new QVBoxLayout( fr );
370 lay->setSpacing( 0 );
373 QTabWidget* tab = new QTabWidget( fr );
374 tab->setTabShape( QTabWidget::Rounded );
375 tab->setTabPosition( QTabWidget::North );
376 lay->addWidget( tab );
379 myStdGroup = new QWidget();
380 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
381 aStdLayout->setSpacing( 6 );
382 aStdLayout->setMargin( 11 );
388 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
389 myName = new QLineEdit( myStdGroup );
390 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
393 myStdWidget = new HYBRIDPluginGUI_StdWidget( myStdGroup );
394 myStdWidget->verticalLayout->setMargin( 0 );
395 aStdLayout->addWidget( myStdWidget, row++, 0, 1, 2 );
397 // advanced parameters
398 myAdvWidget = new HYBRIDPluginGUI_AdvWidget( tab );
400 // Enforced vertices parameters
401 myEnfGroup = new QWidget();
402 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
403 myEnforcedTableWidget = new QTableWidget(myEnfGroup);
404 myEnforcedTableWidget ->setMinimumWidth(300);
405 myEnforcedTableWidget->setRowCount( 0 );
406 myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS );
407 myEnforcedTableWidget->setSortingEnabled(true);
408 QStringList enforcedHeaders;
409 enforcedHeaders << tr( "HYBRID_ENF_NAME_COLUMN" )
410 << tr( "HYBRID_ENF_VER_X_COLUMN" )<< tr( "HYBRID_ENF_VER_Y_COLUMN" ) << tr( "HYBRID_ENF_VER_Z_COLUMN" )
411 << tr( "HYBRID_ENF_SIZE_COLUMN" ) << tr("HYBRID_ENF_ENTRY_COLUMN") << tr("HYBRID_ENF_VER_COMPOUND_COLUMN") << tr( "HYBRID_ENF_GROUP_COLUMN" );
413 myEnforcedTableWidget->setHorizontalHeaderLabels(enforcedHeaders);
414 myEnforcedTableWidget->verticalHeader()->hide();
415 myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true);
416 myEnforcedTableWidget->setAlternatingRowColors(true);
417 myEnforcedTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
418 myEnforcedTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
419 myEnforcedTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
421 myEnforcedTableWidget->resizeColumnsToContents();
422 myEnforcedTableWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
423 myEnforcedTableWidget->hideColumn(ENF_VER_COMPOUND_COLUMN);
425 myEnforcedTableWidget->setItemDelegate(new EnforcedVertexTableWidgetDelegate());
428 TColStd_MapOfInteger shapeTypes;
429 shapeTypes.Add( TopAbs_VERTEX );
430 shapeTypes.Add( TopAbs_COMPOUND );
432 SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes);
433 myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true);
434 myEnfVertexWdg->SetDefaultText(tr("HYBRID_ENF_SELECT_VERTEX"), "QLineEdit { color: grey }");
436 QLabel* myXCoordLabel = new QLabel( tr( "HYBRID_ENF_VER_X_LABEL" ), myEnfGroup );
437 myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
438 myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
439 QLabel* myYCoordLabel = new QLabel( tr( "HYBRID_ENF_VER_Y_LABEL" ), myEnfGroup );
440 myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
441 myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
442 QLabel* myZCoordLabel = new QLabel( tr( "HYBRID_ENF_VER_Z_LABEL" ), myEnfGroup );
443 myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
444 myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
445 QLabel* mySizeLabel = new QLabel( tr( "HYBRID_ENF_SIZE_LABEL" ), myEnfGroup );
446 mySizeValue = new SMESHGUI_SpinBox(myEnfGroup);
447 mySizeValue->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
449 QLabel* myGroupNameLabel = new QLabel( tr( "HYBRID_ENF_GROUP_LABEL" ), myEnfGroup );
450 myGroupName = new QLineEdit(myEnfGroup);
452 addVertexButton = new QPushButton(tr("HYBRID_ENF_ADD"),myEnfGroup);
453 addVertexButton->setEnabled(false);
454 removeVertexButton = new QPushButton(tr("HYBRID_ENF_REMOVE"),myEnfGroup);
455 // myGlobalGroupName = new QCheckBox(tr("HYBRID_ENF_VER_GROUPS"), myEnfGroup);
456 // myGlobalGroupName->setChecked(false);
458 // QGroupBox* GroupBox = new QGroupBox( myEnfGroup );
459 // QLabel* info = new QLabel( GroupBox );
460 // info->setText( tr( "HYBRID_ENF_VER_INFO" ) );
461 // info->setWordWrap( true );
462 // QVBoxLayout* GroupBoxVLayout = new QVBoxLayout( GroupBox );
463 // GroupBoxVLayout->setSpacing( 6 );
464 // GroupBoxVLayout->setMargin( 11 );
465 // GroupBoxVLayout->addWidget( info );
468 //anEnfLayout->addWidget(GroupBox, ENF_VER_WARNING, 0, 1, 2 );
469 anEnfLayout->addWidget(myEnforcedTableWidget, ENF_VER_VERTEX, 0, ENF_VER_NB_LINES, 1);
471 QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
472 anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2);
473 anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1);
474 anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1);
475 anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1);
476 anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1);
477 anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1);
478 anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1);
479 anEnfLayout2->addWidget(mySizeLabel, ENF_VER_SIZE, 0, 1, 1);
480 anEnfLayout2->addWidget(mySizeValue, ENF_VER_SIZE, 1, 1, 1);
481 anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1);
482 anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1);
483 anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1);
484 anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1);
485 anEnfLayout2->setRowStretch(ENF_VER_NB_LINES, 1);
487 anEnfLayout->addLayout(anEnfLayout2, ENF_VER_VERTEX, 1,ENF_VER_NB_LINES, 1);
488 anEnfLayout->setRowStretch(ENF_VER_VERTEX, 10);
490 // Enforced meshes parameters
491 myEnfMeshGroup = new QWidget();
492 QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup);
494 myEnforcedMeshTableWidget = new QTableWidget(myEnfGroup);
495 myEnforcedMeshTableWidget->setRowCount( 0 );
496 myEnforcedMeshTableWidget->setColumnCount( ENF_MESH_NB_COLUMNS );
497 myEnforcedMeshTableWidget->setSortingEnabled(true);
498 myEnforcedMeshTableWidget->verticalHeader()->hide();
499 QStringList enforcedMeshHeaders;
500 enforcedMeshHeaders << tr( "HYBRID_ENF_NAME_COLUMN" )
501 << tr( "HYBRID_ENF_ENTRY_COLUMN" )
502 << tr( "HYBRID_ENF_MESH_CONSTRAINT_COLUMN" )
503 << tr( "HYBRID_ENF_GROUP_COLUMN" );
504 myEnforcedMeshTableWidget->setHorizontalHeaderLabels(enforcedMeshHeaders);
505 myEnforcedMeshTableWidget->horizontalHeader()->setStretchLastSection(true);
506 myEnforcedMeshTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
508 myEnforcedMeshTableWidget->setAlternatingRowColors(true);
509 myEnforcedMeshTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
510 myEnforcedMeshTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
511 myEnforcedMeshTableWidget->resizeColumnsToContents();
512 myEnforcedMeshTableWidget->hideColumn(ENF_MESH_ENTRY_COLUMN);
514 myEnforcedMeshTableWidget->setItemDelegate(new EnforcedMeshTableWidgetDelegate());
516 // myEnfMesh = SMESH::SMESH_Mesh::_nil();
517 // myEnfMeshArray = new SMESH::mesh_array();
519 myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( SMESH::IDSOURCE, myEnfMeshGroup, /*multiSel=*/true);
520 myEnfMeshWdg->SetDefaultText(tr("HYBRID_ENF_SELECT_MESH"), "QLineEdit { color: grey }");
522 myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
523 ////myEnfMeshWdg->hide(); //may be used later
525 QLabel* myMeshConstraintLabel = new QLabel( tr( "HYBRID_ENF_MESH_CONSTRAINT_LABEL" ), myEnfMeshGroup );
526 myEnfMeshConstraint = new QComboBox(myEnfMeshGroup);
527 myEnfMeshConstraint->insertItems(0,myEnfMeshConstraintLabels);
528 myEnfMeshConstraint->setEditable(false);
529 myEnfMeshConstraint->setCurrentIndex(2); //EZ: use mesh group of faces for a layer
530 myMeshConstraintLabel->hide(); //may be used later
531 myEnfMeshConstraint->hide(); //may be used later
533 QLabel* myMeshGroupNameLabel = new QLabel( tr( "HYBRID_ENF_GROUP_LABEL" ), myEnfMeshGroup );
534 myMeshGroupName = new QLineEdit(myEnfMeshGroup);
535 myMeshGroupNameLabel->hide(); //may be used later
536 myMeshGroupName->hide(); //may be used later
538 addEnfMeshButton = new QPushButton(tr("HYBRID_ENF_ADD"),myEnfMeshGroup);
539 // addEnfMeshButton->setEnabled(false);
540 removeEnfMeshButton = new QPushButton(tr("HYBRID_ENF_REMOVE"),myEnfMeshGroup);
542 // QGroupBox* GroupBox2 = new QGroupBox( myEnfMeshGroup );
543 // QLabel* info2 = new QLabel( GroupBox2 );
544 // info2->setText( tr( "HYBRID_ENF_MESH_INFO" ) );
545 // info2->setWordWrap( true );
546 // QVBoxLayout* GroupBox2VLayout = new QVBoxLayout( GroupBox2 );
547 // GroupBox2VLayout->setSpacing( 6 );
548 // GroupBox2VLayout->setMargin( 11 );
549 // GroupBox2VLayout->addWidget( info2 );
551 // anEnfMeshLayout->addWidget( GroupBox2, ENF_MESH_WARNING, 0, 1, 2 );
552 //anEnfMeshLayout->addWidget(myLayersOnAllWrapCheck, ENF_MESH_MESH, 0, 1 , 1);
553 anEnfMeshLayout->addWidget(myEnforcedMeshTableWidget, ENF_MESH_MESH, 0, ENF_MESH_NB_LINES , 1);
555 QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup);
556 anEnfMeshLayout2->addWidget(myEnfMeshWdg, ENF_MESH_MESH, 0, 1, 2);
557 //TODO remove or not be lateful to select layers...
558 //anEnfMeshLayout2->addWidget(myMeshConstraintLabel, ENF_MESH_CONSTRAINT, 0, 1, 1);
559 //anEnfMeshLayout2->addWidget(myEnfMeshConstraint, ENF_MESH_CONSTRAINT, 1, 1, 1);
560 //anEnfMeshLayout2->addWidget(myMeshGroupNameLabel, ENF_MESH_GROUP, 0, 1, 1);
561 //anEnfMeshLayout2->addWidget(myMeshGroupName, ENF_MESH_GROUP, 1, 1, 1);
562 anEnfMeshLayout2->addWidget(addEnfMeshButton, ENF_MESH_BTN, 0, 1, 1);
563 anEnfMeshLayout2->addWidget(removeEnfMeshButton, ENF_MESH_BTN, 1, 1, 1);
564 anEnfMeshLayout2->setRowStretch(ENF_MESH_NB_LINES, 1);
566 anEnfMeshLayout->addLayout(anEnfMeshLayout2, ENF_MESH_MESH, 1, ENF_MESH_NB_LINES, 1);
567 anEnfMeshLayout->setRowStretch(ENF_MESH_MESH, 10);
570 // selection of faces for layers
572 QWidget* faceSelLayersGroup = new QWidget( dlg() );
573 //myLayersOnAllWrapCheck = new QCheckBox( tr( "HYBRID_LAYERS_ON_ALL_WRAP" ), faceSelLayersGroup );
574 QGridLayout* faceSelLayersLayout = new QGridLayout( faceSelLayersGroup );
575 //faceSelLayersLayout->addWidget(myLayersOnAllWrapCheck, 0, 0 );
577 myFacesLbl = new QLabel( tr("HYBRID_FACE_IDS"), faceSelLayersGroup );
578 faceSelLayersLayout->addWidget( myFacesLbl, 1, 0 );
580 myFaceSelectorLayers = new StdMeshersGUI_SubShapeSelectorWdg( faceSelLayersGroup, TopAbs_FACE, true, true );
581 QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
582 QString aSubEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
583 myFaceSelectorLayers->SetGeomShapeEntry( aSubEntry, aMainEntry );
584 faceSelLayersLayout->addWidget( myFaceSelectorLayers, 2, 0);
585 faceSelLayersLayout->setRowStretch( 2, 10);
587 // selection of faces for imprinting
589 QWidget* faceSelImprintingGroup = new QWidget( dlg() );
590 QGridLayout* faceSelImprintingLayout = new QGridLayout( faceSelImprintingGroup );
592 QLabel* facesLblImprinting = new QLabel( tr("HYBRID_FACE_IDS"), faceSelImprintingGroup );
593 faceSelImprintingLayout->addWidget( facesLblImprinting, 0, 0 );
595 myFaceSelectorImprinting = new StdMeshersGUI_SubShapeSelectorWdg( faceSelImprintingGroup, TopAbs_FACE, true, true );
596 myFaceSelectorImprinting->SetGeomShapeEntry( aSubEntry, aMainEntry );
597 faceSelImprintingLayout->addWidget( myFaceSelectorImprinting, 1, 0, 2, 2 );
598 faceSelImprintingLayout->setRowStretch( 1, 10);
600 // selection of faces for snapping
602 QWidget* faceSelSnappingGroup = new QWidget( dlg() );
603 QGridLayout* faceSelSnappingLayout = new QGridLayout( faceSelSnappingGroup );
605 QLabel* facesLblSnapping = new QLabel( tr("HYBRID_FACE_IDS"), faceSelSnappingGroup );
606 faceSelSnappingLayout->addWidget( facesLblSnapping, 0, 0 );
608 myFaceSelectorSnapping = new StdMeshersGUI_SubShapeSelectorWdg( faceSelSnappingGroup, TopAbs_FACE, true, true );
609 myFaceSelectorSnapping->SetGeomShapeEntry( aSubEntry, aMainEntry );
610 faceSelSnappingLayout->addWidget( myFaceSelectorSnapping, 1, 0, 2, 2 );
611 faceSelSnappingLayout->setRowStretch( 1, 10);
614 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
615 tab->insertTab( ADV_TAB, myAdvWidget, tr( "HYBRID_ADV_ARGS" ) );
616 if ( aMainEntry.isEmpty() && aSubEntry.isEmpty() ) { // mesh not based of geometry
617 faceSelLayersGroup->hide();
618 faceSelImprintingGroup->hide();
619 faceSelSnappingGroup->hide();
622 tab->insertTab( FACE_SEL_LAYERS_TAB, faceSelLayersGroup, tr( "HYBRID_FACES_LAYERS_TAB" ));
623 tab->insertTab( FACE_SEL_IMPRINTING_TAB, faceSelImprintingGroup, tr( "HYBRID_FACES_IMPRINTING_TAB" ));
624 tab->insertTab( FACE_SEL_SNAPPING_TAB, faceSelSnappingGroup, tr( "HYBRID_FACES_SNAPPING_TAB" ));
626 tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "HYBRID_ENFORCED_MESHES" ) );
627 tab->setCurrentIndex( STD_TAB );
630 connect( tab, SIGNAL( currentChanged ( int )), this, SLOT( onTabChanged( int ) ) );
631 connect( myAdvWidget->addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
632 connect( myStdWidget->myBoundaryLayersSizeMode, SIGNAL( currentIndexChanged(int)), SLOT( updateWidgets()));
633 connect( myStdWidget->myImprinting, SIGNAL( currentIndexChanged(int)), SLOT( updateWidgets()));
634 connect( myStdWidget->mySnapping, SIGNAL( currentIndexChanged(int)), SLOT( updateWidgets()));
635 connect( myAdvWidget->logInFileCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
636 connect( myAdvWidget->keepWorkingFilesCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
637 connect( myAdvWidget->workingDirectoryPushButton, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
639 connect( myEnforcedTableWidget, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( synchronizeCoords() ) );
640 connect( myEnforcedTableWidget, SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
641 connect( myEnforcedTableWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
642 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertex() ) );
643 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
644 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
645 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
646 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
647 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
648 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
649 connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
650 connect( myXCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
651 connect( myYCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
652 connect( myZCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
653 connect( mySizeValue, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) );
654 connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) );
656 connect( addEnfMeshButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedMesh() ) );
657 connect( removeEnfMeshButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedMesh() ) );
658 // connect( myEnfMeshWdg, SIGNAL( contentModified()), this, SLOT( checkEnfMeshIsDefined() ) );
659 // connect( myEnfMeshConstraint, SIGNAL( currentIndexChanged(int) ), this, SLOT( checkEnfMeshIsDefined() ) );
660 // connect( this, SIGNAL( enfMeshDefined(bool) ), addEnfMeshButton, SLOT( setEnabled(bool) ) );
666 * This method checks if an enforced vertex is defined;
668 void HYBRIDPluginGUI_HypothesisCreator::clearEnfVertexSelection()
670 if (myEnfVertexWdg->NbObjects() != 0) {
671 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
672 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
673 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
674 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
675 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) );
677 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
678 that->checkVertexIsDefined();
682 * This method checks if an enforced vertex is defined;
684 void HYBRIDPluginGUI_HypothesisCreator::checkVertexIsDefined()
686 bool enfVertexIsDefined = false;
687 enfVertexIsDefined = (!mySizeValue->GetString().isEmpty() &&
688 (!myEnfVertexWdg->NbObjects() == 0 ||
689 (myEnfVertexWdg->NbObjects() == 0 && !myXCoord->GetString().isEmpty()
690 && !myYCoord->GetString().isEmpty()
691 && !myZCoord->GetString().isEmpty())));
692 emit vertexDefined(enfVertexIsDefined);
696 * This method checks if an enforced mesh is defined;
698 void HYBRIDPluginGUI_HypothesisCreator::checkEnfMeshIsDefined()
700 emit enfMeshDefined( myEnfVertexWdg->NbObjects() != 0);
704 * This method resets the content of the X, Y, Z, size and GroupName widgets;
706 void HYBRIDPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
708 myXCoord->setCleared(true);
709 myYCoord->setCleared(true);
710 myZCoord->setCleared(true);
711 // mySizeValue->setCleared(true);
712 myXCoord->setText("");
713 myYCoord->setText("");
714 myZCoord->setText("");
715 // mySizeValue->setText("");
716 // myGroupName->setText("");
717 addVertexButton->setEnabled(false);
720 /** HYBRIDPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item)
721 This method updates the tooltip of a modified item. The QLineEdit widgets content
722 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
724 void HYBRIDPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item) {
725 int row = myEnforcedTableWidget->row(item);
727 QVariant vertexName = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole);
728 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
729 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
730 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
731 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
732 QVariant entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
733 QString groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole).toString();
735 clearEnforcedVertexWidgets();
737 if ( !x.isNull() || !entry.isNull()) {
738 QString toolTip = vertexName.toString();
739 toolTip += QString("(");
740 if (entry.isNull() || (!entry.isNull() && entry.toString() == "")) {
741 toolTip += x.toString();
742 toolTip += QString(", ") + y.toString();
743 toolTip += QString(", ") + z.toString();
746 toolTip += entry.toString();
747 toolTip += QString(")");
750 toolTip += QString("=") + size.toString();
752 if (!groupName.isEmpty())
753 toolTip += QString(" [") + groupName + QString("]");
755 for (int col=0;col<ENF_VER_NB_COLUMNS;col++)
756 myEnforcedTableWidget->item(row,col)->setToolTip(toolTip);
759 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
760 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
761 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
762 myXCoord->SetValue(x.toDouble());
763 myYCoord->SetValue(y.toDouble());
764 myZCoord->SetValue(z.toDouble());
765 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
766 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
767 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
770 mySizeValue->SetValue(size.toDouble());
772 if (!groupName.isEmpty())
773 myGroupName->setText(groupName);
777 void HYBRIDPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
778 int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
779 clearEnforcedVertexWidgets();
780 if (nbSelEnfVertex == 1)
782 if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
785 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
786 if (myEnfVertex == GEOM::GEOM_Object::_nil())
788 if (myEnfVertex->GetShapeType() == GEOM::VERTEX)
790 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
791 if (CORBA::is_nil(measureOp))
795 measureOp->PointCoordinates (myEnfVertex, x, y, z);
796 if ( measureOp->IsDone() )
798 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
799 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
800 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
801 myXCoord->SetValue(x);
802 myYCoord->SetValue(y);
803 myZCoord->SetValue(z);
804 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
805 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
806 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
812 /** HYBRIDPluginGUI_HypothesisCreator::synchronizeCoords()
813 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
814 of the enforced vertex clicked in the tree widget.
816 void HYBRIDPluginGUI_HypothesisCreator::synchronizeCoords() {
817 clearEnforcedVertexWidgets();
818 QList<QTableWidgetItem *> items = myEnforcedTableWidget->selectedItems();
819 // myEnfVertexWdg->disconnect(SIGNAL(contentModified()));
820 disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
821 if (! items.isEmpty()) {
822 QTableWidgetItem *item;
825 if (items.size() == 1) {
827 row = myEnforcedTableWidget->row(item);
828 QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole);
829 QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole);
830 QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole);
831 QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole);
832 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
833 if (!entry.isNull()) {
834 SMESH::string_array_var objIds = new SMESH::string_array;
836 objIds[0] = entry.toString().toStdString().c_str();
837 myEnfVertexWdg->SetObjects(objIds);
840 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
842 QVariant group = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole);
843 if (!x.isNull()/* && entry.isNull()*/) {
844 // disconnect( myXCoord, SIGNAL( textChanged(const QString &)), this, SLOT( onSelectEnforcedVertex() ) );
845 disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
846 disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
847 disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
848 myXCoord->SetValue(x.toDouble());
849 myYCoord->SetValue(y.toDouble());
850 myZCoord->SetValue(z.toDouble());
851 connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
852 connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
853 connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) );
856 mySizeValue->SetValue(size.toDouble());
858 if (!group.isNull() && (!x.isNull() || !entry.isNull()))
859 myGroupName->setText(group.toString());
862 QList<QString> entryList;
863 for (int i = 0; i < items.size(); ++i) {
865 row = myEnforcedTableWidget->row(item);
866 entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole);
868 entryList << entry.toString();
870 if (entryList.size() > 0) {
871 SMESH::string_array_var objIds = new SMESH::string_array;
872 objIds->length(entryList.size());
873 for (int i = 0; i < entryList.size() ; i++)
874 objIds[i] = entryList.at(i).toStdString().c_str();
875 myEnfVertexWdg->SetObjects(objIds);
878 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
883 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
885 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
886 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
887 that->checkVertexIsDefined();
890 /** HYBRIDPluginGUI_HypothesisCreator::addEnforcedMesh( meshName, geomEntry, elemType, size, groupName)
891 This method adds in the tree widget an enforced mesh from mesh, submesh or group with optionally size and and groupName.
893 void HYBRIDPluginGUI_HypothesisCreator::addEnforcedMesh(std::string name, std::string entry, int elementType, std::string groupName)
895 bool okToCreate = true;
896 QString itemEntry = "";
897 int itemElementType = 0;
898 int rowCount = myEnforcedMeshTableWidget->rowCount();
899 bool allColumns = true;
900 for (int row = 0;row<rowCount;row++) {
901 for (int col = 0 ; col < ENF_MESH_NB_COLUMNS ; col++) {
902 if (col == ENF_MESH_CONSTRAINT_COLUMN){
903 if (qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col)) == 0) {
908 else if (myEnforcedMeshTableWidget->item(row, col) == 0) {
912 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
913 QComboBox* itemComboBox = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row, col));
914 itemElementType = itemComboBox->currentIndex();
916 else if (col == ENF_MESH_ENTRY_COLUMN)
917 itemEntry = myEnforcedMeshTableWidget->item(row, col)->data(Qt::EditRole).toString();
923 if (itemEntry == QString(entry.c_str()) && itemElementType == elementType) {
924 // // update group name
925 // if (itemGroupName.toStdString() != groupName) {
926 // myEnforcedMeshTableWidget->item(row, ENF_MESH_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
938 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
939 myEnforcedMeshTableWidget->setSortingEnabled(false);
941 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
942 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
943 QComboBox* comboBox = new QComboBox();
944 QPalette pal = comboBox->palette();
945 pal.setColor(QPalette::Button, Qt::white);
946 comboBox->setPalette(pal);
947 comboBox->insertItems(0,myEnfMeshConstraintLabels);
948 comboBox->setEditable(false);
949 comboBox->setCurrentIndex(elementType);
950 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
953 QTableWidgetItem* item = new QTableWidgetItem();
954 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
956 case ENF_MESH_NAME_COLUMN:
957 item->setData( 0, name.c_str() );
958 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
959 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
961 case ENF_MESH_ENTRY_COLUMN:
962 item->setData( 0, entry.c_str() );
963 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
964 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
966 case ENF_MESH_GROUP_COLUMN:
967 item->setData( 0, groupName.c_str() );
968 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
976 // connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
978 myEnforcedMeshTableWidget->setSortingEnabled(true);
979 // myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
980 // updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
984 /** HYBRIDPluginGUI_HypothesisCreator::addEnforcedVertex( x, y, z, size, vertexName, geomEntry, groupName)
985 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.
987 void HYBRIDPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z, double size, std::string vertexName, std::string geomEntry, std::string groupName, bool isCompound)
989 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
990 bool okToCreate = true;
991 double itemX=0.,itemY=0.,itemZ=0.,itemSize = 0;
992 QString itemEntry, itemGroupName = QString("");
993 // bool itemIsCompound;
994 int rowCount = myEnforcedTableWidget->rowCount();
997 for (int row = 0;row<rowCount;row++) {
999 for (int col = 0 ; col < ENF_VER_NB_COLUMNS ; col++) {
1000 if (myEnforcedTableWidget->item(row, col) == 0) {
1005 data = myEnforcedTableWidget->item(row, col)->data(Qt::EditRole);
1006 if (!data.isNull()) {
1008 case ENF_VER_GROUP_COLUMN:
1009 itemGroupName = data.toString();
1011 case ENF_VER_ENTRY_COLUMN:
1012 itemEntry = data.toString();
1014 // case ENF_VER_COMPOUND_COLUMN:
1015 // itemIsCompound = data.toBool();
1017 case ENF_VER_X_COLUMN:
1018 itemX = data.toDouble();
1020 case ENF_VER_Y_COLUMN:
1021 itemY = data.toDouble();
1023 case ENF_VER_Z_COLUMN:
1024 itemZ = data.toDouble();
1026 case ENF_VER_SIZE_COLUMN:
1027 itemSize = data.toDouble();
1039 if (( !isCompound && ((itemX == x) && (itemY == y) && (itemZ == z))) || /*( (itemEntry.toStdString() != "") && */ (itemEntry.toStdString() == geomEntry)/*)*/) {
1041 if (itemSize != size) {
1042 myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size));
1044 // update group name
1045 if (itemGroupName.toStdString() != groupName) {
1046 myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str()));
1053 if (geomEntry.empty()) {
1060 if (geomEntry.empty()) {
1067 QString myVertexName;
1068 while(indexRef != vertexIndex) {
1069 indexRef = vertexIndex;
1070 if (vertexName.empty())
1071 myVertexName = QString("Vertex #%1").arg(vertexIndex);
1073 myVertexName = QString(vertexName.c_str());
1075 for (int row = 0;row<rowCount;row++) {
1076 QString name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString();
1077 if (myVertexName == name) {
1084 myEnforcedTableWidget->setRowCount(rowCount+1);
1085 myEnforcedTableWidget->setSortingEnabled(false);
1086 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1087 QTableWidgetItem* item = new QTableWidgetItem();
1088 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1090 case ENF_VER_NAME_COLUMN:
1091 item->setData( Qt::EditRole, myVertexName );
1092 if (!geomEntry.empty()) {
1094 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1096 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1099 case ENF_VER_X_COLUMN:
1101 item->setData( 0, QVariant(x) );
1103 case ENF_VER_Y_COLUMN:
1105 item->setData( 0, QVariant(y) );
1107 case ENF_VER_Z_COLUMN:
1109 item->setData( 0, QVariant(z) );
1111 case ENF_VER_SIZE_COLUMN:
1112 item->setData( 0, QVariant(size) );
1114 case ENF_VER_ENTRY_COLUMN:
1115 if (!geomEntry.empty())
1116 item->setData( 0, QString(geomEntry.c_str()) );
1118 case ENF_VER_COMPOUND_COLUMN:
1119 item->setData( Qt::CheckStateRole, isCompound );
1120 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1122 case ENF_VER_GROUP_COLUMN:
1123 if (!groupName.empty())
1124 item->setData( 0, QString(groupName.c_str()) );
1130 myEnforcedTableWidget->setItem(rowCount,col,item);
1133 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1135 myEnforcedTableWidget->setSortingEnabled(true);
1136 // myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1137 updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1140 /** HYBRIDPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1141 This method is called when a item is added into the enforced meshes tree widget
1143 void HYBRIDPluginGUI_HypothesisCreator::onAddEnforcedMesh()
1146 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
1148 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1149 myEnfMeshWdg->deactivateSelection();
1151 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1152 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1155 int selEnfMeshes = myEnfMeshWdg->NbObjects();
1156 if (selEnfMeshes == 0)
1159 std::string groupName = myMeshGroupName->text().toStdString();
1160 // if (myGlobalGroupName->isChecked())
1161 // groupName = myGlobalGroupName->text().toStdString();
1163 if (boost::trim_copy(groupName).empty())
1164 groupName = "LayersGroup"; //have to be not empty until non used
1166 int elementType = myEnfMeshConstraint->currentIndex();
1169 _PTR(Study) aStudy = SMESH::getStudy();
1170 _PTR(SObject) aSObj; //SMESH::SMESH_IDSource::_nil;
1171 QString meshEntry = myEnfMeshWdg->GetValue();
1173 if (selEnfMeshes == 1)
1175 // myEnfMesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
1176 // std::string entry = myEnfMeshWdg->GetValue();
1177 aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str());
1178 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj);
1179 if (!CORBA::is_nil(anObj)) {
1180 // SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1181 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1186 QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts);
1187 QStringListIterator meshEntriesIt (meshEntries);
1188 while (meshEntriesIt.hasNext()) {
1189 aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str());
1190 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj);
1191 if (!CORBA::is_nil(anObj)) {
1192 // SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1193 addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, groupName);
1198 myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil());
1200 for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column)
1201 myEnforcedMeshTableWidget->resizeColumnToContents(column);
1205 /** HYBRIDPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1206 This method is called when a item is added into the enforced vertices tree widget
1208 void HYBRIDPluginGUI_HypothesisCreator::onAddEnforcedVertex()
1211 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
1213 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1214 myEnfVertexWdg->deactivateSelection();
1216 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1217 myEnforcedTableWidget->resizeColumnToContents(column);
1220 int selEnfVertex = myEnfVertexWdg->NbObjects();
1221 bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1222 if ((selEnfVertex == 0) && coordsEmpty)
1225 std::string groupName = myGroupName->text().toStdString();
1226 // if (myGlobalGroupName->isChecked())
1227 // groupName = myGlobalGroupName->text().toStdString();
1229 if (boost::trim_copy(groupName).empty())
1232 double size = mySizeValue->GetValue();
1234 if (selEnfVertex <= 1)
1236 double x = 0, y = 0, z=0;
1237 if (myXCoord->GetString() != "") {
1238 x = myXCoord->GetValue();
1239 y = myYCoord->GetValue();
1240 z = myZCoord->GetValue();
1242 if (selEnfVertex == 1) {
1243 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1244 std::string entry = "";
1245 if (myEnfVertex != GEOM::GEOM_Object::_nil())
1246 entry = myEnfVertex->GetStudyEntry();
1247 addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),entry, groupName, myEnfVertex->GetShapeType() == GEOM::COMPOUND);
1250 addEnforcedVertex(x, y, z, size, "", "", groupName);
1255 if ( CORBA::is_nil(getGeomEngine()))
1258 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
1259 if (CORBA::is_nil(measureOp))
1262 CORBA::Double x = 0, y = 0,z = 0;
1263 for (int j = 0 ; j < selEnfVertex ; j++)
1265 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1266 if (myEnfVertex == GEOM::GEOM_Object::_nil())
1268 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1269 measureOp->PointCoordinates (myEnfVertex, x, y, z);
1270 if ( measureOp->IsDone() )
1271 addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1272 } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1273 addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true);
1278 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1280 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1281 myEnforcedTableWidget->resizeColumnToContents(column);
1284 /** HYBRIDPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1285 This method is called when a item is removed from the enforced meshes tree widget
1287 void HYBRIDPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
1289 QList<int> selectedRows;
1290 QList<QTableWidgetItem *> selectedItems = myEnforcedMeshTableWidget->selectedItems();
1291 QTableWidgetItem* item;
1293 foreach( item, selectedItems ) {
1295 if (!selectedRows.contains( row ) )
1296 selectedRows.append(row);
1299 qSort( selectedRows );
1300 QListIterator<int> it( selectedRows );
1302 while ( it.hasPrevious() ) {
1303 row = it.previous();
1304 myEnforcedMeshTableWidget->removeRow(row );
1307 myEnforcedMeshTableWidget->selectionModel()->clearSelection();
1310 /** HYBRIDPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1311 This method is called when a item is removed from the enforced vertices tree widget
1313 void HYBRIDPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1315 QList<int> selectedRows;
1316 QList<QTableWidgetItem *> selectedItems = myEnforcedTableWidget->selectedItems();
1317 QTableWidgetItem* item;
1319 foreach( item, selectedItems ) {
1321 if (!selectedRows.contains( row ) )
1322 selectedRows.append(row);
1325 qSort( selectedRows );
1326 QListIterator<int> it( selectedRows );
1328 while ( it.hasPrevious() ) {
1329 row = it.previous();
1330 myEnforcedTableWidget->removeRow(row );
1333 myEnforcedTableWidget->selectionModel()->clearSelection();
1336 void HYBRIDPluginGUI_HypothesisCreator::onDirBtnClicked()
1338 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myAdvWidget->workingDirectoryLineEdit->text(), QString() );
1339 if ( !dir.isEmpty() )
1340 myAdvWidget->workingDirectoryLineEdit->setText( dir );
1343 void HYBRIDPluginGUI_HypothesisCreator::onTabChanged( int )
1345 myEnfVertexWdg->deactivateSelection();
1346 myEnfMeshWdg->deactivateSelection();
1347 myFaceSelectorLayers->ActivateSelection( false );
1348 myFaceSelectorLayers->ShowPreview( false );
1349 myFaceSelectorImprinting->ActivateSelection( false );
1350 myFaceSelectorImprinting->ShowPreview( false );
1351 myFaceSelectorSnapping->ActivateSelection( false );
1352 myFaceSelectorSnapping->ShowPreview( false );
1355 void HYBRIDPluginGUI_HypothesisCreator::updateWidgets()
1357 if ( sender() == myAdvWidget->logInFileCheck ||
1358 sender() == myAdvWidget->keepWorkingFilesCheck )
1360 bool logFileRemovable = ( myAdvWidget->logInFileCheck->isChecked() &&
1361 !myAdvWidget->keepWorkingFilesCheck->isChecked() );
1362 myAdvWidget->removeLogOnSuccessCheck->setEnabled( logFileRemovable );
1365 myStdWidget->myCoreSize->setEnabled( myStdWidget->myCoreSizeEnabled->isChecked() );
1367 if ( QTabWidget* tab = qobject_cast<QTabWidget*>( myStdGroup->parentWidget()->parentWidget() ))
1369 bool isGlobal = myStdWidget->GetLayersOnAllWrap();
1370 bool isImprinting = myStdWidget->myImprinting->currentIndex();
1371 bool isSnapping = myStdWidget->mySnapping->currentIndex();
1372 tab->setTabEnabled( FACE_SEL_LAYERS_TAB, !isGlobal );
1373 tab->setTabEnabled( FACE_SEL_IMPRINTING_TAB, isImprinting );
1374 tab->setTabEnabled( FACE_SEL_SNAPPING_TAB, isSnapping );
1378 bool HYBRIDPluginGUI_HypothesisCreator::checkParams(QString& msg) const
1381 if ( !QFileInfo( myAdvWidget->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
1382 SUIT_MessageBox::warning( dlg(),
1383 tr( "SMESH_WRN_WARNING" ),
1384 tr( "HYBRID_PERMISSION_DENIED" ) );
1388 HYBRIDPlugin::HYBRIDPlugin_Hypothesis_var h =
1389 HYBRIDPlugin::HYBRIDPlugin_Hypothesis::_narrow( hypothesis() );
1391 myAdvWidget->myOptionTable->setFocus();
1392 QApplication::instance()->processEvents();
1394 QString name, value;
1395 bool isDefault, ok = true;
1396 int iRow = 0, nbRows = myAdvWidget->myOptionTable->topLevelItemCount();
1397 for ( ; iRow < nbRows; ++iRow )
1399 QTreeWidgetItem* row = myAdvWidget->myOptionTable->topLevelItem( iRow );
1400 myAdvWidget->GetOptionAndValue( row, name, value, isDefault );
1402 if ( name.simplified().isEmpty() )
1403 continue; // invalid custom option
1405 if ( isDefault ) // not selected option
1409 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
1411 catch ( const SALOME::SALOME_Exception& ex )
1413 msg = ex.details.text.in();
1421 h->SetOptionValues( myOptions ); // restore values
1427 void HYBRIDPluginGUI_HypothesisCreator::retrieveParams() const
1429 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
1430 HYBRIDHypothesisData data;
1431 readParamsFromHypo( data );
1434 myName->setText( data.myName );
1435 myStdWidget->SetLayersOnAllWrap( data.myLayersOnAllWrap );
1437 myStdWidget->myNbOfBoundaryLayers ->setValue( data.myNbOfBoundaryLayers );
1438 myStdWidget ->SetLayersOnAllWrap( data.myLayersOnAllWrap );
1439 myStdWidget->myHeightFirstLayer ->setValue( data.myHeightFirstLayer );
1440 myStdWidget->myHeightIsRelative ->setCurrentIndex( data.myHeightIsRelative );
1441 myStdWidget->myBoundaryLayersGrowth ->setCurrentIndex( data.myBoundaryLayersGrowth );
1442 myStdWidget->myBoundaryLayersMaxElemAngle->setValue( data.myBoundaryLayersMaxElemAngle );
1443 myStdWidget->myBoundaryLayersProgression ->setValue( data.myBoundaryLayersProgression );
1444 myStdWidget->myImprinting ->setCurrentIndex( data.myImprinting );
1445 myStdWidget->mySnapping ->setCurrentIndex( data.mySnapping );
1446 myStdWidget->myElementGeneration ->setCurrentIndex( data.myElementGeneration );
1447 if (data.myCoreSize <= 0)
1448 myStdWidget->myCoreSize->setText("");
1450 myStdWidget->myCoreSize->setValue( data.myCoreSize );
1451 myStdWidget->myCoreSizeEnabled->setChecked( data.myCoreSize > 0 );
1453 myFaceSelectorLayers ->SetListOfIDs( data.myFaceWLIds );
1454 myFaceSelectorImprinting ->SetListOfIDs( data.myFaceWIIds );
1455 myFaceSelectorSnapping ->SetListOfIDs( data.myFaceWSIds );
1457 myAdvWidget->workingDirectoryLineEdit ->setText ( data.myWorkingDir );
1458 myAdvWidget->keepWorkingFilesCheck ->setChecked( data.myKeepFiles );
1459 myAdvWidget->verboseLevelSpin ->setValue ( data.myVerboseLevel );
1460 myAdvWidget->logInFileCheck ->setChecked( !data.myLogInStandardOutput );
1461 myAdvWidget->removeLogOnSuccessCheck ->setChecked( data.myRemoveLogOnSuccess );
1463 if ( myOptions.operator->() ) {
1464 for ( int i = 0, nb = myOptions->length(); i < nb; ++i )
1465 myAdvWidget->AddOption( that->myOptions[i].in() );
1467 if ( myCustomOptions.operator->() ) {
1468 for ( int i = 0, nb = myCustomOptions->length(); i < nb; ++i )
1469 myAdvWidget->AddOption( that->myCustomOptions[i].in() );
1471 myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1473 TEnfVertexList::const_iterator it;
1475 myEnforcedTableWidget->clearContents();
1476 myEnforcedTableWidget->setSortingEnabled(false);
1477 myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1478 for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ )
1480 TEnfVertex* enfVertex = (*it);
1481 myEnforcedTableWidget->setRowCount(rowCount+1);
1483 for (int col=0;col<ENF_VER_NB_COLUMNS;col++) {
1484 QTableWidgetItem* item = new QTableWidgetItem();
1485 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1487 case ENF_VER_NAME_COLUMN:
1488 item->setData( 0, enfVertex->name.c_str() );
1489 if (!enfVertex->geomEntry.empty()) {
1490 if (enfVertex->isCompound)
1491 item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1493 item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1497 case ENF_VER_X_COLUMN:
1498 if (!enfVertex->isCompound) {
1499 item->setData( 0, enfVertex->coords.at(0) );
1502 case ENF_VER_Y_COLUMN:
1503 if (!enfVertex->isCompound) {
1504 item->setData( 0, enfVertex->coords.at(1) );
1507 case ENF_VER_Z_COLUMN:
1508 if (!enfVertex->isCompound) {
1509 item->setData( 0, enfVertex->coords.at(2) );
1512 case ENF_VER_SIZE_COLUMN:
1513 item->setData( 0, enfVertex->size );
1515 case ENF_VER_ENTRY_COLUMN:
1516 item->setData( 0, enfVertex->geomEntry.c_str() );
1518 case ENF_VER_COMPOUND_COLUMN:
1519 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
1520 item->setData( Qt::CheckStateRole, enfVertex->isCompound );
1522 case ENF_VER_GROUP_COLUMN:
1523 item->setData( 0, enfVertex->groupName.c_str() );
1529 myEnforcedTableWidget->setItem(rowCount,col,item);
1531 that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1535 connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1536 myEnforcedTableWidget->setSortingEnabled(true);
1538 for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column)
1539 myEnforcedTableWidget->resizeColumnToContents(column);
1541 // Update Enforced meshes QTableWidget
1542 TEnfMeshList::const_iterator itMesh;
1544 myEnforcedMeshTableWidget->clearContents();
1545 myEnforcedMeshTableWidget->setSortingEnabled(false);
1546 // myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *)));
1547 for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ )
1549 TEnfMesh* enfMesh = (*itMesh);
1550 myEnforcedMeshTableWidget->setRowCount(rowCount+1);
1552 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++) {
1553 if (col == ENF_MESH_CONSTRAINT_COLUMN) {
1554 QComboBox* comboBox = new QComboBox();
1555 QPalette pal = comboBox->palette();
1556 pal.setColor(QPalette::Button, Qt::white);
1557 comboBox->setPalette(pal);
1558 comboBox->insertItems(0,myEnfMeshConstraintLabels);
1559 comboBox->setEditable(false);
1560 comboBox->setCurrentIndex(enfMesh->elementType);
1561 myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox);
1564 QTableWidgetItem* item = new QTableWidgetItem();
1565 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1567 case ENF_MESH_NAME_COLUMN:
1568 item->setData( 0, enfMesh->name.c_str() );
1569 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1570 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1572 case ENF_MESH_ENTRY_COLUMN:
1573 item->setData( 0, enfMesh->entry.c_str() );
1574 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1575 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1577 case ENF_MESH_GROUP_COLUMN:
1578 item->setData( 0, enfMesh->groupName.c_str() );
1579 myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1586 // myEnforcedMeshTableWidget->setItem(rowCount,col,item);
1588 // that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN));
1592 // connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) );
1593 myEnforcedMeshTableWidget->setSortingEnabled(true);
1595 for (int col=0;col<ENF_MESH_NB_COLUMNS;col++)
1596 myEnforcedMeshTableWidget->resizeColumnToContents(col);
1598 that->updateWidgets();
1599 that->checkVertexIsDefined();
1602 QString HYBRIDPluginGUI_HypothesisCreator::storeParams() const
1604 HYBRIDHypothesisData data;
1605 readParamsFromWidgets( data );
1606 storeParamsToHypo( data );
1608 QString valStr = "";
1612 bool HYBRIDPluginGUI_HypothesisCreator::readParamsFromHypo( HYBRIDHypothesisData& h_data ) const
1614 HYBRIDPlugin::HYBRIDPlugin_Hypothesis_var h =
1615 HYBRIDPlugin::HYBRIDPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1617 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1618 h_data.myName = isCreation() && data ? hypName() : "";
1620 h_data.myNbOfBoundaryLayers = h->GetNbOfBoundaryLayers();
1621 h_data.myLayersOnAllWrap = h->GetLayersOnAllWrap();
1622 h_data.myHeightFirstLayer = h->GetHeightFirstLayer();
1623 h_data.myHeightIsRelative = h->GetHeightIsRelative();
1624 h_data.myBoundaryLayersGrowth = h->GetBoundaryLayersGrowth();
1625 h_data.myBoundaryLayersMaxElemAngle = h->GetBoundaryLayersMaxElemAngle();
1626 h_data.myBoundaryLayersProgression = h->GetBoundaryLayersProgression();
1627 h_data.myElementGeneration = h->GetElementGeneration();
1628 h_data.myCoreSize = h->GetCoreSize();
1630 h_data.myFaceWLIds = h->GetFacesWithLayers();
1631 h_data.myFaceWIIds = h->GetFacesWithImprinting();
1632 h_data.myFaceWSIds = h->GetFacesWithSnapping();
1633 h_data.myImprinting = h_data.myFaceWIIds->length();//h->GetImprinting();
1634 h_data.mySnapping = h_data.myFaceWSIds->length();//h->GetSnapping();
1636 h_data.myCollisionMode = h->GetCollisionMode();
1637 h_data.myOptimizationLevel = h->GetOptimizationLevel();
1639 h_data.myKeepFiles = h->GetKeepFiles();
1640 h_data.myWorkingDir = h->GetWorkingDirectory();
1641 h_data.myVerboseLevel = h->GetVerboseLevel();
1642 h_data.myLogInStandardOutput = h->GetStandardOutputLog();
1643 h_data.myRemoveLogOnSuccess = h->GetRemoveLogOnSuccess();
1645 HYBRIDPluginGUI_HypothesisCreator* that = (HYBRIDPluginGUI_HypothesisCreator*)this;
1646 that->myOptions = h->GetOptionValues();
1647 that->myCustomOptions = h->GetAdvancedOptionValues();
1650 HYBRIDPlugin::HYBRIDEnforcedVertexList_var vertices = h->GetEnforcedVertices();
1651 h_data.myEnforcedVertices.clear();
1652 for (CORBA::ULong i=0 ; i<vertices->length() ; i++) {
1653 TEnfVertex* myVertex = new TEnfVertex();
1654 myVertex->name = CORBA::string_dup(vertices[i].name.in());
1655 myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in());
1656 myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in());
1657 myVertex->size = vertices[i].size;
1658 myVertex->isCompound = vertices[i].isCompound;
1659 if (vertices[i].coords.length()) {
1660 for (CORBA::ULong c = 0; c < vertices[i].coords.length() ; c++)
1661 myVertex->coords.push_back(vertices[i].coords[c]);
1663 h_data.myEnforcedVertices.insert(myVertex);
1666 HYBRIDPlugin::HYBRIDEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes();
1667 h_data.myEnforcedMeshes.clear();
1668 for (CORBA::ULong i=0 ; i<enfMeshes->length() ; i++) {
1669 TEnfMesh* myEnfMesh = new TEnfMesh();
1670 myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in());
1671 myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in());
1672 myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in());
1673 switch (enfMeshes[i].elementType) {
1675 myEnfMesh->elementType = 0;
1678 myEnfMesh->elementType = 1;
1681 myEnfMesh->elementType = 2;
1686 // myEnfMesh->elementType = enfMeshes[i].elementType;
1687 h_data.myEnforcedMeshes.insert(myEnfMesh);
1692 bool HYBRIDPluginGUI_HypothesisCreator::storeParamsToHypo( const HYBRIDHypothesisData& h_data ) const
1694 HYBRIDPlugin::HYBRIDPlugin_Hypothesis_var h =
1695 HYBRIDPlugin::HYBRIDPlugin_Hypothesis::_narrow( hypothesis() );
1701 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1703 if ( h->GetNbOfBoundaryLayers() != h_data.myNbOfBoundaryLayers )
1704 h->SetNbOfBoundaryLayers ( h_data.myNbOfBoundaryLayers );
1705 if ( h->GetLayersOnAllWrap() != h_data.myLayersOnAllWrap ) // avoid duplication of DumpPython commands
1706 h->SetLayersOnAllWrap ( h_data.myLayersOnAllWrap );
1707 if ( h->GetHeightFirstLayer() != h_data.myHeightFirstLayer )
1708 h->SetHeightFirstLayer ( h_data.myHeightFirstLayer );
1709 h->SetHeightIsRelative( h_data.myHeightIsRelative );
1710 if ( h->GetBoundaryLayersGrowth() != h_data.myBoundaryLayersGrowth )
1711 h->SetBoundaryLayersGrowth( h_data.myBoundaryLayersGrowth );
1712 h->SetBoundaryLayersMaxElemAngle( h_data.myBoundaryLayersMaxElemAngle );
1713 if ( h->GetBoundaryLayersProgression() != h_data.myBoundaryLayersProgression )
1714 h->SetBoundaryLayersProgression ( h_data.myBoundaryLayersProgression );
1715 if ( h->GetElementGeneration() != h_data.myElementGeneration )
1716 h->SetElementGeneration( h_data.myElementGeneration );
1717 if ( h->GetCoreSize() != h_data.myCoreSize )
1718 h->SetCoreSize ( h_data.myCoreSize );
1720 // if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
1721 // h->SetOptimizationLevel( h_data.myOptimizationLevel );
1722 // if ( h->GetCollisionMode() != h_data.myCollisionMode )
1723 // h->SetCollisionMode( h_data.myCollisionMode );
1725 h->SetFacesWithLayers( h_data.myFaceWLIds );
1726 h->SetFacesWithImprinting( h_data.myFaceWIIds );
1727 h->SetFacesWithSnapping( h_data.myFaceWSIds );
1729 if ( h->GetKeepFiles() != h_data.myKeepFiles)
1730 h->SetKeepFiles ( h_data.myKeepFiles);
1731 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
1732 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
1733 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
1734 h->SetVerboseLevel ( h_data.myVerboseLevel );
1735 if ( h->GetStandardOutputLog() != h_data.myLogInStandardOutput )
1736 h->SetStandardOutputLog ( h_data.myLogInStandardOutput );
1737 if ( h->GetRemoveLogOnSuccess() != h_data.myRemoveLogOnSuccess )
1738 h->SetRemoveLogOnSuccess ( h_data.myRemoveLogOnSuccess );
1740 // Enforced vertices
1741 //int nbVertex = (int) h_data.myEnforcedVertices.size();
1742 HYBRIDPlugin::HYBRIDEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices();
1743 int nbVertexHyp = vertexHyp->length();
1746 // 1. Clear all enforced vertices in hypothesis
1747 // 2. Add new enforced vertex according to h_data
1748 if ( nbVertexHyp > 0)
1749 h->ClearEnforcedVertices();
1751 TEnfVertexList::const_iterator it;
1752 double x = 0, y = 0, z = 0;
1753 for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) {
1754 TEnfVertex* enfVertex = (*it);
1756 if (enfVertex->coords.size()) {
1757 x = enfVertex->coords.at(0);
1758 y = enfVertex->coords.at(1);
1759 z = enfVertex->coords.at(2);
1761 ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound);
1765 //int nbEnfMeshes = (int) h_data.myEnforcedMeshes.size();
1766 HYBRIDPlugin::HYBRIDEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes();
1767 int nbEnfMeshListHyp = enfMeshListHyp->length();
1770 // 1. Clear all enforced vertices in hypothesis
1771 // 2. Add new enforced vertex according to h_data
1772 if ( nbEnfMeshListHyp > 0)
1773 h->ClearEnforcedMeshes();
1775 TEnfMeshList::const_iterator itEnfMesh;
1777 _PTR(Study) aStudy = SMESH::getStudy();
1779 for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) {
1780 TEnfMesh* enfMesh = (*itEnfMesh);
1782 _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str());
1783 SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aSObj );
1785 SMESH::ElementType elementType = SMESH::NODE;
1786 switch(enfMesh->elementType) {
1788 elementType = SMESH::NODE;
1791 elementType = SMESH::EDGE;
1794 elementType = SMESH::FACE;
1800 ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->name.c_str(), enfMesh->groupName.c_str());
1803 // catch(const std::exception& ex) {
1804 // std::cout << "Exception: " << ex.what() << std::endl;
1807 catch ( const SALOME::SALOME_Exception& ex )
1809 SalomeApp_Tools::QtCatchCorbaException( ex );
1815 bool HYBRIDPluginGUI_HypothesisCreator::readParamsFromWidgets( HYBRIDHypothesisData& h_data ) const
1817 h_data.myName = myName ? myName->text() : "";
1818 h_data.myNbOfBoundaryLayers = myStdWidget->myNbOfBoundaryLayers -> value();
1819 h_data.myLayersOnAllWrap = myStdWidget->GetLayersOnAllWrap();
1820 h_data.myHeightFirstLayer = myStdWidget->myHeightFirstLayer -> value();
1821 h_data.myHeightIsRelative = myStdWidget->myHeightIsRelative->currentIndex();
1822 h_data.myBoundaryLayersGrowth = myStdWidget->myBoundaryLayersGrowth->currentIndex();
1823 h_data.myBoundaryLayersMaxElemAngle = myStdWidget->myBoundaryLayersMaxElemAngle->value();
1824 h_data.myBoundaryLayersProgression = myStdWidget->myBoundaryLayersProgression -> value();
1825 h_data.myElementGeneration = myStdWidget->myElementGeneration->currentIndex();
1826 h_data.myCoreSize = myStdWidget->myCoreSizeEnabled->isChecked() ? myStdWidget->myCoreSize -> value() : 0;
1828 h_data.myFaceWLIds = myFaceSelectorLayers->GetListOfIDs();
1829 h_data.myFaceWIIds = myFaceSelectorImprinting->GetListOfIDs();
1830 h_data.myFaceWSIds = myFaceSelectorSnapping->GetListOfIDs();
1832 h_data.myKeepFiles = myAdvWidget->keepWorkingFilesCheck->isChecked();
1833 h_data.myWorkingDir = myAdvWidget->workingDirectoryLineEdit->text().trimmed();
1834 h_data.myVerboseLevel = myAdvWidget->verboseLevelSpin->value();
1835 h_data.myLogInStandardOutput = !myAdvWidget->logInFileCheck->isChecked();
1836 h_data.myRemoveLogOnSuccess = myAdvWidget->removeLogOnSuccessCheck->isChecked();
1838 // Enforced vertices
1839 h_data.myEnforcedVertices.clear();
1840 QVariant valueX, valueY, valueZ;
1841 for (int row=0 ; row<myEnforcedTableWidget->rowCount() ; row++) {
1843 TEnfVertex *myVertex = new TEnfVertex();
1844 myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1845 myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1846 if (myVertex->geomEntry.size())
1847 myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1848 if (myVertex->groupName.size())
1849 valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole);
1850 valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole);
1851 valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole);
1852 if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) {
1853 myVertex->coords.push_back(valueX.toDouble());
1854 myVertex->coords.push_back(valueY.toDouble());
1855 myVertex->coords.push_back(valueZ.toDouble());
1857 myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble();
1858 myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool();
1859 h_data.myEnforcedVertices.insert(myVertex);
1863 h_data.myEnforcedMeshes.clear();
1865 for (int row=0 ; row<myEnforcedMeshTableWidget->rowCount() ; row++) {
1867 TEnfMesh *myEnfMesh = new TEnfMesh();
1868 myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString();
1869 myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString();
1870 myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString();
1871 QComboBox* combo = qobject_cast<QComboBox*>(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN));
1872 myEnfMesh->elementType = combo->currentIndex();
1873 h_data.myEnforcedMeshes.insert(myEnfMesh);
1879 QString HYBRIDPluginGUI_HypothesisCreator::caption() const
1881 return tr( "HYBRID_TITLE" );
1884 QPixmap HYBRIDPluginGUI_HypothesisCreator::icon() const
1886 return SUIT_Session::session()->resourceMgr()->loadPixmap( "HYBRIDPlugin", tr( "ICON_DLG_HYBRID_PARAMETERS" ) );
1889 QString HYBRIDPluginGUI_HypothesisCreator::type() const
1891 return tr( "HYBRID_HYPOTHESIS" );
1894 QString HYBRIDPluginGUI_HypothesisCreator::helpPage() const
1896 return "hybrid_hypo_page.html";
1899 void HYBRIDPluginGUI_HypothesisCreator::onAddOption()
1901 myAdvWidget->AddOption( NULL, true );