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