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 aSel = GeomToolSelected->selectionMgr();
216 /* Initialize the Python interpreter */
217 //assert(Py_IsInitialized());
218 if (not Py_IsInitialized())
219 throw ("Erreur: Python interpreter is not initialized");
220 PyGILState_STATE gstate;
221 gstate = PyGILState_Ensure();
224 main_mod = PyImport_AddModule("__main__");
227 main_dict = PyModule_GetDict(main_mod);
229 PyRun_SimpleString("from math import *");
230 PyGILState_Release(gstate);
234 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
238 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
240 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
241 if (that->GeomToolSelected == NULL) {
242 cout << "GeomToolSelected is created" << endl;
243 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
244 that->GeomToolSelected = new GeomSelectionTools(aStudy);
246 return that->GeomToolSelected;
250 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
251 QString str = theText.trimmed();
253 if ( !str.isEmpty() )
261 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
263 cout << "BLSURFPluginGUI_HypothesisCreator::checkParams" << endl;
265 if ( !isDouble( myPhySize->text(), false )) {
266 if ( myPhySize->text().isEmpty() )
267 myPhySize->setText(tr("OBLIGATORY_VALUE"));
268 myPhySize->selectAll();
271 if ( !isDouble( myPhyMin->text(), true )) {
272 myPhyMin->selectAll();
275 if ( !isDouble( myPhyMax->text(), true )) {
276 myPhyMax->selectAll();
279 if ( !isDouble( myGeoMin->text(), true )) {
280 myGeoMin->selectAll();
283 if ( !isDouble( myGeoMin->text(), true )) {
284 myGeoMin->selectAll();
289 myOptionTable->setFocus();
290 QApplication::instance()->processEvents();
292 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
293 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
295 int row = 0, nbRows = myOptionTable->rowCount();
296 for ( ; row < nbRows; ++row )
298 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
299 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
300 if ( !value.isEmpty() ) {
302 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
304 catch ( const SALOME::SALOME_Exception& ex )
306 SUIT_MessageBox::critical( dlg(),
308 ex.details.text.in() );
313 h->SetOptionValues( myOptions ); // restore values
319 mySizeMapTable->setFocus();
320 QApplication::instance()->processEvents();
322 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
323 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
325 int row = 0, nbRows = mySizeMapTable->rowCount();
326 for ( ; row < nbRows; ++row )
328 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
329 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
330 if ( !sizeMap.isEmpty() ) {
331 if (that->sizeMapValidationFromRow(row))
334 const char* e = entry.toLatin1().constData();
335 const char* s = that->mySMPMap[entry].toLatin1().constData();
336 h->SetSizeMapEntry( e, s );
338 catch ( const SALOME::SALOME_Exception& ex )
340 SUIT_MessageBox::critical( dlg(),
342 ex.details.text.in() );
356 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
358 cout << "BLSURFPluginGUI_HypothesisCreator::buildFrame" << endl;
359 QFrame* fr = new QFrame( 0 );
360 QVBoxLayout* lay = new QVBoxLayout( fr );
362 lay->setSpacing( 0 );
365 QTabWidget* tab = new QTabWidget( fr );
366 tab->setTabShape( QTabWidget::Rounded );
367 tab->setTabPosition( QTabWidget::North );
368 lay->addWidget( tab );
371 myStdGroup = new QWidget();
372 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
373 aStdLayout->setSpacing( 6 );
374 aStdLayout->setMargin( 11 );
379 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
380 myName = new QLineEdit( myStdGroup );
381 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
384 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
385 myPhysicalMesh = new QComboBox( myStdGroup );
386 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
387 QStringList physicalTypes;
388 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
389 myPhysicalMesh->addItems( physicalTypes );
391 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
392 myPhySize = new QLineEdit( myStdGroup );
393 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
395 #ifdef WITH_SIZE_BOUNDARIES
396 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
397 myPhyMin = new QLineEdit( myStdGroup );
398 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
400 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
401 myPhyMax = new QLineEdit( myStdGroup );
402 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
405 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
406 myGeometricMesh = new QComboBox( myStdGroup );
407 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
409 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
410 myGeometricMesh->addItems( types );
412 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
413 myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
414 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
415 myAngleMeshS->setMinimum( 0 );
416 myAngleMeshS->setMaximum( 16 );
417 myAngleMeshS->setSingleStep( 0.5 );
419 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
420 myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
421 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
422 myAngleMeshC->setMinimum( 0 );
423 myAngleMeshC->setMaximum( 16 );
424 myAngleMeshC->setSingleStep( 0.5 );
426 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
427 myGradation = new QtxDoubleSpinBox( myStdGroup );
428 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
429 myGradation->setMinimum( 1.1 );
430 myGradation->setMaximum( 2.5 );
431 myGradation->setSingleStep( 0.1 );
433 #ifdef WITH_SIZE_BOUNDARIES
434 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
435 myGeoMin = new QLineEdit( myStdGroup );
436 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
438 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
439 myGeoMax = new QLineEdit( myStdGroup );
440 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
443 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
444 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
446 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
447 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
449 // advanced parameters
450 myAdvGroup = new QWidget();
451 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
452 anAdvLayout->setSpacing( 6 );
453 anAdvLayout->setMargin( 11 );
455 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
456 myTopology = new QComboBox( myAdvGroup );
457 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
458 QStringList topologyTypes;
459 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
460 myTopology->addItems( topologyTypes );
462 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
463 myVerbosity = new QSpinBox( myAdvGroup );
464 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
465 myVerbosity->setMinimum( 0 );
466 myVerbosity->setMaximum( 100 );
467 myVerbosity->setSingleStep( 5 );
469 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
470 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
472 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
473 myOptionTable->setHorizontalHeaderLabels( headers );
474 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
475 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
476 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
477 myOptionTable->verticalHeader()->hide();
478 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
480 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
481 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
482 addBtn->setMenu( new QMenu() );
484 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
485 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
487 anAdvLayout->setRowStretch( 4, 5 );
488 anAdvLayout->setColumnStretch( 1, 5 );
490 // Size Maps parameters
492 mySmpGroup = new QWidget();
493 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
495 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
496 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
497 QStringList sizeMapHeaders;
498 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
499 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
500 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
501 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
502 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
503 mySizeMapTable->setAlternatingRowColors(true);
504 mySizeMapTable->verticalHeader()->hide();
506 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
507 anSmpLayout->addWidget(addAttractorButton, 1, 1, 1, 1);
509 QFrame *line = new QFrame(mySmpGroup);
510 line->setFrameShape(QFrame::HLine);
511 line->setFrameShadow(QFrame::Sunken);
512 anSmpLayout->addWidget(line, 2, 1, 1, 1);
514 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
515 anSmpLayout->addWidget(addSurfaceButton, 3, 1, 1, 1);
517 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
518 anSmpLayout->addWidget(addEdgeButton, 4, 1, 1, 1);
520 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
521 anSmpLayout->addWidget(addPointButton, 5, 1, 1, 1);
523 QFrame *line2 = new QFrame(mySmpGroup);
524 line2->setFrameShape(QFrame::HLine);
525 line2->setFrameShadow(QFrame::Sunken);
526 anSmpLayout->addWidget(line2, 6, 1, 1, 1);
528 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
529 anSmpLayout->addWidget(removeButton, 7, 1, 1, 1);
533 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
534 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
535 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
537 tab->setCurrentIndex( STD_TAB );
540 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
541 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
542 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
543 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
544 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
546 connect(addSurfaceButton, SIGNAL(clicked()), this, SLOT(onAddMapOnSurface()));
547 connect(addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddMapOnEdge()));
548 connect(addPointButton, SIGNAL(clicked()), this, SLOT(onAddMapOnPoint()));
549 connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
550 connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
552 // connect(tab, SIGNAL(currentChanged ( int )),this,SLOT (onSetSelectionFilter(int)));
558 void BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(int page)
560 cout << "BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(" << page << ")" << endl;
561 aSel->clearFilters();
562 if (page == SMP_TAB) {
563 cout << "Page is SIZEMAP" << endl;
564 aSel = GeomToolSelected->selectionMgr();
568 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
570 cout << "BLSURFPluginGUI_HypothesisCreator::retrieveParams" << endl;
571 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
573 BlsurfHypothesisData data;
574 that->readParamsFromHypo( data );
577 myName->setText( data.myName );
578 QFontMetrics metrics( myName->font() );
579 myName->setMinimumWidth( metrics.width( data.myName )+5 );
581 myTopology->setCurrentIndex( data.myTopology );
582 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
583 myPhySize->setText( data.myPhySize );
584 #ifdef WITH_SIZE_BOUNDARIES
585 myPhyMin->setText( data.myPhyMin );
586 myPhyMax->setText( data.myPhyMax );
587 myGeoMin->setText( data.myGeoMin );
588 myGeoMax->setText( data.myGeoMax );
590 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
591 myAngleMeshS->setValue( data.myAngleMeshS );
592 myAngleMeshC->setValue( data.myAngleMeshC );
593 myGradation->setValue( data.myGradation );
594 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
595 myDecimesh->setChecked( data.myDecimesh );
596 myVerbosity->setValue( data.myVerbosity );
598 if ( myOptions.operator->() ) {
599 printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
600 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
601 QString option = that->myOptions[i].in();
602 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
603 if ( name_value.count() > 1 ) {
604 QString idStr = QString("%1").arg( i );
605 int row = myOptionTable->rowCount();
606 myOptionTable->setRowCount( row+1 );
607 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
608 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
609 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
610 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
611 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
612 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
618 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
620 printf("retrieveParams():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
621 QMapIterator<QString, QString> i(that->mySMPMap);
622 while (i.hasNext()) {
624 const QString entry = i.key();
625 string shapeName = GeomToolSelected->getNameFromEntry(entry.toStdString());
626 const QString sizeMap = i.value();
627 int row = mySizeMapTable->rowCount();
628 mySizeMapTable->setRowCount( row+1 );
629 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
630 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
631 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
632 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
633 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
634 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
639 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
640 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
643 that->onPhysicalMeshChanged();
644 that->onGeometricMeshChanged();
647 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
649 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
651 BlsurfHypothesisData data;
652 QString guiHyp = that->readParamsFromWidgets( data );
653 that->storeParamsToHypo( data );
655 //cout<<"BLSURFPluginGUI_HypothesisCreator::storeParams(), guiHyp: "<<endl<<guiHyp.toStdString()<<endl;
659 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
661 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo" << endl;
662 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
663 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
665 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
666 h_data.myName = isCreation() && data ? hypName() : "";
668 h_data.myTopology = (int) h->GetTopology();
669 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
670 h_data.myPhySize = QString::number( h->GetPhySize() );
671 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
672 h_data.myAngleMeshS = h->GetAngleMeshS();
673 h_data.myAngleMeshC = h->GetAngleMeshC();
674 h_data.myGradation = h->GetGradation();
675 h_data.myAllowQuadrangles = h->GetQuadAllowed();
676 h_data.myDecimesh = h->GetDecimesh();
677 h_data.myVerbosity = h->GetVerbosity();
679 #ifdef WITH_SIZE_BOUNDARIES
680 double PhyMin = h->GetPhyMin();
681 double PhyMax = h->GetPhyMax();
682 double GeoMin = h->GetGeoMin();
683 double GeoMax = h->GetGeoMax();
685 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
686 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
687 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
688 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
691 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
692 that->myOptions = h->GetOptionValues();
694 that->mySMPMap.clear();
697 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
698 cout << "mySizeMaps->length() = " << mySizeMaps->length() << endl;
700 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
701 QString fullSizeMaps = mySizeMaps[i].in();
702 QStringList fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
703 if ( fullSizeMapList.count() > 1 ) {
704 string fullSizeMap = fullSizeMapList[1].toStdString();
705 int pos = fullSizeMap.find("return")+7;
706 QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
707 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
708 that->mySMPShapeTypeMap[fullSizeMapList[0]] = GeomToolSelected->entryToShape(fullSizeMapList[0].toStdString()).ShapeType();
709 MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
710 MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
716 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
717 cout << "myCustomSizeMaps->length() = " << myCustomSizeMaps->length() << endl;
719 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
720 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
721 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
722 if ( fullCustomSizeMapList.count() > 1 ) {
723 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
724 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShape(fullCustomSizeMapList[0].toStdString()).ShapeType();
725 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
726 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
731 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
732 cout << "myAttractors->length() = " << allMyAttractors->length() << endl;
734 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
735 QString myAttractors = allMyAttractors[i].in();
736 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
737 if ( myAttractorList.count() > 1 ) {
738 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
739 that->mySMPShapeTypeMap[myAttractorList[0]] = GeomToolSelected->entryToShape(myAttractorList[0].toStdString()).ShapeType();
740 MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
741 MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
748 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
750 cout << "BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo" << endl;
751 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
752 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
758 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
760 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
761 h->SetTopology( (int) h_data.myTopology );
762 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
763 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
764 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
765 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
766 if ( h->GetGradation() != h_data.myGradation )
767 h->SetGradation( h_data.myGradation );
768 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
769 h->SetQuadAllowed( h_data.myAllowQuadrangles );
770 if ( h->GetDecimesh() != h_data.myDecimesh )
771 h->SetDecimesh( h_data.myDecimesh );
772 if ( h->GetVerbosity() != h_data.myVerbosity )
773 h->SetVerbosity( h_data.myVerbosity );
775 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
776 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
777 h->SetPhySize( h_data.myPhySize.toDouble() );
779 if( (int) h_data.myGeometricMesh == UserDefined ) {
780 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
781 h->SetAngleMeshS( h_data.myAngleMeshS );
782 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
783 h->SetAngleMeshC( h_data.myAngleMeshC );
785 #ifdef WITH_SIZE_BOUNDARIES
786 if ( !isDouble( h_data.myPhyMin ))
788 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
789 h->SetPhyMin( h_data.myPhyMin.toDouble() );
790 if ( !isDouble( h_data.myPhyMax ))
792 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
793 h->SetPhyMax( h_data.myPhyMax.toDouble() );
794 if ( !isDouble( h_data.myGeoMin ))
796 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
797 h->SetGeoMin( h_data.myGeoMin.toDouble() );
798 if ( !isDouble( h_data.myGeoMax ))
800 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
801 h->SetGeoMax( h_data.myGeoMax.toDouble() );
804 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
805 h->SetOptionValues( myOptions ); // is set in checkParams()
807 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
808 QMapIterator<QString,QString> i(that->mySMPMap);
809 // Iterate over each size map
810 while (i.hasNext()) {
812 const QString entry = i.key();
813 const QString sizeMap = i.value();
816 if (not that->sizeMapValidationFromEntry(entry,false)) {
817 cout << "Size map for entry " << entry.toStdString() << " is not valid" << endl;
822 if (sizeMap == "__TO_DELETE__") {
823 cout << "Delete entry " << entry.toStdString() << " from engine" << endl;
824 h->UnsetEntry(entry.toLatin1().constData());
826 else if (sizeMap.startsWith("ATTRACTOR")) {
827 cout << "SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
828 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
830 else if (sizeMap.startsWith("def")) {
831 cout << "SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
832 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
836 fullSizeMap = QString("");
837 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
838 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
839 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
840 fullSizeMap = QString("def f(t): return ") + sizeMap;
841 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
842 fullSizeMap = QString("def f(): return ") + sizeMap;
844 cout << "SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString() << endl;
845 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
849 catch(const SALOME::SALOME_Exception& ex)
851 SalomeApp_Tools::QtCatchCorbaException(ex);
857 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
859 cout << "BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets" << endl;
860 h_data.myName = myName ? myName->text() : "";
861 h_data.myTopology = myTopology->currentIndex();
862 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
863 h_data.myPhySize = myPhySize->text();
864 #ifdef WITH_SIZE_BOUNDARIES
865 h_data.myPhyMin = myPhyMin->text();
866 h_data.myPhyMax = myPhyMax->text();
867 h_data.myGeoMin = myGeoMin->text();
868 h_data.myGeoMax = myGeoMax->text();
870 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
871 h_data.myAngleMeshS = myAngleMeshS->value();
872 h_data.myAngleMeshC = myAngleMeshC->value();
873 h_data.myGradation = myGradation->value();
874 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
875 h_data.myDecimesh = myDecimesh->isChecked();
876 h_data.myVerbosity = myVerbosity->value();
879 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
880 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
881 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
882 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
883 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
884 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
885 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
886 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
887 #ifdef WITH_SIZE_BOUNDARIES
888 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
889 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
890 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
891 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
894 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
895 int row = 0, nbRows = myOptionTable->rowCount();
896 for ( ; row < nbRows; ++row )
898 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
899 if ( id >= 0 && id < myOptions->length() )
901 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
902 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
903 if ( value.isNull() )
905 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
907 guiHyp += name + " = " + value + "; ";
912 row = 0, nbRows = mySizeMapTable->rowCount();
913 for ( ; row < nbRows; ++row )
915 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
916 if ( that->mySMPMap.contains(entry) )
917 guiHyp += entry + " = " + that->mySMPMap[entry] + "; ";
920 cout << "guiHyp : " << guiHyp.toLatin1().data() << endl;
925 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
926 cout << "BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged" << endl;
927 bool isCustom = ((myPhysicalMesh->currentIndex() == PhysicalUserDefined) || (myPhysicalMesh->currentIndex() == SizeMap)) ;
928 myPhySize->setEnabled(isCustom);
929 myPhyMax->setEnabled(isCustom);
930 myPhyMin->setEnabled(isCustom);
933 QString aPhySize = "";
934 switch( myPhysicalMesh->currentIndex() ) {
940 myPhySize->setText( aPhySize );
941 if ( !isDouble( myPhyMin->text(), true ))
942 myPhyMin->setText("");
943 if ( !isDouble( myPhyMax->text(), true ))
944 myPhyMax->setText("");
945 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
946 myGeometricMesh->setCurrentIndex( UserDefined );
947 onGeometricMeshChanged();
952 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
953 cout << "BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged" << endl;
954 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
955 myAngleMeshS->setEnabled(isCustom);
956 myAngleMeshC->setEnabled(isCustom);
957 myGradation->setEnabled(isCustom);
958 myGeoMax->setEnabled(isCustom);
959 myGeoMin->setEnabled(isCustom);
962 double aAngleMeshS, aGradation;
963 switch( myGeometricMesh->currentIndex() ) {
970 myAngleMeshS->setValue( aAngleMeshS );
971 myAngleMeshC->setValue( aAngleMeshS );
972 myGradation->setValue( aGradation );
973 if ( !isDouble( myGeoMin->text(), true ))
974 myGeoMin->setText("");
975 if ( !isDouble( myGeoMax->text(), true ))
976 myGeoMax->setText("");
977 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
978 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
979 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
980 onPhysicalMeshChanged();
985 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
987 QMenu* menu = (QMenu*)sender();
988 // fill popup with option names
990 if ( myOptions.operator->() ) {
991 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
992 QString name_value = myOptions[i].in();
993 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
994 menu->addAction( name );
999 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1001 myOptionTable->setFocus();
1002 QMenu* menu = (QMenu*)( a->parent() );
1004 int idx = menu->actions().indexOf( a );
1005 QString idStr = QString("%1").arg( idx );
1006 QString option = myOptions[idx].in();
1007 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1009 // look for a row with optionName
1010 int row = 0, nbRows = myOptionTable->rowCount();
1011 for ( ; row < nbRows; ++row )
1012 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1014 // add a row if not found
1015 if ( row == nbRows ) {
1016 myOptionTable->setRowCount( row+1 );
1017 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1018 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1019 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1020 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1021 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1022 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1023 Qt::ItemIsEditable |
1024 Qt::ItemIsEnabled );
1025 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1027 myOptionTable->clearSelection();
1028 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1029 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1030 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1031 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1034 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1036 // clear option values and remember selected row
1037 QList<int> selectedRows;
1038 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1039 QTableWidgetItem* item;
1040 foreach( item, selected ) {
1041 int row = item->row();
1042 if ( !selectedRows.contains( row ) ) {
1043 selectedRows.append( row );
1044 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1045 if ( id >= 0 && id < myOptions->length() )
1046 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1049 qSort( selectedRows );
1050 QListIterator<int> it( selectedRows );
1052 while ( it.hasPrevious() )
1053 myOptionTable->removeRow( it.previous() );
1056 // **********************
1057 // *** BEGIN SIZE MAP ***
1058 // **********************
1061 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1063 cout<<"BLSURFPluginGUI_HypothesisCreator::onRemoveMap()"<<endl;
1064 QList<int> selectedRows;
1065 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1066 QTableWidgetItem* item;
1068 foreach( item, selected ) {
1070 if ( !selectedRows.contains( row ) )
1071 selectedRows.append( row );
1074 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1076 qSort( selectedRows );
1077 QListIterator<int> it( selectedRows );
1079 while ( it.hasPrevious() ) {
1080 row = it.previous();
1081 cout << "delete row #"<< row <<endl;
1082 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1083 if (that->mySMPMap.contains(entry))
1084 that->mySMPMap[entry] = "__TO_DELETE__";
1085 if (that->mySMPShapeTypeMap.contains(entry))
1086 that->mySMPShapeTypeMap.remove(entry);
1087 mySizeMapTable->removeRow(row );
1089 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1090 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1093 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1095 cout<<"BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")"<<endl;
1096 if (col == SMP_SIZEMAP_COLUMN) {
1097 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1098 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1099 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1100 cout << "entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString() << endl;
1101 if (not that->mySMPShapeTypeMap.contains(entry))
1103 if (that->mySMPMap.contains(entry))
1104 if (that->mySMPMap[entry] == sizeMap)
1106 QColor* bgColor = new QColor("white");
1107 QColor* fgColor = new QColor("black");
1108 if (not sizeMap.isEmpty()) {
1109 that->mySMPMap[entry] = sizeMap;
1110 if (not sizeMapValidationFromRow(row)) {
1111 bgColor->setRgb(255,0,0);
1112 fgColor->setRgb(255,255,255);
1116 cout << "Size map empty: reverse to precedent value" << endl;
1117 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1119 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1120 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1121 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1122 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1123 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1127 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1129 insertElementType(TopAbs_FACE);
1132 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1134 insertElementType(TopAbs_EDGE);
1137 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1139 insertElementType(TopAbs_VERTEX);
1142 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1144 cout<<"BLSURFPluginGUI_HypothesisCreator::insertElementType()"<<endl;
1146 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1147 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1149 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1152 string entry, shapeName;
1153 // LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
1155 SALOME_ListIO ListSelectedObjects;
1156 aSel->selectedObjects(ListSelectedObjects, NULL, false );
1157 if (!ListSelectedObjects.IsEmpty())
1159 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1160 for (; Object_It.More(); Object_It.Next())
1162 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1163 entry = GeomToolSelected->getEntryOfObject(anObject);
1164 shapeName = anObject->getName();
1165 S = GeomToolSelected->entryToShape(entry);
1166 if ((! S.IsNull()) && (S.ShapeType() == typeShapeAsked))
1168 mySizeMapTable->setFocus();
1170 shapeEntry = QString::fromStdString(entry);
1171 double phySize = h->GetPhySize();
1172 std::ostringstream oss;
1175 sizeMap = QString::fromStdString(oss.str());
1176 if (that->mySMPMap.contains(shapeEntry)) {
1177 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1178 MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1182 that->mySMPMap[shapeEntry] = sizeMap;
1183 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1184 int row = mySizeMapTable->rowCount() ;
1185 mySizeMapTable->setRowCount( row+1 );
1186 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1187 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1188 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1189 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1190 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1191 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1192 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1193 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1194 mySizeMapTable->clearSelection();
1195 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1197 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1198 myPhysicalMesh->setCurrentIndex( SizeMap );
1199 onPhysicalMeshChanged();
1206 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1208 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()"<<endl;
1209 int row = 0, nbRows = mySizeMapTable->rowCount();
1210 for ( ; row < nbRows; ++row )
1211 if (not sizeMapValidationFromRow(row))
1216 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1218 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()"<<endl;
1219 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1220 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1221 mySizeMapTable->setFocus();
1225 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1227 cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()"<<endl;
1229 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1231 if (not that->mySMPMap.contains(myEntry)) {
1232 cout<<"Geometry with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1235 if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1236 cout<<"Shape type with entry "<<myEntry.toStdString()<<" was not found."<<endl;
1242 if (that->mySMPMap[myEntry].startsWith("def")) {
1243 cout << "custom function" << endl;
1244 expr = that->mySMPMap[myEntry].toStdString();
1246 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1247 cout << "Attractor" << endl;
1248 // if ((that->mySMPMap[myEntry].count(QRegExp("ATTRACTOR([0-9])")) != 1))
1249 if ((that->mySMPMap[myEntry].count('(') != 1) or
1250 (that->mySMPMap[myEntry].count(')') != 1) or
1251 (that->mySMPMap[myEntry].count(';') != 4) or
1252 (that->mySMPMap[myEntry].size() == 15)){
1254 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b)" );
1260 // case size map is empty
1261 if (that->mySMPMap[myEntry].isEmpty()) {
1263 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1267 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1268 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1269 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1270 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1271 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1272 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1274 //assert(Py_IsInitialized());
1275 if (not Py_IsInitialized())
1276 throw ("Erreur: Python interpreter is not initialized");
1277 PyGILState_STATE gstate;
1278 gstate = PyGILState_Ensure();
1280 PyObject * obj = NULL;
1281 PyObject* new_stderr = NULL;
1282 string err_description="";
1283 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1287 new_stderr=newPyStdOut(err_description);
1288 PySys_SetObject("stderr", new_stderr);
1290 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1291 Py_DECREF(new_stderr);
1293 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1294 PyGILState_Release(gstate);
1299 PyObject * func = NULL;
1300 func = PyObject_GetAttrString(main_mod, "f");
1304 new_stderr=newPyStdOut(err_description);
1305 PySys_SetObject("stderr", new_stderr);
1307 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1308 Py_DECREF(new_stderr);
1310 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1311 PyGILState_Release(gstate);
1315 PyGILState_Release(gstate);
1317 cout<<"SizeMap expression "<<expr<<" is valid"<<endl;
1323 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1324 int myRow = index->row();
1325 int myColumn = index->column();
1329 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1330 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1333 // myEditor->show();
1334 // myEditor->raise();
1335 // myEditor->activateWindow();
1338 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1339 // myEditor->exec();
1340 QString myFunction = myEditor->GetFunctionText();
1341 // FIN RECUPERATION FONCTION
1343 if (! myFunction.isEmpty()) {
1347 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1348 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1350 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1351 // item->text().toLatin1().constData());
1352 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1353 myFunction.toLatin1().constData());
1354 // FIN MAJ DE LA MAP
1359 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1361 return tr( "BLSURF_TITLE" );
1364 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1366 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1369 QString BLSURFPluginGUI_HypothesisCreator::type() const
1371 return tr( "BLSURF_HYPOTHESIS" );
1374 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1376 return "blsurf_hypo_page.html";
1379 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1382 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1384 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );