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