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