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