X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_FilterLibraryDlg.cxx;h=d692e9ef71c97635bba05133ce3e6500b2298f5b;hb=d90a581cefcc55423f12edd390bd91118a4a6b0c;hp=47c9e912cbe88bbf68f6cbd98438b73ae2d7c450;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx index 47c9e912c..d692e9ef7 100644 --- a/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SMESH SMESHGUI : GUI for SMESH component // File : SMESHGUI_FilterLibraryDlg.cxx // Author : Sergey LITONIN, Open CASCADE S.A.S. @@ -29,6 +30,9 @@ #include "SMESHGUI.h" #include "SMESHGUI_FilterUtils.h" #include "SMESHGUI_FilterDlg.h" +#include "SMESHGUI_VTKUtils.h" + +#include // SALOME GUI includes #include @@ -36,8 +40,9 @@ #include #include #include - #include +#include +#include // Qt includes #include @@ -148,7 +153,7 @@ void SMESHGUI_FilterLibraryDlg::construct (const QList& theTypes, aDlgLay->setStretchFactor(myMainFrame, 1); - myHelpFileName = "selection_filter_library_page.html"; + myHelpFileName = "selection_filter_library.html"; Init(myTypes, myMode); } @@ -206,7 +211,7 @@ QWidget* SMESHGUI_FilterLibraryDlg::createMainFrame (QWidget* theParent) myTable->SetLibsEnabled(false); myListBox->setMinimumHeight((int)(myTable->sizeHint().height() * 0.5)); - //myListBox->setRowMode(QListWidget::FitToWidth); //VSR : TODO ??? + //myListBox->setRowMode(QListWidget::FitToWidth); myListBox->setSelectionMode(QListWidget::SingleSelection); myOpenBtn->setAutoDefault(false); @@ -226,19 +231,22 @@ QWidget* SMESHGUI_FilterLibraryDlg::createMainFrame (QWidget* theParent) connect(myOpenBtn, SIGNAL(clicked()), this, SLOT(onBrowse())); connect(myListBox, SIGNAL(itemSelectionChanged()), - this, SLOT(onFilterChanged())); + this, SLOT(onFilterChanged())); connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtnPressed())); connect(myDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeleteBtnPressed())); connect(myName, SIGNAL(textChanged(const QString&)), - this, SLOT(onFilterNameChanged(const QString&))); + this, SLOT(onFilterNameChanged(const QString&))); connect(myTable, SIGNAL(EntityTypeChanged(const int)), - this, SLOT(onEntityTypeChanged(const int))); + this, SLOT(onEntityTypeChanged(const int))); connect(myTable, SIGNAL(NeedValidation()), this, SLOT(onNeedValidation())); + LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( mySMESHGUI ); + connect( selMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone())); + return aMainFrame; } @@ -256,7 +264,6 @@ QWidget* SMESHGUI_FilterLibraryDlg::createButtonFrame (QWidget* theParent) myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp); myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp); - myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp); myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp); myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp); @@ -265,13 +272,11 @@ QWidget* SMESHGUI_FilterLibraryDlg::createButtonFrame (QWidget* theParent) aLay->addWidget(myButtons[ BTN_Apply ]); aLay->addSpacing(10); aLay->addStretch(); - aLay->addWidget(myButtons[ BTN_Cancel ]); aLay->addWidget(myButtons[ BTN_Close ]); aLay->addWidget(myButtons[ BTN_Help ]); connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk())); - connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose())); - connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose())); + connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(reject())); connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply())); connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp())); @@ -290,14 +295,11 @@ QWidget* SMESHGUI_FilterLibraryDlg::createButtonFrame (QWidget* theParent) //======================================================================= void SMESHGUI_FilterLibraryDlg::updateMainButtons() { + myButtons[ BTN_Close ]->show(); if (myTypes.count() == 1) { - myButtons[ BTN_Cancel ]->show(); myButtons[ BTN_Apply ]->hide(); - myButtons[ BTN_Close ]->hide(); } else { - myButtons[ BTN_Cancel ]->hide(); myButtons[ BTN_Apply ]->show(); - myButtons[ BTN_Close ]->show(); } } @@ -342,7 +344,7 @@ void SMESHGUI_FilterLibraryDlg::Init (const QList& theTypes, setEnabled(true); connect( mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate())); - connect( mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose())); + connect( mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject())); if (myMode == ADD_TO) { @@ -423,12 +425,12 @@ bool SMESHGUI_FilterLibraryDlg::onApply() if (myLibrary->_is_nil()) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), - tr("LIBRARY_IS_NOT_LOADED")); + tr("LIBRARY_IS_NOT_LOADED")); return false; } if (myFileName->text() != myLibrary->GetFileName()) - myLibrary->SetFileName( myFileName->text().toLatin1().constData() ); + myLibrary->SetFileName( myFileName->text().toUtf8().constData() ); bool aResult = false; @@ -437,11 +439,11 @@ bool SMESHGUI_FilterLibraryDlg::onApply() } else if (myMode == EDIT || myMode == ADD_TO) { SMESH::Filter_var aFilter = createFilter(); if (!myListBox->selectedItems().empty() && - !myLibrary->Replace(myCurrFilterName.toLatin1().constData(), - myName->text().toLatin1().constData(), - aFilter.in())) { + !myLibrary->Replace(myCurrFilterName.toUtf8().constData(), + myName->text().toUtf8().constData(), + aFilter.in())) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), - tr("ERROR_OF_EDITING")); + tr("ERROR_OF_EDITING")); aResult = false; } else @@ -457,7 +459,7 @@ bool SMESHGUI_FilterLibraryDlg::onApply() delete aFileName; } else if (myMode != COPY_FROM) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), - tr("ERROR_OF_SAVING")); + tr("ERROR_OF_SAVING")); } else { } @@ -471,8 +473,7 @@ bool SMESHGUI_FilterLibraryDlg::onApply() //======================================================================= void SMESHGUI_FilterLibraryDlg::onOk() { - if (onApply()) - { + if (onApply()) { disconnect( mySMESHGUI, 0, this, 0); mySMESHGUI->ResetState(); accept(); @@ -480,14 +481,14 @@ void SMESHGUI_FilterLibraryDlg::onOk() } //======================================================================= -// name : SMESHGUI_FilterLibraryDlg::onClose +// name : SMESHGUI_FilterLibraryDlg::reject // Purpose : SLOT called when "Close" button pressed. Close dialog //======================================================================= -void SMESHGUI_FilterLibraryDlg::onClose() +void SMESHGUI_FilterLibraryDlg::reject() { disconnect( mySMESHGUI, 0, this, 0); mySMESHGUI->ResetState(); - reject(); + QDialog::reject(); } //================================================================================= @@ -507,16 +508,16 @@ void SMESHGUI_FilterLibraryDlg::onHelp() platform = "application"; #endif SUIT_MessageBox::warning(this, tr("WRN_WARNING"), - tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", - platform)). - arg(myHelpFileName)); + tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", + platform)). + arg(myHelpFileName)); } } //======================================================================= // name : SMESHGUI_FilterLibraryDlg::onDeactivate -// Purpose : SLOT called when dialog must be deativated +// Purpose : SLOT called when dialog must be deactivated //======================================================================= void SMESHGUI_FilterLibraryDlg::onDeactivate() { @@ -532,15 +533,6 @@ void SMESHGUI_FilterLibraryDlg::enterEvent(QEvent*) setEnabled(true); } -//================================================================================= -// function : closeEvent() -// purpose : Close dialog -//================================================================================= -void SMESHGUI_FilterLibraryDlg::closeEvent(QCloseEvent* e) -{ - onClose(); -} - //======================================================================= // name : SMESHGUI_FilterLibraryDlg::getFileName // Purpose : Get file name @@ -610,7 +602,7 @@ QStringList SMESHGUI_FilterLibraryDlg::prepareFilters() const //================================================================ // Function : onBrowse -// Purpose : SLOT. Display "Open file" dialog for chosing library name +// Purpose : SLOT. Display "Open file" dialog for choosing library name //================================================================ void SMESHGUI_FilterLibraryDlg::onBrowse() { @@ -619,7 +611,7 @@ void SMESHGUI_FilterLibraryDlg::onBrowse() //aDlg->setMode(myMode == COPY_FROM ? QFileDialogP::ExistingFile : QFileDialogP::AnyFile); aDlg->setFileMode(myMode == COPY_FROM ? QFileDialog::ExistingFile : QFileDialog::AnyFile); - aDlg->setFilters(prepareFilters()); + aDlg->setNameFilters(prepareFilters()); aDlg->selectFile(getFileName()); QPushButton* anOkBtn = (QPushButton*)aDlg->findChild("OK"); @@ -637,8 +629,8 @@ void SMESHGUI_FilterLibraryDlg::onBrowse() if (QFileInfo(fName).suffix().isEmpty()) fName = autoExtension(fName); - fName = QDir::convertSeparators(fName); - QString prev = QDir::convertSeparators(getFileName()); + fName = QDir::toNativeSeparators(fName); + QString prev = QDir::toNativeSeparators(getFileName()); if (prev == fName) return; @@ -670,15 +662,15 @@ void SMESHGUI_FilterLibraryDlg::processNewLibrary() if (aFilterMgr->_is_nil()) return; - myLibrary = aFilterMgr->LoadLibrary(autoExtension(getFileName()).toLatin1().constData()); + myLibrary = aFilterMgr->LoadLibrary(autoExtension(getFileName()).toUtf8().constData()); if (myLibrary->_is_nil()) { if (myMode == COPY_FROM) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), - tr("ERROR_LOAD")); + tr("ERROR_LOAD")); return; } else { myLibrary = aFilterMgr->CreateLibrary(); - myLibrary->SetFileName(getFileName().toLatin1().constData()); + myLibrary->SetFileName(getFileName().toUtf8().constData()); } } @@ -730,7 +722,7 @@ bool SMESHGUI_FilterLibraryDlg::isNameValid(const bool theMess) const if (aCurrName.isEmpty()) { if (theMess) SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), - tr("EMPTY_FILTER_NAME")); + tr("EMPTY_FILTER_NAME")); return false; } @@ -739,7 +731,7 @@ bool SMESHGUI_FilterLibraryDlg::isNameValid(const bool theMess) const if (aNames[ f ] == aCurrName && aNames[ f ] != myCurrFilterName) { if (theMess) SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), - tr("ERROR_FILTER_NAME")); + tr("ERROR_FILTER_NAME")); return false; } } @@ -764,7 +756,7 @@ bool SMESHGUI_FilterLibraryDlg::isPermissionValid(const bool theIsExistingOnly) if (QFileInfo(fName).suffix().isEmpty()) fName = autoExtension(fName); - fName = QDir::convertSeparators(fName); + fName = QDir::toNativeSeparators(fName); if (QFileInfo(fName).exists()) { isWritable = QFileInfo(fName).isWritable(); @@ -787,7 +779,7 @@ bool SMESHGUI_FilterLibraryDlg::isPermissionValid(const bool theIsExistingOnly) if (!isWritable) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), - tr("NO_PERMISSION")); + tr("NO_PERMISSION")); return false; } @@ -830,14 +822,14 @@ void SMESHGUI_FilterLibraryDlg::onFilterChanged() } SMESH::Filter_var aFilter = createFilter(); - myLibrary->Replace(myCurrFilterName.toLatin1().constData(), - myName->text().toLatin1().constData(), - aFilter); + myLibrary->Replace(myCurrFilterName.toUtf8().constData(), + myName->text().toUtf8().constData(), + aFilter); } // Fill table with filter parameters - SMESH::Filter_var aFilter = myLibrary->Copy(theName.toLatin1().constData()); + SMESH::Filter_var aFilter = myLibrary->Copy(theName.toUtf8().constData()); myCurrFilterName = theName; myCurrFilter = myListBox->currentRow(); myName->setText(theName); @@ -900,7 +892,7 @@ void SMESHGUI_FilterLibraryDlg::enableMainButtons() //======================================================================= // name : SMESHGUI_FilterLibraryDlg::createFilter -// Purpose : Cerate filter in accordance with library +// Purpose : Create filter in accordance with library //======================================================================= SMESH::Filter_ptr SMESHGUI_FilterLibraryDlg::createFilter(const int theType) { @@ -937,9 +929,9 @@ void SMESHGUI_FilterLibraryDlg::onAddBtnPressed() return; SMESH::Filter_var aFilter = createFilter(); - myLibrary->Replace(myCurrFilterName.toLatin1().constData(), - myName->text().toLatin1().constData(), - aFilter); + myLibrary->Replace(myCurrFilterName.toUtf8().constData(), + myName->text().toUtf8().constData(), + aFilter); } myTable->Clear(myTable->GetType()); @@ -955,7 +947,7 @@ void SMESHGUI_FilterLibraryDlg::addFilterToLib (const QString& theName) { if (myLibrary->_is_nil()) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), - tr("LIBRARY_IS_NOT_LOADED")); + tr("LIBRARY_IS_NOT_LOADED")); return; } @@ -974,12 +966,12 @@ void SMESHGUI_FilterLibraryDlg::addFilterToLib (const QString& theName) // add new filter in library bool aResult = !aFilter->GetPredicate()->_is_nil() - ? myLibrary->Add(aName.toLatin1().constData(), aFilter) - : myLibrary->AddEmpty(aName.toLatin1().constData(), (SMESH::ElementType)myTable->GetType()); + ? myLibrary->Add(aName.toUtf8().constData(), aFilter) + : myLibrary->AddEmpty(aName.toUtf8().constData(), (SMESH::ElementType)myTable->GetType()); if (!aResult) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), - tr("ERROR_OF_ADDING")); + tr("ERROR_OF_ADDING")); } updateList(); @@ -989,7 +981,7 @@ void SMESHGUI_FilterLibraryDlg::addFilterToLib (const QString& theName) if (theName != aName) SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"), - tr("ASSIGN_NEW_NAME").arg(theName).arg(aName)); + tr("ASSIGN_NEW_NAME").arg(theName).arg(aName)); } //======================================================================= @@ -1089,15 +1081,15 @@ void SMESHGUI_FilterLibraryDlg::onDeleteBtnPressed() { if (myLibrary->_is_nil()) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), - tr("LIBRARY_IS_NOT_LOADED")); + tr("LIBRARY_IS_NOT_LOADED")); return; } int anIndex = getIndex(myCurrFilterName); - if (anIndex == -1 || !myLibrary->Delete(myCurrFilterName.toLatin1().constData())) { + if (anIndex == -1 || !myLibrary->Delete(myCurrFilterName.toUtf8().constData())) { SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), - tr("ERROR_OF_DELETING")); + tr("ERROR_OF_DELETING")); } else { myCurrFilterName = ""; myCurrFilter = -1; @@ -1160,7 +1152,7 @@ const SMESHGUI_FilterTable* SMESHGUI_FilterLibraryDlg::GetTable() const // name : SMESHGUI_FilterLibraryDlg::onEntityTypeChanged // Purpose : SLOT. Called when entiyt type changed //======================================================================= -void SMESHGUI_FilterLibraryDlg::onEntityTypeChanged(const int theType) +void SMESHGUI_FilterLibraryDlg::onEntityTypeChanged(const int /*theType*/) { if (myLibrary->_is_nil()) return; @@ -1187,9 +1179,81 @@ void SMESHGUI_FilterLibraryDlg::onNeedValidation() if (valid) { SMESH::Filter_var aFilter = createFilter(myTable->GetType()); - myLibrary->Replace(myCurrFilterName.toLatin1().constData(), - myName->text().toLatin1().constData(), - aFilter); + myLibrary->Replace(myCurrFilterName.toUtf8().constData(), + myName->text().toUtf8().constData(), + aFilter); + } + } +} + + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onSelectionDone +// Purpose : SLOT called when selection changed. +// If current cell corresponds to the threshold value of +// BelongToGeom criterion name of selected object is set in this cell +//======================================================================= + +void SMESHGUI_FilterLibraryDlg::onSelectionDone() +{ + SALOME_ListIO aList; + if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() ) + aSel->selectedObjects( aList ); + + int aRow, aCol; + if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol)) + return; + + const int type = myTable->GetCriterionType(aRow); + QList types; + types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane + << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface + << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces + << SMESH::FT_ConnectedElements << SMESH::FT_BelongToMeshGroup; + if ( !types.contains( type )) + return; + + Handle(SALOME_InteractiveObject) anIO = aList.First(); + switch ( type ) + { + case SMESH::FT_CoplanarFaces: // get ID of a selected mesh face + { + QString aString; + int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString); + if (nbElems == 1) + myTable->SetThreshold(aRow, aString); + break; + } + case SMESH::FT_ConnectedElements: // get either VERTEX or a node ID + { + GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface(anIO); + if (!anObj->_is_nil()) + { + myTable->SetThreshold(aRow, GEOMBase::GetName(anObj)); + myTable->SetID (aRow, anIO->getEntry()); + } + else + { + QString aString; + int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString); + if (nbElems == 1) + myTable->SetThreshold(aRow, aString); + } + break; + } + case SMESH::FT_BelongToMeshGroup: // get a group name and IOR + { + myTable->SetThreshold(aRow, anIO->getName() ); + break; + } + default: // get a GEOM object + { + GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface(anIO); + if (!anObj->_is_nil()) + { + myTable->SetThreshold(aRow, GEOMBase::GetName(anObj)); + myTable->SetID (aRow, anIO->getEntry()); + } } } }