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