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