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