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