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