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