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