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