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