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