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