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