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