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