Salome HOME
Bug 9189:
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28 #include "SMESHGUI_InitMeshDlg.h"
29 #include "SMESHGUI_AddSubMeshDlg.h"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_StandardMeshInfosDlg.h"
38 #include "SMESHGUI_Preferences_ColorDlg.h"
39 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
40 #include "SMESHGUI_Preferences_SelectionDlg.h"
41 #include "SMESHGUI_Hypotheses.h"
42 #include "SMESHGUI_HypothesesUtils.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_AddMeshElementDlg.h"
45 #include "SMESHGUI_EditHypothesesDlg.h"
46 #include "SMESHGUI_CreateHypothesesDlg.h"
47 #include "SMESHGUI_FilterDlg.h"
48 #include "SMESHGUI_FilterLibraryDlg.h"
49 #include "SMESHGUI_SingleEditDlg.h"
50 #include "SMESHGUI_MultiEditDlg.h"
51 #include "SMESHGUI_GroupOpDlg.h"
52 #include "SMESHGUI_DeleteGroupDlg.h"
53 #include "SMESHGUI_SmoothingDlg.h"
54 #include "SMESHGUI_RenumberingDlg.h"
55 #include "SMESHGUI_ExtrusionDlg.h"
56 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
57 #include "SMESHGUI_RevolutionDlg.h"
58 #include "SMESHGUI_TranslationDlg.h"
59 #include "SMESHGUI_RotationDlg.h"
60 #include "SMESHGUI_SymmetryDlg.h"
61 #include "SMESHGUI_SewingDlg.h"
62 #include "SMESHGUI_MergeNodesDlg.h"
63 #include "SMESHGUI_MeshPatternDlg.h"
64 #include "SMESHGUI_PrecisionDlg.h"
65 #include "SMESHGUI_Selection.h"
66 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
67
68 #include <SVTK_InteractorStyle.h>
69 #include <SVTK_RenderWindowInteractor.h>
70
71 #include "SMESH_Actor.h"
72 #include "SMESH_Object.h"
73 #include "SMESH_TypeFilter.hxx"
74
75 #include "SUIT_Tools.h"
76 #include "SUIT_MessageBox.h"
77 #include "SUIT_ResourceMgr.h"
78 #include "SUIT_FileDlg.h"
79 #include "SUIT_Desktop.h"
80 #include "SUIT_ResourceMgr.h"
81 #include "SUIT_OverrideCursor.h"
82 #include "SUIT_Study.h"
83 #include "SUIT_Session.h"
84
85 #include "SALOME_NamingService.hxx"
86 #include "SALOME_ListIteratorOfListIO.hxx"
87 #include "SALOME_InteractiveObject.hxx"
88 #include "SALOME_ListIO.hxx"
89 #include <SALOME_LifeCycleCORBA.hxx>
90
91 #include "OB_Browser.h"
92
93 #include "QtxPopupMgr.h"
94
95 #include "SalomeApp_Application.h"
96 #include "SalomeApp_NameDlg.h"
97 #include "SalomeApp_DataOwner.h"
98 #include "SalomeApp_ImportOperation.h"
99 #include "SalomeApp_Tools.h"
100 #include "SalomeApp_Study.h"
101 #include "SalomeApp_VTKSelector.h"
102
103 #include <SVTK_ViewWindow.h>
104 #include <SVTK_ViewModel.h>
105
106 #include <VTKViewer_ViewManager.h>
107
108 #include "SMESHGUI_Utils.h"
109 #include "SMESHGUI_GEOMGenUtils.h"
110 #include "SMESHGUI_MeshUtils.h"
111 #include "SMESHGUI_GroupUtils.h"
112 #include "SMESHGUI_FilterUtils.h"
113 #include "SMESHGUI_PatternUtils.h"
114 #include "SMESHGUI_VTKUtils.h"
115
116 #include "SALOMEconfig.h"
117 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
118
119 // QT Includes
120 #define  INCLUDE_MENUITEM_DEF
121 #include <qapplication.h>
122 #include <qlineedit.h>
123 #include <qmenudata.h>
124 #include <qmenubar.h>
125 #include <qpopupmenu.h>
126 #include <qfont.h>
127 #include <qstring.h>
128 #include <qpainter.h>
129 #include <qcheckbox.h>
130 #include <qcolordialog.h>
131 #include <qspinbox.h>
132 #include <qlist.h>
133 #include <qwidget.h>
134 #include <qevent.h>
135 #include <qaction.h>
136 #include <qradiobutton.h>
137
138 #include <boost/shared_ptr.hpp>
139
140 #include <vtkRenderer.h>
141 #include <vtkRenderWindow.h>
142 #include <vtkActorCollection.h>
143 #include <vtkScalarBarActor.h>
144 #include <vtkUnstructuredGrid.h>
145
146 #include "utilities.h"
147
148 #include "SALOMEDS_Study.hxx"
149 #include "SALOMEDSClient_StudyBuilder.hxx"
150 #include "SALOMEDSClient_SComponent.hxx"
151
152 using namespace std;
153
154 namespace{
155   // Decalarations
156   //=============================================================
157   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
158                             int theCommandID);
159
160   void ExportMeshToFile(int theCommandID);
161
162   void SetDisplayMode(int theCommandID);
163
164   void SetDisplayEntity(int theCommandID);
165
166   void Control( int theCommandID );
167
168   void SetDisplaySettings();
169
170
171   // Definitions
172   //=============================================================
173   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
174                             int theCommandID)
175   {
176     QStringList filter;
177     string myExtension;
178   
179     if(theCommandID == 113){
180       filter.append(QObject::tr("MED files (*.med)"));
181       filter.append(QObject::tr("All files (*)"));
182     }else if (theCommandID == 112){
183       filter.append(QObject::tr("IDEAS files (*.unv)"));
184     }else if (theCommandID == 111){
185       filter.append(QObject::tr("DAT files (*.dat)"));
186     }
187     QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
188                                                 "",
189                                                 filter,
190                                                 QObject::tr("Import mesh"),
191                                                 true);
192     if(!filename.isEmpty()) {
193       SUIT_OverrideCursor wc;
194       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
195
196       try {
197         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
198         switch ( theCommandID ) {
199         case 112:
200           {
201             aMeshes->length( 1 );
202             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
203             break;
204           }
205         case 113:
206           {
207             SMESH::DriverMED_ReadStatus res;
208             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
209             if ( res != SMESH::DRS_OK ) {
210               wc.suspend();
211               SUIT_MessageBox::warn1(SMESHGUI::desktop(),
212                                     QObject::tr("SMESH_WRN_WARNING"),
213                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
214                                     QObject::tr("SMESH_BUT_OK"));
215               aMeshes->length( 0 );
216               wc.resume();
217             }
218             break;
219           }
220         }
221
222         bool isEmpty = false;
223         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
224           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
225           if ( aMeshSO ) {
226             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
227             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
228             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
229             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
230               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
231           } else
232             isEmpty = true;
233         }
234
235         if ( isEmpty ) {
236           wc.suspend();
237           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
238                                 QObject::tr("SMESH_WRN_WARNING"),
239                                 QObject::tr("SMESH_DRS_EMPTY"),
240                                 QObject::tr("SMESH_BUT_OK"));
241           wc.resume();
242         }
243       }
244       catch (const SALOME::SALOME_Exception& S_ex){
245         wc.suspend();
246         SalomeApp_Tools::QtCatchCorbaException(S_ex);
247         wc.resume();
248       }
249     }
250   }
251
252
253   void ExportMeshToFile( int theCommandID )
254   {
255     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
256     SALOME_ListIO selected;
257     if( aSel )
258       aSel->selectedObjects( selected );
259
260     if(selected.Extent()){
261       Handle(SALOME_InteractiveObject) anIObject = selected.First();
262       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
263       if ( !aMesh->_is_nil() ) {
264         QString aFilter, aTitle = QObject::tr("Export mesh");
265         QMap<QString, SMESH::MED_VERSION> aFilterMap;
266         switch ( theCommandID ) {
267         case 125:
268         case 122:
269           aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
270           aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
271           break;
272         case 124:
273         case 121:
274           aFilter = QObject::tr("DAT files (*.dat)");
275           break;
276         case 126:
277         case 123: {
278           if(aMesh->NbPyramids()){
279             int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
280                                              QObject::tr("SMESH_WRN_WARNING"),
281                                              QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
282                                              QObject::tr("SMESH_BUT_YES"),
283                                              QObject::tr("SMESH_BUT_NO"),
284                                              0,1,0);
285             if(aRet)
286               return;
287           }
288           aFilter = QObject::tr("IDEAS files (*.unv)");
289           break;
290         default:
291           return;
292         }}
293
294         QString aFilename;
295         SMESH::MED_VERSION aFormat;
296
297         if ( theCommandID != 122 && theCommandID != 125 )
298           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
299         else
300           {
301             QStringList filters;
302             for ( QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin(); it != aFilterMap.end(); ++it )
303               filters.push_back( it.key() );
304             
305             SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
306             fd->setCaption( aTitle );
307             fd->setFilters( filters );
308             fd->exec();
309             aFilename = fd->selectedFile();
310             aFormat = aFilterMap[fd->selectedFilter()];
311             delete fd;
312           }
313         if ( !aFilename.isEmpty() ) {
314           // Check whether the file already exists and delete it if yes
315           QFile aFile( aFilename );
316           if ( aFile.exists() )
317             aFile.remove();
318           SUIT_OverrideCursor wc;
319           switch ( theCommandID ) {
320           case 125:
321           case 122:
322             aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created
323             break;
324           case 124:
325           case 121:
326             aMesh->ExportDAT( aFilename.latin1() );
327             break;
328           case 126:
329           case 123:
330             aMesh->ExportUNV( aFilename.latin1() );
331             break;
332           default:
333             break;
334           }
335         }
336       }
337     }
338   }
339
340   inline void InverseEntityMode(unsigned int& theOutputMode,
341                                 unsigned int theMode)
342   {
343     bool anIsNotPresent = ~theOutputMode & theMode;
344     if(anIsNotPresent)
345       theOutputMode |= theMode;
346     else
347       theOutputMode &= ~theMode;
348   }
349
350   void SetDisplayEntity(int theCommandID){
351     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
352     SALOME_ListIO selected;
353     if( aSel )
354       aSel->selectedObjects( selected );
355
356     if(selected.Extent() >= 1){
357       SALOME_ListIteratorOfListIO It( selected );
358       for(; It.More(); It.Next()){
359         Handle(SALOME_InteractiveObject) IObject = It.Value();
360         if(IObject->hasEntry()){
361           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
362             unsigned int aMode = anActor->GetEntityMode();
363             switch(theCommandID){
364             case 217:
365               InverseEntityMode(aMode,SMESH_Actor::eEdges);
366               break;
367             case 218:
368               InverseEntityMode(aMode,SMESH_Actor::eFaces);
369               break;
370             case 219:
371               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
372               break;
373             case 220:
374               aMode = SMESH_Actor::eAllEntity;
375               break;
376             }
377             if(aMode)
378               anActor->SetEntityMode(aMode);
379           }
380         }
381       }
382     }
383   }
384
385   void SetDisplayMode(int theCommandID){
386     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
387     SALOME_ListIO selected;
388     if( aSel )
389       aSel->selectedObjects( selected );
390
391     if(selected.Extent() >= 1){
392       switch(theCommandID){
393       case 1134:{
394         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
395         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
396         return;
397       }
398       case 1133:{
399         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
400         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
401         return;
402       }}
403       SALOME_ListIteratorOfListIO It( selected );
404       for(; It.More(); It.Next()){
405         Handle(SALOME_InteractiveObject) IObject = It.Value();
406         if(IObject->hasEntry()){
407           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
408             switch(theCommandID){
409             case 211:
410               anActor->SetRepresentation(SMESH_Actor::eEdge);
411               break;
412             case 212:
413               anActor->SetRepresentation(SMESH_Actor::eSurface);
414               break;
415             case 213:
416               if(anActor->IsShrunk())
417                 anActor->UnShrink();
418               else
419                 anActor->SetShrink();
420               break;
421             case 215:
422               anActor->SetRepresentation(SMESH_Actor::ePoint);
423               break;
424             case 1132:{
425               float color[3];
426               anActor->GetSufaceColor(color[0], color[1], color[2]);
427               int c0 = int (color[0] * 255);
428               int c1 = int (color[1] * 255);
429               int c2 = int (color[2] * 255);
430               QColor c(c0, c1, c2);
431
432               float edgecolor[3];
433               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
434               c0 = int (edgecolor[0] * 255);
435               c1 = int (edgecolor[1] * 255);
436               c2 = int (edgecolor[2] * 255);
437               QColor e(c0, c1, c2);
438
439               float backfacecolor[3];
440               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
441               c0 = int (backfacecolor[0] * 255);
442               c1 = int (backfacecolor[1] * 255);
443               c2 = int (backfacecolor[2] * 255);
444               QColor b(c0, c1, c2);
445
446               float nodecolor[3];
447               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
448               c0 = int (nodecolor[0] * 255);
449               c1 = int (nodecolor[1] * 255);
450               c2 = int (nodecolor[2] * 255);
451               QColor n(c0, c1, c2);
452
453               int Edgewidth = (int)anActor->GetLineWidth();
454               if(Edgewidth == 0)
455                 Edgewidth = 1;
456               int intValue = int(anActor->GetNodeSize());
457               float Shrink = anActor->GetShrinkFactor();
458
459               SMESHGUI_Preferences_ColorDlg *aDlg =
460                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
461               aDlg->SetColor(1, c);
462               aDlg->SetColor(2, e);
463               aDlg->SetColor(3, n);
464               aDlg->SetColor(4, b);
465               aDlg->SetIntValue(1, Edgewidth);
466               aDlg->SetIntValue(2, intValue);
467               aDlg->SetIntValue(3, int(Shrink*100.));
468               if(aDlg->exec()){
469                 QColor color = aDlg->GetColor(1);
470                 QColor edgecolor = aDlg->GetColor(2);
471                 QColor nodecolor = aDlg->GetColor(3);
472                 QColor backfacecolor = aDlg->GetColor(4);
473                 /* actor color and backface color */
474                 anActor->SetSufaceColor(float (color.red()) / 255.,
475                                          float (color.green()) / 255.,
476                                          float (color.blue()) / 255.);
477                 anActor->SetBackSufaceColor(float (backfacecolor.red()) / 255.,
478                                              float (backfacecolor.green()) / 255.,
479                                              float (backfacecolor.blue()) / 255.);
480
481                 /* edge color */
482                 anActor->SetEdgeColor(float (edgecolor.red()) / 255.,
483                                        float (edgecolor.green()) / 255.,
484                                        float (edgecolor.blue()) / 255.);
485
486                 /* Shrink factor and size edges */
487                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
488                 anActor->SetLineWidth(aDlg->GetIntValue(1));
489
490                 /* Nodes color and size */
491                 anActor->SetNodeColor(float (nodecolor.red()) / 255.,
492                                float (nodecolor.green()) / 255.,
493                                        float (nodecolor.blue()) / 255.);
494                 anActor->SetNodeSize(aDlg->GetIntValue(2));
495
496                 delete aDlg;
497               }
498               break;
499             }}
500           }
501         }
502       }
503       SMESH::RepaintCurrentView();
504     }
505   }
506
507
508   void SetDisplaySettings()
509   {
510     SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
511     if( !mgr )
512       return;
513
514     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
515     SMESHGUI_Preferences_ColorDlg *aDlg =
516       new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
517
518     QColor color = mgr->colorValue( "SMESH", "SettingsFillColor", QColor(0, 170, 255) );
519     aDlg->SetColor(1, color);
520
521     color = mgr->colorValue( "SMESH", "SettingsOutlineColor", QColor(0, 170, 255) );
522     aDlg->SetColor(2, color);
523
524     color = mgr->colorValue( "SMESH", "SettingsNodeColor", Qt::red );
525     aDlg->SetColor(3, color);
526
527     color = mgr->colorValue( "SMESH", "SettingsBackFaceColor", Qt::blue );
528     aDlg->SetColor(4, color);
529
530     int iVal = mgr->integerValue( "SMESH", "SettingsWidth", 1 );
531     aDlg->SetIntValue(1, iVal);
532
533     iVal = mgr->integerValue( "SMESH", "SettingsNodesSize", 3 );
534     aDlg->SetIntValue(2, iVal);
535
536     iVal = mgr->integerValue( "SMESH", "SettingsShrinkCoeff", 75 );
537     aDlg->SetIntValue(3, iVal);
538
539     if (aDlg->exec()) {
540       mgr->setValue( "SMESH", "SettingsFillColor", aDlg->GetColor(1) );
541       mgr->setValue( "SMESH", "SettingsOutlineColor", aDlg->GetColor(2) );
542       mgr->setValue( "SMESH", "SettingsNodeColor", aDlg->GetColor(3) );
543       mgr->setValue( "SMESH", "SettingsBackFaceColor", aDlg->GetColor(4) );
544
545       mgr->setValue( "SMESH", "SettingsWidth", aDlg->GetIntValue(1) );
546       mgr->setValue( "SMESH", "SettingsNodesSize", aDlg->GetIntValue(2) );
547       mgr->setValue( "SMESH", "SettingsShrinkCoeff", aDlg->GetIntValue(3) );
548     }
549     
550     delete aDlg;
551   }
552
553   
554   void Control( int theCommandID )
555   {
556     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
557     SALOME_ListIO selected;
558     if( aSel )
559       aSel->selectedObjects( selected );
560
561     if( !selected.IsEmpty() ){
562       Handle(SALOME_InteractiveObject) anIO = selected.First();
563       if(!anIO.IsNull()){
564         QString aTitle;
565         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
566         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
567           switch ( theCommandID ){
568           case 6001:
569             aTitle = QObject::tr( "LENGTH_EDGES" );
570             aControl = SMESH_Actor::eLength;
571             break;
572           case 6018:
573             aTitle = QObject::tr( "LENGTH2D_EDGES" );
574             aControl = SMESH_Actor::eLength2D;
575             break;
576           case 6002:
577             aTitle = QObject::tr( "FREE_EDGES" );
578             aControl = SMESH_Actor::eFreeEdges;
579             break;
580           case 6003:
581             aTitle = QObject::tr( "FREE_BORDERS" );
582             aControl = SMESH_Actor::eFreeBorders;
583             break;
584           case 6004:
585             aTitle = QObject::tr( "MULTI_BORDERS" );
586             aControl = SMESH_Actor::eMultiConnection;
587             break;
588           case 6019:
589             aTitle = QObject::tr( "MULTI2D_BORDERS" );
590             aControl = SMESH_Actor::eMultiConnection2D;
591             break;
592           case 6011:
593             aTitle = QObject::tr( "AREA_ELEMENTS" );
594             aControl = SMESH_Actor::eArea;
595             break;
596           case 6012:
597             aTitle = QObject::tr( "TAPER_ELEMENTS" );
598             aControl = SMESH_Actor::eTaper;
599             break;
600           case 6013:
601             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
602             aControl = SMESH_Actor::eAspectRatio;
603             break;
604           case 6017:
605             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
606             aControl = SMESH_Actor::eAspectRatio3D;
607             break;
608           case 6014:
609             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
610             aControl = SMESH_Actor::eMinimumAngle;
611             break;
612           case 6015:
613             aTitle = QObject::tr( "WARP_ELEMENTS" );
614             aControl = SMESH_Actor::eWarping;
615             break;
616           case 6016:
617             aTitle = QObject::tr( "SKEW_ELEMENTS" );
618             aControl = SMESH_Actor::eSkew;
619             break;
620           }
621           anActor->SetControlMode(aControl);
622           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
623         }
624       }
625     }
626   }
627
628
629   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
630                    MeshObjectType                           theType,
631                    const QString                            theInTypeName,
632                    QString &                                theOutTypeName)
633   {
634     SMESH_TypeFilter aTypeFilter( theType );
635     QString entry;
636     if( !theIO.IsNull() )
637     {
638       entry = theIO->getEntry();
639       SalomeApp_DataOwner owner( entry );
640       if ( aTypeFilter.isOk( &owner )) {
641         theOutTypeName = theInTypeName;
642         return true;
643       }
644     }
645     return false;
646   }
647
648
649   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
650   {
651     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
652     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
653     if (aSObj) {
654       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
655       CORBA::String_var anID = aSComp->GetID().c_str();
656       if (!strcmp(anID.in(),theIO->getEntry()))
657         return "Component";
658     }
659
660     QString aTypeName;
661     if (
662         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
663         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
664         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
665         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
666         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
667         )
668       return aTypeName;
669
670     return "NoType";
671   }
672
673
674   QString CheckHomogeneousSelection()
675   {
676     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
677     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
678     SALOME_ListIO selected;
679     if( aSel )
680       aSel->selectedObjects( selected );
681
682     QString RefType = CheckTypeObject(selected.First());
683     SALOME_ListIteratorOfListIO It(selected);
684     for (; It.More(); It.Next())
685       {
686         Handle(SALOME_InteractiveObject) IObject = It.Value();
687         QString Type = CheckTypeObject(IObject);
688         if (Type.compare(RefType) != 0)
689           return "Heterogeneous Selection";
690       }
691
692     return RefType;
693   }
694
695   void OnEditDelete()
696   {
697     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
698     SalomeApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
699     SALOME_ListIO selected; aSel->selectedObjects( selected );
700
701     QString aParentComponent = QString::null;
702     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
703     {
704       QString cur = anIt.Value()->getComponentDataType();
705       if( aParentComponent.isNull() )
706         aParentComponent = cur;
707       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
708         aParentComponent = "";
709     }
710
711     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
712       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
713                               QObject::tr("ERR_ERROR"),
714                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
715                               QObject::tr("BUT_OK") );
716       return;
717     }
718     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
719     if (SUIT_MessageBox::warn2
720         (SMESHGUI::desktop(),
721          QObject::tr("SMESH_WRN_WARNING"),
722          QObject::tr("SMESH_REALLY_DELETE"),
723          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
724       return;
725
726     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
727     SUIT_ViewManager* vm = anApp->activeViewManager();
728     int nbSf = vm->getViewsCount();
729
730     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
731     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
732     _PTR(GenericAttribute) anAttr;
733     _PTR(AttributeIOR) anIOR;
734
735     SALOME_ListIteratorOfListIO It(selected);
736
737     aStudyBuilder->NewCommand();  // There is a transaction
738     for(; It.More(); It.Next()){
739       Handle(SALOME_InteractiveObject) IObject = It.Value();
740       if(IObject->hasEntry()){
741         _PTR(SObject) SO = aStudy->FindObjectID(IObject->getEntry());
742
743         /* Erase child graphical objects */
744         _PTR(ChildIterator) it = aStudy->NewChildIterator(SO);
745         for(it->InitEx(true); it->More(); it->Next()){
746           _PTR(SObject) CSO = it->Value();
747           if(CSO->FindAttribute(anAttr, "AttributeIOR")){
748             anIOR = anAttr;
749
750             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
751             for(int i = 0; i < nbSf; i++){
752               SUIT_ViewWindow *sf = aViews[i];
753               CORBA::String_var anEntry = CSO->GetID().c_str();
754               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
755                 SMESH::RemoveActor(sf,anActor);
756               }
757             }
758           }
759         }
760
761         /* Erase main graphical object */
762         QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
763         for(int i = 0; i < nbSf; i++){
764           SUIT_ViewWindow *sf = aViews[i];
765           if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
766             SMESH::RemoveActor(sf,anActor);
767           }
768         }
769
770         // Remove object(s) from data structures
771         _PTR(SObject) obj = aStudy->FindObjectID(IObject->getEntry());
772         if(obj){
773           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( obj ) );
774           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( obj ) );
775
776           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
777             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
778             aMesh->RemoveGroup( aGroup );
779           }
780           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
781             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
782             aMesh->RemoveSubMesh( aSubMesh );
783           }
784           else {// default action: remove SObject from the study
785             // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
786             //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
787             //op->start();
788             aStudyBuilder->RemoveObjectWithChildren( obj );
789             //op->finish();
790           }
791         }
792
793       } /* IObject->hasEntry() */
794     } /* more/next */
795     aStudyBuilder->CommitCommand();
796
797     /* Clear any previous selection */
798     SALOME_ListIO l1;
799     aSel->setSelectedObjects( l1 );
800
801     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
802   }
803 }
804
805 //=============================================================================
806 /*!
807  *
808  */
809 //=============================================================================
810 class CustomItem : public QCustomMenuItem
811 {
812 public:
813   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
814   ~CustomItem() {}
815
816   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
817   {
818     p->save();
819     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
820     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
821     p->setFont( myFont );
822     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
823     p->restore();
824   }
825
826   QSize sizeHint()
827   {
828     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
829   }
830
831   bool fullSpan() const
832   {
833     return true;
834   }
835
836 private:
837   QString myString;
838   QFont   myFont;
839 };
840
841 extern "C" {
842   Standard_EXPORT CAM_Module* createModule()
843   {
844     return SMESHGUI::GetSMESHGUI();
845   }
846 }
847
848 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
849
850 //=============================================================================
851 /*!
852  *
853  */
854 //=============================================================================
855 SMESHGUI::SMESHGUI() :
856   SalomeApp_Module( "SMESH" )
857 {
858   if ( CORBA::is_nil( myComponentSMESH ) )
859   {
860     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
861     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "SMESH" );
862     myComponentSMESH = SMESH::SMESH_Gen::_narrow( comp );
863   }
864
865   myActiveDialogBox = 0 ;
866   myState = -1 ;
867
868   SMESH::GetFilterManager();
869   SMESH::GetPattern();
870   
871   /* load resources for all available meshers */
872   SMESH::InitAvailableHypotheses();
873 }
874
875 //=============================================================================
876 /*!
877  *
878  */
879 //=============================================================================
880 SMESHGUI::~SMESHGUI()
881 {
882   SMESH::GetFilterManager()->Destroy();
883 }
884
885 //=============================================================================
886 /*!
887  *
888  */
889 //=============================================================================
890 SalomeApp_SelectionMgr* SMESHGUI::selectionMgr()
891 {
892   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
893   if( anApp )
894     return dynamic_cast<SalomeApp_SelectionMgr*>( anApp->selectionMgr() );
895   else
896     return 0;
897 }
898
899 //=============================================================================
900 /*!
901  *
902  */
903 //=============================================================================
904 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
905 {
906   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
907 }
908
909 //=============================================================================
910 /*!
911  *
912  */
913 //=============================================================================
914 SMESHGUI* SMESHGUI::GetSMESHGUI()
915 {
916   static SMESHGUI* aSMESHGUI = NULL;
917   if( !aSMESHGUI )
918     aSMESHGUI = new SMESHGUI();
919
920   if(_PTR(Study) aStudy = SMESH::GetActiveStudyDocument())
921     GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
922
923   SUIT_ResourceMgr* mgr = resourceMgr();
924   if( mgr )
925   /* Automatic Update flag */
926     aSMESHGUI->myAutomaticUpdate = ( mgr->stringValue( "SMESH", "AutomaticUpdate" ).compare( "true" ) == 0 );
927
928   return aSMESHGUI;
929 }
930
931 extern "C"
932 {
933   Standard_EXPORT SMESHGUI* GetComponentGUI() {
934     return SMESHGUI::GetSMESHGUI();
935   }
936 }
937
938 //=============================================================================
939 /*!
940  *
941  */
942 //=============================================================================
943 void SMESHGUI::SetState(int aState)
944 {
945   myState = aState;
946 }
947
948 //=============================================================================
949 /*!
950  *
951  */
952 //=============================================================================
953 void SMESHGUI::ResetState()
954 {
955   myState = -1;
956 }
957
958 //=============================================================================
959 /*!
960  *
961  */
962 //=============================================================================
963 void SMESHGUI::EmitSignalDeactivateDialog()
964 {
965   emit SignalDeactivateActiveDialog();
966 }
967
968 //=============================================================================
969 /*!
970  *
971  */
972 //=============================================================================
973 void SMESHGUI::EmitSignalStudyFrameChanged()
974 {
975   emit SignalStudyFrameChanged();
976 }
977
978 //=============================================================================
979 /*!
980  *
981  */
982 //=============================================================================
983 void SMESHGUI::EmitSignalCloseAllDialogs()
984 {
985   emit SignalCloseAllDialogs();
986 }
987
988 //=============================================================================
989 /*!
990  *
991  */
992 //=============================================================================
993 QDialog *SMESHGUI::GetActiveDialogBox()
994 {
995   return myActiveDialogBox;
996 }
997
998 //=============================================================================
999 /*!
1000  *
1001  */
1002 //=============================================================================
1003 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1004 {
1005   myActiveDialogBox = (QDialog *) aDlg;
1006   return;
1007 }
1008
1009 //=============================================================================
1010 /*!
1011  *
1012  */
1013 //=============================================================================
1014 SUIT_Desktop* SMESHGUI::desktop()
1015 {
1016   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1017   if( app )
1018     return app->desktop();
1019   else
1020     return 0;
1021 }
1022
1023 //=============================================================================
1024 /*!
1025  *
1026  */
1027 //=============================================================================
1028 SalomeApp_Study* SMESHGUI::activeStudy()
1029 {
1030   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1031   if( app )
1032     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1033   else
1034     return NULL;
1035 }
1036
1037 //=============================================================================
1038 /*!
1039  *
1040  */
1041 //=============================================================================
1042 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1043 {
1044   /* Here the position is on the bottom right corner - 10 */
1045   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1046   aDlg->adjustSize();
1047   SUIT_Desktop *PP = desktop();
1048   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1049   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1050   return true;
1051 }
1052
1053 //=============================================================================
1054 /*!
1055  *
1056  */
1057 //=============================================================================
1058 static int isStudyLocked(_PTR(Study) theStudy){
1059   return theStudy->GetProperties()->IsLocked();
1060 }
1061
1062 static bool checkLock(_PTR(Study) theStudy) {
1063   if (isStudyLocked(theStudy)) {
1064     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1065                            QObject::tr("WRN_WARNING"),
1066                            QObject::tr("WRN_STUDY_LOCKED"),
1067                            QObject::tr("BUT_OK") );
1068     return true;
1069   }
1070   return false;
1071 }
1072
1073 //=======================================================================
1074 //function : CheckActiveStudyLocked
1075 //purpose  :
1076 //=======================================================================
1077
1078 bool SMESHGUI::isActiveStudyLocked()
1079 {
1080   _PTR(Study) aStudy = activeStudy()->studyDS();
1081   return checkLock( aStudy );
1082 }
1083
1084 //=============================================================================
1085 /*!
1086  *
1087  */
1088 //=============================================================================
1089 bool SMESHGUI::OnGUIEvent( int theCommandID )
1090 {
1091   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1092   if( !anApp )
1093     return false;
1094
1095   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1096   SUIT_ResourceMgr* mgr = resourceMgr();
1097   if( !mgr )
1098     return false;
1099
1100   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1101   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1102
1103   QAction* act = action( theCommandID );
1104
1105   switch (theCommandID) {
1106   case 33:                                      // DELETE
1107     if(checkLock(aStudy)) break;
1108     ::OnEditDelete();
1109     break;
1110
1111   case 113:                                     // IMPORT
1112   case 112:
1113   case 111:
1114     {
1115       if(checkLock(aStudy)) break;
1116       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1117       break;
1118     }
1119
1120   case 122:                                     // EXPORT MED
1121   case 121:
1122   case 123:
1123   case 124:
1124   case 125:
1125   case 126:
1126     {
1127       ::ExportMeshToFile(theCommandID);
1128       break;
1129     }
1130
1131   case 200:                                     // SCALAR BAR
1132     {
1133       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1134       SALOME_ListIO selected;
1135       if( aSel )
1136         aSel->selectedObjects( selected );
1137
1138       if( selected.Extent() ) {
1139         Handle(SALOME_InteractiveObject) anIO = selected.First();
1140         if( anIO->hasEntry() ) {
1141           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1142             anActor->SetControlMode( SMESH_Actor::eNone );
1143           }
1144         }
1145       }
1146       break;
1147     }
1148   case 201:
1149     {
1150       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1151       break;
1152     }
1153
1154   case 1134: // Clipping
1155   case 1133: // Tranparency
1156   case 1132: // Colors / Size
1157
1158     // Display Mode
1159   case 215: // Nodes
1160   case 213: // Nodes
1161   case 212: // Nodes
1162   case 211: // Nodes
1163     ::SetDisplayMode(theCommandID);
1164   break;
1165
1166     // Display Entity
1167   case 217: // Edges
1168   case 218: // Faces
1169   case 219: // Volumes
1170   case 220: // All Entity
1171     ::SetDisplayEntity(theCommandID);
1172   break;
1173
1174   case 214:                                     // UPDATE
1175     {
1176       if(checkLock(aStudy)) break;
1177       SMESH::UpdateView();
1178
1179       SALOME_ListIO l;
1180       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1181       aSel->setSelectedObjects( l );
1182       break;
1183     }
1184
1185   case 300:                                     // ERASE
1186   case 301:                                     // DISPLAY
1187   case 302:                                     // DISPLAY ONLY
1188     {
1189       SMESH::EDisplaing anAction;
1190       switch(theCommandID){
1191       case 300: anAction = SMESH::eErase; break;
1192       case 301: anAction = SMESH::eDisplay; break;
1193       case 302: anAction = SMESH::eDisplayOnly; break;
1194       }
1195
1196       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1197       SALOME_ListIO selected;
1198       if( aSel )
1199         aSel->selectedObjects( selected );
1200
1201       if ( vtkwnd ) {
1202         SALOME_ListIteratorOfListIO It(selected);
1203         for (; It.More(); It.Next()) {
1204           Handle(SALOME_InteractiveObject) IOS = It.Value();
1205           if (IOS->hasEntry()) {
1206             SMESH::UpdateView(anAction,IOS->getEntry());
1207           }
1208         }
1209       }
1210       SALOME_ListIO l1;
1211       aSel->setSelectedObjects( l1 );
1212       break;
1213     }
1214
1215   case 400:                                     // NODES
1216     {
1217       if(checkLock(aStudy)) break;
1218
1219       if ( vtkwnd ) {
1220         EmitSignalDeactivateDialog();
1221
1222         new SMESHGUI_NodesDlg(this);
1223       }
1224       else {
1225         SUIT_MessageBox::warn1(desktop(),
1226                               tr("SMESH_WRN_WARNING"), 
1227                               tr("SMESH_WRN_VIEWER_VTK"),
1228                               tr("SMESH_BUT_OK"));
1229       }
1230       break;
1231     }
1232
1233   case 2151:  // FILTER
1234   {
1235     if ( vtkwnd )
1236     {
1237       EmitSignalDeactivateDialog();
1238       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1239     }
1240     break;
1241   }
1242
1243   case 406:                                     // MOVE NODE
1244     {
1245       if ( !vtkwnd )
1246       {
1247         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1248           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1249         break;
1250       }
1251
1252       if(checkLock(aStudy)) break;
1253       new SMESHGUI_MoveNodesDlg(this);
1254       break;
1255     }
1256
1257   case 701:                                     // COMPUTE MESH
1258     {
1259       if(checkLock(aStudy)) break;
1260       if ( vtkwnd ) {
1261         SalomeApp_SelectionMgr *Sel = selectionMgr();
1262         SALOME_ListIO selected; Sel->selectedObjects( selected );
1263
1264         int nbSel = selected.Extent();
1265         if (nbSel != 1){
1266           break;
1267         }
1268
1269         SMESH::SMESH_Mesh_var aMesh;
1270         SMESH::SMESH_subMesh_var aSubMesh;
1271         Handle(SALOME_InteractiveObject) IObject = selected.First();
1272         if (IObject->hasEntry()){
1273           _PTR(SObject) aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
1274           GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
1275           if ( aShapeObject->_is_nil() ) {
1276             // imported mesh
1277             break;
1278           }
1279           if( aMeshSObj ) {
1280             SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
1281             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
1282
1283             if (!aMesh->_is_nil()){
1284               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1285               if (!refShapeObject->_is_nil()) {
1286                 if(!GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject)){
1287                   SUIT_MessageBox::warn1(desktop(),
1288                                         tr("SMESH_WRN_WARNING"),
1289                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1290                                         tr("SMESH_BUT_OK"));
1291                   break;
1292                 }
1293                 try{
1294                   if (GetSMESHGen()->Compute(aMesh,refShapeObject))
1295                     SMESH::ModifiedMesh(aMeshSObj,true);
1296                   // TO Do : change icon of all submeshes
1297                   else
1298                     SUIT_MessageBox::warn1(desktop(), 
1299                                           tr("SMESH_WRN_WARNING"),
1300                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1301                                           tr("SMESH_BUT_OK"));
1302                 }
1303                 catch(const SALOME::SALOME_Exception & S_ex){
1304                   SalomeApp_Tools::QtCatchCorbaException(S_ex);
1305                 }
1306               }
1307             }else if(!aSubMesh->_is_nil()){
1308               aMesh = aSubMesh->GetFather();
1309               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1310               if(!refShapeObject->_is_nil()){
1311                 bool compute = GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject);
1312                 if(!compute){
1313                   SUIT_MessageBox::warn1(desktop(), 
1314                                         tr("SMESH_WRN_WARNING"),
1315                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1316                                         tr("SMESH_BUT_OK"));
1317                   break;
1318                 }
1319                 try{
1320                   if ( GetSMESHGen()->Compute(aMesh,refShapeObject) )
1321                     SMESH::ModifiedMesh(aMeshSObj,true);
1322                   // TO Do : change icon of all submeshes
1323                   else
1324                     SUIT_MessageBox::warn1(desktop(),
1325                                           tr("SMESH_WRN_WARNING"),
1326                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1327                                           tr("SMESH_BUT_OK"));
1328                 }catch(const SALOME::SALOME_Exception & S_ex){
1329                   SalomeApp_Tools::QtCatchCorbaException(S_ex);
1330                 }
1331               }
1332             }
1333           }
1334         }
1335         CORBA::Long anId = aStudy->StudyId();
1336         TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,IObject->getEntry());
1337         cout<<"myAutomaticUpdate - "<<myAutomaticUpdate<<endl;
1338         if(myAutomaticUpdate && aVisualObj){
1339           aVisualObj->Update();
1340           SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
1341           if(!anActor){
1342             anActor = SMESH::CreateActor(aStudy,IObject->getEntry());
1343             if(anActor){
1344               SMESH::DisplayActor(view,anActor); //apo
1345               SMESH::FitAll();
1346             }
1347           }
1348         }
1349       }else{
1350         SUIT_MessageBox::warn1(desktop(),
1351                               tr("SMESH_WRN_WARNING"), 
1352                               tr("SMESH_WRN_VIEWER_VTK"),
1353                               tr("SMESH_BUT_OK"));
1354       }
1355       updateObjBrowser();
1356       break;
1357     }
1358
1359   case 702:                                     // ADD SUB MESH
1360     {
1361       if(checkLock(aStudy)) break;
1362       if( vtkwnd ) {
1363         EmitSignalDeactivateDialog();
1364         new SMESHGUI_AddSubMeshDlg( this );
1365       }
1366       else {
1367         SUIT_MessageBox::warn1(desktop(),
1368                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1369                               tr("SMESH_BUT_OK"));
1370       }
1371       break;
1372     }
1373
1374   case 703:                                     // INIT MESH
1375     {
1376       if(checkLock(aStudy)) break;
1377       EmitSignalDeactivateDialog();
1378       new SMESHGUI_InitMeshDlg( this );
1379       break;
1380     }
1381
1382   case 704:                                     // EDIT Hypothesis 
1383     {
1384       if(checkLock(aStudy)) break;
1385       EmitSignalDeactivateDialog();
1386       new SMESHGUI_EditHypothesesDlg( this );
1387       break;
1388     }
1389
1390   case 705:                                     //  EDIT Global Hypothesis
1391     {
1392       if(checkLock(aStudy)) break;
1393       EmitSignalDeactivateDialog();
1394       new SMESHGUI_EditHypothesesDlg( this );
1395       break;
1396     }
1397
1398   case 706:                                     //  EDIT Local Hypothesis
1399     {
1400       if(checkLock(aStudy)) break;
1401       EmitSignalDeactivateDialog();
1402       new SMESHGUI_EditHypothesesDlg( this );
1403       break;
1404     }
1405
1406   case 407: // DIAGONAL INVERSION
1407   case 408: // Delete diagonal
1408     {
1409       if ( !vtkwnd )
1410       {
1411         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1412           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1413         break;
1414       }
1415
1416       if ( checkLock( aStudy ) )
1417         break;
1418
1419       /*Standard_Boolean aRes;
1420       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1421       if ( aMesh->_is_nil() )
1422       {
1423         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1424           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1425         break;
1426       }
1427       */
1428       EmitSignalDeactivateDialog();
1429       if ( theCommandID == 407 )
1430         new SMESHGUI_TrianglesInversionDlg(this);
1431       else
1432         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1433       break;
1434     }
1435     case 409: // Change orientation
1436     case 410: // Union of triangles
1437     case 411: // Cutting of quadrangles
1438     {
1439       if ( !vtkwnd )
1440       {
1441         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1442           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1443         break;
1444       }
1445
1446       if ( checkLock( aStudy ) )
1447         break;
1448
1449       EmitSignalDeactivateDialog();
1450       SMESHGUI_MultiEditDlg* aDlg = NULL;
1451       if ( theCommandID == 409 )
1452         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1453       else if ( theCommandID == 410 )
1454         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1455       else
1456         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1457
1458       int x, y ;
1459       DefineDlgPosition( aDlg, x, y );
1460       aDlg->move( x, y );
1461       aDlg->show();
1462       break;
1463     }
1464   case 412: // Smoothing
1465     {
1466       if(checkLock(aStudy)) break;
1467       if( vtkwnd ) {
1468         EmitSignalDeactivateDialog();
1469         new SMESHGUI_SmoothingDlg( this );
1470       }
1471       else {
1472         SUIT_MessageBox::warn1(desktop(),
1473                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1474                               tr("SMESH_BUT_OK"));
1475       }
1476       break;
1477     }
1478   case 413: // Extrusion
1479     {
1480       if (checkLock(aStudy)) break;
1481       if (vtkwnd) {
1482         EmitSignalDeactivateDialog();
1483         new SMESHGUI_ExtrusionDlg ( this );
1484       } else {
1485         SUIT_MessageBox::warn1(desktop(),
1486                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1487                                tr("SMESH_BUT_OK"));
1488       }
1489       break;
1490     }
1491   case 414: // Revolution
1492     {
1493       if(checkLock(aStudy)) break;
1494       if( vtkwnd ) {
1495         EmitSignalDeactivateDialog();
1496         new SMESHGUI_RevolutionDlg( this );
1497       }
1498       else {
1499         SUIT_MessageBox::warn1(desktop(),
1500                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1501                               tr("SMESH_BUT_OK"));
1502       }
1503       break;
1504     }
1505   case 415: // Pattern mapping
1506     {
1507       if ( checkLock( aStudy ) )
1508         break;
1509       if ( vtkwnd )
1510       {
1511         EmitSignalDeactivateDialog();
1512         new SMESHGUI_MeshPatternDlg( this );
1513       }
1514       else {
1515         SUIT_MessageBox::warn1(desktop(),
1516                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1517                               tr("SMESH_BUT_OK"));
1518       }
1519       break;
1520     }
1521   case 416: // Extrusion along a path
1522     {
1523       if (checkLock(aStudy)) break;
1524       if (vtkwnd) {
1525         EmitSignalDeactivateDialog();
1526         new SMESHGUI_ExtrusionAlongPathDlg( this );
1527       } else {
1528         SUIT_MessageBox::warn1(desktop(),
1529                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1530                                tr("SMESH_BUT_OK"));
1531       }
1532       break;
1533     }
1534   case 801:                                     // CREATE GROUP
1535     {
1536       if ( !vtkwnd )
1537       {
1538         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1539           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1540         break;
1541       }
1542
1543       if(checkLock(aStudy)) break;
1544       EmitSignalDeactivateDialog();
1545       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1546
1547       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1548       SALOME_ListIO selected;
1549       if( aSel )
1550         aSel->selectedObjects( selected );
1551
1552       int nbSel = selected.Extent();
1553       if (nbSel == 1) {
1554         // check if mesh is selected
1555         aMesh = SMESH::GetMeshByIO( selected.First() );
1556       }
1557       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1558       aDlg->show();
1559       break;
1560     }
1561
1562   case 802:                                     // CONSTRUCT GROUP
1563     {
1564       if ( !vtkwnd )
1565       {
1566         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1567           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1568         break;
1569       }
1570
1571       if(checkLock(aStudy)) break;
1572       EmitSignalDeactivateDialog();
1573
1574       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1575       SALOME_ListIO selected;
1576       if( aSel )
1577         aSel->selectedObjects( selected );
1578
1579       int nbSel = selected.Extent();
1580       if (nbSel == 1) {
1581         // check if submesh is selected
1582         Handle(SALOME_InteractiveObject) IObject = selected.First();
1583         if (IObject->hasEntry()) {
1584           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1585           if( aSObj ) {
1586             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1587             if (!aSubMesh->_is_nil()) {
1588               try {
1589                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1590                 // get submesh elements list by types
1591                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1592                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1593                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1594                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1595                 // create group for each type o elements
1596                 QString aName = IObject->getName();
1597                 if (aNodes->length() > 0) {
1598                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1599                   aGroup->Add(aNodes.inout());
1600                 }
1601                 if (aEdges->length() > 0) {
1602                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1603                   aGroup->Add(aEdges.inout());
1604                 }
1605                 if (aFaces->length() > 0) {
1606                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1607                   aGroup->Add(aFaces.inout());
1608                 }
1609                 if (aVolumes->length() > 0) {
1610                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1611                   aGroup->Add(aVolumes.inout());
1612                 }
1613                 updateObjBrowser();
1614                 
1615               }catch(const SALOME::SALOME_Exception & S_ex){
1616                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1617               }
1618             }
1619           }
1620         }
1621       }
1622       break;
1623     }
1624
1625   case 803:                                     // EDIT GROUP
1626     {
1627       if(checkLock(aStudy)) break;
1628       EmitSignalDeactivateDialog();
1629
1630       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1631       SALOME_ListIO selected;
1632       if( aSel )
1633         aSel->selectedObjects( selected );
1634
1635       SALOME_ListIteratorOfListIO It (selected);
1636       int nbSelectedGroups = 0;
1637       for ( ; It.More(); It.Next() )
1638       {
1639         SMESH::SMESH_Group_var aGroup =
1640           SMESH::IObjectToInterface<SMESH::SMESH_Group>(It.Value());
1641         if (!aGroup->_is_nil()) {
1642           nbSelectedGroups++;
1643           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1644           aDlg->show();
1645         }
1646       }
1647       if (nbSelectedGroups == 0)
1648         {
1649           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_Group::_nil());
1650           aDlg->show();
1651         }
1652       break;
1653     }
1654
1655   case 804:                                     // Add elements to group
1656     {
1657       if(checkLock(aStudy)) break;
1658       if (myState == 800) {
1659         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1660         if (aDlg) aDlg->onAdd();
1661       }
1662       break;
1663     }
1664
1665   case 805:                                     // Remove elements from group
1666     {
1667       if(checkLock(aStudy)) break;
1668       if (myState == 800) {
1669         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1670         if (aDlg) aDlg->onRemove();
1671       }
1672       break;
1673     }
1674
1675     case 810: // Union Groups
1676     case 811: // Intersect groups
1677     case 812: // Cut groups
1678     {
1679       if ( checkLock( aStudy ) )
1680         break;
1681
1682       EmitSignalDeactivateDialog();
1683
1684       int aMode;
1685       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1686       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1687       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1688
1689       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1690       break;
1691     }
1692
1693     case 813: // Delete groups with their contents
1694     {
1695       if ( checkLock( aStudy ) )
1696         break;
1697
1698       EmitSignalDeactivateDialog();
1699
1700       new SMESHGUI_DeleteGroupDlg( this );
1701       break;
1702     }
1703
1704   case 900:                                     // MESH INFOS
1705     {
1706       EmitSignalDeactivateDialog();
1707       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1708       SALOME_ListIO selected;
1709       if( aSel )
1710         aSel->selectedObjects( selected );
1711
1712       if ( selected.Extent() > 1 ) { // a dlg for each IO
1713         SALOME_ListIO IOs;
1714         SALOME_ListIteratorOfListIO It (selected);
1715         for ( ; It.More(); It.Next() ) {
1716           IOs.Clear(); IOs.Append( It.Value() );
1717           aSel->setSelectedObjects( IOs );
1718           new SMESHGUI_MeshInfosDlg(this, "", false);
1719         }
1720         // restore selection
1721         aSel->setSelectedObjects( selected );
1722       }
1723       else
1724         new SMESHGUI_MeshInfosDlg(this, "", false);
1725       break;
1726     }
1727
1728   case 902:                                     // STANDARD MESH INFOS
1729     {
1730       EmitSignalDeactivateDialog();
1731       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1732       SALOME_ListIO selected;
1733       if( aSel )
1734         aSel->selectedObjects( selected );
1735
1736       if ( selected.Extent() > 1 ) { // a dlg for each IO
1737         SALOME_ListIO IOs;
1738         SALOME_ListIteratorOfListIO It (selected);
1739         for ( ; It.More(); It.Next() ) {
1740           IOs.Clear();
1741           IOs.Append( It.Value() );
1742           aSel->setSelectedObjects( IOs );
1743           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1744         }
1745         // restore selection
1746         aSel->setSelectedObjects( selected );
1747       }
1748       else
1749         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1750       break;
1751     } 
1752     
1753   case 1001:                                    // AUTOMATIC UPDATE PREFERENCES
1754     {
1755       if (act->isOn()) {
1756         mgr->setValue( "SMESH", "AutomaticUpdate", true );
1757         myAutomaticUpdate = true;
1758       }
1759       else {
1760         mgr->setValue( "SMESH", "AutomaticUpdate", false );
1761         myAutomaticUpdate = false;
1762       }
1763       break;
1764     }
1765
1766   case 1003:                                    // MESH PREFERENCES
1767     {
1768       ::SetDisplaySettings();
1769       break;
1770     }
1771
1772   case 1005:
1773     {
1774       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( this );
1775       break;
1776     }
1777
1778   case 10070:
1779     {
1780       ( new SMESHGUI_PrecisionDlg( this ) )->exec();
1781       break;
1782     }
1783
1784   case 10071:
1785     {
1786       if (act->isOn()) {
1787         mgr->setValue( "SMESH", "DispayEntity", true );
1788       }
1789       else {
1790         mgr->setValue( "SMESH", "DispayEntity", false );
1791       }
1792       break;
1793     }
1794   case 1006:
1795     {
1796       SMESHGUI_Preferences_SelectionDlg* aDlg = 
1797         new SMESHGUI_Preferences_SelectionDlg( this );
1798
1799       QColor aColor = mgr->colorValue( "SMESH", "SettingsPreSelectColor", Qt::cyan );
1800       aDlg->SetColor(1, aColor);
1801
1802       aColor = mgr->colorValue( "SMESH", "SettingsItemSelectColor", Qt::yellow );
1803       aDlg->SetColor(2, aColor);
1804
1805       aColor = mgr->colorValue( "SMESH", "SettingsSelectColor", Qt::white );
1806       aDlg->SetColor(3, aColor);
1807
1808       aDlg->SetWidth(1, mgr->integerValue( "SMESH", "SettingsPreSelectWidth", 5 ) );
1809       aDlg->SetWidth(2, mgr->integerValue( "SMESH", "SettingsItemSelectWidth", 5 ) );
1810       aDlg->SetPrecision(1, mgr->doubleValue( "SMESH", "SettingsNodeSelectTol", 0.025 ) );
1811       aDlg->SetPrecision(2, mgr->doubleValue( "SMESH", "SettingsElementsSelectTol", 0.001 ) );
1812
1813       if (aDlg->exec()) {
1814         QColor aPreColor = aDlg->GetColor(1),
1815                aSelColor = aDlg->GetColor(2),
1816                aHiColor = aDlg->GetColor(3);
1817         int aPreWidth = aDlg->GetWidth(1),
1818             aSelWidth = aDlg->GetWidth(2);
1819         double aTolNodes = aDlg->GetPrecision(1),
1820                aTolItems = aDlg->GetPrecision(2);
1821
1822         mgr->setValue( "SMESH", "SettingsPreSelectColor", aPreColor );
1823         mgr->setValue( "SMESH", "SettingsItemSelectColor", aSelColor );
1824         mgr->setValue( "SMESH", "SettingsSelectColor", aHiColor );
1825
1826         mgr->setValue( "SMESH", "SettingsPreSelectWidth", aPreWidth );
1827         mgr->setValue( "SMESH", "SettingsItemSelectWidth", aSelWidth );
1828         mgr->setValue( "SMESH", "SettingsNodeSelectTol", aTolNodes );
1829         mgr->setValue( "SMESH", "SettingsElementsSelectTol", aTolItems );
1830
1831         // update current study settings
1832         SMESH::UpdateSelectionProp( this );
1833
1834         if( vtkwnd ) {
1835           // update VTK viewer properties
1836           SVTK_RenderWindowInteractor* anInteractor =
1837             dynamic_cast<SVTK_RenderWindowInteractor*>( vtkwnd->getRWInteractor() );
1838           if (anInteractor) {
1839             anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
1840                                            aSelColor.blue()/255., aSelWidth);
1841             anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
1842             SVTK_InteractorStyle* aStyle =
1843               dynamic_cast<SVTK_InteractorStyle*>( anInteractor->GetInteractorStyle() );
1844
1845             if (aStyle)
1846               aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
1847                                           aPreColor.blue()/255., aPreWidth);
1848           }
1849           // update actors
1850           vtkRenderer* aRenderer = vtkwnd->getRenderer();
1851           vtkActorCollection *aCollection = aRenderer->GetActors();
1852           aCollection->InitTraversal();
1853           while(vtkActor *anAct = aCollection->GetNextActor()){
1854             if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1855               anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
1856                                          aHiColor.blue()/255.);
1857               anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
1858                                             aPreColor.blue()/255.);
1859             }
1860           }
1861         }
1862       }
1863
1864       break;
1865     }
1866
1867   case 1100:                                    // EDIT HYPOTHESIS
1868     {
1869       if(checkLock(aStudy)) break;
1870
1871       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1872       SALOME_ListIO selected;
1873       if( aSel )
1874         aSel->selectedObjects( selected );
1875
1876       int nbSel = selected.Extent();
1877
1878       if (nbSel == 1) {
1879         SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(selected.First());
1880
1881         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1882         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1883         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1884         if ( !Hyp->_is_nil() )
1885         {
1886           char* sName = Hyp->GetName();
1887           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
1888           if (aCreator)
1889           {
1890             aCreator->EditHypothesis(Hyp);
1891           }
1892           else
1893           {
1894             // report error
1895           }
1896         }
1897       }
1898       updateObjBrowser( true );
1899       break;
1900     }
1901
1902   case 1101:                                    // RENAME
1903     {
1904       if ( checkLock( aStudy ) )
1905         break;
1906
1907       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1908       SALOME_ListIO selected;
1909       if( aSel )
1910         aSel->selectedObjects( selected );
1911
1912       SALOME_ListIteratorOfListIO It( selected );
1913       for ( ; It.More(); It.Next() )
1914       {
1915         Handle(SALOME_InteractiveObject) IObject = It.Value();
1916         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
1917         _PTR(GenericAttribute) anAttr;
1918         _PTR(AttributeName) aName;
1919         if ( obj )
1920         {
1921           if ( obj->FindAttribute(anAttr, "AttributeName") )
1922           {
1923             aName = anAttr;
1924             QString newName = QString(aName->Value().c_str());
1925             newName = SalomeApp_NameDlg::getName( desktop(), newName );
1926             if ( !newName.isEmpty() )
1927             {
1928               //old source: aStudy->renameIObject( IObject, newName );
1929               aName->SetValue( newName.latin1() );
1930
1931               // if current object is group update group's name
1932               SMESH::SMESH_GroupBase_var aGroup =
1933                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1934               if (!aGroup->_is_nil() )
1935                 aGroup->SetName( newName.latin1() );
1936                 
1937               updateObjBrowser();
1938             }
1939           }
1940         }
1941       }
1942       break;
1943     }
1944
1945   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1946     {
1947       if(checkLock(aStudy)) break;
1948       SUIT_OverrideCursor wc;
1949
1950       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1951       SALOME_ListIO selected;
1952       if( aSel )
1953         aSel->selectedObjects( selected );
1954
1955       SALOME_ListIteratorOfListIO It(selected);
1956       for (int i = 0; It.More(); It.Next(), i++) {
1957         Handle(SALOME_InteractiveObject) IObject = It.Value();
1958         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1959       }
1960       SALOME_ListIO l1;
1961       aSel->setSelectedObjects( l1 );
1962       updateObjBrowser();
1963       break;
1964     }
1965
1966   case 401:                                     // GEOM::EDGE
1967   case 4021:                                    // TRIANGLE
1968   case 4022:                                    // QUAD
1969   case 4023:                                    // POLYGON
1970   case 4031:                                    // TETRA
1971   case 4032:                                    // HEXA
1972     {
1973       if(checkLock(aStudy)) break;
1974       if ( vtkwnd ) {
1975         EmitSignalDeactivateDialog();
1976         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1977         int                 nbNodes = 2;
1978         switch (theCommandID) {
1979         case 4021:                                      // TRIANGLE
1980           type = SMDSAbs_Face; nbNodes = 3; break;
1981         case 4022:                                      // QUAD
1982           type = SMDSAbs_Face; nbNodes = 4; break;
1983         case 4031:                                      // TETRA
1984           type = SMDSAbs_Volume; nbNodes = 4; break;
1985         case 4023:                                      // POLYGON
1986           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
1987         case 4032:                                      // HEXA
1988           type = SMDSAbs_Volume; nbNodes = 8; break;
1989         case 4033:                                      // POLYHEDRE
1990           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
1991         default:;
1992         }
1993         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
1994       }
1995       else {
1996         SUIT_MessageBox::warn1(desktop(),
1997                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1998                               tr("SMESH_BUT_OK"));
1999       }
2000       break;
2001     }
2002   case 4033:                                    // POLYHEDRON
2003     {
2004       if(checkLock(aStudy)) break;
2005       if ( vtkwnd ) {
2006         EmitSignalDeactivateDialog();
2007         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2008       }
2009       else {
2010         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2011                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2012                               tr("SMESH_BUT_OK"));
2013       }
2014       break;
2015     }
2016   case 4041:                                    // REMOVES NODES
2017     {
2018       if(checkLock(aStudy)) break;
2019       if ( vtkwnd ) {
2020         EmitSignalDeactivateDialog();
2021         new SMESHGUI_RemoveNodesDlg(this);
2022       }
2023       else {
2024         SUIT_MessageBox::warn1(desktop(),
2025                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2026                               tr("SMESH_BUT_OK"));
2027       }
2028       break;
2029     }
2030   case 4042:                                    // REMOVES ELEMENTS
2031     {
2032       if(checkLock(aStudy)) break;
2033       if( vtkwnd ) {
2034         EmitSignalDeactivateDialog();
2035         new SMESHGUI_RemoveElementsDlg(this);
2036       }
2037       else
2038         {
2039           SUIT_MessageBox::warn1(desktop(),
2040                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2041                                 tr("SMESH_BUT_OK"));
2042         }
2043       break;
2044     }
2045   case 4051:                                    // RENUMBERING NODES
2046     {
2047       if(checkLock(aStudy)) break;
2048       if( vtkwnd ) {
2049         EmitSignalDeactivateDialog();
2050         new SMESHGUI_RenumberingDlg( this, "", 0);
2051       }
2052       else
2053         {
2054           SUIT_MessageBox::warn1(desktop(),
2055                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2056                                 tr("SMESH_BUT_OK"));
2057         }
2058       break;
2059     }
2060   case 4052:                                    // RENUMBERING ELEMENTS
2061     {
2062       if(checkLock(aStudy)) break;
2063       if ( vtkwnd ) {
2064         EmitSignalDeactivateDialog();
2065         new SMESHGUI_RenumberingDlg( this, "", 1);
2066       }
2067       else
2068         {
2069           SUIT_MessageBox::warn1(desktop(),
2070                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2071                                 tr("SMESH_BUT_OK"));
2072         }
2073       break;
2074     }
2075   case 4061:                                   // TRANSLATION
2076     {
2077       if(checkLock(aStudy)) break;
2078       if ( vtkwnd ) {
2079         EmitSignalDeactivateDialog();
2080         new SMESHGUI_TranslationDlg( this );
2081       }
2082       else {
2083         SUIT_MessageBox::warn1(desktop(),
2084                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2085                               tr("SMESH_BUT_OK"));
2086       }
2087       break;
2088     }
2089   case 4062:                                   // ROTATION
2090     {
2091       if(checkLock(aStudy)) break;
2092       if( vtkwnd ) {
2093         EmitSignalDeactivateDialog();
2094         new SMESHGUI_RotationDlg( this );
2095       }
2096       else {
2097         SUIT_MessageBox::warn1(desktop(),
2098                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2099                               tr("SMESH_BUT_OK"));
2100       }
2101       break;
2102     }
2103   case 4063:                                   // SYMMETRY 
2104     {
2105       if(checkLock(aStudy)) break;
2106       if(vtkwnd) {
2107         EmitSignalDeactivateDialog();
2108         new SMESHGUI_SymmetryDlg( this );
2109       }
2110       else {
2111         SUIT_MessageBox::warn1(desktop(),
2112                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2113                               tr("SMESH_BUT_OK"));
2114       }
2115       break;
2116     }
2117   case 4064:                                   // SEWING
2118     {
2119       if(checkLock(aStudy)) break;
2120       if(vtkwnd) {
2121         EmitSignalDeactivateDialog();
2122         new SMESHGUI_SewingDlg( this );
2123       }
2124       else {
2125         SUIT_MessageBox::warn1(desktop(),
2126                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2127                               tr("SMESH_BUT_OK"));
2128       }
2129       break;
2130     }
2131   case 4065:                                   // MERGE NODES
2132     {
2133       if(checkLock(aStudy)) break;
2134       if(vtkwnd) {
2135         EmitSignalDeactivateDialog();
2136         new SMESHGUI_MergeNodesDlg( this );
2137       }
2138       else {
2139         SUIT_MessageBox::warn1(desktop(),
2140                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2141                               tr("SMESH_BUT_OK"));
2142       }
2143       break;
2144     }
2145     
2146
2147   case 5000: // HYPOTHESIS
2148     {
2149       if(checkLock(aStudy)) break;
2150       EmitSignalDeactivateDialog();
2151       new SMESHGUI_CreateHypothesesDlg ( this, "", FALSE, false );
2152       break;
2153     }
2154   case 5010: // ALGO
2155     {
2156       if(checkLock(aStudy)) break;
2157       EmitSignalDeactivateDialog();
2158       new SMESHGUI_CreateHypothesesDlg ( this, "", FALSE, true);
2159       break;
2160     }
2161
2162   case 5105: // Library of selection filters
2163   {
2164     static QValueList<int> aTypes;
2165     if ( aTypes.isEmpty() )
2166     {
2167       aTypes.append( SMESH::NODE );
2168       aTypes.append( SMESH::EDGE );
2169       aTypes.append( SMESH::FACE );
2170       aTypes.append( SMESH::VOLUME );
2171     }
2172     new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2173   }
2174   break;
2175
2176   case 6017:                                    // CONTROLS
2177   case 6016:
2178   case 6015:
2179   case 6014:
2180   case 6013:
2181   case 6012:
2182   case 6011:
2183   case 6001:
2184   case 6018:
2185   case 6019:
2186   case 6002:
2187   case 6003:
2188   case 6004:
2189     if ( vtkwnd ) {
2190
2191       SalomeApp_SelectionMgr* mgr = selectionMgr();
2192       SALOME_ListIO selected; mgr->selectedObjects( selected );
2193
2194       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2195         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2196         if ( SO ) {
2197           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2198           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2199           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2200           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2201           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2202             ::Control( theCommandID );
2203             break;
2204           }
2205         }
2206       }
2207       SUIT_MessageBox::warn1(desktop(),
2208                             tr( "SMESH_WRN_WARNING" ),
2209                             tr( "SMESH_BAD_SELECTION" ),
2210                             tr( "SMESH_BUT_OK" ) );
2211       break;
2212     }
2213     else {
2214       SUIT_MessageBox::warn1(desktop(),
2215                             tr( "SMESH_WRN_WARNING" ),
2216                             tr( "NOT_A_VTK_VIEWER" ), 
2217                             tr( "SMESH_BUT_OK" ) );
2218     }
2219     break;
2220   case 9010:
2221     {
2222       SalomeApp_SelectionMgr* mgr = selectionMgr();
2223       SALOME_ListIO selected; mgr->selectedObjects( selected );
2224
2225       if (selected.Extent() == 1)       {
2226         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2227         if(anIObject->hasEntry())
2228           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2229             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2230           }
2231       }
2232       break;
2233     }
2234   case 9011:
2235     {
2236       SalomeApp_SelectionMgr* mgr = selectionMgr();
2237       SALOME_ListIO selected; mgr->selectedObjects( selected );
2238
2239       if (selected.Extent() == 1)       {
2240         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2241         if(anIObject->hasEntry())
2242           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2243             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2244           }
2245       }
2246       break;
2247     }
2248   case 10001:                           // DISPLAY MODE PREFERENCE
2249     {
2250       // Wireframe
2251       act->setOn( true );
2252       action( 10002 )->setOn( false );
2253       action( 10004 )->setOn( false );
2254       action( 10003 )->setOn( true );
2255       mgr->setValue( "SMESH", "DisplayMode", "Wireframe");
2256       break;
2257     }
2258   case 10002:
2259     {
2260       act->setOn( true );
2261       action( 10001 )->setOn( false );
2262       action( 10004 )->setOn( false );
2263       action( 10003 )->setOn( true );
2264       mgr->setValue( "SMESH", "DisplayMode", "Shading");
2265       break;
2266     }
2267   case 10003:
2268     {
2269       mgr->setValue( "SMESH", "Shrink", act->isOn() );
2270       break;
2271     }
2272   case 10004:
2273     {
2274       act->setOn( true );
2275       action( 10001 )->setOn( false );
2276       action( 10002 )->setOn( false );
2277       action( 10003 )->setOn( false );
2278       mgr->setValue( "SMESH", "DisplayMode", "Nodes" );
2279       break;
2280     }
2281
2282   }
2283
2284   //updateObjBrowser();
2285   return true;
2286 }
2287
2288 //=============================================================================
2289 /*!
2290  *
2291  */
2292 //=============================================================================
2293 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2294 {
2295   return false;
2296 }
2297
2298 //=============================================================================
2299 /*!
2300  *
2301  */
2302 //=============================================================================
2303 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2304 {
2305   return true;
2306 }
2307
2308 //=============================================================================
2309 /*!
2310  *
2311  */
2312 //=============================================================================
2313 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2314 {
2315   return true;
2316 }
2317
2318 //=============================================================================
2319 /*!
2320  *
2321  */
2322 //=============================================================================
2323 bool SMESHGUI::SetSettings(SUIT_Desktop* parent)
2324 {
2325   SMESHGUI::GetSMESHGUI();
2326   
2327   SUIT_ResourceMgr* mgr = resourceMgr();
2328   if( !mgr )
2329     return false;
2330
2331   // Display mode
2332   QString DisplayMode = "Shading";
2333   if ( mgr->hasValue("SMESH","DisplayMode") )
2334     DisplayMode = mgr->stringValue("SMESH","DisplayMode");
2335   else
2336     mgr->setValue("SMESH","DisplayMode", "Shading");
2337
2338   bool Shrink = false;
2339   if ( mgr->hasValue("SMESH","Shrink") )
2340     Shrink = mgr->stringValue("SMESH","Shrink") == "yes";
2341
2342   if (DisplayMode == "Wireframe") {
2343     // wireframe
2344     action( 10004 )->setOn( false );
2345     action( 10002 )->setOn( false );
2346     action( 10001 )->setOn( true );
2347     action( 10003 )->setOn( true );
2348   }
2349   else if (DisplayMode == "Nodes") {
2350     // poins
2351     action( 10004 )->setOn( true );
2352     action( 10002 )->setOn( false );
2353     action( 10001 )->setOn( false );
2354     action( 10003 )->setOn( false );
2355   }
2356   else {
2357     // default is shading
2358     action( 10004 )->setOn( false );
2359     action( 10002 )->setOn( true );
2360     action( 10001 )->setOn( false );
2361     action( 10003 )->setOn( true );
2362   }
2363
2364   action( 10003 )->setOn( Shrink );
2365
2366   // Automatic Update
2367   if ( mgr->booleanValue( "SMESH","AutomaticUpdate", false ) ) {
2368     action( 1001 )->setOn( true );
2369     myAutomaticUpdate = true;
2370   }
2371   else {
2372     action( 1001 )->setOn( false );
2373     myAutomaticUpdate = false;
2374   }
2375
2376   if ( mgr->booleanValue( "SMESH","DispayEntity", false ) )
2377     action( 10071 )->setOn( true );
2378   else
2379     action( 10071 )->setOn( false );
2380
2381   // Selection
2382   SMESH::UpdateSelectionProp( this );
2383
2384   // menus disable
2385   action( 111 )->setEnabled( false );   // IMPORT DAT
2386
2387   //action( 112 )->setEnabled( false );
2388   //parent->menuBar()->setItemEnabled(112, false);      // IMPORT UNV
2389
2390   return true;
2391 }
2392
2393 //=============================================================================
2394 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2395  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2396  */
2397 //=============================================================================
2398 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2399                                   SUIT_ViewWindow* wnd )
2400 {
2401   if(theIO->hasEntry()){
2402     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2403     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2404   }
2405 }
2406
2407 //=======================================================================
2408 // function : createSMESHAction
2409 // purpose  :
2410 //=======================================================================
2411 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2412 {
2413   QIconSet icon;
2414   QWidget* parent = application()->desktop();
2415   SUIT_ResourceMgr* resMgr = resourceMgr();
2416   QPixmap pix;
2417   if ( icon_id.length() )
2418     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2419   else
2420     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ) );
2421   if ( !pix.isNull() )
2422     icon = QIconSet( pix );
2423
2424   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2425           menu       = tr( QString( "MEN_" )+po_id ),
2426           status_bar = tr( QString( "STB_" )+po_id );
2427
2428   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2429 }
2430
2431 //=======================================================================
2432 // function : createPopupItem
2433 // purpose  :
2434 //=======================================================================
2435 void SMESHGUI::createPopupItem( const int id,
2436                                 const QString& clients,
2437                                 const QString& types,
2438                                 const QString& theRule,
2439                                 const int pId )
2440 {
2441   int parentId = pId;
2442   if( pId!=-1 )
2443     parentId = popupMgr()->actionId( action( pId ) );
2444
2445   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2446     popupMgr()->insert( action( id ), parentId, 0 );
2447
2448   QChar lc = QtxPopupMgr::Selection::defEquality();
2449   QString rule = "(%1) and (%2) and (%3)";
2450   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2451   rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2452   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2453   rule += theRule;
2454
2455   bool cont = myRules.contains( id );
2456   if( cont )
2457     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2458
2459   popupMgr()->setRule( action( id ), rule, true );
2460   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2461 }
2462
2463 //=======================================================================
2464 // function : initialize
2465 // purpose  :
2466 //=======================================================================
2467 void SMESHGUI::initialize( CAM_Application* app )
2468 {
2469   SalomeApp_Module::initialize( app );
2470
2471   // ----- create actions --------------
2472
2473   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2474   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2475   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2476   createSMESHAction(  114, "NUM" );
2477   createSMESHAction(  121, "DAT" );
2478   createSMESHAction(  122, "MED" );
2479   createSMESHAction(  123, "UNV" );
2480   createSMESHAction(  124, "EXPORT_DAT" );
2481   createSMESHAction(  125, "EXPORT_MED" );
2482   createSMESHAction(  126, "EXPORT_UNV" );
2483   createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
2484   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2485   createSMESHAction( 5000, "CREATE_HYPO",     "ICON_HYPO" );
2486   createSMESHAction( 5010, "CREATE_ALG",      "ICON_PATTERN_2d" );
2487   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2488   createSMESHAction(  702, "LOCAL_HYPO",      "ICON_DLG_ADD_SUBMESH" );
2489   createSMESHAction(  703, "GLOBAL_HYPO",     "ICON_DLG_INIT_MESH" );
2490   createSMESHAction(  704, "EDIT_HYPO",       "ICON_DLG_EDIT_MESH" );
2491   createSMESHAction(  705, "EDIT_GLOBAL_HYPO","ICON_DLG_EDIT_MESH" );
2492   createSMESHAction(  706, "EDIT_LOCAL_HYPO", "ICON_DLG_EDIT_MESH" );
2493   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2494   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2495   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2496   createSMESHAction(  804, "ADD" );
2497   createSMESHAction(  805, "REMOVE" );
2498   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2499   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2500   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2501   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2502   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2503   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2504   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2505   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2506   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2507   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2508   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2509   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2510   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2511   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2512   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2513   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2514   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2515   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2516   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2517   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2518   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2519   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2520   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2521   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2522   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2523   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2524   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2525   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2526   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2527   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2528   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2529   createSMESHAction( 4062, "ROT",             "ICON_DLG_ROTATION" );
2530   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2531   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2532   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2533   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2534   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2535   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2536   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2537   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2538   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2539   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2540   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2541   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2542   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2543   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2544   createSMESHAction( 10001, "WIRE",           "ICON_WIRE",   0, true );
2545   createSMESHAction( 10002, "SHADE",          "ICON_SHADE",  0, true );
2546   createSMESHAction( 10003, "SHRINK",         "ICON_SHRINK", 0, true );
2547   createSMESHAction( 10004, "NODES",          "ICON_POINTS", 0, true );
2548   createSMESHAction( 1001, "AUTO_UPD", "", 0, true );
2549   createSMESHAction( 1003, "COLORS" );
2550   createSMESHAction( 1005, "SCALAR_BAR" );
2551   createSMESHAction( 1006, "SELECTION" );
2552   createSMESHAction( 10070, "PRECISION", "", 0, true );
2553   createSMESHAction( 10071, "DISP_ENT", "", 0, true );
2554   createSMESHAction(  200, "RESET" );
2555   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2556   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2557   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2558   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2559   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2560   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2561   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2562   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2563   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2564   createSMESHAction(  220, "ALL" );
2565   createSMESHAction( 1100, "EDIT_HYPO" );
2566   createSMESHAction( 1101, "RENAME" );
2567   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2568   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2569   createSMESHAction( 1131, "DISPMODE" );
2570   createSMESHAction( 1132, "COLORS" );
2571   createSMESHAction( 1133, "TRANSP" );
2572   createSMESHAction( 1134, "CLIP" );
2573   createSMESHAction( 1135, "DISP_ENT" );
2574   createSMESHAction( 2000, "CTRL" );
2575   
2576   createSMESHAction( 300, "ERASE" );
2577   createSMESHAction( 301, "DISPLAY" );
2578   createSMESHAction( 302, "DISPLAY_ONLY" );
2579   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2580
2581   // ----- create menu --------------
2582   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2583       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2584       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 10 ),
2585       hypoId   = createMenu( tr( "MEN_HYPO" ),   -1, 50, 10 ),
2586       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2587       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2588       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2589       prefId   = createMenu( tr( "MEN_PREF" ),   -1,  4, 10 ),
2590       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2591
2592   createMenu( separator(), fileId );
2593
2594   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2595       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2596
2597       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2598       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2599       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2600       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
2601
2602       meshPrefId = createMenu( tr( "MEN_MESH" ), prefId, 100 ),
2603
2604       dispModeId = createMenu( tr( "MEN_DISPMODE" ), meshPrefId, 1000 ),
2605       qualityId  = createMenu( tr( "MEN_QUALITY" ),  meshPrefId, 1007 );
2606
2607   createMenu( 111, importId, -1 );
2608   createMenu( 112, importId, -1 );
2609   createMenu( 113, importId, -1 );
2610
2611   createMenu( 121, exportId, -1 );
2612   createMenu( 122, exportId, -1 );
2613   createMenu( 123, exportId, -1 );
2614
2615   createMenu( separator(), fileId, 10 );
2616
2617   createMenu( 33, editId, -1 );
2618
2619   createMenu( 5105, toolsId, -1 );
2620
2621   createMenu( 5000, hypoId, -1 );
2622   createMenu( 5010, hypoId, -1 );
2623
2624   createMenu( 703, meshId, -1 );
2625   createMenu( 702, meshId, -1 );
2626   createMenu( 704, meshId, -1 );
2627   createMenu( separator(), meshId, -1 );
2628   createMenu( 701, meshId, -1 );
2629   createMenu( separator(), meshId, -1 );
2630   createMenu( 801, meshId, -1 );
2631   createMenu( 802, meshId, -1 );
2632   createMenu( 803, meshId, -1 );
2633   createMenu( separator(), meshId, -1 );
2634   createMenu( 810, meshId, -1 );
2635   createMenu( 811, meshId, -1 );
2636   createMenu( 812, meshId, -1 );
2637   createMenu( separator(), meshId, -1 );
2638   createMenu( 813, meshId, -1 );
2639   createMenu( separator(), meshId, -1 );
2640   createMenu( 900, meshId, -1 );
2641   createMenu( 902, meshId, -1 );
2642   createMenu( separator(), meshId, -1 );
2643
2644   createMenu( 6003, ctrlId, -1 );
2645   createMenu( 6001, ctrlId, -1 );
2646   createMenu( 6004, ctrlId, -1 );
2647   createMenu( separator(), ctrlId, -1 );
2648   createMenu( 6002, ctrlId, -1 );
2649   createMenu( 6018, ctrlId, -1 );
2650   createMenu( 6019, ctrlId, -1 );
2651   createMenu( 6011, ctrlId, -1 );
2652   createMenu( 6012, ctrlId, -1 );
2653   createMenu( 6013, ctrlId, -1 );
2654   createMenu( 6014, ctrlId, -1 );
2655   createMenu( 6015, ctrlId, -1 );
2656   createMenu( 6016, ctrlId, -1 );
2657   createMenu( separator(), ctrlId, -1 );
2658   createMenu( 6017, ctrlId, -1 );
2659   createMenu( separator(), ctrlId, -1 );
2660
2661   createMenu( 400, addId, -1 );
2662   createMenu( 401, addId, -1 );
2663   createMenu( 4021, addId, -1 );
2664   createMenu( 4022, addId, -1 );
2665   createMenu( 4023, addId, -1 );
2666   createMenu( 4031, addId, -1 );
2667   createMenu( 4032, addId, -1 );
2668   createMenu( 4033, addId, -1 );
2669
2670   createMenu( 4041, removeId, -1 );
2671   createMenu( 4042, removeId, -1 );
2672
2673   createMenu( 4051, renumId, -1 );
2674   createMenu( 4052, renumId, -1 );
2675
2676   createMenu( 4061, transfId, -1 );
2677   createMenu( 4062, transfId, -1 );
2678   createMenu( 4063, transfId, -1 );
2679   createMenu( 4064, transfId, -1 );
2680   createMenu( 4065, transfId, -1 );
2681
2682   createMenu( 406, modifyId, -1 );
2683   createMenu( 407, modifyId, -1 );
2684   createMenu( 408, modifyId, -1 );
2685   createMenu( 409, modifyId, -1 );
2686   createMenu( 410, modifyId, -1 );
2687   createMenu( 411, modifyId, -1 );
2688   createMenu( 412, modifyId, -1 );
2689   createMenu( 413, modifyId, -1 );
2690   createMenu( 416, modifyId, -1 );
2691   createMenu( 414, modifyId, -1 );
2692   createMenu( 415, modifyId, -1 );
2693
2694   createMenu( 10001, dispModeId, -1 );
2695   createMenu( 10002, dispModeId, -1 );
2696   createMenu( 10004, dispModeId, -1 );
2697   createMenu( 10003, dispModeId, -1 );
2698
2699   createMenu( 1001, prefId, -1 );
2700   createMenu( separator(), prefId, -1 );
2701   createMenu( 1003, prefId, -1 );
2702   createMenu( separator(), prefId, -1 );
2703   createMenu( 1005, prefId, -1 );
2704   createMenu( separator(), prefId, -1 );
2705   createMenu( 1006, prefId, -1 );
2706   createMenu( separator(), prefId, -1 );
2707
2708   createMenu( 10070, qualityId, -1 );
2709   createMenu( 10071, qualityId, -1 );
2710
2711   createMenu( separator(), prefId, -1 );
2712
2713   createMenu( 214, viewId, -1 );
2714
2715   // ----- create toolbars --------------
2716   int meshTb     = createTool( tr( "TB_MESH" ) ),
2717       hypoTb     = createTool( tr( "TB_HYPO" ) ),
2718       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2719       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2720       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2721       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2722
2723   createTool( 703, meshTb );
2724   createTool( 702, meshTb );
2725   createTool( 704, meshTb );
2726   createTool( separator(), meshTb );
2727   createTool( 701, meshTb );
2728   createTool( separator(), meshTb );
2729   createTool( 801, meshTb );
2730   createTool( 802, meshTb );
2731   createTool( 803, meshTb );
2732   createTool( separator(), meshTb );
2733   createTool( 900, meshTb );
2734   createTool( 902, meshTb );
2735   createTool( separator(), meshTb );
2736
2737   createTool( 5000, hypoTb );
2738   createTool( 5010, hypoTb );
2739
2740   createTool( 6001, ctrlTb );
2741   createTool( 6003, ctrlTb );
2742   createTool( 6004, ctrlTb );
2743   createTool( separator(), ctrlTb );
2744   createTool( 6002, ctrlTb );
2745   createTool( 6018, ctrlTb );
2746   createTool( 6019, ctrlTb );
2747   createTool( 6011, ctrlTb );
2748   createTool( 6012, ctrlTb );
2749   createTool( 6013, ctrlTb );
2750   createTool( 6014, ctrlTb );
2751   createTool( 6015, ctrlTb );
2752   createTool( 6016, ctrlTb );
2753   createTool( separator(), ctrlTb );
2754   createTool( 6017, ctrlTb );
2755   createTool( separator(), ctrlTb );
2756
2757   createTool( 400, addRemTb );
2758   createTool( 401, addRemTb );
2759   createTool( 4021, addRemTb );
2760   createTool( 4022, addRemTb );
2761   createTool( 4023, addRemTb );
2762   createTool( 4031, addRemTb );
2763   createTool( 4032, addRemTb );
2764   createTool( 4033, addRemTb );
2765   createTool( separator(), addRemTb );
2766   createTool( 4041, addRemTb );
2767   createTool( 4042, addRemTb );
2768   createTool( separator(), addRemTb );
2769   createTool( 4051, addRemTb );
2770   createTool( 4052, addRemTb );
2771   createTool( separator(), addRemTb );
2772   createTool( 4061, addRemTb );
2773   createTool( 4062, addRemTb );
2774   createTool( 4063, addRemTb );
2775   createTool( 4064, addRemTb );
2776   createTool( 4065, addRemTb );
2777   createTool( separator(), addRemTb );
2778
2779   createTool( 406, modifyTb );
2780   createTool( 407, modifyTb );
2781   createTool( 408, modifyTb );
2782   createTool( 409, modifyTb );
2783   createTool( 410, modifyTb );
2784   createTool( 411, modifyTb );
2785   createTool( 412, modifyTb );
2786   createTool( 413, modifyTb );
2787   createTool( 416, modifyTb );
2788   createTool( 414, modifyTb );
2789   createTool( 415, modifyTb );
2790
2791   createTool( 214, dispModeTb );
2792
2793
2794   myRules.clear();
2795   QString OB = "'ObjectBrowser'",
2796           View = "'" + SVTK_Viewer::Type() + "'",
2797           pat = "'%1'",
2798           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2799           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2800           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2801           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2802           elems   = QString( "'%1' '%2' '%3' '%4' '%5'" ).
2803                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2804                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2805                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2806                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2807                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ),
2808           subMesh = elems,
2809           mesh_group = mesh + " " + subMesh + " " + group,
2810           hyp_alg = hypo + " " + algo;
2811
2812   // popup for object browser
2813
2814   createPopupItem( 705, OB, mesh, "&& isComputable");      // EDIT_GLOBAL_HYPO
2815   createPopupItem( 706, OB, subMesh, "&& isComputable" );  // EDIT_LOCAL_HYPO
2816   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2817   popupMgr()->insert( separator(), -1, 0 );
2818   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2819   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2820   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2821   createPopupItem( 902, OB, mesh );                        // STD_INFO
2822   popupMgr()->insert( separator(), -1, 0 );
2823   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2824   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2825   popupMgr()->insert( separator(), -1, 0 );
2826   createPopupItem( 1100, OB, hypo );                       // EDIT HYPOTHESIS
2827   createPopupItem( 1102, OB, hyp_alg, "&& hasReference" ); // REMOVE HYPOTHESIS / ALGORITHMS
2828   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2829   popupMgr()->insert( separator(), -1, 0 );
2830   createPopupItem( 125, OB, mesh );                        // EXPORT_MED
2831   createPopupItem( 126, OB, mesh );                        // EXPORT_UNV
2832   createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
2833   popupMgr()->insert( separator(), -1, 0 );
2834
2835   // popup for viewer
2836   createPopupItem( 803, View, group ); // EDIT_GROUP
2837   createPopupItem( 804, View, elems ); // ADD
2838   createPopupItem( 805, View, elems ); // REMOVE
2839   popupMgr()->insert( separator(), -1, 0 );
2840   createPopupItem( 214, View, mesh_group ); // UPDATE
2841   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2842   createPopupItem( 902, View, mesh );       // STD_INFO
2843   popupMgr()->insert( separator(), -1, 0 );
2844
2845   int anId;
2846   QString
2847     isInvisible("not( isVisible )"),
2848     isEmpty("numberOfNodes = 0"),
2849     isNotEmpty("numberOfNodes <> 0"),
2850
2851     // has nodes, edges, etc in VISIBLE! actor
2852     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2853     hasElems("(count( elemTypes ) > 0)"),
2854     hasDifferentElems("(count( elemTypes ) > 1)"),
2855     hasEdges("({'Edge'} in elemTypes)"),
2856     hasFaces("({'Face'} in elemTypes)"),
2857     hasVolumes("({'Volume'} in elemTypes)");
2858
2859   QString aSelCount = QString( "%1 = 1" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2860   QString lc = QtxPopupMgr::Selection::defEquality();
2861   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2862   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() ).arg( mesh_group );
2863   QString aMeshInVTK = aClient + "&&" + aType;// + "&&" + aSelCount;
2864   
2865   //-------------------------------------------------
2866   // Numbering
2867   //-------------------------------------------------
2868   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2869
2870   popupMgr()->insert( action( 9010 ), anId, -1 );
2871   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&&" + hasNodes, true );
2872   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2873
2874   popupMgr()->insert( action( 9011 ), anId, -1 );
2875   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&&" + hasElems, true );
2876   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2877
2878   popupMgr()->insert( separator(), -1, -1 );
2879
2880   //-------------------------------------------------
2881   // Display Mode
2882   //-------------------------------------------------
2883   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2884
2885   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2886   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2887   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2888
2889   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2890   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2891   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2892
2893   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2894   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2895   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2896
2897   popupMgr()->insert( separator(), anId, -1 );
2898
2899   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2900   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2901   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2902
2903   //-------------------------------------------------
2904   // Display Entity
2905   //-------------------------------------------------
2906   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2907
2908   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2909
2910   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2911   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&&" + hasEdges, true );
2912   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2913
2914   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2915   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&&" + hasFaces, true );
2916   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2917
2918   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2919   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&&" + hasVolumes, true );
2920   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2921
2922   popupMgr()->insert( separator(), anId, -1 );
2923
2924   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2925   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& not( elemTypes in entityMode )", true );
2926
2927   //-------------------------------------------------
2928   // Color / Size
2929   //-------------------------------------------------
2930   popupMgr()->insert( action( 1132 ), -1, -1 );
2931   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
2932
2933   //-------------------------------------------------
2934   // Transparency
2935   //-------------------------------------------------
2936   popupMgr()->insert( action( 1133 ), -1, -1 );
2937   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
2938
2939   //-------------------------------------------------
2940   // Clipping
2941   //-------------------------------------------------
2942   popupMgr()->insert( action( 1134 ), -1, -1 );
2943   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
2944
2945   popupMgr()->insert( separator(), -1, -1 );
2946
2947   //-------------------------------------------------
2948   // Controls
2949   //-------------------------------------------------
2950   QString
2951     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
2952     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
2953     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
2954
2955   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
2956
2957   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
2958   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2959
2960   popupMgr()->insert( separator(), anId, -1 );
2961
2962   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
2963   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
2964   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeEdges'", false );
2965
2966   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
2967   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
2968   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
2969
2970   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
2971   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
2972   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
2973
2974   popupMgr()->insert( separator(), anId, -1 );
2975
2976   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
2977   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
2978   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeBorders'", false );
2979
2980   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
2981   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
2982   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
2983
2984   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
2985   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
2986   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
2987
2988   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
2989   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
2990   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
2991
2992   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
2993   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
2994   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
2995
2996   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
2997   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
2998   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
2999
3000   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3001   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3002   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3003
3004   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3005   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3006   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3007
3008   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3009   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3010   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3011
3012   popupMgr()->insert( separator(), anId, -1 );
3013
3014   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3015   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3016   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3017
3018   popupMgr()->insert( separator(), anId, -1 );
3019
3020   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3021   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3022
3023   popupMgr()->insert( separator(), -1, -1 );
3024
3025   //-------------------------------------------------
3026   // Display / Erase
3027   //-------------------------------------------------
3028   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3029   QString aRule = aClient + " and " + aType + " and " + aSelCount;
3030   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3031   popupMgr()->setRule( action( 301 ), aRule + "&&" + isNotEmpty + "&&" + isInvisible, true);
3032
3033   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3034   popupMgr()->setRule( action( 300 ), aRule + "&&" + isNotEmpty + "&& isVisible", true );
3035
3036   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3037   popupMgr()->setRule( action( 302 ), aRule + "&&" + isNotEmpty, true );
3038
3039   popupMgr()->insert( separator(), -1, -1 );
3040
3041   connect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ), 
3042            this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
3043 }
3044
3045 bool SMESHGUI::activateModule( SUIT_Study* study )
3046 {
3047   bool res = SalomeApp_Module::activateModule( study );
3048
3049   setMenuShown( true );
3050   setToolShown( true );
3051   SetSettings( desktop() );
3052
3053   return res;
3054 }
3055
3056 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3057 {
3058   setMenuShown( false );
3059   setToolShown( false );
3060
3061   EmitSignalCloseAllDialogs();
3062   
3063   return SalomeApp_Module::deactivateModule( study );
3064 }
3065
3066 void SMESHGUI::OnGUIEvent()
3067 {
3068   const QObject* obj = sender();
3069   if ( !obj || !obj->inherits( "QAction" ) )
3070     return;
3071   int id = actionId((QAction*)obj);
3072   if ( id != -1 )
3073     OnGUIEvent( id );
3074 }
3075
3076 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3077 {
3078   return myComponentSMESH;
3079 }
3080
3081 QString SMESHGUI::engineIOR() const
3082 {
3083   CORBA::ORB_var anORB = getApp()->orb();
3084   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3085   return anIOR.in();
3086 }
3087
3088 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
3089 {
3090   SMESHGUI_Selection sel;
3091   sel.init( client, selectionMgr() );
3092   popupMgr()->updatePopup( menu, &sel );
3093 }
3094
3095 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3096 {
3097   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3098   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3099 }
3100
3101 void SMESHGUI::viewManagers( QStringList& list ) const
3102 {
3103   list.append( SVTK_Viewer::Type() );
3104 }
3105
3106 void SMESHGUI::onViewManagerAdded( SUIT_ViewManager* mgr )
3107 {
3108   if( dynamic_cast<VTKViewer_ViewManager*>( mgr ) )
3109     SMESH::UpdateSelectionProp( this );
3110 }