X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_GroupDlg.cxx;h=c7d806b7da09362543e0ff236a00ef96c5072eb5;hp=352215c957923d3e79eb4e02e221b14b9abd0033;hb=refs%2Ftags%2FV8_3_0a2;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070 diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 352215c95..c7d806b7d 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -1,28 +1,29 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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_GroupDlg.cxx -// Author : Natalia KOPNOVA, Open CASCADE S.A.S. -// SMESH includes + +// SMESH SMESHGUI : GUI for SMESH component +// File : SMESHGUI_GroupDlg.cxx +// Author : Natalia KOPNOVA, Open CASCADE S.A.S. +// SMESH includes // #include "SMESHGUI_GroupDlg.h" @@ -37,11 +38,13 @@ #include #include -#include +//#include +#include // SALOME GEOM includes #include #include +#include // SALOME GUI includes #include @@ -50,6 +53,7 @@ #include #include #include +#include #include #include @@ -57,10 +61,11 @@ #include #include -#include #include +#include + // SALOME KERNEL includes #include @@ -96,19 +101,35 @@ #define SPACING 6 #define MARGIN 11 +enum grpSelectionMode { + grpNoSelection = -1, + grpNodeSelection = 0, + grp0DSelection = 1, + grpBallSelection = 2, + grpEdgeSelection = 3, + grpFaceSelection = 4, + grpVolumeSelection = 5, + grpSubMeshSelection = 6, + grpGroupSelection = 7, + grpMeshSelection = 8, + grpGeomSelection = 9, + grpAllSelection = 10, +}; + //================================================================================= // function : SMESHGUI_GroupDlg() // purpose : //================================================================================= SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, - SMESH::SMESH_Mesh_ptr theMesh ) + SMESH::SMESH_Mesh_ptr theMesh ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), - mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0), mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ), myIsBusy( false ), myNameChanged( false ), - myActor( 0 ) + myNbChangesOfContents(0), + myIsApplyAndClose( false ) { initDialog( true ); if ( !theMesh->_is_nil() ) @@ -127,14 +148,15 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, // purpose : //================================================================================= SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, - SMESH::SMESH_GroupBase_ptr theGroup, + SMESH::SMESH_GroupBase_ptr theGroup, const bool theIsConvert ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), - mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0), mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ), myIsBusy( false ), - myNameChanged( false ) + myNameChanged( false ), + myNbChangesOfContents(0) // just not to use uninitialized variable { initDialog( false ); if ( !theGroup->_is_nil() ) @@ -145,7 +167,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, mySelectGroup->setEnabled( false ); myCurrentLineEdit = myMeshGroupLine; - setSelectionMode( 5 ); + setSelectionMode( grpGroupSelection ); } } @@ -194,6 +216,8 @@ void SMESHGUI_GroupDlg::initDialog( bool create) QStringList types; types.append( tr( "MESH_NODE" ) ); + types.append( tr( "SMESH_ELEM0D" ) ); + types.append( tr( "SMESH_BALL_ELEM" ) ); types.append( tr( "SMESH_EDGE" ) ); types.append( tr( "SMESH_FACE" ) ); types.append( tr( "SMESH_VOLUME" ) ); @@ -221,10 +245,13 @@ void SMESHGUI_GroupDlg::initDialog( bool create) QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox ); QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox ); + QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox ); myGrpTypeGroup->addButton( rb1, 0 ); myGrpTypeGroup->addButton( rb2, 1 ); + myGrpTypeGroup->addButton( rb3, 2 ); aGrpTypeBoxLayout->addWidget( rb1 ); aGrpTypeBoxLayout->addWidget( rb2 ); + aGrpTypeBoxLayout->addWidget( rb3 ); aGrpTypeBox->setEnabled( create ); myGrpTypeId = -1; @@ -232,66 +259,72 @@ void SMESHGUI_GroupDlg::initDialog( bool create) myWGStack = new QStackedWidget( this ); QWidget* wg1 = new QWidget( myWGStack ); QWidget* wg2 = new QWidget( myWGStack ); + QWidget* wg3 = new QWidget( myWGStack ); /***************************************************************/ - QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 ); + QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 ); QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox ); aContentBoxLayout->setMargin( MARGIN ); aContentBoxLayout->setSpacing( SPACING ); - QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox ); - myElements = new QListWidget( aContentBox ); + mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox ); + myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox ); + + myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox ); + myElements = new QListWidget( aContentBox ); myElements->setSelectionMode( QListWidget::ExtendedSelection ); - myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox ); - QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox ); - QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox ); - QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox ); + myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox ); + myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox ); + myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox ); + mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox ); - aContentBoxLayout->addWidget( aLabel, 0, 0 ); - aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 ); - aContentBoxLayout->addWidget( myFilter, 1, 1 ); - aContentBoxLayout->addWidget( aAddBtn, 3, 1 ); - aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 ); - aContentBoxLayout->addWidget( aSortBtn, 6, 1 ); + aContentBoxLayout->addWidget( mySelectAll, 0, 0 ); + aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 ); + aContentBoxLayout->addWidget( myFilterBtn, 1, 1 ); + aContentBoxLayout->addWidget( myElementsLab, 2, 0 ); + aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 ); + aContentBoxLayout->addWidget( myAddBtn, 3, 1 ); + aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 ); + aContentBoxLayout->addWidget( mySortBtn, 8, 1 ); aContentBoxLayout->setColumnStretch( 0, 1 ); - aContentBoxLayout->setRowStretch( 2, 1 ); - aContentBoxLayout->setRowStretch( 5, 1 ); + aContentBoxLayout->setRowStretch( 3, 1 ); + aContentBoxLayout->setRowStretch( 6, 1 ); /***************************************************************/ - QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 ); - QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox ); - aSelectBoxLayout->setMargin( MARGIN ); - aSelectBoxLayout->setSpacing( SPACING ); + mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 ); + QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox ); + mySelectBoxLayout->setMargin( MARGIN ); + mySelectBoxLayout->setSpacing( SPACING ); - mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox ); - mySubMeshBtn = new QPushButton( aSelectBox ); + mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox ); + mySubMeshBtn = new QPushButton( mySelectBox ); mySubMeshBtn->setIcon( image0 ); - mySubMeshLine = new QLineEdit( aSelectBox ); + mySubMeshLine = new QLineEdit( mySelectBox ); mySubMeshLine->setReadOnly( true ); onSelectSubMesh( false ); - mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox ); - myGroupBtn = new QPushButton( aSelectBox ); + mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox ); + myGroupBtn = new QPushButton( mySelectBox ); myGroupBtn->setIcon( image0 ); - myGroupLine = new QLineEdit( aSelectBox ); + myGroupLine = new QLineEdit( mySelectBox ); myGroupLine->setReadOnly( true ); onSelectGroup( false ); - aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 ); - aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 ); - aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 ); - aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 ); - aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 ); - aSelectBoxLayout->addWidget( myGroupLine, 1, 2 ); + mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 ); + mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 ); + mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 ); + mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 ); + mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 ); + mySelectBoxLayout->addWidget( myGroupLine, 1, 2 ); /***************************************************************/ QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 ); wg1Layout->setMargin( 0 ); wg1Layout->setSpacing( SPACING ); wg1Layout->addWidget( aContentBox ); - wg1Layout->addWidget( aSelectBox ); + wg1Layout->addWidget( mySelectBox ); wg1Layout->setStretchFactor( aContentBox, 10 ); /***************************************************************/ @@ -309,15 +342,24 @@ void SMESHGUI_GroupDlg::initDialog( bool create) /***************************************************************/ QGridLayout* wg2Layout = new QGridLayout( wg2 ); wg2Layout->setMargin( 0 ); - wg1Layout->setSpacing( SPACING ); + wg2Layout->setSpacing( SPACING ); wg2Layout->addWidget( geomObject, 0, 0 ); wg2Layout->addWidget( myGeomGroupBtn, 0, 1 ); wg2Layout->addWidget( myGeomGroupLine,0, 2 ); wg2Layout->setRowStretch( 1, 5 ); + /***************************************************************/ + QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 ); + QGridLayout* wg3Layout = new QGridLayout( wg3 ); + wg3Layout->setMargin( 0 ); + wg3Layout->setSpacing( SPACING ); + wg3Layout->addWidget( aFilter2, 0, 0 ); + wg3Layout->setRowStretch( 1, 5 ); + /***************************************************************/ myWGStack->insertWidget( 0, wg1 ); myWGStack->insertWidget( 1, wg2 ); + myWGStack->insertWidget( 2, wg3 ); /***************************************************************/ QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this); @@ -328,7 +370,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create) QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox ); myColorBtn = new QtxColorButton(aColorBox); myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, - myColorBtn->sizePolicy().verticalPolicy() ); + myColorBtn->sizePolicy().verticalPolicy() ); aColorBoxLayout->addWidget(aColorLab); aColorBoxLayout->addWidget(myColorBtn); @@ -372,54 +414,62 @@ void SMESHGUI_GroupDlg::initDialog( bool create) aMainLayout->addWidget(aButtons, 6, 0, 1, 3); /* signals and slots connections */ - connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); - connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int))); - connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int))); + connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); + connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int))); + connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int))); - connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&))); - connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); + connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&))); + connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); - connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters())); - connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd())); - connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove())); - connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort())); + connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters())); + connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters())); + connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll())); + connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll())); + connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd())); + connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove())); + connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort())); connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool))); connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool))); - connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); - connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); + connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); + connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool))); - connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor ))); + connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor ))); - connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK())); - connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply())); - connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose())); - connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp())); + connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK())); + connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply())); + connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject())); + connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp())); /* Init selection */ mySMESHGUI->SetActiveDialogBox(this); - mySMESHGUI->SetState(800); - mySelectionMode = -1; - myMeshFilter = new SMESH_TypeFilter(MESH); - mySubMeshFilter = new SMESH_TypeFilter(SUBMESH); - myGroupFilter = new SMESH_TypeFilter(GROUP); SalomeApp_Study* aStudy = dynamic_cast( mySMESHGUI->application()->activeStudy() ); - myGeomFilter = new GEOM_SelectionFilter( aStudy, true ); + mySelectionMode = grpNoSelection; + + myMeshFilter = new SMESH_TypeFilter(SMESH::MESH); + mySubMeshFilter = new SMESH_LogicalFilter(QList(), + SMESH_LogicalFilter::LO_OR, + /*takeOwnership=*/true); + myGroupFilter = new SMESH_LogicalFilter(QList(), + SMESH_LogicalFilter::LO_OR, + /*takeOwnership=*/true); + myGeomFilter = new GEOM_SelectionFilter( aStudy, true ); connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate())); - connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose())); + connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject())); connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged())); - + connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged())); + connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView())); + connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView())); rb1->setChecked(true); // VSR !!! onGrpTypeChanged(0); // VSR!!! if (myMesh->_is_nil() ) myTypeGroup->button(0)->setChecked(true); - updateButtons(); - //myName->setText(GetDefaultName(tr( "SMESH_GROUP" ))); + onSelectAll(); //updateButtons(); } //================================================================================= @@ -433,6 +483,10 @@ SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg() myFilterDlg->setParent( 0 ); delete myFilterDlg; } + if ( myMeshFilter ) delete myMeshFilter; + if ( mySubMeshFilter ) delete mySubMeshFilter; + if ( myGroupFilter ) delete myGroupFilter; + if ( myGeomFilter ) delete myGeomFilter; } //================================================================================= @@ -465,12 +519,28 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation) bool isUnique = false; while (!isUnique) { aName = theOperation + "_" + QString::number(++aNumber); - isUnique = (aSet.count(aName.toLatin1().data()) == 0); + isUnique = (aSet.count(std::string(SMESH::toUtf8(aName))) == 0); } return aName; } +void SMESHGUI_GroupDlg::setDefaultName() const +{ + QString aResName; + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + int i=1; + QString aPrefix ="Group_"; + _PTR(SObject) anObj; + do + { + aResName = aPrefix + QString::number( i++ ); + anObj = aStudy->FindObject( SMESH::toUtf8(aResName) ); + } + while ( anObj ); + myName->setText(aResName); +} + //================================================================================= // function : Init() // purpose : @@ -485,6 +555,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) setShowEntityMode(); myGroup = SMESH::SMESH_Group::_nil(); myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil(); // NPAL19389: create a group with a selection in another group // set actor of myMesh, if it is visible, else try @@ -492,13 +563,15 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) SetAppropriateActor(); setDefaultGroupColor(); + setDefaultName(); + SALOME_ListIO aList; mySelectionMgr->selectedObjects( aList ); if( !aList.IsEmpty() ) { QString aName = aList.First()->getName(); - myMeshGroupLine->setText(aName); + myMeshGroupLine->setText(aName);//?????? myMeshGroupLine->home( false ); } @@ -513,7 +586,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) // purpose : //================================================================================= void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, - const bool theIsConvert) + const bool theIsConvert) { restoreShowEntityMode(); myMesh = theGroup->GetMesh(); @@ -521,28 +594,34 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, myNameChanged = true; myName->blockSignals(true); - myName->setText(theGroup->GetName()); + myName->setText(SMESH::fromUtf8(theGroup->GetName())); myName->blockSignals(false); myName->home(false); SALOMEDS::Color aColor = theGroup->GetColor(); setGroupColor( aColor ); - myMeshGroupLine->setText(theGroup->GetName()); + myMeshGroupLine->setText(SMESH::fromUtf8(theGroup->GetName())); int aType = 0; switch(theGroup->GetType()) { - case SMESH::NODE: aType= 0; break; - case SMESH::EDGE: aType = 1; break; - case SMESH::FACE: aType = 2; break; - case SMESH::VOLUME: aType = 3; break; + case SMESH::NODE: aType = grpNodeSelection; break; + case SMESH::ELEM0D: aType = grp0DSelection; break; + case SMESH::BALL: aType = grpBallSelection; break; + case SMESH::EDGE: aType = grpEdgeSelection; break; + case SMESH::FACE: aType = grpFaceSelection; break; + case SMESH::VOLUME: aType = grpVolumeSelection; break; + case SMESH::ALL: + case SMESH::NB_ELEMENT_TYPES: break; } myTypeGroup->button(aType)->setChecked(true); - myGroup = SMESH::SMESH_Group::_narrow( theGroup ); - myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup ); + myGroup = SMESH::SMESH_Group::_narrow( theGroup ); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup ); + myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup ); + myFilter = SMESH::Filter::_nil(); - if (myGroup->_is_nil() && myGroupOnGeom->_is_nil()) + if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() ) return; // NPAL19389: create a group with a selection in another group @@ -550,21 +629,24 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, // actor of theGroup, if it is visible, else try // any visible actor of group or submesh of myMesh // commented, because an attempt to set selection on not displayed cells leads to error - //SetAppropriateActor(); - myActor = SMESH::FindActorByObject(myMesh); - if ( !myActor ) - myActor = SMESH::FindActorByObject(theGroup); - SMESH::SetPickable(myActor); + SetAppropriateActor(); + + /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh); + if ( !anActor ) + anActor = SMESH::FindActorByObject(theGroup); + SMESH::SetPickable(anActor);*/ - int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1)); + int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1)); myGrpTypeGroup->button(grpType)->setChecked(true); onGrpTypeChanged(grpType); - if ( grpType == 0 ) { + myTypeId = aType; + if ( grpType == 0 ) { // standalone group myCurrentLineEdit = 0; myElements->clear(); + myAllowElemsModif->setChecked( true ); + setSelectionMode(aType); - myTypeId = aType; setShowEntityMode(); // depends on myTypeId @@ -579,7 +661,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, myElements->selectAll(); } } - else + else if ( grpType == 1 ) // group on geom { QString aShapeName( "" ); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); @@ -587,15 +669,30 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, if (!aGroupShape->_is_nil()) { _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry()); - aShapeName = aGroupShapeSO->GetName().c_str(); + if ( aGroupShapeSO ) + aShapeName = aGroupShapeSO->GetName().c_str(); } myGeomGroupLine->setText( aShapeName ); + } + else // group on filter + { + myFilter = myGroupOnFilter->GetFilter(); + if ( !myFilter->_is_nil() ) { + SMESH::Predicate_var perdicate = myFilter->GetPredicate(); + if ( perdicate->_is_nil() ) + myFilter = SMESH::Filter::_nil(); + } + } + + if ( grpType != 0 ) + { myNameChanged = true; myName->blockSignals(true); - myName->setText( "Group On " + aShapeName); + myName->setText(SMESH::fromUtf8(theGroup->GetName())); myName->blockSignals(false); } - updateButtons(); + + onSelectAll(); //updateButtons(); } //================================================================================= @@ -605,15 +702,45 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup, void SMESHGUI_GroupDlg::updateButtons() { bool enable = !myName->text().trimmed().isEmpty(); + if ( enable ) + { + if (myGrpTypeId == 0) { // standalone + if ( !mySelectAll->isChecked() ) + { + if ( myAllowElemsModif->isChecked() ) + { + enable = ( myElements->count() > 0 ); + } + else if ((enable = !myFilter->_is_nil() )) + { + SMESH::array_of_ElementType_var types = myFilter->GetTypes(); + enable = types->length(); + } + } + enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil()); + } + else if (myGrpTypeId == 1) // on geom + { + if (CORBA::is_nil(myGroupOnGeom)) // creation mode + enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() ); + } + else if (myGrpTypeId == 2) // on filter + { + if (( enable = !myFilter->_is_nil() )) + if (CORBA::is_nil(myGroupOnFilter) ) // creation mode + enable = !myMesh->_is_nil(); + } + } - if (myGrpTypeId == 0) { - enable = enable && myElements->count() > 0; - enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil()); + bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() ); + if ( myGrpTypeId != 1 ) + { + myGrpTypeGroup->button(1)->setEnabled( meshHasGeom ); } - else if (myGrpTypeId == 1) { - if (CORBA::is_nil(myGroupOnGeom)) { // creation mode - enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil(); - } + else + { + myGeomGroupBtn->setEnabled( meshHasGeom ); + myGeomGroupLine->setEnabled( meshHasGeom ); } myOKBtn->setEnabled(enable); @@ -639,9 +766,13 @@ void SMESHGUI_GroupDlg::onTypeChanged (int id) { if (myTypeId != id) { myElements->clear(); - if (myCurrentLineEdit == 0) - setSelectionMode(id); myTypeId = id; + if ( myGrpTypeId == 0 && myCurrentLineEdit == 0) + setSelectionMode(id); + else + setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode + + onObjectSelectionChanged(); setShowEntityMode(); } } @@ -653,13 +784,14 @@ void SMESHGUI_GroupDlg::onTypeChanged (int id) void SMESHGUI_GroupDlg::onGrpTypeChanged (int id) { if (myGrpTypeId != id) { + myGrpTypeId = id; myWGStack->setCurrentIndex( id ); myName->blockSignals(true); myName->setText(myOldName); myName->blockSignals(false); - onSelectGeomGroup(id == 1); + onSelectGeomGroup(id != 0); } - myGrpTypeId = id; + updateButtons(); } //================================================================================= @@ -680,48 +812,99 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode) // PAL7314 if (myMesh->_is_nil()) return; + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ); + bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0; if (mySelectionMode != theMode) { // [PAL10408] mySelectionMgr->clearSelected(); mySelectionMgr->clearFilters(); - if (myActor) - myActor->SetPointRepresentation(false); + SMESH::RemoveFilters(); + + if (myActorsList.count() > 0) + for (QListIterator it( myActorsList ); it.hasNext(); ) + it.next()->SetPointRepresentation(false); else SMESH::SetPointRepresentation(false); - if (theMode < 4) { - switch (theMode) { - case 0: - if (myActor) - myActor->SetPointRepresentation(true); - else - SMESH::SetPointRepresentation(true); - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(NodeSelection); - break; - case 1: - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(EdgeSelection); - break; - case 2: - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(FaceSelection); - break; - default: - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(VolumeSelection); + + switch (theMode) { + case grpNodeSelection: + if ( myGrpTypeId == 0 ) // standalone + { + if (myActorsList.count() > 0) + for (QListIterator it( myActorsList ); it.hasNext(); ) + it.next()->SetPointRepresentation(true); + else + SMESH::SetPointRepresentation(true); + } + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection); + break; + case grpEdgeSelection: + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection); + break; + case grpBallSelection: + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection); + break; + case grp0DSelection: + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection); + break; + case grpFaceSelection: + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection); + break; + case grpVolumeSelection: + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection); + break; + case grpSubMeshSelection: { + + SMESH_TypeFilter* f = 0; + switch (myTypeId) { + case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break; + case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break; + case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break; + case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break; + default: f = new SMESH_TypeFilter(SMESH::SUBMESH); + } + QList filtList; + filtList.append( f ); + filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND)); + mySubMeshFilter->setFilters( filtList ); + + mySelectionMgr->installFilter( mySubMeshFilter ); + + if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection); + break; + } + case grpGroupSelection: { + + SMESH_TypeFilter* f = 0; + switch (myTypeId) { + case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break; + case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break; + case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break; + case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break; + case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break; + case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break; + default: f = new SMESH_TypeFilter(SMESH::GROUP); } - } else { - if (theMode == 4) - mySelectionMgr->installFilter(mySubMeshFilter); - else if (theMode == 5) - mySelectionMgr->installFilter(myGroupFilter); - else if (theMode == 6) - mySelectionMgr->installFilter(myMeshFilter); - else if (theMode == 7) - mySelectionMgr->installFilter(myGeomFilter); - - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(ActorSelection); + QList filtList; + filtList.append( f ); + myGroupFilter->setFilters( filtList ); + + mySelectionMgr->installFilter(myGroupFilter); + if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection); + break; } + case grpMeshSelection: + mySelectionMgr->installFilter(myMeshFilter); + if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection); + break; + case grpGeomSelection: + mySelectionMgr->installFilter(myGeomFilter); + if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection); + break; + default: + if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection); + break; + } + if ( aViewWindow ) aViewWindow->Repaint(); mySelectionMode = theMode; } } @@ -738,20 +921,44 @@ bool SMESHGUI_GroupDlg::onApply() if (myName->text().trimmed().isEmpty()) return false; - if (myGrpTypeId == 0) { // on mesh elements - if (!myElements->count()) + SMESH::ElementType aType = SMESH::ALL; + switch (myTypeId) { + case grpNodeSelection: aType = SMESH::NODE; break; + case grp0DSelection: aType = SMESH::ELEM0D; break; + case grpBallSelection: aType = SMESH::BALL; break; + case grpEdgeSelection: aType = SMESH::EDGE; break; + case grpFaceSelection: aType = SMESH::FACE; break; + case grpVolumeSelection: aType = SMESH::VOLUME; break; + } + + bool anIsOk = false; + QStringList anEntryList; + + SMESH::SMESH_GroupBase_var resultGroup; + bool isCreation = false, isConversion = false; + + SUIT_OverrideCursor wc; + + if (myGrpTypeId == 0) // standalone + { + if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked()) return false; mySelectionMgr->clearSelected(); if (myGroup->_is_nil()) { // creation or conversion // check if group on geometry is not null - if (!CORBA::is_nil(myGroupOnGeom)) { + if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) { if (myMesh->_is_nil()) return false; - myGroup = myMesh->ConvertToStandalone( myGroupOnGeom ); - // nullify pointer, because object become dead - myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + if ( myGroupOnGeom->_is_nil() ) + myGroup = myMesh->ConvertToStandalone( myGroupOnFilter ); + else + myGroup = myMesh->ConvertToStandalone( myGroupOnGeom ); + + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil(); + isConversion = true; } } @@ -759,107 +966,96 @@ bool SMESHGUI_GroupDlg::onApply() if (myMesh->_is_nil()) return false; - SMESH::ElementType aType = SMESH::ALL; - switch (myTypeId) { - case 0: aType = SMESH::NODE; break; - case 1: aType = SMESH::EDGE; break; - case 2: aType = SMESH::FACE; break; - case 3: aType = SMESH::VOLUME; break; - } - - SMESH::long_array_var anIdList = new SMESH::long_array; - int i, k = myElements->count(); - anIdList->length(k); - for (i = 0; i < k; i++) { - anIdList[i] = myElements->item(i)->text().toInt(); - } - myGroup = SMESH::AddGroup(myMesh, aType, myName->text()); - myGroup->Add(anIdList.inout()); - SALOMEDS::Color aColor = getGroupColor(); - myGroup->SetColor(aColor); + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup ); + isCreation = true; - _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup); + if ( mySelectAll->isChecked() ) { + // select all + myGroup->AddFrom(myMesh.in()); + } + else { + // select manually - //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) ); - SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" ); + if ( !myFilter->_is_nil() && + ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked())) + { + myGroup->AddFrom( myFilter ); + } + else + { + SMESH::long_array_var anIdList = new SMESH::long_array; + int i, k = myElements->count(); + anIdList->length(k); + for (i = 0; i < k; i++) { + anIdList[i] = myElements->item(i)->text().toInt(); + } + myGroup->Add(anIdList.inout()); + } + } - /* init for next operation */ - myName->setText( "" ); - myElements->clear(); - myGroup = SMESH::SMESH_Group::_nil(); } else { // edition - myGroup->SetName(myName->text().toLatin1().data()); - SALOMEDS::Color aColor = getGroupColor(); - myGroup->SetColor(aColor); + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup ); + isCreation = false; - _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup); - if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) - anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); - - QList aAddList; - - int i, total = myElements->count(); - for (i = 0; i < total; i++) { - int anId = myElements->item(i)->text().toInt(); - int idx = myIdList.indexOf(anId); - if ( idx == -1 ) - aAddList.append(anId); - else - myIdList.removeAt(idx); - } - if (!aAddList.empty()) { - SMESH::long_array_var anIdList = new SMESH::long_array; - int added = aAddList.count(); - anIdList->length(added); - for (i = 0; i < added; i++) - anIdList[i] = aAddList[i]; - myGroup->Add(anIdList.inout()); + if ( mySelectAll->isChecked() ) { + // select all + myGroup->Clear(); + myGroup->AddFrom(myMesh.in()); } - if (!myIdList.empty()) { - SMESH::long_array_var anIdList = new SMESH::long_array; - int removed = myIdList.count(); - anIdList->length(removed); - for (i = 0; i < removed; i++) - anIdList[i] = myIdList[i]; - myGroup->Remove(anIdList.inout()); - } - /* init for next operation */ - myIdList.clear(); - for (i = 0; i < total; i++) { - myIdList.append(myElements->item(i)->text().toInt()); + else { + QList aAddList; + + int i, total = myElements->count(); + for (i = 0; i < total; i++) { + int anId = myElements->item(i)->text().toInt(); + int idx = myIdList.indexOf(anId); + if ( idx == -1 ) + aAddList.append(anId); + else + myIdList.removeAt(idx); + } + if (!aAddList.empty()) { + SMESH::long_array_var anIdList = new SMESH::long_array; + int added = aAddList.count(); + anIdList->length(added); + for (i = 0; i < added; i++) + anIdList[i] = aAddList[i]; + myGroup->Add(anIdList.inout()); + } + if (!myIdList.empty()) { + SMESH::long_array_var anIdList = new SMESH::long_array; + int removed = myIdList.count(); + anIdList->length(removed); + for (i = 0; i < removed; i++) + anIdList[i] = myIdList[i]; + myGroup->Remove(anIdList.inout()); + } + /* init for next operation */ + myIdList.clear(); + for (i = 0; i < total; i++) { + myIdList.append(myElements->item(i)->text().toInt()); + } } } - mySMESHGUI->updateObjBrowser(true); - SMESH::UpdateView(); // asv: fix of BUG PAL5515 - mySelectionMgr->clearSelected(); - return true; + anIsOk = true; } - else if (myGrpTypeId == 1) { // on geom object + else if (myGrpTypeId == 1) // on geom object + { if (CORBA::is_nil(myGroupOnGeom)) { // creation if (myMesh->_is_nil() || !myGeomObjects->length()) return false; - SMESH::ElementType aType = SMESH::ALL; - switch (myTypeId) { - case 0: aType = SMESH::NODE; break; - case 1: aType = SMESH::EDGE; break; - case 2: aType = SMESH::FACE; break; - case 3: aType = SMESH::VOLUME; break; - } - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var aGroupOp = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); if (myGeomObjects->length() == 1) { - myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, - myName->text().toLatin1().data(), - myGeomObjects[0]); + myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, + SMESH::toUtf8(myName->text()), + myGeomObjects[0]); } else { SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen(); @@ -873,15 +1069,14 @@ bool SMESHGUI_GroupDlg::onApply() if (geomGen->_is_nil() || !aStudy) return false; - GEOM::GEOM_IGroupOperations_var op = - geomGen->GetIGroupOperations(aStudy->StudyId()); + GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId()); if (op->_is_nil()) return false; // check and add all selected GEOM objects: they must be // a sub-shapes of the main GEOM and must be of one type TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; - for ( int i =0; i < myGeomObjects->length(); i++) { + for ( int i =0; i < (int)myGeomObjects->length(); i++) { TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType(); if (i == 0) aGroupType = aSubShapeType; @@ -891,8 +1086,8 @@ bool SMESHGUI_GroupDlg::onApply() } } - GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); - GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType); + GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); + GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType); op->UnionList(aGroupVar, myGeomObjects); if (op->IsDone()) { @@ -901,43 +1096,125 @@ bool SMESHGUI_GroupDlg::onApply() aNewGeomGroupName += myName->text(); SALOMEDS::SObject_var aNewGroupSO = geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, - aNewGeomGroupName.toLatin1().data(), aMeshShape); + SMESH::toUtf8(aNewGeomGroupName), aMeshShape); } myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, - myName->text().toLatin1().data(), - aGroupVar); + SMESH::toUtf8(myName->text()), + aGroupVar); } + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom ); + isCreation = true; + + } + else { // edition - SALOMEDS::Color aColor = getGroupColor(); - myGroupOnGeom->SetColor(aColor); + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom ); + isCreation = false; + } + anIsOk = true; + } + if (myGrpTypeId == 2) // group on filter + { + if ( myFilter->_is_nil() ) return false; - _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom); + if (CORBA::is_nil(myGroupOnFilter)) { // creation + if (myMesh->_is_nil()) + return false; - //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) ); - SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" ); + myGroupOnFilter = myMesh->CreateGroupFromFilter(aType, + SMESH::toUtf8(myName->text()), + myFilter); - /* init for next operation */ - myName->setText( "" ); - myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter ); + isCreation = true; } - else { // edition - myGroupOnGeom->SetName(myName->text().toLatin1().data()); - - SALOMEDS::Color aColor = getGroupColor(); - myGroupOnGeom->SetColor(aColor); + else + { + myGroupOnFilter->SetFilter( myFilter ); - _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom); - if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) - anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); + resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter ); + isCreation = false; } + anIsOk = true; + } + if( anIsOk ) + { + SALOMEDS::Color aColor = getGroupColor(); + resultGroup->SetColor(aColor); + + _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup ); + if( aMeshGroupSO ) + anEntryList.append( aMeshGroupSO->GetID().c_str() ); + + resultGroup->SetName(SMESH::toUtf8(myName->text().trimmed())); + + if ( isCreation ) + { + SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" ); + + /* init for the next operation */ + setDefaultName(); + myElements->clear(); + myGroup = SMESH::SMESH_Group::_nil(); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil(); + myFilter = SMESH::Filter::_nil(); + + setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled. + } + else + { + if ( aMeshGroupSO ) + { + if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) + { + Handle(SALOME_InteractiveObject) anIO = anActor->getIO(); + if ( isConversion ) { // need to reset TVisualObj and actor + SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true ); + SMESH::Update( anIO,true); + myActorsList.clear(); + anActor = SMESH::FindActorByEntry( anIO->getEntry() ); + if ( !anActor ) return false; + myActorsList.append( anActor ); + } + anActor->setName(SMESH::toUtf8(myName->text())); + QColor c; + int delta; + switch ( myTypeId ) { + case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break; + case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break; + case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break; + case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break; + case grpVolumeSelection: + SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100"); + anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break; + break; + case grpFaceSelection: + default: + SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100"); + anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break; + break; + } + // update a visible group accoding to a changed contents + if ( !isConversion && anActor->GetVisibility() ) + { + SMESH::Update( anIO, true ); + SMESH::RepaintCurrentView(); + } + } + } + } + SMESHGUI::Modified(); mySMESHGUI->updateObjBrowser(true); mySelectionMgr->clearSelected(); - return true; - } - return false; + if( LightApp_Application* anApp = + dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() ); + } + return anIsOk; } //================================================================================= @@ -946,8 +1223,12 @@ bool SMESHGUI_GroupDlg::onApply() //================================================================================= void SMESHGUI_GroupDlg::onOK() { + setIsApplyAndClose( true ); if ( onApply() ) - onClose(); + reject(); + setIsApplyAndClose( false ); + + if ( myFilterDlg ) myFilterDlg->UnRegisterFilters(); } //================================================================================= @@ -956,9 +1237,9 @@ void SMESHGUI_GroupDlg::onOK() //================================================================================= void SMESHGUI_GroupDlg::onListSelectionChanged() { - // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor); - if( myIsBusy || !myActor) return; - myIsBusy = true; + //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count()); + if( myIsBusy || myActorsList.count() == 0 ) return; + myIsBusy = true; if (myCurrentLineEdit == 0) { mySelectionMgr->clearSelected(); @@ -966,9 +1247,9 @@ void SMESHGUI_GroupDlg::onListSelectionChanged() QList selItems = myElements->selectedItems(); QListWidgetItem* anItem; foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt()); - mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false); + mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false); SALOME_ListIO aList; - aList.Append(myActor->getIO()); + aList.Append(myActorsList.first()->getIO()); mySelectionMgr->setSelectedObjects(aList,false); } myIsBusy = false; @@ -1010,7 +1291,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() myGeomObjects->length(0); if (myGeomGroupBtn->isChecked()) - myGeomGroupBtn->setChecked(false); + myGeomGroupBtn->setChecked(false); if (!myCreate) myName->setText( "" ); @@ -1029,16 +1310,20 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() Handle(SALOME_InteractiveObject) IO = aList.First(); if (myCreate) { - restoreShowEntityMode(); - myMesh = SMESH::IObjectToInterface(IO); + restoreShowEntityMode(); + myMesh = SMESH::IObjectToInterface(IO); setShowEntityMode(); updateGeomPopup(); if (myMesh->_is_nil()) - { + { updateButtons(); - myIsBusy = false; - return; - } + myIsBusy = false; + return; + } + + if ( myFilterDlg && !myMesh->_is_nil()){ + myFilterDlg->SetMesh( myMesh ); + } myGroup = SMESH::SMESH_Group::_nil(); // NPAL19389: create a group with a selection in another group @@ -1046,6 +1331,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() // any visible actor of group or submesh of myMesh SetAppropriateActor(); + setDefaultGroupColor(); + if (myName->text().isEmpty()) + setDefaultName(); + aString = aList.First()->getName(); myMeshGroupLine->setText(aString); myMeshGroupLine->home( false ); @@ -1059,15 +1348,14 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() else { SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface(IO); if (aGroup->_is_nil()) - { - myIsBusy = false; + { + myIsBusy = false; return; - } + } myIsBusy = false; - myCurrentLineEdit = 0; - myGroup = SMESH::SMESH_Group::_nil(); - myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + myGroup = SMESH::SMESH_Group::_nil(); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); init(aGroup); myIsBusy = true; @@ -1081,13 +1369,13 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() if (myGrpTypeId == 0) { - if (myTypeId == -1) - onTypeChanged(0); - else - { - myElements->clear(); - setSelectionMode(myTypeId); - } + if (myTypeId == -1) + onTypeChanged(0); + else + { + myElements->clear(); + setSelectionMode(myTypeId); + } } myIsBusy = false; @@ -1103,55 +1391,53 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() if (aNbSel == 0 || !aMeshSO) { - myGeomObjects->length(0); - updateButtons(); - myIsBusy = false; - return; + myGeomObjects->length(0); + updateButtons(); + myIsBusy = false; + return; } myGeomObjects->length(aNbSel); GEOM::GEOM_Object_var aGeomGroup; - Standard_Boolean testResult; int i = 0; SALOME_ListIteratorOfListIO anIt (aList); for (; anIt.More(); anIt.Next()) { - testResult = Standard_False; - aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult); + aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value()); // Check if the object is a geometry group - if (!testResult || CORBA::is_nil(aGeomGroup)) + if (CORBA::is_nil(aGeomGroup)) continue; // Check if group constructed on the same shape as a mesh or on its child _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var anOp = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); // The main shape of the group GEOM::GEOM_Object_var aGroupMainShape; - if (aGeomGroup->GetType() == 37) + if (aGeomGroup->GetType() == 37) { + GEOM::GEOM_IGroupOperations_wrap anOp = + SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); aGroupMainShape = anOp->GetMainShape(aGeomGroup); - else - aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup); + // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap + } + else { + aGroupMainShape = aGeomGroup; + aGroupMainShape->Register(); + } _PTR(SObject) aGroupMainShapeSO = - //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape)); aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); _PTR(SObject) anObj, aRef; bool isRefOrSubShape = false; if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) { - //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) { if (aRef->GetID() == aGroupMainShapeSO->GetID()) { isRefOrSubShape = true; } else { _PTR(SObject) aFather = aGroupMainShapeSO->GetFather(); _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent(); - //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) { while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) { - //if (strcmp(aRef->GetID(), aFather->GetID()) == 0) if (aRef->GetID() == aFather->GetID()) isRefOrSubShape = true; else @@ -1165,10 +1451,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() myGeomObjects->length(i); if ( i == 0 ) - { - myIsBusy = false; - return; - } + { + myIsBusy = false; + return; + } aNbSel = i; } @@ -1202,13 +1488,12 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() } else // !myCurrentLineEdit: local selection of nodes or elements { - if (aNbSel == 1 && myActor && myActor->hasIO()) + if (aNbSel == 1 && myActorsList.count() > 0 ) { -#ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION // NPAL19389: create a group with a selection in another group // Switch myActor to the newly selected one, if the last // is visible and belongs to group or submesh of myMesh - Handle(SALOME_InteractiveObject) curIO = myActor->getIO(); + /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO(); Handle(SALOME_InteractiveObject) selIO = aList.First(); if (curIO->hasEntry() && selIO->hasEntry()) { const char* selEntry = selIO->getEntry(); @@ -1235,54 +1520,103 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() } } } - } + }*/ // NPAL19389 END -#endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION QString aListStr = ""; int aNbItems = 0; if (myTypeId == 0) { - aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr); + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + QString tmpStr; + aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr); + aListStr += tmpStr; + } } else { - aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr); + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + QString tmpStr; + aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr); + aListStr += tmpStr; + } } if (aNbItems > 0) { - QListWidgetItem* anItem; - QList listItemsToSel; - QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts); - for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) { - QList found = myElements->findItems(*it, Qt::MatchExactly); - foreach(anItem, found) - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } - bool blocked = myElements->signalsBlocked(); - myElements->blockSignals(true); - foreach(anItem, listItemsToSel) anItem->setSelected(true); - myElements->blockSignals(blocked); - onListSelectionChanged(); - listItemsToSel.clear(); + QListWidgetItem* anItem; + QList listItemsToSel; + QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts); + for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) { + QList found = myElements->findItems(*it, Qt::MatchExactly); + foreach(anItem, found) + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + bool blocked = myElements->signalsBlocked(); + myElements->blockSignals(true); + foreach(anItem, listItemsToSel) anItem->setSelected(true); + myElements->blockSignals(blocked); + onListSelectionChanged(); + listItemsToSel.clear(); } } } - - if (!myActor) { - if (!myGroup->_is_nil()) - myActor = SMESH::FindActorByObject(myGroup); - else if(!myGroupOnGeom->_is_nil()) - myActor = SMESH::FindActorByObject(myGroupOnGeom); - else - myActor = SMESH::FindActorByObject(myMesh); + + if (myActorsList.count() == 0) { + if (!myGroup->_is_nil()) { + SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup); + if ( anActor ) + myActorsList.append( anActor ); + } + else if(!myGroupOnGeom->_is_nil()) { + SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom); + if ( anActor ) + myActorsList.append( anActor ); + } + else { + SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh ); + if ( anActor ) + myActorsList.append( anActor ); + } } // somehow, if we display the mesh, while selecting from another actor, // the mesh becomes pickable, and there is no way to select any element - if (myActor) - SMESH::SetPickable(myActor); + if (myActorsList.count() > 0) { + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + SMESH_Actor* anActor = it.next(); + if ( IsActorVisible(anActor) ) + anActor->SetPickable(true); + } + } myIsBusy = false; } +//================================================================================= +// function : onSelectAll() +// purpose : Called when "Select all" is checked +//================================================================================= +void SMESHGUI_GroupDlg::onSelectAll() +{ + bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() ); + + myElementsLab->setEnabled( !noElemsModif ); + myElements->setEnabled ( !noElemsModif ); + myFilterBtn->setEnabled ( !noElemsModif ); + myAddBtn->setEnabled ( !noElemsModif ); + myRemoveBtn->setEnabled ( !noElemsModif ); + mySortBtn->setEnabled ( !noElemsModif ); + mySelectBox->setEnabled ( !noElemsModif ); + myAllowElemsModif->setEnabled( !mySelectAll->isChecked() ); + if ( noElemsModif ) mySMESHGUI->ResetState(); + else mySMESHGUI->SetState(800); + + int selMode = mySelectionMode; + mySelectionMode = grpNoSelection; + setSelectionMode( selMode ); + updateButtons(); +} + //================================================================================= // function : onSelectSubMesh() // purpose : Called when selection in 3D view or ObjectBrowser is changed @@ -1297,7 +1631,7 @@ void SMESHGUI_GroupDlg::onSelectSubMesh(bool on) //VSR: mySelectGeomGroup->setChecked(false); //VSR: } myCurrentLineEdit = mySubMeshLine; - setSelectionMode(4); + setSelectionMode(grpSubMeshSelection); } else { mySubMeshLine->setText( "" ); @@ -1321,7 +1655,7 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on) mySelectSubMesh->setChecked(false); } myCurrentLineEdit = myGroupLine; - setSelectionMode(5); + setSelectionMode(grpGroupSelection); } else { myGroupLine->setText( "" ); @@ -1336,7 +1670,7 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on) //================================================================================= // function : (onSelectGeomGroup) -// purpose : Called when selection in 3D view or ObjectBrowser is changed +// purpose : Called when group type changed. on == "on geometry" or "on filter" //================================================================================= void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on) { @@ -1347,9 +1681,14 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on) else if (mySelectGroup->isChecked()) { mySelectGroup->setChecked(false); } - myCurrentLineEdit = myGeomGroupLine; - updateGeomPopup(); - setSelectionMode(8); + if ( myGrpTypeId == 1 ) { // on geometry + myCurrentLineEdit = myGeomGroupLine; + updateGeomPopup(); + } + else { // on filter + myCurrentLineEdit = 0; + } + setSelectionMode(grpAllSelection); } else { myGeomGroupBtn->setChecked(false); @@ -1357,11 +1696,10 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on) myGeomGroupLine->setText( "" ); myCurrentLineEdit = 0; if (myTypeId != -1) - setSelectionMode(myTypeId); + setSelectionMode( myTypeId ); } } - //================================================================================= // function : setCurrentSelection() // purpose : @@ -1371,11 +1709,14 @@ void SMESHGUI_GroupDlg::setCurrentSelection() QPushButton* send = (QPushButton*)sender(); myCurrentLineEdit = 0; if (send == myMeshGroupBtn) { - myCurrentLineEdit = myMeshGroupLine; + disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); + mySelectionMgr->clearSelected(); if (myCreate) - setSelectionMode(6); + setSelectionMode(grpMeshSelection); else - setSelectionMode(5); + setSelectionMode(grpGroupSelection); + connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); + myCurrentLineEdit = myMeshGroupLine; onObjectSelectionChanged(); } else if (send == mySubMeshBtn) { @@ -1395,14 +1736,23 @@ void SMESHGUI_GroupDlg::setCurrentSelection() //================================================================================= void SMESHGUI_GroupDlg::setFilters() { + if(myMesh->_is_nil()) { + SUIT_MessageBox::critical(this, + tr("SMESH_ERROR"), + tr("NO_MESH_SELECTED")); + return; + } + SMESH::ElementType aType = SMESH::ALL; switch ( myTypeId ) { - case 0 : aType = SMESH::NODE; break; - case 1 : aType = SMESH::EDGE; break; - case 2 : aType = SMESH::FACE; break; - case 3 : aType = SMESH::VOLUME; break; - default: return; + case grpNodeSelection: aType = SMESH::NODE; break; + case grp0DSelection: aType = SMESH::ELEM0D; break; + case grpBallSelection: aType = SMESH::BALL; break; + case grpEdgeSelection: aType = SMESH::EDGE; break; + case grpFaceSelection: aType = SMESH::FACE; break; + case grpVolumeSelection: aType = SMESH::VOLUME; break; + default: return; } if ( myFilterDlg == 0 ) @@ -1413,9 +1763,19 @@ void SMESHGUI_GroupDlg::setFilters() else myFilterDlg->Init( aType ); - myFilterDlg->SetSelection(); + if ( !myGroupOnFilter->_is_nil() ) + { + myFilterDlg->SetFilter( myFilter, aType ); + myFilterDlg->Init( aType ); + } + + bool isStandalone = ( sender() == myFilterBtn ); + myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone, + /*diffSources=*/isStandalone ); myFilterDlg->SetMesh( myMesh ); - myFilterDlg->SetSourceWg( myElements ); + myFilterDlg->SetGroup( myGroupOnFilter ); + myFilterDlg->SetSelection(); + myFilterDlg->SetSourceWg( myElements, false ); myFilterDlg->show(); } @@ -1433,6 +1793,32 @@ void SMESHGUI_GroupDlg::onFilterAccepted() mySelectSubMesh->setChecked( false ); mySelectGroup->setChecked( false ); } + // get a filter from myFilterDlg + myFilter = myFilterDlg->GetFilter(); + if ( !myFilter->_is_nil() ) { + SMESH::Predicate_var perdicate = myFilter->GetPredicate(); + if ( perdicate->_is_nil() ) + myFilter = SMESH::Filter::_nil(); + } + // set mesh to myFilter + if ( !myFilter->_is_nil() ) { + SMESH::SMESH_Mesh_var mesh = myMesh; + if ( mesh->_is_nil() ) { + if ( !myGroup->_is_nil() ) + mesh = myGroup->GetMesh(); + else if ( !myGroupOnGeom->_is_nil() ) + mesh = myGroupOnGeom->GetMesh(); + else if ( !myGroupOnFilter->_is_nil() ) + mesh = myGroupOnFilter->GetMesh(); + } + myFilter->SetMesh( mesh ); + + // highlight ids if selection changed in the Viewer (IPAL52924) + myCurrentLineEdit = 0; + onObjectSelectionChanged(); + } + + updateButtons(); } //================================================================================= @@ -1446,25 +1832,36 @@ void SMESHGUI_GroupDlg::onAdd() int aNbSel = aList.Extent(); - if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return; + if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return; + + SUIT_OverrideCursor wc; myIsBusy = true; + int sizeBefore = myElements->count(); SMESH::ElementType aType = SMESH::ALL; switch(myTypeId) { - case 0: + case grpNodeSelection: aType = SMESH::NODE; mySelector->SetSelectionMode(NodeSelection); break; - case 1: + case grpBallSelection: + aType = SMESH::BALL; + mySelector->SetSelectionMode(BallSelection); + break; + case grp0DSelection: + aType = SMESH::ELEM0D; + mySelector->SetSelectionMode(Elem0DSelection); + break; + case grpEdgeSelection: aType = SMESH::EDGE; mySelector->SetSelectionMode(EdgeSelection); break; - case 2: + case grpFaceSelection: aType = SMESH::FACE; mySelector->SetSelectionMode(FaceSelection); break; - case 3: + case grpVolumeSelection: aType = SMESH::VOLUME; mySelector->SetSelectionMode(VolumeSelection); break; @@ -1480,26 +1877,36 @@ void SMESHGUI_GroupDlg::onAdd() QString aListStr = ""; int aNbItems = 0; if (myTypeId == 0) { - aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr); + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + QString tmpStr; + aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr); + aListStr += tmpStr; + } } else { - aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr); + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + QString tmpStr; + aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr); + aListStr += tmpStr; + } } if (aNbItems > 0) { QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts); for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) { - QList found = myElements->findItems(*it, Qt::MatchExactly); - if (found.count() == 0) { - anItem = new QListWidgetItem(*it); - myElements->addItem(anItem); - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } - else { - foreach(anItem, found) - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } + QList found = myElements->findItems(*it, Qt::MatchExactly); + if (found.count() == 0) { + anItem = new QListWidgetItem(*it); + myElements->addItem(anItem); + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + else { + foreach(anItem, found) + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } } bool blocked = myElements->signalsBlocked(); myElements->blockSignals(true); @@ -1519,8 +1926,8 @@ void SMESHGUI_GroupDlg::onAdd() SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface(anIt.Value()); if (!aSubMesh->_is_nil()) { - // check if mesh is the same - if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) { + // check if mesh is the same + if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) { try { SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType); int k = anElements->length(); @@ -1530,21 +1937,21 @@ void SMESHGUI_GroupDlg::onAdd() if (found.count() == 0) { anItem = new QListWidgetItem(aText); myElements->addItem(anItem); - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + else { + foreach(anItem, found) + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); } - else { - foreach(anItem, found) - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } } - bool blocked = myElements->signalsBlocked(); - myElements->blockSignals(true); - foreach(anItem, listItemsToSel) anItem->setSelected(true); - myElements->blockSignals(blocked); - onListSelectionChanged(); - listItemsToSel.clear(); + bool blocked = myElements->signalsBlocked(); + myElements->blockSignals(true); + foreach(anItem, listItemsToSel) anItem->setSelected(true); + myElements->blockSignals(blocked); + onListSelectionChanged(); + listItemsToSel.clear(); } catch (const SALOME::SALOME_Exception& ex) { SalomeApp_Tools::QtCatchCorbaException(ex); @@ -1566,32 +1973,32 @@ void SMESHGUI_GroupDlg::onAdd() SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface(anIt.Value()); if (!aGroup->_is_nil()) { - // check if mesh is the same - if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) { - SMESH::long_array_var anElements = aGroup->GetListOfID(); - int k = anElements->length(); - for (int i = 0; i < k; i++) { - QString aText = QString::number(anElements[i]); - QList found = myElements->findItems(aText, Qt::MatchExactly); - if (found.count() == 0) { - anItem = new QListWidgetItem(aText); - myElements->addItem(anItem); - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } - else { - foreach(anItem, found) - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } - } - bool blocked = myElements->signalsBlocked(); - myElements->blockSignals(true); - foreach(anItem, listItemsToSel) anItem->setSelected(true); - myElements->blockSignals(blocked); - onListSelectionChanged(); - listItemsToSel.clear(); - } + // check if mesh is the same + if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) { + SMESH::long_array_var anElements = aGroup->GetListOfID(); + int k = anElements->length(); + for (int i = 0; i < k; i++) { + QString aText = QString::number(anElements[i]); + QList found = myElements->findItems(aText, Qt::MatchExactly); + if (found.count() == 0) { + anItem = new QListWidgetItem(aText); + myElements->addItem(anItem); + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + else { + foreach(anItem, found) + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + } + bool blocked = myElements->signalsBlocked(); + myElements->blockSignals(true); + foreach(anItem, listItemsToSel) anItem->setSelected(true); + myElements->blockSignals(blocked); + onListSelectionChanged(); + listItemsToSel.clear(); + } } } mySelectGroup->setChecked(false); @@ -1600,15 +2007,15 @@ void SMESHGUI_GroupDlg::onAdd() } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) { _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var aGroupOp = + GEOM::GEOM_IGroupOperations_wrap aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::ElementType aGroupType = SMESH::ALL; switch(aGroupOp->GetType(myGeomObjects[0])) { - case 7: aGroupType = SMESH::NODE; break; - case 6: aGroupType = SMESH::EDGE; break; - case 4: aGroupType = SMESH::FACE; break; - case 2: aGroupType = SMESH::VOLUME; break; + case TopAbs_VERTEX: aGroupType = SMESH::NODE; break; + case TopAbs_EDGE: aGroupType = SMESH::EDGE; break; + case TopAbs_FACE: aGroupType = SMESH::FACE; break; + case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break; default: myIsBusy = false; return; } @@ -1619,7 +2026,7 @@ void SMESHGUI_GroupDlg::onAdd() // Construct filter SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager(); SMESH::Filter_var aFilter = aFilterMgr->CreateFilter(); - SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();; + SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom(); aBelongToGeom->SetGeom(myGeomObjects[0]); aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str()); aBelongToGeom->SetElementType(aType); @@ -1629,19 +2036,19 @@ void SMESHGUI_GroupDlg::onAdd() int k = anElements->length(); for (int i = 0; i < k; i++) { - QString aText = QString::number(anElements[i]); - QList found = myElements->findItems(aText, Qt::MatchExactly); - if (found.count() == 0) { - anItem = new QListWidgetItem(aText); - myElements->addItem(anItem); - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } - else { - foreach(anItem, found) - if (!anItem->isSelected()) - listItemsToSel.push_back(anItem); - } + QString aText = QString::number(anElements[i]); + QList found = myElements->findItems(aText, Qt::MatchExactly); + if (found.count() == 0) { + anItem = new QListWidgetItem(aText); + myElements->addItem(anItem); + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } + else { + foreach(anItem, found) + if (!anItem->isSelected()) + listItemsToSel.push_back(anItem); + } } bool blocked = myElements->signalsBlocked(); myElements->blockSignals(true); @@ -1656,6 +2063,8 @@ void SMESHGUI_GroupDlg::onAdd() onListSelectionChanged(); } myIsBusy = false; + if ( sizeBefore < myElements->count() ) + ++myNbChangesOfContents; // mySelectionMgr->clearSelected(); updateButtons(); } @@ -1667,6 +2076,8 @@ void SMESHGUI_GroupDlg::onAdd() void SMESHGUI_GroupDlg::onRemove() { myIsBusy = true; + int sizeBefore = myElements->count(); + if (myCurrentLineEdit == 0) { QList selItems = myElements->selectedItems(); QListWidgetItem* item; @@ -1681,10 +2092,12 @@ void SMESHGUI_GroupDlg::onRemove() SMESH::ElementType aType = SMESH::ALL; switch(myTypeId) { - case 0: aType = SMESH::NODE; break; - case 1: aType = SMESH::EDGE; break; - case 2: aType = SMESH::FACE; break; - case 3: aType = SMESH::VOLUME; break; + case grpNodeSelection: aType = SMESH::NODE; break; + case grp0DSelection: aType = SMESH::ELEM0D; break; + case grpBallSelection: aType = SMESH::BALL; break; + case grpEdgeSelection: aType = SMESH::EDGE; break; + case grpFaceSelection: aType = SMESH::FACE; break; + case grpVolumeSelection: aType = SMESH::VOLUME; break; } if (myCurrentLineEdit == mySubMeshLine) { @@ -1694,70 +2107,70 @@ void SMESHGUI_GroupDlg::onRemove() SALOME_ListIteratorOfListIO anIt (aList); for ( ; anIt.More(); anIt.Next()) { - SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface(anIt.Value()); - if (!aSubMesh->_is_nil()) { - // check if mesh is the same - if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) { - if (aType == SMESH::NODE) { - try { - SMESH::long_array_var anElements = aSubMesh->GetNodesId(); - int k = anElements->length(); - for (int i = 0; i < k; i++) { - QList found = - myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); - QListWidgetItem* anItem; - foreach(anItem, found) delete anItem; - } - } - catch (const SALOME::SALOME_Exception& ex) { - SalomeApp_Tools::QtCatchCorbaException(ex); - } - } - else { - try { - SMESH::long_array_var anElements = aSubMesh->GetElementsId(); - int k = anElements->length(); - for (int i = 0; i < k; i++) { - QList found = - myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); - QListWidgetItem* anItem; - foreach(anItem, found) delete anItem; - } - } - catch (const SALOME::SALOME_Exception& ex) { - SalomeApp_Tools::QtCatchCorbaException(ex); - } - } - } - } + SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface(anIt.Value()); + if (!aSubMesh->_is_nil()) { + // check if mesh is the same + if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) { + if (aType == SMESH::NODE) { + try { + SMESH::long_array_var anElements = aSubMesh->GetNodesId(); + int k = anElements->length(); + for (int i = 0; i < k; i++) { + QList found = + myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); + QListWidgetItem* anItem; + foreach(anItem, found) delete anItem; + } + } + catch (const SALOME::SALOME_Exception& ex) { + SalomeApp_Tools::QtCatchCorbaException(ex); + } + } + else { + try { + SMESH::long_array_var anElements = aSubMesh->GetElementsId(); + int k = anElements->length(); + for (int i = 0; i < k; i++) { + QList found = + myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); + QListWidgetItem* anItem; + foreach(anItem, found) delete anItem; + } + } + catch (const SALOME::SALOME_Exception& ex) { + SalomeApp_Tools::QtCatchCorbaException(ex); + } + } + } + } } } else if (myCurrentLineEdit == myGroupLine) { - Standard_Boolean aRes; - //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects()); SALOME_ListIO aList; mySelectionMgr->selectedObjects( aList ); SALOME_ListIteratorOfListIO anIt (aList); for ( ; anIt.More(); anIt.Next()) { - SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface(anIt.Value()); - if (aRes && !aGroup->_is_nil()) { - // check if mesh is the same - if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) { - SMESH::long_array_var anElements = aGroup->GetListOfID(); - int k = anElements->length(); - for (int i = 0; i < k; i++) { - QList found = - myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); - QListWidgetItem* anItem; - foreach(anItem, found) delete anItem; - } - } - } + SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface(anIt.Value()); + if (!aGroup->_is_nil()) { + // check if mesh is the same + if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) { + SMESH::long_array_var anElements = aGroup->GetListOfID(); + int k = anElements->length(); + for (int i = 0; i < k; i++) { + QList found = + myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly); + QListWidgetItem* anItem; + foreach(anItem, found) delete anItem; + } + } + } } } } myIsBusy = false; + if ( sizeBefore > myElements->count() ) + myNbChangesOfContents += 2; // it's used to detect that "Add" was only once updateButtons(); } @@ -1781,7 +2194,7 @@ void SMESHGUI_GroupDlg::onSort() int id = myElements->item(i)->text().toInt(); anArray[i] = id; if (myElements->item(i)->isSelected()) - aSelected.append(id); + aSelected.append(id); } // sort & update list std::sort(anArray.begin(), anArray.end()); @@ -1793,7 +2206,7 @@ void SMESHGUI_GroupDlg::onSort() anItem = new QListWidgetItem(QString::number(anArray[i])); myElements->addItem(anItem); if (aSelected.contains(anArray[i])) - listItemsToSel.push_back(anItem); + listItemsToSel.push_back(anItem); } bool blocked = myElements->signalsBlocked(); myElements->blockSignals(true); @@ -1805,19 +2218,19 @@ void SMESHGUI_GroupDlg::onSort() } //================================================================================= -// function : closeEvent() +// function : onVisibilityChanged() // purpose : //================================================================================= -void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*) +void SMESHGUI_GroupDlg::onVisibilityChanged() { - onClose(); + SetAppropriateActor(); } //================================================================================= -// function : SMESHGUI_GroupDlg::onClose +// function : SMESHGUI_GroupDlg::reject // purpose : SLOT called when "Close" button pressed. Close dialog //================================================================================= -void SMESHGUI_GroupDlg::onClose() +void SMESHGUI_GroupDlg::reject() { if (SMESH::GetCurrentVtkView()) { SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters @@ -1826,13 +2239,47 @@ void SMESHGUI_GroupDlg::onClose() restoreShowEntityMode(); } - mySelectionMgr->clearSelected(); + if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) { + SUIT_DataOwnerPtrList aList; + aList.append( new LightApp_DataOwner( myObjectToSelect ) ); + mySelectionMgr->setSelected( aList ); + } + else + mySelectionMgr->clearSelected(); if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode(ActorSelection); mySelectionMgr->clearFilters(); mySMESHGUI->ResetState(); - reject(); + QDialog::reject(); + + if ( myFilterDlg ) myFilterDlg->UnRegisterFilters(); +} + +//================================================================================= +// function : onOpenView() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::onOpenView() +{ + if ( mySelector ) { + SMESH::SetPointRepresentation(false); + } + else { + mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector(); + mySMESHGUI->EmitSignalDeactivateDialog(); + setEnabled(true); + } +} + +//================================================================================= +// function : onCloseView() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::onCloseView() +{ + onDeactivate(); + mySelector = 0; } //================================================================================= @@ -1843,19 +2290,21 @@ void SMESHGUI_GroupDlg::onHelp() { LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); if (app) - app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName); - else { - QString platform; + { + app->onHelpContextModule + ( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString(""), myHelpFileName ); + } + else + { #ifdef WIN32 - platform = "winapplication"; + QString platform = "winapplication"; #else - platform = "application"; + QString 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)); } } @@ -1876,26 +2325,20 @@ void SMESHGUI_GroupDlg::onDeactivate() void SMESHGUI_GroupDlg::enterEvent (QEvent*) { if (!isEnabled()) { + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ); + if ( aViewWindow && !mySelector) { + mySelector = aViewWindow->GetSelector(); + } mySMESHGUI->EmitSignalDeactivateDialog(); setEnabled(true); - mySelectionMode = -1; + mySelectionMode = grpNoSelection; setSelectionMode(myTypeId); - //mySMESHGUI->SetActiveDialogBox((QDialog*)this); mySMESHGUI->SetActiveDialogBox(this); - mySMESHGUI->SetState(800); + if ( mySelectBox->isEnabled() ) mySMESHGUI->SetState(800); + else mySMESHGUI->ResetState(); } } -//================================================================================= -// function : hideEvent -// purpose : caused by ESC key -//================================================================================= -void SMESHGUI_GroupDlg::hideEvent (QHideEvent*) -{ - if (!isMinimized() && !myIsBusy) - onClose(); -} - //================================================================================= // function : keyPressEvent() // purpose : @@ -1907,16 +2350,16 @@ void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e ) return; if ( e->key() == Qt::Key_F1 ) - { - e->accept(); - onHelp(); - } + { + e->accept(); + onHelp(); + } } //================================================================================ /*! * \brief Enable showing of the popup when Geometry selection btn is clicked - * \param enable - true to enable + * \param enable - true to enable */ //================================================================================ @@ -1952,17 +2395,17 @@ void SMESHGUI_GroupDlg::updateGeomPopup() void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn) { if ( myGeomPopup && isBtnOn ) - { - myCurrentLineEdit = myGeomGroupLine; - QAction* a = myGeomPopup->exec( QCursor::pos() ); - if (!a || myActions[a] == DIRECT_GEOM_INDEX) - setSelectionMode(7); - } + { + myCurrentLineEdit = myGeomGroupLine; + QAction* a = myGeomPopup->exec( QCursor::pos() ); + if (!a || myActions[a] == DIRECT_GEOM_INDEX) + setSelectionMode(grpGeomSelection); + } else if (!isBtnOn) - { - myCurrentLineEdit = 0; - setSelectionMode(8); - } + { + myCurrentLineEdit = 0; + setSelectionMode(grpAllSelection); + } } //================================================================================= @@ -1973,26 +2416,26 @@ void SMESHGUI_GroupDlg::onGeomPopup( QAction* a ) { int index = myActions[a]; if ( index == GEOM_BY_MESH_INDEX ) - { - mySelectionMode = -1; - if ( !myShapeByMeshOp ) { - myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true); - connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)), - SLOT(onPublishShapeByMeshDlg(SUIT_Operation*))); - connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)), - SLOT(onCloseShapeByMeshDlg(SUIT_Operation*))); - } - // set mesh object to SMESHGUI_ShapeByMeshOp and start it - if ( !myMesh->_is_nil() ) { - myIsBusy = true; - hide(); // stop processing selection - myIsBusy = false; - myShapeByMeshOp->setModule( mySMESHGUI ); - myShapeByMeshOp->setStudy( 0 ); // it's really necessary - myShapeByMeshOp->SetMesh( myMesh ); - myShapeByMeshOp->start(); - } + { + mySelectionMode = grpNoSelection; + if ( !myShapeByMeshOp ) { + myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true); + connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)), + SLOT(onPublishShapeByMeshDlg(SUIT_Operation*))); + connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)), + SLOT(onCloseShapeByMeshDlg(SUIT_Operation*))); } + // set mesh object to SMESHGUI_ShapeByMeshOp and start it + if ( !myMesh->_is_nil() ) { + myIsBusy = true; + hide(); // stop processing selection + myIsBusy = false; + myShapeByMeshOp->setModule( mySMESHGUI ); + myShapeByMeshOp->setStudy( 0 ); // it's really necessary + myShapeByMeshOp->SetMesh( myMesh ); + myShapeByMeshOp->start(); + } + } } //================================================================================ @@ -2013,12 +2456,12 @@ void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op) QString ID = aGeomVar->GetStudyEntry(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) { - SALOME_ListIO anIOList; - Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject - ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() ); - anIOList.Append( anIO ); - mySelectionMgr->setSelectedObjects( anIOList, false ); - onObjectSelectionChanged(); + SALOME_ListIO anIOList; + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject + ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() ); + anIOList.Append( anIO ); + mySelectionMgr->setSelectedObjects( anIOList, false ); + onObjectSelectionChanged(); } } } @@ -2033,10 +2476,10 @@ void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op) void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op) { if ( myShapeByMeshOp == op ) - { - show(); - setSelectionMode(7); - } + { + show(); + setSelectionMode(grpGeomSelection); + } } //================================================================================= @@ -2046,8 +2489,8 @@ void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op) void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor ) { QColor aQColor( (int)( theColor.R * 255.0 ), - (int)( theColor.G * 255.0 ), - (int)( theColor.B * 255.0 ) ); + (int)( theColor.G * 255.0 ), + (int)( theColor.B * 255.0 ) ); setGroupQColor( aQColor ); } @@ -2097,15 +2540,20 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor() bool isAutoColor = myMesh->GetAutoColor(); - QColor aQColor; + QColor aQColor = myColorBtn->color(); if( !isAutoColor ) { - int r = 0, g = 0, b = 0; - SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) ); - aQColor.setRgb( r, g, b ); + if ( !aQColor.isValid() ) { + int r = 0, g = 0, b = 0; + SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) ); + aQColor.setRgb( r, g, b ); + } } else { +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor(); +#else // old algorithm for auto-colors SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); QList aReservedColors; @@ -2117,9 +2565,11 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor() } SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors ); +#endif // SIMPLE_AUTOCOLOR + aQColor.setRgb( (int)( aColor.R * 255.0 ), - (int)( aColor.G * 255.0 ), - (int)( aColor.B * 255.0 ) ); + (int)( aColor.G * 255.0 ), + (int)( aColor.B * 255.0 ) ); } @@ -2130,85 +2580,97 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor() // function : SetAppropriateActor() // purpose : Find more appropriate of visible actors, set it to myActor, allow picking // NPAL19389: create a group with a selection in another group. -// if mesh actor is not visible - find any first visible group or submesh +// if mesh actor is not visible - find any first visible group or sub-mesh //================================================================================= bool SMESHGUI_GroupDlg::SetAppropriateActor() { bool isActor = false; + myActorsList.clear(); if (myMesh->_is_nil()) return false; SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView(); - // try mesh actor - myActor = SMESH::FindActorByObject(myMesh); - if (myActor && myActor->hasIO()) - { - isActor = true; - if (aViewWindow && !aViewWindow->isVisible(myActor->getIO())) + if (myGrpTypeGroup->checkedId() > 0) { // try current group on geometry actor + SMESH_Actor* anActor = 0; + if (!myGroupOnGeom->_is_nil()) + anActor = SMESH::FindActorByObject(myGroupOnGeom); + if (!myGroupOnFilter->_is_nil()) + anActor = SMESH::FindActorByObject(myGroupOnFilter); + if (anActor && anActor->hasIO()) + { + isActor = true; + if (aViewWindow && !aViewWindow->isVisible(anActor->getIO())) isActor = false; - } - - // try current group actor - if (!isActor) { - if (!myGroup->_is_nil()) { - myActor = SMESH::FindActorByObject(myGroup); - if (myActor && myActor->hasIO()) - { - isActor = true; - if (aViewWindow && !aViewWindow->isVisible(myActor->getIO())) - isActor = false; - } + else + myActorsList.append(anActor); } + return anActor; } + else { + // try mesh actor + SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh); + if (anActor && anActor->hasIO()) { + isActor = true; + if (aViewWindow && !aViewWindow->isVisible(anActor->getIO())) + isActor = false; + else + myActorsList.append(anActor); + } - // try current group on geometry actor - if (!isActor) { - if (!myGroupOnGeom->_is_nil()) { - myActor = SMESH::FindActorByObject(myGroupOnGeom); - if (myActor && myActor->hasIO()) - { - isActor = true; - if (aViewWindow && !aViewWindow->isVisible(myActor->getIO())) - isActor = false; - } + // try group actor + SMESH_Actor* aGroupActor = 0; + if (!isActor && !myGroup->_is_nil()) { + aGroupActor = SMESH::FindActorByObject(myGroup); + if (aGroupActor && aGroupActor->hasIO()) + myActorsList.append(aGroupActor); } - } - // try any visible actor of group or submesh of current mesh - if (!isActor && aViewWindow) { - // mesh entry - _PTR(SObject) aSObject = SMESH::FindSObject(myMesh); - if (aSObject) { - CORBA::String_var meshEntry = aSObject->GetID().c_str(); - int len = strlen(meshEntry); - - // iterate on all actors in current view window, search for - // any visible actor, that belongs to group or submesh of current mesh - vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors(); - aCollection->InitTraversal(); - for (vtkActor *anAct = aCollection->GetNextActor(); - anAct && !isActor; - anAct = aCollection->GetNextActor()) - { - SMESH_Actor *anActor = dynamic_cast(anAct); - if (anActor && anActor->hasIO()) { - Handle(SALOME_InteractiveObject) anIO = anActor->getIO(); - if (aViewWindow->isVisible(anIO)) { - if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) { - myActor = anActor; - isActor = true; + // try any visible actor of group or sub-mesh of current mesh + if (aViewWindow) { + // mesh entry + _PTR(SObject) aSObject = SMESH::FindSObject(myMesh); + if (aSObject) { + CORBA::String_var meshEntry = aSObject->GetID().c_str(); + int len = strlen(meshEntry); + + // iterate on all actors in current view window, search for + // any visible actor, that belongs to group or submesh of current mesh + VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors()); + vtkActorCollection *aCollection = aCopy.GetActors(); + int nbItems = aCollection->GetNumberOfItems(); + for (int i=0; i(aCollection->GetItemAsObject(i)); + if (anActor && anActor->hasIO()) { + Handle(SALOME_InteractiveObject) anIO = anActor->getIO(); + if (aViewWindow->isVisible(anIO)) { + if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) ) + myActorsList.append(anActor); } } } } } + + // Show a standalone group if nothing else is visible (IPAL52227) + if ( myActorsList.count() == 1 && + myActorsList[0] == aGroupActor && + aViewWindow && !aViewWindow->isVisible(aGroupActor->getIO())) + SMESH::UpdateView( aViewWindow, SMESH::eDisplay, aGroupActor->getIO()->getEntry() ); } - if (isActor) - SMESH::SetPickable(myActor); - return isActor; + if (myActorsList.count() > 0) { + QListIterator it( myActorsList ); + while ( it.hasNext() ) { + SMESH_Actor* anActor = it.next(); + if ( IsActorVisible(anActor) ) + anActor->SetPickable(true); + } + } + + return ( isActor || (myActorsList.count() > 0) ); } //======================================================================= @@ -2222,10 +2684,12 @@ void SMESHGUI_GroupDlg::setShowEntityMode() if (!myStoredShownEntity) myStoredShownEntity = actor->GetEntityMode(); switch ( myTypeId ) { - case 0: restoreShowEntityMode(); break; - case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break; - case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break; - case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break; + case grpNodeSelection: restoreShowEntityMode(); break; + case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break; + case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break; + case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break; + case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break; + case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break; } } } @@ -2244,3 +2708,35 @@ void SMESHGUI_GroupDlg::restoreShowEntityMode() } myStoredShownEntity = 0; } + +//======================================================================= +//function : IsActorVisible +//purpose : return visibility of the actor +//======================================================================= +bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor ) +{ + SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView(); + if (theActor && aViewWindow) + return aViewWindow->isVisible(theActor->getIO()); + return false; +} + +//================================================================ +//function : setIsApplyAndClose +//purpose : Set value of the flag indicating that the dialog is +// accepted by Apply & Close button +//================================================================ +void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag ) +{ + myIsApplyAndClose = theFlag; +} + +//================================================================ +//function : isApplyAndClose +//purpose : Get value of the flag indicating that the dialog is +// accepted by Apply & Close button +//================================================================ +bool SMESHGUI_GroupDlg::isApplyAndClose() const +{ + return myIsApplyAndClose; +}