Back to index

salome-smesh  6.5.0
SMESHGUI_GroupDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESHGUI : GUI for SMESH component
00024 //  File   : SMESHGUI_GroupDlg.cxx
00025 //  Author : Natalia KOPNOVA, Open CASCADE S.A.S.
00026 //  SMESH includes
00027 //
00028 #include "SMESHGUI_GroupDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_GroupUtils.h"
00034 #include "SMESHGUI_FilterUtils.h"
00035 #include "SMESHGUI_GEOMGenUtils.h"
00036 #include "SMESHGUI_FilterDlg.h"
00037 #include "SMESHGUI_ShapeByMeshDlg.h"
00038 
00039 #include <SMESH_TypeFilter.hxx>
00040 #include <SMESH_Actor.h>
00041 #include <SMESH_ActorUtils.h>
00042 #include <SMESH_LogicalFilter.hxx>
00043 
00044 // SALOME GEOM includes
00045 #include <GEOMBase.h>
00046 #include <GEOM_SelectionFilter.h>
00047 
00048 // SALOME GUI includes
00049 #include <QtxColorButton.h>
00050 
00051 #include <SUIT_Desktop.h>
00052 #include <SUIT_ResourceMgr.h>
00053 #include <SUIT_Session.h>
00054 #include <SUIT_MessageBox.h>
00055 
00056 #include <SalomeApp_Tools.h>
00057 #include <SalomeApp_Application.h>
00058 #include <SalomeApp_Study.h>
00059 #include <LightApp_SelectionMgr.h>
00060 
00061 #include <SALOME_ListIO.hxx>
00062 #include <SALOME_ListIteratorOfListIO.hxx>
00063 
00064 #include <SVTK_ViewWindow.h>
00065 
00066 #include <VTKViewer_Algorithm.h>
00067 
00068 // SALOME KERNEL includes
00069 #include <SALOMEDSClient_Study.hxx>
00070 
00071 // VTK Includes
00072 #include <vtkRenderer.h>
00073 #include <vtkActorCollection.h>
00074 
00075 // OCCT includes
00076 #include <TColStd_MapOfInteger.hxx>
00077 
00078 // Qt includes
00079 #include <QButtonGroup>
00080 #include <QGroupBox>
00081 #include <QLabel>
00082 #include <QLineEdit>
00083 #include <QPushButton>
00084 #include <QToolButton>
00085 #include <QRadioButton>
00086 #include <QCheckBox>
00087 #include <QGridLayout>
00088 #include <QHBoxLayout>
00089 #include <QVBoxLayout>
00090 #include <QListWidget>
00091 #include <QStackedWidget>
00092 #include <QKeyEvent>
00093 #include <QMenu>
00094 
00095 // STL includes
00096 #include <vector>
00097 #include <algorithm>
00098 #include <set>
00099 
00100 #define SPACING 6
00101 #define MARGIN  11
00102 
00103 enum grpSelectionMode {
00104   grpNoSelection       = -1,
00105   grpNodeSelection     = 0,
00106   grpEdgeSelection     = 1,
00107   grpFaceSelection     = 2,
00108   grpVolumeSelection   = 3,
00109   grpSubMeshSelection  = 4,
00110   grpGroupSelection    = 5,
00111   grpMeshSelection     = 6,
00112   grpGeomSelection     = 7,
00113   grpAllSelection      = 8,
00114 };
00115 
00116 //=================================================================================
00117 // function : SMESHGUI_GroupDlg()
00118 // purpose  :
00119 //=================================================================================
00120 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
00121                                       SMESH::SMESH_Mesh_ptr theMesh )
00122   : QDialog( SMESH::GetDesktop( theModule ) ),
00123     mySMESHGUI( theModule ),
00124     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00125     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
00126     myIsBusy( false ),
00127     myNameChanged( false ),
00128     myIsApplyAndClose( false ),
00129     myNbChangesOfContents(0)
00130 {
00131   initDialog( true );
00132   if ( !theMesh->_is_nil() )
00133     init( theMesh );
00134   else
00135   {
00136     mySelectSubMesh->setEnabled( false );
00137     mySelectGroup->setEnabled( false );
00138     myGeomGroupBtn->setEnabled( false );
00139     myGeomGroupLine->setEnabled( false );
00140   }
00141 }
00142 
00143 //=================================================================================
00144 // function : SMESHGUI_GroupDlg()
00145 // purpose  :
00146 //=================================================================================
00147 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
00148                                       SMESH::SMESH_GroupBase_ptr theGroup,
00149                                       const bool theIsConvert )
00150   : QDialog( SMESH::GetDesktop( theModule ) ),
00151     mySMESHGUI( theModule ),
00152     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00153     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
00154     myIsBusy( false ),
00155     myNameChanged( false ),
00156     myNbChangesOfContents(0) // just not to use uninitialized variable
00157 {
00158   initDialog( false );
00159   if ( !theGroup->_is_nil() )
00160     init( theGroup, theIsConvert );
00161   else
00162   {
00163     mySelectSubMesh->setEnabled( false );
00164     mySelectGroup->setEnabled( false );
00165 
00166     myCurrentLineEdit = myMeshGroupLine;
00167     setSelectionMode( grpGroupSelection );
00168   }
00169 }
00170 
00171 //=================================================================================
00172 // function : SMESHGUI_GroupDlg()
00173 // purpose  :
00174 //=================================================================================
00175 void SMESHGUI_GroupDlg::initDialog( bool create)
00176 {
00177   setModal( false );
00178   setAttribute( Qt::WA_DeleteOnClose, true );
00179 
00180   myFilterDlg = 0;
00181   myCreate = create;
00182   myCurrentLineEdit = 0;
00183 
00184   myShapeByMeshOp = 0;
00185   myGeomPopup = 0;
00186   myGeomObjects = new GEOM::ListOfGO();
00187   myGeomObjects->length( 0 );
00188 
00189   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
00190 
00191   setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
00192   myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
00193 
00194   setSizeGripEnabled( true);
00195 
00196   QGridLayout* aMainLayout = new QGridLayout( this );
00197   aMainLayout->setMargin( MARGIN );
00198   aMainLayout->setSpacing( SPACING );
00199 
00200   /***************************************************************/
00201   QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
00202   myMeshGroupBtn = new QPushButton( this );
00203   myMeshGroupBtn->setIcon( image0 );
00204   myMeshGroupLine = new QLineEdit( this );
00205   myMeshGroupLine->setReadOnly( true );
00206 
00207   /***************************************************************/
00208   QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
00209   myTypeGroup = new QButtonGroup( this );
00210   QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
00211   aTypeBoxLayout->setMargin( MARGIN );
00212   aTypeBoxLayout->setSpacing( SPACING );
00213 
00214   QStringList types;
00215   types.append( tr( "MESH_NODE" ) );
00216   types.append( tr( "SMESH_EDGE" ) );
00217   types.append( tr( "SMESH_FACE" ) );
00218   types.append( tr( "SMESH_VOLUME" ) );
00219   QRadioButton* rb;
00220   for ( int i = 0; i < types.count(); i++ )
00221   {
00222     rb = new QRadioButton( types[i], aTypeBox );
00223     myTypeGroup->addButton( rb, i );
00224     aTypeBoxLayout->addWidget( rb );
00225   }
00226   aTypeBox->setEnabled( create );
00227   myTypeId = -1;
00228 
00229   /***************************************************************/
00230   QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
00231   aName->setMinimumWidth( 50 );
00232   myName = new QLineEdit( this );
00233 
00234   /***************************************************************/
00235   QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
00236   myGrpTypeGroup = new QButtonGroup( this );
00237   QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
00238   aGrpTypeBoxLayout->setMargin( MARGIN );
00239   aGrpTypeBoxLayout->setSpacing( SPACING );
00240 
00241   QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
00242   QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ),   aGrpTypeBox );
00243   QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ),     aGrpTypeBox );
00244   myGrpTypeGroup->addButton( rb1, 0 );
00245   myGrpTypeGroup->addButton( rb2, 1 );
00246   myGrpTypeGroup->addButton( rb3, 2 );
00247   aGrpTypeBoxLayout->addWidget( rb1 );
00248   aGrpTypeBoxLayout->addWidget( rb2 );
00249   aGrpTypeBoxLayout->addWidget( rb3 );
00250   aGrpTypeBox->setEnabled( create );
00251   myGrpTypeId = -1;
00252 
00253   /***************************************************************/
00254   myWGStack = new QStackedWidget( this );
00255   QWidget* wg1 = new QWidget( myWGStack );
00256   QWidget* wg2 = new QWidget( myWGStack );
00257   QWidget* wg3 = new QWidget( myWGStack );
00258 
00259   /***************************************************************/
00260   QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
00261   QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
00262   aContentBoxLayout->setMargin( MARGIN );
00263   aContentBoxLayout->setSpacing( SPACING );
00264 
00265   mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
00266   myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
00267 
00268   myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
00269   myElements = new QListWidget( aContentBox );
00270   myElements->setSelectionMode( QListWidget::ExtendedSelection );
00271 
00272   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
00273   myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
00274   myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
00275   mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
00276 
00277   aContentBoxLayout->addWidget( mySelectAll,       0, 0 );
00278   aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
00279   aContentBoxLayout->addWidget( myFilterBtn,       1, 1 );
00280   aContentBoxLayout->addWidget( myElementsLab,     2, 0 );
00281   aContentBoxLayout->addWidget( myElements,        3, 0, 6, 1 );
00282   aContentBoxLayout->addWidget( myAddBtn,          3, 1 );
00283   aContentBoxLayout->addWidget( myRemoveBtn,       4, 1 );
00284   aContentBoxLayout->addWidget( mySortBtn,         8, 1 );
00285 
00286   aContentBoxLayout->setColumnStretch( 0, 1 );
00287   aContentBoxLayout->setRowStretch( 3, 1 );
00288   aContentBoxLayout->setRowStretch( 6, 1 );
00289 
00290   /***************************************************************/
00291   mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
00292   QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
00293   mySelectBoxLayout->setMargin( MARGIN );
00294   mySelectBoxLayout->setSpacing( SPACING );
00295 
00296   mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
00297   mySubMeshBtn = new QPushButton( mySelectBox );
00298   mySubMeshBtn->setIcon( image0 );
00299   mySubMeshLine = new QLineEdit( mySelectBox );
00300   mySubMeshLine->setReadOnly( true );
00301   onSelectSubMesh( false );
00302 
00303   mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
00304   myGroupBtn = new QPushButton( mySelectBox );
00305   myGroupBtn->setIcon( image0 );
00306   myGroupLine = new QLineEdit( mySelectBox );
00307   myGroupLine->setReadOnly( true );
00308   onSelectGroup( false );
00309 
00310   mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
00311   mySelectBoxLayout->addWidget( mySubMeshBtn,    0, 1 );
00312   mySelectBoxLayout->addWidget( mySubMeshLine,   0, 2 );
00313   mySelectBoxLayout->addWidget( mySelectGroup,   1, 0 );
00314   mySelectBoxLayout->addWidget( myGroupBtn,      1, 1 );
00315   mySelectBoxLayout->addWidget( myGroupLine,     1, 2 );
00316 
00317   /***************************************************************/
00318   QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
00319   wg1Layout->setMargin( 0 );
00320   wg1Layout->setSpacing( SPACING );
00321   wg1Layout->addWidget( aContentBox );
00322   wg1Layout->addWidget( mySelectBox );
00323   wg1Layout->setStretchFactor( aContentBox, 10 );
00324 
00325   /***************************************************************/
00326   QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
00327   myGeomGroupBtn = new QToolButton( wg2 );
00328   myGeomGroupBtn->setIcon( image0 );
00329   myGeomGroupBtn->setCheckable( true );
00330   myGeomGroupLine = new QLineEdit( wg2 );
00331   myGeomGroupLine->setReadOnly( true ); //VSR ???
00332   onSelectGeomGroup( false );
00333 
00334   myGeomGroupBtn->setEnabled( create );
00335   myGeomGroupLine->setEnabled( create );
00336 
00337   /***************************************************************/
00338   QGridLayout* wg2Layout = new QGridLayout( wg2 );
00339   wg2Layout->setMargin( 0 );
00340   wg2Layout->setSpacing( SPACING );
00341   wg2Layout->addWidget( geomObject,     0, 0 );
00342   wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
00343   wg2Layout->addWidget( myGeomGroupLine,0, 2 );
00344   wg2Layout->setRowStretch( 1, 5 );
00345 
00346   /***************************************************************/
00347   QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
00348   QGridLayout* wg3Layout = new QGridLayout( wg3 );
00349   wg3Layout->setMargin( 0 );
00350   wg3Layout->setSpacing( SPACING );
00351   wg3Layout->addWidget( aFilter2, 0, 0 );
00352   wg3Layout->setRowStretch( 1, 5 );
00353 
00354   /***************************************************************/
00355   myWGStack->insertWidget( 0, wg1 );
00356   myWGStack->insertWidget( 1, wg2 );
00357   myWGStack->insertWidget( 2, wg3 );
00358 
00359   /***************************************************************/
00360   QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
00361   QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
00362   aColorBoxLayout->setMargin(MARGIN);
00363   aColorBoxLayout->setSpacing(SPACING);
00364 
00365   QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
00366   myColorBtn = new QtxColorButton(aColorBox);
00367   myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, 
00368                              myColorBtn->sizePolicy().verticalPolicy() );
00369 
00370   aColorBoxLayout->addWidget(aColorLab);
00371   aColorBoxLayout->addWidget(myColorBtn);
00372 
00373   /***************************************************************/
00374 
00375   QFrame* aButtons = new QFrame(this);
00376   aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
00377   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
00378   aBtnLayout->setMargin(MARGIN);
00379   aBtnLayout->setSpacing(SPACING);
00380 
00381   myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
00382   myOKBtn->setAutoDefault(true);
00383   myOKBtn->setDefault(true);
00384   myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
00385   myApplyBtn->setAutoDefault(true);
00386   myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
00387   myCloseBtn->setAutoDefault(true);
00388   myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
00389   myHelpBtn->setAutoDefault(true);
00390 
00391   aBtnLayout->addWidget(myOKBtn);
00392   aBtnLayout->addSpacing(10);
00393   aBtnLayout->addWidget(myApplyBtn);
00394   aBtnLayout->addSpacing(10);
00395   aBtnLayout->addStretch();
00396   aBtnLayout->addWidget(myCloseBtn);
00397   aBtnLayout->addWidget(myHelpBtn);
00398 
00399   /***************************************************************/
00400   aMainLayout->addWidget(meshGroupLab,    0, 0);
00401   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
00402   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
00403   aMainLayout->addWidget(aTypeBox,        1, 0, 1, 3);
00404   aMainLayout->addWidget(aName,           2, 0);
00405   aMainLayout->addWidget(myName,          2, 2);
00406   aMainLayout->addWidget(aGrpTypeBox,     3, 0, 1, 3);
00407   aMainLayout->addWidget(myWGStack,       4, 0, 1, 3);
00408   aMainLayout->addWidget(aColorBox,       5, 0, 1, 3);
00409   aMainLayout->addWidget(aButtons,        6, 0, 1, 3);
00410 
00411   /* signals and slots connections */
00412   connect(myMeshGroupBtn,  SIGNAL(clicked()),          this, SLOT(setCurrentSelection()));
00413   connect(myGrpTypeGroup,  SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
00414   connect(myTypeGroup,     SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
00415 
00416   connect(myName,          SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
00417   connect(myElements,      SIGNAL(itemSelectionChanged()),      this, SLOT(onListSelectionChanged()));
00418 
00419   connect(myFilterBtn,        SIGNAL(clicked()),     this, SLOT(setFilters()));
00420   connect(aFilter2,        SIGNAL(clicked()),     this, SLOT(setFilters()));
00421   connect(mySelectAll,     SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
00422   connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
00423   connect(myAddBtn,        SIGNAL(clicked()),     this, SLOT(onAdd()));
00424   connect(myRemoveBtn,     SIGNAL(clicked()),     this, SLOT(onRemove()));
00425   connect(mySortBtn,       SIGNAL(clicked()),     this, SLOT(onSort()));
00426 
00427   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
00428   connect(mySelectGroup,   SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
00429   connect(mySubMeshBtn,    SIGNAL(clicked()),     this, SLOT(setCurrentSelection()));
00430   connect(myGroupBtn,      SIGNAL(clicked()),     this, SLOT(setCurrentSelection()));
00431   connect(myGeomGroupBtn,  SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
00432 
00433   connect(myColorBtn,      SIGNAL(changed( QColor )),  this, SLOT(onColorChanged( QColor )));
00434 
00435   connect(myOKBtn,         SIGNAL(clicked()), this, SLOT(onOK()));
00436   connect(myApplyBtn,      SIGNAL(clicked()), this, SLOT(onApply()));
00437   connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(onClose()));
00438   connect(myHelpBtn,       SIGNAL(clicked()), this, SLOT(onHelp()));
00439 
00440   /* Init selection */
00441   mySMESHGUI->SetActiveDialogBox(this);
00442   mySMESHGUI->SetState(800);
00443 
00444   mySelectionMode = grpNoSelection;
00445   myMeshFilter = new SMESH_TypeFilter(MESH);
00446   mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
00447                                             SMESH_LogicalFilter::LO_OR,
00448                                             /*takeOwnership=*/true);
00449   myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
00450                                           SMESH_LogicalFilter::LO_OR,
00451                                           /*takeOwnership=*/true);
00452   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
00453   myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
00454 
00455   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
00456   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(onClose()));
00457   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),  this, SLOT(onObjectSelectionChanged()));
00458   connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()),      this, SLOT(onVisibilityChanged()));
00459 
00460   rb1->setChecked(true); // VSR !!!
00461   onGrpTypeChanged(0); // VSR!!!
00462 
00463   if (myMesh->_is_nil() )
00464     myTypeGroup->button(0)->setChecked(true);
00465 
00466   onSelectAll(); //updateButtons();
00467 }
00468 
00469 //=================================================================================
00470 // function : ~SMESHGUI_GroupDlg()
00471 // purpose  : Destroys the object and frees any allocated resources
00472 //=================================================================================
00473 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
00474 {
00475   // no need to delete child widgets, Qt does it all for us
00476   if ( myFilterDlg != 0 ) {
00477     myFilterDlg->setParent( 0 );
00478     delete myFilterDlg;
00479   }
00480   if ( myMeshFilter )    delete myMeshFilter;
00481   if ( mySubMeshFilter ) delete mySubMeshFilter;
00482   if ( myGroupFilter )   delete myGroupFilter;
00483   if ( myGeomFilter )    delete myGeomFilter;
00484 }
00485 
00486 //=================================================================================
00487 // function : GetDefaultName()
00488 // purpose  : Get the Group Name if Create new Group
00489 //=================================================================================
00490 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
00491 {
00492   QString aName = "";
00493 
00494   // collect all object names of SMESH component
00495   SalomeApp_Study* appStudy =
00496     dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00497   if ( !appStudy ) return aName;
00498   _PTR(Study) aStudy = appStudy->studyDS();
00499 
00500   std::set<std::string> aSet;
00501   _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
00502   if (aMeshCompo) {
00503     _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
00504     _PTR(SObject) obj;
00505     for (it->InitEx(true); it->More(); it->Next()) {
00506       obj = it->Value();
00507       aSet.insert(obj->GetName());
00508     }
00509   }
00510 
00511   // build a unique name
00512   int aNumber = 0;
00513   bool isUnique = false;
00514   while (!isUnique) {
00515     aName = theOperation + "_" + QString::number(++aNumber);
00516     isUnique = (aSet.count(aName.toLatin1().data()) == 0);
00517   }
00518 
00519   return aName;
00520 }
00521 
00522 //=================================================================================
00523 // function : Init()
00524 // purpose  :
00525 //=================================================================================
00526 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
00527 {
00528   mySelectionMgr->installFilter(myMeshFilter);
00529 
00530   /* init data from current selection */
00531   restoreShowEntityMode();
00532   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
00533   setShowEntityMode();
00534   myGroup = SMESH::SMESH_Group::_nil();
00535   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
00536   myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
00537 
00538   // NPAL19389: create a group with a selection in another group
00539   // set actor of myMesh, if it is visible, else try
00540   // any visible actor of group or submesh of myMesh
00541   SetAppropriateActor();
00542 
00543   setDefaultGroupColor();
00544 
00545   SALOME_ListIO aList;
00546   mySelectionMgr->selectedObjects( aList );
00547   if( !aList.IsEmpty() )
00548   {
00549     QString aName = aList.First()->getName();
00550     myMeshGroupLine->setText(aName);
00551     myMeshGroupLine->home( false );
00552   }
00553 
00554   myCurrentLineEdit = 0;
00555 
00556   myTypeGroup->button(0)->setChecked(true);
00557   onTypeChanged(0);
00558 }
00559 
00560 //=================================================================================
00561 // function : Init()
00562 // purpose  :
00563 //=================================================================================
00564 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
00565                               const bool theIsConvert)
00566 {
00567   restoreShowEntityMode();
00568   myMesh = theGroup->GetMesh();
00569   setShowEntityMode();
00570 
00571   myNameChanged = true;
00572   myName->blockSignals(true);
00573   myName->setText(theGroup->GetName());
00574   myName->blockSignals(false);
00575   myName->home(false);
00576 
00577   SALOMEDS::Color aColor = theGroup->GetColor();
00578   setGroupColor( aColor );
00579 
00580   myMeshGroupLine->setText(theGroup->GetName());
00581 
00582   int aType = 0;
00583   switch(theGroup->GetType()) {
00584   case SMESH::NODE: aType= 0; break;
00585   case SMESH::EDGE: aType = 1; break;
00586   case SMESH::FACE: aType = 2; break;
00587   case SMESH::VOLUME: aType = 3; break;
00588   }
00589   myTypeGroup->button(aType)->setChecked(true);
00590 
00591   myGroup = SMESH::SMESH_Group::_narrow( theGroup );
00592   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
00593   myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
00594   myFilter = SMESH::Filter::_nil();
00595 
00596   if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
00597     return;
00598 
00599   // NPAL19389: create a group with a selection in another group
00600   // set actor of myMesh, if it is visible, else set
00601   // actor of theGroup, if it is visible, else try
00602   // any visible actor of group or submesh of myMesh
00603   // commented, because an attempt to set selection on not displayed cells leads to error
00604   SetAppropriateActor();
00605 
00606   /*  SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
00607   if ( !anActor )
00608     anActor = SMESH::FindActorByObject(theGroup);
00609   SMESH::SetPickable(anActor);*/
00610 
00611   int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
00612   myGrpTypeGroup->button(grpType)->setChecked(true);
00613   onGrpTypeChanged(grpType);
00614 
00615   myTypeId = aType;
00616   if ( grpType == 0 ) { // standalone group
00617     myCurrentLineEdit = 0;
00618     myElements->clear();
00619     myAllowElemsModif->setChecked( true );
00620 
00621     setSelectionMode(aType);
00622 
00623     setShowEntityMode(); // depends on myTypeId
00624 
00625     myIdList.clear();
00626     if (!theGroup->IsEmpty()) {
00627       SMESH::long_array_var anElements = theGroup->GetListOfID();
00628       int k = anElements->length();
00629       for (int i = 0; i < k; i++) {
00630         myIdList.append(anElements[i]);
00631         myElements->addItem(QString::number(anElements[i]));
00632       }
00633       myElements->selectAll();
00634     }
00635   }
00636   else if ( grpType == 1 ) // group on geom
00637   {
00638     QString aShapeName( "" );
00639     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00640     GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
00641     if (!aGroupShape->_is_nil())
00642     {
00643       _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
00644       if ( aGroupShapeSO )
00645         aShapeName = aGroupShapeSO->GetName().c_str();
00646     }
00647     myGeomGroupLine->setText( aShapeName );
00648   }
00649   else // group on filter
00650   {
00651     myFilter = myGroupOnFilter->GetFilter();
00652     if ( !myFilter->_is_nil() ) {
00653       SMESH::Predicate_var perdicate = myFilter->GetPredicate();
00654       if ( perdicate->_is_nil() )
00655         myFilter = SMESH::Filter::_nil();
00656     }
00657   }
00658 
00659   if ( grpType != 0 )
00660   {
00661     myNameChanged = true;
00662     myName->blockSignals(true);
00663     myName->setText(theGroup->GetName());
00664     myName->blockSignals(false);
00665   }
00666 
00667   onSelectAll(); //updateButtons();
00668 }
00669 
00670 //=================================================================================
00671 // function : updateButtons()
00672 // purpose  :
00673 //=================================================================================
00674 void SMESHGUI_GroupDlg::updateButtons()
00675 {
00676   bool enable = !myName->text().trimmed().isEmpty();
00677   if ( enable )
00678   {
00679     if (myGrpTypeId == 0) { // standalone
00680       if ( !mySelectAll->isChecked() )
00681       {
00682         if ( myAllowElemsModif->isChecked() )
00683         {
00684           enable = ( myElements->count() > 0 );
00685         }
00686         else if ((enable = !myFilter->_is_nil() ))
00687         {
00688           SMESH::array_of_ElementType_var types = myFilter->GetTypes();
00689           enable = types->length();
00690         }
00691       }
00692       enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
00693     }
00694     else if (myGrpTypeId == 1) // on geom
00695     {
00696       if (CORBA::is_nil(myGroupOnGeom)) // creation mode
00697         enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
00698     }
00699     else if (myGrpTypeId == 2) // on filter
00700     {
00701       if (( enable = !myFilter->_is_nil() ))
00702         if (CORBA::is_nil(myGroupOnFilter) )  // creation mode
00703           enable = !myMesh->_is_nil();
00704     }
00705   }
00706 
00707   myOKBtn->setEnabled(enable);
00708   myApplyBtn->setEnabled(enable);
00709 }
00710 
00711 //=================================================================================
00712 // function : onNameChanged()
00713 // purpose  :
00714 //=================================================================================
00715 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
00716 {
00717   myOldName = myName->text();
00718   updateButtons();
00719   myNameChanged = !myName->text().trimmed().isEmpty();
00720 }
00721 
00722 //=================================================================================
00723 // function : onTypeChanged()
00724 // purpose  : Group elements type radio button management
00725 //=================================================================================
00726 void SMESHGUI_GroupDlg::onTypeChanged (int id)
00727 {
00728   if (myTypeId != id) {
00729     myElements->clear();
00730     myTypeId = id;
00731     if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
00732       setSelectionMode(id);
00733     else
00734       setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
00735 
00736     onObjectSelectionChanged();
00737     setShowEntityMode();
00738   }
00739 }
00740 
00741 //=================================================================================
00742 // function : onGrpTypeChanged()
00743 // purpose  : Group type radio button management
00744 //=================================================================================
00745 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
00746 {
00747   if (myGrpTypeId != id) {
00748     myGrpTypeId = id;
00749     myWGStack->setCurrentIndex( id );
00750     myName->blockSignals(true);
00751     myName->setText(myOldName);
00752     myName->blockSignals(false);
00753     onSelectGeomGroup(id != 0);
00754   }
00755   updateButtons();
00756 }
00757 
00758 //=================================================================================
00759 // function : onColorChanged()
00760 // purpose  : Color button management
00761 //=================================================================================
00762 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
00763 {
00764   updateButtons();
00765 }
00766 
00767 //=================================================================================
00768 // function : setSelectionMode()
00769 // purpose  : Radio button management
00770 //=================================================================================
00771 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
00772 {
00773   // PAL7314
00774   if (myMesh->_is_nil())
00775     return;
00776   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
00777   bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
00778   if (mySelectionMode != theMode) {
00779     // [PAL10408] mySelectionMgr->clearSelected();
00780     mySelectionMgr->clearFilters();
00781     SMESH::RemoveFilters();
00782 
00783     if (myActorsList.count() > 0)
00784       for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
00785         it.next()->SetPointRepresentation(false);
00786     else
00787       SMESH::SetPointRepresentation(false);
00788 
00789     switch (theMode) {
00790     case grpNodeSelection:
00791       if ( myGrpTypeId == 0 ) // standalone
00792       {
00793         if (myActorsList.count() > 0)
00794           for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
00795             it.next()->SetPointRepresentation(true);
00796         else
00797           SMESH::SetPointRepresentation(true);
00798       }
00799       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
00800       break;
00801     case grpEdgeSelection:
00802       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
00803       break;
00804     case grpFaceSelection:
00805       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
00806       break;
00807     case grpVolumeSelection:
00808       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
00809       break;
00810     case grpSubMeshSelection: {
00811 
00812       SMESH_TypeFilter* f = 0;
00813       switch (myTypeId) {
00814       case 0: f = new SMESH_TypeFilter(SUBMESH); break;
00815       case 1: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
00816       case 2: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
00817       case 3: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
00818       default:f = new SMESH_TypeFilter(SUBMESH);
00819       }
00820       QList<SUIT_SelectionFilter*> filtList;
00821       filtList.append( f );
00822       filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
00823       mySubMeshFilter->setFilters( filtList );
00824 
00825       mySelectionMgr->installFilter( mySubMeshFilter );
00826 
00827       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
00828       break;
00829     }
00830     case grpGroupSelection: {
00831 
00832       SMESH_TypeFilter* f = 0;
00833       switch (myTypeId) {
00834       case 0: f = new SMESH_TypeFilter(GROUP_NODE); break;
00835       case 1: f = new SMESH_TypeFilter(GROUP_EDGE); break;
00836       case 2: f = new SMESH_TypeFilter(GROUP_FACE); break;
00837       case 3: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
00838       default:f = new SMESH_TypeFilter(GROUP);
00839       }
00840       QList<SUIT_SelectionFilter*> filtList;
00841       filtList.append( f );
00842       myGroupFilter->setFilters( filtList );
00843 
00844       mySelectionMgr->installFilter(myGroupFilter);
00845       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
00846       break;
00847     }
00848     case grpMeshSelection:
00849       mySelectionMgr->installFilter(myMeshFilter);
00850       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
00851       break;
00852     case grpGeomSelection:
00853       mySelectionMgr->installFilter(myGeomFilter);
00854       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
00855       break;
00856     default:
00857       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
00858       break;
00859     }
00860     if ( aViewWindow ) aViewWindow->Repaint();
00861     mySelectionMode = theMode;
00862   }
00863 }
00864 
00865 //=================================================================================
00866 // function : onApply()
00867 // purpose  :
00868 //=================================================================================
00869 bool SMESHGUI_GroupDlg::onApply()
00870 {
00871   if (mySMESHGUI->isActiveStudyLocked())
00872     return false;
00873 
00874   if (myName->text().trimmed().isEmpty())
00875     return false;
00876 
00877   SMESH::ElementType aType = SMESH::ALL;
00878   switch (myTypeId) {
00879   case 0: aType = SMESH::NODE; break;
00880   case 1: aType = SMESH::EDGE; break;
00881   case 2: aType = SMESH::FACE; break;
00882   case 3: aType = SMESH::VOLUME; break;
00883   }
00884 
00885   bool anIsOk = false;
00886   QStringList anEntryList;
00887 
00888   SMESH::SMESH_GroupBase_var resultGroup;
00889   bool isCreation;
00890     
00891   if (myGrpTypeId == 0)  // standalone
00892   {
00893     if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
00894       return false;
00895 
00896     mySelectionMgr->clearSelected();
00897 
00898     if (myGroup->_is_nil()) { // creation or conversion
00899       // check if group on geometry is not null
00900       if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
00901         if (myMesh->_is_nil())
00902           return false;
00903         if ( myGroupOnGeom->_is_nil() )
00904           myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
00905         else
00906           myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
00907 
00908         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
00909         myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
00910       }
00911     }
00912 
00913     if (myGroup->_is_nil()) { // creation
00914       if (myMesh->_is_nil())
00915         return false;
00916 
00917       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
00918 
00919       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
00920       isCreation = true;
00921 
00922       if ( mySelectAll->isChecked() ) {
00923         // select all
00924         myGroup->AddFrom(myMesh.in());
00925       }
00926       else {
00927         // select manually
00928 
00929         if ( !myFilter->_is_nil() &&
00930              ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
00931         {
00932           myGroup->AddFrom( myFilter );
00933         }
00934         else
00935         {
00936           SMESH::long_array_var anIdList = new SMESH::long_array;
00937           int i, k = myElements->count();
00938           anIdList->length(k);
00939           for (i = 0; i < k; i++) {
00940             anIdList[i] = myElements->item(i)->text().toInt();
00941           }
00942           myGroup->Add(anIdList.inout());
00943         }
00944       }
00945 
00946 
00947     } else { // edition
00948 
00949       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
00950       isCreation = false;
00951 
00952       if ( mySelectAll->isChecked() ) {
00953         // select all
00954         myGroup->Clear();
00955         myGroup->AddFrom(myMesh.in());
00956       }
00957       else {
00958         QList<int> aAddList;
00959         
00960         int i, total = myElements->count();
00961         for (i = 0; i < total; i++) {
00962           int anId = myElements->item(i)->text().toInt();
00963           int idx = myIdList.indexOf(anId);
00964           if ( idx == -1 )
00965             aAddList.append(anId);
00966           else
00967             myIdList.removeAt(idx);
00968         }
00969         if (!aAddList.empty()) {
00970           SMESH::long_array_var anIdList = new SMESH::long_array;
00971           int added = aAddList.count();
00972           anIdList->length(added);
00973           for (i = 0; i < added; i++)
00974             anIdList[i] = aAddList[i];
00975           myGroup->Add(anIdList.inout());
00976         }
00977         if (!myIdList.empty()) {
00978           SMESH::long_array_var anIdList = new SMESH::long_array;
00979           int removed = myIdList.count();
00980           anIdList->length(removed);
00981           for (i = 0; i < removed; i++)
00982             anIdList[i] = myIdList[i];
00983           myGroup->Remove(anIdList.inout());
00984         }
00985         /* init for next operation */
00986         myIdList.clear();
00987         for (i = 0; i < total; i++) {
00988           myIdList.append(myElements->item(i)->text().toInt());
00989         }
00990       }
00991     }
00992 
00993     anIsOk = true;
00994   }
00995   else if (myGrpTypeId == 1) // on geom object
00996   {
00997     if (CORBA::is_nil(myGroupOnGeom)) { // creation
00998       if (myMesh->_is_nil() || !myGeomObjects->length())
00999         return false;
01000 
01001       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
01002       GEOM::GEOM_IGroupOperations_var aGroupOp =
01003         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
01004 
01005       if (myGeomObjects->length() == 1) {
01006         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
01007                                                     myName->text().toLatin1().data(),
01008                                                     myGeomObjects[0]);
01009       }
01010       else {
01011         SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
01012         if ( aSMESHGen->_is_nil() )
01013           return false;
01014 
01015         // create a geometry group
01016         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
01017         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
01018 
01019         if (geomGen->_is_nil() || !aStudy)
01020           return false;
01021 
01022         GEOM::GEOM_IGroupOperations_var op =
01023           geomGen->GetIGroupOperations(aStudy->StudyId());
01024         if (op->_is_nil())
01025           return false;
01026 
01027         // check and add all selected GEOM objects: they must be
01028         // a sub-shapes of the main GEOM and must be of one type
01029         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
01030         for ( int i =0; i < myGeomObjects->length(); i++) {
01031           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
01032           if (i == 0)
01033             aGroupType = aSubShapeType;
01034           else if (aSubShapeType != aGroupType) {
01035             aGroupType = TopAbs_SHAPE;
01036             break;
01037           }
01038         }
01039 
01040         GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
01041         GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
01042         op->UnionList(aGroupVar, myGeomObjects);
01043 
01044         if (op->IsDone()) {
01045           // publish the GEOM group in study
01046           QString aNewGeomGroupName ( "Auto_group_for_" );
01047           aNewGeomGroupName += myName->text();
01048           SALOMEDS::SObject_var aNewGroupSO =
01049             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
01050                                 aNewGeomGroupName.toLatin1().data(), aMeshShape);
01051         }
01052 
01053         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
01054                                                     myName->text().toLatin1().data(),
01055                                                     aGroupVar);
01056       }
01057       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
01058       isCreation = true;
01059 
01060     }
01061     else { // edition
01062 
01063       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
01064       isCreation = false;
01065     }      
01066     anIsOk = true;
01067   }
01068   if (myGrpTypeId == 2) // group on filter
01069   {
01070     if ( myFilter->_is_nil() ) return false;
01071 
01072     if (CORBA::is_nil(myGroupOnFilter)) { // creation
01073       if (myMesh->_is_nil())
01074         return false;
01075 
01076       myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
01077                                                       myName->text().toLatin1().data(),
01078                                                       myFilter);
01079 
01080       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
01081       isCreation = true;
01082     }
01083     else
01084     {
01085       myGroupOnFilter->SetFilter( myFilter );
01086 
01087       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
01088       isCreation = false;
01089     }
01090     anIsOk = true;
01091   }
01092 
01093   if( anIsOk )
01094   {
01095     SALOMEDS::Color aColor = getGroupColor();
01096     resultGroup->SetColor(aColor);
01097 
01098     _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
01099     if( aMeshGroupSO )
01100       anEntryList.append( aMeshGroupSO->GetID().c_str() );
01101 
01102     if ( isCreation )
01103     {
01104       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
01105 
01106       /* init for the next operation */
01107       myName->setText( "" );
01108       myElements->clear();
01109       myGroup         = SMESH::SMESH_Group::_nil();
01110       myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
01111       myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
01112       myFilter        = SMESH::Filter::_nil();
01113     }
01114     else
01115     {
01116       resultGroup->SetName(myName->text().toLatin1().data());
01117 
01118       if ( aMeshGroupSO )
01119         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
01120           anActor->setName(myName->text().toLatin1().data());
01121           switch ( myTypeId ) {
01122           case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
01123           case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
01124           case 2:
01125           case 3: 
01126             {
01127               QColor c;
01128               int delta;
01129               SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
01130               anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;          
01131             }
01132           }
01133         }
01134     }
01135     SMESHGUI::Modified();
01136     mySMESHGUI->updateObjBrowser(true);
01137     SMESH::UpdateView(); // asv: fix of BUG PAL5515
01138     mySelectionMgr->clearSelected();
01139 
01140     if( LightApp_Application* anApp =
01141         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
01142       myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
01143   }
01144   return anIsOk;
01145 }
01146 
01147 //=================================================================================
01148 // function : onOK()
01149 // purpose  :
01150 //=================================================================================
01151 void SMESHGUI_GroupDlg::onOK()
01152 {
01153   setIsApplyAndClose( true );
01154   if ( onApply() )
01155     onClose();
01156   setIsApplyAndClose( false );
01157 }
01158 
01159 //=================================================================================
01160 // function : onListSelectionChanged()
01161 // purpose  : Called when selection in element list is changed
01162 //=================================================================================
01163 void SMESHGUI_GroupDlg::onListSelectionChanged()
01164 {
01165   //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
01166   if( myIsBusy || myActorsList.count() == 0 ) return;
01167   myIsBusy = true;
01168 
01169   if (myCurrentLineEdit == 0) {
01170     mySelectionMgr->clearSelected();
01171     TColStd_MapOfInteger aIndexes;
01172     QList<QListWidgetItem*> selItems = myElements->selectedItems();
01173     QListWidgetItem* anItem;
01174     foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
01175     mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
01176     SALOME_ListIO aList;
01177     aList.Append(myActorsList.first()->getIO());
01178     mySelectionMgr->setSelectedObjects(aList,false);
01179   }
01180   myIsBusy = false;
01181 }
01182 
01183 //=================================================================================
01184 // function : onObjectSelectionChanged()
01185 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
01186 //=================================================================================
01187 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
01188 {
01189   if ( myIsBusy || !isEnabled()) return;
01190   if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
01191 
01192   myIsBusy = true;
01193 
01194   SALOME_ListIO aList;
01195   mySelectionMgr->selectedObjects( aList );
01196 
01197   int aNbSel = aList.Extent();
01198   myElements->clearSelection();
01199 
01200   if (myCurrentLineEdit)
01201   {
01202     myCurrentLineEdit->setText( "" );
01203     QString aString = "";
01204 
01205     if (myCurrentLineEdit == myMeshGroupLine)
01206     {
01207       mySelectSubMesh->setEnabled(false);
01208       mySelectGroup->setEnabled(false);
01209       myGroupLine->setText( "" );
01210       mySubMeshLine->setText( "" );
01211 
01212       myGeomGroupBtn->setEnabled(false);
01213       myGeomGroupLine->setEnabled(false);
01214       myGeomGroupLine->setText( "" );
01215       myGeomObjects = new GEOM::ListOfGO();
01216       myGeomObjects->length(0);
01217 
01218       if (myGeomGroupBtn->isChecked())
01219         myGeomGroupBtn->setChecked(false);
01220       if (!myCreate)
01221         myName->setText( "" );
01222 
01223       myElements->clear();
01224 
01225       if (aNbSel != 1 ) {
01226         myGroup = SMESH::SMESH_Group::_nil();
01227         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
01228         restoreShowEntityMode();
01229         myMesh = SMESH::SMESH_Mesh::_nil();
01230         updateGeomPopup();
01231         updateButtons();
01232         myIsBusy = false;
01233         return;
01234       }
01235       Handle(SALOME_InteractiveObject) IO = aList.First();
01236 
01237       if (myCreate) {
01238         restoreShowEntityMode();
01239         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
01240         setShowEntityMode();
01241         updateGeomPopup();
01242         if (myMesh->_is_nil())
01243         {
01244           updateButtons();
01245           myIsBusy = false;
01246           return;
01247         }
01248 
01249         if ( myFilterDlg && !myMesh->_is_nil()){
01250           myFilterDlg->SetMesh( myMesh );
01251         }
01252         myGroup = SMESH::SMESH_Group::_nil();
01253 
01254         // NPAL19389: create a group with a selection in another group
01255         // set actor of myMesh, if it is visible, else try
01256         // any visible actor of group or submesh of myMesh
01257         SetAppropriateActor();
01258 
01259         aString = aList.First()->getName();
01260         myMeshGroupLine->setText(aString);
01261         myMeshGroupLine->home( false );
01262 
01263         mySelectSubMesh->setEnabled(true);
01264         mySelectGroup->setEnabled(true);
01265         myGeomGroupBtn->setEnabled(true);
01266         myGeomGroupLine->setEnabled(true);
01267         updateButtons();
01268       }
01269       else {
01270         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
01271         if (aGroup->_is_nil())
01272         {
01273           myIsBusy = false;
01274           return;
01275         }
01276         myIsBusy = false;
01277 
01278         myGroup = SMESH::SMESH_Group::_nil();
01279         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
01280 
01281         init(aGroup);
01282         myIsBusy = true;
01283         mySelectSubMesh->setEnabled(true);
01284         mySelectGroup->setEnabled(true);
01285       }
01286       myCurrentLineEdit = 0;
01287       myIsBusy = false;
01288       if (!myCreate)
01289         return;
01290 
01291       if (myGrpTypeId == 0)
01292       {
01293         if (myTypeId == -1)
01294           onTypeChanged(0);
01295         else
01296         {
01297           myElements->clear();
01298           setSelectionMode(myTypeId);
01299         }
01300       }
01301 
01302       myIsBusy = false;
01303       return;
01304 
01305     }
01306     else if (myCurrentLineEdit == myGeomGroupLine)
01307     {
01308       myGeomObjects = new GEOM::ListOfGO();
01309 
01310       // The mesh SObject
01311       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
01312 
01313       if (aNbSel == 0 || !aMeshSO)
01314       {
01315         myGeomObjects->length(0);
01316         updateButtons();
01317         myIsBusy = false;
01318         return;
01319       }
01320 
01321       myGeomObjects->length(aNbSel);
01322 
01323       GEOM::GEOM_Object_var aGeomGroup;
01324       int i = 0;
01325 
01326       SALOME_ListIteratorOfListIO anIt (aList);
01327       for (; anIt.More(); anIt.Next())
01328       {
01329         aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
01330 
01331         // Check if the object is a geometry group
01332         if (CORBA::is_nil(aGeomGroup))
01333           continue;
01334 
01335         // Check if group constructed on the same shape as a mesh or on its child
01336         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
01337         GEOM::GEOM_IGroupOperations_var anOp =
01338           SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
01339 
01340         // The main shape of the group
01341         GEOM::GEOM_Object_var aGroupMainShape;
01342         if (aGeomGroup->GetType() == 37)
01343           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
01344         else
01345           aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
01346         _PTR(SObject) aGroupMainShapeSO =
01347           //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
01348           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
01349 
01350         _PTR(SObject) anObj, aRef;
01351         bool isRefOrSubShape = false;
01352         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
01353           //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
01354           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
01355             isRefOrSubShape = true;
01356           } else {
01357             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
01358             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
01359             //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
01360             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
01361               //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
01362               if (aRef->GetID() == aFather->GetID())
01363                 isRefOrSubShape = true;
01364               else
01365                 aFather = aFather->GetFather();
01366             }
01367           }
01368         }
01369         if (isRefOrSubShape)
01370           myGeomObjects[i++] = aGeomGroup;
01371       }
01372 
01373       myGeomObjects->length(i);
01374       if ( i == 0 )
01375         {
01376           myIsBusy = false;
01377           return;
01378         }
01379 
01380       aNbSel = i;
01381     }
01382 
01383     if (aNbSel >= 1) {
01384       if (aNbSel > 1) {
01385         if (myCurrentLineEdit == mySubMeshLine)
01386           aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
01387         else if (myCurrentLineEdit == myGroupLine)
01388           aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
01389         else if (myCurrentLineEdit == myGeomGroupLine)
01390           aString = tr( "%1 Objects" ).arg(aNbSel);
01391       }
01392       else {
01393         aString = aList.First()->getName();
01394       }
01395     }
01396 
01397     myCurrentLineEdit->setText(aString);
01398     myCurrentLineEdit->home(false);
01399     // 07.06.2008 skl for IPAL19574:
01400     // change name of group only if it is empty
01401     if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
01402       myOldName = myName->text();
01403       myName->blockSignals(true);
01404       myName->setText(aString);
01405       myName->blockSignals(false);
01406     }
01407 
01408     updateButtons();
01409   }
01410   else // !myCurrentLineEdit: local selection of nodes or elements
01411   {
01412     if (aNbSel == 1 && myActorsList.count() > 0 )
01413     {
01414       // NPAL19389: create a group with a selection in another group
01415       // Switch myActor to the newly selected one, if the last
01416       // is visible and belongs to group or submesh of myMesh
01417       /*      Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
01418       Handle(SALOME_InteractiveObject) selIO = aList.First();
01419       if (curIO->hasEntry() && selIO->hasEntry()) {
01420         const char* selEntry = selIO->getEntry();
01421         if (strcmp(curIO->getEntry(), selEntry) != 0) {
01422           // different objects: selected and myActor
01423           SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
01424           if (aViewWindow && aViewWindow->isVisible(selIO)) {
01425             // newly selected actor is visible
01426 
01427             // mesh entry
01428             _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
01429             if (aSObject) {
01430               CORBA::String_var meshEntry = aSObject->GetID().c_str();
01431               int len = strlen(meshEntry);
01432 
01433               if (strncmp(selEntry, meshEntry, len) == 0) {
01434                 // selected object is myMesh or a part of it
01435                 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
01436                 if (anActor) {
01437                   myActor = anActor;
01438                   SMESH::SetPickable(myActor);
01439                 }
01440               }
01441             }
01442           }
01443         }
01444       }*/
01445       // NPAL19389 END
01446 
01447       QString aListStr = "";
01448       int aNbItems = 0;
01449       if (myTypeId == 0) {
01450         QListIterator<SMESH_Actor*> it( myActorsList );
01451         while ( it.hasNext() ) {
01452           QString tmpStr;
01453           aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
01454           aListStr += tmpStr;
01455         }
01456       } else {
01457         QListIterator<SMESH_Actor*> it( myActorsList );
01458         while ( it.hasNext() ) {
01459           QString tmpStr;
01460           aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
01461           aListStr += tmpStr;
01462         }
01463       }
01464       if (aNbItems > 0) {
01465         QListWidgetItem* anItem;
01466         QList<QListWidgetItem*> listItemsToSel;
01467         QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
01468         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
01469           QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
01470           foreach(anItem, found)
01471             if (!anItem->isSelected())
01472               listItemsToSel.push_back(anItem);
01473         }
01474         bool blocked = myElements->signalsBlocked();
01475         myElements->blockSignals(true);
01476         foreach(anItem, listItemsToSel) anItem->setSelected(true);
01477         myElements->blockSignals(blocked);
01478         onListSelectionChanged();
01479         listItemsToSel.clear();
01480       }
01481     }
01482   }
01483   
01484   if (myActorsList.count() == 0) {
01485     if (!myGroup->_is_nil()) {
01486       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
01487       if ( anActor )
01488         myActorsList.append( anActor  );
01489     }
01490     else if(!myGroupOnGeom->_is_nil()) {
01491       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
01492       if ( anActor )
01493         myActorsList.append( anActor );
01494     }
01495     else {
01496       SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
01497       if ( anActor )
01498         myActorsList.append( anActor );
01499     }
01500   }
01501 
01502   // somehow, if we display the mesh, while selecting from another actor,
01503   // the mesh becomes pickable, and there is no way to select any element
01504   if (myActorsList.count() > 0) {
01505     QListIterator<SMESH_Actor*> it( myActorsList );
01506     while ( it.hasNext() ) {
01507       SMESH_Actor* anActor = it.next();
01508       if ( IsActorVisible(anActor) )
01509         anActor->SetPickable(true);
01510     }
01511   }
01512 
01513   myIsBusy = false;
01514 }
01515 
01516 //=================================================================================
01517 // function : onSelectAll()
01518 // purpose  : Called when "Select all" is checked
01519 //=================================================================================
01520 void SMESHGUI_GroupDlg::onSelectAll()
01521 {
01522   bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
01523 
01524   myElementsLab->setEnabled( !noElemsModif );
01525   myElements->setEnabled   ( !noElemsModif );
01526   myFilterBtn->setEnabled  ( !mySelectAll->isChecked() );
01527   myAddBtn->setEnabled     ( !noElemsModif );
01528   myRemoveBtn->setEnabled  ( !noElemsModif );
01529   mySortBtn->setEnabled    ( !noElemsModif );
01530   mySelectBox->setEnabled  ( !noElemsModif );
01531   myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
01532 
01533   int selMode     = mySelectionMode;
01534   mySelectionMode = grpNoSelection;
01535   setSelectionMode( selMode );
01536   updateButtons();
01537 }
01538 
01539 //=================================================================================
01540 // function : onSelectSubMesh()
01541 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
01542 //=================================================================================
01543 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
01544 {
01545   if (on) {
01546     if (mySelectGroup->isChecked()) {
01547       mySelectGroup->setChecked(false);
01548     }
01549     //VSR: else if (mySelectGeomGroup->isChecked()) {
01550     //VSR:   mySelectGeomGroup->setChecked(false);
01551     //VSR: }
01552     myCurrentLineEdit = mySubMeshLine;
01553     setSelectionMode(grpSubMeshSelection);
01554   }
01555   else {
01556     mySubMeshLine->setText( "" );
01557     myCurrentLineEdit = 0;
01558     if (myTypeId != -1)
01559       setSelectionMode(myTypeId);
01560   }
01561   mySubMeshBtn->setEnabled(on);
01562   mySubMeshLine->setEnabled(on);
01563 }
01564 
01565 
01566 //=================================================================================
01567 // function : (onSelectGroup)
01568 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
01569 //=================================================================================
01570 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
01571 {
01572   if (on) {
01573     if (mySelectSubMesh->isChecked()) {
01574       mySelectSubMesh->setChecked(false);
01575     }
01576     myCurrentLineEdit = myGroupLine;
01577     setSelectionMode(grpGroupSelection);
01578   }
01579   else {
01580     myGroupLine->setText( "" );
01581     myCurrentLineEdit = 0;
01582     if (myTypeId != -1)
01583       setSelectionMode(myTypeId);
01584   }
01585   myGroupBtn->setEnabled(on);
01586   myGroupLine->setEnabled(on);
01587 }
01588 
01589 
01590 //=================================================================================
01591 // function : (onSelectGeomGroup)
01592 // purpose  : Called when group type changed. on == "on group" or "on filter"
01593 //=================================================================================
01594 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
01595 {
01596   if (on) {
01597     if (mySelectSubMesh->isChecked()) {
01598       mySelectSubMesh->setChecked(false);
01599     }
01600     else if (mySelectGroup->isChecked()) {
01601       mySelectGroup->setChecked(false);
01602     }
01603     if ( myGrpTypeId == 1 ) { // on group
01604       myCurrentLineEdit = myGeomGroupLine;
01605       updateGeomPopup();
01606     }
01607     else { // on filter
01608       myCurrentLineEdit = 0;
01609     }
01610     setSelectionMode(grpAllSelection);
01611   }
01612   else {
01613     myGeomGroupBtn->setChecked(false);
01614     myGeomObjects->length(0);
01615     myGeomGroupLine->setText( "" );
01616     myCurrentLineEdit = 0;
01617     if (myTypeId != -1)
01618       setSelectionMode( myTypeId );
01619   }
01620 }
01621 
01622 //=================================================================================
01623 // function : setCurrentSelection()
01624 // purpose  :
01625 //=================================================================================
01626 void SMESHGUI_GroupDlg::setCurrentSelection()
01627 {
01628   QPushButton* send = (QPushButton*)sender();
01629   myCurrentLineEdit = 0;
01630   if (send == myMeshGroupBtn) {
01631     disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
01632     mySelectionMgr->clearSelected();
01633     if (myCreate)
01634       setSelectionMode(grpMeshSelection);
01635     else
01636       setSelectionMode(grpGroupSelection);
01637     connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
01638     myCurrentLineEdit = myMeshGroupLine;
01639     onObjectSelectionChanged();
01640   }
01641   else if (send == mySubMeshBtn) {
01642     myCurrentLineEdit = mySubMeshLine;
01643     onObjectSelectionChanged();
01644   }
01645   else if (send == myGroupBtn) {
01646     myCurrentLineEdit = myGroupLine;
01647     onObjectSelectionChanged();
01648   }
01649 }
01650 
01651 
01652 //=================================================================================
01653 // function : setFilters()
01654 // purpose  : SLOT. Called when "Filter" button pressed.
01655 //=================================================================================
01656 void SMESHGUI_GroupDlg::setFilters()
01657 {
01658   if(myMesh->_is_nil()) {
01659     SUIT_MessageBox::critical(this,
01660                               tr("SMESH_ERROR"),
01661                               tr("NO_MESH_SELECTED"));
01662    return;
01663   }
01664 
01665   SMESH::ElementType aType = SMESH::ALL;
01666   switch ( myTypeId )
01667   {
01668     case 0 : aType = SMESH::NODE; break;
01669     case 1 : aType = SMESH::EDGE; break;
01670     case 2 : aType = SMESH::FACE; break;
01671     case 3 : aType = SMESH::VOLUME; break;
01672     default: return;
01673   }
01674 
01675   if ( myFilterDlg == 0 )
01676   {
01677     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
01678     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
01679   }
01680   else
01681     myFilterDlg->Init( aType );
01682 
01683   if ( !myGroupOnFilter->_is_nil() )
01684   {
01685     myFilterDlg->SetFilter( myFilter, aType );
01686     myFilterDlg->Init( aType );
01687   }
01688 
01689   myFilterDlg->SetSelection();
01690   myFilterDlg->SetMesh( myMesh );
01691   myFilterDlg->SetSourceWg( myElements, false );
01692 
01693   myFilterDlg->show();
01694 }
01695 
01696 //=================================================================================
01697 // function : onFilterAccepted()
01698 // purpose  : SLOT. Called when Filter dlg closed with OK button.
01699 //            Uncheck "Select submesh" and "Select group" checkboxes
01700 //=================================================================================
01701 void SMESHGUI_GroupDlg::onFilterAccepted()
01702 {
01703   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
01704   {
01705     mySelectionMode = myTypeId;
01706     mySelectSubMesh->setChecked( false );
01707     mySelectGroup->setChecked( false );
01708   }
01709   // get a filter from myFilterDlg
01710   myFilter = myFilterDlg->GetFilter();
01711   if ( !myFilter->_is_nil() ) {
01712     SMESH::Predicate_var perdicate = myFilter->GetPredicate();
01713     if ( perdicate->_is_nil() )
01714       myFilter = SMESH::Filter::_nil();
01715   }
01716   // set mesh to myFilter
01717   if ( !myFilter->_is_nil() ) {
01718     SMESH::SMESH_Mesh_var mesh = myMesh;
01719     if ( mesh->_is_nil() ) {
01720       if ( !myGroup->_is_nil() )
01721         mesh = myGroup->GetMesh();
01722       else if ( !myGroupOnGeom->_is_nil() )
01723         mesh = myGroupOnGeom->GetMesh();
01724       else if ( !myGroupOnFilter->_is_nil() )
01725         mesh = myGroupOnFilter->GetMesh();
01726     }
01727     myFilter->SetMesh( mesh );
01728   }
01729 
01730   updateButtons();
01731 }
01732 
01733 //=================================================================================
01734 // function : onAdd()
01735 // purpose  :
01736 //=================================================================================
01737 void SMESHGUI_GroupDlg::onAdd()
01738 {
01739   SALOME_ListIO aList;
01740   mySelectionMgr->selectedObjects( aList );
01741 
01742   int aNbSel = aList.Extent();
01743 
01744   if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
01745 
01746   myIsBusy = true;
01747   int sizeBefore = myElements->count();
01748 
01749   SMESH::ElementType aType = SMESH::ALL;
01750   switch(myTypeId) {
01751   case 0:
01752     aType = SMESH::NODE;
01753     mySelector->SetSelectionMode(NodeSelection);
01754     break;
01755   case 1:
01756     aType = SMESH::EDGE;
01757     mySelector->SetSelectionMode(EdgeSelection);
01758     break;
01759   case 2:
01760     aType = SMESH::FACE;
01761     mySelector->SetSelectionMode(FaceSelection);
01762     break;
01763   case 3:
01764     aType = SMESH::VOLUME;
01765     mySelector->SetSelectionMode(VolumeSelection);
01766     break;
01767   default:
01768     mySelector->SetSelectionMode(ActorSelection);
01769   }
01770 
01771   QListWidgetItem* anItem = 0;
01772   QList<QListWidgetItem*> listItemsToSel;
01773 
01774   if (myCurrentLineEdit == 0) {
01775     //if (aNbSel != 1) { myIsBusy = false; return; }
01776     QString aListStr = "";
01777     int aNbItems = 0;
01778     if (myTypeId == 0) {
01779       QListIterator<SMESH_Actor*> it( myActorsList );
01780       while ( it.hasNext() ) {
01781         QString tmpStr;
01782         aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
01783         aListStr += tmpStr;
01784       }
01785     }
01786     else {
01787       QListIterator<SMESH_Actor*> it( myActorsList );
01788       while ( it.hasNext() ) {
01789         QString tmpStr;
01790         aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
01791         aListStr += tmpStr;
01792       }
01793     }
01794     if (aNbItems > 0) {
01795       QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
01796       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
01797         QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
01798         if (found.count() == 0) {
01799           anItem = new QListWidgetItem(*it);
01800           myElements->addItem(anItem);
01801           if (!anItem->isSelected())
01802             listItemsToSel.push_back(anItem);
01803         }
01804         else {
01805           foreach(anItem, found)
01806             if (!anItem->isSelected())
01807               listItemsToSel.push_back(anItem);
01808         }
01809       }
01810       bool blocked = myElements->signalsBlocked();
01811       myElements->blockSignals(true);
01812       foreach(anItem, listItemsToSel) anItem->setSelected(true);
01813       myElements->blockSignals(blocked);
01814       onListSelectionChanged();
01815       listItemsToSel.clear();
01816     }
01817   } else if (myCurrentLineEdit == mySubMeshLine) {
01818     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
01819 
01820     SALOME_ListIO aList;
01821     mySelectionMgr->selectedObjects( aList );
01822 
01823     SALOME_ListIteratorOfListIO anIt (aList);
01824     for ( ; anIt.More(); anIt.Next()) {
01825       SMESH::SMESH_subMesh_var aSubMesh =
01826         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
01827       if (!aSubMesh->_is_nil()) {
01828         // check if mesh is the same
01829         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
01830           try {
01831             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
01832             int k = anElements->length();
01833             for (int i = 0; i < k; i++) {
01834               QString aText = QString::number(anElements[i]);
01835               QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
01836               if (found.count() == 0) {
01837                 anItem = new QListWidgetItem(aText);
01838                 myElements->addItem(anItem);
01839                 if (!anItem->isSelected())
01840                   listItemsToSel.push_back(anItem);
01841               }
01842               else {
01843                 foreach(anItem, found)
01844                   if (!anItem->isSelected())
01845                     listItemsToSel.push_back(anItem);
01846               }
01847             }
01848             bool blocked = myElements->signalsBlocked();
01849             myElements->blockSignals(true);
01850             foreach(anItem, listItemsToSel) anItem->setSelected(true);
01851             myElements->blockSignals(blocked);
01852             onListSelectionChanged();
01853             listItemsToSel.clear();
01854           }
01855           catch (const SALOME::SALOME_Exception& ex) {
01856             SalomeApp_Tools::QtCatchCorbaException(ex);
01857           }
01858         }
01859       }
01860     }
01861     mySelectSubMesh->setChecked(false);
01862     myIsBusy = false;
01863     onListSelectionChanged();
01864 
01865   } else if (myCurrentLineEdit == myGroupLine) {
01866     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
01867     SALOME_ListIO aList;
01868     mySelectionMgr->selectedObjects( aList );
01869 
01870     SALOME_ListIteratorOfListIO anIt (aList);
01871     for ( ; anIt.More(); anIt.Next()) {
01872       SMESH::SMESH_GroupBase_var aGroup =
01873         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
01874       if (!aGroup->_is_nil()) {
01875         // check if mesh is the same
01876         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
01877           SMESH::long_array_var anElements = aGroup->GetListOfID();
01878           int k = anElements->length();
01879           for (int i = 0; i < k; i++) {
01880             QString aText = QString::number(anElements[i]);
01881             QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
01882             if (found.count() == 0) {
01883               anItem = new QListWidgetItem(aText);
01884               myElements->addItem(anItem);
01885               if (!anItem->isSelected())
01886                 listItemsToSel.push_back(anItem);
01887             }
01888             else {
01889               foreach(anItem, found)
01890                 if (!anItem->isSelected())
01891                   listItemsToSel.push_back(anItem);
01892             }
01893           }
01894           bool blocked = myElements->signalsBlocked();
01895           myElements->blockSignals(true);
01896           foreach(anItem, listItemsToSel) anItem->setSelected(true);
01897           myElements->blockSignals(blocked);
01898           onListSelectionChanged();
01899           listItemsToSel.clear();
01900         }
01901       }
01902     }
01903     mySelectGroup->setChecked(false);
01904     myIsBusy = false;
01905     onListSelectionChanged();
01906 
01907   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
01908     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
01909     GEOM::GEOM_IGroupOperations_var aGroupOp =
01910       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
01911 
01912     SMESH::ElementType aGroupType = SMESH::ALL;
01913     switch(aGroupOp->GetType(myGeomObjects[0])) {
01914     case 7: aGroupType = SMESH::NODE; break;
01915     case 6: aGroupType = SMESH::EDGE; break;
01916     case 4: aGroupType = SMESH::FACE; break;
01917     case 2: aGroupType = SMESH::VOLUME; break;
01918     default: myIsBusy = false; return;
01919     }
01920 
01921     if (aGroupType == aType) {
01922       _PTR(SObject) aGroupSO =
01923         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
01924         aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
01925       // Construct filter
01926       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
01927       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
01928       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
01929       aBelongToGeom->SetGeom(myGeomObjects[0]);
01930       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
01931       aBelongToGeom->SetElementType(aType);
01932       aFilter->SetPredicate(aBelongToGeom);
01933 
01934       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
01935 
01936       int k = anElements->length();
01937       for (int i = 0; i < k; i++) {
01938         QString aText = QString::number(anElements[i]);
01939         QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
01940         if (found.count() == 0) {
01941           anItem = new QListWidgetItem(aText);
01942           myElements->addItem(anItem);
01943           if (!anItem->isSelected())
01944             listItemsToSel.push_back(anItem);
01945         }
01946         else {
01947           foreach(anItem, found)
01948             if (!anItem->isSelected())
01949               listItemsToSel.push_back(anItem);
01950         }
01951       }
01952       bool blocked = myElements->signalsBlocked();
01953       myElements->blockSignals(true);
01954       foreach(anItem, listItemsToSel) anItem->setSelected(true);
01955       myElements->blockSignals(blocked);
01956       onListSelectionChanged();
01957       listItemsToSel.clear();
01958     }
01959 
01960     //VSR: mySelectGeomGroup->setChecked(false);
01961     myIsBusy = false;
01962     onListSelectionChanged();
01963   }
01964   myIsBusy = false;
01965   if ( sizeBefore < myElements->count() )
01966     ++myNbChangesOfContents;
01967   //  mySelectionMgr->clearSelected();
01968   updateButtons();
01969 }
01970 
01971 //=================================================================================
01972 // function : onRemove()
01973 // purpose  :
01974 //=================================================================================
01975 void SMESHGUI_GroupDlg::onRemove()
01976 {
01977   myIsBusy = true;
01978   int sizeBefore = myElements->count();
01979 
01980   if (myCurrentLineEdit == 0) {
01981     QList<QListWidgetItem*> selItems = myElements->selectedItems();
01982     QListWidgetItem* item;
01983     foreach(item, selItems) delete item;
01984   } else {
01985     SALOME_ListIO aList;
01986     mySelectionMgr->selectedObjects( aList );
01987 
01988     int aNbSel = aList.Extent();
01989 
01990     if (aNbSel == 0) { myIsBusy = false; return; }
01991 
01992     SMESH::ElementType aType = SMESH::ALL;
01993     switch(myTypeId) {
01994     case 0: aType = SMESH::NODE; break;
01995     case 1: aType = SMESH::EDGE; break;
01996     case 2: aType = SMESH::FACE; break;
01997     case 3: aType = SMESH::VOLUME; break;
01998     }
01999 
02000     if (myCurrentLineEdit == mySubMeshLine) {
02001       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
02002       SALOME_ListIO aList;
02003       mySelectionMgr->selectedObjects( aList );
02004 
02005       SALOME_ListIteratorOfListIO anIt (aList);
02006       for ( ; anIt.More(); anIt.Next()) {
02007         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
02008         if (!aSubMesh->_is_nil()) {
02009           // check if mesh is the same
02010           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
02011             if (aType == SMESH::NODE) {
02012               try {
02013                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
02014                 int k = anElements->length();
02015                 for (int i = 0; i < k; i++) {
02016                   QList<QListWidgetItem*> found = 
02017                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
02018                   QListWidgetItem* anItem;
02019                   foreach(anItem, found) delete anItem;
02020                 }
02021               }
02022               catch (const SALOME::SALOME_Exception& ex) {
02023                 SalomeApp_Tools::QtCatchCorbaException(ex);
02024               }
02025             }
02026             else {
02027               try {
02028                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
02029                 int k = anElements->length();
02030                 for (int i = 0; i < k; i++) {
02031                   QList<QListWidgetItem*> found = 
02032                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
02033                   QListWidgetItem* anItem;
02034                   foreach(anItem, found) delete anItem;
02035                 }
02036               }
02037               catch (const SALOME::SALOME_Exception& ex) {
02038                 SalomeApp_Tools::QtCatchCorbaException(ex);
02039               }
02040             }
02041           }
02042         }
02043       }
02044     }
02045     else if (myCurrentLineEdit == myGroupLine) {
02046       Standard_Boolean aRes;
02047       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
02048       SALOME_ListIO aList;
02049       mySelectionMgr->selectedObjects( aList );
02050 
02051       SALOME_ListIteratorOfListIO anIt (aList);
02052       for ( ; anIt.More(); anIt.Next()) {
02053         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
02054         if (aRes && !aGroup->_is_nil()) {
02055           // check if mesh is the same
02056           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
02057             SMESH::long_array_var anElements = aGroup->GetListOfID();
02058             int k = anElements->length();
02059             for (int i = 0; i < k; i++) {
02060               QList<QListWidgetItem*> found = 
02061                 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
02062               QListWidgetItem* anItem;
02063               foreach(anItem, found) delete anItem;
02064             }
02065           }
02066         }
02067       }
02068     }
02069   }
02070   myIsBusy = false;
02071   if ( sizeBefore > myElements->count() )
02072     myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
02073   updateButtons();
02074 }
02075 
02076 //=================================================================================
02077 // function : onSort()
02078 // purpose  :
02079 //=================================================================================
02080 void SMESHGUI_GroupDlg::onSort()
02081 {
02082   // PAL5412: sorts items in ascending by "string" value
02083   // myElements->sort(true);
02084   // myElements->update();
02085   int i, k = myElements->count();
02086   if (k > 0) {
02087     myIsBusy = true;
02088     QList<int> aSelected;
02089     std::vector<int> anArray(k);
02090     //    QMemArray<int> anArray(k);
02091     // fill the array
02092     for (i = 0; i < k; i++) {
02093       int id = myElements->item(i)->text().toInt();
02094       anArray[i] = id;
02095       if (myElements->item(i)->isSelected())
02096         aSelected.append(id);
02097     }
02098     // sort & update list
02099     std::sort(anArray.begin(), anArray.end());
02100     //    anArray.sort();
02101     myElements->clear();
02102     QListWidgetItem* anItem;
02103     QList<QListWidgetItem*> listItemsToSel;
02104     for (i = 0; i < k; i++) {
02105       anItem = new QListWidgetItem(QString::number(anArray[i]));
02106       myElements->addItem(anItem);
02107       if (aSelected.contains(anArray[i]))
02108         listItemsToSel.push_back(anItem);
02109     }
02110     bool blocked = myElements->signalsBlocked();
02111     myElements->blockSignals(true);
02112     foreach(anItem, listItemsToSel) anItem->setSelected(true);
02113     myElements->blockSignals(blocked);
02114     listItemsToSel.clear();
02115     myIsBusy = false;
02116   }
02117 }
02118 
02119 //=================================================================================
02120 // function : closeEvent()
02121 // purpose  :
02122 //=================================================================================
02123 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
02124 {
02125   onClose();
02126 }
02127 
02128 //=================================================================================
02129 // function : onVisibilityChanged()
02130 // purpose  :
02131 //=================================================================================
02132 void SMESHGUI_GroupDlg::onVisibilityChanged()
02133 {
02134   SetAppropriateActor();
02135 }
02136 
02137 //=================================================================================
02138 // function : SMESHGUI_GroupDlg::onClose
02139 // purpose  : SLOT called when "Close" button pressed. Close dialog
02140 //=================================================================================
02141 void SMESHGUI_GroupDlg::onClose()
02142 {
02143   if (SMESH::GetCurrentVtkView()) {
02144     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
02145     SMESH::SetPointRepresentation(false);
02146     SMESH::SetPickable();
02147     restoreShowEntityMode();
02148   }
02149 
02150   if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
02151     SUIT_DataOwnerPtrList aList;
02152     aList.append( new LightApp_DataOwner( myObjectToSelect ) );
02153     mySelectionMgr->setSelected( aList );
02154   }
02155   else
02156     mySelectionMgr->clearSelected();
02157   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02158     aViewWindow->SetSelectionMode(ActorSelection);
02159   mySelectionMgr->clearFilters();
02160   mySMESHGUI->ResetState();
02161 
02162   reject();
02163 }
02164 
02165 //=================================================================================
02166 // function : onHelp()
02167 // purpose  :
02168 //=================================================================================
02169 void SMESHGUI_GroupDlg::onHelp()
02170 {
02171   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
02172   if (app)
02173     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
02174   else {
02175     QString platform;
02176 #ifdef WIN32
02177     platform = "winapplication";
02178 #else
02179     platform = "application";
02180 #endif
02181     SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
02182                              tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
02183                              arg(app->resourceMgr()->stringValue( "ExternalBrowser",
02184                                                                  platform)).
02185                              arg(myHelpFileName));
02186   }
02187 }
02188 
02189 //=================================================================================
02190 // function : SMESHGUI_GroupDlg::onDeactivate
02191 // purpose  : SLOT called when dialog must be deativated
02192 //=================================================================================
02193 void SMESHGUI_GroupDlg::onDeactivate()
02194 {
02195   mySMESHGUI->ResetState();
02196   setEnabled(false);
02197 }
02198 
02199 //=================================================================================
02200 // function : SMESHGUI_GroupDlg::enterEvent
02201 // purpose  : Event filter
02202 //=================================================================================
02203 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
02204 {
02205   if (!isEnabled()) {
02206     mySMESHGUI->EmitSignalDeactivateDialog();
02207     setEnabled(true);
02208     mySelectionMode = grpNoSelection;
02209     setSelectionMode(myTypeId);
02210     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
02211     mySMESHGUI->SetActiveDialogBox(this);
02212     mySMESHGUI->SetState(800);
02213   }
02214 }
02215 
02216 //=================================================================================
02217 // function : hideEvent
02218 // purpose  : caused by ESC key
02219 //=================================================================================
02220 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
02221 {
02222   if (!isMinimized() && !myIsBusy)
02223     onClose();
02224 }
02225 
02226 //=================================================================================
02227 // function : keyPressEvent()
02228 // purpose  :
02229 //=================================================================================
02230 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
02231 {
02232   QDialog::keyPressEvent( e );
02233   if ( e->isAccepted() )
02234     return;
02235 
02236   if ( e->key() == Qt::Key_F1 )
02237     {
02238       e->accept();
02239       onHelp();
02240     }
02241 }
02242 
02243 //================================================================================
02248 //================================================================================
02249 
02250 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
02251 
02252 void SMESHGUI_GroupDlg::updateGeomPopup()
02253 {
02254   bool enable = false;
02255 
02256   if ( !myMesh->_is_nil() )
02257     enable = myMesh->NbEdges() > 0;
02258 
02259   if ( myGeomGroupBtn )
02260   {
02261     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
02262     if ( enable ) {
02263       if ( !myGeomPopup ) {
02264         myGeomPopup = new QMenu(this);
02265         myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
02266         myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
02267         connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
02268       }
02269       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
02270     }
02271   }
02272 }
02273 
02274 
02275 //=================================================================================
02276 // function : onGeomSelectionButton()
02277 // purpose  :
02278 //=================================================================================
02279 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
02280 {
02281   if ( myGeomPopup && isBtnOn )
02282     {
02283       myCurrentLineEdit = myGeomGroupLine;
02284       QAction* a = myGeomPopup->exec( QCursor::pos() );
02285       if (!a || myActions[a] == DIRECT_GEOM_INDEX)
02286         setSelectionMode(grpGeomSelection);
02287     }
02288   else if (!isBtnOn)
02289     {
02290       myCurrentLineEdit = 0;
02291       setSelectionMode(grpAllSelection);
02292     }
02293 }
02294 
02295 //=================================================================================
02296 // function : onGeomPopup()
02297 // purpose  :
02298 //=================================================================================
02299 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
02300 {
02301   int index = myActions[a];
02302   if ( index == GEOM_BY_MESH_INDEX )
02303     {
02304       mySelectionMode = grpNoSelection;
02305       if ( !myShapeByMeshOp ) {
02306         myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
02307         connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
02308                 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
02309         connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
02310                 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
02311       }
02312       // set mesh object to SMESHGUI_ShapeByMeshOp and start it
02313       if ( !myMesh->_is_nil() ) {
02314         myIsBusy = true;
02315         hide(); // stop processing selection
02316         myIsBusy = false;
02317         myShapeByMeshOp->setModule( mySMESHGUI );
02318         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
02319         myShapeByMeshOp->SetMesh( myMesh );
02320         myShapeByMeshOp->start();
02321       }
02322     }
02323 }
02324 
02325 //================================================================================
02329 //================================================================================
02330 
02331 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
02332 {
02333   if ( myShapeByMeshOp == op ) {
02334     mySMESHGUI->getApp()->updateObjectBrowser();
02335     show();
02336     // Select a found geometry object
02337     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
02338     if ( !aGeomVar->_is_nil() )
02339     {
02340       QString ID = aGeomVar->GetStudyEntry();
02341       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
02342       if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
02343         SALOME_ListIO anIOList;
02344         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
02345           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
02346         anIOList.Append( anIO );
02347         mySelectionMgr->setSelectedObjects( anIOList, false );
02348         onObjectSelectionChanged();
02349       }
02350     }
02351   }
02352 }
02353 
02354 //================================================================================
02358 //================================================================================
02359 
02360 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
02361 {
02362   if ( myShapeByMeshOp == op )
02363     {
02364       show();
02365       setSelectionMode(grpGeomSelection);
02366     }
02367 }
02368 
02369 //=================================================================================
02370 // function : setGroupColor()
02371 // purpose  :
02372 //=================================================================================
02373 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
02374 {
02375   QColor aQColor( (int)( theColor.R * 255.0 ),
02376                   (int)( theColor.G * 255.0 ),
02377                   (int)( theColor.B * 255.0 ) );
02378   setGroupQColor( aQColor );
02379 }
02380 
02381 //=================================================================================
02382 // function : getGroupColor()
02383 // purpose  :
02384 //=================================================================================
02385 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
02386 {
02387   QColor aQColor = getGroupQColor();
02388 
02389   SALOMEDS::Color aColor;
02390   aColor.R = (float)aQColor.red() / 255.0;
02391   aColor.G = (float)aQColor.green() / 255.0;
02392   aColor.B = (float)aQColor.blue() / 255.0;
02393 
02394   return aColor;
02395 }
02396 
02397 //=================================================================================
02398 // function : setGroupQColor()
02399 // purpose  :
02400 //=================================================================================
02401 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
02402 {
02403   if( theColor.isValid() )
02404     myColorBtn->setColor( theColor );
02405 }
02406 
02407 //=================================================================================
02408 // function : getGroupQColor()
02409 // purpose  :
02410 //=================================================================================
02411 QColor SMESHGUI_GroupDlg::getGroupQColor() const
02412 {
02413   return myColorBtn->color();
02414 }
02415 
02416 //=================================================================================
02417 // function : setDefaultGroupColor()
02418 // purpose  :
02419 //=================================================================================
02420 void SMESHGUI_GroupDlg::setDefaultGroupColor()
02421 {
02422   if( myMesh->_is_nil() )
02423     return;
02424 
02425   bool isAutoColor = myMesh->GetAutoColor();
02426 
02427   QColor aQColor;
02428   if( !isAutoColor )
02429   {
02430     int r = 0, g = 0, b = 0;
02431     SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
02432     aQColor.setRgb( r, g, b );
02433   }
02434   else
02435   {
02436     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
02437 
02438     QList<SALOMEDS::Color> aReservedColors;
02439     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
02440     {
02441       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
02442       SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
02443       aReservedColors.append( aReservedColor );
02444     }
02445 
02446     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
02447     aQColor.setRgb( (int)( aColor.R * 255.0 ),
02448                     (int)( aColor.G * 255.0 ),
02449                     (int)( aColor.B * 255.0 ) );
02450 
02451   }
02452 
02453   setGroupQColor( aQColor );
02454 }
02455 
02456 //=================================================================================
02457 // function : SetAppropriateActor()
02458 // purpose  : Find more appropriate of visible actors, set it to myActor, allow picking
02459 //            NPAL19389: create a group with a selection in another group.
02460 //            if mesh actor is not visible - find any first visible group or submesh
02461 //=================================================================================
02462 bool SMESHGUI_GroupDlg::SetAppropriateActor()
02463 {
02464   bool isActor = false;
02465   myActorsList.clear();
02466 
02467   if (myMesh->_is_nil()) return false;
02468 
02469   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
02470 
02471   if (myGeomGroupBtn->isChecked()) {   // try current group on geometry actor
02472     if (!isActor) {
02473       if (!myGroupOnGeom->_is_nil()) {
02474         SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
02475         if (anActor && anActor->hasIO())
02476           {
02477             isActor = true;
02478             if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
02479               isActor = false;
02480             else
02481               myActorsList.append(anActor);
02482           }
02483       }
02484     }
02485   } else {
02486     // try mesh actor
02487     SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
02488     if (anActor && anActor->hasIO()) {
02489       isActor = true;
02490       if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
02491         isActor = false;
02492       else
02493         myActorsList.append(anActor);
02494     }
02495     
02496     // try group actor
02497     if (!isActor && !myGroup->_is_nil()) {
02498       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
02499       if (anActor && anActor->hasIO())
02500         myActorsList.append(anActor);
02501     }
02502     
02503     // try any visible actor of group or submesh of current mesh
02504     if (aViewWindow) {
02505       // mesh entry
02506       _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
02507       if (aSObject) {
02508         CORBA::String_var meshEntry = aSObject->GetID().c_str();
02509         int len = strlen(meshEntry);
02510         
02511         // iterate on all actors in current view window, search for
02512         // any visible actor, that belongs to group or submesh of current mesh
02513         VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
02514         vtkActorCollection *aCollection = aCopy.GetActors();
02515         int nbItems = aCollection->GetNumberOfItems();
02516         for (int i=0; i<nbItems && !isActor; i++)
02517           {
02518             SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
02519             if (anActor && anActor->hasIO()) {
02520               Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
02521               if (aViewWindow->isVisible(anIO)) {
02522                 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
02523                   myActorsList.append(anActor);
02524               }
02525             }
02526           }
02527       }
02528     }
02529   }
02530   
02531   if (myActorsList.count() > 0) {
02532     QListIterator<SMESH_Actor*> it( myActorsList );
02533     while ( it.hasNext() ) {
02534       SMESH_Actor* anActor = it.next();
02535       if ( IsActorVisible(anActor) )
02536         anActor->SetPickable(true);
02537     }
02538   }
02539   
02540   return ( isActor || (myActorsList.count() > 0) );
02541 }
02542   
02543 //=======================================================================
02544 //function : setShowEntityMode
02545 //purpose  : make shown only entity corresponding to my type
02546 //=======================================================================
02547 void SMESHGUI_GroupDlg::setShowEntityMode()
02548 {
02549   if ( !myMesh->_is_nil() ) {
02550     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
02551       if (!myStoredShownEntity)
02552         myStoredShownEntity = actor->GetEntityMode();
02553       switch ( myTypeId ) {
02554       case 0: restoreShowEntityMode(); break;
02555       case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
02556       case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
02557       case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
02558       }
02559     }
02560   }
02561 }
02562 
02563 //=======================================================================
02564 //function : restoreShowEntityMode
02565 //purpose  : restore ShowEntity mode of myActor
02566 //=======================================================================
02567 void SMESHGUI_GroupDlg::restoreShowEntityMode()
02568 {
02569   if ( myStoredShownEntity && !myMesh->_is_nil() ) {
02570     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
02571       actor->SetEntityMode(myStoredShownEntity);
02572     }
02573   }
02574   myStoredShownEntity = 0;
02575 }
02576 
02577 //=======================================================================
02578 //function : IsActorVisible
02579 //purpose  : return visibility of the actor
02580 //=======================================================================
02581 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
02582 {
02583   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
02584   if (theActor && aViewWindow)
02585     return aViewWindow->isVisible(theActor->getIO());
02586   return false;
02587 }
02588 
02589 //================================================================
02590 //function : setIsApplyAndClose
02591 //purpose  : Set value of the flag indicating that the dialog is
02592 //           accepted by Apply & Close button
02593 //================================================================
02594 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
02595 {
02596   myIsApplyAndClose = theFlag;
02597 }
02598 
02599 //================================================================
02600 //function : isApplyAndClose
02601 //purpose  : Get value of the flag indicating that the dialog is
02602 //           accepted by Apply & Close button
02603 //================================================================
02604 bool SMESHGUI_GroupDlg::isApplyAndClose() const
02605 {
02606   return myIsApplyAndClose;
02607 }