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