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