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