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