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