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