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