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