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
113 PyStdOut_dealloc(PyStdOut *self)
119 PyStdOut_write(PyStdOut *self, PyObject *args)
123 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
127 *(self->out)=*(self->out)+c;
133 static PyMethodDef PyStdOut_methods[] = {
134 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
135 PyDoc_STR("write(string) -> None")},
136 {NULL, NULL} /* sentinel */
139 static PyMemberDef PyStdOut_memberlist[] = {
140 {"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
141 "flag indicating that a space needs to be printed; used by print"},
142 {NULL} /* Sentinel */
145 static PyTypeObject PyStdOut_Type = {
146 /* The ob_type field must be initialized in the module init function
147 * to be portable to Windows without using C++. */
148 PyObject_HEAD_INIT(NULL)
151 sizeof(PyStdOut), /*tp_basicsize*/
154 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
161 0, /*tp_as_sequence*/
166 PyObject_GenericGetAttr, /*tp_getattro*/
167 /* softspace is writable: we must supply tp_setattro */
168 PyObject_GenericSetAttr, /* tp_setattro */
170 Py_TPFLAGS_DEFAULT, /*tp_flags*/
174 0, /*tp_richcompare*/
175 0, /*tp_weaklistoffset*/
178 PyStdOut_methods, /*tp_methods*/
179 PyStdOut_memberlist, /*tp_members*/
193 PyObject * newPyStdOut( std::string& out )
196 self = PyObject_New(PyStdOut, &PyStdOut_Type);
201 return (PyObject*)self;
205 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
206 : SMESHGUI_GenericHypothesisCreator( theHypType )
208 cout << "BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator" << endl;
209 this->mySMPMap.clear();
211 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
212 GeomToolSelected = new GeomSelectionTools(aStudy);
214 /* Initialize the Python interpreter */
215 assert(Py_IsInitialized());
216 PyGILState_STATE gstate;
217 gstate = PyGILState_Ensure();
220 main_mod = PyImport_AddModule("__main__");
223 main_dict = PyModule_GetDict(main_mod);
225 PyRun_SimpleString("from math import *");
226 PyGILState_Release(gstate);
229 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
234 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
235 QString str = theText.trimmed();
237 if ( !str.isEmpty() )
245 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
247 cout << "BLSURFPluginGUI_HypothesisCreator::checkParams" << endl;
249 if ( !isDouble( myPhySize->text(), false )) {
250 if ( myPhySize->text().isEmpty() )
251 myPhySize->setText(tr("OBLIGATORY_VALUE"));
252 myPhySize->selectAll();
255 if ( !isDouble( myPhyMin->text(), true )) {
256 myPhyMin->selectAll();
259 if ( !isDouble( myPhyMax->text(), true )) {
260 myPhyMax->selectAll();
263 if ( !isDouble( myGeoMin->text(), true )) {
264 myGeoMin->selectAll();
267 if ( !isDouble( myGeoMin->text(), true )) {
268 myGeoMin->selectAll();
273 myOptionTable->setFocus();
274 QApplication::instance()->processEvents();
276 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
277 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
279 int row = 0, nbRows = myOptionTable->rowCount();
280 for ( ; row < nbRows; ++row )
282 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
283 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
284 if ( !value.isEmpty() ) {
286 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
288 catch ( const SALOME::SALOME_Exception& ex )
290 SUIT_MessageBox::critical( dlg(),
292 ex.details.text.in() );
297 h->SetOptionValues( myOptions ); // restore values
303 mySizeMapTable->setFocus();
304 QApplication::instance()->processEvents();
306 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
307 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
309 int row = 0, nbRows = mySizeMapTable->rowCount();
310 for ( ; row < nbRows; ++row )
312 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
313 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
314 if ( !sizeMap.isEmpty() ) {
315 if (that->sizeMapValidationFromRow(row))
318 const char* e = entry.toLatin1().constData();
319 const char* s = that->mySMPMap[entry].toLatin1().constData();
320 h->SetSizeMapEntry( e, s );
322 catch ( const SALOME::SALOME_Exception& ex )
324 SUIT_MessageBox::critical( dlg(),
326 ex.details.text.in() );
340 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
342 cout << "BLSURFPluginGUI_HypothesisCreator::buildFrame" << endl;
343 QFrame* fr = new QFrame( 0 );
344 QVBoxLayout* lay = new QVBoxLayout( fr );
346 lay->setSpacing( 0 );
349 QTabWidget* tab = new QTabWidget( fr );
350 tab->setTabShape( QTabWidget::Rounded );
351 tab->setTabPosition( QTabWidget::North );
352 lay->addWidget( tab );
355 myStdGroup = new QWidget();
356 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
357 aStdLayout->setSpacing( 6 );
358 aStdLayout->setMargin( 11 );
363 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
364 myName = new QLineEdit( myStdGroup );
365 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
368 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
369 myPhysicalMesh = new QComboBox( myStdGroup );
370 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
371 QStringList physicalTypes;
372 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
373 myPhysicalMesh->addItems( physicalTypes );
375 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
376 myPhySize = new QLineEdit( myStdGroup );
377 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
379 #ifdef WITH_SIZE_BOUNDARIES
380 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
381 myPhyMin = new QLineEdit( myStdGroup );
382 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
384 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
385 myPhyMax = new QLineEdit( myStdGroup );
386 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
389 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
390 myGeometricMesh = new QComboBox( myStdGroup );
391 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
393 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
394 myGeometricMesh->addItems( types );
396 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
397 myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
398 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
399 myAngleMeshS->setMinimum( 0 );
400 myAngleMeshS->setMaximum( 16 );
401 myAngleMeshS->setSingleStep( 0.5 );
403 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
404 myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
405 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
406 myAngleMeshC->setMinimum( 0 );
407 myAngleMeshC->setMaximum( 16 );
408 myAngleMeshC->setSingleStep( 0.5 );
410 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
411 myGradation = new QtxDoubleSpinBox( myStdGroup );
412 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
413 myGradation->setMinimum( 1.1 );
414 myGradation->setMaximum( 2.5 );
415 myGradation->setSingleStep( 0.1 );
417 #ifdef WITH_SIZE_BOUNDARIES
418 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
419 myGeoMin = new QLineEdit( myStdGroup );
420 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
422 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
423 myGeoMax = new QLineEdit( myStdGroup );
424 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
427 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
428 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
430 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
431 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
433 // advanced parameters
434 myAdvGroup = new QWidget();
435 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
436 anAdvLayout->setSpacing( 6 );
437 anAdvLayout->setMargin( 11 );
439 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
440 myTopology = new QComboBox( myAdvGroup );
441 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
442 QStringList topologyTypes;
443 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
444 myTopology->addItems( topologyTypes );
446 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
447 myVerbosity = new QSpinBox( myAdvGroup );
448 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
449 myVerbosity->setMinimum( 0 );
450 myVerbosity->setMaximum( 100 );
451 myVerbosity->setSingleStep( 5 );
453 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
454 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
456 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
457 myOptionTable->setHorizontalHeaderLabels( headers );
458 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
459 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
460 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
461 myOptionTable->verticalHeader()->hide();
462 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
464 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
465 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
466 addBtn->setMenu( new QMenu() );
468 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
469 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
471 anAdvLayout->setRowStretch( 4, 5 );
472 anAdvLayout->setColumnStretch( 1, 5 );
474 // Size Maps parameters
476 mySmpGroup = new QWidget();
477 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
479 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
480 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 6, 1);
481 QStringList sizeMapHeaders;
482 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
483 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
484 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
485 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
486 mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
487 mySizeMapTable->setAlternatingRowColors(true);
488 mySizeMapTable->verticalHeader()->hide();
490 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
491 anSmpLayout->addWidget(addSurfaceButton, 1, 1, 1, 1);
493 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
494 anSmpLayout->addWidget(addEdgeButton, 2, 1, 1, 1);
496 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
497 anSmpLayout->addWidget(addPointButton, 3, 1, 1, 1);
499 QFrame *line = new QFrame(mySmpGroup);
500 line->setFrameShape(QFrame::HLine);
501 line->setFrameShadow(QFrame::Sunken);
502 anSmpLayout->addWidget(line, 4, 1, 1, 1);
504 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
505 anSmpLayout->addWidget(removeButton, 5, 1, 1, 1);
509 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
510 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
511 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
513 tab->setCurrentIndex( STD_TAB );
516 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
517 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
518 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
519 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
520 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
522 connect(addSurfaceButton, SIGNAL(clicked()), this, SLOT(onAddMapOnSurface()));
523 connect(addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddMapOnEdge()));
524 connect(addPointButton, SIGNAL(clicked()), this, SLOT(onAddMapOnPoint()));
525 connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
526 connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
532 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
534 cout << "BLSURFPluginGUI_HypothesisCreator::retrieveParams" << endl;
535 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
537 BlsurfHypothesisData data;
538 that->readParamsFromHypo( data );
541 myName->setText( data.myName );
542 QFontMetrics metrics( myName->font() );
543 myName->setMinimumWidth( metrics.width( data.myName )+5 );
545 myTopology->setCurrentIndex( data.myTopology );
546 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
547 myPhySize->setText( data.myPhySize );
548 #ifdef WITH_SIZE_BOUNDARIES
549 myPhyMin->setText( data.myPhyMin );
550 myPhyMax->setText( data.myPhyMax );
551 myGeoMin->setText( data.myGeoMin );
552 myGeoMax->setText( data.myGeoMax );
554 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
555 myAngleMeshS->setValue( data.myAngleMeshS );
556 myAngleMeshC->setValue( data.myAngleMeshC );
557 myGradation->setValue( data.myGradation );
558 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
559 myDecimesh->setChecked( data.myDecimesh );
560 myVerbosity->setValue( data.myVerbosity );
562 if ( myOptions.operator->() ) {
563 printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
564 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
565 QString option = that->myOptions[i].in();
566 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
567 if ( name_value.count() > 1 ) {
568 QString idStr = QString("%1").arg( i );
569 int row = myOptionTable->rowCount();
570 myOptionTable->setRowCount( row+1 );
571 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
572 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
573 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
574 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
575 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
576 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
582 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
584 printf("retrieveParams():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
585 QMapIterator<QString, QString> i(that->mySMPMap);
586 while (i.hasNext()) {
588 const QString entry = i.key();
589 string shapeName = GeomToolSelected->getNameFromEntry(entry.toStdString());
590 const QString sizeMap = i.value();
591 int row = mySizeMapTable->rowCount();
592 mySizeMapTable->setRowCount( row+1 );
593 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
594 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
595 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
596 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
597 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
598 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
603 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
604 mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
607 that->onPhysicalMeshChanged();
608 that->onGeometricMeshChanged();
611 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
613 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
615 BlsurfHypothesisData data;
616 QString guiHyp = that->readParamsFromWidgets( data );
617 that->storeParamsToHypo( data );
619 //cout<<"BLSURFPluginGUI_HypothesisCreator::storeParams(), guiHyp: "<<endl<<guiHyp.toStdString()<<endl;
623 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
625 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo" << endl;
626 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
627 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
629 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
630 h_data.myName = isCreation() && data ? hypName() : "";
632 h_data.myTopology = (int) h->GetTopology();
633 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
634 h_data.myPhySize = QString::number( h->GetPhySize() );
635 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
636 h_data.myAngleMeshS = h->GetAngleMeshS();
637 h_data.myAngleMeshC = h->GetAngleMeshC();
638 h_data.myGradation = h->GetGradation();
639 h_data.myAllowQuadrangles = h->GetQuadAllowed();
640 h_data.myDecimesh = h->GetDecimesh();
641 h_data.myVerbosity = h->GetVerbosity();
643 #ifdef WITH_SIZE_BOUNDARIES
644 double PhyMin = h->GetPhyMin();
645 double PhyMax = h->GetPhyMax();
646 double GeoMin = h->GetGeoMin();
647 double GeoMax = h->GetGeoMax();
649 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
650 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
651 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
652 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
655 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
656 that->myOptions = h->GetOptionValues();
659 BLSURFPlugin::string_array_var mySMPString = h->GetSizeMapEntries();
661 cout << "mySMPString->length() = " << mySMPString->length() << endl;
662 that->mySMPMap.clear();
666 for ( int i = 0;i<mySMPString->length(); ++i ) {
667 QString sizemaps_line = mySMPString[i].in();
668 QStringList entry_sm = sizemaps_line.split( "|", QString::KeepEmptyParts );
669 if ( entry_sm.count() > 1 ) {
670 string fullSizeMap = entry_sm[1].toStdString();
671 int pos = fullSizeMap.find("return")+7;
672 QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
673 that->mySMPMap[entry_sm[0]] = sizeMap;
674 that->mySMPShapeTypeMap[entry_sm[0]] = GeomToolSelected->entryToShape(entry_sm[0].toStdString()).ShapeType();
675 MESSAGE("mySMPMap[" << entry_sm[0].toStdString() << "] = " << sizeMap.toStdString());
676 MESSAGE("mySMPShapeTypeMap[" << entry_sm[0].toStdString() << "] = " << that->mySMPShapeTypeMap[entry_sm[0]]);
683 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
685 cout << "BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo" << endl;
686 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
687 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
693 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
695 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
696 h->SetTopology( (int) h_data.myTopology );
697 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
698 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
699 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
700 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
701 if ( h->GetGradation() != h_data.myGradation )
702 h->SetGradation( h_data.myGradation );
703 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
704 h->SetQuadAllowed( h_data.myAllowQuadrangles );
705 if ( h->GetDecimesh() != h_data.myDecimesh )
706 h->SetDecimesh( h_data.myDecimesh );
707 if ( h->GetVerbosity() != h_data.myVerbosity )
708 h->SetVerbosity( h_data.myVerbosity );
710 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
711 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
712 h->SetPhySize( h_data.myPhySize.toDouble() );
714 if( (int) h_data.myGeometricMesh == UserDefined ) {
715 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
716 h->SetAngleMeshS( h_data.myAngleMeshS );
717 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
718 h->SetAngleMeshC( h_data.myAngleMeshC );
720 #ifdef WITH_SIZE_BOUNDARIES
721 if ( !isDouble( h_data.myPhyMin ))
723 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
724 h->SetPhyMin( h_data.myPhyMin.toDouble() );
725 if ( !isDouble( h_data.myPhyMax ))
727 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
728 h->SetPhyMax( h_data.myPhyMax.toDouble() );
729 if ( !isDouble( h_data.myGeoMin ))
731 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
732 h->SetGeoMin( h_data.myGeoMin.toDouble() );
733 if ( !isDouble( h_data.myGeoMax ))
735 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
736 h->SetGeoMax( h_data.myGeoMax.toDouble() );
739 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
740 h->SetOptionValues( myOptions ); // is set in checkParams()
742 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
743 //printf("storeParamsToHypo():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
744 QMapIterator<QString,QString> i(that->mySMPMap);
745 // Reset the size maps in engine
746 // h->ClearSizeMaps();
747 // Iterate over each size map
748 while (i.hasNext()) {
750 const QString entry = i.key();
751 const QString sizeMap = i.value();
753 if (sizeMap == "__TO_DELETE__") {
754 cout << "Delete entry " << entry.toStdString() << " from engine" << endl;
755 h->UnsetEntry(entry.toLatin1().constData());
761 fullSizeMap = QString("");
762 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
763 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
764 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
765 fullSizeMap = QString("def f(t): return ") + sizeMap;
766 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
767 fullSizeMap = QString("def f(): return ") + sizeMap;
769 cout << "SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString() << endl;
770 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
773 catch(const SALOME::SALOME_Exception& ex)
775 SalomeApp_Tools::QtCatchCorbaException(ex);
781 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
783 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets" << endl;
784 h_data.myName = myName ? myName->text() : "";
785 h_data.myTopology = myTopology->currentIndex();
786 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
787 h_data.myPhySize = myPhySize->text();
788 #ifdef WITH_SIZE_BOUNDARIES
789 h_data.myPhyMin = myPhyMin->text();
790 h_data.myPhyMax = myPhyMax->text();
791 h_data.myGeoMin = myGeoMin->text();
792 h_data.myGeoMax = myGeoMax->text();
794 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
795 h_data.myAngleMeshS = myAngleMeshS->value();
796 h_data.myAngleMeshC = myAngleMeshC->value();
797 h_data.myGradation = myGradation->value();
798 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
799 h_data.myDecimesh = myDecimesh->isChecked();
800 h_data.myVerbosity = myVerbosity->value();
803 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
804 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
805 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
806 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
807 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
808 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
809 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
810 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
811 #ifdef WITH_SIZE_BOUNDARIES
812 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
813 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
814 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
815 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
818 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
819 int row = 0, nbRows = myOptionTable->rowCount();
820 for ( ; row < nbRows; ++row )
822 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
823 if ( id >= 0 && id < myOptions->length() )
825 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
826 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
827 if ( value.isNull() )
829 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
831 guiHyp += name + " = " + value + "; ";
836 row = 0, nbRows = mySizeMapTable->rowCount();
837 for ( ; row < nbRows; ++row )
839 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
840 if ( that->mySMPMap.contains(entry) )
841 guiHyp += entry + " = " + that->mySMPMap[entry] + "; ";
844 cout << "guiHyp : " << guiHyp.toLatin1().data() << endl;
849 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
850 cout << "BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged" << endl;
851 bool isCustom = ((myPhysicalMesh->currentIndex() == PhysicalUserDefined) || (myPhysicalMesh->currentIndex() == SizeMap)) ;
852 myPhySize->setEnabled(isCustom);
853 myPhyMax->setEnabled(isCustom);
854 myPhyMin->setEnabled(isCustom);
857 QString aPhySize = "";
858 switch( myPhysicalMesh->currentIndex() ) {
864 myPhySize->setText( aPhySize );
865 if ( !isDouble( myPhyMin->text(), true ))
866 myPhyMin->setText("");
867 if ( !isDouble( myPhyMax->text(), true ))
868 myPhyMax->setText("");
869 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
870 myGeometricMesh->setCurrentIndex( UserDefined );
871 onGeometricMeshChanged();
876 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
877 cout << "BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged" << endl;
878 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
879 myAngleMeshS->setEnabled(isCustom);
880 myAngleMeshC->setEnabled(isCustom);
881 myGradation->setEnabled(isCustom);
882 myGeoMax->setEnabled(isCustom);
883 myGeoMin->setEnabled(isCustom);
886 double aAngleMeshS, aGradation;
887 switch( myGeometricMesh->currentIndex() ) {
894 myAngleMeshS->setValue( aAngleMeshS );
895 myAngleMeshC->setValue( aAngleMeshS );
896 myGradation->setValue( aGradation );
897 if ( !isDouble( myGeoMin->text(), true ))
898 myGeoMin->setText("");
899 if ( !isDouble( myGeoMax->text(), true ))
900 myGeoMax->setText("");
901 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
902 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
903 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
904 onPhysicalMeshChanged();
909 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
911 QMenu* menu = (QMenu*)sender();
912 // fill popup with option names
914 if ( myOptions.operator->() ) {
915 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
916 QString name_value = myOptions[i].in();
917 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
918 menu->addAction( name );
923 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
925 myOptionTable->setFocus();
926 QMenu* menu = (QMenu*)( a->parent() );
928 int idx = menu->actions().indexOf( a );
929 QString idStr = QString("%1").arg( idx );
930 QString option = myOptions[idx].in();
931 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
933 // look for a row with optionName
934 int row = 0, nbRows = myOptionTable->rowCount();
935 for ( ; row < nbRows; ++row )
936 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
938 // add a row if not found
939 if ( row == nbRows ) {
940 myOptionTable->setRowCount( row+1 );
941 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
942 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
943 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
944 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
945 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
946 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
949 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
951 myOptionTable->clearSelection();
952 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
953 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
954 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
955 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
958 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
960 // clear option values and remember selected row
961 QList<int> selectedRows;
962 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
963 QTableWidgetItem* item;
964 foreach( item, selected ) {
965 int row = item->row();
966 if ( !selectedRows.contains( row ) ) {
967 selectedRows.append( row );
968 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
969 if ( id >= 0 && id < myOptions->length() )
970 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
973 qSort( selectedRows );
974 QListIterator<int> it( selectedRows );
976 while ( it.hasPrevious() )
977 myOptionTable->removeRow( it.previous() );
980 // **********************
981 // *** BEGIN SIZE MAP ***
982 // **********************
985 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
987 cout<<"BLSURFPluginGUI_HypothesisCreator::onRemoveMap()"<<endl;
988 QList<int> selectedRows;
989 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
990 QTableWidgetItem* item;
992 foreach( item, selected ) {
994 if ( !selectedRows.contains( row ) )
995 selectedRows.append( row );
998 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1000 qSort( selectedRows );
1001 QListIterator<int> it( selectedRows );
1003 while ( it.hasPrevious() ) {
1004 row = it.previous();
1005 cout << "delete row #"<< row <<endl;
1006 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1007 if (that->mySMPMap.contains(entry))
1008 that->mySMPMap[entry] = "__TO_DELETE__";
1009 if (that->mySMPShapeTypeMap.contains(entry))
1010 that->mySMPShapeTypeMap.remove(entry);
1011 mySizeMapTable->removeRow(row );
1013 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1014 mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
1017 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1019 cout<<"BLSURFPluginGUI_HypothesisCreator::onSetSizeMap()"<<endl;
1020 if (col == SMP_SIZEMAP_COLUMN) {
1021 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1022 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1023 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1024 if (not that->mySMPShapeTypeMap.contains(entry))
1026 QString prevSizeMap = that->mySMPMap[entry];
1027 that->mySMPMap[entry] = sizeMap;
1028 if (not sizeMapValidationFromEntry(entry)) {
1029 that->mySMPMap[entry] = prevSizeMap;
1030 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(prevSizeMap);
1035 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1037 insertElementType(TopAbs_FACE);
1040 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1042 insertElementType(TopAbs_EDGE);
1045 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1047 insertElementType(TopAbs_VERTEX);
1050 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1052 cout<<"BLSURFPluginGUI_HypothesisCreator::insertElementType()"<<endl;
1054 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1055 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1057 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1060 string entry, shapeName;
1061 LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
1062 SALOME_ListIO ListSelectedObjects;
1063 aSel->selectedObjects(ListSelectedObjects, NULL, false );
1064 if (!ListSelectedObjects.IsEmpty())
1066 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1067 for (; Object_It.More(); Object_It.Next())
1069 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1070 entry = GeomToolSelected->getEntryOfObject(anObject);
1071 shapeName = anObject->getName();
1072 S = GeomToolSelected->entryToShape(entry);
1073 if ((! S.IsNull()) && (S.ShapeType() == typeShapeAsked))
1075 mySizeMapTable->setFocus();
1077 shapeEntry = QString::fromStdString(entry);
1078 double phySize = h->GetPhySize();
1079 std::ostringstream oss;
1082 sizeMap = QString::fromStdString(oss.str());
1083 if (that->mySMPMap.contains(shapeEntry)) {
1084 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1085 MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1089 that->mySMPMap[shapeEntry] = sizeMap;
1090 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1091 int row = mySizeMapTable->rowCount() ;
1092 mySizeMapTable->setRowCount( row+1 );
1093 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1094 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1095 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1096 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1097 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1098 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1099 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1100 mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
1101 mySizeMapTable->clearSelection();
1102 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1104 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1105 myPhysicalMesh->setCurrentIndex( SizeMap );
1106 onPhysicalMeshChanged();
1113 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1115 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()"<<endl;
1116 int row = 0, nbRows = mySizeMapTable->rowCount();
1117 for ( ; row < nbRows; ++row )
1118 if (not sizeMapValidationFromRow(row))
1123 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow)
1125 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()"<<endl;
1126 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1127 return sizeMapValidationFromEntry(myEntry);
1130 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry)
1132 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()"<<endl;
1134 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1136 if (not that->mySMPMap.contains(myEntry)) {
1137 cout<<"Geometry with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1140 if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1141 cout<<"Shape type with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1147 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1148 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1149 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1150 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1151 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1152 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1154 assert(Py_IsInitialized());
1155 PyGILState_STATE gstate;
1156 gstate = PyGILState_Ensure();
1158 PyObject * obj = NULL;
1159 PyObject* new_stderr = NULL;
1160 string err_description="";
1161 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1165 new_stderr=newPyStdOut(err_description);
1166 PySys_SetObject("stderr", new_stderr);
1168 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1169 Py_DECREF(new_stderr);
1170 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1171 PyGILState_Release(gstate);
1176 PyObject * func = NULL;
1177 func = PyObject_GetAttrString(main_mod, "f");
1181 new_stderr=newPyStdOut(err_description);
1182 PySys_SetObject("stderr", new_stderr);
1184 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1185 Py_DECREF(new_stderr);
1186 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1187 PyGILState_Release(gstate);
1191 PyGILState_Release(gstate);
1193 cout<<"SizeMap expression "<<expr<<" is valid"<<endl;
1199 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1200 int myRow = index->row();
1201 int myColumn = index->column();
1205 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1206 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1209 // myEditor->show();
1210 // myEditor->raise();
1211 // myEditor->activateWindow();
1214 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1215 // myEditor->exec();
1216 QString myFunction = myEditor->GetFunctionText();
1217 // FIN RECUPERATION FONCTION
1219 if (! myFunction.isEmpty()) {
1223 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1224 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1226 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1227 // item->text().toLatin1().constData());
1228 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1229 myFunction.toLatin1().constData());
1230 // FIN MAJ DE LA MAP
1235 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1237 return tr( "BLSURF_TITLE" );
1240 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1242 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1245 QString BLSURFPluginGUI_HypothesisCreator::type() const
1247 return tr( "BLSURF_HYPOTHESIS" );
1250 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1252 return "blsurf_hypo_page.html";
1255 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1258 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1260 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );