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