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