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