1 // Copyright (C) 2007-2010 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"
29 #include <SMESHGUI_Utils.h>
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_Dialog.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Tools.h>
37 #include <SalomeApp_DoubleSpinBox.h>
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 #include <QGridLayout>
50 #include <QPushButton>
52 #include <QTableWidget>
53 #include <QHeaderView>
54 #include <QApplication>
55 #include <QRadioButton>
57 #include <QStandardItemModel>
58 #include <QStandardItem>
59 #include <QTreeWidget>
60 #include <QTreeWidgetItem>
61 #include <QModelIndexList>
63 #include <LightApp_SelectionMgr.h>
64 #include <SalomeApp_Application.h>
65 #include <SALOME_ListIO.hxx>
66 #include <SALOME_ListIteratorOfListIO.hxx>
68 #include <GEOM_Client.hxx>
69 #include <TopoDS_Shape.hxx>
70 #include <SMESH_Gen_i.hxx>
71 #include <boost/shared_ptr.hpp>
72 #include <structmember.h>
74 // #include <GeomSelectionTools.h>
75 #define WITH_SIZE_BOUNDARIES
101 OPTION_ID_COLUMN = 0,
105 SMP_ENTRY_COLUMN = 0,
113 // SMP_ATTRACTOR_BTN,
122 // Enforced vertices inputs
133 // Enforced vertices array columns
135 ENF_VER_NAME_COLUMN = 0,
136 ENF_VER_ENTRY_COLUMN,
144 /**************************************************
145 Begin initialization Python structures and objects
146 ***************************************************/
155 PyStdOut_dealloc(PyStdOut *self)
161 PyStdOut_write(PyStdOut *self, PyObject *args)
165 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
169 *(self->out)=*(self->out)+c;
175 static PyMethodDef PyStdOut_methods[] = {
176 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
177 PyDoc_STR("write(string) -> None")},
178 {NULL, NULL} /* sentinel */
181 static PyMemberDef PyStdOut_memberlist[] = {
182 {"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
183 "flag indicating that a space needs to be printed; used by print"},
184 {NULL} /* Sentinel */
187 static PyTypeObject PyStdOut_Type = {
188 /* The ob_type field must be initialized in the module init function
189 * to be portable to Windows without using C++. */
190 PyObject_HEAD_INIT(NULL)
193 sizeof(PyStdOut), /*tp_basicsize*/
196 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
203 0, /*tp_as_sequence*/
208 PyObject_GenericGetAttr, /*tp_getattro*/
209 /* softspace is writable: we must supply tp_setattro */
210 PyObject_GenericSetAttr, /* tp_setattro */
212 Py_TPFLAGS_DEFAULT, /*tp_flags*/
216 0, /*tp_richcompare*/
217 0, /*tp_weaklistoffset*/
220 PyStdOut_methods, /*tp_methods*/
221 PyStdOut_memberlist, /*tp_members*/
235 PyObject * newPyStdOut( std::string& out )
238 self = PyObject_New(PyStdOut, &PyStdOut_Type);
243 return (PyObject*)self;
246 /*************************************************
247 End initialization Python structures and objects
248 **************************************************/
251 class QDoubleValidator;
254 // BEGIN EnforcedTreeWidgetDelegate
257 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
258 : QItemDelegate(parent)
262 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
263 const QStyleOptionViewItem & option ,
264 const QModelIndex & index ) const
266 QLineEdit *editor = new QLineEdit(parent);
267 if (index.column() == ENF_VER_X_COLUMN || \
268 index.column() == ENF_VER_Y_COLUMN || \
269 index.column() == ENF_VER_Z_COLUMN)
270 editor->setValidator(new QDoubleValidator(parent));
275 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
276 const QModelIndex &index) const
278 QString value = index.model()->data(index, Qt::EditRole).toString();
280 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
281 lineEdit->setText(value);
284 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
285 const QModelIndex &index) const
287 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
289 if (index.column() == ENF_VER_X_COLUMN || \
290 index.column() == ENF_VER_Y_COLUMN || \
291 index.column() == ENF_VER_Z_COLUMN)
293 if (! vertexExists(model, index, lineEdit->text())) {
295 double value = lineEdit->text().toDouble(&ok);
297 model->setData(index, value, Qt::EditRole);
300 else if (index.column() == ENF_VER_NAME_COLUMN) {
301 QString value = lineEdit->text();
302 if (! vertexExists(model, index, value))
303 model->setData(index, value, Qt::EditRole);
304 // MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")");
308 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
309 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
311 editor->setGeometry(option.rect);
314 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
315 const QModelIndex &index, QString value) const
318 QModelIndex parent = index.parent();
319 int row = index.row();
320 int col = index.column();
322 if (parent.isValid()) {
323 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
325 if (col == ENF_VER_X_COLUMN) {
326 x = value.toDouble();
327 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
328 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
330 if (col == ENF_VER_Y_COLUMN) {
331 y = value.toDouble();
332 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
333 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
335 if (col == ENF_VER_Z_COLUMN) {
336 z = value.toDouble();
337 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
338 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
340 // MESSAGE("Checking for existing vertex " << x << ", " << y << "," << z);
341 int nbChildren = model->rowCount(parent);
342 for (int i = 0 ; i < nbChildren ; i++) {
344 double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
345 double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
346 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
347 // MESSAGE("Vertex: " << childX << ", " << childY << "," << childZ);
348 if ((childX == x) && (childY == y) && (childZ == z)) {
349 // MESSAGE("Found !");
356 else if (index.column() == ENF_VER_NAME_COLUMN) {
357 int nbChildren = model->rowCount(parent);
358 for (int i = 0 ; i < nbChildren ; i++) {
360 QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
361 if (childName == value) {
374 // END EnforcedTreeWidgetDelegate
379 * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
380 * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
383 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
384 : SMESHGUI_GenericHypothesisCreator( theHypType )
386 MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
387 this->mySMPMap.clear();
389 GeomToolSelected = NULL;
390 GeomToolSelected = getGeomSelectionTool();
392 aSel = GeomToolSelected->selectionMgr();
394 /* Initialize the Python interpreter */
395 if (! Py_IsInitialized())
396 throw ("Error: Python interpreter is not initialized");
397 PyGILState_STATE gstate;
398 gstate = PyGILState_Ensure();
401 main_mod = PyImport_AddModule("__main__");
404 main_dict = PyModule_GetDict(main_mod);
406 PyRun_SimpleString("from math import *");
407 PyGILState_Release(gstate);
411 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
416 * \brief {Get or create the geom selection tool for active study}
418 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
420 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool");
421 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
422 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
423 // MESSAGE("aStudy->StudyId(): " << aStudy->StudyId());
424 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
425 // MESSAGE("GeomToolSelected is created");
426 that->GeomToolSelected = new GeomSelectionTools(aStudy);
429 // MESSAGE("GeomToolSelected already exists");
430 // MESSAGE("that->GeomToolSelected->getMyStudy()->StudyId(): " << that->GeomToolSelected->getMyStudy()->StudyId());
431 return that->GeomToolSelected;
435 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
436 QString str = theText.trimmed();
438 if ( !str.isEmpty() )
447 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
449 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
451 if ( !isDouble( myPhySize->text(), false )) {
452 if ( myPhySize->text().isEmpty() )
453 myPhySize->setText(tr("OBLIGATORY_VALUE"));
454 myPhySize->selectAll();
457 if ( !isDouble( myPhyMin->text(), true )) {
458 myPhyMin->selectAll();
461 if ( !isDouble( myPhyMax->text(), true )) {
462 myPhyMax->selectAll();
465 if ( !isDouble( myGeoMin->text(), true )) {
466 myGeoMin->selectAll();
469 if ( !isDouble( myGeoMin->text(), true )) {
470 myGeoMin->selectAll();
475 myOptionTable->setFocus();
476 QApplication::instance()->processEvents();
478 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
479 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
481 int row = 0, nbRows = myOptionTable->rowCount();
482 for ( ; row < nbRows; ++row )
484 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
485 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
486 if ( !value.isEmpty() ) {
488 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
490 catch ( const SALOME::SALOME_Exception& ex )
492 SUIT_MessageBox::critical( dlg(),
494 ex.details.text.in() );
499 h->SetOptionValues( myOptions ); // restore values
502 // SizeMap and attractors
505 mySizeMapTable->setFocus();
506 QApplication::instance()->processEvents();
508 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
509 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
511 int row = 0, nbRows = mySizeMapTable->rowCount();
512 for ( ; row < nbRows; ++row )
514 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
515 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
516 if ( !sizeMap.isEmpty() ) {
517 if (that->sizeMapValidationFromRow(row))
520 const char* e = entry.toLatin1().constData();
521 const char* s = that->mySMPMap[entry].toLatin1().constData();
522 h->SetSizeMapEntry( e, s );
524 catch ( const SALOME::SALOME_Exception& ex )
526 SUIT_MessageBox::critical( dlg(),
528 ex.details.text.in() );
545 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
547 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
548 QFrame* fr = new QFrame( 0 );
549 QVBoxLayout* lay = new QVBoxLayout( fr );
551 lay->setSpacing( 0 );
554 QTabWidget* tab = new QTabWidget( fr );
555 tab->setTabShape( QTabWidget::Rounded );
556 tab->setTabPosition( QTabWidget::North );
557 lay->addWidget( tab );
560 myStdGroup = new QWidget();
561 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
562 aStdLayout->setSpacing( 6 );
563 aStdLayout->setMargin( 11 );
568 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
569 myName = new QLineEdit( myStdGroup );
570 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
573 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
574 myGradation = new SalomeApp_DoubleSpinBox( myStdGroup );
575 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
576 myGradation->setMinimum( 1.1 );
577 myGradation->setMaximum( 2.5 );
578 myGradation->setSingleStep( 0.1 );
580 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
581 myPhysicalMesh = new QComboBox( myStdGroup );
582 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
583 QStringList physicalTypes;
584 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
585 myPhysicalMesh->addItems( physicalTypes );
587 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
588 myPhySize = new QLineEdit( myStdGroup );
589 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
591 #ifdef WITH_SIZE_BOUNDARIES
592 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
593 myPhyMin = new QLineEdit( myStdGroup );
594 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
596 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
597 myPhyMax = new QLineEdit( myStdGroup );
598 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
601 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
602 myGeometricMesh = new QComboBox( myStdGroup );
603 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
605 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
606 myGeometricMesh->addItems( types );
608 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
609 myAngleMeshS = new SalomeApp_DoubleSpinBox( myStdGroup );
610 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
611 myAngleMeshS->setMinimum( 0 );
612 myAngleMeshS->setMaximum( 16 );
613 myAngleMeshS->setSingleStep( 0.5 );
615 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
616 myAngleMeshC = new SalomeApp_DoubleSpinBox( myStdGroup );
617 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
618 myAngleMeshC->setMinimum( 0 );
619 myAngleMeshC->setMaximum( 16 );
620 myAngleMeshC->setSingleStep( 0.5 );
622 #ifdef WITH_SIZE_BOUNDARIES
623 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
624 myGeoMin = new QLineEdit( myStdGroup );
625 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
627 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
628 myGeoMax = new QLineEdit( myStdGroup );
629 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
632 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
633 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
635 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
636 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
638 // advanced parameters
639 myAdvGroup = new QWidget();
640 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
641 anAdvLayout->setSpacing( 6 );
642 anAdvLayout->setMargin( 11 );
644 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
645 myTopology = new QComboBox( myAdvGroup );
646 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
647 QStringList topologyTypes;
648 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
649 myTopology->addItems( topologyTypes );
651 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
652 myVerbosity = new QSpinBox( myAdvGroup );
653 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
654 myVerbosity->setMinimum( 0 );
655 myVerbosity->setMaximum( 100 );
656 myVerbosity->setSingleStep( 5 );
658 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
659 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
661 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
662 myOptionTable->setHorizontalHeaderLabels( headers );
663 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
664 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
665 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
666 myOptionTable->verticalHeader()->hide();
667 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
669 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
670 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
671 addBtn->setMenu( new QMenu() );
673 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
674 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
676 anAdvLayout->setRowStretch( 4, 5 );
677 anAdvLayout->setColumnStretch( 1, 5 );
679 // Size Maps parameters
681 mySmpGroup = new QWidget();
682 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
684 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
685 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
686 QStringList sizeMapHeaders;
687 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
688 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
689 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
690 mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
691 // mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
692 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
693 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
694 mySizeMapTable->setAlternatingRowColors(true);
695 mySizeMapTable->verticalHeader()->hide();
698 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
699 anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
701 QFrame *line = new QFrame(mySmpGroup);
702 line->setFrameShape(QFrame::HLine);
703 line->setFrameShadow(QFrame::Sunken);
704 anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
706 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
707 anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
709 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
710 anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
712 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
713 anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
715 QFrame *line2 = new QFrame(mySmpGroup);
716 line2->setFrameShape(QFrame::HLine);
717 line2->setFrameShadow(QFrame::Sunken);
718 anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
720 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
721 anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
723 // Enforced vertices parameters
725 myEnfGroup = new QWidget();
726 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
728 myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
729 myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
730 myEnforcedTreeWidget->setSortingEnabled(true);
731 QStringList enforcedHeaders;
732 enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_X_COLUMN" )<< tr( "BLSURF_ENF_VER_Y_COLUMN" ) << tr( "BLSURF_ENF_VER_Z_COLUMN" ) ;
733 myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
734 myEnforcedTreeWidget->setAlternatingRowColors(true);
735 myEnforcedTreeWidget->setUniformRowHeights(true);
736 myEnforcedTreeWidget->setAnimated(true);
737 myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
738 myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
739 for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
740 myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
741 myEnforcedTreeWidget->resizeColumnToContents(column);
743 myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
744 myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
745 anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, 8, 1);
747 QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
748 anEnfLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
749 myXCoord = new QLineEdit(myEnfGroup);
750 myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
751 anEnfLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
753 QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
754 anEnfLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
755 myYCoord = new QLineEdit(myEnfGroup);
756 myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
757 anEnfLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
759 QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
760 anEnfLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
761 myZCoord = new QLineEdit(myEnfGroup);
762 myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
763 anEnfLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
765 addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
766 anEnfLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
768 QFrame *line = new QFrame(myEnfGroup);
769 line->setFrameShape(QFrame::HLine);
770 line->setFrameShadow(QFrame::Sunken);
771 anEnfLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
773 removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
774 anEnfLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
777 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
778 tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
779 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
780 tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
782 tab->setCurrentIndex( STD_TAB );
785 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
786 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
787 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
788 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
789 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
791 connect( addSurfaceButton, SIGNAL( clicked()), this, SLOT( onAddMapOnSurface() ) );
792 connect( addEdgeButton, SIGNAL( clicked()), this, SLOT( onAddMapOnEdge() ) );
793 connect( addPointButton, SIGNAL( clicked()), this, SLOT( onAddMapOnPoint() ) );
794 connect( removeButton, SIGNAL( clicked()), this, SLOT( onRemoveMap() ) );
795 connect( mySizeMapTable, SIGNAL( cellChanged ( int, int )), this, SLOT( onSetSizeMap(int,int ) ) );
797 connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
798 connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
799 connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
800 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertices() ) );
801 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
806 /** BLSURFPluginGUI_HypothesisCreator::update(item, column)
807 This method updates the tooltip of a modified item. The QLineEdit widgets content
808 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
810 void BLSURFPluginGUI_HypothesisCreator::update(QTreeWidgetItem* item, int column) {
811 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateVertexList");
812 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
814 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
815 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
816 QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
818 QTreeWidgetItem* parent = item->parent();
820 QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
821 QString toolTip = shapeName + QString(": ") + vertexName.toString();
822 toolTip += QString("(") + x.toString();
823 toolTip += QString(", ") + y.toString();
824 toolTip += QString(", ") + z.toString();
825 toolTip += QString(")");
826 item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
829 myXCoord->setText(x.toString());
830 myYCoord->setText(y.toString());
831 myZCoord->setText(z.toString());
835 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
836 This method synchronizes the QLineEdit widgets content with the coordinates
837 of the enforced vertex clicked in the tree widget.
839 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
840 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::synchronizeCoords");
841 QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
842 if (! items.isEmpty()) {
843 QTreeWidgetItem *item;
844 for (int i=0 ; i < items.size() ; i++) {
846 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
848 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
849 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
850 myXCoord->setText(x.toString());
851 myYCoord->setText(y.toString());
852 myZCoord->setText(z.toString());
859 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
860 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
862 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std::string shapeName, double x, double y, double z) {
864 QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(entry.c_str()),Qt::MatchExactly,ENF_VER_ENTRY_COLUMN);
865 QTreeWidgetItem* theItem;
866 if (theItemList.empty()) {
867 theItem = new QTreeWidgetItem();
868 theItem->setData(ENF_VER_ENTRY_COLUMN, Qt::EditRole, QVariant(entry.c_str()));
869 theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(shapeName.c_str()));
870 theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(entry.c_str()));
871 myEnforcedTreeWidget->addTopLevelItem(theItem);
874 theItem = theItemList[0];
877 // MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
878 bool okToCreate = true;
880 const int nbVert = theItem->childCount();
881 // MESSAGE("Number of child rows: " << nbVert);
883 double childValueX,childValueY,childValueZ;
884 QTreeWidgetItem* child;
885 for (int row = 0;row<nbVert;row++) {
886 child = theItem->child(row);
887 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
888 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
889 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
890 if ((childValueX == x) && (childValueY == y) && (childValueZ == z)) {
897 MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
899 QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
900 vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
904 while(indexRef != vertexIndex) {
905 indexRef = vertexIndex;
906 vertexName = QString("Vertex #%1").arg(vertexIndex);
907 for (int row = 0;row<nbVert;row++) {
908 QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
909 if (vertexName == name) {
915 vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, vertexName );
916 vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
917 vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
918 vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
919 QString toolTip = QString(shapeName.c_str())+QString(": ")+vertexName;
920 toolTip += QString(" (%1, ").arg(x);
921 toolTip += QString("%1, ").arg(y);
922 toolTip += QString("%1)").arg(z);
923 vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
924 theItem->setExpanded(true);
925 myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
928 MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " already exist: dont create again");
931 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
932 This method is called when a item is added into the enforced vertices tree widget
934 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
935 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
937 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
938 myEnforcedTreeWidget->resizeColumnToContents(column);
940 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
942 if ((myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty())) return;
944 double x = myXCoord->text().toDouble();
945 double y = myYCoord->text().toDouble();
946 double z = myZCoord->text().toDouble();
948 TopAbs_ShapeEnum shapeType;
949 string entry, shapeName;
950 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
951 LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
952 SALOME_ListIO ListSelectedObjects;
953 mySel->selectedObjects(ListSelectedObjects, NULL, false );
954 if (!ListSelectedObjects.IsEmpty()) {
955 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
956 for (; Object_It.More(); Object_It.Next()) {
957 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
958 entry = myGeomToolSelected->getEntryOfObject(anObject);
959 shapeName = anObject->getName();
960 shapeType = myGeomToolSelected->entryToShapeType(entry);
961 // MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
962 if (shapeType == TopAbs_FACE) {
963 addEnforcedVertex(entry, shapeName, x, y, z);
967 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
968 myEnforcedTreeWidget->resizeColumnToContents(column);
970 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
971 myPhysicalMesh->setCurrentIndex( SizeMap );
972 onPhysicalMeshChanged();
976 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
977 This method is called when a item is removed from the enforced vertices tree widget
979 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
980 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
981 QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
982 QList<QTreeWidgetItem *> selectedVertices;
983 QSet<QTreeWidgetItem *> selectedEntries;
984 QTreeWidgetItem* item;
986 foreach( item, selectedItems ) {
987 QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
988 if (! value.isNull())
989 selectedVertices.append(item);
991 selectedEntries.insert(item);
994 foreach(item,selectedVertices) {
995 QTreeWidgetItem* parent = item->parent();
996 // MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
997 parent->removeChild(item);
999 if (parent->childCount() == 0) {
1000 if (selectedEntries.contains(parent))
1001 selectedEntries.remove(parent);
1006 foreach(item,selectedEntries) {
1007 // MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1011 myEnforcedTreeWidget->selectionModel()->clearSelection();
1014 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1015 This method updates the GUI widgets with the hypothesis data
1017 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1019 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1020 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1022 BlsurfHypothesisData data;
1023 that->readParamsFromHypo( data );
1026 myName->setText( data.myName );
1027 QFontMetrics metrics( myName->font() );
1028 myName->setMinimumWidth( metrics.width( data.myName )+5 );
1030 myTopology->setCurrentIndex( data.myTopology );
1031 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1032 myPhySize->setText( data.myPhySize );
1033 #ifdef WITH_SIZE_BOUNDARIES
1034 myPhyMin->setText( data.myPhyMin );
1035 myPhyMax->setText( data.myPhyMax );
1036 myGeoMin->setText( data.myGeoMin );
1037 myGeoMax->setText( data.myGeoMax );
1039 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1040 myAngleMeshS->setValue( data.myAngleMeshS );
1041 myAngleMeshC->setValue( data.myAngleMeshC );
1042 myGradation->setValue( data.myGradation );
1043 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1044 myDecimesh->setChecked( data.myDecimesh );
1045 myVerbosity->setValue( data.myVerbosity );
1047 if ( myOptions.operator->() ) {
1048 // MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1049 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1050 QString option = that->myOptions[i].in();
1051 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1052 if ( name_value.count() > 1 ) {
1053 QString idStr = QString("%1").arg( i );
1054 int row = myOptionTable->rowCount();
1055 myOptionTable->setRowCount( row+1 );
1056 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1057 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1058 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1059 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1060 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1061 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1062 Qt::ItemIsEditable |
1063 Qt::ItemIsEnabled );
1067 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1070 // MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1071 QMapIterator<QString, QString> i(that->mySMPMap);
1072 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1073 while (i.hasNext()) {
1075 const QString entry = i.key();
1076 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1077 const QString sizeMap = i.value();
1078 int row = mySizeMapTable->rowCount();
1079 mySizeMapTable->setRowCount( row+1 );
1080 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
1081 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1082 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1083 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1084 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1085 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
1086 Qt::ItemIsEditable |
1087 Qt::ItemIsEnabled );
1090 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1091 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1093 // Enforced vertices
1094 // MESSAGE("retrieveParams(): data.enfVertMap.size() = " << data.enfVertMap.size());
1095 std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = data.enfVertMap.begin();
1096 for ( ; evmIt != data.enfVertMap.end() ; ++evmIt) {
1097 std::string entry = (*evmIt).first;
1098 std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1100 std::set<std::vector<double> > evs;
1101 std::set<std::vector<double> >::const_iterator evsIt;
1103 evs = (*evmIt).second;
1106 // MESSAGE("evs = (*evmIt)[entry]: FAIL");
1110 evsIt = evs.begin();
1111 for ( ; evsIt != evs.end() ; ++evsIt) {
1116 that->addEnforcedVertex(entry, shapeName, x, y, z);
1119 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1120 myEnforcedTreeWidget->resizeColumnToContents(column);
1123 that->onPhysicalMeshChanged();
1124 that->onGeometricMeshChanged();
1127 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1128 This method updates the hypothesis data with the GUI widgets content.
1130 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1132 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1134 BlsurfHypothesisData data;
1135 QString guiHyp = that->readParamsFromWidgets( data );
1136 that->storeParamsToHypo( data );
1141 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1142 Updates the hypothesis data from hypothesis values.
1144 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1146 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1147 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1148 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1150 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1151 h_data.myName = isCreation() && data ? hypName() : "";
1153 h_data.myTopology = (int) h->GetTopology();
1154 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
1155 h_data.myPhySize = QString::number( h->GetPhySize() );
1156 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
1157 h_data.myAngleMeshS = h->GetAngleMeshS();
1158 h_data.myAngleMeshC = h->GetAngleMeshC();
1159 h_data.myGradation = h->GetGradation();
1160 h_data.myAllowQuadrangles = h->GetQuadAllowed();
1161 h_data.myDecimesh = h->GetDecimesh();
1162 h_data.myVerbosity = h->GetVerbosity();
1164 #ifdef WITH_SIZE_BOUNDARIES
1165 double PhyMin = h->GetPhyMin();
1166 double PhyMax = h->GetPhyMax();
1167 double GeoMin = h->GetGeoMin();
1168 double GeoMax = h->GetGeoMax();
1170 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
1171 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
1172 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
1173 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
1176 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1177 that->myOptions = h->GetOptionValues();
1179 that->mySMPMap.clear();
1181 // classic size maps
1182 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1183 // MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1184 QString fullSizeMaps;
1185 QStringList fullSizeMapList;
1186 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1187 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1188 fullSizeMaps = mySizeMaps[i].in();
1189 // MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1190 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1191 if ( fullSizeMapList.count() > 1 ) {
1192 string fullSizeMap = fullSizeMapList[1].toStdString();
1193 int pos = fullSizeMap.find("return")+7;
1194 // MESSAGE("pos:" << pos);
1197 sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1202 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1203 // MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1204 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1205 // MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1211 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1212 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1214 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1215 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
1216 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1217 if ( fullCustomSizeMapList.count() > 1 ) {
1218 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1219 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1220 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1221 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1226 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1227 // MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1229 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1230 QString myAttractors = allMyAttractors[i].in();
1231 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1232 if ( myAttractorList.count() > 1 ) {
1233 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1234 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1235 // MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1236 // MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1240 // Enforced vertices
1241 BLSURFPlugin::TEnforcedVertexMap_var enforcedVertexMap = h->GetAllEnforcedVertices();
1242 // MESSAGE("enforcedVertexMap->length() = " << enforcedVertexMap->length());
1244 for ( int i = 0;i<enforcedVertexMap->length(); ++i ) {
1245 std::string entry = enforcedVertexMap[i].entry.in();
1246 // BLSURFPlugin::TEnforcedVertexList_var vertexList = enforcedVertexMap[i].vertexList;
1247 BLSURFPlugin::TEnforcedVertexList vertexList = enforcedVertexMap[i].vertexList;
1248 std::set<std::vector<double> > evs;
1249 for (int j=0 ; j<vertexList.length(); ++j) {
1250 double x = vertexList[j][0];
1251 double y = vertexList[j][1];
1252 double z = vertexList[j][2];
1253 std::vector<double> ev;
1258 // MESSAGE("New enf vertex for entry " << entry << ": " << x << ", " << y << ", " << z);
1260 h_data.enfVertMap[entry] = evs;
1261 if (evs.size() == 0) {
1262 // MESSAGE("No enf vertex for entry " << entry << ": key is erased");
1263 h_data.enfVertMap.erase(entry);
1270 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1271 Saves the hypothesis data to hypothesis values.
1273 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1275 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1276 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1277 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1283 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1285 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
1286 h->SetTopology( (int) h_data.myTopology );
1287 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
1288 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1289 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1290 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1291 if ( h->GetGradation() != h_data.myGradation )
1292 h->SetGradation( h_data.myGradation );
1293 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1294 h->SetQuadAllowed( h_data.myAllowQuadrangles );
1295 if ( h->GetDecimesh() != h_data.myDecimesh )
1296 h->SetDecimesh( h_data.myDecimesh );
1297 if ( h->GetVerbosity() != h_data.myVerbosity )
1298 h->SetVerbosity( h_data.myVerbosity );
1300 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
1301 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
1302 h->SetPhySize( h_data.myPhySize.toDouble() );
1304 if( (int) h_data.myGeometricMesh == UserDefined ) {
1305 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
1306 h->SetAngleMeshS( h_data.myAngleMeshS );
1307 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
1308 h->SetAngleMeshC( h_data.myAngleMeshC );
1310 #ifdef WITH_SIZE_BOUNDARIES
1311 if ( !isDouble( h_data.myPhyMin ))
1313 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
1314 h->SetPhyMin( h_data.myPhyMin.toDouble() );
1315 if ( !isDouble( h_data.myPhyMax ))
1317 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
1318 h->SetPhyMax( h_data.myPhyMax.toDouble() );
1319 if ( !isDouble( h_data.myGeoMin ))
1321 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
1322 h->SetGeoMin( h_data.myGeoMin.toDouble() );
1323 if ( !isDouble( h_data.myGeoMax ))
1325 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
1326 h->SetGeoMax( h_data.myGeoMax.toDouble() );
1329 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
1330 h->SetOptionValues( myOptions ); // is set in checkParams()
1332 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1333 QMapIterator<QString,QString> i(that->mySMPMap);
1334 // Iterate over each size map
1335 while (i.hasNext()) {
1337 const QString entry = i.key();
1338 const QString sizeMap = i.value();
1340 if (sizeMap == "__TO_DELETE__") {
1341 // MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1342 h->UnsetEntry(entry.toLatin1().constData());
1344 else if (sizeMap.startsWith("ATTRACTOR")) {
1345 // MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1346 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1348 else if (sizeMap.startsWith("def")) {
1349 // MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1350 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1353 QString fullSizeMap;
1354 fullSizeMap = QString("");
1355 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
1356 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1357 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
1358 fullSizeMap = QString("def f(t): return ") + sizeMap;
1359 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1360 fullSizeMap = QString("def f(): return ") + sizeMap;
1362 // MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1363 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1367 // Enforced vertices
1368 std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = h_data.enfVertMap.begin();
1369 for ( ; evmIt != h_data.enfVertMap.end() ; ++evmIt) {
1370 std::string entry = evmIt->first;
1371 std::set<std::vector<double> > evs;
1372 std::set<std::vector<double> >::const_iterator evsIt;
1374 BLSURFPlugin::TEnforcedVertexList_var hypVertexList;
1375 int hypNbVertex = 0;
1377 hypVertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1378 hypNbVertex = hypVertexList->length();
1382 evs = evmIt->second;
1383 evsIt = evs.begin();
1384 for ( ; evsIt != evs.end() ; ++evsIt) {
1388 // MESSAGE("SetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1389 h->SetEnforcedVertexEntry( entry.c_str(), x, y, z );
1391 // Remove old vertices
1392 if (hypNbVertex >0) {
1393 for (int i =0 ; i<hypNbVertex ; i++) {
1394 x = hypVertexList[i][0];
1395 y = hypVertexList[i][1];
1396 z = hypVertexList[i][2];
1397 std::vector<double> vertex;
1398 vertex.push_back(x);
1399 vertex.push_back(y);
1400 vertex.push_back(z);
1401 if (evs.find(vertex) == evs.end()) {
1402 // MESSAGE("UnsetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1403 h->UnsetEnforcedVertexEntry( entry.c_str(), x, y, z );
1409 catch(const SALOME::SALOME_Exception& ex)
1411 SalomeApp_Tools::QtCatchCorbaException(ex);
1417 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1418 Stores the widgets content to the hypothesis data.
1420 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1422 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1423 h_data.myName = myName ? myName->text() : "";
1424 h_data.myTopology = myTopology->currentIndex();
1425 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
1426 h_data.myPhySize = myPhySize->text();
1427 #ifdef WITH_SIZE_BOUNDARIES
1428 h_data.myPhyMin = myPhyMin->text();
1429 h_data.myPhyMax = myPhyMax->text();
1430 h_data.myGeoMin = myGeoMin->text();
1431 h_data.myGeoMax = myGeoMax->text();
1433 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
1434 h_data.myAngleMeshS = myAngleMeshS->value();
1435 h_data.myAngleMeshC = myAngleMeshC->value();
1436 h_data.myGradation = myGradation->value();
1437 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
1438 h_data.myDecimesh = myDecimesh->isChecked();
1439 h_data.myVerbosity = myVerbosity->value();
1442 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1443 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1444 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
1445 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1446 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
1447 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1448 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1449 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
1450 #ifdef WITH_SIZE_BOUNDARIES
1451 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
1452 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
1453 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
1454 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
1457 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1458 int row = 0, nbRows = myOptionTable->rowCount();
1459 for ( ; row < nbRows; ++row )
1461 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1462 if ( id >= 0 && id < myOptions->length() )
1464 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1465 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1466 if ( value.isNull() )
1468 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1470 guiHyp += name + " = " + value + "; ";
1475 row = 0, nbRows = mySizeMapTable->rowCount();
1476 for ( ; row < nbRows; ++row )
1478 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
1479 if ( that->mySMPMap.contains(entry) )
1480 guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1483 // Enforced vertices
1484 // h_data.enfVertMap
1486 int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1487 int nbEnforcedVertices = 0;
1488 // MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1489 for (int i=0 ; i<nbEnforcedShapes ; i++) {
1490 QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1492 std::string entry = shapeItem->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1493 nbEnforcedVertices = shapeItem->childCount();
1494 if (nbEnforcedVertices >0) {
1495 double childValueX,childValueY,childValueZ;
1496 QTreeWidgetItem* child;
1497 std::set<std::vector<double> > evs;
1498 for (row = 0;row<nbEnforcedVertices;row++) {
1499 child = shapeItem->child(row);
1500 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1501 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1502 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1503 std::vector<double> vertex;
1504 vertex.push_back(childValueX);
1505 vertex.push_back(childValueY);
1506 vertex.push_back(childValueZ);
1509 h_data.enfVertMap[entry] = evs;
1514 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
1518 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
1519 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
1520 bool isPhysicalUserDefined = (myPhysicalMesh->currentIndex() == PhysicalUserDefined);
1521 bool isSizeMap = (myPhysicalMesh->currentIndex() == SizeMap);
1522 bool isCustom = (isPhysicalUserDefined || isSizeMap) ;
1523 bool geomIsCustom = (myGeometricMesh->currentIndex() == UserDefined);
1525 myGradation->setEnabled(!isPhysicalUserDefined || geomIsCustom);
1526 myPhySize->setEnabled(isCustom);
1527 myPhyMax->setEnabled(isCustom);
1528 myPhyMin->setEnabled(isCustom);
1530 if ( !myGradation->isEnabled())
1531 myGradation->setValue( 1.1 );
1534 QString aPhySize = "";
1535 switch( myPhysicalMesh->currentIndex() ) {
1541 myPhySize->setText( aPhySize );
1542 if ( !isDouble( myPhyMin->text(), true ))
1543 myPhyMin->setText("");
1544 if ( !isDouble( myPhyMax->text(), true ))
1545 myPhyMax->setText("");
1546 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
1547 myGeometricMesh->setCurrentIndex( UserDefined );
1548 onGeometricMeshChanged();
1553 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
1554 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
1555 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
1556 bool phyIsSizemap = (myPhysicalMesh->currentIndex() == SizeMap);
1558 myAngleMeshS->setEnabled(isCustom);
1559 myAngleMeshC->setEnabled(isCustom);
1560 myGradation->setEnabled(isCustom || phyIsSizemap);
1561 myGeoMax->setEnabled(isCustom);
1562 myGeoMin->setEnabled(isCustom);
1564 if ( !myGradation->isEnabled())
1565 myGradation->setValue( 1.1 );
1569 switch( myGeometricMesh->currentIndex() ) {
1575 myAngleMeshS->setValue( aAngleMeshS );
1576 myAngleMeshC->setValue( aAngleMeshS );
1577 if ( !isDouble( myGeoMin->text(), true ))
1578 myGeoMin->setText("");
1579 if ( !isDouble( myGeoMax->text(), true ))
1580 myGeoMax->setText("");
1581 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
1582 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
1583 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
1584 onPhysicalMeshChanged();
1589 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
1591 QMenu* menu = (QMenu*)sender();
1592 // fill popup with option names
1594 if ( myOptions.operator->() ) {
1595 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1596 QString name_value = myOptions[i].in();
1597 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1598 menu->addAction( name );
1603 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1605 myOptionTable->setFocus();
1606 QMenu* menu = (QMenu*)( a->parent() );
1608 int idx = menu->actions().indexOf( a );
1609 QString idStr = QString("%1").arg( idx );
1610 QString option = myOptions[idx].in();
1611 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1613 // look for a row with optionName
1614 int row = 0, nbRows = myOptionTable->rowCount();
1615 for ( ; row < nbRows; ++row )
1616 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1618 // add a row if not found
1619 if ( row == nbRows ) {
1620 myOptionTable->setRowCount( row+1 );
1621 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1622 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1623 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1624 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1625 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1626 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1627 Qt::ItemIsEditable |
1628 Qt::ItemIsEnabled );
1629 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1631 myOptionTable->clearSelection();
1632 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1633 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1634 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1635 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1638 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1640 // clear option values and remember selected row
1641 QList<int> selectedRows;
1642 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1643 QTableWidgetItem* item;
1644 foreach( item, selected ) {
1645 int row = item->row();
1646 if ( !selectedRows.contains( row ) ) {
1647 selectedRows.append( row );
1648 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1649 if ( id >= 0 && id < myOptions->length() )
1650 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1653 qSort( selectedRows );
1654 QListIterator<int> it( selectedRows );
1656 while ( it.hasPrevious() )
1657 myOptionTable->removeRow( it.previous() );
1660 // **********************
1661 // *** BEGIN SIZE MAP ***
1662 // **********************
1665 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1667 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1668 QList<int> selectedRows;
1669 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1670 QTableWidgetItem* item;
1672 foreach( item, selected ) {
1674 if ( !selectedRows.contains( row ) )
1675 selectedRows.append( row );
1678 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1680 qSort( selectedRows );
1681 QListIterator<int> it( selectedRows );
1683 while ( it.hasPrevious() ) {
1684 row = it.previous();
1685 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1686 if (that->mySMPMap.contains(entry))
1687 that->mySMPMap[entry] = "__TO_DELETE__";
1688 if (that->mySMPShapeTypeMap.contains(entry))
1689 that->mySMPShapeTypeMap.remove(entry);
1690 mySizeMapTable->removeRow(row );
1692 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1693 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1696 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1698 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1699 if (col == SMP_SIZEMAP_COLUMN) {
1700 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1701 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1702 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1703 // MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1704 if (! that->mySMPShapeTypeMap.contains(entry))
1706 if (that->mySMPMap.contains(entry))
1707 if (that->mySMPMap[entry] == sizeMap)
1709 QColor* bgColor = new QColor("white");
1710 QColor* fgColor = new QColor("black");
1711 if (! sizeMap.isEmpty()) {
1712 that->mySMPMap[entry] = sizeMap;
1713 if (! sizeMapValidationFromRow(row)) {
1714 bgColor->setRgb(255,0,0);
1715 fgColor->setRgb(255,255,255);
1719 // MESSAGE("Size map empty: reverse to precedent value" );
1720 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1722 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1723 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1724 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1725 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1726 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1730 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1732 insertElementType(TopAbs_FACE);
1735 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1737 insertElementType(TopAbs_EDGE);
1740 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1742 insertElementType(TopAbs_VERTEX);
1745 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1747 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1749 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1750 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1752 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1754 TopAbs_ShapeEnum shapeType;
1755 string entry, shapeName;
1756 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1758 LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1760 SALOME_ListIO ListSelectedObjects;
1761 mySel->selectedObjects(ListSelectedObjects, NULL, false );
1762 if (!ListSelectedObjects.IsEmpty())
1764 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1765 for (; Object_It.More(); Object_It.Next())
1767 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1768 entry = myGeomToolSelected->getEntryOfObject(anObject);
1769 shapeName = anObject->getName();
1770 shapeType = myGeomToolSelected->entryToShapeType(entry);
1771 // MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
1772 if (shapeType == typeShapeAsked)
1774 mySizeMapTable->setFocus();
1776 shapeEntry = QString::fromStdString(entry);
1777 double phySize = h->GetPhySize();
1778 std::ostringstream oss;
1781 sizeMap = QString::fromStdString(oss.str());
1782 if (that->mySMPMap.contains(shapeEntry)) {
1783 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1784 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1788 that->mySMPMap[shapeEntry] = sizeMap;
1789 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1790 int row = mySizeMapTable->rowCount() ;
1791 mySizeMapTable->setRowCount( row+1 );
1792 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1793 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1794 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1795 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1796 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1797 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1798 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1799 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1800 mySizeMapTable->clearSelection();
1801 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1803 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1804 myPhysicalMesh->setCurrentIndex( SizeMap );
1805 onPhysicalMeshChanged();
1812 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1814 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
1815 int row = 0, nbRows = mySizeMapTable->rowCount();
1816 for ( ; row < nbRows; ++row )
1817 if (! sizeMapValidationFromRow(row))
1822 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1824 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
1825 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1826 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1827 mySizeMapTable->setFocus();
1831 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1833 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
1835 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1837 if (! that->mySMPMap.contains(myEntry)) {
1838 // MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
1841 if (! that->mySMPShapeTypeMap.contains(myEntry)) {
1842 // MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
1848 if (that->mySMPMap[myEntry].startsWith("def")) {
1849 // MESSAGE("custom function" );
1850 expr = that->mySMPMap[myEntry].toStdString();
1852 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1853 // MESSAGE("Attractor" );
1854 if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)\\)$")) != 1)) {
1855 // if ((that->mySMPMap[myEntry].count('(') != 1) or
1856 // (that->mySMPMap[myEntry].count(')') != 1) or
1857 // (that->mySMPMap[myEntry].count(';') != 4) or
1858 // (that->mySMPMap[myEntry].size() == 15)){
1860 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False)" );
1866 // case size map is empty
1867 if (that->mySMPMap[myEntry].isEmpty()) {
1869 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1873 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1874 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1875 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1876 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1877 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1878 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1881 //assert(Py_IsInitialized());
1882 if (! Py_IsInitialized())
1883 throw ("Erreur: Python interpreter is not initialized");
1884 PyGILState_STATE gstate;
1885 gstate = PyGILState_Ensure();
1887 PyObject * obj = NULL;
1888 PyObject* new_stderr = NULL;
1889 string err_description="";
1890 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1894 new_stderr=newPyStdOut(err_description);
1895 PySys_SetObject("stderr", new_stderr);
1897 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1898 Py_DECREF(new_stderr);
1900 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1901 PyGILState_Release(gstate);
1906 PyObject * func = NULL;
1907 func = PyObject_GetAttrString(main_mod, "f");
1911 new_stderr=newPyStdOut(err_description);
1912 PySys_SetObject("stderr", new_stderr);
1914 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1915 Py_DECREF(new_stderr);
1917 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1918 PyGILState_Release(gstate);
1922 PyGILState_Release(gstate);
1924 // MESSAGE("SizeMap expression "<<expr<<" is valid");
1930 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1931 int myRow = index->row();
1932 int myColumn = index->column();
1936 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1937 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1940 // myEditor->show();
1941 // myEditor->raise();
1942 // myEditor->activateWindow();
1945 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1946 // myEditor->exec();
1947 QString myFunction = myEditor->GetFunctionText();
1948 // FIN RECUPERATION FONCTION
1950 if (! myFunction.isEmpty()) {
1954 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1955 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1957 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1958 // item->text().toLatin1().constData());
1959 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1960 myFunction.toLatin1().constData());
1961 // FIN MAJ DE LA MAP
1966 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1968 return tr( "BLSURF_TITLE" );
1971 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1973 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1976 QString BLSURFPluginGUI_HypothesisCreator::type() const
1978 return tr( "BLSURF_HYPOTHESIS" );
1981 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1983 return "blsurf_hypo_page.html";
1986 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1989 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1991 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );