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