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