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