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 <QtxDoubleSpinBox.h>
42 #include <QVBoxLayout>
43 #include <QGridLayout>
48 #include <QPushButton>
50 #include <QTableWidget>
51 #include <QHeaderView>
52 #include <QApplication>
53 #include <QRadioButton>
54 #include <QStandardItemModel>
55 #include <QStandardItem>
57 #include <LightApp_SelectionMgr.h>
58 #include <SalomeApp_Application.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
62 #include <GEOM_Client.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <SMESH_Gen_i.hxx>
65 #include <boost/shared_ptr.hpp>
66 #include <structmember.h>
68 // #include <GeomSelectionTools.h>
69 #define WITH_SIZE_BOUNDARIES
106 // SMP_ATTRACTOR_BTN,
122 PyStdOut_dealloc(PyStdOut *self)
128 PyStdOut_write(PyStdOut *self, PyObject *args)
132 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
136 *(self->out)=*(self->out)+c;
142 static PyMethodDef PyStdOut_methods[] = {
143 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
144 PyDoc_STR("write(string) -> None")},
145 {NULL, NULL} /* sentinel */
148 static PyMemberDef PyStdOut_memberlist[] = {
149 {"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
150 "flag indicating that a space needs to be printed; used by print"},
151 {NULL} /* Sentinel */
154 static PyTypeObject PyStdOut_Type = {
155 /* The ob_type field must be initialized in the module init function
156 * to be portable to Windows without using C++. */
157 PyObject_HEAD_INIT(NULL)
160 sizeof(PyStdOut), /*tp_basicsize*/
163 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
170 0, /*tp_as_sequence*/
175 PyObject_GenericGetAttr, /*tp_getattro*/
176 /* softspace is writable: we must supply tp_setattro */
177 PyObject_GenericSetAttr, /* tp_setattro */
179 Py_TPFLAGS_DEFAULT, /*tp_flags*/
183 0, /*tp_richcompare*/
184 0, /*tp_weaklistoffset*/
187 PyStdOut_methods, /*tp_methods*/
188 PyStdOut_memberlist, /*tp_members*/
202 PyObject * newPyStdOut( std::string& out )
205 self = PyObject_New(PyStdOut, &PyStdOut_Type);
210 return (PyObject*)self;
214 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
215 : SMESHGUI_GenericHypothesisCreator( theHypType )
217 cout << "BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator" << endl;
218 this->mySMPMap.clear();
220 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
221 GeomToolSelected = new GeomSelectionTools(aStudy);
223 aSel = GeomToolSelected->selectionMgr();
225 /* Initialize the Python interpreter */
226 //assert(Py_IsInitialized());
227 if (not Py_IsInitialized())
228 throw ("Erreur: Python interpreter is not initialized");
229 PyGILState_STATE gstate;
230 gstate = PyGILState_Ensure();
233 main_mod = PyImport_AddModule("__main__");
236 main_dict = PyModule_GetDict(main_mod);
238 PyRun_SimpleString("from math import *");
239 PyGILState_Release(gstate);
243 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
247 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
249 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
250 if (that->GeomToolSelected == NULL) {
251 cout << "GeomToolSelected is created" << endl;
252 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
253 that->GeomToolSelected = new GeomSelectionTools(aStudy);
255 return that->GeomToolSelected;
259 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
260 QString str = theText.trimmed();
262 if ( !str.isEmpty() )
270 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
272 cout << "BLSURFPluginGUI_HypothesisCreator::checkParams" << endl;
274 if ( !isDouble( myPhySize->text(), false )) {
275 if ( myPhySize->text().isEmpty() )
276 myPhySize->setText(tr("OBLIGATORY_VALUE"));
277 myPhySize->selectAll();
280 if ( !isDouble( myPhyMin->text(), true )) {
281 myPhyMin->selectAll();
284 if ( !isDouble( myPhyMax->text(), true )) {
285 myPhyMax->selectAll();
288 if ( !isDouble( myGeoMin->text(), true )) {
289 myGeoMin->selectAll();
292 if ( !isDouble( myGeoMin->text(), true )) {
293 myGeoMin->selectAll();
298 myOptionTable->setFocus();
299 QApplication::instance()->processEvents();
301 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
302 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
304 int row = 0, nbRows = myOptionTable->rowCount();
305 for ( ; row < nbRows; ++row )
307 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
308 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
309 if ( !value.isEmpty() ) {
311 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
313 catch ( const SALOME::SALOME_Exception& ex )
315 SUIT_MessageBox::critical( dlg(),
317 ex.details.text.in() );
322 h->SetOptionValues( myOptions ); // restore values
328 mySizeMapTable->setFocus();
329 QApplication::instance()->processEvents();
331 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
332 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
334 int row = 0, nbRows = mySizeMapTable->rowCount();
335 for ( ; row < nbRows; ++row )
337 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
338 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
339 if ( !sizeMap.isEmpty() ) {
340 if (that->sizeMapValidationFromRow(row))
343 const char* e = entry.toLatin1().constData();
344 const char* s = that->mySMPMap[entry].toLatin1().constData();
345 h->SetSizeMapEntry( e, s );
347 catch ( const SALOME::SALOME_Exception& ex )
349 SUIT_MessageBox::critical( dlg(),
351 ex.details.text.in() );
365 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
367 cout << "BLSURFPluginGUI_HypothesisCreator::buildFrame" << endl;
368 QFrame* fr = new QFrame( 0 );
369 QVBoxLayout* lay = new QVBoxLayout( fr );
371 lay->setSpacing( 0 );
374 QTabWidget* tab = new QTabWidget( fr );
375 tab->setTabShape( QTabWidget::Rounded );
376 tab->setTabPosition( QTabWidget::North );
377 lay->addWidget( tab );
380 myStdGroup = new QWidget();
381 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
382 aStdLayout->setSpacing( 6 );
383 aStdLayout->setMargin( 11 );
388 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
389 myName = new QLineEdit( myStdGroup );
390 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
393 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
394 myPhysicalMesh = new QComboBox( myStdGroup );
395 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
396 QStringList physicalTypes;
397 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
398 myPhysicalMesh->addItems( physicalTypes );
400 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
401 myPhySize = new QLineEdit( myStdGroup );
402 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
404 #ifdef WITH_SIZE_BOUNDARIES
405 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
406 myPhyMin = new QLineEdit( myStdGroup );
407 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
409 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
410 myPhyMax = new QLineEdit( myStdGroup );
411 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
414 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
415 myGeometricMesh = new QComboBox( myStdGroup );
416 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
418 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
419 myGeometricMesh->addItems( types );
421 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
422 myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
423 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
424 myAngleMeshS->setMinimum( 0 );
425 myAngleMeshS->setMaximum( 16 );
426 myAngleMeshS->setSingleStep( 0.5 );
428 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
429 myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
430 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
431 myAngleMeshC->setMinimum( 0 );
432 myAngleMeshC->setMaximum( 16 );
433 myAngleMeshC->setSingleStep( 0.5 );
435 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
436 myGradation = new QtxDoubleSpinBox( myStdGroup );
437 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
438 myGradation->setMinimum( 1.1 );
439 myGradation->setMaximum( 2.5 );
440 myGradation->setSingleStep( 0.1 );
442 #ifdef WITH_SIZE_BOUNDARIES
443 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
444 myGeoMin = new QLineEdit( myStdGroup );
445 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
447 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
448 myGeoMax = new QLineEdit( myStdGroup );
449 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
452 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
453 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
455 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
456 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
458 // advanced parameters
459 myAdvGroup = new QWidget();
460 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
461 anAdvLayout->setSpacing( 6 );
462 anAdvLayout->setMargin( 11 );
464 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
465 myTopology = new QComboBox( myAdvGroup );
466 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
467 QStringList topologyTypes;
468 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
469 myTopology->addItems( topologyTypes );
471 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
472 myVerbosity = new QSpinBox( myAdvGroup );
473 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
474 myVerbosity->setMinimum( 0 );
475 myVerbosity->setMaximum( 100 );
476 myVerbosity->setSingleStep( 5 );
478 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
479 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
481 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
482 myOptionTable->setHorizontalHeaderLabels( headers );
483 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
484 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
485 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
486 myOptionTable->verticalHeader()->hide();
487 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
489 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
490 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
491 addBtn->setMenu( new QMenu() );
493 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
494 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
496 anAdvLayout->setRowStretch( 4, 5 );
497 anAdvLayout->setColumnStretch( 1, 5 );
499 // Size Maps parameters
501 mySmpGroup = new QWidget();
502 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
504 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
505 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
506 QStringList sizeMapHeaders;
507 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
508 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
509 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
510 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
511 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
512 mySizeMapTable->setAlternatingRowColors(true);
513 mySizeMapTable->verticalHeader()->hide();
516 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
517 anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
519 QFrame *line = new QFrame(mySmpGroup);
520 line->setFrameShape(QFrame::HLine);
521 line->setFrameShadow(QFrame::Sunken);
522 anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
524 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
525 anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
527 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
528 anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
530 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
531 anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
533 QFrame *line2 = new QFrame(mySmpGroup);
534 line2->setFrameShape(QFrame::HLine);
535 line2->setFrameShadow(QFrame::Sunken);
536 anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
538 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
539 anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
543 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
544 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
545 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
547 tab->setCurrentIndex( STD_TAB );
550 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
551 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
552 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
553 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
554 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
556 connect(addSurfaceButton, SIGNAL(clicked()), this, SLOT(onAddMapOnSurface()));
557 connect(addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddMapOnEdge()));
558 connect(addPointButton, SIGNAL(clicked()), this, SLOT(onAddMapOnPoint()));
559 connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
560 connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
562 // connect(tab, SIGNAL(currentChanged ( int )),this,SLOT (onSetSelectionFilter(int)));
568 void BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(int page)
570 cout << "BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(" << page << ")" << endl;
571 aSel->clearFilters();
572 if (page == SMP_TAB) {
573 cout << "Page is SIZEMAP" << endl;
574 aSel = GeomToolSelected->selectionMgr();
578 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
580 cout << "BLSURFPluginGUI_HypothesisCreator::retrieveParams" << endl;
581 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
583 BlsurfHypothesisData data;
584 that->readParamsFromHypo( data );
587 myName->setText( data.myName );
588 QFontMetrics metrics( myName->font() );
589 myName->setMinimumWidth( metrics.width( data.myName )+5 );
591 myTopology->setCurrentIndex( data.myTopology );
592 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
593 myPhySize->setText( data.myPhySize );
594 #ifdef WITH_SIZE_BOUNDARIES
595 myPhyMin->setText( data.myPhyMin );
596 myPhyMax->setText( data.myPhyMax );
597 myGeoMin->setText( data.myGeoMin );
598 myGeoMax->setText( data.myGeoMax );
600 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
601 myAngleMeshS->setValue( data.myAngleMeshS );
602 myAngleMeshC->setValue( data.myAngleMeshC );
603 myGradation->setValue( data.myGradation );
604 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
605 myDecimesh->setChecked( data.myDecimesh );
606 myVerbosity->setValue( data.myVerbosity );
608 if ( myOptions.operator->() ) {
609 printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
610 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
611 QString option = that->myOptions[i].in();
612 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
613 if ( name_value.count() > 1 ) {
614 QString idStr = QString("%1").arg( i );
615 int row = myOptionTable->rowCount();
616 myOptionTable->setRowCount( row+1 );
617 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
618 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
619 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
620 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
621 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
622 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
628 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
630 printf("retrieveParams():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
631 QMapIterator<QString, QString> i(that->mySMPMap);
632 while (i.hasNext()) {
634 const QString entry = i.key();
635 string shapeName = GeomToolSelected->getNameFromEntry(entry.toStdString());
636 const QString sizeMap = i.value();
637 int row = mySizeMapTable->rowCount();
638 mySizeMapTable->setRowCount( row+1 );
639 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
640 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
641 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
642 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
643 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
644 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
649 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
650 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
653 that->onPhysicalMeshChanged();
654 that->onGeometricMeshChanged();
657 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
659 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
661 BlsurfHypothesisData data;
662 QString guiHyp = that->readParamsFromWidgets( data );
663 that->storeParamsToHypo( data );
665 //cout<<"BLSURFPluginGUI_HypothesisCreator::storeParams(), guiHyp: "<<endl<<guiHyp.toStdString()<<endl;
669 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
671 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo" << endl;
672 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
673 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
675 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
676 h_data.myName = isCreation() && data ? hypName() : "";
678 h_data.myTopology = (int) h->GetTopology();
679 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
680 h_data.myPhySize = QString::number( h->GetPhySize() );
681 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
682 h_data.myAngleMeshS = h->GetAngleMeshS();
683 h_data.myAngleMeshC = h->GetAngleMeshC();
684 h_data.myGradation = h->GetGradation();
685 h_data.myAllowQuadrangles = h->GetQuadAllowed();
686 h_data.myDecimesh = h->GetDecimesh();
687 h_data.myVerbosity = h->GetVerbosity();
689 #ifdef WITH_SIZE_BOUNDARIES
690 double PhyMin = h->GetPhyMin();
691 double PhyMax = h->GetPhyMax();
692 double GeoMin = h->GetGeoMin();
693 double GeoMax = h->GetGeoMax();
695 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
696 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
697 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
698 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
701 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
702 that->myOptions = h->GetOptionValues();
704 that->mySMPMap.clear();
707 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
708 cout << "mySizeMaps->length() = " << mySizeMaps->length() << endl;
710 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
711 QString fullSizeMaps = mySizeMaps[i].in();
712 QStringList fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
713 if ( fullSizeMapList.count() > 1 ) {
714 string fullSizeMap = fullSizeMapList[1].toStdString();
715 int pos = fullSizeMap.find("return")+7;
716 QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
717 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
718 that->mySMPShapeTypeMap[fullSizeMapList[0]] = GeomToolSelected->entryToShape(fullSizeMapList[0].toStdString()).ShapeType();
719 MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
720 MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
726 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
727 cout << "myCustomSizeMaps->length() = " << myCustomSizeMaps->length() << endl;
729 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
730 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
731 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
732 if ( fullCustomSizeMapList.count() > 1 ) {
733 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
734 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShape(fullCustomSizeMapList[0].toStdString()).ShapeType();
735 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
736 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
741 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
742 cout << "myAttractors->length() = " << allMyAttractors->length() << endl;
744 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
745 QString myAttractors = allMyAttractors[i].in();
746 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
747 if ( myAttractorList.count() > 1 ) {
748 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
749 that->mySMPShapeTypeMap[myAttractorList[0]] = GeomToolSelected->entryToShape(myAttractorList[0].toStdString()).ShapeType();
750 MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
751 MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
758 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
760 cout << "BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo" << endl;
761 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
762 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
768 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
770 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
771 h->SetTopology( (int) h_data.myTopology );
772 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
773 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
774 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
775 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
776 if ( h->GetGradation() != h_data.myGradation )
777 h->SetGradation( h_data.myGradation );
778 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
779 h->SetQuadAllowed( h_data.myAllowQuadrangles );
780 if ( h->GetDecimesh() != h_data.myDecimesh )
781 h->SetDecimesh( h_data.myDecimesh );
782 if ( h->GetVerbosity() != h_data.myVerbosity )
783 h->SetVerbosity( h_data.myVerbosity );
785 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
786 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
787 h->SetPhySize( h_data.myPhySize.toDouble() );
789 if( (int) h_data.myGeometricMesh == UserDefined ) {
790 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
791 h->SetAngleMeshS( h_data.myAngleMeshS );
792 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
793 h->SetAngleMeshC( h_data.myAngleMeshC );
795 #ifdef WITH_SIZE_BOUNDARIES
796 if ( !isDouble( h_data.myPhyMin ))
798 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
799 h->SetPhyMin( h_data.myPhyMin.toDouble() );
800 if ( !isDouble( h_data.myPhyMax ))
802 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
803 h->SetPhyMax( h_data.myPhyMax.toDouble() );
804 if ( !isDouble( h_data.myGeoMin ))
806 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
807 h->SetGeoMin( h_data.myGeoMin.toDouble() );
808 if ( !isDouble( h_data.myGeoMax ))
810 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
811 h->SetGeoMax( h_data.myGeoMax.toDouble() );
814 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
815 h->SetOptionValues( myOptions ); // is set in checkParams()
817 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
818 QMapIterator<QString,QString> i(that->mySMPMap);
819 // Iterate over each size map
820 while (i.hasNext()) {
822 const QString entry = i.key();
823 const QString sizeMap = i.value();
826 if (not that->sizeMapValidationFromEntry(entry,false)) {
827 cout << "Size map for entry " << entry.toStdString() << " is not valid" << endl;
832 if (sizeMap == "__TO_DELETE__") {
833 cout << "Delete entry " << entry.toStdString() << " from engine" << endl;
834 h->UnsetEntry(entry.toLatin1().constData());
836 else if (sizeMap.startsWith("ATTRACTOR")) {
837 cout << "SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
838 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
840 else if (sizeMap.startsWith("def")) {
841 cout << "SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
842 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
846 fullSizeMap = QString("");
847 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
848 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
849 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
850 fullSizeMap = QString("def f(t): return ") + sizeMap;
851 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
852 fullSizeMap = QString("def f(): return ") + sizeMap;
854 cout << "SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString() << endl;
855 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
859 catch(const SALOME::SALOME_Exception& ex)
861 SalomeApp_Tools::QtCatchCorbaException(ex);
867 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
869 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets" << endl;
870 h_data.myName = myName ? myName->text() : "";
871 h_data.myTopology = myTopology->currentIndex();
872 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
873 h_data.myPhySize = myPhySize->text();
874 #ifdef WITH_SIZE_BOUNDARIES
875 h_data.myPhyMin = myPhyMin->text();
876 h_data.myPhyMax = myPhyMax->text();
877 h_data.myGeoMin = myGeoMin->text();
878 h_data.myGeoMax = myGeoMax->text();
880 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
881 h_data.myAngleMeshS = myAngleMeshS->value();
882 h_data.myAngleMeshC = myAngleMeshC->value();
883 h_data.myGradation = myGradation->value();
884 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
885 h_data.myDecimesh = myDecimesh->isChecked();
886 h_data.myVerbosity = myVerbosity->value();
889 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
890 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
891 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
892 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
893 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
894 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
895 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
896 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
897 #ifdef WITH_SIZE_BOUNDARIES
898 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
899 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
900 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
901 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
904 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
905 int row = 0, nbRows = myOptionTable->rowCount();
906 for ( ; row < nbRows; ++row )
908 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
909 if ( id >= 0 && id < myOptions->length() )
911 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
912 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
913 if ( value.isNull() )
915 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
917 guiHyp += name + " = " + value + "; ";
922 row = 0, nbRows = mySizeMapTable->rowCount();
923 for ( ; row < nbRows; ++row )
925 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
926 if ( that->mySMPMap.contains(entry) )
927 guiHyp += entry + " = " + that->mySMPMap[entry] + "; ";
930 cout << "guiHyp : " << guiHyp.toLatin1().data() << endl;
935 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
936 cout << "BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged" << endl;
937 bool isCustom = ((myPhysicalMesh->currentIndex() == PhysicalUserDefined) || (myPhysicalMesh->currentIndex() == SizeMap)) ;
938 myPhySize->setEnabled(isCustom);
939 myPhyMax->setEnabled(isCustom);
940 myPhyMin->setEnabled(isCustom);
943 QString aPhySize = "";
944 switch( myPhysicalMesh->currentIndex() ) {
950 myPhySize->setText( aPhySize );
951 if ( !isDouble( myPhyMin->text(), true ))
952 myPhyMin->setText("");
953 if ( !isDouble( myPhyMax->text(), true ))
954 myPhyMax->setText("");
955 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
956 myGeometricMesh->setCurrentIndex( UserDefined );
957 onGeometricMeshChanged();
962 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
963 cout << "BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged" << endl;
964 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
965 myAngleMeshS->setEnabled(isCustom);
966 myAngleMeshC->setEnabled(isCustom);
967 myGradation->setEnabled(isCustom);
968 myGeoMax->setEnabled(isCustom);
969 myGeoMin->setEnabled(isCustom);
972 double aAngleMeshS, aGradation;
973 switch( myGeometricMesh->currentIndex() ) {
980 myAngleMeshS->setValue( aAngleMeshS );
981 myAngleMeshC->setValue( aAngleMeshS );
982 myGradation->setValue( aGradation );
983 if ( !isDouble( myGeoMin->text(), true ))
984 myGeoMin->setText("");
985 if ( !isDouble( myGeoMax->text(), true ))
986 myGeoMax->setText("");
987 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
988 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
989 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
990 onPhysicalMeshChanged();
995 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
997 QMenu* menu = (QMenu*)sender();
998 // fill popup with option names
1000 if ( myOptions.operator->() ) {
1001 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1002 QString name_value = myOptions[i].in();
1003 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1004 menu->addAction( name );
1009 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1011 myOptionTable->setFocus();
1012 QMenu* menu = (QMenu*)( a->parent() );
1014 int idx = menu->actions().indexOf( a );
1015 QString idStr = QString("%1").arg( idx );
1016 QString option = myOptions[idx].in();
1017 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1019 // look for a row with optionName
1020 int row = 0, nbRows = myOptionTable->rowCount();
1021 for ( ; row < nbRows; ++row )
1022 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1024 // add a row if not found
1025 if ( row == nbRows ) {
1026 myOptionTable->setRowCount( row+1 );
1027 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1028 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1029 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1030 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1031 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1032 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1033 Qt::ItemIsEditable |
1034 Qt::ItemIsEnabled );
1035 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1037 myOptionTable->clearSelection();
1038 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1039 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1040 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1041 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1044 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1046 // clear option values and remember selected row
1047 QList<int> selectedRows;
1048 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1049 QTableWidgetItem* item;
1050 foreach( item, selected ) {
1051 int row = item->row();
1052 if ( !selectedRows.contains( row ) ) {
1053 selectedRows.append( row );
1054 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1055 if ( id >= 0 && id < myOptions->length() )
1056 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1059 qSort( selectedRows );
1060 QListIterator<int> it( selectedRows );
1062 while ( it.hasPrevious() )
1063 myOptionTable->removeRow( it.previous() );
1066 // **********************
1067 // *** BEGIN SIZE MAP ***
1068 // **********************
1071 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1073 cout<<"BLSURFPluginGUI_HypothesisCreator::onRemoveMap()"<<endl;
1074 QList<int> selectedRows;
1075 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1076 QTableWidgetItem* item;
1078 foreach( item, selected ) {
1080 if ( !selectedRows.contains( row ) )
1081 selectedRows.append( row );
1084 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1086 qSort( selectedRows );
1087 QListIterator<int> it( selectedRows );
1089 while ( it.hasPrevious() ) {
1090 row = it.previous();
1091 cout << "delete row #"<< row <<endl;
1092 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1093 if (that->mySMPMap.contains(entry))
1094 that->mySMPMap[entry] = "__TO_DELETE__";
1095 if (that->mySMPShapeTypeMap.contains(entry))
1096 that->mySMPShapeTypeMap.remove(entry);
1097 mySizeMapTable->removeRow(row );
1099 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1100 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1103 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1105 cout<<"BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")"<<endl;
1106 if (col == SMP_SIZEMAP_COLUMN) {
1107 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1108 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1109 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1110 cout << "entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString() << endl;
1111 if (not that->mySMPShapeTypeMap.contains(entry))
1113 if (that->mySMPMap.contains(entry))
1114 if (that->mySMPMap[entry] == sizeMap)
1116 QColor* bgColor = new QColor("white");
1117 QColor* fgColor = new QColor("black");
1118 if (not sizeMap.isEmpty()) {
1119 that->mySMPMap[entry] = sizeMap;
1120 if (not sizeMapValidationFromRow(row)) {
1121 bgColor->setRgb(255,0,0);
1122 fgColor->setRgb(255,255,255);
1126 cout << "Size map empty: reverse to precedent value" << endl;
1127 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1129 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1130 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1131 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1132 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1133 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1137 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1139 insertElementType(TopAbs_FACE);
1142 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1144 insertElementType(TopAbs_EDGE);
1147 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1149 insertElementType(TopAbs_VERTEX);
1152 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1154 cout<<"BLSURFPluginGUI_HypothesisCreator::insertElementType()"<<endl;
1156 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1157 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1159 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1162 string entry, shapeName;
1163 // LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
1165 SALOME_ListIO ListSelectedObjects;
1166 aSel->selectedObjects(ListSelectedObjects, NULL, false );
1167 if (!ListSelectedObjects.IsEmpty())
1169 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1170 for (; Object_It.More(); Object_It.Next())
1172 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1173 entry = GeomToolSelected->getEntryOfObject(anObject);
1174 shapeName = anObject->getName();
1175 S = GeomToolSelected->entryToShape(entry);
1176 if ((! S.IsNull()) && (S.ShapeType() == typeShapeAsked))
1178 mySizeMapTable->setFocus();
1180 shapeEntry = QString::fromStdString(entry);
1181 double phySize = h->GetPhySize();
1182 std::ostringstream oss;
1185 sizeMap = QString::fromStdString(oss.str());
1186 if (that->mySMPMap.contains(shapeEntry)) {
1187 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1188 MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1192 that->mySMPMap[shapeEntry] = sizeMap;
1193 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1194 int row = mySizeMapTable->rowCount() ;
1195 mySizeMapTable->setRowCount( row+1 );
1196 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1197 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1198 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1199 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1200 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1201 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1202 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1203 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1204 mySizeMapTable->clearSelection();
1205 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1207 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1208 myPhysicalMesh->setCurrentIndex( SizeMap );
1209 onPhysicalMeshChanged();
1216 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1218 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()"<<endl;
1219 int row = 0, nbRows = mySizeMapTable->rowCount();
1220 for ( ; row < nbRows; ++row )
1221 if (not sizeMapValidationFromRow(row))
1226 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1228 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()"<<endl;
1229 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1230 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1231 mySizeMapTable->setFocus();
1235 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1237 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()"<<endl;
1239 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1241 if (not that->mySMPMap.contains(myEntry)) {
1242 cout<<"Geometry with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1245 if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1246 cout<<"Shape type with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1252 if (that->mySMPMap[myEntry].startsWith("def")) {
1253 cout << "custom function" << endl;
1254 expr = that->mySMPMap[myEntry].toStdString();
1256 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1257 cout << "Attractor" << endl;
1258 // if ((that->mySMPMap[myEntry].count(QRegExp("ATTRACTOR([0-9])")) != 1))
1259 if ((that->mySMPMap[myEntry].count('(') != 1) or
1260 (that->mySMPMap[myEntry].count(')') != 1) or
1261 (that->mySMPMap[myEntry].count(';') != 4) or
1262 (that->mySMPMap[myEntry].size() == 15)){
1264 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b)" );
1270 // case size map is empty
1271 if (that->mySMPMap[myEntry].isEmpty()) {
1273 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1277 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1278 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1279 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1280 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1281 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1282 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1284 //assert(Py_IsInitialized());
1285 if (not Py_IsInitialized())
1286 throw ("Erreur: Python interpreter is not initialized");
1287 PyGILState_STATE gstate;
1288 gstate = PyGILState_Ensure();
1290 PyObject * obj = NULL;
1291 PyObject* new_stderr = NULL;
1292 string err_description="";
1293 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1297 new_stderr=newPyStdOut(err_description);
1298 PySys_SetObject("stderr", new_stderr);
1300 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1301 Py_DECREF(new_stderr);
1303 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1304 PyGILState_Release(gstate);
1309 PyObject * func = NULL;
1310 func = PyObject_GetAttrString(main_mod, "f");
1314 new_stderr=newPyStdOut(err_description);
1315 PySys_SetObject("stderr", new_stderr);
1317 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1318 Py_DECREF(new_stderr);
1320 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1321 PyGILState_Release(gstate);
1325 PyGILState_Release(gstate);
1327 cout<<"SizeMap expression "<<expr<<" is valid"<<endl;
1333 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1334 int myRow = index->row();
1335 int myColumn = index->column();
1339 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1340 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1343 // myEditor->show();
1344 // myEditor->raise();
1345 // myEditor->activateWindow();
1348 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1349 // myEditor->exec();
1350 QString myFunction = myEditor->GetFunctionText();
1351 // FIN RECUPERATION FONCTION
1353 if (! myFunction.isEmpty()) {
1357 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1358 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1360 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1361 // item->text().toLatin1().constData());
1362 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1363 myFunction.toLatin1().constData());
1364 // FIN MAJ DE LA MAP
1369 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1371 return tr( "BLSURF_TITLE" );
1374 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1376 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1379 QString BLSURFPluginGUI_HypothesisCreator::type() const
1381 return tr( "BLSURF_HYPOTHESIS" );
1384 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1386 return "blsurf_hypo_page.html";
1389 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1392 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1394 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );