Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
24
25 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
26 #ifdef HAVE_FINITE
27 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #endif
29 #include "Python.h"
30 //  SMESH includes
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_AddMeshElementDlg.h"
33 #include "SMESHGUI_AddQuadraticElementDlg.h"
34 #include "SMESHGUI_BuildCompoundDlg.h"
35 #include "SMESHGUI_ClippingDlg.h"
36 #include "SMESHGUI_ComputeDlg.h"
37 #include "SMESHGUI_ConvToQuadOp.h"
38 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
39 #include "SMESHGUI_DeleteGroupDlg.h"
40 #include "SMESHGUI_Displayer.h"
41 #include "SMESHGUI_MergeDlg.h"
42 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
43 #include "SMESHGUI_ExtrusionDlg.h"
44 #include "SMESHGUI_FileInfoDlg.h"
45 #include "SMESHGUI_FileValidator.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_FindElemByPointDlg.h"
49 #include "SMESHGUI_GroupDlg.h"
50 #include "SMESHGUI_GroupOnShapeDlg.h"
51 #include "SMESHGUI_GroupOpDlg.h"
52 #include "SMESHGUI_Hypotheses.h"
53 #include "SMESHGUI_Make2DFrom3DOp.h"
54 #include "SMESHGUI_MakeNodeAtPointDlg.h"
55 #include "SMESHGUI_Measurements.h"
56 #include "SMESHGUI_MeshInfo.h"
57 #include "SMESHGUI_MeshOp.h"
58 #include "SMESHGUI_MeshOrderOp.h"
59 #include "SMESHGUI_MeshPatternDlg.h"
60 #include "SMESHGUI_MultiEditDlg.h"
61 #include "SMESHGUI_NodesDlg.h"
62 #include "SMESHGUI_Preferences_ColorDlg.h"
63 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
64 #include "SMESHGUI_RemoveElementsDlg.h"
65 #include "SMESHGUI_RemoveNodesDlg.h"
66 #include "SMESHGUI_RenumberingDlg.h"
67 #include "SMESHGUI_RevolutionDlg.h"
68 #include "SMESHGUI_RotationDlg.h"
69 #include "SMESHGUI_Selection.h"
70 #include "SMESHGUI_SewingDlg.h"
71 #include "SMESHGUI_SingleEditDlg.h"
72 #include "SMESHGUI_SmoothingDlg.h"
73 #include "SMESHGUI_SymmetryDlg.h"
74 #include "SMESHGUI_TranslationDlg.h"
75 #include "SMESHGUI_ScaleDlg.h"
76 #include "SMESHGUI_TransparencyDlg.h"
77 #include "SMESHGUI_DuplicateNodesDlg.h"
78 #include "SMESHGUI_CopyMeshDlg.h"
79 #include "SMESHGUI_ReorientFacesDlg.h"
80
81 #include "SMESHGUI_Utils.h"
82 #include "SMESHGUI_MeshUtils.h"
83 #include "SMESHGUI_GroupUtils.h"
84 #include "SMESHGUI_FilterUtils.h"
85 #include "SMESHGUI_PatternUtils.h"
86 #include "SMESHGUI_VTKUtils.h"
87 #include "SMESHGUI_HypothesesUtils.h"
88
89 #include <SMESH_version.h>
90
91 #include <SMESH_Client.hxx>
92 #include <SMESH_Actor.h>
93 #include <SMESH_ScalarBarActor.h>
94 #include <SMESH_ActorUtils.h>
95 #include <SMESH_TypeFilter.hxx>
96 #include "SMESH_ControlsDef.hxx"
97
98 // SALOME GUI includes
99 #include <SalomeApp_Tools.h>
100 #include <SalomeApp_Study.h>
101 #include <SalomeApp_Application.h>
102 #include <SalomeApp_CheckFileDlg.h>
103 #include <SalomeApp_DataObject.h>
104
105 #include <LightApp_DataOwner.h>
106 #include <LightApp_Preferences.h>
107 #include <LightApp_SelectionMgr.h>
108 #include <LightApp_UpdateFlags.h>
109 #include <LightApp_NameDlg.h>
110
111 #include <SVTK_ViewWindow.h>
112 #include <SVTK_ViewModel.h>
113 #include <SVTK_ViewManager.h>
114
115 #include <VTKViewer_Algorithm.h>
116
117 #include <SUIT_MessageBox.h>
118 #include <SUIT_ResourceMgr.h>
119 #include <SUIT_FileDlg.h>
120 #include <SUIT_Desktop.h>
121 #include <SUIT_OverrideCursor.h>
122 #include <SUIT_Session.h>
123
124 #include <QtxPopupMgr.h>
125 #include <QtxFontEdit.h>
126
127 #include <SALOME_ListIO.hxx>
128 #include <SALOME_ListIteratorOfListIO.hxx>
129
130 #ifndef DISABLE_PLOT2DVIEWER
131 #include <SPlot2d_ViewModel.h>
132 #include <SPlot2d_Histogram.h>
133 #endif
134
135 // IDL includes
136 #include <SALOMEconfig.h>
137 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
138 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
139 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
140
141 // Qt includes
142 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
143 #include <QApplication>
144 #include <QMenu>
145 #include <QTextStream>
146
147 // BOOST includes
148 #include <boost/shared_ptr.hpp>
149
150 // VTK includes
151 #include <vtkCamera.h>
152 #include <vtkRenderer.h>
153 #include <vtkPlane.h>
154 #include <vtkCallbackCommand.h>
155 #include <vtkLookupTable.h>
156
157 // SALOME KERNEL includes
158 #include <SALOMEDS_Study.hxx>
159 #include <SALOMEDSClient_StudyBuilder.hxx>
160 #include <SALOMEDSClient_SComponent.hxx>
161 #include <SALOMEDSClient_ClientFactory.hxx>
162 #include <SALOMEDSClient_IParameters.hxx>
163
164 // OCCT includes
165 #include <Standard_ErrorHandler.hxx>
166 #include <NCollection_DataMap.hxx>
167
168 //To disable automatic genericobj management, the following line should be commented.
169 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
170 #define WITHGENERICOBJ
171
172 //namespace{
173   // Declarations
174   //=============================================================
175   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
176                             int theCommandID);
177
178   void ExportMeshToFile(int theCommandID);
179
180   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
181
182   void SetDisplayEntity(int theCommandID);
183
184   void Control( int theCommandID );
185
186
187   // Definitions
188   //=============================================================
189   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
190                              int theCommandID )
191   {
192     QStringList filter;
193     std::string myExtension;
194
195     if ( theCommandID == 113 ) {
196       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.med)" );
197       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
198     }
199     else if ( theCommandID == 112 ) {
200       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
201     }
202     else if ( theCommandID == 111 ) {
203       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
204     }
205     else if ( theCommandID == 115 ) {
206       filter.append( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
207     }
208     else if ( theCommandID == 116 ) {
209       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
210     }
211     else if ( theCommandID == 117 ) {
212       filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
213       filter.append( QObject::tr( "All files (*)" ) );
214     }
215
216     QString anInitialPath = "";
217     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
218       anInitialPath = QDir::currentPath();
219
220     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
221                                                             anInitialPath,
222                                                             filter,
223                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
224     if ( filenames.count() > 0 ) {
225       SUIT_OverrideCursor wc;
226       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
227
228       QStringList errors;
229       QStringList anEntryList;
230       bool isEmpty = false;
231       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
232         QString filename = *it;
233         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
234         try {
235           switch ( theCommandID ) {
236           case 111:
237             {
238               // DAT format (currently unsupported)
239               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
240                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
241               break;
242             }
243           case 112:
244             {
245               // UNV format
246               aMeshes->length( 1 );
247               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toLatin1().constData() );
248               if ( aMeshes[0]->_is_nil() )
249                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
250                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
251               break;
252             }
253           case 113:
254             {
255               // MED format
256               SMESH::DriverMED_ReadStatus res;
257               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toLatin1().constData(), res );
258               if ( res != SMESH::DRS_OK ) {
259                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
260                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
261               }
262               break;
263             }
264           case 115:
265             {
266               // STL format
267               aMeshes->length( 1 );
268               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toLatin1().constData() );
269               if ( aMeshes[0]->_is_nil() ) {
270                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
271                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
272               }
273               break;
274             }
275           case 116:
276             {
277               // CGNS format
278               SMESH::DriverMED_ReadStatus res;
279               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toLatin1().constData(), res );
280               if ( res != SMESH::DRS_OK ) {
281                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
282                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
283               }
284               break;
285             }
286           case 117:
287             {
288               // SAUV format
289               SMESH::DriverMED_ReadStatus res;
290               aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toLatin1().constData(), res );
291               if ( res != SMESH::DRS_OK ) {
292                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
293                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
294               }
295               break;
296             }
297           }
298         }
299         catch ( const SALOME::SALOME_Exception& S_ex ) {
300           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
301                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
302         }
303
304         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
305           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
306           if ( aMeshSO ) {
307             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
308             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
309             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
310             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
311               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
312
313             anEntryList.append( aMeshSO->GetID().c_str() );
314
315 #ifdef WITHGENERICOBJ
316             // obj has been published in study. Its refcount has been incremented.
317             // It is safe to decrement its refcount
318             // so that it will be destroyed when the entry in study will be removed
319             aMeshes[i]->UnRegister();
320 #endif
321           }
322           else {
323             isEmpty = true;
324           }
325         }
326       }
327
328       // update Object browser
329       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
330
331       // browse to the published meshes
332       if( LightApp_Application* anApp =
333           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
334         anApp->browseObjects( anEntryList );
335
336       // show Error message box if there were errors
337       if ( errors.count() > 0 ) {
338         SUIT_MessageBox::critical( SMESHGUI::desktop(),
339                                    QObject::tr( "SMESH_ERROR" ),
340                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
341       }
342
343       // show warning message box, if some imported mesh is empty
344       if ( isEmpty ) {
345           SUIT_MessageBox::warning( SMESHGUI::desktop(),
346                                     QObject::tr( "SMESH_WRN_WARNING" ),
347                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
348       }
349     }
350   }
351
352   //================================================================================
353   /*!
354    * \brief Export selected meshes or groups into a file
355    */
356   //================================================================================
357
358   void ExportMeshToFile( int theCommandID )
359   {
360     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
361     SALOME_ListIO selected;
362     if( aSel )
363       aSel->selectedObjects( selected );
364
365     const bool isMED = ( theCommandID == 122 || theCommandID == 125 );
366     const bool isDAT = ( theCommandID == 121 || theCommandID == 124 );
367     const bool isUNV = ( theCommandID == 123 || theCommandID == 126 );
368     const bool isSTL = ( theCommandID == 140 || theCommandID == 141 );
369     const bool isCGNS= ( theCommandID == 142 || theCommandID == 143 );
370     const bool isSAUV= ( theCommandID == 144 || theCommandID == 145 );
371
372     // actually, the following condition can't be met (added for insurance)
373     if( selected.Extent() == 0 ||
374         ( selected.Extent() > 1 && !isMED && !isSTL ))
375       return;
376
377     // get mesh object from selection and check duplication of their names
378     bool hasDuplicatedMeshNames = false;
379     QList< QPair< SMESH::SMESH_IDSource_var, QString > > aMeshList;
380     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
381     SALOME_ListIteratorOfListIO It( selected );
382     for( ; It.More(); It.Next() )
383     {
384       Handle(SALOME_InteractiveObject) anIObject = It.Value();
385       SMESH::SMESH_IDSource_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
386       if ( aMeshItem->_is_nil() ) {
387         SUIT_MessageBox::warning( SMESHGUI::desktop(),
388                                   QObject::tr( "SMESH_WRN_WARNING" ),
389                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
390         return;
391       }
392
393       QString aMeshName = anIObject->getName();
394
395       // check for name duplications
396       if ( !hasDuplicatedMeshNames )
397         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
398           if( aMeshName == (*aMeshIter).second ) {
399             hasDuplicatedMeshNames = true;
400             break;
401           }
402         }
403
404       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
405     }
406
407     if( hasDuplicatedMeshNames && isMED ) {
408       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
409                                           QObject::tr("SMESH_WRN_WARNING"),
410                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
411                                           QObject::tr("SMESH_BUT_YES"),
412                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
413       if (aRet != 0)
414         return;
415     }
416
417     aMeshIter = aMeshList.begin();
418     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
419     SMESH::SMESH_Mesh_var aMesh = aMeshOrGroup->GetMesh();
420     QString aMeshName = (*aMeshIter).second;
421
422     if ( isMED || isCGNS || isSAUV )
423     {
424       // check for equal group names within each mesh
425       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
426         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
427         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
428           int aRet = SUIT_MessageBox::warning
429             (SMESHGUI::desktop(),
430              QObject::tr("SMESH_WRN_WARNING"),
431              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
432              QObject::tr("SMESH_BUT_YES"),
433              QObject::tr("SMESH_BUT_NO"), 0, 1);
434           if (aRet != 0)
435             return;
436         }
437       }
438     }
439     
440     // Warn the user about presence of not supported elements
441     QString format;
442     std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
443     if ( isDAT )
444     {
445       format = "DAT";
446       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Quadrangle );
447       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
448       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
449       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
450       notSupportedElemTypes.push_back( SMESH::Entity_Tetra );
451       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Tetra );
452       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
453       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
454       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Hexa );
455       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
456       notSupportedElemTypes.push_back( SMESH::Entity_Penta );
457       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
458       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
459       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
460       notSupportedElemTypes.push_back( SMESH::Entity_0D );
461       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
462     }
463     else if ( isUNV )
464     {
465       format = "UNV";
466       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
467       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
468       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
469       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
470       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
471       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
472       notSupportedElemTypes.push_back( SMESH::Entity_0D );
473       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
474     }
475     else if ( isSTL )
476     {
477       format = "STL";
478       notSupportedElemTypes.push_back( SMESH::Entity_Edge );
479       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
480       notSupportedElemTypes.push_back( SMESH::Entity_0D );
481       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
482     }
483     else if ( isCGNS )
484     {
485       format = "CGNS";
486       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
487     }
488     else if ( isSAUV )
489     {
490       format = "SAUV";
491       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
492       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
493       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
494       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
495       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
496       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
497     }
498     if ( ! notSupportedElemTypes.empty() )
499     {
500       SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
501       for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
502         if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
503           presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
504     }
505     if ( !presentNotSupported.empty() )
506     {
507       QString typeNames;
508       const char* typeMsg[SMESH::Entity_Last] = { "SMESH_NODES",
509         "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES","SMESH_TRIANGLES",
510         "SMESH_QUADRATIC_TRIANGLES","SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES",
511         "SMESH_BIQUADRATIC_QUADRANGLES","SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
512         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
513         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
514         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
515         "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
516       };
517       QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
518       for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
519         typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
520         if ( iType != presentNotSupported.size() - 1 )
521           typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
522       }
523       int aRet = SUIT_MessageBox::warning
524         (SMESHGUI::desktop(),
525          QObject::tr("SMESH_WRN_WARNING"),
526          QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
527          QObject::tr("SMESH_BUT_YES"),
528          QObject::tr("SMESH_BUT_NO"), 0, 1);
529       if (aRet != 0)
530         return;
531     }
532
533     // Get parameters of export operation
534
535     QString aFilename;
536     SMESH::MED_VERSION aFormat;
537     // Init the parameters with the default values
538     bool aIsASCII_STL = true;
539     bool toCreateGroups = false;
540     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
541     if ( resMgr )
542       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
543     bool toOverwrite = true;
544
545     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
546     QString anInitialPath = "";
547     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
548       anInitialPath = QDir::currentPath();
549
550     if ( isUNV || isDAT )
551     {
552       if ( isUNV )
553         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
554       else
555         aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
556       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
557       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
558                                             anInitialPath + QString("/") + aMeshName,
559                                             aFilter, aTitle, false);
560     }
561     else if ( isCGNS )// Export to CGNS
562     {
563       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
564       fd->setWindowTitle( aTitle );
565       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
566       if ( !anInitialPath.isEmpty() )
567         fd->setDirectory( anInitialPath );
568       fd->selectFile(aMeshName);
569       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
570       fd->setValidator( fv );
571
572       if ( fd->exec() )
573         aFilename = fd->selectedFile();
574       toOverwrite = fv->isOverwrite();
575
576       delete fd;
577     }
578     else if ( isSTL ) // Export to STL
579     {
580       QMap<QString, int> aFilterMap;
581       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
582       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
583
584       QStringList filters;
585       QMap<QString, int>::const_iterator it = aFilterMap.begin();
586       for ( ; it != aFilterMap.end(); ++it )
587         filters.push_back( it.key() );
588
589       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
590       fd->setWindowTitle( aTitle );
591       fd->setNameFilters( filters );
592       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
593       if ( !anInitialPath.isEmpty() )
594         fd->setDirectory( anInitialPath );
595       fd->selectFile(aMeshName);
596       bool is_ok = false;
597       while (!is_ok) {
598         if ( fd->exec() )
599           aFilename = fd->selectedFile();
600         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
601         is_ok = true;
602       }
603       delete fd;
604     }
605     else if ( isMED || isSAUV ) // Export to MED or SAUV
606     {
607       QMap<QString, SMESH::MED_VERSION> aFilterMap;
608       //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
609       if ( isMED ) {
610         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
611         //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
612         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
613       }
614       else { // isSAUV
615         aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
616         aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
617         aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
618       }
619
620       QStringList filters;
621       QString aDefaultFilter;
622       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
623       for ( ; it != aFilterMap.end(); ++it ) {
624         filters.push_back( it.key() );
625         if (it.value() == SMESH::MED_V2_2)
626           aDefaultFilter = it.key();
627       }
628
629       SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
630         ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
631       fd->setWindowTitle( aTitle );
632       fd->setNameFilters( filters );
633       fd->selectNameFilter(aDefaultFilter);
634       fd->SetChecked(toCreateGroups);
635       if ( !anInitialPath.isEmpty() )
636         fd->setDirectory( anInitialPath );
637       fd->selectFile(aMeshName);
638
639       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
640       fd->setValidator( fv );
641
642       bool is_ok = false;
643       while (!is_ok) {
644         if ( fd->exec() )
645           aFilename = fd->selectedFile();
646         else {
647           aFilename = QString::null;
648           break;
649         }
650         aFormat = aFilterMap[fd->selectedNameFilter()];
651         toOverwrite = fv->isOverwrite();
652         is_ok = true;
653         if ( !aFilename.isEmpty() ) {
654           // med-2.1 does not support poly elements
655           if ( aFormat==SMESH::MED_V2_1 )
656             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
657               SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
658               SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
659               if ( nbElems[ SMESH::Entity_Polygon   ] + nbElems[ SMESH::Entity_Quad_Polygon   ] +
660                    nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
661               {
662                 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
663                                                     QObject::tr("SMESH_WRN_WARNING"),
664                                                     QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
665                                                     QObject::tr("SMESH_BUT_YES"),
666                                                     QObject::tr("SMESH_BUT_NO"), 0, 1);
667                 if (aRet != 0) {
668                   is_ok = false;
669                   break;
670                 }
671               }
672             }
673           if( !toOverwrite ) {
674             // can't append to an existing using other format
675             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
676             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
677             if( !isVersionOk || aVersion != aFormat ) {
678               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
679                                                   QObject::tr("SMESH_WRN_WARNING"),
680                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
681                                                   QObject::tr("SMESH_BUT_YES"),
682                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
683               if (aRet == 0)
684                 toOverwrite = true;
685               else
686                 is_ok = false;
687             }
688
689             QStringList aMeshNamesCollisionList;
690             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
691             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
692               QString anExistingMeshName( aMeshNames[ i ] );
693               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
694                 QString anExportMeshName = (*aMeshIter).second;
695                 if( anExportMeshName == anExistingMeshName ) {
696                   aMeshNamesCollisionList.append( anExportMeshName );
697                   break;
698                 }
699               }
700             }
701             if( !aMeshNamesCollisionList.isEmpty() ) {
702               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
703               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
704                                                   QObject::tr("SMESH_WRN_WARNING"),
705                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
706                                                   QObject::tr("SMESH_BUT_YES"),
707                                                   QObject::tr("SMESH_BUT_NO"),
708                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
709               if (aRet == 0)
710                 toOverwrite = true;
711               else if (aRet == 2)
712                 is_ok = false;
713             }
714           }
715         }
716       }
717       toCreateGroups = fd->IsChecked();
718       delete fd;
719     }
720     else
721     {
722       return;
723     }
724
725     // Perform export
726
727     if ( !aFilename.isEmpty() ) {
728       // Check whether the file already exists and delete it if yes
729       QFile aFile( aFilename );
730       if ( aFile.exists() && toOverwrite )
731         aFile.remove();
732       SUIT_OverrideCursor wc;
733
734       try {
735         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
736 //         bool Renumber = false;
737 //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
738 //         if (resMgr)
739 //           Renumber= resMgr->booleanValue("renumbering");
740 //         if (Renumber){
741 //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
742 //           aMeshEditor->RenumberNodes();
743 //           aMeshEditor->RenumberElements();
744 //           if ( SMESHGUI::automaticUpdate() )
745 //             SMESH::UpdateView();
746 //         }
747         if ( isMED )
748         {
749           aMeshIter = aMeshList.begin();
750           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
751           {
752             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
753             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
754             if ( aMeshOrGroup->_is_equivalent( aMeshItem ))
755               aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups,
756                                        aFormat, toOverwrite && aMeshIndex == 0 );
757             else
758               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toLatin1().data(), toCreateGroups,
759                                           aFormat, toOverwrite && aMeshIndex == 0 );
760           }
761         }
762         else if ( isSAUV )
763         {
764           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
765           {
766             SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
767             if( !aMeshItem->_is_nil() )
768               aMeshItem->ExportSAUV( aFilename.toLatin1().data(), toCreateGroups );
769           }
770         }
771         else if ( isDAT )
772         {
773           if ( aMeshOrGroup->_is_equivalent( aMesh ))
774             aMesh->ExportDAT( aFilename.toLatin1().data() );
775           else
776             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toLatin1().data() );
777         }
778         else if ( isUNV )
779         {
780           if ( aMeshOrGroup->_is_equivalent( aMesh ))
781             aMesh->ExportUNV( aFilename.toLatin1().data() );
782           else
783             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toLatin1().data() );
784         }
785         else if ( isSTL )
786         {
787           if ( aMeshOrGroup->_is_equivalent( aMesh ))
788             aMesh->ExportSTL( aFilename.toLatin1().data(), aIsASCII_STL );
789           else
790             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toLatin1().data(), aIsASCII_STL );
791         }
792         else if ( isCGNS )
793         {
794           aMeshIter = aMeshList.begin();
795           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
796           {
797             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
798             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
799             aMeshItem->ExportCGNS( aMeshOrGroup,
800                                    aFilename.toLatin1().data(),
801                                    toOverwrite && aMeshIndex == 0 );
802           }
803         }
804       }
805       catch (const SALOME::SALOME_Exception& S_ex){
806         wc.suspend();
807         SUIT_MessageBox::warning(SMESHGUI::desktop(),
808                                  QObject::tr("SMESH_WRN_WARNING"),
809                                  QObject::tr("SMESH_EXPORT_FAILED"));
810         wc.resume();
811       }
812     }
813   }
814
815   inline void InverseEntityMode(unsigned int& theOutputMode,
816                                 unsigned int theMode)
817   {
818     bool anIsNotPresent = ~theOutputMode & theMode;
819     if(anIsNotPresent)
820       theOutputMode |= theMode;
821     else
822       theOutputMode &= ~theMode;
823   }
824
825   void SetDisplayEntity(int theCommandID){
826     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
827     SALOME_ListIO selected;
828     if( aSel )
829       aSel->selectedObjects( selected );
830
831     if(selected.Extent() >= 1){
832       SALOME_ListIteratorOfListIO It( selected );
833       for( ; It.More(); It.Next()){
834         Handle(SALOME_InteractiveObject) IObject = It.Value();
835         if(IObject->hasEntry()){
836           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
837             unsigned int aMode = anActor->GetEntityMode();
838             switch(theCommandID){
839             case 222:
840               InverseEntityMode(aMode,SMESH_Actor::eBallElem);
841               break;
842             case 216:
843               InverseEntityMode(aMode,SMESH_Actor::e0DElements);
844               break;
845             case 217:
846               InverseEntityMode(aMode,SMESH_Actor::eEdges);
847               break;
848             case 218:
849               InverseEntityMode(aMode,SMESH_Actor::eFaces);
850               break;
851             case 219:
852               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
853               break;
854             case 220:
855               aMode = SMESH_Actor::eAllEntity;
856               break;
857             }
858             if(aMode)
859               anActor->SetEntityMode(aMode);
860           }
861         }
862       }
863     }
864   }
865
866   void AutoColor(){
867     SALOME_ListIO selected;
868     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
869     if( !app )
870       return;
871
872     LightApp_SelectionMgr* aSel = app->selectionMgr();
873     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
874     if( !aSel || !appStudy )
875       return;
876
877     aSel->selectedObjects( selected );
878     if( selected.IsEmpty() )
879       return;
880
881     Handle(SALOME_InteractiveObject) anIObject = selected.First();
882
883     _PTR(Study) aStudy = appStudy->studyDS();
884     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
885     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
886     if( aMainObject->_is_nil() )
887       return;
888
889     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
890
891     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
892     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
893     {
894       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
895       SALOMEDS::Color aColor = aGroupObject->GetColor();
896       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
897       if (aGroupSObject) {
898         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
899           switch ( aGroupObject->GetType ()) {
900           case SMESH::NODE:
901             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
902           case SMESH::EDGE:
903             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
904           case SMESH::ELEM0D:
905             anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
906           case SMESH::BALL:
907             anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
908           default:
909             QColor c;
910             int delta;
911             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
912             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
913           }
914         }
915       }
916     }
917
918     SMESH::RepaintCurrentView();
919   }
920
921   QString functorToString( SMESH::Controls::FunctorPtr f )
922   {
923     QString type = QObject::tr( "UNKNOWN_CONTROL" );
924     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
925       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
926     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
927       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
928     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
929       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
930     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
931       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
932     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
933       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
934     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
935       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
936     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
937       type = QObject::tr( "WARP_ELEMENTS" );
938     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
939       type = QObject::tr( "TAPER_ELEMENTS" );
940     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
941       type = QObject::tr( "SKEW_ELEMENTS" );
942     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
943       type = QObject::tr( "AREA_ELEMENTS" );
944     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
945       type = QObject::tr( "LENGTH_EDGES" );
946     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
947       type = QObject::tr( "LENGTH2D_EDGES" );
948     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
949       type = QObject::tr( "MULTI_BORDERS" );
950     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
951       type = QObject::tr( "MULTI2D_BORDERS" );
952     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
953       type = QObject::tr( "FREE_NODES" );
954     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
955       type = QObject::tr( "FREE_EDGES" );
956     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
957       type = QObject::tr( "FREE_BORDERS" );
958     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
959       type = QObject::tr( "FREE_FACES" );
960     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
961       type = QObject::tr( "BARE_BORDER_VOLUME" );
962     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
963       type = QObject::tr( "BARE_BORDER_FACE" );
964     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
965       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
966     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
967       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
968     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
969       type = QObject::tr( "EQUAL_NODE" );
970     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
971       type = QObject::tr( "EQUAL_EDGE" );
972     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
973       type = QObject::tr( "EQUAL_FACE" );
974     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
975       type = QObject::tr( "EQUAL_VOLUME" );
976     return type;
977   }
978
979   void SaveDistribution()
980   {
981     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
982     SALOME_ListIO selected;
983     if ( aSel )
984       aSel->selectedObjects( selected );
985
986     if ( selected.Extent() == 1 ) {
987       Handle(SALOME_InteractiveObject) anIO = selected.First();
988       if ( anIO->hasEntry() ) {
989         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
990         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
991           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
992           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
993           if ( aScalarBarActor && aFunctor ) {
994             SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
995             if ( aNumFun ) {
996               std::vector<int> elements;
997               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
998               if ( mesh->_is_nil() ) {
999                 SMESH::SMESH_IDSource_var idSource =
1000                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1001                 if ( !idSource->_is_nil() )
1002                 {
1003                   SMESH::long_array_var ids = idSource->GetIDs();
1004                   elements.resize( ids->length() );
1005                   for ( unsigned i = 0; i < elements.size(); ++i )
1006                     elements[i] = ids[i];
1007                 }
1008               }
1009               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1010               vtkLookupTable* lookupTable =
1011                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1012               double * minmax = lookupTable->GetRange();
1013               std::vector<int>    nbEvents;
1014               std::vector<double> funValues;
1015               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax );
1016               QString anInitialPath = "";
1017               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1018                 anInitialPath = QDir::currentPath();
1019               QString aMeshName = anIO->getName();
1020               QStringList filter;
1021               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1022               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1023               QString aFilename = anInitialPath + "/" + aMeshName + "_" + 
1024                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1025               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1026                                                      aFilename,
1027                                                      filter,
1028                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1029                                                      false );
1030               if ( !aFilename.isEmpty() ) {
1031                 QFile f( aFilename );
1032                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1033                   QTextStream out( &f );
1034                   out << "# Mesh: " << aMeshName << endl;
1035                   out << "# Control: " << functorToString( aFunctor ) << endl;
1036                   out << "#" << endl;
1037                   out.setFieldWidth( 10 );
1038                   for ( int i = 0; i < qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1039                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1040                   f.close();
1041                 }
1042               }
1043             }
1044           }
1045         }
1046       }
1047     }
1048   }
1049
1050   void ShowDistribution() {
1051     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1052     SALOME_ListIO selected;
1053     if ( aSel )
1054       aSel->selectedObjects( selected );
1055     
1056     if ( selected.Extent() == 1 ) {
1057       Handle(SALOME_InteractiveObject) anIO = selected.First();
1058       if ( anIO->hasEntry() ) {
1059         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1060         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1061           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1062           aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1063         }
1064       }
1065     }
1066   }
1067
1068 #ifndef DISABLE_PLOT2DVIEWER
1069  void PlotDistribution() {
1070    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1071    if( !app )
1072      return;
1073
1074    LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1075    SALOME_ListIO selected;
1076    if ( aSel )
1077      aSel->selectedObjects( selected );
1078     
1079    if ( selected.Extent() == 1 ) {
1080      Handle(SALOME_InteractiveObject) anIO = selected.First();
1081      if ( anIO->hasEntry() ) {
1082        //Find Actor by entry before getting Plot2d viewer,
1083        //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1084        SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1085
1086        SUIT_ViewManager* aViewManager = app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1087
1088        if( !aViewManager )
1089          return;
1090        
1091        SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1092        if ( !aView )
1093          return;
1094
1095        Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1096        if ( !aPlot )
1097          return;
1098
1099        if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1100          SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1101          QString functorName = functorToString( anActor->GetFunctor());
1102          QString aHistogramName("%1 : %2");
1103          aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1104          aHistogram->setName(aHistogramName);
1105          aHistogram->setHorTitle(functorName);
1106          aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1107          aPlot->displayObject(aHistogram, true);
1108        }
1109      }
1110    }
1111  }
1112 #endif //DISABLE_PLOT2DVIEWER
1113
1114   void DisableAutoColor(){
1115     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1116     SALOME_ListIO selected;
1117     if( aSel )
1118       aSel->selectedObjects( selected );
1119
1120     if(selected.Extent()){
1121       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1122       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1123       if ( !aMesh->_is_nil() ) {
1124         aMesh->SetAutoColor( false );
1125       }
1126     }
1127   }
1128
1129   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
1130   {
1131     SALOME_ListIO selected;
1132     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1133     if( !app )
1134       return;
1135
1136     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1137     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1138     if( !aSel || !appStudy )
1139       return;
1140
1141     if( theCommandID == 1134 ) { // Clipping dialog can be activated without selection
1142       if( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1143         aModule->EmitSignalDeactivateDialog();
1144         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1145           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1146       }
1147       return;
1148     }
1149
1150     _PTR(Study) aStudy = appStudy->studyDS();
1151
1152     aSel->selectedObjects( selected );
1153
1154     if(selected.Extent() >= 1){
1155       switch(theCommandID){
1156       case 1133:{
1157         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1158         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1159         return;
1160       }
1161       case 1132:{
1162         QColor c, e, b, n, c0D, cBall, o, outl, selection, preselection;
1163         int delta;
1164         int size0D = 0, ballSize = 0;
1165         int Edgewidth = 0;
1166         vtkFloatingPointType Shrink = 0.0;
1167         vtkFloatingPointType faces_orientation_scale = 0.0;
1168         bool faces_orientation_3dvectors = false;
1169
1170         VTK::MarkerType aMarkerTypeCurrent = VTK::MT_NONE;
1171         VTK::MarkerScale aMarkerScaleCurrent = VTK::MS_NONE;
1172         int aMarkerTextureCurrent = 0;
1173
1174         SALOME_ListIteratorOfListIO It( selected );
1175         for( ; It.More(); It.Next()){
1176           Handle(SALOME_InteractiveObject) IObject = It.Value();
1177           if(IObject->hasEntry()){
1178             if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1179               vtkFloatingPointType color[3];
1180               anActor->GetSufaceColor(color[0], color[1], color[2],delta);
1181               int c0 = int (color[0] * 255);
1182               int c1 = int (color[1] * 255);
1183               int c2 = int (color[2] * 255);
1184               c.setRgb(c0, c1, c2);
1185
1186               vtkFloatingPointType edgecolor[3];
1187               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1188               c0 = int (edgecolor[0] * 255);
1189               c1 = int (edgecolor[1] * 255);
1190               c2 = int (edgecolor[2] * 255);
1191               e.setRgb(c0, c1, c2);
1192
1193               vtkFloatingPointType nodecolor[3];
1194               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1195               c0 = int (nodecolor[0] * 255);
1196               c1 = int (nodecolor[1] * 255);
1197               c2 = int (nodecolor[2] * 255);
1198               n.setRgb(c0, c1, c2);
1199
1200               vtkFloatingPointType color0D[3];
1201               anActor->Get0DColor(color0D[0], color0D[1], color0D[2]);
1202               c0 = int (color0D[0] * 255);
1203               c1 = int (color0D[1] * 255);
1204               c2 = int (color0D[2] * 255);
1205               c0D.setRgb(c0, c1, c2);
1206
1207               vtkFloatingPointType ballcolor[3];
1208               anActor->GetBallColor(ballcolor[0], ballcolor[1], ballcolor[2]);
1209               c0 = int (ballcolor[0] * 255);
1210               c1 = int (ballcolor[1] * 255);
1211               c2 = int (ballcolor[2] * 255);
1212               cBall.setRgb(c0, c1, c2);
1213
1214               vtkFloatingPointType outlineColor[3];
1215               anActor->GetOutlineColor(outlineColor[0], outlineColor[1], outlineColor[2]);
1216               c0 = int (outlineColor[0] * 255);
1217               c1 = int (outlineColor[1] * 255);
1218               c2 = int (outlineColor[2] * 255);
1219               outl.setRgb(c0, c1, c2);
1220
1221               vtkFloatingPointType hColor[3];
1222               anActor->GetHighlightColor(hColor[0], hColor[1], hColor[2]);
1223               c0 = int (hColor[0] * 255);
1224               c1 = int (hColor[1] * 255);
1225               c2 = int (hColor[2] * 255);
1226               selection.setRgb(c0, c1, c2);
1227
1228               vtkFloatingPointType phColor[3];
1229               anActor->GetPreHighlightColor(phColor[0], phColor[1], phColor[2]);
1230               c0 = int (phColor[0] * 255);
1231               c1 = int (phColor[1] * 255);
1232               c2 = int (phColor[2] * 255);
1233               preselection.setRgb(c0, c1, c2);
1234
1235               size0D = (int)anActor->Get0DSize();
1236               if(size0D == 0)
1237                 size0D = 1;
1238               ballSize = (int)anActor->GetBallSize();
1239               if(ballSize == 0)
1240                 ballSize = 1;
1241               Edgewidth = (int)anActor->GetLineWidth();
1242               if(Edgewidth == 0)
1243                 Edgewidth = 1;
1244               Shrink = anActor->GetShrinkFactor();
1245
1246               vtkFloatingPointType faces_orientation_color[3];
1247               anActor->GetFacesOrientationColor(faces_orientation_color);
1248               c0 = int (faces_orientation_color[0] * 255);
1249               c1 = int (faces_orientation_color[1] * 255);
1250               c2 = int (faces_orientation_color[2] * 255);
1251               o.setRgb(c0, c1, c2);
1252
1253               faces_orientation_scale = anActor->GetFacesOrientationScale();
1254               faces_orientation_3dvectors = anActor->GetFacesOrientation3DVectors();
1255
1256               aMarkerTypeCurrent = anActor->GetMarkerType();
1257               aMarkerScaleCurrent = anActor->GetMarkerScale();
1258               aMarkerTextureCurrent = anActor->GetMarkerTexture();
1259
1260               // even if there are multiple objects in the selection,
1261               // we need only the first one to get values for the dialog
1262               break;
1263             }
1264           }
1265         }
1266
1267         SMESHGUI_Preferences_ColorDlg *aDlg =
1268           new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI() );
1269         aDlg->SetBooleanValue(1, faces_orientation_3dvectors);
1270         aDlg->SetColor(1, c);
1271         aDlg->SetColor(2, e);
1272         aDlg->SetColor(3, n);
1273         aDlg->SetColor(4, outl);
1274         aDlg->SetColor(5, c0D);
1275         aDlg->SetColor(6, cBall);
1276         aDlg->SetColor(7, o);
1277         aDlg->SetColor(8, selection);
1278         aDlg->SetColor(9, preselection);
1279         aDlg->SetDeltaBrightness(delta);
1280         aDlg->SetDoubleValue(1, faces_orientation_scale);
1281         aDlg->SetIntValue(1, Edgewidth);
1282         aDlg->SetIntValue(2, int(Shrink*100.));
1283         aDlg->SetIntValue(3, size0D);
1284         aDlg->SetIntValue(4, ballSize);
1285  
1286         aDlg->setCustomMarkerMap( theMarkerMap[ aStudy->StudyId() ] );
1287
1288         if( aMarkerTypeCurrent != VTK::MT_USER )
1289           aDlg->setStandardMarker( aMarkerTypeCurrent, aMarkerScaleCurrent );
1290         else
1291           aDlg->setCustomMarker( aMarkerTextureCurrent );
1292
1293         if(aDlg->exec()){
1294           QColor color                   = aDlg->GetColor(1);
1295           QColor edgecolor               = aDlg->GetColor(2);
1296           QColor nodecolor               = aDlg->GetColor(3);
1297           QColor outlinecolor            = aDlg->GetColor(4);
1298           QColor color0D                 = aDlg->GetColor(5);
1299           QColor ballcolor               = aDlg->GetColor(6);
1300           QColor faces_orientation_color = aDlg->GetColor(7);
1301           QColor selectioncolor          = aDlg->GetColor(8);
1302           QColor preSelectioncolor       = aDlg->GetColor(9);
1303           int delta = aDlg->GetDeltaBrightness();
1304
1305           /* Point marker */
1306           theMarkerMap[ aStudy->StudyId() ] = aDlg->getCustomMarkerMap();
1307
1308           SALOME_ListIteratorOfListIO It( selected );
1309           for( ; It.More(); It.Next()){
1310             Handle(SALOME_InteractiveObject) IObject = It.Value();
1311             if(IObject->hasEntry()){
1312               if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1313                 /* actor color and backface color */
1314                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
1315                                         vtkFloatingPointType (color.green()) / 255.,
1316                                         vtkFloatingPointType (color.blue()) / 255.,
1317                                         delta);
1318                 /* edge color */
1319                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
1320                                       vtkFloatingPointType (edgecolor.green()) / 255.,
1321                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
1322                 /* edge outline */
1323                 anActor->SetOutlineColor(vtkFloatingPointType (outlinecolor.red()) / 255.,
1324                                          vtkFloatingPointType (outlinecolor.green()) / 255.,
1325                                          vtkFloatingPointType (outlinecolor.blue()) / 255.);
1326
1327                 /* selection */
1328                 anActor->SetHighlightColor(vtkFloatingPointType (selectioncolor.red()) / 255.,
1329                                            vtkFloatingPointType (selectioncolor.green()) / 255.,
1330                                            vtkFloatingPointType (selectioncolor.blue()) / 255.);
1331                 /* pre-selection */
1332                 anActor->SetPreHighlightColor(vtkFloatingPointType (preSelectioncolor.red()) / 255.,
1333                                               vtkFloatingPointType (preSelectioncolor.green()) / 255.,
1334                                               vtkFloatingPointType (preSelectioncolor.blue()) / 255.);
1335                 
1336
1337                 /* Shrink factor and size edges */
1338                 anActor->SetShrinkFactor(aDlg->GetIntValue(2) / 100.);
1339                 anActor->SetLineWidth(aDlg->GetIntValue(1));
1340
1341                 /* Nodes color and size */
1342                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
1343                                       vtkFloatingPointType (nodecolor.green()) / 255.,
1344                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
1345
1346                 /* 0D elements */
1347                 anActor->Set0DColor(vtkFloatingPointType (color0D.red()) / 255.,
1348                                     vtkFloatingPointType (color0D.green()) / 255.,
1349                                     vtkFloatingPointType (color0D.blue()) / 255.);
1350                 anActor->Set0DSize(aDlg->GetIntValue(3));
1351
1352                 /* Ball elements */
1353                 anActor->SetBallColor(vtkFloatingPointType (ballcolor.red()) / 255.,
1354                                       vtkFloatingPointType (ballcolor.green()) / 255.,
1355                                       vtkFloatingPointType (ballcolor.blue()) / 255.);
1356                 anActor->SetBallSize(aDlg->GetIntValue(4));
1357
1358                 /* Faces orientation */
1359                 vtkFloatingPointType c[3] = {vtkFloatingPointType(faces_orientation_color.redF()),
1360                                              vtkFloatingPointType(faces_orientation_color.greenF()),
1361                                              vtkFloatingPointType(faces_orientation_color.blueF())};
1362                 anActor->SetFacesOrientationColor(c);
1363                 anActor->SetFacesOrientationScale(aDlg->GetDoubleValue(1));
1364                 anActor->SetFacesOrientation3DVectors(aDlg->GetBooleanValue(1));
1365
1366                 VTK::MarkerType aMarkerTypeNew = aDlg->getMarkerType();
1367                 VTK::MarkerScale aMarkerScaleNew = aDlg->getStandardMarkerScale();
1368                 int aMarkerTextureNew = aDlg->getCustomMarkerID();
1369                 if( aMarkerTypeNew != VTK::MT_USER )
1370                   anActor->SetMarkerStd( aMarkerTypeNew, aMarkerScaleNew );
1371                 else {
1372                   const VTK::MarkerMap& aMarkerMap = theMarkerMap[ aStudy->StudyId() ];
1373                   VTK::MarkerMap::const_iterator anIter = aMarkerMap.find( aMarkerTextureNew );
1374                   if( anIter != aMarkerMap.end() )
1375                     anActor->SetMarkerTexture( aMarkerTextureNew, anIter->second.second );
1376                 }
1377
1378                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1379                 if( !aGroupObject->_is_nil() )
1380                 {
1381                   SMESH::ElementType anElementType = aGroupObject->GetType();
1382                   QColor aColor;
1383                   switch( anElementType )
1384                   {
1385                     case SMESH::NODE: aColor = nodecolor; break;
1386                     case SMESH::EDGE: aColor = edgecolor; break;
1387                     default: aColor = color; break;
1388                   }
1389
1390                   SALOMEDS::Color aGroupColor;
1391                   aGroupColor.R = (float)aColor.red() / 255.0;
1392                   aGroupColor.G = (float)aColor.green() / 255.0;
1393                   aGroupColor.B = (float)aColor.blue() / 255.0;
1394                   aGroupObject->SetColor( aGroupColor );
1395                 }
1396               }
1397             }
1398           }
1399           SMESH::RepaintCurrentView();
1400         }
1401         delete aDlg;
1402         return;
1403       }
1404       }
1405       SALOME_ListIteratorOfListIO It( selected );
1406       for( ; It.More(); It.Next()){
1407         Handle(SALOME_InteractiveObject) IObject = It.Value();
1408         if(IObject->hasEntry()){
1409           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1410             switch(theCommandID){
1411             case 211:
1412               anActor->SetRepresentation(SMESH_Actor::eEdge);
1413               break;
1414             case 212:
1415               anActor->SetRepresentation(SMESH_Actor::eSurface);
1416               break;
1417             case 213:
1418               if(anActor->IsShrunk())
1419                 anActor->UnShrink();
1420               else
1421                 anActor->SetShrink();
1422               break;
1423             case 215:
1424               anActor->SetRepresentation(SMESH_Actor::ePoint);
1425               break;
1426             case 231:
1427               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1428                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1429               break;
1430             case 232:
1431               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1432                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1433               break;
1434             }
1435           }
1436         }
1437       }
1438       SMESH::RepaintCurrentView();
1439     }
1440   }
1441
1442   void Control( int theCommandID )
1443   {
1444     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1445     SALOME_ListIO selected;
1446     if( aSel )
1447       aSel->selectedObjects( selected );
1448
1449     if( !selected.IsEmpty() ){
1450       Handle(SALOME_InteractiveObject) anIO = selected.First();
1451       if(!anIO.IsNull()){
1452         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
1453         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())) {
1454           switch ( theCommandID ){
1455           case 6001:
1456             aControl = SMESH_Actor::eLength;
1457             break;
1458           case 6018:
1459             aControl = SMESH_Actor::eLength2D;
1460             break;
1461           case 6002:
1462             aControl = SMESH_Actor::eFreeEdges;
1463             break;
1464           case 6003:
1465             aControl = SMESH_Actor::eFreeBorders;
1466             break;
1467           case 6004:
1468             aControl = SMESH_Actor::eMultiConnection;
1469             break;
1470           case 6005:
1471             aControl = SMESH_Actor::eFreeNodes;
1472             break;
1473           case 6019:
1474             aControl = SMESH_Actor::eMultiConnection2D;
1475             break;
1476           case 6011:
1477             aControl = SMESH_Actor::eArea;
1478             break;
1479           case 6012:
1480             aControl = SMESH_Actor::eTaper;
1481             break;
1482           case 6013:
1483             aControl = SMESH_Actor::eAspectRatio;
1484             break;
1485           case 6017:
1486             aControl = SMESH_Actor::eAspectRatio3D;
1487             break;
1488           case 6014:
1489             aControl = SMESH_Actor::eMinimumAngle;
1490             break;
1491           case 6015:
1492             aControl = SMESH_Actor::eWarping;
1493             break;
1494           case 6016:
1495             aControl = SMESH_Actor::eSkew;
1496             break;
1497           case 6009:
1498             aControl = SMESH_Actor::eVolume3D;
1499             break;
1500           case 6021:
1501             aControl = SMESH_Actor::eFreeFaces;
1502             break;
1503           case 6022:
1504             aControl = SMESH_Actor::eMaxElementLength2D;
1505             break;
1506           case 6023:
1507             aControl = SMESH_Actor::eMaxElementLength3D;
1508             break;
1509           case 6024:
1510             aControl = SMESH_Actor::eBareBorderVolume;
1511             break;
1512           case 6025:
1513             aControl = SMESH_Actor::eBareBorderFace;
1514             break;
1515           case 6026:
1516             aControl = SMESH_Actor::eOverConstrainedVolume;
1517             break;
1518           case 6027:
1519             aControl = SMESH_Actor::eOverConstrainedFace;
1520             break;
1521           case 6028:
1522             aControl = SMESH_Actor::eCoincidentNodes;
1523             break;
1524           case 6029:
1525             aControl = SMESH_Actor::eCoincidentElems1D;
1526             break;
1527           case 6030:
1528             aControl = SMESH_Actor:: eCoincidentElems2D;
1529             break;
1530           case 6031:
1531             aControl = SMESH_Actor::eCoincidentElems3D;
1532             break;
1533           }
1534             
1535           anActor->SetControlMode(aControl);
1536           anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1537           SMESH::RepaintCurrentView();
1538 #ifndef DISABLE_PLOT2DVIEWER
1539           if(anActor->GetPlot2Histogram()) {
1540             SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1541             QString functorName = functorToString( anActor->GetFunctor());
1542             QString aHistogramName("%1 : %2");
1543             aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1544             aHistogram->setName(aHistogramName);
1545             aHistogram->setHorTitle(functorName);
1546             SMESH::ProcessIn2DViewers(anActor);
1547           }
1548 #endif
1549         }
1550       }
1551     }
1552   }
1553
1554
1555   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1556                    MeshObjectType                           theType,
1557                    const QString                            theInTypeName,
1558                    QString &                                theOutTypeName)
1559   {
1560     SMESH_TypeFilter aTypeFilter( theType );
1561     QString entry;
1562     if( !theIO.IsNull() )
1563     {
1564       entry = theIO->getEntry();
1565       LightApp_DataOwner owner( entry );
1566       if ( aTypeFilter.isOk( &owner )) {
1567         theOutTypeName = theInTypeName;
1568         return true;
1569       }
1570     }
1571     return false;
1572   }
1573
1574
1575   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1576   {
1577     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1578     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1579     if (aSObj) {
1580       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1581       CORBA::String_var anID = aSComp->GetID().c_str();
1582       if (!strcmp(anID.in(),theIO->getEntry()))
1583         return "Component";
1584     }
1585
1586     QString aTypeName;
1587     if (
1588         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1589         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
1590         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
1591         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
1592         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
1593         )
1594       return aTypeName;
1595
1596     return "NoType";
1597   }
1598
1599
1600   QString CheckHomogeneousSelection()
1601   {
1602     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1603     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1604     SALOME_ListIO selected;
1605     if( aSel )
1606       aSel->selectedObjects( selected );
1607
1608     QString RefType = CheckTypeObject(selected.First());
1609     SALOME_ListIteratorOfListIO It(selected);
1610     for ( ; It.More(); It.Next())
1611       {
1612         Handle(SALOME_InteractiveObject) IObject = It.Value();
1613         QString Type = CheckTypeObject(IObject);
1614         if (Type.compare(RefType) != 0)
1615           return "Heterogeneous Selection";
1616       }
1617
1618     return RefType;
1619   }
1620
1621
1622   void SMESHGUI::OnEditDelete()
1623   {
1624     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1625     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1626     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1627
1628     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1629     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1630     _PTR(GenericAttribute) anAttr;
1631     _PTR(AttributeIOR) anIOR;
1632
1633     int objectCount = 0;
1634     QString aNameList;
1635     QString aParentComponent = QString::null;
1636     Handle(SALOME_InteractiveObject) anIO;
1637     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1638     {
1639       anIO = anIt.Value();
1640       QString cur = anIO->getComponentDataType();
1641       _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1642       if (aSO) {
1643         // check if object is reference
1644         _PTR(SObject) aRefSObj;
1645         aNameList.append("\n    - ");
1646         if ( aSO->ReferencedObject( aRefSObj ) ) {
1647           QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1648           aNameList.append( aRefName );
1649           cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1650         }
1651         else
1652           aNameList.append(anIO->getName());
1653         objectCount++;
1654       }
1655
1656       if( aParentComponent.isNull() )
1657         aParentComponent = cur;
1658       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1659         aParentComponent = "";
1660     }
1661
1662     if ( objectCount == 0 )
1663       return; // No Valid Objects Selected
1664
1665     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1666       SUIT_MessageBox::warning( SMESHGUI::desktop(),
1667                                 QObject::tr("ERR_ERROR"),
1668                                 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1669       return;
1670     }
1671     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1672     if (SUIT_MessageBox::warning
1673         (SMESHGUI::desktop(),
1674          QObject::tr("SMESH_WRN_WARNING"),
1675          QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1676          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1677          SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1678       return;
1679
1680     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1681
1682     // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1683     // then treat them all starting from the deepest objects (at list back)
1684     std::list< _PTR(SObject) > listSO;
1685     SALOME_ListIteratorOfListIO It(selected);
1686     for( ; It.More(); It.Next()) // loop on selected IO's
1687     {
1688       Handle(SALOME_InteractiveObject) IObject = It.Value();
1689       if(IObject->hasEntry()) {
1690         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1691
1692         // disable removal of "SMESH" component object
1693         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1694           anIOR = anAttr;
1695           if ( engineIOR() == anIOR->Value().c_str() )
1696             continue;
1697         }
1698         //Check the referenced object
1699         _PTR(SObject) aRefSObject;
1700         if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1701           aSO = aRefSObject; // Delete main Object instead of reference
1702
1703         listSO.push_back( aSO );
1704         std::list< _PTR(SObject) >::iterator itSO = listSO.begin();
1705         for ( ; itSO != listSO.end(); ++itSO ) {
1706           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1707           for (it->InitEx(false); it->More(); it->Next())
1708             listSO.push_back( it->Value() );
1709         }
1710       }
1711     }
1712     // Check if none of objects to delete is referred from outside
1713     std::list< _PTR(SObject) >::reverse_iterator ritSO;
1714     for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1715     {
1716       _PTR(SObject) SO = *ritSO;
1717       if ( !SO ) continue;
1718       std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO  );
1719       for (size_t i = 0; i < aReferences.size(); i++) {
1720         _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1721         std::string type = aComponent->ComponentDataType();
1722         if ( type != "SMESH" )
1723         {
1724           SUIT_MessageBox::warning( anApp->desktop(),
1725                                     QObject::tr("WRN_WARNING"),
1726                                     QObject::tr("DEP_OBJECT") );
1727           return; // outside SMESH, there is an object depending on a SMESH object 
1728         }
1729       }
1730     }
1731
1732     // Treat SO's in the list starting from the back
1733     aStudyBuilder->NewCommand();  // There is a transaction
1734     for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1735     {
1736       _PTR(SObject) SO = *ritSO;
1737       if ( !SO ) continue;
1738       std::string anEntry = SO->GetID();
1739
1740       /** Erase graphical object **/
1741       if(SO->FindAttribute(anAttr, "AttributeIOR")){
1742         ViewManagerList aViewMenegers = anApp->viewManagers();
1743         ViewManagerList::const_iterator it = aViewMenegers.begin();
1744         for( ; it != aViewMenegers.end(); it++) {         
1745           SUIT_ViewManager* vm = *it;
1746           int nbSf = vm ? vm->getViewsCount() : 0;
1747           if(vm) {
1748             QVector<SUIT_ViewWindow*> aViews = vm->getViews();
1749             for(int i = 0; i < nbSf; i++){
1750               SUIT_ViewWindow *sf = aViews[i];
1751               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1752                 SMESH::RemoveActor(sf,anActor);
1753               }
1754             }
1755           }
1756         }
1757       }
1758       /** Remove an object from data structures **/
1759       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1760       SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1761       if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1762         SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1763         aMesh->RemoveGroup( aGroup );
1764       }
1765       else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1766         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1767         aMesh->RemoveSubMesh( aSubMesh );
1768
1769         _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1770         if (aMeshSO)
1771           SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1772       }
1773       else {
1774         Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1775           ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1776         QString objType = CheckTypeObject(IObject);
1777         if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1778           SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1779           aStudyBuilder->RemoveObjectWithChildren( SO );
1780         }
1781         else {// default action: remove SObject from the study
1782               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1783               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1784               //op->start();
1785           aStudyBuilder->RemoveObjectWithChildren( SO );
1786           //op->finish();
1787         }
1788       }
1789     } /* listSO back loop */
1790
1791     aStudyBuilder->CommitCommand();
1792
1793     /* Clear any previous selection */
1794     SALOME_ListIO l1;
1795     aSel->setSelectedObjects( l1 );
1796
1797     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1798   }
1799 //} namespace
1800
1801 extern "C" {
1802   SMESHGUI_EXPORT CAM_Module* createModule()
1803   {
1804     return new SMESHGUI();
1805   }
1806
1807   SMESHGUI_EXPORT  char* getModuleVersion() {
1808     return (char*)SMESH_VERSION_STR;
1809   }
1810 }
1811
1812 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1813
1814 //=============================================================================
1815 /*!
1816  *
1817  */
1818 //=============================================================================
1819 SMESHGUI::SMESHGUI() :
1820 SalomeApp_Module( "SMESH" ),
1821 LightApp_Module( "SMESH" )
1822 {
1823   if ( CORBA::is_nil( myComponentSMESH ) )
1824   {
1825     CORBA::Boolean anIsEmbeddedMode;
1826     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1827     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1828
1829     //  0019923: EDF 765 SMESH : default values of hypothesis
1830     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1831     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1832     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1833     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1834     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1835
1836     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif" };
1837     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
1838       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
1839       {
1840         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
1841         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
1842       }
1843   }
1844
1845   myActiveDialogBox = 0;
1846   myFilterLibraryDlg = 0;
1847   myState = -1;
1848   myDisplayer = 0;
1849
1850   myEventCallbackCommand = vtkCallbackCommand::New();
1851   myEventCallbackCommand->Delete();
1852   myEventCallbackCommand->SetClientData( this );
1853   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1854   myPriority = 0.0;
1855
1856   SMESH::GetFilterManager();
1857   SMESH::GetPattern();
1858   SMESH::GetMeasurements();
1859
1860   /* load resources for all available meshers */
1861   SMESH::InitAvailableHypotheses();
1862 }
1863
1864 //=============================================================================
1865 /*!
1866  *
1867  */
1868 //=============================================================================
1869 SMESHGUI::~SMESHGUI()
1870 {
1871 #ifdef WITHGENERICOBJ
1872   SMESH::GetFilterManager()->UnRegister();
1873   SMESH::GetMeasurements()->UnRegister();
1874 #endif
1875   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1876   SMESH::GetMeasurements() = SMESH::Measurements::_nil();
1877 }
1878
1879 //=============================================================================
1880 /*!
1881  *
1882  */
1883 //=============================================================================
1884 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1885 {
1886   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1887   if( anApp )
1888     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1889   else
1890     return 0;
1891 }
1892
1893 //=============================================================================
1894 /*!
1895  *
1896  */
1897 //=============================================================================
1898 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
1899 {
1900   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1901   if ( !resMgr )
1902     return false;
1903
1904   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
1905   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
1906   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
1907   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
1908   return autoUpdate && !exceeded;
1909 }
1910
1911 //=============================================================================
1912 /*!
1913  *
1914  */
1915 //=============================================================================
1916 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1917 {
1918   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1919 }
1920
1921 //=============================================================================
1922 /*!
1923  *
1924  */
1925 //=============================================================================
1926 SMESHGUI* SMESHGUI::GetSMESHGUI()
1927 {
1928   SMESHGUI* smeshMod = 0;
1929   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1930   if ( app )
1931   {
1932     CAM_Module* module = app->module( "Mesh" );
1933     smeshMod = dynamic_cast<SMESHGUI*>( module );
1934   }
1935
1936   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1937   {
1938     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1939     if ( study )
1940     {
1941       _PTR(Study) aStudy = study->studyDS();
1942       if ( aStudy )
1943         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1944     }
1945   }
1946
1947   return smeshMod;
1948 }
1949
1950 extern "C"
1951 {
1952   Standard_EXPORT SMESHGUI* GetComponentGUI()
1953   {
1954     return SMESHGUI::GetSMESHGUI();
1955   }
1956 }
1957
1958 //=============================================================================
1959 /*!
1960  *
1961  */
1962 //=============================================================================
1963 void SMESHGUI::SetState(int aState)
1964 {
1965   myState = aState;
1966 }
1967
1968 //=============================================================================
1969 /*!
1970  *
1971  */
1972 //=============================================================================
1973 void SMESHGUI::ResetState()
1974 {
1975   myState = -1;
1976 }
1977
1978 //=============================================================================
1979 /*!
1980  *
1981  */
1982 //=============================================================================
1983 void SMESHGUI::EmitSignalDeactivateDialog()
1984 {
1985   emit SignalDeactivateActiveDialog();
1986 }
1987
1988 //=============================================================================
1989 /*!
1990  *
1991  */
1992 //=============================================================================
1993 void SMESHGUI::EmitSignalStudyFrameChanged()
1994 {
1995   emit SignalStudyFrameChanged();
1996 }
1997
1998 //=============================================================================
1999 /*!
2000  *
2001  */
2002 //=============================================================================
2003 void SMESHGUI::EmitSignalCloseAllDialogs()
2004 {
2005   emit SignalCloseAllDialogs();
2006 }
2007
2008 //=============================================================================
2009 /*!
2010  *
2011  */
2012 //=============================================================================
2013 void SMESHGUI::EmitSignalVisibilityChanged()
2014 {
2015   emit SignalVisibilityChanged();
2016 }
2017
2018 //=============================================================================
2019 /*!
2020  *
2021  */
2022 //=============================================================================
2023 QDialog *SMESHGUI::GetActiveDialogBox()
2024 {
2025   return myActiveDialogBox;
2026 }
2027
2028 //=============================================================================
2029 /*!
2030  *
2031  */
2032 //=============================================================================
2033 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2034 {
2035   myActiveDialogBox = (QDialog *) aDlg;
2036   return;
2037 }
2038
2039 //=============================================================================
2040 /*!
2041  *
2042  */
2043 //=============================================================================
2044 SUIT_Desktop* SMESHGUI::desktop()
2045 {
2046   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2047   if( app )
2048     return app->desktop();
2049   else
2050     return 0;
2051 }
2052
2053 //=============================================================================
2054 /*!
2055  *
2056  */
2057 //=============================================================================
2058 SalomeApp_Study* SMESHGUI::activeStudy()
2059 {
2060   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2061   if( app )
2062     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2063   else
2064     return NULL;
2065 }
2066
2067 //=============================================================================
2068 /*!
2069  *
2070  */
2071 //=============================================================================
2072 void SMESHGUI::Modified( bool theIsUpdateActions )
2073 {
2074   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2075     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2076       appStudy->Modified();
2077       if( theIsUpdateActions )
2078         app->updateActions();
2079     }
2080   }
2081 }
2082
2083 //=============================================================================
2084 /*!
2085  *
2086  */
2087 //=============================================================================
2088 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2089 {
2090   /* Here the position is on the bottom right corner - 10 */
2091   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2092   aDlg->adjustSize();
2093   SUIT_Desktop *PP = desktop();
2094   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2095   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2096   return true;
2097 }
2098
2099 //=============================================================================
2100 /*!
2101  *
2102  */
2103 //=============================================================================
2104 static int isStudyLocked(_PTR(Study) theStudy){
2105   return theStudy->GetProperties()->IsLocked();
2106 }
2107
2108 static bool checkLock(_PTR(Study) theStudy) {
2109   if (isStudyLocked(theStudy)) {
2110     SUIT_MessageBox::warning( SMESHGUI::desktop(),
2111                               QObject::tr("WRN_WARNING"),
2112                               QObject::tr("WRN_STUDY_LOCKED") );
2113     return true;
2114   }
2115   return false;
2116 }
2117
2118 //=======================================================================
2119 //function : CheckActiveStudyLocked
2120 //purpose  :
2121 //=======================================================================
2122
2123 bool SMESHGUI::isActiveStudyLocked()
2124 {
2125   _PTR(Study) aStudy = activeStudy()->studyDS();
2126   return checkLock( aStudy );
2127 }
2128
2129 //=============================================================================
2130 /*!
2131  *
2132  */
2133 //=============================================================================
2134 bool SMESHGUI::OnGUIEvent( int theCommandID )
2135 {
2136   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2137   if( !anApp )
2138     return false;
2139
2140   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2141   SUIT_ResourceMgr* mgr = resourceMgr();
2142   if( !mgr )
2143     return false;
2144
2145   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2146     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2147   }
2148
2149   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2150   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2151
2152   //QAction* act = action( theCommandID );
2153
2154   switch (theCommandID) {
2155   case 33:                                      // DELETE
2156     if(checkLock(aStudy)) break;
2157     OnEditDelete();
2158     break;
2159
2160   case 116:
2161   case 115:
2162   case 117:
2163   case 113:
2164   case 112:
2165   case 111:                                     // IMPORT
2166     {
2167       if(checkLock(aStudy)) break;
2168       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2169       break;
2170     }
2171
2172   case 150:    //MED FILE INFORMATION
2173     {
2174       SALOME_ListIO selected;
2175       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2176       if( aSel )
2177         aSel->selectedObjects( selected );
2178       if( selected.Extent() )
2179       {
2180         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2181         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2182         if ( !aMesh->_is_nil() )
2183         {
2184           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2185           dlg.exec();
2186         }
2187       }
2188       break;
2189     }
2190
2191   case 122:                                     // EXPORT MED
2192   case 121:
2193   case 123:
2194   case 124:
2195   case 125:
2196   case 126:
2197   case 140:
2198   case 141:
2199   case 142:
2200   case 143:
2201   case 144:
2202   case 145:
2203     {
2204       ::ExportMeshToFile(theCommandID);
2205       break;
2206     }
2207
2208   case 200:                                     // SCALAR BAR
2209     {
2210       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2211       SALOME_ListIO selected;
2212       if( aSel )
2213         aSel->selectedObjects( selected );
2214
2215       if( selected.Extent() ) {
2216         Handle(SALOME_InteractiveObject) anIO = selected.First();
2217         if( anIO->hasEntry() ) {
2218           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2219             anActor->SetControlMode( SMESH_Actor::eNone );
2220 #ifndef DISABLE_PLOT2DVIEWER
2221             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2222 #endif
2223           }
2224         }
2225       }
2226       break;
2227     }
2228   case 201:
2229     {
2230       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2231       break;
2232     }
2233   case 2021:
2234     {
2235       // dump control distribution data to the text file
2236       ::SaveDistribution();
2237       break;
2238     }
2239
2240   case 2022:
2241     {
2242       // show/ distribution
2243       ::ShowDistribution();
2244       break;
2245     }
2246
2247 #ifndef DISABLE_PLOT2DVIEWER
2248   case 2023:
2249     {
2250       // plot distribution
2251       ::PlotDistribution();
2252       break;
2253     }
2254 #endif
2255
2256     // Auto-color
2257   case 1136:
2258     ::AutoColor();
2259   break;
2260
2261   case 1137:
2262     ::DisableAutoColor();
2263   break;
2264
2265   case 1134: // Clipping
2266   case 1133: // Tranparency
2267   case 1132: // Display preferences (colors, shrink size, line width, ...)
2268
2269     // Display Mode
2270   case 215: // Nodes
2271   case 213: // Nodes
2272   case 212: // Nodes
2273   case 211: // Nodes
2274     ::SetDisplayMode(theCommandID, myMarkerMap);
2275   break;
2276
2277   //2D quadratic representation
2278   case 231:
2279   case 232:
2280     ::SetDisplayMode(theCommandID, myMarkerMap);
2281   break;
2282
2283   // Display Entity
2284   case 216: // 0D elements
2285   case 217: // Edges
2286   case 218: // Faces
2287   case 219: // Volumes
2288   case 220: // All Entity
2289   case 222: // Balls
2290     ::SetDisplayEntity(theCommandID);
2291   break;
2292
2293   case 221: // Orientation of faces
2294     {
2295       LightApp_SelectionMgr* mgr = selectionMgr();
2296       SALOME_ListIO selected; mgr->selectedObjects( selected );
2297
2298       SALOME_ListIteratorOfListIO it(selected);
2299       for( ; it.More(); it.Next()) {
2300         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2301         if(anIObject->hasEntry()) {
2302           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2303             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2304           }
2305         }
2306       }
2307       break;
2308     }
2309
2310   case 214:                                     // UPDATE
2311     {
2312       if(checkLock(aStudy)) break;
2313       try {
2314 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2315         OCC_CATCH_SIGNALS;
2316 #endif
2317         SMESH::UpdateView();
2318       }
2319       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2320         SMESH::OnVisuException();
2321       }
2322       catch (...) { // PAL16774 (Crash after display of many groups)
2323         SMESH::OnVisuException();
2324       }
2325
2326       SALOME_ListIO l;
2327       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2328       aSel->selectedObjects( l );
2329       aSel->setSelectedObjects( l );
2330       break;
2331     }
2332
2333   case 300:                                     // ERASE
2334   case 301:                                     // DISPLAY
2335   case 302:                                     // DISPLAY ONLY
2336     {
2337       SMESH::EDisplaing anAction;
2338       switch (theCommandID) {
2339       case 300: anAction = SMESH::eErase; break;
2340       case 301: anAction = SMESH::eDisplay; break;
2341       case 302: anAction = SMESH::eDisplayOnly; break;
2342       }
2343
2344       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2345       SALOME_ListIO sel_objects, to_process;
2346       if (aSel)
2347         aSel->selectedObjects( sel_objects );
2348
2349       if( theCommandID==302 )
2350       {
2351         MESSAGE("anAction = SMESH::eDisplayOnly");
2352         startOperation( myEraseAll );
2353       }
2354
2355       extractContainers( sel_objects, to_process );
2356
2357       try {
2358 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2359         OCC_CATCH_SIGNALS;
2360 #endif
2361         if (vtkwnd) {
2362           SALOME_ListIteratorOfListIO It( to_process );
2363           for ( ; It.More(); It.Next()) {
2364                 MESSAGE("---");
2365             Handle(SALOME_InteractiveObject) IOS = It.Value();
2366             if (IOS->hasEntry()) {
2367                 MESSAGE("---");
2368               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
2369                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2370                 break; // PAL16774 (Crash after display of many groups)
2371               }
2372               if (anAction == SMESH::eDisplayOnly)
2373               {
2374                 MESSAGE("anAction = SMESH::eDisplayOnly");
2375                 anAction = SMESH::eDisplay;
2376               }
2377             }
2378           }
2379         }
2380
2381         // PAL13338 + PAL15161 -->
2382         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
2383                 MESSAGE("anAction = SMESH::eDisplayOnly");
2384           SMESH::UpdateView();
2385           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2386         }
2387         // PAL13338 + PAL15161 <--
2388       }
2389       catch (...) { // PAL16774 (Crash after display of many groups)
2390         SMESH::OnVisuException();
2391       }
2392
2393       if (anAction == SMESH::eErase) {
2394         MESSAGE("anAction == SMESH::eErase");
2395         SALOME_ListIO l1;
2396         aSel->setSelectedObjects( l1 );
2397       }
2398       else
2399         aSel->setSelectedObjects( to_process );
2400
2401       break;
2402     }
2403
2404   case 4000:                                    // NODES
2405     {
2406       if(checkLock(aStudy)) break;
2407
2408       if ( vtkwnd ) {
2409         EmitSignalDeactivateDialog();
2410
2411         ( new SMESHGUI_NodesDlg( this ) )->show();
2412       }
2413       else {
2414         SUIT_MessageBox::warning(desktop(),
2415                                  tr("SMESH_WRN_WARNING"),
2416                                  tr("SMESH_WRN_VIEWER_VTK"));
2417       }
2418       break;
2419     }
2420
2421   case 2151:  // FILTER
2422   {
2423     if ( vtkwnd )
2424     {
2425       EmitSignalDeactivateDialog();
2426       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
2427     }
2428     break;
2429   }
2430
2431   case 701: // COMPUTE MESH
2432   case 711: // PRECOMPUTE MESH
2433   case 712: // EVALUATE MESH
2434   case 713: // MESH ORDER
2435   case 702: // Create mesh
2436   case 703: // Create sub-mesh
2437   case 704: // Edit mesh/sub-mesh
2438     startOperation( theCommandID );
2439     break;
2440   case 705: // copy mesh
2441     {
2442       if (checkLock(aStudy)) break;
2443       EmitSignalDeactivateDialog();
2444       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2445     }
2446     break;
2447   case 710: // Build compound mesh
2448     {
2449       if (checkLock(aStudy)) break;
2450       EmitSignalDeactivateDialog();
2451       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2452     }
2453     break;
2454
2455   case 407: // DIAGONAL INVERSION
2456   case 408: // Delete diagonal
2457     {
2458       if ( !vtkwnd )
2459       {
2460         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2461                                   tr( "NOT_A_VTK_VIEWER" ) );
2462         break;
2463       }
2464
2465       if ( checkLock( aStudy ) )
2466         break;
2467
2468       /*Standard_Boolean aRes;
2469       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2470       if ( aMesh->_is_nil() )
2471       {
2472         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2473           tr( "SMESH_BAD_SELECTION" ) );
2474         break;
2475       }
2476       */
2477       EmitSignalDeactivateDialog();
2478       if ( theCommandID == 407 )
2479         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2480       else
2481         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2482       break;
2483     }
2484   case 409: // Change orientation
2485   case 410: // Union of triangles
2486   case 411: // Cutting of quadrangles
2487   case 419: // Splitting volumes into tetrahedra
2488     {
2489       if ( !vtkwnd )
2490       {
2491         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2492                                   tr( "NOT_A_VTK_VIEWER" ) );
2493         break;
2494       }
2495
2496       if ( checkLock( aStudy ) )
2497         break;
2498
2499       EmitSignalDeactivateDialog();
2500       SMESHGUI_MultiEditDlg* aDlg = NULL;
2501       if ( theCommandID == 409 )
2502         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2503       else if ( theCommandID == 410 )
2504         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2505       else if ( theCommandID == 419 )
2506         aDlg = new SMESHGUI_CuttingIntoTetraDlg(this);
2507       else
2508         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2509
2510       aDlg->show();
2511       break;
2512     }
2513   case 412: // Smoothing
2514     {
2515       if(checkLock(aStudy)) break;
2516       if( vtkwnd ) {
2517         EmitSignalDeactivateDialog();
2518         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2519       }
2520       else {
2521         SUIT_MessageBox::warning(desktop(),
2522                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2523       }
2524       break;
2525     }
2526   case 413: // Extrusion
2527     {
2528       if (checkLock(aStudy)) break;
2529       if (vtkwnd) {
2530         EmitSignalDeactivateDialog();
2531         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2532       } else {
2533         SUIT_MessageBox::warning(desktop(),
2534                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2535       }
2536       break;
2537     }
2538   case 414: // Revolution
2539     {
2540       if(checkLock(aStudy)) break;
2541       if( vtkwnd ) {
2542         EmitSignalDeactivateDialog();
2543         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2544       }
2545       else {
2546         SUIT_MessageBox::warning(desktop(),
2547                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2548       }
2549       break;
2550     }
2551   case 415: // Pattern mapping
2552     {
2553       if ( checkLock( aStudy ) )
2554         break;
2555       if ( vtkwnd )
2556       {
2557         EmitSignalDeactivateDialog();
2558         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2559       }
2560       else {
2561         SUIT_MessageBox::warning(desktop(),
2562                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2563       }
2564       break;
2565     }
2566   case 416: // Extrusion along a path
2567     {
2568       if (checkLock(aStudy)) break;
2569       if (vtkwnd) {
2570         EmitSignalDeactivateDialog();
2571         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2572       } else {
2573         SUIT_MessageBox::warning(desktop(),
2574                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2575       }
2576       break;
2577     }
2578   case 417: // Convert mesh to quadratic
2579   case 418: // create 2D mesh from 3D
2580   case 420: // Reorient faces
2581   case 806: // CREATE GEO GROUP
2582     {
2583       startOperation( theCommandID );
2584       break;
2585     }
2586   case 801:                                     // CREATE GROUP
2587     {
2588       if ( !vtkwnd )
2589       {
2590         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2591                                   tr( "NOT_A_VTK_VIEWER" ) );
2592         break;
2593       }
2594
2595       if(checkLock(aStudy)) break;
2596       EmitSignalDeactivateDialog();
2597       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2598
2599       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2600       SALOME_ListIO selected;
2601       if( aSel )
2602         aSel->selectedObjects( selected );
2603
2604       int nbSel = selected.Extent();
2605       if (nbSel == 1) {
2606         // check if mesh is selected
2607         aMesh = SMESH::GetMeshByIO( selected.First() );
2608       }
2609       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2610       aDlg->show();
2611       break;
2612     }
2613
2614   case 802:                                     // CONSTRUCT GROUP
2615     {
2616       if ( !vtkwnd )
2617       {
2618         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2619                                   tr( "NOT_A_VTK_VIEWER" ) );
2620         break;
2621       }
2622
2623       if(checkLock(aStudy)) break;
2624       EmitSignalDeactivateDialog();
2625
2626       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2627       SALOME_ListIO selected;
2628       if( aSel )
2629         aSel->selectedObjects( selected );
2630
2631       int nbSel = selected.Extent();
2632       if (nbSel == 1) {
2633         // check if submesh is selected
2634         Handle(SALOME_InteractiveObject) IObject = selected.First();
2635         if (IObject->hasEntry()) {
2636           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2637           if( aSObj ) {
2638             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2639             if (!aSubMesh->_is_nil()) {
2640               try {
2641                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2642                 // get submesh elements list by types
2643                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2644                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2645                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2646                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2647                 // create group for each type o elements
2648                 QString aName = IObject->getName();
2649                 QStringList anEntryList;
2650                 if (aNodes->length() > 0) {
2651                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2652                   aGroup->Add(aNodes.inout());
2653                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2654                     anEntryList.append( aSObject->GetID().c_str() );
2655                 }
2656                 if (aEdges->length() > 0) {
2657                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2658                   aGroup->Add(aEdges.inout());
2659                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2660                     anEntryList.append( aSObject->GetID().c_str() );
2661                 }
2662                 if (aFaces->length() > 0) {
2663                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2664                   aGroup->Add(aFaces.inout());
2665                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2666                     anEntryList.append( aSObject->GetID().c_str() );
2667                 }
2668                 if (aVolumes->length() > 0) {
2669                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2670                   aGroup->Add(aVolumes.inout());
2671                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2672                     anEntryList.append( aSObject->GetID().c_str() );
2673                 }
2674                 updateObjBrowser();
2675                 anApp->browseObjects( anEntryList );
2676               }
2677               catch(const SALOME::SALOME_Exception & S_ex){
2678                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2679               }
2680             }
2681           }
2682         }
2683       }
2684       else if(nbSel==0) {
2685         SUIT_MessageBox::warning(desktop(),
2686                                  tr("SMESH_WRN_WARNING"),
2687                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2688       }
2689       break;
2690     }
2691
2692   case 803:                                     // EDIT GROUP
2693     {
2694       if ( !vtkwnd )
2695       {
2696         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2697                                   tr( "NOT_A_VTK_VIEWER" ) );
2698         break;
2699       }
2700
2701       if(checkLock(aStudy)) break;
2702       EmitSignalDeactivateDialog();
2703
2704       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2705       SALOME_ListIO selected;
2706       if( aSel )
2707         aSel->selectedObjects( selected );
2708
2709       SALOME_ListIteratorOfListIO It (selected);
2710       int nbSelectedGroups = 0;
2711       for ( ; It.More(); It.Next() )
2712       {
2713         SMESH::SMESH_GroupBase_var aGroup =
2714           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2715         if (!aGroup->_is_nil()) {
2716           nbSelectedGroups++;
2717           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2718           aDlg->show();
2719         }
2720       }
2721       if (nbSelectedGroups == 0)
2722         {
2723           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2724           aDlg->show();
2725         }
2726       break;
2727     }
2728
2729   case 804:                                     // Add elements to group
2730     {
2731       if(checkLock(aStudy)) break;
2732       if (myState == 800) {
2733         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2734         if (aDlg) aDlg->onAdd();
2735       }
2736       break;
2737     }
2738
2739   case 805:                                     // Remove elements from group
2740     {
2741       if(checkLock(aStudy)) break;
2742       if (myState == 800) {
2743         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2744         if (aDlg) aDlg->onRemove();
2745       }
2746       break;
2747     }
2748
2749   case 815:                                     // Edit GEOM GROUP as standalone
2750     {
2751       if ( !vtkwnd )
2752       {
2753         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2754                                   tr( "NOT_A_VTK_VIEWER" ) );
2755         break;
2756       }
2757
2758       if(checkLock(aStudy)) break;
2759       EmitSignalDeactivateDialog();
2760
2761       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2762       SALOME_ListIO selected;
2763       if( aSel )
2764         aSel->selectedObjects( selected );
2765
2766       SALOME_ListIteratorOfListIO It (selected);
2767       for ( ; It.More(); It.Next() )
2768       {
2769         SMESH::SMESH_GroupOnGeom_var aGroup =
2770           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
2771         if (!aGroup->_is_nil()) {
2772           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2773           aDlg->show();
2774         }
2775         else
2776         {
2777           SMESH::SMESH_GroupOnFilter_var aGroup =
2778             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
2779           if (!aGroup->_is_nil()) {
2780             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2781             aDlg->show();
2782           }
2783         }
2784       }
2785       break;
2786     }
2787
2788     case 810: // Union Groups
2789     case 811: // Intersect groups
2790     case 812: // Cut groups
2791     {
2792       if ( !vtkwnd )
2793       {
2794         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2795                                   tr( "NOT_A_VTK_VIEWER" ) );
2796         break;
2797       }
2798
2799       if ( checkLock( aStudy ) )
2800         break;
2801
2802       EmitSignalDeactivateDialog();
2803
2804       SMESHGUI_GroupOpDlg* aDlg = 0;
2805       if ( theCommandID == 810 )
2806         aDlg = new SMESHGUI_UnionGroupsDlg( this );
2807       else if ( theCommandID == 811 )
2808         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
2809       else
2810         aDlg = new SMESHGUI_CutGroupsDlg( this );
2811
2812       aDlg->show();
2813
2814       break;
2815     }
2816
2817     case 814: // Create groups of entities from existing groups of superior dimensions
2818     {
2819       if ( checkLock( aStudy ) )
2820         break;
2821
2822       EmitSignalDeactivateDialog();
2823       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
2824       aDlg->show();
2825
2826       break;
2827     }
2828
2829     case 813: // Delete groups with their contents
2830     {
2831       if ( !vtkwnd )
2832       {
2833         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2834                                   tr( "NOT_A_VTK_VIEWER" ) );
2835         break;
2836       }
2837
2838       if ( checkLock( aStudy ) )
2839         break;
2840
2841       EmitSignalDeactivateDialog();
2842
2843       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
2844       break;
2845     }
2846
2847   case 900:                                     // MESH INFOS
2848   case 903:                                     // WHAT IS
2849     {
2850       int page = theCommandID == 900 ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
2851       EmitSignalDeactivateDialog();
2852       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2853       SALOME_ListIO selected;
2854       if( aSel )
2855         aSel->selectedObjects( selected );
2856
2857       if ( selected.Extent() > 1 ) { // a dlg for each IO
2858         SALOME_ListIteratorOfListIO It( selected );
2859         for ( ; It.More(); It.Next() ) {
2860           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2861           dlg->showInfo( It.Value() ); 
2862           dlg->show();
2863         }
2864       }
2865       else {
2866         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2867         dlg->show();
2868       }
2869       break;
2870     }
2871
2872   case 904:                                     // FIND ELEM
2873     {
2874       startOperation( theCommandID );
2875       break;
2876     }
2877
2878   case 1100:                                    // EDIT HYPOTHESIS
2879     {
2880       if(checkLock(aStudy)) break;
2881
2882       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2883       SALOME_ListIO selected;
2884       if( aSel )
2885         aSel->selectedObjects( selected );
2886
2887       int nbSel = selected.Extent();
2888
2889       if (nbSel == 1) {
2890         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2891         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2892
2893         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2894         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2895         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2896         if ( !aHypothesis->_is_nil() )
2897         {
2898           // BUG 0020378
2899           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2900           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2901           if (aCreator) {
2902             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
2903           }
2904           else
2905           {
2906             // report error
2907           }
2908         }
2909       }
2910       break;
2911     }
2912   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2913     {
2914       if(checkLock(aStudy)) break;
2915       SUIT_OverrideCursor wc;
2916
2917       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2918       SALOME_ListIO selected;
2919       if( aSel )
2920         aSel->selectedObjects( selected, QString::null, false );
2921
2922       SALOME_ListIteratorOfListIO It(selected);
2923       for (int i = 0; It.More(); It.Next(), i++) {
2924         Handle(SALOME_InteractiveObject) IObject = It.Value();
2925         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2926       }
2927       SALOME_ListIO l1;
2928       aSel->setSelectedObjects( l1 );
2929       updateObjBrowser();
2930       break;
2931     }
2932
2933   case 4008:                                    // BALL
2934   case 4009:                                    // ELEM0D
2935   case 4010:                                    // EDGE
2936   case 4021:                                    // TRIANGLE
2937   case 4022:                                    // QUAD
2938   case 4023:                                    // POLYGON
2939   case 4031:                                    // TETRA
2940   case 4032:                                    // HEXA
2941   case 4133:                                    // PENTA
2942   case 4134:                                    // PYRAMID
2943   case 4135:                                    // OCTA12
2944     {
2945       if(checkLock(aStudy)) break;
2946       if ( vtkwnd ) {
2947         EmitSignalDeactivateDialog();
2948         SMDSAbs_EntityType type = SMDSEntity_Edge;
2949         switch (theCommandID) {
2950         case 4008: type = SMDSEntity_Ball;            break;
2951         case 4009: type = SMDSEntity_0D;              break;
2952         case 4021: type = SMDSEntity_Triangle;        break;
2953         case 4022: type = SMDSEntity_Quadrangle;      break;
2954         case 4031: type = SMDSEntity_Tetra;           break;
2955         case 4023: type = SMDSEntity_Polygon;         break;
2956         case 4032: type = SMDSEntity_Hexa;            break;
2957         case 4133: type = SMDSEntity_Penta;           break;
2958         case 4134: type = SMDSEntity_Pyramid;         break;
2959         case 4135: type = SMDSEntity_Hexagonal_Prism; break;
2960         default:;
2961         }
2962         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
2963       }
2964       else {
2965         SUIT_MessageBox::warning(desktop(),
2966                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2967       }
2968       break;
2969     }
2970   case 4033:                                    // POLYHEDRON
2971     {
2972       if(checkLock(aStudy)) break;
2973       if ( vtkwnd ) {
2974         EmitSignalDeactivateDialog();
2975         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2976       }
2977       else {
2978         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2979                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2980       }
2981       break;
2982     }
2983   case 4034:     // QUADRATIC EDGE
2984   case 4035:     // QUADRATIC TRIANGLE
2985   case 4036:     // QUADRATIC QUADRANGLE
2986   case 4136:     // BIQUADRATIC QUADRANGLE
2987   case 4037:     // QUADRATIC TETRAHEDRON
2988   case 4038:     // QUADRATIC PYRAMID
2989   case 4039:     // QUADRATIC PENTAHEDRON
2990   case 4040:     // QUADRATIC HEXAHEDRON
2991   case 4140:     // TRIQUADRATIC HEXAHEDRON
2992     {
2993       if(checkLock(aStudy)) break;
2994       if ( vtkwnd ) {
2995         EmitSignalDeactivateDialog();
2996         SMDSAbs_EntityType type;
2997
2998         switch (theCommandID) {
2999         case 4034:
3000           type = SMDSEntity_Quad_Edge; break;
3001         case 4035:
3002           type = SMDSEntity_Quad_Triangle; break;
3003         case 4036:
3004           type = SMDSEntity_Quad_Quadrangle; break;
3005         case 4136:
3006           type = SMDSEntity_BiQuad_Quadrangle; break;
3007         case 4037:
3008           type = SMDSEntity_Quad_Tetra; break;
3009         case 4038:
3010           type = SMDSEntity_Quad_Pyramid; break;
3011         case 4039:
3012           type = SMDSEntity_Quad_Penta; break;
3013         case 4040:
3014           type = SMDSEntity_Quad_Hexa;
3015         case 4140:
3016           type = SMDSEntity_TriQuad_Hexa;
3017           break;
3018         default:;
3019         }
3020          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3021       }
3022       else {
3023         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3024                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3025       }
3026       break;
3027     }
3028   case 4041:                                    // REMOVES NODES
3029     {
3030       if(checkLock(aStudy)) break;
3031       if ( vtkwnd ) {
3032         EmitSignalDeactivateDialog();
3033         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3034       }
3035       else {
3036         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3037                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3038       }
3039       break;
3040     }
3041   case 4042:                                    // REMOVES ELEMENTS
3042     {
3043       if(checkLock(aStudy)) break;
3044       if( vtkwnd ) {
3045         EmitSignalDeactivateDialog();
3046         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3047       }
3048       else
3049         {
3050           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3051                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3052         }
3053       break;
3054     }
3055   case 4043: {                                // CLEAR_MESH
3056
3057     if(checkLock(aStudy)) break;
3058
3059     SALOME_ListIO selected;
3060     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3061       aSel->selectedObjects( selected );
3062
3063     SUIT_OverrideCursor wc;
3064     SALOME_ListIteratorOfListIO It (selected);
3065     for ( ; It.More(); It.Next() )
3066     {
3067       Handle(SALOME_InteractiveObject) IOS = It.Value();
3068       SMESH::SMESH_Mesh_var aMesh =
3069         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3070       if ( aMesh->_is_nil()) continue;
3071       try {
3072         SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3073         aMesh->Clear();
3074         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3075         SMESH::ModifiedMesh( aMeshSObj, false, true);
3076         // hide groups and submeshes
3077         _PTR(ChildIterator) anIter =
3078           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3079         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3080         {
3081           _PTR(SObject) so = anIter->Value();
3082           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3083         }
3084       }
3085       catch (const SALOME::SALOME_Exception& S_ex){
3086         wc.suspend();
3087         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3088         wc.resume();
3089       }
3090     }
3091     SMESH::UpdateView();
3092     updateObjBrowser();
3093     break;
3094   }
3095   case 4044:                                     // REMOVE ORPHAN NODES
3096     {
3097       if(checkLock(aStudy)) break;
3098       SALOME_ListIO selected;
3099       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3100         aSel->selectedObjects( selected );
3101       if ( selected.Extent() == 1 ) {
3102         Handle(SALOME_InteractiveObject) anIO = selected.First();
3103         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3104         if ( !aMesh->_is_nil() ) {
3105           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3106                                                     tr( "SMESH_WARNING" ),
3107                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3108                                                     SUIT_MessageBox::Yes |
3109                                                     SUIT_MessageBox::No,
3110                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3111           if( confirm ) {
3112             try {
3113               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3114               int removed = aMeshEditor->RemoveOrphanNodes();
3115               SUIT_MessageBox::information(SMESHGUI::desktop(),
3116                                            tr("SMESH_INFORMATION"),
3117                                            tr("NB_NODES_REMOVED").arg(removed));
3118               if ( removed > 0 ) {
3119                 SMESH::UpdateView();
3120                 SMESHGUI::Modified();
3121               }
3122             }
3123             catch (const SALOME::SALOME_Exception& S_ex) {
3124               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3125             }
3126             catch (...) {
3127             }
3128           }
3129         }
3130       }
3131       break;
3132     }
3133   case 4051:                                    // RENUMBERING NODES
3134     {
3135       if(checkLock(aStudy)) break;
3136       if( vtkwnd ) {
3137         EmitSignalDeactivateDialog();
3138         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3139       }
3140       else
3141         {
3142           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3143                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3144         }
3145       break;
3146     }
3147   case 4052:                                    // RENUMBERING ELEMENTS
3148     {
3149       if(checkLock(aStudy)) break;
3150       if ( vtkwnd ) {
3151         EmitSignalDeactivateDialog();
3152         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3153       }
3154       else
3155         {
3156           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3157                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3158         }
3159       break;
3160     }
3161   case 4061:                                   // TRANSLATION
3162     {
3163       if(checkLock(aStudy)) break;
3164       if ( vtkwnd ) {
3165         EmitSignalDeactivateDialog();
3166         ( new SMESHGUI_TranslationDlg( this ) )->show();
3167       }
3168       else {
3169         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3170                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3171       }
3172       break;
3173     }
3174   case 4062:                                   // ROTATION
3175     {
3176       if(checkLock(aStudy)) break;
3177       if( vtkwnd ) {
3178         EmitSignalDeactivateDialog();
3179         ( new SMESHGUI_RotationDlg( this ) )->show();
3180       }
3181       else {
3182         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3183                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3184       }
3185       break;
3186     }
3187   case 4063:                                   // SYMMETRY
3188     {
3189       if(checkLock(aStudy)) break;
3190       if(vtkwnd) {
3191         EmitSignalDeactivateDialog();
3192         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3193       }
3194       else {
3195         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3196                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3197       }
3198       break;
3199     }
3200   case 4064:                                   // SEWING
3201     {
3202       if(checkLock(aStudy)) break;
3203       if(vtkwnd) {
3204         EmitSignalDeactivateDialog();
3205         ( new SMESHGUI_SewingDlg( this ) )->show();
3206       }
3207       else {
3208         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3209                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3210       }
3211       break;
3212     }
3213   case 4065:                                   // MERGE NODES
3214     {
3215       if(checkLock(aStudy)) break;
3216       if(vtkwnd) {
3217         EmitSignalDeactivateDialog();
3218         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3219       }
3220       else {
3221         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3222                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3223       }
3224       break;
3225     }
3226   case 4066:                                   // MERGE EQUAL ELEMENTS
3227     {
3228       if (checkLock(aStudy)) break;
3229       if (vtkwnd) {
3230         EmitSignalDeactivateDialog();
3231         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3232       } else {
3233         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3234                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3235       }
3236       break;
3237     }
3238
3239   case 4067: // MAKE MESH PASS THROUGH POINT
3240     startOperation( 4067 );
3241     break;
3242
3243   case 4068: // SCALE
3244     {
3245       if(checkLock(aStudy)) break;
3246       if ( vtkwnd ) {
3247         EmitSignalDeactivateDialog();
3248         ( new SMESHGUI_ScaleDlg( this ) )->show();
3249       }
3250       else {
3251         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3252                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3253       }
3254       break;
3255     }
3256
3257   case 4069: // DUPLICATE NODES
3258     {
3259       if(checkLock(aStudy)) break;
3260       if ( vtkwnd ) {
3261         EmitSignalDeactivateDialog();
3262         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3263       }
3264       else {
3265         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3266                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3267       }
3268       break;
3269     }
3270
3271   case 5105: // Library of selection filters
3272   {
3273     static QList<int> aTypes;
3274     if ( aTypes.isEmpty() )
3275     {
3276       aTypes.append( SMESH::NODE );
3277       aTypes.append( SMESH::EDGE );
3278       aTypes.append( SMESH::FACE );
3279       aTypes.append( SMESH::VOLUME );
3280     }
3281     if (!myFilterLibraryDlg)
3282       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3283     else if (myFilterLibraryDlg->isHidden())
3284       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3285     myFilterLibraryDlg->raise();
3286   }
3287   break;
3288
3289   case 6017:                                    // CONTROLS
3290   case 6016:
3291   case 6015:
3292   case 6014:
3293   case 6013:
3294   case 6012:
3295   case 6011:
3296   case 6001:
3297   case 6018:
3298   case 6019:
3299   case 6002:
3300   case 6003:
3301   case 6004:
3302   case 6005:
3303   case 6009:
3304   case 6021:
3305   case 6022:
3306   case 6023:
3307   case 6024:
3308   case 6025:
3309   case 6026:
3310   case 6027:
3311   case 6028:
3312   case 6029:
3313   case 6030:
3314   case 6031:
3315     if ( vtkwnd ) {
3316
3317       LightApp_SelectionMgr* mgr = selectionMgr();
3318       SALOME_ListIO selected; mgr->selectedObjects( selected );
3319
3320       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
3321         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
3322         if ( SO ) {
3323           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
3324           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
3325           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
3326           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
3327           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
3328             ::Control( theCommandID );
3329             break;
3330           }
3331         }
3332       }
3333       SUIT_MessageBox::warning(desktop(),
3334                                tr( "SMESH_WRN_WARNING" ),
3335                                tr( "SMESH_BAD_SELECTION" ) );
3336       break;
3337     }
3338     else {
3339       SUIT_MessageBox::warning(desktop(),
3340                                tr( "SMESH_WRN_WARNING" ),
3341                                tr( "NOT_A_VTK_VIEWER" ) );
3342     }
3343     break;
3344   case 9010:
3345     {
3346       LightApp_SelectionMgr* mgr = selectionMgr();
3347       SALOME_ListIO selected; mgr->selectedObjects( selected );
3348
3349       SALOME_ListIteratorOfListIO it(selected);
3350       for( ; it.More(); it.Next()) {
3351         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3352         if(anIObject->hasEntry()) {
3353           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3354             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3355           }
3356         }
3357       }
3358       break;
3359     }
3360   case 9011:
3361     {
3362       LightApp_SelectionMgr* mgr = selectionMgr();
3363       SALOME_ListIO selected; mgr->selectedObjects( selected );
3364
3365       SALOME_ListIteratorOfListIO it(selected);
3366       for( ; it.More(); it.Next()) {
3367         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3368         if(anIObject->hasEntry())
3369           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3370             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3371           }
3372       }
3373       break;
3374     }
3375   case 501:
3376   case 502:
3377     {
3378       int page = theCommandID == 501 ? SMESHGUI_MeasureDlg::MinDistance : SMESHGUI_MeasureDlg::BoundingBox;
3379       EmitSignalDeactivateDialog();
3380       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3381       dlg->show();
3382       break;
3383     }
3384   }
3385
3386   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3387   //updateObjBrowser();
3388   return true;
3389 }
3390
3391 //=============================================================================
3392 /*!
3393  *
3394  */
3395 //=============================================================================
3396 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3397 {
3398   return false;
3399 }
3400
3401 //=============================================================================
3402 /*!
3403  *
3404  */
3405 //=============================================================================
3406 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3407 {
3408   return true;
3409 }
3410
3411 //=============================================================================
3412 /*!
3413  *
3414  */
3415 //=============================================================================
3416 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
3417 {
3418   return true;
3419 }
3420
3421 //=============================================================================
3422 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3423  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3424  */
3425 //=============================================================================
3426 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3427                                   SUIT_ViewWindow* wnd )
3428 {
3429   if(theIO->hasEntry()){
3430     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3431     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3432   }
3433 }
3434
3435 //=======================================================================
3436 // function : createSMESHAction
3437 // purpose  :
3438 //=======================================================================
3439 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
3440                                   const int key, const bool toggle, const QString& shortcutAction  )
3441 {
3442   QIcon icon;
3443   QWidget* parent = application()->desktop();
3444   SUIT_ResourceMgr* resMgr = resourceMgr();
3445   QPixmap pix;
3446   if ( !icon_id.isEmpty() )
3447     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3448   else
3449     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
3450   if ( !pix.isNull() )
3451     icon = QIcon( pix );
3452
3453   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
3454           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
3455           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
3456
3457   createAction( id, tooltip, icon, menu, status_bar, key, parent,
3458                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
3459 }
3460
3461 //=======================================================================
3462 // function : createPopupItem
3463 // purpose  :
3464 //=======================================================================
3465 void SMESHGUI::createPopupItem( const int id,
3466                                 const QString& clients,
3467                                 const QString& types,
3468                                 const QString& theRule,
3469                                 const int pId )
3470 {
3471   int parentId = pId;
3472   if( pId!=-1 )
3473     parentId = popupMgr()->actionId( action( pId ) );
3474
3475   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
3476     popupMgr()->insert( action( id ), parentId, 0 );
3477
3478   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3479   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
3480   QString rule = "(%1) and (%2) and (%3)";
3481   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
3482   if( clients.isEmpty() )
3483     rule = rule.arg( QString( "true" ) );
3484   else
3485     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
3486   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
3487   rule += theRule;
3488
3489   bool cont = myRules.contains( id );
3490   if( cont )
3491     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
3492
3493   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
3494   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
3495 }
3496
3497 //=======================================================================
3498 // function : initialize
3499 // purpose  :
3500 //=======================================================================
3501 void SMESHGUI::initialize( CAM_Application* app )
3502 {
3503   SalomeApp_Module::initialize( app );
3504
3505 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
3506 //   if ( mgr )
3507   /* Automatic Update flag */
3508 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
3509
3510   // ----- create actions --------------
3511
3512   createSMESHAction(  111, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
3513   createSMESHAction(  112, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_U) );
3514   createSMESHAction(  113, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
3515   createSMESHAction(  114, "NUM" );
3516   createSMESHAction(  115, "IMPORT_STL" );
3517   createSMESHAction(  116, "IMPORT_CGNS" );
3518   createSMESHAction(  117, "IMPORT_SAUV" );
3519   createSMESHAction(  121, "DAT" );
3520   createSMESHAction(  122, "MED" );
3521   createSMESHAction(  123, "UNV" );
3522   createSMESHAction(  140, "STL" );
3523   createSMESHAction(  142, "CGNS" );
3524   createSMESHAction(  144, "SAUV" );
3525   createSMESHAction(  124, "EXPORT_DAT" );
3526   createSMESHAction(  125, "EXPORT_MED" );
3527   createSMESHAction(  126, "EXPORT_UNV" );
3528   createSMESHAction(  141, "EXPORT_STL" );
3529   createSMESHAction(  143, "EXPORT_CGNS" );
3530   createSMESHAction(  145, "EXPORT_SAUV" );
3531   createSMESHAction(  150, "FILE_INFO" );
3532   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
3533   createSMESHAction( 5105, "SEL_FILTER_LIB" );
3534   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
3535   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
3536   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
3537   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
3538   createSMESHAction(  705, "COPY_MESH",       "ICON_COPY_MESH" );
3539   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
3540   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
3541   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
3542   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
3543   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
3544   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
3545   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
3546   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
3547   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
3548   createSMESHAction(  804, "ADD" );
3549   createSMESHAction(  805, "REMOVE" );
3550   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
3551   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
3552   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
3553   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
3554   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
3555   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
3556   //createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
3557   //createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3558   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
3559   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
3560   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
3561   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
3562   createSMESHAction( 6022, "MAX_ELEMENT_LENGTH_2D",  "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
3563   createSMESHAction( 6023, "MAX_ELEMENT_LENGTH_3D",  "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
3564   createSMESHAction( 6024, "BARE_BORDER_VOLUME",     "ICON_BARE_BORDER_VOLUME",      0, true );
3565   createSMESHAction( 6025, "BARE_BORDER_FACE",       "ICON_BARE_BORDER_FACE",        0, true );
3566   createSMESHAction( 6026, "OVER_CONSTRAINED_VOLUME","ICON_OVER_CONSTRAINED_VOLUME", 0, true );
3567   createSMESHAction( 6027, "OVER_CONSTRAINED_FACE",  "ICON_OVER_CONSTRAINED_FACE",   0, true );
3568   createSMESHAction( 6028, "EQUAL_NODE",      "ICON_EQUAL_NODE",    0, true );
3569   createSMESHAction( 6029, "EQUAL_EDGE",      "ICON_EQUAL_EDGE",    0, true );
3570   createSMESHAction( 6030, "EQUAL_FACE",      "ICON_EQUAL_FACE",    0, true );
3571   createSMESHAction( 6031, "EQUAL_VOLUME",    "ICON_EQUAL_VOLUME",  0, true );
3572   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
3573   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
3574   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
3575   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
3576   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
3577   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
3578   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
3579   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
3580   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
3581   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
3582   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
3583   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
3584   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
3585   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
3586   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
3587   createSMESHAction( 4008, "BALL",            "ICON_DLG_BALL" );
3588   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
3589   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
3590   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
3591   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
3592   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
3593   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
3594   createSMESHAction( 4133, "PENTA",           "ICON_DLG_PENTA" );
3595   createSMESHAction( 4134, "PYRAMID",         "ICON_DLG_PYRAMID" );
3596   createSMESHAction( 4135, "OCTA",            "ICON_DLG_OCTA" );
3597   createSMESHAction( 4033, "POLYHEDRON",              "ICON_DLG_POLYHEDRON" );
3598   createSMESHAction( 4034, "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
3599   createSMESHAction( 4035, "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
3600   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
3601   createSMESHAction( 4136, "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
3602   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3603   createSMESHAction( 4038, "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
3604   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3605   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3606   createSMESHAction( 4140, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
3607   createSMESHAction( 4041, "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
3608   createSMESHAction( 4042, "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
3609   createSMESHAction( 4044, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
3610   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
3611   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
3612   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
3613   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
3614   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
3615   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
3616   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
3617   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
3618   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
3619   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
3620   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
3621   createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
3622   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
3623   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
3624   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
3625   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
3626   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
3627   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
3628   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
3629   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
3630   createSMESHAction(  415, "MAP",             "ICON_MAP" );
3631   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
3632   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
3633   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
3634   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
3635   createSMESHAction(  420, "REORIENT_2D",     "ICON_REORIENT_2D" );
3636   createSMESHAction(  200, "RESET" );
3637   createSMESHAction(  201, "SCALAR_BAR_PROP" );
3638   createSMESHAction(  2021, "SAVE_DISTRIBUTION" );
3639   createSMESHAction(  2022, "SHOW_DISTRIBUTION","",0, true );
3640 #ifndef DISABLE_PLOT2DVIEWER
3641   createSMESHAction(  2023, "PLOT_DISTRIBUTION" );
3642 #endif
3643   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
3644   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
3645   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
3646   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
3647   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
3648   createSMESHAction(  222, "BALLS",          "ICON_DLG_BALL", 0, true );
3649   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
3650   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
3651   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
3652   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3653   createSMESHAction(  220, "ALL" );
3654   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3655
3656   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3657   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3658
3659   createSMESHAction( 1100, "EDIT_HYPO" );
3660   createSMESHAction( 1102, "UNASSIGN" );
3661   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3662   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3663   createSMESHAction( 1131, "DISPMODE" );
3664   createSMESHAction( 1132, "COLORS" );
3665   createSMESHAction( 1133, "TRANSP" );
3666   createSMESHAction( 1134, "CLIP" );
3667   createSMESHAction( 1135, "DISP_ENT" );
3668   createSMESHAction( 1136, "AUTO_COLOR" );
3669   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3670   createSMESHAction( 2000, "CTRL" );
3671
3672   createSMESHAction( 501, "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
3673   createSMESHAction( 502, "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
3674
3675   createSMESHAction( 300, "HIDE" );
3676   createSMESHAction( 301, "SHOW" );
3677   createSMESHAction( 302, "DISPLAY_ONLY" );
3678
3679   // ----- create menu --------------
3680   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
3681       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
3682       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
3683       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
3684       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
3685       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
3686       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
3687       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
3688
3689   createMenu( separator(), fileId );
3690
3691   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3692       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3693       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10 ),
3694       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10 ),
3695       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10 ),
3696       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10 ),
3697       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3698       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3699       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3700       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
3701
3702   createMenu( 111, importId, -1 );
3703   createMenu( 112, importId, -1 );
3704   createMenu( 113, importId, -1 );
3705   createMenu( 115, importId, -1 );
3706 #ifdef WITH_CGNS
3707   createMenu( 116, importId, -1 );
3708 #endif
3709   createMenu( 117, importId, -1 );
3710   createMenu( 121, exportId, -1 );
3711   createMenu( 122, exportId, -1 );
3712   createMenu( 123, exportId, -1 );
3713   createMenu( 140, exportId, -1 ); // export to STL
3714 #ifdef WITH_CGNS
3715   createMenu( 142, exportId, -1 ); // export to CGNS
3716 #endif
3717   createMenu( 144, exportId, -1 ); // export to SAUV
3718   createMenu( separator(), fileId, 10 );
3719
3720   createMenu( 33, editId, -1 );
3721
3722   createMenu( 5105, toolsId, -1 );
3723
3724   createMenu( 702, meshId, -1 ); // "Mesh" menu
3725   createMenu( 703, meshId, -1 );
3726   createMenu( 704, meshId, -1 );
3727   createMenu( 710, meshId, -1 );
3728   createMenu( 705, meshId, -1 );
3729   createMenu( separator(), meshId, -1 );
3730   createMenu( 701, meshId, -1 );
3731   createMenu( 711, meshId, -1 );
3732   createMenu( 712, meshId, -1 );
3733   createMenu( 713, meshId, -1 );
3734   createMenu( separator(), meshId, -1 );
3735   createMenu( 801, meshId, -1 );
3736   createMenu( 806, meshId, -1 );
3737   createMenu( 802, meshId, -1 );
3738   createMenu( 803, meshId, -1 );
3739   createMenu( 815, meshId, -1 );
3740   createMenu( separator(), meshId, -1 );
3741   createMenu( 810, meshId, -1 );
3742   createMenu( 811, meshId, -1 );
3743   createMenu( 812, meshId, -1 );
3744   createMenu( separator(), meshId, -1 );
3745   createMenu( 814, meshId, -1 );
3746   createMenu( separator(), meshId, -1 );
3747   createMenu( 900, meshId, -1 );
3748   //createMenu( 902, meshId, -1 );
3749   //createMenu( 903, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3750   createMenu( 904, meshId, -1 );
3751   createMenu( separator(), meshId, -1 );
3752
3753   createMenu( 6005, nodeId, -1 );
3754   createMenu( 6028, nodeId, -1 );
3755   createMenu( 6002, edgeId, -1 );
3756   createMenu( 6003, edgeId, -1 );
3757   createMenu( 6001, edgeId, -1 );
3758   createMenu( 6004, edgeId, -1 );
3759   createMenu( 6029, edgeId, -1 );
3760   createMenu( 6021, faceId, -1 );
3761   createMenu( 6025, faceId, -1 );
3762   createMenu( 6027, faceId, -1 );
3763   createMenu( 6018, faceId, -1 );
3764   createMenu( 6019, faceId, -1 );
3765   createMenu( 6011, faceId, -1 );
3766   createMenu( 6012, faceId, -1 );
3767   createMenu( 6013, faceId, -1 );
3768   createMenu( 6014, faceId, -1 );
3769   createMenu( 6015, faceId, -1 );
3770   createMenu( 6016, faceId, -1 );
3771   createMenu( 6022, faceId, -1 );
3772   createMenu( 6030, faceId, -1 );
3773   createMenu( 6017, volumeId, -1 );
3774   createMenu( 6009, volumeId, -1 );
3775   createMenu( 6023, volumeId, -1 );
3776   createMenu( 6024, volumeId, -1 );
3777   createMenu( 6026, volumeId, -1 );
3778   createMenu( 6031, volumeId, -1 );
3779
3780   createMenu( 4000, addId, -1 );
3781   createMenu( 4009, addId, -1 );
3782   createMenu( 4008, addId, -1 );
3783   createMenu( 4010, addId, -1 );
3784   createMenu( 4021, addId, -1 );
3785   createMenu( 4022, addId, -1 );
3786   createMenu( 4023, addId, -1 );
3787   createMenu( 4031, addId, -1 );
3788   createMenu( 4032, addId, -1 );
3789   createMenu( 4133, addId, -1 );
3790   createMenu( 4134, addId, -1 );
3791   createMenu( 4135, addId, -1 );
3792   createMenu( 4033, addId, -1 );
3793   createMenu( separator(), addId, -1 );
3794   createMenu( 4034, addId, -1 );
3795   createMenu( 4035, addId, -1 );
3796   createMenu( 4036, addId, -1 );
3797   createMenu( 4136, addId, -1 );
3798   createMenu( 4037, addId, -1 );
3799   createMenu( 4038, addId, -1 );
3800   createMenu( 4039, addId, -1 );
3801   createMenu( 4040, addId, -1 );
3802   createMenu( 4140, addId, -1 );
3803
3804   createMenu( 4041, removeId, -1 );
3805   createMenu( 4042, removeId, -1 );
3806   createMenu( 4044, removeId, -1 );
3807   createMenu( separator(), removeId, -1 );
3808   createMenu( 813, removeId, -1 );
3809   createMenu( separator(), removeId, -1 );
3810   createMenu( 4043, removeId, -1 );
3811
3812   createMenu( 4051, renumId, -1 );
3813   createMenu( 4052, renumId, -1 );
3814
3815   createMenu( 4061, transfId, -1 );
3816   createMenu( 4062, transfId, -1 );
3817   createMenu( 4063, transfId, -1 );
3818   createMenu( 4068, transfId, -1 );
3819   createMenu( 4064, transfId, -1 );
3820   createMenu( 4065, transfId, -1 );
3821   createMenu( 4066, transfId, -1 );
3822   createMenu( 4069, transfId, -1 );
3823
3824   createMenu( 4067,modifyId, -1 );
3825   createMenu( 407, modifyId, -1 );
3826   createMenu( 408, modifyId, -1 );
3827   createMenu( 409, modifyId, -1 );
3828   createMenu( 420, modifyId, -1 );
3829   createMenu( 410, modifyId, -1 );
3830   createMenu( 411, modifyId, -1 );
3831   createMenu( 419, modifyId, -1 );
3832   createMenu( 412, modifyId, -1 );
3833   createMenu( 413, modifyId, -1 );
3834   createMenu( 416, modifyId, -1 );
3835   createMenu( 414, modifyId, -1 );
3836   createMenu( 415, modifyId, -1 );
3837   createMenu( 417, modifyId, -1 );
3838   createMenu( 418, modifyId, -1 );
3839
3840   createMenu( 501, measureId, -1 );
3841   createMenu( 502, measureId, -1 );
3842   createMenu( 214, viewId, -1 );
3843
3844   // ----- create toolbars --------------
3845   int meshTb     = createTool( tr( "TB_MESH" ) ),
3846       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3847       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3848       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3849       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3850
3851   createTool( 702, meshTb );
3852   createTool( 703, meshTb );
3853   createTool( 704, meshTb );
3854   createTool( 710, meshTb );
3855   createTool( 705, meshTb );
3856   createTool( separator(), meshTb );
3857   createTool( 701, meshTb );
3858   createTool( 711, meshTb );
3859   createTool( 712, meshTb );
3860   createTool( 713, meshTb );
3861   createTool( separator(), meshTb );
3862   createTool( 801, meshTb );
3863   createTool( 806, meshTb );
3864   createTool( 802, meshTb );
3865   createTool( 803, meshTb );
3866   //createTool( 815, meshTb );
3867   createTool( separator(), meshTb );
3868   createTool( 900, meshTb );
3869   //createTool( 902, meshTb );
3870   //createTool( 903, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3871   createTool( 904, meshTb );
3872   createTool( separator(), meshTb );
3873
3874   createTool( 6005, ctrlTb );
3875   createTool( 6028, ctrlTb );
3876   createTool( separator(), ctrlTb );
3877   createTool( 6002, ctrlTb );
3878   createTool( 6003, ctrlTb );
3879   createTool( 6001, ctrlTb );
3880   createTool( 6004, ctrlTb );
3881   createTool( 6029, ctrlTb );
3882   createTool( separator(), ctrlTb );
3883   createTool( 6021, ctrlTb );
3884   createTool( 6025, ctrlTb );
3885   createTool( 6027, ctrlTb );
3886   createTool( 6018, ctrlTb );
3887   createTool( 6019, ctrlTb );
3888   createTool( 6011, ctrlTb );
3889   createTool( 6012, ctrlTb );
3890   createTool( 6013, ctrlTb );
3891   createTool( 6014, ctrlTb );
3892   createTool( 6015, ctrlTb );
3893   createTool( 6016, ctrlTb );
3894   createTool( 6022, ctrlTb );
3895   createTool( 6030, ctrlTb );
3896   createTool( separator(), ctrlTb );
3897   createTool( 6017, ctrlTb );
3898   createTool( 6009, ctrlTb );
3899   createTool( 6023, ctrlTb );
3900   createTool( 6024, ctrlTb );
3901   createTool( 6026, ctrlTb );
3902   createTool( 6031, ctrlTb );
3903   createTool( separator(), ctrlTb );
3904
3905   createTool( 4000, addRemTb );
3906   createTool( 4009, addRemTb );
3907   createTool( 4008, addRemTb );
3908   createTool( 4010, addRemTb );
3909   createTool( 4021, addRemTb );
3910   createTool( 4022, addRemTb );
3911   createTool( 4023, addRemTb );
3912   createTool( 4031, addRemTb );
3913   createTool( 4032, addRemTb );
3914   createTool( 4133, addRemTb );
3915   createTool( 4134, addRemTb );
3916   createTool( 4135, addRemTb );
3917   createTool( 4033, addRemTb );
3918   createTool( separator(), addRemTb );
3919   createTool( 4034, addRemTb );
3920   createTool( 4035, addRemTb );
3921   createTool( 4036, addRemTb );
3922   createTool( 4136, addRemTb );
3923   createTool( 4037, addRemTb );
3924   createTool( 4038, addRemTb );
3925   createTool( 4039, addRemTb );
3926   createTool( 4040, addRemTb );
3927   createTool( 4140, addRemTb );
3928   createTool( separator(), addRemTb );
3929   createTool( 4041, addRemTb );
3930   createTool( 4042, addRemTb );
3931   createTool( 4044, addRemTb );
3932   createTool( 4043, addRemTb );
3933   createTool( separator(), addRemTb );
3934   createTool( 4051, addRemTb );
3935   createTool( 4052, addRemTb );
3936   createTool( separator(), addRemTb );
3937   createTool( 4061, addRemTb );
3938   createTool( 4062, addRemTb );
3939   createTool( 4063, addRemTb );
3940   createTool( 4068, addRemTb );
3941   createTool( 4064, addRemTb );
3942   createTool( 4065, addRemTb );
3943   createTool( 4066, addRemTb );
3944   createTool( 4069, addRemTb );
3945   createTool( separator(), addRemTb );
3946
3947   createTool( 4067,modifyTb );
3948   createTool( 407, modifyTb );
3949   createTool( 408, modifyTb );
3950   createTool( 409, modifyTb );
3951   createTool( 420, modifyTb );
3952   createTool( 410, modifyTb );
3953   createTool( 411, modifyTb );
3954   createTool( 419, modifyTb );
3955   createTool( 412, modifyTb );
3956   createTool( 413, modifyTb );
3957   createTool( 416, modifyTb );
3958   createTool( 414, modifyTb );
3959   createTool( 415, modifyTb );
3960   createTool( 417, modifyTb );
3961   createTool( 418, modifyTb );
3962
3963   createTool( 214, dispModeTb );
3964
3965   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3966   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3967
3968   myRules.clear();
3969   QString OB = "'ObjectBrowser'",
3970           View = "'" + SVTK_Viewer::Type() + "'",
3971           pat = "'%1'",
3972           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3973           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3974           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3975           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3976           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3977                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3978                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3979                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3980                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3981                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3982                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3983           subMesh = elems,
3984           mesh_part = mesh + " " + subMesh + " " + group,
3985           mesh_group = mesh + " " + group,
3986           hyp_alg = hypo + " " + algo;
3987
3988   // popup for object browser
3989   QString
3990     isInvisible("not( isVisible )"),
3991     isEmpty("numberOfNodes = 0"),
3992     isNotEmpty("numberOfNodes <> 0"),
3993
3994     // has nodes, edges, etc in VISIBLE! actor
3995     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3996     hasElems("(count( elemTypes ) > 0)"),
3997     hasDifferentElems("(count( elemTypes ) > 1)"),
3998     hasBalls("({'BallElem'} in elemTypes)"),
3999     hasElems0d("({'Elem0d'} in elemTypes)"),
4000     hasEdges("({'Edge'} in elemTypes)"),
4001     hasFaces("({'Face'} in elemTypes)"),
4002     hasVolumes("({'Volume'} in elemTypes)");
4003
4004   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
4005   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
4006   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
4007   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
4008   createPopupItem( 803, OB, group );                       // EDIT_GROUP
4009   createPopupItem( 815, OB, group, "&& groupType != 'Group'" ); // EDIT AS STANDALONE
4010
4011   popupMgr()->insert( separator(), -1, 0 );
4012   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
4013   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
4014   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
4015   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
4016   createPopupItem( 214, OB, mesh_part );                   // UPDATE
4017   createPopupItem( 900, OB, mesh_part );                   // ADV_INFO
4018   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
4019   popupMgr()->insert( separator(), -1, 0 );
4020   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
4021   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
4022   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
4023   popupMgr()->insert( separator(), -1, 0 );
4024   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
4025   createPopupItem( 1102, OB, hyp_alg );                    // REMOVE HYPOTHESIS / ALGORITHMS
4026   popupMgr()->insert( separator(), -1, 0 );
4027   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
4028   popupMgr()->insert( separator(), -1, 0 );
4029   createPopupItem( 417, OB, mesh + " " + subMesh );        // convert to quadratic
4030   createPopupItem( 418, OB, mesh + " " + group,            // create 2D mesh from 3D
4031                    "&& dim>=2");
4032   popupMgr()->insert( separator(), -1, 0 );
4033
4034   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
4035   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
4036   QString only_one_2D        = only_one_non_empty + " && dim>1";
4037
4038   createPopupItem( 125, OB, mesh_group, multiple_non_empty );   // EXPORT_MED
4039   createPopupItem( 126, OB, mesh_group, only_one_non_empty );   // EXPORT_UNV
4040   createPopupItem( 141, OB, mesh_group, only_one_2D );          // EXPORT_STL
4041 #ifdef WITH_CGNS
4042   createPopupItem( 143, OB, mesh_group, multiple_non_empty );   // EXPORT_CGNS
4043 #endif
4044   createPopupItem( 145, OB, mesh_group, multiple_non_empty );   // EXPORT_SAUV
4045   createPopupItem(  33, OB, mesh_part + " " + hyp_alg );        // DELETE
4046   createPopupItem( 813, OB, group );                            // DEL_GROUP with contents
4047   popupMgr()->insert( separator(), -1, 0 );
4048
4049   // popup for viewer
4050   createPopupItem( 803, View, group ); // EDIT_GROUP
4051   createPopupItem( 804, View, elems ); // ADD
4052   createPopupItem( 805, View, elems ); // REMOVE
4053
4054   popupMgr()->insert( separator(), -1, 0 );
4055   createPopupItem( 214, View, mesh_part );  // UPDATE
4056   createPopupItem( 900, View, mesh_part );  // ADV_INFO
4057   createPopupItem( 904, View, mesh );       // FIND_ELEM
4058   popupMgr()->insert( separator(), -1, 0 );
4059
4060   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
4061   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
4062   popupMgr()->insert( separator(), -1, 0 );
4063
4064   int anId;
4065   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
4066   QString aType = QString( "%1type in {%2}" ).arg( lc );
4067   aType = aType.arg( mesh_part );
4068   QString aMeshInVTK = aClient + "&&" + aType;
4069
4070   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
4071   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
4072   QString aSelCount = QString( "%1 > 0" ).arg( dc );
4073
4074   //-------------------------------------------------
4075   // Numbering
4076   //-------------------------------------------------
4077   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
4078
4079   popupMgr()->insert( action( 9010 ), anId, -1 );
4080   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4081   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4082
4083   popupMgr()->insert( action( 9011 ), anId, -1 );
4084   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4085   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4086
4087   popupMgr()->insert( separator(), -1, -1 );
4088
4089   //-------------------------------------------------
4090   // Display Mode
4091   //-------------------------------------------------
4092   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4093
4094   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
4095   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4096   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4097
4098   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
4099   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4100   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4101
4102   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
4103   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
4104   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4105
4106   popupMgr()->insert( separator(), anId, -1 );
4107
4108   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
4109   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4110   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4111
4112   //-------------------------------------------------
4113   // Display Entity
4114   //-------------------------------------------------
4115   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4116
4117   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4118
4119   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
4120   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4121   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4122
4123   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
4124   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4125   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4126
4127   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
4128   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4129   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4130
4131   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
4132   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4133   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4134
4135   popupMgr()->insert( action( 222 ), anId, -1 ); // BALLS
4136   popupMgr()->setRule( action( 222 ), aDiffElemsInVTK + "&& isVisible &&" + hasBalls, QtxPopupMgr::VisibleRule );
4137   popupMgr()->setRule( action( 222 ), "{'BallElem'} in entityMode", QtxPopupMgr::ToggleRule );
4138
4139   popupMgr()->insert( separator(), anId, -1 );
4140
4141   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
4142   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4143
4144
4145   //-------------------------------------------------
4146   // Representation of the 2D Quadratic elements
4147   //-------------------------------------------------
4148   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4149   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
4150   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
4151   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4152
4153   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
4154   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
4155   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4156
4157   //-------------------------------------------------
4158   // Orientation of faces
4159   //-------------------------------------------------
4160   popupMgr()->insert( action( 221 ), -1, -1 );
4161   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4162   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4163
4164   //-------------------------------------------------
4165   // Color / Size
4166   //-------------------------------------------------
4167   popupMgr()->insert( action( 1132 ), -1, -1 );
4168   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4169
4170   //-------------------------------------------------
4171   // Transparency
4172   //-------------------------------------------------
4173   popupMgr()->insert( action( 1133 ), -1, -1 );
4174   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4175
4176   //-------------------------------------------------
4177   // Controls
4178   //-------------------------------------------------
4179   QString
4180     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
4181     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
4182     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
4183     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4184
4185   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4186
4187   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
4188   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4189
4190   popupMgr()->insert( separator(), anId, -1 );
4191
4192   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4193
4194   popupMgr()->insert( action( 6005 ), aSubId, -1 ); // FREE_NODE
4195   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4196   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4197
4198   popupMgr()->insert ( action( 6028 ), aSubId, -1 ); // EQUAL_NODE
4199   popupMgr()->setRule( action( 6028 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4200   popupMgr()->setRule( action( 6028 ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4201
4202   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4203
4204   popupMgr()->insert( action( 6002 ), aSubId, -1 ); // FREE_EDGE
4205   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4206   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4207
4208   popupMgr()->insert( action( 6003 ), aSubId, -1 ); // FREE_BORDER
4209   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4210   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4211
4212   popupMgr()->insert( action( 6001 ), aSubId, -1 ); // LENGTH
4213   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4214   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4215
4216   popupMgr()->insert( action( 6004 ), aSubId, -1 ); // CONNECTION
4217   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4218   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4219   popupMgr()->insert ( action( 6029 ), aSubId, -1 ); // EQUAL_EDGE
4220   popupMgr()->setRule( action( 6029 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4221   popupMgr()->setRule( action( 6029 ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4222
4223   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4224
4225   popupMgr()->insert ( action( 6021 ), aSubId, -1 ); // FREE_FACE
4226   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4227                                        QtxPopupMgr::VisibleRule );
4228   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4229
4230   popupMgr()->insert ( action( 6018 ), aSubId, -1 ); // LENGTH_2D
4231   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4232   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4233
4234   popupMgr()->insert ( action( 6019 ), aSubId, -1 ); // CONNECTION_2D
4235   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4236   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4237
4238   popupMgr()->insert ( action( 6011 ), aSubId, -1 ); // AREA
4239   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4240   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4241
4242   popupMgr()->insert ( action( 6012 ), aSubId, -1 ); // TAPER
4243   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4244   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4245
4246   popupMgr()->insert ( action( 6013 ), aSubId, -1 ); // ASPECT
4247   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4248   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4249
4250   popupMgr()->insert ( action( 6014 ), aSubId, -1 ); // MIN_ANG
4251   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4252   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4253
4254   popupMgr()->insert ( action( 6015 ), aSubId, -1 ); // WARP
4255   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4256   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4257
4258   popupMgr()->insert ( action( 6016 ), aSubId, -1 ); // SKEW
4259   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4260   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4261
4262   popupMgr()->insert ( action( 6022 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_2D
4263   popupMgr()->setRule( action( 6022 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4264   popupMgr()->setRule( action( 6022 ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4265
4266   popupMgr()->insert ( action( 6025 ), aSubId, -1 ); // BARE_BORDER_FACE
4267   popupMgr()->setRule( action( 6025 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4268   popupMgr()->setRule( action( 6025 ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4269
4270   popupMgr()->insert ( action( 6027 ), aSubId, -1 ); // OVER_CONSTRAINED_FACE
4271   popupMgr()->setRule( action( 6027 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4272   popupMgr()->setRule( action( 6027 ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4273   popupMgr()->insert ( action( 6030 ), aSubId, -1 ); // EQUAL_FACE
4274   popupMgr()->setRule( action( 6030 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4275   popupMgr()->setRule( action( 6030 ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4276
4277   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4278
4279   popupMgr()->insert ( action( 6017 ), aSubId, -1 ); // ASPECT_3D
4280   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4281   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4282
4283   popupMgr()->insert ( action( 6009 ), aSubId, -1 ); // VOLUME_3D
4284   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4285   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4286
4287   popupMgr()->insert ( action( 6023 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_3D
4288   popupMgr()->setRule( action( 6023 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4289   popupMgr()->setRule( action( 6023 ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4290
4291   popupMgr()->insert ( action( 6024 ), aSubId, -1 ); // BARE_BORDER_VOLUME
4292   popupMgr()->setRule( action( 6024 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4293   popupMgr()->setRule( action( 6024 ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4294
4295   popupMgr()->insert ( action( 6026 ), aSubId, -1 ); // OVER_CONSTRAINED_VOLUME
4296   popupMgr()->setRule( action( 6026 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4297   popupMgr()->setRule( action( 6026 ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4298
4299   popupMgr()->insert ( action( 6031 ), aSubId, -1 ); // EQUAL_VOLUME
4300   popupMgr()->setRule( action( 6031 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4301   popupMgr()->setRule( action( 6031 ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
4302
4303   popupMgr()->insert( separator(), anId, -1 );
4304
4305   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
4306   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4307
4308   popupMgr()->insert( separator(), anId, -1 );
4309
4310   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4311
4312   popupMgr()->insert( action( 2021 ), aSubId, -1 ); // SAVE_DISTRIBUTION
4313   popupMgr()->setRule( action( 2021 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4314
4315   popupMgr()->insert( action( 2022 ), aSubId, -1 ); // SHOW_DISTRIBUTION
4316   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4317   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor && isDistributionVisible", QtxPopupMgr::ToggleRule);
4318
4319 #ifndef DISABLE_PLOT2DVIEWER
4320   popupMgr()->insert( action( 2023 ), aSubId, -1 ); // PLOT_DISTRIBUTION
4321   popupMgr()->setRule( action( 2023 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4322 #endif
4323
4324   //-------------------------------------------------
4325   // Display / Erase
4326   //-------------------------------------------------
4327   popupMgr()->insert( separator(), -1, -1 );
4328   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4329     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4330   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
4331   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4332
4333   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
4334   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4335
4336   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
4337   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4338
4339   popupMgr()->insert( separator(), -1, -1 );
4340
4341   //-------------------------------------------------
4342   // Clipping
4343   //-------------------------------------------------
4344   popupMgr()->insert( action( 1134 ), -1, -1 );
4345   popupMgr()->setRule( action( 1134 ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4346
4347   popupMgr()->insert( separator(), -1, -1 );
4348
4349   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4350            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4351
4352   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4353            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4354 }
4355
4356 //================================================================================
4357 /*!
4358  * \brief Return true if SMESH or GEOM objects are selected.
4359  * Is called form LightApp_Module::activateModule() which clear selection if
4360  * not isSelectionCompatible()
4361  */
4362 //================================================================================
4363
4364 bool SMESHGUI::isSelectionCompatible()
4365 {
4366   bool isCompatible = true;
4367   SALOME_ListIO selected;
4368   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4369     Sel->selectedObjects( selected );
4370
4371   SALOME_ListIteratorOfListIO It( selected );
4372   for ( ; isCompatible && It.More(); It.Next())
4373     isCompatible =
4374       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4375       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4376
4377   return isCompatible;
4378 }
4379
4380
4381 bool SMESHGUI::reusableOperation( const int id )
4382 {
4383   // compute, evaluate and precompute are not reusable operations
4384   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
4385 }
4386
4387 bool SMESHGUI::activateModule( SUIT_Study* study )
4388 {
4389   bool res = SalomeApp_Module::activateModule( study );
4390
4391   setMenuShown( true );
4392   setToolShown( true );
4393
4394   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4395   PyGILState_STATE gstate = PyGILState_Ensure();
4396   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
4397   if(pluginsmanager==NULL)
4398     PyErr_Print();
4399   else
4400     {
4401       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
4402       if(result==NULL)
4403         PyErr_Print();
4404       Py_XDECREF(result);
4405     }
4406   PyGILState_Release(gstate);
4407   // end of GEOM plugins loading
4408
4409   // Reset actions accelerator keys
4410   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
4411   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
4412   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
4413
4414   action(  33)->setEnabled(true); // Delete: Key_Delete
4415
4416   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4417   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
4418   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
4419     if ( _PTR(Study) aStudy = s->studyDS()) {
4420       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
4421       updateObjBrowser(); // objects can be removed
4422     }
4423
4424   // get all view currently opened in the study and connect their signals  to
4425   // the corresponding slots of the class.
4426   SUIT_Desktop* aDesk = study->application()->desktop();
4427   if ( aDesk ) {
4428     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4429     SUIT_ViewWindow* wnd;
4430     foreach ( wnd, wndList )
4431       connectView( wnd );
4432   }
4433
4434   return res;
4435 }
4436
4437 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4438 {
4439   setMenuShown( false );
4440   setToolShown( false );
4441
4442   EmitSignalCloseAllDialogs();
4443
4444   // Unset actions accelerator keys
4445   action(111)->setShortcut(QKeySequence()); // Import DAT
4446   action(112)->setShortcut(QKeySequence()); // Import UNV
4447   action(113)->setShortcut(QKeySequence()); // Import MED
4448
4449   action(  33)->setEnabled(false); // Delete: Key_Delete
4450
4451   return SalomeApp_Module::deactivateModule( study );
4452 }
4453
4454 void SMESHGUI::studyClosed( SUIT_Study* s )
4455 {
4456   SMESH::RemoveVisuData( s->id() );
4457   SalomeApp_Module::studyClosed( s );
4458 }
4459
4460 void SMESHGUI::OnGUIEvent()
4461 {
4462   const QObject* obj = sender();
4463   if ( !obj || !obj->inherits( "QAction" ) )
4464     return;
4465   int id = actionId((QAction*)obj);
4466   if ( id != -1 )
4467     OnGUIEvent( id );
4468 }
4469
4470 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
4471 {
4472   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
4473   if ( CORBA::is_nil( myComponentSMESH ) )
4474     {
4475       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
4476       if ( aStudy )
4477         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4478       return aGUI.myComponentSMESH;
4479     }
4480   if ( aStudy )
4481     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4482   return myComponentSMESH;
4483 }
4484
4485 QString SMESHGUI::engineIOR() const
4486 {
4487   CORBA::ORB_var anORB = getApp()->orb();
4488   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
4489   return QString( anIOR.in() );
4490 }
4491
4492 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
4493 {
4494   SalomeApp_Module::contextMenuPopup( client, menu, title );
4495   SALOME_ListIO lst;
4496   selectionMgr()->selectedObjects( lst );
4497   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
4498     Handle(SALOME_InteractiveObject) io = lst.First();
4499     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
4500     _PTR(Study) study = appStudy->studyDS();
4501     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
4502     if ( obj ) {
4503       QString aName = QString( obj->GetName().c_str() );
4504       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
4505           aName.remove( (aName.length() - 1), 1 );
4506       title = aName;
4507     }
4508   }
4509 }
4510
4511 LightApp_Selection* SMESHGUI::createSelection() const
4512 {
4513   return new SMESHGUI_Selection();
4514 }
4515
4516 void SMESHGUI::windows( QMap<int, int>& aMap ) const
4517 {
4518   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
4519   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
4520 }
4521
4522 void SMESHGUI::viewManagers( QStringList& list ) const
4523 {
4524   list.append( SVTK_Viewer::Type() );
4525 }
4526
4527 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
4528 {
4529   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
4530     SMESH::UpdateSelectionProp( this );
4531
4532     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
4533     for(int i = 0; i < aViews.count() ; i++){
4534       SUIT_ViewWindow *sf = aViews[i];
4535       connectView( sf );
4536     }
4537   }
4538 }
4539
4540 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
4541 {
4542   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
4543     myClippingPlaneInfoMap.erase( theViewManager );
4544 }
4545
4546 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
4547 {
4548   theActor->AddObserver( SMESH::DeleteActorEvent,
4549                          myEventCallbackCommand.GetPointer(),
4550                          myPriority );
4551 }
4552
4553 void SMESHGUI::ProcessEvents( vtkObject* theObject,
4554                               unsigned long theEvent,
4555                               void* theClientData,
4556                               void* theCallData )
4557 {
4558   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
4559     if( theObject && theEvent == SMESH::DeleteActorEvent ) {
4560       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
4561         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
4562         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
4563         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
4564           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
4565           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
4566           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
4567             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
4568             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
4569             SMESH::TActorList::iterator anIter3 = anActorList.begin();
4570             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
4571               if( anActor == *anIter3 ) {
4572                 anActorList.erase( anIter3 );
4573                 break;
4574               }
4575             }
4576           }
4577         }
4578       }
4579     }
4580   }
4581 }
4582
4583 void SMESHGUI::createPreferences()
4584 {
4585   // General tab ------------------------------------------------------------------------
4586   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
4587
4588   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
4589   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
4590   setPreferenceProperty( lim, "min",  0 );
4591   setPreferenceProperty( lim, "max",  100000000 );
4592   setPreferenceProperty( lim, "step", 1000 );
4593   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4594
4595   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
4596   setPreferenceProperty( qaGroup, "columns", 2 );
4597   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
4598   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
4599   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
4600   setPreferenceProperty( prec, "min", 0 );
4601   setPreferenceProperty( prec, "max", 16 );
4602   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
4603   setPreferenceProperty( doubleNodesTol, "precision", 10 );
4604   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
4605   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
4606   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
4607
4608   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
4609   setPreferenceProperty( dispgroup, "columns", 2 );
4610   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
4611   QStringList modes;
4612   modes.append( tr("MEN_WIRE") );
4613   modes.append( tr("MEN_SHADE") );
4614   modes.append( tr("MEN_NODES") );
4615   modes.append( tr("MEN_SHRINK") );
4616   QList<QVariant> indices;
4617   indices.append( 0 );
4618   indices.append( 1 );
4619   indices.append( 2 );
4620   indices.append( 3 );
4621   setPreferenceProperty( dispmode, "strings", modes );
4622   setPreferenceProperty( dispmode, "indexes", indices );
4623
4624   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
4625   setPreferenceProperty( arcgroup, "columns", 2 );
4626   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
4627   QStringList quadraticModes;
4628   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
4629   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
4630   indices.clear();
4631   indices.append( 0 );
4632   indices.append( 1 );
4633   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
4634   setPreferenceProperty( quadraticmode, "indexes", indices );
4635
4636   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
4637                               "SMESH", "max_angle" );
4638   setPreferenceProperty( maxAngle, "min", 1 );
4639   setPreferenceProperty( maxAngle, "max", 90 );
4640
4641
4642
4643   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
4644   setPreferenceProperty( exportgroup, "columns", 2 );
4645   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
4646   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
4647
4648   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
4649   setPreferenceProperty( computeGroup, "columns", 2 );
4650   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
4651   modes.clear();
4652   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
4653   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
4654   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
4655   indices.clear();
4656   indices.append( 0 );
4657   indices.append( 1 );
4658   indices.append( 2 );
4659   setPreferenceProperty( notifyMode, "strings", modes );
4660   setPreferenceProperty( notifyMode, "indexes", indices );
4661
4662   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
4663   setPreferenceProperty( infoGroup, "columns", 4 );
4664   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
4665   modes.clear();
4666   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
4667   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
4668   indices.clear();
4669   indices.append( 0 );
4670   indices.append( 1 );
4671   setPreferenceProperty( elemInfo, "strings", modes );
4672   setPreferenceProperty( elemInfo, "indexes", indices );
4673   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
4674   setPreferenceProperty( nodesLim, "min", 0 );
4675   setPreferenceProperty( nodesLim, "max", 10000000 );
4676   setPreferenceProperty( nodesLim, "step", 10000 );
4677   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4678
4679   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
4680   setPreferenceProperty( segGroup, "columns", 2 );
4681   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
4682                               "SMESH", "segmentation" );
4683   setPreferenceProperty( segLen, "min", 1 );
4684   setPreferenceProperty( segLen, "max", 10000000 );
4685   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
4686                              "SMESH", "nb_segments_per_edge" );
4687   setPreferenceProperty( nbSeg, "min", 1 );
4688   setPreferenceProperty( nbSeg, "max", 10000000 );
4689
4690   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
4691   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
4692                  "SMESH", "forget_mesh_on_hyp_modif" );
4693
4694
4695   // Quantities with individual precision settings
4696   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
4697   setPreferenceProperty( precGroup, "columns", 2 );
4698
4699   const int nbQuantities = 6;
4700   int precs[nbQuantities], ii = 0;
4701   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
4702                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
4703   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
4704                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
4705   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
4706                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
4707   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
4708                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
4709   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
4710                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
4711   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
4712                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
4713
4714   // Set property for precision value for spinboxes
4715   for ( ii = 0; ii < nbQuantities; ii++ ){
4716     setPreferenceProperty( precs[ii], "min", -14 );
4717     setPreferenceProperty( precs[ii], "max", 14 );
4718     setPreferenceProperty( precs[ii], "precision", 2 );
4719   }
4720
4721   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
4722   setPreferenceProperty( previewGroup, "columns", 2 );
4723   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
4724   setPreferenceProperty( chunkSize, "min",  0 );
4725   setPreferenceProperty( chunkSize, "max",  1000 );
4726   setPreferenceProperty( chunkSize, "step", 50 );
4727
4728   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
4729   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
4730
4731   // Mesh tab ------------------------------------------------------------------------
4732   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
4733   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
4734   setPreferenceProperty( nodeGroup, "columns", 3 );
4735
4736   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
4737
4738   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
4739
4740   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4741   QList<QVariant> aMarkerTypeIndicesList;
4742   QList<QVariant> aMarkerTypeIconsList;
4743   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
4744     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
4745     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
4746     aMarkerTypeIndicesList << i;
4747     aMarkerTypeIconsList << pixmap;
4748   }
4749   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
4750   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
4751
4752   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
4753
4754   QList<QVariant> aMarkerScaleIndicesList;
4755   QStringList     aMarkerScaleValuesList;
4756   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
4757     aMarkerScaleIndicesList << i;
4758     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
4759   }
4760   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
4761   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
4762
4763   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
4764   setPreferenceProperty( elemGroup, "columns", 2 );
4765
4766   int ColorId = addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
4767   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
4768   addPreference( tr( "PREF_BALL_COLOR" ), elemGroup, LightApp_Preferences::Color, "SMESH", "ball_elem_color" );
4769   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
4770   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
4771
4772   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
4773
4774   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
4775   setPreferenceProperty( grpGroup, "columns", 2 );
4776
4777   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
4778
4779   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
4780                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
4781   int ballSize = addPreference(tr("PREF_BALL_SIZE"), elemGroup,
4782                              LightApp_Preferences::IntSpin, "SMESH", "ball_elem_size");
4783   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
4784                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
4785   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
4786                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
4787
4788   setPreferenceProperty( size0d, "min", 1 );
4789   setPreferenceProperty( size0d, "max", 10 );
4790
4791   setPreferenceProperty( ballSize, "min", 1 );
4792   setPreferenceProperty( ballSize, "max", 10 );
4793
4794   setPreferenceProperty( elemW, "min", 1 );
4795   setPreferenceProperty( elemW, "max", 5 );
4796
4797   setPreferenceProperty( shrink, "min", 0 );
4798   setPreferenceProperty( shrink, "max", 100 );
4799
4800   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
4801   setPreferenceProperty( orientGroup, "columns", 1 );
4802
4803   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
4804   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
4805
4806   setPreferenceProperty( orientScale, "min", 0.05 );
4807   setPreferenceProperty( orientScale, "max", 0.5 );
4808   setPreferenceProperty( orientScale, "step", 0.05 );
4809
4810   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
4811
4812   // Selection tab ------------------------------------------------------------------------
4813   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
4814
4815   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
4816   setPreferenceProperty( selGroup, "columns", 2 );
4817
4818   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
4819   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
4820
4821   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
4822   setPreferenceProperty( preGroup, "columns", 2 );
4823
4824   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
4825
4826   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
4827   setPreferenceProperty( precSelGroup, "columns", 2 );
4828
4829   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
4830   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
4831   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
4832
4833   // Scalar Bar tab ------------------------------------------------------------------------
4834   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
4835   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
4836   setPreferenceProperty( fontGr, "columns", 2 );
4837
4838   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
4839   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
4840
4841   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
4842   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
4843
4844   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
4845   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
4846
4847   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
4848   setPreferenceProperty( numcol, "min", 2 );
4849   setPreferenceProperty( numcol, "max", 256 );
4850
4851   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
4852   setPreferenceProperty( numlab, "min", 2 );
4853   setPreferenceProperty( numlab, "max", 65 );
4854
4855   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
4856   setPreferenceProperty( orientGr, "columns", 2 );
4857   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
4858   QStringList orients;
4859   orients.append( tr( "SMESH_VERTICAL" ) );
4860   orients.append( tr( "SMESH_HORIZONTAL" ) );
4861   indices.clear(); indices.append( 0 ); indices.append( 1 );
4862   setPreferenceProperty( orient, "strings", orients );
4863   setPreferenceProperty( orient, "indexes", indices );
4864
4865   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
4866   setPreferenceProperty( posVSizeGr, "columns", 2 );
4867   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
4868   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
4869   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
4870   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
4871   setPreferenceProperty( xv, "step", 0.1 );
4872   setPreferenceProperty( xv, "min", 0.0 );
4873   setPreferenceProperty( xv, "max", 1.0 );
4874   setPreferenceProperty( yv, "step", 0.1 );
4875   setPreferenceProperty( yv, "min", 0.0 );
4876   setPreferenceProperty( yv, "max", 1.0 );
4877   setPreferenceProperty( wv, "step", 0.1 );
4878   setPreferenceProperty( wv, "min", 0.0 );
4879   setPreferenceProperty( wv, "max", 1.0 );
4880   setPreferenceProperty( hv, "min", 0.0 );
4881   setPreferenceProperty( hv, "max", 1.0 );
4882   setPreferenceProperty( hv, "step", 0.1 );
4883
4884   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4885   setPreferenceProperty( posHSizeGr, "columns", 2 );
4886   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4887   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4888   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4889   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4890   setPreferenceProperty( xv, "min", 0.0 );
4891   setPreferenceProperty( xv, "max", 1.0 );
4892   setPreferenceProperty( xv, "step", 0.1 );
4893   setPreferenceProperty( xh, "min", 0.0 );
4894   setPreferenceProperty( xh, "max", 1.0 );
4895   setPreferenceProperty( xh, "step", 0.1 );
4896   setPreferenceProperty( yh, "min", 0.0 );
4897   setPreferenceProperty( yh, "max", 1.0 );
4898   setPreferenceProperty( yh, "step", 0.1 );
4899   setPreferenceProperty( wh, "min", 0.0 );
4900   setPreferenceProperty( wh, "max", 1.0 );
4901   setPreferenceProperty( wh, "step", 0.1 );
4902   setPreferenceProperty( hh, "min", 0.0 );
4903   setPreferenceProperty( hh, "max", 1.0 );
4904   setPreferenceProperty( hh, "step", 0.1 );
4905
4906   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
4907   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
4908   setPreferenceProperty( distributionGr, "columns", 3 );
4909   QStringList types;
4910   types.append( tr( "SMESH_MONOCOLOR" ) );
4911   types.append( tr( "SMESH_MULTICOLOR" ) );
4912   indices.clear(); indices.append( 0 ); indices.append( 1 );
4913   setPreferenceProperty( coloringType, "strings", types );
4914   setPreferenceProperty( coloringType, "indexes", indices );
4915   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
4916
4917 }
4918
4919 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4920 {
4921   if( sect=="SMESH" ) {
4922     float sbX1,sbY1,sbW,sbH;
4923     float aTol = 1.00000009999999;
4924     std::string aWarning;
4925     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4926     if( name=="selection_object_color" || name=="selection_element_color" ||
4927         name=="highlight_color" ||
4928         name=="selection_precision_node" || name=="selection_precision_element" ||
4929         name=="selection_precision_object")
4930       SMESH::UpdateSelectionProp( this );
4931     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4932       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4933       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4934       if(sbX1+sbW > aTol){
4935         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4936         sbX1=0.01;
4937         sbW=0.08;
4938         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4939         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4940       }
4941     }
4942     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4943       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4944       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4945       if(sbY1+sbH > aTol){
4946         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4947         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4948         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4949       }
4950     }
4951     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4952       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4953       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4954       if(sbX1+sbW > aTol){
4955         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4956         sbX1=0.1;
4957         sbW=0.08;
4958         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4959         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4960       }
4961     }
4962     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4963       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4964       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4965       if(sbY1+sbH > aTol){
4966         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4967         sbY1=0.01;
4968         sbH=0.08;
4969         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4970         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4971       }
4972     }
4973     else if ( name == "segmentation" ) {
4974       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4975       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4976     }
4977     else if ( name == "nb_segments_per_edge" ) {
4978       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4979       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4980     }
4981     else if ( name == "historical_python_dump" ||
4982               name == "forget_mesh_on_hyp_modif") {
4983       QString val = aResourceMgr->stringValue( "SMESH", name );
4984       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
4985     }
4986
4987     if(aWarning.size() != 0){
4988       aWarning += "The default values are applied instead.";
4989       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4990                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4991                                QObject::tr(aWarning.c_str()));
4992     }
4993   }
4994 }
4995
4996 //================================================================================
4997 /*!
4998  * \brief Update something in accordance with update flags
4999   * \param theFlags - update flags
5000 *
5001 * Update viewer or/and object browser etc. in accordance with update flags ( see
5002 * LightApp_UpdateFlags enumeration ).
5003 */
5004 //================================================================================
5005 void SMESHGUI::update( const int flags )
5006 {
5007   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5008     SMESH::UpdateView();
5009   else
5010     SalomeApp_Module::update( flags );
5011 }
5012
5013 //================================================================================
5014 /*!
5015  * \brief Set default selection mode
5016 *
5017 * SLOT called when operation commited. Sets default selection mode
5018 */
5019 //================================================================================
5020 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5021 {
5022   SVTK_ViewWindow* vtkWnd =
5023     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5024   if ( vtkWnd )
5025     vtkWnd->SetSelectionMode( ActorSelection );
5026 }
5027
5028 //================================================================================
5029 /*!
5030  * \brief Set default selection mode
5031 *
5032 * SLOT called when operation aborted. Sets default selection mode
5033 */
5034 //================================================================================
5035 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5036 {
5037   SVTK_ViewWindow* vtkWnd =
5038     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5039   if ( vtkWnd )
5040     vtkWnd->SetSelectionMode( ActorSelection );
5041 }
5042
5043 //================================================================================
5044 /*!
5045  * \brief Creates operation with given identifier
5046   * \param id - identifier of operation to be started
5047   * \return Pointer on created operation or NULL if operation is not created
5048 *
5049 * Virtual method redefined from the base class creates operation with given id.
5050 * It is called called automatically from startOperation method of base class.
5051 */
5052 //================================================================================
5053 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5054 {
5055   LightApp_Operation* op = 0;
5056   // to do : create operation here
5057   switch( id )
5058   {
5059     case 417: //convert to quadratic
5060       op = new SMESHGUI_ConvToQuadOp();
5061     break;
5062     case 418: // create 2D mesh as boundary on 3D
5063       op = new SMESHGUI_Make2DFrom3DOp();
5064     break;
5065     case 420: // Reorient faces
5066       op = new SMESHGUI_ReorientFacesOp();
5067       break;
5068     case 701: // Compute mesh
5069       op = new SMESHGUI_ComputeOp();
5070     break;
5071     case 702: // Create mesh
5072       op = new SMESHGUI_MeshOp( true, true );
5073     break;
5074     case 703: // Create sub-mesh
5075       op = new SMESHGUI_MeshOp( true, false );
5076     break;
5077     case 704: // Edit mesh/sub-mesh
5078       op = new SMESHGUI_MeshOp( false );
5079     break;
5080     case 711: // Precompute mesh
5081       op = new SMESHGUI_PrecomputeOp();
5082     break;
5083     case 712: // Evaluate mesh
5084       op = new SMESHGUI_EvaluateOp();
5085     break;
5086     case 713: // Evaluate mesh
5087       op = new SMESHGUI_MeshOrderOp();
5088     break;
5089     case 806: // Create group on geom
5090       op = new SMESHGUI_GroupOnShapeOp();
5091       break;
5092     case 904: // Find element
5093       op = new SMESHGUI_FindElemByPointOp();
5094       break;
5095     case 4067: // make mesh pass through point
5096       op = new SMESHGUI_MakeNodeAtPointOp();
5097       break;
5098     default:
5099     break;
5100   }
5101
5102   if( !op )
5103     op = SalomeApp_Module::createOperation( id );
5104   return op;
5105 }
5106
5107 //================================================================================
5108 /*!
5109  * \brief Stops current operations and starts a given one
5110   * \param id - The id of the operation to start
5111  */
5112 //================================================================================
5113
5114 void SMESHGUI::switchToOperation(int id)
5115 {
5116   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
5117     activeStudy()->abortAllOperations();
5118   startOperation( id );
5119 }
5120
5121 LightApp_Displayer* SMESHGUI::displayer()
5122 {
5123   if( !myDisplayer )
5124     myDisplayer = new SMESHGUI_Displayer( getApp() );
5125   return myDisplayer;
5126 }
5127
5128 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
5129 {
5130   int aHue = -1;
5131   int aTolerance = 64;
5132   int anIterations = 0;
5133   int aPeriod = 5;
5134
5135   while( 1 )
5136   {
5137     anIterations++;
5138     if( anIterations % aPeriod == 0 )
5139     {
5140       aTolerance /= 2;
5141       if( aTolerance < 1 )
5142         break;
5143     }
5144
5145     aHue = (int)( 360.0 * rand() / RAND_MAX );
5146
5147     bool ok = true;
5148     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
5149     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
5150     for( ; it != itEnd; ++it )
5151     {
5152       SALOMEDS::Color anAutoColor = *it;
5153       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
5154
5155       int h, s, v;
5156       aQColor.getHsv( &h, &s, &v );
5157       if( abs( h - aHue ) < aTolerance )
5158       {
5159         ok = false;
5160         break;
5161       }
5162     }
5163
5164     if( ok )
5165       break;
5166   }
5167
5168   QColor aColor;
5169   aColor.setHsv( aHue, 255, 255 );
5170
5171   SALOMEDS::Color aSColor;
5172   aSColor.R = (double)aColor.red() / 255.0;
5173   aSColor.G = (double)aColor.green() / 255.0;
5174   aSColor.B = (double)aColor.blue() / 255.0;
5175
5176   return aSColor;
5177 }
5178
5179 const char gSeparator = '_'; // character used to separate parameter names
5180 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
5181 const char gPathSep   = '|'; // character used to separate paths
5182
5183 /*!
5184  * \brief Store visual parameters
5185  *
5186  * This method is called just before the study document is saved.
5187  * Store visual parameters in AttributeParameter attribue(s)
5188  */
5189 void SMESHGUI::storeVisualParameters (int savePoint)
5190 {
5191   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5192   if (!appStudy || !appStudy->studyDS())
5193     return;
5194   _PTR(Study) studyDS = appStudy->studyDS();
5195
5196   // componentName is used for encoding of entries when storing them in IParameters
5197   std::string componentName = myComponentSMESH->ComponentDataType();
5198   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
5199   //if (!aSComponent) return;
5200
5201   // IParameters
5202   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5203                                                              componentName.c_str(),
5204                                                              savePoint);
5205   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5206
5207   // store map of custom markers
5208   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5209   if( !aMarkerMap.empty() )
5210   {
5211     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
5212     for( ; anIter != aMarkerMap.end(); anIter++ )
5213     {
5214       int anId = anIter->first;
5215       VTK::MarkerData aMarkerData = anIter->second;
5216       std::string aMarkerFileName = aMarkerData.first;
5217       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
5218       if( aMarkerTexture.size() < 3 )
5219         continue; // should contain at least width, height and the first value
5220
5221       QString aPropertyName( "texture" );
5222       aPropertyName += gSeparator;
5223       aPropertyName += QString::number( anId );
5224
5225       QString aPropertyValue = aMarkerFileName.c_str();
5226       aPropertyValue += gPathSep;
5227
5228       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
5229       ushort aWidth = *aTextureIter++;
5230       ushort aHeight = *aTextureIter++;
5231       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
5232       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
5233       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
5234         aPropertyValue += QString::number( *aTextureIter );
5235
5236       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5237     }
5238   }
5239
5240   // viewers counters are used for storing view_numbers in IParameters
5241   int vtkViewers = 0;
5242
5243   // main cycle to store parameters of displayed objects
5244   QList<SUIT_ViewManager*> lst;
5245   QList<SUIT_ViewManager*>::Iterator it;
5246   getApp()->viewManagers(lst);
5247   for (it = lst.begin(); it != lst.end(); it++)
5248   {
5249     SUIT_ViewManager* vman = *it;
5250     QString vType = vman->getType();
5251
5252     // saving VTK actors properties
5253     if (vType == SVTK_Viewer::Type())
5254     {
5255       // store the clipping planes attached to the view manager
5256       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
5257       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
5258       if( anIter != myClippingPlaneInfoMap.end() )
5259         aClippingPlaneInfoList = anIter->second;
5260
5261       if( !aClippingPlaneInfoList.empty() ) {
5262         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
5263         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
5264         {
5265           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
5266           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
5267
5268           QString aPropertyName( "ClippingPlane" );
5269           aPropertyName += gSeparator;
5270           aPropertyName += QString::number( vtkViewers );
5271           aPropertyName += gSeparator;
5272           aPropertyName += QString::number( anId );
5273
5274           QString aPropertyValue = QString::number( (int)aPlane->GetOrientation() ).toLatin1().constData();
5275           aPropertyValue += gDigitsSep;
5276           aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5277           aPropertyValue += gDigitsSep;
5278           aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5279           aPropertyValue += gDigitsSep;
5280           aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5281
5282           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5283         }
5284       }
5285
5286       QVector<SUIT_ViewWindow*> views = vman->getViews();
5287       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5288       {
5289         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5290         {
5291           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5292           vtkActorCollection* allActors = aCopy.GetActors();
5293           allActors->InitTraversal();
5294           while (vtkActor* actor = allActors->GetNextActor())
5295           {
5296             if (actor->GetVisibility()) // store only visible actors
5297             {
5298               SMESH_Actor* aSmeshActor = 0;
5299               if (actor->IsA("SMESH_Actor"))
5300                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5301               if (aSmeshActor && aSmeshActor->hasIO())
5302               {
5303                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5304                 if (io->hasEntry())
5305                 {
5306                   // entry is "encoded" = it does NOT contain component adress,
5307                   // since it is a subject to change on next component loading
5308                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5309
5310                   std::string param, vtkParam = vType.toLatin1().data();
5311                   vtkParam += gSeparator;
5312                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5313                   vtkParam += gSeparator;
5314
5315                   // Visibility
5316                   param = vtkParam + "Visibility";
5317                   ip->setParameter(entry, param, "On");
5318
5319                   // Representation
5320                   param = vtkParam + "Representation";
5321                   ip->setParameter(entry, param, QString::number
5322                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5323
5324                   // IsShrunk
5325                   param = vtkParam + "IsShrunk";
5326                   ip->setParameter(entry, param, QString::number
5327                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5328
5329                   // Displayed entities
5330                   unsigned int aMode = aSmeshActor->GetEntityMode();
5331                   bool isE = aMode & SMESH_Actor::eEdges;
5332                   bool isF = aMode & SMESH_Actor::eFaces;
5333                   bool isV = aMode & SMESH_Actor::eVolumes;
5334
5335                   QString modeStr ("e");
5336                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5337                   modeStr += gDigitsSep; modeStr += "f";
5338                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5339                   modeStr += gDigitsSep; modeStr += "v";
5340                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5341
5342                   param = vtkParam + "Entities";
5343                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5344
5345                   // Colors (surface:edge:)
5346                   vtkFloatingPointType r, g, b;
5347                   int delta;
5348
5349                   aSmeshActor->GetSufaceColor(r, g, b, delta);
5350                   QString colorStr ("surface");
5351                   colorStr += gDigitsSep; colorStr += QString::number(r);
5352                   colorStr += gDigitsSep; colorStr += QString::number(g);
5353                   colorStr += gDigitsSep; colorStr += QString::number(b);
5354
5355                   colorStr += gDigitsSep; colorStr += "backsurface";
5356                   colorStr += gDigitsSep; colorStr += QString::number(delta);
5357
5358
5359                   aSmeshActor->GetEdgeColor(r, g, b);
5360                   colorStr += gDigitsSep; colorStr += "edge";
5361                   colorStr += gDigitsSep; colorStr += QString::number(r);
5362                   colorStr += gDigitsSep; colorStr += QString::number(g);
5363                   colorStr += gDigitsSep; colorStr += QString::number(b);
5364
5365                   aSmeshActor->GetNodeColor(r, g, b);
5366                   colorStr += gDigitsSep; colorStr += "node";
5367                   colorStr += gDigitsSep; colorStr += QString::number(r);
5368                   colorStr += gDigitsSep; colorStr += QString::number(g);
5369                   colorStr += gDigitsSep; colorStr += QString::number(b);
5370
5371                   aSmeshActor->GetOutlineColor(r, g, b);
5372                   colorStr += gDigitsSep; colorStr += "outline";
5373                   colorStr += gDigitsSep; colorStr += QString::number(r);
5374                   colorStr += gDigitsSep; colorStr += QString::number(g);
5375                   colorStr += gDigitsSep; colorStr += QString::number(b);
5376
5377                   param = vtkParam + "Colors";
5378                   ip->setParameter(entry, param, colorStr.toLatin1().data());
5379
5380                   // Sizes of lines and points
5381                   QString sizeStr ("line");
5382                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
5383                   sizeStr += gDigitsSep; sizeStr += "shrink";
5384                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
5385
5386                   param = vtkParam + "Sizes";
5387                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
5388
5389                   // Point marker
5390                   QString markerStr;
5391
5392                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5393                   if( aMarkerType == VTK::MT_USER ) {
5394                     markerStr += "custom";
5395                     markerStr += gDigitsSep;
5396                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5397                   }
5398                   else {
5399                     markerStr += "std";
5400                     markerStr += gDigitsSep;
5401                     markerStr += QString::number( (int)aMarkerType );
5402                     markerStr += gDigitsSep;
5403                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5404                   }
5405
5406                   param = vtkParam + "PointMarker";
5407                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5408
5409                   // Opacity
5410                   param = vtkParam + "Opacity";
5411                   ip->setParameter(entry, param,
5412                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5413
5414                   // Clipping
5415                   param = vtkParam + "ClippingPlane";
5416                   int aPlaneId = 0;
5417                   if( !aClippingPlaneInfoList.empty() ) {
5418                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5419                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5420                     {
5421                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5422                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5423                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5424                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5425                         if( aSmeshActor == *anIter2 ) {
5426                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5427                                             QString::number( anId ).toLatin1().constData() );
5428                           break;
5429                         }
5430                       }
5431                     }
5432                   }
5433                   if( aPlaneId == 0 )
5434                     ip->setParameter( entry, param, "Off" );
5435                 } // if (io->hasEntry())
5436               } // SMESH_Actor && hasIO
5437             } // isVisible
5438           } // while.. actors traversal
5439         } // if (vtkView)
5440       } // for (views)
5441       vtkViewers++;
5442     } // if (SVTK view model)
5443   } // for (viewManagers)
5444 }
5445
5446 // data structures for clipping planes processing
5447 typedef struct {
5448   int Id;
5449   vtkIdType Orientation;
5450   vtkFloatingPointType Distance;
5451   vtkFloatingPointType Angle[2];
5452 } TPlaneData;
5453 typedef std::list<TPlaneData>         TPlaneDataList;
5454 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5455
5456 typedef std::list<vtkActor*>          TActorList;
5457 typedef struct {
5458   int PlaneId;
5459   TActorList ActorList;
5460   SUIT_ViewManager* ViewManager;
5461 } TPlaneInfo;
5462 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5463 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5464
5465 /*!
5466  * \brief Restore visual parameters
5467  *
5468  * This method is called after the study document is opened.
5469  * Restore visual parameters from AttributeParameter attribue(s)
5470  */
5471 void SMESHGUI::restoreVisualParameters (int savePoint)
5472 {
5473   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5474   if (!appStudy || !appStudy->studyDS())
5475     return;
5476   _PTR(Study) studyDS = appStudy->studyDS();
5477
5478   // componentName is used for encoding of entries when storing them in IParameters
5479   std::string componentName = myComponentSMESH->ComponentDataType();
5480   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5481   //if (!aSComponent) return;
5482
5483   // IParameters
5484   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5485                                                              componentName.c_str(),
5486                                                              savePoint);
5487   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5488
5489   // restore map of custom markers and map of clipping planes
5490   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5491   TPlaneDataMap aPlaneDataMap;
5492
5493   std::vector<std::string> properties = ip->getProperties();
5494   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5495   {
5496     std::string property = *propIt;
5497     QString aPropertyName( property.c_str() );
5498     QString aPropertyValue( ip->getProperty( property ).c_str() );
5499
5500     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5501     if( aPropertyNameList.isEmpty() )
5502       continue;
5503
5504     QString aPropertyType = aPropertyNameList[0];
5505     if( aPropertyType == "texture" )
5506     {
5507       if( aPropertyNameList.size() != 2 )
5508         continue;
5509
5510       bool ok = false;
5511       int anId = aPropertyNameList[1].toInt( &ok );
5512       if( !ok || anId < 1 )
5513         continue;
5514
5515       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5516       if( aPropertyValueList.size() != 2 )
5517         continue;
5518
5519       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5520       QString aMarkerTextureString = aPropertyValueList[1];
5521       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5522       if( aMarkerTextureStringList.size() != 3 )
5523         continue;
5524
5525       ok = false;
5526       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5527       if( !ok )
5528         continue;
5529
5530       ok = false;
5531       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5532       if( !ok )
5533         continue;
5534
5535       VTK::MarkerTexture aMarkerTexture;
5536       aMarkerTexture.push_back( aWidth );
5537       aMarkerTexture.push_back( aHeight );
5538
5539       QString aMarkerTextureData = aMarkerTextureStringList[2];
5540       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5541       {
5542         QChar aChar = aMarkerTextureData.at( i );
5543         if( aChar.isDigit() )
5544           aMarkerTexture.push_back( aChar.digitValue() );
5545       }
5546
5547       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5548     }
5549     else if( aPropertyType == "ClippingPlane" )
5550     {
5551       if( aPropertyNameList.size() != 3 )
5552         continue;
5553
5554       bool ok = false;
5555       int aViewId = aPropertyNameList[1].toInt( &ok );
5556       if( !ok || aViewId < 0 )
5557         continue;
5558
5559       ok = false;
5560       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5561       if( !ok || aClippingPlaneId < 0 )
5562         continue;
5563
5564       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5565       if( aPropertyValueList.size() != 4 )
5566         continue;
5567
5568       TPlaneData aPlaneData;
5569       aPlaneData.Id = aClippingPlaneId;
5570
5571       ok = false;
5572       aPlaneData.Orientation = aPropertyValueList[0].toInt( &ok );
5573       if( !ok )
5574         continue;
5575
5576       ok = false;
5577       aPlaneData.Distance = aPropertyValueList[1].toDouble( &ok );
5578       if( !ok )
5579         continue;
5580
5581       ok = false;
5582       aPlaneData.Angle[0] = aPropertyValueList[2].toDouble( &ok );
5583       if( !ok )
5584         continue;
5585
5586       ok = false;
5587       aPlaneData.Angle[1] = aPropertyValueList[3].toDouble( &ok );
5588       if( !ok )
5589         continue;
5590
5591       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
5592       aPlaneDataList.push_back( aPlaneData );
5593     }
5594   }
5595
5596   TPlaneInfoMap aPlaneInfoMap;
5597
5598   std::vector<std::string> entries = ip->getEntries();
5599
5600   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
5601   {
5602     // entry is a normal entry - it should be "decoded" (setting base adress of component)
5603     QString entry (ip->decodeEntry(*entIt).c_str());
5604
5605     // Check that the entry corresponds to a real object in the Study
5606     // as the object may be deleted or modified after the visual state is saved.
5607     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
5608     if (!so) continue; //Skip the not existent entry
5609
5610     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
5611     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
5612
5613     std::vector<std::string>::iterator namesIt = paramNames.begin();
5614     std::vector<std::string>::iterator valuesIt = paramValues.begin();
5615
5616     // actors are stored in a map after displaying of them for
5617     // quicker access in the future: map < viewID to actor >
5618     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
5619
5620     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
5621     {
5622       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
5623       // '_' is used as separator and should not be used in viewer type or parameter names.
5624       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
5625       if (lst.size() != 3)
5626         continue;
5627
5628       QString viewerTypStr = lst[0];
5629       QString viewIndexStr = lst[1];
5630       QString paramNameStr = lst[2];
5631
5632       bool ok;
5633       int viewIndex = viewIndexStr.toUInt(&ok);
5634       if (!ok) // bad conversion of view index to integer
5635         continue;
5636
5637       // viewers
5638       if (viewerTypStr == SVTK_Viewer::Type())
5639       {
5640         SMESH_Actor* aSmeshActor = 0;
5641         if (vtkActors.IsBound(viewIndex))
5642           aSmeshActor = vtkActors.Find(viewIndex);
5643
5644         QList<SUIT_ViewManager*> lst;
5645         getApp()->viewManagers(viewerTypStr, lst);
5646
5647         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5648         SUIT_ViewManager* vman = NULL;
5649         if (viewIndex >= 0 && viewIndex < lst.count())
5650           vman = lst.at(viewIndex);
5651
5652         if (paramNameStr == "Visibility")
5653         {
5654           if (!aSmeshActor && displayer() && vman)
5655           {
5656             SUIT_ViewModel* vmodel = vman->getViewModel();
5657             // SVTK view model can be casted to SALOME_View
5658             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
5659
5660             // store displayed actor in a temporary map for quicker
5661             // access later when restoring other parameters
5662             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5663             vtkRenderer* Renderer = vtkView->getRenderer();
5664             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
5665             vtkActorCollection* theActors = aCopy.GetActors();
5666             theActors->InitTraversal();
5667             bool isFound = false;
5668             vtkActor *ac = theActors->GetNextActor();
5669             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
5670               if (ac->IsA("SMESH_Actor")) {
5671                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
5672                 if (aGeomAc->hasIO()) {
5673                   Handle(SALOME_InteractiveObject) io =
5674                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
5675                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
5676                     isFound = true;
5677                     vtkActors.Bind(viewIndex, aGeomAc);
5678                   }
5679                 }
5680               }
5681             }
5682           }
5683         } // if (paramNameStr == "Visibility")
5684         else
5685         {
5686           // the rest properties "work" with SMESH_Actor
5687           if (aSmeshActor)
5688           {
5689             QString val ((*valuesIt).c_str());
5690
5691             // Representation
5692             if (paramNameStr == "Representation") {
5693               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
5694             }
5695             // IsShrunk
5696             else if (paramNameStr == "IsShrunk") {
5697               if (val.toInt()) {
5698                 if (!aSmeshActor->IsShrunk())
5699                   aSmeshActor->SetShrink();
5700               }
5701               else {
5702                 if (aSmeshActor->IsShrunk())
5703                   aSmeshActor->UnShrink();
5704               }
5705             }
5706             // Displayed entities
5707             else if (paramNameStr == "Entities") {
5708               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
5709               if (mode.count() == 6) {
5710                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
5711                   MESSAGE("Invalid order of data in Entities, must be: "
5712                           "e:0/1:f:0/1:v:0/1");
5713                 }
5714                 else {
5715                   unsigned int aMode = aSmeshActor->GetEntityMode();
5716                   unsigned int aNewMode =
5717                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
5718                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
5719                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
5720                   if (aNewMode != aMode)
5721                     aSmeshActor->SetEntityMode(aNewMode);
5722                 }
5723               }
5724             }
5725             // Colors
5726             else if (paramNameStr == "Colors") {
5727               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
5728               if (colors.count() == 16 || colors.count() == 18 ) {
5729                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
5730                     (colors[8] != "edge" && colors[6] != "edge" ) || (colors[12] != "node" && colors[10] != "node") ||
5731                     (colors.count() == 18 && colors[14] != "outline")) {
5732                   MESSAGE("Invalid order of data in Colors, must be: "
5733                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b or surface:r:g:b:backsurface:delta:edge:r:g:b:node:r:g:b:outline:r:g:b");
5734                 }
5735                 else {
5736                   int delta = 0;
5737                   float er,eg,eb;
5738                   float nr,ng,nb;
5739                   vtkFloatingPointType otr,otg,otb;
5740                   //Old case backsurface color is independent
5741                   if( colors.count() == 16 ) {
5742                     QColor ffc;
5743                     SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "0,170,255|-100" ) ;
5744                     er = colors[9].toFloat();
5745                     eg = colors[10].toFloat();
5746                     eb = colors[11].toFloat();
5747
5748                     nr = colors[13].toFloat();
5749                     ng = colors[14].toFloat();
5750                     nb = colors[15].toFloat();
5751                     SMESH::GetColor("SMESH", "outline_color", otr, otg, otb, QColor( 0, 70, 0 ) );
5752                   } else {
5753                     //New case backsurface color depends on surface color
5754                     delta = colors[5].toInt();
5755
5756                     er = colors[7].toFloat();
5757                     eg = colors[8].toFloat();
5758                     eb = colors[9].toFloat();
5759
5760                     nr = colors[11].toFloat();
5761                     ng = colors[12].toFloat();
5762                     nb = colors[13].toFloat();
5763
5764                     otr = colors[15].toFloat();
5765                     otg = colors[16].toFloat();
5766                     otb = colors[17].toFloat();
5767                   }
5768                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat(), delta);
5769                   aSmeshActor->SetEdgeColor(er,eg,eb);
5770                   aSmeshActor->SetNodeColor(nr,ng,nb);
5771                   aSmeshActor->SetOutlineColor(otr,otg,otb);
5772                 }
5773               }
5774             }
5775             // Sizes of lines and points
5776             else if (paramNameStr == "Sizes") {
5777               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
5778               if (sizes.count() == 4) {
5779                 if (sizes[0] != "line" || sizes[2] != "shrink") {
5780                   MESSAGE("Invalid order of data in Sizes, must be: "
5781                           "line:int:shrink:float");
5782                 }
5783                 else {
5784                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5785                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
5786                 }
5787               }
5788               else if (sizes.count() == 6) { // just to support old format
5789                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
5790                   MESSAGE("Invalid order of data in Sizes, must be: "
5791                           "line:int:node:int:shrink:float");
5792                 }
5793                 else {
5794                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5795                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
5796                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
5797                 }
5798               }
5799             }
5800             // Point marker
5801             else if (paramNameStr == "PointMarker") {
5802               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
5803               if( data.count() >= 2 ) {
5804                 bool ok = false;
5805                 int aParam1 = data[1].toInt( &ok );
5806                 if( ok ) {
5807                   if( data[0] == "std" && data.count() == 3 ) {
5808                     int aParam2 = data[2].toInt( &ok );
5809                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
5810                   }
5811                   else if( data[0] == "custom" ) {
5812                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
5813                     if( markerIt != aMarkerMap.end() ) {
5814                       VTK::MarkerData aMarkerData = markerIt->second;
5815                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
5816                     }
5817                   }
5818                 }
5819               }
5820             }
5821             // Opacity
5822             else if (paramNameStr == "Opacity") {
5823               aSmeshActor->SetOpacity(val.toFloat());
5824             }
5825             // Clipping
5826             else if (paramNameStr.startsWith("ClippingPlane")) {
5827               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
5828               // old format - val looks like "Off" or "0:0.5:0:0" (orientation, distance, two angles)
5829               // new format - val looks like "Off" or "0" (plane id)
5830               // (note: in new format "Off" value is used only for consistency,
5831               //  so it is processed together with values in old format)
5832               bool anIsOldFormat = ( vals.count() == 4 || val == "Off" );
5833               if( anIsOldFormat ) {
5834                 if (paramNameStr == "ClippingPlane1" || val == "Off")
5835                   aSmeshActor->RemoveAllClippingPlanes();
5836                 if (val != "Off") {
5837                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
5838                   double aDistance = vals[1].toFloat();
5839                   vtkFloatingPointType anAngle[2];
5840                   anAngle[0] = vals[2].toFloat();
5841                   anAngle[1] = vals[3].toFloat();
5842
5843                   QList<SUIT_ViewManager*> lst;
5844                   getApp()->viewManagers(viewerTypStr, lst);
5845                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5846                   if (viewIndex >= 0 && viewIndex < lst.count()) {
5847                     SUIT_ViewManager* vman = lst.at(viewIndex);
5848                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5849
5850                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
5851
5852                     SMESH::TActorList anActorList;
5853                     anActorList.push_back( aSmeshActor );
5854                     SMESH::OrientedPlane* aPlane =
5855                       SMESHGUI_ClippingDlg::AddPlane(anActorList, vtkView, anOrientation, aDistance, anAngle);
5856                     if( aPlane ) {
5857                       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5858                       aClippingPlaneInfo.Plane = aPlane;
5859                       aClippingPlaneInfo.ActorList = anActorList;
5860                       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5861                     }
5862                   }
5863                 }
5864               }
5865               else {
5866                 bool ok = false;
5867                 int aPlaneId = val.toInt( &ok );
5868                 if( ok && aPlaneId >= 0 ) {
5869                   bool anIsDefinedPlane = false;
5870                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
5871                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
5872                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5873                     TPlaneInfo& aPlaneInfo = *anIter;
5874                     if( aPlaneInfo.PlaneId == aPlaneId ) {
5875                       aPlaneInfo.ActorList.push_back( aSmeshActor );
5876                       anIsDefinedPlane = true;
5877                       break;
5878                     }
5879                   }
5880                   if( !anIsDefinedPlane ) {
5881                     TPlaneInfo aPlaneInfo;
5882                     aPlaneInfo.PlaneId = aPlaneId;
5883                     aPlaneInfo.ActorList.push_back( aSmeshActor );
5884                     aPlaneInfo.ViewManager = vman;
5885
5886                     // to make the list sorted by plane id
5887                     anIter = aPlaneInfoList.begin();
5888                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5889                       const TPlaneInfo& aPlaneInfoRef = *anIter;
5890                       if( aPlaneInfoRef.PlaneId > aPlaneId )
5891                         break;
5892                     }
5893                     aPlaneInfoList.insert( anIter, aPlaneInfo );
5894                   }
5895                 }
5896               }
5897             }
5898           } // if (aSmeshActor)
5899         } // other parameters than Visibility
5900       }
5901     } // for names/parameters iterator
5902   } // for entries iterator
5903
5904   // take into account planes with empty list of actors referred to them
5905   QList<SUIT_ViewManager*> aVMList;
5906   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
5907
5908   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
5909   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
5910     int aViewId = aPlaneDataIter->first;
5911     if( aViewId >= 0 && aViewId < aVMList.count() ) {
5912       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
5913
5914       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
5915
5916       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
5917       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
5918       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
5919         const TPlaneData& aPlaneData = *anIter2;
5920         int aPlaneId = aPlaneData.Id;
5921
5922         bool anIsFound = false;
5923         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5924         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5925           const TPlaneInfo& aPlaneInfo = *anIter3;
5926           if( aPlaneInfo.PlaneId == aPlaneId ) {
5927             anIsFound = true;
5928             break;
5929           }
5930         }
5931
5932         if( !anIsFound ) {
5933           TPlaneInfo aPlaneInfo; // ActorList field is empty
5934           aPlaneInfo.PlaneId = aPlaneId;
5935           aPlaneInfo.ViewManager = aViewManager;
5936
5937           // to make the list sorted by plane id
5938           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
5939           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
5940             const TPlaneInfo& aPlaneInfoRef = *anIter4;
5941             if( aPlaneInfoRef.PlaneId > aPlaneId )
5942               break;
5943           }
5944           aPlaneInfoList.insert( anIter4, aPlaneInfo );
5945         }
5946       }
5947     }
5948   }
5949
5950   // add clipping planes to actors according to the restored parameters
5951   // and update the clipping plane map
5952   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
5953   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
5954     int aViewId = anIter1->first;
5955     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
5956
5957     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
5958     if( anIter2 == aPlaneDataMap.end() )
5959       continue;
5960     const TPlaneDataList& aPlaneDataList = anIter2->second;
5961
5962     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5963     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5964       const TPlaneInfo& aPlaneInfo = *anIter3;
5965       int aPlaneId = aPlaneInfo.PlaneId;
5966       const TActorList& anActorList = aPlaneInfo.ActorList;
5967       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
5968       if( !aViewManager )
5969         continue;
5970
5971       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
5972       if( !aViewWindow )
5973         continue;
5974
5975       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
5976
5977       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
5978       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
5979         const TPlaneData& aPlaneData = *anIter4;
5980         if( aPlaneData.Id == aPlaneId ) {
5981           SMESH::OrientedPlane* aPlane =
5982             SMESHGUI_ClippingDlg::AddPlane( anActorList,
5983                                             aViewWindow,
5984                                             (SMESH::Orientation)aPlaneData.Orientation,
5985                                             aPlaneData.Distance,
5986                                             aPlaneData.Angle );
5987           if( aPlane ) {
5988             SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5989             aClippingPlaneInfo.Plane = aPlane;
5990             aClippingPlaneInfo.ActorList = anActorList;
5991             aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5992           }
5993           break;
5994         }
5995       }
5996     }
5997   }
5998
5999   // update all VTK views
6000   QList<SUIT_ViewManager*> lst;
6001   getApp()->viewManagers(lst);
6002   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
6003     SUIT_ViewModel* vmodel = (*it)->getViewModel();
6004     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
6005       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
6006       vtkView->getRenderer()->ResetCameraClippingRange();
6007       vtkView->Repaint();
6008     }
6009   }
6010 }
6011
6012 /*!
6013   \brief Adds preferences for dfont of VTK viewer
6014   \param label label
6015   \param pIf group identifier
6016   \param param parameter
6017   \return identifier of preferences
6018 */
6019 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
6020 {
6021   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
6022
6023   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
6024
6025   QStringList fam;
6026   fam.append( tr( "SMESH_FONT_ARIAL" ) );
6027   fam.append( tr( "SMESH_FONT_COURIER" ) );
6028   fam.append( tr( "SMESH_FONT_TIMES" ) );
6029
6030   setPreferenceProperty( tfont, "fonts", fam );
6031
6032   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
6033   setPreferenceProperty( tfont, "features", f );
6034
6035   return tfont;
6036 }
6037
6038 /*!
6039   \brief Actions after hypothesis edition
6040   Updates object browser after hypothesis edition
6041 */
6042 void SMESHGUI::onHypothesisEdit( int result )
6043 {
6044   if( result == 1 )
6045     SMESHGUI::Modified();
6046   updateObjBrowser( true );
6047 }
6048
6049
6050 /*!
6051   \brief Signal handler closing(SUIT_ViewWindow*) of a view
6052   \param pview view being closed
6053 */
6054 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
6055 #ifndef DISABLE_PLOT2DVIEWER
6056   //Crear all Plot2d Viewers if need.
6057   SMESH::ClearPlot2Viewers(pview);
6058 #endif
6059 }
6060
6061 void SMESHGUI::message( const QString& msg )
6062 {
6063   // dispatch message
6064   QStringList data = msg.split("/");
6065   if ( data.count() > 0 ) {
6066     if ( data.first() == "mesh_loading" ) {
6067       // get mesh entry
6068       QString entry = data.count() > 1 ? data[1] : QString();
6069       if ( entry.isEmpty() )
6070         return;
6071       // get study
6072       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
6073       // get mesh name
6074       _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().constData() );
6075       QString name;
6076       if ( obj )
6077         name = obj->GetName().c_str();
6078       if ( name.isEmpty() )
6079         return;
6080       
6081       if ( data.last() == "stop" )
6082         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
6083       else
6084         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
6085       QApplication::processEvents();
6086     }
6087   }
6088 }
6089
6090 /*!
6091   \brief Connects or disconnects signals about activating and cloning view on the module slots
6092   \param pview view which is connected/disconnected
6093 */
6094 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
6095   if(!pview)
6096     return;
6097
6098   SUIT_ViewManager* viewMgr = pview->getViewManager();
6099   if ( viewMgr ) {
6100     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6101                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6102
6103     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6104              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6105   }
6106 }
6107
6108 /*!
6109   \brief Return \c true if object can be renamed
6110 */
6111 bool SMESHGUI::renameAllowed( const QString& entry) const {
6112   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6113   if( !anApp )
6114     return false;
6115
6116   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6117   if( !appStudy )
6118     return false;
6119
6120   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
6121   
6122   if(!obj)
6123     return false;
6124
6125   if(appStudy->isComponent(entry) || obj->isReference())
6126     return false;
6127
6128   // check type to prevent renaming of inappropriate objects
6129   int aType = SMESHGUI_Selection::type(qPrintable(entry), SMESH::GetActiveStudyDocument());
6130   if (aType == MESH || aType == GROUP ||
6131       aType == SUBMESH || aType == SUBMESH_COMPOUND ||
6132       aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
6133       aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
6134       aType == HYPOTHESIS || aType == ALGORITHM)
6135     return true;
6136
6137   return false;
6138 }
6139
6140 /*!
6141   Rename object by entry.
6142   \param entry entry of the object
6143   \param name new name of the object
6144   \brief Return \c true if rename operation finished successfully, \c false otherwise.
6145 */
6146 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
6147
6148   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6149   if( !anApp )
6150     return false;
6151     
6152   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6153
6154   if(!appStudy)
6155     return false;
6156   
6157   _PTR(Study) aStudy = appStudy->studyDS();
6158   
6159   if(!aStudy)
6160     return false;
6161   
6162   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
6163   if ( aLocked ) {
6164     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
6165     return false;
6166   }
6167
6168
6169   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
6170   _PTR(GenericAttribute) anAttr;
6171   _PTR(AttributeName) aName;
6172   if ( obj ) {
6173     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
6174       aName = anAttr;
6175       // check type to prevent renaming of inappropriate objects
6176       int aType = SMESHGUI_Selection::type( qPrintable(entry), SMESH::GetActiveStudyDocument() );
6177       if (aType == MESH || aType == GROUP ||
6178           aType == SUBMESH || aType == SUBMESH_COMPOUND ||
6179           aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
6180           aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
6181           aType == HYPOTHESIS || aType == ALGORITHM) {
6182         if ( !name.isEmpty() ) {
6183           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
6184
6185           // update name of group object and its actor
6186           Handle(SALOME_InteractiveObject) IObject =
6187             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
6188
6189           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
6190           if( !aGroupObject->_is_nil() ) {
6191             aGroupObject->SetName( qPrintable(name) );
6192             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
6193               anActor->setName( qPrintable(name) );
6194           }
6195           return true;
6196         }
6197       }
6198     }
6199   }
6200   return false;
6201 }