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