1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : BLSURFPluginGUI_HypothesisCreator.cxx
21 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
22 // & Aurelien ALLEAUME (DISTENE)
23 // Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
26 #include "BLSURFPluginGUI_HypothesisCreator.h"
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_Dialog.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Tools.h>
36 #include <SalomeApp_DoubleSpinBox.h>
42 #include <QVBoxLayout>
43 #include <QHBoxLayout>
44 #include <QGridLayout>
49 #include <QPushButton>
51 #include <QTableWidget>
52 #include <QHeaderView>
53 #include <QApplication>
54 #include <QRadioButton>
56 #include <QStandardItemModel>
57 #include <QStandardItem>
58 #include <QTreeWidget>
59 #include <QTreeWidgetItem>
60 #include <QModelIndexList>
62 #include <LightApp_SelectionMgr.h>
63 #include <SalomeApp_Application.h>
64 #include <SALOME_ListIO.hxx>
65 #include <SALOME_ListIteratorOfListIO.hxx>
67 #include <GEOM_Client.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <SMESH_Gen_i.hxx>
70 #include <boost/shared_ptr.hpp>
71 #include <structmember.h>
73 // #include <GeomSelectionTools.h>
74 #define WITH_SIZE_BOUNDARIES
100 OPTION_ID_COLUMN = 0,
104 SMP_ENTRY_COLUMN = 0,
112 // SMP_ATTRACTOR_BTN,
121 // Enforced vertices inputs
132 // Enforced vertices array columns
134 ENF_VER_NAME_COLUMN = 0,
135 ENF_VER_ENTRY_COLUMN,
143 /**************************************************
144 Begin initialization Python structures and objects
145 ***************************************************/
154 PyStdOut_dealloc(PyStdOut *self)
160 PyStdOut_write(PyStdOut *self, PyObject *args)
164 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
168 *(self->out)=*(self->out)+c;
174 static PyMethodDef PyStdOut_methods[] = {
175 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
176 PyDoc_STR("write(string) -> None")},
177 {NULL, NULL} /* sentinel */
180 static PyMemberDef PyStdOut_memberlist[] = {
181 {"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
182 "flag indicating that a space needs to be printed; used by print"},
183 {NULL} /* Sentinel */
186 static PyTypeObject PyStdOut_Type = {
187 /* The ob_type field must be initialized in the module init function
188 * to be portable to Windows without using C++. */
189 PyObject_HEAD_INIT(NULL)
192 sizeof(PyStdOut), /*tp_basicsize*/
195 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
202 0, /*tp_as_sequence*/
207 PyObject_GenericGetAttr, /*tp_getattro*/
208 /* softspace is writable: we must supply tp_setattro */
209 PyObject_GenericSetAttr, /* tp_setattro */
211 Py_TPFLAGS_DEFAULT, /*tp_flags*/
215 0, /*tp_richcompare*/
216 0, /*tp_weaklistoffset*/
219 PyStdOut_methods, /*tp_methods*/
220 PyStdOut_memberlist, /*tp_members*/
234 PyObject * newPyStdOut( std::string& out )
237 self = PyObject_New(PyStdOut, &PyStdOut_Type);
242 return (PyObject*)self;
245 /*************************************************
246 End initialization Python structures and objects
247 **************************************************/
250 class QDoubleValidator;
253 // BEGIN EnforcedTreeWidgetDelegate
256 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
257 : QItemDelegate(parent)
261 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
262 const QStyleOptionViewItem & option ,
263 const QModelIndex & index ) const
265 QLineEdit *editor = new QLineEdit(parent);
266 if (index.column() == ENF_VER_X_COLUMN || \
267 index.column() == ENF_VER_Y_COLUMN || \
268 index.column() == ENF_VER_Z_COLUMN)
269 editor->setValidator(new QDoubleValidator(parent));
274 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
275 const QModelIndex &index) const
277 QString value = index.model()->data(index, Qt::EditRole).toString();
279 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
280 lineEdit->setText(value);
283 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
284 const QModelIndex &index) const
286 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
288 if (index.column() == ENF_VER_X_COLUMN || \
289 index.column() == ENF_VER_Y_COLUMN || \
290 index.column() == ENF_VER_Z_COLUMN)
292 if (not vertexExists(model, index, lineEdit->text())) {
294 double value = lineEdit->text().toDouble(&ok);
296 model->setData(index, value, Qt::EditRole);
299 else if (index.column() == ENF_VER_NAME_COLUMN) {
300 QString value = lineEdit->text();
301 if (not vertexExists(model, index, value))
302 model->setData(index, value, Qt::EditRole);
303 // MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")");
307 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
308 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
310 editor->setGeometry(option.rect);
313 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
314 const QModelIndex &index, QString value) const
317 QModelIndex parent = index.parent();
318 int row = index.row();
319 int col = index.column();
321 if (parent.isValid()) {
322 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
324 if (col == ENF_VER_X_COLUMN) {
325 x = value.toDouble();
326 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
327 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
329 if (col == ENF_VER_Y_COLUMN) {
330 y = value.toDouble();
331 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
332 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
334 if (col == ENF_VER_Z_COLUMN) {
335 z = value.toDouble();
336 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
337 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
339 // MESSAGE("Checking for existing vertex " << x << ", " << y << "," << z);
340 int nbChildren = model->rowCount(parent);
341 for (int i = 0 ; i < nbChildren ; i++) {
343 double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
344 double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
345 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
346 // MESSAGE("Vertex: " << childX << ", " << childY << "," << childZ);
347 if ((childX == x) && (childY == y) && (childZ == z)) {
348 // MESSAGE("Found !");
355 else if (index.column() == ENF_VER_NAME_COLUMN) {
356 int nbChildren = model->rowCount(parent);
357 for (int i = 0 ; i < nbChildren ; i++) {
359 QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
360 if (childName == value) {
373 // END EnforcedTreeWidgetDelegate
378 * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
379 * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
382 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
383 : SMESHGUI_GenericHypothesisCreator( theHypType )
385 MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
386 this->mySMPMap.clear();
388 GeomToolSelected = NULL;
389 GeomToolSelected = getGeomSelectionTool();
391 aSel = GeomToolSelected->selectionMgr();
393 /* Initialize the Python interpreter */
394 if (! Py_IsInitialized())
395 throw ("Error: Python interpreter is not initialized");
396 PyGILState_STATE gstate;
397 gstate = PyGILState_Ensure();
400 main_mod = PyImport_AddModule("__main__");
403 main_dict = PyModule_GetDict(main_mod);
405 PyRun_SimpleString("from math import *");
406 PyGILState_Release(gstate);
410 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
415 * \brief {Get or create the geom selection tool for active study}
417 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
419 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool");
420 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
421 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
422 // MESSAGE("aStudy->StudyId(): " << aStudy->StudyId());
423 if (that->GeomToolSelected == NULL or that->GeomToolSelected->getMyStudy() != aStudy) {
424 // MESSAGE("GeomToolSelected is created");
425 that->GeomToolSelected = new GeomSelectionTools(aStudy);
428 // MESSAGE("GeomToolSelected already exists");
429 // MESSAGE("that->GeomToolSelected->getMyStudy()->StudyId(): " << that->GeomToolSelected->getMyStudy()->StudyId());
430 return that->GeomToolSelected;
434 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
435 QString str = theText.trimmed();
437 if ( !str.isEmpty() )
446 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
448 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
450 if ( !isDouble( myPhySize->text(), false )) {
451 if ( myPhySize->text().isEmpty() )
452 myPhySize->setText(tr("OBLIGATORY_VALUE"));
453 myPhySize->selectAll();
456 if ( !isDouble( myPhyMin->text(), true )) {
457 myPhyMin->selectAll();
460 if ( !isDouble( myPhyMax->text(), true )) {
461 myPhyMax->selectAll();
464 if ( !isDouble( myGeoMin->text(), true )) {
465 myGeoMin->selectAll();
468 if ( !isDouble( myGeoMin->text(), true )) {
469 myGeoMin->selectAll();
474 myOptionTable->setFocus();
475 QApplication::instance()->processEvents();
477 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
478 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
480 int row = 0, nbRows = myOptionTable->rowCount();
481 for ( ; row < nbRows; ++row )
483 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
484 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
485 if ( !value.isEmpty() ) {
487 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
489 catch ( const SALOME::SALOME_Exception& ex )
491 SUIT_MessageBox::critical( dlg(),
493 ex.details.text.in() );
498 h->SetOptionValues( myOptions ); // restore values
501 // SizeMap and attractors
504 mySizeMapTable->setFocus();
505 QApplication::instance()->processEvents();
507 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
508 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
510 int row = 0, nbRows = mySizeMapTable->rowCount();
511 for ( ; row < nbRows; ++row )
513 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
514 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
515 if ( !sizeMap.isEmpty() ) {
516 if (that->sizeMapValidationFromRow(row))
519 const char* e = entry.toLatin1().constData();
520 const char* s = that->mySMPMap[entry].toLatin1().constData();
521 h->SetSizeMapEntry( e, s );
523 catch ( const SALOME::SALOME_Exception& ex )
525 SUIT_MessageBox::critical( dlg(),
527 ex.details.text.in() );
544 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
546 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
547 QFrame* fr = new QFrame( 0 );
548 QVBoxLayout* lay = new QVBoxLayout( fr );
550 lay->setSpacing( 0 );
553 QTabWidget* tab = new QTabWidget( fr );
554 tab->setTabShape( QTabWidget::Rounded );
555 tab->setTabPosition( QTabWidget::North );
556 lay->addWidget( tab );
559 myStdGroup = new QWidget();
560 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
561 aStdLayout->setSpacing( 6 );
562 aStdLayout->setMargin( 11 );
567 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
568 myName = new QLineEdit( myStdGroup );
569 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
572 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
573 myGradation = new SalomeApp_DoubleSpinBox( myStdGroup );
574 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
575 myGradation->setMinimum( 1.1 );
576 myGradation->setMaximum( 2.5 );
577 myGradation->setSingleStep( 0.1 );
579 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
580 myPhysicalMesh = new QComboBox( myStdGroup );
581 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
582 QStringList physicalTypes;
583 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
584 myPhysicalMesh->addItems( physicalTypes );
586 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
587 myPhySize = new QLineEdit( myStdGroup );
588 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
590 #ifdef WITH_SIZE_BOUNDARIES
591 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
592 myPhyMin = new QLineEdit( myStdGroup );
593 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
595 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
596 myPhyMax = new QLineEdit( myStdGroup );
597 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
600 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
601 myGeometricMesh = new QComboBox( myStdGroup );
602 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
604 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
605 myGeometricMesh->addItems( types );
607 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
608 myAngleMeshS = new SalomeApp_DoubleSpinBox( myStdGroup );
609 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
610 myAngleMeshS->setMinimum( 0 );
611 myAngleMeshS->setMaximum( 16 );
612 myAngleMeshS->setSingleStep( 0.5 );
614 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
615 myAngleMeshC = new SalomeApp_DoubleSpinBox( myStdGroup );
616 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
617 myAngleMeshC->setMinimum( 0 );
618 myAngleMeshC->setMaximum( 16 );
619 myAngleMeshC->setSingleStep( 0.5 );
621 #ifdef WITH_SIZE_BOUNDARIES
622 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
623 myGeoMin = new QLineEdit( myStdGroup );
624 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
626 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
627 myGeoMax = new QLineEdit( myStdGroup );
628 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
631 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
632 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
634 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
635 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
637 // advanced parameters
638 myAdvGroup = new QWidget();
639 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
640 anAdvLayout->setSpacing( 6 );
641 anAdvLayout->setMargin( 11 );
643 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
644 myTopology = new QComboBox( myAdvGroup );
645 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
646 QStringList topologyTypes;
647 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
648 myTopology->addItems( topologyTypes );
650 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
651 myVerbosity = new QSpinBox( myAdvGroup );
652 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
653 myVerbosity->setMinimum( 0 );
654 myVerbosity->setMaximum( 100 );
655 myVerbosity->setSingleStep( 5 );
657 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
658 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
660 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
661 myOptionTable->setHorizontalHeaderLabels( headers );
662 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
663 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
664 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
665 myOptionTable->verticalHeader()->hide();
666 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
668 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
669 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
670 addBtn->setMenu( new QMenu() );
672 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
673 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
675 anAdvLayout->setRowStretch( 4, 5 );
676 anAdvLayout->setColumnStretch( 1, 5 );
678 // Size Maps parameters
680 mySmpGroup = new QWidget();
681 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
683 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
684 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
685 QStringList sizeMapHeaders;
686 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
687 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
688 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
689 mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
690 // mySizeMapTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
691 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
692 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
693 mySizeMapTable->setAlternatingRowColors(true);
694 mySizeMapTable->verticalHeader()->hide();
697 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
698 anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
700 QFrame *line = new QFrame(mySmpGroup);
701 line->setFrameShape(QFrame::HLine);
702 line->setFrameShadow(QFrame::Sunken);
703 anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
705 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
706 anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
708 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
709 anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
711 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
712 anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
714 QFrame *line2 = new QFrame(mySmpGroup);
715 line2->setFrameShape(QFrame::HLine);
716 line2->setFrameShadow(QFrame::Sunken);
717 anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
719 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
720 anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
722 // Enforced vertices parameters
724 myEnfGroup = new QWidget();
725 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
727 myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
728 myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
729 myEnforcedTreeWidget->setSortingEnabled(true);
730 QStringList enforcedHeaders;
731 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" ) ;
732 myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
733 myEnforcedTreeWidget->setAlternatingRowColors(true);
734 myEnforcedTreeWidget->setUniformRowHeights(true);
735 myEnforcedTreeWidget->setAnimated(true);
736 myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
737 myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
738 for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
739 myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
740 myEnforcedTreeWidget->resizeColumnToContents(column);
742 myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
743 myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
744 anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, 8, 1);
746 QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
747 anEnfLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1);
748 myXCoord = new QLineEdit(myEnfGroup);
749 myXCoord->setValidator(new QDoubleValidator(myEnfGroup));
750 anEnfLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1);
752 QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
753 anEnfLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1);
754 myYCoord = new QLineEdit(myEnfGroup);
755 myYCoord->setValidator(new QDoubleValidator(myEnfGroup));
756 anEnfLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1);
758 QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
759 anEnfLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1);
760 myZCoord = new QLineEdit(myEnfGroup);
761 myZCoord->setValidator(new QDoubleValidator(myEnfGroup));
762 anEnfLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1);
764 addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
765 anEnfLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2);
767 QFrame *line = new QFrame(myEnfGroup);
768 line->setFrameShape(QFrame::HLine);
769 line->setFrameShadow(QFrame::Sunken);
770 anEnfLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2);
772 removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
773 anEnfLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2);
776 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
777 tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
778 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
779 tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
781 tab->setCurrentIndex( STD_TAB );
784 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
785 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
786 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
787 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
788 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
790 connect( addSurfaceButton, SIGNAL( clicked()), this, SLOT( onAddMapOnSurface() ) );
791 connect( addEdgeButton, SIGNAL( clicked()), this, SLOT( onAddMapOnEdge() ) );
792 connect( addPointButton, SIGNAL( clicked()), this, SLOT( onAddMapOnPoint() ) );
793 connect( removeButton, SIGNAL( clicked()), this, SLOT( onRemoveMap() ) );
794 connect( mySizeMapTable, SIGNAL( cellChanged ( int, int )), this, SLOT( onSetSizeMap(int,int ) ) );
796 connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
797 connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
798 connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
799 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertices() ) );
800 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
805 /** BLSURFPluginGUI_HypothesisCreator::update(item, column)
806 This method updates the tooltip of a modified item. The QLineEdit widgets content
807 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
809 void BLSURFPluginGUI_HypothesisCreator::update(QTreeWidgetItem* item, int column) {
810 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateVertexList");
811 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
812 if (not x.isNull()) {
813 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
814 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
815 QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
817 QTreeWidgetItem* parent = item->parent();
819 QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
820 QString toolTip = shapeName + QString(": ") + vertexName.toString();
821 toolTip += QString("(") + x.toString();
822 toolTip += QString(", ") + y.toString();
823 toolTip += QString(", ") + z.toString();
824 toolTip += QString(")");
825 item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
828 myXCoord->setText(x.toString());
829 myYCoord->setText(y.toString());
830 myZCoord->setText(z.toString());
834 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
835 This method synchronizes the QLineEdit widgets content with the coordinates
836 of the enforced vertex clicked in the tree widget.
838 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
839 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::synchronizeCoords");
840 QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
841 if (not items.isEmpty()) {
842 QTreeWidgetItem *item;
843 for (int i=0 ; i < items.size() ; i++) {
845 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
846 if (not x.isNull()) {
847 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
848 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
849 myXCoord->setText(x.toString());
850 myYCoord->setText(y.toString());
851 myZCoord->setText(z.toString());
858 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
859 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
861 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std::string shapeName, double x, double y, double z) {
863 QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(entry.c_str()),Qt::MatchExactly,ENF_VER_ENTRY_COLUMN);
864 QTreeWidgetItem* theItem;
865 if (theItemList.empty()) {
866 theItem = new QTreeWidgetItem();
867 theItem->setData(ENF_VER_ENTRY_COLUMN, Qt::EditRole, QVariant(entry.c_str()));
868 theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(shapeName.c_str()));
869 theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(entry.c_str()));
870 myEnforcedTreeWidget->addTopLevelItem(theItem);
873 theItem = theItemList[0];
876 // MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
877 bool okToCreate = true;
879 const int nbVert = theItem->childCount();
880 // MESSAGE("Number of child rows: " << nbVert);
882 double childValueX,childValueY,childValueZ;
883 QTreeWidgetItem* child;
884 for (int row = 0;row<nbVert;row++) {
885 child = theItem->child(row);
886 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
887 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
888 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
889 if ((childValueX == x) and (childValueY == y) and (childValueZ == z)) {
896 MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
898 QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
899 vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
903 while(indexRef != vertexIndex) {
904 indexRef = vertexIndex;
905 vertexName = QString("Vertex #%1").arg(vertexIndex);
906 for (int row = 0;row<nbVert;row++) {
907 QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
908 if (vertexName == name) {
914 vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, vertexName );
915 vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
916 vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
917 vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
918 QString toolTip = QString(shapeName.c_str())+QString(": ")+vertexName;
919 toolTip += QString(" (%1, ").arg(x);
920 toolTip += QString("%1, ").arg(y);
921 toolTip += QString("%1)").arg(z);
922 vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
923 theItem->setExpanded(true);
924 myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
927 MESSAGE("In " << shapeName << " vertex with coords " << x << ", " << y << ", " << z<< " already exist: dont create again");
930 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
931 This method is called when a item is added into the enforced vertices tree widget
933 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
934 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
936 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
937 myEnforcedTreeWidget->resizeColumnToContents(column);
939 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
941 if ((myXCoord->text().isEmpty()) or (myYCoord->text().isEmpty()) or (myZCoord->text().isEmpty())) return;
943 double x = myXCoord->text().toDouble();
944 double y = myYCoord->text().toDouble();
945 double z = myZCoord->text().toDouble();
947 TopAbs_ShapeEnum shapeType;
948 string entry, shapeName;
949 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
950 LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
951 SALOME_ListIO ListSelectedObjects;
952 mySel->selectedObjects(ListSelectedObjects, NULL, false );
953 if (!ListSelectedObjects.IsEmpty()) {
954 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
955 for (; Object_It.More(); Object_It.Next()) {
956 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
957 entry = myGeomToolSelected->getEntryOfObject(anObject);
958 shapeName = anObject->getName();
959 shapeType = myGeomToolSelected->entryToShapeType(entry);
960 // MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
961 if (shapeType == TopAbs_FACE) {
962 addEnforcedVertex(entry, shapeName, x, y, z);
966 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
967 myEnforcedTreeWidget->resizeColumnToContents(column);
969 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
970 myPhysicalMesh->setCurrentIndex( SizeMap );
971 onPhysicalMeshChanged();
975 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
976 This method is called when a item is removed from the enforced vertices tree widget
978 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
979 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
980 QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
981 QList<QTreeWidgetItem *> selectedVertices;
982 QSet<QTreeWidgetItem *> selectedEntries;
983 QTreeWidgetItem* item;
985 foreach( item, selectedItems ) {
986 QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
987 if (not value.isNull())
988 selectedVertices.append(item);
990 selectedEntries.insert(item);
993 foreach(item,selectedVertices) {
994 QTreeWidgetItem* parent = item->parent();
995 // MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
996 parent->removeChild(item);
998 if (parent->childCount() == 0) {
999 if (selectedEntries.contains(parent))
1000 selectedEntries.remove(parent);
1005 foreach(item,selectedEntries) {
1006 // MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1010 myEnforcedTreeWidget->selectionModel()->clearSelection();
1013 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1014 This method updates the GUI widgets with the hypothesis data
1016 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1018 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1019 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1021 BlsurfHypothesisData data;
1022 that->readParamsFromHypo( data );
1025 myName->setText( data.myName );
1026 QFontMetrics metrics( myName->font() );
1027 myName->setMinimumWidth( metrics.width( data.myName )+5 );
1029 myTopology->setCurrentIndex( data.myTopology );
1030 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1031 myPhySize->setText( data.myPhySize );
1032 #ifdef WITH_SIZE_BOUNDARIES
1033 myPhyMin->setText( data.myPhyMin );
1034 myPhyMax->setText( data.myPhyMax );
1035 myGeoMin->setText( data.myGeoMin );
1036 myGeoMax->setText( data.myGeoMax );
1038 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1039 myAngleMeshS->setValue( data.myAngleMeshS );
1040 myAngleMeshC->setValue( data.myAngleMeshC );
1041 myGradation->setValue( data.myGradation );
1042 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1043 myDecimesh->setChecked( data.myDecimesh );
1044 myVerbosity->setValue( data.myVerbosity );
1046 if ( myOptions.operator->() ) {
1047 // MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1048 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1049 QString option = that->myOptions[i].in();
1050 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1051 if ( name_value.count() > 1 ) {
1052 QString idStr = QString("%1").arg( i );
1053 int row = myOptionTable->rowCount();
1054 myOptionTable->setRowCount( row+1 );
1055 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1056 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1057 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1058 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1059 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1060 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1061 Qt::ItemIsEditable |
1062 Qt::ItemIsEnabled );
1066 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1069 // MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1070 QMapIterator<QString, QString> i(that->mySMPMap);
1071 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1072 while (i.hasNext()) {
1074 const QString entry = i.key();
1075 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1076 const QString sizeMap = i.value();
1077 int row = mySizeMapTable->rowCount();
1078 mySizeMapTable->setRowCount( row+1 );
1079 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
1080 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1081 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1082 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1083 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1084 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
1085 Qt::ItemIsEditable |
1086 Qt::ItemIsEnabled );
1089 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1090 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1092 // Enforced vertices
1093 // MESSAGE("retrieveParams(): data.enfVertMap.size() = " << data.enfVertMap.size());
1094 std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = data.enfVertMap.begin();
1095 for ( ; evmIt != data.enfVertMap.end() ; ++evmIt) {
1096 std::string entry = (*evmIt).first;
1097 std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1099 std::set<std::vector<double> > evs;
1100 std::set<std::vector<double> >::const_iterator evsIt;
1102 evs = (*evmIt).second;
1105 // MESSAGE("evs = (*evmIt)[entry]: FAIL");
1109 evsIt = evs.begin();
1110 for ( ; evsIt != evs.end() ; ++evsIt) {
1115 that->addEnforcedVertex(entry, shapeName, x, y, z);
1118 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1119 myEnforcedTreeWidget->resizeColumnToContents(column);
1122 that->onPhysicalMeshChanged();
1123 that->onGeometricMeshChanged();
1126 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1127 This method updates the hypothesis data with the GUI widgets content.
1129 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1131 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1133 BlsurfHypothesisData data;
1134 QString guiHyp = that->readParamsFromWidgets( data );
1135 that->storeParamsToHypo( data );
1140 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1141 Updates the hypothesis data from hypothesis values.
1143 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1145 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1146 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1147 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1149 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1150 h_data.myName = isCreation() && data ? hypName() : "";
1152 h_data.myTopology = (int) h->GetTopology();
1153 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
1154 h_data.myPhySize = QString::number( h->GetPhySize() );
1155 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
1156 h_data.myAngleMeshS = h->GetAngleMeshS();
1157 h_data.myAngleMeshC = h->GetAngleMeshC();
1158 h_data.myGradation = h->GetGradation();
1159 h_data.myAllowQuadrangles = h->GetQuadAllowed();
1160 h_data.myDecimesh = h->GetDecimesh();
1161 h_data.myVerbosity = h->GetVerbosity();
1163 #ifdef WITH_SIZE_BOUNDARIES
1164 double PhyMin = h->GetPhyMin();
1165 double PhyMax = h->GetPhyMax();
1166 double GeoMin = h->GetGeoMin();
1167 double GeoMax = h->GetGeoMax();
1169 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
1170 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
1171 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
1172 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
1175 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1176 that->myOptions = h->GetOptionValues();
1178 that->mySMPMap.clear();
1180 // classic size maps
1181 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1182 // MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1183 QString fullSizeMaps;
1184 QStringList fullSizeMapList;
1185 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1186 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1187 fullSizeMaps = mySizeMaps[i].in();
1188 // MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1189 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1190 if ( fullSizeMapList.count() > 1 ) {
1191 string fullSizeMap = fullSizeMapList[1].toStdString();
1192 int pos = fullSizeMap.find("return")+7;
1193 // MESSAGE("pos:" << pos);
1196 sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1201 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1202 // MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1203 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1204 // MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1210 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1211 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1213 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1214 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
1215 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1216 if ( fullCustomSizeMapList.count() > 1 ) {
1217 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1218 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1219 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1220 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1225 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1226 // MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1228 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1229 QString myAttractors = allMyAttractors[i].in();
1230 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1231 if ( myAttractorList.count() > 1 ) {
1232 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1233 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1234 // MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1235 // MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1239 // Enforced vertices
1240 BLSURFPlugin::TEnforcedVertexMap_var enforcedVertexMap = h->GetAllEnforcedVertices();
1241 // MESSAGE("enforcedVertexMap->length() = " << enforcedVertexMap->length());
1243 for ( int i = 0;i<enforcedVertexMap->length(); ++i ) {
1244 std::string entry = enforcedVertexMap[i].entry.in();
1245 // BLSURFPlugin::TEnforcedVertexList_var vertexList = enforcedVertexMap[i].vertexList;
1246 BLSURFPlugin::TEnforcedVertexList vertexList = enforcedVertexMap[i].vertexList;
1247 std::set<std::vector<double> > evs;
1248 for (int j=0 ; j<vertexList.length(); ++j) {
1249 double x = vertexList[j][0];
1250 double y = vertexList[j][1];
1251 double z = vertexList[j][2];
1252 std::vector<double> ev;
1257 // MESSAGE("New enf vertex for entry " << entry << ": " << x << ", " << y << ", " << z);
1259 h_data.enfVertMap[entry] = evs;
1260 if (evs.size() == 0) {
1261 // MESSAGE("No enf vertex for entry " << entry << ": key is erased");
1262 h_data.enfVertMap.erase(entry);
1269 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1270 Saves the hypothesis data to hypothesis values.
1272 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1274 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1275 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1276 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1282 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1284 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
1285 h->SetTopology( (int) h_data.myTopology );
1286 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
1287 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1288 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1289 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1290 if ( h->GetGradation() != h_data.myGradation )
1291 h->SetGradation( h_data.myGradation );
1292 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1293 h->SetQuadAllowed( h_data.myAllowQuadrangles );
1294 if ( h->GetDecimesh() != h_data.myDecimesh )
1295 h->SetDecimesh( h_data.myDecimesh );
1296 if ( h->GetVerbosity() != h_data.myVerbosity )
1297 h->SetVerbosity( h_data.myVerbosity );
1299 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
1300 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
1301 h->SetPhySize( h_data.myPhySize.toDouble() );
1303 if( (int) h_data.myGeometricMesh == UserDefined ) {
1304 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
1305 h->SetAngleMeshS( h_data.myAngleMeshS );
1306 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
1307 h->SetAngleMeshC( h_data.myAngleMeshC );
1309 #ifdef WITH_SIZE_BOUNDARIES
1310 if ( !isDouble( h_data.myPhyMin ))
1312 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
1313 h->SetPhyMin( h_data.myPhyMin.toDouble() );
1314 if ( !isDouble( h_data.myPhyMax ))
1316 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
1317 h->SetPhyMax( h_data.myPhyMax.toDouble() );
1318 if ( !isDouble( h_data.myGeoMin ))
1320 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
1321 h->SetGeoMin( h_data.myGeoMin.toDouble() );
1322 if ( !isDouble( h_data.myGeoMax ))
1324 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
1325 h->SetGeoMax( h_data.myGeoMax.toDouble() );
1328 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
1329 h->SetOptionValues( myOptions ); // is set in checkParams()
1331 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1332 QMapIterator<QString,QString> i(that->mySMPMap);
1333 // Iterate over each size map
1334 while (i.hasNext()) {
1336 const QString entry = i.key();
1337 const QString sizeMap = i.value();
1339 if (sizeMap == "__TO_DELETE__") {
1340 // MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1341 h->UnsetEntry(entry.toLatin1().constData());
1343 else if (sizeMap.startsWith("ATTRACTOR")) {
1344 // MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1345 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1347 else if (sizeMap.startsWith("def")) {
1348 // MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1349 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1352 QString fullSizeMap;
1353 fullSizeMap = QString("");
1354 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
1355 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1356 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
1357 fullSizeMap = QString("def f(t): return ") + sizeMap;
1358 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1359 fullSizeMap = QString("def f(): return ") + sizeMap;
1361 // MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1362 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1366 // Enforced vertices
1367 std::map<std::string, std::set<std::vector<double> > >::const_iterator evmIt = h_data.enfVertMap.begin();
1368 for ( ; evmIt != h_data.enfVertMap.end() ; ++evmIt) {
1369 std::string entry = evmIt->first;
1370 std::set<std::vector<double> > evs;
1371 std::set<std::vector<double> >::const_iterator evsIt;
1373 BLSURFPlugin::TEnforcedVertexList_var hypVertexList;
1374 int hypNbVertex = 0;
1376 hypVertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1377 hypNbVertex = hypVertexList->length();
1381 evs = evmIt->second;
1382 evsIt = evs.begin();
1383 for ( ; evsIt != evs.end() ; ++evsIt) {
1387 // MESSAGE("SetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1388 h->SetEnforcedVertexEntry( entry.c_str(), x, y, z );
1390 // Remove old vertices
1391 if (hypNbVertex >0) {
1392 for (int i =0 ; i<hypNbVertex ; i++) {
1393 x = hypVertexList[i][0];
1394 y = hypVertexList[i][1];
1395 z = hypVertexList[i][2];
1396 std::vector<double> vertex;
1397 vertex.push_back(x);
1398 vertex.push_back(y);
1399 vertex.push_back(z);
1400 if (evs.find(vertex) == evs.end()) {
1401 // MESSAGE("UnsetEnforcedVertexEntry("<<entry<<", "<<x<<", "<<y<<", "<<z<<")");
1402 h->UnsetEnforcedVertexEntry( entry.c_str(), x, y, z );
1408 catch(const SALOME::SALOME_Exception& ex)
1410 SalomeApp_Tools::QtCatchCorbaException(ex);
1416 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1417 Stores the widgets content to the hypothesis data.
1419 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1421 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1422 h_data.myName = myName ? myName->text() : "";
1423 h_data.myTopology = myTopology->currentIndex();
1424 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
1425 h_data.myPhySize = myPhySize->text();
1426 #ifdef WITH_SIZE_BOUNDARIES
1427 h_data.myPhyMin = myPhyMin->text();
1428 h_data.myPhyMax = myPhyMax->text();
1429 h_data.myGeoMin = myGeoMin->text();
1430 h_data.myGeoMax = myGeoMax->text();
1432 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
1433 h_data.myAngleMeshS = myAngleMeshS->value();
1434 h_data.myAngleMeshC = myAngleMeshC->value();
1435 h_data.myGradation = myGradation->value();
1436 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
1437 h_data.myDecimesh = myDecimesh->isChecked();
1438 h_data.myVerbosity = myVerbosity->value();
1441 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1442 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1443 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
1444 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1445 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
1446 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1447 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1448 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
1449 #ifdef WITH_SIZE_BOUNDARIES
1450 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
1451 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
1452 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
1453 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
1456 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1457 int row = 0, nbRows = myOptionTable->rowCount();
1458 for ( ; row < nbRows; ++row )
1460 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1461 if ( id >= 0 && id < myOptions->length() )
1463 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1464 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1465 if ( value.isNull() )
1467 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1469 guiHyp += name + " = " + value + "; ";
1474 row = 0, nbRows = mySizeMapTable->rowCount();
1475 for ( ; row < nbRows; ++row )
1477 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
1478 if ( that->mySMPMap.contains(entry) )
1479 guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1482 // Enforced vertices
1483 // h_data.enfVertMap
1485 int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1486 int nbEnforcedVertices = 0;
1487 // MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1488 for (int i=0 ; i<nbEnforcedShapes ; i++) {
1489 QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1491 std::string entry = shapeItem->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1492 nbEnforcedVertices = shapeItem->childCount();
1493 if (nbEnforcedVertices >0) {
1494 double childValueX,childValueY,childValueZ;
1495 QTreeWidgetItem* child;
1496 std::set<std::vector<double> > evs;
1497 for (row = 0;row<nbEnforcedVertices;row++) {
1498 child = shapeItem->child(row);
1499 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1500 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1501 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1502 std::vector<double> vertex;
1503 vertex.push_back(childValueX);
1504 vertex.push_back(childValueY);
1505 vertex.push_back(childValueZ);
1508 h_data.enfVertMap[entry] = evs;
1513 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
1517 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
1518 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
1519 bool isPhysicalUserDefined = (myPhysicalMesh->currentIndex() == PhysicalUserDefined);
1520 bool isSizeMap = (myPhysicalMesh->currentIndex() == SizeMap);
1521 bool isCustom = (isPhysicalUserDefined || isSizeMap) ;
1522 bool geomIsCustom = (myGeometricMesh->currentIndex() == UserDefined);
1524 myGradation->setEnabled(not isPhysicalUserDefined || geomIsCustom);
1525 myPhySize->setEnabled(isCustom);
1526 myPhyMax->setEnabled(isCustom);
1527 myPhyMin->setEnabled(isCustom);
1531 switch( myPhysicalMesh->currentIndex() ) {
1537 myGradation->setValue( gradation );
1541 QString aPhySize = "";
1542 switch( myPhysicalMesh->currentIndex() ) {
1548 myPhySize->setText( aPhySize );
1549 if ( !isDouble( myPhyMin->text(), true ))
1550 myPhyMin->setText("");
1551 if ( !isDouble( myPhyMax->text(), true ))
1552 myPhyMax->setText("");
1553 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
1554 myGeometricMesh->setCurrentIndex( UserDefined );
1555 onGeometricMeshChanged();
1560 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
1561 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
1562 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
1563 bool phyIsSizemap = (myPhysicalMesh->currentIndex() == SizeMap);
1565 myAngleMeshS->setEnabled(isCustom);
1566 myAngleMeshC->setEnabled(isCustom);
1567 myGradation->setEnabled(isCustom || phyIsSizemap);
1568 myGeoMax->setEnabled(isCustom);
1569 myGeoMin->setEnabled(isCustom);
1573 switch( myGeometricMesh->currentIndex() ) {
1579 myAngleMeshS->setValue( aAngleMeshS );
1580 myAngleMeshC->setValue( aAngleMeshS );
1581 if ( !isDouble( myGeoMin->text(), true ))
1582 myGeoMin->setText("");
1583 if ( !isDouble( myGeoMax->text(), true ))
1584 myGeoMax->setText("");
1585 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
1586 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
1587 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
1588 onPhysicalMeshChanged();
1593 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
1595 QMenu* menu = (QMenu*)sender();
1596 // fill popup with option names
1598 if ( myOptions.operator->() ) {
1599 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1600 QString name_value = myOptions[i].in();
1601 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1602 menu->addAction( name );
1607 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1609 myOptionTable->setFocus();
1610 QMenu* menu = (QMenu*)( a->parent() );
1612 int idx = menu->actions().indexOf( a );
1613 QString idStr = QString("%1").arg( idx );
1614 QString option = myOptions[idx].in();
1615 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1617 // look for a row with optionName
1618 int row = 0, nbRows = myOptionTable->rowCount();
1619 for ( ; row < nbRows; ++row )
1620 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1622 // add a row if not found
1623 if ( row == nbRows ) {
1624 myOptionTable->setRowCount( row+1 );
1625 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1626 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1627 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1628 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1629 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1630 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1631 Qt::ItemIsEditable |
1632 Qt::ItemIsEnabled );
1633 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1635 myOptionTable->clearSelection();
1636 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1637 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1638 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1639 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1642 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1644 // clear option values and remember selected row
1645 QList<int> selectedRows;
1646 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1647 QTableWidgetItem* item;
1648 foreach( item, selected ) {
1649 int row = item->row();
1650 if ( !selectedRows.contains( row ) ) {
1651 selectedRows.append( row );
1652 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1653 if ( id >= 0 && id < myOptions->length() )
1654 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1657 qSort( selectedRows );
1658 QListIterator<int> it( selectedRows );
1660 while ( it.hasPrevious() )
1661 myOptionTable->removeRow( it.previous() );
1664 // **********************
1665 // *** BEGIN SIZE MAP ***
1666 // **********************
1669 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1671 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1672 QList<int> selectedRows;
1673 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1674 QTableWidgetItem* item;
1676 foreach( item, selected ) {
1678 if ( !selectedRows.contains( row ) )
1679 selectedRows.append( row );
1682 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1684 qSort( selectedRows );
1685 QListIterator<int> it( selectedRows );
1687 while ( it.hasPrevious() ) {
1688 row = it.previous();
1689 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1690 if (that->mySMPMap.contains(entry))
1691 that->mySMPMap[entry] = "__TO_DELETE__";
1692 if (that->mySMPShapeTypeMap.contains(entry))
1693 that->mySMPShapeTypeMap.remove(entry);
1694 mySizeMapTable->removeRow(row );
1696 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1697 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1700 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1702 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1703 if (col == SMP_SIZEMAP_COLUMN) {
1704 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1705 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1706 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1707 // MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1708 if (not that->mySMPShapeTypeMap.contains(entry))
1710 if (that->mySMPMap.contains(entry))
1711 if (that->mySMPMap[entry] == sizeMap)
1713 QColor* bgColor = new QColor("white");
1714 QColor* fgColor = new QColor("black");
1715 if (! sizeMap.isEmpty()) {
1716 that->mySMPMap[entry] = sizeMap;
1717 if (! sizeMapValidationFromRow(row)) {
1718 bgColor->setRgb(255,0,0);
1719 fgColor->setRgb(255,255,255);
1723 // MESSAGE("Size map empty: reverse to precedent value" );
1724 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1726 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1727 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1728 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1729 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1730 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1734 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1736 insertElementType(TopAbs_FACE);
1739 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1741 insertElementType(TopAbs_EDGE);
1744 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1746 insertElementType(TopAbs_VERTEX);
1749 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1751 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1753 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1754 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1756 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1758 TopAbs_ShapeEnum shapeType;
1759 string entry, shapeName;
1760 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1762 LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1764 SALOME_ListIO ListSelectedObjects;
1765 mySel->selectedObjects(ListSelectedObjects, NULL, false );
1766 if (!ListSelectedObjects.IsEmpty())
1768 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1769 for (; Object_It.More(); Object_It.Next())
1771 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1772 entry = myGeomToolSelected->getEntryOfObject(anObject);
1773 shapeName = anObject->getName();
1774 shapeType = myGeomToolSelected->entryToShapeType(entry);
1775 // MESSAGE("Object Name = " << shapeName << "& Type is " << anObject->getComponentDataType() << " & ShapeType is " << shapeType);
1776 if (shapeType == typeShapeAsked)
1778 mySizeMapTable->setFocus();
1780 shapeEntry = QString::fromStdString(entry);
1781 double phySize = h->GetPhySize();
1782 std::ostringstream oss;
1785 sizeMap = QString::fromStdString(oss.str());
1786 if (that->mySMPMap.contains(shapeEntry)) {
1787 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1788 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1792 that->mySMPMap[shapeEntry] = sizeMap;
1793 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1794 int row = mySizeMapTable->rowCount() ;
1795 mySizeMapTable->setRowCount( row+1 );
1796 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1797 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1798 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1799 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1800 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1801 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1802 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1803 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1804 mySizeMapTable->clearSelection();
1805 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1807 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1808 myPhysicalMesh->setCurrentIndex( SizeMap );
1809 onPhysicalMeshChanged();
1816 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1818 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
1819 int row = 0, nbRows = mySizeMapTable->rowCount();
1820 for ( ; row < nbRows; ++row )
1821 if (! sizeMapValidationFromRow(row))
1826 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1828 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
1829 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1830 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1831 mySizeMapTable->setFocus();
1835 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1837 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
1839 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1841 if (not that->mySMPMap.contains(myEntry)) {
1842 // MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
1845 if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1846 // MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
1852 if (that->mySMPMap[myEntry].startsWith("def")) {
1853 // MESSAGE("custom function" );
1854 expr = that->mySMPMap[myEntry].toStdString();
1856 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1857 // MESSAGE("Attractor" );
1858 if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)\\)$")) != 1)) {
1859 // if ((that->mySMPMap[myEntry].count('(') != 1) or
1860 // (that->mySMPMap[myEntry].count(')') != 1) or
1861 // (that->mySMPMap[myEntry].count(';') != 4) or
1862 // (that->mySMPMap[myEntry].size() == 15)){
1864 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False)" );
1870 // case size map is empty
1871 if (that->mySMPMap[myEntry].isEmpty()) {
1873 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1877 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1878 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1879 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1880 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1881 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1882 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1885 //assert(Py_IsInitialized());
1886 if (! Py_IsInitialized())
1887 throw ("Erreur: Python interpreter is not initialized");
1888 PyGILState_STATE gstate;
1889 gstate = PyGILState_Ensure();
1891 PyObject * obj = NULL;
1892 PyObject* new_stderr = NULL;
1893 string err_description="";
1894 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1898 new_stderr=newPyStdOut(err_description);
1899 PySys_SetObject("stderr", new_stderr);
1901 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1902 Py_DECREF(new_stderr);
1904 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1905 PyGILState_Release(gstate);
1910 PyObject * func = NULL;
1911 func = PyObject_GetAttrString(main_mod, "f");
1915 new_stderr=newPyStdOut(err_description);
1916 PySys_SetObject("stderr", new_stderr);
1918 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1919 Py_DECREF(new_stderr);
1921 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1922 PyGILState_Release(gstate);
1926 PyGILState_Release(gstate);
1928 // MESSAGE("SizeMap expression "<<expr<<" is valid");
1934 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1935 int myRow = index->row();
1936 int myColumn = index->column();
1940 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1941 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1944 // myEditor->show();
1945 // myEditor->raise();
1946 // myEditor->activateWindow();
1949 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1950 // myEditor->exec();
1951 QString myFunction = myEditor->GetFunctionText();
1952 // FIN RECUPERATION FONCTION
1954 if (! myFunction.isEmpty()) {
1958 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1959 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1961 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1962 // item->text().toLatin1().constData());
1963 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1964 myFunction.toLatin1().constData());
1965 // FIN MAJ DE LA MAP
1970 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1972 return tr( "BLSURF_TITLE" );
1975 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1977 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1980 QString BLSURFPluginGUI_HypothesisCreator::type() const
1982 return tr( "BLSURF_HYPOTHESIS" );
1985 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1987 return "blsurf_hypo_page.html";
1990 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1993 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1995 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );