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