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