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