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