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 (! 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 MESSAGE("aStudy->StudyId(): " << aStudy->StudyId());
265 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
266 MESSAGE("GeomToolSelected is created");
267 that->GeomToolSelected = new GeomSelectionTools(aStudy);
270 MESSAGE("GeomToolSelected already exists");
271 MESSAGE("that->GeomToolSelected->getMyStudy()->StudyId(): " << that->GeomToolSelected->getMyStudy()->StudyId());
272 return that->GeomToolSelected;
276 inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
277 QString str = theText.trimmed();
279 if ( !str.isEmpty() )
288 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
290 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
292 if ( !isDouble( myPhySize->text(), false )) {
293 if ( myPhySize->text().isEmpty() )
294 myPhySize->setText(tr("OBLIGATORY_VALUE"));
295 myPhySize->selectAll();
298 if ( !isDouble( myPhyMin->text(), true )) {
299 myPhyMin->selectAll();
302 if ( !isDouble( myPhyMax->text(), true )) {
303 myPhyMax->selectAll();
306 if ( !isDouble( myGeoMin->text(), true )) {
307 myGeoMin->selectAll();
310 if ( !isDouble( myGeoMin->text(), true )) {
311 myGeoMin->selectAll();
316 myOptionTable->setFocus();
317 QApplication::instance()->processEvents();
319 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
320 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
322 int row = 0, nbRows = myOptionTable->rowCount();
323 for ( ; row < nbRows; ++row )
325 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
326 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
327 if ( !value.isEmpty() ) {
329 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
331 catch ( const SALOME::SALOME_Exception& ex )
333 SUIT_MessageBox::critical( dlg(),
335 ex.details.text.in() );
340 h->SetOptionValues( myOptions ); // restore values
346 mySizeMapTable->setFocus();
347 QApplication::instance()->processEvents();
349 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h = BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
350 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
352 int row = 0, nbRows = mySizeMapTable->rowCount();
353 for ( ; row < nbRows; ++row )
355 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
356 QString sizeMap = mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->text().trimmed();
357 if ( !sizeMap.isEmpty() ) {
358 if (that->sizeMapValidationFromRow(row))
361 const char* e = entry.toLatin1().constData();
362 const char* s = that->mySMPMap[entry].toLatin1().constData();
363 h->SetSizeMapEntry( e, s );
365 catch ( const SALOME::SALOME_Exception& ex )
367 SUIT_MessageBox::critical( dlg(),
369 ex.details.text.in() );
383 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
385 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
386 QFrame* fr = new QFrame( 0 );
387 QVBoxLayout* lay = new QVBoxLayout( fr );
389 lay->setSpacing( 0 );
392 QTabWidget* tab = new QTabWidget( fr );
393 tab->setTabShape( QTabWidget::Rounded );
394 tab->setTabPosition( QTabWidget::North );
395 lay->addWidget( tab );
398 myStdGroup = new QWidget();
399 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
400 aStdLayout->setSpacing( 6 );
401 aStdLayout->setMargin( 11 );
406 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
407 myName = new QLineEdit( myStdGroup );
408 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
411 aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
412 myPhysicalMesh = new QComboBox( myStdGroup );
413 aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
414 QStringList physicalTypes;
415 physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" ) << tr( "BLSURF_SIZE_MAP");
416 myPhysicalMesh->addItems( physicalTypes );
418 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
419 myPhySize = new QLineEdit( myStdGroup );
420 aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
422 #ifdef WITH_SIZE_BOUNDARIES
423 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
424 myPhyMin = new QLineEdit( myStdGroup );
425 aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
427 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
428 myPhyMax = new QLineEdit( myStdGroup );
429 aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
432 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
433 myGeometricMesh = new QComboBox( myStdGroup );
434 aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
436 types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
437 myGeometricMesh->addItems( types );
439 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
440 myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
441 aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
442 myAngleMeshS->setMinimum( 0 );
443 myAngleMeshS->setMaximum( 16 );
444 myAngleMeshS->setSingleStep( 0.5 );
446 aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
447 myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
448 aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
449 myAngleMeshC->setMinimum( 0 );
450 myAngleMeshC->setMaximum( 16 );
451 myAngleMeshC->setSingleStep( 0.5 );
453 aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
454 myGradation = new QtxDoubleSpinBox( myStdGroup );
455 aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
456 myGradation->setMinimum( 1.1 );
457 myGradation->setMaximum( 2.5 );
458 myGradation->setSingleStep( 0.1 );
460 #ifdef WITH_SIZE_BOUNDARIES
461 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
462 myGeoMin = new QLineEdit( myStdGroup );
463 aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
465 aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
466 myGeoMax = new QLineEdit( myStdGroup );
467 aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
470 myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
471 aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
473 myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
474 aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
476 // advanced parameters
477 myAdvGroup = new QWidget();
478 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
479 anAdvLayout->setSpacing( 6 );
480 anAdvLayout->setMargin( 11 );
482 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
483 myTopology = new QComboBox( myAdvGroup );
484 anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
485 QStringList topologyTypes;
486 topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
487 myTopology->addItems( topologyTypes );
489 anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
490 myVerbosity = new QSpinBox( myAdvGroup );
491 anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
492 myVerbosity->setMinimum( 0 );
493 myVerbosity->setMaximum( 100 );
494 myVerbosity->setSingleStep( 5 );
496 myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
497 anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
499 headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
500 myOptionTable->setHorizontalHeaderLabels( headers );
501 myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
502 //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
503 //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
504 myOptionTable->verticalHeader()->hide();
505 //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
507 QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"), myAdvGroup );
508 anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
509 addBtn->setMenu( new QMenu() );
511 QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
512 anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
514 anAdvLayout->setRowStretch( 4, 5 );
515 anAdvLayout->setColumnStretch( 1, 5 );
517 // Size Maps parameters
519 mySmpGroup = new QWidget();
520 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
522 mySizeMapTable = new QTableWidget( 0, SMP_NB_COLUMNS, mySmpGroup );
523 anSmpLayout->addWidget(mySizeMapTable, 1, 0, 8, 1);
524 QStringList sizeMapHeaders;
525 sizeMapHeaders << tr( "SMP_ENTRY_COLUMN" )<< tr( "SMP_NAME_COLUMN" ) << tr( "SMP_SIZEMAP_COLUMN" );
526 mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
527 mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
528 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
529 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
530 mySizeMapTable->setAlternatingRowColors(true);
531 mySizeMapTable->verticalHeader()->hide();
534 addAttractorButton = new QPushButton(tr("BLSURF_SM_ATTRACTOR"),mySmpGroup);
535 anSmpLayout->addWidget(addAttractorButton, SMP_ATTRACTOR_BTN, 1, 1, 1);
537 QFrame *line = new QFrame(mySmpGroup);
538 line->setFrameShape(QFrame::HLine);
539 line->setFrameShadow(QFrame::Sunken);
540 anSmpLayout->addWidget(line, SMP_SEPARATOR1, 1, 1, 1);
542 addSurfaceButton = new QPushButton(tr("BLSURF_SM_SURFACE"),mySmpGroup);
543 anSmpLayout->addWidget(addSurfaceButton, SMP_SURFACE_BTN, 1, 1, 1);
545 addEdgeButton = new QPushButton(tr("BLSURF_SM_EDGE"),mySmpGroup);
546 anSmpLayout->addWidget(addEdgeButton, SMP_EDGE_BTN, 1, 1, 1);
548 addPointButton = new QPushButton(tr("BLSURF_SM_POINT"),mySmpGroup);
549 anSmpLayout->addWidget(addPointButton, SMP_POINT_BTN, 1, 1, 1);
551 QFrame *line2 = new QFrame(mySmpGroup);
552 line2->setFrameShape(QFrame::HLine);
553 line2->setFrameShadow(QFrame::Sunken);
554 anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 1, 1);
556 removeButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
557 anSmpLayout->addWidget(removeButton, SMP_REMOVE_BTN, 1, 1, 1);
561 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
562 tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
563 tab->insertTab( SMP_TAB, mySmpGroup, tr( "BLSURF_SIZE_MAP" ) );
565 tab->setCurrentIndex( STD_TAB );
568 connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
569 connect( myPhysicalMesh, SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
570 connect( addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
571 connect( addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
572 connect( rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
574 connect(addSurfaceButton, SIGNAL(clicked()), this, SLOT(onAddMapOnSurface()));
575 connect(addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddMapOnEdge()));
576 connect(addPointButton, SIGNAL(clicked()), this, SLOT(onAddMapOnPoint()));
577 connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
578 connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
583 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
585 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
586 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
588 BlsurfHypothesisData data;
589 that->readParamsFromHypo( data );
592 myName->setText( data.myName );
593 QFontMetrics metrics( myName->font() );
594 myName->setMinimumWidth( metrics.width( data.myName )+5 );
596 myTopology->setCurrentIndex( data.myTopology );
597 myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
598 myPhySize->setText( data.myPhySize );
599 #ifdef WITH_SIZE_BOUNDARIES
600 myPhyMin->setText( data.myPhyMin );
601 myPhyMax->setText( data.myPhyMax );
602 myGeoMin->setText( data.myGeoMin );
603 myGeoMax->setText( data.myGeoMax );
605 myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
606 myAngleMeshS->setValue( data.myAngleMeshS );
607 myAngleMeshC->setValue( data.myAngleMeshC );
608 myGradation->setValue( data.myGradation );
609 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
610 myDecimesh->setChecked( data.myDecimesh );
611 myVerbosity->setValue( data.myVerbosity );
613 if ( myOptions.operator->() ) {
614 printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
615 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
616 QString option = that->myOptions[i].in();
617 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
618 if ( name_value.count() > 1 ) {
619 QString idStr = QString("%1").arg( i );
620 int row = myOptionTable->rowCount();
621 myOptionTable->setRowCount( row+1 );
622 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
623 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
624 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
625 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
626 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
627 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
633 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
635 printf("retrieveParams():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
636 QMapIterator<QString, QString> i(that->mySMPMap);
637 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
638 while (i.hasNext()) {
640 const QString entry = i.key();
641 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
642 const QString sizeMap = i.value();
643 int row = mySizeMapTable->rowCount();
644 mySizeMapTable->setRowCount( row+1 );
645 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( entry ) );
646 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
647 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
648 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
649 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
650 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |
655 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
656 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
659 that->onPhysicalMeshChanged();
660 that->onGeometricMeshChanged();
663 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
665 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
667 BlsurfHypothesisData data;
668 QString guiHyp = that->readParamsFromWidgets( data );
669 that->storeParamsToHypo( data );
674 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
676 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
677 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
678 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
680 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
681 h_data.myName = isCreation() && data ? hypName() : "";
683 h_data.myTopology = (int) h->GetTopology();
684 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
685 h_data.myPhySize = QString::number( h->GetPhySize() );
686 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
687 h_data.myAngleMeshS = h->GetAngleMeshS();
688 h_data.myAngleMeshC = h->GetAngleMeshC();
689 h_data.myGradation = h->GetGradation();
690 h_data.myAllowQuadrangles = h->GetQuadAllowed();
691 h_data.myDecimesh = h->GetDecimesh();
692 h_data.myVerbosity = h->GetVerbosity();
694 #ifdef WITH_SIZE_BOUNDARIES
695 double PhyMin = h->GetPhyMin();
696 double PhyMax = h->GetPhyMax();
697 double GeoMin = h->GetGeoMin();
698 double GeoMax = h->GetGeoMax();
700 h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
701 h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
702 h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
703 h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
706 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
707 that->myOptions = h->GetOptionValues();
709 that->mySMPMap.clear();
712 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
713 MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
714 QString fullSizeMaps;
715 QStringList fullSizeMapList;
716 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
717 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
718 fullSizeMaps = mySizeMaps[i].in();
719 MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
720 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
721 if ( fullSizeMapList.count() > 1 ) {
722 string fullSizeMap = fullSizeMapList[1].toStdString();
723 int pos = fullSizeMap.find("return")+7;
724 QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
725 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
726 MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
727 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShape(fullSizeMapList[0].toStdString()).ShapeType();
728 MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
734 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
735 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
737 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
738 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
739 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
740 if ( fullCustomSizeMapList.count() > 1 ) {
741 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
742 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShape(fullCustomSizeMapList[0].toStdString()).ShapeType();
743 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
744 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
749 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
750 MESSAGE("myAttractors->length() = " << allMyAttractors->length());
752 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
753 QString myAttractors = allMyAttractors[i].in();
754 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
755 if ( myAttractorList.count() > 1 ) {
756 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
757 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShape(myAttractorList[0].toStdString()).ShapeType();
758 MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
759 MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
766 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
768 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
769 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
770 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
776 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
778 if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
779 h->SetTopology( (int) h_data.myTopology );
780 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
781 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
782 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
783 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
784 if ( h->GetGradation() != h_data.myGradation )
785 h->SetGradation( h_data.myGradation );
786 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
787 h->SetQuadAllowed( h_data.myAllowQuadrangles );
788 if ( h->GetDecimesh() != h_data.myDecimesh )
789 h->SetDecimesh( h_data.myDecimesh );
790 if ( h->GetVerbosity() != h_data.myVerbosity )
791 h->SetVerbosity( h_data.myVerbosity );
793 if( ((int) h_data.myPhysicalMesh == PhysicalUserDefined)||((int) h_data.myPhysicalMesh == SizeMap) ) {
794 if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
795 h->SetPhySize( h_data.myPhySize.toDouble() );
797 if( (int) h_data.myGeometricMesh == UserDefined ) {
798 if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
799 h->SetAngleMeshS( h_data.myAngleMeshS );
800 if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
801 h->SetAngleMeshC( h_data.myAngleMeshC );
803 #ifdef WITH_SIZE_BOUNDARIES
804 if ( !isDouble( h_data.myPhyMin ))
806 else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
807 h->SetPhyMin( h_data.myPhyMin.toDouble() );
808 if ( !isDouble( h_data.myPhyMax ))
810 else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
811 h->SetPhyMax( h_data.myPhyMax.toDouble() );
812 if ( !isDouble( h_data.myGeoMin ))
814 else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
815 h->SetGeoMin( h_data.myGeoMin.toDouble() );
816 if ( !isDouble( h_data.myGeoMax ))
818 else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
819 h->SetGeoMax( h_data.myGeoMax.toDouble() );
822 //printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
823 h->SetOptionValues( myOptions ); // is set in checkParams()
825 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
826 QMapIterator<QString,QString> i(that->mySMPMap);
827 // Iterate over each size map
828 while (i.hasNext()) {
830 const QString entry = i.key();
831 const QString sizeMap = i.value();
833 if (sizeMap == "__TO_DELETE__") {
834 MESSAGE("Delete entry " << entry.toStdString() << " from engine");
835 h->UnsetEntry(entry.toLatin1().constData());
837 else if (sizeMap.startsWith("ATTRACTOR")) {
838 MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
839 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
841 else if (sizeMap.startsWith("def")) {
842 MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
843 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
847 fullSizeMap = QString("");
848 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
849 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
850 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
851 fullSizeMap = QString("def f(t): return ") + sizeMap;
852 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
853 fullSizeMap = QString("def f(): return ") + sizeMap;
855 MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
856 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
860 catch(const SALOME::SALOME_Exception& ex)
862 SalomeApp_Tools::QtCatchCorbaException(ex);
868 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
870 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
871 h_data.myName = myName ? myName->text() : "";
872 h_data.myTopology = myTopology->currentIndex();
873 h_data.myPhysicalMesh = myPhysicalMesh->currentIndex();
874 h_data.myPhySize = myPhySize->text();
875 #ifdef WITH_SIZE_BOUNDARIES
876 h_data.myPhyMin = myPhyMin->text();
877 h_data.myPhyMax = myPhyMax->text();
878 h_data.myGeoMin = myGeoMin->text();
879 h_data.myGeoMax = myGeoMax->text();
881 h_data.myGeometricMesh = myGeometricMesh->currentIndex();
882 h_data.myAngleMeshS = myAngleMeshS->value();
883 h_data.myAngleMeshC = myAngleMeshC->value();
884 h_data.myGradation = myGradation->value();
885 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
886 h_data.myDecimesh = myDecimesh->isChecked();
887 h_data.myVerbosity = myVerbosity->value();
890 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
891 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
892 guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
893 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
894 guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
895 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
896 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
897 guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
898 #ifdef WITH_SIZE_BOUNDARIES
899 if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
900 if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
901 if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
902 if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
905 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
906 int row = 0, nbRows = myOptionTable->rowCount();
907 for ( ; row < nbRows; ++row )
909 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
910 if ( id >= 0 && id < myOptions->length() )
912 QString name = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
913 QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
914 if ( value.isNull() )
916 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
918 guiHyp += name + " = " + value + "; ";
923 row = 0, nbRows = mySizeMapTable->rowCount();
924 for ( ; row < nbRows; ++row )
926 QString entry = mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->text();
927 if ( that->mySMPMap.contains(entry) )
928 guiHyp += entry + " = " + that->mySMPMap[entry] + "; ";
931 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
936 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
937 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged");
938 bool isCustom = ((myPhysicalMesh->currentIndex() == PhysicalUserDefined) || (myPhysicalMesh->currentIndex() == SizeMap)) ;
939 myPhySize->setEnabled(isCustom);
940 myPhyMax->setEnabled(isCustom);
941 myPhyMin->setEnabled(isCustom);
944 QString aPhySize = "";
945 switch( myPhysicalMesh->currentIndex() ) {
951 myPhySize->setText( aPhySize );
952 if ( !isDouble( myPhyMin->text(), true ))
953 myPhyMin->setText("");
954 if ( !isDouble( myPhyMax->text(), true ))
955 myPhyMax->setText("");
956 if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
957 myGeometricMesh->setCurrentIndex( UserDefined );
958 onGeometricMeshChanged();
963 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
964 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged");
965 bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
966 myAngleMeshS->setEnabled(isCustom);
967 myAngleMeshC->setEnabled(isCustom);
968 myGradation->setEnabled(isCustom);
969 myGeoMax->setEnabled(isCustom);
970 myGeoMin->setEnabled(isCustom);
973 double aAngleMeshS, aGradation;
974 switch( myGeometricMesh->currentIndex() ) {
981 myAngleMeshS->setValue( aAngleMeshS );
982 myAngleMeshC->setValue( aAngleMeshS );
983 myGradation->setValue( aGradation );
984 if ( !isDouble( myGeoMin->text(), true ))
985 myGeoMin->setText("");
986 if ( !isDouble( myGeoMax->text(), true ))
987 myGeoMax->setText("");
988 // hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
989 if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
990 myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
991 onPhysicalMeshChanged();
996 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
998 QMenu* menu = (QMenu*)sender();
999 // fill popup with option names
1001 if ( myOptions.operator->() ) {
1002 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1003 QString name_value = myOptions[i].in();
1004 QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
1005 menu->addAction( name );
1010 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
1012 myOptionTable->setFocus();
1013 QMenu* menu = (QMenu*)( a->parent() );
1015 int idx = menu->actions().indexOf( a );
1016 QString idStr = QString("%1").arg( idx );
1017 QString option = myOptions[idx].in();
1018 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
1020 // look for a row with optionName
1021 int row = 0, nbRows = myOptionTable->rowCount();
1022 for ( ; row < nbRows; ++row )
1023 if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
1025 // add a row if not found
1026 if ( row == nbRows ) {
1027 myOptionTable->setRowCount( row+1 );
1028 myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1029 myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1030 myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
1031 myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1032 myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
1033 myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1034 Qt::ItemIsEditable |
1035 Qt::ItemIsEnabled );
1036 myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1038 myOptionTable->clearSelection();
1039 myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1040 //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
1041 myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
1042 //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
1045 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
1047 // clear option values and remember selected row
1048 QList<int> selectedRows;
1049 QList<QTableWidgetItem*> selected = myOptionTable->selectedItems();
1050 QTableWidgetItem* item;
1051 foreach( item, selected ) {
1052 int row = item->row();
1053 if ( !selectedRows.contains( row ) ) {
1054 selectedRows.append( row );
1055 int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1056 if ( id >= 0 && id < myOptions->length() )
1057 myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
1060 qSort( selectedRows );
1061 QListIterator<int> it( selectedRows );
1063 while ( it.hasPrevious() )
1064 myOptionTable->removeRow( it.previous() );
1067 // **********************
1068 // *** BEGIN SIZE MAP ***
1069 // **********************
1072 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
1074 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
1075 QList<int> selectedRows;
1076 QList<QTableWidgetItem*> selected = mySizeMapTable->selectedItems();
1077 QTableWidgetItem* item;
1079 foreach( item, selected ) {
1081 if ( !selectedRows.contains( row ) )
1082 selectedRows.append( row );
1085 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1087 qSort( selectedRows );
1088 QListIterator<int> it( selectedRows );
1090 while ( it.hasPrevious() ) {
1091 row = it.previous();
1092 QString entry = mySizeMapTable->item(row,SMP_ENTRY_COLUMN)->text();
1093 if (that->mySMPMap.contains(entry))
1094 that->mySMPMap[entry] = "__TO_DELETE__";
1095 if (that->mySMPShapeTypeMap.contains(entry))
1096 that->mySMPShapeTypeMap.remove(entry);
1097 mySizeMapTable->removeRow(row );
1099 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
1100 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1103 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
1105 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")");
1106 if (col == SMP_SIZEMAP_COLUMN) {
1107 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1108 QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
1109 QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
1110 MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
1111 if (! that->mySMPShapeTypeMap.contains(entry))
1113 if (that->mySMPMap.contains(entry))
1114 if (that->mySMPMap[entry] == sizeMap)
1116 QColor* bgColor = new QColor("white");
1117 QColor* fgColor = new QColor("black");
1118 if (! sizeMap.isEmpty()) {
1119 that->mySMPMap[entry] = sizeMap;
1120 if (! sizeMapValidationFromRow(row)) {
1121 bgColor->setRgb(255,0,0);
1122 fgColor->setRgb(255,255,255);
1126 MESSAGE("Size map empty: reverse to precedent value" );
1127 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
1129 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
1130 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
1131 that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
1132 that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
1133 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1137 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnSurface()
1139 insertElementType(TopAbs_FACE);
1142 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnEdge()
1144 insertElementType(TopAbs_EDGE);
1147 void BLSURFPluginGUI_HypothesisCreator::onAddMapOnPoint()
1149 insertElementType(TopAbs_VERTEX);
1152 void BLSURFPluginGUI_HypothesisCreator::insertElementType(TopAbs_ShapeEnum typeShapeAsked)
1154 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElementType()");
1156 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1157 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1159 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1162 string entry, shapeName;
1163 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1165 LightApp_SelectionMgr* mySel = myGeomToolSelected->selectionMgr();
1167 SALOME_ListIO ListSelectedObjects;
1168 mySel->selectedObjects(ListSelectedObjects, NULL, false );
1169 if (!ListSelectedObjects.IsEmpty())
1171 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
1172 for (; Object_It.More(); Object_It.Next())
1174 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
1175 entry = myGeomToolSelected->getEntryOfObject(anObject);
1176 shapeName = anObject->getName();
1177 S = myGeomToolSelected->entryToShape(entry);
1178 if ((! S.IsNull()) && (S.ShapeType() == typeShapeAsked))
1180 mySizeMapTable->setFocus();
1182 shapeEntry = QString::fromStdString(entry);
1183 double phySize = h->GetPhySize();
1184 std::ostringstream oss;
1187 sizeMap = QString::fromStdString(oss.str());
1188 if (that->mySMPMap.contains(shapeEntry)) {
1189 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
1190 MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
1194 that->mySMPMap[shapeEntry] = sizeMap;
1195 that->mySMPShapeTypeMap[shapeEntry] = typeShapeAsked;
1196 int row = mySizeMapTable->rowCount() ;
1197 mySizeMapTable->setRowCount( row+1 );
1198 mySizeMapTable->setItem( row, SMP_ENTRY_COLUMN, new QTableWidgetItem( shapeEntry ) );
1199 mySizeMapTable->item( row, SMP_ENTRY_COLUMN )->setFlags( 0 );
1200 mySizeMapTable->setItem( row, SMP_NAME_COLUMN, new QTableWidgetItem( QString::fromStdString(shapeName) ) );
1201 mySizeMapTable->item( row, SMP_NAME_COLUMN )->setFlags( 0 );
1202 mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
1203 mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
1204 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1205 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1206 mySizeMapTable->clearSelection();
1207 mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
1209 if ( myPhysicalMesh->currentIndex() != SizeMap ) {
1210 myPhysicalMesh->setCurrentIndex( SizeMap );
1211 onPhysicalMeshChanged();
1218 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
1220 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
1221 int row = 0, nbRows = mySizeMapTable->rowCount();
1222 for ( ; row < nbRows; ++row )
1223 if (! sizeMapValidationFromRow(row))
1228 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
1230 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()");
1231 QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
1232 bool res = sizeMapValidationFromEntry(myEntry,displayError);
1233 mySizeMapTable->setFocus();
1237 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
1239 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
1241 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1243 if (! that->mySMPMap.contains(myEntry)) {
1244 MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
1247 if (! that->mySMPShapeTypeMap.contains(myEntry)) {
1248 MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
1254 if (that->mySMPMap[myEntry].startsWith("def")) {
1255 MESSAGE("custom function" );
1256 expr = that->mySMPMap[myEntry].toStdString();
1258 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
1259 MESSAGE("Attractor" );
1260 // if ((that->mySMPMap[myEntry].count(QRegExp("ATTRACTOR([0-9])")) != 1))
1261 if ((that->mySMPMap[myEntry].count('(') != 1) ||
1262 (that->mySMPMap[myEntry].count(')') != 1) ||
1263 (that->mySMPMap[myEntry].count(';') != 4) ||
1264 (that->mySMPMap[myEntry].size() == 15)){
1266 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b)" );
1272 // case size map is empty
1273 if (that->mySMPMap[myEntry].isEmpty()) {
1275 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
1279 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
1280 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
1281 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
1282 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
1283 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
1284 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
1286 //assert(Py_IsInitialized());
1287 if (! Py_IsInitialized())
1288 throw ("Erreur: Python interpreter is not initialized");
1289 PyGILState_STATE gstate;
1290 gstate = PyGILState_Ensure();
1292 PyObject * obj = NULL;
1293 PyObject* new_stderr = NULL;
1294 string err_description="";
1295 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
1299 new_stderr=newPyStdOut(err_description);
1300 PySys_SetObject("stderr", new_stderr);
1302 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1303 Py_DECREF(new_stderr);
1305 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
1306 PyGILState_Release(gstate);
1311 PyObject * func = NULL;
1312 func = PyObject_GetAttrString(main_mod, "f");
1316 new_stderr=newPyStdOut(err_description);
1317 PySys_SetObject("stderr", new_stderr);
1319 PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
1320 Py_DECREF(new_stderr);
1322 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
1323 PyGILState_Release(gstate);
1327 PyGILState_Release(gstate);
1329 MESSAGE("SizeMap expression "<<expr<<" is valid");
1335 void BLSURFPluginGUI_HypothesisCreator::OnEditMapFunction(QModelIndex* index) {
1336 int myRow = index->row();
1337 int myColumn = index->column();
1341 myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1342 connect(myEditor, SIGNAL(FunctionEntered(QString)), this, SLOT(FunctionLightValidation(QString)));
1345 // myEditor->show();
1346 // myEditor->raise();
1347 // myEditor->activateWindow();
1350 // BLSURFPluginGUI_MapFunctionEditor* myEditor = new BLSURFPluginGUI_MapFunctionEditor(sizeMapModel->item(myRow,0)->text());
1351 // myEditor->exec();
1352 QString myFunction = myEditor->GetFunctionText();
1353 // FIN RECUPERATION FONCTION
1355 if (! myFunction.isEmpty()) {
1359 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1360 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
1362 // h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1363 // item->text().toLatin1().constData());
1364 h->SetSizeMapEntry(sizeMapModel->item(myRow,1)->text().toLatin1().constData(),
1365 myFunction.toLatin1().constData());
1366 // FIN MAJ DE LA MAP
1371 QString BLSURFPluginGUI_HypothesisCreator::caption() const
1373 return tr( "BLSURF_TITLE" );
1376 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
1378 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
1381 QString BLSURFPluginGUI_HypothesisCreator::type() const
1383 return tr( "BLSURF_HYPOTHESIS" );
1386 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
1388 return "blsurf_hypo_page.html";
1391 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
1394 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1396 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );