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