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