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