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>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Application.h>
57 #include <SALOME_ListIO.hxx>
58 #include <SALOME_ListIteratorOfListIO.hxx>
60 #include <GEOM_Client.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <SMESH_Gen_i.hxx>
63 #include <boost/shared_ptr.hpp>
64 #include <structmember.h>
66 // #include <GeomSelectionTools.h>
67 #define WITH_SIZE_BOUNDARIES
104 // SMP_ATTRACTOR_BTN,
113 /**************************************************
114 Begin initialization Python structures and objects
115 ***************************************************/
124 PyStdOut_dealloc(PyStdOut *self)
130 PyStdOut_write(PyStdOut *self, PyObject *args)
134 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
138 *(self->out)=*(self->out)+c;
144 static PyMethodDef PyStdOut_methods[] = {
145 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
146 PyDoc_STR("write(string) -> None")},
147 {NULL, NULL} /* sentinel */
150 static PyMemberDef PyStdOut_memberlist[] = {
151 {"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
152 "flag indicating that a space needs to be printed; used by print"},
153 {NULL} /* Sentinel */
156 static PyTypeObject PyStdOut_Type = {
157 /* The ob_type field must be initialized in the module init function
158 * to be portable to Windows without using C++. */
159 PyObject_HEAD_INIT(NULL)
162 sizeof(PyStdOut), /*tp_basicsize*/
165 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
172 0, /*tp_as_sequence*/
177 PyObject_GenericGetAttr, /*tp_getattro*/
178 /* softspace is writable: we must supply tp_setattro */
179 PyObject_GenericSetAttr, /* tp_setattro */
181 Py_TPFLAGS_DEFAULT, /*tp_flags*/
185 0, /*tp_richcompare*/
186 0, /*tp_weaklistoffset*/
189 PyStdOut_methods, /*tp_methods*/
190 PyStdOut_memberlist, /*tp_members*/
204 PyObject * newPyStdOut( std::string& out )
207 self = PyObject_New(PyStdOut, &PyStdOut_Type);
212 return (PyObject*)self;
215 /*************************************************
216 End initialization Python structures and objects
217 **************************************************/
220 * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
221 * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
224 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
225 : SMESHGUI_GenericHypothesisCreator( theHypType )
227 MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
228 this->mySMPMap.clear();
230 GeomToolSelected = NULL;
231 GeomToolSelected = getGeomSelectionTool();
233 aSel = GeomToolSelected->selectionMgr();
235 /* Initialize the Python interpreter */
236 if (not Py_IsInitialized())
237 throw ("Error: Python interpreter is not initialized");
238 PyGILState_STATE gstate;
239 gstate = PyGILState_Ensure();
242 main_mod = PyImport_AddModule("__main__");
245 main_dict = PyModule_GetDict(main_mod);
247 PyRun_SimpleString("from math import *");
248 PyGILState_Release(gstate);
252 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
257 * \brief {Get or create the geom selection tool for active study}
259 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
261 MESSAGE("BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool");
262 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
263 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
264 if (that->GeomToolSelected == NULL or that->GeomToolSelected->getMyStudy() != aStudy) {
265 MESSAGE("GeomToolSelected is created");
266 that->GeomToolSelected = new GeomSelectionTools(aStudy);
269 MESSAGE("GeomToolSelected already exists");
270 return that->GeomToolSelected;
274 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
275 QString str = theText.trimmed();
277 if ( !str.isEmpty() )
286 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
288 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
290 if ( !isDouble( myPhySize->text(), false )) {
291 if ( myPhySize->text().isEmpty() )
292 myPhySize->setText(tr("OBLIGATORY_VALUE"));
293 myPhySize->selectAll();
296 if ( !isDouble( myPhyMin->text(), true )) {
297 myPhyMin->selectAll();
300 if ( !isDouble( myPhyMax->text(), true )) {
301 myPhyMax->selectAll();
304 if ( !isDouble( myGeoMin->text(), true )) {
305 myGeoMin->selectAll();
308 if ( !isDouble( myGeoMin->text(), true )) {
309 myGeoMin->selectAll();
314 myOptionTable->setFocus();
315 QApplication::instance()->processEvents();
317 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
318 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
320 int row = 0, nbRows = myOptionTable->rowCount();
321 for ( ; row < nbRows; ++row )
323 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
324 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
325 if ( !value.isEmpty() ) {
327 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
329 catch ( const SALOME::SALOME_Exception& ex )
331 SUIT_MessageBox::critical( dlg(),
333 ex.details.text.in() );
338 h->SetOptionValues( myOptions ); // restore values
344 mySizeMapTable->setFocus();
345 QApplication::instance()->processEvents();
347 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
348 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
350 int row = 0, nbRows = mySizeMapTable->rowCount();
351 for ( ; row < nbRows; ++row )
353 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
354 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
355 if ( !sizeMap.isEmpty() ) {
356 if (that->sizeMapValidationFromRow(row))
359 const char* e = entry.toLatin1().constData();
360 const char* s = that->mySMPMap[entry].toLatin1().constData();
361 h->SetSizeMapEntry( e, s );
363 catch ( const SALOME::SALOME_Exception& ex )
365 SUIT_MessageBox::critical( dlg(),
367 ex.details.text.in() );
381 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
383 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
384 QFrame* fr = new QFrame( 0 );
385 QVBoxLayout* lay = new QVBoxLayout( fr );
387 lay->setSpacing( 0 );
390 QTabWidget* tab = new QTabWidget( fr );
391 tab->setTabShape( QTabWidget::Rounded );
392 tab->setTabPosition( QTabWidget::North );
393 lay->addWidget( tab );
396 myStdGroup = new QWidget();
397 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
398 aStdLayout->setSpacing( 6 );
399 aStdLayout->setMargin( 11 );
404 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
405 myName = new QLineEdit( myStdGroup );
406 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
409 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
410 myPhysicalMesh = new QComboBox( myStdGroup );
411 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
412 QStringList physicalTypes;
413 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
414 myPhysicalMesh->addItems( physicalTypes );
416 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
417 myPhySize = new QLineEdit( myStdGroup );
418 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
420 #ifdef WITH_SIZE_BOUNDARIES
421 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
422 myPhyMin = new QLineEdit( myStdGroup );
423 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
425 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
426 myPhyMax = new QLineEdit( myStdGroup );
427 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
430 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
431 myGeometricMesh = new QComboBox( myStdGroup );
432 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
434 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
435 myGeometricMesh->addItems( types );
437 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
438 myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
439 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
440 myAngleMeshS->setMinimum( 0 );
441 myAngleMeshS->setMaximum( 16 );
442 myAngleMeshS->setSingleStep( 0.5 );
444 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
445 myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
446 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
447 myAngleMeshC->setMinimum( 0 );
448 myAngleMeshC->setMaximum( 16 );
449 myAngleMeshC->setSingleStep( 0.5 );
451 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
452 myGradation = new QtxDoubleSpinBox( myStdGroup );
453 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
454 myGradation->setMinimum( 1.1 );
455 myGradation->setMaximum( 2.5 );
456 myGradation->setSingleStep( 0.1 );
458 #ifdef WITH_SIZE_BOUNDARIES
459 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
460 myGeoMin = new QLineEdit( myStdGroup );
461 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
463 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
464 myGeoMax = new QLineEdit( myStdGroup );
465 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
468 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
469 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
471 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
472 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
474 // advanced parameters
475 myAdvGroup = new QWidget();
476 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
477 anAdvLayout->setSpacing( 6 );
478 anAdvLayout->setMargin( 11 );
480 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
481 myTopology = new QComboBox( myAdvGroup );
482 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
483 QStringList topologyTypes;
484 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
485 myTopology->addItems( topologyTypes );
487 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
488 myVerbosity = new QSpinBox( myAdvGroup );
489 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
490 myVerbosity->setMinimum( 0 );
491 myVerbosity->setMaximum( 100 );
492 myVerbosity->setSingleStep( 5 );
494 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
495 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
497 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
498 myOptionTable->setHorizontalHeaderLabels( headers );
499 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
500 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
501 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
502 myOptionTable->verticalHeader()->hide();
503 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
505 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
506 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
507 addBtn->setMenu( new QMenu() );
509 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
510 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
512 anAdvLayout->setRowStretch( 4, 5 );
513 anAdvLayout->setColumnStretch( 1, 5 );
515 // Size Maps parameters
517 mySmpGroup = new QWidget();
518 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
520 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
521 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
522 QStringList sizeMapHeaders;
523 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
524 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
525 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
526 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
527 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
528 mySizeMapTable->setAlternatingRowColors(true);
529 mySizeMapTable->verticalHeader()->hide();
532 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
533 anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
535 QFrame *line = new QFrame(mySmpGroup);
536 line->setFrameShape(QFrame::HLine);
537 line->setFrameShadow(QFrame::Sunken);
538 anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
540 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
541 anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
543 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
544 anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
546 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
547 anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
549 QFrame *line2 = new QFrame(mySmpGroup);
550 line2->setFrameShape(QFrame::HLine);
551 line2->setFrameShadow(QFrame::Sunken);
552 anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
554 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
555 anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
559 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
560 tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
561 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
563 tab->setCurrentIndex( STD_TAB );
566 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
567 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
568 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
569 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
570 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
572 connect(addSurfaceButton, SIGNAL(clicked()), this, SLOT(onAddMapOnSurface()));
573 connect(addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddMapOnEdge()));
574 connect(addPointButton, SIGNAL(clicked()), this, SLOT(onAddMapOnPoint()));
575 connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
576 connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
581 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
583 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
584 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
586 BlsurfHypothesisData data;
587 that->readParamsFromHypo( data );
590 myName->setText( data.myName );
591 QFontMetrics metrics( myName->font() );
592 myName->setMinimumWidth( metrics.width( data.myName )+5 );
594 myTopology->setCurrentIndex( data.myTopology );
595 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
596 myPhySize->setText( data.myPhySize );
597 #ifdef WITH_SIZE_BOUNDARIES
598 myPhyMin->setText( data.myPhyMin );
599 myPhyMax->setText( data.myPhyMax );
600 myGeoMin->setText( data.myGeoMin );
601 myGeoMax->setText( data.myGeoMax );
603 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
604 myAngleMeshS->setValue( data.myAngleMeshS );
605 myAngleMeshC->setValue( data.myAngleMeshC );
606 myGradation->setValue( data.myGradation );
607 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
608 myDecimesh->setChecked( data.myDecimesh );
609 myVerbosity->setValue( data.myVerbosity );
611 if ( myOptions.operator->() ) {
612 printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
613 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
614 QString option = that->myOptions[i].in();
615 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
616 if ( name_value.count() > 1 ) {
617 QString idStr = QString("%1").arg( i );
618 int row = myOptionTable->rowCount();
619 myOptionTable->setRowCount( row+1 );
620 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
621 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
622 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
623 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
624 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
625 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
631 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
633 printf("retrieveParams():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
634 QMapIterator<QString, QString> i(that->mySMPMap);
635 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
636 while (i.hasNext()) {
638 const QString entry = i.key();
639 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
640 const QString sizeMap = i.value();
641 int row = mySizeMapTable->rowCount();
642 mySizeMapTable->setRowCount( row+1 );
643 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
644 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
645 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
646 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
647 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
648 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
653 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
654 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
657 that->onPhysicalMeshChanged();
658 that->onGeometricMeshChanged();
661 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
663 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
665 BlsurfHypothesisData data;
666 QString guiHyp = that->readParamsFromWidgets( data );
667 that->storeParamsToHypo( data );
672 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
674 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
675 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
676 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
678 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
679 h_data.myName = isCreation() && data ? hypName() : "";
681 h_data.myTopology = (int) h->GetTopology();
682 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
683 h_data.myPhySize = QString::number( h->GetPhySize() );
684 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
685 h_data.myAngleMeshS = h->GetAngleMeshS();
686 h_data.myAngleMeshC = h->GetAngleMeshC();
687 h_data.myGradation = h->GetGradation();
688 h_data.myAllowQuadrangles = h->GetQuadAllowed();
689 h_data.myDecimesh = h->GetDecimesh();
690 h_data.myVerbosity = h->GetVerbosity();
692 #ifdef WITH_SIZE_BOUNDARIES
693 double PhyMin = h->GetPhyMin();
694 double PhyMax = h->GetPhyMax();
695 double GeoMin = h->GetGeoMin();
696 double GeoMax = h->GetGeoMax();
698 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
699 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
700 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
701 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
704 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
705 that->myOptions = h->GetOptionValues();
707 that->mySMPMap.clear();
710 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
711 MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
712 QString fullSizeMaps;
713 QStringList fullSizeMapList;
714 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
715 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
716 fullSizeMaps = mySizeMaps[i].in();
717 MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
718 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
719 if ( fullSizeMapList.count() > 1 ) {
720 string fullSizeMap = fullSizeMapList[1].toStdString();
721 int pos = fullSizeMap.find("return")+7;
722 QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
723 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
724 MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
725 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShape(fullSizeMapList[0].toStdString()).ShapeType();
726 MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
732 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
733 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
735 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
736 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
737 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
738 if ( fullCustomSizeMapList.count() > 1 ) {
739 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
740 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShape(fullCustomSizeMapList[0].toStdString()).ShapeType();
741 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
742 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
747 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
748 MESSAGE("myAttractors->length() = " << allMyAttractors->length());
750 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
751 QString myAttractors = allMyAttractors[i].in();
752 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
753 if ( myAttractorList.count() > 1 ) {
754 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
755 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShape(myAttractorList[0].toStdString()).ShapeType();
756 MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
757 MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
764 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
766 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
767 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
768 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
774 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
776 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
777 h->SetTopology( (int) h_data.myTopology );
778 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
779 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
780 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
781 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
782 if ( h->GetGradation() != h_data.myGradation )
783 h->SetGradation( h_data.myGradation );
784 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
785 h->SetQuadAllowed( h_data.myAllowQuadrangles );
786 if ( h->GetDecimesh() != h_data.myDecimesh )
787 h->SetDecimesh( h_data.myDecimesh );
788 if ( h->GetVerbosity() != h_data.myVerbosity )
789 h->SetVerbosity( h_data.myVerbosity );
791 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
792 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
793 h->SetPhySize( h_data.myPhySize.toDouble() );
795 if( (int) h_data.myGeometricMesh == UserDefined ) {
796 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
797 h->SetAngleMeshS( h_data.myAngleMeshS );
798 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
799 h->SetAngleMeshC( h_data.myAngleMeshC );
801 #ifdef WITH_SIZE_BOUNDARIES
802 if ( !isDouble( h_data.myPhyMin ))
804 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
805 h->SetPhyMin( h_data.myPhyMin.toDouble() );
806 if ( !isDouble( h_data.myPhyMax ))
808 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
809 h->SetPhyMax( h_data.myPhyMax.toDouble() );
810 if ( !isDouble( h_data.myGeoMin ))
812 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
813 h->SetGeoMin( h_data.myGeoMin.toDouble() );
814 if ( !isDouble( h_data.myGeoMax ))
816 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
817 h->SetGeoMax( h_data.myGeoMax.toDouble() );
820 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
821 h->SetOptionValues( myOptions ); // is set in checkParams()
823 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
824 QMapIterator<QString,QString> i(that->mySMPMap);
825 // Iterate over each size map
826 while (i.hasNext()) {
828 const QString entry = i.key();
829 const QString sizeMap = i.value();
831 if (sizeMap == "__TO_DELETE__") {
832 MESSAGE("Delete entry " << entry.toStdString() << " from engine");
833 h->UnsetEntry(entry.toLatin1().constData());
835 else if (sizeMap.startsWith("ATTRACTOR")) {
836 MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
837 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
839 else if (sizeMap.startsWith("def")) {
840 MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
841 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
845 fullSizeMap = QString("");
846 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
847 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
848 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
849 fullSizeMap = QString("def f(t): return ") + sizeMap;
850 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
851 fullSizeMap = QString("def f(): return ") + sizeMap;
853 MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
854 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
858 catch(const SALOME::SALOME_Exception& ex)
860 SalomeApp_Tools::QtCatchCorbaException(ex);
866 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
868 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
869 h_data.myName = myName ? myName->text() : "";
870 h_data.myTopology = myTopology->currentIndex();
871 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
872 h_data.myPhySize = myPhySize->text();
873 #ifdef WITH_SIZE_BOUNDARIES
874 h_data.myPhyMin = myPhyMin->text();
875 h_data.myPhyMax = myPhyMax->text();
876 h_data.myGeoMin = myGeoMin->text();
877 h_data.myGeoMax = myGeoMax->text();
879 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
880 h_data.myAngleMeshS = myAngleMeshS->value();
881 h_data.myAngleMeshC = myAngleMeshC->value();
882 h_data.myGradation = myGradation->value();
883 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
884 h_data.myDecimesh = myDecimesh->isChecked();
885 h_data.myVerbosity = myVerbosity->value();
888 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
889 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
890 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
891 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
892 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
893 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
894 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
895 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
896 #ifdef WITH_SIZE_BOUNDARIES
897 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
898 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
899 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
900 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
903 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
904 int row = 0, nbRows = myOptionTable->rowCount();
905 for ( ; row < nbRows; ++row )
907 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
908 if ( id >= 0 && id < myOptions->length() )
910 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
911 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
912 if ( value.isNull() )
914 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
916 guiHyp += name + " = " + value + "; ";
921 row = 0, nbRows = mySizeMapTable->rowCount();
922 for ( ; row < nbRows; ++row )
924 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
925 if ( that->mySMPMap.contains(entry) )
926 guiHyp += entry + " = " + that->mySMPMap[entry] + "; ";
929 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
934 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
935 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
936 bool isCustom = ((myPhysicalMesh->currentIndex() == PhysicalUserDefined) || (myPhysicalMesh->currentIndex() == SizeMap)) ;
937 myPhySize->setEnabled(isCustom);
938 myPhyMax->setEnabled(isCustom);
939 myPhyMin->setEnabled(isCustom);
942 QString aPhySize = "";
943 switch( myPhysicalMesh->currentIndex() ) {
949 myPhySize->setText( aPhySize );
950 if ( !isDouble( myPhyMin->text(), true ))
951 myPhyMin->setText("");
952 if ( !isDouble( myPhyMax->text(), true ))
953 myPhyMax->setText("");
954 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
955 myGeometricMesh->setCurrentIndex( UserDefined );
956 onGeometricMeshChanged();
961 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
962 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
963 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
964 myAngleMeshS->setEnabled(isCustom);
965 myAngleMeshC->setEnabled(isCustom);
966 myGradation->setEnabled(isCustom);
967 myGeoMax->setEnabled(isCustom);
968 myGeoMin->setEnabled(isCustom);
971 double aAngleMeshS, aGradation;
972 switch( myGeometricMesh->currentIndex() ) {
979 myAngleMeshS->setValue( aAngleMeshS );
980 myAngleMeshC->setValue( aAngleMeshS );
981 myGradation->setValue( aGradation );
982 if ( !isDouble( myGeoMin->text(), true ))
983 myGeoMin->setText("");
984 if ( !isDouble( myGeoMax->text(), true ))
985 myGeoMax->setText("");
986 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
987 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
988 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
989 onPhysicalMeshChanged();
994 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
996 QMenu* menu = (QMenu*)sender();
997 // fill popup with option names
999 if ( myOptions.operator->() ) {
1000 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1001 QString name_value = myOptions[i].in();
1002 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1003 menu->addAction( name );
1008 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1010 myOptionTable->setFocus();
1011 QMenu* menu = (QMenu*)( a->parent() );
1013 int idx = menu->actions().indexOf( a );
1014 QString idStr = QString("%1").arg( idx );
1015 QString option = myOptions[idx].in();
1016 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1018 // look for a row with optionName
1019 int row = 0, nbRows = myOptionTable->rowCount();
1020 for ( ; row < nbRows; ++row )
1021 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1023 // add a row if not found
1024 if ( row == nbRows ) {
1025 myOptionTable->setRowCount( row+1 );
1026 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1027 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1028 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1029 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1030 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1031 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1032 Qt::ItemIsEditable |
1033 Qt::ItemIsEnabled );
1034 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1036 myOptionTable->clearSelection();
1037 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1038 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1039 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1040 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1043 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1045 // clear option values and remember selected row
1046 QList<int> selectedRows;
1047 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1048 QTableWidgetItem* item;
1049 foreach( item, selected ) {
1050 int row = item->row();
1051 if ( !selectedRows.contains( row ) ) {
1052 selectedRows.append( row );
1053 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1054 if ( id >= 0 && id < myOptions->length() )
1055 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1058 qSort( selectedRows );
1059 QListIterator<int> it( selectedRows );
1061 while ( it.hasPrevious() )
1062 myOptionTable->removeRow( it.previous() );
1065 // **********************
1066 // *** BEGIN SIZE MAP ***
1067 // **********************
1070 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1072 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1073 QList<int> selectedRows;
1074 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1075 QTableWidgetItem* item;
1077 foreach( item, selected ) {
1079 if ( !selectedRows.contains( row ) )
1080 selectedRows.append( row );
1083 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1085 qSort( selectedRows );
1086 QListIterator<int> it( selectedRows );
1088 while ( it.hasPrevious() ) {
1089 row = it.previous();
1090 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1091 if (that->mySMPMap.contains(entry))
1092 that->mySMPMap[entry] = "__TO_DELETE__";
1093 if (that->mySMPShapeTypeMap.contains(entry))
1094 that->mySMPShapeTypeMap.remove(entry);
1095 mySizeMapTable->removeRow(row );
1097 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1098 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1101 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1103 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1104 if (col == SMP_SIZEMAP_COLUMN) {
1105 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1106 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1107 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1108 MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1109 if (not that->mySMPShapeTypeMap.contains(entry))
1111 if (that->mySMPMap.contains(entry))
1112 if (that->mySMPMap[entry] == sizeMap)
1114 QColor* bgColor = new QColor("white");
1115 QColor* fgColor = new QColor("black");
1116 if (not sizeMap.isEmpty()) {
1117 that->mySMPMap[entry] = sizeMap;
1118 if (not sizeMapValidationFromRow(row)) {
1119 bgColor->setRgb(255,0,0);
1120 fgColor->setRgb(255,255,255);
1124 MESSAGE("Size map empty: reverse to precedent value" );
1125 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1127 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1128 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1129 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1130 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1131 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1135 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1137 insertElementType(TopAbs_FACE);
1140 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1142 insertElementType(TopAbs_EDGE);
1145 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1147 insertElementType(TopAbs_VERTEX);
1150 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1152 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1154 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1155 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1157 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1160 string entry, shapeName;
1161 // LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
1163 SALOME_ListIO ListSelectedObjects;
1164 aSel->selectedObjects(ListSelectedObjects, NULL, false );
1165 if (!ListSelectedObjects.IsEmpty())
1167 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1168 GeomSelectionTools* myGeomToolSelected = getGeomSelectionTool();
1169 for (; Object_It.More(); Object_It.Next())
1171 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1172 entry = myGeomToolSelected->getEntryOfObject(anObject);
1173 shapeName = anObject->getName();
1174 S = myGeomToolSelected->entryToShape(entry);
1175 if ((! S.IsNull()) && (S.ShapeType() == typeShapeAsked))
1177 mySizeMapTable->setFocus();
1179 shapeEntry = QString::fromStdString(entry);
1180 double phySize = h->GetPhySize();
1181 std::ostringstream oss;
1184 sizeMap = QString::fromStdString(oss.str());
1185 if (that->mySMPMap.contains(shapeEntry)) {
1186 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1187 MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1191 that->mySMPMap[shapeEntry] = sizeMap;
1192 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1193 int row = mySizeMapTable->rowCount() ;
1194 mySizeMapTable->setRowCount( row+1 );
1195 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1196 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1197 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1198 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1199 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1200 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1201 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1202 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1203 mySizeMapTable->clearSelection();
1204 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1206 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1207 myPhysicalMesh->setCurrentIndex( SizeMap );
1208 onPhysicalMeshChanged();
1215 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1217 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
1218 int row = 0, nbRows = mySizeMapTable->rowCount();
1219 for ( ; row < nbRows; ++row )
1220 if (not sizeMapValidationFromRow(row))
1225 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1227 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
1228 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1229 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1230 mySizeMapTable->setFocus();
1234 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1236 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
1238 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1240 if (not that->mySMPMap.contains(myEntry)) {
1241 MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
1244 if (not that->mySMPShapeTypeMap.contains(myEntry)) {
1245 MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
1251 if (that->mySMPMap[myEntry].startsWith("def")) {
1252 MESSAGE("custom function" );
1253 expr = that->mySMPMap[myEntry].toStdString();
1255 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1256 MESSAGE("Attractor" );
1257 // if ((that->mySMPMap[myEntry].count(QRegExp("ATTRACTOR([0-9])")) != 1))
1258 if ((that->mySMPMap[myEntry].count('(') != 1) or
1259 (that->mySMPMap[myEntry].count(')') != 1) or
1260 (that->mySMPMap[myEntry].count(';') != 4) or
1261 (that->mySMPMap[myEntry].size() == 15)){
1263 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b)" );
1269 // case size map is empty
1270 if (that->mySMPMap[myEntry].isEmpty()) {
1272 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1276 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1277 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1278 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1279 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1280 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1281 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1283 //assert(Py_IsInitialized());
1284 if (not Py_IsInitialized())
1285 throw ("Erreur: Python interpreter is not initialized");
1286 PyGILState_STATE gstate;
1287 gstate = PyGILState_Ensure();
1289 PyObject * obj = NULL;
1290 PyObject* new_stderr = NULL;
1291 string err_description="";
1292 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1296 new_stderr=newPyStdOut(err_description);
1297 PySys_SetObject("stderr", new_stderr);
1299 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1300 Py_DECREF(new_stderr);
1302 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1303 PyGILState_Release(gstate);
1308 PyObject * func = NULL;
1309 func = PyObject_GetAttrString(main_mod, "f");
1313 new_stderr=newPyStdOut(err_description);
1314 PySys_SetObject("stderr", new_stderr);
1316 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1317 Py_DECREF(new_stderr);
1319 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1320 PyGILState_Release(gstate);
1324 PyGILState_Release(gstate);
1326 MESSAGE("SizeMap expression "<<expr<<" is valid");
1332 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1333 int myRow = index->row();
1334 int myColumn = index->column();
1338 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1339 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1342 // myEditor->show();
1343 // myEditor->raise();
1344 // myEditor->activateWindow();
1347 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1348 // myEditor->exec();
1349 QString myFunction = myEditor->GetFunctionText();
1350 // FIN RECUPERATION FONCTION
1352 if (! myFunction.isEmpty()) {
1356 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1357 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1359 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1360 // item->text().toLatin1().constData());
1361 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1362 myFunction.toLatin1().constData());
1363 // FIN MAJ DE LA MAP
1368 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1370 return tr( "BLSURF_TITLE" );
1373 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1375 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1378 QString BLSURFPluginGUI_HypothesisCreator::type() const
1380 return tr( "BLSURF_HYPOTHESIS" );
1383 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1385 return "blsurf_hypo_page.html";
1388 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1391 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1393 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );