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