Version: 6.3.1

src/SMESHGUI/SMESHGUI_GroupDlg.cxx

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