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