Back to index

salome-smesh  6.5.0
SMESHGUI_MergeDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_MergeDlg.cxx
00025 // Author : Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_MergeDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_SpinBox.h"
00035 
00036 #include <SMESH_Actor.h>
00037 #include <SMESH_TypeFilter.hxx>
00038 #include <SMESH_LogicalFilter.hxx>
00039 #include <SMDS_Mesh.hxx>
00040 
00041 // SALOME GUI includes
00042 #include <SUIT_Desktop.h>
00043 #include <SUIT_ResourceMgr.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_MessageBox.h>
00046 #include <SUIT_OverrideCursor.h>
00047 
00048 #include <LightApp_Application.h>
00049 #include <LightApp_SelectionMgr.h>
00050 
00051 #include <SVTK_ViewModel.h>
00052 #include <SVTK_ViewWindow.h>
00053 #include <SALOME_ListIO.hxx>
00054 
00055 // OCCT includes
00056 #include <TColStd_MapOfInteger.hxx>
00057 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00058 
00059 // IDL includes
00060 #include <SALOMEconfig.h>
00061 #include CORBA_SERVER_HEADER(SMESH_Group)
00062 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00063 
00064 // VTK includes
00065 #include <vtkUnstructuredGrid.h>
00066 #include <vtkRenderer.h>
00067 #include <vtkActor2D.h>
00068 #include <vtkPoints.h>
00069 #include <vtkDataSetMapper.h>
00070 #include <vtkMaskPoints.h>
00071 #include <vtkSelectVisiblePoints.h>
00072 #include <vtkLabeledDataMapper.h>
00073 #include <vtkTextProperty.h>
00074 #include <vtkIntArray.h>
00075 #include <vtkProperty2D.h>
00076 #include <vtkPointData.h>
00077 #include <vtkConfigure.h>
00078 #if !defined(VTK_XVERSION)
00079 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
00080 #endif
00081 
00082 // Qt includes
00083 #include <QApplication>
00084 #include <QGroupBox>
00085 #include <QLabel>
00086 #include <QLineEdit>
00087 #include <QListWidget>
00088 #include <QPushButton>
00089 #include <QRadioButton>
00090 #include <QCheckBox>
00091 #include <QHBoxLayout>
00092 #include <QVBoxLayout>
00093 #include <QGridLayout>
00094 #include <QKeyEvent>
00095 #include <QButtonGroup>
00096 
00097 #define SPACING 6
00098 #define MARGIN  11
00099 
00100 namespace SMESH
00101 {
00102   class TIdPreview
00103   { // to display in the viewer IDs of the selected elements
00104     SVTK_ViewWindow* myViewWindow;
00105 
00106     vtkUnstructuredGrid* myIdGrid;
00107     SALOME_Actor* myIdActor;
00108 
00109     vtkUnstructuredGrid* myPointsNumDataSet;
00110     vtkMaskPoints* myPtsMaskPoints;
00111     vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
00112     vtkLabeledDataMapper* myPtsLabeledDataMapper;
00113     vtkTextProperty* aPtsTextProp;
00114     bool myIsPointsLabeled;
00115     vtkActor2D* myPointLabels;
00116 
00117     std::vector<int> myIDs;
00118 
00119   public:
00120     TIdPreview(SVTK_ViewWindow* theViewWindow):
00121       myViewWindow(theViewWindow)
00122     {
00123       myIdGrid = vtkUnstructuredGrid::New();
00124 
00125       // Create and display actor
00126       vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00127       aMapper->SetInput( myIdGrid );
00128 
00129       myIdActor = SALOME_Actor::New();
00130       myIdActor->SetInfinitive(true);
00131       myIdActor->VisibilityOff();
00132       myIdActor->PickableOff();
00133 
00134       myIdActor->SetMapper( aMapper );
00135       aMapper->Delete();
00136 
00137       myViewWindow->AddActor(myIdActor);
00138 
00139       //Definition of points numbering pipeline
00140       myPointsNumDataSet = vtkUnstructuredGrid::New();
00141 
00142       myPtsMaskPoints = vtkMaskPoints::New();
00143       myPtsMaskPoints->SetInput(myPointsNumDataSet);
00144       myPtsMaskPoints->SetOnRatio(1);
00145 
00146       myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
00147       myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
00148       myPtsSelectVisiblePoints->SelectInvisibleOff();
00149       myPtsSelectVisiblePoints->SetTolerance(0.1);
00150     
00151       myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
00152       myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
00153 #if (VTK_XVERSION < 0x050200)
00154       myPtsLabeledDataMapper->SetLabelFormat("%g");
00155 #endif
00156       myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
00157     
00158       vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
00159       aPtsTextProp->SetFontFamilyToTimes();
00160       static int aPointsFontSize = 12;
00161       aPtsTextProp->SetFontSize(aPointsFontSize);
00162       aPtsTextProp->SetBold(1);
00163       aPtsTextProp->SetItalic(0);
00164       aPtsTextProp->SetShadow(0);
00165       myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
00166       aPtsTextProp->Delete();
00167   
00168       myIsPointsLabeled = false;
00169 
00170       myPointLabels = vtkActor2D::New();
00171       myPointLabels->SetMapper(myPtsLabeledDataMapper);
00172       myPointLabels->GetProperty()->SetColor(1,1,1);
00173       myPointLabels->SetVisibility(myIsPointsLabeled);
00174 
00175       AddToRender(myViewWindow->getRenderer());
00176     }
00177 
00178     void SetPointsData ( SMDS_Mesh* theMesh, 
00179                          TColStd_MapOfInteger & theNodesIdMap )
00180     {
00181       vtkPoints* aPoints = vtkPoints::New();
00182       aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
00183       myIDs.clear();
00184       
00185       TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
00186       for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
00187         const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
00188         aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
00189         myIDs.push_back(idIter.Key());
00190       }
00191 
00192       myIdGrid->SetPoints(aPoints);
00193 
00194       aPoints->Delete();
00195 
00196       myIdActor->GetMapper()->Update();
00197     }
00198 
00199     void SetElemsData( TColStd_MapOfInteger & theElemsIdMap, 
00200                        std::list<gp_XYZ> & aGrCentersXYZ )
00201     {
00202       vtkPoints* aPoints = vtkPoints::New();
00203       aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
00204       myIDs.clear();
00205       
00206       TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
00207       for( ; idIter.More(); idIter.Next() ) {
00208         myIDs.push_back(idIter.Key());
00209       }
00210 
00211       gp_XYZ aXYZ;
00212       std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
00213       for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
00214         aXYZ = *coordIt;
00215         aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
00216       }
00217       myIdGrid->SetPoints(aPoints);
00218       aPoints->Delete();
00219       
00220       myIdActor->GetMapper()->Update();
00221     }
00222 
00223     void AddToRender(vtkRenderer* theRenderer)
00224     {
00225       myIdActor->AddToRender(theRenderer);
00226 
00227       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
00228       theRenderer->AddActor2D(myPointLabels);
00229     }
00230 
00231     void RemoveFromRender(vtkRenderer* theRenderer)
00232     {
00233       myIdActor->RemoveFromRender(theRenderer);
00234 
00235       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
00236       theRenderer->RemoveActor(myPointLabels);
00237     }
00238 
00239     void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
00240     {
00241       myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
00242       
00243       if ( myIsPointsLabeled ) {
00244         myPointsNumDataSet->ShallowCopy(myIdGrid);
00245         vtkDataSet *aDataSet = myPointsNumDataSet;
00246         int aNbElem = myIDs.size();
00247         vtkIntArray *anArray = vtkIntArray::New();
00248         anArray->SetNumberOfValues( aNbElem );
00249         for ( int i = 0; i < aNbElem; i++ )
00250           anArray->SetValue( i, myIDs[i] );
00251         aDataSet->GetPointData()->SetScalars( anArray );
00252         anArray->Delete();
00253         myPtsMaskPoints->SetInput( aDataSet );
00254         myPointLabels->SetVisibility( theIsActorVisible );
00255       }
00256       else {
00257         myPointLabels->SetVisibility( false );
00258       }
00259     }
00260     
00261     ~TIdPreview()
00262     {
00263       RemoveFromRender(myViewWindow->getRenderer());
00264 
00265       myIdGrid->Delete();
00266 
00267       myViewWindow->RemoveActor(myIdActor);
00268       myIdActor->Delete();
00269 
00270       //Deleting of points numbering pipeline
00271       //---------------------------------------
00272       myPointsNumDataSet->Delete();
00273       
00274       //myPtsLabeledDataMapper->RemoveAllInputs();        //vtk 5.0 porting
00275       myPtsLabeledDataMapper->Delete();
00276 
00277       //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
00278       myPtsSelectVisiblePoints->Delete();
00279 
00280       //myPtsMaskPoints->UnRegisterAllOutputs();          //vtk 5.0 porting
00281       myPtsMaskPoints->Delete();
00282 
00283       myPointLabels->Delete();
00284 
00285 //       myTimeStamp->Delete();
00286     }
00287   };
00288 }
00289 
00290 static const char * IconFirst[] = {
00291 "18 10 2 1",
00292 "       g None",
00293 ".      g #000000",
00294 "         .     .  ",
00295 "  ..    ..    ..  ",
00296 "  ..   ...   ...  ",
00297 "  ..  ....  ....  ",
00298 "  .. ..... .....  ",
00299 "  .. ..... .....  ",
00300 "  ..  ....  ....  ",
00301 "  ..   ...   ...  ",
00302 "  ..    ..    ..  ",
00303 "         .     .  "};
00304 
00305 //=================================================================================
00306 // class    : SMESHGUI_MergeDlg()
00307 // purpose  :
00308 //=================================================================================
00309 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
00310   : QDialog(SMESH::GetDesktop(theModule)),
00311     mySMESHGUI(theModule),
00312     mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00313     myAction(theAction)
00314 {
00315   setModal(false);
00316   setAttribute(Qt::WA_DeleteOnClose, true);
00317   setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
00318 
00319   myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
00320 
00321   SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
00322   QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
00323   QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
00324   QPixmap IconSelect     (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
00325   QPixmap IconAdd        (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
00326   QPixmap IconRemove     (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
00327 
00328   setSizeGripEnabled(true);
00329 
00330   QVBoxLayout* DlgLayout = new QVBoxLayout(this);
00331   DlgLayout->setSpacing(SPACING);
00332   DlgLayout->setMargin(MARGIN);
00333 
00334   /***************************************************************/
00335   GroupConstructors = new QGroupBox(myAction == 1 ? 
00336                                     tr("SMESH_MERGE_ELEMENTS") : 
00337                                     tr("SMESH_MERGE_NODES"), 
00338                                     this);
00339 
00340   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00341   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00342   GroupConstructorsLayout->setSpacing(SPACING);
00343   GroupConstructorsLayout->setMargin(MARGIN);
00344 
00345   RadioButton = new QRadioButton(GroupConstructors);
00346   RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
00347   RadioButton->setChecked(true);
00348   GroupConstructorsLayout->addWidget(RadioButton);
00349   ButtonGroup->addButton(RadioButton, 0);
00350 
00351   /***************************************************************/
00352   // Controls for mesh defining
00353   GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
00354   QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
00355   GroupMeshLayout->setSpacing(SPACING);
00356   GroupMeshLayout->setMargin(MARGIN);
00357 
00358   TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
00359   SelectMeshButton = new QPushButton(GroupMesh);
00360   SelectMeshButton->setIcon(IconSelect);
00361   LineEditMesh = new QLineEdit(GroupMesh);
00362   LineEditMesh->setReadOnly(true);
00363 
00364   GroupMeshLayout->addWidget(TextLabelName);
00365   GroupMeshLayout->addWidget(SelectMeshButton);
00366   GroupMeshLayout->addWidget(LineEditMesh);
00367 
00368   /***************************************************************/
00369   // Controls for switch dialog behaviour
00370 
00371   TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
00372   GroupType = new QButtonGroup( this );
00373   QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
00374   aTypeBoxLayout->setMargin( MARGIN );
00375   aTypeBoxLayout->setSpacing( SPACING );
00376 
00377   QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
00378   QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ),   TypeBox );
00379   GroupType->addButton( rb1, 0 );
00380   GroupType->addButton( rb2, 1 );
00381   aTypeBoxLayout->addWidget( rb1 );
00382   aTypeBoxLayout->addWidget( rb2 );
00383 
00384   myTypeId = 0;
00385 
00386   /***************************************************************/
00387   // Controls for coincident elements detecting
00388   GroupCoincident = new QGroupBox(myAction == 1 ? 
00389                                   tr("COINCIDENT_ELEMENTS") : 
00390                                   tr("COINCIDENT_NODES"), 
00391                                   this);
00392 
00393   QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
00394   aCoincidentLayout->setSpacing(SPACING);
00395   aCoincidentLayout->setMargin(MARGIN);
00396 
00397   if (myAction == 0) { // case merge nodes
00398     QWidget* foo = new QWidget(GroupCoincident);
00399     TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
00400     SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
00401     SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
00402 
00403     GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
00404     GroupExclude->setCheckable( true );
00405     GroupExclude->setChecked( false );
00406     ListExclude = new QListWidget( GroupExclude );
00407     QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
00408     GroupExcludeLayout->setSpacing(SPACING);
00409     GroupExcludeLayout->setMargin(MARGIN);
00410     GroupExcludeLayout->addWidget(ListExclude);
00411 
00412     QGridLayout* fooLayout = new QGridLayout( foo );
00413     fooLayout->setSpacing(SPACING);
00414     fooLayout->setMargin(0);
00415     fooLayout->addWidget(TextLabelTolerance, 0, 0 );
00416     fooLayout->addWidget(SpinBoxTolerance,   0, 1 );
00417     fooLayout->addWidget(GroupExclude,       1, 0, 1, 2 );
00418     aCoincidentLayout->addWidget(foo);
00419   }
00420   else {
00421     TextLabelTolerance = 0;
00422     SpinBoxTolerance = 0;
00423     GroupExclude = 0;
00424     ListExclude = 0;
00425   }
00426 
00427   GroupCoincidentWidget = new QWidget(GroupCoincident);
00428   QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
00429   GroupCoincidentLayout->setSpacing(SPACING);
00430   GroupCoincidentLayout->setMargin(0);
00431 
00432   ListCoincident = new QListWidget(GroupCoincidentWidget);
00433   ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
00434 
00435   DetectButton      = new QPushButton(tr("DETECT"),           GroupCoincidentWidget);
00436   AddGroupButton    = new QPushButton(tr("SMESH_BUT_ADD"),    GroupCoincidentWidget);
00437   RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
00438 
00439   SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
00440 
00441   GroupCoincidentLayout->addWidget(ListCoincident,    0,   0, 4, 2);
00442   GroupCoincidentLayout->addWidget(DetectButton,      0,   2);
00443   GroupCoincidentLayout->addWidget(AddGroupButton,    2, 2);
00444   GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
00445   GroupCoincidentLayout->addWidget(SelectAllCB,       4, 0, 1, 3);
00446   GroupCoincidentLayout->setRowMinimumHeight(1, 10);
00447   GroupCoincidentLayout->setRowStretch(1, 5);
00448 
00449   aCoincidentLayout->addWidget(GroupCoincidentWidget);
00450 
00451   /***************************************************************/
00452   // Controls for editing the selected group
00453   GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
00454   QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
00455   GroupEditLayout->setSpacing(SPACING);
00456   GroupEditLayout->setMargin(MARGIN);
00457 
00458   ListEdit = new QListWidget(GroupEdit);
00459   //ListEdit->setRowMode(QListBox::FixedNumber);
00460   //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
00461   //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
00462   ListEdit->setFlow( QListView::LeftToRight );
00463   ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
00464 
00465   AddElemButton = new QPushButton(GroupEdit);
00466   AddElemButton->setIcon(IconAdd);
00467   RemoveElemButton = new QPushButton(GroupEdit);
00468   RemoveElemButton->setIcon(IconRemove);
00469   SetFirstButton = new QPushButton(GroupEdit);
00470   SetFirstButton->setIcon(QPixmap(IconFirst));
00471 
00472   GroupEditLayout->addWidget(ListEdit,         0, 0, 2, 1);
00473   GroupEditLayout->addWidget(AddElemButton,    0, 1);
00474   GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
00475   GroupEditLayout->addWidget(SetFirstButton,   1, 1, 1, 2);
00476 
00477   /***************************************************************/
00478   GroupButtons = new QGroupBox(this);
00479   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00480   GroupButtonsLayout->setSpacing(SPACING);
00481   GroupButtonsLayout->setMargin(MARGIN);
00482 
00483   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00484   buttonOk->setAutoDefault(true);
00485   buttonOk->setDefault(true);
00486   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00487   buttonApply->setAutoDefault(true);
00488   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00489   buttonCancel->setAutoDefault(true);
00490   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00491   buttonHelp->setAutoDefault(true);
00492 
00493   GroupButtonsLayout->addWidget(buttonOk);
00494   GroupButtonsLayout->addSpacing(10);
00495   GroupButtonsLayout->addWidget(buttonApply);
00496   GroupButtonsLayout->addSpacing(10);
00497   GroupButtonsLayout->addStretch();
00498   GroupButtonsLayout->addWidget(buttonCancel);
00499   GroupButtonsLayout->addWidget(buttonHelp);
00500 
00501   /***************************************************************/
00502   DlgLayout->addWidget(GroupConstructors);
00503   DlgLayout->addWidget(GroupMesh);
00504   DlgLayout->addWidget(TypeBox);
00505   DlgLayout->addWidget(GroupCoincident);
00506   DlgLayout->addWidget(GroupEdit);
00507   DlgLayout->addWidget(GroupButtons);
00508 
00509   GroupCoincidentWidget->setVisible( myAction != 0 );
00510   GroupCoincident->setVisible( myAction == 0 );
00511   //if GroupExclude->setVisible( myAction == 0 );
00512   GroupEdit->hide();
00513 
00514   this->resize(10,10);
00515 
00516   Init(); // Initialisations
00517 }
00518 
00519 //=================================================================================
00520 // function : ~SMESHGUI_MergeDlg()
00521 // purpose  : Destroys the object and frees any allocated resources
00522 //=================================================================================
00523 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
00524 {
00525   delete myIdPreview;
00526 }
00527 
00528 //=================================================================================
00529 // function : Init()
00530 // purpose  :
00531 //=================================================================================
00532 void SMESHGUI_MergeDlg::Init()
00533 {
00534   if (myAction == 0) {
00535     SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
00536     SpinBoxTolerance->SetValue(1e-05);
00537   }
00538 
00539   RadioButton->setChecked(true);
00540 
00541   GroupType->button(0)->setChecked(true);
00542 
00543   myEditCurrentArgument = (QWidget*)LineEditMesh; 
00544 
00545   myActor = 0;
00546   mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
00547 
00548   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00549 
00550   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00551   myIsBusy = false;
00552   
00553   /* signals and slots connections */
00554   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00555   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00556   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00557   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00558 
00559   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
00560   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
00561   connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
00562   connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
00563   connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
00564   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
00565   connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
00566   connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
00567   connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
00568   connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
00569   connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
00570 
00571   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00572   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00573   /* to close dialog if study change */
00574   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00575 
00576   // Init Mesh field from selection
00577   SelectionIntoArgument();
00578 
00579   // Update Buttons
00580   updateControls();
00581   
00582   if (myAction == 0)
00583     myHelpFileName = "merging_nodes_page.html";
00584   else
00585     myHelpFileName = "merging_elements_page.html";
00586 }
00587 
00588 //=================================================================================
00589 // function : FindGravityCenter()
00590 // purpose  :
00591 //=================================================================================
00592 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap, 
00593                                           std::list< gp_XYZ > & theGrCentersXYZ)
00594 {
00595   if (!myActor)
00596     return;
00597 
00598   SMDS_Mesh* aMesh = 0;
00599   aMesh = myActor->GetObject()->GetMesh();
00600   if (!aMesh)
00601     return;
00602 
00603   int nbNodes;
00604 
00605   TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
00606   for( ; idIter.More(); idIter.Next() ) {
00607     const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
00608     if ( !anElem )
00609       continue;
00610 
00611     gp_XYZ anXYZ(0., 0., 0.);
00612     SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
00613     for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
00614       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
00615       anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
00616     }
00617     anXYZ.Divide( nbNodes );
00618     
00619     theGrCentersXYZ.push_back( anXYZ );
00620   }
00621 }
00622 
00623 //=================================================================================
00624 // function : ClickOnApply()
00625 // purpose  :
00626 //=================================================================================
00627 bool SMESHGUI_MergeDlg::ClickOnApply()
00628 {
00629   if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
00630     return false;
00631 
00632   try {
00633     if (myTypeId == 0)
00634       onDetect();
00635 
00636     SUIT_OverrideCursor aWaitCursor;
00637     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00638 
00639     SMESH::long_array_var anIds = new SMESH::long_array;
00640     SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
00641 
00642     if ( ListCoincident->count() == 0) {
00643       if (myAction == 0)
00644         SUIT_MessageBox::warning(this,
00645                                  tr("SMESH_WARNING"),
00646                                  tr("SMESH_NO_NODES_DETECTED"));
00647       else
00648         SUIT_MessageBox::warning(this,
00649                                  tr("SMESH_WARNING"),
00650                                  tr("SMESH_NO_ELEMENTS_DETECTED"));
00651       return false;
00652     }
00653 
00654     aGroupsOfElements->length(ListCoincident->count());
00655 
00656     int anArrayNum = 0;
00657     for (int i = 0; i < ListCoincident->count(); i++) {
00658       QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
00659 
00660       anIds->length(aListIds.count());
00661       for (int i = 0; i < aListIds.count(); i++)
00662         anIds[i] = aListIds[i].toInt();
00663 
00664       aGroupsOfElements[anArrayNum++] = anIds.inout();
00665     }
00666 
00667     if( myAction == 0 )
00668       aMeshEditor->MergeNodes (aGroupsOfElements.inout());
00669     else
00670       aMeshEditor->MergeElements (aGroupsOfElements.inout());
00671 
00672     if ( myTypeId == 0 ) {
00673       if (myAction ==0)
00674         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
00675                                      tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
00676       else
00677         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
00678                                      tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
00679     }
00680       
00681 
00682   } catch(...) {
00683   }
00684   
00685   ListCoincident->clear();
00686   
00687   SMESH::UpdateView();
00688   SMESHGUI::Modified();
00689   
00690   return true;
00691 }
00692 
00693 //=================================================================================
00694 // function : ClickOnOk()
00695 // purpose  :
00696 //=================================================================================
00697 void SMESHGUI_MergeDlg::ClickOnOk()
00698 {
00699   if (ClickOnApply())
00700     ClickOnCancel();
00701 }
00702 
00703 //=================================================================================
00704 // function : ClickOnCancel()
00705 // purpose  :
00706 //=================================================================================
00707 void SMESHGUI_MergeDlg::ClickOnCancel()
00708 {
00709   myIdPreview->SetPointsLabeled(false);
00710   SMESH::SetPointRepresentation(false);
00711   disconnect(mySelectionMgr, 0, this, 0);
00712   disconnect(mySMESHGUI, 0, this, 0);
00713   mySMESHGUI->ResetState();
00714 
00715   mySelectionMgr->clearFilters();
00716   //mySelectionMgr->clearSelected();
00717 
00718   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00719     aViewWindow->SetSelectionMode(ActorSelection);
00720 
00721   reject();
00722 }
00723 
00724 //=================================================================================
00725 // function : ClickOnHelp()
00726 // purpose  :
00727 //=================================================================================
00728 void SMESHGUI_MergeDlg::ClickOnHelp()
00729 {
00730   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00731   if (app) 
00732     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00733   else {
00734     QString platform;
00735 #ifdef WIN32
00736     platform = "winapplication";
00737 #else
00738     platform = "application";
00739 #endif
00740     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00741                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00742                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00743                                                                  platform)).
00744                              arg(myHelpFileName));
00745   }
00746 }
00747 
00748 //=================================================================================
00749 // function : onEditGroup()
00750 // purpose  :
00751 //=================================================================================
00752 void SMESHGUI_MergeDlg::onEditGroup()
00753 {
00754   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
00755   if ( selItems.count() != 1 ) {
00756     ListEdit->clear();
00757     return;
00758   }
00759 
00760   QStringList aNewIds;
00761 
00762   for (int i = 0; i < ListEdit->count(); i++ )
00763     aNewIds.append(ListEdit->item(i)->text());
00764 
00765   ListCoincident->clearSelection();
00766   selItems.first()->setText(aNewIds.join(" "));
00767   selItems.first()->setSelected(true);
00768 }
00769 
00770 //=================================================================================
00771 // function : updateControls()
00772 // purpose  :
00773 //=================================================================================
00774 void SMESHGUI_MergeDlg::updateControls()
00775 {
00776   if (ListEdit->count() == 0)
00777     SetFirstButton->setEnabled(false);
00778   bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
00779   buttonOk->setEnabled(enable);
00780   buttonApply->setEnabled(enable);
00781 }
00782 
00783 //=================================================================================
00784 // function : onDetect()
00785 // purpose  :
00786 //=================================================================================
00787 void SMESHGUI_MergeDlg::onDetect()
00788 {
00789   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
00790     return;
00791 
00792   try {
00793     SUIT_OverrideCursor aWaitCursor;
00794     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00795 
00796     ListCoincident->clear();
00797     ListEdit->clear();
00798 
00799     SMESH::array_of_long_array_var aGroupsArray;
00800     SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
00801 
00802     SMESH::SMESH_IDSource_var src;
00803     if ( mySubMeshOrGroup->_is_nil() ) src = SMESH::SMESH_IDSource::_duplicate( myMesh );
00804     else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
00805 
00806     switch (myAction) {
00807     case 0 :
00808       for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
00809         if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
00810           aExcludeGroups->length( aExcludeGroups->length()+1 );
00811           aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_duplicate( myGroups[i] );
00812         }
00813       }
00814       aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
00815                                                 SpinBoxTolerance->GetValue(), 
00816                                                 aGroupsArray.out(),
00817                                                 aExcludeGroups.in());
00818       break;
00819     case 1 :
00820       aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
00821       break;
00822     }
00823     
00824     for (int i = 0; i < aGroupsArray->length(); i++) {
00825       SMESH::long_array& aGroup = aGroupsArray[i];
00826 
00827       QStringList anIDs;
00828       for (int j = 0; j < aGroup.length(); j++)
00829         anIDs.append(QString::number(aGroup[j]));
00830 
00831       ListCoincident->addItem(anIDs.join(" "));
00832     }
00833    } catch(...) {
00834   }
00835 
00836   ListCoincident->selectAll();
00837   updateControls();
00838 }
00839 
00840 //=================================================================================
00841 // function : onSelectGroup()
00842 // purpose  :
00843 //=================================================================================
00844 void SMESHGUI_MergeDlg::onSelectGroup()
00845 {
00846   if (myIsBusy || !myActor)
00847     return;
00848   myEditCurrentArgument = (QWidget*)ListCoincident;
00849 
00850   ListEdit->clear();
00851   
00852   TColStd_MapOfInteger anIndices;
00853   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
00854   QListWidgetItem* anItem;
00855   QStringList aListIds;
00856 
00857   ListEdit->clear();
00858 
00859   foreach(anItem, selItems) {
00860     aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
00861     for (int i = 0; i < aListIds.count(); i++)
00862       anIndices.Add(aListIds[i].toInt());
00863   }
00864   
00865   if (selItems.count() == 1) {
00866     ListEdit->addItems(aListIds);
00867     ListEdit->selectAll();
00868   }
00869 
00870   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
00871   SALOME_ListIO aList;
00872   aList.Append(myActor->getIO());
00873   mySelectionMgr->setSelectedObjects(aList,false);
00874   
00875   if (myAction == 0) {
00876     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
00877     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
00878   }
00879   else {
00880     std::list< gp_XYZ > aGrCentersXYZ;
00881     FindGravityCenter(anIndices, aGrCentersXYZ);
00882     myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
00883     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
00884   }
00885 
00886   updateControls();
00887 }
00888 
00889 //=================================================================================
00890 // function : onSelectAll()
00891 // purpose  :
00892 //=================================================================================
00893 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
00894 {
00895   if ( isToggled )
00896     ListCoincident->selectAll();
00897   else
00898     ListCoincident->clearSelection();
00899 }
00900 
00901 //=================================================================================
00902 // function : onSelectElementFromGroup()
00903 // purpose  :
00904 //=================================================================================
00905 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
00906 {
00907   if (myIsBusy || !myActor)
00908     return;
00909 
00910   TColStd_MapOfInteger anIndices;
00911   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
00912   QListWidgetItem* anItem;
00913 
00914   foreach(anItem, selItems)
00915     anIndices.Add(anItem->text().toInt());
00916 
00917   SetFirstButton->setEnabled(selItems.count() == 1);
00918 
00919   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
00920   SALOME_ListIO aList;
00921   aList.Append(myActor->getIO());
00922   mySelectionMgr->setSelectedObjects(aList);
00923 
00924   if (myAction == 0) {
00925     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
00926     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
00927   }
00928   else {
00929     std::list< gp_XYZ > aGrCentersXYZ;
00930     FindGravityCenter(anIndices, aGrCentersXYZ);
00931     myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
00932     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
00933   }
00934 }
00935 
00936 //=================================================================================
00937 // function : onAddGroup()
00938 // purpose  :
00939 //=================================================================================
00940 void SMESHGUI_MergeDlg::onAddGroup()
00941 {
00942   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
00943     return;
00944 
00945   QString anIDs = "";
00946   int aNbElements = 0;
00947   aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
00948 
00949   if (aNbElements < 1)
00950     return;
00951   
00952   ListCoincident->clearSelection();
00953   ListCoincident->addItem(anIDs);
00954   int nbGroups = ListCoincident->count();
00955   if (nbGroups) {
00956     ListCoincident->setCurrentRow(nbGroups-1);
00957     ListCoincident->item(nbGroups-1)->setSelected(true);
00958   }
00959   else {
00960     // VSR ? this code seems to be never executed!!!
00961     ListCoincident->setCurrentRow(0);
00962     //ListCoincident->setSelected(0, true); // VSR: no items - no selection
00963   }
00964 
00965   updateControls();
00966 }
00967 
00968 //=================================================================================
00969 // function : onRemoveGroup()
00970 // purpose  :
00971 //=================================================================================
00972 void SMESHGUI_MergeDlg::onRemoveGroup()
00973 {
00974   if (myEditCurrentArgument != (QWidget*)ListCoincident)
00975     return;
00976   myIsBusy = true;
00977 
00978   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
00979   QListWidgetItem* anItem;
00980 
00981   foreach(anItem, selItems)
00982     delete anItem;
00983 
00984   ListEdit->clear();
00985   updateControls();
00986 
00987   myIsBusy = false;
00988 }
00989 
00990 //=================================================================================
00991 // function : onAddElement()
00992 // purpose  :
00993 //=================================================================================
00994 void SMESHGUI_MergeDlg::onAddElement()
00995 {
00996   if (!myActor)
00997     return;
00998   myIsBusy = true;
00999 
01000   QString aListStr = "";
01001   int aNbNnodes = 0;
01002 
01003   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
01004   if (aNbNnodes < 1)
01005     return;
01006 
01007   QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
01008 
01009   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
01010     QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
01011     if ( found.count() == 0 ) {
01012       QListWidgetItem* anItem = new QListWidgetItem(*it);
01013       ListEdit->addItem(anItem);
01014       anItem->setSelected(true);
01015     }
01016     else {
01017       QListWidgetItem* anItem;
01018       foreach(anItem, found) anItem->setSelected(true);
01019     }
01020   }
01021 
01022   myIsBusy = false;
01023   onEditGroup();
01024 }
01025 
01026 //=================================================================================
01027 // function : onRemoveElement()
01028 // purpose  :
01029 //=================================================================================
01030 void SMESHGUI_MergeDlg::onRemoveElement()
01031 {
01032   if (myEditCurrentArgument != (QWidget*)ListCoincident)
01033     return;
01034   myIsBusy = true;
01035 
01036   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
01037   QListWidgetItem* anItem;
01038 
01039   foreach(anItem, selItems)
01040     delete anItem;
01041   
01042   myIsBusy = false;
01043   onEditGroup();
01044 }
01045 
01046 //=================================================================================
01047 // function : onSetFirst()
01048 // purpose  :
01049 //=================================================================================
01050 void SMESHGUI_MergeDlg::onSetFirst()
01051 {
01052   if (myEditCurrentArgument != (QWidget*)ListCoincident)
01053     return;
01054   myIsBusy = true;
01055   
01056   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
01057   QListWidgetItem* anItem;
01058   
01059   foreach(anItem, selItems) {
01060     ListEdit->takeItem(ListEdit->row(anItem));
01061     ListEdit->insertItem(0, anItem);
01062   }
01063 
01064   myIsBusy = false;
01065   onEditGroup();
01066 }
01067 
01068 //=================================================================================
01069 // function : SetEditCurrentArgument()
01070 // purpose  :
01071 //=================================================================================
01072 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
01073 {
01074   QPushButton* send = (QPushButton*)sender();
01075 
01076   disconnect(mySelectionMgr, 0, this, 0);
01077   mySelectionMgr->clearSelected();
01078   mySelectionMgr->clearFilters();
01079 
01080   if (send == SelectMeshButton) {
01081     myEditCurrentArgument = (QWidget*)LineEditMesh;
01082     SMESH::SetPointRepresentation(false);
01083     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01084       aViewWindow->SetSelectionMode(ActorSelection);
01085     if (myTypeId == 1)
01086       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
01087   }
01088 
01089   myEditCurrentArgument->setFocus();
01090   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
01091   SelectionIntoArgument();
01092 }
01093 
01094 //=================================================================================
01095 // function : SelectionIntoArgument()
01096 // purpose  : Called when selection as changed or other case
01097 //=================================================================================
01098 void SMESHGUI_MergeDlg::SelectionIntoArgument()
01099 {
01100   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
01101     QString aString = "";
01102     LineEditMesh->setText(aString);
01103     
01104     ListCoincident->clear();
01105     ListEdit->clear();
01106     myActor = 0;
01107     QString aCurrentEntry = myEntry;
01108     
01109     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
01110     if (nbSel != 1) {
01111       myIdPreview->SetPointsLabeled(false);
01112       SMESH::SetPointRepresentation(false);
01113       mySelectionMgr->clearFilters();
01114       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01115         aViewWindow->SetSelectionMode(ActorSelection);
01116       return;
01117     }
01118 
01119     SALOME_ListIO aList;
01120     mySelectionMgr->selectedObjects(aList);
01121     
01122     Handle(SALOME_InteractiveObject) IO = aList.First();
01123     myEntry = IO->getEntry();
01124     myMesh = SMESH::GetMeshByIO(IO);
01125     
01126     if (myMesh->_is_nil())
01127       return;
01128 
01129     LineEditMesh->setText(aString);
01130     
01131     myActor = SMESH::FindActorByEntry(IO->getEntry());
01132     if (!myActor)
01133       myActor = SMESH::FindActorByObject(myMesh);
01134     
01135     if ( myActor && myTypeId ==1 ) {
01136       mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
01137       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
01138       
01139       if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
01140            !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
01141           !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
01142         mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
01143       
01144       if (myAction == 0) {
01145         SMESH::SetPointRepresentation(true);
01146         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01147           aViewWindow->SetSelectionMode(NodeSelection);
01148       }
01149       else
01150         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01151           aViewWindow->SetSelectionMode(CellSelection);
01152     }
01153 
01154     // process groups
01155     if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
01156       myGroups.clear();
01157       ListExclude->clear();
01158       SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
01159       for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
01160         SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
01161         if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
01162           QString aGroupName( aGroup->GetName() );
01163           if ( !aGroupName.isEmpty() ) {
01164             myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
01165             QListWidgetItem* item = new QListWidgetItem( aGroupName );
01166             item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
01167             item->setCheckState( Qt::Unchecked );
01168             ListExclude->addItem( item );
01169           }
01170         }
01171       }
01172     }
01173 
01174     updateControls();
01175   }
01176 }
01177 
01178 //=================================================================================
01179 // function : DeactivateActiveDialog()
01180 // purpose  :
01181 //=================================================================================
01182 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
01183 {
01184   if (GroupConstructors->isEnabled()) {
01185     GroupConstructors->setEnabled(false);
01186     TypeBox->setEnabled(false);
01187     GroupMesh->setEnabled(false);
01188     GroupCoincident->setEnabled(false);
01189     GroupEdit->setEnabled(false);
01190     GroupButtons->setEnabled(false);
01191     mySMESHGUI->ResetState();
01192     mySMESHGUI->SetActiveDialogBox(0);
01193   }
01194 
01195   mySelectionMgr->clearSelected();
01196   disconnect(mySelectionMgr, 0, this, 0);
01197 }
01198 
01199 //=================================================================================
01200 // function : ActivateThisDialog()
01201 // purpose  :
01202 //=================================================================================
01203 void SMESHGUI_MergeDlg::ActivateThisDialog()
01204 {
01205   /* Emit a signal to deactivate the active dialog */
01206   mySMESHGUI->EmitSignalDeactivateDialog();
01207   GroupConstructors->setEnabled(true);
01208   TypeBox->setEnabled(true);
01209   GroupMesh->setEnabled(true);
01210   GroupCoincident->setEnabled(true);
01211   GroupEdit->setEnabled(true);
01212   GroupButtons->setEnabled(true);
01213 
01214   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
01215   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
01216   SelectionIntoArgument();
01217 }
01218 
01219 //=================================================================================
01220 // function : enterEvent()
01221 // purpose  :
01222 //=================================================================================
01223 void SMESHGUI_MergeDlg::enterEvent(QEvent*)
01224 {
01225   if (!GroupConstructors->isEnabled())
01226     ActivateThisDialog();
01227 }
01228 
01229 //=================================================================================
01230 // function : closeEvent()
01231 // purpose  :
01232 //=================================================================================
01233 void SMESHGUI_MergeDlg::closeEvent(QCloseEvent*)
01234 {
01235   /* same than click on cancel button */
01236   ClickOnCancel();
01237 }
01238 
01239 //=======================================================================
01240 //function : hideEvent
01241 //purpose  : caused by ESC key
01242 //=======================================================================
01243 void SMESHGUI_MergeDlg::hideEvent (QHideEvent *)
01244 {
01245   if (!isMinimized())
01246     ClickOnCancel();
01247 }
01248 
01249 //=================================================================================
01250 // function : keyPressEvent()
01251 // purpose  :
01252 //=================================================================================
01253 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
01254 {
01255   QDialog::keyPressEvent( e );
01256   if ( e->isAccepted() )
01257     return;
01258 
01259   if ( e->key() == Qt::Key_F1 ) {
01260     e->accept();
01261     ClickOnHelp();
01262   }
01263 }
01264 
01265 //=================================================================================
01266 // function : onTypeChanged()
01267 // purpose  : the type radio button management
01268 //=================================================================================
01269 void SMESHGUI_MergeDlg::onTypeChanged (int id)
01270 {
01271   if (myTypeId == id)
01272     return;
01273 
01274   myTypeId = id;
01275   switch (id)
01276   {
01277   case 0: // automatic
01278     myIdPreview->SetPointsLabeled(false);
01279     SMESH::SetPointRepresentation(false);
01280     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01281       aViewWindow->SetSelectionMode(ActorSelection);
01282     mySelectionMgr->clearFilters();
01283     if (myAction == 0)
01284       GroupCoincidentWidget->hide();
01285     else
01286       GroupCoincident->hide();
01287     GroupEdit->hide();
01288     break;
01289 
01290   case 1: // manual
01291     SMESH::UpdateView();
01292 
01293     // Costruction of the logical filter
01294     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
01295     SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
01296     
01297     QList<SUIT_SelectionFilter*> aListOfFilters;
01298     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
01299     if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
01300     
01301     myMeshOrSubMeshOrGroupFilter =
01302       new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
01303 
01304     if (myAction == 0) {
01305       GroupCoincidentWidget->show();
01306       SMESH::SetPointRepresentation(true);
01307       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01308         aViewWindow->SetSelectionMode(NodeSelection);
01309     }
01310     else {
01311       GroupCoincident->show();
01312       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01313         aViewWindow->SetSelectionMode(CellSelection);
01314     }
01315     GroupEdit->show();
01316     break;
01317   }
01318   updateControls();
01319 
01320   qApp->processEvents();
01321   updateGeometry();
01322   resize(10,10);
01323 
01324   SelectionIntoArgument();
01325 }