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