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