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