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