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