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