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