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