Salome HOME
Préalables de l'activation des menus
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AdaptDlg.cxx
1 // Copyright (C) 2011-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESHGUI : GUI for the adaptation in the SMESH component
21 //  File   : SMESHGUI_AdaptDlg.cxx
22 //  Author : Gerald NICOLAS, EDF
23 //  ADAPTGUI includes
24 //
25 #include "SMESHGUI_AdaptDlg.h"
26
27 #include "SMESHGUI.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_GroupUtils.h"
31 #include "SMESHGUI_FilterUtils.h"
32 #include "SMESHGUI_GEOMGenUtils.h"
33 #include "SMESHGUI_FilterDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_Actor.h>
38 //#include <SMESH_ActorUtils.h>
39 #include <SMESH_LogicalFilter.hxx>
40
41 // SALOME GEOM includes
42 #include <GEOMBase.h>
43 #include <GEOM_SelectionFilter.h>
44 #include <GEOM_wrap.hxx>
45
46 // SALOME GUI includes
47 #include <QtxColorButton.h>
48
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_OverrideCursor.h>
54
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <LightApp_SelectionMgr.h>
59
60 #include <SALOME_ListIO.hxx>
61
62 #include <SVTK_ViewWindow.h>
63
64 #include <VTKViewer_Algorithm.h>
65
66 // SALOME KERNEL includes
67 #include <SALOMEDSClient_Study.hxx>
68 #include <utilities.h>
69
70 // VTK Includes
71 #include <vtkRenderer.h>
72 #include <vtkActorCollection.h>
73
74 // OCCT includes
75 #include <TColStd_MapOfInteger.hxx>
76
77 // Qt includes
78 #include <QButtonGroup>
79 #include <QGroupBox>
80 #include <QLabel>
81 #include <QLineEdit>
82 #include <QPushButton>
83 #include <QToolButton>
84 #include <QRadioButton>
85 #include <QCheckBox>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QListWidget>
90 #include <QStackedWidget>
91 #include <QKeyEvent>
92 #include <QMenu>
93
94 // HOMARD includes
95 #include "MonCreateCase.h"
96
97 // STL includes
98 #include <vector>
99 #include <algorithm>
100 #include <set>
101
102 #define SPACING 6
103 #define MARGIN  11
104
105 enum grpSelectionMode {
106   grpNoSelection       = -1,
107   grpNodeSelection     = 0,
108   grp0DSelection       = 1,
109   grpBallSelection     = 2,
110   grpEdgeSelection     = 3,
111   grpFaceSelection     = 4,
112   grpVolumeSelection   = 5,
113   grpSubMeshSelection  = 6,
114   grpGroupSelection    = 7,
115   grpMeshSelection     = 8,
116   grpGeomSelection     = 9,
117   grpAllSelection      = 10,
118 };
119
120 //=================================================================================
121 // function : SMESHGUI_AdaptDlg()
122 // purpose  :
123 //=================================================================================
124 SMESHGUI_AdaptDlg::SMESHGUI_AdaptDlg( SMESHGUI* theModule,
125                                       int theCommandID,
126                                       SMESH::SMESH_Mesh_ptr theMesh )
127   : QDialog( SMESH::GetDesktop( theModule ) ),
128     mySMESHGUI( theModule ),
129     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
130     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
131     myIsBusy( false ),
132     myNameChanged( false ),
133     myNbChangesOfContents(0),
134     myIsApplyAndClose( false )
135 {
136   std::cout  << "SMESHGUI_AdaptDlg avec theCommandID : " << theCommandID << std::endl;
137   initDialog( true );
138   if ( !theMesh->_is_nil() )
139     init( theMesh );
140   else
141   {
142     mySelectSubMesh->setEnabled( false );
143     mySelectGroup->setEnabled( false );
144     myGeomGroupBtn->setEnabled( false );
145     myGeomGroupLine->setEnabled( false );
146   }
147 }
148 //=======================================================================
149 // OnGUIEvent for the adaptations
150 //=======================================================================
151 bool SMESHGUI_AdaptDlg::OnGUIEvent (int theCommandID)
152 {
153   std::cout  << "OnGUIEvent avec theCommandID : " << theCommandID << std::endl;
154 // A. Controles
155 //   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( application() );
156 //   if ( !app ) return false;
157 //
158 //   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
159 //   if ( !stud )
160 //   {
161 //     MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
162 //     return false;
163 //   }
164 //
165 //   SUIT_Desktop* parent = application()->desktop();
166 //
167 //   ADAPT::ADAPT_Gen_var homardGen = ADAPTGUI::InitHOMARDGen(app);
168 //
169 //   if (!CORBA::is_nil(homardGen))
170 //     homardGen->UpdateStudy();
171 //
172 //   getApp()->updateObjectBrowser();
173 //
174 // B. Choix selon les commandes
175   SCRUTE(theCommandID);
176   switch (theCommandID)
177   {
178     case 8011: // Creation d un Cas
179     {
180       MESSAGE("command " << theCommandID << " activated");
181 //       MonCreateCase *aDlg = new MonCreateCase( true,
182 //                             ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
183 //       aDlg->show();
184       break;
185     }
186
187 //     case 8012: // Poursuite d une iteration
188 //     {
189 //       MESSAGE("command " << theCommandID << " activated");
190 //       MonPursueIteration *aDlg = new MonPursueIteration( true,
191 //                                 ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
192 //       aDlg->show();
193 //       break;
194 //     }
195
196 //     case 8013: // Creation d une Iteration
197 //     {
198 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
199 //       MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
200 //                                      ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
201 //       IterDlg->show();
202 //       break;
203 //     }
204
205 //     case 8014: // Compute une iteration
206 //     {
207 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
208 //       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 1); }
209 //       catch( SALOME::SALOME_Exception& S_ex )
210 //       {
211 //         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
212 //                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
213 //         getApp()->updateObjectBrowser();
214 //         return false;
215 //       }
216 //       break;
217 //     }
218
219 //     case 8015: // Compute une iteration et publication
220 //     {
221 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
222 //       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 2); }
223 //       catch( SALOME::SALOME_Exception& S_ex )
224 //       {
225 //         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
226 //                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
227 //         getApp()->updateObjectBrowser();
228 //         return false;
229 //       }
230 //       break;
231 //     }
232
233 //     case 1121: // Information sur le maillage de l'iteration
234 //     {
235 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
236 //       MonIterInfo *IterDlg = new MonIterInfo( parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
237 //       IterDlg->show();
238 //       break;
239 //     }
240 //
241 //     case 1131: // Publication du maillage de l'iteration
242 //     {
243 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
244 //       homardGen->PublishMeshIterInSmesh(_ObjectName.toStdString().c_str());
245 //       break;
246 //     }
247 //
248 //     case 1132: // Publication du maillage de l'iteration a partir du fichier
249 //     {
250 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
251 //       homardGen->PublishResultInSmesh(_ObjectName.toStdString().c_str(), 1);
252 //       break;
253 //     }
254 //
255 //     case 1201: // Edition d'un objet
256 //     {
257 //       MESSAGE("command " << theCommandID << " activated");
258 //       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
259 //       if (nomObjet == QString("")) break;
260 //       _PTR(SObject) obj = chercheMonObjet();
261 //       if (obj)
262 //       {
263 //         // Edition d'une frontiere CAO
264 //         if (HOMARD_UTILS::isBoundaryCAO(obj))
265 //         {
266 //           MonEditBoundaryCAO *aDlg = new MonEditBoundaryCAO(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
267 //           aDlg->show();
268 //         }
269 //         // Edition d'une frontiere discrete
270 //         else if (HOMARD_UTILS::isBoundaryDi(obj))
271 //         {
272 //           MonEditBoundaryDi *aDlg = new MonEditBoundaryDi(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
273 //           aDlg->show();
274 //         }
275 //         // Edition d'une frontiere analytique
276 //         else if (HOMARD_UTILS::isBoundaryAn(obj))
277 //         {
278 //           MonEditBoundaryAn *aDlg = new MonEditBoundaryAn(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
279 //           aDlg->show();
280 //         }
281 //         // Edition d'un cas
282 //         else if (HOMARD_UTILS::isCase(obj))
283 //         {
284 //           MonEditCase *aDlg = new MonEditCase(true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
285 //           aDlg->show();
286 //         }
287 //         // Edition d'une hypothese
288 //         else if (HOMARD_UTILS::isHypo(obj))
289 //         {
290 //           MonEditHypothesis *aDlg = new MonEditHypothesis(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen),  _ObjectName, QString(""), QString("")) ;
291 //           aDlg->show();
292 //         }
293 //         // Edition d'une iteration
294 //         else if (HOMARD_UTILS::isIter(obj))
295 //         {
296 //           MonEditIteration *aDlg = new MonEditIteration(parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
297 //           aDlg->show();
298 //         }
299 //         // Edition d'un schema YACS
300 //         else if (HOMARD_UTILS::isYACS(obj))
301 //         {
302 //           MESSAGE("appel de MonEditYACS");
303 //           MonEditYACS *aDlg = new MonEditYACS(true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName) ;
304 //           aDlg->show();
305 //         }
306 //         // Edition d'une zone
307 //         else if (HOMARD_UTILS::isZone(obj))
308 //         {
309 //           MonEditZone *aDlg = new MonEditZone(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
310 //           aDlg->show();
311 //         }
312 //       }
313 //       break;
314 //     }
315 //
316 //     case 1211: // Suppression d'un objet
317 //     {
318 //       MESSAGE("command " << theCommandID << " activated");
319 //       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
320 //       if (nomObjet == QString("")) break;
321 //       _PTR(SObject) obj = chercheMonObjet();
322 //       if (obj)
323 //       {
324 //         // Suppression d'une frontiere
325 //         if ( HOMARD_UTILS::isBoundaryCAO(obj) || HOMARD_UTILS::isBoundaryDi(obj) || HOMARD_UTILS::isBoundaryAn(obj) )
326 //         {
327 //           try
328 //           { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); }
329 //           catch( SALOME::SALOME_Exception& S_ex )
330 //           {
331 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
332 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
333 //             getApp()->updateObjectBrowser();
334 //             return false;
335 //           }
336 //         }
337 //         // Suppression d'un cas
338 //         else if (HOMARD_UTILS::isCase(obj))
339 //         {
340 //           try
341 //           { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); }
342 //           catch( SALOME::SALOME_Exception& S_ex )
343 //           {
344 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
345 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
346 //             getApp()->updateObjectBrowser();
347 //             return false;
348 //           }
349 //         }
350 //         // Suppression d'une hypothese
351 //         else if (HOMARD_UTILS::isHypo(obj))
352 //         {
353 //           try
354 //           { homardGen->DeleteHypo(_ObjectName.toStdString().c_str()); }
355 //           catch( SALOME::SALOME_Exception& S_ex )
356 //           {
357 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
358 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
359 //             getApp()->updateObjectBrowser();
360 //             return false;
361 //           }
362 //         }
363 //         // Suppression d'une iteration
364 //         else if (HOMARD_UTILS::isIter(obj))
365 //         {
366 //           try
367 //           { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); }
368 //           catch( SALOME::SALOME_Exception& S_ex )
369 //           {
370 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
371 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
372 //             getApp()->updateObjectBrowser();
373 //             return false;
374 //           }
375 //         }
376 //         // Suppression d'un schema YACS
377 //         else if (HOMARD_UTILS::isYACS(obj))
378 //         {
379 //           try
380 //           { homardGen->DeleteYACS(_ObjectName.toStdString().c_str(), 1); }
381 //           catch( SALOME::SALOME_Exception& S_ex )
382 //           {
383 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
384 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
385 //             getApp()->updateObjectBrowser();
386 //             return false;
387 //           }
388 //         }
389 //         // Suppression d'une zone
390 //         else if (HOMARD_UTILS::isZone(obj))
391 //         {
392 //           try
393 //           { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); }
394 //           catch( SALOME::SALOME_Exception& S_ex )
395 //           {
396 //             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
397 //                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
398 //             getApp()->updateObjectBrowser();
399 //             return false;
400 //           }
401 //         }
402 //       }
403 //       break;
404 //     }
405 //
406 //     case 1301: // Information sur un maillage
407 //     {
408 //       MESSAGE("etape 1301")
409 //       MESSAGE("command " << theCommandID << " activated");
410 //       MonMeshInfo *aDlg = new MonMeshInfo( parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
411 //       aDlg->show();
412 //       break;
413 //     }
414 //
415 //     case 1302: // Affichage de fichier texte
416 //     {
417 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
418 //       _PTR(SObject) obj = chercheMonObjet();
419 //       if ( (obj) && ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) ) )
420 //       {
421 //           MonEditFile *aDlg = new MonEditFile( 0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName, 0 ) ;
422 //           if ( aDlg->_codret == 0 ) { aDlg->show(); }
423 //       }
424 //       break;
425 //     }
426 //
427 //     case 1401: // CrĂ©ation d'un schema YACS
428 //     {
429 //       MESSAGE("etape 1401")
430 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
431 //       MonCreateYACS *aDlg = new MonCreateYACS( true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
432 //       aDlg->show();
433 //       break;
434 //     }
435 //
436 //     case 1402: // Ecriture d'un schĂ©ma YACS
437 //     {
438 //       MESSAGE("etape 1402")
439 //       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
440 //       try { homardGen->YACSWrite(_ObjectName.toStdString().c_str()); }
441 //       catch( SALOME::SALOME_Exception& S_ex )
442 //       {
443 //         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
444 //                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
445 //         getApp()->updateObjectBrowser();
446 //         return false;
447 //       }
448 //       break;
449 //     }
450
451   }
452 //   getApp()->updateObjectBrowser();
453   return true;
454 }
455
456 //=================================================================================
457 // function : SMESHGUI_AdaptDlg()
458 // purpose  :
459 //=================================================================================
460 void SMESHGUI_AdaptDlg::initDialog( bool create)
461 {
462   std::cout  << "passage par initDialog" << std::endl;
463   setModal( false );
464   setAttribute( Qt::WA_DeleteOnClose, true );
465
466   myFilterDlg = 0;
467   myCreate = create;
468   myCurrentLineEdit = 0;
469
470   myShapeByMeshOp = 0;
471   myGeomPopup = 0;
472   myGeomObjects = new GEOM::ListOfGO();
473   myGeomObjects->length( 0 );
474
475   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
476
477   setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
478   myHelpFileName = create ? "creating_groups.html" : "editing_groups.html";
479
480   setSizeGripEnabled( true);
481
482   QGridLayout* aMainLayout = new QGridLayout( this );
483   aMainLayout->setMargin( MARGIN );
484   aMainLayout->setSpacing( SPACING );
485
486   /***************************************************************/
487   QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
488   myMeshGroupBtn = new QPushButton( this );
489   myMeshGroupBtn->setIcon( image0 );
490   myMeshGroupLine = new QLineEdit( this );
491   myMeshGroupLine->setReadOnly( true );
492
493   /***************************************************************/
494   QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
495   myTypeGroup = new QButtonGroup( this );
496   QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
497   aTypeBoxLayout->setMargin( MARGIN );
498   aTypeBoxLayout->setSpacing( SPACING );
499
500   QStringList types;
501   types.append( tr( "MESH_NODE" ) );
502   types.append( tr( "SMESH_ELEM0D" ) );
503   types.append( tr( "SMESH_BALL_ELEM" ) );
504   types.append( tr( "SMESH_EDGE" ) );
505   types.append( tr( "SMESH_FACE" ) );
506   types.append( tr( "SMESH_VOLUME" ) );
507   QRadioButton* rb;
508   for ( int i = 0; i < types.count(); i++ )
509   {
510     rb = new QRadioButton( types[i], aTypeBox );
511     myTypeGroup->addButton( rb, i );
512     aTypeBoxLayout->addWidget( rb );
513   }
514   aTypeBox->setEnabled( create );
515   myTypeId = -1;
516
517   /***************************************************************/
518   QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
519   aName->setMinimumWidth( 50 );
520   myName = new QLineEdit( this );
521
522   /***************************************************************/
523   QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
524   myGrpTypeGroup = new QButtonGroup( this );
525   QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
526   aGrpTypeBoxLayout->setMargin( MARGIN );
527   aGrpTypeBoxLayout->setSpacing( SPACING );
528
529   QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
530   QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ),   aGrpTypeBox );
531   QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ),     aGrpTypeBox );
532   myGrpTypeGroup->addButton( rb1, 0 );
533   myGrpTypeGroup->addButton( rb2, 1 );
534   myGrpTypeGroup->addButton( rb3, 2 );
535   aGrpTypeBoxLayout->addWidget( rb1 );
536   aGrpTypeBoxLayout->addWidget( rb2 );
537   aGrpTypeBoxLayout->addWidget( rb3 );
538   aGrpTypeBox->setEnabled( create );
539   myGrpTypeId = -1;
540
541   /***************************************************************/
542   myWGStack = new QStackedWidget( this );
543   QWidget* wg1 = new QWidget( myWGStack );
544   QWidget* wg2 = new QWidget( myWGStack );
545   QWidget* wg3 = new QWidget( myWGStack );
546
547   /***************************************************************/
548   QGroupBox* aContentBox         = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
549   QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
550   aContentBoxLayout->setMargin( MARGIN );
551   aContentBoxLayout->setSpacing( SPACING );
552
553   mySelectAll       = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
554   myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
555
556   myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
557   myElements    = new QListWidget( aContentBox );
558   myElements->setSelectionMode( QListWidget::ExtendedSelection );
559
560   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
561   myAddBtn    = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
562   myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
563   mySortBtn   = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
564
565   aContentBoxLayout->addWidget( mySelectAll,       0, 0 );
566   aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
567   aContentBoxLayout->addWidget( myFilterBtn,       1, 1 );
568   aContentBoxLayout->addWidget( myElementsLab,     2, 0 );
569   aContentBoxLayout->addWidget( myElements,        3, 0, 6, 1 );
570   aContentBoxLayout->addWidget( myAddBtn,          3, 1 );
571   aContentBoxLayout->addWidget( myRemoveBtn,       4, 1 );
572   aContentBoxLayout->addWidget( mySortBtn,         8, 1 );
573
574   aContentBoxLayout->setColumnStretch( 0, 1 );
575   aContentBoxLayout->setRowStretch( 3, 1 );
576   aContentBoxLayout->setRowStretch( 6, 1 );
577
578   /***************************************************************/
579   mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
580   QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
581   mySelectBoxLayout->setMargin( MARGIN );
582   mySelectBoxLayout->setSpacing( SPACING );
583
584   mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
585   mySubMeshBtn = new QPushButton( mySelectBox );
586   mySubMeshBtn->setIcon( image0 );
587   mySubMeshLine = new QLineEdit( mySelectBox );
588   mySubMeshLine->setReadOnly( true );
589   onSelectSubMesh( false );
590
591   mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
592   myGroupBtn = new QPushButton( mySelectBox );
593   myGroupBtn->setIcon( image0 );
594   myGroupLine = new QLineEdit( mySelectBox );
595   myGroupLine->setReadOnly( true );
596   onSelectGroup( false );
597
598   mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
599   mySelectBoxLayout->addWidget( mySubMeshBtn,    0, 1 );
600   mySelectBoxLayout->addWidget( mySubMeshLine,   0, 2 );
601   mySelectBoxLayout->addWidget( mySelectGroup,   1, 0 );
602   mySelectBoxLayout->addWidget( myGroupBtn,      1, 1 );
603   mySelectBoxLayout->addWidget( myGroupLine,     1, 2 );
604
605   /***************************************************************/
606   QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
607   wg1Layout->setMargin( 0 );
608   wg1Layout->setSpacing( SPACING );
609   wg1Layout->addWidget( aContentBox );
610   wg1Layout->addWidget( mySelectBox );
611   wg1Layout->setStretchFactor( aContentBox, 10 );
612
613   /***************************************************************/
614   QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
615   myGeomGroupBtn = new QToolButton( wg2 );
616   myGeomGroupBtn->setIcon( image0 );
617   myGeomGroupBtn->setCheckable( true );
618   myGeomGroupLine = new QLineEdit( wg2 );
619   myGeomGroupLine->setReadOnly( true ); //VSR ???
620   onSelectGeomGroup( false );
621
622   myGeomGroupBtn->setEnabled( create );
623   myGeomGroupLine->setEnabled( create );
624
625   /***************************************************************/
626   QGridLayout* wg2Layout = new QGridLayout( wg2 );
627   wg2Layout->setMargin( 0 );
628   wg2Layout->setSpacing( SPACING );
629   wg2Layout->addWidget( geomObject,     0, 0 );
630   wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
631   wg2Layout->addWidget( myGeomGroupLine,0, 2 );
632   wg2Layout->setRowStretch( 1, 5 );
633
634   /***************************************************************/
635   QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
636   QGridLayout* wg3Layout = new QGridLayout( wg3 );
637   wg3Layout->setMargin( 0 );
638   wg3Layout->setSpacing( SPACING );
639   wg3Layout->addWidget( aFilter2, 0, 0 );
640   wg3Layout->setRowStretch( 1, 5 );
641
642   /***************************************************************/
643   myWGStack->insertWidget( 0, wg1 );
644   myWGStack->insertWidget( 1, wg2 );
645   myWGStack->insertWidget( 2, wg3 );
646
647   /***************************************************************/
648   QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
649   QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
650   aColorBoxLayout->setMargin(MARGIN);
651   aColorBoxLayout->setSpacing(SPACING);
652
653   QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
654   myColorBtn = new QtxColorButton(aColorBox);
655   myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
656                              myColorBtn->sizePolicy().verticalPolicy() );
657
658   aColorBoxLayout->addWidget(aColorLab);
659   aColorBoxLayout->addWidget(myColorBtn);
660
661   /***************************************************************/
662
663   QFrame* aButtons = new QFrame(this);
664   aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
665   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
666   aBtnLayout->setMargin(MARGIN);
667   aBtnLayout->setSpacing(SPACING);
668
669   myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
670   myOKBtn->setAutoDefault(true);
671   myOKBtn->setDefault(true);
672   myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
673   myApplyBtn->setAutoDefault(true);
674   myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
675   myCloseBtn->setAutoDefault(true);
676   myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
677   myHelpBtn->setAutoDefault(true);
678
679   aBtnLayout->addWidget(myOKBtn);
680   aBtnLayout->addSpacing(10);
681   aBtnLayout->addWidget(myApplyBtn);
682   aBtnLayout->addSpacing(10);
683   aBtnLayout->addStretch();
684   aBtnLayout->addWidget(myCloseBtn);
685   aBtnLayout->addWidget(myHelpBtn);
686
687   /***************************************************************/
688   aMainLayout->addWidget(meshGroupLab,    0, 0);
689   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
690   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
691   aMainLayout->addWidget(aTypeBox,        1, 0, 1, 3);
692   aMainLayout->addWidget(aName,           2, 0);
693   aMainLayout->addWidget(myName,          2, 2);
694   aMainLayout->addWidget(aGrpTypeBox,     3, 0, 1, 3);
695   aMainLayout->addWidget(myWGStack,       4, 0, 1, 3);
696   aMainLayout->addWidget(aColorBox,       5, 0, 1, 3);
697   aMainLayout->addWidget(aButtons,        6, 0, 1, 3);
698
699   /* signals and slots connections */
700   connect(myMeshGroupBtn,  SIGNAL(clicked()),          this, SLOT(setCurrentSelection()));
701   connect(myGrpTypeGroup,  SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
702   connect(myTypeGroup,     SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
703
704   connect(myName,          SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
705   connect(myElements,      SIGNAL(itemSelectionChanged()),      this, SLOT(onListSelectionChanged()));
706
707   connect(myFilterBtn,     SIGNAL(clicked()),     this, SLOT(setFilters()));
708   connect(aFilter2,        SIGNAL(clicked()),     this, SLOT(setFilters()));
709   connect(mySelectAll,     SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
710   connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
711   connect(myAddBtn,        SIGNAL(clicked()),     this, SLOT(onAdd()));
712   connect(myRemoveBtn,     SIGNAL(clicked()),     this, SLOT(onRemove()));
713   connect(mySortBtn,       SIGNAL(clicked()),     this, SLOT(onSort()));
714
715   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
716   connect(mySelectGroup,   SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
717   connect(mySubMeshBtn,    SIGNAL(clicked()),     this, SLOT(setCurrentSelection()));
718   connect(myGroupBtn,      SIGNAL(clicked()),     this, SLOT(setCurrentSelection()));
719   connect(myGeomGroupBtn,  SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
720
721   connect(myColorBtn,      SIGNAL(changed( QColor )),  this, SLOT(onColorChanged( QColor )));
722
723   connect(myOKBtn,         SIGNAL(clicked()), this, SLOT(onOK()));
724   connect(myApplyBtn,      SIGNAL(clicked()), this, SLOT(onApply()));
725   connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(reject()));
726   connect(myHelpBtn,       SIGNAL(clicked()), this, SLOT(onHelp()));
727
728   /* Init selection */
729   mySMESHGUI->SetActiveDialogBox(this);
730
731   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
732   mySelectionMode = grpNoSelection;
733
734   myMeshFilter    = new SMESH_TypeFilter(SMESH::MESH);
735   mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
736                                             SMESH_LogicalFilter::LO_OR,
737                                             /*takeOwnership=*/true);
738   myGroupFilter   = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
739                                             SMESH_LogicalFilter::LO_OR,
740                                             /*takeOwnership=*/true);
741   myGeomFilter    = new GEOM_SelectionFilter( aStudy, true );
742
743   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
744   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
745   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),  this, SLOT(onObjectSelectionChanged()));
746   connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()),      this, SLOT(onVisibilityChanged()));
747   connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()),   this, SLOT(onOpenView()));
748   connect(mySMESHGUI, SIGNAL(SignalCloseView()),              this, SLOT(onCloseView()));
749   rb1->setChecked(true); // VSR !!!
750   onGrpTypeChanged(0); // VSR!!!
751
752   if (myMesh->_is_nil() )
753     myTypeGroup->button(0)->setChecked(true);
754
755   onSelectAll(); //updateButtons();
756 }
757
758 //=================================================================================
759 // function : ~SMESHGUI_AdaptDlg()
760 // purpose  : Destroys the object and frees any allocated resources
761 //=================================================================================
762 SMESHGUI_AdaptDlg::~SMESHGUI_AdaptDlg()
763 {
764   // no need to delete child widgets, Qt does it all for us
765   if ( myFilterDlg != 0 ) {
766     myFilterDlg->setParent( 0 );
767     delete myFilterDlg;
768   }
769   if ( myMeshFilter )    delete myMeshFilter;
770   if ( mySubMeshFilter ) delete mySubMeshFilter;
771   if ( myGroupFilter )   delete myGroupFilter;
772   if ( myGeomFilter )    delete myGeomFilter;
773 }
774
775 //=================================================================================
776 // function : GetDefaultName()
777 // purpose  : Get the Group Name if Create new Group
778 //=================================================================================
779 QString SMESHGUI_AdaptDlg::GetDefaultName(const QString& theOperation)
780 {
781   std::cout  << "passage par GetDefaultName" << std::endl;
782   QString aName = "";
783
784   // collect all object names of SMESH component
785   _PTR(Study) aStudy = SMESH::getStudy();
786
787   std::set<std::string> aSet;
788   _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
789   if (aMeshCompo) {
790     _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
791     _PTR(SObject) obj;
792     for (it->InitEx(true); it->More(); it->Next()) {
793       obj = it->Value();
794       aSet.insert(obj->GetName());
795     }
796   }
797
798   // build a unique name
799   int aNumber = 0;
800   bool isUnique = false;
801   while (!isUnique) {
802     aName = theOperation + "_" + QString::number(++aNumber);
803     isUnique = (aSet.count(std::string(aName.toUtf8().constData())) == 0);
804   }
805
806   return aName;
807 }
808
809 void  SMESHGUI_AdaptDlg::setDefaultName() const
810 {
811   std::cout  << "passage par setDefaultName" << std::endl;
812   QString aResName;
813   int i=1;
814   QString aPrefix ="Group_";
815   _PTR(SObject) anObj;
816   do
817   {
818     aResName = aPrefix + QString::number( i++ );
819     anObj = SMESH::getStudy()->FindObject( aResName.toUtf8().constData() );
820   }
821   while ( anObj );
822   myName->setText(aResName);
823 }
824
825 //=================================================================================
826 // function : Init()
827 // purpose  :
828 //=================================================================================
829 void SMESHGUI_AdaptDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
830 {
831   std::cout  << "passage par init (SMESH::SMESH_Mesh_ptr theMesh)" << std::endl;
832   mySelectionMgr->installFilter(myMeshFilter);
833
834   /* init data from current selection */
835   restoreShowEntityMode();
836   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
837   setShowEntityMode();
838   myGroup = SMESH::SMESH_Group::_nil();
839   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
840   myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
841
842   // NPAL19389: create a group with a selection in another group
843   // set actor of myMesh, if it is visible, else try
844   // any visible actor of group or submesh of myMesh
845   SetAppropriateActor();
846
847   setDefaultGroupColor();
848   setDefaultName();
849
850
851   SALOME_ListIO aList;
852   mySelectionMgr->selectedObjects( aList );
853   if( !aList.IsEmpty() )
854   {
855     QString aName = aList.First()->getName();
856     myMeshGroupLine->setText(aName);//??????
857     myMeshGroupLine->home( false );
858   }
859
860   myCurrentLineEdit = 0;
861
862   myTypeGroup->button(0)->setChecked(true);
863   onTypeChanged(0);
864 }
865
866 //=================================================================================
867 // function : Init()
868 // purpose  :
869 //=================================================================================
870 void SMESHGUI_AdaptDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
871 {
872   std::cout  << "passage par init (SMESH::SMESH_GroupBase_ptr theGroup)" << std::endl;
873   restoreShowEntityMode();
874   myMesh = theGroup->GetMesh();
875   setShowEntityMode();
876
877   myNameChanged = true;
878   myName->blockSignals(true);
879   myName->setText(SMESH::fromUtf8(theGroup->GetName()));
880   myName->blockSignals(false);
881   myName->home(false);
882
883   SALOMEDS::Color aColor = theGroup->GetColor();
884   setGroupColor( aColor );
885
886   myMeshGroupLine->setText(theGroup->GetName());
887
888   int aType = 0;
889   switch(theGroup->GetType()) {
890   case SMESH::NODE:   aType = grpNodeSelection;   break;
891   case SMESH::ELEM0D: aType = grp0DSelection;     break;
892   case SMESH::BALL:   aType = grpBallSelection;   break;
893   case SMESH::EDGE:   aType = grpEdgeSelection;   break;
894   case SMESH::FACE:   aType = grpFaceSelection;   break;
895   case SMESH::VOLUME: aType = grpVolumeSelection; break;
896   case SMESH::ALL:
897   case SMESH::NB_ELEMENT_TYPES: break;
898   }
899   myTypeGroup->button(aType)->setChecked(true);
900
901   myGroup         = SMESH::SMESH_Group::_narrow( theGroup );
902   myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
903   myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
904   myFilter        = SMESH::Filter::_nil();
905
906   if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
907     return;
908
909   // NPAL19389: create a group with a selection in another group
910   // set actor of myMesh, if it is visible, else set
911   // actor of theGroup, if it is visible, else try
912   // any visible actor of group or submesh of myMesh
913   // commented, because an attempt to set selection on not displayed cells leads to error
914   SetAppropriateActor();
915
916   /*  SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
917   if ( !anActor )
918     anActor = SMESH::FindActorByObject(theGroup);
919   SMESH::SetPickable(anActor);*/
920   int grpType = (!myGroup->_is_nil() ? 0 : (false ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
921   myGrpTypeGroup->button(grpType)->setChecked(true);
922   onGrpTypeChanged(grpType);
923
924   myTypeId = aType;
925   if ( grpType == 0 ) { // standalone group
926     myCurrentLineEdit = 0;
927     myElements->clear();
928     myAllowElemsModif->setChecked( true );
929
930     setSelectionMode(aType);
931
932     setShowEntityMode(); // depends on myTypeId
933
934     myIdList.clear();
935     if (!theGroup->IsEmpty()) {
936       SMESH::long_array_var anElements = theGroup->GetListOfID();
937       int k = anElements->length();
938       for (int i = 0; i < k; i++) {
939         myIdList.append(anElements[i]);
940         myElements->addItem(QString::number(anElements[i]));
941       }
942       myElements->selectAll();
943     }
944   }
945   else if ( grpType == 1 ) // group on geom
946   {
947     QString aShapeName( "" );
948     _PTR(Study) aStudy = SMESH::getStudy();
949     GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
950     if (!aGroupShape->_is_nil())
951     {
952       _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
953       if ( aGroupShapeSO )
954         aShapeName = aGroupShapeSO->GetName().c_str();
955     }
956     myGeomGroupLine->setText( aShapeName );
957   }
958   else // group on filter
959   {
960     myFilter = myGroupOnFilter->GetFilter();
961     if ( !myFilter->_is_nil() ) {
962       SMESH::Predicate_var perdicate = myFilter->GetPredicate();
963       if ( perdicate->_is_nil() )
964         myFilter = SMESH::Filter::_nil();
965     }
966   }
967
968   if ( grpType != 0 )
969   {
970     myNameChanged = true;
971     myName->blockSignals(true);
972     myName->setText(theGroup->GetName());
973     myName->blockSignals(false);
974   }
975
976   onSelectAll(); //updateButtons();
977 }
978
979 //=================================================================================
980 // function : updateButtons()
981 // purpose  :
982 //=================================================================================
983 void SMESHGUI_AdaptDlg::updateButtons()
984 {
985   std::cout  << "passage par updateButtons" << std::endl;
986   bool enable = !myName->text().trimmed().isEmpty();
987   if ( enable )
988   {
989     if (myGrpTypeId == 0) { // standalone
990       if ( !mySelectAll->isChecked() )
991       {
992         if ( myAllowElemsModif->isChecked() )
993         {
994           enable = ( myElements->count() > 0 );
995         }
996         else if ((enable = !myFilter->_is_nil() ))
997         {
998           SMESH::array_of_ElementType_var types = myFilter->GetTypes();
999           enable = types->length();
1000         }
1001       }
1002       enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
1003     }
1004     else if (myGrpTypeId == 1) // on geom
1005     {
1006       if (CORBA::is_nil(myGroupOnGeom)) // creation mode
1007         enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
1008     }
1009     else if (myGrpTypeId == 2) // on filter
1010     {
1011       if (( enable = !myFilter->_is_nil() ))
1012         if (CORBA::is_nil(myGroupOnFilter) )  // creation mode
1013           enable = !myMesh->_is_nil();
1014     }
1015   }
1016
1017   bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
1018   if ( myGrpTypeId != 1 )
1019   {
1020     myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
1021   }
1022   else
1023   {
1024     myGeomGroupBtn->setEnabled( meshHasGeom );
1025     myGeomGroupLine->setEnabled( meshHasGeom );
1026   }
1027
1028   myOKBtn->setEnabled(enable);
1029   myApplyBtn->setEnabled(enable);
1030 }
1031
1032 //=================================================================================
1033 // function : onNameChanged()
1034 // purpose  :
1035 //=================================================================================
1036 void SMESHGUI_AdaptDlg::onNameChanged (const QString& text)
1037 {
1038   std::cout  << "passage par onNameChanged" << std::endl;
1039   myOldName = myName->text();
1040   updateButtons();
1041   myNameChanged = !myName->text().trimmed().isEmpty();
1042 }
1043
1044 //=================================================================================
1045 // function : onTypeChanged()
1046 // purpose  : Group elements type radio button management
1047 //=================================================================================
1048 void SMESHGUI_AdaptDlg::onTypeChanged (int id)
1049 {
1050   if (myTypeId != id) {
1051     myElements->clear();
1052     myTypeId = id;
1053     if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
1054       setSelectionMode(id);
1055     else
1056       setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
1057
1058     onObjectSelectionChanged();
1059     setShowEntityMode();
1060   }
1061 }
1062
1063 //=================================================================================
1064 // function : onGrpTypeChanged()
1065 // purpose  : Group type radio button management
1066 //=================================================================================
1067 void SMESHGUI_AdaptDlg::onGrpTypeChanged (int id)
1068 {
1069   if (myGrpTypeId != id) {
1070     myGrpTypeId = id;
1071     myWGStack->setCurrentIndex( id );
1072     myName->blockSignals(true);
1073     myName->setText(myOldName);
1074     myName->blockSignals(false);
1075     onSelectGeomGroup(id != 0);
1076   }
1077   updateButtons();
1078 }
1079
1080 //=================================================================================
1081 // function : onColorChanged()
1082 // purpose  : Color button management
1083 //=================================================================================
1084 void SMESHGUI_AdaptDlg::onColorChanged(QColor theColor)
1085 {
1086   updateButtons();
1087 }
1088
1089 //=================================================================================
1090 // function : setSelectionMode()
1091 // purpose  : Radio button management
1092 //=================================================================================
1093 void SMESHGUI_AdaptDlg::setSelectionMode (int theMode)
1094 {
1095   // PAL7314
1096   if (myMesh->_is_nil())
1097     return;
1098   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1099   bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
1100   if (mySelectionMode != theMode) {
1101     // [PAL10408] mySelectionMgr->clearSelected();
1102     mySelectionMgr->clearFilters();
1103     SMESH::RemoveFilters();
1104
1105     if (myActorsList.count() > 0)
1106       for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
1107         it.next()->SetPointRepresentation(false);
1108     else
1109       SMESH::SetPointRepresentation(false);
1110
1111     switch (theMode) {
1112     case grpNodeSelection:
1113       if ( myGrpTypeId == 0 ) // standalone
1114       {
1115         if (myActorsList.count() > 0)
1116           for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
1117             it.next()->SetPointRepresentation(true);
1118         else
1119           SMESH::SetPointRepresentation(true);
1120       }
1121       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
1122       break;
1123     case grpEdgeSelection:
1124       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
1125       break;
1126     case grpBallSelection:
1127       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
1128       break;
1129     case grp0DSelection:
1130       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
1131       break;
1132     case grpFaceSelection:
1133       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
1134       break;
1135     case grpVolumeSelection:
1136       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
1137       break;
1138     case grpSubMeshSelection: {
1139
1140       SMESH_TypeFilter* f = 0;
1141       switch (myTypeId) {
1142       case grpNodeSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
1143       case grpEdgeSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
1144       case grpFaceSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
1145       case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
1146       default:                 f = new SMESH_TypeFilter(SMESH::SUBMESH);
1147       }
1148       QList<SUIT_SelectionFilter*> filtList;
1149       filtList.append( f );
1150       filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
1151       mySubMeshFilter->setFilters( filtList );
1152
1153       mySelectionMgr->installFilter( mySubMeshFilter );
1154
1155       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1156       break;
1157     }
1158     case grpGroupSelection: {
1159
1160       SMESH_TypeFilter* f = 0;
1161       switch (myTypeId) {
1162       case grpNodeSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_NODE);   break;
1163       case grp0DSelection:     f = new SMESH_TypeFilter(SMESH::GROUP_0D);     break;
1164       case grpBallSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_BALL);   break;
1165       case grpEdgeSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_EDGE);   break;
1166       case grpFaceSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_FACE);   break;
1167       case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
1168       default:                 f = new SMESH_TypeFilter(SMESH::GROUP);
1169       }
1170       QList<SUIT_SelectionFilter*> filtList;
1171       filtList.append( f );
1172       myGroupFilter->setFilters( filtList );
1173
1174       mySelectionMgr->installFilter(myGroupFilter);
1175       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1176       break;
1177     }
1178     case grpMeshSelection:
1179       mySelectionMgr->installFilter(myMeshFilter);
1180       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1181       break;
1182     case grpGeomSelection:
1183       mySelectionMgr->installFilter(myGeomFilter);
1184       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1185       break;
1186     default:
1187       if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1188       break;
1189     }
1190     if ( aViewWindow ) aViewWindow->Repaint();
1191     mySelectionMode = theMode;
1192   }
1193 }
1194
1195 //=================================================================================
1196 // function : onApply()
1197 // purpose  :
1198 //=================================================================================
1199 bool SMESHGUI_AdaptDlg::onApply()
1200 {
1201   if (SMESHGUI::isStudyLocked())
1202     return false;
1203
1204   if (myName->text().trimmed().isEmpty())
1205     return false;
1206
1207   SMESH::ElementType aType = SMESH::ALL;
1208   switch (myTypeId) {
1209   case grpNodeSelection:   aType = SMESH::NODE;   break;
1210   case grp0DSelection:     aType = SMESH::ELEM0D; break;
1211   case grpBallSelection:   aType = SMESH::BALL;   break;
1212   case grpEdgeSelection:   aType = SMESH::EDGE;   break;
1213   case grpFaceSelection:   aType = SMESH::FACE;   break;
1214   case grpVolumeSelection: aType = SMESH::VOLUME; break;
1215   }
1216
1217   bool anIsOk = false;
1218   QStringList anEntryList;
1219
1220   SMESH::SMESH_GroupBase_var resultGroup;
1221   bool isCreation = false, isConversion = false;
1222
1223   SUIT_OverrideCursor wc;
1224
1225   if (myGrpTypeId == 0)  // standalone
1226   {
1227     if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
1228       return false;
1229
1230     mySelectionMgr->clearSelected();
1231
1232     if (myGroup->_is_nil()) { // creation or conversion
1233       // check if group on geometry is not null
1234       if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
1235         if (myMesh->_is_nil())
1236           return false;
1237         if ( myGroupOnGeom->_is_nil() )
1238           myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
1239         else
1240           myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
1241
1242         myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
1243         myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1244         isConversion    = true;
1245       }
1246     }
1247
1248     if (myGroup->_is_nil()) { // creation
1249       if (myMesh->_is_nil())
1250         return false;
1251
1252       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
1253
1254       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1255       isCreation = true;
1256
1257       if ( mySelectAll->isChecked() ) {
1258         // select all
1259         myGroup->AddFrom(myMesh.in());
1260       }
1261       else {
1262         // select manually
1263
1264         if ( !myFilter->_is_nil() &&
1265              ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
1266         {
1267           myGroup->AddFrom( myFilter );
1268         }
1269         else
1270         {
1271           SMESH::long_array_var anIdList = new SMESH::long_array;
1272           int i, k = myElements->count();
1273           anIdList->length(k);
1274           for (i = 0; i < k; i++) {
1275             anIdList[i] = myElements->item(i)->text().toInt();
1276           }
1277           myGroup->Add(anIdList.inout());
1278         }
1279       }
1280
1281
1282     } else { // edition
1283
1284       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1285       isCreation = false;
1286
1287       if ( mySelectAll->isChecked() ) {
1288         // select all
1289         myGroup->Clear();
1290         myGroup->AddFrom(myMesh.in());
1291       }
1292       else {
1293         QList<int> aAddList;
1294
1295         int i, total = myElements->count();
1296         for (i = 0; i < total; i++) {
1297           int anId = myElements->item(i)->text().toInt();
1298           int idx = myIdList.indexOf(anId);
1299           if ( idx == -1 )
1300             aAddList.append(anId);
1301           else
1302             myIdList.removeAt(idx);
1303         }
1304         if (!aAddList.empty()) {
1305           SMESH::long_array_var anIdList = new SMESH::long_array;
1306           int added = aAddList.count();
1307           anIdList->length(added);
1308           for (i = 0; i < added; i++)
1309             anIdList[i] = aAddList[i];
1310           myGroup->Add(anIdList.inout());
1311         }
1312         if (!myIdList.empty()) {
1313           SMESH::long_array_var anIdList = new SMESH::long_array;
1314           int removed = myIdList.count();
1315           anIdList->length(removed);
1316           for (i = 0; i < removed; i++)
1317             anIdList[i] = myIdList[i];
1318           myGroup->Remove(anIdList.inout());
1319         }
1320         /* init for next operation */
1321         myIdList.clear();
1322         for (i = 0; i < total; i++) {
1323           myIdList.append(myElements->item(i)->text().toInt());
1324         }
1325       }
1326     }
1327
1328     anIsOk = true;
1329   }
1330   else if (myGrpTypeId == 1) // on geom object
1331   {
1332     if (CORBA::is_nil(myGroupOnGeom)) { // creation
1333       if (myMesh->_is_nil() || !myGeomObjects->length())
1334         return false;
1335
1336       _PTR(Study) aStudy = SMESH::getStudy();
1337
1338       if (myGeomObjects->length() == 1) {
1339         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1340                                                     myName->text().toUtf8(),
1341                                                     myGeomObjects[0]);
1342       }
1343       else {
1344         SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1345         if ( aSMESHGen->_is_nil() || myGeomObjects->length() == 0 )
1346           return false;
1347
1348         // create a geometry group
1349         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( myGeomObjects[0] );
1350         if (geomGen->_is_nil())
1351           return false;
1352
1353         GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
1354         if (op->_is_nil())
1355           return false;
1356
1357         // check and add all selected GEOM objects: they must be
1358         // a sub-shapes of the main GEOM and must be of one type
1359         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1360         for ( CORBA::ULong i =0; i < myGeomObjects->length(); i++)
1361         {
1362           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1363           if ( i == 0 )
1364             aGroupType = aSubShapeType;
1365           else if ( aSubShapeType != aGroupType ) {
1366             aGroupType = TopAbs_SHAPE;
1367             break;
1368           }
1369         }
1370
1371         GEOM::GEOM_Object_var  aMeshShape = myMesh->GetShapeToMesh();
1372         GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1373         if ( aGroupVar->_is_nil() )
1374           return false;
1375         op->UnionList(aGroupVar, myGeomObjects);
1376
1377         if (op->IsDone()) {
1378           // publish the GEOM group in study
1379           QString aNewGeomGroupName ( "Auto_group_for_" );
1380           aNewGeomGroupName += myName->text();
1381           SALOMEDS::SObject_var aNewGroupSO =
1382             geomGen->AddInStudy(aGroupVar,
1383                                 aNewGeomGroupName.toUtf8(), aMeshShape);
1384         }
1385
1386         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1387                                                     myName->text().toUtf8(),
1388                                                     aGroupVar);
1389       }
1390       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1391       isCreation = true;
1392
1393     }
1394     else { // edition
1395
1396       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1397       isCreation = false;
1398     }
1399     anIsOk = true;
1400   }
1401   if (myGrpTypeId == 2) // group on filter
1402   {
1403     if ( myFilter->_is_nil() ) return false;
1404
1405     if (CORBA::is_nil(myGroupOnFilter)) // creation
1406     {
1407       if (myMesh->_is_nil())
1408         return false;
1409
1410       myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1411                                                       myName->text().toUtf8(),
1412                                                       myFilter);
1413       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1414       isCreation = true;
1415     }
1416     else
1417     {
1418       myGroupOnFilter->SetFilter( myFilter );
1419
1420       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1421       isCreation = false;
1422     }
1423     anIsOk = true;
1424   }
1425
1426   if ( anIsOk )
1427   {
1428     SALOMEDS::Color aColor = getGroupColor();
1429     resultGroup->SetColor(aColor);
1430
1431     _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1432     if( aMeshGroupSO )
1433       anEntryList.append( aMeshGroupSO->GetID().c_str() );
1434
1435     resultGroup->SetName(myName->text().trimmed().toUtf8());
1436
1437     if ( isCreation )
1438     {
1439       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1440
1441       /* init for the next operation */
1442       setDefaultName();
1443       myElements->clear();
1444       myGroup         = SMESH::SMESH_Group::_nil();
1445       myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
1446       myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1447       myFilter        = SMESH::Filter::_nil();
1448
1449       setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1450     }
1451     else
1452     {
1453       if ( aMeshGroupSO )
1454       {
1455         if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1456         {
1457           Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1458           if ( isConversion ) { // need to reset TVisualObj and actor
1459             SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1460             SMESH::Update( anIO,true);
1461             myActorsList.clear();
1462             anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1463             if ( !anActor ) return false;
1464             myActorsList.append( anActor );
1465           }
1466           anActor->setName(myName->text().toUtf8());
1467           QColor c;
1468           int delta;
1469           switch ( myTypeId ) {
1470           case grpNodeSelection:   anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1471           case grp0DSelection:     anActor->Set0DColor  ( aColor.R, aColor.G, aColor.B ); break;
1472           case grpBallSelection:   anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1473           case grpEdgeSelection:   anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1474           case grpVolumeSelection:
1475             SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1476             anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1477             break;
1478           case grpFaceSelection:
1479           default:
1480             SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1481             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1482             break;
1483           }
1484           // update a visible group according to a changed contents
1485           if ( !isConversion && anActor->GetVisibility() )
1486           {
1487             SMESH::Update( anIO, true );
1488             SMESH::RepaintCurrentView();
1489           }
1490         }
1491       }
1492     }
1493     SMESHGUI::Modified();
1494     mySMESHGUI->updateObjBrowser(true);
1495     mySelectionMgr->clearSelected();
1496
1497     if( LightApp_Application* anApp =
1498         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1499       myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1500   }
1501   return anIsOk;
1502 }
1503
1504 //=================================================================================
1505 // function : onOK()
1506 // purpose  :
1507 //=================================================================================
1508 void SMESHGUI_AdaptDlg::onOK()
1509 {
1510   setIsApplyAndClose( true );
1511   if ( onApply() )
1512     reject();
1513   setIsApplyAndClose( false );
1514
1515   if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1516 }
1517
1518 //=================================================================================
1519 // function : onListSelectionChanged()
1520 // purpose  : Called when selection in element list is changed
1521 //=================================================================================
1522 void SMESHGUI_AdaptDlg::onListSelectionChanged()
1523 {
1524   //MESSAGE( "SMESHGUI_AdaptDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1525   if( myIsBusy || myActorsList.count() == 0 ) return;
1526   myIsBusy = true;
1527
1528   if (myCurrentLineEdit == 0) {
1529     mySelectionMgr->clearSelected();
1530     TColStd_MapOfInteger aIndexes;
1531     QList<QListWidgetItem*> selItems = myElements->selectedItems();
1532     QListWidgetItem* anItem;
1533     foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1534     mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1535     SALOME_ListIO aList;
1536     aList.Append(myActorsList.first()->getIO());
1537     mySelectionMgr->setSelectedObjects(aList,false);
1538   }
1539   myIsBusy = false;
1540 }
1541
1542 //=================================================================================
1543 // function : onObjectSelectionChanged()
1544 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1545 //=================================================================================
1546 void SMESHGUI_AdaptDlg::onObjectSelectionChanged()
1547 {
1548   if ( myIsBusy || !isEnabled()) return;
1549   if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1550
1551   myIsBusy = true;
1552
1553   SALOME_ListIO aList;
1554   mySelectionMgr->selectedObjects( aList );
1555
1556   int aNbSel = aList.Extent();
1557   myElements->clearSelection();
1558
1559   if (myCurrentLineEdit)
1560   {
1561     myCurrentLineEdit->setText( "" );
1562     QString aString = "";
1563
1564     if (myCurrentLineEdit == myMeshGroupLine)
1565     {
1566       mySelectSubMesh->setEnabled(false);
1567       mySelectGroup->setEnabled(false);
1568       myGroupLine->setText( "" );
1569       mySubMeshLine->setText( "" );
1570
1571       myGeomGroupBtn->setEnabled(false);
1572       myGeomGroupLine->setEnabled(false);
1573       myGeomGroupLine->setText( "" );
1574       myGeomObjects = new GEOM::ListOfGO();
1575       myGeomObjects->length(0);
1576
1577       if (myGeomGroupBtn->isChecked())
1578         myGeomGroupBtn->setChecked(false);
1579       if (!myCreate)
1580         myName->setText( "" );
1581
1582       myElements->clear();
1583
1584       if (aNbSel != 1 ) {
1585         myGroup = SMESH::SMESH_Group::_nil();
1586         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1587         restoreShowEntityMode();
1588         myMesh = SMESH::SMESH_Mesh::_nil();
1589         updateGeomPopup();
1590         updateButtons();
1591         myIsBusy = false;
1592         return;
1593       }
1594       Handle(SALOME_InteractiveObject) IO = aList.First();
1595
1596       if (myCreate) {
1597         restoreShowEntityMode();
1598         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1599         setShowEntityMode();
1600         updateGeomPopup();
1601         if (myMesh->_is_nil())
1602         {
1603           updateButtons();
1604           myIsBusy = false;
1605           return;
1606         }
1607
1608         if ( myFilterDlg && !myMesh->_is_nil()){
1609           myFilterDlg->SetMesh( myMesh );
1610         }
1611         myGroup = SMESH::SMESH_Group::_nil();
1612
1613         // NPAL19389: create a group with a selection in another group
1614         // set actor of myMesh, if it is visible, else try
1615         // any visible actor of group or submesh of myMesh
1616         SetAppropriateActor();
1617
1618         setDefaultGroupColor();
1619         if (myName->text().isEmpty())
1620           setDefaultName();
1621
1622         aString = aList.First()->getName();
1623         myMeshGroupLine->setText(aString);
1624         myMeshGroupLine->home( false );
1625
1626         mySelectSubMesh->setEnabled(true);
1627         mySelectGroup->setEnabled(true);
1628         myGeomGroupBtn->setEnabled(true);
1629         myGeomGroupLine->setEnabled(true);
1630         updateButtons();
1631       }
1632       else {
1633         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1634         if (aGroup->_is_nil())
1635         {
1636           myIsBusy = false;
1637           return;
1638         }
1639         myIsBusy = false;
1640
1641         myGroup = SMESH::SMESH_Group::_nil();
1642         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1643
1644         init(aGroup);
1645         myIsBusy = true;
1646         mySelectSubMesh->setEnabled(true);
1647         mySelectGroup->setEnabled(true);
1648       }
1649       myCurrentLineEdit = 0;
1650       myIsBusy = false;
1651       if (!myCreate)
1652         return;
1653
1654       if (myGrpTypeId == 0)
1655       {
1656         if (myTypeId == -1)
1657           onTypeChanged(0);
1658         else
1659         {
1660           myElements->clear();
1661           setSelectionMode(myTypeId);
1662         }
1663       }
1664
1665       myIsBusy = false;
1666       return;
1667
1668     }
1669     else if (myCurrentLineEdit == myGeomGroupLine)
1670     {
1671       myGeomObjects = new GEOM::ListOfGO();
1672
1673       // The mesh SObject
1674       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1675
1676       if (aNbSel == 0 || !aMeshSO)
1677       {
1678         myGeomObjects->length(0);
1679         updateButtons();
1680         myIsBusy = false;
1681         return;
1682       }
1683
1684       myGeomObjects->length(aNbSel);
1685
1686       GEOM::GEOM_Object_var aGeomGroup;
1687       int i = 0;
1688
1689       SALOME_ListIteratorOfListIO anIt (aList);
1690       for (; anIt.More(); anIt.Next())
1691       {
1692         aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1693
1694         // Check if the object is a geometry group
1695         if (CORBA::is_nil(aGeomGroup))
1696           continue;
1697
1698         // Check if group constructed on the same shape as a mesh or on its child
1699
1700         // The main shape of the group
1701         GEOM::GEOM_Object_var aGroupMainShape;
1702         if (aGeomGroup->GetType() == 37)
1703         {
1704           GEOM::GEOM_IGroupOperations_wrap anOp =
1705             SMESH::GetGEOMGen( aGeomGroup )->GetIGroupOperations();
1706           aGroupMainShape = anOp->GetMainShape( aGeomGroup );
1707           // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1708         }
1709         else
1710         {
1711           aGroupMainShape = aGeomGroup;
1712           aGroupMainShape->Register();
1713         }
1714         CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
1715         _PTR(SObject) aGroupMainShapeSO =
1716           SMESH::getStudy()->FindObjectID( entry.in() );
1717
1718         _PTR(SObject) anObj, aRef;
1719         bool isRefOrSubShape = false;
1720         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
1721           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1722             isRefOrSubShape = true;
1723           } else {
1724             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1725             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1726             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1727               if (aRef->GetID() == aFather->GetID())
1728                 isRefOrSubShape = true;
1729               else
1730                 aFather = aFather->GetFather();
1731             }
1732           }
1733         }
1734         if (isRefOrSubShape)
1735           myGeomObjects[i++] = aGeomGroup;
1736       }
1737
1738       myGeomObjects->length(i);
1739       if ( i == 0 )
1740       {
1741         myIsBusy = false;
1742         return;
1743       }
1744
1745       aNbSel = i;
1746     }
1747
1748     if (aNbSel >= 1) {
1749       if (aNbSel > 1) {
1750         if (myCurrentLineEdit == mySubMeshLine)
1751           aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1752         else if (myCurrentLineEdit == myGroupLine)
1753           aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1754         else if (myCurrentLineEdit == myGeomGroupLine)
1755           aString = tr( "%1 Objects" ).arg(aNbSel);
1756       }
1757       else {
1758         aString = aList.First()->getName();
1759       }
1760     }
1761
1762     myCurrentLineEdit->setText(aString);
1763     myCurrentLineEdit->home(false);
1764     // 07.06.2008 skl for IPAL19574:
1765     // change name of group only if it is empty
1766     if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1767       myOldName = myName->text();
1768       myName->blockSignals(true);
1769       myName->setText(aString);
1770       myName->blockSignals(false);
1771     }
1772
1773     updateButtons();
1774   }
1775   else // !myCurrentLineEdit: local selection of nodes or elements
1776   {
1777     if (aNbSel == 1 && myActorsList.count() > 0 )
1778     {
1779       // NPAL19389: create a group with a selection in another group
1780       // Switch myActor to the newly selected one, if the last
1781       // is visible and belongs to group or submesh of myMesh
1782       /*      Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1783       Handle(SALOME_InteractiveObject) selIO = aList.First();
1784       if (curIO->hasEntry() && selIO->hasEntry()) {
1785         const char* selEntry = selIO->getEntry();
1786         if (strcmp(curIO->getEntry(), selEntry) != 0) {
1787           // different objects: selected and myActor
1788           SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1789           if (aViewWindow && aViewWindow->isVisible(selIO)) {
1790             // newly selected actor is visible
1791
1792             // mesh entry
1793             _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1794             if (aSObject) {
1795               CORBA::String_var meshEntry = aSObject->GetID().c_str();
1796               int len = strlen(meshEntry);
1797
1798               if (strncmp(selEntry, meshEntry, len) == 0) {
1799                 // selected object is myMesh or a part of it
1800                 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1801                 if (anActor) {
1802                   myActor = anActor;
1803                   SMESH::SetPickable(myActor);
1804                 }
1805               }
1806             }
1807           }
1808         }
1809       }*/
1810       // NPAL19389 END
1811
1812       QString aListStr = "";
1813       int aNbItems = 0;
1814       if (myTypeId == 0) {
1815         QListIterator<SMESH_Actor*> it( myActorsList );
1816         while ( it.hasNext() ) {
1817           QString tmpStr;
1818           aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1819           aListStr += tmpStr;
1820         }
1821       } else {
1822         QListIterator<SMESH_Actor*> it( myActorsList );
1823         while ( it.hasNext() ) {
1824           QString tmpStr;
1825           aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1826           aListStr += tmpStr;
1827         }
1828       }
1829       if (aNbItems > 0) {
1830         QListWidgetItem* anItem;
1831         QList<QListWidgetItem*> listItemsToSel;
1832         QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1833         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1834           QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1835           foreach(anItem, found)
1836             if (!anItem->isSelected())
1837               listItemsToSel.push_back(anItem);
1838         }
1839         bool blocked = myElements->signalsBlocked();
1840         myElements->blockSignals(true);
1841         foreach(anItem, listItemsToSel) anItem->setSelected(true);
1842         myElements->blockSignals(blocked);
1843         onListSelectionChanged();
1844         listItemsToSel.clear();
1845       }
1846     }
1847   }
1848
1849   if (myActorsList.count() == 0) {
1850     if (!myGroup->_is_nil()) {
1851       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1852       if ( anActor )
1853         myActorsList.append( anActor  );
1854     }
1855     else if(!myGroupOnGeom->_is_nil()) {
1856       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1857       if ( anActor )
1858         myActorsList.append( anActor );
1859     }
1860     else {
1861       SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1862       if ( anActor )
1863         myActorsList.append( anActor );
1864     }
1865   }
1866
1867   // somehow, if we display the mesh, while selecting from another actor,
1868   // the mesh becomes pickable, and there is no way to select any element
1869   if (myActorsList.count() > 0) {
1870     QListIterator<SMESH_Actor*> it( myActorsList );
1871     while ( it.hasNext() ) {
1872       SMESH_Actor* anActor = it.next();
1873       if ( IsActorVisible(anActor) )
1874         anActor->SetPickable(true);
1875     }
1876   }
1877
1878   myIsBusy = false;
1879 }
1880
1881 //=================================================================================
1882 // function : onSelectAll()
1883 // purpose  : Called when "Select all" is checked
1884 //=================================================================================
1885 void SMESHGUI_AdaptDlg::onSelectAll()
1886 {
1887   bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1888
1889   myElementsLab->setEnabled( !noElemsModif );
1890   myElements->setEnabled   ( !noElemsModif );
1891   myFilterBtn->setEnabled  ( !noElemsModif );
1892   myAddBtn->setEnabled     ( !noElemsModif );
1893   myRemoveBtn->setEnabled  ( !noElemsModif );
1894   mySortBtn->setEnabled    ( !noElemsModif );
1895   mySelectBox->setEnabled  ( !noElemsModif );
1896   myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1897   if ( noElemsModif ) mySMESHGUI->ResetState();
1898   else                mySMESHGUI->SetState(800);
1899
1900   int selMode     = mySelectionMode;
1901   mySelectionMode = grpNoSelection;
1902   setSelectionMode( selMode );
1903   updateButtons();
1904 }
1905
1906 //=================================================================================
1907 // function : onSelectSubMesh()
1908 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1909 //=================================================================================
1910 void SMESHGUI_AdaptDlg::onSelectSubMesh(bool on)
1911 {
1912   if (on) {
1913     if (mySelectGroup->isChecked()) {
1914       mySelectGroup->setChecked(false);
1915     }
1916     //VSR: else if (mySelectGeomGroup->isChecked()) {
1917     //VSR:   mySelectGeomGroup->setChecked(false);
1918     //VSR: }
1919     myCurrentLineEdit = mySubMeshLine;
1920     setSelectionMode(grpSubMeshSelection);
1921   }
1922   else {
1923     mySubMeshLine->setText( "" );
1924     myCurrentLineEdit = 0;
1925     if (myTypeId != -1)
1926       setSelectionMode(myTypeId);
1927   }
1928   mySubMeshBtn->setEnabled(on);
1929   mySubMeshLine->setEnabled(on);
1930 }
1931
1932
1933 //=================================================================================
1934 // function : (onSelectGroup)
1935 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1936 //=================================================================================
1937 void SMESHGUI_AdaptDlg::onSelectGroup(bool on)
1938 {
1939   if (on) {
1940     if (mySelectSubMesh->isChecked()) {
1941       mySelectSubMesh->setChecked(false);
1942     }
1943     myCurrentLineEdit = myGroupLine;
1944     setSelectionMode(grpGroupSelection);
1945   }
1946   else {
1947     myGroupLine->setText( "" );
1948     myCurrentLineEdit = 0;
1949     if (myTypeId != -1)
1950       setSelectionMode(myTypeId);
1951   }
1952   myGroupBtn->setEnabled(on);
1953   myGroupLine->setEnabled(on);
1954 }
1955
1956
1957 //=================================================================================
1958 // function : (onSelectGeomGroup)
1959 // purpose  : Called when group type changed. on == "on geometry" or "on filter"
1960 //=================================================================================
1961 void SMESHGUI_AdaptDlg::onSelectGeomGroup(bool on)
1962 {
1963   if (on) {
1964     if (mySelectSubMesh->isChecked()) {
1965       mySelectSubMesh->setChecked(false);
1966     }
1967     else if (mySelectGroup->isChecked()) {
1968       mySelectGroup->setChecked(false);
1969     }
1970     if ( myGrpTypeId == 1 ) { // on geometry
1971       myCurrentLineEdit = myGeomGroupLine;
1972       updateGeomPopup();
1973     }
1974     else { // on filter
1975       myCurrentLineEdit = 0;
1976     }
1977     setSelectionMode(grpAllSelection);
1978   }
1979   else {
1980     myGeomGroupBtn->setChecked(false);
1981     myGeomObjects->length(0);
1982     myGeomGroupLine->setText( "" );
1983     myCurrentLineEdit = 0;
1984     if (myTypeId != -1)
1985       setSelectionMode( myTypeId );
1986   }
1987 }
1988
1989 //=================================================================================
1990 // function : setCurrentSelection()
1991 // purpose  :
1992 //=================================================================================
1993 void SMESHGUI_AdaptDlg::setCurrentSelection()
1994 {
1995   QPushButton* send = (QPushButton*)sender();
1996   myCurrentLineEdit = 0;
1997   if (send == myMeshGroupBtn) {
1998     disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1999     mySelectionMgr->clearSelected();
2000     if (myCreate)
2001       setSelectionMode(grpMeshSelection);
2002     else
2003       setSelectionMode(grpGroupSelection);
2004     connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
2005     myCurrentLineEdit = myMeshGroupLine;
2006     onObjectSelectionChanged();
2007   }
2008   else if (send == mySubMeshBtn) {
2009     myCurrentLineEdit = mySubMeshLine;
2010     onObjectSelectionChanged();
2011   }
2012   else if (send == myGroupBtn) {
2013     myCurrentLineEdit = myGroupLine;
2014     onObjectSelectionChanged();
2015   }
2016 }
2017
2018
2019 //=================================================================================
2020 // function : setFilters()
2021 // purpose  : SLOT. Called when "Filter" button pressed.
2022 //=================================================================================
2023 void SMESHGUI_AdaptDlg::setFilters()
2024 {
2025   if(myMesh->_is_nil()) {
2026     SUIT_MessageBox::critical(this,
2027                               tr("SMESH_ERROR"),
2028                               tr("NO_MESH_SELECTED"));
2029    return;
2030   }
2031
2032   SMESH::ElementType aType = SMESH::ALL;
2033   switch ( myTypeId )
2034   {
2035     case grpNodeSelection:   aType = SMESH::NODE;   break;
2036     case grp0DSelection:     aType = SMESH::ELEM0D; break;
2037     case grpBallSelection:   aType = SMESH::BALL;   break;
2038     case grpEdgeSelection:   aType = SMESH::EDGE;   break;
2039     case grpFaceSelection:   aType = SMESH::FACE;   break;
2040     case grpVolumeSelection: aType = SMESH::VOLUME; break;
2041     default:                 return;
2042   }
2043
2044   if ( myFilterDlg == 0 )
2045   {
2046     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
2047     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
2048   }
2049   else
2050     myFilterDlg->Init( aType );
2051
2052   if ( !myGroupOnFilter->_is_nil() )
2053   {
2054     myFilterDlg->SetFilter( myFilter, aType );
2055     myFilterDlg->Init( aType );
2056   }
2057
2058   bool isStandalone = ( sender() == myFilterBtn );
2059   myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
2060                            /*diffSources=*/isStandalone );
2061   myFilterDlg->SetMesh( myMesh );
2062   myFilterDlg->SetGroup( myGroupOnFilter );
2063   myFilterDlg->SetSelection();
2064   myFilterDlg->SetSourceWg( myElements, false );
2065
2066   myFilterDlg->show();
2067 }
2068
2069 //=================================================================================
2070 // function : onFilterAccepted()
2071 // purpose  : SLOT. Called when Filter dlg closed with OK button.
2072 //            Uncheck "Select submesh" and "Select group" checkboxes
2073 //=================================================================================
2074 void SMESHGUI_AdaptDlg::onFilterAccepted()
2075 {
2076   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
2077   {
2078     mySelectionMode = myTypeId;
2079     mySelectSubMesh->setChecked( false );
2080     mySelectGroup->setChecked( false );
2081   }
2082   // get a filter from myFilterDlg
2083   myFilter = myFilterDlg->GetFilter();
2084   if ( !myFilter->_is_nil() ) {
2085     SMESH::Predicate_var perdicate = myFilter->GetPredicate();
2086     if ( perdicate->_is_nil() )
2087       myFilter = SMESH::Filter::_nil();
2088   }
2089   // set mesh to myFilter
2090   if ( !myFilter->_is_nil() ) {
2091     SMESH::SMESH_Mesh_var mesh = myMesh;
2092     if ( mesh->_is_nil() ) {
2093       if ( !myGroup->_is_nil() )
2094         mesh = myGroup->GetMesh();
2095       else if ( !myGroupOnGeom->_is_nil() )
2096         mesh = myGroupOnGeom->GetMesh();
2097       else if ( !myGroupOnFilter->_is_nil() )
2098         mesh = myGroupOnFilter->GetMesh();
2099     }
2100     myFilter->SetMesh( mesh );
2101
2102     // highlight ids if selection changed in the Viewer (IPAL52924)
2103     myCurrentLineEdit = 0;
2104     onObjectSelectionChanged();
2105   }
2106
2107   updateButtons();
2108 }
2109
2110 //=================================================================================
2111 // function : onAdd()
2112 // purpose  :
2113 //=================================================================================
2114 void SMESHGUI_AdaptDlg::onAdd()
2115 {
2116   SALOME_ListIO aList;
2117   mySelectionMgr->selectedObjects( aList );
2118
2119   int aNbSel = aList.Extent();
2120
2121   if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
2122
2123   SUIT_OverrideCursor wc;
2124
2125   myIsBusy = true;
2126   int sizeBefore = myElements->count();
2127
2128   SMESH::ElementType aType = SMESH::ALL;
2129   switch(myTypeId) {
2130   case grpNodeSelection:
2131     aType = SMESH::NODE;
2132     mySelector->SetSelectionMode(NodeSelection);
2133     break;
2134   case grpBallSelection:
2135     aType = SMESH::BALL;
2136     mySelector->SetSelectionMode(BallSelection);
2137     break;
2138   case grp0DSelection:
2139     aType = SMESH::ELEM0D;
2140     mySelector->SetSelectionMode(Elem0DSelection);
2141     break;
2142   case grpEdgeSelection:
2143     aType = SMESH::EDGE;
2144     mySelector->SetSelectionMode(EdgeSelection);
2145     break;
2146   case grpFaceSelection:
2147     aType = SMESH::FACE;
2148     mySelector->SetSelectionMode(FaceSelection);
2149     break;
2150   case grpVolumeSelection:
2151     aType = SMESH::VOLUME;
2152     mySelector->SetSelectionMode(VolumeSelection);
2153     break;
2154   default:
2155     mySelector->SetSelectionMode(ActorSelection);
2156   }
2157
2158   QListWidgetItem* anItem = 0;
2159   QList<QListWidgetItem*> listItemsToSel;
2160
2161   if ( myCurrentLineEdit == 0 )
2162   {
2163     //if (aNbSel != 1) { myIsBusy = false; return; }
2164     QString aListStr = "";
2165     int aNbItems = 0;
2166     if (myTypeId == 0) {
2167       QListIterator<SMESH_Actor*> it( myActorsList );
2168       while ( it.hasNext() ) {
2169         QString tmpStr;
2170         aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
2171         aListStr += tmpStr;
2172       }
2173     }
2174     else {
2175       QListIterator<SMESH_Actor*> it( myActorsList );
2176       while ( it.hasNext() ) {
2177         QString tmpStr;
2178         aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
2179         aListStr += tmpStr;
2180       }
2181     }
2182     if (aNbItems > 0) {
2183       QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
2184       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
2185         QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
2186         if (found.count() == 0) {
2187           anItem = new QListWidgetItem(*it);
2188           myElements->addItem(anItem);
2189           if (!anItem->isSelected())
2190             listItemsToSel.push_back(anItem);
2191         }
2192         else {
2193           foreach(anItem, found)
2194             if (!anItem->isSelected())
2195               listItemsToSel.push_back(anItem);
2196         }
2197       }
2198       bool blocked = myElements->signalsBlocked();
2199       myElements->blockSignals(true);
2200       foreach(anItem, listItemsToSel) anItem->setSelected(true);
2201       myElements->blockSignals(blocked);
2202       onListSelectionChanged();
2203       listItemsToSel.clear();
2204     }
2205   }
2206   else if ( myCurrentLineEdit == mySubMeshLine )
2207   {
2208     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2209
2210     SALOME_ListIO aList;
2211     mySelectionMgr->selectedObjects( aList );
2212
2213     SALOME_ListIteratorOfListIO anIt (aList);
2214     for ( ; anIt.More(); anIt.Next()) {
2215       SMESH::SMESH_subMesh_var aSubMesh =
2216         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2217       if (!aSubMesh->_is_nil()) {
2218         // check if mesh is the same
2219         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2220           try {
2221             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
2222             int k = anElements->length();
2223             for (int i = 0; i < k; i++) {
2224               QString aText = QString::number(anElements[i]);
2225               QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2226               if (found.count() == 0) {
2227                 anItem = new QListWidgetItem(aText);
2228                 myElements->addItem(anItem);
2229                 if (!anItem->isSelected())
2230                   listItemsToSel.push_back(anItem);
2231               }
2232               else {
2233                 foreach(anItem, found)
2234                   if (!anItem->isSelected())
2235                     listItemsToSel.push_back(anItem);
2236               }
2237             }
2238             bool blocked = myElements->signalsBlocked();
2239             myElements->blockSignals(true);
2240             foreach(anItem, listItemsToSel) anItem->setSelected(true);
2241             myElements->blockSignals(blocked);
2242             onListSelectionChanged();
2243             listItemsToSel.clear();
2244           }
2245           catch (const SALOME::SALOME_Exception& ex) {
2246             SalomeApp_Tools::QtCatchCorbaException(ex);
2247           }
2248         }
2249       }
2250     }
2251     mySelectSubMesh->setChecked(false);
2252     myIsBusy = false;
2253     onListSelectionChanged();
2254
2255   }
2256   else if ( myCurrentLineEdit == myGroupLine )
2257   {
2258     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2259     SALOME_ListIO aList;
2260     mySelectionMgr->selectedObjects( aList );
2261
2262     SALOME_ListIteratorOfListIO anIt (aList);
2263     for ( ; anIt.More(); anIt.Next()) {
2264       SMESH::SMESH_GroupBase_var aGroup =
2265         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
2266       if (!aGroup->_is_nil()) {
2267         // check if mesh is the same
2268         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2269           SMESH::long_array_var anElements = aGroup->GetListOfID();
2270           int k = anElements->length();
2271           for (int i = 0; i < k; i++) {
2272             QString aText = QString::number(anElements[i]);
2273             QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2274             if (found.count() == 0) {
2275               anItem = new QListWidgetItem(aText);
2276               myElements->addItem(anItem);
2277               if (!anItem->isSelected())
2278                 listItemsToSel.push_back(anItem);
2279             }
2280             else {
2281               foreach(anItem, found)
2282                 if (!anItem->isSelected())
2283                   listItemsToSel.push_back(anItem);
2284             }
2285           }
2286           bool blocked = myElements->signalsBlocked();
2287           myElements->blockSignals(true);
2288           foreach(anItem, listItemsToSel) anItem->setSelected(true);
2289           myElements->blockSignals(blocked);
2290           onListSelectionChanged();
2291           listItemsToSel.clear();
2292         }
2293       }
2294     }
2295     mySelectGroup->setChecked(false);
2296     myIsBusy = false;
2297     onListSelectionChanged();
2298
2299   }
2300   else if ( myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1 )
2301   {
2302     GEOM::GEOM_IGroupOperations_wrap aGroupOp =
2303       SMESH::GetGEOMGen( myGeomObjects[0] )->GetIGroupOperations();
2304
2305     SMESH::ElementType aGroupType = SMESH::ALL;
2306     switch(aGroupOp->GetType(myGeomObjects[0])) {
2307     case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
2308     case TopAbs_EDGE:   aGroupType = SMESH::EDGE; break;
2309     case TopAbs_FACE:   aGroupType = SMESH::FACE; break;
2310     case TopAbs_SOLID:  aGroupType = SMESH::VOLUME; break;
2311     default: myIsBusy = false; return;
2312     }
2313
2314     if (aGroupType == aType) {
2315       _PTR(SObject) aGroupSO =
2316         //SMESH::getStudy()->FindObjectIOR(SMESH::getStudy()->ConvertObjectToIOR(myGeomGroup));
2317         SMESH::getStudy()->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2318       // Construct filter
2319       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2320       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2321       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2322       aBelongToGeom->SetGeom(myGeomObjects[0]);
2323       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2324       aBelongToGeom->SetElementType(aType);
2325       aFilter->SetPredicate(aBelongToGeom);
2326
2327       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2328
2329       int k = anElements->length();
2330       for (int i = 0; i < k; i++) {
2331         QString aText = QString::number(anElements[i]);
2332         QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2333         if (found.count() == 0) {
2334           anItem = new QListWidgetItem(aText);
2335           myElements->addItem(anItem);
2336           if (!anItem->isSelected())
2337             listItemsToSel.push_back(anItem);
2338         }
2339         else {
2340           foreach(anItem, found)
2341             if (!anItem->isSelected())
2342               listItemsToSel.push_back(anItem);
2343         }
2344       }
2345       bool blocked = myElements->signalsBlocked();
2346       myElements->blockSignals(true);
2347       foreach(anItem, listItemsToSel) anItem->setSelected(true);
2348       myElements->blockSignals(blocked);
2349       onListSelectionChanged();
2350       listItemsToSel.clear();
2351     }
2352
2353     //VSR: mySelectGeomGroup->setChecked(false);
2354     myIsBusy = false;
2355     onListSelectionChanged();
2356   }
2357   myIsBusy = false;
2358   if ( sizeBefore < myElements->count() )
2359     ++myNbChangesOfContents;
2360   //  mySelectionMgr->clearSelected();
2361   updateButtons();
2362 }
2363
2364 //=================================================================================
2365 // function : onRemove()
2366 // purpose  :
2367 //=================================================================================
2368 void SMESHGUI_AdaptDlg::onRemove()
2369 {
2370   myIsBusy = true;
2371   int sizeBefore = myElements->count();
2372
2373   if (myCurrentLineEdit == 0) {
2374     QList<QListWidgetItem*> selItems = myElements->selectedItems();
2375     QListWidgetItem* item;
2376     foreach(item, selItems) delete item;
2377   } else {
2378     SALOME_ListIO aList;
2379     mySelectionMgr->selectedObjects( aList );
2380
2381     int aNbSel = aList.Extent();
2382
2383     if (aNbSel == 0) { myIsBusy = false; return; }
2384
2385     SMESH::ElementType aType = SMESH::ALL;
2386     switch(myTypeId) {
2387     case grpNodeSelection:   aType = SMESH::NODE;   break;
2388     case grp0DSelection:     aType = SMESH::ELEM0D; break;
2389     case grpBallSelection:   aType = SMESH::BALL;   break;
2390     case grpEdgeSelection:   aType = SMESH::EDGE;   break;
2391     case grpFaceSelection:   aType = SMESH::FACE;   break;
2392     case grpVolumeSelection: aType = SMESH::VOLUME; break;
2393     }
2394
2395     if (myCurrentLineEdit == mySubMeshLine) {
2396       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2397       SALOME_ListIO aList;
2398       mySelectionMgr->selectedObjects( aList );
2399
2400       SALOME_ListIteratorOfListIO anIt (aList);
2401       for ( ; anIt.More(); anIt.Next()) {
2402         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2403         if (!aSubMesh->_is_nil()) {
2404           // check if mesh is the same
2405           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2406             if (aType == SMESH::NODE) {
2407               try {
2408                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2409                 int k = anElements->length();
2410                 for (int i = 0; i < k; i++) {
2411                   QList<QListWidgetItem*> found =
2412                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2413                   QListWidgetItem* anItem;
2414                   foreach(anItem, found) delete anItem;
2415                 }
2416               }
2417               catch (const SALOME::SALOME_Exception& ex) {
2418                 SalomeApp_Tools::QtCatchCorbaException(ex);
2419               }
2420             }
2421             else {
2422               try {
2423                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2424                 int k = anElements->length();
2425                 for (int i = 0; i < k; i++) {
2426                   QList<QListWidgetItem*> found =
2427                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2428                   QListWidgetItem* anItem;
2429                   foreach(anItem, found) delete anItem;
2430                 }
2431               }
2432               catch (const SALOME::SALOME_Exception& ex) {
2433                 SalomeApp_Tools::QtCatchCorbaException(ex);
2434               }
2435             }
2436           }
2437         }
2438       }
2439     }
2440     else if (myCurrentLineEdit == myGroupLine) {
2441       SALOME_ListIO aList;
2442       mySelectionMgr->selectedObjects( aList );
2443
2444       SALOME_ListIteratorOfListIO anIt (aList);
2445       for ( ; anIt.More(); anIt.Next()) {
2446         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2447         if (!aGroup->_is_nil()) {
2448           // check if mesh is the same
2449           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2450             SMESH::long_array_var anElements = aGroup->GetListOfID();
2451             int k = anElements->length();
2452             for (int i = 0; i < k; i++) {
2453               QList<QListWidgetItem*> found =
2454                 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2455               QListWidgetItem* anItem;
2456               foreach(anItem, found) delete anItem;
2457             }
2458           }
2459         }
2460       }
2461     }
2462   }
2463   myIsBusy = false;
2464   if ( sizeBefore > myElements->count() )
2465     myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2466   updateButtons();
2467 }
2468
2469 //=================================================================================
2470 // function : onSort()
2471 // purpose  :
2472 //=================================================================================
2473 void SMESHGUI_AdaptDlg::onSort()
2474 {
2475   // PAL5412: sorts items in ascending by "string" value
2476   // myElements->sort(true);
2477   // myElements->update();
2478   int i, k = myElements->count();
2479   if (k > 0) {
2480     myIsBusy = true;
2481     QList<int> aSelected;
2482     std::vector<int> anArray(k);
2483     //    QMemArray<int> anArray(k);
2484     // fill the array
2485     for (i = 0; i < k; i++) {
2486       int id = myElements->item(i)->text().toInt();
2487       anArray[i] = id;
2488       if (myElements->item(i)->isSelected())
2489         aSelected.append(id);
2490     }
2491     // sort & update list
2492     std::sort(anArray.begin(), anArray.end());
2493     //    anArray.sort();
2494     myElements->clear();
2495     QListWidgetItem* anItem;
2496     QList<QListWidgetItem*> listItemsToSel;
2497     for (i = 0; i < k; i++) {
2498       anItem = new QListWidgetItem(QString::number(anArray[i]));
2499       myElements->addItem(anItem);
2500       if (aSelected.contains(anArray[i]))
2501         listItemsToSel.push_back(anItem);
2502     }
2503     bool blocked = myElements->signalsBlocked();
2504     myElements->blockSignals(true);
2505     foreach(anItem, listItemsToSel) anItem->setSelected(true);
2506     myElements->blockSignals(blocked);
2507     listItemsToSel.clear();
2508     myIsBusy = false;
2509   }
2510 }
2511
2512 //=================================================================================
2513 // function : onVisibilityChanged()
2514 // purpose  :
2515 //=================================================================================
2516 void SMESHGUI_AdaptDlg::onVisibilityChanged()
2517 {
2518   SetAppropriateActor();
2519 }
2520
2521 //=================================================================================
2522 // function : SMESHGUI_AdaptDlg::reject
2523 // purpose  : SLOT called when "Close" button pressed. Close dialog
2524 //=================================================================================
2525 void SMESHGUI_AdaptDlg::reject()
2526 {
2527   if (SMESH::GetCurrentVtkView()) {
2528     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2529     SMESH::SetPointRepresentation(false);
2530     SMESH::SetPickable();
2531     restoreShowEntityMode();
2532   }
2533
2534   if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2535     SUIT_DataOwnerPtrList aList;
2536     aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2537     mySelectionMgr->setSelected( aList );
2538   }
2539   else
2540     mySelectionMgr->clearSelected();
2541   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2542     aViewWindow->SetSelectionMode(ActorSelection);
2543   mySelectionMgr->clearFilters();
2544   mySMESHGUI->ResetState();
2545
2546   QDialog::reject();
2547
2548   if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2549 }
2550
2551 //=================================================================================
2552 // function : onOpenView()
2553 // purpose  :
2554 //=================================================================================
2555 void SMESHGUI_AdaptDlg::onOpenView()
2556 {
2557   if ( mySelector ) {
2558     SMESH::SetPointRepresentation(false);
2559   }
2560   else {
2561     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
2562     mySMESHGUI->EmitSignalDeactivateDialog();
2563     setEnabled(true);
2564   }
2565 }
2566
2567 //=================================================================================
2568 // function : onCloseView()
2569 // purpose  :
2570 //=================================================================================
2571 void SMESHGUI_AdaptDlg::onCloseView()
2572 {
2573   onDeactivate();
2574   mySelector = 0;
2575 }
2576
2577 //=================================================================================
2578 // function : onHelp()
2579 // purpose  :
2580 //=================================================================================
2581 void SMESHGUI_AdaptDlg::onHelp()
2582 {
2583   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2584   if (app)
2585   {
2586     app->onHelpContextModule
2587       ( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString(""), myHelpFileName );
2588   }
2589   else
2590   {
2591 #ifdef WIN32
2592     QString platform = "winapplication";
2593 #else
2594     QString platform = "application";
2595 #endif
2596     SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2597                              tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2598                              arg(app->resourceMgr()->stringValue( "ExternalBrowser", platform)).
2599                              arg(myHelpFileName));
2600   }
2601 }
2602
2603 //=================================================================================
2604 // function : SMESHGUI_AdaptDlg::onDeactivate
2605 // purpose  : SLOT called when dialog must be deactivated
2606 //=================================================================================
2607 void SMESHGUI_AdaptDlg::onDeactivate()
2608 {
2609   mySMESHGUI->ResetState();
2610   setEnabled(false);
2611 }
2612
2613 //=================================================================================
2614 // function : SMESHGUI_AdaptDlg::enterEvent
2615 // purpose  : Event filter
2616 //=================================================================================
2617 void SMESHGUI_AdaptDlg::enterEvent (QEvent*)
2618 {
2619   if (!isEnabled()) {
2620     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2621     if ( aViewWindow && !mySelector) {
2622       mySelector = aViewWindow->GetSelector();
2623     }
2624     mySMESHGUI->EmitSignalDeactivateDialog();
2625     setEnabled(true);
2626     mySelectionMode = grpNoSelection;
2627     setSelectionMode(myTypeId);
2628     mySMESHGUI->SetActiveDialogBox(this);
2629     if ( mySelectBox->isEnabled() ) mySMESHGUI->SetState(800);
2630     else                            mySMESHGUI->ResetState();
2631   }
2632 }
2633
2634 //=================================================================================
2635 // function : keyPressEvent()
2636 // purpose  :
2637 //=================================================================================
2638 void SMESHGUI_AdaptDlg::keyPressEvent( QKeyEvent* e )
2639 {
2640   QDialog::keyPressEvent( e );
2641   if ( e->isAccepted() )
2642     return;
2643
2644   if ( e->key() == Qt::Key_F1 )
2645   {
2646     e->accept();
2647     onHelp();
2648   }
2649 }
2650
2651 //================================================================================
2652 /*!
2653  * \brief Enable showing of the popup when Geometry selection btn is clicked
2654  * \param enable - true to enable
2655  */
2656 //================================================================================
2657
2658 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2659
2660 void SMESHGUI_AdaptDlg::updateGeomPopup()
2661 {
2662   bool enable = false;
2663
2664   if ( !myMesh->_is_nil() )
2665     enable = myMesh->NbEdges() > 0;
2666
2667   if ( myGeomGroupBtn )
2668   {
2669     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2670     if ( enable ) {
2671       if ( !myGeomPopup ) {
2672         myGeomPopup = new QMenu(this);
2673         myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2674         myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2675         connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2676       }
2677       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2678     }
2679   }
2680 }
2681
2682
2683 //=================================================================================
2684 // function : onGeomSelectionButton()
2685 // purpose  :
2686 //=================================================================================
2687 void SMESHGUI_AdaptDlg::onGeomSelectionButton(bool isBtnOn)
2688 {
2689   if ( myGeomPopup && isBtnOn )
2690   {
2691     myCurrentLineEdit = myGeomGroupLine;
2692     QAction* a = myGeomPopup->exec( QCursor::pos() );
2693     if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2694       setSelectionMode(grpGeomSelection);
2695   }
2696   else if (!isBtnOn)
2697   {
2698     myCurrentLineEdit = 0;
2699     setSelectionMode(grpAllSelection);
2700   }
2701 }
2702
2703 //=================================================================================
2704 // function : onGeomPopup()
2705 // purpose  :
2706 //=================================================================================
2707 void SMESHGUI_AdaptDlg::onGeomPopup( QAction* a )
2708 {
2709   int index = myActions[a];
2710   if ( index == GEOM_BY_MESH_INDEX )
2711   {
2712     mySelectionMode = grpNoSelection;
2713     if ( !myShapeByMeshOp ) {
2714       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2715       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2716               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2717       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2718               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2719     }
2720     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2721     if ( !myMesh->_is_nil() ) {
2722       myIsBusy = true;
2723       hide(); // stop processing selection
2724       myIsBusy = false;
2725       myShapeByMeshOp->setModule( mySMESHGUI );
2726       myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2727       myShapeByMeshOp->SetMesh( myMesh );
2728       myShapeByMeshOp->start();
2729     }
2730   }
2731 }
2732
2733 //================================================================================
2734 /*!
2735  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2736  */
2737 //================================================================================
2738
2739 void SMESHGUI_AdaptDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2740 {
2741   if ( myShapeByMeshOp == op ) {
2742     mySMESHGUI->getApp()->updateObjectBrowser();
2743     show();
2744     // Select a found geometry object
2745     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2746     if ( !aGeomVar->_is_nil() )
2747     {
2748       QString ID = aGeomVar->GetStudyEntry();
2749       if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toLatin1().data() )) {
2750         SALOME_ListIO anIOList;
2751         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2752           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2753         anIOList.Append( anIO );
2754         mySelectionMgr->setSelectedObjects( anIOList, false );
2755         onObjectSelectionChanged();
2756       }
2757     }
2758   }
2759 }
2760
2761 //================================================================================
2762 /*!
2763  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2764  */
2765 //================================================================================
2766
2767 void SMESHGUI_AdaptDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2768 {
2769   if ( myShapeByMeshOp == op )
2770   {
2771     show();
2772     setSelectionMode(grpGeomSelection);
2773   }
2774 }
2775
2776 //=================================================================================
2777 // function : setGroupColor()
2778 // purpose  :
2779 //=================================================================================
2780 void SMESHGUI_AdaptDlg::setGroupColor( const SALOMEDS::Color& theColor )
2781 {
2782   QColor aQColor( (int)( theColor.R * 255.0 ),
2783                   (int)( theColor.G * 255.0 ),
2784                   (int)( theColor.B * 255.0 ) );
2785   setGroupQColor( aQColor );
2786 }
2787
2788 //=================================================================================
2789 // function : getGroupColor()
2790 // purpose  :
2791 //=================================================================================
2792 SALOMEDS::Color SMESHGUI_AdaptDlg::getGroupColor() const
2793 {
2794   QColor aQColor = getGroupQColor();
2795
2796   SALOMEDS::Color aColor;
2797   aColor.R = (float)aQColor.red() / 255.0;
2798   aColor.G = (float)aQColor.green() / 255.0;
2799   aColor.B = (float)aQColor.blue() / 255.0;
2800
2801   return aColor;
2802 }
2803
2804 //=================================================================================
2805 // function : setGroupQColor()
2806 // purpose  :
2807 //=================================================================================
2808 void SMESHGUI_AdaptDlg::setGroupQColor( const QColor& theColor )
2809 {
2810   if( theColor.isValid() )
2811     myColorBtn->setColor( theColor );
2812 }
2813
2814 //=================================================================================
2815 // function : getGroupQColor()
2816 // purpose  :
2817 //=================================================================================
2818 QColor SMESHGUI_AdaptDlg::getGroupQColor() const
2819 {
2820   return myColorBtn->color();
2821 }
2822
2823 //=================================================================================
2824 // function : setDefaultGroupColor()
2825 // purpose  :
2826 //=================================================================================
2827 void SMESHGUI_AdaptDlg::setDefaultGroupColor()
2828 {
2829   if( myMesh->_is_nil() )
2830     return;
2831
2832   bool isAutoColor = myMesh->GetAutoColor();
2833
2834   QColor aQColor = myColorBtn->color();
2835   if( !isAutoColor )
2836   {
2837     if ( !aQColor.isValid() ) {
2838       int r = 0, g = 0, b = 0;
2839       SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2840       aQColor.setRgb( r, g, b );
2841     }
2842   }
2843   else
2844   {
2845 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
2846     SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2847 #else                     // old algorithm  for auto-colors
2848     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2849
2850     QList<SALOMEDS::Color> aReservedColors;
2851     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2852     {
2853       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2854       SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2855       aReservedColors.append( aReservedColor );
2856     }
2857
2858     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2859 #endif                    // SIMPLE_AUTOCOLOR
2860
2861     aQColor.setRgb( (int)( aColor.R * 255.0 ),
2862                     (int)( aColor.G * 255.0 ),
2863                     (int)( aColor.B * 255.0 ) );
2864
2865   }
2866
2867   setGroupQColor( aQColor );
2868 }
2869
2870 //=================================================================================
2871 // function : SetAppropriateActor()
2872 // purpose  : Find more appropriate of visible actors, set it to myActor, allow picking
2873 //            NPAL19389: create a group with a selection in another group.
2874 //            if mesh actor is not visible - find any first visible group or sub-mesh
2875 //=================================================================================
2876 bool SMESHGUI_AdaptDlg::SetAppropriateActor()
2877 {
2878   bool isActor = false;
2879   myActorsList.clear();
2880
2881   if (myMesh->_is_nil()) return false;
2882
2883   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2884
2885   if (myGrpTypeGroup->checkedId() > 0) {   // try current group on geometry actor
2886     SMESH_Actor* anActor = 0;
2887     if (!myGroupOnGeom->_is_nil())
2888       anActor = SMESH::FindActorByObject(myGroupOnGeom);
2889     if (!myGroupOnFilter->_is_nil())
2890       anActor = SMESH::FindActorByObject(myGroupOnFilter);
2891     if (anActor && anActor->hasIO())
2892     {
2893       isActor = true;
2894       if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2895         isActor = false;
2896       else
2897         myActorsList.append(anActor);
2898     }
2899     return anActor;
2900   }
2901   else {
2902     // try mesh actor
2903     SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2904     if (anActor && anActor->hasIO()) {
2905       isActor = true;
2906       if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2907         isActor = false;
2908       else
2909         myActorsList.append(anActor);
2910     }
2911
2912     // try group actor
2913     SMESH_Actor* aGroupActor = 0;
2914     if (!isActor && !myGroup->_is_nil()) {
2915       aGroupActor = SMESH::FindActorByObject(myGroup);
2916       if (aGroupActor && aGroupActor->hasIO())
2917         myActorsList.append(aGroupActor);
2918     }
2919
2920     // try any visible actor of group or sub-mesh of current mesh
2921     if (aViewWindow) {
2922       // mesh entry
2923       _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2924       if (aSObject) {
2925         CORBA::String_var meshEntry = aSObject->GetID().c_str();
2926         int len = strlen(meshEntry);
2927
2928         // iterate on all actors in current view window, search for
2929         // any visible actor, that belongs to group or submesh of current mesh
2930         VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2931         vtkActorCollection *aCollection = aCopy.GetActors();
2932         int nbItems = aCollection->GetNumberOfItems();
2933         for (int i=0; i<nbItems && !isActor; i++)
2934         {
2935           SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2936           if (anActor && anActor->hasIO()) {
2937             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2938             if (aViewWindow->isVisible(anIO)) {
2939               if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2940                 myActorsList.append(anActor);
2941             }
2942           }
2943         }
2944       }
2945     }
2946
2947     // Show a standalone group if nothing else is visible (IPAL52227)
2948     if ( myActorsList.count() == 1 &&
2949          myActorsList[0] == aGroupActor &&
2950          aViewWindow && !aViewWindow->isVisible(aGroupActor->getIO()))
2951       SMESH::UpdateView( aViewWindow, SMESH::eDisplay, aGroupActor->getIO()->getEntry() );
2952   }
2953
2954
2955   if (myActorsList.count() > 0) {
2956     QListIterator<SMESH_Actor*> it( myActorsList );
2957     while ( it.hasNext() ) {
2958       SMESH_Actor* anActor = it.next();
2959       if ( IsActorVisible(anActor) )
2960         anActor->SetPickable(true);
2961     }
2962   }
2963
2964   return ( isActor || (myActorsList.count() > 0) );
2965 }
2966
2967 //=======================================================================
2968 //function : setShowEntityMode
2969 //purpose  : make shown only entity corresponding to my type
2970 //=======================================================================
2971 void SMESHGUI_AdaptDlg::setShowEntityMode()
2972 {
2973   if ( !myMesh->_is_nil() ) {
2974     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2975       if (!myStoredShownEntity)
2976         myStoredShownEntity = actor->GetEntityMode();
2977       switch ( myTypeId ) {
2978       case grpNodeSelection:   restoreShowEntityMode();                          break;
2979       case grp0DSelection:     actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2980       case grpBallSelection:   actor->SetEntityMode( SMESH_Actor::eBallElem );   break;
2981       case grpEdgeSelection:   actor->SetEntityMode( SMESH_Actor::eEdges );      break;
2982       case grpFaceSelection:   actor->SetEntityMode( SMESH_Actor::eFaces );      break;
2983       case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes );    break;
2984       }
2985     }
2986   }
2987 }
2988
2989 //=======================================================================
2990 //function : restoreShowEntityMode
2991 //purpose  : restore ShowEntity mode of myActor
2992 //=======================================================================
2993 void SMESHGUI_AdaptDlg::restoreShowEntityMode()
2994 {
2995   if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2996     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2997       actor->SetEntityMode(myStoredShownEntity);
2998     }
2999   }
3000   myStoredShownEntity = 0;
3001 }
3002
3003 //=======================================================================
3004 //function : IsActorVisible
3005 //purpose  : return visibility of the actor
3006 //=======================================================================
3007 bool SMESHGUI_AdaptDlg::IsActorVisible( SMESH_Actor* theActor )
3008 {
3009   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
3010   if (theActor && aViewWindow)
3011     return aViewWindow->isVisible(theActor->getIO());
3012   return false;
3013 }
3014
3015 //================================================================
3016 //function : setIsApplyAndClose
3017 //purpose  : Set value of the flag indicating that the dialog is
3018 //           accepted by Apply & Close button
3019 //================================================================
3020 void SMESHGUI_AdaptDlg::setIsApplyAndClose( const bool theFlag )
3021 {
3022   myIsApplyAndClose = theFlag;
3023 }
3024
3025 //================================================================
3026 //function : isApplyAndClose
3027 //purpose  : Get value of the flag indicating that the dialog is
3028 //           accepted by Apply & Close button
3029 //================================================================
3030 bool SMESHGUI_AdaptDlg::isApplyAndClose() const
3031 {
3032   return myIsApplyAndClose;
3033 }