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