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