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