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