Salome HOME
0022480: EDF 2773 SMESH: Automatic update in SMESH
[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_IDSource_ptr theMesh,
2016                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
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   SMESH::long_array_var info = theMesh->GetMeshInfo();
2027   long nbOdElems = info[SMDSEntity_0D];
2028   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2029   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] + 
2030                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] + 
2031                    info[SMDSEntity_Polygon];
2032   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] + 
2033                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] + 
2034                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] + 
2035                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + 
2036                    info[SMDSEntity_Polyhedra] + 
2037                    info[SMDSEntity_Hexagonal_Prism];
2038   long nbBalls   = info[SMDSEntity_Ball];
2039
2040   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2041   *nbElements = requestedSize;
2042   
2043   *entities = SMESH_Actor::eAllEntity;
2044   *hidden   = 0;
2045
2046   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2047
2048   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2049
2050   if ( incrementalLimit ) {
2051     long total     = 0;
2052
2053     if ( nbOdElems > 0 ) {
2054       if ( total + nbOdElems > updateLimit ) {
2055         *entities = *entities & ~SMESH_Actor::e0DElements;
2056         *hidden = *hidden | SMESH_Actor::e0DElements;
2057       }
2058       else
2059         exceeded = false;
2060     }
2061     total += nbOdElems;
2062
2063     if ( nbEdges > 0 ) {
2064       if ( total + nbEdges > updateLimit ) {
2065         *entities = *entities & ~SMESH_Actor::eEdges;
2066         *hidden = *hidden | SMESH_Actor::eEdges;
2067       }
2068       else
2069         exceeded = false;
2070     }
2071     total += nbEdges;
2072
2073     if ( nbFaces > 0 ) {
2074       if ( total + nbFaces > updateLimit ) {
2075         *entities = *entities & ~SMESH_Actor::eFaces;
2076         *hidden = *hidden | SMESH_Actor::eFaces;
2077       }
2078       else
2079         exceeded = false;
2080     }
2081     total += nbFaces;
2082
2083     if ( nbVolumes > 0 ) {
2084       if ( total + nbVolumes > updateLimit ) {
2085         *entities = *entities & ~SMESH_Actor::eVolumes;
2086         *hidden = *hidden | SMESH_Actor::eVolumes;
2087       }
2088       else
2089         exceeded = false;
2090     }
2091     total += nbVolumes;
2092
2093     if ( nbBalls > 0 ) {
2094       if ( total + nbBalls > updateLimit ) {
2095         *entities = *entities & ~SMESH_Actor::eBallElem;
2096         *hidden = *hidden | SMESH_Actor::eBallElem;
2097       }
2098       else
2099         exceeded = false;
2100     }
2101     total += nbBalls;
2102   }
2103
2104   return autoUpdate && !exceeded;
2105 }
2106
2107 //=============================================================================
2108 /*!
2109  *
2110  */
2111 //=============================================================================
2112 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2113 {
2114   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2115 }
2116
2117 //=============================================================================
2118 /*!
2119  *
2120  */
2121 //=============================================================================
2122 SMESHGUI* SMESHGUI::GetSMESHGUI()
2123 {
2124   SMESHGUI* smeshMod = 0;
2125   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2126   if ( app )
2127   {
2128     CAM_Module* module = app->module( "Mesh" );
2129     smeshMod = dynamic_cast<SMESHGUI*>( module );
2130   }
2131
2132   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
2133   {
2134     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
2135     if ( study )
2136     {
2137       _PTR(Study) aStudy = study->studyDS();
2138       if ( aStudy )
2139         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
2140     }
2141   }
2142
2143   return smeshMod;
2144 }
2145
2146 extern "C"
2147 {
2148   Standard_EXPORT SMESHGUI* GetComponentGUI()
2149   {
2150     return SMESHGUI::GetSMESHGUI();
2151   }
2152 }
2153
2154 //=============================================================================
2155 /*!
2156  *
2157  */
2158 //=============================================================================
2159 void SMESHGUI::SetState(int aState)
2160 {
2161   myState = aState;
2162 }
2163
2164 //=============================================================================
2165 /*!
2166  *
2167  */
2168 //=============================================================================
2169 void SMESHGUI::ResetState()
2170 {
2171   myState = -1;
2172 }
2173
2174 //=============================================================================
2175 /*!
2176  *
2177  */
2178 //=============================================================================
2179 void SMESHGUI::EmitSignalDeactivateDialog()
2180 {
2181   emit SignalDeactivateActiveDialog();
2182 }
2183
2184 //=============================================================================
2185 /*!
2186  *
2187  */
2188 //=============================================================================
2189 void SMESHGUI::EmitSignalStudyFrameChanged()
2190 {
2191   emit SignalStudyFrameChanged();
2192 }
2193
2194 //=============================================================================
2195 /*!
2196  *
2197  */
2198 //=============================================================================
2199 void SMESHGUI::EmitSignalCloseAllDialogs()
2200 {
2201   emit SignalCloseAllDialogs();
2202 }
2203
2204 //=============================================================================
2205 /*!
2206  *
2207  */
2208 //=============================================================================
2209 void SMESHGUI::EmitSignalVisibilityChanged()
2210 {
2211   emit SignalVisibilityChanged();
2212 }
2213
2214 //=============================================================================
2215 /*!
2216  *
2217  */
2218 //=============================================================================
2219 QDialog *SMESHGUI::GetActiveDialogBox()
2220 {
2221   return myActiveDialogBox;
2222 }
2223
2224 //=============================================================================
2225 /*!
2226  *
2227  */
2228 //=============================================================================
2229 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2230 {
2231   myActiveDialogBox = (QDialog *) aDlg;
2232   return;
2233 }
2234
2235 //=============================================================================
2236 /*!
2237  *
2238  */
2239 //=============================================================================
2240 SUIT_Desktop* SMESHGUI::desktop()
2241 {
2242   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2243   if( app )
2244     return app->desktop();
2245   else
2246     return 0;
2247 }
2248
2249 //=============================================================================
2250 /*!
2251  *
2252  */
2253 //=============================================================================
2254 SalomeApp_Study* SMESHGUI::activeStudy()
2255 {
2256   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2257   if( app )
2258     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2259   else
2260     return NULL;
2261 }
2262
2263 //=============================================================================
2264 /*!
2265  *
2266  */
2267 //=============================================================================
2268 void SMESHGUI::Modified( bool theIsUpdateActions )
2269 {
2270   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2271     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2272       appStudy->Modified();
2273       if( theIsUpdateActions )
2274         app->updateActions();
2275     }
2276   }
2277 }
2278
2279 //=============================================================================
2280 /*!
2281  *
2282  */
2283 //=============================================================================
2284 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2285 {
2286   /* Here the position is on the bottom right corner - 10 */
2287   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2288   aDlg->adjustSize();
2289   SUIT_Desktop *PP = desktop();
2290   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2291   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2292   return true;
2293 }
2294
2295 //=============================================================================
2296 /*!
2297  *
2298  */
2299 //=============================================================================
2300 static int isStudyLocked(_PTR(Study) theStudy){
2301   return theStudy->GetProperties()->IsLocked();
2302 }
2303
2304 static bool checkLock(_PTR(Study) theStudy) {
2305   if (isStudyLocked(theStudy)) {
2306     SUIT_MessageBox::warning( SMESHGUI::desktop(),
2307                               QObject::tr("WRN_WARNING"),
2308                               QObject::tr("WRN_STUDY_LOCKED") );
2309     return true;
2310   }
2311   return false;
2312 }
2313
2314 //=======================================================================
2315 //function : CheckActiveStudyLocked
2316 //purpose  :
2317 //=======================================================================
2318
2319 bool SMESHGUI::isActiveStudyLocked()
2320 {
2321   _PTR(Study) aStudy = activeStudy()->studyDS();
2322   return checkLock( aStudy );
2323 }
2324
2325 //=============================================================================
2326 /*!
2327  *
2328  */
2329 //=============================================================================
2330 bool SMESHGUI::OnGUIEvent( int theCommandID )
2331 {
2332   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2333   if( !anApp )
2334     return false;
2335
2336   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2337   SUIT_ResourceMgr* mgr = resourceMgr();
2338   if( !mgr )
2339     return false;
2340
2341   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2342     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2343   }
2344
2345   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2346   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2347
2348   //QAction* act = action( theCommandID );
2349
2350   switch (theCommandID) {
2351   case 33:                                      // DELETE
2352     if(checkLock(aStudy)) break;
2353     OnEditDelete();
2354     break;
2355
2356   case 116:
2357   case 115:
2358   case 117:
2359   case 118:
2360   case 113:
2361   case 112:
2362   case 111:                                     // IMPORT
2363     {
2364       if(checkLock(aStudy)) break;
2365       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2366       break;
2367     }
2368
2369   case 150:    //MED FILE INFORMATION
2370     {
2371       SALOME_ListIO selected;
2372       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2373       if( aSel )
2374         aSel->selectedObjects( selected );
2375       if( selected.Extent() )
2376       {
2377         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2378         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2379         if ( !aMesh->_is_nil() )
2380         {
2381           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2382           dlg.exec();
2383         }
2384       }
2385       break;
2386     }
2387
2388   case 122:                                     // EXPORT MED
2389   case 121:
2390   case 123:
2391   case 124:
2392   case 125:
2393   case 126:
2394   case 140:
2395   case 141:
2396   case 142:
2397   case 143:
2398   case 144:
2399   case 145:
2400   case 146:
2401   case 147:
2402     {
2403       ::ExportMeshToFile(theCommandID);
2404       break;
2405     }
2406
2407   case 200:                                     // SCALAR BAR
2408     {
2409       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2410       SALOME_ListIO selected;
2411       if( aSel )
2412         aSel->selectedObjects( selected );
2413
2414       if( selected.Extent() ) {
2415         Handle(SALOME_InteractiveObject) anIO = selected.First();
2416         if( anIO->hasEntry() ) {
2417           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2418             anActor->SetControlMode( SMESH_Actor::eNone );
2419 #ifndef DISABLE_PLOT2DVIEWER
2420             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2421 #endif
2422           }
2423         }
2424       }
2425       break;
2426     }
2427   case 201:
2428     {
2429       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2430       break;
2431     }
2432   case 2021:
2433     {
2434       // dump control distribution data to the text file
2435       ::SaveDistribution();
2436       break;
2437     }
2438
2439   case 2022:
2440     {
2441       // show/ distribution
2442       ::ShowDistribution();
2443       break;
2444     }
2445
2446 #ifndef DISABLE_PLOT2DVIEWER
2447   case 2023:
2448     {
2449       // plot distribution
2450       ::PlotDistribution();
2451       break;
2452     }
2453 #endif
2454
2455     // Auto-color
2456   case 1136:
2457     ::AutoColor();
2458   break;
2459
2460   case 1137:
2461     ::DisableAutoColor();
2462   break;
2463
2464   case 1134: // Clipping
2465   case 1133: // Tranparency
2466   case 1132: // Display preferences (colors, shrink size, line width, ...)
2467
2468     // Display Mode
2469   case 215: // Nodes
2470   case 213: // Nodes
2471   case 212: // Nodes
2472   case 211: // Nodes
2473     ::SetDisplayMode(theCommandID, myMarkerMap);
2474   break;
2475
2476   //2D quadratic representation
2477   case 231:
2478   case 232:
2479     ::SetDisplayMode(theCommandID, myMarkerMap);
2480   break;
2481
2482   // Display Entity
2483   case 216: // 0D elements
2484   case 217: // Edges
2485   case 218: // Faces
2486   case 219: // Volumes
2487   case 220: // All Entity
2488   case 222: // Balls
2489     ::SetDisplayEntity(theCommandID);
2490   break;
2491
2492   case 221: // Orientation of faces
2493     {
2494       LightApp_SelectionMgr* mgr = selectionMgr();
2495       SALOME_ListIO selected; mgr->selectedObjects( selected );
2496
2497       SALOME_ListIteratorOfListIO it(selected);
2498       for( ; it.More(); it.Next()) {
2499         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2500         if(anIObject->hasEntry()) {
2501           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2502             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2503           }
2504         }
2505       }
2506       break;
2507     }
2508
2509   case 214:                                     // UPDATE
2510     {
2511       if(checkLock(aStudy)) break;
2512       SUIT_OverrideCursor wc;
2513       try {
2514 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2515         OCC_CATCH_SIGNALS;
2516 #endif
2517         SMESH::UpdateView();
2518       }
2519       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2520         SMESH::OnVisuException();
2521       }
2522       catch (...) { // PAL16774 (Crash after display of many groups)
2523         SMESH::OnVisuException();
2524       }
2525
2526       SALOME_ListIO l;
2527       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2528       aSel->selectedObjects( l );
2529       aSel->setSelectedObjects( l );
2530       break;
2531     }
2532
2533   case 300:                                     // ERASE
2534   case 301:                                     // DISPLAY
2535   case 302:                                     // DISPLAY ONLY
2536     {
2537       SMESH::EDisplaing anAction;
2538       switch (theCommandID) {
2539       case 300: anAction = SMESH::eErase; break;
2540       case 301: anAction = SMESH::eDisplay; break;
2541       case 302: anAction = SMESH::eDisplayOnly; break;
2542       }
2543
2544       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2545       SALOME_ListIO sel_objects, to_process;
2546       if (aSel)
2547         aSel->selectedObjects( sel_objects );
2548
2549       if( theCommandID==302 )
2550       {
2551         MESSAGE("anAction = SMESH::eDisplayOnly");
2552         startOperation( myEraseAll );
2553       }
2554
2555       extractContainers( sel_objects, to_process );
2556
2557       try {
2558 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2559         OCC_CATCH_SIGNALS;
2560 #endif
2561         if (vtkwnd) {
2562           SALOME_ListIteratorOfListIO It( to_process );
2563           for ( ; It.More(); It.Next()) {
2564             MESSAGE("---");
2565             Handle(SALOME_InteractiveObject) IOS = It.Value();
2566             if (IOS->hasEntry()) {
2567               MESSAGE("---");
2568               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
2569                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2570                 break; // PAL16774 (Crash after display of many groups)
2571               }
2572               if (anAction == SMESH::eDisplayOnly)
2573               {
2574                 MESSAGE("anAction = SMESH::eDisplayOnly");
2575                 anAction = SMESH::eDisplay;
2576               }
2577             }
2578           }
2579         }
2580
2581         // PAL13338 + PAL15161 -->
2582         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
2583           MESSAGE("anAction = SMESH::eDisplayOnly");
2584           SMESH::UpdateView();
2585           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2586         }
2587         // PAL13338 + PAL15161 <--
2588       }
2589       catch (...) { // PAL16774 (Crash after display of many groups)
2590         SMESH::OnVisuException();
2591       }
2592
2593       if (anAction == SMESH::eErase) {
2594         MESSAGE("anAction == SMESH::eErase");
2595         SALOME_ListIO l1;
2596         aSel->setSelectedObjects( l1 );
2597       }
2598       else
2599         aSel->setSelectedObjects( to_process );
2600
2601       break;
2602     }
2603
2604   case 4000:                                    // NODES
2605     {
2606       if(checkLock(aStudy)) break;
2607
2608       if ( vtkwnd ) {
2609         EmitSignalDeactivateDialog();
2610
2611         ( new SMESHGUI_NodesDlg( this ) )->show();
2612       }
2613       else {
2614         SUIT_MessageBox::warning(desktop(),
2615                                  tr("SMESH_WRN_WARNING"),
2616                                  tr("SMESH_WRN_VIEWER_VTK"));
2617       }
2618       break;
2619     }
2620
2621   case 2151:  // FILTER
2622   {
2623     if ( vtkwnd )
2624     {
2625       EmitSignalDeactivateDialog();
2626       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
2627     }
2628     break;
2629   }
2630
2631   case 701: // COMPUTE MESH
2632   case 711: // PRECOMPUTE MESH
2633   case 712: // EVALUATE MESH
2634   case 713: // MESH ORDER
2635   case 702: // Create mesh
2636   case 703: // Create sub-mesh
2637   case 704: // Edit mesh/sub-mesh
2638     startOperation( theCommandID );
2639     break;
2640   case 705: // copy mesh
2641     {
2642       if (checkLock(aStudy)) break;
2643       EmitSignalDeactivateDialog();
2644       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2645     }
2646     break;
2647   case 710: // Build compound mesh
2648     {
2649       if (checkLock(aStudy)) break;
2650       EmitSignalDeactivateDialog();
2651       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2652     }
2653     break;
2654
2655   case 407: // DIAGONAL INVERSION
2656   case 408: // Delete diagonal
2657     {
2658       if ( !vtkwnd )
2659       {
2660         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2661                                   tr( "NOT_A_VTK_VIEWER" ) );
2662         break;
2663       }
2664
2665       if ( checkLock( aStudy ) )
2666         break;
2667
2668       /*Standard_Boolean aRes;
2669       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2670       if ( aMesh->_is_nil() )
2671       {
2672         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2673           tr( "SMESH_BAD_SELECTION" ) );
2674         break;
2675       }
2676       */
2677       EmitSignalDeactivateDialog();
2678       if ( theCommandID == 407 )
2679         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2680       else
2681         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2682       break;
2683     }
2684   case 409: // Change orientation
2685   case 410: // Union of triangles
2686   case 411: // Cutting of quadrangles
2687   case 419: // Splitting volumes into tetrahedra
2688     {
2689       if ( !vtkwnd )
2690       {
2691         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2692                                   tr( "NOT_A_VTK_VIEWER" ) );
2693         break;
2694       }
2695
2696       if ( checkLock( aStudy ) )
2697         break;
2698
2699       EmitSignalDeactivateDialog();
2700       SMESHGUI_MultiEditDlg* aDlg = NULL;
2701       if ( theCommandID == 409 )
2702         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2703       else if ( theCommandID == 410 )
2704         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2705       else if ( theCommandID == 419 )
2706         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2707       else
2708         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2709
2710       aDlg->show();
2711       break;
2712     }
2713   case 412: // Smoothing
2714     {
2715       if(checkLock(aStudy)) break;
2716       if( vtkwnd ) {
2717         EmitSignalDeactivateDialog();
2718         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2719       }
2720       else {
2721         SUIT_MessageBox::warning(desktop(),
2722                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2723       }
2724       break;
2725     }
2726   case 413: // Extrusion
2727     {
2728       if (checkLock(aStudy)) break;
2729       if (vtkwnd) {
2730         EmitSignalDeactivateDialog();
2731         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2732       } else {
2733         SUIT_MessageBox::warning(desktop(),
2734                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2735       }
2736       break;
2737     }
2738   case 414: // Revolution
2739     {
2740       if(checkLock(aStudy)) break;
2741       if( vtkwnd ) {
2742         EmitSignalDeactivateDialog();
2743         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2744       }
2745       else {
2746         SUIT_MessageBox::warning(desktop(),
2747                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2748       }
2749       break;
2750     }
2751   case 415: // Pattern mapping
2752     {
2753       if ( checkLock( aStudy ) )
2754         break;
2755       if ( vtkwnd )
2756       {
2757         EmitSignalDeactivateDialog();
2758         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2759       }
2760       else {
2761         SUIT_MessageBox::warning(desktop(),
2762                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2763       }
2764       break;
2765     }
2766   case 416: // Extrusion along a path
2767     {
2768       if (checkLock(aStudy)) break;
2769       if (vtkwnd) {
2770         EmitSignalDeactivateDialog();
2771         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2772       } else {
2773         SUIT_MessageBox::warning(desktop(),
2774                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2775       }
2776       break;
2777     }
2778   case 417: // Convert mesh to quadratic
2779   case 418: // create 2D mesh from 3D
2780   case 420: // Reorient faces
2781   case 806: // CREATE GEO GROUP
2782     {
2783       startOperation( theCommandID );
2784       break;
2785     }
2786   case 801:                                     // CREATE GROUP
2787     {
2788       if ( !vtkwnd )
2789       {
2790         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2791                                   tr( "NOT_A_VTK_VIEWER" ) );
2792         break;
2793       }
2794
2795       if(checkLock(aStudy)) break;
2796       EmitSignalDeactivateDialog();
2797       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2798
2799       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2800       SALOME_ListIO selected;
2801       if( aSel )
2802         aSel->selectedObjects( selected );
2803
2804       int nbSel = selected.Extent();
2805       if (nbSel == 1) {
2806         // check if mesh is selected
2807         aMesh = SMESH::GetMeshByIO( selected.First() );
2808       }
2809       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2810       aDlg->show();
2811       break;
2812     }
2813
2814   case 802:                                     // CONSTRUCT GROUP
2815     {
2816       if ( !vtkwnd )
2817       {
2818         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2819                                   tr( "NOT_A_VTK_VIEWER" ) );
2820         break;
2821       }
2822
2823       if(checkLock(aStudy)) break;
2824       EmitSignalDeactivateDialog();
2825
2826       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2827       SALOME_ListIO selected;
2828       if( aSel )
2829         aSel->selectedObjects( selected );
2830
2831       int nbSel = selected.Extent();
2832       if (nbSel == 1) {
2833         // check if submesh is selected
2834         Handle(SALOME_InteractiveObject) IObject = selected.First();
2835         if (IObject->hasEntry()) {
2836           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2837           if( aSObj ) {
2838             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2839             if (!aSubMesh->_is_nil()) {
2840               try {
2841                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2842                 // get submesh elements list by types
2843                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2844                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2845                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2846                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2847                 // create group for each type o elements
2848                 QString aName = IObject->getName();
2849                 QStringList anEntryList;
2850                 if (aNodes->length() > 0) {
2851                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2852                   aGroup->Add(aNodes.inout());
2853                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2854                     anEntryList.append( aSObject->GetID().c_str() );
2855                 }
2856                 if (aEdges->length() > 0) {
2857                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2858                   aGroup->Add(aEdges.inout());
2859                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2860                     anEntryList.append( aSObject->GetID().c_str() );
2861                 }
2862                 if (aFaces->length() > 0) {
2863                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2864                   aGroup->Add(aFaces.inout());
2865                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2866                     anEntryList.append( aSObject->GetID().c_str() );
2867                 }
2868                 if (aVolumes->length() > 0) {
2869                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2870                   aGroup->Add(aVolumes.inout());
2871                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2872                     anEntryList.append( aSObject->GetID().c_str() );
2873                 }
2874                 updateObjBrowser();
2875                 anApp->browseObjects( anEntryList );
2876               }
2877               catch(const SALOME::SALOME_Exception & S_ex){
2878                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2879               }
2880             }
2881           }
2882         }
2883       }
2884       else if(nbSel==0) {
2885         SUIT_MessageBox::warning(desktop(),
2886                                  tr("SMESH_WRN_WARNING"),
2887                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2888       }
2889       break;
2890     }
2891
2892   case 803:                                     // EDIT GROUP
2893     {
2894       if ( !vtkwnd )
2895       {
2896         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2897                                   tr( "NOT_A_VTK_VIEWER" ) );
2898         break;
2899       }
2900
2901       if(checkLock(aStudy)) break;
2902       EmitSignalDeactivateDialog();
2903
2904       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2905       SALOME_ListIO selected;
2906       if( aSel )
2907         aSel->selectedObjects( selected );
2908
2909       SALOME_ListIteratorOfListIO It (selected);
2910       int nbSelectedGroups = 0;
2911       for ( ; It.More(); It.Next() )
2912       {
2913         SMESH::SMESH_GroupBase_var aGroup =
2914           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2915         if (!aGroup->_is_nil()) {
2916           nbSelectedGroups++;
2917           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2918           aDlg->show();
2919         }
2920       }
2921       if (nbSelectedGroups == 0)
2922         {
2923           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2924           aDlg->show();
2925         }
2926       break;
2927     }
2928
2929   case 804:                                     // Add elements to group
2930     {
2931       if(checkLock(aStudy)) break;
2932       if (myState == 800) {
2933         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2934         if (aDlg) aDlg->onAdd();
2935       }
2936       break;
2937     }
2938
2939   case 805:                                     // Remove elements from group
2940     {
2941       if(checkLock(aStudy)) break;
2942       if (myState == 800) {
2943         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2944         if (aDlg) aDlg->onRemove();
2945       }
2946       break;
2947     }
2948
2949   case 815:                                     // Edit GEOM GROUP as standalone
2950     {
2951       if ( !vtkwnd )
2952       {
2953         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2954                                   tr( "NOT_A_VTK_VIEWER" ) );
2955         break;
2956       }
2957
2958       if(checkLock(aStudy)) break;
2959       EmitSignalDeactivateDialog();
2960
2961       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2962       SALOME_ListIO selected;
2963       if( aSel )
2964         aSel->selectedObjects( selected );
2965
2966       SALOME_ListIteratorOfListIO It (selected);
2967       for ( ; It.More(); It.Next() )
2968       {
2969         SMESH::SMESH_GroupOnGeom_var aGroup =
2970           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
2971         if (!aGroup->_is_nil()) {
2972           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2973           aDlg->show();
2974         }
2975         else
2976         {
2977           SMESH::SMESH_GroupOnFilter_var aGroup =
2978             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
2979           if (!aGroup->_is_nil()) {
2980             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2981             aDlg->show();
2982           }
2983         }
2984       }
2985       break;
2986     }
2987
2988     case 810: // Union Groups
2989     case 811: // Intersect groups
2990     case 812: // Cut groups
2991     {
2992       if ( !vtkwnd )
2993       {
2994         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2995                                   tr( "NOT_A_VTK_VIEWER" ) );
2996         break;
2997       }
2998
2999       if ( checkLock( aStudy ) )
3000         break;
3001
3002       EmitSignalDeactivateDialog();
3003
3004       SMESHGUI_GroupOpDlg* aDlg = 0;
3005       if ( theCommandID == 810 )
3006         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3007       else if ( theCommandID == 811 )
3008         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3009       else
3010         aDlg = new SMESHGUI_CutGroupsDlg( this );
3011
3012       aDlg->show();
3013
3014       break;
3015     }
3016
3017     case 814: // Create groups of entities from existing groups of superior dimensions
3018     {
3019       if ( checkLock( aStudy ) )
3020         break;
3021
3022       EmitSignalDeactivateDialog();
3023       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3024       aDlg->show();
3025
3026       break;
3027     }
3028
3029     case 813: // Delete groups with their contents
3030     {
3031       if ( !vtkwnd )
3032       {
3033         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3034                                   tr( "NOT_A_VTK_VIEWER" ) );
3035         break;
3036       }
3037
3038       if ( checkLock( aStudy ) )
3039         break;
3040
3041       EmitSignalDeactivateDialog();
3042
3043       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3044       break;
3045     }
3046
3047   case 900:                                     // MESH INFOS
3048   case 903:                                     // WHAT IS
3049     {
3050       int page = theCommandID == 900 ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3051       EmitSignalDeactivateDialog();
3052       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3053       SALOME_ListIO selected;
3054       if( aSel )
3055         aSel->selectedObjects( selected );
3056
3057       if ( selected.Extent() > 1 ) { // a dlg for each IO
3058         SALOME_ListIteratorOfListIO It( selected );
3059         for ( ; It.More(); It.Next() ) {
3060           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3061           dlg->showInfo( It.Value() ); 
3062           dlg->show();
3063         }
3064       }
3065       else {
3066         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3067         dlg->show();
3068       }
3069       break;
3070     }
3071
3072   case 904:                                     // FIND ELEM
3073     {
3074       startOperation( theCommandID );
3075       break;
3076     }
3077
3078   case 1100:                                    // EDIT HYPOTHESIS
3079     {
3080       if(checkLock(aStudy)) break;
3081
3082       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3083       SALOME_ListIO selected;
3084       if( aSel )
3085         aSel->selectedObjects( selected );
3086
3087       int nbSel = selected.Extent();
3088
3089       if (nbSel == 1) {
3090         Handle(SALOME_InteractiveObject) anIObject = selected.First();
3091         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3092
3093         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
3094         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
3095         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
3096         if ( !aHypothesis->_is_nil() )
3097         {
3098           // BUG 0020378
3099           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
3100           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
3101           if (aCreator) {
3102             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3103           }
3104           else
3105           {
3106             // report error
3107           }
3108         }
3109       }
3110       break;
3111     }
3112   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
3113     {
3114       if(checkLock(aStudy)) break;
3115       SUIT_OverrideCursor wc;
3116
3117       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3118       SALOME_ListIO selected;
3119       if( aSel )
3120         aSel->selectedObjects( selected, QString::null, false );
3121
3122       SALOME_ListIteratorOfListIO It(selected);
3123       for (int i = 0; It.More(); It.Next(), i++) {
3124         Handle(SALOME_InteractiveObject) IObject = It.Value();
3125         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3126       }
3127       SALOME_ListIO l1;
3128       aSel->setSelectedObjects( l1 );
3129       updateObjBrowser();
3130       break;
3131     }
3132
3133   case 4008:                                    // BALL
3134   case 4009:                                    // ELEM0D
3135   case 4010:                                    // EDGE
3136   case 4021:                                    // TRIANGLE
3137   case 4022:                                    // QUAD
3138   case 4023:                                    // POLYGON
3139   case 4031:                                    // TETRA
3140   case 4032:                                    // HEXA
3141   case 4133:                                    // PENTA
3142   case 4134:                                    // PYRAMID
3143   case 4135:                                    // OCTA12
3144     {
3145       if(checkLock(aStudy)) break;
3146       if ( vtkwnd ) {
3147         EmitSignalDeactivateDialog();
3148         SMDSAbs_EntityType type = SMDSEntity_Edge;
3149         switch (theCommandID) {
3150         case 4008: type = SMDSEntity_Ball;            break;
3151         case 4009: type = SMDSEntity_0D;              break;
3152         case 4021: type = SMDSEntity_Triangle;        break;
3153         case 4022: type = SMDSEntity_Quadrangle;      break;
3154         case 4031: type = SMDSEntity_Tetra;           break;
3155         case 4023: type = SMDSEntity_Polygon;         break;
3156         case 4032: type = SMDSEntity_Hexa;            break;
3157         case 4133: type = SMDSEntity_Penta;           break;
3158         case 4134: type = SMDSEntity_Pyramid;         break;
3159         case 4135: type = SMDSEntity_Hexagonal_Prism; break;
3160         default:;
3161         }
3162         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3163       }
3164       else {
3165         SUIT_MessageBox::warning(desktop(),
3166                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3167       }
3168       break;
3169     }
3170   case 4033:                                    // POLYHEDRON
3171     {
3172       if(checkLock(aStudy)) break;
3173       if ( vtkwnd ) {
3174         EmitSignalDeactivateDialog();
3175         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3176       }
3177       else {
3178         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3179                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3180       }
3181       break;
3182     }
3183   case 4034:     // QUADRATIC EDGE
3184   case 4035:     // QUADRATIC TRIANGLE
3185   case 4036:     // QUADRATIC QUADRANGLE
3186   case 4136:     // BIQUADRATIC QUADRANGLE
3187   case 4137:     // BIQUADRATIC TRIANGLE
3188   case 4037:     // QUADRATIC TETRAHEDRON
3189   case 4038:     // QUADRATIC PYRAMID
3190   case 4039:     // QUADRATIC PENTAHEDRON
3191   case 4040:     // QUADRATIC HEXAHEDRON
3192   case 4140:     // TRIQUADRATIC HEXAHEDRON
3193     {
3194       if(checkLock(aStudy)) break;
3195       if ( vtkwnd ) {
3196         EmitSignalDeactivateDialog();
3197         SMDSAbs_EntityType type = SMDSEntity_Last;
3198
3199         switch (theCommandID) {
3200         case 4034: type = SMDSEntity_Quad_Edge; break;
3201         case 4035: type = SMDSEntity_Quad_Triangle; break;
3202         case 4036: type = SMDSEntity_Quad_Quadrangle; break;
3203         case 4136: type = SMDSEntity_BiQuad_Quadrangle; break;
3204         case 4137: type = SMDSEntity_BiQuad_Triangle; break;
3205         case 4037: type = SMDSEntity_Quad_Tetra; break;
3206         case 4038: type = SMDSEntity_Quad_Pyramid; break;
3207         case 4039: type = SMDSEntity_Quad_Penta; break;
3208         case 4040: type = SMDSEntity_Quad_Hexa; break;
3209         case 4140: type = SMDSEntity_TriQuad_Hexa; break;
3210         default: break;
3211         }
3212         if ( type != SMDSEntity_Last )
3213           ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3214       }
3215       else {
3216         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3217                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3218       }
3219       break;
3220     }
3221   case 4041:                                    // REMOVES NODES
3222     {
3223       if(checkLock(aStudy)) break;
3224       if ( vtkwnd ) {
3225         EmitSignalDeactivateDialog();
3226         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3227       }
3228       else {
3229         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3230                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3231       }
3232       break;
3233     }
3234   case 4042:                                    // REMOVES ELEMENTS
3235     {
3236       if(checkLock(aStudy)) break;
3237       if( vtkwnd ) {
3238         EmitSignalDeactivateDialog();
3239         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3240       }
3241       else
3242         {
3243           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3244                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3245         }
3246       break;
3247     }
3248   case 4043: {                                // CLEAR_MESH
3249
3250     if(checkLock(aStudy)) break;
3251
3252     SALOME_ListIO selected;
3253     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3254       aSel->selectedObjects( selected );
3255
3256     SUIT_OverrideCursor wc;
3257     SALOME_ListIteratorOfListIO It (selected);
3258     for ( ; It.More(); It.Next() )
3259     {
3260       Handle(SALOME_InteractiveObject) IOS = It.Value();
3261       SMESH::SMESH_Mesh_var aMesh =
3262         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3263       if ( aMesh->_is_nil()) continue;
3264       try {
3265         SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3266         aMesh->Clear();
3267         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3268         SMESH::ModifiedMesh( aMeshSObj, false, true);
3269         // hide groups and submeshes
3270         _PTR(ChildIterator) anIter =
3271           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3272         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3273         {
3274           _PTR(SObject) so = anIter->Value();
3275           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3276         }
3277       }
3278       catch (const SALOME::SALOME_Exception& S_ex){
3279         wc.suspend();
3280         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3281         wc.resume();
3282       }
3283     }
3284     SMESH::UpdateView();
3285     updateObjBrowser();
3286     break;
3287   }
3288   case 4044:                                     // REMOVE ORPHAN NODES
3289     {
3290       if(checkLock(aStudy)) break;
3291       SALOME_ListIO selected;
3292       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3293         aSel->selectedObjects( selected );
3294       if ( selected.Extent() == 1 ) {
3295         Handle(SALOME_InteractiveObject) anIO = selected.First();
3296         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3297         if ( !aMesh->_is_nil() ) {
3298           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3299                                                     tr( "SMESH_WARNING" ),
3300                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3301                                                     SUIT_MessageBox::Yes |
3302                                                     SUIT_MessageBox::No,
3303                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3304           if( confirm ) {
3305             try {
3306               SUIT_OverrideCursor wc;
3307               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3308               int removed = aMeshEditor->RemoveOrphanNodes();
3309               SUIT_MessageBox::information(SMESHGUI::desktop(),
3310                                            tr("SMESH_INFORMATION"),
3311                                            tr("NB_NODES_REMOVED").arg(removed));
3312               if ( removed > 0 ) {
3313                 SMESH::UpdateView();
3314                 SMESHGUI::Modified();
3315               }
3316             }
3317             catch (const SALOME::SALOME_Exception& S_ex) {
3318               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3319             }
3320             catch (...) {
3321             }
3322           }
3323         }
3324       }
3325       break;
3326     }
3327   case 4051:                                    // RENUMBERING NODES
3328     {
3329       if(checkLock(aStudy)) break;
3330       if( vtkwnd ) {
3331         EmitSignalDeactivateDialog();
3332         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3333       }
3334       else
3335         {
3336           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3337                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3338         }
3339       break;
3340     }
3341   case 4052:                                    // RENUMBERING ELEMENTS
3342     {
3343       if(checkLock(aStudy)) break;
3344       if ( vtkwnd ) {
3345         EmitSignalDeactivateDialog();
3346         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3347       }
3348       else
3349         {
3350           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3351                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3352         }
3353       break;
3354     }
3355   case 4061:                                   // TRANSLATION
3356     {
3357       if(checkLock(aStudy)) break;
3358       if ( vtkwnd ) {
3359         EmitSignalDeactivateDialog();
3360         ( new SMESHGUI_TranslationDlg( this ) )->show();
3361       }
3362       else {
3363         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3364                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3365       }
3366       break;
3367     }
3368   case 4062:                                   // ROTATION
3369     {
3370       if(checkLock(aStudy)) break;
3371       if( vtkwnd ) {
3372         EmitSignalDeactivateDialog();
3373         ( new SMESHGUI_RotationDlg( this ) )->show();
3374       }
3375       else {
3376         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3377                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3378       }
3379       break;
3380     }
3381   case 4063:                                   // SYMMETRY
3382     {
3383       if(checkLock(aStudy)) break;
3384       if(vtkwnd) {
3385         EmitSignalDeactivateDialog();
3386         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3387       }
3388       else {
3389         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3390                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3391       }
3392       break;
3393     }
3394   case 4064:                                   // SEWING
3395     {
3396       if(checkLock(aStudy)) break;
3397       if(vtkwnd) {
3398         EmitSignalDeactivateDialog();
3399         ( new SMESHGUI_SewingDlg( this ) )->show();
3400       }
3401       else {
3402         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3403                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3404       }
3405       break;
3406     }
3407   case 4065:                                   // MERGE NODES
3408     {
3409       if(checkLock(aStudy)) break;
3410       if(vtkwnd) {
3411         EmitSignalDeactivateDialog();
3412         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3413       }
3414       else {
3415         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3416                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3417       }
3418       break;
3419     }
3420   case 4066:                                   // MERGE EQUAL ELEMENTS
3421     {
3422       if (checkLock(aStudy)) break;
3423       if (vtkwnd) {
3424         EmitSignalDeactivateDialog();
3425         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3426       } else {
3427         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3428                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3429       }
3430       break;
3431     }
3432
3433   case 4067: // MAKE MESH PASS THROUGH POINT
3434     startOperation( 4067 );
3435     break;
3436
3437   case 4068: // SCALE
3438     {
3439       if(checkLock(aStudy)) break;
3440       if ( vtkwnd ) {
3441         EmitSignalDeactivateDialog();
3442         ( new SMESHGUI_ScaleDlg( this ) )->show();
3443       }
3444       else {
3445         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3446                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3447       }
3448       break;
3449     }
3450
3451   case 4069: // DUPLICATE NODES
3452     {
3453       if(checkLock(aStudy)) break;
3454       if ( vtkwnd ) {
3455         EmitSignalDeactivateDialog();
3456         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3457       }
3458       else {
3459         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3460                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3461       }
3462       break;
3463     }
3464
3465   case 4070: // 0D_ON_ALL_NODES
3466     startOperation( 4070 );
3467     break;
3468
3469   case 5105: // Library of selection filters
3470   {
3471     static QList<int> aTypes;
3472     if ( aTypes.isEmpty() )
3473     {
3474       aTypes.append( SMESH::NODE );
3475       aTypes.append( SMESH::EDGE );
3476       aTypes.append( SMESH::FACE );
3477       aTypes.append( SMESH::VOLUME );
3478     }
3479     if (!myFilterLibraryDlg)
3480       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3481     else if (myFilterLibraryDlg->isHidden())
3482       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3483     myFilterLibraryDlg->raise();
3484   }
3485   break;
3486
3487   case 6017:                                    // CONTROLS
3488   case 6016:
3489   case 6015:
3490   case 6014:
3491   case 6013:
3492   case 6012:
3493   case 6011:
3494   case 6001:
3495   case 6018:
3496   case 6019:
3497   case 6002:
3498   case 6003:
3499   case 6004:
3500   case 6005:
3501   case 6009:
3502   case 6021:
3503   case 6022:
3504   case 6023:
3505   case 6024:
3506   case 6025:
3507   case 6026:
3508   case 6027:
3509   case 6028:
3510   case 6029:
3511   case 6030:
3512   case 6031:
3513     if ( vtkwnd ) {
3514
3515       LightApp_SelectionMgr* mgr = selectionMgr();
3516       SALOME_ListIO selected; mgr->selectedObjects( selected );
3517
3518       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
3519         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
3520         if ( SO ) {
3521           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
3522           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
3523           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
3524           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
3525           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
3526             SUIT_OverrideCursor wc;
3527             ::Control( theCommandID );
3528             break;
3529           }
3530         }
3531       }
3532       SUIT_MessageBox::warning(desktop(),
3533                                tr( "SMESH_WRN_WARNING" ),
3534                                tr( "SMESH_BAD_SELECTION" ) );
3535       break;
3536     }
3537     else {
3538       SUIT_MessageBox::warning(desktop(),
3539                                tr( "SMESH_WRN_WARNING" ),
3540                                tr( "NOT_A_VTK_VIEWER" ) );
3541     }
3542     break;
3543   case 6032:
3544     OverallMeshQuality();
3545     break;
3546   case 9010:
3547     {
3548       SUIT_OverrideCursor wc;
3549       LightApp_SelectionMgr* mgr = selectionMgr();
3550       SALOME_ListIO selected; mgr->selectedObjects( selected );
3551
3552       SALOME_ListIteratorOfListIO it(selected);
3553       for( ; it.More(); it.Next()) {
3554         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3555         if(anIObject->hasEntry()) {
3556           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3557             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3558           }
3559         }
3560       }
3561       break;
3562     }
3563   case 9011:
3564     {
3565       SUIT_OverrideCursor wc;
3566       LightApp_SelectionMgr* mgr = selectionMgr();
3567       SALOME_ListIO selected; mgr->selectedObjects( selected );
3568
3569       SALOME_ListIteratorOfListIO it(selected);
3570       for( ; it.More(); it.Next()) {
3571         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3572         if(anIObject->hasEntry())
3573           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3574             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3575           }
3576       }
3577       break;
3578     }
3579   case 501:
3580   case 502:
3581   case 503:
3582   case 504:
3583   case 505:
3584     {
3585       int page = SMESHGUI_MeasureDlg::MinDistance;
3586       if ( theCommandID == 502 )
3587         page = SMESHGUI_MeasureDlg::BoundingBox;
3588       else if ( theCommandID == 503 )
3589         page = SMESHGUI_MeasureDlg::Length;
3590       else if ( theCommandID == 504 )
3591         page = SMESHGUI_MeasureDlg::Area;
3592       else if ( theCommandID == 505 )
3593         page = SMESHGUI_MeasureDlg::Volume;
3594
3595       EmitSignalDeactivateDialog();
3596       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3597       dlg->show();
3598       break;
3599     }
3600   case 41:
3601     ::sortChildren();
3602     break;
3603
3604   }
3605
3606   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3607   //updateObjBrowser();
3608   return true;
3609 }
3610
3611 //=============================================================================
3612 /*!
3613  *
3614  */
3615 //=============================================================================
3616 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3617 {
3618   return false;
3619 }
3620
3621 //=============================================================================
3622 /*!
3623  *
3624  */
3625 //=============================================================================
3626 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3627 {
3628   return true;
3629 }
3630
3631 //=============================================================================
3632 /*!
3633  *
3634  */
3635 //=============================================================================
3636 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
3637 {
3638   return true;
3639 }
3640
3641 //=============================================================================
3642 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3643  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3644  */
3645 //=============================================================================
3646 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3647                                   SUIT_ViewWindow* wnd )
3648 {
3649   if(theIO->hasEntry()){
3650     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3651     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3652   }
3653 }
3654
3655 //=======================================================================
3656 // function : createSMESHAction
3657 // purpose  :
3658 //=======================================================================
3659 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
3660                                   const int key, const bool toggle, const QString& shortcutAction  )
3661 {
3662   QIcon icon;
3663   QWidget* parent = application()->desktop();
3664   SUIT_ResourceMgr* resMgr = resourceMgr();
3665   QPixmap pix;
3666   if ( !icon_id.isEmpty() )
3667     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3668   else
3669     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
3670   if ( !pix.isNull() )
3671     icon = QIcon( pix );
3672
3673   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
3674           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
3675           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
3676
3677   createAction( id, tooltip, icon, menu, status_bar, key, parent,
3678                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
3679 }
3680
3681 //=======================================================================
3682 // function : createPopupItem
3683 // purpose  :
3684 //=======================================================================
3685 void SMESHGUI::createPopupItem( const int id,
3686                                 const QString& clients,
3687                                 const QString& types,
3688                                 const QString& theRule,
3689                                 const int pId )
3690 {
3691   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
3692     popupMgr()->insert( action( id ), pId, 0 );
3693
3694   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3695   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
3696   QString rule = "(%1) and (%2) and (%3)";
3697   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
3698   if( clients.isEmpty() )
3699     rule = rule.arg( QString( "true" ) );
3700   else
3701     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
3702   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
3703   rule += theRule;
3704
3705   bool cont = myRules.contains( id );
3706   if( cont )
3707     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
3708
3709   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
3710   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
3711 }
3712
3713 //=======================================================================
3714 // function : initialize
3715 // purpose  :
3716 //=======================================================================
3717 void SMESHGUI::initialize( CAM_Application* app )
3718 {
3719   SalomeApp_Module::initialize( app );
3720
3721 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
3722 //   if ( mgr )
3723   /* Automatic Update flag */
3724 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
3725
3726   // ----- create actions --------------
3727
3728   //createSMESHAction(  111, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
3729   createSMESHAction(  112, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_U) );
3730   createSMESHAction(  113, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
3731   createSMESHAction(  114, "NUM" );
3732   createSMESHAction(  115, "IMPORT_STL"  );
3733   createSMESHAction(  116, "IMPORT_CGNS" );
3734   createSMESHAction(  117, "IMPORT_SAUV" );
3735   createSMESHAction(  118, "IMPORT_GMF"  );
3736   createSMESHAction(  121, "DAT" );
3737   createSMESHAction(  122, "MED" );
3738   createSMESHAction(  123, "UNV" );
3739   createSMESHAction(  140, "STL" );
3740   createSMESHAction(  142, "CGNS");
3741   createSMESHAction(  144, "SAUV");
3742   createSMESHAction(  146, "GMF" );
3743   createSMESHAction(  124, "DAT" );
3744   createSMESHAction(  125, "MED" );
3745   createSMESHAction(  126, "UNV" );
3746   createSMESHAction(  141, "STL" );
3747   createSMESHAction(  143, "CGNS");
3748   createSMESHAction(  145, "SAUV");
3749   createSMESHAction(  147, "GMF" );
3750   createSMESHAction(  150, "FILE_INFO" );
3751   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
3752   createSMESHAction( 5105, "SEL_FILTER_LIB" );
3753   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
3754   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
3755   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
3756   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
3757   createSMESHAction(  705, "COPY_MESH",       "ICON_COPY_MESH" );
3758   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
3759   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
3760   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
3761   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
3762   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
3763   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
3764   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
3765   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
3766   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
3767   createSMESHAction(  804, "ADD" );
3768   createSMESHAction(  805, "REMOVE" );
3769   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
3770   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
3771   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
3772   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
3773   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
3774   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
3775   //createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
3776   //createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3777   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
3778   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
3779   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
3780   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
3781   createSMESHAction( 6022, "MAX_ELEMENT_LENGTH_2D",  "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
3782   createSMESHAction( 6023, "MAX_ELEMENT_LENGTH_3D",  "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
3783   createSMESHAction( 6024, "BARE_BORDER_VOLUME",     "ICON_BARE_BORDER_VOLUME",      0, true );
3784   createSMESHAction( 6025, "BARE_BORDER_FACE",       "ICON_BARE_BORDER_FACE",        0, true );
3785   createSMESHAction( 6026, "OVER_CONSTRAINED_VOLUME","ICON_OVER_CONSTRAINED_VOLUME", 0, true );
3786   createSMESHAction( 6027, "OVER_CONSTRAINED_FACE",  "ICON_OVER_CONSTRAINED_FACE",   0, true );
3787   createSMESHAction( 6028, "EQUAL_NODE",      "ICON_EQUAL_NODE",    0, true );
3788   createSMESHAction( 6029, "EQUAL_EDGE",      "ICON_EQUAL_EDGE",    0, true );
3789   createSMESHAction( 6030, "EQUAL_FACE",      "ICON_EQUAL_FACE",    0, true );
3790   createSMESHAction( 6031, "EQUAL_VOLUME",    "ICON_EQUAL_VOLUME",  0, true );
3791   createSMESHAction( 6032, "OVERALL_MESH_QUALITY" );
3792   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
3793   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
3794   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
3795   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
3796   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
3797   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
3798   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
3799   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
3800   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
3801   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
3802   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
3803   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
3804   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
3805   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
3806   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
3807   createSMESHAction( 4008, "BALL",            "ICON_DLG_BALL" );
3808   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
3809   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
3810   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
3811   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
3812   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
3813   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
3814   createSMESHAction( 4133, "PENTA",           "ICON_DLG_PENTA" );
3815   createSMESHAction( 4134, "PYRAMID",         "ICON_DLG_PYRAMID" );
3816   createSMESHAction( 4135, "OCTA",            "ICON_DLG_OCTA" );
3817   createSMESHAction( 4033, "POLYHEDRON",              "ICON_DLG_POLYHEDRON" );
3818   createSMESHAction( 4034, "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
3819   createSMESHAction( 4035, "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
3820   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
3821   createSMESHAction( 4136, "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
3822   createSMESHAction( 4137, "BIQUADRATIC_TRIANGLE",    "ICON_DLG_BIQUADRATIC_TRIANGLE" );
3823   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3824   createSMESHAction( 4038, "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
3825   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3826   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3827   createSMESHAction( 4140, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
3828   createSMESHAction( 4041, "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
3829   createSMESHAction( 4042, "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
3830   createSMESHAction( 4044, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
3831   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
3832   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
3833   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
3834   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
3835   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
3836   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
3837   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
3838   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
3839   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
3840   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
3841   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
3842   createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
3843   createSMESHAction( 4070, "0D_ON_ALL_NODES", "ICON_0D_ON_ALL_NODES" );
3844   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
3845   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
3846   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
3847   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
3848   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
3849   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
3850   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
3851   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
3852   createSMESHAction(  415, "MAP",             "ICON_MAP" );
3853   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
3854   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
3855   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
3856   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
3857   createSMESHAction(  420, "REORIENT_2D",     "ICON_REORIENT_2D" );
3858   createSMESHAction(  200, "RESET" );
3859   createSMESHAction(  201, "SCALAR_BAR_PROP" );
3860   createSMESHAction(  2021, "SAVE_DISTRIBUTION" );
3861   createSMESHAction(  2022, "SHOW_DISTRIBUTION","",0, true );
3862 #ifndef DISABLE_PLOT2DVIEWER
3863   createSMESHAction(  2023, "PLOT_DISTRIBUTION" );
3864 #endif
3865   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
3866   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
3867   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
3868   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
3869   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
3870   createSMESHAction(  222, "BALLS",          "ICON_DLG_BALL", 0, true );
3871   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
3872   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
3873   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
3874   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3875   createSMESHAction(  220, "ALL" );
3876   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3877
3878   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3879   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3880
3881   createSMESHAction( 1100, "EDIT_HYPO" );
3882   createSMESHAction( 1102, "UNASSIGN" );
3883   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3884   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3885   createSMESHAction( 1131, "DISPMODE" );
3886   createSMESHAction( 1132, "COLORS" );
3887   createSMESHAction( 1133, "TRANSP" );
3888   createSMESHAction( 1134, "CLIP" );
3889   createSMESHAction( 1135, "DISP_ENT" );
3890   createSMESHAction( 1136, "AUTO_COLOR" );
3891   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3892   createSMESHAction( 2000, "CTRL" );
3893
3894   createSMESHAction( 501, "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
3895   createSMESHAction( 502, "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
3896   createSMESHAction( 503, "MEASURE_LENGTH",   "ICON_MEASURE_LENGTH" );
3897   createSMESHAction( 504, "MEASURE_AREA",     "ICON_MEASURE_AREA" );
3898   createSMESHAction( 505, "MEASURE_VOLUME",   "ICON_MEASURE_VOLUME" );
3899
3900   createSMESHAction( 300, "HIDE" );
3901   createSMESHAction( 301, "SHOW" );
3902   createSMESHAction( 302, "DISPLAY_ONLY" );
3903
3904   createSMESHAction( 41, "SORT_CHILD_ITEMS" );
3905
3906   // ----- create menu --------------
3907   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
3908       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
3909       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
3910       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
3911       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
3912       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
3913       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
3914       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
3915
3916   createMenu( separator(), fileId );
3917
3918   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3919       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3920       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10 ),
3921       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10 ),
3922       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10 ),
3923       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10 ),
3924       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3925       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3926       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3927       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
3928       basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 );
3929
3930   //createMenu( 111, importId, -1 );
3931   createMenu( 112, importId, -1 );
3932   createMenu( 113, importId, -1 );
3933   createMenu( 115, importId, -1 );
3934 #ifdef WITH_CGNS
3935   createMenu( 116, importId, -1 );
3936 #endif
3937   createMenu( 117, importId, -1 );
3938   createMenu( 118, importId, -1 );
3939   createMenu( 121, exportId, -1 );
3940   createMenu( 122, exportId, -1 );
3941   createMenu( 123, exportId, -1 );
3942   createMenu( 140, exportId, -1 ); // export to STL
3943 #ifdef WITH_CGNS
3944   createMenu( 142, exportId, -1 ); // export to CGNS
3945 #endif
3946   createMenu( 144, exportId, -1 ); // export to SAUV
3947   createMenu( 146, exportId, -1 ); // export to GMF
3948   createMenu( separator(), fileId, 10 );
3949
3950   createMenu( 33, editId, -1 );
3951
3952   createMenu( 5105, toolsId, -1 );
3953
3954   createMenu( 702, meshId, -1 ); // "Mesh" menu
3955   createMenu( 703, meshId, -1 );
3956   createMenu( 704, meshId, -1 );
3957   createMenu( 710, meshId, -1 );
3958   createMenu( 705, meshId, -1 );
3959   createMenu( separator(), meshId, -1 );
3960   createMenu( 701, meshId, -1 );
3961   createMenu( 711, meshId, -1 );
3962   createMenu( 712, meshId, -1 );
3963   createMenu( 713, meshId, -1 );
3964   createMenu( separator(), meshId, -1 );
3965   createMenu( 801, meshId, -1 );
3966   createMenu( 806, meshId, -1 );
3967   createMenu( 802, meshId, -1 );
3968   createMenu( 803, meshId, -1 );
3969   createMenu( 815, meshId, -1 );
3970   createMenu( separator(), meshId, -1 );
3971   createMenu( 810, meshId, -1 );
3972   createMenu( 811, meshId, -1 );
3973   createMenu( 812, meshId, -1 );
3974   createMenu( separator(), meshId, -1 );
3975   createMenu( 814, meshId, -1 );
3976   createMenu( separator(), meshId, -1 );
3977   createMenu( 900, meshId, -1 );
3978   //createMenu( 902, meshId, -1 );
3979   //createMenu( 903, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3980   createMenu( 904, meshId, -1 );
3981   createMenu( separator(), meshId, -1 );
3982
3983   createMenu( 6005, nodeId, -1 );
3984   createMenu( 6028, nodeId, -1 );
3985   createMenu( 6002, edgeId, -1 );
3986   createMenu( 6003, edgeId, -1 );
3987   createMenu( 6001, edgeId, -1 );
3988   createMenu( 6004, edgeId, -1 );
3989   createMenu( 6029, edgeId, -1 );
3990   createMenu( 6021, faceId, -1 );
3991   createMenu( 6025, faceId, -1 );
3992   createMenu( 6027, faceId, -1 );
3993   createMenu( 6018, faceId, -1 );
3994   createMenu( 6019, faceId, -1 );
3995   createMenu( 6011, faceId, -1 );
3996   createMenu( 6012, faceId, -1 );
3997   createMenu( 6013, faceId, -1 );
3998   createMenu( 6014, faceId, -1 );
3999   createMenu( 6015, faceId, -1 );
4000   createMenu( 6016, faceId, -1 );
4001   createMenu( 6022, faceId, -1 );
4002   createMenu( 6030, faceId, -1 );
4003   createMenu( 6017, volumeId, -1 );
4004   createMenu( 6009, volumeId, -1 );
4005   createMenu( 6023, volumeId, -1 );
4006   createMenu( 6024, volumeId, -1 );
4007   createMenu( 6026, volumeId, -1 );
4008   createMenu( 6031, volumeId, -1 );
4009   createMenu( separator(), ctrlId, -1 );
4010   createMenu( 6032, ctrlId, -1 );
4011
4012   createMenu( 4000, addId, -1 );
4013   createMenu( 4009, addId, -1 );
4014   createMenu( 4070, addId, -1 );
4015   createMenu( 4008, addId, -1 );
4016   createMenu( 4010, addId, -1 );
4017   createMenu( 4021, addId, -1 );
4018   createMenu( 4022, addId, -1 );
4019   createMenu( 4023, addId, -1 );
4020   createMenu( 4031, addId, -1 );
4021   createMenu( 4032, addId, -1 );
4022   createMenu( 4133, addId, -1 );
4023   createMenu( 4134, addId, -1 );
4024   createMenu( 4135, addId, -1 );
4025   createMenu( 4033, addId, -1 );
4026   createMenu( separator(), addId, -1 );
4027   createMenu( 4034, addId, -1 );
4028   createMenu( 4035, addId, -1 );
4029   createMenu( 4137, addId, -1 );
4030   createMenu( 4036, addId, -1 );
4031   createMenu( 4136, addId, -1 );
4032   createMenu( 4037, addId, -1 );
4033   createMenu( 4038, addId, -1 );
4034   createMenu( 4039, addId, -1 );
4035   createMenu( 4040, addId, -1 );
4036   createMenu( 4140, addId, -1 );
4037
4038   createMenu( 4041, removeId, -1 );
4039   createMenu( 4042, removeId, -1 );
4040   createMenu( 4044, removeId, -1 );
4041   createMenu( separator(), removeId, -1 );
4042   createMenu( 813, removeId, -1 );
4043   createMenu( separator(), removeId, -1 );
4044   createMenu( 4043, removeId, -1 );
4045
4046   createMenu( 4051, renumId, -1 );
4047   createMenu( 4052, renumId, -1 );
4048
4049   createMenu( 4061, transfId, -1 );
4050   createMenu( 4062, transfId, -1 );
4051   createMenu( 4063, transfId, -1 );
4052   createMenu( 4068, transfId, -1 );
4053   createMenu( 4064, transfId, -1 );
4054   createMenu( 4065, transfId, -1 );
4055   createMenu( 4066, transfId, -1 );
4056   createMenu( 4069, transfId, -1 );
4057
4058   createMenu( 4067,modifyId, -1 );
4059   createMenu( 407, modifyId, -1 );
4060   createMenu( 408, modifyId, -1 );
4061   createMenu( 409, modifyId, -1 );
4062   createMenu( 420, modifyId, -1 );
4063   createMenu( 410, modifyId, -1 );
4064   createMenu( 411, modifyId, -1 );
4065   createMenu( 419, modifyId, -1 );
4066   createMenu( 412, modifyId, -1 );
4067   createMenu( 413, modifyId, -1 );
4068   createMenu( 416, modifyId, -1 );
4069   createMenu( 414, modifyId, -1 );
4070   createMenu( 415, modifyId, -1 );
4071   createMenu( 417, modifyId, -1 );
4072   createMenu( 418, modifyId, -1 );
4073
4074   createMenu( 501, measureId, -1 );
4075   createMenu( 502, measureId, -1 );
4076   createMenu( 503, basicPropId, -1 );
4077   createMenu( 504, basicPropId, -1 );
4078   createMenu( 505, basicPropId, -1 );
4079   createMenu( 214, viewId, -1 );
4080
4081   // ----- create toolbars --------------
4082   int meshTb       = createTool( tr( "TB_MESH" ) ),
4083       info         = createTool( tr( "TB_INFO" ) ),
4084       groupTb      = createTool( tr( "TB_GROUP" ) ),
4085       ctrl0dTb     = createTool( tr( "TB_CTRL0D" ) ),
4086       ctrl1dTb     = createTool( tr( "TB_CTRL1D" ) ),
4087       ctrl2dTb     = createTool( tr( "TB_CTRL2D" ) ),
4088       ctrl3dTb     = createTool( tr( "TB_CTRL3D" ) ),
4089       addElemTb    = createTool( tr( "TB_ADD" ) ),
4090       addNonElemTb = createTool( tr( "TB_ADDNON" ) ),
4091       remTb        = createTool( tr( "TB_REM" ) ),
4092       renumbTb     = createTool( tr( "TB_RENUMBER" ) ),  
4093       transformTb  = createTool( tr( "TB_TRANSFORM" ) ),  
4094       modifyTb     = createTool( tr( "TB_MODIFY" ) ),
4095       measuremTb     = createTool( tr( "TB_MEASUREM" ) ),
4096       dispModeTb   = createTool( tr( "TB_DISP_MODE" ) );
4097
4098   createTool( 702, meshTb );
4099   createTool( 703, meshTb );
4100   createTool( 704, meshTb );
4101   createTool( 710, meshTb );
4102   createTool( 705, meshTb );
4103   createTool( separator(), meshTb );
4104   createTool( 701, meshTb );
4105   createTool( 711, meshTb );
4106   createTool( 712, meshTb );
4107   createTool( 713, meshTb );
4108
4109   createTool( 801, groupTb );
4110   createTool( 806, groupTb );
4111   createTool( 802, groupTb );
4112   createTool( 803, groupTb );
4113
4114   createTool( 900, info );
4115   //createTool( 902, meshTb );
4116   //createTool( 903, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4117   createTool( 904, info );
4118
4119   createTool( 6005, ctrl0dTb );
4120   createTool( 6028, ctrl0dTb );
4121
4122   createTool( 6002, ctrl1dTb );
4123   createTool( 6003, ctrl1dTb );
4124   createTool( 6001, ctrl1dTb );
4125   createTool( 6004, ctrl1dTb );
4126   createTool( 6029, ctrl1dTb );
4127
4128   createTool( 6021, ctrl2dTb );
4129   createTool( 6025, ctrl2dTb );
4130   createTool( 6027, ctrl2dTb );
4131   createTool( 6018, ctrl2dTb );
4132   createTool( 6019, ctrl2dTb );
4133   createTool( 6011, ctrl2dTb );
4134   createTool( 6012, ctrl2dTb );
4135   createTool( 6013, ctrl2dTb );
4136   createTool( 6014, ctrl2dTb );
4137   createTool( 6015, ctrl2dTb );
4138   createTool( 6016, ctrl2dTb );
4139   createTool( 6022, ctrl2dTb );
4140   createTool( 6030, ctrl2dTb );
4141
4142   createTool( 6017, ctrl3dTb );
4143   createTool( 6009, ctrl3dTb );
4144   createTool( 6023, ctrl3dTb );
4145   createTool( 6024, ctrl3dTb );
4146   createTool( 6026, ctrl3dTb );
4147   createTool( 6031, ctrl3dTb );
4148
4149   createTool( 4000, addElemTb );
4150   createTool( 4009, addElemTb );
4151   createTool( 4070, addElemTb );
4152   createTool( 4008, addElemTb );
4153   createTool( 4010, addElemTb );
4154   createTool( 4021, addElemTb );
4155   createTool( 4022, addElemTb );
4156   createTool( 4023, addElemTb );
4157   createTool( 4031, addElemTb );
4158   createTool( 4032, addElemTb );
4159   createTool( 4133, addElemTb );
4160   createTool( 4134, addElemTb );
4161   createTool( 4135, addElemTb );
4162   createTool( 4033, addElemTb );
4163
4164   createTool( 4034, addNonElemTb );
4165   createTool( 4035, addNonElemTb );
4166   createTool( 4137, addNonElemTb );
4167   createTool( 4036, addNonElemTb );
4168   createTool( 4136, addNonElemTb );
4169   createTool( 4037, addNonElemTb );
4170   createTool( 4038, addNonElemTb );
4171   createTool( 4039, addNonElemTb );
4172   createTool( 4040, addNonElemTb );
4173   createTool( 4140, addNonElemTb );
4174
4175   createTool( 4041, remTb );
4176   createTool( 4042, remTb );
4177   createTool( 4044, remTb );
4178   createTool( 4043, remTb );
4179
4180   createTool( 4051, renumbTb );
4181   createTool( 4052, renumbTb );
4182
4183
4184   createTool( 4061, transformTb );
4185   createTool( 4062, transformTb );
4186   createTool( 4063, transformTb );
4187   createTool( 4068, transformTb );
4188   createTool( 4064, transformTb );
4189   createTool( 4065, transformTb );
4190   createTool( 4066, transformTb );
4191   createTool( 4069, transformTb );
4192
4193   createTool( 4067,modifyTb );
4194   createTool( 407, modifyTb );
4195   createTool( 408, modifyTb );
4196   createTool( 409, modifyTb );
4197   createTool( 420, modifyTb );
4198   createTool( 410, modifyTb );
4199   createTool( 411, modifyTb );
4200   createTool( 419, modifyTb );
4201   createTool( 412, modifyTb );
4202   createTool( 413, modifyTb );
4203   createTool( 416, modifyTb );
4204   createTool( 414, modifyTb );
4205   createTool( 415, modifyTb );
4206   createTool( 417, modifyTb );
4207   createTool( 418, modifyTb );
4208
4209   createTool( 501, measuremTb );  
4210
4211   createTool( 214, dispModeTb );
4212
4213   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4214   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4215
4216   myRules.clear();
4217   QString OB = "'ObjectBrowser'",
4218           View = "'" + SVTK_Viewer::Type() + "'",
4219           pat = "'%1'",
4220           mesh    = pat.arg( SMESHGUI_Selection::typeName( SMESH::MESH ) ),
4221           group   = pat.arg( SMESHGUI_Selection::typeName( SMESH::GROUP ) ),
4222           hypo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::HYPOTHESIS ) ),
4223           algo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::ALGORITHM ) ),
4224           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
4225                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_VERTEX ) ).
4226                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_EDGE ) ).
4227                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_FACE ) ).
4228                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_SOLID ) ).
4229                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_COMPOUND ) ).
4230                        arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH ) ),
4231           subMesh = elems,
4232           mesh_part = mesh + " " + subMesh + " " + group,
4233           mesh_group = mesh + " " + group,
4234           hyp_alg = hypo + " " + algo;
4235
4236   // popup for object browser
4237   QString
4238     isInvisible("not( isVisible )"),
4239     isEmpty("numberOfNodes = 0"),
4240     isNotEmpty("numberOfNodes <> 0"),
4241
4242     // has nodes, edges, etc in VISIBLE! actor
4243     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
4244     hasElems("(count( elemTypes ) > 0)"),
4245     hasDifferentElems("(count( elemTypes ) > 1)"),
4246     hasBalls("({'BallElem'} in elemTypes)"),
4247     hasElems0d("({'Elem0d'} in elemTypes)"),
4248     hasEdges("({'Edge'} in elemTypes)"),
4249     hasFaces("({'Face'} in elemTypes)"),
4250     hasVolumes("({'Volume'} in elemTypes)");
4251
4252   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
4253   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
4254   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
4255   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
4256   createPopupItem( 803, OB, group );                       // EDIT_GROUP
4257   createPopupItem( 815, OB, group, "&& groupType != 'Group'" ); // EDIT AS STANDALONE
4258
4259   popupMgr()->insert( separator(), -1, 0 );
4260   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
4261   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
4262   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
4263   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
4264   createPopupItem( 214, OB, mesh_part );                   // UPDATE
4265   createPopupItem( 900, OB, mesh_part );                   // ADV_INFO
4266   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
4267   createPopupItem( 6032, OB, mesh_part );                  // CTRL_INFO
4268   popupMgr()->insert( separator(), -1, 0 );
4269   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
4270   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
4271   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
4272   popupMgr()->insert( separator(), -1, 0 );
4273   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
4274   createPopupItem( 1102, OB, hyp_alg );                    // REMOVE HYPOTHESIS / ALGORITHMS
4275   popupMgr()->insert( separator(), -1, 0 );
4276   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
4277   popupMgr()->insert( separator(), -1, 0 );
4278   createPopupItem( 417, OB, mesh + " " + subMesh );        // convert to quadratic
4279   createPopupItem( 418, OB, mesh + " " + group,            // create 2D mesh from 3D
4280                    "&& dim>=2");
4281   popupMgr()->insert( separator(), -1, 0 );
4282
4283   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
4284   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
4285   QString only_one_2D        = only_one_non_empty + " && dim>1";
4286
4287   int anId = popupMgr()->insert( tr( "MEN_EXPORT" ), -1, -1 );        // EXPORT submenu
4288   createPopupItem( 125, OB, mesh_group, multiple_non_empty, anId );   // EXPORT_MED
4289   createPopupItem( 126, OB, mesh_group, only_one_non_empty, anId );   // EXPORT_UNV
4290   createPopupItem( 141, OB, mesh_group, only_one_2D, anId );          // EXPORT_STL
4291 #ifdef WITH_CGNS
4292   createPopupItem( 143, OB, mesh_group, multiple_non_empty, anId );   // EXPORT_CGNS
4293 #endif
4294   createPopupItem( 145, OB, mesh_group, multiple_non_empty, anId );   // EXPORT_SAUV
4295   createPopupItem( 147, OB, mesh_group, multiple_non_empty, anId );   // EXPORT_GMF
4296   createPopupItem( 124, OB, mesh_group, multiple_non_empty, anId );   // EXPORT_DAT
4297   createPopupItem(  33, OB, mesh_part + " " + hyp_alg );        // DELETE
4298   createPopupItem( 813, OB, group );                            // DEL_GROUP with contents
4299   popupMgr()->insert( separator(), -1, 0 );
4300
4301   // popup for viewer
4302   createPopupItem( 803, View, group ); // EDIT_GROUP
4303   createPopupItem( 804, View, elems ); // ADD
4304   createPopupItem( 805, View, elems ); // REMOVE
4305
4306   popupMgr()->insert( separator(), -1, 0 );
4307   createPopupItem( 214, View, mesh_part );  // UPDATE
4308   createPopupItem( 900, View, mesh_part );  // ADV_INFO
4309   createPopupItem( 6032,View, mesh_part );  // CTRL_INFO
4310   createPopupItem( 904, View, mesh );       // FIND_ELEM
4311   popupMgr()->insert( separator(), -1, 0 );
4312
4313   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
4314   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
4315   popupMgr()->insert( separator(), -1, 0 );
4316
4317   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
4318   QString aType = QString( "%1type in {%2}" ).arg( lc );
4319   aType = aType.arg( mesh_part );
4320   QString aMeshInVTK = aClient + "&&" + aType;
4321
4322   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
4323   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
4324   QString aSelCount = QString( "%1 > 0" ).arg( dc );
4325
4326   //-------------------------------------------------
4327   // Numbering
4328   //-------------------------------------------------
4329   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
4330
4331   popupMgr()->insert( action( 9010 ), anId, -1 );
4332   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4333   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4334
4335   popupMgr()->insert( action( 9011 ), anId, -1 );
4336   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4337   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4338
4339   popupMgr()->insert( separator(), -1, -1 );
4340
4341   //-------------------------------------------------
4342   // Display Mode
4343   //-------------------------------------------------
4344   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4345
4346   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
4347   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4348   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4349
4350   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
4351   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4352   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4353
4354   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
4355   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
4356   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4357
4358   popupMgr()->insert( separator(), anId, -1 );
4359
4360   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
4361   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4362   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4363
4364   //-------------------------------------------------
4365   // Display Entity
4366   //-------------------------------------------------
4367   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4368
4369   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4370
4371   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
4372   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4373   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4374
4375   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
4376   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4377   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4378
4379   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
4380   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4381   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4382
4383   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
4384   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4385   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4386
4387   popupMgr()->insert( action( 222 ), anId, -1 ); // BALLS
4388   popupMgr()->setRule( action( 222 ), aDiffElemsInVTK + "&& isVisible &&" + hasBalls, QtxPopupMgr::VisibleRule );
4389   popupMgr()->setRule( action( 222 ), "{'BallElem'} in entityMode", QtxPopupMgr::ToggleRule );
4390
4391   popupMgr()->insert( separator(), anId, -1 );
4392
4393   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
4394   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4395
4396
4397   //-------------------------------------------------
4398   // Representation of the 2D Quadratic elements
4399   //-------------------------------------------------
4400   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4401   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
4402   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
4403   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4404
4405   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
4406   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
4407   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4408
4409   //-------------------------------------------------
4410   // Orientation of faces
4411   //-------------------------------------------------
4412   popupMgr()->insert( action( 221 ), -1, -1 );
4413   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4414   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4415
4416   //-------------------------------------------------
4417   // Color / Size
4418   //-------------------------------------------------
4419   popupMgr()->insert( action( 1132 ), -1, -1 );
4420   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4421
4422   //-------------------------------------------------
4423   // Transparency
4424   //-------------------------------------------------
4425   popupMgr()->insert( action( 1133 ), -1, -1 );
4426   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4427
4428   //-------------------------------------------------
4429   // Controls
4430   //-------------------------------------------------
4431   QString
4432     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
4433     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
4434     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
4435     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4436
4437   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4438
4439   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
4440   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4441
4442   popupMgr()->insert( separator(), anId, -1 );
4443
4444   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4445
4446   popupMgr()->insert( action( 6005 ), aSubId, -1 ); // FREE_NODE
4447   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4448   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4449
4450   popupMgr()->insert ( action( 6028 ), aSubId, -1 ); // EQUAL_NODE
4451   popupMgr()->setRule( action( 6028 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4452   popupMgr()->setRule( action( 6028 ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4453
4454   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4455
4456   popupMgr()->insert( action( 6002 ), aSubId, -1 ); // FREE_EDGE
4457   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4458   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4459
4460   popupMgr()->insert( action( 6003 ), aSubId, -1 ); // FREE_BORDER
4461   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4462   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4463
4464   popupMgr()->insert( action( 6001 ), aSubId, -1 ); // LENGTH
4465   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4466   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4467
4468   popupMgr()->insert( action( 6004 ), aSubId, -1 ); // CONNECTION
4469   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4470   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4471   popupMgr()->insert ( action( 6029 ), aSubId, -1 ); // EQUAL_EDGE
4472   popupMgr()->setRule( action( 6029 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4473   popupMgr()->setRule( action( 6029 ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4474
4475   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4476
4477   popupMgr()->insert ( action( 6021 ), aSubId, -1 ); // FREE_FACE
4478   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4479                                        QtxPopupMgr::VisibleRule );
4480   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4481
4482   popupMgr()->insert ( action( 6018 ), aSubId, -1 ); // LENGTH_2D
4483   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4484   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4485
4486   popupMgr()->insert ( action( 6019 ), aSubId, -1 ); // CONNECTION_2D
4487   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4488   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4489
4490   popupMgr()->insert ( action( 6011 ), aSubId, -1 ); // AREA
4491   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4492   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4493
4494   popupMgr()->insert ( action( 6012 ), aSubId, -1 ); // TAPER
4495   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4496   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4497
4498   popupMgr()->insert ( action( 6013 ), aSubId, -1 ); // ASPECT
4499   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4500   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4501
4502   popupMgr()->insert ( action( 6014 ), aSubId, -1 ); // MIN_ANG
4503   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4504   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4505
4506   popupMgr()->insert ( action( 6015 ), aSubId, -1 ); // WARP
4507   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4508   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4509
4510   popupMgr()->insert ( action( 6016 ), aSubId, -1 ); // SKEW
4511   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4512   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4513
4514   popupMgr()->insert ( action( 6022 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_2D
4515   popupMgr()->setRule( action( 6022 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4516   popupMgr()->setRule( action( 6022 ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4517
4518   popupMgr()->insert ( action( 6025 ), aSubId, -1 ); // BARE_BORDER_FACE
4519   popupMgr()->setRule( action( 6025 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4520   popupMgr()->setRule( action( 6025 ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4521
4522   popupMgr()->insert ( action( 6027 ), aSubId, -1 ); // OVER_CONSTRAINED_FACE
4523   popupMgr()->setRule( action( 6027 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4524   popupMgr()->setRule( action( 6027 ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4525   popupMgr()->insert ( action( 6030 ), aSubId, -1 ); // EQUAL_FACE
4526   popupMgr()->setRule( action( 6030 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4527   popupMgr()->setRule( action( 6030 ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4528
4529   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4530
4531   popupMgr()->insert ( action( 6017 ), aSubId, -1 ); // ASPECT_3D
4532   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4533   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4534
4535   popupMgr()->insert ( action( 6009 ), aSubId, -1 ); // VOLUME_3D
4536   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4537   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4538
4539   popupMgr()->insert ( action( 6023 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_3D
4540   popupMgr()->setRule( action( 6023 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4541   popupMgr()->setRule( action( 6023 ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4542
4543   popupMgr()->insert ( action( 6024 ), aSubId, -1 ); // BARE_BORDER_VOLUME
4544   popupMgr()->setRule( action( 6024 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4545   popupMgr()->setRule( action( 6024 ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4546
4547   popupMgr()->insert ( action( 6026 ), aSubId, -1 ); // OVER_CONSTRAINED_VOLUME
4548   popupMgr()->setRule( action( 6026 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4549   popupMgr()->setRule( action( 6026 ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4550
4551   popupMgr()->insert ( action( 6031 ), aSubId, -1 ); // EQUAL_VOLUME
4552   popupMgr()->setRule( action( 6031 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4553   popupMgr()->setRule( action( 6031 ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
4554
4555   popupMgr()->insert( separator(), anId, -1 );
4556
4557   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
4558   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4559
4560   popupMgr()->insert( separator(), anId, -1 );
4561
4562   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4563
4564   popupMgr()->insert( action( 2021 ), aSubId, -1 ); // SAVE_DISTRIBUTION
4565   popupMgr()->setRule( action( 2021 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4566
4567   popupMgr()->insert( action( 2022 ), aSubId, -1 ); // SHOW_DISTRIBUTION
4568   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4569   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor && isDistributionVisible", QtxPopupMgr::ToggleRule);
4570
4571 #ifndef DISABLE_PLOT2DVIEWER
4572   popupMgr()->insert( action( 2023 ), aSubId, -1 ); // PLOT_DISTRIBUTION
4573   popupMgr()->setRule( action( 2023 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4574 #endif
4575
4576   //-------------------------------------------------
4577   // Display / Erase
4578   //-------------------------------------------------
4579   popupMgr()->insert( separator(), -1, -1 );
4580   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4581     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4582   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
4583   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4584
4585   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
4586   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4587
4588   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
4589   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4590
4591   popupMgr()->insert( separator(), -1, -1 );
4592
4593   //-------------------------------------------------
4594   // Clipping
4595   //-------------------------------------------------
4596   popupMgr()->insert( action( 1134 ), -1, -1 );
4597   popupMgr()->setRule( action( 1134 ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4598
4599   popupMgr()->insert( separator(), -1, -1 );
4600
4601   popupMgr()->insert( action( 41 ), -1, -1 );
4602   popupMgr()->setRule( action( 41 ), "$component={'SMESH'} and client='ObjectBrowser' and isContainer and nbChildren>1", QtxPopupMgr::VisibleRule );
4603   popupMgr()->insert( separator(), -1, -1 );
4604
4605   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4606            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4607
4608   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4609            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4610 }
4611
4612 //================================================================================
4613 /*!
4614  * \brief Return true if SMESH or GEOM objects are selected.
4615  * Is called form LightApp_Module::activateModule() which clear selection if
4616  * not isSelectionCompatible()
4617  */
4618 //================================================================================
4619
4620 bool SMESHGUI::isSelectionCompatible()
4621 {
4622   bool isCompatible = true;
4623   SALOME_ListIO selected;
4624   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4625     Sel->selectedObjects( selected );
4626
4627   SALOME_ListIteratorOfListIO It( selected );
4628   for ( ; isCompatible && It.More(); It.Next())
4629     isCompatible =
4630       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4631       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4632
4633   return isCompatible;
4634 }
4635
4636
4637 bool SMESHGUI::reusableOperation( const int id )
4638 {
4639   // compute, evaluate and precompute are not reusable operations
4640   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
4641 }
4642
4643 bool SMESHGUI::activateModule( SUIT_Study* study )
4644 {
4645   bool res = SalomeApp_Module::activateModule( study );
4646
4647   setMenuShown( true );
4648   setToolShown( true );
4649
4650   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4651   PyGILState_STATE gstate = PyGILState_Ensure();
4652   PyObjWrapper pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
4653   if ( !pluginsmanager ) {
4654     PyErr_Print();
4655   }
4656   else {
4657     PyObjWrapper result = PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
4658     if ( !result )
4659       PyErr_Print();
4660   }
4661   PyGILState_Release(gstate);
4662   // end of SMESH plugins loading
4663
4664   // Reset actions accelerator keys
4665   //action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
4666   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
4667   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
4668
4669   action(  33)->setEnabled(true); // Delete: Key_Delete
4670
4671   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4672   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
4673   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
4674     if ( _PTR(Study) aStudy = s->studyDS()) {
4675       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
4676       updateObjBrowser(); // objects can be removed
4677     }
4678
4679   // get all view currently opened in the study and connect their signals  to
4680   // the corresponding slots of the class.
4681   SUIT_Desktop* aDesk = study->application()->desktop();
4682   if ( aDesk ) {
4683     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4684     SUIT_ViewWindow* wnd;
4685     foreach ( wnd, wndList )
4686       connectView( wnd );
4687   }
4688
4689   return res;
4690 }
4691
4692 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4693 {
4694   setMenuShown( false );
4695   setToolShown( false );
4696
4697   EmitSignalCloseAllDialogs();
4698
4699   // Unset actions accelerator keys
4700   //action(111)->setShortcut(QKeySequence()); // Import DAT
4701   action(112)->setShortcut(QKeySequence()); // Import UNV
4702   action(113)->setShortcut(QKeySequence()); // Import MED
4703
4704   action(  33)->setEnabled(false); // Delete: Key_Delete
4705
4706   return SalomeApp_Module::deactivateModule( study );
4707 }
4708
4709 void SMESHGUI::studyClosed( SUIT_Study* s )
4710 {
4711   SMESH::RemoveVisuData( s->id() );
4712   SalomeApp_Module::studyClosed( s );
4713 }
4714
4715 void SMESHGUI::OnGUIEvent()
4716 {
4717   const QObject* obj = sender();
4718   if ( !obj || !obj->inherits( "QAction" ) )
4719     return;
4720   int id = actionId((QAction*)obj);
4721   if ( id != -1 )
4722     OnGUIEvent( id );
4723 }
4724
4725 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
4726 {
4727   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
4728   if ( CORBA::is_nil( myComponentSMESH ) )
4729     {
4730       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
4731       if ( aStudy )
4732         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4733       return aGUI.myComponentSMESH;
4734     }
4735   if ( aStudy )
4736     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4737   return myComponentSMESH;
4738 }
4739
4740 QString SMESHGUI::engineIOR() const
4741 {
4742   CORBA::ORB_var anORB = getApp()->orb();
4743   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
4744   return QString( anIOR.in() );
4745 }
4746
4747 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
4748 {
4749   SalomeApp_Module::contextMenuPopup( client, menu, title );
4750   SALOME_ListIO lst;
4751   selectionMgr()->selectedObjects( lst );
4752   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
4753     Handle(SALOME_InteractiveObject) io = lst.First();
4754     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
4755     _PTR(Study) study = appStudy->studyDS();
4756     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
4757     if ( obj ) {
4758       QString aName = QString( obj->GetName().c_str() );
4759       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
4760           aName.remove( (aName.length() - 1), 1 );
4761       title = aName;
4762     }
4763   }
4764 }
4765
4766 LightApp_Selection* SMESHGUI::createSelection() const
4767 {
4768   return new SMESHGUI_Selection();
4769 }
4770
4771 void SMESHGUI::windows( QMap<int, int>& aMap ) const
4772 {
4773   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
4774   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
4775 }
4776
4777 void SMESHGUI::viewManagers( QStringList& list ) const
4778 {
4779   list.append( SVTK_Viewer::Type() );
4780 }
4781
4782 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
4783 {
4784   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
4785     SMESH::UpdateSelectionProp( this );
4786
4787     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
4788     for(int i = 0; i < aViews.count() ; i++){
4789       SUIT_ViewWindow *sf = aViews[i];
4790       connectView( sf );
4791     }
4792   }
4793 }
4794
4795 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
4796 {
4797   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
4798     myClippingPlaneInfoMap.erase( theViewManager );
4799 }
4800
4801 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
4802 {
4803   theActor->AddObserver( SMESH::DeleteActorEvent,
4804                          myEventCallbackCommand.GetPointer(),
4805                          myPriority );
4806 }
4807
4808 void SMESHGUI::ProcessEvents( vtkObject* theObject,
4809                               unsigned long theEvent,
4810                               void* theClientData,
4811                               void* theCallData )
4812 {
4813   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
4814     if( theObject && theEvent == SMESH::DeleteActorEvent ) {
4815       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
4816         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
4817         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
4818         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
4819           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
4820           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
4821           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
4822             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
4823             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
4824             SMESH::TActorList::iterator anIter3 = anActorList.begin();
4825             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
4826               if( anActor == *anIter3 ) {
4827                 anActorList.erase( anIter3 );
4828                 break;
4829               }
4830             }
4831           }
4832         }
4833       }
4834     }
4835   }
4836 }
4837
4838 void SMESHGUI::createPreferences()
4839 {
4840   // General tab ------------------------------------------------------------------------
4841   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
4842
4843   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
4844   setPreferenceProperty( autoUpdate, "columns", 2 );
4845   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
4846   setPreferenceProperty( lim, "min",  0 );
4847   setPreferenceProperty( lim, "max",  100000000 );
4848   setPreferenceProperty( lim, "step", 1000 );
4849   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4850   addPreference( tr( "PREF_INCREMENTAL_LIMIT" ), autoUpdate, LightApp_Preferences::Bool, "SMESH", "incremental_limit" );
4851
4852   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
4853   setPreferenceProperty( qaGroup, "columns", 2 );
4854   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
4855   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
4856   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
4857   setPreferenceProperty( prec, "min", 0 );
4858   setPreferenceProperty( prec, "max", 16 );
4859   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
4860   setPreferenceProperty( doubleNodesTol, "precision", 10 );
4861   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
4862   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
4863   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
4864
4865   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
4866   setPreferenceProperty( dispgroup, "columns", 2 );
4867   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
4868   QStringList modes;
4869   modes.append( tr("MEN_WIRE") );
4870   modes.append( tr("MEN_SHADE") );
4871   modes.append( tr("MEN_NODES") );
4872   modes.append( tr("MEN_SHRINK") );
4873   QList<QVariant> indices;
4874   indices.append( 0 );
4875   indices.append( 1 );
4876   indices.append( 2 );
4877   indices.append( 3 );
4878   setPreferenceProperty( dispmode, "strings", modes );
4879   setPreferenceProperty( dispmode, "indexes", indices );
4880
4881   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
4882   setPreferenceProperty( arcgroup, "columns", 2 );
4883   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
4884   QStringList quadraticModes;
4885   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
4886   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
4887   indices.clear();
4888   indices.append( 0 );
4889   indices.append( 1 );
4890   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
4891   setPreferenceProperty( quadraticmode, "indexes", indices );
4892
4893   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
4894                               "SMESH", "max_angle" );
4895   setPreferenceProperty( maxAngle, "min", 1 );
4896   setPreferenceProperty( maxAngle, "max", 90 );
4897
4898
4899
4900   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
4901   setPreferenceProperty( exportgroup, "columns", 2 );
4902   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
4903   //addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
4904
4905   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
4906   setPreferenceProperty( computeGroup, "columns", 2 );
4907   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
4908   modes.clear();
4909   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
4910   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
4911   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
4912   indices.clear();
4913   indices.append( 0 );
4914   indices.append( 1 );
4915   indices.append( 2 );
4916   setPreferenceProperty( notifyMode, "strings", modes );
4917   setPreferenceProperty( notifyMode, "indexes", indices );
4918
4919   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
4920   setPreferenceProperty( infoGroup, "columns", 2 );
4921   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
4922   modes.clear();
4923   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
4924   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
4925   indices.clear();
4926   indices.append( 0 );
4927   indices.append( 1 );
4928   setPreferenceProperty( elemInfo, "strings", modes );
4929   setPreferenceProperty( elemInfo, "indexes", indices );
4930   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
4931   setPreferenceProperty( nodesLim, "min", 0 );
4932   setPreferenceProperty( nodesLim, "max", 10000000 );
4933   setPreferenceProperty( nodesLim, "step", 10000 );
4934   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4935   int ctrlLim = addPreference( tr( "PREF_CTRL_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_controls_limit" );
4936   setPreferenceProperty( ctrlLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4937   setPreferenceProperty( ctrlLim, "min", 0 );
4938   setPreferenceProperty( ctrlLim, "max", 10000000 );
4939   setPreferenceProperty( ctrlLim, "step", 1000 );
4940   addPreference( tr( "PREF_ELEM_INFO_GRP_DETAILS" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "elem_info_grp_details" );
4941   addPreference( tr( "PREF_DUMP_BASE_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_base" );
4942   addPreference( tr( "PREF_DUMP_ELEM_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_elem" );
4943   addPreference( tr( "PREF_DUMP_ADD_INFO"  ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_add" );
4944   addPreference( tr( "PREF_DUMP_CTRL_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_ctrl" );
4945
4946   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
4947   setPreferenceProperty( segGroup, "columns", 2 );
4948   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
4949                               "SMESH", "segmentation" );
4950   setPreferenceProperty( segLen, "min", 1 );
4951   setPreferenceProperty( segLen, "max", 10000000 );
4952   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
4953                              "SMESH", "nb_segments_per_edge" );
4954   setPreferenceProperty( nbSeg, "min", 1 );
4955   setPreferenceProperty( nbSeg, "max", 10000000 );
4956
4957   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
4958   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
4959                  "SMESH", "forget_mesh_on_hyp_modif" );
4960
4961
4962   // Quantities with individual precision settings
4963   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
4964   setPreferenceProperty( precGroup, "columns", 2 );
4965
4966   const int nbQuantities = 6;
4967   int precs[nbQuantities], ii = 0;
4968   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
4969                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
4970   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
4971                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
4972   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
4973                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
4974   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
4975                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
4976   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
4977                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
4978   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
4979                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
4980
4981   // Set property for precision value for spinboxes
4982   for ( ii = 0; ii < nbQuantities; ii++ ){
4983     setPreferenceProperty( precs[ii], "min", -14 );
4984     setPreferenceProperty( precs[ii], "max", 14 );
4985     setPreferenceProperty( precs[ii], "precision", 2 );
4986   }
4987
4988   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
4989   setPreferenceProperty( previewGroup, "columns", 2 );
4990   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
4991   setPreferenceProperty( chunkSize, "min",  1 );
4992   setPreferenceProperty( chunkSize, "max",  1000 );
4993   setPreferenceProperty( chunkSize, "step", 50 );
4994
4995   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
4996   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
4997
4998   // Mesh tab ------------------------------------------------------------------------
4999   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
5000   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
5001   setPreferenceProperty( nodeGroup, "columns", 3 );
5002
5003   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
5004
5005   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
5006
5007   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5008   QList<QVariant> aMarkerTypeIndicesList;
5009   QList<QVariant> aMarkerTypeIconsList;
5010   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
5011     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
5012     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
5013     aMarkerTypeIndicesList << i;
5014     aMarkerTypeIconsList << pixmap;
5015   }
5016   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
5017   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
5018
5019   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
5020
5021   QList<QVariant> aMarkerScaleIndicesList;
5022   QStringList     aMarkerScaleValuesList;
5023   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
5024     aMarkerScaleIndicesList << i;
5025     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
5026   }
5027   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
5028   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
5029
5030   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
5031   //setPreferenceProperty( elemGroup, "columns", 2 );
5032
5033   int ColorId = addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
5034   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
5035   ColorId = addPreference( tr( "PREF_VOLUME" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "volume_color" );
5036   setPreferenceProperty( ColorId, "text", tr("PREF_REVERSEDVOLUME") );
5037   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
5038   addPreference( tr( "PREF_BALL_COLOR" ), elemGroup, LightApp_Preferences::Color, "SMESH", "ball_elem_color" );
5039   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
5040   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
5041   addPreference( tr( "PREF_PREVIEW_COLOR"  ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "preview_color" );
5042
5043
5044   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
5045   setPreferenceProperty( grpGroup, "columns", 2 );
5046
5047   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
5048   addPreference( tr( "PREF_GRP_DEF_COLOR" ), grpGroup, LightApp_Preferences::Color, "SMESH", "default_grp_color" );
5049
5050   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
5051                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
5052   int ballSize = addPreference(tr("PREF_BALL_SIZE"), elemGroup,
5053                              LightApp_Preferences::IntSpin, "SMESH", "ball_elem_size");
5054   double ballScale = addPreference(tr("PREF_BALL_SCALE"), elemGroup,
5055                              LightApp_Preferences::DblSpin, "SMESH", "ball_elem_scale");
5056   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
5057                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
5058   int outW  = addPreference(tr("PREF_OUTLINE_WIDTH"), elemGroup,
5059                              LightApp_Preferences::IntSpin, "SMESH", "outline_width");
5060   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
5061                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
5062
5063   setPreferenceProperty( size0d, "min", 1 );
5064   setPreferenceProperty( size0d, "max", 10 );
5065
5066   setPreferenceProperty( ballSize, "min", 1 );
5067   setPreferenceProperty( ballSize, "max", 10 );
5068
5069   setPreferenceProperty( ballScale, "min", 1e-2 );
5070   setPreferenceProperty( ballScale, "max", 1e7 );
5071   setPreferenceProperty( ballScale, "step", 0.5 );
5072
5073   setPreferenceProperty( elemW, "min", 1 );
5074   setPreferenceProperty( elemW, "max", 5 );
5075
5076   setPreferenceProperty( outW, "min", 1 );
5077   setPreferenceProperty( outW, "max", 5 );
5078
5079   setPreferenceProperty( shrink, "min", 0 );
5080   setPreferenceProperty( shrink, "max", 100 );
5081
5082   int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
5083   setPreferenceProperty( numGroup, "columns", 2 );
5084   
5085   addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
5086   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
5087
5088   addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
5089   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
5090
5091   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
5092   setPreferenceProperty( orientGroup, "columns", 1 );
5093
5094   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
5095   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
5096
5097   setPreferenceProperty( orientScale, "min", 0.05 );
5098   setPreferenceProperty( orientScale, "max", 0.5 );
5099   setPreferenceProperty( orientScale, "step", 0.05 );
5100
5101   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
5102
5103   // Selection tab ------------------------------------------------------------------------
5104   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
5105
5106   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
5107   setPreferenceProperty( selGroup, "columns", 2 );
5108
5109   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
5110   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
5111
5112   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
5113   setPreferenceProperty( preGroup, "columns", 2 );
5114
5115   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
5116
5117   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
5118   setPreferenceProperty( precSelGroup, "columns", 2 );
5119
5120   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
5121   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
5122   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
5123
5124   // Scalar Bar tab ------------------------------------------------------------------------
5125   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
5126   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
5127   setPreferenceProperty( fontGr, "columns", 2 );
5128
5129   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
5130   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
5131
5132   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
5133   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
5134
5135   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
5136   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
5137
5138   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
5139   setPreferenceProperty( numcol, "min", 2 );
5140   setPreferenceProperty( numcol, "max", 256 );
5141
5142   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
5143   setPreferenceProperty( numlab, "min", 2 );
5144   setPreferenceProperty( numlab, "max", 65 );
5145
5146   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
5147   setPreferenceProperty( orientGr, "columns", 2 );
5148   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
5149   QStringList orients;
5150   orients.append( tr( "SMESH_VERTICAL" ) );
5151   orients.append( tr( "SMESH_HORIZONTAL" ) );
5152   indices.clear(); indices.append( 0 ); indices.append( 1 );
5153   setPreferenceProperty( orient, "strings", orients );
5154   setPreferenceProperty( orient, "indexes", indices );
5155
5156   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
5157   setPreferenceProperty( posVSizeGr, "columns", 2 );
5158   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
5159   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
5160   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
5161   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
5162   setPreferenceProperty( xv, "step", 0.1 );
5163   setPreferenceProperty( xv, "min", 0.0 );
5164   setPreferenceProperty( xv, "max", 1.0 );
5165   setPreferenceProperty( yv, "step", 0.1 );
5166   setPreferenceProperty( yv, "min", 0.0 );
5167   setPreferenceProperty( yv, "max", 1.0 );
5168   setPreferenceProperty( wv, "step", 0.1 );
5169   setPreferenceProperty( wv, "min", 0.0 );
5170   setPreferenceProperty( wv, "max", 1.0 );
5171   setPreferenceProperty( hv, "min", 0.0 );
5172   setPreferenceProperty( hv, "max", 1.0 );
5173   setPreferenceProperty( hv, "step", 0.1 );
5174
5175   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
5176   setPreferenceProperty( posHSizeGr, "columns", 2 );
5177   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
5178   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
5179   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
5180   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
5181   setPreferenceProperty( xv, "min", 0.0 );
5182   setPreferenceProperty( xv, "max", 1.0 );
5183   setPreferenceProperty( xv, "step", 0.1 );
5184   setPreferenceProperty( xh, "min", 0.0 );
5185   setPreferenceProperty( xh, "max", 1.0 );
5186   setPreferenceProperty( xh, "step", 0.1 );
5187   setPreferenceProperty( yh, "min", 0.0 );
5188   setPreferenceProperty( yh, "max", 1.0 );
5189   setPreferenceProperty( yh, "step", 0.1 );
5190   setPreferenceProperty( wh, "min", 0.0 );
5191   setPreferenceProperty( wh, "max", 1.0 );
5192   setPreferenceProperty( wh, "step", 0.1 );
5193   setPreferenceProperty( hh, "min", 0.0 );
5194   setPreferenceProperty( hh, "max", 1.0 );
5195   setPreferenceProperty( hh, "step", 0.1 );
5196
5197   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
5198   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
5199   setPreferenceProperty( distributionGr, "columns", 3 );
5200   QStringList types;
5201   types.append( tr( "SMESH_MONOCOLOR" ) );
5202   types.append( tr( "SMESH_MULTICOLOR" ) );
5203   indices.clear(); indices.append( 0 ); indices.append( 1 );
5204   setPreferenceProperty( coloringType, "strings", types );
5205   setPreferenceProperty( coloringType, "indexes", indices );
5206   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
5207
5208 }
5209
5210 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
5211 {
5212   if( sect=="SMESH" ) {
5213     float sbX1,sbY1,sbW,sbH;
5214     float aTol = 1.00000009999999;
5215     std::string aWarning;
5216     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5217     if( name=="selection_object_color" || name=="selection_element_color" ||
5218         name=="highlight_color" ||
5219         name=="selection_precision_node" || name=="selection_precision_element" ||
5220         name=="selection_precision_object")
5221       SMESH::UpdateSelectionProp( this );
5222     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
5223       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
5224       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
5225       if(sbX1+sbW > aTol){
5226         aWarning = "Origin and Size Vertical: X+Width > 1\n";
5227         sbX1=0.01;
5228         sbW=0.08;
5229         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
5230         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
5231       }
5232     }
5233     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
5234       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
5235       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
5236       if(sbY1+sbH > aTol){
5237         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
5238         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
5239         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
5240       }
5241     }
5242     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
5243       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5244       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
5245       if(sbX1+sbW > aTol){
5246         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
5247         sbX1=0.1;
5248         sbW=0.08;
5249         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5250         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
5251       }
5252     }
5253     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
5254       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5255       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
5256       if(sbY1+sbH > aTol){
5257         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
5258         sbY1=0.01;
5259         sbH=0.08;
5260         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5261         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
5262       }
5263     }
5264     else if ( name == "segmentation" ) {
5265       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
5266       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
5267     }
5268     else if ( name == "nb_segments_per_edge" ) {
5269       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
5270       myComponentSMESH->SetDefaultNbSegments( nbSeg );
5271     }
5272     else if ( name == "historical_python_dump" ||
5273               name == "forget_mesh_on_hyp_modif") {
5274       QString val = aResourceMgr->stringValue( "SMESH", name );
5275       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
5276     }
5277     else if ( name == QString( "numbering_node_color" ) || name == QString( "numbering_node_font" ) ) {
5278       SMESH::UpdateFontProp( this );    
5279     }
5280     else if ( name == QString( "numbering_elem_color" ) || name == QString( "numbering_elem_font" ) ) {
5281       SMESH::UpdateFontProp( this );
5282     }
5283
5284     if(aWarning.size() != 0){
5285       aWarning += "The default values are applied instead.";
5286       SUIT_MessageBox::warning(SMESHGUI::desktop(),
5287                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
5288                                QObject::tr(aWarning.c_str()));
5289     }
5290   }
5291 }
5292
5293 //================================================================================
5294 /*!
5295  * \brief Update something in accordance with update flags
5296   * \param theFlags - update flags
5297 *
5298 * Update viewer or/and object browser etc. in accordance with update flags ( see
5299 * LightApp_UpdateFlags enumeration ).
5300 */
5301 //================================================================================
5302 void SMESHGUI::update( const int flags )
5303 {
5304   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5305     SMESH::UpdateView();
5306   else
5307     SalomeApp_Module::update( flags );
5308 }
5309
5310 //================================================================================
5311 /*!
5312  * \brief Set default selection mode
5313 *
5314 * SLOT called when operation commited. Sets default selection mode
5315 */
5316 //================================================================================
5317 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5318 {
5319   SVTK_ViewWindow* vtkWnd =
5320     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5321   if ( vtkWnd )
5322     vtkWnd->SetSelectionMode( ActorSelection );
5323 }
5324
5325 //================================================================================
5326 /*!
5327  * \brief Set default selection mode
5328 *
5329 * SLOT called when operation aborted. Sets default selection mode
5330 */
5331 //================================================================================
5332 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5333 {
5334   SVTK_ViewWindow* vtkWnd =
5335     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5336   if ( vtkWnd )
5337     vtkWnd->SetSelectionMode( ActorSelection );
5338 }
5339
5340 //================================================================================
5341 /*!
5342  * \brief Creates operation with given identifier
5343   * \param id - identifier of operation to be started
5344   * \return Pointer on created operation or NULL if operation is not created
5345 *
5346 * Virtual method redefined from the base class creates operation with given id.
5347 * It is called called automatically from startOperation method of base class.
5348 */
5349 //================================================================================
5350 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5351 {
5352   LightApp_Operation* op = 0;
5353   // to do : create operation here
5354   switch( id )
5355   {
5356     case 417: //convert to quadratic
5357       op = new SMESHGUI_ConvToQuadOp();
5358     break;
5359     case 418: // create 2D mesh as boundary on 3D
5360       op = new SMESHGUI_Make2DFrom3DOp();
5361     break;
5362     case 420: // Reorient faces
5363       op = new SMESHGUI_ReorientFacesOp();
5364       break;
5365     case 701: // Compute mesh
5366       op = new SMESHGUI_ComputeOp();
5367     break;
5368     case 702: // Create mesh
5369       op = new SMESHGUI_MeshOp( true, true );
5370     break;
5371     case 703: // Create sub-mesh
5372       op = new SMESHGUI_MeshOp( true, false );
5373     break;
5374     case 704: // Edit mesh/sub-mesh
5375       op = new SMESHGUI_MeshOp( false );
5376     break;
5377     case 711: // Precompute mesh
5378       op = new SMESHGUI_PrecomputeOp();
5379     break;
5380     case 712: // Evaluate mesh
5381       op = new SMESHGUI_EvaluateOp();
5382     break;
5383     case 713: // Evaluate mesh
5384       op = new SMESHGUI_MeshOrderOp();
5385     break;
5386     case 806: // Create group on geom
5387       op = new SMESHGUI_GroupOnShapeOp();
5388       break;
5389     case 904: // Find element
5390       op = new SMESHGUI_FindElemByPointOp();
5391       break;
5392     case 4067: // Make mesh pass through point
5393       op = new SMESHGUI_MakeNodeAtPointOp();
5394       break;
5395     case 4070: // Create 0D elements on all nodes
5396       op = new SMESHGUI_Add0DElemsOnAllNodesOp();
5397       break;
5398     default:
5399     break;
5400   }
5401
5402   if( !op )
5403     op = SalomeApp_Module::createOperation( id );
5404   return op;
5405 }
5406
5407 //================================================================================
5408 /*!
5409  * \brief Stops current operations and starts a given one
5410   * \param id - The id of the operation to start
5411  */
5412 //================================================================================
5413
5414 void SMESHGUI::switchToOperation(int id)
5415 {
5416   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
5417     activeStudy()->abortAllOperations();
5418   startOperation( id );
5419 }
5420
5421 LightApp_Displayer* SMESHGUI::displayer()
5422 {
5423   if( !myDisplayer )
5424     myDisplayer = new SMESHGUI_Displayer( getApp() );
5425   return myDisplayer;
5426 }
5427
5428 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
5429 {
5430   int aHue = -1;
5431   int aTolerance = 64;
5432   int anIterations = 0;
5433   int aPeriod = 5;
5434
5435   while( 1 )
5436   {
5437     anIterations++;
5438     if( anIterations % aPeriod == 0 )
5439     {
5440       aTolerance /= 2;
5441       if( aTolerance < 1 )
5442         break;
5443     }
5444
5445     aHue = (int)( 360.0 * rand() / RAND_MAX );
5446
5447     bool ok = true;
5448     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
5449     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
5450     for( ; it != itEnd; ++it )
5451     {
5452       SALOMEDS::Color anAutoColor = *it;
5453       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
5454
5455       int h, s, v;
5456       aQColor.getHsv( &h, &s, &v );
5457       if( abs( h - aHue ) < aTolerance )
5458       {
5459         ok = false;
5460         break;
5461       }
5462     }
5463
5464     if( ok )
5465       break;
5466   }
5467
5468   QColor aColor;
5469   aColor.setHsv( aHue, 255, 255 );
5470
5471   SALOMEDS::Color aSColor;
5472   aSColor.R = aColor.redF();
5473   aSColor.G = aColor.greenF();
5474   aSColor.B = aColor.blueF();
5475
5476   return aSColor;
5477 }
5478
5479 const char* gSeparator = "_"; // character used to separate parameter names
5480 const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
5481 const char* gPathSep   = "|"; // character used to separate paths
5482
5483 /*!
5484  * \brief Store visual parameters
5485  *
5486  * This method is called just before the study document is saved.
5487  * Store visual parameters in AttributeParameter attribue(s)
5488  */
5489 void SMESHGUI::storeVisualParameters (int savePoint)
5490 {
5491   // localizing
5492   Kernel_Utils::Localizer loc;
5493
5494   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5495   if (!appStudy || !appStudy->studyDS())
5496     return;
5497   _PTR(Study) studyDS = appStudy->studyDS();
5498
5499   // componentName is used for encoding of entries when storing them in IParameters
5500   std::string componentName = myComponentSMESH->ComponentDataType();
5501   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
5502   //if (!aSComponent) return;
5503
5504   // IParameters
5505   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5506                                                              componentName.c_str(),
5507                                                              savePoint);
5508   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5509
5510   // store map of custom markers
5511   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5512   if( !aMarkerMap.empty() )
5513   {
5514     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
5515     for( ; anIter != aMarkerMap.end(); anIter++ )
5516     {
5517       int anId = anIter->first;
5518       VTK::MarkerData aMarkerData = anIter->second;
5519       std::string aMarkerFileName = aMarkerData.first;
5520       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
5521       if( aMarkerTexture.size() < 3 )
5522         continue; // should contain at least width, height and the first value
5523
5524       QString aPropertyName( "texture" );
5525       aPropertyName += gSeparator;
5526       aPropertyName += QString::number( anId );
5527
5528       QString aPropertyValue = aMarkerFileName.c_str();
5529       aPropertyValue += gPathSep;
5530
5531       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
5532       ushort aWidth = *aTextureIter++;
5533       ushort aHeight = *aTextureIter++;
5534       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
5535       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
5536       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
5537         aPropertyValue += QString::number( *aTextureIter );
5538
5539       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5540     }
5541   }
5542
5543   // viewers counters are used for storing view_numbers in IParameters
5544   int vtkViewers = 0;
5545
5546   // main cycle to store parameters of displayed objects
5547   QList<SUIT_ViewManager*> lst;
5548   QList<SUIT_ViewManager*>::Iterator it;
5549   getApp()->viewManagers(lst);
5550   for (it = lst.begin(); it != lst.end(); it++)
5551   {
5552     SUIT_ViewManager* vman = *it;
5553     QString vType = vman->getType();
5554
5555     // saving VTK actors properties
5556     if (vType == SVTK_Viewer::Type())
5557     {
5558       // store the clipping planes attached to the view manager
5559       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
5560       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
5561       if( anIter != myClippingPlaneInfoMap.end() )
5562         aClippingPlaneInfoList = anIter->second;
5563
5564       if( !aClippingPlaneInfoList.empty() ) {
5565         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
5566         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
5567         {
5568           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
5569           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
5570
5571           QString aPropertyName( "ClippingPlane" );
5572           aPropertyName += gSeparator;
5573           aPropertyName += QString::number( vtkViewers );
5574           aPropertyName += gSeparator;
5575           aPropertyName += QString::number( anId );
5576
5577           QString aPropertyValue = QString::number( (int)aPlane->PlaneMode ).toLatin1().constData();
5578           aPropertyValue += gDigitsSep;
5579           aPropertyValue += QString::number( aPlane->IsOpenGLClipping ).toLatin1().constData();
5580           aPropertyValue += gDigitsSep;
5581           if ( aPlane->PlaneMode == SMESH::Absolute ) {
5582             aPropertyValue += QString::number( aPlane->myAbsoluteOrientation ).toLatin1().constData();
5583             aPropertyValue += gDigitsSep;
5584             aPropertyValue += QString::number( aPlane->X ).toLatin1().constData();
5585             aPropertyValue += gDigitsSep;
5586             aPropertyValue += QString::number( aPlane->Y ).toLatin1().constData();
5587             aPropertyValue += gDigitsSep;
5588             aPropertyValue += QString::number( aPlane->Z ).toLatin1().constData();
5589             aPropertyValue += gDigitsSep;
5590             aPropertyValue += QString::number( aPlane->Dx ).toLatin1().constData();
5591             aPropertyValue += gDigitsSep;
5592             aPropertyValue += QString::number( aPlane->Dy ).toLatin1().constData();
5593             aPropertyValue += gDigitsSep;
5594             aPropertyValue += QString::number( aPlane->Dz ).toLatin1().constData();
5595           }
5596           else if ( aPlane->PlaneMode == SMESH::Relative ) {
5597             aPropertyValue += QString::number( (int)aPlane->myRelativeOrientation ).toLatin1().constData();
5598             aPropertyValue += gDigitsSep;
5599             aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5600             aPropertyValue += gDigitsSep;
5601             aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5602             aPropertyValue += gDigitsSep;
5603             aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5604           }
5605
5606           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5607         }
5608       }
5609
5610       QVector<SUIT_ViewWindow*> views = vman->getViews();
5611       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5612       {
5613         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5614         {
5615           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5616           vtkActorCollection* allActors = aCopy.GetActors();
5617           allActors->InitTraversal();
5618           while (vtkActor* actor = allActors->GetNextActor())
5619           {
5620             if (actor->GetVisibility()) // store only visible actors
5621             {
5622               SMESH_Actor* aSmeshActor = 0;
5623               if (actor->IsA("SMESH_Actor"))
5624                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5625               if (aSmeshActor && aSmeshActor->hasIO())
5626               {
5627                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5628                 if (io->hasEntry())
5629                 {
5630                   // entry is "encoded" = it does NOT contain component adress,
5631                   // since it is a subject to change on next component loading
5632                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5633
5634                   std::string param, vtkParam = vType.toLatin1().data();
5635                   vtkParam += gSeparator;
5636                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5637                   vtkParam += gSeparator;
5638
5639                   // Visibility
5640                   param = vtkParam + "Visibility";
5641                   ip->setParameter(entry, param, "On");
5642
5643                   // Representation
5644                   param = vtkParam + "Representation";
5645                   ip->setParameter(entry, param, QString::number
5646                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5647
5648                   // IsShrunk
5649                   param = vtkParam + "IsShrunk";
5650                   ip->setParameter(entry, param, QString::number
5651                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5652
5653                   // Displayed entities
5654                   unsigned int aMode = aSmeshActor->GetEntityMode();
5655                   bool isE  = aMode & SMESH_Actor::eEdges;
5656                   bool isF  = aMode & SMESH_Actor::eFaces;
5657                   bool isV  = aMode & SMESH_Actor::eVolumes;
5658                   bool is0d = aMode & SMESH_Actor::e0DElements;
5659                   bool isB  = aMode & SMESH_Actor::eBallElem;
5660
5661                   QString modeStr ("e");
5662                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5663                   modeStr += gDigitsSep; modeStr += "f";
5664                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5665                   modeStr += gDigitsSep; modeStr += "v";
5666                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5667                   modeStr += gDigitsSep; modeStr += "0d";
5668                   modeStr += gDigitsSep; modeStr += QString::number(is0d);
5669                   modeStr += gDigitsSep; modeStr += "b";
5670                   modeStr += gDigitsSep; modeStr += QString::number(isB);
5671
5672                   param = vtkParam + "Entities";
5673                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5674
5675                   // Colors
5676                   double r, g, b;
5677                   int delta;
5678
5679                   aSmeshActor->GetSufaceColor(r, g, b, delta);
5680                   QStringList colorStr;
5681                   colorStr << "surface";
5682                   colorStr << QString::number(r);
5683                   colorStr << QString::number(g);
5684                   colorStr << QString::number(b);
5685
5686                   colorStr << "backsurface";
5687                   colorStr << QString::number(delta);
5688
5689                   aSmeshActor->GetVolumeColor(r, g, b, delta);
5690                   colorStr << "volume";
5691                   colorStr << QString::number(r);
5692                   colorStr << QString::number(g);
5693                   colorStr << QString::number(b);
5694                   colorStr << QString::number(delta);
5695
5696                   aSmeshActor->GetEdgeColor(r, g, b);
5697                   colorStr << "edge";
5698                   colorStr << QString::number(r);
5699                   colorStr << QString::number(g);
5700                   colorStr << QString::number(b);
5701
5702                   aSmeshActor->GetNodeColor(r, g, b);
5703                   colorStr << "node";
5704                   colorStr << QString::number(r);
5705                   colorStr << QString::number(g);
5706                   colorStr << QString::number(b);
5707
5708                   aSmeshActor->GetOutlineColor(r, g, b);
5709                   colorStr << "outline";
5710                   colorStr << QString::number(r);
5711                   colorStr << QString::number(g);
5712                   colorStr << QString::number(b);
5713
5714                   aSmeshActor->Get0DColor(r, g, b);
5715                   colorStr << "elem0d";
5716                   colorStr << QString::number(r);
5717                   colorStr << QString::number(g);
5718                   colorStr << QString::number(b);
5719
5720                   aSmeshActor->GetBallColor(r, g, b);
5721                   colorStr << "ball";
5722                   colorStr << QString::number(r);
5723                   colorStr << QString::number(g);
5724                   colorStr << QString::number(b);
5725
5726                   aSmeshActor->GetFacesOrientationColor(r, g, b);
5727                   colorStr << "orientation";
5728                   colorStr << QString::number(r);
5729                   colorStr << QString::number(g);
5730                   colorStr << QString::number(b);
5731
5732                   param = vtkParam + "Colors";
5733                   ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
5734
5735                   // Sizes
5736                   QStringList sizeStr;
5737                   sizeStr << "line";
5738                   sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
5739                   sizeStr << "outline";
5740                   sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
5741                   sizeStr << "elem0d";
5742                   sizeStr << QString::number((int)aSmeshActor->Get0DSize());
5743                   sizeStr << "ball";
5744                   sizeStr << QString::number((int)aSmeshActor->GetBallSize());
5745                   sizeStr << QString::number((double)aSmeshActor->GetBallScale());
5746                   sizeStr << "shrink";
5747                   sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
5748                   sizeStr << "orientation";
5749                   sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
5750                   sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
5751
5752                   param = vtkParam + "Sizes";
5753                   ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
5754
5755                   // Point marker
5756                   QString markerStr;
5757
5758                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5759                   if( aMarkerType == VTK::MT_USER ) {
5760                     markerStr += "custom";
5761                     markerStr += gDigitsSep;
5762                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5763                   }
5764                   else {
5765                     markerStr += "std";
5766                     markerStr += gDigitsSep;
5767                     markerStr += QString::number( (int)aMarkerType );
5768                     markerStr += gDigitsSep;
5769                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5770                   }
5771
5772                   param = vtkParam + "PointMarker";
5773                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5774
5775                   // Opacity
5776                   param = vtkParam + "Opacity";
5777                   ip->setParameter(entry, param,
5778                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5779
5780                   // Clipping
5781                   param = vtkParam + "ClippingPlane";
5782                   int aPlaneId = 0;
5783                   if( !aClippingPlaneInfoList.empty() ) {
5784                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5785                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5786                     {
5787                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5788                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5789                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5790                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5791                         if( aSmeshActor == *anIter2 ) {
5792                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5793                                             QString::number( anId ).toLatin1().constData() );
5794                           break;
5795                         }
5796                       }
5797                     }
5798                   }
5799                   if( aPlaneId == 0 )
5800                     ip->setParameter( entry, param, "Off" );
5801                 } // if (io->hasEntry())
5802               } // SMESH_Actor && hasIO
5803             } // isVisible
5804           } // while.. actors traversal
5805         } // if (vtkView)
5806       } // for (views)
5807       vtkViewers++;
5808     } // if (SVTK view model)
5809   } // for (viewManagers)
5810 }
5811
5812 // data structures for clipping planes processing
5813 typedef struct {
5814   int Id;
5815   int Mode;
5816   bool isOpenGLClipping;
5817   vtkIdType RelativeOrientation;
5818   double Distance;
5819   double Angle[2];
5820   int AbsoluteOrientation;
5821   double X, Y, Z, Dx, Dy, Dz;
5822 } TPlaneData;
5823 typedef std::list<TPlaneData>         TPlaneDataList;
5824 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5825
5826 typedef std::list<vtkActor*>          TActorList;
5827 typedef struct {
5828   int PlaneId;
5829   TActorList ActorList;
5830   SUIT_ViewManager* ViewManager;
5831 } TPlaneInfo;
5832 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5833 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5834
5835 /*!
5836  * \brief Restore visual parameters
5837  *
5838  * This method is called after the study document is opened.
5839  * Restore visual parameters from AttributeParameter attribue(s)
5840  */
5841 void SMESHGUI::restoreVisualParameters (int savePoint)
5842 {
5843   // localizing
5844   Kernel_Utils::Localizer loc;
5845
5846   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5847   if (!appStudy || !appStudy->studyDS())
5848     return;
5849   _PTR(Study) studyDS = appStudy->studyDS();
5850
5851   // componentName is used for encoding of entries when storing them in IParameters
5852   std::string componentName = myComponentSMESH->ComponentDataType();
5853   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5854   //if (!aSComponent) return;
5855
5856   // IParameters
5857   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5858                                                              componentName.c_str(),
5859                                                              savePoint);
5860   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5861
5862   // restore map of custom markers and map of clipping planes
5863   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5864   TPlaneDataMap aPlaneDataMap;
5865
5866   std::vector<std::string> properties = ip->getProperties();
5867   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5868   {
5869     std::string property = *propIt;
5870     QString aPropertyName( property.c_str() );
5871     QString aPropertyValue( ip->getProperty( property ).c_str() );
5872
5873     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5874     if( aPropertyNameList.isEmpty() )
5875       continue;
5876
5877     QString aPropertyType = aPropertyNameList[0];
5878     if( aPropertyType == "texture" )
5879     {
5880       if( aPropertyNameList.size() != 2 )
5881         continue;
5882
5883       bool ok = false;
5884       int anId = aPropertyNameList[1].toInt( &ok );
5885       if( !ok || anId < 1 )
5886         continue;
5887
5888       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5889       if( aPropertyValueList.size() != 2 )
5890         continue;
5891
5892       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5893       QString aMarkerTextureString = aPropertyValueList[1];
5894       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5895       if( aMarkerTextureStringList.size() != 3 )
5896         continue;
5897
5898       ok = false;
5899       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5900       if( !ok )
5901         continue;
5902
5903       ok = false;
5904       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5905       if( !ok )
5906         continue;
5907
5908       VTK::MarkerTexture aMarkerTexture;
5909       aMarkerTexture.push_back( aWidth );
5910       aMarkerTexture.push_back( aHeight );
5911
5912       QString aMarkerTextureData = aMarkerTextureStringList[2];
5913       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5914       {
5915         QChar aChar = aMarkerTextureData.at( i );
5916         if( aChar.isDigit() )
5917           aMarkerTexture.push_back( aChar.digitValue() );
5918       }
5919
5920       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5921     }
5922     else if( aPropertyType == "ClippingPlane" )
5923     {
5924       if( aPropertyNameList.size() != 3 )
5925         continue;
5926
5927       bool ok = false;
5928       int aViewId = aPropertyNameList[1].toInt( &ok );
5929       if( !ok || aViewId < 0 )
5930         continue;
5931
5932       ok = false;
5933       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5934       if( !ok || aClippingPlaneId < 0 )
5935         continue;
5936
5937       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5938       if( aPropertyValueList.size() != 6 && aPropertyValueList.size() != 9 )
5939         continue;
5940
5941       TPlaneData aPlaneData;
5942       aPlaneData.Id = aClippingPlaneId;
5943
5944       ok = false;
5945       aPlaneData.Mode = aPropertyValueList[0].toInt( &ok );
5946       if( !ok )
5947         continue;
5948       
5949       ok = false;
5950       aPlaneData.isOpenGLClipping = aPropertyValueList[1].toInt( &ok );
5951       if( !ok )
5952         continue;
5953
5954       if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Absolute )
5955       {
5956         ok = false;
5957         aPlaneData.AbsoluteOrientation = aPropertyValueList[2].toInt( &ok );
5958         if( !ok )
5959           continue;
5960
5961         ok = false;
5962         aPlaneData.X = aPropertyValueList[3].toDouble( &ok );
5963         if( !ok )
5964           continue;
5965
5966         ok = false;
5967         aPlaneData.Y = aPropertyValueList[4].toDouble( &ok );
5968         if( !ok )
5969           continue;
5970
5971         ok = false;
5972         aPlaneData.Z = aPropertyValueList[5].toDouble( &ok );
5973         if( !ok )
5974           continue;
5975
5976         ok = false;
5977         aPlaneData.Dx = aPropertyValueList[6].toDouble( &ok );
5978         if( !ok )
5979           continue;
5980
5981         ok = false;
5982         aPlaneData.Dy = aPropertyValueList[7].toDouble( &ok );
5983         if( !ok )
5984           continue;
5985
5986         ok = false;
5987         aPlaneData.Dz = aPropertyValueList[8].toDouble( &ok );
5988         if( !ok )
5989           continue;
5990       }
5991       else if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Relative ) {
5992         ok = false;
5993         aPlaneData.RelativeOrientation = aPropertyValueList[2].toInt( &ok );
5994         if( !ok )
5995           continue;
5996
5997         ok = false;
5998         aPlaneData.Distance = aPropertyValueList[3].toDouble( &ok );
5999         if( !ok )
6000           continue;
6001
6002         ok = false;
6003         aPlaneData.Angle[0] = aPropertyValueList[4].toDouble( &ok );
6004         if( !ok )
6005           continue;
6006
6007         ok = false;
6008         aPlaneData.Angle[1] = aPropertyValueList[5].toDouble( &ok );
6009         if( !ok )
6010           continue;
6011       }
6012
6013       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
6014       aPlaneDataList.push_back( aPlaneData );
6015     }
6016   }
6017
6018   TPlaneInfoMap aPlaneInfoMap;
6019
6020   std::vector<std::string> entries = ip->getEntries();
6021
6022   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
6023   {
6024     // entry is a normal entry - it should be "decoded" (setting base adress of component)
6025     QString entry (ip->decodeEntry(*entIt).c_str());
6026
6027     // Check that the entry corresponds to a real object in the Study
6028     // as the object may be deleted or modified after the visual state is saved.
6029     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
6030     if (!so) continue; //Skip the not existent entry
6031
6032     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
6033     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
6034
6035     std::vector<std::string>::iterator namesIt = paramNames.begin();
6036     std::vector<std::string>::iterator valuesIt = paramValues.begin();
6037
6038     // actors are stored in a map after displaying of them for
6039     // quicker access in the future: map < viewID to actor >
6040     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
6041
6042     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
6043     {
6044       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
6045       // '_' is used as separator and should not be used in viewer type or parameter names.
6046       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
6047       if (lst.size() != 3)
6048         continue;
6049
6050       QString viewerTypStr = lst[0];
6051       QString viewIndexStr = lst[1];
6052       QString paramNameStr = lst[2];
6053
6054       bool ok;
6055       int viewIndex = viewIndexStr.toUInt(&ok);
6056       if (!ok) // bad conversion of view index to integer
6057         continue;
6058
6059       // viewers
6060       if (viewerTypStr == SVTK_Viewer::Type())
6061       {
6062         SMESH_Actor* aSmeshActor = 0;
6063         if (vtkActors.IsBound(viewIndex))
6064           aSmeshActor = vtkActors.Find(viewIndex);
6065
6066         QList<SUIT_ViewManager*> lst;
6067         getApp()->viewManagers(viewerTypStr, lst);
6068
6069         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6070         SUIT_ViewManager* vman = NULL;
6071         if (viewIndex >= 0 && viewIndex < lst.count())
6072           vman = lst.at(viewIndex);
6073
6074         if (paramNameStr == "Visibility")
6075         {
6076           if (!aSmeshActor && displayer() && vman)
6077           {
6078             SUIT_ViewModel* vmodel = vman->getViewModel();
6079             // SVTK view model can be casted to SALOME_View
6080             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
6081
6082             // store displayed actor in a temporary map for quicker
6083             // access later when restoring other parameters
6084             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6085             vtkRenderer* Renderer = vtkView->getRenderer();
6086             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
6087             vtkActorCollection* theActors = aCopy.GetActors();
6088             theActors->InitTraversal();
6089             bool isFound = false;
6090             vtkActor *ac = theActors->GetNextActor();
6091             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
6092               if (ac->IsA("SMESH_Actor")) {
6093                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
6094                 if (aGeomAc->hasIO()) {
6095                   Handle(SALOME_InteractiveObject) io =
6096                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
6097                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
6098                     isFound = true;
6099                     vtkActors.Bind(viewIndex, aGeomAc);
6100                   }
6101                 }
6102               }
6103             }
6104           }
6105         } // if (paramNameStr == "Visibility")
6106         else
6107         {
6108           // the rest properties "work" with SMESH_Actor
6109           if (aSmeshActor)
6110           {
6111             QString val ((*valuesIt).c_str());
6112
6113             // Representation
6114             if (paramNameStr == "Representation") {
6115               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
6116             }
6117             // IsShrunk
6118             else if (paramNameStr == "IsShrunk") {
6119               if (val.toInt()) {
6120                 if (!aSmeshActor->IsShrunk())
6121                   aSmeshActor->SetShrink();
6122               }
6123               else {
6124                 if (aSmeshActor->IsShrunk())
6125                   aSmeshActor->UnShrink();
6126               }
6127             }
6128             // Displayed entities
6129             else if (paramNameStr == "Entities") {
6130               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
6131               int aEntityMode = SMESH_Actor::eAllEntity;
6132               for ( int i = 0; i < mode.count(); i+=2 ) {
6133                 if ( i < mode.count()-1 ) {
6134                   QString type = mode[i];
6135                   bool val = mode[i+1].toInt();
6136                   if      ( type == "e" && !val )
6137                     aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
6138                   else if ( type == "f" && !val )
6139                     aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
6140                   else if ( type == "v" && !val )
6141                     aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
6142                   else if ( type == "0d" && !val )
6143                     aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
6144                   else if ( type == "b" && !val )
6145                     aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
6146                 }
6147               }
6148               aSmeshActor->SetEntityMode( aEntityMode );
6149             }
6150             // Colors
6151             else if (paramNameStr == "Colors") {
6152               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
6153               QColor nodeColor;
6154               QColor edgeColor;
6155               QColor faceColor;
6156               QColor volumeColor;
6157               QColor elem0dColor;
6158               QColor ballColor;
6159               QColor outlineColor;
6160               QColor orientationColor;
6161               int deltaF;
6162               int deltaV;
6163               QColor c;
6164               double r, g, b;
6165               bool bOk;
6166               // below lines are required to get default values for delta coefficients
6167               // of backface color for faces and color of reversed volumes
6168               SMESH::GetColor( "SMESH", "fill_color",   c, deltaF, "0,170,255|-100" );
6169               SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
6170               for ( int i = 0; i < colors.count(); i++ ) {
6171                 QString type = colors[i];
6172                 if ( type == "surface" ) {
6173                   // face color is set by 3 values r:g:b, where
6174                   // - r,g,b - is rgb color components
6175                   if ( i+1 >= colors.count() ) break;                  // format error
6176                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6177                   if ( i+2 >= colors.count() ) break;                  // format error
6178                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6179                   if ( i+3 >= colors.count() ) break;                  // format error
6180                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6181                   faceColor.setRgbF( r, g, b );
6182                   i += 3;
6183                 }
6184                 else if ( type == "backsurface" ) {
6185                   // backface color can be defined in several ways
6186                   // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
6187                   // - in latest versions, it is set as delta coefficient
6188                   bool rgbOk = false, deltaOk;
6189                   if ( i+1 >= colors.count() ) break;                  // format error
6190                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6191                   int delta = colors[i+1].toInt( &deltaOk );
6192                   i++;                                 // shift index
6193                   if ( i+1 < colors.count() )          // index is shifted to 1
6194                     g = colors[i+1].toDouble( &rgbOk );
6195                   if ( rgbOk ) i++;                    // shift index
6196                   if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
6197                     b = colors[i+1].toDouble( &rgbOk );
6198                   if ( rgbOk ) i++;
6199                   // - as currently there's no way to set directly backsurface color as it was before,
6200                   // we ignore old dump where r,g,b triple was set
6201                   // - also we check that delta parameter is set properly
6202                   if ( !rgbOk && deltaOk )
6203                     deltaF = delta;
6204                 }
6205                 else if ( type == "volume" ) {
6206                   // volume color is set by 4 values r:g:b:delta, where
6207                   // - r,g,b - is a normal volume rgb color components
6208                   // - delta - is a reversed volume color delta coefficient
6209                   if ( i+1 >= colors.count() ) break;                  // format error
6210                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6211                   if ( i+2 >= colors.count() ) break;                  // format error
6212                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6213                   if ( i+3 >= colors.count() ) break;                  // format error
6214                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6215                   if ( i+4 >= colors.count() ) break;                  // format error
6216                   int delta = colors[i+4].toInt( &bOk );
6217                   if ( !bOk ) break;                                   // format error
6218                   volumeColor.setRgbF( r, g, b );
6219                   deltaV = delta;
6220                   i += 4;
6221                 }
6222                 else if ( type == "edge" ) {
6223                   // edge color is set by 3 values r:g:b, where
6224                   // - r,g,b - is rgb color components
6225                   if ( i+1 >= colors.count() ) break;                  // format error
6226                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6227                   if ( i+2 >= colors.count() ) break;                  // format error
6228                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6229                   if ( i+3 >= colors.count() ) break;                  // format error
6230                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6231                   edgeColor.setRgbF( r, g, b );
6232                   i += 3;
6233                 }
6234                 else if ( type == "node" ) {
6235                   // node color is set by 3 values r:g:b, where
6236                   // - r,g,b - is rgb color components
6237                   if ( i+1 >= colors.count() ) break;                  // format error
6238                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6239                   if ( i+2 >= colors.count() ) break;                  // format error
6240                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6241                   if ( i+3 >= colors.count() ) break;                  // format error
6242                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6243                   nodeColor.setRgbF( r, g, b );
6244                   i += 3;
6245                 }
6246                 else if ( type == "elem0d" ) {
6247                   // 0d element color is set by 3 values r:g:b, where
6248                   // - r,g,b - is rgb color components
6249                   if ( i+1 >= colors.count() ) break;                  // format error
6250                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6251                   if ( i+2 >= colors.count() ) break;                  // format error
6252                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6253                   if ( i+3 >= colors.count() ) break;                  // format error
6254                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6255                   elem0dColor.setRgbF( r, g, b );
6256                   i += 3;
6257                 }
6258                 else if ( type == "ball" ) {
6259                   // ball color is set by 3 values r:g:b, where
6260                   // - r,g,b - is rgb color components
6261                   if ( i+1 >= colors.count() ) break;                  // format error
6262                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6263                   if ( i+2 >= colors.count() ) break;                  // format error
6264                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6265                   if ( i+3 >= colors.count() ) break;                  // format error
6266                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6267                   ballColor.setRgbF( r, g, b );
6268                   i += 3;
6269                 }
6270                 else if ( type == "outline" ) {
6271                   // outline color is set by 3 values r:g:b, where
6272                   // - r,g,b - is rgb color components
6273                   if ( i+1 >= colors.count() ) break;                  // format error
6274                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6275                   if ( i+2 >= colors.count() ) break;                  // format error
6276                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6277                   if ( i+3 >= colors.count() ) break;                  // format error
6278                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6279                   outlineColor.setRgbF( r, g, b );
6280                   i += 3;
6281                 }
6282                 else if ( type == "orientation" ) {
6283                   // orientation color is set by 3 values r:g:b, where
6284                   // - r,g,b - is rgb color components
6285                   if ( i+1 >= colors.count() ) break;                  // format error
6286                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6287                   if ( i+2 >= colors.count() ) break;                  // format error
6288                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6289                   if ( i+3 >= colors.count() ) break;                  // format error
6290                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6291                   orientationColor.setRgbF( r, g, b );
6292                   i += 3;
6293                 }
6294               }
6295               // node color
6296               if ( nodeColor.isValid() )
6297                 aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
6298               // edge color
6299               if ( edgeColor.isValid() )
6300                 aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
6301               // face color
6302               if ( faceColor.isValid() )
6303                 aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6304               // volume color
6305               if ( volumeColor.isValid() )
6306                 aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
6307               else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
6308                 aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6309               // 0d element color
6310               if ( elem0dColor.isValid() )
6311                 aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
6312               // ball color
6313               if ( ballColor.isValid() )
6314                 aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
6315               // outline color
6316               if ( outlineColor.isValid() )
6317                 aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
6318               // orientation color
6319               if ( orientationColor.isValid() )
6320                 aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
6321             }
6322             // Sizes
6323             else if (paramNameStr == "Sizes") {
6324               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
6325               bool bOk;
6326               int lineWidth = -1;
6327               int outlineWidth = -1;
6328               int elem0dSize = -1;
6329               int ballSize = -1;
6330               double ballScale = -1.0;
6331               double shrinkSize = -1;
6332               double orientationSize = -1;
6333               bool orientation3d = false;
6334               for ( int i = 0; i < sizes.count(); i++ ) {
6335                 QString type = sizes[i];
6336                 if ( type == "line" ) {
6337                   // line (wireframe) width is given as single integer value
6338                   if ( i+1 >= sizes.count() ) break;                    // format error
6339                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6340                   lineWidth = v;
6341                   i++;
6342                 }
6343                 if ( type == "outline" ) {
6344                   // outline width is given as single integer value
6345                   if ( i+1 >= sizes.count() ) break;                    // format error
6346                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6347                   outlineWidth = v;
6348                   i++;
6349                 }
6350                 else if ( type == "elem0d" ) {
6351                   // 0d element size is given as single integer value
6352                   if ( i+1 >= sizes.count() ) break;                    // format error
6353                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6354                   elem0dSize = v;
6355                   i++;
6356                 }
6357                 else if ( type == "ball" ) {
6358                   // balls are specified by two values: size:scale, where
6359                   // - size - is a integer value specifying size
6360                   // - scale - is a double value specifying scale factor
6361                   if ( i+1 >= sizes.count() ) break;                       // format error
6362                   int v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6363                   if ( i+2 >= sizes.count() ) break;                       // format error
6364                   double v2 = sizes[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6365                   ballSize = v1;
6366                   ballScale = v2;
6367                   i += 2;
6368                 }
6369                 else if ( type == "shrink" ) {
6370                   // shrink factor is given as single floating point value
6371                   if ( i+1 >= sizes.count() ) break;                          // format error
6372                   double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break;  // format error
6373                   shrinkSize = v;
6374                   i++;
6375                 }
6376                 else if ( type == "orientation" ) {
6377                   // orientation vectors are specified by two values size:3d, where
6378                   // - size - is a floating point value specifying scale factor
6379                   // - 3d - is a boolean
6380                   if ( i+1 >= sizes.count() ) break;                          // format error
6381                   double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6382                   if ( i+2 >= sizes.count() ) break;                          // format error
6383                   int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break;       // format error
6384                   orientationSize = v1;
6385                   orientation3d = (bool)v2;
6386                   i += 2;
6387                 }
6388               }
6389               // line (wireframe) width
6390               if ( lineWidth > 0 )
6391                 aSmeshActor->SetLineWidth( lineWidth );
6392               // outline width
6393               if ( outlineWidth > 0 )
6394                 aSmeshActor->SetOutlineWidth( outlineWidth );
6395               else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
6396                 aSmeshActor->SetOutlineWidth( lineWidth );
6397               // 0d element size
6398               if ( elem0dSize > 0 )
6399                 aSmeshActor->Set0DSize( elem0dSize );
6400               // ball size
6401               if ( ballSize > 0 )
6402                 aSmeshActor->SetBallSize( ballSize );
6403               // ball scale
6404               if ( ballScale > 0.0 )
6405                 aSmeshActor->SetBallScale( ballScale );
6406               // shrink factor
6407               if ( shrinkSize > 0 )
6408                 aSmeshActor->SetShrinkFactor( shrinkSize );
6409               // orientation vectors
6410               if ( orientationSize > 0 ) {
6411                 aSmeshActor->SetFacesOrientationScale( orientationSize );
6412                 aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
6413               }
6414             }
6415             // Point marker
6416             else if (paramNameStr == "PointMarker") {
6417               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
6418               if( data.count() >= 2 ) {
6419                 bool ok = false;
6420                 int aParam1 = data[1].toInt( &ok );
6421                 if( ok ) {
6422                   if( data[0] == "std" && data.count() == 3 ) {
6423                     int aParam2 = data[2].toInt( &ok );
6424                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
6425                   }
6426                   else if( data[0] == "custom" ) {
6427                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
6428                     if( markerIt != aMarkerMap.end() ) {
6429                       VTK::MarkerData aMarkerData = markerIt->second;
6430                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
6431                     }
6432                   }
6433                 }
6434               }
6435             }
6436             // Opacity
6437             else if (paramNameStr == "Opacity") {
6438               aSmeshActor->SetOpacity(val.toFloat());
6439             }
6440             // Clipping
6441             else if (paramNameStr.startsWith("ClippingPlane")) {
6442               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
6443               // old format - val looks like "Off" or "1:0:0:0.5:0:0" 
6444               // (mode(relative), is OpenGL clipping plane, orientation, distance, two angles)
6445               // or "0:1:1:10.5:1.0:1.0:15.0:10.0:10.0" 
6446               // (mode(absolute), is OpenGL clipping plane, orientation, base point(x, y, z), direction (dx, dy, dz))
6447               // new format - val looks like "Off" or "0" (plane id)
6448               // (note: in new format "Off" value is used only for consistency,
6449               //  so it is processed together with values in old format)
6450               bool anIsOldFormat = ( vals.count() == 6 || vals.count() == 9 || val == "Off" );
6451               if( anIsOldFormat ) {
6452                 if (paramNameStr == "ClippingPlane1" || val == "Off")
6453                   aSmeshActor->RemoveAllClippingPlanes();
6454                 if (val != "Off") {
6455                   QList<SUIT_ViewManager*> lst;
6456                   getApp()->viewManagers(viewerTypStr, lst);
6457                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6458                   if (viewIndex >= 0 && viewIndex < lst.count()) {
6459                     SUIT_ViewManager* vman = lst.at(viewIndex);
6460                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6461
6462                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
6463
6464                     SMESH::TActorList anActorList;
6465                     anActorList.push_back( aSmeshActor );
6466                     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( vtkView );
6467                     aPlane->myViewWindow = vtkView;
6468                     SMESH::Mode aMode = ( SMESH::Mode )vals[0].toInt();
6469                     aPlane->PlaneMode = aMode;
6470                     bool isOpenGLClipping = ( bool )vals[1].toInt();
6471                     aPlane->IsOpenGLClipping = isOpenGLClipping;
6472                     if ( aMode == SMESH::Absolute ) {
6473                       aPlane->myAbsoluteOrientation = vals[2].toInt();
6474                       aPlane->X = vals[3].toFloat();
6475                       aPlane->Y = vals[4].toFloat();
6476                       aPlane->Z = vals[5].toFloat();
6477                       aPlane->Dx = vals[6].toFloat();
6478                       aPlane->Dy = vals[7].toFloat();
6479                       aPlane->Dz = vals[8].toFloat();
6480                     }
6481                     else if ( aMode == SMESH::Relative ) {
6482                       aPlane->myRelativeOrientation = (SMESH::Orientation)vals[2].toInt();
6483                       aPlane->myDistance = vals[3].toFloat();
6484                       aPlane->myAngle[0] = vals[4].toFloat();
6485                       aPlane->myAngle[1] = vals[5].toFloat();
6486                     }
6487
6488                     if( aPlane ) {
6489                       if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6490                         SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6491                         aClippingPlaneInfo.Plane = aPlane;
6492                         aClippingPlaneInfo.ActorList = anActorList;
6493                         aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6494                       }
6495                     }
6496                   }
6497                 }
6498               }
6499               else {
6500                 bool ok = false;
6501                 int aPlaneId = val.toInt( &ok );
6502                 if( ok && aPlaneId >= 0 ) {
6503                   bool anIsDefinedPlane = false;
6504                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
6505                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
6506                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6507                     TPlaneInfo& aPlaneInfo = *anIter;
6508                     if( aPlaneInfo.PlaneId == aPlaneId ) {
6509                       aPlaneInfo.ActorList.push_back( aSmeshActor );
6510                       anIsDefinedPlane = true;
6511                       break;
6512                     }
6513                   }
6514                   if( !anIsDefinedPlane ) {
6515                     TPlaneInfo aPlaneInfo;
6516                     aPlaneInfo.PlaneId = aPlaneId;
6517                     aPlaneInfo.ActorList.push_back( aSmeshActor );
6518                     aPlaneInfo.ViewManager = vman;
6519
6520                     // to make the list sorted by plane id
6521                     anIter = aPlaneInfoList.begin();
6522                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6523                       const TPlaneInfo& aPlaneInfoRef = *anIter;
6524                       if( aPlaneInfoRef.PlaneId > aPlaneId )
6525                         break;
6526                     }
6527                     aPlaneInfoList.insert( anIter, aPlaneInfo );
6528                   }
6529                 }
6530               }
6531             }
6532           } // if (aSmeshActor)
6533         } // other parameters than Visibility
6534       }
6535     } // for names/parameters iterator
6536   } // for entries iterator
6537
6538   // take into account planes with empty list of actors referred to them
6539   QList<SUIT_ViewManager*> aVMList;
6540   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
6541
6542   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
6543   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
6544     int aViewId = aPlaneDataIter->first;
6545     if( aViewId >= 0 && aViewId < aVMList.count() ) {
6546       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
6547
6548       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
6549
6550       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
6551       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
6552       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
6553         const TPlaneData& aPlaneData = *anIter2;
6554         int aPlaneId = aPlaneData.Id;
6555
6556         bool anIsFound = false;
6557         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6558         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6559           const TPlaneInfo& aPlaneInfo = *anIter3;
6560           if( aPlaneInfo.PlaneId == aPlaneId ) {
6561             anIsFound = true;
6562             break;
6563           }
6564         }
6565
6566         if( !anIsFound ) {
6567           TPlaneInfo aPlaneInfo; // ActorList field is empty
6568           aPlaneInfo.PlaneId = aPlaneId;
6569           aPlaneInfo.ViewManager = aViewManager;
6570
6571           // to make the list sorted by plane id
6572           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
6573           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
6574             const TPlaneInfo& aPlaneInfoRef = *anIter4;
6575             if( aPlaneInfoRef.PlaneId > aPlaneId )
6576               break;
6577           }
6578           aPlaneInfoList.insert( anIter4, aPlaneInfo );
6579         }
6580       }
6581     }
6582   }
6583
6584   // add clipping planes to actors according to the restored parameters
6585   // and update the clipping plane map
6586   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
6587   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
6588     int aViewId = anIter1->first;
6589     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
6590
6591     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
6592     if( anIter2 == aPlaneDataMap.end() )
6593       continue;
6594     const TPlaneDataList& aPlaneDataList = anIter2->second;
6595
6596     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6597     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6598       const TPlaneInfo& aPlaneInfo = *anIter3;
6599       int aPlaneId = aPlaneInfo.PlaneId;
6600       const TActorList& anActorList = aPlaneInfo.ActorList;
6601       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
6602       if( !aViewManager )
6603         continue;
6604
6605       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
6606       if( !aViewWindow )
6607         continue;
6608
6609       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
6610
6611       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
6612       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
6613         const TPlaneData& aPlaneData = *anIter4;
6614         if( aPlaneData.Id == aPlaneId ) {
6615           SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( aViewWindow );
6616           aPlane->myViewWindow = aViewWindow;
6617           aPlane->PlaneMode = (SMESH::Mode)aPlaneData.Mode;
6618           aPlane->IsOpenGLClipping = aPlaneData.isOpenGLClipping;
6619           if ( aPlane->PlaneMode == SMESH::Absolute ) {
6620             aPlane->myAbsoluteOrientation = aPlaneData.AbsoluteOrientation;
6621             aPlane->X = aPlaneData.X;
6622             aPlane->Y = aPlaneData.Y;
6623             aPlane->Z = aPlaneData.Z;
6624             aPlane->Dx = aPlaneData.Dx;
6625             aPlane->Dy = aPlaneData.Dy;
6626             aPlane->Dz = aPlaneData.Dz;
6627           }
6628           else if ( aPlane->PlaneMode == SMESH::Relative ) {
6629             aPlane->myRelativeOrientation = (SMESH::Orientation)aPlaneData.RelativeOrientation;
6630             aPlane->myDistance = aPlaneData.Distance;
6631             aPlane->myAngle[0] = aPlaneData.Angle[0];
6632             aPlane->myAngle[1] = aPlaneData.Angle[1];
6633           }
6634           if( aPlane ) {
6635             if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6636               SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6637               aClippingPlaneInfo.Plane = aPlane;
6638               aClippingPlaneInfo.ActorList = anActorList;
6639               aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6640             }
6641           }
6642           break;
6643         }
6644       }
6645     
6646     }
6647   }
6648   
6649
6650   // update all VTK views
6651   QList<SUIT_ViewManager*> lst;
6652   getApp()->viewManagers(lst);
6653   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
6654     SUIT_ViewModel* vmodel = (*it)->getViewModel();
6655     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
6656       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
6657       // set OpenGL clipping planes
6658       VTK::ActorCollectionCopy aCopy( vtkView->getRenderer()->GetActors() );
6659       vtkActorCollection* anAllActors = aCopy.GetActors();
6660       anAllActors->InitTraversal();
6661       while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
6662         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
6663           anActor->SetOpenGLClippingPlane();
6664       
6665       vtkView->getRenderer()->ResetCameraClippingRange();
6666       vtkView->Repaint();
6667     }
6668   }
6669 }
6670
6671 /*!
6672   \brief Adds preferences for dfont of VTK viewer
6673   \param label label
6674   \param pIf group identifier
6675   \param param parameter
6676   \return identifier of preferences
6677 */
6678 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
6679 {
6680   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
6681
6682   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
6683
6684   QStringList fam;
6685   fam.append( tr( "SMESH_FONT_ARIAL" ) );
6686   fam.append( tr( "SMESH_FONT_COURIER" ) );
6687   fam.append( tr( "SMESH_FONT_TIMES" ) );
6688
6689   setPreferenceProperty( tfont, "fonts", fam );
6690
6691   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
6692   if ( needSize ) f = f | QtxFontEdit::Size;
6693   setPreferenceProperty( tfont, "features", f );
6694
6695   return tfont;
6696 }
6697
6698 /*!
6699   \brief Actions after hypothesis edition
6700   Updates object browser after hypothesis edition
6701 */
6702 void SMESHGUI::onHypothesisEdit( int result )
6703 {
6704   if( result == 1 )
6705     SMESHGUI::Modified();
6706   updateObjBrowser( true );
6707 }
6708
6709
6710 /*!
6711   \brief Signal handler closing(SUIT_ViewWindow*) of a view
6712   \param pview view being closed
6713 */
6714 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
6715 #ifndef DISABLE_PLOT2DVIEWER
6716   //Crear all Plot2d Viewers if need.
6717   SMESH::ClearPlot2Viewers(pview);
6718 #endif
6719 }
6720
6721 void SMESHGUI::message( const QString& msg )
6722 {
6723   // dispatch message
6724   QStringList data = msg.split("/");
6725   if ( data.count() > 0 ) {
6726     if ( data.first() == "mesh_loading" ) {
6727       // get mesh entry
6728       QString entry = data.count() > 1 ? data[1] : QString();
6729       if ( entry.isEmpty() )
6730         return;
6731       // get study
6732       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
6733       // get mesh name
6734       _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().constData() );
6735       QString name;
6736       if ( obj )
6737         name = obj->GetName().c_str();
6738       if ( name.isEmpty() )
6739         return;
6740       
6741       if ( data.last() == "stop" )
6742         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
6743       else
6744         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
6745       QApplication::processEvents();
6746     }
6747   }
6748 }
6749
6750 /*!
6751   \brief Connects or disconnects signals about activating and cloning view on the module slots
6752   \param pview view which is connected/disconnected
6753 */
6754 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
6755   if(!pview)
6756     return;
6757
6758   SUIT_ViewManager* viewMgr = pview->getViewManager();
6759   if ( viewMgr ) {
6760     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6761                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6762
6763     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6764              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6765   }
6766 }
6767
6768 /*!
6769   \brief Return \c true if object can be renamed
6770 */
6771 bool SMESHGUI::renameAllowed( const QString& entry) const {
6772   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6773   if( !anApp )
6774     return false;
6775
6776   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6777   if( !appStudy )
6778     return false;
6779
6780   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
6781   
6782   if(!obj)
6783     return false;
6784
6785   if(appStudy->isComponent(entry) || obj->isReference())
6786     return false;
6787
6788   // check type to prevent renaming of inappropriate objects
6789   int aType = SMESHGUI_Selection::type(qPrintable(entry), SMESH::GetActiveStudyDocument());
6790   if (aType == SMESH::MESH || aType == SMESH::GROUP ||
6791       aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
6792       aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
6793       aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
6794       aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
6795     return true;
6796
6797   return false;
6798 }
6799
6800 /*!
6801   Rename object by entry.
6802   \param entry entry of the object
6803   \param name new name of the object
6804   \brief Return \c true if rename operation finished successfully, \c false otherwise.
6805 */
6806 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
6807
6808   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6809   if( !anApp )
6810     return false;
6811     
6812   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6813
6814   if(!appStudy)
6815     return false;
6816   
6817   _PTR(Study) aStudy = appStudy->studyDS();
6818   
6819   if(!aStudy)
6820     return false;
6821   
6822   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
6823   if ( aLocked ) {
6824     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
6825     return false;
6826   }
6827
6828
6829   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
6830   _PTR(GenericAttribute) anAttr;
6831   _PTR(AttributeName) aName;
6832   if ( obj ) {
6833     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
6834       aName = anAttr;
6835       // check type to prevent renaming of inappropriate objects
6836       int aType = SMESHGUI_Selection::type( qPrintable(entry), SMESH::GetActiveStudyDocument() );
6837       if (aType == SMESH::MESH || aType == SMESH::GROUP ||
6838           aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
6839           aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
6840           aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
6841           aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
6842         if ( !name.isEmpty() ) {
6843           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
6844
6845           // update name of group object and its actor
6846           Handle(SALOME_InteractiveObject) IObject =
6847             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
6848
6849           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
6850           if( !aGroupObject->_is_nil() ) {
6851             aGroupObject->SetName( qPrintable(name) );
6852             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
6853               anActor->setName( qPrintable(name) );
6854           }
6855           return true;
6856         }
6857       }
6858     }
6859   }
6860   return false;
6861 }
6862
6863 SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
6864 {
6865   static QList<QColor> colors;
6866
6867   if ( colors.isEmpty() ) {
6868
6869     for (int s = 0; s < 2 ; s++)
6870     {
6871       for (int v = 100; v >= 40; v = v - 20)
6872       {
6873         for (int h = 0; h < 359 ; h = h + 60)
6874         {
6875           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
6876         }
6877       }
6878     }
6879   }
6880   static int currentColor = 0;
6881
6882   SALOMEDS::Color color;
6883   color.R = (double)colors[currentColor].red()   / 255.0;
6884   color.G = (double)colors[currentColor].green() / 255.0;
6885   color.B = (double)colors[currentColor].blue()  / 255.0;
6886
6887   currentColor = (currentColor+1) % colors.count();
6888
6889   return color;
6890 }