1 // Copyright (C) 2007-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
21 // File : BLSURFPluginGUI_HypothesisCreator.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPluginGUI_HypothesisCreator.h"
28 #include "BLSURFPluginGUI_Dlg.h"
30 #include "GeometryGUI.h"
32 #include <SMESHGUI_Utils.h>
33 #include <SMESHGUI_HypothesesUtils.h>
34 #include <SMESHGUI_Dialog.h>
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESH_NumberFilter.hxx"
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Tools.h>
43 #include <QApplication>
47 #include <QHBoxLayout>
48 #include <QHeaderView>
49 #include <QGridLayout>
55 #include <QPushButton>
56 #include <QRadioButton>
58 #include <QTableWidget>
60 #include <QVBoxLayout>
62 #include <QStandardItemModel>
63 #include <QStandardItem>
64 #include <QTreeWidget>
65 #include <QTreeWidgetItem>
66 #include <QModelIndexList>
68 #include <LightApp_SelectionMgr.h>
69 #include <SalomeApp_Application.h>
70 #include <SALOME_ListIO.hxx>
71 #include <SALOME_ListIteratorOfListIO.hxx>
72 #include "SALOME_LifeCycleCORBA.hxx"
74 #include <TopoDS_Shape.hxx>
75 #include <TopoDS_Iterator.hxx>
76 #include <SMESH_Gen_i.hxx>
77 #include <boost/shared_ptr.hpp>
78 #include <boost/algorithm/string.hpp>
79 #include <structmember.h>
94 // Enforced vertices array columns
95 ENF_VER_NAME_COLUMN = 0,
96 ENF_VER_FACE_ENTRY_COLUMN,
100 ENF_VER_ENTRY_COLUMN,
101 ENF_VER_GROUP_COLUMN,
128 // Enforced vertices inputs
136 // ENF_VER_GROUP_CHECK,
140 ENF_VER_INTERNAL_ALL_FACES,
141 ENF_VER_INTERNAL_ALL_FACES_GROUP,
142 // ENF_VER_VERTEX_BTN,
143 // ENF_VER_REMOVE_BTN,
144 // ENF_VER_SEPARATOR,
149 /**************************************************
150 Begin initialization Python structures and objects
151 ***************************************************/
160 PyStdOut_dealloc(PyStdOut *self)
166 PyStdOut_write(PyStdOut *self, PyObject *args)
170 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
174 *(self->out)=*(self->out)+c;
180 static PyMethodDef PyStdOut_methods[] = {
181 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
182 PyDoc_STR("write(string) -> None")},
183 {NULL, NULL} /* sentinel */
186 static PyMemberDef PyStdOut_memberlist[] = {
187 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
188 (char*)"flag indicating that a space needs to be printed; used by print"},
189 {NULL} /* Sentinel */
192 static PyTypeObject PyStdOut_Type = {
193 /* The ob_type field must be initialized in the module init function
194 * to be portable to Windows without using C++. */
195 PyObject_HEAD_INIT(NULL)
198 sizeof(PyStdOut), /*tp_basicsize*/
201 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
208 0, /*tp_as_sequence*/
213 PyObject_GenericGetAttr, /*tp_getattro*/
214 /* softspace is writable: we must supply tp_setattro */
215 PyObject_GenericSetAttr, /* tp_setattro */
217 Py_TPFLAGS_DEFAULT, /*tp_flags*/
221 0, /*tp_richcompare*/
222 0, /*tp_weaklistoffset*/
225 PyStdOut_methods, /*tp_methods*/
226 PyStdOut_memberlist, /*tp_members*/
240 PyObject * newPyStdOut( std::string& out )
243 self = PyObject_New(PyStdOut, &PyStdOut_Type);
248 return (PyObject*)self;
251 /*************************************************
252 End initialization Python structures and objects
253 **************************************************/
257 // BEGIN EnforcedTreeWidgetDelegate
260 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
261 : QItemDelegate(parent)
265 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
266 const QStyleOptionViewItem & option ,
267 const QModelIndex & index ) const
269 QModelIndex father = index.parent();
270 QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
272 if (index.column() == ENF_VER_X_COLUMN || \
273 index.column() == ENF_VER_Y_COLUMN || \
274 index.column() == ENF_VER_Z_COLUMN)
276 SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
277 editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 editor->setReadOnly(!entry.isEmpty());
279 editor->setDisabled(!entry.isEmpty());
284 QLineEdit *editor = new QLineEdit(parent);
285 if (index.column() != ENF_VER_GROUP_COLUMN) {
286 editor->setReadOnly(!entry.isEmpty());
287 editor->setDisabled(!entry.isEmpty());
293 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
294 const QModelIndex &index) const
296 QString value = index.model()->data(index, Qt::EditRole).toString();
298 if (index.column() == ENF_VER_X_COLUMN ||
299 index.column() == ENF_VER_Y_COLUMN ||
300 index.column() == ENF_VER_Z_COLUMN)
302 SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
303 lineEdit->setText(value);
306 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
307 lineEdit->setText(value);
311 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
312 const QModelIndex &index) const
314 QModelIndex parent = index.parent();
315 QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
316 if (index.column() == ENF_VER_X_COLUMN || index.column() == ENF_VER_Y_COLUMN || index.column() == ENF_VER_Z_COLUMN) {
317 SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
318 if (entry.isEmpty() && !vertexExists(model, index, lineEdit->GetString()))
319 model->setData(index, lineEdit->GetValue(), Qt::EditRole);
320 } else if (index.column() == ENF_VER_NAME_COLUMN) {
321 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
322 QString value = lineEdit->text();
323 if (entry.isEmpty() && !vertexExists(model, index, value))
324 model->setData(index, value, Qt::EditRole);
325 } else if (index.column() == ENF_VER_ENTRY_COLUMN) {
326 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
327 QString value = lineEdit->text();
328 if (! vertexExists(model, index, value))
329 model->setData(index, value, Qt::EditRole);
330 } else if (index.column() == ENF_VER_GROUP_COLUMN) {
331 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
332 model->setData(index, lineEdit->text(), Qt::EditRole);
336 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
337 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
339 editor->setGeometry(option.rect);
342 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
343 const QModelIndex &index, QString value) const
346 QModelIndex parent = index.parent();
347 int row = index.row();
348 int col = index.column();
350 if (parent.isValid() && !value.isEmpty()) {
351 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
353 if (col == ENF_VER_X_COLUMN) {
354 x = value.toDouble();
355 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
356 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
358 if (col == ENF_VER_Y_COLUMN) {
359 y = value.toDouble();
360 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
361 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
363 if (col == ENF_VER_Z_COLUMN) {
364 z = value.toDouble();
365 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
366 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
368 int nbChildren = model->rowCount(parent);
369 for (int i = 0 ; i < nbChildren ; i++) {
371 double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
372 double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
373 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
374 if ((childX == x) && (childY == y) && (childZ == z)) {
381 else if (col == ENF_VER_NAME_COLUMN) {
382 int nbChildren = model->rowCount(parent);
383 for (int i = 0 ; i < nbChildren ; i++) {
385 QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
386 if (childName == value) {
399 // END EnforcedTreeWidgetDelegate
404 * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
405 * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
408 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
409 : SMESHGUI_GenericHypothesisCreator( theHypType )
411 MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
412 this->mySMPMap.clear();
414 GeomToolSelected = NULL;
415 GeomToolSelected = getGeomSelectionTool();
417 aSel = GeomToolSelected->selectionMgr();
419 /* Initialize the Python interpreter */
420 if (! Py_IsInitialized())
421 throw ("Error: Python interpreter is not initialized");
422 PyGILState_STATE gstate;
423 gstate = PyGILState_Ensure();
426 main_mod = PyImport_AddModule("__main__");
429 main_dict = PyModule_GetDict(main_mod);
431 PyRun_SimpleString("from math import *");
432 PyGILState_Release(gstate);
436 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
441 * \brief {Get or create the geom selection tool for active study}
443 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
445 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
446 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
447 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
448 that->GeomToolSelected = new GeomSelectionTools(aStudy);
450 return that->GeomToolSelected;
453 GEOM::GEOM_Gen_var BLSURFPluginGUI_HypothesisCreator::getGeomEngine()
455 return GeometryGUI::GetGeomGen();
459 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
461 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
464 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
465 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
469 myAdvWidget->myOptionTable->setFocus();
470 QApplication::instance()->processEvents();
472 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
473 for ( ; row < nbRows; ++row )
475 QString name = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
476 QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
477 if ( !value.isEmpty() ) {
479 QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().trimmed();
480 if (optionType == "PRECAD")
481 h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
482 else if (optionType == "BLSURF")
483 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
485 catch ( const SALOME::SALOME_Exception& ex )
487 msg = ex.details.text.in();
495 h->SetOptionValues( myOptions ); // restore values
496 h->SetPreCADOptionValues( myPreCADOptions ); // restore values
499 // SizeMap and attractors
502 mySizeMapTable->setFocus();
503 QApplication::instance()->processEvents();
505 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
506 int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
508 for ( ; row < nbRows; ++row )
510 QString entry = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
511 QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
512 MESSAGE("entry ="<<entry.toStdString())
513 if ( !sizeMap.isEmpty() ) {
514 if (that->sizeMapValidationFromRow(row))
517 MESSAGE("entry ="<<entry.toStdString())
518 MESSAGE("sizeMap ="<<sizeMap.toStdString())
520 e = entry.toStdString();
521 s = that->mySMPMap[entry].toStdString();
522 MESSAGE("row = "<<row)
525 h->SetSizeMapEntry( e.c_str(), s.c_str() );
527 catch ( const SALOME::SALOME_Exception& ex )
529 msg = ex.details.text.in();
540 // 22207: BLSURFPLUGIN: The user is allowed to enter 0 as a global or local size.
543 // In case if not STD_TAB is current tab, then text() of empty spinboxes returns "0" value.
544 // So STD_TAB must be current tab to get correct value of it's spinbox.
545 myTabWidget->setCurrentIndex( STD_TAB );
549 if ( !( ok = ( myStdWidget->myPhySize->text().isEmpty() ||
550 myStdWidget->myPhySize->text().toDouble() > 0.0 )))
551 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_HPHYDEF"));
555 if ( !( ok = ( myStdWidget->myMaxSize->text().isEmpty() ||
556 myStdWidget->myMaxSize->text().toDouble() > 0.0 )))
557 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_MAXSIZE"));
561 if ( !( ok = ( myStdWidget->myAngleMesh->text().isEmpty() ||
562 myStdWidget->myAngleMesh->text().toDouble() > 0.0 )))
563 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_ANGLE_MESH"));
567 if ( !( ok = ( myStdWidget->myChordalError->text().isEmpty() ||
568 myStdWidget->myChordalError->text().toDouble() > 0.0 )))
569 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_CHORDAL_ERROR"));
578 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
580 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
582 QFrame* fr = new QFrame( 0 );
583 // fr-> setMinimumSize(600,400);
584 QVBoxLayout* lay = new QVBoxLayout( fr );
585 // lay->setSizeConstraint(QLayout::SetDefaultConstraint);
587 lay->setSpacing( 0 );
589 // main TabWidget of the dialog
590 myTabWidget = new QTabWidget( fr );
591 myTabWidget->setTabShape( QTabWidget::Rounded );
592 myTabWidget->setTabPosition( QTabWidget::North );
593 lay->addWidget( myTabWidget );
598 myStdGroup = new QWidget();
599 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
600 aStdLayout->setSpacing( 6 );
601 aStdLayout->setMargin( 11 );
604 myName = new QLineEdit( myStdGroup );
605 myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
609 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), 0, 0, 1, 1 );
610 aStdLayout->addWidget( myName, row++, 1, 1, 3 );
612 aStdLayout->addWidget( myStdWidget, row++, 0, 1, 4 );
618 // row = max(row,maxrow)+1;
619 aStdLayout->setRowStretch(row,1);
620 aStdLayout->setColumnStretch(1,1);
624 // advanced parameters
625 myAdvGroup = new QWidget();
626 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
627 anAdvLayout->setSpacing( 6 );
628 anAdvLayout->setMargin( 11 );
629 myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
630 myAdvWidget->addBtn->setMenu( new QMenu() );
631 anAdvLayout->addWidget( myAdvWidget);
634 // Size Maps parameters
636 mySmpGroup = new QWidget();
637 // mySmpGroup->setMinimumWidth(500);
640 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
643 mySizeMapTable = new QTreeWidget( mySmpGroup );
644 mySizeMapTable ->setMinimumWidth(200);
645 QStringList sizeMapHeaders;
646 sizeMapHeaders << tr( "SMP_NAME_COLUMN" )<< tr( "SMP_SIZEMAP_COLUMN" )<< tr( "SMP_ENTRY_COLUMN" );// << tr( "SMP_DIST_COLUMN" );
647 mySizeMapTable->setHeaderLabels(sizeMapHeaders);
648 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
649 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
650 mySizeMapTable->hideColumn(SMP_ENTRY_COLUMN);
651 mySizeMapTable->setAlternatingRowColors(true);
654 smpTab = new QTabWidget( mySmpGroup );
655 smpTab->setTabShape( QTabWidget::Rounded );
656 smpTab->setTabPosition( QTabWidget::South );
657 lay->addWidget( smpTab );
659 // Filters of selection
660 TColStd_MapOfInteger SM_ShapeTypes, ATT_ShapeTypes;
662 SM_ShapeTypes.Add( TopAbs_VERTEX );
663 SM_ShapeTypes.Add( TopAbs_EDGE );
664 SM_ShapeTypes.Add( TopAbs_FACE );
665 SM_ShapeTypes.Add( TopAbs_COMPOUND );
667 ATT_ShapeTypes.Add( TopAbs_VERTEX );
668 ATT_ShapeTypes.Add( TopAbs_EDGE );
669 ATT_ShapeTypes.Add( TopAbs_WIRE );
670 ATT_ShapeTypes.Add( TopAbs_COMPOUND );
672 SMESH_NumberFilter* myFilter1 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
673 SMESH_NumberFilter* myFilter2 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, ATT_ShapeTypes);
674 SMESH_NumberFilter* myFilter3 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, TopAbs_FACE);
676 // Standard size map tab
677 mySmpStdGroup = new QWidget();
678 QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
679 myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false,/*stretch=*/false);
680 myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
681 mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
682 mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
683 QLabel* mySmpSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),mySmpStdGroup);
686 myAttractorGroup = new QWidget();
687 QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
688 myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false,/*stretch=*/false);
689 myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
690 myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
691 myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
692 myConstSizeCheck = new QCheckBox(tr("BLSURF_CONST_SIZE"),myAttractorGroup);
693 QFrame* attLine = new QFrame(myAttractorGroup);
694 attLine->setFrameShape(QFrame::HLine);
695 attLine->setFrameShadow(QFrame::Sunken);
696 myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false,/*stretch=*/false);
697 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
698 myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
699 myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
700 myAttSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),myAttractorGroup);
701 myAttDistSpin = new SMESHGUI_SpinBox(myAttractorGroup);
702 myAttDistSpin->RangeStepAndValidator(0., COORD_MAX, 10.0, "length_precision");
703 myAttDistLabel = new QLabel(tr("BLSURF_ATT_DIST"),myAttractorGroup);
704 myAttDistSpin2 = new SMESHGUI_SpinBox(myAttractorGroup);
705 myAttDistSpin2->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
706 myAttDistLabel2 = new QLabel(tr("BLSURF_ATT_RADIUS"),myAttractorGroup);
708 myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
709 myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
713 addMapButton = new QPushButton(tr("BLSURF_SM_ADD"),mySmpGroup);
714 removeMapButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
715 modifyMapButton = new QPushButton(tr("BLSURF_SM_MODIFY"),mySmpGroup);
716 modifyMapButton->setEnabled(false);
719 myAttSelWdg->setEnabled(false);
720 myAttSizeSpin->setEnabled(false);
721 myAttSizeLabel->setEnabled(false);
722 myAttDistSpin->setEnabled(false);
723 myAttDistLabel->setEnabled(false);
724 myAttDistSpin2->setEnabled(false);
725 myAttDistLabel2->setEnabled(false);
726 myAttDistSpin->setValue(0.);
727 myAttDistSpin2->setValue(0.);
728 myAttSizeSpin->setValue(0.);
729 mySmpSizeSpin->setValue(0.);
732 // ADD WIDGETS (SIZEMAP TAB)
733 anSmpLayout->addWidget(mySizeMapTable, 0, 0, SMP_NB_LINES, 1);
734 anSmpLayout->setColumnStretch(0, 1);
735 // anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 2, 2);
736 anSmpLayout->addWidget(smpTab, SMP_TAB_WDG, 1, 1, 3);
737 anSmpLayout->setRowStretch(SMP_TAB_WDG, 1);
738 anSmpLayout->addWidget(addMapButton, SMP_ADD_BTN, 1, 1, 1);
739 anSmpLayout->addWidget(removeMapButton, SMP_ADD_BTN, 2, 1, 1);
740 anSmpLayout->addWidget(modifyMapButton, SMP_ADD_BTN, 3, 1, 1);
743 anSmpStdLayout->addWidget(myGeomSelWdg1, SMP_GEOM_BTN_1, 1, 1, 2);
744 anSmpStdLayout->addWidget(mySmpSizeLabel, SMP_SIZE, 1, 1, 1);
745 anSmpStdLayout->addWidget(mySmpSizeSpin, SMP_SIZE, 2, 1, 1);
746 anSmpStdLayout->setRowStretch(SMP_SPACE2, 1);
749 anAttLayout->addWidget(myGeomSelWdg2, SMP_GEOM_BTN_2, 1, 1, 2);
750 anAttLayout->addWidget(myAttractorCheck, ATT_CHECK, 1, 1, 2);
751 anAttLayout->addWidget(myConstSizeCheck, CONST_SIZE_CHECK,1, 1, 2);
752 anAttLayout->addWidget(attLine, SMP_SPACE, 1, 1, 2);
753 anAttLayout->addWidget(myAttSelWdg, SMP_ATT_SHAPE, 1, 1, 2);
754 anAttLayout->addWidget(myAttSizeLabel, SMP_ATT_SIZE, 1, 1, 1);
755 anAttLayout->addWidget(myAttSizeSpin, SMP_ATT_SIZE, 2, 1, 1);
756 anAttLayout->addWidget(myAttDistLabel, SMP_ATT_DIST, 1, 1, 1);
757 anAttLayout->addWidget(myAttDistSpin, SMP_ATT_DIST, 2, 1, 1);
758 anAttLayout->addWidget(myAttDistLabel2, SMP_ATT_RAD, 1, 1, 1);
759 anAttLayout->addWidget(myAttDistSpin2, SMP_ATT_RAD, 2, 1, 1);
760 anAttLayout->setRowStretch(SMP_ATT_RAD+1, 1);
762 smpTab->insertTab( SMP_STD_TAB, mySmpStdGroup, tr( "BLSURF_SM_STD_TAB" ) );
763 smpTab->insertTab( ATT_TAB, myAttractorGroup, tr( "BLSURF_SM_ATT_TAB" ) );
765 smpTab->setCurrentIndex( SMP_STD_TAB );
767 // Enforced vertices parameters
768 myEnfGroup = new QWidget();
769 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
771 // myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
772 // anEnfLayout->addWidget(myEnforcedVertexWidget);
773 // MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
774 // myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
776 myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
777 myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
778 myEnforcedTreeWidget->setSortingEnabled(true);
779 QStringList enforcedHeaders;
780 enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_FACE_ENTRY_COLUMN")
781 << tr("BLSURF_ENF_VER_X_COLUMN")<< tr("BLSURF_ENF_VER_Y_COLUMN") << tr("BLSURF_ENF_VER_Z_COLUMN")
782 << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
784 myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
785 myEnforcedTreeWidget->header()->setStretchLastSection(true);
786 myEnforcedTreeWidget->setAlternatingRowColors(true);
787 myEnforcedTreeWidget->setUniformRowHeights(true);
788 myEnforcedTreeWidget->setAnimated(true);
789 myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
790 myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
791 for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
792 myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
793 myEnforcedTreeWidget->resizeColumnToContents(column);
795 myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
796 myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
797 myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
799 // FACE AND VERTEX SELECTION
800 TColStd_MapOfInteger shapeTypes1, shapeTypes2;
801 shapeTypes1.Add( TopAbs_FACE );
802 shapeTypes1.Add( TopAbs_COMPOUND );
803 shapeTypes2.Add( TopAbs_VERTEX );
804 shapeTypes2.Add( TopAbs_COMPOUND );
806 SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
807 myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true, /*stretch=*/false);
808 myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
810 SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
811 myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false);
812 myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
814 myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
816 QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
817 myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
818 myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
820 QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
821 myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
822 myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
824 QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
825 myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
826 myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
828 QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
829 myGroupName = new QLineEdit(myEnfGroup);
831 addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
832 removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
834 myInternalEnforcedVerticesAllFaces = new QCheckBox(tr("BLSURF_ENF_VER_INTERNAL_VERTICES"),myEnfGroup);
836 QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
837 myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
839 // myGlobalGroupName = new QCheckBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
840 // myGlobalGroupName->setChecked(false);
842 anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, ENF_VER_NB_LINES, 1);
843 QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
844 // FACE AND VERTEX SELECTION
845 anEnfLayout2->addWidget(myEnfFaceWdg, ENF_VER_FACE, 0, 1, 2);
846 anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2);
847 anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1);
848 anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1);
849 anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1);
850 anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1);
851 anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1);
852 anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1);
853 anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1);
854 anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1);
855 // anEnfLayout2->addWidget(myGlobalGroupName, ENF_VER_GROUP_CHECK, 0, 1, 2);
856 // anEnfLayout2->setRowStretch( ENF_VER_SPACE, 1);
857 anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1);
858 anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1);
859 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
860 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
861 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
862 anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
863 // anEnfLayout2->addWidget(makeGroupsCheck, ENF_VER_GROUP_CHECK, 0, 1, 2);
864 anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
865 // anEnfLayout->setRowStretch(1, 1);
868 myTabWidget->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
869 myTabWidget->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
870 myTabWidget->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
871 myTabWidget->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
873 myTabWidget->setCurrentIndex( STD_TAB );
875 connect( myAdvWidget->addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
876 connect( myAdvWidget->addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
877 connect( myAdvWidget->rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
880 connect( addMapButton, SIGNAL( clicked()), this, SLOT( onAddMap() ) );
881 connect( removeMapButton, SIGNAL( clicked()), this, SLOT( onRemoveMap() ) );
882 connect( modifyMapButton, SIGNAL( clicked()), this, SLOT( onModifyMap() ) );
883 // connect( mySizeMapTable, SIGNAL( cellChanged ( int, int )), this, SLOT( onSetSizeMap(int,int ) ) );
884 connect( mySizeMapTable, SIGNAL( itemClicked (QTreeWidgetItem *, int)),this, SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
885 connect( myGeomSelWdg2, SIGNAL( contentModified() ), this, SLOT( onMapGeomContentModified() ) );
886 connect( myGeomSelWdg1, SIGNAL( contentModified() ), this, SLOT( onMapGeomContentModified() ) );
887 // connect( myAttractorGroup, SIGNAL( clicked(bool) ), this, SLOT( onAttractorGroupClicked(bool) ) );
888 connect( mySizeMapTable, SIGNAL( itemChanged (QTreeWidgetItem *, int)),this, SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
889 connect( myAttractorCheck, SIGNAL( stateChanged ( int )), this, SLOT( onAttractorClicked( int ) ) );
890 connect( myConstSizeCheck, SIGNAL( stateChanged ( int )), this, SLOT( onConstSizeClicked( int ) ) );
891 connect( smpTab, SIGNAL( currentChanged ( int )), this, SLOT( onSmpTabChanged( int ) ) );
894 connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
895 connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
896 // connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
897 connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
898 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertices() ) );
899 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
900 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
901 connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this, SLOT( onInternalVerticesClicked( int ) ) );
902 // connect( myEnfVertexWdg, SIGNAL( selectionActivated()), this, SLOT( onVertexSelectionActivated() ) );
903 // connect( myEnfFaceWdg, SIGNAL( selectionActivated()), this, SLOT( onFaceSelectionActivated() ) );
908 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
909 This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
911 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
913 // if ((now == myXCoord) || (now == myYCoord) || (now == myZCoord)
914 // || (now = myGroupName) || (now = myGlobalGroupName) || (now = myEnforcedTreeWidget)) {
915 // BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
916 // that->getGeomSelectionTool()->selectionMgr()->clearFilters();
917 // myEnfFaceWdg->deactivateSelection();
918 // myEnfVertexWdg->deactivateSelection();
923 * This method resets the content of the X, Y, Z widgets;
925 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
927 myXCoord->setCleared(true);
928 myYCoord->setCleared(true);
929 myZCoord->setCleared(true);
930 myXCoord->setText("");
931 myYCoord->setText("");
932 myZCoord->setText("");
933 // myGroupName->setText("");
936 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
937 This method updates the tooltip of a modified item. The QLineEdit widgets content
938 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
940 void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
941 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
942 QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
943 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
944 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
945 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
946 QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
947 QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
948 QTreeWidgetItem* parent = item->parent();
950 clearEnforcedVertexWidgets();
952 if (parent && (!x.isNull() || !entry.isNull())) {
953 QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
954 QString toolTip = shapeName + QString(": ") + vertexName.toString();
955 if (entry.isNull()) {
956 toolTip += QString("(") + x.toString();
957 toolTip += QString(", ") + y.toString();
958 toolTip += QString(", ") + z.toString();
959 toolTip += QString(")");
962 if (!groupName.isEmpty())
963 toolTip += QString(" [") + groupName + QString("]");
965 item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
968 myXCoord->SetValue(x.toDouble());
969 myYCoord->SetValue(y.toDouble());
970 myZCoord->SetValue(z.toDouble());
973 if (!groupName.isEmpty())
974 myGroupName->setText(groupName);
978 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
979 int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
980 clearEnforcedVertexWidgets();
981 if (nbSelEnfVertex == 1)
983 if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
986 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
987 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
988 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
989 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
990 if (CORBA::is_nil(measureOp))
994 measureOp->PointCoordinates (myEnfVertex, x, y, z);
995 if ( measureOp->IsDone() )
997 myXCoord->SetValue(x);
998 myYCoord->SetValue(y);
999 myZCoord->SetValue(z);
1005 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1006 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
1007 of the enforced vertex clicked in the tree widget.
1009 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
1010 clearEnforcedVertexWidgets();
1011 QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
1012 if (! items.isEmpty() && items.size() == 1) {
1013 QTreeWidgetItem *item = items[0];
1014 // for (int i=0 ; i < items.size() ; i++) {
1016 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1017 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1018 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1019 QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1020 QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
1021 if (!x.isNull()/* && entry.isNull()*/) {
1022 myXCoord->SetValue(x.toDouble());
1023 myYCoord->SetValue(y.toDouble());
1024 myZCoord->SetValue(z.toDouble());
1027 if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1028 myGroupName->setText(group.toString());
1033 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1034 This method adds a face containing enforced vertices in the tree widget.
1036 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
1037 // Find theFaceEntry item
1038 QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1039 QTreeWidgetItem* theItem;
1040 if (theItemList.empty()) {
1041 theItem = new QTreeWidgetItem();
1042 theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1043 theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1044 theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1045 myEnforcedTreeWidget->addTopLevelItem(theItem);
1048 theItem = theItemList[0];
1053 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1054 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1056 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theItem, double x, double y, double z,
1057 std::string vertexName, std::string geomEntry, std::string groupName) {
1059 std::string theFaceName = theItem->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
1060 // MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
1061 bool okToCreate = true;
1063 const int nbVert = theItem->childCount();
1064 // MESSAGE("Number of child rows: " << nbVert);
1066 double childValueX,childValueY,childValueZ;
1067 QString childEntry, childGroupName;
1068 QTreeWidgetItem* child;
1069 for (int row = 0;row<nbVert;row++) {
1070 child = theItem->child(row);
1071 childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1072 childEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1073 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1074 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1075 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1076 if (((childValueX == x) && (childValueY == y) && (childValueZ == z)) || ( (childEntry.toStdString() != "") && (childEntry.toStdString() == geomEntry))) {
1077 // update group name
1078 if (childGroupName.toStdString() != groupName) {
1079 MESSAGE("Group is updated from \"" << childGroupName.toStdString() << "\" to \"" << groupName << "\"");
1080 child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1088 if (geomEntry.empty()) {
1089 MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1092 MESSAGE("In " << theFaceName << " vertex with entry " << geomEntry << " already exist: dont create again");
1097 if (geomEntry.empty()) {
1098 MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
1101 MESSAGE("In " << theFaceName << " vertex with geom entry " << geomEntry << " is created");
1104 QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
1105 vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1106 QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1107 QSize iconSize = iconSelect.size()*0.7;
1109 int vertexIndex=myEnforcedTreeWidget->indexOfTopLevelItem(theItem);
1110 QString myVertexName;
1112 while(indexRef != vertexIndex) {
1113 indexRef = vertexIndex;
1114 if (vertexName.empty())
1115 myVertexName = QString("Vertex #%1").arg(vertexIndex);
1117 myVertexName = QString(vertexName.c_str());
1119 for (int row = 0;row<nbVert;row++) {
1120 QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1121 if (myVertexName == name) {
1127 vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1128 if (geomEntry.empty()) {
1129 vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1130 vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1131 vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1134 vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1135 vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1137 if (groupName != "")
1138 vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1140 QString toolTip = QString(theFaceName.c_str())+QString(": ")+myVertexName;
1141 if (geomEntry.empty()) {
1142 toolTip += QString(" (%1, ").arg(x);
1143 toolTip += QString("%1, ").arg(y);
1144 toolTip += QString("%1)").arg(z);
1146 if (groupName != "")
1147 toolTip += QString(" [%1]").arg(groupName.c_str());
1149 vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1150 theItem->setExpanded(true);
1151 myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1154 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1155 This method is called when a item is added into the enforced vertices tree widget
1157 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
1158 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1160 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1162 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1163 myEnfFaceWdg->deactivateSelection();
1164 myEnfVertexWdg->deactivateSelection();
1166 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1167 myEnforcedTreeWidget->resizeColumnToContents(column);
1170 int selEnfFace = myEnfFaceWdg->NbObjects();
1171 int selEnfVertex = myEnfVertexWdg->NbObjects();
1172 bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1174 if (selEnfFace == 0)
1177 if ((selEnfVertex == 0) && coordsEmpty)
1180 string entry, shapeName;
1182 for (int i = 0 ; i < selEnfFace ; i++) {
1183 myEnfFace = myEnfFaceWdg->GetObject< GEOM::GEOM_Object >(i);
1184 entry = myEnfFace->GetStudyEntry();
1185 shapeName = myEnfFace->GetName();
1187 QTreeWidgetItem * faceItem = addEnforcedFace(entry, shapeName);
1189 std::string groupName = myGroupName->text().toStdString();
1191 if (boost::trim_copy(groupName).empty())
1194 if (selEnfVertex <= 1)
1197 x = myXCoord->GetValue();
1198 y = myYCoord->GetValue();
1199 z = myZCoord->GetValue();
1200 if (selEnfVertex == 1) {
1201 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1202 addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1205 addEnforcedVertex(faceItem, x, y, z, "", "", groupName);
1209 if ( CORBA::is_nil(getGeomEngine()))
1212 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1213 if (CORBA::is_nil(measureOp))
1216 CORBA::Double x,y,z;
1218 for (int j = 0 ; j < selEnfVertex ; j++)
1220 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1221 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1222 measureOp->PointCoordinates (myEnfVertex, x, y, z);
1223 if ( measureOp->IsDone() )
1224 addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1225 } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1226 addEnforcedVertex(faceItem, 0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1232 myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
1233 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1235 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1236 myEnforcedTreeWidget->resizeColumnToContents(column);
1238 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1239 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1240 myStdWidget->onPhysicalMeshChanged();
1244 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1245 This method is called when a item is removed from the enforced vertices tree widget
1247 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1248 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1249 QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1250 QList<QTreeWidgetItem *> selectedVertices;
1251 QSet<QTreeWidgetItem *> selectedEntries;
1252 QTreeWidgetItem* item;
1254 foreach( item, selectedItems ) {
1255 QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1256 if (! value.isNull())
1257 selectedVertices.append(item);
1259 value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1260 if (! value.isNull())
1261 selectedVertices.append(item);
1263 selectedEntries.insert(item);
1267 foreach(item,selectedVertices) {
1268 QTreeWidgetItem* parent = item->parent();
1269 // MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1270 parent->removeChild(item);
1272 if (parent->childCount() == 0) {
1273 if (selectedEntries.contains(parent))
1274 selectedEntries.remove(parent);
1279 foreach(item,selectedEntries) {
1280 // MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1284 myEnforcedTreeWidget->selectionModel()->clearSelection();
1288 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1290 myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1293 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1294 This method updates the GUI widgets with the hypothesis data
1296 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1298 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1299 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1301 BlsurfHypothesisData data;
1302 that->readParamsFromHypo( data );
1305 myName->setText( data.myName );
1306 QFontMetrics metrics( myName->font() );
1307 myName->setMinimumWidth( metrics.width( data.myName )+5 );
1309 myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1310 myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1311 if (data.myPhySize <= 0)
1312 myStdWidget->myPhySize->setText("");
1314 myStdWidget->myPhySize->SetValue( data.myPhySize );
1315 myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1316 if (data.myMinSize < 0)
1317 myStdWidget->myMinSize->setText("");
1319 myStdWidget->myMinSize->SetValue( data.myMinSize );
1320 myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1321 if (data.myMaxSize < 0)
1322 myStdWidget->myMaxSize->setText("");
1324 myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1325 myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1326 if (data.myGradation <= 0)
1327 myStdWidget->myGradation->setText("");
1329 myStdWidget->myGradation->SetValue( data.myGradation );
1330 myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1332 if (data.myAngleMesh < 0)
1333 myStdWidget->myAngleMesh->setText("");
1335 myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1336 if (data.myChordalError <= 0)
1337 myStdWidget->myChordalError->setText("");
1339 myStdWidget->myChordalError->SetValue( data.myChordalError );
1340 myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1341 if (data.myAnisotropicRatio <= 0)
1342 myStdWidget->myAnisotropicRatio->setText("");
1344 myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1345 myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1346 if (data.myTinyEdgeLength <= 0)
1347 myStdWidget->myTinyEdgeLength->setText("");
1349 myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1350 myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1351 if (data.myBadElementAspectRatio <= 0)
1352 myStdWidget->myBadElementAspectRatio->setText("");
1354 myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1355 myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1356 myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1358 myStdWidget->resizeWidgets();
1360 myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1361 myAdvWidget->myPreCADGroupBox->setChecked(data.myTopology == PreCAD);
1362 myAdvWidget->myPreCADMergeEdges->setChecked( data.myPreCADMergeEdges );
1363 myAdvWidget->myPreCADProcess3DTopology->setChecked( data.myPreCADProcess3DTopology );
1364 myAdvWidget->myPreCADDiscardInput->setChecked( data.myPreCADDiscardInput );
1366 if ( myOptions.operator->() ) {
1367 // MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1368 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1369 QString option = that->myOptions[i].in();
1370 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1371 if ( name_value.count() > 1 ) {
1372 QString idStr = QString("%1").arg( i );
1373 int row = myAdvWidget->myOptionTable->rowCount();
1374 myAdvWidget->myOptionTable->setRowCount( row+1 );
1375 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1376 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1377 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "BLSURF" ) );
1378 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1379 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1380 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1381 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1382 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1383 Qt::ItemIsEditable |
1384 Qt::ItemIsEnabled );
1388 if ( myPreCADOptions.operator->() ) {
1389 // MESSAGE("retrieveParams():myPreCADOptions->length() = " << myPreCADOptions->length());
1390 for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
1391 QString option = that->myPreCADOptions[i].in();
1392 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1393 if ( name_value.count() > 1 ) {
1394 QString idStr = QString("%1").arg( i );
1395 int row = myAdvWidget->myOptionTable->rowCount();
1396 myAdvWidget->myOptionTable->setRowCount( row+1 );
1397 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1398 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1399 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "PRECAD" ) );
1400 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1401 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1402 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1403 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1404 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1405 Qt::ItemIsEditable |
1406 Qt::ItemIsEnabled );
1410 myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1411 myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1412 // myGMFFileMode->setChecked(data.myGMFFileMode);
1415 MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1416 QMapIterator<QString, QString> i(that->mySMPMap);
1417 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1418 while (i.hasNext()) {
1420 const QString entry = i.key();
1421 const QString sizeMap = i.value();
1422 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1423 int row = mySizeMapTable->topLevelItemCount();
1424 QTreeWidgetItem* item = new QTreeWidgetItem();
1425 mySizeMapTable->addTopLevelItem( item );
1426 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1427 item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1428 item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1429 if (that->myATTMap.contains(entry)){
1430 const QString attEntry = that->myATTMap[entry];
1431 std::string attName = myGeomToolSelected->getNameFromEntry(attEntry.toStdString());
1432 QTreeWidgetItem* child = new QTreeWidgetItem();
1433 item->addChild( child );
1434 item->setExpanded(true);
1435 child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1436 child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attEntry ) );
1437 child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString( attName ) ) );
1439 if (that->myAttDistMap[entry] > std::numeric_limits<double>::epsilon()){
1440 item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Attractor" ) ) );
1443 item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Constant Size" ) ) );
1448 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1451 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1452 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1453 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1455 // Enforced vertices
1456 MESSAGE("retrieveParams(): data.entryCoordsListMap.size() = " << data.faceEntryEnfVertexListMap.size());
1457 TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1459 for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1460 TEntry entry = (*evmIt).first;
1461 std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1462 MESSAGE("Face entry: " << entry);
1463 MESSAGE("Face name: " << shapeName);
1465 QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1467 TEnfVertexList evs = (*evmIt).second;
1469 TEnfVertexList::const_iterator evsIt = evs.begin();
1470 TEnfVertex *enfVertex;
1471 for ( ; evsIt != evs.end() ; ++evsIt) {
1472 enfVertex = (*evsIt);
1473 MESSAGE("Name: " << enfVertex->name);
1475 if (enfVertex->coords.size()) {
1476 x = enfVertex->coords[0];
1477 y = enfVertex->coords[1];
1478 z = enfVertex->coords[2];
1480 that->addEnforcedVertex(faceItem, x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1484 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1485 myEnforcedTreeWidget->resizeColumnToContents(column);
1487 myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
1488 myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
1489 myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
1492 that->myStdWidget->onPhysicalMeshChanged();
1493 that->myStdWidget->onGeometricMeshChanged();
1496 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1497 This method updates the hypothesis data with the GUI widgets content.
1499 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1501 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1503 BlsurfHypothesisData data;
1504 QString guiHyp = that->readParamsFromWidgets( data );
1505 that->storeParamsToHypo( data );
1510 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1511 Updates the hypothesis data from hypothesis values.
1513 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1515 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1516 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1517 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1519 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1520 h_data.myName = isCreation() && data ? hypName() : "";
1522 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
1523 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
1524 h_data.myPhySize = h->GetPhySize();
1525 h_data.myPhySizeRel = h->IsPhySizeRel();
1526 double minSize = h->GetMinSize();
1527 double maxSize = h->GetMaxSize();
1528 h_data.myMinSize = minSize > 0 ? minSize : -1.0;
1529 h_data.myMinSizeRel = h->IsMinSizeRel();
1530 h_data.myMaxSize = maxSize > 0 ? maxSize : -1.0;
1531 h_data.myMaxSizeRel = h->IsMaxSizeRel();
1532 h_data.myGradation = h->GetGradation();
1533 h_data.myAllowQuadrangles = h->GetQuadAllowed();
1534 double angle = h->GetAngleMesh();
1535 h_data.myAngleMesh = angle > 0 ? angle : -1.0;
1536 double chordalError = h->GetChordalError();
1537 h_data.myChordalError = chordalError > 0 ? chordalError : -1.0;
1538 h_data.myAnisotropic = h->GetAnisotropic();
1539 double myAnisotropicRatio = h->GetAnisotropicRatio();
1540 h_data.myAnisotropicRatio = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
1541 h_data.myRemoveTinyEdges = h->GetRemoveTinyEdges();
1542 double myTinyEdgeLength = h->GetTinyEdgeLength();
1543 h_data.myTinyEdgeLength = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
1544 h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
1545 double myBadElementAspectRatio = h->GetBadElementAspectRatio();
1546 h_data.myBadElementAspectRatio = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
1547 h_data.myOptimizeMesh = h->GetOptimizeMesh();
1548 h_data.myQuadraticMesh = h->GetQuadraticMesh();
1549 h_data.myVerbosity = h->GetVerbosity();
1550 h_data.myTopology = (int) h->GetTopology();
1551 h_data.myPreCADMergeEdges = h->GetPreCADMergeEdges();
1552 h_data.myPreCADProcess3DTopology = h->GetPreCADProcess3DTopology();
1553 h_data.myPreCADDiscardInput = h->GetPreCADDiscardInput();
1556 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1557 that->myOptions = h->GetOptionValues();
1558 that->myPreCADOptions = h->GetPreCADOptionValues();
1560 h_data.myGMFFileName = h->GetGMFFile();
1561 // h_data.myGMFFileMode = h->GetGMFFileMode();
1563 that->mySMPMap.clear();
1564 that->myATTMap.clear();
1565 that->myAttDistMap.clear();
1566 that->myDistMap.clear();
1568 // classic size maps
1569 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1570 // MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1571 QString fullSizeMaps;
1572 QStringList fullSizeMapList;
1573 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1574 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1575 fullSizeMaps = mySizeMaps[i].in();
1576 // MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1577 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1578 if ( fullSizeMapList.count() > 1 ) {
1579 string fullSizeMap = fullSizeMapList[1].toStdString();
1580 int pos = fullSizeMap.find("return")+7;
1581 // MESSAGE("pos:" << pos);
1584 sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1589 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1590 // MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1591 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1592 // MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1598 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1599 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1601 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1602 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
1603 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1604 if ( fullCustomSizeMapList.count() > 1 ) {
1605 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1606 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1607 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1608 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1613 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1614 // MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1616 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1617 QString myAttractors = allMyAttractors[i].in();
1618 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1619 if ( myAttractorList.count() > 1 ) {
1620 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1621 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1622 // MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1623 // MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1627 // attractor new version
1628 MESSAGE("retrieveParams, Attractors")
1629 BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
1630 for ( int i = 0;i<allMyAttractorParams->length(); ++i ) {
1631 BLSURFPlugin::TAttractorParams myAttractorParams = allMyAttractorParams[i];
1632 QString faceEntry = myAttractorParams.faceEntry.in();
1633 QString attEntry = myAttractorParams.attEntry.in();
1634 MESSAGE("attEntry = "<<attEntry.toStdString())
1635 double startSize = myAttractorParams.startSize;
1636 double endSize = myAttractorParams.endSize;
1637 double infDist = myAttractorParams.infDist;
1638 double constDist = myAttractorParams.constDist;
1639 that->mySMPMap[faceEntry] = QString::number( startSize, 'g', 6 ); // TODO utiliser les préférences ici (cf. sketcher)
1640 that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
1641 that->myATTMap[faceEntry] = attEntry;
1642 that->myAttDistMap[faceEntry] = infDist;
1643 that->myDistMap[faceEntry] = constDist;
1646 // Enforced vertices
1647 h_data.enfVertexList.clear();
1648 h_data.faceEntryEnfVertexListMap.clear();
1650 h_data.groupNameEnfVertexListMap.clear();
1653 BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
1654 MESSAGE("faceEntryEnfVertexListMap->length() = " << faceEntryEnfVertexListMap->length());
1656 for ( int i = 0;i<faceEntryEnfVertexListMap->length(); ++i ) {
1657 std::string entry = faceEntryEnfVertexListMap[i].faceEntry.in();
1658 // BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList.in();
1659 BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
1660 // BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1662 // TEnfVertexList& enfVertexList = h_data.faceEntryEnfVertexListMap[entry];
1664 for (int j=0 ; j<vertexList.length(); ++j) {
1665 TEnfVertex *enfVertex = new TEnfVertex();
1667 enfVertex->name = CORBA::string_dup(vertexList[j].name.in());
1668 enfVertex->geomEntry = CORBA::string_dup(vertexList[j].geomEntry.in());
1669 enfVertex->grpName = CORBA::string_dup(vertexList[j].grpName.in());
1670 for (int k=0 ; k< vertexList[j].coords.length();k++)
1671 enfVertex->coords.push_back(vertexList[j].coords[k]);
1673 h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
1676 if (groupName != "") {
1677 h_data.groupNameEnfVertexListMap[groupName].insert(ev);
1681 // h_data.enfVertMap[entry] = evs;
1682 // h_data.entryCoordsListMap[entry] = coordsList;
1684 if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
1685 h_data.faceEntryEnfVertexListMap.erase(entry);
1688 h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
1689 h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
1694 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1695 Saves the hypothesis data to hypothesis values.
1697 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1699 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1700 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1701 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1707 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1709 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
1710 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1711 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1712 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1714 if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
1715 if ( h->GetPhySize() != h_data.myPhySize ||
1716 h->IsPhySizeRel() != h_data.myPhySizeRel ) {
1717 if ( h_data.myPhySizeRel )
1718 h->SetPhySizeRel( h_data.myPhySize );
1720 h->SetPhySize( h_data.myPhySize );
1723 if (h->GetMinSize() != h_data.myMinSize ||
1724 h->IsMinSizeRel() != h_data.myMinSizeRel ) {
1725 if ( h_data.myMinSizeRel )
1726 h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1728 h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1730 if (h->GetMaxSize() != h_data.myMaxSize ||
1731 h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
1732 if ( h_data.myMaxSizeRel )
1733 h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1735 h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1737 if ( h->GetGradation() != h_data.myGradation )
1738 h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
1739 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1740 h->SetQuadAllowed( h_data.myAllowQuadrangles );
1742 if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
1743 if ( h->GetAngleMesh() != h_data.myAngleMesh )
1744 h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
1745 if ( h->GetChordalError() != h_data.myChordalError )
1746 h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
1749 if ( h->GetAnisotropic() != h_data.myAnisotropic )
1750 h->SetAnisotropic( h_data.myAnisotropic );
1751 if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
1752 h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
1754 if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
1755 h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
1756 if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
1757 h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
1759 if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
1760 h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
1761 if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
1762 h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
1764 if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
1765 h->SetOptimizeMesh( h_data.myOptimizeMesh );
1767 if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
1768 h->SetQuadraticMesh( h_data.myQuadraticMesh );
1770 if ( h->GetVerbosity() != h_data.myVerbosity )
1771 h->SetVerbosity( h_data.myVerbosity );
1772 if ( h->GetTopology() != h_data.myTopology )
1773 h->SetTopology( (int) h_data.myTopology );
1774 if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
1775 h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
1776 if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
1777 h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
1778 if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
1779 h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
1781 h->SetOptionValues( myOptions ); // is set in checkParams()
1782 h->SetPreCADOptionValues( myPreCADOptions ); // is set in checkParams()
1784 if ( h->GetGMFFile() != h_data.myGMFFileName )
1785 // || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
1786 // h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
1787 h->SetGMFFile( h_data.myGMFFileName.c_str());
1789 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1790 QMapIterator<QString,QString> i(that->mySMPMap);
1791 while (i.hasNext()) {
1793 const QString entry = i.key();
1794 const QString sizeMap = i.value();
1796 if (sizeMap == "__TO_DELETE__") {
1797 MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1798 h->UnsetEntry(entry.toLatin1().constData());
1800 else if (sizeMap.startsWith("ATTRACTOR")) {
1801 // MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1802 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
1804 else if (sizeMap.startsWith("def")) {
1805 // MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1806 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1809 if (!myATTMap[entry].isEmpty()){
1810 QString att_entry = myATTMap[entry];
1811 double infDist = myAttDistMap[entry];
1812 double constDist = myDistMap[entry];
1813 double phySize = h->GetPhySize();
1814 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1815 h->SetClassAttractorEntry( entry.toLatin1().constData(), att_entry.toLatin1().constData(), sizeMap.toDouble() , phySize, infDist, constDist );
1816 QApplication::restoreOverrideCursor();
1819 QString fullSizeMap;
1820 fullSizeMap = QString("");
1821 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
1822 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1823 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
1824 fullSizeMap = QString("def f(t): return ") + sizeMap;
1825 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1826 fullSizeMap = QString("def f(): return ") + sizeMap;
1827 MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1828 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1833 // Enforced vertices
1836 std::string enfName;
1838 std::string groupName = "";
1841 TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
1842 // 1. Clear all enforced vertices in hypothesis
1843 // 2. Add new enforced vertex according to h_data
1845 if ( h->GetAllEnforcedVertices()->length() > 0 )
1846 h->ClearAllEnforcedVertices();
1849 TEnfVertexList::const_iterator evsIt;
1850 for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
1852 faceEntry = evmIt->first;
1853 evs = evmIt->second;
1854 MESSAGE("Number of enforced vertices for face entry " << faceEntry << ": " << evs.size());
1855 evsIt = evs.begin();
1856 for ( ; evsIt != evs.end() ; ++evsIt)
1859 if ((*evsIt)->coords.size()) {
1860 x = (*evsIt)->coords[0];
1861 y = (*evsIt)->coords[1];
1862 z = (*evsIt)->coords[2];
1864 ret = h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
1868 if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
1869 h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
1870 if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
1871 h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
1874 catch(const std::exception& ex) {
1875 std::cout << "Exception: " << ex.what() << std::endl;
1878 // catch(const SALOME::SALOME_Exception& ex)
1881 // // SalomeApp_Tools::QtCatchCorbaException(ex);
1887 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1888 Stores the widgets content to the hypothesis data.
1890 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1892 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1893 h_data.myName = myName ? myName->text() : "";
1894 h_data.myPhysicalMesh = myStdWidget->myPhysicalMesh->currentIndex();
1895 h_data.myGeometricMesh = myStdWidget->myGeometricMesh->currentIndex();
1896 h_data.myPhySize = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
1897 h_data.myPhySizeRel = myStdWidget->myPhySizeRel->isChecked();
1898 h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
1899 h_data.myMinSizeRel = myStdWidget->myMinSizeRel->isChecked();
1900 h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
1901 h_data.myMaxSizeRel = myStdWidget->myMaxSizeRel->isChecked();
1902 h_data.myGradation = myStdWidget->myGradation->text().isEmpty() ? -1.0 : myStdWidget->myGradation->GetValue();
1903 h_data.myAllowQuadrangles = myStdWidget->myAllowQuadrangles->isChecked();
1904 h_data.myAngleMesh = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
1905 h_data.myChordalError = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
1906 h_data.myAnisotropic = myStdWidget->myAnisotropic->isChecked();
1907 h_data.myAnisotropicRatio = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
1908 h_data.myRemoveTinyEdges = myStdWidget->myRemoveTinyEdges->isChecked();
1909 h_data.myTinyEdgeLength = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
1910 h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
1911 h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
1912 h_data.myOptimizeMesh = myStdWidget->myOptimizeMesh->isChecked();
1913 h_data.myQuadraticMesh = myStdWidget->myQuadraticMesh->isChecked();
1914 h_data.myVerbosity = myAdvWidget->myVerbosity->value();
1915 h_data.myTopology = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
1916 h_data.myPreCADMergeEdges = myAdvWidget->myPreCADMergeEdges->isChecked();
1917 h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
1918 h_data.myPreCADDiscardInput = myAdvWidget->myPreCADDiscardInput->isChecked();
1921 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1922 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1923 guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
1924 guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
1925 guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
1926 guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
1927 guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
1928 guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
1929 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1930 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1931 guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
1932 guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
1933 guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
1934 guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
1937 guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
1938 guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
1939 guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
1940 guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
1941 guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
1942 guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
1945 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1946 guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
1947 guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
1948 guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
1950 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1951 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
1952 for ( ; row < nbRows; ++row )
1954 int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1955 std::string optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().toStdString();
1956 if ( id >= 0 && ( ( optionType == "BLSURF" && id < myOptions->length() ) || ( optionType == "PRECAD" && id < myPreCADOptions->length() ) ) )
1958 QString name = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1959 QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1960 if ( value.isNull() )
1962 if (optionType == "PRECAD")
1963 that->myPreCADOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1965 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1967 if ( value != "" ) {
1968 if (optionType == "PRECAD")
1969 guiHyp += "PRECAD_";
1970 guiHyp += name + " = " + value + "; ";
1975 h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
1976 // h_data.myGMFFileMode = myGMFFileMode->isChecked();
1979 row = 0, nbRows = mySizeMapTable->topLevelItemCount();
1980 for ( ; row < nbRows; ++row )
1982 QString entry = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
1983 if ( that->mySMPMap.contains(entry) )
1984 guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1987 // Enforced vertices
1988 h_data.enfVertexList.clear();
1989 h_data.faceEntryEnfVertexListMap.clear();
1991 int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1992 int nbEnforcedVertices = 0;
1993 std::string groupName = "";
1994 // MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1995 for (int i=0 ; i<nbEnforcedShapes ; i++) {
1996 QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1998 std::string faceEntry = shapeItem->data(ENF_VER_FACE_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1999 nbEnforcedVertices = shapeItem->childCount();
2000 if (nbEnforcedVertices >0) {
2001 double childValueX,childValueY,childValueZ;
2002 std::string childName, vertexEntry;
2003 QTreeWidgetItem* child;
2006 for (row = 0;row<nbEnforcedVertices;row++) {
2007 child = shapeItem->child(row);
2008 childName = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
2009 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
2010 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
2011 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
2012 vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2013 // if (myGlobalGroupName->isChecked())
2014 // groupName = myGlobalGroupName->text().toStdString();
2016 groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
2018 TEnfVertex *enfVertex = new TEnfVertex();
2019 enfVertex->name = childName;
2020 if (vertexEntry.empty()) {
2021 enfVertex->coords.push_back(childValueX);
2022 enfVertex->coords.push_back(childValueY);
2023 enfVertex->coords.push_back(childValueZ);
2026 enfVertex->geomEntry = vertexEntry;
2027 enfVertex->grpName = groupName;
2028 // TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
2029 // if (it == h_data.enfVertexList.end())
2030 h_data.enfVertexList.insert(enfVertex);
2031 evs.insert(enfVertex);
2033 if (groupName != "")
2034 h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2037 h_data.faceEntryEnfVertexListMap[faceEntry] = evs;
2042 h_data.myInternalEnforcedVerticesAllFaces = myInternalEnforcedVerticesAllFaces->isChecked();
2043 h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2045 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
2049 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2051 QMenu* menu = (QMenu*)sender();
2052 // fill popup with option names
2054 QString name_value, name;
2055 if ( myOptions.operator->() ) {
2056 QMenu* blsurfMenu = menu->addMenu(tr("OPTION_MENU_BLSURF"));
2057 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
2058 name_value = myOptions[i].in();
2059 name = name_value.split( ":", QString::KeepEmptyParts )[0];
2060 blsurfMenu->addAction( name );
2063 if ( myPreCADOptions.operator->() ) {
2064 QMenu* preCADmenu = menu->addMenu(tr("OPTION_MENU_PRECAD"));
2065 for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
2066 name_value = myPreCADOptions[i].in();
2067 name = name_value.split( ":", QString::KeepEmptyParts )[0];
2068 preCADmenu->addAction( name );
2073 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
2075 myAdvWidget->myOptionTable->setFocus();
2076 QMenu* menu = (QMenu*)( a->parent() );
2078 int idx = menu->actions().indexOf( a );
2079 QString idStr = QString("%1").arg( idx );
2080 QString option, optionType;
2081 if (menu->title() == tr("OPTION_MENU_BLSURF")) {
2082 option = myOptions[idx].in();
2083 optionType = "BLSURF";
2085 else if (menu->title() == tr("OPTION_MENU_PRECAD")) {
2086 option = myPreCADOptions[idx].in();
2087 optionType = "PRECAD";
2089 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
2091 // look for a row with optionName
2092 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
2093 for ( ; row < nbRows; ++row )
2094 if ( myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
2095 if ( myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text() == optionType )
2097 // add a row if not found
2098 if ( row == nbRows ) {
2099 myAdvWidget->myOptionTable->setRowCount( row+1 );
2100 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
2101 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
2102 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( optionType ) );
2103 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
2104 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
2105 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
2106 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
2107 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
2108 Qt::ItemIsEditable |
2109 Qt::ItemIsEnabled );
2110 myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2112 myAdvWidget->myOptionTable->clearSelection();
2113 myAdvWidget->myOptionTable->scrollToItem( myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2114 //myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
2115 myAdvWidget->myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
2116 //myAdvWidget->myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2119 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
2121 // clear option values and remember selected row
2122 QList<int> selectedRows;
2123 QList<QTableWidgetItem*> selected = myAdvWidget->myOptionTable->selectedItems();
2124 QTableWidgetItem* item;
2125 foreach( item, selected ) {
2126 int row = item->row();
2127 if ( !selectedRows.contains( row ) ) {
2128 selectedRows.append( row );
2129 int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
2130 QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text();
2132 if (optionType == "BLSURF" && id < myOptions->length() )
2133 myOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2134 else if (optionType == "PRECAD" && id < myPreCADOptions->length() )
2135 myPreCADOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2138 qSort( selectedRows );
2139 QListIterator<int> it( selectedRows );
2141 while ( it.hasPrevious() )
2142 myAdvWidget->myOptionTable->removeRow( it.previous() );
2145 // **********************
2146 // *** BEGIN SIZE MAP ***
2147 // **********************
2149 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2151 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2153 if ( myGeomSelWdg2->IsObjectSelected() ){
2154 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2156 else if ( myGeomSelWdg1->IsObjectSelected() ){
2157 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2159 std::string entry = (string) mySMapObject->GetStudyEntry();
2160 QString qEntry = QString::fromStdString(entry);
2161 if (that->mySMPMap.contains(qEntry) && that->mySMPMap[qEntry] != "__TO_DELETE__" ) {
2162 addMapButton->setEnabled(false);
2163 modifyMapButton->setEnabled(true);
2166 addMapButton->setEnabled(true);
2167 modifyMapButton->setEnabled(false);
2172 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2174 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked("<<col<<")")
2175 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2176 if (col == SMP_SIZEMAP_COLUMN){
2177 QString entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2178 if (!mySMPMap.contains(entry))
2180 QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2181 CORBA::Object_var obj = entryToObject(entry);
2182 if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")){ // ADVANCED MAPS
2183 smpTab->setCurrentIndex(ATT_TAB); // Change Tab
2184 double phySize = that->mySMPMap[entry].toDouble(); // Retrieve values of the selected item in the current tab widgets
2185 double infDist = that->myAttDistMap[entry];
2186 double constDist = that->myDistMap[entry];
2187 QString attEntry = that->myATTMap[entry];
2188 CORBA::Object_var attObj = entryToObject(attEntry);
2189 myAttSizeSpin->setValue(phySize);
2190 if (sizeMap.startsWith("Attractor")){
2191 myAttDistSpin->setValue(infDist);
2192 myAttractorCheck->setChecked(true);
2195 myAttractorCheck->setChecked(false);
2197 if (sizeMap.startsWith("Constant") || constDist > std::numeric_limits<double>::epsilon()){
2198 myAttDistSpin2->setValue(constDist);
2199 myConstSizeCheck->setChecked(true);
2202 myConstSizeCheck->setChecked(false);
2204 myGeomSelWdg2->SetObject(obj);
2205 myAttSelWdg->SetObject(attObj);
2207 else { // CLASSIC MAPS
2208 smpTab->setCurrentIndex(SMP_STD_TAB); // Change Tab
2209 myGeomSelWdg1->SetObject(obj); // Retrieve values of the selected item in the current tab widgets
2210 if (!sizeMap.startsWith("def")){
2211 mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
2217 void BLSURFPluginGUI_HypothesisCreator::onSmpTabChanged(int tab)
2219 myAttDistSpin->setValue(0.); // Reinitialize widgets
2220 myAttSizeSpin->setValue(0.);
2221 myAttDistSpin2->setValue(0.);
2222 mySmpSizeSpin->setValue(0.);
2223 myGeomSelWdg1->deactivateSelection();
2224 myGeomSelWdg2->deactivateSelection();
2225 myAttSelWdg->deactivateSelection();
2226 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2227 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2228 myAttSelWdg->SetObject(CORBA::Object::_nil());
2229 myAttractorCheck->setChecked(false);
2230 myConstSizeCheck->setChecked(false);
2233 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2235 if (state == Qt::Checked){
2236 myAttSelWdg->setEnabled(true);
2237 myAttSizeSpin->setEnabled(true);
2238 myAttSizeLabel->setEnabled(true);
2239 myAttDistSpin->setEnabled(true);
2240 myAttDistLabel->setEnabled(true);
2241 if (!myAttSelWdg->IsObjectSelected()){
2242 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2245 if (state == Qt::Unchecked){
2246 myAttDistSpin->setEnabled(false);
2247 myAttDistLabel->setEnabled(false);
2248 myAttDistSpin->setValue(0.);
2249 if(myConstSizeCheck->checkState() == Qt::Unchecked){ // No predefined map selected
2250 myAttSelWdg->setEnabled(false);
2251 myAttSizeSpin->setEnabled(false);
2252 myAttSizeLabel->setEnabled(false);
2253 myAttDistSpin2->setEnabled(false);
2254 myAttDistLabel2->setEnabled(false);
2256 else if (!myAttSelWdg->IsObjectSelected()){ // Only constant size selected
2257 myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2262 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2264 if (state == Qt::Checked){
2265 myAttSelWdg->setEnabled(true);
2266 myAttSizeSpin->setEnabled(true);
2267 myAttSizeLabel->setEnabled(true);
2268 myAttDistSpin2->setEnabled(true);
2269 myAttDistLabel2->setEnabled(true);
2270 if (myAttractorCheck->checkState() == Qt::Unchecked &&
2271 !myAttSelWdg->IsObjectSelected()){
2272 myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2275 if (state == Qt::Unchecked){
2276 myAttDistSpin2->setEnabled(false);
2277 myAttDistLabel2->setEnabled(false);
2278 myAttDistSpin2->setValue(0.);
2279 if(myAttractorCheck->checkState() == Qt::Unchecked){ // No predefined map selected
2280 myAttSelWdg->setEnabled(false);
2281 myAttSizeSpin->setEnabled(false);
2282 myAttSizeLabel->setEnabled(false);
2283 myAttDistSpin->setEnabled(false);
2284 myAttDistLabel->setEnabled(false);
2286 else if (!myAttSelWdg->IsObjectSelected()){ // Only constant size selected
2287 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2292 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
2294 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
2295 QList<int> selectedRows;
2296 QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
2297 QTreeWidgetItem* item;
2298 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2300 qSort( selectedRows );
2301 QListIterator<QTreeWidgetItem*> it( selected );
2303 while ( it.hasPrevious() ) {
2304 item = it.previous();
2305 QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2306 if (that->mySMPMap.contains(entry))
2307 that->mySMPMap[entry] = "__TO_DELETE__";
2308 if (that->mySMPShapeTypeMap.contains(entry))
2309 that->mySMPShapeTypeMap.remove(entry);
2310 if (that->myATTMap.contains(entry))
2311 that->myATTMap.remove(entry);
2312 if (that->myDistMap.contains(entry))
2313 that->myDistMap.remove(entry);
2314 if (that->myAttDistMap.contains(entry))
2315 that->myAttDistMap.remove(entry);
2318 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
2319 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2322 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
2324 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< col << ")");
2325 MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2326 if (col == SMP_SIZEMAP_COLUMN) {
2327 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2328 QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2329 QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
2330 MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
2331 if (! that->mySMPShapeTypeMap.contains(entry))
2332 MESSAGE("no such entry in mySMPShapeTypeMap")
2334 if (that->mySMPMap.contains(entry))
2335 if (that->mySMPMap[entry] == sizeMap
2336 || sizeMap.startsWith("Attractor")
2337 || sizeMap.startsWith("Constant") ){
2340 if (! sizeMap.isEmpty()) {
2341 that->mySMPMap[entry] = sizeMap;
2342 sizeMapValidationFromEntry(entry);
2345 MESSAGE("Size map empty: reverse to precedent value" );
2346 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
2348 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2352 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
2355 if ( smpTab->currentIndex() == ATT_TAB ){
2356 if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
2357 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2358 myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2359 res = insertAttractor(mySMapObject, myAttObject);
2362 if (smpTab->currentIndex() == SMP_STD_TAB ){
2363 if ( myGeomSelWdg1->IsObjectSelected() ){
2364 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2365 res = insertElement(mySMapObject);
2369 // Local size should be more than 0
2370 QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
2371 SUIT_MessageBox::critical( dlg(),"Error" , msg );
2374 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2375 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2376 myAttDistSpin->setValue(0.);
2377 myAttSizeSpin->setValue(0.);
2378 myAttDistSpin2->setValue(0.);
2379 mySmpSizeSpin->setValue(0.);
2380 myConstSizeCheck->setChecked(false);
2381 myAttractorCheck->setChecked(false);
2382 myGeomSelWdg1->deactivateSelection();
2383 myGeomSelWdg2->deactivateSelection();
2384 myAttSelWdg->deactivateSelection();
2385 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2386 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2387 myAttSelWdg->SetObject(CORBA::Object::_nil());
2390 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
2392 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onModifyMap()");
2394 if ( smpTab->currentIndex() == ATT_TAB ){
2395 if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
2396 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2397 myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2398 res = insertAttractor(mySMapObject, myAttObject, /*modify = */true);
2401 if (smpTab->currentIndex() == SMP_STD_TAB ){
2402 if ( myGeomSelWdg1->IsObjectSelected() ){
2403 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2404 res = insertElement(mySMapObject, /*modify = */true);
2408 // Local size should be more than 0
2409 QString msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_SM_SIZE"));
2410 SUIT_MessageBox::critical( dlg(),"Error" , msg );
2413 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2414 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2415 myAttDistSpin->setValue(0.);
2416 myAttSizeSpin->setValue(0.);
2417 myAttDistSpin2->setValue(0.);
2418 mySmpSizeSpin->setValue(0.);
2419 myConstSizeCheck->setChecked(false);
2420 myAttractorCheck->setChecked(false);
2421 myGeomSelWdg1->deactivateSelection();
2422 myGeomSelWdg2->deactivateSelection();
2423 myAttSelWdg->deactivateSelection();
2424 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2425 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2426 myAttSelWdg->SetObject(CORBA::Object::_nil());
2429 bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
2431 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElement()");
2432 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2433 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2435 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2437 TopAbs_ShapeEnum shapeType;
2438 string entry, shapeName;
2439 entry = (string) anObject->GetStudyEntry();
2440 MESSAGE("entry = "<<entry);
2441 shapeName = anObject->GetName();
2442 shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
2443 // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
2444 // in order to write the size map with the right syntax in StoreParamsToHypo
2445 // (f(t) for edges, f(u,v) for faces ...)
2446 if (shapeType == TopAbs_COMPOUND){
2447 TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
2448 TopoDS_Shape childShape;
2449 TopoDS_Iterator anIt(theShape);
2450 for(;anIt.More();anIt.Next()){
2451 childShape = anIt.Value();
2452 shapeType = childShape.ShapeType();
2453 if(!childShape.IsNull()){
2458 mySizeMapTable->setFocus();
2460 shapeEntry = QString::fromStdString(entry);
2461 double phySize = mySmpSizeSpin->value();
2464 return false; // Local size should be more than 0
2466 std::ostringstream oss;
2469 sizeMap = QString::fromStdString(oss.str());
2470 QTreeWidgetItem* item = new QTreeWidgetItem();
2472 int rowToChange = findRowFromEntry(shapeEntry);
2473 item = mySizeMapTable->topLevelItem( rowToChange );
2476 if (that->mySMPMap.contains(shapeEntry)) {
2477 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2478 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2482 mySizeMapTable->addTopLevelItem(item);
2484 that->mySMPMap[shapeEntry] = sizeMap;
2485 that->myDistMap[shapeEntry] = 0. ;
2486 that->mySMPShapeTypeMap[shapeEntry] = shapeType;
2487 item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
2488 item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2489 item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
2490 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2491 mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2492 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2493 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2494 mySizeMapTable->clearSelection();
2496 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2497 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2498 myStdWidget->onPhysicalMeshChanged();
2503 bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
2505 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertAttractor()");
2506 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2507 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2509 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2511 TopAbs_ShapeEnum shapeType;
2512 string entry, attEntry, faceName, attName;
2513 entry = (string) aFace->GetStudyEntry();
2514 attEntry = (string) anAttractor->GetStudyEntry();
2515 faceName = aFace->GetName();
2516 attName = anAttractor->GetName();
2517 shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
2518 mySizeMapTable->setFocus();
2519 QString shapeEntry = QString::fromStdString(entry);
2520 QString qAttEntry = QString::fromStdString(attEntry);
2522 double phySize = h->GetPhySize();
2523 double infDist = 0. ;
2524 double constDist = 0. ;
2525 phySize = myAttSizeSpin->value();
2528 return false; // Local size should be more than 0
2530 if (myAttractorCheck->isChecked()){
2531 infDist = myAttDistSpin->value();
2533 if (myConstSizeCheck->isChecked()){
2534 constDist = myAttDistSpin2->value();
2536 std::ostringstream oss;
2537 std::ostringstream oss2;
2538 std::ostringstream oss3;
2542 QString sizeMap = QString::fromStdString(oss.str());
2543 QString infDistString = QString::fromStdString(oss2.str());
2544 QString constDistString = QString::fromStdString(oss3.str());
2546 QTreeWidgetItem* item;
2547 QTreeWidgetItem* child;
2549 int rowToChange = findRowFromEntry(shapeEntry);
2550 item = mySizeMapTable->topLevelItem( rowToChange );
2551 child = item->child( 0 );
2554 if (that->mySMPMap.contains(shapeEntry)) {
2555 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2556 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2560 item = new QTreeWidgetItem();
2561 child = new QTreeWidgetItem();
2562 mySizeMapTable->addTopLevelItem(item);
2563 item->addChild(child);
2565 that->mySMPMap.insert(shapeEntry,sizeMap);
2566 that->myATTMap.insert(shapeEntry,qAttEntry);
2567 that->myAttDistMap.insert(shapeEntry,infDist);
2568 that->myDistMap.insert(shapeEntry,constDist);
2569 that->mySMPShapeTypeMap.insert(shapeEntry,shapeType);
2570 item->setExpanded(true);
2571 item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2572 item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
2573 if (infDist > std::numeric_limits<double>::epsilon()){
2574 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
2576 else if (constDist > std::numeric_limits<double>::epsilon()){
2577 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
2579 item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
2581 child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
2582 child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
2583 child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2585 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2586 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2587 mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2589 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2590 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2591 myStdWidget->onPhysicalMeshChanged();
2593 MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2597 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
2599 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
2600 int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2601 for ( ; row < nbRows; ++row )
2602 if (! sizeMapValidationFromRow(row))
2607 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
2609 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(), row = "<<myRow);
2610 QString myEntry = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2611 bool res = sizeMapValidationFromEntry(myEntry,displayError);
2612 mySizeMapTable->setFocus();
2616 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
2618 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
2619 MESSAGE("myEntry = "<<myEntry.toStdString())
2621 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2623 if (! that->mySMPMap.contains(myEntry)) {
2624 // MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
2627 if (! that->mySMPShapeTypeMap.contains(myEntry)) {
2628 // MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
2634 if (that->mySMPMap[myEntry].startsWith("def")) {
2635 // MESSAGE("custom function" );
2636 expr = that->mySMPMap[myEntry].toStdString();
2638 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
2639 // MESSAGE("Attractor" );
2640 if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)(?:;(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+))?\\)$")) != 1)) {
2643 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False[;d])" );
2649 // case size map is empty
2650 if (that->mySMPMap[myEntry].isEmpty()) {
2652 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
2656 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
2657 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
2658 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
2659 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
2660 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
2661 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
2664 //assert(Py_IsInitialized());
2665 if (! Py_IsInitialized())
2666 throw ("Erreur: Python interpreter is not initialized");
2667 PyGILState_STATE gstate;
2668 gstate = PyGILState_Ensure();
2670 PyObject * obj = NULL;
2671 PyObject* new_stderr = NULL;
2672 string err_description="";
2673 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
2677 new_stderr=newPyStdOut(err_description);
2678 PySys_SetObject((char*)"stderr", new_stderr);
2680 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2681 Py_DECREF(new_stderr);
2683 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
2684 PyGILState_Release(gstate);
2689 PyObject * func = NULL;
2690 func = PyObject_GetAttrString(main_mod, "f");
2694 new_stderr=newPyStdOut(err_description);
2695 PySys_SetObject((char*)"stderr", new_stderr);
2697 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2698 Py_DECREF(new_stderr);
2700 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
2701 PyGILState_Release(gstate);
2705 PyGILState_Release(gstate);
2707 // MESSAGE("SizeMap expression "<<expr<<" is valid");
2712 QString BLSURFPluginGUI_HypothesisCreator::caption() const
2714 return tr( "BLSURF_TITLE" );
2717 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
2719 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
2722 QString BLSURFPluginGUI_HypothesisCreator::type() const
2724 return tr( "BLSURF_HYPOTHESIS" );
2727 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
2729 return "blsurf_hypo_page.html";
2732 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
2735 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2737 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2742 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
2744 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
2745 SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
2746 CORBA::Object_var obj;
2747 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
2748 if (!aSObj->_is_nil()) {
2749 obj = aSObj->GetObject();
2750 aSObj->UnRegister();
2755 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
2756 QString entryForChecking;
2757 int endRow = mySizeMapTable->topLevelItemCount()-1;
2759 entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2760 while (entry != entryForChecking && row <= endRow){
2762 entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2764 MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)