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