1 // Copyright (C) 2007-2013 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
21 // File : BLSURFPluginGUI_HypothesisCreator.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPluginGUI_HypothesisCreator.h"
28 #include "BLSURFPluginGUI_Dlg.h"
30 #include "GeometryGUI.h"
32 #include <SMESHGUI_Utils.h>
33 #include <SMESHGUI_HypothesesUtils.h>
34 #include <SMESHGUI_Dialog.h>
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESH_NumberFilter.hxx"
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Tools.h>
43 #include <QApplication>
47 #include <QHBoxLayout>
48 #include <QHeaderView>
49 #include <QGridLayout>
55 #include <QPushButton>
56 #include <QRadioButton>
58 #include <QTableWidget>
60 #include <QVBoxLayout>
62 #include <QStandardItemModel>
63 #include <QStandardItem>
64 #include <QTreeWidget>
65 #include <QTreeWidgetItem>
66 #include <QModelIndexList>
68 #include <LightApp_SelectionMgr.h>
69 #include <SalomeApp_Application.h>
70 #include <SALOME_ListIO.hxx>
71 #include <SALOME_ListIteratorOfListIO.hxx>
72 #include "SALOME_LifeCycleCORBA.hxx"
74 #include <TopoDS_Shape.hxx>
75 #include <TopoDS_Iterator.hxx>
76 #include <SMESH_Gen_i.hxx>
77 #include <boost/shared_ptr.hpp>
78 #include <boost/algorithm/string.hpp>
79 #include <structmember.h>
94 // Enforced vertices array columns
95 ENF_VER_NAME_COLUMN = 0,
96 ENF_VER_FACE_ENTRY_COLUMN,
100 ENF_VER_ENTRY_COLUMN,
101 ENF_VER_GROUP_COLUMN,
128 // Enforced vertices inputs
136 // ENF_VER_GROUP_CHECK,
140 ENF_VER_INTERNAL_ALL_FACES,
141 ENF_VER_INTERNAL_ALL_FACES_GROUP,
142 // ENF_VER_VERTEX_BTN,
143 // ENF_VER_REMOVE_BTN,
144 // ENF_VER_SEPARATOR,
149 /**************************************************
150 Begin initialization Python structures and objects
151 ***************************************************/
160 PyStdOut_dealloc(PyStdOut *self)
166 PyStdOut_write(PyStdOut *self, PyObject *args)
170 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
174 *(self->out)=*(self->out)+c;
180 static PyMethodDef PyStdOut_methods[] = {
181 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
182 PyDoc_STR("write(string) -> None")},
183 {NULL, NULL} /* sentinel */
186 static PyMemberDef PyStdOut_memberlist[] = {
187 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
188 (char*)"flag indicating that a space needs to be printed; used by print"},
189 {NULL} /* Sentinel */
192 static PyTypeObject PyStdOut_Type = {
193 /* The ob_type field must be initialized in the module init function
194 * to be portable to Windows without using C++. */
195 PyObject_HEAD_INIT(NULL)
198 sizeof(PyStdOut), /*tp_basicsize*/
201 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
208 0, /*tp_as_sequence*/
213 PyObject_GenericGetAttr, /*tp_getattro*/
214 /* softspace is writable: we must supply tp_setattro */
215 PyObject_GenericSetAttr, /* tp_setattro */
217 Py_TPFLAGS_DEFAULT, /*tp_flags*/
221 0, /*tp_richcompare*/
222 0, /*tp_weaklistoffset*/
225 PyStdOut_methods, /*tp_methods*/
226 PyStdOut_memberlist, /*tp_members*/
240 PyObject * newPyStdOut( std::string& out )
243 self = PyObject_New(PyStdOut, &PyStdOut_Type);
248 return (PyObject*)self;
251 /*************************************************
252 End initialization Python structures and objects
253 **************************************************/
257 // BEGIN EnforcedTreeWidgetDelegate
260 EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
261 : QItemDelegate(parent)
265 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
266 const QStyleOptionViewItem & option ,
267 const QModelIndex & index ) const
269 QModelIndex father = index.parent();
270 QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
272 if (index.column() == ENF_VER_X_COLUMN || \
273 index.column() == ENF_VER_Y_COLUMN || \
274 index.column() == ENF_VER_Z_COLUMN)
276 SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent);
277 editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 editor->setReadOnly(!entry.isEmpty());
279 editor->setDisabled(!entry.isEmpty());
284 QLineEdit *editor = new QLineEdit(parent);
285 if (index.column() != ENF_VER_GROUP_COLUMN) {
286 editor->setReadOnly(!entry.isEmpty());
287 editor->setDisabled(!entry.isEmpty());
293 void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor,
294 const QModelIndex &index) const
296 QString value = index.model()->data(index, Qt::EditRole).toString();
298 if (index.column() == ENF_VER_X_COLUMN ||
299 index.column() == ENF_VER_Y_COLUMN ||
300 index.column() == ENF_VER_Z_COLUMN)
302 SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
303 lineEdit->setText(value);
306 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
307 lineEdit->setText(value);
311 void EnforcedTreeWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
312 const QModelIndex &index) const
314 QModelIndex parent = index.parent();
315 QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data(Qt::EditRole).toString();
316 if (index.column() == ENF_VER_X_COLUMN || index.column() == ENF_VER_Y_COLUMN || index.column() == ENF_VER_Z_COLUMN) {
317 SMESHGUI_SpinBox *lineEdit = static_cast<SMESHGUI_SpinBox*>(editor);
318 if (entry.isEmpty() && !vertexExists(model, index, lineEdit->GetString()))
319 model->setData(index, lineEdit->GetValue(), Qt::EditRole);
320 } else if (index.column() == ENF_VER_NAME_COLUMN) {
321 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
322 QString value = lineEdit->text();
323 if (entry.isEmpty() && !vertexExists(model, index, value))
324 model->setData(index, value, Qt::EditRole);
325 } else if (index.column() == ENF_VER_ENTRY_COLUMN) {
326 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
327 QString value = lineEdit->text();
328 if (! vertexExists(model, index, value))
329 model->setData(index, value, Qt::EditRole);
330 } else if (index.column() == ENF_VER_GROUP_COLUMN) {
331 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
332 model->setData(index, lineEdit->text(), Qt::EditRole);
336 void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor,
337 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
339 editor->setGeometry(option.rect);
342 bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
343 const QModelIndex &index, QString value) const
346 QModelIndex parent = index.parent();
347 int row = index.row();
348 int col = index.column();
350 if (parent.isValid() && !value.isEmpty()) {
351 if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) {
353 if (col == ENF_VER_X_COLUMN) {
354 x = value.toDouble();
355 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
356 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
358 if (col == ENF_VER_Y_COLUMN) {
359 y = value.toDouble();
360 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
361 z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
363 if (col == ENF_VER_Z_COLUMN) {
364 z = value.toDouble();
365 x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
366 y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
368 int nbChildren = model->rowCount(parent);
369 for (int i = 0 ; i < nbChildren ; i++) {
371 double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble();
372 double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble();
373 double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble();
374 if ((childX == x) && (childY == y) && (childZ == z)) {
381 else if (col == ENF_VER_NAME_COLUMN) {
382 int nbChildren = model->rowCount(parent);
383 for (int i = 0 ; i < nbChildren ; i++) {
385 QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString();
386 if (childName == value) {
399 // END EnforcedTreeWidgetDelegate
404 * \brief {BLSURFPluginGUI_HypothesisCreator constructor}
405 * @param theHypType Name of the hypothesis type (here BLSURF_Parameters)
408 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
409 : SMESHGUI_GenericHypothesisCreator( theHypType )
411 MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
412 this->mySMPMap.clear();
414 GeomToolSelected = NULL;
415 GeomToolSelected = getGeomSelectionTool();
417 aSel = GeomToolSelected->selectionMgr();
419 /* Initialize the Python interpreter */
420 if (! Py_IsInitialized())
421 throw ("Error: Python interpreter is not initialized");
422 PyGILState_STATE gstate;
423 gstate = PyGILState_Ensure();
426 main_mod = PyImport_AddModule("__main__");
429 main_dict = PyModule_GetDict(main_mod);
431 PyRun_SimpleString("from math import *");
432 PyGILState_Release(gstate);
436 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
441 * \brief {Get or create the geom selection tool for active study}
443 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
445 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
446 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
447 if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
448 that->GeomToolSelected = new GeomSelectionTools(aStudy);
450 return that->GeomToolSelected;
453 GEOM::GEOM_Gen_var BLSURFPluginGUI_HypothesisCreator::getGeomEngine()
455 return GeometryGUI::GetGeomGen();
459 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
461 MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
464 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
465 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
469 myAdvWidget->myOptionTable->setFocus();
470 QApplication::instance()->processEvents();
472 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
473 for ( ; row < nbRows; ++row )
475 QString name = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
476 QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
477 if ( !value.isEmpty() ) {
479 QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().trimmed();
480 if (optionType == "PRECAD")
481 h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
482 else if (optionType == "BLSURF")
483 h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
485 catch ( const SALOME::SALOME_Exception& ex )
487 msg = ex.details.text.in();
495 h->SetOptionValues( myOptions ); // restore values
496 h->SetPreCADOptionValues( myPreCADOptions ); // restore values
499 // SizeMap and attractors
502 mySizeMapTable->setFocus();
503 QApplication::instance()->processEvents();
505 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
506 int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
508 for ( ; row < nbRows; ++row )
510 QString entry = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
511 QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
512 MESSAGE("entry ="<<entry.toStdString())
513 if ( !sizeMap.isEmpty() ) {
514 if (that->sizeMapValidationFromRow(row))
517 MESSAGE("entry ="<<entry.toStdString())
518 MESSAGE("sizeMap ="<<sizeMap.toStdString())
520 e = entry.toStdString();
521 s = that->mySMPMap[entry].toStdString();
522 MESSAGE("row = "<<row)
525 h->SetSizeMapEntry( e.c_str(), s.c_str() );
527 catch ( const SALOME::SALOME_Exception& ex )
529 msg = ex.details.text.in();
536 if ( ok && sizeMap.toDouble() <= 0.0 )
538 msg = tr("ZERO_VALUE_OF").arg( tr("SMP_SIZEMAP_COLUMN"));
545 // 22207: BLSURFPLUGIN: The user is allowed to enter 0 as a global or local size.
548 if ( !( ok = ( myStdWidget->myPhySize->text().isEmpty() ||
549 myStdWidget->myPhySize->text().toDouble() > 0.0 )))
550 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_HPHYDEF"));
554 if ( !( ok = ( myStdWidget->myMaxSize->text().isEmpty() ||
555 myStdWidget->myMaxSize->text().toDouble() > 0.0 )))
556 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_MAXSIZE"));
560 if ( !( ok = ( myStdWidget->myAngleMesh->text().isEmpty() ||
561 myStdWidget->myAngleMesh->text().toDouble() > 0.0 )))
562 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_ANGLE_MESH"));
566 if ( !( ok = ( myStdWidget->myChordalError->text().isEmpty() ||
567 myStdWidget->myChordalError->text().toDouble() > 0.0 )))
568 msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_CHORDAL_ERROR"));
577 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
579 MESSAGE("BLSURFPluginGUI_HypothesisCreator::buildFrame");
581 QFrame* fr = new QFrame( 0 );
582 // fr-> setMinimumSize(600,400);
583 QVBoxLayout* lay = new QVBoxLayout( fr );
584 // lay->setSizeConstraint(QLayout::SetDefaultConstraint);
586 lay->setSpacing( 0 );
589 QTabWidget* tab = new QTabWidget( fr );
590 tab->setTabShape( QTabWidget::Rounded );
591 tab->setTabPosition( QTabWidget::North );
592 lay->addWidget( tab );
597 myStdGroup = new QWidget();
598 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
599 aStdLayout->setSpacing( 6 );
600 aStdLayout->setMargin( 11 );
603 myName = new QLineEdit( myStdGroup );
604 myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
608 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), 0, 0, 1, 1 );
609 aStdLayout->addWidget( myName, row++, 1, 1, 3 );
611 aStdLayout->addWidget( myStdWidget, row++, 0, 1, 4 );
617 // row = max(row,maxrow)+1;
618 aStdLayout->setRowStretch(row,1);
619 aStdLayout->setColumnStretch(1,1);
623 // advanced parameters
624 myAdvGroup = new QWidget();
625 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
626 anAdvLayout->setSpacing( 6 );
627 anAdvLayout->setMargin( 11 );
628 myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
629 myAdvWidget->addBtn->setMenu( new QMenu() );
630 anAdvLayout->addWidget( myAdvWidget);
633 // Size Maps parameters
635 mySmpGroup = new QWidget();
636 // mySmpGroup->setMinimumWidth(500);
639 QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
642 mySizeMapTable = new QTreeWidget( mySmpGroup );
643 mySizeMapTable ->setMinimumWidth(200);
644 QStringList sizeMapHeaders;
645 sizeMapHeaders << tr( "SMP_NAME_COLUMN" )<< tr( "SMP_SIZEMAP_COLUMN" )<< tr( "SMP_ENTRY_COLUMN" );// << tr( "SMP_DIST_COLUMN" );
646 mySizeMapTable->setHeaderLabels(sizeMapHeaders);
647 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
648 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
649 mySizeMapTable->hideColumn(SMP_ENTRY_COLUMN);
650 mySizeMapTable->setAlternatingRowColors(true);
653 smpTab = new QTabWidget( mySmpGroup );
654 smpTab->setTabShape( QTabWidget::Rounded );
655 smpTab->setTabPosition( QTabWidget::South );
656 lay->addWidget( smpTab );
658 // Filters of selection
659 TColStd_MapOfInteger SM_ShapeTypes, ATT_ShapeTypes;
661 SM_ShapeTypes.Add( TopAbs_VERTEX );
662 SM_ShapeTypes.Add( TopAbs_EDGE );
663 SM_ShapeTypes.Add( TopAbs_FACE );
664 SM_ShapeTypes.Add( TopAbs_COMPOUND );
666 ATT_ShapeTypes.Add( TopAbs_VERTEX );
667 ATT_ShapeTypes.Add( TopAbs_EDGE );
668 ATT_ShapeTypes.Add( TopAbs_WIRE );
669 ATT_ShapeTypes.Add( TopAbs_COMPOUND );
671 SMESH_NumberFilter* myFilter1 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes);
672 SMESH_NumberFilter* myFilter2 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, ATT_ShapeTypes);
673 SMESH_NumberFilter* myFilter3 = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, TopAbs_FACE);
675 // Standard size map tab
676 mySmpStdGroup = new QWidget();
677 QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
678 myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false,/*stretch=*/false);
679 myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
680 mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
681 mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
682 QLabel* mySmpSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),mySmpStdGroup);
685 myAttractorGroup = new QWidget();
686 QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
687 myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false,/*stretch=*/false);
688 myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
689 myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
690 myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
691 myConstSizeCheck = new QCheckBox(tr("BLSURF_CONST_SIZE"),myAttractorGroup);
692 QFrame* attLine = new QFrame(myAttractorGroup);
693 attLine->setFrameShape(QFrame::HLine);
694 attLine->setFrameShadow(QFrame::Sunken);
695 myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false,/*stretch=*/false);
696 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
697 myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
698 myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
699 myAttSizeLabel = new QLabel(tr("BLSURF_SM_SIZE"),myAttractorGroup);
700 myAttDistSpin = new SMESHGUI_SpinBox(myAttractorGroup);
701 myAttDistSpin->RangeStepAndValidator(0., COORD_MAX, 10.0, "length_precision");
702 myAttDistLabel = new QLabel(tr("BLSURF_ATT_DIST"),myAttractorGroup);
703 myAttDistSpin2 = new SMESHGUI_SpinBox(myAttractorGroup);
704 myAttDistSpin2->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
705 myAttDistLabel2 = new QLabel(tr("BLSURF_ATT_RADIUS"),myAttractorGroup);
707 myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
708 myAttSelWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
712 addMapButton = new QPushButton(tr("BLSURF_SM_ADD"),mySmpGroup);
713 removeMapButton = new QPushButton(tr("BLSURF_SM_REMOVE"),mySmpGroup);
714 modifyMapButton = new QPushButton(tr("BLSURF_SM_MODIFY"),mySmpGroup);
715 modifyMapButton->setEnabled(false);
718 myAttSelWdg->setEnabled(false);
719 myAttSizeSpin->setEnabled(false);
720 myAttSizeLabel->setEnabled(false);
721 myAttDistSpin->setEnabled(false);
722 myAttDistLabel->setEnabled(false);
723 myAttDistSpin2->setEnabled(false);
724 myAttDistLabel2->setEnabled(false);
725 myAttDistSpin->setValue(0.);
726 myAttDistSpin2->setValue(0.);
727 myAttSizeSpin->setValue(0.);
728 mySmpSizeSpin->setValue(0.);
731 // ADD WIDGETS (SIZEMAP TAB)
732 anSmpLayout->addWidget(mySizeMapTable, 0, 0, SMP_NB_LINES, 1);
733 anSmpLayout->setColumnStretch(0, 1);
734 // anSmpLayout->addWidget(line2, SMP_SEPARATOR2, 1, 2, 2);
735 anSmpLayout->addWidget(smpTab, SMP_TAB_WDG, 1, 1, 3);
736 anSmpLayout->setRowStretch(SMP_TAB_WDG, 1);
737 anSmpLayout->addWidget(addMapButton, SMP_ADD_BTN, 1, 1, 1);
738 anSmpLayout->addWidget(removeMapButton, SMP_ADD_BTN, 2, 1, 1);
739 anSmpLayout->addWidget(modifyMapButton, SMP_ADD_BTN, 3, 1, 1);
742 anSmpStdLayout->addWidget(myGeomSelWdg1, SMP_GEOM_BTN_1, 1, 1, 2);
743 anSmpStdLayout->addWidget(mySmpSizeLabel, SMP_SIZE, 1, 1, 1);
744 anSmpStdLayout->addWidget(mySmpSizeSpin, SMP_SIZE, 2, 1, 1);
745 anSmpStdLayout->setRowStretch(SMP_SPACE2, 1);
748 anAttLayout->addWidget(myGeomSelWdg2, SMP_GEOM_BTN_2, 1, 1, 2);
749 anAttLayout->addWidget(myAttractorCheck, ATT_CHECK, 1, 1, 2);
750 anAttLayout->addWidget(myConstSizeCheck, CONST_SIZE_CHECK,1, 1, 2);
751 anAttLayout->addWidget(attLine, SMP_SPACE, 1, 1, 2);
752 anAttLayout->addWidget(myAttSelWdg, SMP_ATT_SHAPE, 1, 1, 2);
753 anAttLayout->addWidget(myAttSizeLabel, SMP_ATT_SIZE, 1, 1, 1);
754 anAttLayout->addWidget(myAttSizeSpin, SMP_ATT_SIZE, 2, 1, 1);
755 anAttLayout->addWidget(myAttDistLabel, SMP_ATT_DIST, 1, 1, 1);
756 anAttLayout->addWidget(myAttDistSpin, SMP_ATT_DIST, 2, 1, 1);
757 anAttLayout->addWidget(myAttDistLabel2, SMP_ATT_RAD, 1, 1, 1);
758 anAttLayout->addWidget(myAttDistSpin2, SMP_ATT_RAD, 2, 1, 1);
759 anAttLayout->setRowStretch(SMP_ATT_RAD+1, 1);
761 smpTab->insertTab( SMP_STD_TAB, mySmpStdGroup, tr( "BLSURF_SM_STD_TAB" ) );
762 smpTab->insertTab( ATT_TAB, myAttractorGroup, tr( "BLSURF_SM_ATT_TAB" ) );
764 smpTab->setCurrentIndex( SMP_STD_TAB );
766 // Enforced vertices parameters
767 myEnfGroup = new QWidget();
768 QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
770 // myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
771 // anEnfLayout->addWidget(myEnforcedVertexWidget);
772 // MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
773 // myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
775 myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
776 myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
777 myEnforcedTreeWidget->setSortingEnabled(true);
778 QStringList enforcedHeaders;
779 enforcedHeaders << tr("BLSURF_ENF_VER_NAME_COLUMN") << tr("BLSURF_ENF_VER_FACE_ENTRY_COLUMN")
780 << tr("BLSURF_ENF_VER_X_COLUMN")<< tr("BLSURF_ENF_VER_Y_COLUMN") << tr("BLSURF_ENF_VER_Z_COLUMN")
781 << tr("BLSURF_ENF_VER_ENTRY_COLUMN") << tr( "BLSURF_ENF_VER_GROUP_COLUMN" );
783 myEnforcedTreeWidget->setHeaderLabels(enforcedHeaders);
784 myEnforcedTreeWidget->header()->setStretchLastSection(true);
785 myEnforcedTreeWidget->setAlternatingRowColors(true);
786 myEnforcedTreeWidget->setUniformRowHeights(true);
787 myEnforcedTreeWidget->setAnimated(true);
788 myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
789 myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
790 for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
791 myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
792 myEnforcedTreeWidget->resizeColumnToContents(column);
794 myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
795 myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
796 myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
798 // FACE AND VERTEX SELECTION
799 TColStd_MapOfInteger shapeTypes1, shapeTypes2;
800 shapeTypes1.Add( TopAbs_FACE );
801 shapeTypes1.Add( TopAbs_COMPOUND );
802 shapeTypes2.Add( TopAbs_VERTEX );
803 shapeTypes2.Add( TopAbs_COMPOUND );
805 SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
806 myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true, /*stretch=*/false);
807 myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
809 SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
810 myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false);
811 myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
813 myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
815 QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
816 myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
817 myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
819 QLabel* myYCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Y_LABEL" ), myEnfGroup );
820 myYCoord = new SMESHGUI_SpinBox(myEnfGroup);
821 myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
823 QLabel* myZCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_Z_LABEL" ), myEnfGroup );
824 myZCoord = new SMESHGUI_SpinBox(myEnfGroup);
825 myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
827 QLabel* myGroupNameLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
828 myGroupName = new QLineEdit(myEnfGroup);
830 addVertexButton = new QPushButton(tr("BLSURF_ENF_VER_VERTEX"),myEnfGroup);
831 removeVertexButton = new QPushButton(tr("BLSURF_ENF_VER_REMOVE"),myEnfGroup);
833 myInternalEnforcedVerticesAllFaces = new QCheckBox(tr("BLSURF_ENF_VER_INTERNAL_VERTICES"),myEnfGroup);
835 QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
836 myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
838 // myGlobalGroupName = new QCheckBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
839 // myGlobalGroupName->setChecked(false);
841 anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, ENF_VER_NB_LINES, 1);
842 QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
843 // FACE AND VERTEX SELECTION
844 anEnfLayout2->addWidget(myEnfFaceWdg, ENF_VER_FACE, 0, 1, 2);
845 anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2);
846 anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1);
847 anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1);
848 anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1);
849 anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1);
850 anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1);
851 anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1);
852 anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1);
853 anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1);
854 // anEnfLayout2->addWidget(myGlobalGroupName, ENF_VER_GROUP_CHECK, 0, 1, 2);
855 // anEnfLayout2->setRowStretch( ENF_VER_SPACE, 1);
856 anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1);
857 anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1);
858 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
859 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
860 anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
861 anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
862 // anEnfLayout2->addWidget(makeGroupsCheck, ENF_VER_GROUP_CHECK, 0, 1, 2);
863 anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
864 // anEnfLayout->setRowStretch(1, 1);
867 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
868 tab->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
869 tab->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
870 tab->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
872 tab->setCurrentIndex( STD_TAB );
874 connect( myAdvWidget->addBtn->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAddOption() ) );
875 connect( myAdvWidget->addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
876 connect( myAdvWidget->rmBtn, SIGNAL( clicked()), this, SLOT( onDeleteOption() ) );
879 connect( addMapButton, SIGNAL( clicked()), this, SLOT( onAddMap() ) );
880 connect( removeMapButton, SIGNAL( clicked()), this, SLOT( onRemoveMap() ) );
881 connect( modifyMapButton, SIGNAL( clicked()), this, SLOT( onModifyMap() ) );
882 // connect( mySizeMapTable, SIGNAL( cellChanged ( int, int )), this, SLOT( onSetSizeMap(int,int ) ) );
883 connect( mySizeMapTable, SIGNAL( itemClicked (QTreeWidgetItem *, int)),this, SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
884 connect( myGeomSelWdg2, SIGNAL( contentModified() ), this, SLOT( onMapGeomContentModified() ) );
885 connect( myGeomSelWdg1, SIGNAL( contentModified() ), this, SLOT( onMapGeomContentModified() ) );
886 // connect( myAttractorGroup, SIGNAL( clicked(bool) ), this, SLOT( onAttractorGroupClicked(bool) ) );
887 connect( mySizeMapTable, SIGNAL( itemChanged (QTreeWidgetItem *, int)),this, SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
888 connect( myAttractorCheck, SIGNAL( stateChanged ( int )), this, SLOT( onAttractorClicked( int ) ) );
889 connect( myConstSizeCheck, SIGNAL( stateChanged ( int )), this, SLOT( onConstSizeClicked( int ) ) );
890 connect( smpTab, SIGNAL( currentChanged ( int )), this, SLOT( onSmpTabChanged( int ) ) );
893 connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) );
894 connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
895 // connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) );
896 connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) );
897 connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertices() ) );
898 connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) );
899 connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) );
900 connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this, SLOT( onInternalVerticesClicked( int ) ) );
901 // connect( myEnfVertexWdg, SIGNAL( selectionActivated()), this, SLOT( onVertexSelectionActivated() ) );
902 // connect( myEnfFaceWdg, SIGNAL( selectionActivated()), this, SLOT( onFaceSelectionActivated() ) );
907 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
908 This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
910 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
912 // if ((now == myXCoord) || (now == myYCoord) || (now == myZCoord)
913 // || (now = myGroupName) || (now = myGlobalGroupName) || (now = myEnforcedTreeWidget)) {
914 // BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
915 // that->getGeomSelectionTool()->selectionMgr()->clearFilters();
916 // myEnfFaceWdg->deactivateSelection();
917 // myEnfVertexWdg->deactivateSelection();
922 * This method resets the content of the X, Y, Z widgets;
924 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
926 myXCoord->setCleared(true);
927 myYCoord->setCleared(true);
928 myZCoord->setCleared(true);
929 myXCoord->setText("");
930 myYCoord->setText("");
931 myZCoord->setText("");
932 // myGroupName->setText("");
935 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
936 This method updates the tooltip of a modified item. The QLineEdit widgets content
937 is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
939 void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
940 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
941 QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
942 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
943 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
944 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
945 QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
946 QString groupName = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole).toString();
947 QTreeWidgetItem* parent = item->parent();
949 clearEnforcedVertexWidgets();
951 if (parent && (!x.isNull() || !entry.isNull())) {
952 QString shapeName = parent->data(ENF_VER_NAME_COLUMN, Qt::EditRole).toString();
953 QString toolTip = shapeName + QString(": ") + vertexName.toString();
954 if (entry.isNull()) {
955 toolTip += QString("(") + x.toString();
956 toolTip += QString(", ") + y.toString();
957 toolTip += QString(", ") + z.toString();
958 toolTip += QString(")");
961 if (!groupName.isEmpty())
962 toolTip += QString(" [") + groupName + QString("]");
964 item->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
967 myXCoord->SetValue(x.toDouble());
968 myYCoord->SetValue(y.toDouble());
969 myZCoord->SetValue(z.toDouble());
972 if (!groupName.isEmpty())
973 myGroupName->setText(groupName);
977 void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
978 int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
979 clearEnforcedVertexWidgets();
980 if (nbSelEnfVertex == 1)
982 if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() )
985 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
986 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
987 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
988 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
989 if (CORBA::is_nil(measureOp))
993 measureOp->PointCoordinates (myEnfVertex, x, y, z);
994 if ( measureOp->IsDone() )
996 myXCoord->SetValue(x);
997 myYCoord->SetValue(y);
998 myZCoord->SetValue(z);
1004 /** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
1005 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
1006 of the enforced vertex clicked in the tree widget.
1008 void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
1009 clearEnforcedVertexWidgets();
1010 QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
1011 if (! items.isEmpty() && items.size() == 1) {
1012 QTreeWidgetItem *item = items[0];
1013 // for (int i=0 ; i < items.size() ; i++) {
1015 QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1016 QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
1017 QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole);
1018 QVariant entry = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1019 QVariant group = item->data(ENF_VER_GROUP_COLUMN, Qt::EditRole);
1020 if (!x.isNull()/* && entry.isNull()*/) {
1021 myXCoord->SetValue(x.toDouble());
1022 myYCoord->SetValue(y.toDouble());
1023 myZCoord->SetValue(z.toDouble());
1026 if (!group.isNull() && (!x.isNull() || !entry.isNull()))
1027 myGroupName->setText(group.toString());
1032 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
1033 This method adds a face containing enforced vertices in the tree widget.
1035 QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
1036 // Find theFaceEntry item
1037 QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
1038 QTreeWidgetItem* theItem;
1039 if (theItemList.empty()) {
1040 theItem = new QTreeWidgetItem();
1041 theItem->setData(ENF_VER_FACE_ENTRY_COLUMN, Qt::EditRole, QVariant(theFaceEntry.c_str()));
1042 theItem->setData(ENF_VER_NAME_COLUMN, Qt::EditRole, QVariant(theFaceName.c_str()));
1043 theItem->setToolTip(ENF_VER_NAME_COLUMN,QString(theFaceEntry.c_str()));
1044 myEnforcedTreeWidget->addTopLevelItem(theItem);
1047 theItem = theItemList[0];
1052 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
1053 This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
1055 void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theItem, double x, double y, double z,
1056 std::string vertexName, std::string geomEntry, std::string groupName) {
1058 std::string theFaceName = theItem->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
1059 // MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
1060 bool okToCreate = true;
1062 const int nbVert = theItem->childCount();
1063 // MESSAGE("Number of child rows: " << nbVert);
1065 double childValueX,childValueY,childValueZ;
1066 QString childEntry, childGroupName;
1067 QTreeWidgetItem* child;
1068 for (int row = 0;row<nbVert;row++) {
1069 child = theItem->child(row);
1070 childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
1071 childEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
1072 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
1073 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
1074 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
1075 if (((childValueX == x) && (childValueY == y) && (childValueZ == z)) || ( (childEntry.toStdString() != "") && (childEntry.toStdString() == geomEntry))) {
1076 // update group name
1077 if (childGroupName.toStdString() != groupName) {
1078 MESSAGE("Group is updated from \"" << childGroupName.toStdString() << "\" to \"" << groupName << "\"");
1079 child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1087 if (geomEntry.empty()) {
1088 MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
1091 MESSAGE("In " << theFaceName << " vertex with entry " << geomEntry << " already exist: dont create again");
1096 if (geomEntry.empty()) {
1097 MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
1100 MESSAGE("In " << theFaceName << " vertex with geom entry " << geomEntry << " is created");
1103 QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
1104 vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1105 QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
1106 QSize iconSize = iconSelect.size()*0.7;
1108 int vertexIndex=myEnforcedTreeWidget->indexOfTopLevelItem(theItem);
1109 QString myVertexName;
1111 while(indexRef != vertexIndex) {
1112 indexRef = vertexIndex;
1113 if (vertexName.empty())
1114 myVertexName = QString("Vertex #%1").arg(vertexIndex);
1116 myVertexName = QString(vertexName.c_str());
1118 for (int row = 0;row<nbVert;row++) {
1119 QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
1120 if (myVertexName == name) {
1126 vertexItem->setData( ENF_VER_NAME_COLUMN, Qt::EditRole, myVertexName );
1127 if (geomEntry.empty()) {
1128 vertexItem->setData( ENF_VER_X_COLUMN, Qt::EditRole, QVariant(x) );
1129 vertexItem->setData( ENF_VER_Y_COLUMN, Qt::EditRole, QVariant(y) );
1130 vertexItem->setData( ENF_VER_Z_COLUMN, Qt::EditRole, QVariant(z) );
1133 vertexItem->setIcon(ENF_VER_NAME_COLUMN, QIcon(iconSelect.scaled(iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
1134 vertexItem->setData( ENF_VER_ENTRY_COLUMN, Qt::EditRole, QString(geomEntry.c_str()) );
1136 if (groupName != "")
1137 vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
1139 QString toolTip = QString(theFaceName.c_str())+QString(": ")+myVertexName;
1140 if (geomEntry.empty()) {
1141 toolTip += QString(" (%1, ").arg(x);
1142 toolTip += QString("%1, ").arg(y);
1143 toolTip += QString("%1)").arg(z);
1145 if (groupName != "")
1146 toolTip += QString(" [%1]").arg(groupName.c_str());
1148 vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
1149 theItem->setExpanded(true);
1150 myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
1153 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
1154 This method is called when a item is added into the enforced vertices tree widget
1156 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
1157 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
1159 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1161 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
1162 myEnfFaceWdg->deactivateSelection();
1163 myEnfVertexWdg->deactivateSelection();
1165 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1166 myEnforcedTreeWidget->resizeColumnToContents(column);
1169 int selEnfFace = myEnfFaceWdg->NbObjects();
1170 int selEnfVertex = myEnfVertexWdg->NbObjects();
1171 bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
1173 if (selEnfFace == 0)
1176 if ((selEnfVertex == 0) && coordsEmpty)
1179 string entry, shapeName;
1181 for (int i = 0 ; i < selEnfFace ; i++) {
1182 myEnfFace = myEnfFaceWdg->GetObject< GEOM::GEOM_Object >(i);
1183 entry = myEnfFace->GetStudyEntry();
1184 shapeName = myEnfFace->GetName();
1186 QTreeWidgetItem * faceItem = addEnforcedFace(entry, shapeName);
1188 std::string groupName = myGroupName->text().toStdString();
1190 if (boost::trim_copy(groupName).empty())
1193 if (selEnfVertex <= 1)
1196 x = myXCoord->GetValue();
1197 y = myYCoord->GetValue();
1198 z = myZCoord->GetValue();
1199 if (selEnfVertex == 1) {
1200 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
1201 addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1204 addEnforcedVertex(faceItem, x, y, z, "", "", groupName);
1208 if ( CORBA::is_nil(getGeomEngine()))
1211 GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
1212 if (CORBA::is_nil(measureOp))
1215 CORBA::Double x,y,z;
1217 for (int j = 0 ; j < selEnfVertex ; j++)
1219 myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
1220 if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
1221 measureOp->PointCoordinates (myEnfVertex, x, y, z);
1222 if ( measureOp->IsDone() )
1223 addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1224 } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
1225 addEnforcedVertex(faceItem, 0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
1231 myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
1232 myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
1234 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1235 myEnforcedTreeWidget->resizeColumnToContents(column);
1237 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
1238 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
1239 myStdWidget->onPhysicalMeshChanged();
1243 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
1244 This method is called when a item is removed from the enforced vertices tree widget
1246 void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
1247 // MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
1248 QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
1249 QList<QTreeWidgetItem *> selectedVertices;
1250 QSet<QTreeWidgetItem *> selectedEntries;
1251 QTreeWidgetItem* item;
1253 foreach( item, selectedItems ) {
1254 QVariant value = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
1255 if (! value.isNull())
1256 selectedVertices.append(item);
1258 value = item->data(ENF_VER_ENTRY_COLUMN, Qt::EditRole);
1259 if (! value.isNull())
1260 selectedVertices.append(item);
1262 selectedEntries.insert(item);
1266 foreach(item,selectedVertices) {
1267 QTreeWidgetItem* parent = item->parent();
1268 // MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1269 parent->removeChild(item);
1271 if (parent->childCount() == 0) {
1272 if (selectedEntries.contains(parent))
1273 selectedEntries.remove(parent);
1278 foreach(item,selectedEntries) {
1279 // MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
1283 myEnforcedTreeWidget->selectionModel()->clearSelection();
1287 void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
1289 myInternalEnforcedVerticesAllFacesGroup->setEnabled(state == Qt::Checked);
1292 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
1293 This method updates the GUI widgets with the hypothesis data
1295 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
1297 MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
1298 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1300 BlsurfHypothesisData data;
1301 that->readParamsFromHypo( data );
1304 myName->setText( data.myName );
1305 QFontMetrics metrics( myName->font() );
1306 myName->setMinimumWidth( metrics.width( data.myName )+5 );
1308 myStdWidget->myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
1309 myStdWidget->myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
1310 if (data.myPhySize <= 0)
1311 myStdWidget->myPhySize->setText("");
1313 myStdWidget->myPhySize->SetValue( data.myPhySize );
1314 myStdWidget->myPhySizeRel->setChecked( data.myPhySizeRel );
1315 if (data.myMinSize < 0)
1316 myStdWidget->myMinSize->setText("");
1318 myStdWidget->myMinSize->SetValue( data.myMinSize );
1319 myStdWidget->myMinSizeRel->setChecked( data.myMinSizeRel );
1320 if (data.myMaxSize < 0)
1321 myStdWidget->myMaxSize->setText("");
1323 myStdWidget->myMaxSize->SetValue( data.myMaxSize );
1324 myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
1325 if (data.myGradation <= 0)
1326 myStdWidget->myGradation->setText("");
1328 myStdWidget->myGradation->SetValue( data.myGradation );
1329 myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
1331 if (data.myAngleMesh < 0)
1332 myStdWidget->myAngleMesh->setText("");
1334 myStdWidget->myAngleMesh->SetValue( data.myAngleMesh );
1335 if (data.myChordalError <= 0)
1336 myStdWidget->myChordalError->setText("");
1338 myStdWidget->myChordalError->SetValue( data.myChordalError );
1339 myStdWidget->myAnisotropic->setChecked( data.myAnisotropic );
1340 if (data.myAnisotropicRatio <= 0)
1341 myStdWidget->myAnisotropicRatio->setText("");
1343 myStdWidget->myAnisotropicRatio->SetValue( data.myAnisotropicRatio );
1344 myStdWidget->myRemoveTinyEdges->setChecked( data.myRemoveTinyEdges );
1345 if (data.myTinyEdgeLength <= 0)
1346 myStdWidget->myTinyEdgeLength->setText("");
1348 myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
1349 myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
1350 if (data.myBadElementAspectRatio <= 0)
1351 myStdWidget->myBadElementAspectRatio->setText("");
1353 myStdWidget->myBadElementAspectRatio->SetValue( data.myBadElementAspectRatio );
1354 myStdWidget->myOptimizeMesh->setChecked( data.myOptimizeMesh );
1355 myStdWidget->myQuadraticMesh->setChecked( data.myQuadraticMesh );
1357 myStdWidget->resizeWidgets();
1359 myAdvWidget->myVerbosity->setValue( data.myVerbosity );
1360 myAdvWidget->myPreCADGroupBox->setChecked(data.myTopology == PreCAD);
1361 myAdvWidget->myPreCADMergeEdges->setChecked( data.myPreCADMergeEdges );
1362 myAdvWidget->myPreCADProcess3DTopology->setChecked( data.myPreCADProcess3DTopology );
1363 myAdvWidget->myPreCADDiscardInput->setChecked( data.myPreCADDiscardInput );
1365 if ( myOptions.operator->() ) {
1366 // MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
1367 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
1368 QString option = that->myOptions[i].in();
1369 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1370 if ( name_value.count() > 1 ) {
1371 QString idStr = QString("%1").arg( i );
1372 int row = myAdvWidget->myOptionTable->rowCount();
1373 myAdvWidget->myOptionTable->setRowCount( row+1 );
1374 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1375 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1376 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "BLSURF" ) );
1377 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1378 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1379 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1380 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1381 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1382 Qt::ItemIsEditable |
1383 Qt::ItemIsEnabled );
1387 if ( myPreCADOptions.operator->() ) {
1388 // MESSAGE("retrieveParams():myPreCADOptions->length() = " << myPreCADOptions->length());
1389 for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
1390 QString option = that->myPreCADOptions[i].in();
1391 QStringList name_value = option.split( ":", QString::KeepEmptyParts );
1392 if ( name_value.count() > 1 ) {
1393 QString idStr = QString("%1").arg( i );
1394 int row = myAdvWidget->myOptionTable->rowCount();
1395 myAdvWidget->myOptionTable->setRowCount( row+1 );
1396 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
1397 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
1398 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "PRECAD" ) );
1399 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
1400 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
1401 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
1402 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
1403 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
1404 Qt::ItemIsEditable |
1405 Qt::ItemIsEnabled );
1409 myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
1410 myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
1411 // myGMFFileMode->setChecked(data.myGMFFileMode);
1414 MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
1415 QMapIterator<QString, QString> i(that->mySMPMap);
1416 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1417 while (i.hasNext()) {
1419 const QString entry = i.key();
1420 const QString sizeMap = i.value();
1421 string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
1422 int row = mySizeMapTable->topLevelItemCount();
1423 QTreeWidgetItem* item = new QTreeWidgetItem();
1424 mySizeMapTable->addTopLevelItem( item );
1425 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
1426 item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
1427 item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
1428 if (that->myATTMap.contains(entry)){
1429 const QString attEntry = that->myATTMap[entry];
1430 std::string attName = myGeomToolSelected->getNameFromEntry(attEntry.toStdString());
1431 QTreeWidgetItem* child = new QTreeWidgetItem();
1432 item->addChild( child );
1433 item->setExpanded(true);
1434 child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1435 child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attEntry ) );
1436 child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString( attName ) ) );
1438 if (that->myAttDistMap[entry] > std::numeric_limits<double>::epsilon()){
1439 item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Attractor" ) ) );
1442 item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Constant Size" ) ) );
1447 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
1450 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
1451 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
1452 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
1454 // Enforced vertices
1455 MESSAGE("retrieveParams(): data.entryCoordsListMap.size() = " << data.faceEntryEnfVertexListMap.size());
1456 TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
1458 for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
1459 TEntry entry = (*evmIt).first;
1460 std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
1461 MESSAGE("Face entry: " << entry);
1462 MESSAGE("Face name: " << shapeName);
1464 QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
1466 TEnfVertexList evs = (*evmIt).second;
1468 TEnfVertexList::const_iterator evsIt = evs.begin();
1469 TEnfVertex *enfVertex;
1470 for ( ; evsIt != evs.end() ; ++evsIt) {
1471 enfVertex = (*evsIt);
1472 MESSAGE("Name: " << enfVertex->name);
1474 if (enfVertex->coords.size()) {
1475 x = enfVertex->coords[0];
1476 y = enfVertex->coords[1];
1477 z = enfVertex->coords[2];
1479 that->addEnforcedVertex(faceItem, x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
1483 for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
1484 myEnforcedTreeWidget->resizeColumnToContents(column);
1486 myInternalEnforcedVerticesAllFaces->setChecked(data.myInternalEnforcedVerticesAllFaces);
1487 myInternalEnforcedVerticesAllFacesGroup->setText(QString(data.myInternalEnforcedVerticesAllFacesGroup.c_str()));
1488 myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
1491 that->myStdWidget->onPhysicalMeshChanged();
1492 that->myStdWidget->onGeometricMeshChanged();
1495 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
1496 This method updates the hypothesis data with the GUI widgets content.
1498 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
1500 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1502 BlsurfHypothesisData data;
1503 QString guiHyp = that->readParamsFromWidgets( data );
1504 that->storeParamsToHypo( data );
1509 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo(h_data)
1510 Updates the hypothesis data from hypothesis values.
1512 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
1514 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
1515 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1516 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
1518 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
1519 h_data.myName = isCreation() && data ? hypName() : "";
1521 h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
1522 h_data.myGeometricMesh = (int) h->GetGeometricMesh();
1523 h_data.myPhySize = h->GetPhySize();
1524 h_data.myPhySizeRel = h->IsPhySizeRel();
1525 double minSize = h->GetMinSize();
1526 double maxSize = h->GetMaxSize();
1527 h_data.myMinSize = minSize > 0 ? minSize : -1.0;
1528 h_data.myMinSizeRel = h->IsMinSizeRel();
1529 h_data.myMaxSize = maxSize > 0 ? maxSize : -1.0;
1530 h_data.myMaxSizeRel = h->IsMaxSizeRel();
1531 h_data.myGradation = h->GetGradation();
1532 h_data.myAllowQuadrangles = h->GetQuadAllowed();
1533 double angle = h->GetAngleMesh();
1534 h_data.myAngleMesh = angle > 0 ? angle : -1.0;
1535 double chordalError = h->GetChordalError();
1536 h_data.myChordalError = chordalError > 0 ? chordalError : -1.0;
1537 h_data.myAnisotropic = h->GetAnisotropic();
1538 double myAnisotropicRatio = h->GetAnisotropicRatio();
1539 h_data.myAnisotropicRatio = myAnisotropicRatio > 0 ? myAnisotropicRatio : -1.0;
1540 h_data.myRemoveTinyEdges = h->GetRemoveTinyEdges();
1541 double myTinyEdgeLength = h->GetTinyEdgeLength();
1542 h_data.myTinyEdgeLength = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
1543 h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
1544 double myBadElementAspectRatio = h->GetBadElementAspectRatio();
1545 h_data.myBadElementAspectRatio = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
1546 h_data.myOptimizeMesh = h->GetOptimizeMesh();
1547 h_data.myQuadraticMesh = h->GetQuadraticMesh();
1548 h_data.myVerbosity = h->GetVerbosity();
1549 h_data.myTopology = (int) h->GetTopology();
1550 h_data.myPreCADMergeEdges = h->GetPreCADMergeEdges();
1551 h_data.myPreCADProcess3DTopology = h->GetPreCADProcess3DTopology();
1552 h_data.myPreCADDiscardInput = h->GetPreCADDiscardInput();
1555 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1556 that->myOptions = h->GetOptionValues();
1557 that->myPreCADOptions = h->GetPreCADOptionValues();
1559 h_data.myGMFFileName = h->GetGMFFile();
1560 // h_data.myGMFFileMode = h->GetGMFFileMode();
1562 that->mySMPMap.clear();
1563 that->myATTMap.clear();
1564 that->myAttDistMap.clear();
1565 that->myDistMap.clear();
1567 // classic size maps
1568 BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
1569 // MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
1570 QString fullSizeMaps;
1571 QStringList fullSizeMapList;
1572 GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
1573 for ( int i = 0;i<mySizeMaps->length(); ++i ) {
1574 fullSizeMaps = mySizeMaps[i].in();
1575 // MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
1576 fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
1577 if ( fullSizeMapList.count() > 1 ) {
1578 string fullSizeMap = fullSizeMapList[1].toStdString();
1579 int pos = fullSizeMap.find("return")+7;
1580 // MESSAGE("pos:" << pos);
1583 sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
1588 that->mySMPMap[fullSizeMapList[0]] = sizeMap;
1589 // MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
1590 that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
1591 // MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
1597 BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
1598 MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
1600 for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
1601 QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
1602 QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
1603 if ( fullCustomSizeMapList.count() > 1 ) {
1604 that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
1605 that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
1606 MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
1607 MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
1612 BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
1613 // MESSAGE("myAttractors->length() = " << allMyAttractors->length());
1615 for ( int i = 0;i<allMyAttractors->length(); ++i ) {
1616 QString myAttractors = allMyAttractors[i].in();
1617 QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
1618 if ( myAttractorList.count() > 1 ) {
1619 that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
1620 that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
1621 // MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
1622 // MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
1626 // attractor new version
1627 MESSAGE("retrieveParams, Attractors")
1628 BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
1629 for ( int i = 0;i<allMyAttractorParams->length(); ++i ) {
1630 BLSURFPlugin::TAttractorParams myAttractorParams = allMyAttractorParams[i];
1631 QString faceEntry = myAttractorParams.faceEntry.in();
1632 QString attEntry = myAttractorParams.attEntry.in();
1633 MESSAGE("attEntry = "<<attEntry.toStdString())
1634 double startSize = myAttractorParams.startSize;
1635 double endSize = myAttractorParams.endSize;
1636 double infDist = myAttractorParams.infDist;
1637 double constDist = myAttractorParams.constDist;
1638 that->mySMPMap[faceEntry] = QString::number( startSize, 'g', 6 ); // TODO utiliser les préférences ici (cf. sketcher)
1639 that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
1640 that->myATTMap[faceEntry] = attEntry;
1641 that->myAttDistMap[faceEntry] = infDist;
1642 that->myDistMap[faceEntry] = constDist;
1645 // Enforced vertices
1646 h_data.enfVertexList.clear();
1647 h_data.faceEntryEnfVertexListMap.clear();
1649 h_data.groupNameEnfVertexListMap.clear();
1652 BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
1653 MESSAGE("faceEntryEnfVertexListMap->length() = " << faceEntryEnfVertexListMap->length());
1655 for ( int i = 0;i<faceEntryEnfVertexListMap->length(); ++i ) {
1656 std::string entry = faceEntryEnfVertexListMap[i].faceEntry.in();
1657 // BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList.in();
1658 BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
1659 // BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
1661 // TEnfVertexList& enfVertexList = h_data.faceEntryEnfVertexListMap[entry];
1663 for (int j=0 ; j<vertexList.length(); ++j) {
1664 TEnfVertex *enfVertex = new TEnfVertex();
1666 enfVertex->name = CORBA::string_dup(vertexList[j].name.in());
1667 enfVertex->geomEntry = CORBA::string_dup(vertexList[j].geomEntry.in());
1668 enfVertex->grpName = CORBA::string_dup(vertexList[j].grpName.in());
1669 for (int k=0 ; k< vertexList[j].coords.length();k++)
1670 enfVertex->coords.push_back(vertexList[j].coords[k]);
1672 h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
1675 if (groupName != "") {
1676 h_data.groupNameEnfVertexListMap[groupName].insert(ev);
1680 // h_data.enfVertMap[entry] = evs;
1681 // h_data.entryCoordsListMap[entry] = coordsList;
1683 if (h_data.faceEntryEnfVertexListMap[entry].size() == 0) {
1684 h_data.faceEntryEnfVertexListMap.erase(entry);
1687 h_data.myInternalEnforcedVerticesAllFaces = h->GetInternalEnforcedVertexAllFaces();
1688 h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
1693 /** BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo(h_data)
1694 Saves the hypothesis data to hypothesis values.
1696 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
1698 MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
1699 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
1700 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
1706 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
1708 if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh ) // avoid duplication of DumpPython commands
1709 h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
1710 if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
1711 h->SetGeometricMesh( (int) h_data.myGeometricMesh );
1713 if ( ((int) h_data.myPhysicalMesh == PhysicalGlobalSize)||((int) h_data.myPhysicalMesh == PhysicalLocalSize) ) {
1714 if ( h->GetPhySize() != h_data.myPhySize ||
1715 h->IsPhySizeRel() != h_data.myPhySizeRel ) {
1716 if ( h_data.myPhySizeRel )
1717 h->SetPhySizeRel( h_data.myPhySize );
1719 h->SetPhySize( h_data.myPhySize );
1722 if (h->GetMinSize() != h_data.myMinSize ||
1723 h->IsMinSizeRel() != h_data.myMinSizeRel ) {
1724 if ( h_data.myMinSizeRel )
1725 h->SetMinSizeRel( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1727 h->SetMinSize( h_data.myMinSize <= 0 ? -1 : h_data.myMinSize );
1729 if (h->GetMaxSize() != h_data.myMaxSize ||
1730 h->IsMaxSizeRel() != h_data.myMaxSizeRel ) {
1731 if ( h_data.myMaxSizeRel )
1732 h->SetMaxSizeRel( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1734 h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
1736 if ( h->GetGradation() != h_data.myGradation )
1737 h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
1738 if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
1739 h->SetQuadAllowed( h_data.myAllowQuadrangles );
1741 if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
1742 if ( h->GetAngleMesh() != h_data.myAngleMesh )
1743 h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
1744 if ( h->GetChordalError() != h_data.myChordalError )
1745 h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
1748 if ( h->GetAnisotropic() != h_data.myAnisotropic )
1749 h->SetAnisotropic( h_data.myAnisotropic );
1750 if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
1751 h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
1753 if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
1754 h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
1755 if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
1756 h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
1758 if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
1759 h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
1760 if ( h_data.myForceBadElementRemoval && ( h->GetBadElementAspectRatio() != h_data.myBadElementAspectRatio ) )
1761 h->SetBadElementAspectRatio( h_data.myBadElementAspectRatio <= 0 ? -1 :h_data.myBadElementAspectRatio );
1763 if ( h->GetOptimizeMesh() != h_data.myOptimizeMesh )
1764 h->SetOptimizeMesh( h_data.myOptimizeMesh );
1766 if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
1767 h->SetQuadraticMesh( h_data.myQuadraticMesh );
1769 if ( h->GetVerbosity() != h_data.myVerbosity )
1770 h->SetVerbosity( h_data.myVerbosity );
1771 if ( h->GetTopology() != h_data.myTopology )
1772 h->SetTopology( (int) h_data.myTopology );
1773 if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
1774 h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
1775 if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
1776 h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
1777 if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
1778 h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
1780 h->SetOptionValues( myOptions ); // is set in checkParams()
1781 h->SetPreCADOptionValues( myPreCADOptions ); // is set in checkParams()
1783 if ( h->GetGMFFile() != h_data.myGMFFileName )
1784 // || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
1785 // h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
1786 h->SetGMFFile( h_data.myGMFFileName.c_str());
1788 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1789 QMapIterator<QString,QString> i(that->mySMPMap);
1790 while (i.hasNext()) {
1792 const QString entry = i.key();
1793 const QString sizeMap = i.value();
1795 if (sizeMap == "__TO_DELETE__") {
1796 MESSAGE("Delete entry " << entry.toStdString() << " from engine");
1797 h->UnsetEntry(entry.toLatin1().constData());
1799 else if (sizeMap.startsWith("ATTRACTOR")) {
1800 // MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1801 h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
1803 else if (sizeMap.startsWith("def")) {
1804 // MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
1805 // h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
1808 if (!myATTMap[entry].isEmpty()){
1809 QString att_entry = myATTMap[entry];
1810 double infDist = myAttDistMap[entry];
1811 double constDist = myDistMap[entry];
1812 double phySize = h->GetPhySize();
1813 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1814 h->SetClassAttractorEntry( entry.toLatin1().constData(), att_entry.toLatin1().constData(), sizeMap.toDouble() , phySize, infDist, constDist );
1815 QApplication::restoreOverrideCursor();
1818 QString fullSizeMap;
1819 fullSizeMap = QString("");
1820 if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
1821 fullSizeMap = QString("def f(u,v): return ") + sizeMap;
1822 else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
1823 fullSizeMap = QString("def f(t): return ") + sizeMap;
1824 else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
1825 fullSizeMap = QString("def f(): return ") + sizeMap;
1826 MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
1827 h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
1832 // Enforced vertices
1835 std::string enfName;
1837 std::string groupName = "";
1840 TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
1841 // 1. Clear all enforced vertices in hypothesis
1842 // 2. Add new enforced vertex according to h_data
1844 if ( h->GetAllEnforcedVertices()->length() > 0 )
1845 h->ClearAllEnforcedVertices();
1848 TEnfVertexList::const_iterator evsIt;
1849 for ( ; evmIt != h_data.faceEntryEnfVertexListMap.end() ; ++evmIt)
1851 faceEntry = evmIt->first;
1852 evs = evmIt->second;
1853 MESSAGE("Number of enforced vertices for face entry " << faceEntry << ": " << evs.size());
1854 evsIt = evs.begin();
1855 for ( ; evsIt != evs.end() ; ++evsIt)
1858 if ((*evsIt)->coords.size()) {
1859 x = (*evsIt)->coords[0];
1860 y = (*evsIt)->coords[1];
1861 z = (*evsIt)->coords[2];
1863 ret = h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
1867 if ( h->GetInternalEnforcedVertexAllFaces() != h_data.myInternalEnforcedVerticesAllFaces )
1868 h->SetInternalEnforcedVertexAllFaces( h_data.myInternalEnforcedVerticesAllFaces );
1869 if ( h->GetInternalEnforcedVertexAllFacesGroup() != h_data.myInternalEnforcedVerticesAllFacesGroup )
1870 h->SetInternalEnforcedVertexAllFacesGroup( h_data.myInternalEnforcedVerticesAllFacesGroup.c_str() );
1873 catch(const std::exception& ex) {
1874 std::cout << "Exception: " << ex.what() << std::endl;
1877 // catch(const SALOME::SALOME_Exception& ex)
1880 // // SalomeApp_Tools::QtCatchCorbaException(ex);
1886 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
1887 Stores the widgets content to the hypothesis data.
1889 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
1891 MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
1892 h_data.myName = myName ? myName->text() : "";
1893 h_data.myPhysicalMesh = myStdWidget->myPhysicalMesh->currentIndex();
1894 h_data.myGeometricMesh = myStdWidget->myGeometricMesh->currentIndex();
1895 h_data.myPhySize = myStdWidget->myPhySize->text().isEmpty() ? -1.0 : myStdWidget->myPhySize->GetValue();
1896 h_data.myPhySizeRel = myStdWidget->myPhySizeRel->isChecked();
1897 h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? -1.0 : myStdWidget->myMinSize->GetValue();
1898 h_data.myMinSizeRel = myStdWidget->myMinSizeRel->isChecked();
1899 h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
1900 h_data.myMaxSizeRel = myStdWidget->myMaxSizeRel->isChecked();
1901 h_data.myGradation = myStdWidget->myGradation->text().isEmpty() ? -1.0 : myStdWidget->myGradation->GetValue();
1902 h_data.myAllowQuadrangles = myStdWidget->myAllowQuadrangles->isChecked();
1903 h_data.myAngleMesh = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
1904 h_data.myChordalError = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
1905 h_data.myAnisotropic = myStdWidget->myAnisotropic->isChecked();
1906 h_data.myAnisotropicRatio = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
1907 h_data.myRemoveTinyEdges = myStdWidget->myRemoveTinyEdges->isChecked();
1908 h_data.myTinyEdgeLength = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
1909 h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
1910 h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
1911 h_data.myOptimizeMesh = myStdWidget->myOptimizeMesh->isChecked();
1912 h_data.myQuadraticMesh = myStdWidget->myQuadraticMesh->isChecked();
1913 h_data.myVerbosity = myAdvWidget->myVerbosity->value();
1914 h_data.myTopology = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
1915 h_data.myPreCADMergeEdges = myAdvWidget->myPreCADMergeEdges->isChecked();
1916 h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
1917 h_data.myPreCADDiscardInput = myAdvWidget->myPreCADDiscardInput->isChecked();
1920 guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
1921 guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
1922 guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( h_data.myPhySize ) + "; ";
1923 guiHyp += tr("BLSURF_HPHYDEF") + " " + tr("BLSURF_SIZE_REL") +" = " + QString(h_data.myPhySizeRel ? "yes" : "no") + "; ";
1924 guiHyp += tr("BLSURF_MINSIZE") + " = "+ QString::number( h_data.myMinSize ) + "; ";
1925 guiHyp += tr("BLSURF_MINSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMinSizeRel ? "yes" : "no") + "; ";
1926 guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
1927 guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
1928 guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
1929 guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
1930 guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
1931 guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
1932 guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
1933 guiHyp += tr("BLSURF_ANISOTROPIC_RATIO") + " = " + QString::number( h_data.myAnisotropicRatio ) + "; ";
1936 guiHyp += tr("BLSURF_REMOVE_TINY_EDGES") + " = " + QString(h_data.myRemoveTinyEdges ? "yes" : "no") + "; ";
1937 guiHyp += tr("BLSURF_TINY_EDGES_LENGTH") + " = " + QString::number( h_data.myTinyEdgeLength ) + "; ";
1938 guiHyp += tr("BLSURF_REMOVE_SLIVERS") + " = " + QString(h_data.myForceBadElementRemoval ? "yes" : "no") + "; ";
1939 guiHyp += tr("BLSURF_BAD_SURFACE_ELEMENT_ASPECT_RATIO") + " = " + QString::number( h_data.myBadElementAspectRatio ) + "; ";
1940 guiHyp += tr("BLSURF_OPTIMISATION") + " = " + QString(h_data.myOptimizeMesh ? "yes" : "no") + "; ";
1941 guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
1944 guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
1945 guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
1946 guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
1947 guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
1949 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
1950 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
1951 for ( ; row < nbRows; ++row )
1953 int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
1954 std::string optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().toStdString();
1955 if ( id >= 0 && ( ( optionType == "BLSURF" && id < myOptions->length() ) || ( optionType == "PRECAD" && id < myPreCADOptions->length() ) ) )
1957 QString name = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
1958 QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
1959 if ( value.isNull() )
1961 if (optionType == "PRECAD")
1962 that->myPreCADOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1964 that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
1966 if ( value != "" ) {
1967 if (optionType == "PRECAD")
1968 guiHyp += "PRECAD_";
1969 guiHyp += name + " = " + value + "; ";
1974 h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
1975 // h_data.myGMFFileMode = myGMFFileMode->isChecked();
1978 row = 0, nbRows = mySizeMapTable->topLevelItemCount();
1979 for ( ; row < nbRows; ++row )
1981 QString entry = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
1982 if ( that->mySMPMap.contains(entry) )
1983 guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
1986 // Enforced vertices
1987 h_data.enfVertexList.clear();
1988 h_data.faceEntryEnfVertexListMap.clear();
1990 int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
1991 int nbEnforcedVertices = 0;
1992 std::string groupName = "";
1993 // MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
1994 for (int i=0 ; i<nbEnforcedShapes ; i++) {
1995 QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
1997 std::string faceEntry = shapeItem->data(ENF_VER_FACE_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
1998 nbEnforcedVertices = shapeItem->childCount();
1999 if (nbEnforcedVertices >0) {
2000 double childValueX,childValueY,childValueZ;
2001 std::string childName, vertexEntry;
2002 QTreeWidgetItem* child;
2005 for (row = 0;row<nbEnforcedVertices;row++) {
2006 child = shapeItem->child(row);
2007 childName = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
2008 childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
2009 childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
2010 childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
2011 vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
2012 // if (myGlobalGroupName->isChecked())
2013 // groupName = myGlobalGroupName->text().toStdString();
2015 groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
2017 TEnfVertex *enfVertex = new TEnfVertex();
2018 enfVertex->name = childName;
2019 if (vertexEntry.empty()) {
2020 enfVertex->coords.push_back(childValueX);
2021 enfVertex->coords.push_back(childValueY);
2022 enfVertex->coords.push_back(childValueZ);
2025 enfVertex->geomEntry = vertexEntry;
2026 enfVertex->grpName = groupName;
2027 // TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
2028 // if (it == h_data.enfVertexList.end())
2029 h_data.enfVertexList.insert(enfVertex);
2030 evs.insert(enfVertex);
2032 if (groupName != "")
2033 h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
2036 h_data.faceEntryEnfVertexListMap[faceEntry] = evs;
2041 h_data.myInternalEnforcedVerticesAllFaces = myInternalEnforcedVerticesAllFaces->isChecked();
2042 h_data.myInternalEnforcedVerticesAllFacesGroup = myInternalEnforcedVerticesAllFacesGroup->text().toStdString();
2044 MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
2048 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
2050 QMenu* menu = (QMenu*)sender();
2051 // fill popup with option names
2053 QString name_value, name;
2054 if ( myOptions.operator->() ) {
2055 QMenu* blsurfMenu = menu->addMenu(tr("OPTION_MENU_BLSURF"));
2056 for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
2057 name_value = myOptions[i].in();
2058 name = name_value.split( ":", QString::KeepEmptyParts )[0];
2059 blsurfMenu->addAction( name );
2062 if ( myPreCADOptions.operator->() ) {
2063 QMenu* preCADmenu = menu->addMenu(tr("OPTION_MENU_PRECAD"));
2064 for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
2065 name_value = myPreCADOptions[i].in();
2066 name = name_value.split( ":", QString::KeepEmptyParts )[0];
2067 preCADmenu->addAction( name );
2072 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
2074 myAdvWidget->myOptionTable->setFocus();
2075 QMenu* menu = (QMenu*)( a->parent() );
2077 int idx = menu->actions().indexOf( a );
2078 QString idStr = QString("%1").arg( idx );
2079 QString option, optionType;
2080 if (menu->title() == tr("OPTION_MENU_BLSURF")) {
2081 option = myOptions[idx].in();
2082 optionType = "BLSURF";
2084 else if (menu->title() == tr("OPTION_MENU_PRECAD")) {
2085 option = myPreCADOptions[idx].in();
2086 optionType = "PRECAD";
2088 QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
2090 // look for a row with optionName
2091 int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
2092 for ( ; row < nbRows; ++row )
2093 if ( myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
2094 if ( myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text() == optionType )
2096 // add a row if not found
2097 if ( row == nbRows ) {
2098 myAdvWidget->myOptionTable->setRowCount( row+1 );
2099 myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
2100 myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
2101 myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( optionType ) );
2102 myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
2103 myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
2104 myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
2105 myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
2106 myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
2107 Qt::ItemIsEditable |
2108 Qt::ItemIsEnabled );
2109 myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
2111 myAdvWidget->myOptionTable->clearSelection();
2112 myAdvWidget->myOptionTable->scrollToItem( myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2113 //myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
2114 myAdvWidget->myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
2115 //myAdvWidget->myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
2118 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
2120 // clear option values and remember selected row
2121 QList<int> selectedRows;
2122 QList<QTableWidgetItem*> selected = myAdvWidget->myOptionTable->selectedItems();
2123 QTableWidgetItem* item;
2124 foreach( item, selected ) {
2125 int row = item->row();
2126 if ( !selectedRows.contains( row ) ) {
2127 selectedRows.append( row );
2128 int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
2129 QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text();
2131 if (optionType == "BLSURF" && id < myOptions->length() )
2132 myOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2133 else if (optionType == "PRECAD" && id < myPreCADOptions->length() )
2134 myPreCADOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
2137 qSort( selectedRows );
2138 QListIterator<int> it( selectedRows );
2140 while ( it.hasPrevious() )
2141 myAdvWidget->myOptionTable->removeRow( it.previous() );
2144 // **********************
2145 // *** BEGIN SIZE MAP ***
2146 // **********************
2148 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
2150 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2152 if ( myGeomSelWdg2->IsObjectSelected() ){
2153 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2155 else if ( myGeomSelWdg1->IsObjectSelected() ){
2156 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2158 std::string entry = (string) mySMapObject->GetStudyEntry();
2159 QString qEntry = QString::fromStdString(entry);
2160 if (that->mySMPMap.contains(qEntry) && that->mySMPMap[qEntry] != "__TO_DELETE__" ) {
2161 addMapButton->setEnabled(false);
2162 modifyMapButton->setEnabled(true);
2165 addMapButton->setEnabled(true);
2166 modifyMapButton->setEnabled(false);
2171 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
2173 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked("<<col<<")")
2174 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2175 if (col == SMP_SIZEMAP_COLUMN){
2176 QString entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2177 if (!mySMPMap.contains(entry))
2179 QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
2180 CORBA::Object_var obj = entryToObject(entry);
2181 if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")){ // ADVANCED MAPS
2182 smpTab->setCurrentIndex(ATT_TAB); // Change Tab
2183 double phySize = that->mySMPMap[entry].toDouble(); // Retrieve values of the selected item in the current tab widgets
2184 double infDist = that->myAttDistMap[entry];
2185 double constDist = that->myDistMap[entry];
2186 QString attEntry = that->myATTMap[entry];
2187 CORBA::Object_var attObj = entryToObject(attEntry);
2188 myAttSizeSpin->setValue(phySize);
2189 if (sizeMap.startsWith("Attractor")){
2190 myAttDistSpin->setValue(infDist);
2191 myAttractorCheck->setChecked(true);
2194 myAttractorCheck->setChecked(false);
2196 if (sizeMap.startsWith("Constant") || constDist > std::numeric_limits<double>::epsilon()){
2197 myAttDistSpin2->setValue(constDist);
2198 myConstSizeCheck->setChecked(true);
2201 myConstSizeCheck->setChecked(false);
2203 myGeomSelWdg2->SetObject(obj);
2204 myAttSelWdg->SetObject(attObj);
2206 else { // CLASSIC MAPS
2207 smpTab->setCurrentIndex(SMP_STD_TAB); // Change Tab
2208 myGeomSelWdg1->SetObject(obj); // Retrieve values of the selected item in the current tab widgets
2209 if (!sizeMap.startsWith("def")){
2210 mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
2216 void BLSURFPluginGUI_HypothesisCreator::onSmpTabChanged(int tab)
2218 myAttDistSpin->setValue(0.); // Reinitialize widgets
2219 myAttSizeSpin->setValue(0.);
2220 myAttDistSpin2->setValue(0.);
2221 mySmpSizeSpin->setValue(0.);
2222 myGeomSelWdg1->deactivateSelection();
2223 myGeomSelWdg2->deactivateSelection();
2224 myAttSelWdg->deactivateSelection();
2225 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2226 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2227 myAttSelWdg->SetObject(CORBA::Object::_nil());
2228 myAttractorCheck->setChecked(false);
2229 myConstSizeCheck->setChecked(false);
2232 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
2234 if (state == Qt::Checked){
2235 myAttSelWdg->setEnabled(true);
2236 myAttSizeSpin->setEnabled(true);
2237 myAttSizeLabel->setEnabled(true);
2238 myAttDistSpin->setEnabled(true);
2239 myAttDistLabel->setEnabled(true);
2240 if (!myAttSelWdg->IsObjectSelected()){
2241 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2244 if (state == Qt::Unchecked){
2245 myAttDistSpin->setEnabled(false);
2246 myAttDistLabel->setEnabled(false);
2247 myAttDistSpin->setValue(0.);
2248 if(myConstSizeCheck->checkState() == Qt::Unchecked){ // No predefined map selected
2249 myAttSelWdg->setEnabled(false);
2250 myAttSizeSpin->setEnabled(false);
2251 myAttSizeLabel->setEnabled(false);
2252 myAttDistSpin2->setEnabled(false);
2253 myAttDistLabel2->setEnabled(false);
2255 else if (!myAttSelWdg->IsObjectSelected()){ // Only constant size selected
2256 myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2261 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
2263 if (state == Qt::Checked){
2264 myAttSelWdg->setEnabled(true);
2265 myAttSizeSpin->setEnabled(true);
2266 myAttSizeLabel->setEnabled(true);
2267 myAttDistSpin2->setEnabled(true);
2268 myAttDistLabel2->setEnabled(true);
2269 if (myAttractorCheck->checkState() == Qt::Unchecked &&
2270 !myAttSelWdg->IsObjectSelected()){
2271 myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
2274 if (state == Qt::Unchecked){
2275 myAttDistSpin2->setEnabled(false);
2276 myAttDistLabel2->setEnabled(false);
2277 myAttDistSpin2->setValue(0.);
2278 if(myAttractorCheck->checkState() == Qt::Unchecked){ // No predefined map selected
2279 myAttSelWdg->setEnabled(false);
2280 myAttSizeSpin->setEnabled(false);
2281 myAttSizeLabel->setEnabled(false);
2282 myAttDistSpin->setEnabled(false);
2283 myAttDistLabel->setEnabled(false);
2285 else if (!myAttSelWdg->IsObjectSelected()){ // Only constant size selected
2286 myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
2291 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
2293 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
2294 QList<int> selectedRows;
2295 QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
2296 QTreeWidgetItem* item;
2297 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2299 qSort( selectedRows );
2300 QListIterator<QTreeWidgetItem*> it( selected );
2302 while ( it.hasPrevious() ) {
2303 item = it.previous();
2304 QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2305 if (that->mySMPMap.contains(entry))
2306 that->mySMPMap[entry] = "__TO_DELETE__";
2307 if (that->mySMPShapeTypeMap.contains(entry))
2308 that->mySMPShapeTypeMap.remove(entry);
2309 if (that->myATTMap.contains(entry))
2310 that->myATTMap.remove(entry);
2311 if (that->myDistMap.contains(entry))
2312 that->myDistMap.remove(entry);
2313 if (that->myAttDistMap.contains(entry))
2314 that->myAttDistMap.remove(entry);
2317 mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
2318 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2321 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
2323 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< col << ")");
2324 MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2325 if (col == SMP_SIZEMAP_COLUMN) {
2326 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2327 QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
2328 QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
2329 MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
2330 if (! that->mySMPShapeTypeMap.contains(entry))
2331 MESSAGE("no such entry in mySMPShapeTypeMap")
2333 if (that->mySMPMap.contains(entry))
2334 if (that->mySMPMap[entry] == sizeMap
2335 || sizeMap.startsWith("Attractor")
2336 || sizeMap.startsWith("Constant") ){
2339 if (! sizeMap.isEmpty()) {
2340 that->mySMPMap[entry] = sizeMap;
2341 sizeMapValidationFromEntry(entry);
2344 MESSAGE("Size map empty: reverse to precedent value" );
2345 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
2347 mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
2351 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
2353 if ( smpTab->currentIndex() == ATT_TAB ){
2354 if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
2355 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2356 myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2357 insertAttractor(mySMapObject, myAttObject);
2360 if (smpTab->currentIndex() == SMP_STD_TAB ){
2361 if ( myGeomSelWdg1->IsObjectSelected() ){
2362 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2363 insertElement(mySMapObject);
2366 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2367 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2368 myAttDistSpin->setValue(0.);
2369 myAttSizeSpin->setValue(0.);
2370 myAttDistSpin2->setValue(0.);
2371 mySmpSizeSpin->setValue(0.);
2372 myConstSizeCheck->setChecked(false);
2373 myAttractorCheck->setChecked(false);
2374 myGeomSelWdg1->deactivateSelection();
2375 myGeomSelWdg2->deactivateSelection();
2376 myAttSelWdg->deactivateSelection();
2377 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2378 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2379 myAttSelWdg->SetObject(CORBA::Object::_nil());
2382 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
2384 MESSAGE("BLSURFPluginGUI_HypothesisCreator::onModifyMap()");
2385 if ( smpTab->currentIndex() == ATT_TAB ){
2386 if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
2387 mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
2388 myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
2389 insertAttractor(mySMapObject, myAttObject, /*modify = */true);
2392 if (smpTab->currentIndex() == SMP_STD_TAB ){
2393 if ( myGeomSelWdg1->IsObjectSelected() ){
2394 mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
2395 insertElement(mySMapObject, /*modify = */true);
2398 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2399 that->getGeomSelectionTool()->selectionMgr()->clearFilters();
2400 myAttDistSpin->setValue(0.);
2401 myAttSizeSpin->setValue(0.);
2402 myAttDistSpin2->setValue(0.);
2403 mySmpSizeSpin->setValue(0.);
2404 myConstSizeCheck->setChecked(false);
2405 myAttractorCheck->setChecked(false);
2406 myGeomSelWdg1->deactivateSelection();
2407 myGeomSelWdg2->deactivateSelection();
2408 myAttSelWdg->deactivateSelection();
2409 myGeomSelWdg1->SetObject(CORBA::Object::_nil());
2410 myGeomSelWdg2->SetObject(CORBA::Object::_nil());
2411 myAttSelWdg->SetObject(CORBA::Object::_nil());
2414 void BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
2416 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElement()");
2417 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2418 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2420 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2422 TopAbs_ShapeEnum shapeType;
2423 string entry, shapeName;
2424 entry = (string) anObject->GetStudyEntry();
2425 MESSAGE("entry = "<<entry);
2426 shapeName = anObject->GetName();
2427 shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
2428 // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
2429 // in order to write the size map with the right syntax in StoreParamsToHypo
2430 // (f(t) for edges, f(u,v) for faces ...)
2431 if (shapeType == TopAbs_COMPOUND){
2432 TopoDS_Shape theShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject );
2433 TopoDS_Shape childShape;
2434 TopoDS_Iterator anIt(theShape);
2435 for(;anIt.More();anIt.Next()){
2436 childShape = anIt.Value();
2437 shapeType = childShape.ShapeType();
2438 if(!childShape.IsNull()){
2443 mySizeMapTable->setFocus();
2445 shapeEntry = QString::fromStdString(entry);
2446 double phySize = mySmpSizeSpin->value();
2447 std::ostringstream oss;
2450 sizeMap = QString::fromStdString(oss.str());
2451 QTreeWidgetItem* item = new QTreeWidgetItem();
2453 int rowToChange = findRowFromEntry(shapeEntry);
2454 item = mySizeMapTable->topLevelItem( rowToChange );
2457 if (that->mySMPMap.contains(shapeEntry)) {
2458 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2459 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2463 mySizeMapTable->addTopLevelItem(item);
2465 that->mySMPMap[shapeEntry] = sizeMap;
2466 that->myDistMap[shapeEntry] = 0. ;
2467 that->mySMPShapeTypeMap[shapeEntry] = shapeType;
2468 item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
2469 item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2470 item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(shapeName)) );
2471 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2472 mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2473 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2474 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2475 mySizeMapTable->clearSelection();
2477 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2478 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2479 myStdWidget->onPhysicalMeshChanged();
2483 void BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
2485 MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertAttractor()");
2486 BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
2487 BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
2489 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2491 TopAbs_ShapeEnum shapeType;
2492 string entry, attEntry, faceName, attName;
2493 entry = (string) aFace->GetStudyEntry();
2494 attEntry = (string) anAttractor->GetStudyEntry();
2495 faceName = aFace->GetName();
2496 attName = anAttractor->GetName();
2497 shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aFace ).ShapeType();
2498 mySizeMapTable->setFocus();
2499 QString shapeEntry = QString::fromStdString(entry);
2500 QString qAttEntry = QString::fromStdString(attEntry);
2502 double phySize = h->GetPhySize();
2503 double infDist = 0. ;
2504 double constDist = 0. ;
2505 phySize = myAttSizeSpin->value();
2506 if (myAttractorCheck->isChecked()){
2507 infDist = myAttDistSpin->value();
2509 if (myConstSizeCheck->isChecked()){
2510 constDist = myAttDistSpin2->value();
2512 std::ostringstream oss;
2513 std::ostringstream oss2;
2514 std::ostringstream oss3;
2518 QString sizeMap = QString::fromStdString(oss.str());
2519 QString infDistString = QString::fromStdString(oss2.str());
2520 QString constDistString = QString::fromStdString(oss3.str());
2522 QTreeWidgetItem* item;
2523 QTreeWidgetItem* child;
2525 int rowToChange = findRowFromEntry(shapeEntry);
2526 item = mySizeMapTable->topLevelItem( rowToChange );
2527 child = item->child( 0 );
2530 if (that->mySMPMap.contains(shapeEntry)) {
2531 if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
2532 // MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
2536 item = new QTreeWidgetItem();
2537 child = new QTreeWidgetItem();
2538 mySizeMapTable->addTopLevelItem(item);
2539 item->addChild(child);
2541 that->mySMPMap.insert(shapeEntry,sizeMap);
2542 that->myATTMap.insert(shapeEntry,qAttEntry);
2543 that->myAttDistMap.insert(shapeEntry,infDist);
2544 that->myDistMap.insert(shapeEntry,constDist);
2545 that->mySMPShapeTypeMap.insert(shapeEntry,shapeType);
2546 item->setExpanded(true);
2547 item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
2548 item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
2549 if (infDist > std::numeric_limits<double>::epsilon()){
2550 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Attractor")) );
2552 else if (constDist > std::numeric_limits<double>::epsilon()){
2553 item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(QString::fromStdString("Constant Size")) );
2555 item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
2557 child->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(qAttEntry) );
2558 child->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(attName)) );
2559 child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(sizeMap) );
2561 mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
2562 mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
2563 mySizeMapTable->resizeColumnToContents( SMP_SIZEMAP_COLUMN );
2565 if ( myStdWidget->myPhysicalMesh->currentIndex() != PhysicalLocalSize ) {
2566 myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
2567 myStdWidget->onPhysicalMeshChanged();
2569 MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
2572 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
2574 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
2575 int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
2576 for ( ; row < nbRows; ++row )
2577 if (! sizeMapValidationFromRow(row))
2582 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
2584 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(), row = "<<myRow);
2585 QString myEntry = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2586 bool res = sizeMapValidationFromEntry(myEntry,displayError);
2587 mySizeMapTable->setFocus();
2591 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
2593 MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
2594 MESSAGE("myEntry = "<<myEntry.toStdString())
2596 BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
2598 if (! that->mySMPMap.contains(myEntry)) {
2599 // MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
2602 if (! that->mySMPShapeTypeMap.contains(myEntry)) {
2603 // MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
2609 if (that->mySMPMap[myEntry].startsWith("def")) {
2610 // MESSAGE("custom function" );
2611 expr = that->mySMPMap[myEntry].toStdString();
2613 else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
2614 // MESSAGE("Attractor" );
2615 if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)(?:;(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+))?\\)$")) != 1)) {
2618 SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False[;d])" );
2624 // case size map is empty
2625 if (that->mySMPMap[myEntry].isEmpty()) {
2627 SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
2631 if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
2632 expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
2633 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
2634 expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
2635 else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
2636 expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
2639 //assert(Py_IsInitialized());
2640 if (! Py_IsInitialized())
2641 throw ("Erreur: Python interpreter is not initialized");
2642 PyGILState_STATE gstate;
2643 gstate = PyGILState_Ensure();
2645 PyObject * obj = NULL;
2646 PyObject* new_stderr = NULL;
2647 string err_description="";
2648 obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
2652 new_stderr=newPyStdOut(err_description);
2653 PySys_SetObject((char*)"stderr", new_stderr);
2655 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2656 Py_DECREF(new_stderr);
2658 SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
2659 PyGILState_Release(gstate);
2664 PyObject * func = NULL;
2665 func = PyObject_GetAttrString(main_mod, "f");
2669 new_stderr=newPyStdOut(err_description);
2670 PySys_SetObject((char*)"stderr", new_stderr);
2672 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
2673 Py_DECREF(new_stderr);
2675 SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
2676 PyGILState_Release(gstate);
2680 PyGILState_Release(gstate);
2682 // MESSAGE("SizeMap expression "<<expr<<" is valid");
2687 QString BLSURFPluginGUI_HypothesisCreator::caption() const
2689 return tr( "BLSURF_TITLE" );
2692 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
2694 return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
2697 QString BLSURFPluginGUI_HypothesisCreator::type() const
2699 return tr( "BLSURF_HYPOTHESIS" );
2702 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
2704 return "blsurf_hypo_page.html";
2707 LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
2710 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2712 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2717 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
2719 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
2720 SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
2721 CORBA::Object_var obj;
2722 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
2723 if (!aSObj->_is_nil()) {
2724 obj = aSObj->GetObject();
2725 aSObj->UnRegister();
2730 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
2731 QString entryForChecking;
2732 int endRow = mySizeMapTable->topLevelItemCount()-1;
2734 entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2735 while (entry != entryForChecking && row <= endRow){
2737 entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
2739 MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)