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