Salome HOME
0019970: create groups automatically
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 // 
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details.
15 // 
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI.h"
28 #include "SMESHGUI_NodesDlg.h"
29 #include "SMESHGUI_TransparencyDlg.h"
30 #include "SMESHGUI_ClippingDlg.h"
31 #include "SMESHGUI_GroupDlg.h"
32 #include "SMESHGUI_RemoveNodesDlg.h"
33 #include "SMESHGUI_RemoveElementsDlg.h"
34 #include "SMESHGUI_MeshInfosDlg.h"
35 #include "SMESHGUI_StandardMeshInfosDlg.h"
36 #include "SMESHGUI_WhatIsDlg.h"
37 #include "SMESHGUI_Preferences_ColorDlg.h"
38 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_MoveNodesDlg.h"
41 #include "SMESHGUI_AddMeshElementDlg.h"
42 #include "SMESHGUI_AddQuadraticElementDlg.h"
43 #include "SMESHGUI_FilterDlg.h"
44 #include "SMESHGUI_FilterLibraryDlg.h"
45 #include "SMESHGUI_SingleEditDlg.h"
46 #include "SMESHGUI_MultiEditDlg.h"
47 #include "SMESHGUI_GroupOpDlg.h"
48 #include "SMESHGUI_GroupOnShapeDlg.h"
49 #include "SMESHGUI_DeleteGroupDlg.h"
50 #include "SMESHGUI_SmoothingDlg.h"
51 #include "SMESHGUI_RenumberingDlg.h"
52 #include "SMESHGUI_ExtrusionDlg.h"
53 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
54 #include "SMESHGUI_RevolutionDlg.h"
55 #include "SMESHGUI_TranslationDlg.h"
56 #include "SMESHGUI_RotationDlg.h"
57 #include "SMESHGUI_SymmetryDlg.h"
58 #include "SMESHGUI_SewingDlg.h"
59 #include "SMESHGUI_EditMeshDlg.h"
60 #include "SMESHGUI_MeshPatternDlg.h"
61 #include "SMESHGUI_Selection.h"
62 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
63 #include "SMESHGUI_ConvToQuadOp.h"
64 #include "SMESHGUI_MeshOp.h"
65 #include "SMESHGUI_Displayer.h"
66 #include "SMESHGUI_MakeNodeAtPointDlg.h"
67 #include "SMESHGUI_BuildCompoundDlg.h"
68 #include "SMESHGUI_ComputeDlg.h"
69 #include "SMESHGUI_FileInfoDlg.h"
70
71 #include "SMESHGUI_Utils.h"
72 #include "SMESHGUI_MeshUtils.h"
73 #include "SMESHGUI_GroupUtils.h"
74 #include "SMESHGUI_FilterUtils.h"
75 #include "SMESHGUI_PatternUtils.h"
76 #include "SMESHGUI_VTKUtils.h"
77 #include "SMESHGUI_HypothesesUtils.h"
78
79 #include <SMESH_Client.hxx>
80 #include <SMESH_Actor.h>
81 #include <SMESH_TypeFilter.hxx>
82
83 // SALOME GUI includes
84 #include <SalomeApp_Tools.h>
85 #include <SalomeApp_Study.h>
86 #include <SalomeApp_Application.h>
87 #include <SalomeApp_CheckFileDlg.h>
88
89 #include <LightApp_DataOwner.h>
90 #include <LightApp_Preferences.h>
91 #include <LightApp_SelectionMgr.h>
92 #include <LightApp_UpdateFlags.h>
93 #include <LightApp_NameDlg.h>
94
95 #include <SVTK_ViewWindow.h>
96 #include <SVTK_ViewModel.h>
97 #include <SVTK_ViewManager.h>
98
99 #include <SUIT_MessageBox.h>
100 #include <SUIT_ResourceMgr.h>
101 #include <SUIT_FileDlg.h>
102 #include <SUIT_Desktop.h>
103 #include <SUIT_OverrideCursor.h>
104 #include <SUIT_Session.h>
105
106 #include <QtxPopupMgr.h>
107 #include <QtxFontEdit.h>
108
109 #include <SALOME_ListIO.hxx>
110 #include <SALOME_ListIteratorOfListIO.hxx>
111
112 // IDL includes
113 #include <SALOMEconfig.h>
114 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
115 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
116
117 // Qt includes
118 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
119 #include <QMenu>
120
121 // BOOST includes
122 #include <boost/shared_ptr.hpp>
123
124 // VTK includes
125 #include <vtkScalarBarActor.h>
126 #include <vtkCamera.h>
127 #include <vtkRenderer.h>
128 #include <vtkPlane.h>
129
130 // SALOME KERNEL includes
131 #include <SALOMEDS_Study.hxx>
132 #include <SALOMEDSClient_StudyBuilder.hxx>
133 #include <SALOMEDSClient_SComponent.hxx>
134 #include <SALOMEDSClient_ClientFactory.hxx>
135 #include <SALOMEDSClient_IParameters.hxx>
136
137 // OCCT includes
138 #include <Standard_ErrorHandler.hxx>
139 #include <NCollection_DataMap.hxx>
140
141 //namespace{
142   // Declarations
143   //=============================================================
144   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
145                             int theCommandID);
146
147   void ExportMeshToFile(int theCommandID);
148
149   void SetDisplayMode(int theCommandID);
150
151   void SetDisplayEntity(int theCommandID);
152
153   void Control( int theCommandID );
154
155
156   // Definitions
157   //=============================================================
158   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
159                              int theCommandID )
160   {
161     QStringList filter;
162     std::string myExtension;
163
164     if ( theCommandID == 113 ) {
165       filter.append( QObject::tr( "MED files (*.med)" ) );
166       filter.append( QObject::tr( "All files (*)" ) );
167     }
168     else if ( theCommandID == 112 ) {
169       filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
170     }
171     else if ( theCommandID == 111 ) {
172       filter.append( QObject::tr( "DAT files (*.dat)" ) );
173     }
174
175     QString anInitialPath = "";
176     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
177       anInitialPath = QDir::currentPath();
178
179     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
180                                                             anInitialPath,
181                                                             filter,
182                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
183     if ( filenames.count() > 0 ) {
184       SUIT_OverrideCursor wc;
185       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
186
187       QStringList errors;
188       bool isEmpty = false;
189       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
190         QString filename = *it;
191         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
192         try {
193           switch ( theCommandID ) {
194           case 111:
195             {
196               // DAT format (currently unsupported)
197               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
198                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
199               break;
200             }
201           case 112:
202             {
203               // UNV format
204               aMeshes->length( 1 );
205               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toLatin1().constData() );
206               if ( aMeshes[0]->_is_nil() )
207                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
208                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
209               break;
210             }
211           case 113:
212             {
213               // MED format
214               SMESH::DriverMED_ReadStatus res;
215               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toLatin1().constData(), res );
216               if ( res != SMESH::DRS_OK ) {
217                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
218                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
219               }
220               break;
221             }
222           }
223         }
224         catch ( const SALOME::SALOME_Exception& S_ex ) {
225           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
226                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
227         }
228
229         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
230           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
231           if ( aMeshSO ) {
232             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
233             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
234             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
235             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
236               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
237           }
238           else {
239             isEmpty = true;
240           }
241         }
242       }
243
244       // update Object browser
245       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
246
247       // show Error message box if there were errors
248       if ( errors.count() > 0 ) {
249         SUIT_MessageBox::critical( SMESHGUI::desktop(),
250                                    QObject::tr( "SMESH_ERROR" ),
251                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
252       }
253
254       // show warning message box, if some imported mesh is empty
255       if ( isEmpty ) {
256           SUIT_MessageBox::warning( SMESHGUI::desktop(),
257                                     QObject::tr( "SMESH_WRN_WARNING" ),
258                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
259       }
260     }
261   }
262
263   void ExportMeshToFile( int theCommandID )
264   {
265     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
266     SALOME_ListIO selected;
267     if( aSel )
268       aSel->selectedObjects( selected );
269
270     if(selected.Extent()){
271       Handle(SALOME_InteractiveObject) anIObject = selected.First();
272       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
273       if ( !aMesh->_is_nil() ) {
274         QString aFilter, aTitle = QObject::tr("Export mesh");
275         QMap<QString, SMESH::MED_VERSION> aFilterMap;
276         QMap<QString, int> aFilterMapSTL;
277         switch ( theCommandID ) {
278         case 125:
279         case 122:
280           {
281             if (aMesh->HasDuplicatedGroupNamesMED()) {
282               int aRet = SUIT_MessageBox::warning
283                 (SMESHGUI::desktop(),
284                  QObject::tr("SMESH_WRN_WARNING"),
285                  QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
286                  SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
287               if (aRet != SUIT_MessageBox::Yes)
288                 return;
289             }
290             // PAL18696
291             QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
292             QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
293             aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
294             aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
295           }
296           break;
297         case 124:
298         case 121:
299           aFilter = QObject::tr("DAT files (*.dat)");
300           break;
301         case 126:
302         case 123:
303           {
304             if (aMesh->NbPyramids()) {
305               int aRet = SUIT_MessageBox::warning
306                 (SMESHGUI::desktop(),
307                  QObject::tr("SMESH_WRN_WARNING"),
308                  QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
309                  SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
310               if (aRet != SUIT_MessageBox::Yes)
311                 return;
312             }
313             aFilter = QObject::tr("IDEAS files (*.unv)");
314           }
315           break;
316         case 140:
317         case 141:
318           {
319             // export STL
320             /*
321               there must be check on others mesh elements not equal triangles
322             */
323             if (aMesh->NbTriangles() < 1) {
324               SUIT_MessageBox::warning
325                 (SMESHGUI::desktop(),
326                  QObject::tr("SMESH_WRN_WARNING"),
327                  QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()));
328               return;
329             }
330             if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
331               int aRet = SUIT_MessageBox::warning
332                 (SMESHGUI::desktop(),
333                  QObject::tr("SMESH_WRN_WARNING"),
334                  QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
335                  SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
336               if (aRet != SUIT_MessageBox::Yes)
337                 return;
338             }
339
340             aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
341             aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
342           }
343           break;
344         default:
345           return;
346         }
347
348         QString aFilename;
349         SMESH::MED_VERSION aFormat;
350         // Init the parameter with the default value
351         bool aIsASCII_STL = true;
352         bool toCreateGroups = false;
353         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
354         if ( resMgr )
355           toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
356
357         QString anInitialPath = "";
358         if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
359           anInitialPath = QDir::currentPath();
360
361         if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) {
362           if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
363           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
364                                                 aFilter, aTitle, false);
365         }
366         else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
367           QStringList filters;
368           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
369           for ( ; it != aFilterMapSTL.end(); ++it )
370             filters.push_back( it.key() );
371
372           SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
373           fd->setWindowTitle( aTitle );
374           fd->setFilters( filters );
375           fd->selectFilter( QObject::tr("STL ASCII  (*.stl)") );
376           if ( !anInitialPath.isEmpty() )
377             fd->setDirectory( anInitialPath );
378           fd->selectFile(anIObject->getName());
379           bool is_ok = false;
380           while (!is_ok) {
381             if ( fd->exec() )
382               aFilename = fd->selectedFile();
383             aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
384             is_ok = true;
385           }
386           delete fd;
387         }
388         else { // Export to MED
389           QStringList filters;
390           QString aDefaultFilter;
391           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
392           for ( ; it != aFilterMap.end(); ++it ) {
393             filters.push_back( it.key() );
394             if (it.value() == SMESH::MED_V2_2)
395               aDefaultFilter = it.key();
396           }
397
398           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
399           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
400             ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
401           fd->setWindowTitle( aTitle );
402           fd->setFilters( filters );
403           //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
404           fd->selectFilter(aDefaultFilter);
405           fd->SetChecked(toCreateGroups);
406           if ( !anInitialPath.isEmpty() )
407             fd->setDirectory( anInitialPath );
408           fd->selectFile(anIObject->getName());
409           bool is_ok = false;
410           while (!is_ok) {
411             if ( fd->exec() )
412               aFilename = fd->selectedFile();
413             aFormat = aFilterMap[fd->selectedFilter()];
414             is_ok = true;
415             if ( !aFilename.isEmpty()
416                  && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
417                  && aFormat==SMESH::MED_V2_1) {
418               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
419                                                   QObject::tr("SMESH_WRN_WARNING"),
420                                                   QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
421                                                   SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
422               if (aRet != SUIT_MessageBox::Yes) {
423                 is_ok = false;
424               }
425             }
426           }
427           toCreateGroups = fd->IsChecked();
428           delete fd;
429         }
430         if ( !aFilename.isEmpty() ) {
431           // Check whether the file already exists and delete it if yes
432           QFile aFile( aFilename );
433           if ( aFile.exists() )
434             aFile.remove();
435           SUIT_OverrideCursor wc;
436
437           try {
438             bool Renumber = false;
439             // PAL 14172  : Check of we have to renumber or not from the preferences before export
440             if (resMgr)
441               Renumber= resMgr->booleanValue("SMESH","renumbering");
442             if (Renumber){
443               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
444               aMeshEditor->RenumberNodes();
445               aMeshEditor->RenumberElements();
446               if ( SMESHGUI::automaticUpdate() )
447                 SMESH::UpdateView();
448               }
449             switch ( theCommandID ) {
450             case 125:
451             case 122:
452               aMesh->ExportToMED( aFilename.toLatin1().data(), toCreateGroups, aFormat );
453               break;
454             case 124:
455             case 121:
456               aMesh->ExportDAT( aFilename.toLatin1().data() );
457               break;
458             case 126:
459             case 123:
460               aMesh->ExportUNV( aFilename.toLatin1().data() );
461               break;
462             case 140:
463             case 141:
464               aMesh->ExportSTL( aFilename.toLatin1().data(), aIsASCII_STL );
465               break;
466             default:
467               break;
468             }
469           }
470           catch (const SALOME::SALOME_Exception& S_ex){
471             wc.suspend();
472             SUIT_MessageBox::warning(SMESHGUI::desktop(),
473                                      QObject::tr("SMESH_WRN_WARNING"),
474                                      QObject::tr("SMESH_EXPORT_FAILED"));
475             wc.resume();
476           }
477         }
478       }
479     }
480   }
481
482   inline void InverseEntityMode(unsigned int& theOutputMode,
483                                 unsigned int theMode)
484   {
485     bool anIsNotPresent = ~theOutputMode & theMode;
486     if(anIsNotPresent)
487       theOutputMode |= theMode;
488     else
489       theOutputMode &= ~theMode;
490   }
491
492   void SetDisplayEntity(int theCommandID){
493     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
494     SALOME_ListIO selected;
495     if( aSel )
496       aSel->selectedObjects( selected );
497
498     if(selected.Extent() >= 1){
499       SALOME_ListIteratorOfListIO It( selected );
500       for( ; It.More(); It.Next()){
501         Handle(SALOME_InteractiveObject) IObject = It.Value();
502         if(IObject->hasEntry()){
503           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
504             unsigned int aMode = anActor->GetEntityMode();
505             switch(theCommandID){
506             case 217:
507               InverseEntityMode(aMode,SMESH_Actor::eEdges);
508               break;
509             case 218:
510               InverseEntityMode(aMode,SMESH_Actor::eFaces);
511               break;
512             case 219:
513               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
514               break;
515             case 220:
516               aMode = SMESH_Actor::eAllEntity;
517               break;
518             }
519             if(aMode)
520               anActor->SetEntityMode(aMode);
521           }
522         }
523       }
524     }
525   }
526
527   void AutoColor(){
528     SALOME_ListIO selected;
529     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
530     if( !app )
531       return;
532
533     LightApp_SelectionMgr* aSel = app->selectionMgr();
534     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
535     if( !aSel || !appStudy )
536       return;
537
538     aSel->selectedObjects( selected );
539     if( selected.IsEmpty() )
540       return;
541
542     Handle(SALOME_InteractiveObject) anIObject = selected.First();
543
544     _PTR(Study) aStudy = appStudy->studyDS();
545     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
546     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
547     if( aMainObject->_is_nil() )
548       return;
549
550     aMainObject->SetAutoColor( true );
551
552     QList<SALOMEDS::Color> aReservedColors;
553
554     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
555     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
556     {
557       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
558       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
559
560       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
561       aGroupObject->SetColor( aColor );
562       aReservedColors.append( aColor );
563
564       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
565       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
566       {
567         if( aGroupObject->GetType() == SMESH::NODE )
568           anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
569         else if( aGroupObject->GetType() == SMESH::EDGE )
570           anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
571         else
572           anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
573       }
574     }
575
576     SMESH::RepaintCurrentView();
577   }
578
579   void DisableAutoColor(){
580     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
581     SALOME_ListIO selected;
582     if( aSel )
583       aSel->selectedObjects( selected );
584
585     if(selected.Extent()){
586       Handle(SALOME_InteractiveObject) anIObject = selected.First();
587       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
588       if ( !aMesh->_is_nil() ) {
589         aMesh->SetAutoColor( false );
590       }
591     }
592   }
593
594   void SetDisplayMode(int theCommandID){
595     SALOME_ListIO selected;
596     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
597     if( !app )
598       return;
599
600     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
601     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
602     if( !aSel || !appStudy )
603       return;
604
605     _PTR(Study) aStudy = appStudy->studyDS();
606
607     aSel->selectedObjects( selected );
608
609     if(selected.Extent() >= 1){
610       switch(theCommandID){
611       case 1134:{
612         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
613         (new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI() ))->show();
614         return;
615       }
616       case 1133:{
617         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
618         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
619         return;
620       }}
621       SALOME_ListIteratorOfListIO It( selected );
622       for( ; It.More(); It.Next()){
623         Handle(SALOME_InteractiveObject) IObject = It.Value();
624         if(IObject->hasEntry()){
625           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
626             switch(theCommandID){
627             case 211:
628               anActor->SetRepresentation(SMESH_Actor::eEdge);
629               break;
630             case 212:
631               anActor->SetRepresentation(SMESH_Actor::eSurface);
632               break;
633             case 213:
634               if(anActor->IsShrunk())
635                 anActor->UnShrink();
636               else
637                 anActor->SetShrink();
638               break;
639             case 215:
640               anActor->SetRepresentation(SMESH_Actor::ePoint);
641               break;
642             case 1132:{
643               vtkFloatingPointType color[3];
644               anActor->GetSufaceColor(color[0], color[1], color[2]);
645               int c0 = int (color[0] * 255);
646               int c1 = int (color[1] * 255);
647               int c2 = int (color[2] * 255);
648               QColor c(c0, c1, c2);
649
650               vtkFloatingPointType edgecolor[3];
651               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
652               c0 = int (edgecolor[0] * 255);
653               c1 = int (edgecolor[1] * 255);
654               c2 = int (edgecolor[2] * 255);
655               QColor e(c0, c1, c2);
656
657               vtkFloatingPointType backfacecolor[3];
658               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
659               c0 = int (backfacecolor[0] * 255);
660               c1 = int (backfacecolor[1] * 255);
661               c2 = int (backfacecolor[2] * 255);
662               QColor b(c0, c1, c2);
663
664               vtkFloatingPointType nodecolor[3];
665               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
666               c0 = int (nodecolor[0] * 255);
667               c1 = int (nodecolor[1] * 255);
668               c2 = int (nodecolor[2] * 255);
669               QColor n(c0, c1, c2);
670
671               int Edgewidth = (int)anActor->GetLineWidth();
672               if(Edgewidth == 0)
673                 Edgewidth = 1;
674               int intValue = int(anActor->GetNodeSize());
675               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
676
677               SMESHGUI_Preferences_ColorDlg *aDlg =
678                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI() );
679               aDlg->SetColor(1, c);
680               aDlg->SetColor(2, e);
681               aDlg->SetColor(3, n);
682               aDlg->SetColor(4, b);
683               aDlg->SetIntValue(1, Edgewidth);
684               aDlg->SetIntValue(2, intValue);
685               aDlg->SetIntValue(3, int(Shrink*100.));
686               if(aDlg->exec()){
687                 QColor color = aDlg->GetColor(1);
688                 QColor edgecolor = aDlg->GetColor(2);
689                 QColor nodecolor = aDlg->GetColor(3);
690                 QColor backfacecolor = aDlg->GetColor(4);
691                 /* actor color and backface color */
692                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
693                                         vtkFloatingPointType (color.green()) / 255.,
694                                         vtkFloatingPointType (color.blue()) / 255.);
695                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
696                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
697                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
698
699                 /* edge color */
700                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
701                                       vtkFloatingPointType (edgecolor.green()) / 255.,
702                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
703
704                 /* Shrink factor and size edges */
705                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
706                 anActor->SetLineWidth(aDlg->GetIntValue(1));
707
708                 /* Nodes color and size */
709                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
710                                       vtkFloatingPointType (nodecolor.green()) / 255.,
711                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
712                 anActor->SetNodeSize(aDlg->GetIntValue(2));
713
714                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
715                 if( !aGroupObject->_is_nil() )
716                 {
717                   SALOMEDS::Color aColor;
718                   aColor.R = (float)color.red() / 255.0;
719                   aColor.G = (float)color.green() / 255.0;
720                   aColor.B = (float)color.blue() / 255.0;
721                   aGroupObject->SetColor( aColor );
722                 }
723
724                 delete aDlg;
725               }
726               break;
727             }}
728           }
729         }
730       }
731       SMESH::RepaintCurrentView();
732     }
733   }
734
735   void Control( int theCommandID )
736   {
737     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
738     SALOME_ListIO selected;
739     if( aSel )
740       aSel->selectedObjects( selected );
741
742     if( !selected.IsEmpty() ){
743       Handle(SALOME_InteractiveObject) anIO = selected.First();
744       if(!anIO.IsNull()){
745         QString aTitle;
746         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
747         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
748           switch ( theCommandID ){
749           case 6001:
750             aTitle = QObject::tr( "LENGTH_EDGES" );
751             aControl = SMESH_Actor::eLength;
752             break;
753           case 6018:
754             aTitle = QObject::tr( "LENGTH2D_EDGES" );
755             aControl = SMESH_Actor::eLength2D;
756             break;
757           case 6002:
758             aTitle = QObject::tr( "FREE_EDGES" );
759             aControl = SMESH_Actor::eFreeEdges;
760             break;
761           case 6003:
762             aTitle = QObject::tr( "FREE_BORDERS" );
763             aControl = SMESH_Actor::eFreeBorders;
764             break;
765           case 6004:
766             aTitle = QObject::tr( "MULTI_BORDERS" );
767             aControl = SMESH_Actor::eMultiConnection;
768             break;
769           case 6019:
770             aTitle = QObject::tr( "MULTI2D_BORDERS" );
771             aControl = SMESH_Actor::eMultiConnection2D;
772             break;
773           case 6011:
774             aTitle = QObject::tr( "AREA_ELEMENTS" );
775             aControl = SMESH_Actor::eArea;
776             break;
777           case 6012:
778             aTitle = QObject::tr( "TAPER_ELEMENTS" );
779             aControl = SMESH_Actor::eTaper;
780             break;
781           case 6013:
782             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
783             aControl = SMESH_Actor::eAspectRatio;
784             break;
785           case 6017:
786             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
787             aControl = SMESH_Actor::eAspectRatio3D;
788             break;
789           case 6014:
790             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
791             aControl = SMESH_Actor::eMinimumAngle;
792             break;
793           case 6015:
794             aTitle = QObject::tr( "WARP_ELEMENTS" );
795             aControl = SMESH_Actor::eWarping;
796             break;
797           case 6016:
798             aTitle = QObject::tr( "SKEW_ELEMENTS" );
799             aControl = SMESH_Actor::eSkew;
800             break;
801           case 6009:
802             aTitle = QObject::tr( "SMESH_VOLUME" );
803             aControl = SMESH_Actor::eVolume3D;
804             break;
805           }
806           anActor->SetControlMode(aControl);
807           anActor->GetScalarBarActor()->SetTitle(aTitle.toLatin1().data());
808           SMESH::RepaintCurrentView();
809         }
810       }
811     }
812   }
813
814
815   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
816                    MeshObjectType                           theType,
817                    const QString                            theInTypeName,
818                    QString &                                theOutTypeName)
819   {
820     SMESH_TypeFilter aTypeFilter( theType );
821     QString entry;
822     if( !theIO.IsNull() )
823     {
824       entry = theIO->getEntry();
825       LightApp_DataOwner owner( entry );
826       if ( aTypeFilter.isOk( &owner )) {
827         theOutTypeName = theInTypeName;
828         return true;
829       }
830     }
831     return false;
832   }
833
834
835   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
836   {
837     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
838     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
839     if (aSObj) {
840       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
841       CORBA::String_var anID = aSComp->GetID().c_str();
842       if (!strcmp(anID.in(),theIO->getEntry()))
843         return "Component";
844     }
845
846     QString aTypeName;
847     if (
848         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
849         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
850         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
851         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
852         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
853         )
854       return aTypeName;
855
856     return "NoType";
857   }
858
859
860   QString CheckHomogeneousSelection()
861   {
862     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
863     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
864     SALOME_ListIO selected;
865     if( aSel )
866       aSel->selectedObjects( selected );
867
868     QString RefType = CheckTypeObject(selected.First());
869     SALOME_ListIteratorOfListIO It(selected);
870     for ( ; It.More(); It.Next())
871       {
872         Handle(SALOME_InteractiveObject) IObject = It.Value();
873         QString Type = CheckTypeObject(IObject);
874         if (Type.compare(RefType) != 0)
875           return "Heterogeneous Selection";
876       }
877
878     return RefType;
879   }
880
881
882   void SMESHGUI::OnEditDelete()
883   {
884     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
885     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
886     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
887
888     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
889     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
890     _PTR(GenericAttribute) anAttr;
891     _PTR(AttributeIOR) anIOR;
892
893     int objectCount = 0;
894     QString aParentComponent = QString::null;
895     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
896     {
897       _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry());
898       if (aSO) {
899         // check if object is not reference
900         _PTR(SObject) refobj;
901         if ( !aSO->ReferencedObject( refobj ) )
902           objectCount++;
903       }
904
905       QString cur = anIt.Value()->getComponentDataType();
906       if( aParentComponent.isNull() )
907         aParentComponent = cur;
908       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
909         aParentComponent = "";
910     }
911
912     if ( objectCount == 0 )
913       return; // No Valid Objects Selected
914
915     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
916       SUIT_MessageBox::warning( SMESHGUI::desktop(),
917                                 QObject::tr("ERR_ERROR"),
918                                 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
919       return;
920     }
921     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
922     if (SUIT_MessageBox::warning
923         (SMESHGUI::desktop(),
924          QObject::tr("SMESH_WRN_WARNING"),
925          QObject::tr("SMESH_REALLY_DELETE"),
926          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
927          SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
928       return;
929
930     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
931     SUIT_ViewManager* vm = anApp->activeViewManager();
932     int nbSf = vm->getViewsCount();
933
934     SALOME_ListIteratorOfListIO It(selected);
935
936     aStudyBuilder->NewCommand();  // There is a transaction
937     for( ; It.More(); It.Next()){ // loop on selected IO's
938       Handle(SALOME_InteractiveObject) IObject = It.Value();
939       if(IObject->hasEntry()) {
940         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
941
942         // disable removal of "SMESH" component object
943         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
944           anIOR = anAttr;
945           if ( engineIOR() == anIOR->Value().c_str() )
946             continue;
947         }
948
949         _PTR(SObject) refobj;
950         if ( aSO && aSO->ReferencedObject( refobj ) )
951           continue; // skip references
952
953         // put the whole hierarchy of sub-objects of the selected SO into a list and
954         // then treat them all starting from the deepest objects (at list back)
955
956         std::list< _PTR(SObject) > listSO;
957         listSO.push_back( aSO );
958         std::list< _PTR(SObject) >::iterator itSO = listSO.begin();
959         for ( ; itSO != listSO.end(); ++itSO ) {
960           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
961           for (it->InitEx(false); it->More(); it->Next())
962             listSO.push_back( it->Value() );
963         }
964
965         // treat SO's in the list starting from the back
966
967         std::list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
968         for ( ; ritSO != listSO.rend(); ++ritSO ) {
969           _PTR(SObject) SO = *ritSO;
970           if ( !SO ) continue;
971           std::string anEntry = SO->GetID();
972
973           /** Erase graphical object **/
974           if(SO->FindAttribute(anAttr, "AttributeIOR")){
975             QVector<SUIT_ViewWindow*> aViews = vm->getViews();
976             for(int i = 0; i < nbSf; i++){
977               SUIT_ViewWindow *sf = aViews[i];
978               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
979                 SMESH::RemoveActor(sf,anActor);
980               }
981             }
982           }
983
984           /** Remove an object from data structures **/
985           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
986           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
987           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
988             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
989             aMesh->RemoveGroup( aGroup );
990           }
991           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
992             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
993             aMesh->RemoveSubMesh( aSubMesh );
994
995             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
996             if (aMeshSO)
997               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
998           }
999           else {
1000             IObject = new SALOME_InteractiveObject
1001               ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1002             QString objType = CheckTypeObject(IObject);
1003             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1004               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1005               aStudyBuilder->RemoveObjectWithChildren( SO );
1006             }
1007             else {// default action: remove SObject from the study
1008               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1009               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1010               //op->start();
1011               aStudyBuilder->RemoveObjectWithChildren( SO );
1012               //op->finish();
1013             }
1014           }
1015         } /* listSO back loop */
1016       } /* IObject->hasEntry() */
1017     } /* more/next */
1018     aStudyBuilder->CommitCommand();
1019
1020     /* Clear any previous selection */
1021     SALOME_ListIO l1;
1022     aSel->setSelectedObjects( l1 );
1023
1024     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1025   }
1026 //}
1027
1028 extern "C" {
1029   SMESHGUI_EXPORT CAM_Module* createModule()
1030   {
1031     return new SMESHGUI();
1032   }
1033 }
1034
1035 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1036
1037 //=============================================================================
1038 /*!
1039  *
1040  */
1041 //=============================================================================
1042 SMESHGUI::SMESHGUI() :
1043 SalomeApp_Module( "SMESH" )
1044 {
1045   if ( CORBA::is_nil( myComponentSMESH ) )
1046   {
1047     CORBA::Boolean anIsEmbeddedMode;
1048     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1049   }
1050
1051   myActiveDialogBox = 0;
1052   myFilterLibraryDlg = 0;
1053   myState = -1;
1054   myDisplayer = 0;
1055
1056   SMESH::GetFilterManager();
1057   SMESH::GetPattern();
1058
1059   /* load resources for all available meshers */
1060   SMESH::InitAvailableHypotheses();
1061 }
1062
1063 //=============================================================================
1064 /*!
1065  *
1066  */
1067 //=============================================================================
1068 SMESHGUI::~SMESHGUI()
1069 {
1070   SMESH::GetFilterManager()->Destroy();
1071   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1072 }
1073
1074 //=============================================================================
1075 /*!
1076  *
1077  */
1078 //=============================================================================
1079 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1080 {
1081   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1082   if( anApp )
1083     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1084   else
1085     return 0;
1086 }
1087
1088 bool SMESHGUI::automaticUpdate()
1089 {
1090   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1091   if ( !resMgr )
1092     return false;
1093
1094   return resMgr->booleanValue( "SMESH", "auto_update", false );
1095 }
1096
1097 //=============================================================================
1098 /*!
1099  *
1100  */
1101 //=============================================================================
1102 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1103 {
1104   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1105 }
1106
1107 //=============================================================================
1108 /*!
1109  *
1110  */
1111 //=============================================================================
1112 SMESHGUI* SMESHGUI::GetSMESHGUI()
1113 {
1114   SMESHGUI* smeshMod = 0;
1115   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1116   if ( app )
1117   {
1118     CAM_Module* module = app->module( "Mesh" );
1119     smeshMod = dynamic_cast<SMESHGUI*>( module );
1120   }
1121
1122   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1123   {
1124     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1125     if ( study )
1126     {
1127       _PTR(Study) aStudy = study->studyDS();
1128       if ( aStudy )
1129         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1130     }
1131   }
1132
1133   return smeshMod;
1134 }
1135
1136 extern "C"
1137 {
1138   Standard_EXPORT SMESHGUI* GetComponentGUI()
1139   {
1140     return SMESHGUI::GetSMESHGUI();
1141   }
1142 }
1143
1144 //=============================================================================
1145 /*!
1146  *
1147  */
1148 //=============================================================================
1149 void SMESHGUI::SetState(int aState)
1150 {
1151   myState = aState;
1152 }
1153
1154 //=============================================================================
1155 /*!
1156  *
1157  */
1158 //=============================================================================
1159 void SMESHGUI::ResetState()
1160 {
1161   myState = -1;
1162 }
1163
1164 //=============================================================================
1165 /*!
1166  *
1167  */
1168 //=============================================================================
1169 void SMESHGUI::EmitSignalDeactivateDialog()
1170 {
1171   emit SignalDeactivateActiveDialog();
1172 }
1173
1174 //=============================================================================
1175 /*!
1176  *
1177  */
1178 //=============================================================================
1179 void SMESHGUI::EmitSignalStudyFrameChanged()
1180 {
1181   emit SignalStudyFrameChanged();
1182 }
1183
1184 //=============================================================================
1185 /*!
1186  *
1187  */
1188 //=============================================================================
1189 void SMESHGUI::EmitSignalCloseAllDialogs()
1190 {
1191   emit SignalCloseAllDialogs();
1192 }
1193
1194 //=============================================================================
1195 /*!
1196  *
1197  */
1198 //=============================================================================
1199 QDialog *SMESHGUI::GetActiveDialogBox()
1200 {
1201   return myActiveDialogBox;
1202 }
1203
1204 //=============================================================================
1205 /*!
1206  *
1207  */
1208 //=============================================================================
1209 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1210 {
1211   myActiveDialogBox = (QDialog *) aDlg;
1212   return;
1213 }
1214
1215 //=============================================================================
1216 /*!
1217  *
1218  */
1219 //=============================================================================
1220 SUIT_Desktop* SMESHGUI::desktop()
1221 {
1222   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1223   if( app )
1224     return app->desktop();
1225   else
1226     return 0;
1227 }
1228
1229 //=============================================================================
1230 /*!
1231  *
1232  */
1233 //=============================================================================
1234 SalomeApp_Study* SMESHGUI::activeStudy()
1235 {
1236   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1237   if( app )
1238     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1239   else
1240     return NULL;
1241 }
1242
1243 //=============================================================================
1244 /*!
1245  *
1246  */
1247 //=============================================================================
1248 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1249 {
1250   /* Here the position is on the bottom right corner - 10 */
1251   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1252   aDlg->adjustSize();
1253   SUIT_Desktop *PP = desktop();
1254   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1255   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1256   return true;
1257 }
1258
1259 //=============================================================================
1260 /*!
1261  *
1262  */
1263 //=============================================================================
1264 static int isStudyLocked(_PTR(Study) theStudy){
1265   return theStudy->GetProperties()->IsLocked();
1266 }
1267
1268 static bool checkLock(_PTR(Study) theStudy) {
1269   if (isStudyLocked(theStudy)) {
1270     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1271                               QObject::tr("WRN_WARNING"),
1272                               QObject::tr("WRN_STUDY_LOCKED") );
1273     return true;
1274   }
1275   return false;
1276 }
1277
1278 //=======================================================================
1279 //function : CheckActiveStudyLocked
1280 //purpose  :
1281 //=======================================================================
1282
1283 bool SMESHGUI::isActiveStudyLocked()
1284 {
1285   _PTR(Study) aStudy = activeStudy()->studyDS();
1286   return checkLock( aStudy );
1287 }
1288
1289 //=============================================================================
1290 /*!
1291  *
1292  */
1293 //=============================================================================
1294 bool SMESHGUI::OnGUIEvent( int theCommandID )
1295 {
1296   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1297   if( !anApp )
1298     return false;
1299
1300   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1301   SUIT_ResourceMgr* mgr = resourceMgr();
1302   if( !mgr )
1303     return false;
1304
1305   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1306     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1307   }
1308
1309   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1310   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1311
1312   //QAction* act = action( theCommandID );
1313
1314   switch (theCommandID) {
1315   case 33:                                      // DELETE
1316     if(checkLock(aStudy)) break;
1317     OnEditDelete();
1318     break;
1319
1320   case 113:                                     // IMPORT
1321   case 112:
1322   case 111:
1323     {
1324       if(checkLock(aStudy)) break;
1325       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1326       break;
1327     }
1328
1329   case 150:    //MED FILE INFORMATION
1330     {
1331       SALOME_ListIO selected;
1332       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1333       if( aSel )
1334         aSel->selectedObjects( selected );
1335       if( selected.Extent() )
1336       {
1337         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1338         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1339         if ( !aMesh->_is_nil() )
1340         {
1341           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1342           dlg.exec();
1343         }
1344       }
1345       break;
1346     }
1347
1348   case 122:                                     // EXPORT MED
1349   case 121:
1350   case 123:
1351   case 124:
1352   case 125:
1353   case 126:
1354   case 140:
1355   case 141:
1356     {
1357       ::ExportMeshToFile(theCommandID);
1358       break;
1359     }
1360
1361   case 200:                                     // SCALAR BAR
1362     {
1363       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1364       SALOME_ListIO selected;
1365       if( aSel )
1366         aSel->selectedObjects( selected );
1367
1368       if( selected.Extent() ) {
1369         Handle(SALOME_InteractiveObject) anIO = selected.First();
1370         if( anIO->hasEntry() ) {
1371           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1372             anActor->SetControlMode( SMESH_Actor::eNone );
1373           }
1374         }
1375       }
1376       break;
1377     }
1378   case 201:
1379     {
1380       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1381       break;
1382     }
1383
1384     // Auto-color
1385   case 1136:
1386     ::AutoColor();
1387   break;
1388
1389   case 1137:
1390     ::DisableAutoColor();
1391   break;
1392
1393   case 1134: // Clipping
1394   case 1133: // Tranparency
1395   case 1132: // Colors / Size
1396
1397     // Display Mode
1398   case 215: // Nodes
1399   case 213: // Nodes
1400   case 212: // Nodes
1401   case 211: // Nodes
1402     ::SetDisplayMode(theCommandID);
1403   break;
1404
1405     // Display Entity
1406   case 217: // Edges
1407   case 218: // Faces
1408   case 219: // Volumes
1409   case 220: // All Entity
1410     ::SetDisplayEntity(theCommandID);
1411   break;
1412
1413   case 221: // Orientation of faces
1414     {
1415       LightApp_SelectionMgr* mgr = selectionMgr();
1416       SALOME_ListIO selected; mgr->selectedObjects( selected );
1417
1418       SALOME_ListIteratorOfListIO it(selected);
1419       for( ; it.More(); it.Next()) {
1420         Handle(SALOME_InteractiveObject) anIObject = it.Value();
1421         if(anIObject->hasEntry()) {
1422           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
1423             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
1424           }
1425         }
1426       }
1427       break;
1428     }
1429
1430   case 214:                                     // UPDATE
1431     {
1432       if(checkLock(aStudy)) break;
1433       try {
1434 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1435         OCC_CATCH_SIGNALS;
1436 #endif
1437         SMESH::UpdateView();
1438       }
1439       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1440         SMESH::OnVisuException();
1441       }
1442       catch (...) { // PAL16774 (Crash after display of many groups)
1443         SMESH::OnVisuException();
1444       }
1445
1446       SALOME_ListIO l;
1447       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1448       aSel->selectedObjects( l );
1449       aSel->setSelectedObjects( l );
1450       break;
1451     }
1452
1453   case 300:                                     // ERASE
1454   case 301:                                     // DISPLAY
1455   case 302:                                     // DISPLAY ONLY
1456     {
1457       SMESH::EDisplaing anAction;
1458       switch (theCommandID) {
1459       case 300: anAction = SMESH::eErase; break;
1460       case 301: anAction = SMESH::eDisplay; break;
1461       case 302: anAction = SMESH::eDisplayOnly; break;
1462       }
1463
1464       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1465       SALOME_ListIO sel_objects, to_process;
1466       if (aSel)
1467         aSel->selectedObjects( sel_objects );
1468
1469       if( theCommandID==302 )
1470         startOperation( myEraseAll );
1471
1472       extractContainers( sel_objects, to_process );
1473
1474       try {
1475 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1476         OCC_CATCH_SIGNALS;
1477 #endif
1478         if (vtkwnd) {
1479           SALOME_ListIteratorOfListIO It( to_process );
1480           for ( ; It.More(); It.Next()) {
1481             Handle(SALOME_InteractiveObject) IOS = It.Value();
1482             if (IOS->hasEntry()) {
1483               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1484                 break; // PAL16774 (Crash after display of many groups)
1485               if (anAction == SMESH::eDisplayOnly)
1486                 anAction = SMESH::eDisplay;
1487             }
1488           }
1489         }
1490
1491         // PAL13338 + PAL15161 -->
1492         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1493           SMESH::UpdateView();
1494         // PAL13338 + PAL15161 <--
1495       }
1496       catch (...) { // PAL16774 (Crash after display of many groups)
1497         SMESH::OnVisuException();
1498       }
1499
1500       if (anAction == SMESH::eErase) {
1501         SALOME_ListIO l1;
1502         aSel->setSelectedObjects( l1 );
1503       }
1504       else
1505         aSel->setSelectedObjects( to_process );
1506
1507       break;
1508     }
1509
1510   case 400:                                     // NODES
1511     {
1512       if(checkLock(aStudy)) break;
1513
1514       if ( vtkwnd ) {
1515         EmitSignalDeactivateDialog();
1516
1517         ( new SMESHGUI_NodesDlg( this ) )->show();
1518       }
1519       else {
1520         SUIT_MessageBox::warning(desktop(),
1521                                  tr("SMESH_WRN_WARNING"),
1522                                  tr("SMESH_WRN_VIEWER_VTK"));
1523       }
1524       break;
1525     }
1526
1527   case 2151:  // FILTER
1528   {
1529     if ( vtkwnd )
1530     {
1531       EmitSignalDeactivateDialog();
1532       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
1533     }
1534     break;
1535   }
1536
1537   case 406:                                     // MOVE NODE
1538     {
1539       if ( !vtkwnd )
1540       {
1541         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1542                                   tr( "NOT_A_VTK_VIEWER" ) );
1543         break;
1544       }
1545
1546       if(checkLock(aStudy)) break;
1547       ( new SMESHGUI_MoveNodesDlg( this ) )->show();
1548       break;
1549     }
1550
1551   case 701:                                     // COMPUTE MESH
1552     {
1553       if (checkLock(aStudy)) break;
1554
1555       startOperation( 701 );
1556     }
1557     break;
1558
1559   case 702:  // Create mesh
1560     startOperation( 702 );
1561     break;
1562   case 703:  // Create sub-mesh
1563     startOperation( 703 );
1564     break;
1565   case 704: // Edit mesh/sub-mesh
1566     startOperation( 704 );
1567     break;
1568   case 710: // Build compound mesh
1569     {
1570       if (checkLock(aStudy)) break;
1571       EmitSignalDeactivateDialog();
1572       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
1573     }
1574     break;
1575
1576   case 407: // DIAGONAL INVERSION
1577   case 408: // Delete diagonal
1578     {
1579       if ( !vtkwnd )
1580       {
1581         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1582                                   tr( "NOT_A_VTK_VIEWER" ) );
1583         break;
1584       }
1585
1586       if ( checkLock( aStudy ) )
1587         break;
1588
1589       /*Standard_Boolean aRes;
1590       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1591       if ( aMesh->_is_nil() )
1592       {
1593         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1594           tr( "SMESH_BAD_SELECTION" ) );
1595         break;
1596       }
1597       */
1598       EmitSignalDeactivateDialog();
1599       if ( theCommandID == 407 )
1600         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
1601       else
1602         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
1603       break;
1604     }
1605     case 409: // Change orientation
1606     case 410: // Union of triangles
1607     case 411: // Cutting of quadrangles
1608     {
1609       if ( !vtkwnd )
1610       {
1611         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1612                                   tr( "NOT_A_VTK_VIEWER" ) );
1613         break;
1614       }
1615
1616       if ( checkLock( aStudy ) )
1617         break;
1618
1619       EmitSignalDeactivateDialog();
1620       SMESHGUI_MultiEditDlg* aDlg = NULL;
1621       if ( theCommandID == 409 )
1622         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1623       else if ( theCommandID == 410 )
1624         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1625       else
1626         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1627
1628       aDlg->show();
1629       break;
1630     }
1631   case 412: // Smoothing
1632     {
1633       if(checkLock(aStudy)) break;
1634       if( vtkwnd ) {
1635         EmitSignalDeactivateDialog();
1636         ( new SMESHGUI_SmoothingDlg( this ) )->show();
1637       }
1638       else {
1639         SUIT_MessageBox::warning(desktop(),
1640                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1641       }
1642       break;
1643     }
1644   case 413: // Extrusion
1645     {
1646       if (checkLock(aStudy)) break;
1647       if (vtkwnd) {
1648         EmitSignalDeactivateDialog();
1649         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
1650       } else {
1651         SUIT_MessageBox::warning(desktop(),
1652                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1653       }
1654       break;
1655     }
1656   case 414: // Revolution
1657     {
1658       if(checkLock(aStudy)) break;
1659       if( vtkwnd ) {
1660         EmitSignalDeactivateDialog();
1661         ( new SMESHGUI_RevolutionDlg( this ) )->show();
1662       }
1663       else {
1664         SUIT_MessageBox::warning(desktop(),
1665                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1666       }
1667       break;
1668     }
1669   case 415: // Pattern mapping
1670     {
1671       if ( checkLock( aStudy ) )
1672         break;
1673       if ( vtkwnd )
1674       {
1675         EmitSignalDeactivateDialog();
1676         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
1677       }
1678       else {
1679         SUIT_MessageBox::warning(desktop(),
1680                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1681       }
1682       break;
1683     }
1684   case 416: // Extrusion along a path
1685     {
1686       if (checkLock(aStudy)) break;
1687       if (vtkwnd) {
1688         EmitSignalDeactivateDialog();
1689         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
1690       } else {
1691         SUIT_MessageBox::warning(desktop(),
1692                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1693       }
1694       break;
1695     }
1696   case 417: // Convert mesh to quadratic
1697     {
1698     startOperation( 417 );
1699       /*      if (checkLock(aStudy)) break;
1700       if (vtkwnd) {
1701         EmitSignalDeactivateDialog();
1702         new SMESHGUI_ConvToQuadDlg();
1703       } else {
1704         SUIT_MessageBox::warning(desktop(),
1705                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1706                                }*/
1707       break;
1708     }
1709   case 806:                                     // CREATE GEO GROUP
1710     {
1711       startOperation( 806 );
1712       break;
1713     }
1714   case 801:                                     // CREATE GROUP
1715     {
1716       if ( !vtkwnd )
1717       {
1718         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1719                                   tr( "NOT_A_VTK_VIEWER" ) );
1720         break;
1721       }
1722
1723       if(checkLock(aStudy)) break;
1724       EmitSignalDeactivateDialog();
1725       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1726
1727       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1728       SALOME_ListIO selected;
1729       if( aSel )
1730         aSel->selectedObjects( selected );
1731
1732       int nbSel = selected.Extent();
1733       if (nbSel == 1) {
1734         // check if mesh is selected
1735         aMesh = SMESH::GetMeshByIO( selected.First() );
1736       }
1737       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
1738       aDlg->show();
1739       break;
1740     }
1741
1742   case 802:                                     // CONSTRUCT GROUP
1743     {
1744       if ( !vtkwnd )
1745       {
1746         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1747                                   tr( "NOT_A_VTK_VIEWER" ) );
1748         break;
1749       }
1750
1751       if(checkLock(aStudy)) break;
1752       EmitSignalDeactivateDialog();
1753
1754       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1755       SALOME_ListIO selected;
1756       if( aSel )
1757         aSel->selectedObjects( selected );
1758
1759       int nbSel = selected.Extent();
1760       if (nbSel == 1) {
1761         // check if submesh is selected
1762         Handle(SALOME_InteractiveObject) IObject = selected.First();
1763         if (IObject->hasEntry()) {
1764           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1765           if( aSObj ) {
1766             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1767             if (!aSubMesh->_is_nil()) {
1768               try {
1769                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1770                 // get submesh elements list by types
1771                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1772                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1773                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1774                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1775                 // create group for each type o elements
1776                 QString aName = IObject->getName();
1777                 if (aNodes->length() > 0) {
1778                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1779                   aGroup->Add(aNodes.inout());
1780                 }
1781                 if (aEdges->length() > 0) {
1782                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1783                   aGroup->Add(aEdges.inout());
1784                 }
1785                 if (aFaces->length() > 0) {
1786                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1787                   aGroup->Add(aFaces.inout());
1788                 }
1789                 if (aVolumes->length() > 0) {
1790                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1791                   aGroup->Add(aVolumes.inout());
1792                 }
1793                 updateObjBrowser();
1794
1795               }
1796               catch(const SALOME::SALOME_Exception & S_ex){
1797                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1798               }
1799             }
1800           }
1801         }
1802       }
1803       else if(nbSel==0) {
1804         SUIT_MessageBox::warning(desktop(),
1805                                  tr("SMESH_WRN_WARNING"),
1806                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
1807       }
1808       break;
1809     }
1810
1811   case 803:                                     // EDIT GROUP
1812     {
1813       if ( !vtkwnd )
1814       {
1815         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1816                                   tr( "NOT_A_VTK_VIEWER" ) );
1817         break;
1818       }
1819
1820       if(checkLock(aStudy)) break;
1821       EmitSignalDeactivateDialog();
1822
1823       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1824       SALOME_ListIO selected;
1825       if( aSel )
1826         aSel->selectedObjects( selected );
1827
1828       SALOME_ListIteratorOfListIO It (selected);
1829       int nbSelectedGroups = 0;
1830       for ( ; It.More(); It.Next() )
1831       {
1832         SMESH::SMESH_GroupBase_var aGroup =
1833           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1834         if (!aGroup->_is_nil()) {
1835           nbSelectedGroups++;
1836           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
1837           aDlg->show();
1838         }
1839       }
1840       if (nbSelectedGroups == 0)
1841         {
1842           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
1843           aDlg->show();
1844         }
1845       break;
1846     }
1847
1848   case 804:                                     // Add elements to group
1849     {
1850       if(checkLock(aStudy)) break;
1851       if (myState == 800) {
1852         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1853         if (aDlg) aDlg->onAdd();
1854       }
1855       break;
1856     }
1857
1858   case 805:                                     // Remove elements from group
1859     {
1860       if(checkLock(aStudy)) break;
1861       if (myState == 800) {
1862         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1863         if (aDlg) aDlg->onRemove();
1864       }
1865       break;
1866     }
1867
1868     case 810: // Union Groups
1869     case 811: // Intersect groups
1870     case 812: // Cut groups
1871     {
1872       if ( !vtkwnd )
1873       {
1874         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1875                                   tr( "NOT_A_VTK_VIEWER" ) );
1876         break;
1877       }
1878
1879       if ( checkLock( aStudy ) )
1880         break;
1881
1882       EmitSignalDeactivateDialog();
1883
1884       int aMode;
1885       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1886       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1887       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1888
1889       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1890       break;
1891     }
1892
1893     case 813: // Delete groups with their contents
1894     {
1895       if ( !vtkwnd )
1896       {
1897         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1898                                   tr( "NOT_A_VTK_VIEWER" ) );
1899         break;
1900       }
1901
1902       if ( checkLock( aStudy ) )
1903         break;
1904
1905       EmitSignalDeactivateDialog();
1906
1907       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
1908       break;
1909     }
1910
1911   case 900:                                     // MESH INFOS
1912     {
1913       EmitSignalDeactivateDialog();
1914       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1915       SALOME_ListIO selected;
1916       if( aSel )
1917         aSel->selectedObjects( selected );
1918
1919       if ( selected.Extent() > 1 ) { // a dlg for each IO
1920         SALOME_ListIO IOs;
1921         SALOME_ListIteratorOfListIO It (selected);
1922         for ( ; It.More(); It.Next() ) {
1923           IOs.Clear(); IOs.Append( It.Value() );
1924           aSel->setSelectedObjects( IOs );
1925           ( new SMESHGUI_MeshInfosDlg( this ) )->show();
1926         }
1927         // restore selection
1928         aSel->setSelectedObjects( selected );
1929       }
1930       else
1931         ( new SMESHGUI_MeshInfosDlg( this ) )->show();
1932       break;
1933     }
1934
1935   case 902:                                     // STANDARD MESH INFOS
1936     {
1937       EmitSignalDeactivateDialog();
1938       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1939       SALOME_ListIO selected;
1940       if( aSel )
1941         aSel->selectedObjects( selected );
1942
1943       if ( selected.Extent() > 1 ) { // a dlg for each IO
1944         SALOME_ListIO IOs;
1945         SALOME_ListIteratorOfListIO It (selected);
1946         for ( ; It.More(); It.Next() ) {
1947           IOs.Clear();
1948           IOs.Append( It.Value() );
1949           aSel->setSelectedObjects( IOs );
1950           ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
1951         }
1952         // restore selection
1953         aSel->setSelectedObjects( selected );
1954       }
1955       else
1956         ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
1957       break;
1958     }
1959
1960   case 903:                                     // WHAT IS
1961     {
1962       EmitSignalDeactivateDialog();
1963       ( new SMESHGUI_WhatIsDlg( this ) )->show();
1964       break;
1965     }
1966
1967   case 1100:                                    // EDIT HYPOTHESIS
1968     {
1969       if(checkLock(aStudy)) break;
1970
1971       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1972       SALOME_ListIO selected;
1973       if( aSel )
1974         aSel->selectedObjects( selected );
1975
1976       int nbSel = selected.Extent();
1977
1978       if (nbSel == 1) {
1979         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1980         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
1981
1982         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1983         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1984         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1985         if ( !aHypothesis->_is_nil() )
1986         {
1987           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
1988           if (aCreator)
1989             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
1990           else
1991           {
1992             // report error
1993           }
1994         }
1995       }
1996       updateObjBrowser( true );
1997       break;
1998     }
1999
2000   case 1101:                                    // RENAME
2001     {
2002       if ( checkLock( aStudy ) )
2003         break;
2004
2005       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2006       SALOME_ListIO selected;
2007       if( aSel )
2008         aSel->selectedObjects( selected );
2009
2010       bool isAny = false; // iss there any appropriate object selected
2011
2012       SALOME_ListIteratorOfListIO It( selected );
2013       for ( ; It.More(); It.Next() )
2014       {
2015         Handle(SALOME_InteractiveObject) IObject = It.Value();
2016         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2017         _PTR(GenericAttribute) anAttr;
2018         _PTR(AttributeName) aName;
2019         if ( obj )
2020         {
2021           if ( obj->FindAttribute(anAttr, "AttributeName") )
2022           {
2023             aName = anAttr;
2024             QString newName = QString(aName->Value().c_str());
2025
2026             // check type to prevent renaming of inappropriate objects
2027             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2028             if (aType == MESH || aType == GROUP ||
2029                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2030                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2031                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2032                 aType == HYPOTHESIS || aType == ALGORITHM)
2033             {
2034               isAny = true;
2035               newName = LightApp_NameDlg::getName(desktop(), newName);
2036               if ( !newName.isEmpty() )
2037               {
2038                 //old source: aStudy->renameIObject( IObject, newName );
2039                 aName->SetValue( newName.toLatin1().constData() );
2040
2041                 // if current object is group update group's name
2042                 SMESH::SMESH_GroupBase_var aGroup =
2043                   SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2044                 if (!aGroup->_is_nil() )
2045                   aGroup->SetName( newName.toLatin1().constData() );
2046
2047                 updateObjBrowser();
2048               }
2049             }
2050           }
2051         }
2052       } // for
2053
2054       if (!isAny) {
2055         SUIT_MessageBox::warning(desktop(),
2056                                  QObject::tr("SMESH_WRN_WARNING"),
2057                                  QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"));
2058       }
2059       break;
2060     }
2061
2062   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2063     {
2064       if(checkLock(aStudy)) break;
2065       SUIT_OverrideCursor wc;
2066
2067       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2068       SALOME_ListIO selected;
2069       if( aSel )
2070         aSel->selectedObjects( selected, QString::null, false );
2071
2072       SALOME_ListIteratorOfListIO It(selected);
2073       for (int i = 0; It.More(); It.Next(), i++) {
2074         Handle(SALOME_InteractiveObject) IObject = It.Value();
2075         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2076       }
2077       SALOME_ListIO l1;
2078       aSel->setSelectedObjects( l1 );
2079       updateObjBrowser();
2080       break;
2081     }
2082
2083   case 401:                                     // GEOM::EDGE
2084   case 4021:                                    // TRIANGLE
2085   case 4022:                                    // QUAD
2086   case 4023:                                    // POLYGON
2087   case 4031:                                    // TETRA
2088   case 4032:                                    // HEXA
2089     {
2090       if(checkLock(aStudy)) break;
2091       if ( vtkwnd ) {
2092         EmitSignalDeactivateDialog();
2093         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2094         int                 nbNodes = 2;
2095         switch (theCommandID) {
2096         case 4021:                                      // TRIANGLE
2097           type = SMDSAbs_Face; nbNodes = 3; break;
2098         case 4022:                                      // QUAD
2099           type = SMDSAbs_Face; nbNodes = 4; break;
2100         case 4031:                                      // TETRA
2101           type = SMDSAbs_Volume; nbNodes = 4; break;
2102         case 4023:                                      // POLYGON
2103           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2104         case 4032:                                      // HEXA
2105           type = SMDSAbs_Volume; nbNodes = 8; break;
2106         case 4033:                                      // POLYHEDRE
2107           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2108         default:;
2109         }
2110         ( new SMESHGUI_AddMeshElementDlg( this, type, nbNodes ) )->show();
2111       }
2112       else {
2113         SUIT_MessageBox::warning(desktop(),
2114                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2115       }
2116       break;
2117     }
2118   case 4033:                                    // POLYHEDRON
2119     {
2120       if(checkLock(aStudy)) break;
2121       if ( vtkwnd ) {
2122         EmitSignalDeactivateDialog();
2123         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2124       }
2125       else {
2126         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2127                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2128       }
2129       break;
2130     }
2131   case 4034:     // QUADRATIC EDGE
2132   case 4035:     // QUADRATIC TRIANGLE
2133   case 4036:     // QUADRATIC QUADRANGLE
2134   case 4037:     // QUADRATIC TETRAHEDRON
2135   case 4038:     // QUADRATIC PYRAMID
2136   case 4039:     // QUADRATIC PENTAHEDRON
2137   case 4040:     // QUADRATIC HEXAHEDRON
2138     {
2139       if(checkLock(aStudy)) break;
2140       if ( vtkwnd ) {
2141         EmitSignalDeactivateDialog();
2142         int type;
2143
2144         switch (theCommandID) {
2145         case 4034:
2146           type = QUAD_EDGE; break;
2147         case 4035:
2148           type = QUAD_TRIANGLE; break;
2149         case 4036:
2150           type = QUAD_QUADRANGLE; break;
2151         case 4037:
2152           type = QUAD_TETRAHEDRON; break;
2153         case 4038:
2154           type = QUAD_PYRAMID; break;
2155         case 4039:
2156           type = QUAD_PENTAHEDRON; break;
2157         case 4040:
2158           type = QUAD_HEXAHEDRON;
2159           break;
2160         default:;
2161         }
2162          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
2163       }
2164       else {
2165         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2166                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2167       }
2168       break;
2169     }
2170   case 4041:                                    // REMOVES NODES
2171     {
2172       if(checkLock(aStudy)) break;
2173       if ( vtkwnd ) {
2174         EmitSignalDeactivateDialog();
2175         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
2176       }
2177       else {
2178         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2179                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2180       }
2181       break;
2182     }
2183   case 4042:                                    // REMOVES ELEMENTS
2184     {
2185       if(checkLock(aStudy)) break;
2186       if( vtkwnd ) {
2187         EmitSignalDeactivateDialog();
2188         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
2189       }
2190       else
2191         {
2192           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2193                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2194         }
2195       break;
2196     }
2197   case 4043: {                                // CLEAR_MESH
2198
2199     if(checkLock(aStudy)) break;
2200
2201     SALOME_ListIO selected;
2202     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2203       aSel->selectedObjects( selected );
2204
2205     SUIT_OverrideCursor wc;
2206     SALOME_ListIteratorOfListIO It (selected);
2207     for ( ; It.More(); It.Next() )
2208     {
2209       Handle(SALOME_InteractiveObject) IOS = It.Value();
2210       SMESH::SMESH_Mesh_var aMesh =
2211         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2212       if ( aMesh->_is_nil()) continue;
2213       try {
2214         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2215         aMesh->Clear();
2216         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2217         SMESH::ModifiedMesh( aMeshSObj, false, true);
2218         // hide groups and submeshes
2219         _PTR(ChildIterator) anIter =
2220           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2221         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2222         {
2223           _PTR(SObject) so = anIter->Value();
2224           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2225         }
2226       }
2227       catch (const SALOME::SALOME_Exception& S_ex){
2228         wc.suspend();
2229         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2230         wc.resume();
2231       }
2232     }
2233     SMESH::UpdateView();
2234     updateObjBrowser();
2235     break;
2236   }
2237   case 4051:                                    // RENUMBERING NODES
2238     {
2239       if(checkLock(aStudy)) break;
2240       if( vtkwnd ) {
2241         EmitSignalDeactivateDialog();
2242         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
2243       }
2244       else
2245         {
2246           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2247                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2248         }
2249       break;
2250     }
2251   case 4052:                                    // RENUMBERING ELEMENTS
2252     {
2253       if(checkLock(aStudy)) break;
2254       if ( vtkwnd ) {
2255         EmitSignalDeactivateDialog();
2256         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
2257       }
2258       else
2259         {
2260           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2261                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2262         }
2263       break;
2264     }
2265   case 4061:                                   // TRANSLATION
2266     {
2267       if(checkLock(aStudy)) break;
2268       if ( vtkwnd ) {
2269         EmitSignalDeactivateDialog();
2270         ( new SMESHGUI_TranslationDlg( this ) )->show();
2271       }
2272       else {
2273         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2274                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2275       }
2276       break;
2277     }
2278   case 4062:                                   // ROTATION
2279     {
2280       if(checkLock(aStudy)) break;
2281       if( vtkwnd ) {
2282         EmitSignalDeactivateDialog();
2283         ( new SMESHGUI_RotationDlg( this ) )->show();
2284       }
2285       else {
2286         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2287                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2288       }
2289       break;
2290     }
2291   case 4063:                                   // SYMMETRY
2292     {
2293       if(checkLock(aStudy)) break;
2294       if(vtkwnd) {
2295         EmitSignalDeactivateDialog();
2296         ( new SMESHGUI_SymmetryDlg( this ) )->show();
2297       }
2298       else {
2299         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2300                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2301       }
2302       break;
2303     }
2304   case 4064:                                   // SEWING
2305     {
2306       if(checkLock(aStudy)) break;
2307       if(vtkwnd) {
2308         EmitSignalDeactivateDialog();
2309         ( new SMESHGUI_SewingDlg( this ) )->show();
2310       }
2311       else {
2312         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2313                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2314       }
2315       break;
2316     }
2317   case 4065:                                   // MERGE NODES
2318     {
2319       if(checkLock(aStudy)) break;
2320       if(vtkwnd) {
2321         EmitSignalDeactivateDialog();
2322         ( new SMESHGUI_EditMeshDlg( this, 0 ) )->show();
2323       }
2324       else {
2325         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2326                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2327       }
2328       break;
2329     }
2330   case 4066:                                   // MERGE EQUAL ELEMENTS
2331     {
2332       if (checkLock(aStudy)) break;
2333       if (vtkwnd) {
2334         EmitSignalDeactivateDialog();
2335         ( new SMESHGUI_EditMeshDlg( this, 1 ) )->show();
2336       } else {
2337         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2338                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2339       }
2340       break;
2341     }
2342
2343   case 4067: // MAKE MESH PASS THROUGH POINT
2344     startOperation( 4067 );
2345     break;
2346
2347   case 5105: // Library of selection filters
2348   {
2349     static QList<int> aTypes;
2350     if ( aTypes.isEmpty() )
2351     {
2352       aTypes.append( SMESH::NODE );
2353       aTypes.append( SMESH::EDGE );
2354       aTypes.append( SMESH::FACE );
2355       aTypes.append( SMESH::VOLUME );
2356     }
2357     if (!myFilterLibraryDlg)
2358       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2359     else if (myFilterLibraryDlg->isHidden())
2360       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2361     myFilterLibraryDlg->raise();
2362   }
2363   break;
2364
2365   case 6017:                                    // CONTROLS
2366   case 6016:
2367   case 6015:
2368   case 6014:
2369   case 6013:
2370   case 6012:
2371   case 6011:
2372   case 6001:
2373   case 6018:
2374   case 6019:
2375   case 6002:
2376   case 6003:
2377   case 6004:
2378   case 6009:
2379     if ( vtkwnd ) {
2380
2381       LightApp_SelectionMgr* mgr = selectionMgr();
2382       SALOME_ListIO selected; mgr->selectedObjects( selected );
2383
2384       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2385         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2386         if ( SO ) {
2387           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2388           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2389           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2390           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2391           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2392             ::Control( theCommandID );
2393             break;
2394           }
2395         }
2396       }
2397       SUIT_MessageBox::warning(desktop(),
2398                                tr( "SMESH_WRN_WARNING" ),
2399                                tr( "SMESH_BAD_SELECTION" ) );
2400       break;
2401     }
2402     else {
2403       SUIT_MessageBox::warning(desktop(),
2404                                tr( "SMESH_WRN_WARNING" ),
2405                                tr( "NOT_A_VTK_VIEWER" ) );
2406     }
2407     break;
2408   case 9010:
2409     {
2410       LightApp_SelectionMgr* mgr = selectionMgr();
2411       SALOME_ListIO selected; mgr->selectedObjects( selected );
2412
2413       SALOME_ListIteratorOfListIO it(selected);
2414       for( ; it.More(); it.Next()) {
2415         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2416         if(anIObject->hasEntry()) {
2417           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2418             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2419           }
2420         }
2421       }
2422       break;
2423     }
2424   case 9011:
2425     {
2426       LightApp_SelectionMgr* mgr = selectionMgr();
2427       SALOME_ListIO selected; mgr->selectedObjects( selected );
2428
2429       if (selected.Extent() == 1)       {
2430         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2431         if(anIObject->hasEntry())
2432           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2433             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2434           }
2435       }
2436       break;
2437     }
2438   }
2439
2440   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2441   //updateObjBrowser();
2442   return true;
2443 }
2444
2445 //=============================================================================
2446 /*!
2447  *
2448  */
2449 //=============================================================================
2450 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2451 {
2452   return false;
2453 }
2454
2455 //=============================================================================
2456 /*!
2457  *
2458  */
2459 //=============================================================================
2460 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2461 {
2462   return true;
2463 }
2464
2465 //=============================================================================
2466 /*!
2467  *
2468  */
2469 //=============================================================================
2470 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2471 {
2472   return true;
2473 }
2474
2475 //=============================================================================
2476 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2477  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2478  */
2479 //=============================================================================
2480 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2481                                   SUIT_ViewWindow* wnd )
2482 {
2483   if(theIO->hasEntry()){
2484     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2485     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2486   }
2487 }
2488
2489 //=======================================================================
2490 // function : createSMESHAction
2491 // purpose  :
2492 //=======================================================================
2493 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2494 {
2495   QIcon icon;
2496   QWidget* parent = application()->desktop();
2497   SUIT_ResourceMgr* resMgr = resourceMgr();
2498   QPixmap pix;
2499   if ( !icon_id.isEmpty() )
2500     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
2501   else
2502     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
2503   if ( !pix.isNull() )
2504     icon = QIcon( pix );
2505
2506   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
2507           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
2508           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
2509
2510   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2511 }
2512
2513 //=======================================================================
2514 // function : createPopupItem
2515 // purpose  :
2516 //=======================================================================
2517 void SMESHGUI::createPopupItem( const int id,
2518                                 const QString& clients,
2519                                 const QString& types,
2520                                 const QString& theRule,
2521                                 const int pId )
2522 {
2523   int parentId = pId;
2524   if( pId!=-1 )
2525     parentId = popupMgr()->actionId( action( pId ) );
2526
2527   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2528     popupMgr()->insert( action( id ), parentId, 0 );
2529
2530   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
2531   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
2532   QString rule = "(%1) and (%2) and (%3)";
2533   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
2534   if( clients.isEmpty() )
2535     rule = rule.arg( QString( "true" ) );
2536   else
2537     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2538   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2539   rule += theRule;
2540
2541   bool cont = myRules.contains( id );
2542   if( cont )
2543     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2544
2545   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
2546   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2547 }
2548
2549 //=======================================================================
2550 // function : initialize
2551 // purpose  :
2552 //=======================================================================
2553 void SMESHGUI::initialize( CAM_Application* app )
2554 {
2555   SalomeApp_Module::initialize( app );
2556
2557 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2558 //   if ( mgr )
2559   /* Automatic Update flag */
2560 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2561
2562   // ----- create actions --------------
2563
2564   createSMESHAction(  111, "DAT", "", (Qt::CTRL+Qt::Key_B) );
2565   createSMESHAction(  112, "UNV", "", (Qt::CTRL+Qt::Key_U) );
2566   createSMESHAction(  113, "MED", "", (Qt::CTRL+Qt::Key_M) );
2567   createSMESHAction(  114, "NUM" );
2568   createSMESHAction(  121, "DAT" );
2569   createSMESHAction(  122, "MED" );
2570   createSMESHAction(  123, "UNV" );
2571   createSMESHAction(  140, "STL" );
2572   createSMESHAction(  124, "EXPORT_DAT" );
2573   createSMESHAction(  125, "EXPORT_MED" );
2574   createSMESHAction(  126, "EXPORT_UNV" );
2575   createSMESHAction(  141, "EXPORT_STL" );
2576   createSMESHAction(  150, "FILE_INFO" );
2577   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
2578   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2579   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2580   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2581   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2582   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2583   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2584   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
2585   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
2586   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2587   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2588   createSMESHAction(  804, "ADD" );
2589   createSMESHAction(  805, "REMOVE" );
2590   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2591   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2592   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2593   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2594   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2595   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2596   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2597   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
2598   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
2599   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
2600   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
2601   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
2602   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
2603   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
2604   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
2605   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
2606   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2607   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2608   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2609   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2610   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2611   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2612   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2613   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2614   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2615   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2616   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2617   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2618   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2619   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2620   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2621   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2622   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2623   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2624   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2625   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2626   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2627   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2628   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2629   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2630   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2631   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2632   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2633   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2634   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2635   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2636   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2637   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2638   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2639   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2640   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2641   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2642   createSMESHAction(  200, "RESET" );
2643   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2644   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2645   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2646   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2647   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2648   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2649   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2650   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2651   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2652   createSMESHAction(  220, "ALL" );
2653   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
2654   createSMESHAction( 1100, "EDIT_HYPO" );
2655   createSMESHAction( 1101, "RENAME", "", Qt::Key_F2 );
2656   createSMESHAction( 1102, "UNASSIGN" );
2657   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2658   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2659   createSMESHAction( 1131, "DISPMODE" );
2660   createSMESHAction( 1132, "COLORS" );
2661   createSMESHAction( 1133, "TRANSP" );
2662   createSMESHAction( 1134, "CLIP" );
2663   createSMESHAction( 1135, "DISP_ENT" );
2664   createSMESHAction( 1136, "AUTO_COLOR" );
2665   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2666   createSMESHAction( 2000, "CTRL" );
2667
2668   createSMESHAction( 300, "ERASE" );
2669   createSMESHAction( 301, "DISPLAY" );
2670   createSMESHAction( 302, "DISPLAY_ONLY" );
2671   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2672   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2673   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2674   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2675   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2676   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2677   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2678   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2679
2680   // ----- create menu --------------
2681   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2682       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2683       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2684       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2685       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2686       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2687       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2688
2689   createMenu( separator(), fileId );
2690
2691   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2692       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2693       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2694       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2695       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2696       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2697
2698   createMenu( 111, importId, -1 );
2699   createMenu( 112, importId, -1 );
2700   createMenu( 113, importId, -1 );
2701
2702   createMenu( 121, exportId, -1 );
2703   createMenu( 122, exportId, -1 );
2704   createMenu( 123, exportId, -1 );
2705   createMenu( 140, exportId, -1 ); // export to stl STL
2706
2707   createMenu( separator(), fileId, 10 );
2708
2709   createMenu( 33, editId, -1 );
2710
2711   createMenu( 5105, toolsId, -1 );
2712
2713   createMenu( 702, meshId, -1 ); // "Mesh" menu
2714   createMenu( 703, meshId, -1 );
2715   createMenu( 704, meshId, -1 );
2716   createMenu( 710, meshId, -1 );
2717   createMenu( separator(), meshId, -1 );
2718   createMenu( 701, meshId, -1 );
2719   createMenu( separator(), meshId, -1 );
2720   createMenu( 801, meshId, -1 );
2721   createMenu( 806, meshId, -1 );
2722   createMenu( 802, meshId, -1 );
2723   createMenu( 803, meshId, -1 );
2724   createMenu( separator(), meshId, -1 );
2725   createMenu( 810, meshId, -1 );
2726   createMenu( 811, meshId, -1 );
2727   createMenu( 812, meshId, -1 );
2728   createMenu( separator(), meshId, -1 );
2729   createMenu( 813, meshId, -1 );
2730   createMenu( separator(), meshId, -1 );
2731   createMenu( 900, meshId, -1 );
2732   createMenu( 902, meshId, -1 );
2733   createMenu( 903, meshId, -1 );
2734   createMenu( separator(), meshId, -1 );
2735
2736   createMenu( 6003, ctrlId, -1 );
2737   createMenu( 6001, ctrlId, -1 );
2738   createMenu( 6004, ctrlId, -1 );
2739   createMenu( separator(), ctrlId, -1 );
2740   createMenu( 6002, ctrlId, -1 );
2741   createMenu( 6018, ctrlId, -1 );
2742   createMenu( 6019, ctrlId, -1 );
2743   createMenu( 6011, ctrlId, -1 );
2744   createMenu( 6012, ctrlId, -1 );
2745   createMenu( 6013, ctrlId, -1 );
2746   createMenu( 6014, ctrlId, -1 );
2747   createMenu( 6015, ctrlId, -1 );
2748   createMenu( 6016, ctrlId, -1 );
2749   createMenu( separator(), ctrlId, -1 );
2750   createMenu( 6017, ctrlId, -1 );
2751   createMenu( 6009, ctrlId, -1 );
2752   createMenu( separator(), ctrlId, -1 );
2753
2754   createMenu( 400, addId, -1 );
2755   createMenu( 401, addId, -1 );
2756   createMenu( 4021, addId, -1 );
2757   createMenu( 4022, addId, -1 );
2758   createMenu( 4023, addId, -1 );
2759   createMenu( 4031, addId, -1 );
2760   createMenu( 4032, addId, -1 );
2761   createMenu( 4033, addId, -1 );
2762   createMenu( separator(), addId, -1 );
2763   createMenu( 4034, addId, -1 );
2764   createMenu( 4035, addId, -1 );
2765   createMenu( 4036, addId, -1 );
2766   createMenu( 4037, addId, -1 );
2767   createMenu( 4038, addId, -1 );
2768   createMenu( 4039, addId, -1 );
2769   createMenu( 4040, addId, -1 );
2770
2771   createMenu( 4041, removeId, -1 );
2772   createMenu( 4042, removeId, -1 );
2773   createMenu( 4043, removeId, -1 );
2774
2775   createMenu( 4051, renumId, -1 );
2776   createMenu( 4052, renumId, -1 );
2777
2778   createMenu( 4061, transfId, -1 );
2779   createMenu( 4062, transfId, -1 );
2780   createMenu( 4063, transfId, -1 );
2781   createMenu( 4064, transfId, -1 );
2782   createMenu( 4065, transfId, -1 );
2783   createMenu( 4066, transfId, -1 );
2784
2785   createMenu( 406, modifyId, -1 );
2786   createMenu( 4067,modifyId, -1 );
2787   createMenu( 407, modifyId, -1 );
2788   createMenu( 408, modifyId, -1 );
2789   createMenu( 409, modifyId, -1 );
2790   createMenu( 410, modifyId, -1 );
2791   createMenu( 411, modifyId, -1 );
2792   createMenu( 412, modifyId, -1 );
2793   createMenu( 413, modifyId, -1 );
2794   createMenu( 416, modifyId, -1 );
2795   createMenu( 414, modifyId, -1 );
2796   createMenu( 415, modifyId, -1 );
2797   createMenu( 417, modifyId, -1 );
2798
2799   createMenu( 214, viewId, -1 );
2800
2801   // ----- create toolbars --------------
2802   int meshTb     = createTool( tr( "TB_MESH" ) ),
2803       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2804       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2805       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2806       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2807
2808   createTool( 702, meshTb );
2809   createTool( 703, meshTb );
2810   createTool( 704, meshTb );
2811   createTool( 710, meshTb );
2812   createTool( separator(), meshTb );
2813   createTool( 701, meshTb );
2814   createTool( separator(), meshTb );
2815   createTool( 801, meshTb );
2816   createTool( 806, meshTb );
2817   createTool( 802, meshTb );
2818   createTool( 803, meshTb );
2819   createTool( separator(), meshTb );
2820   createTool( 900, meshTb );
2821   createTool( 902, meshTb );
2822   createTool( 903, meshTb );
2823   createTool( separator(), meshTb );
2824
2825   createTool( 6001, ctrlTb );
2826   createTool( 6003, ctrlTb );
2827   createTool( 6004, ctrlTb );
2828   createTool( separator(), ctrlTb );
2829   createTool( 6002, ctrlTb );
2830   createTool( 6018, ctrlTb );
2831   createTool( 6019, ctrlTb );
2832   createTool( 6011, ctrlTb );
2833   createTool( 6012, ctrlTb );
2834   createTool( 6013, ctrlTb );
2835   createTool( 6014, ctrlTb );
2836   createTool( 6015, ctrlTb );
2837   createTool( 6016, ctrlTb );
2838   createTool( separator(), ctrlTb );
2839   createTool( 6017, ctrlTb );
2840   createTool( 6009, ctrlTb );
2841   createTool( separator(), ctrlTb );
2842
2843   createTool( 400, addRemTb );
2844   createTool( 401, addRemTb );
2845   createTool( 4021, addRemTb );
2846   createTool( 4022, addRemTb );
2847   createTool( 4023, addRemTb );
2848   createTool( 4031, addRemTb );
2849   createTool( 4032, addRemTb );
2850   createTool( 4033, addRemTb );
2851   createTool( separator(), addRemTb );
2852   createTool( 4034, addRemTb );
2853   createTool( 4035, addRemTb );
2854   createTool( 4036, addRemTb );
2855   createTool( 4037, addRemTb );
2856   createTool( 4038, addRemTb );
2857   createTool( 4039, addRemTb );
2858   createTool( 4040, addRemTb );
2859   createTool( separator(), addRemTb );
2860   createTool( 4041, addRemTb );
2861   createTool( 4042, addRemTb );
2862   createTool( 4043, addRemTb );
2863   createTool( separator(), addRemTb );
2864   createTool( 4051, addRemTb );
2865   createTool( 4052, addRemTb );
2866   createTool( separator(), addRemTb );
2867   createTool( 4061, addRemTb );
2868   createTool( 4062, addRemTb );
2869   createTool( 4063, addRemTb );
2870   createTool( 4064, addRemTb );
2871   createTool( 4065, addRemTb );
2872   createTool( 4066, addRemTb );
2873   createTool( separator(), addRemTb );
2874
2875   createTool( 406, modifyTb );
2876   createTool( 4067,modifyTb );
2877   createTool( 407, modifyTb );
2878   createTool( 408, modifyTb );
2879   createTool( 409, modifyTb );
2880   createTool( 410, modifyTb );
2881   createTool( 411, modifyTb );
2882   createTool( 412, modifyTb );
2883   createTool( 413, modifyTb );
2884   createTool( 416, modifyTb );
2885   createTool( 414, modifyTb );
2886   createTool( 415, modifyTb );
2887   createTool( 417, modifyTb );
2888
2889   createTool( 214, dispModeTb );
2890
2891   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
2892   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
2893
2894   myRules.clear();
2895   QString OB = "'ObjectBrowser'",
2896           View = "'" + SVTK_Viewer::Type() + "'",
2897           pat = "'%1'",
2898           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2899           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2900           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2901           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2902           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2903                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2904                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2905                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2906                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2907                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2908                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2909           subMesh = elems,
2910           mesh_group = mesh + " " + subMesh + " " + group,
2911           hyp_alg = hypo + " " + algo;
2912
2913   // popup for object browser
2914
2915   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
2916   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2917   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2918   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2919   popupMgr()->insert( separator(), -1, 0 );
2920   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2921   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2922   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2923   createPopupItem( 902, OB, mesh );                        // STD_INFO
2924   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2925   popupMgr()->insert( separator(), -1, 0 );
2926   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2927   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
2928   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2929   popupMgr()->insert( separator(), -1, 0 );
2930   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
2931   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2932   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2933   popupMgr()->insert( separator(), -1, 0 );
2934   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
2935   popupMgr()->insert( separator(), -1, 0 );
2936
2937   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
2938
2939   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2940   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2941   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2942   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2943   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2944   popupMgr()->insert( separator(), -1, 0 );
2945
2946   // popup for viewer
2947   createPopupItem( 803, View, group ); // EDIT_GROUP
2948   createPopupItem( 804, View, elems ); // ADD
2949   createPopupItem( 805, View, elems ); // REMOVE
2950   popupMgr()->insert( separator(), -1, 0 );
2951   createPopupItem( 214, View, mesh_group ); // UPDATE
2952   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2953   createPopupItem( 902, View, mesh );       // STD_INFO
2954   createPopupItem( 903, View, mesh_group ); // WHAT_IS
2955   popupMgr()->insert( separator(), -1, 0 );
2956
2957   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2958   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2959   popupMgr()->insert( separator(), -1, 0 );
2960
2961   int anId;
2962   QString
2963     isInvisible("not( isVisible )"),
2964     isEmpty("numberOfNodes = 0"),
2965     isNotEmpty("numberOfNodes <> 0"),
2966
2967     // has nodes, edges, etc in VISIBLE! actor
2968     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2969     hasElems("(count( elemTypes ) > 0)"),
2970     hasDifferentElems("(count( elemTypes ) > 1)"),
2971     hasEdges("({'Edge'} in elemTypes)"),
2972     hasFaces("({'Face'} in elemTypes)"),
2973     hasVolumes("({'Volume'} in elemTypes)");
2974
2975   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2976   QString aType = QString( "%1type in {%2}" ).arg( lc );
2977   aType = aType.arg( mesh_group );
2978   QString aMeshInVTK = aClient + "&&" + aType;
2979
2980   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2981   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2982   QString aSelCount = QString( "%1 > 0" ).arg( dc );
2983
2984   //-------------------------------------------------
2985   // Numbering
2986   //-------------------------------------------------
2987   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2988
2989   popupMgr()->insert( action( 9010 ), anId, -1 );
2990   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
2991   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
2992
2993   popupMgr()->insert( action( 9011 ), anId, -1 );
2994   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
2995   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
2996
2997   popupMgr()->insert( separator(), -1, -1 );
2998
2999   //-------------------------------------------------
3000   // Display Mode
3001   //-------------------------------------------------
3002   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3003
3004   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3005   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3006   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3007
3008   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3009   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3010   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3011
3012   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3013   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3014   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3015
3016   popupMgr()->insert( separator(), anId, -1 );
3017
3018   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3019   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3020   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3021
3022   //-------------------------------------------------
3023   // Display Entity
3024   //-------------------------------------------------
3025   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3026
3027   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3028
3029   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3030   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3031   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3032
3033   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3034   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3035   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3036
3037   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3038   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3039   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3040
3041   popupMgr()->insert( separator(), anId, -1 );
3042
3043   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3044   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3045
3046   //-------------------------------------------------
3047   // Orientation of faces
3048   //-------------------------------------------------
3049   popupMgr()->insert( action( 221 ), -1, -1 );
3050   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3051   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3052
3053   //-------------------------------------------------
3054   // Color / Size
3055   //-------------------------------------------------
3056   popupMgr()->insert( action( 1132 ), -1, -1 );
3057   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3058
3059   //-------------------------------------------------
3060   // Transparency
3061   //-------------------------------------------------
3062   popupMgr()->insert( action( 1133 ), -1, -1 );
3063   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3064
3065   //-------------------------------------------------
3066   // Clipping
3067   //-------------------------------------------------
3068   popupMgr()->insert( action( 1134 ), -1, -1 );
3069   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3070
3071   popupMgr()->insert( separator(), -1, -1 );
3072
3073   //-------------------------------------------------
3074   // Controls
3075   //-------------------------------------------------
3076   QString
3077     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3078     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3079     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3080
3081   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3082
3083   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3084   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3085
3086   popupMgr()->insert( separator(), anId, -1 );
3087
3088   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3089   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3090   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3091
3092   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3093   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3094   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3095
3096   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3097   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3098   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3099
3100   popupMgr()->insert( separator(), anId, -1 );
3101
3102   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3103   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3104   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3105
3106   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3107   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3108   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3109
3110   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3111   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3112   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3113
3114   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3115   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3116   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3117
3118   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3119   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3120   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
3121
3122   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3123   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3124   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
3125
3126   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3127   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3128   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
3129
3130   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3131   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3132   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
3133
3134   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3135   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3136   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
3137
3138   popupMgr()->insert( separator(), anId, -1 );
3139
3140   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3141   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3142   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
3143
3144   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3145   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3146   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
3147
3148   popupMgr()->insert( separator(), anId, -1 );
3149
3150   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3151   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3152
3153   popupMgr()->insert( separator(), -1, -1 );
3154
3155   //-------------------------------------------------
3156   // Display / Erase
3157   //-------------------------------------------------
3158   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3159     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3160   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3161   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
3162
3163   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3164   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
3165
3166   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3167   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
3168
3169   popupMgr()->insert( separator(), -1, -1 );
3170
3171   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3172            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3173 }
3174
3175 //================================================================================
3176 /*!
3177  * \brief Return true if SMESH or GEOM objects are selected.
3178  * Is called form LightApp_Module::activateModule() which clear selection if
3179  * not isSelectionCompatible()
3180  */
3181 //================================================================================
3182
3183 bool SMESHGUI::isSelectionCompatible()
3184 {
3185   bool isCompatible = true;
3186   SALOME_ListIO selected;
3187   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3188     Sel->selectedObjects( selected );
3189
3190   SALOME_ListIteratorOfListIO It( selected );
3191   for ( ; isCompatible && It.More(); It.Next())
3192     isCompatible =
3193       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3194       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3195
3196   return isCompatible;
3197 }
3198
3199 bool SMESHGUI::activateModule( SUIT_Study* study )
3200 {
3201   bool res = SalomeApp_Module::activateModule( study );
3202
3203   setMenuShown( true );
3204   setToolShown( true );
3205
3206   // Reset actions accelerator keys
3207   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
3208   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
3209   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
3210
3211   action(  33)->setEnabled(true); // Delete: Key_Delete
3212   action(1101)->setEnabled(true); // Rename: Key_F2
3213
3214   return res;
3215 }
3216
3217 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3218 {
3219   setMenuShown( false );
3220   setToolShown( false );
3221
3222   EmitSignalCloseAllDialogs();
3223
3224   // Unset actions accelerator keys
3225   action(111)->setShortcut(QKeySequence()); // Import DAT
3226   action(112)->setShortcut(QKeySequence()); // Import UNV
3227   action(113)->setShortcut(QKeySequence()); // Import MED
3228
3229   action(  33)->setEnabled(false); // Delete: Key_Delete
3230   action(1101)->setEnabled(false); // Rename: Key_F2
3231
3232   return SalomeApp_Module::deactivateModule( study );
3233 }
3234
3235 void SMESHGUI::studyClosed( SUIT_Study* s )
3236 {
3237   SMESH::RemoveVisuData( s->id() );
3238   SalomeApp_Module::studyClosed( s );
3239 }
3240
3241 void SMESHGUI::OnGUIEvent()
3242 {
3243   const QObject* obj = sender();
3244   if ( !obj || !obj->inherits( "QAction" ) )
3245     return;
3246   int id = actionId((QAction*)obj);
3247   if ( id != -1 )
3248     OnGUIEvent( id );
3249 }
3250
3251 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3252 {
3253   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3254   if ( CORBA::is_nil( myComponentSMESH ) )
3255     {
3256       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3257       if ( aStudy )
3258         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3259       return aGUI.myComponentSMESH;
3260     }
3261   if ( aStudy )
3262     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3263   return myComponentSMESH;
3264 }
3265
3266 QString SMESHGUI::engineIOR() const
3267 {
3268   CORBA::ORB_var anORB = getApp()->orb();
3269   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3270   return QString( anIOR.in() );
3271 }
3272
3273 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
3274 {
3275   SalomeApp_Module::contextMenuPopup( client, menu, title );
3276   SALOME_ListIO lst;
3277   selectionMgr()->selectedObjects( lst );
3278   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3279     Handle(SALOME_InteractiveObject) io = lst.First();
3280     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3281     _PTR(Study) study = appStudy->studyDS();
3282     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3283     if ( obj ) {
3284       QString aName = QString( obj->GetName().c_str() );
3285       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3286           aName.remove( (aName.length() - 1), 1 );
3287       title = aName;
3288     }
3289   }
3290 }
3291
3292 LightApp_Selection* SMESHGUI::createSelection() const
3293 {
3294   return new SMESHGUI_Selection();
3295 }
3296
3297 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3298 {
3299   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
3300   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
3301 }
3302
3303 void SMESHGUI::viewManagers( QStringList& list ) const
3304 {
3305   list.append( SVTK_Viewer::Type() );
3306 }
3307
3308 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3309 {
3310   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3311     SMESH::UpdateSelectionProp( this );
3312 }
3313
3314 void SMESHGUI::createPreferences()
3315 {
3316   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3317
3318   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3319   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3320
3321   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3322   setPreferenceProperty( qaGroup, "columns", 2 );
3323   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3324   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3325
3326   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3327   setPreferenceProperty( precGroup, "columns", 2 );
3328
3329   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3330
3331   setPreferenceProperty( prec, "min", 0 );
3332   setPreferenceProperty( prec, "max", 16 );
3333
3334   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3335   setPreferenceProperty( dispgroup, "columns", 2 );
3336   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3337   QStringList modes;
3338   modes.append( "Wireframe" );
3339   modes.append( "Shading" );
3340   modes.append( "Nodes" );
3341   modes.append( "Shrink" );
3342   QList<QVariant> indices;
3343   indices.append( 0 );
3344   indices.append( 1 );
3345   indices.append( 2 );
3346   indices.append( 3 );
3347   setPreferenceProperty( dispmode, "strings", modes );
3348   setPreferenceProperty( dispmode, "indexes", indices );
3349
3350   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3351   setPreferenceProperty( exportgroup, "columns", 2 );
3352   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3353   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3354
3355   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
3356   setPreferenceProperty( computeGroup, "columns", 2 );
3357   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
3358   modes.clear();
3359   modes.append( "Never" );
3360   modes.append( "Errors only" );
3361   modes.append( "Always" );
3362   indices.clear();
3363   indices.append( 0 );
3364   indices.append( 1 );
3365   indices.append( 2 );
3366   setPreferenceProperty( notifyMode, "strings", modes );
3367   setPreferenceProperty( notifyMode, "indexes", indices );
3368
3369   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3370   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3371   setPreferenceProperty( nodeGroup, "columns", 2 );
3372
3373   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3374   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3375
3376   setPreferenceProperty( nodeSz, "min", 1 );
3377   setPreferenceProperty( nodeSz, "max", 5 );
3378
3379   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3380   setPreferenceProperty( elemGroup, "columns", 2 );
3381
3382   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3383   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3384   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3385   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3386
3387   setPreferenceProperty( sp, "hstretch", 0 );
3388   setPreferenceProperty( sp, "vstretch", 0 );
3389
3390   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3391   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3392
3393   setPreferenceProperty( elemW, "min", 1 );
3394   setPreferenceProperty( elemW, "max", 5 );
3395
3396   setPreferenceProperty( shrink, "min", 0 );
3397   setPreferenceProperty( shrink, "max", 100 );
3398
3399   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
3400   setPreferenceProperty( orientGroup, "columns", 1 );
3401
3402   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
3403   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
3404
3405   setPreferenceProperty( orientScale, "min", 0.05 );
3406   setPreferenceProperty( orientScale, "max", 0.5 );
3407   setPreferenceProperty( orientScale, "step", 0.05 );
3408
3409   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
3410
3411   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3412
3413   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3414   setPreferenceProperty( selGroup, "columns", 2 );
3415
3416   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3417   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3418   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3419
3420   setPreferenceProperty( selW, "min", 1 );
3421   setPreferenceProperty( selW, "max", 5 );
3422
3423   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3424   setPreferenceProperty( preGroup, "columns", 2 );
3425
3426   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3427   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3428
3429   setPreferenceProperty( preW, "min", 1 );
3430   setPreferenceProperty( preW, "max", 5 );
3431
3432   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3433   setPreferenceProperty( precSelGroup, "columns", 2 );
3434
3435   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3436   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3437   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3438
3439   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3440   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3441   setPreferenceProperty( fontGr, "columns", 2 );
3442
3443   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3444   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3445   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3446   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3447
3448   QStringList fam;
3449   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3450   fam.append( tr( "SMESH_FONT_COURIER" ) );
3451   fam.append( tr( "SMESH_FONT_TIMES" ) );
3452   int wflag = ( QtxFontEdit::Family | QtxFontEdit::Scripting );
3453
3454   setPreferenceProperty( tfont, "families", fam );
3455   setPreferenceProperty( tfont, "system", false );
3456   setPreferenceProperty( tfont, "widget_flags", wflag );
3457   setPreferenceProperty( lfont, "families", fam );
3458   setPreferenceProperty( lfont, "system", false );
3459   setPreferenceProperty( lfont, "widget_flags", wflag );
3460
3461   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3462   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
3463
3464   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3465   setPreferenceProperty( numcol, "min", 2 );
3466   setPreferenceProperty( numcol, "max", 256 );
3467
3468   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3469   setPreferenceProperty( numlab, "min", 2 );
3470   setPreferenceProperty( numlab, "max", 65 );
3471
3472   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3473   setPreferenceProperty( orientGr, "columns", 2 );
3474   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3475   QStringList orients;
3476   orients.append( tr( "SMESH_VERTICAL" ) );
3477   orients.append( tr( "SMESH_HORIZONTAL" ) );
3478   indices.clear(); indices.append( 0 ); indices.append( 1 );
3479   setPreferenceProperty( orient, "strings", orients );
3480   setPreferenceProperty( orient, "indexes", indices );
3481
3482   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3483   setPreferenceProperty( posVSizeGr, "columns", 2 );
3484   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3485   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3486   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3487   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3488   setPreferenceProperty( xv, "step", 0.1 );
3489   setPreferenceProperty( xv, "min", 0.0 );
3490   setPreferenceProperty( xv, "max", 1.0 );
3491   setPreferenceProperty( yv, "step", 0.1 );
3492   setPreferenceProperty( yv, "min", 0.0 );
3493   setPreferenceProperty( yv, "max", 1.0 );
3494   setPreferenceProperty( wv, "step", 0.1 );
3495   setPreferenceProperty( wv, "min", 0.0 );
3496   setPreferenceProperty( wv, "max", 1.0 );
3497   setPreferenceProperty( hv, "min", 0.0 );
3498   setPreferenceProperty( hv, "max", 1.0 );
3499   setPreferenceProperty( hv, "step", 0.1 );
3500
3501   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3502   setPreferenceProperty( posHSizeGr, "columns", 2 );
3503   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3504   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3505   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3506   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3507   setPreferenceProperty( xv, "min", 0.0 );
3508   setPreferenceProperty( xv, "max", 1.0 );
3509   setPreferenceProperty( xv, "step", 0.1 );
3510   setPreferenceProperty( xh, "min", 0.0 );
3511   setPreferenceProperty( xh, "max", 1.0 );
3512   setPreferenceProperty( xh, "step", 0.1 );
3513   setPreferenceProperty( yh, "min", 0.0 );
3514   setPreferenceProperty( yh, "max", 1.0 );
3515   setPreferenceProperty( yh, "step", 0.1 );
3516   setPreferenceProperty( wh, "min", 0.0 );
3517   setPreferenceProperty( wh, "max", 1.0 );
3518   setPreferenceProperty( wh, "step", 0.1 );
3519   setPreferenceProperty( hh, "min", 0.0 );
3520   setPreferenceProperty( hh, "max", 1.0 );
3521   setPreferenceProperty( hh, "step", 0.1 );
3522 }
3523
3524 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3525 {
3526   if( sect=="SMESH" ){
3527     float sbX1,sbY1,sbW,sbH;
3528     float aTol = 1.00000009999999;
3529     std::string aWarning;
3530     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3531     if( name=="selection_object_color" || name=="selection_element_color" ||
3532         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3533         name=="selection_precision_node" || name=="selection_precision_element" ||
3534         name=="selection_precision_object")
3535       SMESH::UpdateSelectionProp( this );
3536     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3537       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3538       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3539       if(sbX1+sbW > aTol){
3540         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3541         sbX1=0.01;
3542         sbW=0.05;
3543         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3544         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3545       }
3546     }
3547     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3548       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3549       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3550       if(sbY1+sbH > aTol){
3551         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3552         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3553         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3554       }
3555     }
3556     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3557       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3558       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3559       if(sbX1+sbW > aTol){
3560         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3561         sbX1=0.01;
3562         sbW=0.05;
3563         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3564         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3565       }
3566     }
3567     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3568       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3569       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3570       if(sbY1+sbH > aTol){
3571         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3572         sbY1=0.01;
3573         sbH=0.05;
3574         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3575         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3576       }
3577     }
3578
3579     if(aWarning.size() != 0){
3580       aWarning += "The default values are applied instead.";
3581       SUIT_MessageBox::warning(SMESHGUI::desktop(),
3582                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3583                                QObject::tr(aWarning.c_str()));
3584     }
3585   }
3586 }
3587
3588 //================================================================================
3589 /*!
3590  * \brief Update something in accordance with update flags
3591   * \param theFlags - update flags
3592 *
3593 * Update viewer or/and object browser etc. in accordance with update flags ( see
3594 * LightApp_UpdateFlags enumeration ).
3595 */
3596 //================================================================================
3597 void SMESHGUI::update( const int flags )
3598 {
3599   if ( flags & UF_Viewer | flags & UF_Forced )
3600     SMESH::UpdateView();
3601   else
3602     SalomeApp_Module::update( flags );
3603 }
3604
3605 //================================================================================
3606 /*!
3607  * \brief Set default selection mode
3608 *
3609 * SLOT called when operation commited. Sets default selection mode
3610 */
3611 //================================================================================
3612 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3613 {
3614   SVTK_ViewWindow* vtkWnd =
3615     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3616   if ( vtkWnd )
3617     vtkWnd->SetSelectionMode( ActorSelection );
3618 }
3619
3620 //================================================================================
3621 /*!
3622  * \brief Set default selection mode
3623 *
3624 * SLOT called when operation aborted. Sets default selection mode
3625 */
3626 //================================================================================
3627 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3628 {
3629   SVTK_ViewWindow* vtkWnd =
3630     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3631   if ( vtkWnd )
3632     vtkWnd->SetSelectionMode( ActorSelection );
3633 }
3634
3635 //================================================================================
3636 /*!
3637  * \brief Creates operation with given identifier
3638   * \param id - identifier of operation to be started
3639   * \return Pointer on created operation or NULL if operation is not created
3640 *
3641 * Virtual method redefined from the base class creates operation with given id.
3642 * It is called called automatically from startOperation method of base class.
3643 */
3644 //================================================================================
3645 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3646 {
3647   LightApp_Operation* op = 0;
3648   // to do : create operation here
3649   switch( id )
3650   {
3651     case 701: // Compute mesh
3652       op = new SMESHGUI_ComputeOp();
3653     break;
3654     case 702: // Create mesh
3655       op = new SMESHGUI_MeshOp( true, true );
3656     break;
3657     case 703: // Create sub-mesh
3658       op = new SMESHGUI_MeshOp( true, false );
3659     break;
3660     case 704: // Edit mesh/sub-mesh
3661       op = new SMESHGUI_MeshOp( false );
3662     break;
3663     case 806: // Create group on geom
3664       op = new SMESHGUI_GroupOnShapeOp();
3665       break;
3666     case 417: //convert to quadratic
3667       op = new SMESHGUI_ConvToQuadOp();
3668     break;
3669     case 4067: // make mesh pass through point
3670       op = new SMESHGUI_MakeNodeAtPointOp();
3671       break;
3672     default:
3673     break;
3674   }
3675
3676   if( !op )
3677     op = SalomeApp_Module::createOperation( id );
3678   return op;
3679 }
3680
3681 //================================================================================
3682 /*!
3683  * \brief Stops current operations and starts a given one
3684   * \param id - The id of the operation to start
3685  */
3686 //================================================================================
3687
3688 void SMESHGUI::switchToOperation(int id)
3689 {
3690   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3691     activeStudy()->abortAllOperations();
3692   startOperation( id );
3693 }
3694
3695 LightApp_Displayer* SMESHGUI::displayer()
3696 {
3697   if( !myDisplayer )
3698     myDisplayer = new SMESHGUI_Displayer( getApp() );
3699   return myDisplayer;
3700 }
3701
3702 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
3703 {
3704   int aHue = -1;
3705   int aTolerance = 64;
3706   int anIterations = 0;
3707   int aPeriod = 5;
3708
3709   while( 1 )
3710   {
3711     anIterations++;
3712     if( anIterations % aPeriod == 0 )
3713     {
3714       aTolerance /= 2;
3715       if( aTolerance < 1 )
3716         break;
3717     }
3718     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3719
3720     aHue = (int)( 360.0 * rand() / RAND_MAX );
3721     //cout << "Hue = " << aHue << endl;
3722
3723     //cout << "Auto colors : ";
3724     bool ok = true;
3725     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3726     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3727     for( ; it != itEnd; ++it )
3728     {
3729       SALOMEDS::Color anAutoColor = *it;
3730       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3731
3732       int h, s, v;
3733       aQColor.getHsv( &h, &s, &v );
3734       //cout << h << " ";
3735       if( abs( h - aHue ) < aTolerance )
3736       {
3737         ok = false;
3738         //cout << "break (diff = " << abs( h - aHue ) << ")";
3739         break;
3740       }
3741     }
3742     //cout << endl;
3743
3744     if( ok )
3745       break;
3746   }
3747
3748   //cout << "Hue of the returned color = " << aHue << endl;
3749   QColor aColor;
3750   aColor.setHsv( aHue, 255, 255 );
3751
3752   SALOMEDS::Color aSColor;
3753   aSColor.R = (double)aColor.red() / 255.0;
3754   aSColor.G = (double)aColor.green() / 255.0;
3755   aSColor.B = (double)aColor.blue() / 255.0;
3756
3757   return aSColor;
3758 }
3759
3760 const char gSeparator = '_'; // character used to separate parameter names
3761 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
3762
3763 /*!
3764  * \brief Store visual parameters
3765  *
3766  * This method is called just before the study document is saved.
3767  * Store visual parameters in AttributeParameter attribue(s)
3768  */
3769 void SMESHGUI::storeVisualParameters (int savePoint)
3770 {
3771   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
3772   if (!appStudy || !appStudy->studyDS())
3773     return;
3774   _PTR(Study) studyDS = appStudy->studyDS();
3775
3776   // componentName is used for encoding of entries when storing them in IParameters
3777   std::string componentName = myComponentSMESH->ComponentDataType();
3778   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
3779   //if (!aSComponent) return;
3780
3781   // IParameters
3782   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
3783                                                              componentName.c_str(),
3784                                                              savePoint);
3785   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
3786
3787   // viewers counters are used for storing view_numbers in IParameters
3788   int vtkViewers = 0;
3789
3790   // main cycle to store parameters of displayed objects
3791   QList<SUIT_ViewManager*> lst;
3792   QList<SUIT_ViewManager*>::Iterator it;
3793   getApp()->viewManagers(lst);
3794   for (it = lst.begin(); it != lst.end(); it++)
3795   {
3796     SUIT_ViewManager* vman = *it;
3797     QString vType = vman->getType();
3798
3799     // saving VTK actors properties
3800     if (vType == SVTK_Viewer::Type())
3801     {
3802       QVector<SUIT_ViewWindow*> views = vman->getViews();
3803       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
3804       {
3805         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
3806         {
3807           vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
3808           allActors->InitTraversal();
3809           while (vtkActor* actor = allActors->GetNextActor())
3810           {
3811             if (actor->GetVisibility()) // store only visible actors
3812             {
3813               SMESH_Actor* aSmeshActor = 0;
3814               if (actor->IsA("SMESH_Actor"))
3815                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
3816               if (aSmeshActor && aSmeshActor->hasIO())
3817               {
3818                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
3819                 if (io->hasEntry())
3820                 {
3821                   // entry is "encoded" = it does NOT contain component adress,
3822                   // since it is a subject to change on next component loading
3823                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
3824
3825                   std::string param, vtkParam = vType.toLatin1().data();
3826                   vtkParam += gSeparator;
3827                   vtkParam += QString::number(vtkViewers).toLatin1().data();
3828                   vtkParam += gSeparator;
3829
3830                   // Visibility
3831                   param = vtkParam + "Visibility";
3832                   ip->setParameter(entry, param, "On");
3833
3834                   // Representation
3835                   param = vtkParam + "Representation";
3836                   ip->setParameter(entry, param, QString::number
3837                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
3838
3839                   // IsShrunk
3840                   param = vtkParam + "IsShrunk";
3841                   ip->setParameter(entry, param, QString::number
3842                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
3843
3844                   // Displayed entities
3845                   unsigned int aMode = aSmeshActor->GetEntityMode();
3846                   bool isE = aMode & SMESH_Actor::eEdges;
3847                   bool isF = aMode & SMESH_Actor::eFaces;
3848                   bool isV = aMode & SMESH_Actor::eVolumes;
3849
3850                   QString modeStr ("e");
3851                   modeStr += gDigitsSep; modeStr += QString::number(isE);
3852                   modeStr += gDigitsSep; modeStr += "f";
3853                   modeStr += gDigitsSep; modeStr += QString::number(isF);
3854                   modeStr += gDigitsSep; modeStr += "v";
3855                   modeStr += gDigitsSep; modeStr += QString::number(isV);
3856
3857                   param = vtkParam + "Entities";
3858                   ip->setParameter(entry, param, modeStr.toLatin1().data());
3859
3860                   // Colors (surface:edge:)
3861                   vtkFloatingPointType r, g, b;
3862
3863                   aSmeshActor->GetSufaceColor(r, g, b);
3864                   QString colorStr ("surface");
3865                   colorStr += gDigitsSep; colorStr += QString::number(r);
3866                   colorStr += gDigitsSep; colorStr += QString::number(g);
3867                   colorStr += gDigitsSep; colorStr += QString::number(b);
3868
3869                   aSmeshActor->GetBackSufaceColor(r, g, b);
3870                   colorStr += gDigitsSep; colorStr += "backsurface";
3871                   colorStr += gDigitsSep; colorStr += QString::number(r);
3872                   colorStr += gDigitsSep; colorStr += QString::number(g);
3873                   colorStr += gDigitsSep; colorStr += QString::number(b);
3874
3875                   aSmeshActor->GetEdgeColor(r, g, b);
3876                   colorStr += gDigitsSep; colorStr += "edge";
3877                   colorStr += gDigitsSep; colorStr += QString::number(r);
3878                   colorStr += gDigitsSep; colorStr += QString::number(g);
3879                   colorStr += gDigitsSep; colorStr += QString::number(b);
3880
3881                   aSmeshActor->GetNodeColor(r, g, b);
3882                   colorStr += gDigitsSep; colorStr += "node";
3883                   colorStr += gDigitsSep; colorStr += QString::number(r);
3884                   colorStr += gDigitsSep; colorStr += QString::number(g);
3885                   colorStr += gDigitsSep; colorStr += QString::number(b);
3886
3887                   param = vtkParam + "Colors";
3888                   ip->setParameter(entry, param, colorStr.toLatin1().data());
3889
3890                   // Sizes of lines and points
3891                   QString sizeStr ("line");
3892                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
3893                   sizeStr += gDigitsSep; sizeStr += "node";
3894                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetNodeSize());
3895                   sizeStr += gDigitsSep; sizeStr += "shrink";
3896                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
3897
3898                   param = vtkParam + "Sizes";
3899                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
3900
3901                   // Opacity
3902                   param = vtkParam + "Opacity";
3903                   ip->setParameter(entry, param,
3904                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
3905
3906                   // Clipping
3907                   param = vtkParam + "ClippingPlane";
3908                   int nPlanes = aSmeshActor->GetNumberOfClippingPlanes();
3909                   if (!nPlanes)
3910                     ip->setParameter(entry, param, "Off");
3911                   for (int ipl = 0; ipl < nPlanes; ipl++) {
3912                     //vtkPlane* plane = aSmeshActor->GetClippingPlane(ipl);
3913                     SMESH::Orientation anOrientation;
3914                     double aDistance;
3915                     vtkFloatingPointType anAngle[2];
3916                     SMESHGUI_ClippingDlg::GetPlaneParam(aSmeshActor, ipl, anOrientation, aDistance, anAngle);
3917                     std::string planeValue = QString::number((int)anOrientation).toLatin1().data();
3918                     planeValue += gDigitsSep; planeValue += QString::number(aDistance).toLatin1().data();
3919                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[0]).toLatin1().data();
3920                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[1]).toLatin1().data();
3921
3922                     ip->setParameter(entry, param + QString::number(ipl+1).toLatin1().data(), planeValue);
3923                   }
3924                 } // if (io->hasEntry())
3925               } // SMESH_Actor && hasIO
3926             } // isVisible
3927           } // while.. actors traversal
3928         } // if (vtkView)
3929       } // for (views)
3930       vtkViewers++;
3931     } // if (SVTK view model)
3932   } // for (viewManagers)
3933 }
3934
3935 /*!
3936  * \brief Restore visual parameters
3937  *
3938  * This method is called after the study document is opened.
3939  * Restore visual parameters from AttributeParameter attribue(s)
3940  */
3941 void SMESHGUI::restoreVisualParameters (int savePoint)
3942 {
3943   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
3944   if (!appStudy || !appStudy->studyDS())
3945     return;
3946   _PTR(Study) studyDS = appStudy->studyDS();
3947
3948   // componentName is used for encoding of entries when storing them in IParameters
3949   std::string componentName = myComponentSMESH->ComponentDataType();
3950   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
3951   //if (!aSComponent) return;
3952
3953   // IParameters
3954   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
3955                                                              componentName.c_str(),
3956                                                              savePoint);
3957   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
3958
3959   std::vector<std::string> entries = ip->getEntries();
3960
3961   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
3962   {
3963     // entry is a normal entry - it should be "decoded" (setting base adress of component)
3964     QString entry (ip->decodeEntry(*entIt).c_str());
3965
3966     // Check that the entry corresponds to a real object in the Study
3967     // as the object may be deleted or modified after the visual state is saved.
3968     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
3969     if (!so) continue; //Skip the not existent entry
3970
3971     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
3972     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
3973
3974     std::vector<std::string>::iterator namesIt = paramNames.begin();
3975     std::vector<std::string>::iterator valuesIt = paramValues.begin();
3976
3977     // actors are stored in a map after displaying of them for
3978     // quicker access in the future: map < viewID to actor >
3979     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
3980
3981     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
3982     {
3983       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
3984       // '_' is used as separator and should not be used in viewer type or parameter names.
3985       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
3986       if (lst.size() != 3)
3987         continue;
3988
3989       QString viewerTypStr = lst[0];
3990       QString viewIndexStr = lst[1];
3991       QString paramNameStr = lst[2];
3992
3993       bool ok;
3994       int viewIndex = viewIndexStr.toUInt(&ok);
3995       if (!ok) // bad conversion of view index to integer
3996         continue;
3997
3998       // viewers
3999       if (viewerTypStr == SVTK_Viewer::Type())
4000       {
4001         SMESH_Actor* aSmeshActor = 0;
4002         if (vtkActors.IsBound(viewIndex))
4003           aSmeshActor = vtkActors.Find(viewIndex);
4004
4005         if (paramNameStr == "Visibility")
4006         {
4007           if (!aSmeshActor && displayer())
4008           {
4009             QList<SUIT_ViewManager*> lst;
4010             getApp()->viewManagers(viewerTypStr, lst);
4011
4012             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4013             if (viewIndex >= 0 && viewIndex < lst.count()) {
4014               SUIT_ViewManager* vman = lst.at(viewIndex);
4015               SUIT_ViewModel* vmodel = vman->getViewModel();
4016               // SVTK view model can be casted to SALOME_View
4017               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
4018
4019               // store displayed actor in a temporary map for quicker
4020               // access later when restoring other parameters
4021               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4022               vtkRenderer* Renderer = vtkView->getRenderer();
4023               vtkActorCollection* theActors = Renderer->GetActors();
4024               theActors->InitTraversal();
4025               bool isFound = false;
4026               vtkActor *ac = theActors->GetNextActor();
4027               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
4028                 if (ac->IsA("SMESH_Actor")) {
4029                   SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
4030                   if (aGeomAc->hasIO()) {
4031                     Handle(SALOME_InteractiveObject) io =
4032                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
4033                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
4034                       isFound = true;
4035                       vtkActors.Bind(viewIndex, aGeomAc);
4036                     }
4037                   }
4038                 }
4039               }
4040             }
4041           }
4042         } // if (paramNameStr == "Visibility")
4043         else
4044         {
4045           // the rest properties "work" with SMESH_Actor
4046           if (aSmeshActor)
4047           {
4048             QString val ((*valuesIt).c_str());
4049
4050             // Representation
4051             if (paramNameStr == "Representation") {
4052               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
4053             }
4054             // IsShrunk
4055             else if (paramNameStr == "IsShrunk") {
4056               if (val.toInt()) {
4057                 if (!aSmeshActor->IsShrunk())
4058                   aSmeshActor->SetShrink();
4059               }
4060               else {
4061                 if (aSmeshActor->IsShrunk())
4062                   aSmeshActor->UnShrink();
4063               }
4064             }
4065             // Displayed entities
4066             else if (paramNameStr == "Entities") {
4067               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
4068               if (mode.count() == 6) {
4069                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
4070                   MESSAGE("Invalid order of data in Entities, must be: "
4071                           "e:0/1:f:0/1:v:0/1");
4072                 }
4073                 else {
4074                   unsigned int aMode = aSmeshActor->GetEntityMode();
4075                   unsigned int aNewMode =
4076                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
4077                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
4078                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
4079                   if (aNewMode != aMode)
4080                     aSmeshActor->SetEntityMode(aNewMode);
4081                 }
4082               }
4083             }
4084             // Colors
4085             else if (paramNameStr == "Colors") {
4086               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
4087               if (colors.count() == 16) {
4088                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
4089                     colors[8] != "edge"    || colors[12] != "node") {
4090                   MESSAGE("Invalid order of data in Colors, must be: "
4091                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
4092                 }
4093                 else {
4094                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
4095                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
4096                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
4097                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
4098                 }
4099               }
4100             }
4101             // Sizes of lines and points
4102             else if (paramNameStr == "Sizes") {
4103               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
4104               if (sizes.count() == 6) {
4105                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
4106                   MESSAGE("Invalid order of data in Sizes, must be: "
4107                           "line:int:node:int:shrink:float");
4108                 }
4109                 else {
4110                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4111                   aSmeshActor->SetNodeSize(sizes[3].toInt());
4112                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
4113                 }
4114               }
4115             }
4116             // Opacity
4117             else if (paramNameStr == "Opacity") {
4118               aSmeshActor->SetOpacity(val.toFloat());
4119             }
4120             // Clipping
4121             else if (paramNameStr.startsWith("ClippingPlane")) {
4122               cout << "$$$ ClippingPlane 1" << endl;
4123               if (paramNameStr == "ClippingPlane1" || val == "Off")
4124                 aSmeshActor->RemoveAllClippingPlanes();
4125               if (val != "Off") {
4126                 cout << "$$$ ClippingPlane 2" << endl;
4127                 QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
4128                 if (vals.count() == 4) { // format check: 4 values
4129                   cout << "$$$ ClippingPlane 3" << endl;
4130                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
4131                   double aDistance = vals[1].toFloat();
4132                   vtkFloatingPointType anAngle[2];
4133                   anAngle[0] = vals[2].toFloat();
4134                   anAngle[1] = vals[3].toFloat();
4135
4136                   QList<SUIT_ViewManager*> lst;
4137                   getApp()->viewManagers(viewerTypStr, lst);
4138                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4139                   if (viewIndex >= 0 && viewIndex < lst.count()) {
4140                     SUIT_ViewManager* vman = lst.at(viewIndex);
4141                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4142                     SMESHGUI_ClippingDlg::AddPlane(aSmeshActor, vtkView,
4143                                                    anOrientation, aDistance, anAngle);
4144                   }
4145                 }
4146               }
4147             }
4148           } // if (aSmeshActor)
4149         } // other parameters than Visibility
4150       }
4151     } // for names/parameters iterator
4152   } // for entries iterator
4153
4154   // update all VTK views
4155   QList<SUIT_ViewManager*> lst;
4156   getApp()->viewManagers(lst);
4157   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
4158     SUIT_ViewModel* vmodel = (*it)->getViewModel();
4159     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
4160       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
4161       vtkView->getRenderer()->ResetCameraClippingRange();
4162       vtkView->Repaint();
4163     }
4164   }
4165 }