Salome HOME
PAL9785
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 //
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28
29 #include "SMESHGUI_InitMeshDlg.h"
30 #include "SMESHGUI_AddSubMeshDlg.h"
31 #include "SMESHGUI_NodesDlg.h"
32 #include "SMESHGUI_TransparencyDlg.h"
33 #include "SMESHGUI_ClippingDlg.h"
34 #include "SMESHGUI_GroupDlg.h"
35 #include "SMESHGUI_RemoveNodesDlg.h"
36 #include "SMESHGUI_RemoveElementsDlg.h"
37 #include "SMESHGUI_MeshInfosDlg.h"
38 #include "SMESHGUI_StandardMeshInfosDlg.h"
39 #include "SMESHGUI_Preferences_ColorDlg.h"
40 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
41 #include "SMESHGUI_Preferences_SelectionDlg.h"
42 #include "SMESHGUI_Hypotheses.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_EditMeshDlg.h"
64 #include "SMESHGUI_MeshPatternDlg.h"
65 #include "SMESHGUI_PrecisionDlg.h"
66 #include "SMESHGUI_Selection.h"
67 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
68
69 #include "SMESHGUI_Utils.h"
70 #include "SMESHGUI_GEOMGenUtils.h"
71 #include "SMESHGUI_MeshUtils.h"
72 #include "SMESHGUI_GroupUtils.h"
73 #include "SMESHGUI_FilterUtils.h"
74 #include "SMESHGUI_PatternUtils.h"
75 #include "SMESHGUI_VTKUtils.h"
76 #include "SMESHGUI_HypothesesUtils.h"
77
78 #include "SMESH_Actor.h"
79 #include "SMESH_Object.h"
80 #include "SMESH_TypeFilter.hxx"
81
82 #include "SalomeApp_Tools.h"
83 #include "SalomeApp_Study.h"
84 #include "SalomeApp_NameDlg.h"
85 #include "SalomeApp_DataOwner.h"
86 #include "SalomeApp_Application.h"
87 #include "SalomeApp_Preferences.h"
88 #include "SalomeApp_VTKSelector.h"
89 #include "SalomeApp_ImportOperation.h"
90
91 #include <SVTK_ViewWindow.h>
92 #include <SVTK_ViewModel.h>
93 #include <SVTK_InteractorStyle.h>
94 #include <SVTK_RenderWindowInteractor.h>
95
96 #include <VTKViewer_ViewManager.h>
97
98 #include "OB_Browser.h"
99
100 #include "SUIT_Tools.h"
101 #include "SUIT_MessageBox.h"
102 #include "SUIT_ResourceMgr.h"
103 #include "SUIT_FileDlg.h"
104 #include "SUIT_Desktop.h"
105 #include "SUIT_ResourceMgr.h"
106 #include "SUIT_OverrideCursor.h"
107 #include "SUIT_Study.h"
108 #include "SUIT_Session.h"
109
110 #include "QtxPopupMgr.h"
111
112 #include "SALOME_ListIO.hxx"
113 #include "SALOME_ListIteratorOfListIO.hxx"
114 #include "SALOME_InteractiveObject.hxx"
115 #include "SALOME_NamingService.hxx"
116 #include "SALOME_LifeCycleCORBA.hxx"
117
118 #include "SALOMEconfig.h"
119 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
120
121 // QT Includes
122 #define  INCLUDE_MENUITEM_DEF
123 #include <qpopupmenu.h>
124 #include <qstring.h>
125 #include <qwidget.h>
126 #include <qaction.h>
127
128 // BOOST Includes
129 #include <boost/shared_ptr.hpp>
130
131 // VTK Includes
132 #include <vtkRenderer.h>
133 #include <vtkRenderWindow.h>
134 #include <vtkActorCollection.h>
135 #include <vtkScalarBarActor.h>
136 #include <vtkUnstructuredGrid.h>
137
138 #include "utilities.h"
139
140 #include "SALOMEDS_Study.hxx"
141 #include "SALOMEDSClient_StudyBuilder.hxx"
142 #include "SALOMEDSClient_SComponent.hxx"
143
144 using namespace std;
145
146 namespace{
147   // Decalarations
148   //=============================================================
149   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
150                             int theCommandID);
151
152   void ExportMeshToFile(int theCommandID);
153
154   void SetDisplayMode(int theCommandID);
155
156   void SetDisplayEntity(int theCommandID);
157
158   void Control( int theCommandID );
159
160
161   // Definitions
162   //=============================================================
163   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
164                             int theCommandID)
165   {
166     QStringList filter;
167     string myExtension;
168   
169     if(theCommandID == 113){
170       filter.append(QObject::tr("MED files (*.med)"));
171       filter.append(QObject::tr("All files (*)"));
172     }else if (theCommandID == 112){
173       filter.append(QObject::tr("IDEAS files (*.unv)"));
174     }else if (theCommandID == 111){
175       filter.append(QObject::tr("DAT files (*.dat)"));
176     }
177     QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
178                                                 "",
179                                                 filter,
180                                                 QObject::tr("Import mesh"),
181                                                 true);
182     if(!filename.isEmpty()) {
183       SUIT_OverrideCursor wc;
184       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
185       theComponentMesh->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
186
187       try {
188         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
189         switch ( theCommandID ) {
190         case 112:
191           {
192             aMeshes->length( 1 );
193             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
194             break;
195           }
196         case 113:
197           {
198             SMESH::DriverMED_ReadStatus res;
199             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
200             if ( res != SMESH::DRS_OK ) {
201               wc.suspend();
202               SUIT_MessageBox::warn1(SMESHGUI::desktop(),
203                                     QObject::tr("SMESH_WRN_WARNING"),
204                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
205                                     QObject::tr("SMESH_BUT_OK"));
206               aMeshes->length( 0 );
207               wc.resume();
208             }
209             break;
210           }
211         }
212
213         bool isEmpty = false;
214         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
215           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
216           if ( aMeshSO ) {
217             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
218             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
219             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
220             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
221               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
222           } else
223             isEmpty = true;
224         }
225
226         if ( isEmpty ) {
227           wc.suspend();
228           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
229                                 QObject::tr("SMESH_WRN_WARNING"),
230                                 QObject::tr("SMESH_DRS_EMPTY"),
231                                 QObject::tr("SMESH_BUT_OK"));
232           wc.resume();
233         }
234
235         SMESHGUI::GetSMESHGUI()->updateObjBrowser();
236       }
237       catch (const SALOME::SALOME_Exception& S_ex){
238         wc.suspend();
239         SalomeApp_Tools::QtCatchCorbaException(S_ex);
240         wc.resume();
241       }
242     }
243   }
244
245
246   void ExportMeshToFile( int theCommandID )
247   {
248     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
249     SALOME_ListIO selected;
250     if( aSel )
251       aSel->selectedObjects( selected );
252
253     if(selected.Extent()){
254       Handle(SALOME_InteractiveObject) anIObject = selected.First();
255       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
256       if ( !aMesh->_is_nil() ) {
257         QString aFilter, aTitle = QObject::tr("Export mesh");
258         QMap<QString, SMESH::MED_VERSION> aFilterMap;
259         switch ( theCommandID ) {
260         case 125:
261         case 122:
262           aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
263           aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
264           break;
265         case 124:
266         case 121:
267           aFilter = QObject::tr("DAT files (*.dat)");
268           break;
269         case 126:
270         case 123: {
271           if(aMesh->NbPyramids()){
272             int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
273                                              QObject::tr("SMESH_WRN_WARNING"),
274                                              QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
275                                              QObject::tr("SMESH_BUT_YES"),
276                                              QObject::tr("SMESH_BUT_NO"),
277                                              0,1,0);
278             if(aRet)
279               return;
280           }
281           aFilter = QObject::tr("IDEAS files (*.unv)");
282           break;
283         default:
284           return;
285         }}
286
287         QString aFilename;
288         SMESH::MED_VERSION aFormat;
289
290         if ( theCommandID != 122 && theCommandID != 125 )
291           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
292         else
293           {
294             QStringList filters;
295             for ( QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin(); it != aFilterMap.end(); ++it )
296               filters.push_back( it.key() );
297             
298             SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
299             fd->setCaption( aTitle );
300             fd->setFilters( filters );
301             bool is_ok = false;
302             while(!is_ok){
303               fd->exec();
304               aFilename = fd->selectedFile();
305               aFormat = aFilterMap[fd->selectedFilter()];
306               is_ok = true;
307               if( !aFilename.isEmpty()
308                   && (aMesh->NbPolygons()>0 or aMesh->NbPolyhedrons()>0) 
309                   && aFormat==SMESH::MED_V2_1){
310                 int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
311                                                   QObject::tr("SMESH_WRN_WARNING"),
312                                                   QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
313                                                   QObject::tr("SMESH_BUT_YES"),
314                                                   QObject::tr("SMESH_BUT_NO"),
315                                                   0,1,0);
316                 if(aRet){
317                   is_ok = false;
318                 }
319               }
320             }
321             delete fd;
322           }
323         if ( !aFilename.isEmpty() ) {
324           // Check whether the file already exists and delete it if yes
325           QFile aFile( aFilename );
326           if ( aFile.exists() )
327             aFile.remove();
328           SUIT_OverrideCursor wc;
329           switch ( theCommandID ) {
330           case 125:
331           case 122:
332             aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created
333             break;
334           case 124:
335           case 121:
336             aMesh->ExportDAT( aFilename.latin1() );
337             break;
338           case 126:
339           case 123:
340             aMesh->ExportUNV( aFilename.latin1() );
341             break;
342           default:
343             break;
344           }
345         }
346       }
347     }
348   }
349
350   inline void InverseEntityMode(unsigned int& theOutputMode,
351                                 unsigned int theMode)
352   {
353     bool anIsNotPresent = ~theOutputMode & theMode;
354     if(anIsNotPresent)
355       theOutputMode |= theMode;
356     else
357       theOutputMode &= ~theMode;
358   }
359
360   void SetDisplayEntity(int theCommandID){
361     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
362     SALOME_ListIO selected;
363     if( aSel )
364       aSel->selectedObjects( selected );
365
366     if(selected.Extent() >= 1){
367       SALOME_ListIteratorOfListIO It( selected );
368       for(; It.More(); It.Next()){
369         Handle(SALOME_InteractiveObject) IObject = It.Value();
370         if(IObject->hasEntry()){
371           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
372             unsigned int aMode = anActor->GetEntityMode();
373             switch(theCommandID){
374             case 217:
375               InverseEntityMode(aMode,SMESH_Actor::eEdges);
376               break;
377             case 218:
378               InverseEntityMode(aMode,SMESH_Actor::eFaces);
379               break;
380             case 219:
381               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
382               break;
383             case 220:
384               aMode = SMESH_Actor::eAllEntity;
385               break;
386             }
387             if(aMode)
388               anActor->SetEntityMode(aMode);
389           }
390         }
391       }
392     }
393   }
394
395   void SetDisplayMode(int theCommandID){
396     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
397     SALOME_ListIO selected;
398     if( aSel )
399       aSel->selectedObjects( selected );
400
401     if(selected.Extent() >= 1){
402       switch(theCommandID){
403       case 1134:{
404         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
405         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
406         return;
407       }
408       case 1133:{
409         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
410         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
411         return;
412       }}
413       SALOME_ListIteratorOfListIO It( selected );
414       for(; It.More(); It.Next()){
415         Handle(SALOME_InteractiveObject) IObject = It.Value();
416         if(IObject->hasEntry()){
417           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
418             switch(theCommandID){
419             case 211:
420               anActor->SetRepresentation(SMESH_Actor::eEdge);
421               break;
422             case 212:
423               anActor->SetRepresentation(SMESH_Actor::eSurface);
424               break;
425             case 213:
426               if(anActor->IsShrunk())
427                 anActor->UnShrink();
428               else
429                 anActor->SetShrink();
430               break;
431             case 215:
432               anActor->SetRepresentation(SMESH_Actor::ePoint);
433               break;
434             case 1132:{
435               float color[3];
436               anActor->GetSufaceColor(color[0], color[1], color[2]);
437               int c0 = int (color[0] * 255);
438               int c1 = int (color[1] * 255);
439               int c2 = int (color[2] * 255);
440               QColor c(c0, c1, c2);
441
442               float edgecolor[3];
443               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
444               c0 = int (edgecolor[0] * 255);
445               c1 = int (edgecolor[1] * 255);
446               c2 = int (edgecolor[2] * 255);
447               QColor e(c0, c1, c2);
448
449               float backfacecolor[3];
450               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
451               c0 = int (backfacecolor[0] * 255);
452               c1 = int (backfacecolor[1] * 255);
453               c2 = int (backfacecolor[2] * 255);
454               QColor b(c0, c1, c2);
455
456               float nodecolor[3];
457               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
458               c0 = int (nodecolor[0] * 255);
459               c1 = int (nodecolor[1] * 255);
460               c2 = int (nodecolor[2] * 255);
461               QColor n(c0, c1, c2);
462
463               int Edgewidth = (int)anActor->GetLineWidth();
464               if(Edgewidth == 0)
465                 Edgewidth = 1;
466               int intValue = int(anActor->GetNodeSize());
467               float Shrink = anActor->GetShrinkFactor();
468
469               SMESHGUI_Preferences_ColorDlg *aDlg =
470                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
471               aDlg->SetColor(1, c);
472               aDlg->SetColor(2, e);
473               aDlg->SetColor(3, n);
474               aDlg->SetColor(4, b);
475               aDlg->SetIntValue(1, Edgewidth);
476               aDlg->SetIntValue(2, intValue);
477               aDlg->SetIntValue(3, int(Shrink*100.));
478               if(aDlg->exec()){
479                 QColor color = aDlg->GetColor(1);
480                 QColor edgecolor = aDlg->GetColor(2);
481                 QColor nodecolor = aDlg->GetColor(3);
482                 QColor backfacecolor = aDlg->GetColor(4);
483                 /* actor color and backface color */
484                 anActor->SetSufaceColor(float (color.red()) / 255.,
485                                          float (color.green()) / 255.,
486                                          float (color.blue()) / 255.);
487                 anActor->SetBackSufaceColor(float (backfacecolor.red()) / 255.,
488                                              float (backfacecolor.green()) / 255.,
489                                              float (backfacecolor.blue()) / 255.);
490
491                 /* edge color */
492                 anActor->SetEdgeColor(float (edgecolor.red()) / 255.,
493                                        float (edgecolor.green()) / 255.,
494                                        float (edgecolor.blue()) / 255.);
495
496                 /* Shrink factor and size edges */
497                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
498                 anActor->SetLineWidth(aDlg->GetIntValue(1));
499
500                 /* Nodes color and size */
501                 anActor->SetNodeColor(float (nodecolor.red()) / 255.,
502                                float (nodecolor.green()) / 255.,
503                                        float (nodecolor.blue()) / 255.);
504                 anActor->SetNodeSize(aDlg->GetIntValue(2));
505
506                 delete aDlg;
507               }
508               break;
509             }}
510           }
511         }
512       }
513       SMESH::RepaintCurrentView();
514     }
515   }
516   
517   void Control( int theCommandID )
518   {
519     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
520     SALOME_ListIO selected;
521     if( aSel )
522       aSel->selectedObjects( selected );
523
524     if( !selected.IsEmpty() ){
525       Handle(SALOME_InteractiveObject) anIO = selected.First();
526       if(!anIO.IsNull()){
527         QString aTitle;
528         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
529         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
530           switch ( theCommandID ){
531           case 6001:
532             aTitle = QObject::tr( "LENGTH_EDGES" );
533             aControl = SMESH_Actor::eLength;
534             break;
535           case 6018:
536             aTitle = QObject::tr( "LENGTH2D_EDGES" );
537             aControl = SMESH_Actor::eLength2D;
538             break;
539           case 6002:
540             aTitle = QObject::tr( "FREE_EDGES" );
541             aControl = SMESH_Actor::eFreeEdges;
542             break;
543           case 6003:
544             aTitle = QObject::tr( "FREE_BORDERS" );
545             aControl = SMESH_Actor::eFreeBorders;
546             break;
547           case 6004:
548             aTitle = QObject::tr( "MULTI_BORDERS" );
549             aControl = SMESH_Actor::eMultiConnection;
550             break;
551           case 6019:
552             aTitle = QObject::tr( "MULTI2D_BORDERS" );
553             aControl = SMESH_Actor::eMultiConnection2D;
554             break;
555           case 6011:
556             aTitle = QObject::tr( "AREA_ELEMENTS" );
557             aControl = SMESH_Actor::eArea;
558             break;
559           case 6012:
560             aTitle = QObject::tr( "TAPER_ELEMENTS" );
561             aControl = SMESH_Actor::eTaper;
562             break;
563           case 6013:
564             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
565             aControl = SMESH_Actor::eAspectRatio;
566             break;
567           case 6017:
568             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
569             aControl = SMESH_Actor::eAspectRatio3D;
570             break;
571           case 6014:
572             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
573             aControl = SMESH_Actor::eMinimumAngle;
574             break;
575           case 6015:
576             aTitle = QObject::tr( "WARP_ELEMENTS" );
577             aControl = SMESH_Actor::eWarping;
578             break;
579           case 6016:
580             aTitle = QObject::tr( "SKEW_ELEMENTS" );
581             aControl = SMESH_Actor::eSkew;
582             break;
583           }
584           anActor->SetControlMode(aControl);
585           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
586         }
587       }
588     }
589   }
590
591
592   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
593                    MeshObjectType                           theType,
594                    const QString                            theInTypeName,
595                    QString &                                theOutTypeName)
596   {
597     SMESH_TypeFilter aTypeFilter( theType );
598     QString entry;
599     if( !theIO.IsNull() )
600     {
601       entry = theIO->getEntry();
602       SalomeApp_DataOwner owner( entry );
603       if ( aTypeFilter.isOk( &owner )) {
604         theOutTypeName = theInTypeName;
605         return true;
606       }
607     }
608     return false;
609   }
610
611
612   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
613   {
614     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
615     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
616     if (aSObj) {
617       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
618       CORBA::String_var anID = aSComp->GetID().c_str();
619       if (!strcmp(anID.in(),theIO->getEntry()))
620         return "Component";
621     }
622
623     QString aTypeName;
624     if (
625         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
626         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
627         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
628         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
629         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
630         )
631       return aTypeName;
632
633     return "NoType";
634   }
635
636
637   QString CheckHomogeneousSelection()
638   {
639     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
640     SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
641     SALOME_ListIO selected;
642     if( aSel )
643       aSel->selectedObjects( selected );
644
645     QString RefType = CheckTypeObject(selected.First());
646     SALOME_ListIteratorOfListIO It(selected);
647     for (; It.More(); It.Next())
648       {
649         Handle(SALOME_InteractiveObject) IObject = It.Value();
650         QString Type = CheckTypeObject(IObject);
651         if (Type.compare(RefType) != 0)
652           return "Heterogeneous Selection";
653       }
654
655     return RefType;
656   }
657
658
659   void SMESHGUI::OnEditDelete()
660   {
661     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
662     SalomeApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
663     SALOME_ListIO selected; aSel->selectedObjects( selected );
664
665     QString aParentComponent = QString::null;
666     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
667     {
668       QString cur = anIt.Value()->getComponentDataType();
669       if( aParentComponent.isNull() )
670         aParentComponent = cur;
671       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
672         aParentComponent = "";
673     }
674
675     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
676       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
677                               QObject::tr("ERR_ERROR"),
678                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
679                               QObject::tr("BUT_OK") );
680       return;
681     }
682     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
683     if (SUIT_MessageBox::warn2
684         (SMESHGUI::desktop(),
685          QObject::tr("SMESH_WRN_WARNING"),
686          QObject::tr("SMESH_REALLY_DELETE"),
687          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
688       return;
689
690     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
691     SUIT_ViewManager* vm = anApp->activeViewManager();
692     int nbSf = vm->getViewsCount();
693
694     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
695     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
696     _PTR(GenericAttribute) anAttr;
697     _PTR(AttributeIOR) anIOR;
698
699     SALOME_ListIteratorOfListIO It(selected);
700
701     aStudyBuilder->NewCommand();  // There is a transaction
702     for(; It.More(); It.Next()){
703       Handle(SALOME_InteractiveObject) IObject = It.Value();
704       if(IObject->hasEntry()){
705         _PTR(SObject) SO = aStudy->FindObjectID(IObject->getEntry());
706
707         // disable removal of "SMESH" component object
708         if(SO->FindAttribute(anAttr, "AttributeIOR")){
709           anIOR = anAttr;
710           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
711             continue;
712         }
713
714         /* Erase child graphical objects */
715         _PTR(ChildIterator) it = aStudy->NewChildIterator(SO);
716         for(it->InitEx(true); it->More(); it->Next()){
717           _PTR(SObject) CSO = it->Value();
718           if(CSO->FindAttribute(anAttr, "AttributeIOR")){
719             anIOR = anAttr;
720
721             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
722             for(int i = 0; i < nbSf; i++){
723               SUIT_ViewWindow *sf = aViews[i];
724               CORBA::String_var anEntry = CSO->GetID().c_str();
725               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
726                 SMESH::RemoveActor(sf,anActor);
727               }
728             }
729           }
730         }
731
732         /* Erase main graphical object */
733         QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
734         for(int i = 0; i < nbSf; i++){
735           SUIT_ViewWindow *sf = aViews[i];
736           if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
737             SMESH::RemoveActor(sf,anActor);
738           }
739         }
740
741         // Remove object(s) from data structures
742         _PTR(SObject) obj = aStudy->FindObjectID(IObject->getEntry());
743         if(obj){
744           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( obj ) );
745           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( obj ) );
746           QString objType = CheckTypeObject(IObject);
747           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
748             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
749             aMesh->RemoveGroup( aGroup );
750           }
751           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
752             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
753             aMesh->RemoveSubMesh( aSubMesh );
754           }
755           else if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
756             SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
757             aStudyBuilder->RemoveObjectWithChildren( obj );
758           }
759           else {// default action: remove SObject from the study
760             // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
761             //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
762             //op->start();
763             aStudyBuilder->RemoveObjectWithChildren( obj );
764             //op->finish();
765           }
766         }
767
768       } /* IObject->hasEntry() */
769     } /* more/next */
770     aStudyBuilder->CommitCommand();
771
772     /* Clear any previous selection */
773     SALOME_ListIO l1;
774     aSel->setSelectedObjects( l1 );
775
776     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
777   }
778 }
779
780 extern "C" {
781   Standard_EXPORT CAM_Module* createModule()
782   {
783     return new SMESHGUI();
784   }
785 }
786
787 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
788
789 //=============================================================================
790 /*!
791  *
792  */
793 //=============================================================================
794 SMESHGUI::SMESHGUI() :
795 SalomeApp_Module( "SMESH" )
796 {
797   if ( CORBA::is_nil( myComponentSMESH ) )
798   {
799     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
800     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "SMESH" );
801     myComponentSMESH = SMESH::SMESH_Gen::_narrow( comp );
802   }
803
804   myActiveDialogBox = 0 ;
805   myState = -1 ;
806
807   SMESH::GetFilterManager();
808   SMESH::GetPattern();
809   
810   /* load resources for all available meshers */
811   SMESH::InitAvailableHypotheses();
812 }
813
814 //=============================================================================
815 /*!
816  *
817  */
818 //=============================================================================
819 SMESHGUI::~SMESHGUI()
820 {
821   SMESH::GetFilterManager()->Destroy();
822 }
823
824 //=============================================================================
825 /*!
826  *
827  */
828 //=============================================================================
829 SalomeApp_SelectionMgr* SMESHGUI::selectionMgr()
830 {
831   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
832   if( anApp )
833     return dynamic_cast<SalomeApp_SelectionMgr*>( anApp->selectionMgr() );
834   else
835     return 0;
836 }
837
838 bool SMESHGUI::automaticUpdate()
839 {
840   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
841   if ( !resMgr )
842     return false;
843
844   return resMgr->booleanValue( "SMESH", "auto_update", false );
845 }
846
847 //=============================================================================
848 /*!
849  *
850  */
851 //=============================================================================
852 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
853 {
854   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
855 }
856
857 //=============================================================================
858 /*!
859  *
860  */
861 //=============================================================================
862 SMESHGUI* SMESHGUI::GetSMESHGUI()
863 {
864   SMESHGUI* smeshMod = 0;
865   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
866   if ( app )
867   {
868     CAM_Module* module = app->module( "Mesh" );
869     smeshMod = dynamic_cast<SMESHGUI*>( module );
870   }
871
872   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
873   {
874     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
875     if ( study )
876     {
877       _PTR(Study) aStudy = study->studyDS();
878       if ( aStudy )
879         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
880     }
881   }
882
883   return smeshMod;
884 }
885
886 extern "C"
887 {
888   Standard_EXPORT SMESHGUI* GetComponentGUI()
889   {
890     return SMESHGUI::GetSMESHGUI();
891   }
892 }
893
894 //=============================================================================
895 /*!
896  *
897  */
898 //=============================================================================
899 void SMESHGUI::SetState(int aState)
900 {
901   myState = aState;
902 }
903
904 //=============================================================================
905 /*!
906  *
907  */
908 //=============================================================================
909 void SMESHGUI::ResetState()
910 {
911   myState = -1;
912 }
913
914 //=============================================================================
915 /*!
916  *
917  */
918 //=============================================================================
919 void SMESHGUI::EmitSignalDeactivateDialog()
920 {
921   emit SignalDeactivateActiveDialog();
922 }
923
924 //=============================================================================
925 /*!
926  *
927  */
928 //=============================================================================
929 void SMESHGUI::EmitSignalStudyFrameChanged()
930 {
931   emit SignalStudyFrameChanged();
932 }
933
934 //=============================================================================
935 /*!
936  *
937  */
938 //=============================================================================
939 void SMESHGUI::EmitSignalCloseAllDialogs()
940 {
941   emit SignalCloseAllDialogs();
942 }
943
944 //=============================================================================
945 /*!
946  *
947  */
948 //=============================================================================
949 QDialog *SMESHGUI::GetActiveDialogBox()
950 {
951   return myActiveDialogBox;
952 }
953
954 //=============================================================================
955 /*!
956  *
957  */
958 //=============================================================================
959 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
960 {
961   myActiveDialogBox = (QDialog *) aDlg;
962   return;
963 }
964
965 //=============================================================================
966 /*!
967  *
968  */
969 //=============================================================================
970 SUIT_Desktop* SMESHGUI::desktop()
971 {
972   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
973   if( app )
974     return app->desktop();
975   else
976     return 0;
977 }
978
979 //=============================================================================
980 /*!
981  *
982  */
983 //=============================================================================
984 SalomeApp_Study* SMESHGUI::activeStudy()
985 {
986   SUIT_Application* app = SUIT_Session::session()->activeApplication();
987   if( app )
988     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
989   else
990     return NULL;
991 }
992
993 //=============================================================================
994 /*!
995  *
996  */
997 //=============================================================================
998 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
999 {
1000   /* Here the position is on the bottom right corner - 10 */
1001   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1002   aDlg->adjustSize();
1003   SUIT_Desktop *PP = desktop();
1004   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1005   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1006   return true;
1007 }
1008
1009 //=============================================================================
1010 /*!
1011  *
1012  */
1013 //=============================================================================
1014 static int isStudyLocked(_PTR(Study) theStudy){
1015   return theStudy->GetProperties()->IsLocked();
1016 }
1017
1018 static bool checkLock(_PTR(Study) theStudy) {
1019   if (isStudyLocked(theStudy)) {
1020     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1021                            QObject::tr("WRN_WARNING"),
1022                            QObject::tr("WRN_STUDY_LOCKED"),
1023                            QObject::tr("BUT_OK") );
1024     return true;
1025   }
1026   return false;
1027 }
1028
1029 //=======================================================================
1030 //function : CheckActiveStudyLocked
1031 //purpose  :
1032 //=======================================================================
1033
1034 bool SMESHGUI::isActiveStudyLocked()
1035 {
1036   _PTR(Study) aStudy = activeStudy()->studyDS();
1037   return checkLock( aStudy );
1038 }
1039
1040 //=============================================================================
1041 /*!
1042  *
1043  */
1044 //=============================================================================
1045 bool SMESHGUI::OnGUIEvent( int theCommandID )
1046 {
1047   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1048   if( !anApp )
1049     return false;
1050
1051   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1052   SUIT_ResourceMgr* mgr = resourceMgr();
1053   if( !mgr )
1054     return false;
1055
1056   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1057   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1058
1059   //QAction* act = action( theCommandID );
1060
1061   switch (theCommandID) {
1062   case 33:                                      // DELETE
1063     if(checkLock(aStudy)) break;
1064     OnEditDelete();
1065     break;
1066
1067   case 113:                                     // IMPORT
1068   case 112:
1069   case 111:
1070     {
1071       if(checkLock(aStudy)) break;
1072       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1073       break;
1074     }
1075
1076   case 122:                                     // EXPORT MED
1077   case 121:
1078   case 123:
1079   case 124:
1080   case 125:
1081   case 126:
1082     {
1083       ::ExportMeshToFile(theCommandID);
1084       break;
1085     }
1086
1087   case 200:                                     // SCALAR BAR
1088     {
1089       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1090       SALOME_ListIO selected;
1091       if( aSel )
1092         aSel->selectedObjects( selected );
1093
1094       if( selected.Extent() ) {
1095         Handle(SALOME_InteractiveObject) anIO = selected.First();
1096         if( anIO->hasEntry() ) {
1097           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1098             anActor->SetControlMode( SMESH_Actor::eNone );
1099           }
1100         }
1101       }
1102       break;
1103     }
1104   case 201:
1105     {
1106       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1107       break;
1108     }
1109
1110   case 1134: // Clipping
1111   case 1133: // Tranparency
1112   case 1132: // Colors / Size
1113
1114     // Display Mode
1115   case 215: // Nodes
1116   case 213: // Nodes
1117   case 212: // Nodes
1118   case 211: // Nodes
1119     ::SetDisplayMode(theCommandID);
1120   break;
1121
1122     // Display Entity
1123   case 217: // Edges
1124   case 218: // Faces
1125   case 219: // Volumes
1126   case 220: // All Entity
1127     ::SetDisplayEntity(theCommandID);
1128   break;
1129
1130   case 214:                                     // UPDATE
1131     {
1132       if(checkLock(aStudy)) break;
1133       SMESH::UpdateView();
1134
1135       SALOME_ListIO l;
1136       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1137       aSel->setSelectedObjects( l );
1138       break;
1139     }
1140
1141   case 300:                                     // ERASE
1142   case 301:                                     // DISPLAY
1143   case 302:                                     // DISPLAY ONLY
1144     {
1145       SMESH::EDisplaing anAction;
1146       switch (theCommandID) {
1147       case 300: anAction = SMESH::eErase; break;
1148       case 301: anAction = SMESH::eDisplay; break;
1149       case 302: anAction = SMESH::eDisplayOnly; break;
1150       }
1151
1152       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1153       SALOME_ListIO selected;
1154       if (aSel)
1155         aSel->selectedObjects( selected );
1156
1157       if (vtkwnd) {
1158         SALOME_ListIteratorOfListIO It (selected);
1159         for (; It.More(); It.Next()) {
1160           Handle(SALOME_InteractiveObject) IOS = It.Value();
1161           if (IOS->hasEntry()) {
1162             SMESH::UpdateView(anAction, IOS->getEntry());
1163             if (anAction == SMESH::eDisplayOnly)
1164               anAction = SMESH::eDisplay;
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   case 4066: // MERGE EQUAL ELEMENTS
2010     {
2011       if (checkLock(aStudy)) break;
2012       if (vtkwnd) {
2013         EmitSignalDeactivateDialog();
2014         new SMESHGUI_EditMeshDlg(this,
2015                                  "SMESH_MERGE_ELEMENTS_TITLE",
2016                                  "ICON_DLG_MERGE_ELEMENTS",
2017                                  1); // MergeEqualElemets
2018       } else {
2019         SUIT_MessageBox::warn1(desktop(),
2020                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2021                               tr("SMESH_BUT_OK"));
2022       }
2023       break;
2024     }
2025     
2026
2027   case 5000: // HYPOTHESIS
2028     {
2029       if(checkLock(aStudy)) break;
2030       EmitSignalDeactivateDialog();
2031       new SMESHGUI_CreateHypothesesDlg ( this, "", FALSE, false );
2032       break;
2033     }
2034   case 5010: // ALGO
2035     {
2036       if(checkLock(aStudy)) break;
2037       EmitSignalDeactivateDialog();
2038       new SMESHGUI_CreateHypothesesDlg ( this, "", FALSE, true);
2039       break;
2040     }
2041
2042   case 5105: // Library of selection filters
2043   {
2044     static QValueList<int> aTypes;
2045     if ( aTypes.isEmpty() )
2046     {
2047       aTypes.append( SMESH::NODE );
2048       aTypes.append( SMESH::EDGE );
2049       aTypes.append( SMESH::FACE );
2050       aTypes.append( SMESH::VOLUME );
2051     }
2052     new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2053   }
2054   break;
2055
2056   case 6017:                                    // CONTROLS
2057   case 6016:
2058   case 6015:
2059   case 6014:
2060   case 6013:
2061   case 6012:
2062   case 6011:
2063   case 6001:
2064   case 6018:
2065   case 6019:
2066   case 6002:
2067   case 6003:
2068   case 6004:
2069     if ( vtkwnd ) {
2070
2071       SalomeApp_SelectionMgr* mgr = selectionMgr();
2072       SALOME_ListIO selected; mgr->selectedObjects( selected );
2073
2074       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2075         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2076         if ( SO ) {
2077           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2078           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2079           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2080           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2081           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2082             ::Control( theCommandID );
2083             break;
2084           }
2085         }
2086       }
2087       SUIT_MessageBox::warn1(desktop(),
2088                             tr( "SMESH_WRN_WARNING" ),
2089                             tr( "SMESH_BAD_SELECTION" ),
2090                             tr( "SMESH_BUT_OK" ) );
2091       break;
2092     }
2093     else {
2094       SUIT_MessageBox::warn1(desktop(),
2095                             tr( "SMESH_WRN_WARNING" ),
2096                             tr( "NOT_A_VTK_VIEWER" ), 
2097                             tr( "SMESH_BUT_OK" ) );
2098     }
2099     break;
2100   case 9010:
2101     {
2102       SalomeApp_SelectionMgr* mgr = selectionMgr();
2103       SALOME_ListIO selected; mgr->selectedObjects( selected );
2104
2105       if (selected.Extent() == 1)       {
2106         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2107         if(anIObject->hasEntry())
2108           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2109             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2110           }
2111       }
2112       break;
2113     }
2114   case 9011:
2115     {
2116       SalomeApp_SelectionMgr* mgr = selectionMgr();
2117       SALOME_ListIO selected; mgr->selectedObjects( selected );
2118
2119       if (selected.Extent() == 1)       {
2120         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2121         if(anIObject->hasEntry())
2122           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2123             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2124           }
2125       }
2126       break;
2127     }
2128   }
2129   //updateObjBrowser();
2130   return true;
2131 }
2132
2133 //=============================================================================
2134 /*!
2135  *
2136  */
2137 //=============================================================================
2138 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2139 {
2140   return false;
2141 }
2142
2143 //=============================================================================
2144 /*!
2145  *
2146  */
2147 //=============================================================================
2148 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2149 {
2150   return true;
2151 }
2152
2153 //=============================================================================
2154 /*!
2155  *
2156  */
2157 //=============================================================================
2158 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2159 {
2160   return true;
2161 }
2162
2163 //=============================================================================
2164 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2165  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2166  */
2167 //=============================================================================
2168 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2169                                   SUIT_ViewWindow* wnd )
2170 {
2171   if(theIO->hasEntry()){
2172     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2173     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2174   }
2175 }
2176
2177 //=======================================================================
2178 // function : createSMESHAction
2179 // purpose  :
2180 //=======================================================================
2181 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2182 {
2183   QIconSet icon;
2184   QWidget* parent = application()->desktop();
2185   SUIT_ResourceMgr* resMgr = resourceMgr();
2186   QPixmap pix;
2187   if ( icon_id.length() )
2188     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2189   else
2190     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2191   if ( !pix.isNull() )
2192     icon = QIconSet( pix );
2193
2194   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2195           menu       = tr( QString( "MEN_" )+po_id ),
2196           status_bar = tr( QString( "STB_" )+po_id );
2197
2198   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2199 }
2200
2201 //=======================================================================
2202 // function : createPopupItem
2203 // purpose  :
2204 //=======================================================================
2205 void SMESHGUI::createPopupItem( const int id,
2206                                 const QString& clients,
2207                                 const QString& types,
2208                                 const QString& theRule,
2209                                 const int pId )
2210 {
2211   int parentId = pId;
2212   if( pId!=-1 )
2213     parentId = popupMgr()->actionId( action( pId ) );
2214
2215   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2216     popupMgr()->insert( action( id ), parentId, 0 );
2217
2218   QChar lc = QtxPopupMgr::Selection::defEquality();
2219   QString rule = "(%1) and (%2) and (%3)";
2220   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2221   rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2222   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2223   rule += theRule;
2224
2225   bool cont = myRules.contains( id );
2226   if( cont )
2227     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2228
2229   popupMgr()->setRule( action( id ), rule, true );
2230   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2231 }
2232
2233 //=======================================================================
2234 // function : initialize
2235 // purpose  :
2236 //=======================================================================
2237 void SMESHGUI::initialize( CAM_Application* app )
2238 {
2239   SalomeApp_Module::initialize( app );
2240
2241 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2242 //   if ( mgr )
2243   /* Automatic Update flag */
2244 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2245
2246   // ----- create actions --------------
2247
2248   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2249   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2250   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2251   createSMESHAction(  114, "NUM" );
2252   createSMESHAction(  121, "DAT" );
2253   createSMESHAction(  122, "MED" );
2254   createSMESHAction(  123, "UNV" );
2255   createSMESHAction(  124, "EXPORT_DAT" );
2256   createSMESHAction(  125, "EXPORT_MED" );
2257   createSMESHAction(  126, "EXPORT_UNV" );
2258   createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
2259   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2260   createSMESHAction( 5000, "CREATE_HYPO",     "ICON_HYPO" );
2261   createSMESHAction( 5010, "CREATE_ALG",      "ICON_PATTERN_2d" );
2262   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2263   createSMESHAction(  702, "LOCAL_HYPO",      "ICON_DLG_ADD_SUBMESH" );
2264   createSMESHAction(  703, "GLOBAL_HYPO",     "ICON_DLG_INIT_MESH" );
2265   createSMESHAction(  704, "EDIT_HYPO",       "ICON_DLG_EDIT_MESH" );
2266   createSMESHAction(  705, "EDIT_GLOBAL_HYPO","ICON_DLG_EDIT_MESH" );
2267   createSMESHAction(  706, "EDIT_LOCAL_HYPO", "ICON_DLG_EDIT_MESH" );
2268   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2269   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2270   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2271   createSMESHAction(  804, "ADD" );
2272   createSMESHAction(  805, "REMOVE" );
2273   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2274   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2275   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2276   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2277   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2278   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2279   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2280   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2281   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2282   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2283   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2284   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2285   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2286   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2287   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2288   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2289   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2290   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2291   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2292   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2293   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2294   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2295   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2296   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2297   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2298   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2299   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2300   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2301   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2302   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2303   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2304   createSMESHAction( 4062, "ROT",             "ICON_DLG_ROTATION" );
2305   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2306   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2307   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2308   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2309   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2310   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2311   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2312   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2313   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2314   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2315   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2316   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2317   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2318   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2319   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2320   createSMESHAction(  200, "RESET" );
2321   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2322   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2323   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2324   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2325   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2326   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2327   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2328   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2329   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2330   createSMESHAction(  220, "ALL" );
2331   createSMESHAction( 1100, "EDIT_HYPO" );
2332   createSMESHAction( 1101, "RENAME" );
2333   createSMESHAction( 1102, "UNASSIGN" );
2334   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2335   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2336   createSMESHAction( 1131, "DISPMODE" );
2337   createSMESHAction( 1132, "COLORS" );
2338   createSMESHAction( 1133, "TRANSP" );
2339   createSMESHAction( 1134, "CLIP" );
2340   createSMESHAction( 1135, "DISP_ENT" );
2341   createSMESHAction( 2000, "CTRL" );
2342   
2343   createSMESHAction( 300, "ERASE" );
2344   createSMESHAction( 301, "DISPLAY" );
2345   createSMESHAction( 302, "DISPLAY_ONLY" );
2346   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2347
2348   // ----- create menu --------------
2349   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2350       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2351       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2352       hypoId   = createMenu( tr( "MEN_HYPO" ),   -1, 50, 10 ),
2353       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2354       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2355       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2356       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2357
2358   createMenu( separator(), fileId );
2359
2360   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2361       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2362       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2363       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2364       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2365       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2366
2367   createMenu( 111, importId, -1 );
2368   createMenu( 112, importId, -1 );
2369   createMenu( 113, importId, -1 );
2370
2371   createMenu( 121, exportId, -1 );
2372   createMenu( 122, exportId, -1 );
2373   createMenu( 123, exportId, -1 );
2374
2375   createMenu( separator(), fileId, 10 );
2376
2377   createMenu( 33, editId, -1 );
2378
2379   createMenu( 5105, toolsId, -1 );
2380
2381   createMenu( 5000, hypoId, -1 );
2382   createMenu( 5010, hypoId, -1 );
2383
2384   createMenu( 703, meshId, -1 );
2385   createMenu( 702, meshId, -1 );
2386   createMenu( 704, meshId, -1 );
2387   createMenu( separator(), meshId, -1 );
2388   createMenu( 701, meshId, -1 );
2389   createMenu( separator(), meshId, -1 );
2390   createMenu( 801, meshId, -1 );
2391   createMenu( 802, meshId, -1 );
2392   createMenu( 803, meshId, -1 );
2393   createMenu( separator(), meshId, -1 );
2394   createMenu( 810, meshId, -1 );
2395   createMenu( 811, meshId, -1 );
2396   createMenu( 812, meshId, -1 );
2397   createMenu( separator(), meshId, -1 );
2398   createMenu( 813, meshId, -1 );
2399   createMenu( separator(), meshId, -1 );
2400   createMenu( 900, meshId, -1 );
2401   createMenu( 902, meshId, -1 );
2402   createMenu( separator(), meshId, -1 );
2403
2404   createMenu( 6003, ctrlId, -1 );
2405   createMenu( 6001, ctrlId, -1 );
2406   createMenu( 6004, ctrlId, -1 );
2407   createMenu( separator(), ctrlId, -1 );
2408   createMenu( 6002, ctrlId, -1 );
2409   createMenu( 6018, ctrlId, -1 );
2410   createMenu( 6019, ctrlId, -1 );
2411   createMenu( 6011, ctrlId, -1 );
2412   createMenu( 6012, ctrlId, -1 );
2413   createMenu( 6013, ctrlId, -1 );
2414   createMenu( 6014, ctrlId, -1 );
2415   createMenu( 6015, ctrlId, -1 );
2416   createMenu( 6016, ctrlId, -1 );
2417   createMenu( separator(), ctrlId, -1 );
2418   createMenu( 6017, ctrlId, -1 );
2419   createMenu( separator(), ctrlId, -1 );
2420
2421   createMenu( 400, addId, -1 );
2422   createMenu( 401, addId, -1 );
2423   createMenu( 4021, addId, -1 );
2424   createMenu( 4022, addId, -1 );
2425   createMenu( 4023, addId, -1 );
2426   createMenu( 4031, addId, -1 );
2427   createMenu( 4032, addId, -1 );
2428   createMenu( 4033, addId, -1 );
2429
2430   createMenu( 4041, removeId, -1 );
2431   createMenu( 4042, removeId, -1 );
2432
2433   createMenu( 4051, renumId, -1 );
2434   createMenu( 4052, renumId, -1 );
2435
2436   createMenu( 4061, transfId, -1 );
2437   createMenu( 4062, transfId, -1 );
2438   createMenu( 4063, transfId, -1 );
2439   createMenu( 4064, transfId, -1 );
2440   createMenu( 4065, transfId, -1 );
2441   createMenu( 4066, transfId, -1 );
2442
2443   createMenu( 406, modifyId, -1 );
2444   createMenu( 407, modifyId, -1 );
2445   createMenu( 408, modifyId, -1 );
2446   createMenu( 409, modifyId, -1 );
2447   createMenu( 410, modifyId, -1 );
2448   createMenu( 411, modifyId, -1 );
2449   createMenu( 412, modifyId, -1 );
2450   createMenu( 413, modifyId, -1 );
2451   createMenu( 416, modifyId, -1 );
2452   createMenu( 414, modifyId, -1 );
2453   createMenu( 415, modifyId, -1 );
2454
2455   createMenu( 214, viewId, -1 );
2456
2457   // ----- create toolbars --------------
2458   int meshTb     = createTool( tr( "TB_MESH" ) ),
2459       hypoTb     = createTool( tr( "TB_HYPO" ) ),
2460       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2461       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2462       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2463       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2464
2465   createTool( 703, meshTb );
2466   createTool( 702, meshTb );
2467   createTool( 704, meshTb );
2468   createTool( separator(), meshTb );
2469   createTool( 701, meshTb );
2470   createTool( separator(), meshTb );
2471   createTool( 801, meshTb );
2472   createTool( 802, meshTb );
2473   createTool( 803, meshTb );
2474   createTool( separator(), meshTb );
2475   createTool( 900, meshTb );
2476   createTool( 902, meshTb );
2477   createTool( separator(), meshTb );
2478
2479   createTool( 5000, hypoTb );
2480   createTool( 5010, hypoTb );
2481
2482   createTool( 6001, ctrlTb );
2483   createTool( 6003, ctrlTb );
2484   createTool( 6004, ctrlTb );
2485   createTool( separator(), ctrlTb );
2486   createTool( 6002, ctrlTb );
2487   createTool( 6018, ctrlTb );
2488   createTool( 6019, ctrlTb );
2489   createTool( 6011, ctrlTb );
2490   createTool( 6012, ctrlTb );
2491   createTool( 6013, ctrlTb );
2492   createTool( 6014, ctrlTb );
2493   createTool( 6015, ctrlTb );
2494   createTool( 6016, ctrlTb );
2495   createTool( separator(), ctrlTb );
2496   createTool( 6017, ctrlTb );
2497   createTool( separator(), ctrlTb );
2498
2499   createTool( 400, addRemTb );
2500   createTool( 401, addRemTb );
2501   createTool( 4021, addRemTb );
2502   createTool( 4022, addRemTb );
2503   createTool( 4023, addRemTb );
2504   createTool( 4031, addRemTb );
2505   createTool( 4032, addRemTb );
2506   createTool( 4033, addRemTb );
2507   createTool( separator(), addRemTb );
2508   createTool( 4041, addRemTb );
2509   createTool( 4042, addRemTb );
2510   createTool( separator(), addRemTb );
2511   createTool( 4051, addRemTb );
2512   createTool( 4052, addRemTb );
2513   createTool( separator(), addRemTb );
2514   createTool( 4061, addRemTb );
2515   createTool( 4062, addRemTb );
2516   createTool( 4063, addRemTb );
2517   createTool( 4064, addRemTb );
2518   createTool( 4065, addRemTb );
2519   createTool( 4066, addRemTb );
2520   createTool( separator(), addRemTb );
2521
2522   createTool( 406, modifyTb );
2523   createTool( 407, modifyTb );
2524   createTool( 408, modifyTb );
2525   createTool( 409, modifyTb );
2526   createTool( 410, modifyTb );
2527   createTool( 411, modifyTb );
2528   createTool( 412, modifyTb );
2529   createTool( 413, modifyTb );
2530   createTool( 416, modifyTb );
2531   createTool( 414, modifyTb );
2532   createTool( 415, modifyTb );
2533
2534   createTool( 214, dispModeTb );
2535
2536
2537   myRules.clear();
2538   QString OB = "'ObjectBrowser'",
2539           View = "'" + SVTK_Viewer::Type() + "'",
2540           pat = "'%1'",
2541           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2542           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2543           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2544           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2545           elems   = QString( "'%1' '%2' '%3' '%4' '%5'" ).
2546                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2547                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2548                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2549                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2550                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ),
2551           subMesh = elems,
2552           mesh_group = mesh + " " + subMesh + " " + group,
2553           hyp_alg = hypo + " " + algo;
2554
2555   // popup for object browser
2556
2557   createPopupItem( 705, OB, mesh, "&& isComputable");      // EDIT_GLOBAL_HYPO
2558   createPopupItem( 706, OB, subMesh, "&& isComputable" );  // EDIT_LOCAL_HYPO
2559   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2560   popupMgr()->insert( separator(), -1, 0 );
2561   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2562   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2563   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2564   createPopupItem( 902, OB, mesh );                        // STD_INFO
2565   popupMgr()->insert( separator(), -1, 0 );
2566   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2567   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2568   popupMgr()->insert( separator(), -1, 0 );
2569   createPopupItem( 1100, OB, hypo, "&& $hasReference={false}" );   // EDIT HYPOTHESIS
2570   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2571   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "&& $hasReference={false}" ); // RENAME
2572   popupMgr()->insert( separator(), -1, 0 );
2573   createPopupItem( 125, OB, mesh );                        // EXPORT_MED
2574   createPopupItem( 126, OB, mesh );                        // EXPORT_UNV
2575   createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
2576   popupMgr()->insert( separator(), -1, 0 );
2577
2578   // popup for viewer
2579   createPopupItem( 803, View, group ); // EDIT_GROUP
2580   createPopupItem( 804, View, elems ); // ADD
2581   createPopupItem( 805, View, elems ); // REMOVE
2582   popupMgr()->insert( separator(), -1, 0 );
2583   createPopupItem( 214, View, mesh_group ); // UPDATE
2584   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2585   createPopupItem( 902, View, mesh );       // STD_INFO
2586   popupMgr()->insert( separator(), -1, 0 );
2587
2588   int anId;
2589   QString
2590     isInvisible("not( isVisible )"),
2591     isEmpty("numberOfNodes = 0"),
2592     isNotEmpty("numberOfNodes <> 0"),
2593
2594     // has nodes, edges, etc in VISIBLE! actor
2595     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2596     hasElems("(count( elemTypes ) > 0)"),
2597     hasDifferentElems("(count( elemTypes ) > 1)"),
2598     hasEdges("({'Edge'} in elemTypes)"),
2599     hasFaces("({'Face'} in elemTypes)"),
2600     hasVolumes("({'Volume'} in elemTypes)");
2601
2602   QString lc = QtxPopupMgr::Selection::defEquality();
2603   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2604   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() ).arg( mesh_group );
2605   QString aMeshInVTK = aClient + "&&" + aType;
2606   
2607   //-------------------------------------------------
2608   // Numbering
2609   //-------------------------------------------------
2610   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2611   
2612   popupMgr()->insert( action( 9010 ), anId, -1 );
2613   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2614   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2615
2616   popupMgr()->insert( action( 9011 ), anId, -1 );
2617   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2618   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2619
2620   popupMgr()->insert( separator(), -1, -1 );
2621
2622   //-------------------------------------------------
2623   // Display Mode
2624   //-------------------------------------------------
2625   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2626
2627   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2628   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2629   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2630
2631   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2632   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2633   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2634
2635   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2636   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2637   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2638
2639   popupMgr()->insert( separator(), anId, -1 );
2640
2641   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2642   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2643   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2644
2645   //-------------------------------------------------
2646   // Display Entity
2647   //-------------------------------------------------
2648   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2649
2650   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2651
2652   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2653   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
2654   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2655
2656   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2657   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
2658   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2659
2660   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2661   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
2662   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2663
2664   popupMgr()->insert( separator(), anId, -1 );
2665
2666   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2667   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
2668
2669   //-------------------------------------------------
2670   // Color / Size
2671   //-------------------------------------------------
2672   popupMgr()->insert( action( 1132 ), -1, -1 );
2673   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
2674
2675   //-------------------------------------------------
2676   // Transparency
2677   //-------------------------------------------------
2678   popupMgr()->insert( action( 1133 ), -1, -1 );
2679   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
2680
2681   //-------------------------------------------------
2682   // Clipping
2683   //-------------------------------------------------
2684   popupMgr()->insert( action( 1134 ), -1, -1 );
2685   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
2686
2687   popupMgr()->insert( separator(), -1, -1 );
2688
2689   //-------------------------------------------------
2690   // Controls
2691   //-------------------------------------------------
2692   QString
2693     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
2694     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
2695     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
2696
2697   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
2698
2699   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
2700   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2701
2702   popupMgr()->insert( separator(), anId, -1 );
2703
2704   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
2705   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
2706   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeEdges'", false );
2707
2708   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
2709   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
2710   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
2711
2712   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
2713   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
2714   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
2715
2716   popupMgr()->insert( separator(), anId, -1 );
2717
2718   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
2719   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
2720   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeBorders'", false );
2721
2722   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
2723   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
2724   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
2725
2726   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
2727   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
2728   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
2729
2730   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
2731   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
2732   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
2733
2734   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
2735   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
2736   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
2737
2738   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
2739   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
2740   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
2741
2742   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
2743   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
2744   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
2745
2746   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
2747   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
2748   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
2749
2750   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
2751   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
2752   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
2753
2754   popupMgr()->insert( separator(), anId, -1 );
2755
2756   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
2757   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
2758   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
2759
2760   popupMgr()->insert( separator(), anId, -1 );
2761
2762   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
2763   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2764
2765   popupMgr()->insert( separator(), -1, -1 );
2766
2767   //-------------------------------------------------
2768   // Display / Erase
2769   //-------------------------------------------------
2770   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2771   QString anActiveVTK = QString("activeView = '%1'").arg(VTKViewer_Viewer::Type());
2772   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2773   QString aRule = aClient + " and " + aType + " and " + aSelCount + " and " + anActiveVTK;
2774   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
2775   popupMgr()->setRule( action( 301 ), aRule + "&&" + isNotEmpty + "&&" + isInvisible, true);
2776
2777   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
2778   popupMgr()->setRule( action( 300 ), aRule + "&&" + isNotEmpty + "&& isVisible", true );
2779
2780   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
2781   popupMgr()->setRule( action( 302 ), aRule + "&&" + isNotEmpty, true );
2782
2783   popupMgr()->insert( separator(), -1, -1 );
2784
2785   connect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ), 
2786            this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
2787 }
2788
2789 bool SMESHGUI::activateModule( SUIT_Study* study )
2790 {
2791   bool res = SalomeApp_Module::activateModule( study );
2792
2793   setMenuShown( true );
2794   setToolShown( true );
2795
2796   return res;
2797 }
2798
2799 bool SMESHGUI::deactivateModule( SUIT_Study* study )
2800 {
2801   setMenuShown( false );
2802   setToolShown( false );
2803
2804   EmitSignalCloseAllDialogs();
2805   
2806   return SalomeApp_Module::deactivateModule( study );
2807 }
2808
2809 void SMESHGUI::OnGUIEvent()
2810 {
2811   const QObject* obj = sender();
2812   if ( !obj || !obj->inherits( "QAction" ) )
2813     return;
2814   int id = actionId((QAction*)obj);
2815   if ( id != -1 )
2816     OnGUIEvent( id );
2817 }
2818
2819 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
2820 {
2821   if ( CORBA::is_nil( myComponentSMESH ) )
2822     {
2823       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
2824       return aGUI.myComponentSMESH;
2825     }  
2826   return myComponentSMESH;
2827 }
2828
2829 QString SMESHGUI::engineIOR() const
2830 {
2831   CORBA::ORB_var anORB = getApp()->orb();
2832   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
2833   return anIOR.in();
2834 }
2835
2836 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
2837 {
2838   SMESHGUI_Selection sel;
2839   sel.init( client, selectionMgr() );
2840   popupMgr()->updatePopup( menu, &sel );
2841 }
2842
2843 void SMESHGUI::windows( QMap<int, int>& aMap ) const
2844 {
2845   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
2846   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
2847 }
2848
2849 void SMESHGUI::viewManagers( QStringList& list ) const
2850 {
2851   list.append( SVTK_Viewer::Type() );
2852 }
2853
2854 void SMESHGUI::onViewManagerAdded( SUIT_ViewManager* mgr )
2855 {
2856   if ( dynamic_cast<VTKViewer_ViewManager*>( mgr ) )
2857     SMESH::UpdateSelectionProp( this );
2858 }
2859
2860 void SMESHGUI::createPreferences()
2861 {
2862   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
2863
2864   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
2865   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, SalomeApp_Preferences::Bool, "SMESH", "display_entity" );
2866   addPreference( tr( "PREF_AUTO_UPDATE" ), qaGroup, SalomeApp_Preferences::Bool, "SMESH", "auto_update" );
2867
2868   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
2869   setPreferenceProperty( precGroup, "columns", 1 );
2870
2871   addPreference( tr( "PREF_PRECISION_USE" ), precGroup, SalomeApp_Preferences::Bool );
2872   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, SalomeApp_Preferences::IntSpin, "SMESH", "controls_precision" );
2873
2874   setPreferenceProperty( prec, "min", 0 );
2875   setPreferenceProperty( prec, "max", 16 );
2876
2877   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
2878   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, SalomeApp_Preferences::Selector, "SMESH", "display_mode" );
2879   QStringList modes;
2880   modes.append( "Wireframe" );
2881   modes.append( "Shading" );
2882   modes.append( "Shrink" );
2883   modes.append( "Nodes" );
2884   setPreferenceProperty( dispmode, "strings", modes );
2885   
2886   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
2887   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
2888
2889   addPreference( tr( "PREF_COLOR" ), nodeGroup, SalomeApp_Preferences::Color, "SMESH", "node_color" );
2890   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, SalomeApp_Preferences::IntSpin, "SMESH", "node_size" );
2891
2892   setPreferenceProperty( nodeSz, "min", 1 );
2893   setPreferenceProperty( nodeSz, "max", 5 );
2894
2895   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
2896
2897   addPreference( tr( "PREF_FILL" ), elemGroup, SalomeApp_Preferences::Color, "SMESH", "fill_color" );
2898   addPreference( tr( "PREF_OUTLINE" ), elemGroup, SalomeApp_Preferences::Color, "SMESH", "outline_color" );
2899   addPreference( tr( "PREF_BACKFACE" ), elemGroup, SalomeApp_Preferences::Color, "SMESH", "backface_color" );
2900   addPreference( "", elemGroup, SalomeApp_Preferences::Space );
2901
2902   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, SalomeApp_Preferences::IntSpin, "SMESH", "element_width" );
2903   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, SalomeApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
2904
2905   setPreferenceProperty( elemW, "min", 1 );
2906   setPreferenceProperty( elemW, "max", 5 );
2907
2908   setPreferenceProperty( shrink, "min", 0 );
2909   setPreferenceProperty( shrink, "max", 100 );
2910
2911   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
2912
2913   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
2914
2915   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, SalomeApp_Preferences::Color, "SMESH", "selection_object_color" );
2916   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, SalomeApp_Preferences::Color, "SMESH", "selection_element_color" );
2917   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, SalomeApp_Preferences::IntSpin, "SMESH", "selection_width" );
2918   
2919   setPreferenceProperty( selW, "min", 1 );
2920   setPreferenceProperty( selW, "max", 5 );
2921   
2922   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
2923
2924   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, SalomeApp_Preferences::Color, "SMESH", "highlight_color" );
2925   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, SalomeApp_Preferences::IntSpin, "SMESH", "highlight_width" );
2926
2927   setPreferenceProperty( preW, "min", 1 );
2928   setPreferenceProperty( preW, "max", 5 );
2929
2930   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
2931
2932   addPreference( tr( "PREF_NODES" ), precSelGroup, SalomeApp_Preferences::Double, "SMESH", "selection_precision_node" );
2933   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, SalomeApp_Preferences::Double, "SMESH", "selection_precision_element" );
2934
2935   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
2936   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
2937
2938   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, SalomeApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
2939   addPreference( tr( "SMESH_TITLE" ), fontGr, SalomeApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
2940   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, SalomeApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
2941   addPreference( tr( "SMESH_LABELS" ), fontGr, SalomeApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
2942
2943   QStringList fam;
2944   fam.append( tr( "SMESH_FONT_ARIAL" ) );
2945   fam.append( tr( "SMESH_FONT_COURIER" ) );
2946   fam.append( tr( "SMESH_FONT_TIMES" ) );
2947   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
2948
2949   setPreferenceProperty( tfont, "families", fam );
2950   setPreferenceProperty( tfont, "system", false );
2951   setPreferenceProperty( tfont, "widget_flags", wflag );  
2952   setPreferenceProperty( lfont, "families", fam );
2953   setPreferenceProperty( lfont, "system", false );
2954   setPreferenceProperty( lfont, "widget_flags", wflag );
2955   
2956   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
2957
2958   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, SalomeApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
2959   setPreferenceProperty( numcol, "min", 2 );
2960   setPreferenceProperty( numcol, "max", 256 );  
2961   
2962   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, SalomeApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
2963   setPreferenceProperty( numlab, "min", 2 );
2964   setPreferenceProperty( numlab, "max", 65 );
2965
2966   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
2967   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, SalomeApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
2968   QStringList orients;
2969   orients.append( tr( "SMESH_VERTICAL" ) );
2970   orients.append( tr( "SMESH_HORIZONTAL" ) );
2971   QValueList<QVariant> indices; indices.append( 0 ); indices.append( 1 );
2972   setPreferenceProperty( orient, "strings", orients );
2973   setPreferenceProperty( orient, "indexes", indices );
2974   
2975   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
2976   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
2977   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );  
2978   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
2979   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
2980   setPreferenceProperty( xv, "step", 0.1 );
2981   setPreferenceProperty( xv, "min", 0.0 );
2982   setPreferenceProperty( xv, "max", 1.0 );
2983   setPreferenceProperty( yv, "step", 0.1 );
2984   setPreferenceProperty( yv, "min", 0.0 );
2985   setPreferenceProperty( yv, "max", 1.0 );
2986   setPreferenceProperty( wv, "step", 0.1 );
2987   setPreferenceProperty( wv, "min", 0.0 );
2988   setPreferenceProperty( wv, "max", 1.0 );
2989   setPreferenceProperty( hv, "min", 0.0 );
2990   setPreferenceProperty( hv, "max", 1.0 );
2991   setPreferenceProperty( hv, "step", 0.1 );    
2992
2993   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
2994   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
2995   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
2996   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
2997   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, SalomeApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
2998   setPreferenceProperty( xv, "min", 0.0 );
2999   setPreferenceProperty( xv, "max", 1.0 );
3000   setPreferenceProperty( xv, "step", 0.1 );
3001   setPreferenceProperty( xh, "min", 0.0 );
3002   setPreferenceProperty( xh, "max", 1.0 );
3003   setPreferenceProperty( xh, "step", 0.1 );
3004   setPreferenceProperty( yh, "min", 0.0 );
3005   setPreferenceProperty( yh, "max", 1.0 );
3006   setPreferenceProperty( yh, "step", 0.1 );
3007   setPreferenceProperty( wh, "min", 0.0 );
3008   setPreferenceProperty( wh, "max", 1.0 );
3009   setPreferenceProperty( wh, "step", 0.1 );
3010   setPreferenceProperty( hh, "min", 0.0 );
3011   setPreferenceProperty( hh, "max", 1.0 );
3012   setPreferenceProperty( hh, "step", 0.1 );
3013 }
3014
3015 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3016 {
3017 }