Salome HOME
d7b4ed7445256f2a77d7b3c27cf553e04ee9c7b8
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2021  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, or (at your option) any later version.
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
31 //  SMESH includes
32 #include "SMESHGUI.h"
33 #include "SMESHGUI_Add0DElemsOnAllNodesDlg.h"
34 #include "SMESHGUI_AddMeshElementDlg.h"
35 #include "SMESHGUI_AddQuadraticElementDlg.h"
36 #include "SMESHGUI_BuildCompoundDlg.h"
37 #include "SMESHGUI_ClippingDlg.h"
38 #include "SMESHGUI_ComputeDlg.h"
39 #include "SMESHGUI_ConvToQuadOp.h"
40 #include "SMESHGUI_CopyMeshDlg.h"
41 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
42 #include "SMESHGUI_DeleteGroupDlg.h"
43 #include "SMESHGUI_DisplayEntitiesDlg.h"
44 #include "SMESHGUI_Displayer.h"
45 #include "SMESHGUI_DuplicateNodesDlg.h"
46 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
47 #include "SMESHGUI_ExtrusionDlg.h"
48 #include "SMESHGUI_FaceGroupsSeparatedByEdgesDlg.h"
49 #include "SMESHGUI_FieldSelectorWdg.h"
50 #include "SMESHGUI_FileInfoDlg.h"
51 #include "SMESHGUI_FileValidator.h"
52 #include "SMESHGUI_FilterDlg.h"
53 #include "SMESHGUI_FilterLibraryDlg.h"
54 #include "SMESHGUI_FilterUtils.h"
55 #include "SMESHGUI_FindElemByPointDlg.h"
56 #include "SMESHGUI_GEOMGenUtils.h"
57 #include "SMESHGUI_GroupDlg.h"
58 #include "SMESHGUI_GroupOnShapeDlg.h"
59 #include "SMESHGUI_GroupOpDlg.h"
60 #include "SMESHGUI_GroupUtils.h"
61 #include "SMESHGUI_Hypotheses.h"
62 #include "SMESHGUI_HypothesesUtils.h"
63 #include "SMESHGUI_MG_ADAPTDRIVER.h"
64 #include "SMESHGUI_Make2DFrom3DOp.h"
65 #include "SMESHGUI_MakeNodeAtPointDlg.h"
66 #include "SMESHGUI_Measurements.h"
67 #include "SMESHGUI_MergeDlg.h"
68 #include "SMESHGUI_MeshInfo.h"
69 #include "SMESHGUI_MeshOp.h"
70 #include "SMESHGUI_MeshOrderOp.h"
71 #include "SMESHGUI_MeshPatternDlg.h"
72 #include "SMESHGUI_MeshUtils.h"
73 #include "SMESHGUI_MultiEditDlg.h"
74 #include "SMESHGUI_NodesDlg.h"
75 #include "SMESHGUI_OffsetDlg.h"
76 #include "SMESHGUI_Operations.h"
77 #include "SMESHGUI_PatternUtils.h"
78 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
79 #include "SMESHGUI_PropertiesDlg.h"
80 #include "SMESHGUI_RemoveElementsDlg.h"
81 #include "SMESHGUI_RemoveNodesDlg.h"
82 #include "SMESHGUI_RenumberingDlg.h"
83 #include "SMESHGUI_ReorientFacesDlg.h"
84 #include "SMESHGUI_RevolutionDlg.h"
85 #include "SMESHGUI_RotationDlg.h"
86 #include "SMESHGUI_ScaleDlg.h"
87 #include "SMESHGUI_Selection.h"
88 #include "SMESHGUI_SewingDlg.h"
89 #include "SMESHGUI_SingleEditDlg.h"
90 #include "SMESHGUI_SmoothingDlg.h"
91 #include "SMESHGUI_SpinBox.h"
92 #include "SMESHGUI_SplitBiQuad.h"
93 #include "SMESHGUI_SymmetryDlg.h"
94 #include "SMESHGUI_TranslationDlg.h"
95 #include "SMESHGUI_TransparencyDlg.h"
96 #include "SMESHGUI_Utils.h"
97 #include "SMESHGUI_VTKUtils.h"
98
99 #include "SMESH_version.h"
100
101 #include "SMESH_Actor.h"
102 #include "SMESH_ActorUtils.h"
103 #include "SMESH_Client.hxx"
104 #include "SMESH_Comment.hxx"
105 #include "SMESH_ControlsDef.hxx"
106 #include "SMESH_ScalarBarActor.h"
107 #include "SMESH_TypeFilter.hxx"
108 #include "SMESH_Component_Generator.hxx"
109
110 // SALOME GUI includes
111 #include <LightApp_DataOwner.h>
112 #include <LightApp_NameDlg.h>
113 #include <LightApp_Preferences.h>
114 #include <LightApp_SelectionMgr.h>
115 #include <LightApp_UpdateFlags.h>
116 #include <QtxFontEdit.h>
117 #include <QtxPopupMgr.h>
118 #include <QtxInfoPanel.h>
119 #include <SALOME_ListIO.hxx>
120 #include <SUIT_Desktop.h>
121 #include <SUIT_FileDlg.h>
122 #include <SUIT_MessageBox.h>
123 #include <SUIT_OverrideCursor.h>
124 #include <SUIT_ResourceMgr.h>
125 #include <SUIT_Session.h>
126 #include <SVTK_Renderer.h>
127 #include <SVTK_ViewManager.h>
128 #include <SVTK_ViewModel.h>
129 #include <SVTK_ViewWindow.h>
130 #include <SalomeApp_Application.h>
131 #include <SalomeApp_CheckFileDlg.h>
132 #include <SalomeApp_DataObject.h>
133 #include <SalomeApp_Study.h>
134 #include <SalomeApp_Tools.h>
135 #include <VTKViewer_Algorithm.h>
136
137 #ifndef DISABLE_PLOT2DVIEWER
138 #include <SPlot2d_ViewModel.h>
139 #include <SPlot2d_Histogram.h>
140 #endif
141
142 // IDL includes
143 #include <SALOMEconfig.h>
144 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
145 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
146 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
147 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
148
149 // Qt includes
150 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
151 #include <QApplication>
152 #include <QCheckBox>
153 #include <QDialogButtonBox>
154 #include <QLayout>
155 #include <QListView>
156 #include <QMenu>
157 #include <QTextStream>
158 #include <QTreeView>
159
160 // BOOST includes
161 #include <boost/shared_ptr.hpp>
162
163 // VTK includes
164 #include <vtkCallbackCommand.h>
165 #include <vtkCamera.h>
166 #include <vtkLookupTable.h>
167 #include <vtkPlane.h>
168 #include <vtkRenderer.h>
169
170 // SALOME KERNEL includes
171 #include <Basics_Utils.hxx>
172 #include <SALOMEDSClient_ClientFactory.hxx>
173 #include <SALOMEDSClient_IParameters.hxx>
174 #include <SALOMEDSClient_SComponent.hxx>
175 #include <SALOMEDSClient_StudyBuilder.hxx>
176 #include <SALOMEDS_SObject.hxx>
177 #include <SALOMEDS_Study.hxx>
178 #include <SALOME_GenericObj_wrap.hxx>
179 #include <SALOME_LifeCycleCORBA.hxx>
180 #include <utilities.h>
181
182 // OCCT includes
183 #include <Standard_ErrorHandler.hxx>
184 #include <NCollection_DataMap.hxx>
185 #include <NCollection_DoubleMap.hxx>
186
187 // Below macro, when uncommented, switches on simplified (more performant) algorithm
188 // of auto-color picking up
189 #define SIMPLE_AUTOCOLOR
190
191 namespace
192 {
193   // Declarations
194   //=============================================================
195   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
196                             int                  theCommandID);
197
198   void ExportMeshToFile(int theCommandID);
199
200   void SetDisplayMode(int theCommandID, VTK::MarkerMap& theMarkerMap);
201
202   void SetDisplayEntity(int theCommandID);
203
204   int  ActionToControl( int theID, bool theReversed = false );
205
206   void Control( int theCommandID );
207
208   // Definitions
209   //================================================================================
210   /*!
211    * \brief Reads meshes from file
212    */
213   //================================================================================
214
215   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
216                              int                  theCommandID )
217   {
218     QStringList filter;
219     std::string myExtension;
220
221     if ( theCommandID == SMESHOp::OpImportMED ||
222          theCommandID == SMESHOp::OpPopupImportMED ) {
223       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
224       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
225     }
226     else if ( theCommandID == SMESHOp::OpImportUNV ||
227               theCommandID == SMESHOp::OpPopupImportUNV ) {
228       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
229     }
230     else if ( theCommandID == SMESHOp::OpImportDAT ||
231               theCommandID == SMESHOp::OpPopupImportDAT ) {
232       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
233     }
234     else if ( theCommandID == SMESHOp::OpImportSTL ||
235               theCommandID == SMESHOp::OpPopupImportSTL ) {
236       filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
237     }
238     else if ( theCommandID == SMESHOp::OpImportCGNS ||
239               theCommandID == SMESHOp::OpPopupImportCGNS ) {
240       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
241     }
242     else if ( theCommandID == SMESHOp::OpImportGMF ||
243               theCommandID == SMESHOp::OpPopupImportGMF ) {
244       filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"  );
245       filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
246     }
247
248     QString anInitialPath = "";
249     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
250       anInitialPath = QDir::currentPath();
251
252     QStringList filenames;
253     bool toCreateGroups = true;
254
255     // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
256     //   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
257     //     ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
258     //   fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
259     //   fd->setNameFilters( filter );
260     //   fd->SetChecked( true );
261     //   if ( fd->exec() )
262     //     filenames << fd->selectedFile();
263     //   toCreateGroups = fd->IsChecked();
264
265     //   delete fd;
266     // }
267     // else
268     {
269       filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
270                                                   anInitialPath,
271                                                   filter,
272                                                   QObject::tr( "SMESH_IMPORT_MESH" ) );
273     }
274     if ( filenames.count() > 0 )
275     {
276       SUIT_OverrideCursor wc;
277       _PTR(Study) aStudy = SMESH::getStudy();
278
279       QStringList errors;
280       QStringList anEntryList;
281       bool isEmpty = false;
282       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it )
283       {
284         QString filename = *it;
285         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
286         try {
287           switch ( theCommandID ) {
288           case SMESHOp::OpImportDAT:
289           case SMESHOp::OpPopupImportDAT:
290             {
291               // DAT format (currently unsupported)
292               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
293                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
294               break;
295             }
296           case SMESHOp::OpImportUNV:
297           case SMESHOp::OpPopupImportUNV:
298             {
299               // UNV format
300               aMeshes->length( 1 );
301               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
302               if ( aMeshes[0]->_is_nil() )
303                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
304                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
305               break;
306             }
307           case SMESHOp::OpImportMED:
308           case SMESHOp::OpPopupImportMED:
309             {
310               // MED format
311               SMESH::DriverMED_ReadStatus res;
312               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
313               if ( res != SMESH::DRS_OK ) {
314                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
315                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
316               }
317               break;
318             }
319           case SMESHOp::OpImportSTL:
320           case SMESHOp::OpPopupImportSTL:
321             {
322               // STL format
323               aMeshes->length( 1 );
324               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
325               if ( aMeshes[0]->_is_nil() ) {
326                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
327                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
328               }
329               break;
330             }
331           case SMESHOp::OpImportCGNS:
332           case SMESHOp::OpPopupImportCGNS:
333             {
334               // CGNS format
335               SMESH::DriverMED_ReadStatus res;
336               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
337               if ( res != SMESH::DRS_OK ) {
338                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
339                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
340               }
341               break;
342             }
343           case SMESHOp::OpImportGMF:
344           case SMESHOp::OpPopupImportGMF:
345             {
346               // GMF format
347               SMESH::ComputeError_var res;
348               aMeshes->length( 1 );
349               aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
350                                                                   toCreateGroups,
351                                                                   res.out() );
352               if ( res->code != SMESH::DRS_OK ) {
353                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
354                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
355                 if ( strlen( res->comment.in() ) > 0 ) {
356                   errors.back() += ": ";
357                   errors.back() += res->comment.in();
358                 }
359               }
360               break;
361             }
362           }
363         }
364         catch ( const SALOME::SALOME_Exception& S_ex ) {
365           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
366                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
367         }
368
369         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
370         {
371           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
372           if ( aMeshSO ) {
373             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
374             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
375             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
376             if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
377               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
378
379             anEntryList.append( aMeshSO->GetID().c_str() );
380           }
381           else {
382             isEmpty = true;
383           }
384         }
385       }
386
387       // update Object browser
388       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
389
390       // browse to the published meshes
391       if( LightApp_Application* anApp =
392           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
393         anApp->browseObjects( anEntryList );
394
395       // show Error message box if there were errors
396       if ( errors.count() > 0 ) {
397         SUIT_MessageBox::critical( SMESHGUI::desktop(),
398                                    QObject::tr( "SMESH_ERROR" ),
399                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
400       }
401
402       // show warning message box, if some imported mesh is empty
403       if ( isEmpty ) {
404           SUIT_MessageBox::warning( SMESHGUI::desktop(),
405                                     QObject::tr( "SMESH_WRN_WARNING" ),
406                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
407       }
408     }
409   }
410
411   //================================================================================
412   /*!
413    * \brief Export selected meshes or groups into a file
414    */
415   //================================================================================
416
417   void ExportMeshToFile( int theCommandID )
418   {
419     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
420     SALOME_ListIO selected;
421     if( aSel )
422       aSel->selectedObjects( selected );
423
424     const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT ||
425                          theCommandID == SMESHOp::OpPopupExportDAT );
426     const bool isMED = ( theCommandID == SMESHOp::OpExportMED ||
427                          theCommandID == SMESHOp::OpPopupExportMED );
428     const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV ||
429                          theCommandID == SMESHOp::OpPopupExportUNV );
430     const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL ||
431                          theCommandID == SMESHOp::OpPopupExportSTL );
432     const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS ||
433                          theCommandID == SMESHOp::OpPopupExportCGNS );
434     const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF ||
435                          theCommandID == SMESHOp::OpPopupExportGMF );
436
437     const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
438     if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
439       return;
440     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
441     bool aCheckWarn = true;
442     if ( resMgr )
443       aCheckWarn = resMgr->booleanValue( "SMESH", "show_warning", false );
444
445     // get mesh object from selection and check duplication of their names
446     bool hasDuplicatedMeshNames = false;
447     QList< QPair< SMESH::SMESH_IDSource_var, QString > >           aMeshList;
448     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
449     SALOME_ListIteratorOfListIO It( selected );
450     for( ; It.More(); It.Next() )
451     {
452       Handle(SALOME_InteractiveObject) anIObject = It.Value();
453       SMESH::SMESH_IDSource_var aMeshItem =
454         SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
455       if ( aMeshItem->_is_nil() ) {
456         SUIT_MessageBox::warning( SMESHGUI::desktop(),
457                                   QObject::tr( "SMESH_WRN_WARNING" ),
458                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
459         return;
460       }
461       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( aMeshItem );
462       if ( aCheckWarn && !aGroup->_is_nil() )
463       {
464         QMessageBox msgBox(SUIT_MessageBox::Warning,
465                            QObject::tr("SMESH_WRN_WARNING"),
466                            QObject::tr("SMESH_EXPORT_ONLY_GPOUP"),
467                            QMessageBox::StandardButton::NoButton,
468                            SMESHGUI::desktop());
469         QCheckBox dontShowCheckBox(QObject::tr("SMESH_WRN_SHOW_DLG_CHECKBOX"));
470         msgBox.addButton(QMessageBox::Ok);
471         msgBox.addButton(QMessageBox::Cancel);
472         msgBox.setDefaultButton(QMessageBox::Cancel);
473         QGridLayout* lt = qobject_cast<QGridLayout*>(msgBox.layout());
474         QDialogButtonBox* btnbox = msgBox.findChild<QDialogButtonBox*>();
475         lt->addWidget(&dontShowCheckBox, lt->rowCount(), lt->columnCount()-1, lt->rowCount(), lt->columnCount());
476         lt->addWidget(btnbox, lt->rowCount(), 0, lt->rowCount(), lt->columnCount());
477         if ( msgBox.exec() != QMessageBox::Ok )
478           return;
479
480         if ( dontShowCheckBox.checkState() == Qt::Checked && resMgr )
481           resMgr->setValue( "SMESH", "show_warning", false);
482       }
483
484       QString aMeshName = anIObject->getName();
485
486       // check for name duplications
487       if ( !hasDuplicatedMeshNames )
488         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
489           if( aMeshName == (*aMeshIter).second ) {
490             hasDuplicatedMeshNames = true;
491             break;
492           }
493         }
494
495       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
496     }
497
498     if( hasDuplicatedMeshNames && isMED ) {
499       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
500                                           QObject::tr("SMESH_WRN_WARNING"),
501                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
502                                           QObject::tr("SMESH_BUT_YES"),
503                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
504       if (aRet != 0)
505         return;
506     }
507
508     aMeshIter = aMeshList.begin();
509     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
510     SMESH::SMESH_Mesh_var            aMesh = aMeshOrGroup->GetMesh();
511     QString                      aMeshName = (*aMeshIter).second;
512
513     if ( isMED || isCGNS ) // formats where group names must be unique
514     {
515       // check for equal group names within each mesh
516       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
517         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
518         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
519           int aRet = SUIT_MessageBox::warning
520             (SMESHGUI::desktop(),
521              QObject::tr("SMESH_WRN_WARNING"),
522              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
523              QObject::tr("SMESH_BUT_YES"),
524              QObject::tr("SMESH_BUT_NO"), 0, 1);
525           if (aRet != 0)
526             return;
527         }
528       }
529     }
530
531     // Warn the user about presence of not supported elements
532     QString format;
533     std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
534     if ( isDAT )
535     {
536       format = "DAT";
537       notSupportedElemTypes.push_back( SMESH::Entity_0D );
538       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
539     }
540     else if ( isUNV )
541     {
542       format = "UNV";
543       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
544       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
545       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
546       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
547       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
548       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
549       notSupportedElemTypes.push_back( SMESH::Entity_0D );
550       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
551     }
552     else if ( isSTL )
553     {
554       format = "STL";
555       notSupportedElemTypes.push_back( SMESH::Entity_Edge );
556       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
557       notSupportedElemTypes.push_back( SMESH::Entity_0D );
558       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
559     }
560     else if ( isCGNS )
561     {
562       format = "CGNS";
563       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
564     }
565     else if ( isGMF )
566     {
567       format = "GMF";
568       notSupportedElemTypes.push_back( SMESH::Entity_0D );
569       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
570       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
571       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
572       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
573       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Penta );
574       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
575       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
576       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
577       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
578     }
579     if ( ! notSupportedElemTypes.empty() )
580     {
581       SMESH::smIdType_array_var nbElems = aMeshOrGroup->GetMeshInfo();
582       for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
583         if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
584           presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
585     }
586     if ( !presentNotSupported.empty() )
587     {
588       QString typeNames;
589       const char* typeMsg[] = {
590         "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
591         "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
592         "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
593         "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
594         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
595         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
596         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
597         "SMESH_BIQUADRATIC_PENTAHEDRONS",
598         "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
599       };
600       // is typeMsg complete? (compilation failure mains that enum SMDSAbs_EntityType changed)
601       static_assert( sizeof(typeMsg) / sizeof(const char*) == SMESH::Entity_Last,
602                      "Update names of EntityType's!!!" );
603
604       QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
605       for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
606         typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
607         if ( iType != presentNotSupported.size() - 1 )
608           typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
609       }
610       int aRet = SUIT_MessageBox::warning
611         (SMESHGUI::desktop(),
612          QObject::tr("SMESH_WRN_WARNING"),
613          QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
614          QObject::tr("SMESH_BUT_YES"),
615          QObject::tr("SMESH_BUT_NO"), 0, 1);
616       if (aRet != 0)
617         return;
618     }
619
620     // Get parameters of export operation
621
622     QString aFilename;
623     int aFormat =-1;         // for MED version used for write
624     bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
625
626     // Init the parameters with the default values
627     bool aIsASCII_STL   = true;
628     bool toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
629     bool   toOverwrite  = true;
630     bool   toFindOutDim = true;
631     bool    saveNumbers = resMgr->booleanValue( "SMESH", "med_save_numbers", true );
632     bool     toRenumber = true;
633     double         zTol = resMgr->doubleValue( "SMESH", "med_ztolerance", 0. );
634
635     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
636     QString anInitialPath = "";
637     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
638       anInitialPath = QDir::currentPath();
639
640     QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
641
642     // Get a file name to write in and additional options
643     if ( isGMF ) // Export w/o options
644     {
645       aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER"  ) + " (*.mesh)" +
646         ";;" +  QObject::tr( "GMF_BINARY_FILES_FILTER" ) + " (*.meshb)";
647       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
648
649       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
650                                             anInitialPath + QString("/") + aMeshName,
651                                             aFilter, aTitle, false);
652     }
653     else if ( isCGNS || isUNV || isDAT ) // Export to [ CGNS | UNV | DAT ] - one option
654     {
655       const char* theOptionResource = isCGNS ? "cgns_group_elems_by_type" : "export_renumber";
656       bool option = resMgr->booleanValue( "SMESH", theOptionResource, false );
657
658       QStringList checkBoxes;
659       checkBoxes << QObject::tr( isCGNS ? "CGNS_EXPORT_ELEMS_BY_TYPE" : "SMESH_RENUMBER" );
660
661       SalomeApp_CheckFileDlg* fd =
662         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
663       fd->setWindowTitle( aTitle );
664       if ( isCGNS )
665         fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
666       else if ( isUNV )
667         fd->setNameFilter( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
668       else if ( isDAT )
669         fd->setNameFilter( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
670       if ( !anInitialPath.isEmpty() )
671         fd->setDirectory( anInitialPath );
672       fd->selectFile( aMeshName );
673       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
674       fd->setValidator( fv );
675       fd->SetChecked( option, 0 );
676
677       if ( fd->exec() )
678         aFilename = fd->selectedFile();
679       toOverwrite    = fv->isOverwrite( aFilename );
680       option = fd->IsChecked( 0 );
681       SMESHGUI::resourceMgr()->setValue("SMESH", theOptionResource, option );
682       ( isCGNS ? toCreateGroups : toRenumber ) = option;
683
684       delete fd;
685     }
686     else if ( isSTL ) // Export to STL
687     {
688       QMap<QString, int> aFilterMap;
689       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
690       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
691
692       QStringList filters;
693       QMap<QString, int>::const_iterator it = aFilterMap.begin();
694       for ( ; it != aFilterMap.end(); ++it )
695         filters.push_back( it.key() );
696
697       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
698       fd->setWindowTitle( aTitle );
699       fd->setNameFilters( filters );
700       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
701       if ( !anInitialPath.isEmpty() )
702         fd->setDirectory( anInitialPath );
703       fd->selectFile(aMeshName);
704       bool is_ok = false;
705       while (!is_ok) {
706         if ( fd->exec() )
707           aFilename = fd->selectedFile();
708         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
709         is_ok = true;
710       }
711       delete fd;
712     }
713     else if ( isMED ) // Export to MED
714     {
715       int defaultVersion = 0;
716       QMap<QString, int> aFilterMap;
717       //filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
718       //QString vmed (aMesh->GetVersionString(-1, 2));
719       SMESH::long_array_var mvok = aMesh->GetMEDVersionsCompatibleForAppend();
720       if ( mvok->length() > 0)
721         defaultVersion = mvok[0]; // the current version to set the default filter on it
722       for ( CORBA::ULong i = 0; i < mvok->length(); ++i )
723       {
724         QString vs = (char*)( SMESH_Comment( mvok[i]/10 ) << "." << mvok[i]%10 );
725         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)",  mvok[i]);
726       }
727       QStringList filters;
728       QMap<QString, int>::const_iterator it = aFilterMap.begin();
729       QString aDefaultFilter = it.key();
730       for ( ; it != aFilterMap.end(); ++it ) {
731         filters.push_back( it.key() );
732         if (it.value() == defaultVersion) // explicit default for MED = current MED version
733           aDefaultFilter = it.key();
734       }
735       QStringList checkBoxes;
736       checkBoxes << QObject::tr("SMESH_AUTO_GROUPS")
737                  << QObject::tr("SMESH_AUTO_DIM")
738                  << QObject::tr("SMESH_MED_SAVE_NUMS");
739
740       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
741       QList< QWidget* > wdgList;
742       if ( fieldSelWdg->GetAllFields( aMeshList, aFieldList ))
743         wdgList.append( fieldSelWdg );
744
745       QWidget*           zTolWdg = new QWidget();
746       QCheckBox*       zTolCheck = new QCheckBox( QObject::tr( "SMESH_ZTOLERANCE" ), zTolWdg );
747       SMESHGUI_SpinBox* zTolSpin = new SMESHGUI_SpinBox( zTolWdg );
748       QHBoxLayout*    zTolLayout = new QHBoxLayout( zTolWdg );
749       zTolLayout->addWidget( zTolCheck );
750       zTolLayout->addWidget( zTolSpin );
751       zTolLayout->setMargin( 0 );
752       zTolSpin->RangeStepAndValidator( 0, 1e+100, 1., "length_precision" );
753       zTolSpin->setValue( zTol );
754       QObject::connect( zTolCheck, SIGNAL( toggled(bool)), zTolSpin, SLOT( setEnabled(bool)));
755       zTolCheck->setChecked( resMgr->booleanValue( "SMESH", "enable_ztolerance", false ));
756       zTolSpin ->setEnabled( zTolCheck->isChecked() );
757       wdgList.append( zTolWdg );
758
759       SalomeApp_CheckFileDlg* fd =
760         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
761       fd->setWindowTitle( aTitle );
762       fd->setNameFilters( filters );
763       fd->selectNameFilter( aDefaultFilter );
764       fd->SetChecked( toCreateGroups, 0 );
765       fd->SetChecked( toFindOutDim,   1 );
766       fd->SetChecked( saveNumbers,    2 );
767       if ( !anInitialPath.isEmpty() )
768         fd->setDirectory( anInitialPath );
769       fd->selectFile(aMeshName);
770
771
772       QListView *lview = fd->findChild<QListView*>("listView");
773       if( lview ) {
774         lview->setMinimumHeight(200);
775       }
776       QTreeView *tview = fd->findChild<QTreeView*>("treeView");
777       if( tview ) {
778         tview->setMinimumHeight(200);
779       }
780
781       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
782       fd->setValidator( fv );
783
784       bool is_ok = false;
785       while (!is_ok)
786       {
787         //MESSAGE("******* Loop on file dialog ***********");
788         isOkToWrite =true;
789         if ( fd->exec() )
790           aFilename = fd->selectedFile();
791         else {
792           aFilename = QString::null;
793           break;
794         }
795         aFormat = aFilterMap[fd->selectedNameFilter()];
796         //MESSAGE("selected version: " << aFormat << " file: " << aFilename.toUtf8().constData());
797         toOverwrite = fv->isOverwrite(aFilename);
798         //MESSAGE("toOverwrite:" << toOverwrite);
799         is_ok = true;
800         if ( !aFilename.isEmpty() ) {
801           if( !toOverwrite ) {
802             // append is only possible if the existing file format is compatible
803             bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() );
804             MESSAGE("Append check, isVersionOk:" << isVersionOk);
805             if ( !isVersionOk ) {
806               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
807                                                   QObject::tr("SMESH_WRN_WARNING"),
808                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
809                                                   QObject::tr("SMESH_BUT_YES"),
810                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
811               if (aRet == 0)
812               {
813                 toOverwrite = true;
814                 //MESSAGE("incompatible MED file version for add, overwrite accepted");
815               }
816               else
817               {
818                 isOkToWrite = false;
819                 is_ok = false;
820                 //MESSAGE("incompatible MED file version for add, overwrite refused");
821               }
822             }
823             QStringList aMeshNamesCollisionList;
824             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
825             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
826               QString anExistingMeshName( aMeshNames[ i ] );
827               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
828                 QString anExportMeshName = (*aMeshIter).second;
829                 if( anExportMeshName == anExistingMeshName ) {
830                   aMeshNamesCollisionList.append( anExportMeshName );
831                   break;
832                 }
833               }
834             }
835             if( !aMeshNamesCollisionList.isEmpty() ) {
836               isOkToWrite = false;
837               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
838               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
839                                                   QObject::tr("SMESH_WRN_WARNING"),
840                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
841                                                   QObject::tr("SMESH_BUT_YES"),
842                                                   QObject::tr("SMESH_BUT_NO"),
843                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
844               MESSAGE("answer collision name " << aRet);
845               if (aRet == 0) {
846                 toOverwrite = true;
847                 isOkToWrite = true;
848               }
849               else if (aRet == 2)
850                 is_ok = false;
851             }
852           }
853         }
854       }
855       toCreateGroups = fd->IsChecked(0);
856       toFindOutDim   = fd->IsChecked(1);
857       saveNumbers    = fd->IsChecked(2);
858       zTol           = zTolCheck->isChecked() ? zTolSpin->value() : -1;
859       fieldSelWdg->GetSelectedFields();
860       if ( resMgr ) resMgr->setValue( "SMESH", "enable_ztolerance", zTolCheck->isChecked() );
861
862       if ( !fieldSelWdg->parent() )
863         delete fieldSelWdg;
864       if ( !zTolWdg->parent() )
865         delete zTolWdg;
866       delete fd;
867     }
868     else
869     {
870       return;
871     }
872
873     // Perform export
874
875     if ( !aFilename.isEmpty() ) {
876       // Check whether the file already exists and delete it if yes
877       QFile aFile( aFilename );
878       if ( aFile.exists() && toOverwrite )
879         aFile.remove();
880       SUIT_OverrideCursor wc;
881
882       try {
883         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
884         //         bool Renumber = false;
885         //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
886         //         if (resMgr)
887         //           Renumber= resMgr->booleanValue("renumbering");
888         //         if (Renumber){
889         //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
890 //           aMeshEditor->RenumberNodes();
891 //           aMeshEditor->RenumberElements();
892 //           if ( SMESHGUI::automaticUpdate() )
893 //             SMESH::UpdateView();
894 //         }
895         if ( isMED && isOkToWrite )
896         {
897           aMeshIter = aMeshList.begin();
898           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
899           {
900             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
901             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
902             const GEOM::ListOfFields&       fields = aFieldList[ aMeshIndex ].first.in();
903             const QString&            geoAssFields = aFieldList[ aMeshIndex ].second;
904
905             aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(),
906                                         toCreateGroups, aFormat,
907                                         toOverwrite && aMeshIndex == 0, toFindOutDim,
908                                         fields, geoAssFields.toLatin1().data(), zTol, saveNumbers );
909           }
910         }
911         else if ( isDAT )
912         {
913           if ( aMeshOrGroup->_is_equivalent( aMesh ))
914             aMesh->ExportDAT( aFilename.toUtf8().data(), toRenumber );
915           else
916             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data(), toRenumber );
917         }
918         else if ( isUNV )
919         {
920           if ( aMeshOrGroup->_is_equivalent( aMesh ))
921             aMesh->ExportUNV( aFilename.toUtf8().data(), toRenumber );
922           else
923             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data(), toRenumber );
924         }
925         else if ( isSTL )
926         {
927           if ( aMeshOrGroup->_is_equivalent( aMesh ))
928             aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
929           else
930             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
931         }
932         else if ( isCGNS )
933         {
934           aMeshIter = aMeshList.begin();
935           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
936           {
937             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
938             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
939             aMeshItem->ExportCGNS( aMeshOrGroup,
940                                    aFilename.toUtf8().data(),
941                                    toOverwrite && aMeshIndex == 0,
942                                    toCreateGroups );
943           }
944         }
945         else if ( isGMF )
946         {
947           toCreateGroups = true;
948           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
949         }
950       }
951       catch (const SALOME::SALOME_Exception& S_ex)
952       {
953         wc.suspend();
954         if ( S_ex.details.type == SALOME::COMM && // communicate about too large mesh
955              strncmp( "format=", S_ex.details.sourceFile.in(), 7 ) == 0 )
956
957           SUIT_MessageBox::critical(SMESHGUI::desktop(),
958                                     QObject::tr("SMESH_WRN_WARNING"),
959                                     QObject::tr(S_ex.details.text.in() ));
960         else
961           SUIT_MessageBox::warning(SMESHGUI::desktop(),
962                                    QObject::tr("SMESH_WRN_WARNING"),
963                                    QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
964         wc.resume();
965       }
966     }
967   }
968
969   inline void InverseEntityMode(unsigned int& theOutputMode,
970                                 unsigned int  theMode)
971   {
972     bool anIsNotPresent = ~theOutputMode & theMode;
973     if(anIsNotPresent)
974       theOutputMode |= theMode;
975     else
976       theOutputMode &= ~theMode;
977   }
978
979   void SetDisplayEntity(int theCommandID)
980   {
981     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
982     SALOME_ListIO selected;
983     if ( aSel )
984       aSel->selectedObjects( selected );
985
986     if ( selected.Extent() >= 1 ) {
987       SUIT_OverrideCursor wc;
988       SALOME_ListIteratorOfListIO It( selected );
989       for( ; It.More(); It.Next()){
990         Handle(SALOME_InteractiveObject) IObject = It.Value();
991         if(IObject->hasEntry()){
992           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
993             unsigned int aMode = anActor->GetEntityMode();
994             switch(theCommandID){
995             case SMESHOp::OpDE0DElements: InverseEntityMode(aMode,SMESH_Actor::e0DElements); break;
996             case SMESHOp::OpDEEdges:      InverseEntityMode(aMode,SMESH_Actor::eEdges); break;
997             case SMESHOp::OpDEFaces:      InverseEntityMode(aMode,SMESH_Actor::eFaces); break;
998             case SMESHOp::OpDEVolumes:    InverseEntityMode(aMode,SMESH_Actor::eVolumes); break;
999             case SMESHOp::OpDEBalls:      InverseEntityMode(aMode,SMESH_Actor::eBallElem); break;
1000             case SMESHOp::OpDEAllEntity:  aMode = SMESH_Actor::eAllEntity; break;
1001             }
1002             if(aMode)
1003               anActor->SetEntityMode(aMode);
1004           }
1005         }
1006       }
1007     }
1008   }
1009
1010   void AutoColor()
1011   {
1012     SalomeApp_Application* app =
1013       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1014     if ( !app )
1015       return;
1016
1017     LightApp_SelectionMgr* aSel = app->selectionMgr();
1018     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1019     if ( !aSel || !appStudy )
1020       return;
1021
1022     SALOME_ListIO selected;
1023     aSel->selectedObjects( selected );
1024     if ( selected.IsEmpty() )
1025       return;
1026
1027     Handle(SALOME_InteractiveObject) anIObject = selected.First();
1028
1029     _PTR(Study)         aStudy = appStudy->studyDS();
1030     _PTR(SObject) aMainSObject = aStudy->FindObjectID( anIObject->getEntry() );
1031     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1032     if ( aMainObject->_is_nil() )
1033       return;
1034
1035     SUIT_OverrideCursor wc;
1036
1037     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
1038
1039     QList<SALOMEDS::Color> aReservedColors;
1040
1041     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1042     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1043     {
1044       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1045
1046 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
1047       SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1048 #else                     // old algorithm  for auto-colors
1049       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1050       aReservedColors.append( aColor );
1051 #endif                    // SIMPLE_AUTOCOLOR
1052       aGroupObject->SetColor( aColor );
1053
1054       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1055       if ( aGroupSObject ) {
1056         QColor c;
1057         int delta;
1058         if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1059           switch ( aGroupObject->GetType ()) {
1060           case SMESH::NODE:
1061             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1062           case SMESH::EDGE:
1063             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1064           case SMESH::ELEM0D:
1065             anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1066           case SMESH::BALL:
1067             anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1068           case SMESH::VOLUME:
1069             SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1070             anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1071           case SMESH::FACE:
1072           default:
1073             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1074             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1075           }
1076         }
1077       }
1078     }
1079
1080     SMESH::RepaintCurrentView();
1081   }
1082
1083   void OverallMeshQuality()
1084   {
1085     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1086     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1087     SALOME_ListIO selected;
1088     if( aSel )
1089       aSel->selectedObjects( selected );
1090
1091     if ( selected.IsEmpty() ) return;
1092     SALOME_ListIteratorOfListIO It( selected );
1093     for ( ; It.More(); It.Next() ) {
1094       SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1095       ctrlDlg->showInfo( It.Value() );
1096       ctrlDlg->show();
1097     }
1098   }
1099
1100   QString functorToString( SMESH::Controls::FunctorPtr f )
1101   {
1102     QString type = QObject::tr( "UNKNOWN_CONTROL" );
1103     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1104       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1105     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1106       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1107     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1108       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1109     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1110       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1111     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1112       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1113     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1114       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1115     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1116       type = QObject::tr( "WARP_ELEMENTS" );
1117     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1118       type = QObject::tr( "TAPER_ELEMENTS" );
1119     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1120       type = QObject::tr( "SKEW_ELEMENTS" );
1121     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1122       type = QObject::tr( "AREA_ELEMENTS" );
1123     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1124       type = QObject::tr( "LENGTH_EDGES" );
1125     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1126       type = QObject::tr( "LENGTH2D_EDGES" );
1127     else if ( dynamic_cast< SMESH::Controls::Deflection2D* >( f.get() ) )
1128       type = QObject::tr( "DEFLECTION2D_FACES" );
1129     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1130       type = QObject::tr( "MULTI_BORDERS" );
1131     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1132       type = QObject::tr( "MULTI2D_BORDERS" );
1133     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1134       type = QObject::tr( "FREE_NODES" );
1135     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1136       type = QObject::tr( "FREE_EDGES" );
1137     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1138       type = QObject::tr( "FREE_BORDERS" );
1139     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1140       type = QObject::tr( "FREE_FACES" );
1141     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1142       type = QObject::tr( "BARE_BORDER_VOLUME" );
1143     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1144       type = QObject::tr( "BARE_BORDER_FACE" );
1145     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1146       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1147     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1148       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1149     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1150       type = QObject::tr( "EQUAL_NODE" );
1151     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1152       type = QObject::tr( "EQUAL_EDGE" );
1153     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1154       type = QObject::tr( "EQUAL_FACE" );
1155     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1156       type = QObject::tr( "EQUAL_VOLUME" );
1157     else if ( dynamic_cast< SMESH::Controls::NodeConnectivityNumber* >( f.get() ) )
1158       type = QObject::tr( "NODE_CONNECTIVITY_NB" );
1159     return type;
1160   }
1161
1162   void SaveDistribution()
1163   {
1164     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1165     SALOME_ListIO selected;
1166     if ( aSel )
1167       aSel->selectedObjects( selected );
1168
1169     if ( selected.Extent() == 1 ) {
1170       Handle(SALOME_InteractiveObject) anIO = selected.First();
1171       if ( anIO->hasEntry() ) {
1172         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1173         if ( anActor &&
1174              anActor->GetScalarBarActor() &&
1175              anActor->GetControlMode() != SMESH_Actor::eNone )
1176         {
1177           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1178           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1179           if ( aScalarBarActor && aFunctor ) {
1180             SMESH::Controls::NumericalFunctor* aNumFun =
1181               dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1182             if ( aNumFun ) {
1183               std::vector<smIdType> elements;
1184               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1185               if ( mesh->_is_nil() ) {
1186                 SMESH::SMESH_IDSource_var idSource =
1187                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1188                 if ( !idSource->_is_nil() )
1189                 {
1190                   SMESH::smIdType_array_var ids = idSource->GetIDs();
1191                   elements.resize( ids->length() );
1192                   for ( unsigned i = 0; i < elements.size(); ++i )
1193                     elements[i] = ids[i];
1194                 }
1195               }
1196               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1197               vtkLookupTable* lookupTable =
1198                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1199               double * minmax = lookupTable->GetRange();
1200               bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1201               std::vector<int>    nbEvents;
1202               std::vector<double> funValues;
1203               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues,
1204                                      elements, minmax, isLogarithmic );
1205               QString anInitialPath = "";
1206               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1207                 anInitialPath = QDir::currentPath();
1208               QString aMeshName = anIO->getName();
1209               QStringList filter;
1210               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1211               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1212               QString aFilename = anInitialPath + "/" + aMeshName + "_" +
1213                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1214               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1215                                                      aFilename,
1216                                                      filter,
1217                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1218                                                      false );
1219               if ( !aFilename.isEmpty() ) {
1220                 QFile f( aFilename );
1221                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1222                   QTextStream out( &f );
1223                   out << "# Mesh: " << aMeshName << endl;
1224                   out << "# Control: " << functorToString( aFunctor ) << endl;
1225                   out << "#" << endl;
1226                   out.setFieldWidth( 10 );
1227                   for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1228                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1229                   f.close();
1230                 }
1231               }
1232             }
1233           }
1234         }
1235       }
1236     }
1237   }
1238
1239   void ShowElement( int theCommandID )
1240   {
1241     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1242     SALOME_ListIO selected;
1243     if ( aSel )
1244       aSel->selectedObjects( selected );
1245
1246     if ( selected.Extent() == 1 ) {
1247       Handle(SALOME_InteractiveObject) anIO = selected.First();
1248       if ( anIO->hasEntry() ) {
1249         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1250         if ( anActor &&
1251              anActor->GetScalarBarActor() &&
1252              anActor->GetControlMode() != SMESH_Actor::eNone )
1253         {
1254           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1255           if ( theCommandID == SMESHOp::OpShowDistribution ) {
1256             aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1257           }
1258           else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1259             aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1260           }
1261         }
1262       }
1263     }
1264   }
1265
1266 #ifndef DISABLE_PLOT2DVIEWER
1267   void PlotDistribution()
1268   {
1269     SalomeApp_Application* app =
1270       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1271     if( !app )
1272       return;
1273
1274     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1275     SALOME_ListIO selected;
1276     if ( aSel )
1277       aSel->selectedObjects( selected );
1278
1279     if ( selected.Extent() == 1 ) {
1280       Handle(SALOME_InteractiveObject) anIO = selected.First();
1281       if ( anIO->hasEntry() ) {
1282         //Find Actor by entry before getting Plot2d viewer,
1283         //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1284         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1285
1286         SUIT_ViewManager* aViewManager =
1287           app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1288         if( !aViewManager )
1289           return;
1290
1291         SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1292         if ( !aView )
1293           return;
1294
1295         Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1296         if ( !aPlot )
1297           return;
1298
1299         if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone )
1300         {
1301           SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1302           QString functorName = functorToString( anActor->GetFunctor());
1303           QString aHistogramName("%1 : %2");
1304           aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1305           aHistogram->setName(aHistogramName);
1306           aHistogram->setHorTitle(functorName);
1307           aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1308           aPlot->displayObject(aHistogram, true);
1309         }
1310       }
1311     }
1312   }
1313 #endif //DISABLE_PLOT2DVIEWER
1314
1315   void DisableAutoColor()
1316   {
1317     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1318     SALOME_ListIO selected;
1319     if ( aSel )
1320       aSel->selectedObjects( selected );
1321
1322     if ( selected.Extent() ) {
1323       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1324       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1325       if ( !aMesh->_is_nil() ) {
1326         aMesh->SetAutoColor( false );
1327       }
1328     }
1329   }
1330
1331   void sortChildren()
1332   {
1333     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1334     SALOME_ListIO selected;
1335     if ( aSel ) {
1336       aSel->selectedObjects( selected );
1337       if ( selected.Extent() )
1338       {
1339         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1340         _PTR(Study) aStudy = SMESH::getStudy();
1341         _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1342         if (aSObj) {
1343           if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1344             SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1345           }
1346         }
1347       }
1348     }
1349   }
1350
1351   // Break link with Shaper model
1352   void breakShaperLink()
1353   {
1354     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1355     SALOME_ListIO selected;
1356     if (aSel) {
1357       aSel->selectedObjects(selected);
1358       if (selected.Extent()) {
1359         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1360         _PTR(Study) aStudy = SMESH::getStudy();
1361         std::string aEntry = anIObject->getEntry();
1362         _PTR(SObject) aSObj = aStudy->FindObjectID(aEntry);
1363         if (aSObj) {
1364           std::string aName = aSObj->GetName();
1365           QMessageBox::StandardButton aRes = SUIT_MessageBox::warning(SMESHGUI::desktop(),
1366             QObject::tr("SMESH_WRN_WARNING"),
1367             QObject::tr("MSG_BREAK_SHAPER_LINK").arg(aName.c_str()),
1368             SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No);
1369           if (aRes == SUIT_MessageBox::Yes) {
1370             SUIT_DataOwnerPtrList aList;
1371             aSel->selected(aList, "ObjectBrowser", true);
1372             SUIT_DataOwner* aOwn = aList.first();
1373             LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>(aOwn);
1374             QString aREntry = sowner->entry();
1375
1376             static GEOM::GEOM_Gen_var geomGen;
1377             if (CORBA::is_nil(geomGen)) {
1378               SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
1379                 (SUIT_Session::session()->activeApplication());
1380               if (app) {
1381                 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA(app->namingService());
1382                 Engines::EngineComponent_var comp =
1383                   ls->FindOrLoad_Component("FactoryServer", "SHAPERSTUDY");
1384                 geomGen = GEOM::GEOM_Gen::_narrow(comp);
1385               }
1386             }
1387             if (!CORBA::is_nil(geomGen))
1388             {
1389               geomGen->BreakLink(aREntry.toStdString().c_str());
1390               SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1391
1392               // remove actors whose objects are removed by BreakLink()
1393               QList<SUIT_ViewWindow*> wndList = SMESHGUI::desktop()->windows();
1394               SUIT_ViewWindow* wnd;
1395               foreach(wnd, wndList)
1396                 SMESH::UpdateActorsAfterUpdateStudy(wnd);
1397             }
1398           }
1399         }
1400       }
1401     }
1402   }
1403
1404   //================================================================================
1405   /*!
1406    * \brief Return true if a mesh icon == ICON_SMESH_TREE_GEOM_MODIF
1407    * which means that the mesh can't be modified. It should be either re-computed
1408    * or breakShaperLink()'ed. Warn the user about it.
1409    */
1410   //================================================================================
1411
1412   bool warnOnGeomModif()
1413   {
1414     SALOME_ListIO selected;
1415     if ( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
1416       aSel->selectedObjects(selected,"",/*convertReferences=*/false);
1417
1418     SALOME_ListIteratorOfListIO It( selected );
1419     for ( ; It.More(); It.Next() )
1420     {
1421       Handle(SALOME_InteractiveObject) io = It.Value();
1422       if ( !io->hasEntry() ) continue;
1423       _PTR(SObject) so = SMESH::getStudy()->FindObjectID( io->getEntry() );
1424       SMESH::SMESH_Mesh_var mesh;
1425       while ( mesh->_is_nil() && so && so->GetID() != "0:" )
1426       {
1427         CORBA::Object_var obj = SMESH::SObjectToObject( so );
1428         SMESH::SMESH_IDSource_var isrc = SMESH::SMESH_IDSource::_narrow( obj );
1429         if ( isrc->_is_nil() )
1430           so = so->GetFather();
1431         else
1432           mesh = isrc->GetMesh();
1433       }
1434       if ( mesh->_is_nil() ) continue;
1435       so = SMESH::FindSObject( mesh );
1436       if ( !so ) continue;
1437       _PTR(GenericAttribute) attr;
1438       so->FindAttribute( attr, "AttributePixMap" );
1439       _PTR(AttributePixMap) pixmap = attr;
1440       if ( !pixmap ) continue;
1441
1442       if ( pixmap->GetPixMap() == "ICON_SMESH_TREE_GEOM_MODIF" )
1443       {
1444         SUIT_MessageBox::warning(SMESHGUI::desktop(),
1445                                  QObject::tr("SMESH_WRN_WARNING"),
1446                                  QObject::tr("MSG_WARN_ON_GEOM_MODIF"));
1447         return true;
1448       }
1449     }
1450     return false;
1451   }
1452
1453   void SetDisplayMode(int theCommandID, VTK::MarkerMap& theMarkerMap)
1454   {
1455     SALOME_ListIO selected;
1456     SalomeApp_Application* app =
1457       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1458     if ( !app )
1459       return;
1460
1461     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1462     SalomeApp_Study*   appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1463     if ( !aSel || !appStudy )
1464       return;
1465
1466     if ( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1467       if ( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1468         aModule->EmitSignalDeactivateDialog();
1469         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1470           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1471       }
1472       return;
1473     }
1474
1475     aSel->selectedObjects( selected );
1476
1477     if ( selected.Extent() >= 1 )
1478     {
1479       switch ( theCommandID ) {
1480       case SMESHOp::OpTransparency:
1481       {
1482         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1483         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1484         return;
1485       }
1486       case SMESHOp::OpProperties:
1487       {
1488         double color[3];
1489         QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1490         QColor orientationColor, outlineColor, volumeColor;
1491         int deltaF = 0, deltaV = 0;
1492         int elem0dSize   = 1;
1493         //int ballSize     = 1;
1494         double ballScale = 1.0;
1495         int edgeWidth    = 1;
1496         int outlineWidth = 1;
1497         double shrinkCoef = 0.0;
1498         double orientationScale = 0.0;
1499         bool orientation3d = false;
1500         VTK::MarkerType markerType = VTK::MT_NONE;
1501         VTK::MarkerScale markerScale = VTK::MS_NONE;
1502         int markerId = 0;
1503         bool hasNodes = false;
1504         int presentEntities = 0;
1505         bool firstTime  = true;
1506
1507         SALOME_ListIteratorOfListIO It( selected );
1508         for ( ; It.More(); It.Next() ) {
1509           Handle(SALOME_InteractiveObject) IObject = It.Value();
1510           if ( !IObject->hasEntry() ) continue;
1511           SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1512           if ( !anActor || !anActor->GetObject() ) continue;
1513
1514           if ( firstTime ) {
1515             // nodes: color, marker
1516             anActor->GetNodeColor( color[0], color[1], color[2] );
1517             nodeColor.setRgbF( color[0], color[1], color[2] );
1518             markerType  = anActor->GetMarkerType();
1519             markerScale = anActor->GetMarkerScale();
1520             markerId    = anActor->GetMarkerTexture();
1521             // edges: color, width
1522             anActor->GetEdgeColor( color[0], color[1], color[2] );
1523             edgeColor.setRgbF( color[0], color[1], color[2] );
1524             edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1525             // faces: front color, back color (delta)
1526             anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1527             faceColor.setRgbF( color[0], color[1], color[2] );
1528             // faces: front color, back color (delta)
1529             anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1530             volumeColor.setRgbF( color[0], color[1], color[2] );
1531             // 0d elements: color, size
1532             anActor->Get0DColor( color[0], color[1], color[2] );
1533             elem0dColor.setRgbF( color[0], color[1], color[2] );
1534             elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1535             // balls: color, size
1536             anActor->GetBallColor( color[0], color[1], color[2] );
1537             ballColor.setRgbF( color[0], color[1], color[2] );
1538             //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1539             ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1540             // outlines: color
1541             anActor->GetOutlineColor( color[0], color[1], color[2] );
1542             outlineColor.setRgbF( color[0], color[1], color[2] );
1543             outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1544             // orientation vectors: color, scale, 3d flag
1545             anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1546             orientationColor.setRgbF( color[0], color[1], color[2] );
1547             orientationScale = anActor->GetFacesOrientationScale();
1548             orientation3d = anActor->GetFacesOrientation3DVectors();
1549             // shrink factor
1550             shrinkCoef = anActor->GetShrinkFactor();
1551           }
1552
1553           firstTime = false; // we only take properties from first object (for performance reasons)
1554
1555           if ( !hasNodes )
1556             hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1557           if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1558             presentEntities = presentEntities | SMESH_Actor::eEdges;
1559           if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1560             presentEntities = presentEntities | SMESH_Actor::eFaces;
1561           if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1562             presentEntities = presentEntities | SMESH_Actor::eVolumes;
1563           if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1564             presentEntities = presentEntities | SMESH_Actor::e0DElements;
1565           if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1566             presentEntities = presentEntities | SMESH_Actor::eBallElem;
1567
1568           // as we know that all types of elements are present, we can exit the loop
1569           if ( presentEntities == SMESH_Actor::eAllEntity )
1570             break;
1571         }
1572
1573         SMESHGUI_PropertiesDlg dlg( theMarkerMap, SMESHGUI::desktop() );
1574         // nodes: color, marker
1575         dlg.setNodeColor( nodeColor );
1576         if( markerType != VTK::MT_USER )
1577           dlg.setNodeMarker( markerType, markerScale );
1578         else
1579           dlg.setNodeCustomMarker( markerId );
1580         // edges: color, line width
1581         dlg.setEdgeColor( edgeColor );
1582         dlg.setEdgeWidth( edgeWidth );
1583         // faces: front color, back color
1584         dlg.setFaceColor( faceColor, deltaF );
1585         // volumes: normal color, reversed color
1586         dlg.setVolumeColor( volumeColor, deltaV );
1587         // outlines: color, line width
1588         dlg.setOutlineColor( outlineColor );
1589         dlg.setOutlineWidth( outlineWidth );
1590         // 0d elements: color, size
1591         dlg.setElem0dColor( elem0dColor );
1592         dlg.setElem0dSize( elem0dSize );
1593         // balls: color, size
1594         dlg.setBallColor( ballColor );
1595         //dlg.setBallSize( ballSize );
1596         dlg.setBallScale( ballScale );
1597         // orientation: color, scale, 3d flag
1598         dlg.setOrientationColor( orientationColor );
1599         dlg.setOrientationSize( int( orientationScale * 100. ) );
1600         dlg.setOrientation3d( orientation3d );
1601         // shrink: scale factor
1602         dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1603         // hide unused controls
1604         dlg.showControls( presentEntities, hasNodes );
1605
1606         if ( dlg.exec() ) {
1607           nodeColor        = dlg.nodeColor();
1608           markerType       = dlg.nodeMarkerType();
1609           markerScale      = dlg.nodeMarkerScale();
1610           markerId         = dlg.nodeMarkerId();
1611           edgeColor        = dlg.edgeColor();
1612           edgeWidth        = dlg.edgeWidth();
1613           faceColor        = dlg.faceColor();
1614           deltaF           = dlg.faceColorDelta();
1615           volumeColor      = dlg.volumeColor();
1616           deltaV           = dlg.volumeColorDelta();
1617           outlineColor     = dlg.outlineColor();
1618           outlineWidth     = dlg.outlineWidth();
1619           elem0dColor      = dlg.elem0dColor();
1620           elem0dSize       = dlg.elem0dSize();
1621           ballColor        = dlg.ballColor();
1622          // ballSize         = dlg.ballSize();
1623           ballScale        = dlg.ballScale();
1624           orientationColor = dlg.orientationColor();
1625           orientationScale = dlg.orientationSize() / 100.;
1626           orientation3d    = dlg.orientation3d();
1627           shrinkCoef       = dlg.shrinkCoef() / 100.;
1628
1629           // store point markers that might be changed by the user
1630           theMarkerMap = dlg.customMarkers();
1631
1632           // set properties from dialog box to the presentations
1633           SALOME_ListIteratorOfListIO It( selected );
1634           for ( ; It.More(); It.Next() ) {
1635             Handle(SALOME_InteractiveObject) IObject = It.Value();
1636             if ( !IObject->hasEntry() ) continue;
1637             SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1638             if ( !anActor ) continue;
1639
1640             // nodes: color, marker
1641             anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1642             if ( markerType != VTK::MT_USER ) {
1643               anActor->SetMarkerStd( markerType, markerScale );
1644             }
1645             else {
1646               VTK::MarkerMap::const_iterator iter = theMarkerMap.find( markerId );
1647               if ( iter != theMarkerMap.end() )
1648                 anActor->SetMarkerTexture( markerId, iter->second.second );
1649             }
1650             // volumes: normal color, reversed color (delta)
1651             anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1652             // faces: front color, back color (delta)
1653             anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1654             // edges: color, width
1655             anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1656             anActor->SetLineWidth( edgeWidth );
1657             // outlines: color
1658             anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1659             anActor->SetOutlineWidth( outlineWidth );
1660             // 0D elements: color, size
1661             anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1662             anActor->Set0DSize( elem0dSize );
1663             // balls: color, size
1664             anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1665             // anActor->SetBallSize( ballSize );
1666             anActor->SetBallScale( ballScale );
1667             // orientation: color, scale, 3d flag
1668             anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1669             anActor->SetFacesOrientationScale( orientationScale );
1670             anActor->SetFacesOrientation3DVectors( orientation3d );
1671             // shrink factor
1672             anActor->SetShrinkFactor( shrinkCoef );
1673
1674             // for groups, set also proper color
1675             SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1676             if ( !aGroupObject->_is_nil() ) {
1677               SMESH::ElementType anElementType = aGroupObject->GetType();
1678               QColor aColor;
1679               switch( anElementType ) {
1680               case SMESH::NODE:
1681                 aColor = nodeColor; break;
1682               case SMESH::EDGE:
1683                 aColor = edgeColor; break;
1684               case SMESH::FACE:
1685                 aColor = faceColor; break;
1686               case SMESH::VOLUME:
1687                 aColor = volumeColor; break;
1688               case SMESH::ELEM0D:
1689                 aColor = elem0dColor; break;
1690               case SMESH::BALL:
1691                 aColor = ballColor; break;
1692               default: break;
1693               }
1694
1695               if ( aColor.isValid() ) {
1696                 SALOMEDS::Color aGroupColor;
1697                 aGroupColor.R = aColor.redF();
1698                 aGroupColor.G = aColor.greenF();
1699                 aGroupColor.B = aColor.blueF();
1700                 aGroupObject->SetColor( aGroupColor );
1701               }
1702             } // if ( !aGroupObject->_is_nil() )
1703           } // for ( ; It.More(); It.Next() )
1704           SMESH::RepaintCurrentView();
1705         } // if ( dlg.exec() )
1706         return;
1707       } // case SMESHOp::OpProperties:
1708       } // switch(theCommandID)
1709       SUIT_OverrideCursor wc;
1710       SALOME_ListIteratorOfListIO It( selected );
1711       for( ; It.More(); It.Next()){
1712         Handle(SALOME_InteractiveObject) IObject = It.Value();
1713         if(IObject->hasEntry()){
1714           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1715             switch(theCommandID){
1716             case SMESHOp::OpDMWireframe:
1717               anActor->SetRepresentation(SMESH_Actor::eEdge);
1718               break;
1719             case SMESHOp::OpDMShading:
1720               anActor->SetRepresentation(SMESH_Actor::eSurface);
1721               break;
1722             case SMESHOp::OpDMShrink:
1723               if(anActor->IsShrunk())
1724                 anActor->UnShrink();
1725               else
1726                 anActor->SetShrink();
1727               break;
1728             case SMESHOp::OpDMNodes:
1729               anActor->SetRepresentation(SMESH_Actor::ePoint);
1730               break;
1731             case SMESHOp::OpRepresentationLines:
1732               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1733                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1734               break;
1735             case SMESHOp::OpRepresentationArcs:
1736               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1737                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1738               break;
1739             }
1740           }
1741         }
1742       }
1743       SMESH::RepaintCurrentView();
1744     }
1745   }
1746
1747   int ActionToControl( int theID, bool theReversed )
1748   {
1749     NCollection_DoubleMap<int,int> ActionControl;
1750     ActionControl.Bind( 0,                                SMESH_Actor::eNone );
1751     ActionControl.Bind( SMESHOp::OpFreeNode,              SMESH_Actor::eFreeNodes );
1752     ActionControl.Bind( SMESHOp::OpEqualNode,             SMESH_Actor::eCoincidentNodes );
1753     ActionControl.Bind( SMESHOp::OpNodeConnectivityNb,    SMESH_Actor::eNodeConnectivityNb );
1754     ActionControl.Bind( SMESHOp::OpFreeEdge,              SMESH_Actor::eFreeEdges );
1755     ActionControl.Bind( SMESHOp::OpFreeBorder,            SMESH_Actor::eFreeBorders );
1756     ActionControl.Bind( SMESHOp::OpLength,                SMESH_Actor::eLength );
1757     ActionControl.Bind( SMESHOp::OpConnection,            SMESH_Actor::eMultiConnection );
1758     ActionControl.Bind( SMESHOp::OpEqualEdge,             SMESH_Actor::eCoincidentElems1D );
1759     ActionControl.Bind( SMESHOp::OpFreeFace,              SMESH_Actor::eFreeFaces );
1760     ActionControl.Bind( SMESHOp::OpBareBorderFace,        SMESH_Actor::eBareBorderFace );
1761     ActionControl.Bind( SMESHOp::OpOverConstrainedFace,   SMESH_Actor::eOverConstrainedFace );
1762     ActionControl.Bind( SMESHOp::OpLength2D,              SMESH_Actor::eLength2D );
1763     ActionControl.Bind( SMESHOp::OpDeflection2D,          SMESH_Actor::eDeflection2D );
1764     ActionControl.Bind( SMESHOp::OpConnection2D,          SMESH_Actor::eMultiConnection2D );
1765     ActionControl.Bind( SMESHOp::OpArea,                  SMESH_Actor::eArea );
1766     ActionControl.Bind( SMESHOp::OpTaper,                 SMESH_Actor::eTaper );
1767     ActionControl.Bind( SMESHOp::OpAspectRatio,           SMESH_Actor::eAspectRatio );
1768     ActionControl.Bind( SMESHOp::OpMinimumAngle,          SMESH_Actor::eMinimumAngle );
1769     ActionControl.Bind( SMESHOp::OpWarpingAngle,          SMESH_Actor::eWarping );
1770     ActionControl.Bind( SMESHOp::OpSkew,                  SMESH_Actor::eSkew );
1771     ActionControl.Bind( SMESHOp::OpMaxElementLength2D,    SMESH_Actor::eMaxElementLength2D );
1772     ActionControl.Bind( SMESHOp::OpEqualFace,             SMESH_Actor::eCoincidentElems2D );
1773     ActionControl.Bind( SMESHOp::OpAspectRatio3D,         SMESH_Actor::eAspectRatio3D );
1774     ActionControl.Bind( SMESHOp::OpVolume,                SMESH_Actor::eVolume3D );
1775     ActionControl.Bind( SMESHOp::OpMaxElementLength3D,    SMESH_Actor::eMaxElementLength3D );
1776     ActionControl.Bind( SMESHOp::OpBareBorderVolume,      SMESH_Actor::eBareBorderVolume );
1777     ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1778     ActionControl.Bind( SMESHOp::OpEqualVolume,           SMESH_Actor::eCoincidentElems3D );
1779
1780     if ( theReversed )
1781       return ActionControl.IsBound2( theID ) ? ActionControl.Find2( theID ) : 0;
1782     return   ActionControl.IsBound1( theID ) ? ActionControl.Find1( theID ) : 0;
1783   }
1784
1785   void Control( int theCommandID )
1786   {
1787     SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ));
1788     _PTR(Study) aStudy = SMESH::getStudy();
1789
1790     SALOME_ListIO selected;
1791     if ( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
1792       aSel->selectedObjects( selected );
1793
1794     if ( !selected.IsEmpty() ) {
1795       SALOME_ListIteratorOfListIO It(selected);
1796       for ( ; It.More(); It.Next())
1797       {
1798         Handle(SALOME_InteractiveObject) anIO = It.Value();
1799         if ( !anIO.IsNull() ) {
1800           _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1801           if ( SO ) {
1802             CORBA::Object_var         aObject = SMESH::SObjectToObject( SO );
1803             SMESH::SMESH_IDSource_var anIDSrc = SMESH::SMESH_IDSource::_narrow( aObject );
1804             if ( !anIDSrc->_is_nil() ) {
1805               SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry());
1806               if (( !anActor && selected.Extent() == 1 ) &&
1807                   ( anActor = SMESH::CreateActor( anIO->getEntry() )))
1808               {
1809                 anActor->SetControlMode( aControl );
1810                 SMESH::DisplayActor( SMESH::GetCurrentVtkView(), anActor );
1811                 SMESH::UpdateView  ( SMESH::eDisplay, anIO->getEntry() );
1812               }
1813               if ( anActor )
1814               {
1815                 if ( anActor->GetControlMode() != aControl )
1816                   anActor->SetControlMode( aControl );
1817                 QString functorName = functorToString( anActor->GetFunctor() );
1818                 smIdType anEntitiesCount = anActor->GetNumberControlEntities();
1819                 if (anEntitiesCount >= 0)
1820                   functorName = functorName + ": " + QString::number(anEntitiesCount);
1821                 anActor->GetScalarBarActor()->SetTitle( functorName.toUtf8().constData() );
1822                 SMESH::RepaintCurrentView();
1823 #ifndef DISABLE_PLOT2DVIEWER
1824                 if ( anActor->GetPlot2Histogram() ) {
1825                   SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1826                   QString aHistogramName("%1 : %2");
1827                   aHistogramName = aHistogramName.arg( anIO->getName() ).arg( functorName );
1828                   aHistogram->setName( aHistogramName );
1829                   aHistogram->setHorTitle( functorName );
1830                   SMESH::ProcessIn2DViewers( anActor );
1831                 }
1832 #endif
1833               }
1834             }
1835           }
1836         }
1837       }
1838     }
1839   }
1840
1841
1842   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1843                    SMESH::MeshObjectType                    theType,
1844                    const QString                            theInTypeName,
1845                    QString &                                theOutTypeName)
1846   {
1847     SMESH_TypeFilter aTypeFilter( theType );
1848     QString entry;
1849     if ( !theIO.IsNull() )
1850     {
1851       entry = theIO->getEntry();
1852       LightApp_DataOwner owner( entry );
1853       if ( aTypeFilter.isOk( &owner )) {
1854         theOutTypeName = theInTypeName;
1855         return true;
1856       }
1857     }
1858     return false;
1859   }
1860
1861
1862   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1863   {
1864     _PTR(Study)  aStudy = SMESH::getStudy();
1865     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1866     if (aSObj) {
1867       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1868       CORBA::String_var  anID = aSComp->GetID().c_str();
1869       if ( !strcmp(anID.in(),theIO->getEntry()) )
1870         return "Component";
1871     }
1872
1873     QString aTypeName;
1874     if (
1875         CheckOIType ( theIO, SMESH::HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1876         CheckOIType ( theIO, SMESH::ALGORITHM,     "Algorithm",  aTypeName ) ||
1877         CheckOIType ( theIO, SMESH::MESH,          "Mesh",       aTypeName ) ||
1878         CheckOIType ( theIO, SMESH::SUBMESH,       "SubMesh",    aTypeName ) ||
1879         CheckOIType ( theIO, SMESH::GROUP,         "Group",      aTypeName )
1880         )
1881       return aTypeName;
1882
1883     return "NoType";
1884   }
1885
1886
1887   // QString CheckHomogeneousSelection()
1888   // {
1889   //   LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1890   //   SALOME_ListIO selected;
1891   //   if ( aSel )
1892   //     aSel->selectedObjects( selected );
1893
1894   //   QString RefType = CheckTypeObject(selected.First());
1895   //   SALOME_ListIteratorOfListIO It(selected);
1896   //   for ( ; It.More(); It.Next())
1897   //   {
1898   //     Handle(SALOME_InteractiveObject) IObject = It.Value();
1899   //     QString Type = CheckTypeObject(IObject);
1900   //     if ( Type.compare(RefType) != 0 )
1901   //       return "Heterogeneous Selection";
1902   //   }
1903
1904   //   return RefType;
1905   // }
1906
1907   uint randomize( uint size )
1908   {
1909     static bool initialized = false;
1910     if ( !initialized ) {
1911       qsrand( QDateTime::currentDateTime().toTime_t() );
1912       initialized = true;
1913     }
1914     uint v = qrand();
1915     v = uint( (double)( v ) / RAND_MAX * size );
1916     v = qMax( uint(0), qMin ( v, size-1 ) );
1917     return v;
1918   }
1919
1920 } //namespace
1921
1922 void SMESHGUI::OnEditDelete()
1923 {
1924   // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1925   LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1926   SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1927
1928   _PTR(Study) aStudy = SMESH::getStudy();
1929   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1930   _PTR(GenericAttribute) anAttr;
1931   _PTR(AttributeIOR) anIOR;
1932
1933   const int objectCountLimit = 30; // PAL23599
1934   int objectCount = 0;
1935   QString aNameList;
1936   QString aParentComponent = QString::null;
1937
1938   for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1939   {
1940     Handle(SALOME_InteractiveObject) anIO = anIt.Value();
1941     if ( anIO.IsNull() ) continue;
1942
1943     QString father = "unknown", name;
1944
1945     _PTR(SObject) aSO = aStudy->FindObjectID( anIO->getEntry() );
1946     if (aSO) {
1947       father = QString::fromStdString( aSO->GetFatherComponent()->ComponentDataType() );
1948       // check if object is reference
1949       _PTR(SObject) aRefSObj;
1950       if ( aSO->ReferencedObject( aRefSObj ) ) {
1951         name = QString::fromStdString ( aRefSObj->GetName() );
1952         father = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1953       }
1954       else
1955         name = anIO->getName();
1956       objectCount++;
1957     }
1958     if ( objectCount < objectCountLimit ) { // avoid occupying the whole screen
1959       aNameList.append("\n    - ");
1960       aNameList.append( name );
1961     }
1962
1963     if( aParentComponent.isNull() )
1964       aParentComponent = father;
1965     else if( !aParentComponent.isEmpty() && aParentComponent!=father )
1966       aParentComponent = "";
1967   }
1968   if ( objectCount >= objectCountLimit )
1969     aNameList.append("\n    - ...");
1970
1971   if ( objectCount == 0 )
1972     return; // No Valid Objects Selected
1973
1974   if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1975     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1976                               QObject::tr("ERR_ERROR"),
1977                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1978     return;
1979   }
1980   // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1981   if (SUIT_MessageBox::warning
1982       (SMESHGUI::desktop(),
1983        QObject::tr("SMESH_WRN_WARNING"),
1984        QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1985        SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1986        SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1987     return;
1988
1989   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1990
1991   // Put one level of sub-objects of the selected SO's into a list
1992   // in order to get objects inside folders like "Assigned Algorithms"
1993   std::list< _PTR(SObject) > listSO;
1994   SALOME_ListIteratorOfListIO It(selected);
1995   for( ; It.More(); It.Next()) // loop on selected IO's
1996   {
1997     Handle(SALOME_InteractiveObject) IObject = It.Value();
1998     if(IObject->hasEntry()) {
1999       _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
2000
2001       // disable removal of "SMESH" component object
2002       if(aSO->FindAttribute(anAttr, "AttributeIOR")){
2003         anIOR = anAttr;
2004         if ( engineIOR() == anIOR->Value().c_str() )
2005           continue;
2006       }
2007       //Check the referenced object
2008       _PTR(SObject) aRefSObject;
2009       if ( aSO && aSO->ReferencedObject( aRefSObject ) )
2010         aSO = aRefSObject; // Delete main Object instead of reference
2011
2012       listSO.push_back( aSO );
2013
2014       _PTR(ChildIterator) it = aStudy->NewChildIterator( aSO );
2015       for (it->InitEx(false); it->More(); it->Next())
2016         listSO.push_back( it->Value() );
2017     }
2018   }
2019   // Check if none of objects to delete is referred from outside
2020   std::list< _PTR(SObject) >::reverse_iterator ritSO;
2021   std::vector< _PTR(SObject) > subSO;
2022   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
2023   {
2024     _PTR(SObject) SO = *ritSO;
2025     if ( !SO ) continue;
2026
2027     int nbChildren = SO->GetLastChildTag();
2028     subSO.clear();
2029     subSO.reserve( 1 + nbChildren );
2030     subSO.push_back( SO );
2031     if ( nbChildren > 0 )
2032     {
2033       _PTR(ChildIterator) it = aStudy->NewChildIterator( SO );
2034       for ( it->InitEx( true ); it->More(); it->Next() )
2035         subSO.push_back( it->Value() );
2036     }
2037     for ( size_t i = 0; i < subSO.size(); ++i )
2038     {
2039       std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( subSO[i] );
2040       for ( size_t j = 0; j < aReferences.size(); j++ ) {
2041         _PTR(SComponent) aComponent = aReferences[j]->GetFatherComponent();
2042         std::string type = aComponent->ComponentDataType();
2043         if ( type != "SMESH" )
2044         {
2045           SUIT_MessageBox::warning( anApp->desktop(),
2046                                     QObject::tr("WRN_WARNING"),
2047                                     QObject::tr("DEP_OBJECT") );
2048           return; // outside SMESH, there is an object depending on a SMESH object
2049         }
2050       }
2051     }
2052   }
2053
2054   // Treat SO's in the list starting from the back
2055   aStudyBuilder->NewCommand();  // There is a transaction
2056   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
2057   {
2058     _PTR(SObject) SO = *ritSO;
2059     if ( !SO ) continue;
2060     std::string anEntry = SO->GetID();
2061
2062     /** Erase graphical object and remove all its data **/
2063     if ( SO->FindAttribute( anAttr, "AttributeIOR" )) {
2064       SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
2065     }
2066     /** Remove an object from data structures **/
2067     SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
2068     SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
2069     if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
2070       SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
2071       aMesh->RemoveGroup( aGroup );
2072     }
2073     else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
2074       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2075       aMesh->RemoveSubMesh( aSubMesh );
2076     }
2077     else {
2078       Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
2079         ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
2080       QString objType = CheckTypeObject(IObject);
2081       if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
2082         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2083         aStudyBuilder->RemoveObjectWithChildren( SO );
2084       }
2085       else {// default action: remove SObject from the study            
2086                 // Find Sub-Meshes and Group and delete corresopning visual objects and actors
2087                 _PTR(ChildIterator) it1 = aStudy->NewChildIterator(SO);
2088                 for (it1->InitEx(false); it1->More(); it1->Next()) {
2089                   _PTR(SObject) SObj = it1->Value();
2090                   if (!SObj) continue;
2091                   if (SObj->FindAttribute(anAttr, "AttributeIOR")) {
2092                         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(SMESH::SObjectToObject(SObj));
2093                         SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow(SMESH::SObjectToObject(SObj));
2094                         if (!aGroup->_is_nil() || !aSubMesh->_is_nil()) {
2095                           SMESH::RemoveVisualObjectWithActors(SObj->GetID().c_str(), true);
2096                         }
2097                   }
2098                 }
2099         // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
2100         //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
2101         //op->start();
2102         aStudyBuilder->RemoveObjectWithChildren( SO );
2103         //op->finish();
2104       }
2105     }
2106   } /* listSO back loop */
2107
2108   aStudyBuilder->CommitCommand();
2109
2110   /* Clear any previous selection */
2111   SALOME_ListIO l1;
2112   aSel->setSelectedObjects( l1 );
2113
2114   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
2115 }
2116
2117 extern "C" {
2118   SMESHGUI_EXPORT CAM_Module* createModule()
2119   {
2120     return new SMESHGUI();
2121   }
2122
2123   SMESHGUI_EXPORT  char* getModuleVersion() {
2124     return (char*)SMESH_VERSION_STR;
2125   }
2126 }
2127
2128 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
2129
2130 //=============================================================================
2131 /*!
2132  *
2133  */
2134 //=============================================================================
2135 SMESHGUI::SMESHGUI() : SalomeApp_Module( "SMESH" )
2136 {
2137   if ( CORBA::is_nil( myComponentSMESH ) )
2138   {
2139     CORBA::Boolean anIsEmbeddedMode;
2140     SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
2141     if( dynamic_cast<SALOME_NamingService *>(ns) )
2142       myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
2143     else
2144       {
2145         Engines::EngineComponent_var comp = RetrieveSMESHInstance();
2146         myComponentSMESH = SMESH::SMESH_Gen::_narrow(comp);
2147       }
2148     
2149     //MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
2150
2151     //  0019923: EDF 765 SMESH : default values of hypothesis
2152     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
2153     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
2154     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
2155     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
2156     myComponentSMESH->SetDefaultNbSegments( nbSeg );
2157
2158     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
2159     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
2160       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
2161       {
2162         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
2163         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
2164       }
2165   }
2166
2167   myActiveDialogBox = 0;
2168   myFilterLibraryDlg = 0;
2169   myState = -1;
2170   myDisplayer = 0;
2171
2172   myEventCallbackCommand = vtkCallbackCommand::New();
2173   myEventCallbackCommand->Delete();
2174   myEventCallbackCommand->SetClientData( this );
2175   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
2176   myPriority = 0.0;
2177
2178   /* load resources for all available meshers */
2179   SMESH::InitAvailableHypotheses();
2180 }
2181
2182 //=============================================================================
2183 /*!
2184  *
2185  */
2186 //=============================================================================
2187 SMESHGUI::~SMESHGUI()
2188 {
2189 }
2190
2191 //=============================================================================
2192 /*!
2193  *
2194  */
2195 //=============================================================================
2196 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
2197 {
2198   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2199   if( anApp )
2200     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2201   else
2202     return 0;
2203 }
2204
2205 //=============================================================================
2206 /*!
2207  *
2208  */
2209 //=============================================================================
2210 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2211 {
2212   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2213   if ( !resMgr )
2214     return false;
2215
2216   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
2217   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2218   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2219   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2220   return autoUpdate && !exceeded;
2221 }
2222
2223 //=============================================================================
2224 /*!
2225  *
2226  */
2227 //=============================================================================
2228 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2229                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2230 {
2231   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2232   if ( !resMgr )
2233     return false;
2234
2235   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update", false );
2236   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2237   bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2238
2239   SMESH::smIdType_array_var info = theMesh->GetMeshInfo();
2240   long nbOdElems = info[SMDSEntity_0D];
2241   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2242   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] +
2243                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] +
2244                    info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2245   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] +
2246                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] +
2247                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] +
2248                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + info[SMDSEntity_BiQuad_Penta] +
2249                    info[SMDSEntity_Polyhedra] +
2250                    info[SMDSEntity_Hexagonal_Prism];
2251   long nbBalls   = info[SMDSEntity_Ball];
2252
2253   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2254   *nbElements = requestedSize;
2255
2256   *entities = SMESH_Actor::eAllEntity;
2257   *hidden   = 0;
2258
2259   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2260
2261   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2262
2263   if ( incrementalLimit ) {
2264     long total     = 0;
2265
2266     if ( nbOdElems > 0 ) {
2267       if ( total + nbOdElems > updateLimit ) {
2268         *entities = *entities & ~SMESH_Actor::e0DElements;
2269         *hidden = *hidden | SMESH_Actor::e0DElements;
2270       }
2271       else
2272         exceeded = false;
2273     }
2274     total += nbOdElems;
2275
2276     if ( nbEdges > 0 ) {
2277       if ( total + nbEdges > updateLimit ) {
2278         *entities = *entities & ~SMESH_Actor::eEdges;
2279         *hidden = *hidden | SMESH_Actor::eEdges;
2280       }
2281       else
2282         exceeded = false;
2283     }
2284     total += nbEdges;
2285
2286     if ( nbFaces > 0 ) {
2287       if ( total + nbFaces > updateLimit ) {
2288         *entities = *entities & ~SMESH_Actor::eFaces;
2289         *hidden = *hidden | SMESH_Actor::eFaces;
2290       }
2291       else
2292         exceeded = false;
2293     }
2294     total += nbFaces;
2295
2296     if ( nbVolumes > 0 ) {
2297       if ( total + nbVolumes > updateLimit ) {
2298         *entities = *entities & ~SMESH_Actor::eVolumes;
2299         *hidden = *hidden | SMESH_Actor::eVolumes;
2300       }
2301       else
2302         exceeded = false;
2303     }
2304     total += nbVolumes;
2305
2306     if ( nbBalls > 0 ) {
2307       if ( total + nbBalls > updateLimit ) {
2308         *entities = *entities & ~SMESH_Actor::eBallElem;
2309         *hidden = *hidden | SMESH_Actor::eBallElem;
2310       }
2311       else
2312         exceeded = false;
2313     }
2314     total += nbBalls;
2315   }
2316
2317   return autoUpdate && !exceeded;
2318 }
2319
2320 //=============================================================================
2321 /*!
2322  *
2323  */
2324 //=============================================================================
2325 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2326 {
2327   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2328 }
2329
2330 //=============================================================================
2331 /*!
2332  *
2333  */
2334 //=============================================================================
2335 SMESHGUI* SMESHGUI::GetSMESHGUI()
2336 {
2337   SMESHGUI* smeshMod = 0;
2338   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2339   if ( app )
2340   {
2341     CAM_Module* module = app->module( "Mesh" );
2342     smeshMod = dynamic_cast<SMESHGUI*>( module );
2343   }
2344
2345   return smeshMod;
2346 }
2347
2348 extern "C"
2349 {
2350   Standard_EXPORT SMESHGUI* GetComponentGUI()
2351   {
2352     return SMESHGUI::GetSMESHGUI();
2353   }
2354 }
2355
2356 //=============================================================================
2357 /*!
2358  *
2359  */
2360 //=============================================================================
2361 void SMESHGUI::SetState(int aState)
2362 {
2363   myState = aState;
2364 }
2365
2366 //=============================================================================
2367 /*!
2368  *
2369  */
2370 //=============================================================================
2371 void SMESHGUI::ResetState()
2372 {
2373   myState = -1;
2374 }
2375
2376 //=============================================================================
2377 /*!
2378  *
2379  */
2380 //=============================================================================
2381 void SMESHGUI::EmitSignalDeactivateDialog()
2382 {
2383   emit SignalDeactivateActiveDialog();
2384 }
2385
2386 //=============================================================================
2387 /*!
2388  *
2389  */
2390 //=============================================================================
2391 void SMESHGUI::EmitSignalStudyFrameChanged()
2392 {
2393   emit SignalStudyFrameChanged();
2394 }
2395
2396 //=============================================================================
2397 /*!
2398  *
2399  */
2400 //=============================================================================
2401 void SMESHGUI::EmitSignalCloseAllDialogs()
2402 {
2403   emit SignalCloseAllDialogs();
2404 }
2405
2406 //=============================================================================
2407 /*!
2408  *
2409  */
2410 //=============================================================================
2411 void SMESHGUI::EmitSignalVisibilityChanged()
2412 {
2413   emit SignalVisibilityChanged();
2414 }
2415
2416 //=============================================================================
2417 /*!
2418  *
2419  */
2420 //=============================================================================
2421 void SMESHGUI::EmitSignalCloseView()
2422 {
2423   emit SignalCloseView();
2424 }
2425
2426 //=============================================================================
2427 /*!
2428  *
2429  */
2430 //=============================================================================
2431 void SMESHGUI::EmitSignalActivatedViewManager()
2432 {
2433   emit SignalActivatedViewManager();
2434 }
2435
2436 //=============================================================================
2437 /*!
2438  *
2439  */
2440 //=============================================================================
2441 QDialog *SMESHGUI::GetActiveDialogBox()
2442 {
2443   return myActiveDialogBox;
2444 }
2445
2446 //=============================================================================
2447 /*!
2448  *
2449  */
2450 //=============================================================================
2451 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2452 {
2453   myActiveDialogBox = (QDialog *) aDlg;
2454   return;
2455 }
2456
2457 //=============================================================================
2458 /*!
2459  *
2460  */
2461 //=============================================================================
2462 SUIT_Desktop* SMESHGUI::desktop()
2463 {
2464   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2465   if( app )
2466     return app->desktop();
2467   else
2468     return 0;
2469 }
2470
2471 //=============================================================================
2472 /*!
2473  *
2474  */
2475 //=============================================================================
2476 SalomeApp_Study* SMESHGUI::activeStudy()
2477 {
2478   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2479   if( app )
2480     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2481   else
2482     return NULL;
2483 }
2484
2485 //=============================================================================
2486 /*!
2487  *
2488  */
2489 //=============================================================================
2490 void SMESHGUI::Modified( bool theIsUpdateActions )
2491 {
2492   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2493     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2494       appStudy->Modified();
2495       if( theIsUpdateActions )
2496         app->updateActions();
2497     }
2498   }
2499 }
2500
2501 //=============================================================================
2502 /*!
2503  *
2504  */
2505 //=============================================================================
2506 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2507 {
2508   /* Here the position is on the bottom right corner - 10 */
2509   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2510   aDlg->adjustSize();
2511   SUIT_Desktop *PP = desktop();
2512   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2513   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2514   return true;
2515 }
2516
2517 /*!
2518  * \brief Verifies whether study of operation is locked
2519   * \param theMess - specifies whether message box must be shown if study is locked
2520   * \return State of study.
2521 *
2522 * Verifies whether study of operation is locked. If second parameter is TRUE and study
2523 * is locked when corresponding message box appears
2524 */
2525 bool SMESHGUI::isStudyLocked( bool theMessage )
2526 {
2527   if ( SMESH::getStudy()->GetProperties()->IsLocked() )
2528   {
2529     if ( theMessage )
2530       SUIT_MessageBox::warning( SMESHGUI::desktop(),
2531                                 QObject::tr( "WRN_WARNING" ),
2532                                 QObject::tr( "WRN_STUDY_LOCKED" ) );
2533     return true;
2534   }
2535   return false;
2536 }
2537
2538 //=============================================================================
2539 /*!
2540  *
2541  */
2542 //=============================================================================
2543 bool SMESHGUI::OnGUIEvent( int theCommandID )
2544 {
2545   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2546   if( !anApp )
2547     return false;
2548
2549   SUIT_ResourceMgr* mgr = resourceMgr();
2550   if( !mgr )
2551     return false;
2552
2553   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2554   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2555
2556   //QAction* act = action( theCommandID );
2557
2558   switch (theCommandID) {
2559   case SMESHOp::OpDelete:
2560     if(isStudyLocked()) break;
2561     OnEditDelete();
2562     break;
2563   case SMESHOp::OpImportDAT:
2564   case SMESHOp::OpImportUNV:
2565   case SMESHOp::OpImportMED:
2566   case SMESHOp::OpImportSTL:
2567   case SMESHOp::OpImportCGNS:
2568   case SMESHOp::OpImportGMF:
2569   case SMESHOp::OpPopupImportDAT:
2570   case SMESHOp::OpPopupImportUNV:
2571   case SMESHOp::OpPopupImportMED:
2572   case SMESHOp::OpPopupImportSTL:
2573   case SMESHOp::OpPopupImportCGNS:
2574   case SMESHOp::OpPopupImportGMF:
2575     {
2576       if(isStudyLocked()) break;
2577       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2578       break;
2579     }
2580
2581   case SMESHOp::OpFileInformation:
2582     {
2583       SALOME_ListIO selected;
2584       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2585       if( aSel )
2586         aSel->selectedObjects( selected );
2587       if( selected.Extent() )
2588       {
2589         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2590         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2591         if ( !aMesh->_is_nil() )
2592         {
2593           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2594           dlg.exec();
2595         }
2596       }
2597       break;
2598     }
2599   case SMESHOp::OpExportDAT:
2600   case SMESHOp::OpExportMED:
2601   case SMESHOp::OpExportUNV:
2602   case SMESHOp::OpExportSTL:
2603   case SMESHOp::OpExportCGNS:
2604   case SMESHOp::OpExportGMF:
2605   case SMESHOp::OpPopupExportDAT:
2606   case SMESHOp::OpPopupExportMED:
2607   case SMESHOp::OpPopupExportUNV:
2608   case SMESHOp::OpPopupExportSTL:
2609   case SMESHOp::OpPopupExportCGNS:
2610   case SMESHOp::OpPopupExportGMF:
2611     {
2612       ::ExportMeshToFile(theCommandID);
2613       break;
2614     }
2615
2616   case SMESHOp::OpReset:                      // SCALAR BAR
2617     {
2618       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2619       SALOME_ListIO selected;
2620       if( aSel )
2621         aSel->selectedObjects( selected );
2622
2623       SALOME_ListIteratorOfListIO it(selected);
2624       for( ; it.More(); it.Next()) {
2625         Handle(SALOME_InteractiveObject) anIO = it.Value();
2626         if( anIO->hasEntry() ) {
2627           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2628             anActor->SetControlMode( SMESH_Actor::eNone );
2629 #ifndef DISABLE_PLOT2DVIEWER
2630             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2631 #endif
2632             anActor->UpdateFilter();
2633           }
2634         }
2635       }
2636       SMESH::UpdateView();
2637       break;
2638     }
2639   case SMESHOp::OpScalarBarProperties:
2640     {
2641       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2642       break;
2643     }
2644   case SMESHOp::OpShowScalarBar:
2645     {
2646       // show/hide scalar bar
2647       ::ShowElement(theCommandID);
2648       break;
2649     }
2650   case SMESHOp::OpSaveDistribution:
2651     {
2652       // dump control distribution data to the text file
2653       ::SaveDistribution();
2654       break;
2655     }
2656
2657   case SMESHOp::OpShowDistribution:
2658     {
2659       // show/hide distribution
2660       ::ShowElement(theCommandID);
2661       break;
2662     }
2663
2664 #ifndef DISABLE_PLOT2DVIEWER
2665   case SMESHOp::OpPlotDistribution:
2666     {
2667       // plot distribution
2668       ::PlotDistribution();
2669       break;
2670     }
2671 #endif
2672
2673     // Auto-color
2674   case SMESHOp::OpAutoColor:
2675     ::AutoColor();
2676   break;
2677
2678   case SMESHOp::OpDisableAutoColor:
2679     ::DisableAutoColor();
2680   break;
2681
2682   case SMESHOp::OpClipping:
2683   case SMESHOp::OpTransparency:
2684   case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2685
2686     // Display Mode
2687   case SMESHOp::OpDMWireframe:
2688   case SMESHOp::OpDMShading:
2689   case SMESHOp::OpDMNodes:
2690   case SMESHOp::OpDMShrink:
2691     ::SetDisplayMode(theCommandID, myMarkerMap);
2692   break;
2693
2694   //2D quadratic representation
2695   case SMESHOp::OpRepresentationLines:
2696   case SMESHOp::OpRepresentationArcs:
2697     ::SetDisplayMode(theCommandID, myMarkerMap);
2698   break;
2699
2700   // Display Entity
2701   case SMESHOp::OpDE0DElements:
2702   case SMESHOp::OpDEEdges:
2703   case SMESHOp::OpDEFaces:
2704   case SMESHOp::OpDEVolumes:
2705   case SMESHOp::OpDEBalls:
2706   case SMESHOp::OpDEAllEntity:
2707     ::SetDisplayEntity(theCommandID);
2708   break;
2709
2710   // Choose entities to be displayed
2711   case SMESHOp::OpDEChoose:
2712     {
2713       ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2714       break;
2715     }
2716
2717   case SMESHOp::OpOrientationOnFaces:
2718     {
2719       SUIT_OverrideCursor wc;
2720       LightApp_SelectionMgr* mgr = selectionMgr();
2721       SALOME_ListIO selected; mgr->selectedObjects( selected );
2722
2723       SALOME_ListIteratorOfListIO it(selected);
2724       for( ; it.More(); it.Next()) {
2725         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2726         if(anIObject->hasEntry()) {
2727           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2728             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2729           }
2730         }
2731       }
2732       break;
2733     }
2734
2735   case SMESHOp::OpUpdate:
2736     {
2737       if(isStudyLocked()) break;
2738       SUIT_OverrideCursor wc;
2739       try {
2740         OCC_CATCH_SIGNALS;
2741         SMESH::UpdateView();
2742       }
2743       catch (std::bad_alloc&) { // PAL16774 (Crash after display of many groups)
2744         SMESH::OnVisuException();
2745       }
2746       catch (...) { // PAL16774 (Crash after display of many groups)
2747         SMESH::OnVisuException();
2748       }
2749
2750       SALOME_ListIO l;
2751       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2752       aSel->selectedObjects( l );
2753       aSel->setSelectedObjects( l );
2754       break;
2755     }
2756
2757   case SMESHOp::OpHide:
2758   case SMESHOp::OpShow:
2759   case SMESHOp::OpShowOnly:
2760     {
2761       SUIT_OverrideCursor wc;
2762       SMESH::EDisplaing anAction;
2763       switch (theCommandID) {
2764       case SMESHOp::OpHide:     anAction = SMESH::eErase; break;
2765       case SMESHOp::OpShow:     anAction = SMESH::eDisplay; break;
2766       case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2767       }
2768
2769       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2770       SALOME_ListIO sel_objects, to_process;
2771       if (aSel)
2772         aSel->selectedObjects( sel_objects );
2773
2774       if ( theCommandID==SMESHOp::OpShowOnly )
2775       {
2776         //MESSAGE("anAction = SMESH::eDisplayOnly");
2777         startOperation( myEraseAll );
2778       }
2779
2780       extractContainers( sel_objects, to_process );
2781
2782       try {
2783         OCC_CATCH_SIGNALS;
2784         if (vtkwnd) {
2785           SALOME_ListIteratorOfListIO It( to_process );
2786           for ( ; It.More(); It.Next())
2787           {
2788             Handle(SALOME_InteractiveObject) IOS = It.Value();
2789             if ( IOS->hasEntry() )
2790             {
2791               if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2792                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2793                 break; // PAL16774 (Crash after display of many groups)
2794               }
2795               if (anAction == SMESH::eDisplayOnly)
2796                 anAction = SMESH::eDisplay;
2797             }
2798           }
2799         }
2800
2801         // PAL13338 + PAL15161 -->
2802         if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !isStudyLocked()) {
2803           SMESH::UpdateView();
2804           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2805         }
2806         // PAL13338 + PAL15161 <--
2807       }
2808       catch (...) { // PAL16774 (Crash after display of many groups)
2809         SMESH::OnVisuException();
2810       }
2811
2812       if (anAction == SMESH::eErase) {
2813         SALOME_ListIO l1;
2814         aSel->setSelectedObjects( l1 );
2815       }
2816       else
2817         aSel->setSelectedObjects( to_process );
2818
2819       if ( vtkwnd && vtkwnd->GetRenderer() && !isStudyLocked() &&
2820            ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) )
2821         vtkwnd->GetRenderer()->AdjustActors();
2822
2823       break;
2824     }
2825
2826   case SMESHOp::OpNode:
2827     {
2828       if(isStudyLocked()) break;
2829
2830       if ( vtkwnd ) {
2831         EmitSignalDeactivateDialog();
2832
2833         ( new SMESHGUI_NodesDlg( this ) )->show();
2834       }
2835       else {
2836         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"),tr("SMESH_WRN_VIEWER_VTK"));
2837       }
2838       break;
2839     }
2840
2841   case SMESHOp::OpEditMeshOrSubMesh:
2842   case SMESHOp::OpEditMesh:
2843   case SMESHOp::OpEditSubMesh:
2844   case SMESHOp::OpMeshOrder:
2845   case SMESHOp::OpCreateSubMesh:
2846     if ( warnOnGeomModif() )
2847       break; // action forbidden as geometry modified
2848     // fall through
2849   case SMESHOp::OpCreateMesh:
2850   case SMESHOp::OpCompute:
2851   case SMESHOp::OpComputeSubMesh:
2852   case SMESHOp::OpPreCompute:
2853   case SMESHOp::OpEvaluate:
2854   case SMESHOp::OpShowErrors:
2855     startOperation( theCommandID );
2856     break;
2857   case SMESHOp::OpRecompute:
2858     {
2859       if ( isStudyLocked() )
2860         break;
2861       SALOME_ListIO selected;
2862       if ( LightApp_SelectionMgr *sel = selectionMgr() )
2863         sel->selectedObjects( selected );
2864       if ( selected.Extent() == 1 ) {
2865         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( selected.First() );
2866         if ( !aMesh->_is_nil() )
2867           aMesh->Clear();
2868         startOperation( SMESHOp::OpCompute );
2869       }
2870     }
2871     break;
2872   case SMESHOp::OpCopyMesh:
2873     {
2874       if (isStudyLocked()) break;
2875       EmitSignalDeactivateDialog();
2876       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2877     }
2878     break;
2879   case SMESHOp::OpBuildCompoundMesh:
2880     {
2881       if (isStudyLocked()) break;
2882       EmitSignalDeactivateDialog();
2883       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2884     }
2885     break;
2886
2887   case SMESHOp::OpDiagonalInversion:
2888   case SMESHOp::OpUnionOfTwoTriangle:
2889     {
2890       if ( !vtkwnd )
2891       {
2892         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2893         break;
2894       }
2895
2896       if ( isStudyLocked() )
2897         break;
2898       if ( warnOnGeomModif() )
2899         break; // action forbidden as geometry modified
2900
2901       /*Standard_Boolean aRes;
2902       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2903       if ( aMesh->_is_nil() )
2904       {
2905         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2906           tr( "SMESH_BAD_SELECTION" ) );
2907         break;
2908       }
2909       */
2910       EmitSignalDeactivateDialog();
2911       if ( theCommandID == SMESHOp::OpDiagonalInversion )
2912         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2913       else
2914         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2915       break;
2916     }
2917   case SMESHOp::OpOrientation:
2918   case SMESHOp::OpUnionOfTriangles:
2919   case SMESHOp::OpCuttingOfQuadrangles:
2920   case SMESHOp::OpSplitVolumes:
2921     {
2922       if ( !vtkwnd )
2923       {
2924         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2925         break;
2926       }
2927
2928       if ( isStudyLocked() )
2929         break;
2930       if ( warnOnGeomModif() )
2931         break; // action forbidden as geometry modified
2932
2933       EmitSignalDeactivateDialog();
2934       SMESHGUI_MultiEditDlg* aDlg = NULL;
2935       if ( theCommandID == SMESHOp::OpOrientation )
2936         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2937       else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2938         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2939       else if ( theCommandID == SMESHOp::OpSplitVolumes )
2940         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2941       else
2942         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2943
2944       aDlg->show();
2945       break;
2946     }
2947   case SMESHOp::OpSmoothing:
2948     {
2949       if(isStudyLocked()) break;
2950       if ( warnOnGeomModif() )
2951         break; // action forbidden as geometry modified
2952       if( vtkwnd ) {
2953         EmitSignalDeactivateDialog();
2954         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2955       }
2956       else {
2957         SUIT_MessageBox::warning(desktop(), tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2958       }
2959       break;
2960     }
2961   case SMESHOp::OpExtrusion:
2962     {
2963       if (isStudyLocked()) break;
2964       if ( warnOnGeomModif() )
2965         break; // action forbidden as geometry modified
2966       if (vtkwnd) {
2967         EmitSignalDeactivateDialog();
2968         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2969       } else {
2970         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2971       }
2972       break;
2973     }
2974   case SMESHOp::OpExtrusionAlongAPath:
2975     {
2976       if (isStudyLocked()) break;
2977       if ( warnOnGeomModif() )
2978         break; // action forbidden as geometry modified
2979       if (vtkwnd) {
2980         EmitSignalDeactivateDialog();
2981         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2982       } else {
2983         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2984       }
2985       break;
2986     }
2987   case SMESHOp::OpRevolution:
2988     {
2989       if(isStudyLocked()) break;
2990       if ( warnOnGeomModif() )
2991         break; // action forbidden as geometry modified
2992       if( vtkwnd ) {
2993         EmitSignalDeactivateDialog();
2994         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2995       }
2996       else {
2997         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2998       }
2999       break;
3000     }
3001   case SMESHOp::OpPatternMapping:
3002     {
3003       if ( isStudyLocked() )
3004         break;
3005       if ( warnOnGeomModif() )
3006         break; // action forbidden as geometry modified
3007       if ( vtkwnd )
3008       {
3009         EmitSignalDeactivateDialog();
3010         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
3011       }
3012       else {
3013         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3014       }
3015       break;
3016     }
3017   // Adaptation - begin
3018 #ifndef DISABLE_MG_ADAPT
3019   case SMESHOp::OpMGAdapt:
3020     {
3021       if ( isStudyLocked() )
3022         break;
3023       EmitSignalDeactivateDialog();
3024
3025       SALOME::GenericObj_wrap< SMESH::MG_ADAPT > model = GetSMESHGen()->CreateMG_ADAPT();
3026       bool isCreation = false;
3027       ( new SMESHGUI_MG_ADAPTDRIVER( this, model, isCreation ))->show();
3028       break;
3029     }
3030 #endif
3031   // Adaptation - end
3032   case SMESHOp::OpSplitBiQuadratic:
3033   case SMESHOp::OpConvertMeshToQuadratic:
3034   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
3035   case SMESHOp::OpReorientFaces:
3036   case SMESHOp::OpCreateGeometryGroup:
3037     {
3038       if ( warnOnGeomModif() )
3039         break; // action forbidden as geometry modified
3040       startOperation( theCommandID );
3041       break;
3042     }
3043   case SMESHOp::OpCreateGroup:
3044     {
3045       if ( !vtkwnd )
3046       {
3047         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3048         break;
3049       }
3050
3051       if(isStudyLocked()) break;
3052       if ( warnOnGeomModif() )
3053         break; // action forbidden as geometry modified
3054       EmitSignalDeactivateDialog();
3055       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
3056
3057       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3058       SALOME_ListIO selected;
3059       if( aSel )
3060         aSel->selectedObjects( selected );
3061
3062       int nbSel = selected.Extent();
3063       if (nbSel == 1) {
3064         // check if mesh is selected
3065         aMesh = SMESH::GetMeshByIO( selected.First() );
3066       }
3067       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
3068       aDlg->show();
3069       break;
3070     }
3071
3072   case SMESHOp::OpConstructGroup:
3073     {
3074       if ( !vtkwnd )
3075       {
3076         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3077         break;
3078       }
3079
3080       if(isStudyLocked()) break;
3081       if ( warnOnGeomModif() )
3082         break; // action forbidden as geometry modified
3083       EmitSignalDeactivateDialog();
3084
3085       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3086       SALOME_ListIO selected;
3087       if( aSel )
3088         aSel->selectedObjects( selected );
3089
3090       int nbSel = selected.Extent();
3091       if (nbSel == 1) {
3092         // check if submesh is selected
3093         Handle(SALOME_InteractiveObject) IObject = selected.First();
3094         if (IObject->hasEntry()) {
3095           _PTR(SObject) aSObj = SMESH::getStudy()->FindObjectID(IObject->getEntry());
3096           if( aSObj ) {
3097             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
3098             if (!aSubMesh->_is_nil()) {
3099               try {
3100                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
3101                 // get submesh elements list by types
3102                 SMESH::smIdType_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
3103                 SMESH::smIdType_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
3104                 SMESH::smIdType_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
3105                 SMESH::smIdType_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
3106                 // create group for each type o elements
3107                 QString aName = IObject->getName();
3108                 QStringList anEntryList;
3109                 if (aNodes->length() > 0) {
3110                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
3111                   aGroup->Add(aNodes.inout());
3112                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3113                     anEntryList.append( aSObject->GetID().c_str() );
3114                 }
3115                 if (aEdges->length() > 0) {
3116                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
3117                   aGroup->Add(aEdges.inout());
3118                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3119                     anEntryList.append( aSObject->GetID().c_str() );
3120                 }
3121                 if (aFaces->length() > 0) {
3122                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
3123                   aGroup->Add(aFaces.inout());
3124                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3125                     anEntryList.append( aSObject->GetID().c_str() );
3126                 }
3127                 if (aVolumes->length() > 0) {
3128                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
3129                   aGroup->Add(aVolumes.inout());
3130                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3131                     anEntryList.append( aSObject->GetID().c_str() );
3132                 }
3133                 updateObjBrowser();
3134                 anApp->browseObjects( anEntryList );
3135               }
3136               catch(const SALOME::SALOME_Exception & S_ex){
3137                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3138               }
3139             }
3140           }
3141         }
3142       }
3143       else if(nbSel==0) {
3144         SUIT_MessageBox::warning(desktop(),
3145                                  tr("SMESH_WRN_WARNING"),
3146                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
3147       }
3148       break;
3149     }
3150
3151   case SMESHOp::OpEditGroup:
3152     {
3153       if ( !vtkwnd )
3154       {
3155         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3156         break;
3157       }
3158
3159       if(isStudyLocked()) break;
3160       if ( warnOnGeomModif() )
3161         break; // action forbidden as geometry modified
3162       EmitSignalDeactivateDialog();
3163
3164       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3165       SALOME_ListIO selected;
3166       if( aSel )
3167         aSel->selectedObjects( selected );
3168
3169       SALOME_ListIteratorOfListIO It (selected);
3170       int nbSelectedGroups = 0;
3171       for ( ; It.More(); It.Next() )
3172       {
3173         SMESH::SMESH_GroupBase_var aGroup =
3174           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
3175         if (!aGroup->_is_nil()) {
3176           nbSelectedGroups++;
3177           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
3178           aDlg->show();
3179         }
3180       }
3181       if (nbSelectedGroups == 0)
3182         {
3183           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
3184           aDlg->show();
3185         }
3186       break;
3187     }
3188
3189   case SMESHOp::OpAddElemGroupPopup:     // Add elements to group
3190     {
3191       if(isStudyLocked()) break;
3192       if (myState == 800) {
3193         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3194         if (aDlg) aDlg->onAdd();
3195       }
3196       break;
3197     }
3198
3199   case SMESHOp::OpRemoveElemGroupPopup:  // Remove elements from group
3200     {
3201       if(isStudyLocked()) break;
3202       if (myState == 800) {
3203         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3204         if (aDlg) aDlg->onRemove();
3205       }
3206       break;
3207     }
3208
3209   case SMESHOp::OpEditGeomGroupAsGroup:
3210     {
3211       if ( !vtkwnd )
3212       {
3213         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3214         break;
3215       }
3216
3217       if(isStudyLocked()) break;
3218       EmitSignalDeactivateDialog();
3219
3220       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3221       SALOME_ListIO selected;
3222       if( aSel )
3223         aSel->selectedObjects( selected );
3224
3225       SALOME_ListIteratorOfListIO It (selected);
3226       for ( ; It.More(); It.Next() )
3227       {
3228         SMESH::SMESH_GroupOnGeom_var aGroup =
3229           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3230         if (!aGroup->_is_nil()) {
3231           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3232           aDlg->show();
3233         }
3234         else
3235         {
3236           SMESH::SMESH_GroupOnFilter_var aGroup =
3237             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3238           if (!aGroup->_is_nil()) {
3239             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3240             aDlg->show();
3241           }
3242         }
3243       }
3244       break;
3245     }
3246
3247     case SMESHOp::OpUnionGroups:
3248     case SMESHOp::OpIntersectGroups:
3249     case SMESHOp::OpCutGroups:
3250     {
3251       if ( !vtkwnd )
3252       {
3253         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3254         break;
3255       }
3256
3257       if ( isStudyLocked() )
3258         break;
3259       if ( warnOnGeomModif() )
3260         break; // action forbidden as geometry modified
3261
3262       EmitSignalDeactivateDialog();
3263
3264       SMESHGUI_GroupOpDlg* aDlg = 0;
3265       if ( theCommandID == SMESHOp::OpUnionGroups )
3266         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3267       else if ( theCommandID == SMESHOp::OpIntersectGroups )
3268         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3269       else
3270         aDlg = new SMESHGUI_CutGroupsDlg( this );
3271
3272       aDlg->show();
3273
3274       break;
3275     }
3276
3277     case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3278     {
3279       if ( isStudyLocked() )
3280         break;
3281       if ( warnOnGeomModif() )
3282         break; // action forbidden as geometry modified
3283
3284       EmitSignalDeactivateDialog();
3285       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3286       aDlg->show();
3287
3288       break;
3289     }
3290
3291     case SMESHOp::OpFaceGroupsByEdges: // Create face groups separated by sharp edges
3292     {
3293       if ( isStudyLocked() )
3294         break;
3295       if ( warnOnGeomModif() )
3296         break; // action forbidden as geometry modified
3297
3298       EmitSignalDeactivateDialog();
3299       SMESHGUI_FaceGroupsSeparatedByEdgesDlg* aDlg = new SMESHGUI_FaceGroupsSeparatedByEdgesDlg( this );
3300       aDlg->show();
3301
3302       break;
3303     }
3304
3305     case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3306     {
3307       if ( !vtkwnd )
3308       {
3309         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3310         break;
3311       }
3312
3313       if ( isStudyLocked() )
3314         break;
3315
3316       EmitSignalDeactivateDialog();
3317
3318       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3319       break;
3320     }
3321
3322   case SMESHOp::OpMeshInformation:
3323   case SMESHOp::OpWhatIs:
3324     {
3325       int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3326       EmitSignalDeactivateDialog();
3327       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3328       SALOME_ListIO selected;
3329       if( aSel )
3330         aSel->selectedObjects( selected );
3331
3332       if ( selected.Extent() > 1 ) { // a dlg for each IO
3333         SALOME_ListIteratorOfListIO It( selected );
3334         for ( ; It.More(); It.Next() ) {
3335           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3336           dlg->showInfo( It.Value() );
3337           dlg->show();
3338         }
3339       }
3340       else {
3341         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3342         dlg->show();
3343       }
3344       break;
3345     }
3346
3347   case SMESHOp::OpFindElementByPoint:
3348     {
3349       startOperation( theCommandID );
3350       break;
3351     }
3352
3353   case SMESHOp::OpEditHypothesis:
3354     {
3355       if(isStudyLocked()) break;
3356       if ( warnOnGeomModif() )
3357         break; // action forbidden as geometry modified
3358
3359       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3360       SALOME_ListIO selected;
3361       if( aSel )
3362         aSel->selectedObjects( selected );
3363
3364       int nbSel = selected.Extent();
3365
3366       if (nbSel == 1) {
3367         Handle(SALOME_InteractiveObject) anIObject = selected.First();
3368         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3369
3370         if ( !aHypothesis->_is_nil() )
3371         {
3372           SMESHGUI_GenericHypothesisCreator* aCreator =
3373             SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3374           if (aCreator)
3375           {
3376             // set geometry of mesh and sub-mesh to aCreator
3377             aSel->selectedObjects( selected, "",  /*convertReferences=*/false);
3378             if ( selected.Extent() == 1 )
3379             {
3380               QString subGeomID, meshGeomID;
3381               Handle(SALOME_InteractiveObject) hypIO = selected.First();
3382               if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3383               {
3384                 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3385                 aCreator->setShapeEntry( subGeomID );
3386                 aCreator->setMainShapeEntry( meshGeomID );
3387               }
3388             }
3389
3390             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3391           }
3392           else
3393           {
3394             // report error
3395           }
3396         }
3397       }
3398       break;
3399     }
3400   case SMESHOp::OpUnassign:                      // REMOVE HYPOTHESIS / ALGORITHMS
3401     {
3402       if(isStudyLocked()) break;
3403       if ( warnOnGeomModif() )
3404         break; // action forbidden as geometry modified
3405       SUIT_OverrideCursor wc;
3406
3407       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3408       SALOME_ListIO selected;
3409       if( aSel )
3410         aSel->selectedObjects( selected, QString::null, false );
3411
3412       SALOME_ListIteratorOfListIO It(selected);
3413       for (int i = 0; It.More(); It.Next(), i++) {
3414         Handle(SALOME_InteractiveObject) IObject = It.Value();
3415         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3416       }
3417       SALOME_ListIO l1;
3418       aSel->setSelectedObjects( l1 );
3419       updateObjBrowser();
3420       break;
3421     }
3422
3423   case SMESHOp::OpElem0D:
3424   case SMESHOp::OpBall:
3425   case SMESHOp::OpEdge:
3426   case SMESHOp::OpTriangle:
3427   case SMESHOp::OpQuadrangle:
3428   case SMESHOp::OpPolygon:
3429   case SMESHOp::OpTetrahedron:
3430   case SMESHOp::OpHexahedron:
3431   case SMESHOp::OpPentahedron:
3432   case SMESHOp::OpPyramid:
3433   case SMESHOp::OpHexagonalPrism:
3434     {
3435       if(isStudyLocked()) break;
3436       if ( warnOnGeomModif() )
3437         break; // action forbidden as geometry modified
3438       if ( vtkwnd ) {
3439         EmitSignalDeactivateDialog();
3440         SMDSAbs_EntityType type = SMDSEntity_Edge;
3441         switch (theCommandID) {
3442         case SMESHOp::OpElem0D: type = SMDSEntity_0D;                      break;
3443         case SMESHOp::OpBall: type = SMDSEntity_Ball;                      break;
3444         case SMESHOp::OpTriangle: type = SMDSEntity_Triangle;              break;
3445         case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle;          break;
3446         case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra;              break;
3447         case SMESHOp::OpPolygon: type = SMDSEntity_Polygon;                break;
3448         case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa;                break;
3449         case SMESHOp::OpPentahedron: type = SMDSEntity_Penta;              break;
3450         case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid;                break;
3451         case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3452         default:;
3453         }
3454         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3455       }
3456       else {
3457         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3458       }
3459       break;
3460     }
3461   case SMESHOp::OpPolyhedron:
3462     {
3463       if(isStudyLocked()) break;
3464       if ( warnOnGeomModif() )
3465         break; // action forbidden as geometry modified
3466       if ( vtkwnd ) {
3467         EmitSignalDeactivateDialog();
3468         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3469       }
3470       else {
3471         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3472       }
3473       break;
3474     }
3475   case SMESHOp::OpQuadraticEdge:
3476   case SMESHOp::OpQuadraticTriangle:
3477   case SMESHOp::OpBiQuadraticTriangle:
3478   case SMESHOp::OpQuadraticQuadrangle:
3479   case SMESHOp::OpBiQuadraticQuadrangle:
3480   case SMESHOp::OpQuadraticPolygon:
3481   case SMESHOp::OpQuadraticTetrahedron:
3482   case SMESHOp::OpQuadraticPyramid:
3483   case SMESHOp::OpQuadraticPentahedron:
3484   case SMESHOp::OpBiQuadraticPentahedron:
3485   case SMESHOp::OpQuadraticHexahedron:
3486   case SMESHOp::OpTriQuadraticHexahedron:
3487     {
3488       if(isStudyLocked()) break;
3489       if ( warnOnGeomModif() )
3490         break; // action forbidden as geometry modified
3491       if ( vtkwnd ) {
3492         EmitSignalDeactivateDialog();
3493         SMDSAbs_EntityType type = SMDSEntity_Last;
3494
3495         switch (theCommandID) {
3496         case SMESHOp::OpQuadraticEdge:          type = SMDSEntity_Quad_Edge; break;
3497         case SMESHOp::OpQuadraticTriangle:      type = SMDSEntity_Quad_Triangle; break;
3498         case SMESHOp::OpBiQuadraticTriangle:    type = SMDSEntity_BiQuad_Triangle; break;
3499         case SMESHOp::OpQuadraticQuadrangle:    type = SMDSEntity_Quad_Quadrangle; break;
3500         case SMESHOp::OpBiQuadraticQuadrangle:  type = SMDSEntity_BiQuad_Quadrangle; break;
3501         case SMESHOp::OpQuadraticPolygon:       type = SMDSEntity_Quad_Polygon; break;
3502         case SMESHOp::OpQuadraticTetrahedron:   type = SMDSEntity_Quad_Tetra; break;
3503         case SMESHOp::OpQuadraticPyramid:       type = SMDSEntity_Quad_Pyramid; break;
3504         case SMESHOp::OpQuadraticPentahedron:   type = SMDSEntity_Quad_Penta; break;
3505         case SMESHOp::OpBiQuadraticPentahedron: type = SMDSEntity_BiQuad_Penta; break;
3506         case SMESHOp::OpQuadraticHexahedron:    type = SMDSEntity_Quad_Hexa; break;
3507         case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3508         default: break;
3509         }
3510         if ( type != SMDSEntity_Last )
3511           ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3512       }
3513       else {
3514         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3515                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3516       }
3517       break;
3518     }
3519   case SMESHOp::OpRemoveNodes:
3520     {
3521       if(isStudyLocked()) break;
3522       if ( warnOnGeomModif() )
3523         break; // action forbidden as geometry modified
3524       if ( vtkwnd ) {
3525         EmitSignalDeactivateDialog();
3526         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3527       }
3528       else {
3529         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3530                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3531       }
3532       break;
3533     }
3534   case SMESHOp::OpRemoveElements:                                    // REMOVES ELEMENTS
3535     {
3536       if(isStudyLocked()) break;
3537       if ( warnOnGeomModif() )
3538         break; // action forbidden as geometry modified
3539       if( vtkwnd ) {
3540         EmitSignalDeactivateDialog();
3541         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3542       }
3543       else
3544         {
3545           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3546                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3547         }
3548       break;
3549     }
3550   case SMESHOp::OpClearMesh: {
3551
3552     if(isStudyLocked()) break;
3553     if ( warnOnGeomModif() )
3554       break; // action forbidden as geometry modified
3555
3556     SALOME_ListIO selected;
3557     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3558       aSel->selectedObjects( selected );
3559
3560     SUIT_OverrideCursor wc;
3561     SALOME_ListIteratorOfListIO It (selected);
3562     for ( ; It.More(); It.Next() )
3563     {
3564       Handle(SALOME_InteractiveObject) IOS = It.Value();
3565       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3566       if ( aMesh->_is_nil()) continue;
3567       try {
3568         aMesh->Clear();
3569         if ( aMesh->NbNodes() == 0 ) // imported mesh is not empty
3570           SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3571         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3572         // hide groups and submeshes
3573         _PTR(ChildIterator) anIter =
3574           SMESH::getStudy()->NewChildIterator( aMeshSObj );
3575         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3576         {
3577           _PTR(SObject) so = anIter->Value();
3578           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3579         }
3580       }
3581       catch (const SALOME::SALOME_Exception& S_ex){
3582         wc.suspend();
3583         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3584         wc.resume();
3585       }
3586     }
3587     SMESH::UpdateView();
3588     updateObjBrowser();
3589     break;
3590   }
3591   case SMESHOp::OpRemoveOrphanNodes:
3592     {
3593       if(isStudyLocked()) break;
3594       if ( warnOnGeomModif() )
3595         break; // action forbidden as geometry modified
3596       SALOME_ListIO selected;
3597       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3598         aSel->selectedObjects( selected );
3599       if ( selected.Extent() == 1 ) {
3600         Handle(SALOME_InteractiveObject) anIO = selected.First();
3601         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3602         if ( !aMesh->_is_nil() ) {
3603           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3604                                                     tr( "SMESH_WARNING" ),
3605                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3606                                                     SUIT_MessageBox::Yes |
3607                                                     SUIT_MessageBox::No,
3608                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3609           if( confirm ) {
3610             try {
3611               SUIT_OverrideCursor wc;
3612               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3613               smIdType removed = aMeshEditor->RemoveOrphanNodes();
3614               SUIT_MessageBox::information(SMESHGUI::desktop(),
3615                                            tr("SMESH_INFORMATION"),
3616                                            tr("NB_NODES_REMOVED").arg(removed));
3617               if ( removed > 0 ) {
3618                 SMESH::UpdateView();
3619                 SMESHGUI::Modified();
3620               }
3621             }
3622             catch (const SALOME::SALOME_Exception& S_ex) {
3623               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3624             }
3625             catch (...) {
3626             }
3627           }
3628         }
3629       }
3630       break;
3631     }
3632   case SMESHOp::OpRenumberingNodes:
3633     {
3634       if(isStudyLocked()) break;
3635       if ( warnOnGeomModif() )
3636         break; // action forbidden as geometry modified
3637       if( vtkwnd ) {
3638         EmitSignalDeactivateDialog();
3639         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3640       }
3641       else
3642         {
3643           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3644                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3645         }
3646       break;
3647     }
3648   case SMESHOp::OpRenumberingElements:
3649     {
3650       if(isStudyLocked()) break;
3651       if ( warnOnGeomModif() )
3652         break; // action forbidden as geometry modified
3653       if ( vtkwnd ) {
3654         EmitSignalDeactivateDialog();
3655         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3656       }
3657       else
3658         {
3659           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3660                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3661         }
3662       break;
3663     }
3664   case SMESHOp::OpTranslation:
3665     {
3666       if(isStudyLocked()) break;
3667       if ( warnOnGeomModif() )
3668         break; // action forbidden as geometry modified
3669       if ( vtkwnd ) {
3670         EmitSignalDeactivateDialog();
3671         ( new SMESHGUI_TranslationDlg( this ) )->show();
3672       }
3673       else {
3674         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3675                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3676       }
3677       break;
3678     }
3679   case SMESHOp::OpRotation:
3680     {
3681       if(isStudyLocked()) break;
3682       if ( warnOnGeomModif() )
3683         break; // action forbidden as geometry modified
3684       if( vtkwnd ) {
3685         EmitSignalDeactivateDialog();
3686         ( new SMESHGUI_RotationDlg( this ) )->show();
3687       }
3688       else {
3689         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3690                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3691       }
3692       break;
3693     }
3694   case SMESHOp::OpSymmetry:
3695     {
3696       if(isStudyLocked()) break;
3697       if ( warnOnGeomModif() )
3698         break; // action forbidden as geometry modified
3699       if(vtkwnd) {
3700         EmitSignalDeactivateDialog();
3701         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3702       }
3703       else {
3704         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3705                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3706       }
3707       break;
3708     }
3709   case SMESHOp::OpScale:
3710     {
3711       if(isStudyLocked()) break;
3712       if ( warnOnGeomModif() )
3713         break; // action forbidden as geometry modified
3714       if ( vtkwnd ) {
3715         EmitSignalDeactivateDialog();
3716         ( new SMESHGUI_ScaleDlg( this ) )->show();
3717       }
3718       else {
3719         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3720                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3721       }
3722       break;
3723     }
3724
3725   case SMESHOp::OpOffset:
3726     {
3727       if(isStudyLocked()) break;
3728       if ( warnOnGeomModif() )
3729         break; // action forbidden as geometry modified
3730       if ( vtkwnd ) {
3731         EmitSignalDeactivateDialog();
3732         ( new SMESHGUI_OffsetDlg( this ) )->show();
3733       }
3734       else {
3735         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3736                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3737       }
3738       break;
3739     }
3740
3741   case SMESHOp::OpSewing:
3742     {
3743       if(isStudyLocked()) break;
3744       if ( warnOnGeomModif() )
3745         break; // action forbidden as geometry modified
3746       if(vtkwnd) {
3747         EmitSignalDeactivateDialog();
3748         ( new SMESHGUI_SewingDlg( this ) )->show();
3749       }
3750       else {
3751         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3752                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3753       }
3754       break;
3755     }
3756   case SMESHOp::OpMergeNodes:
3757     {
3758       if(isStudyLocked()) break;
3759       if ( warnOnGeomModif() )
3760         break; // action forbidden as geometry modified
3761       if(vtkwnd) {
3762         EmitSignalDeactivateDialog();
3763         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3764       }
3765       else {
3766         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3767                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3768       }
3769       break;
3770     }
3771   case SMESHOp::OpMergeElements:
3772     {
3773       if (isStudyLocked()) break;
3774       if ( warnOnGeomModif() )
3775         break; // action forbidden as geometry modified
3776       if (vtkwnd) {
3777         EmitSignalDeactivateDialog();
3778         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3779       } else {
3780         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3781                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3782       }
3783       break;
3784     }
3785
3786   case SMESHOp::OpMoveNode: // MAKE MESH PASS THROUGH POINT
3787     if ( warnOnGeomModif() )
3788       break; // action forbidden as geometry modified
3789     startOperation( SMESHOp::OpMoveNode );
3790     break;
3791
3792   case SMESHOp::OpDuplicateNodes:
3793     {
3794       if(isStudyLocked()) break;
3795       if ( warnOnGeomModif() )
3796         break; // action forbidden as geometry modified
3797       if ( vtkwnd ) {
3798         EmitSignalDeactivateDialog();
3799         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3800       }
3801       else {
3802         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3803                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3804       }
3805       break;
3806     }
3807
3808   case SMESHOp::OpElem0DOnElemNodes: // 0D_ON_ALL_NODES
3809     if ( warnOnGeomModif() )
3810       break; // action forbidden as geometry modified
3811     startOperation( SMESHOp::OpElem0DOnElemNodes );
3812     break;
3813
3814   case SMESHOp::OpSelectFiltersLibrary: // Library of selection filters
3815   {
3816     static QList<int> aTypes;
3817     if ( aTypes.isEmpty() )
3818     {
3819       aTypes.append( SMESH::NODE );
3820       aTypes.append( SMESH::EDGE );
3821       aTypes.append( SMESH::FACE );
3822       aTypes.append( SMESH::VOLUME );
3823     }
3824     if (!myFilterLibraryDlg)
3825       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3826     else if (myFilterLibraryDlg->isHidden())
3827       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3828     myFilterLibraryDlg->raise();
3829   }
3830   break;
3831   // CONTROLS
3832   case SMESHOp::OpFreeNode:
3833   case SMESHOp::OpEqualNode:
3834   case SMESHOp::OpNodeConnectivityNb:
3835   case SMESHOp::OpFreeEdge:
3836   case SMESHOp::OpFreeBorder:
3837   case SMESHOp::OpLength:
3838   case SMESHOp::OpConnection:
3839   case SMESHOp::OpEqualEdge:
3840   case SMESHOp::OpFreeFace:
3841   case SMESHOp::OpBareBorderFace:
3842   case SMESHOp::OpOverConstrainedFace:
3843   case SMESHOp::OpLength2D:
3844   case SMESHOp::OpDeflection2D:
3845   case SMESHOp::OpConnection2D:
3846   case SMESHOp::OpArea:
3847   case SMESHOp::OpTaper:
3848   case SMESHOp::OpAspectRatio:
3849   case SMESHOp::OpMinimumAngle:
3850   case SMESHOp::OpWarpingAngle:
3851   case SMESHOp::OpSkew:
3852   case SMESHOp::OpMaxElementLength2D:
3853   case SMESHOp::OpEqualFace:
3854   case SMESHOp::OpAspectRatio3D:
3855   case SMESHOp::OpVolume:
3856   case SMESHOp::OpMaxElementLength3D:
3857   case SMESHOp::OpBareBorderVolume:
3858   case SMESHOp::OpOverConstrainedVolume:
3859   case SMESHOp::OpEqualVolume:
3860     if ( vtkwnd ) {
3861
3862       LightApp_SelectionMgr* mgr = selectionMgr();
3863       SALOME_ListIO selected; mgr->selectedObjects( selected );
3864
3865       if( !selected.IsEmpty() ) {
3866         SUIT_OverrideCursor wc;
3867         ::Control( theCommandID );
3868         break;
3869       }
3870       SUIT_MessageBox::warning(desktop(),
3871                                tr( "SMESH_WRN_WARNING" ),
3872                                tr( "SMESH_BAD_SELECTION" ) );
3873       break;
3874     }
3875     else {
3876       SUIT_MessageBox::warning(desktop(),
3877                                tr( "SMESH_WRN_WARNING" ),
3878                                tr( "NOT_A_VTK_VIEWER" ) );
3879     }
3880     break;
3881   case SMESHOp::OpOverallMeshQuality:
3882     OverallMeshQuality();
3883     break;
3884   case SMESHOp::OpNumberingNodes:
3885     {
3886       SUIT_OverrideCursor wc;
3887       LightApp_SelectionMgr* mgr = selectionMgr();
3888       SALOME_ListIO selected; mgr->selectedObjects( selected );
3889
3890       SALOME_ListIteratorOfListIO it(selected);
3891       for( ; it.More(); it.Next()) {
3892         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3893         if(anIObject->hasEntry()) {
3894           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3895             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3896           }
3897         }
3898       }
3899       break;
3900     }
3901   case SMESHOp::OpNumberingElements:
3902     {
3903       SUIT_OverrideCursor wc;
3904       LightApp_SelectionMgr* mgr = selectionMgr();
3905       SALOME_ListIO selected; mgr->selectedObjects( selected );
3906
3907       SALOME_ListIteratorOfListIO it(selected);
3908       for( ; it.More(); it.Next()) {
3909         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3910         if(anIObject->hasEntry())
3911           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3912             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3913           }
3914       }
3915       break;
3916     }
3917   case SMESHOp::OpPropertiesLength:
3918   case SMESHOp::OpPropertiesArea:
3919   case SMESHOp::OpPropertiesVolume:
3920   case SMESHOp::OpMinimumDistance:
3921   case SMESHOp::OpBoundingBox:
3922   case SMESHOp::OpAngle:
3923     {
3924       int page = SMESHGUI_MeasureDlg::MinDistance;
3925       if ( theCommandID == SMESHOp::OpBoundingBox )
3926         page = SMESHGUI_MeasureDlg::BoundingBox;
3927       else if ( theCommandID == SMESHOp::OpPropertiesLength )
3928         page = SMESHGUI_MeasureDlg::Length;
3929       else if ( theCommandID == SMESHOp::OpPropertiesArea )
3930         page = SMESHGUI_MeasureDlg::Area;
3931       else if ( theCommandID == SMESHOp::OpPropertiesVolume )
3932         page = SMESHGUI_MeasureDlg::Volume;
3933       else if ( theCommandID == SMESHOp::OpAngle )
3934         page = SMESHGUI_MeasureDlg::Angle;
3935
3936       EmitSignalDeactivateDialog();
3937       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3938       dlg->show();
3939       break;
3940     }
3941   case SMESHOp::OpSortChild:
3942     ::sortChildren();
3943     break;
3944   case SMESHOp::OpBreakLink:
3945     ::breakShaperLink();
3946     break;
3947
3948   }
3949
3950   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3951   //updateObjBrowser();
3952   return true;
3953 }
3954
3955 //=============================================================================
3956 /*!
3957  *
3958  */
3959 //=============================================================================
3960 bool SMESHGUI::OnMousePress( QMouseEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3961 {
3962   return false;
3963 }
3964
3965 //=============================================================================
3966 /*!
3967  *
3968  */
3969 //=============================================================================
3970 bool SMESHGUI::OnMouseMove( QMouseEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3971 {
3972   return true;
3973 }
3974
3975 //=============================================================================
3976 /*!
3977  *
3978  */
3979 //=============================================================================
3980 bool SMESHGUI::OnKeyPress( QKeyEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3981 {
3982   return true;
3983 }
3984
3985 //=============================================================================
3986 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3987  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3988  */
3989 //=============================================================================
3990 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3991                                   SUIT_ViewWindow* wnd )
3992 {
3993   if(theIO->hasEntry()){
3994     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3995     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3996   }
3997 }
3998
3999 //=======================================================================
4000 // function : createSMESHAction
4001 // purpose  :
4002 //=======================================================================
4003 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
4004                                   const int key, const bool toggle, const QString& shortcutAction  )
4005 {
4006   QIcon icon;
4007   QWidget* parent = application()->desktop();
4008   SUIT_ResourceMgr* resMgr = resourceMgr();
4009   QPixmap pix;
4010   if ( !icon_id.isEmpty() )
4011     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
4012   else
4013     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICON_%1" ).arg( po_id ).toLatin1().data() ), false );
4014   if ( !pix.isNull() )
4015     icon = QIcon( pix );
4016
4017   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
4018           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
4019           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
4020
4021   createAction( id, tooltip, icon, menu, status_bar, key, parent,
4022                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
4023 }
4024
4025 //=======================================================================
4026 // function : createPopupItem
4027 // purpose  :
4028 //=======================================================================
4029 void SMESHGUI::createPopupItem( const int id,
4030                                 const QString& clients,
4031                                 const QString& types,
4032                                 const QString& theRule,
4033                                 const int pId )
4034 {
4035   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
4036     popupMgr()->insert( action( id ), pId, 0 );
4037
4038   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4039   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4040   QString rule = "(%1) and (%2) and (%3)";
4041   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
4042   if( clients.isEmpty() )
4043     rule = rule.arg( QString( "true" ) );
4044   else
4045     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
4046   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
4047   rule += theRule;
4048
4049   bool cont = myRules.contains( id );
4050   if( cont )
4051     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
4052
4053   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
4054   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
4055 }
4056
4057 //=======================================================================
4058 // function : initialize
4059 // purpose  :
4060 //=======================================================================
4061 void SMESHGUI::initialize( CAM_Application* app )
4062 {
4063   SalomeApp_Module::initialize( app );
4064
4065 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
4066 //   if ( mgr )
4067   /* Automatic Update flag */
4068 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
4069
4070   // ----- create actions --------------
4071
4072   //createSMESHAction(  SMESHOp::OpImportDAT, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
4073   createSMESHAction( SMESHOp::OpImportUNV, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_I) );
4074   createSMESHAction( SMESHOp::OpImportMED, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
4075   createSMESHAction( SMESHOp::OpImportSTL, "IMPORT_STL"  );
4076 #ifdef WITH_CGNS
4077   createSMESHAction( SMESHOp::OpImportCGNS, "IMPORT_CGNS" );
4078 #endif
4079   createSMESHAction( SMESHOp::OpImportGMF,  "IMPORT_GMF"  );
4080   createSMESHAction( SMESHOp::OpPopupImportUNV, "IMPORT_UNV");
4081   createSMESHAction( SMESHOp::OpPopupImportMED, "IMPORT_MED");
4082   createSMESHAction( SMESHOp::OpPopupImportSTL, "IMPORT_STL"  );
4083 #ifdef WITH_CGNS
4084   createSMESHAction( SMESHOp::OpPopupImportCGNS, "IMPORT_CGNS" );
4085 #endif
4086   createSMESHAction( SMESHOp::OpPopupImportGMF,  "IMPORT_GMF"  );
4087
4088   createSMESHAction( SMESHOp::OpExportDAT,  "DAT" );
4089   createSMESHAction( SMESHOp::OpExportMED,  "MED" );
4090   createSMESHAction( SMESHOp::OpExportUNV,  "UNV" );
4091   createSMESHAction( SMESHOp::OpExportSTL,  "STL" );
4092 #ifdef WITH_CGNS
4093   createSMESHAction( SMESHOp::OpExportCGNS, "CGNS");
4094 #endif
4095   createSMESHAction( SMESHOp::OpExportGMF,      "GMF" );
4096   createSMESHAction( SMESHOp::OpPopupExportDAT, "DAT" );
4097   createSMESHAction( SMESHOp::OpPopupExportMED, "MED" );
4098   createSMESHAction( SMESHOp::OpPopupExportUNV, "UNV" );
4099   createSMESHAction( SMESHOp::OpPopupExportSTL, "STL" );
4100 #ifdef WITH_CGNS
4101   createSMESHAction( SMESHOp::OpPopupExportCGNS, "CGNS");
4102 #endif
4103   createSMESHAction( SMESHOp::OpPopupExportGMF,  "GMF" );
4104   createSMESHAction( SMESHOp::OpFileInformation, "FILE_INFO" );
4105   createSMESHAction( SMESHOp::OpDelete,          "DELETE", "ICON_DELETE", Qt::Key_Delete );
4106   createSMESHAction( SMESHOp::OpSelectFiltersLibrary, "SEL_FILTER_LIB" );
4107   createSMESHAction( SMESHOp::OpCreateMesh,           "CREATE_MESH",             "ICON_DLG_INIT_MESH" );
4108   createSMESHAction( SMESHOp::OpCreateSubMesh,        "CREATE_SUBMESH",          "ICON_DLG_ADD_SUBMESH" );
4109   createSMESHAction( SMESHOp::OpEditMeshOrSubMesh,    "EDIT_MESHSUBMESH",        "ICON_DLG_EDIT_MESH" );
4110   createSMESHAction( SMESHOp::OpEditMesh,             "EDIT_MESH",               "ICON_DLG_EDIT_MESH" );
4111   createSMESHAction( SMESHOp::OpEditSubMesh,          "EDIT_SUBMESH",            "ICON_DLG_EDIT_MESH" );
4112   createSMESHAction( SMESHOp::OpBuildCompoundMesh,    "BUILD_COMPOUND",          "ICON_BUILD_COMPOUND" );
4113   createSMESHAction( SMESHOp::OpCopyMesh,             "COPY_MESH",               "ICON_COPY_MESH" );
4114   createSMESHAction( SMESHOp::OpCompute,              "COMPUTE",                 "ICON_COMPUTE" );
4115   createSMESHAction( SMESHOp::OpComputeSubMesh,       "COMPUTE_SUBMESH",         "ICON_COMPUTE" );
4116   createSMESHAction( SMESHOp::OpRecompute,            "RE_COMPUTE",              "ICON_COMPUTE" );
4117   createSMESHAction( SMESHOp::OpPreCompute,           "PRECOMPUTE",              "ICON_PRECOMPUTE" );
4118   createSMESHAction( SMESHOp::OpShowErrors,           "SHOW_ERRORS",             "ICON_SHOW_ERRORS" );
4119   createSMESHAction( SMESHOp::OpEvaluate,             "EVALUATE",                "ICON_EVALUATE" );
4120   createSMESHAction( SMESHOp::OpMeshOrder,            "MESH_ORDER",              "ICON_MESH_ORDER");
4121   createSMESHAction( SMESHOp::OpCreateGroup,          "CREATE_GROUP",            "ICON_CREATE_GROUP" );
4122   createSMESHAction( SMESHOp::OpCreateGeometryGroup,  "CREATE_GEO_GROUP",        "ICON_CREATE_GEO_GROUP" );
4123   createSMESHAction( SMESHOp::OpConstructGroup,       "CONSTRUCT_GROUP",         "ICON_CONSTRUCT_GROUP" );
4124   createSMESHAction( SMESHOp::OpEditGroup,            "EDIT_GROUP",              "ICON_EDIT_GROUP" );
4125   createSMESHAction( SMESHOp::OpEditGeomGroupAsGroup, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
4126   createSMESHAction( SMESHOp::OpUnionGroups,          "UN_GROUP",                "ICON_UNION" );
4127   createSMESHAction( SMESHOp::OpIntersectGroups,      "INT_GROUP",               "ICON_INTERSECT" );
4128   createSMESHAction( SMESHOp::OpCutGroups,            "CUT_GROUP",               "ICON_CUT" );
4129   createSMESHAction( SMESHOp::OpGroupUnderlyingElem,  "UNDERLYING_ELEMS",        "ICON_UNDERLYING_ELEMS" );
4130   createSMESHAction( SMESHOp::OpFaceGroupsByEdges,    "FACE_GROUPS_BY_EDGES",    "ICON_FACE_GROUPS_BY_EDGES" );
4131   createSMESHAction( SMESHOp::OpAddElemGroupPopup,    "ADD_TO_GROUP" );
4132   createSMESHAction( SMESHOp::OpRemoveElemGroupPopup, "REMOVE_FROM_GROUP" );
4133   createSMESHAction( SMESHOp::OpDeleteGroup,          "DEL_GROUP",               "ICON_DEL_GROUP" );
4134   createSMESHAction( SMESHOp::OpMeshInformation ,     "ADV_INFO",                "ICON_ADV_INFO" );
4135   //createSMESHAction( SMESHOp::OpStdInfo, "STD_INFO",        "ICON_STD_INFO" );
4136   //createSMESHAction( SMESHOp::OpWhatIs, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4137   createSMESHAction( SMESHOp::OpFindElementByPoint,   "FIND_ELEM",               "ICON_FIND_ELEM" );
4138   //update
4139   createSMESHAction( SMESHOp::OpFreeNode,              "FREE_NODE",               "ICON_FREE_NODE",     0, true );
4140   createSMESHAction( SMESHOp::OpEqualNode,             "EQUAL_NODE",              "ICON_EQUAL_NODE",    0, true );
4141   createSMESHAction( SMESHOp::OpNodeConnectivityNb,    "NODE_CONNECTIVITY_NB",    "ICON_NODE_CONN_NB",    0, true );
4142   createSMESHAction( SMESHOp::OpFreeEdge,              "FREE_EDGE",               "ICON_FREE_EDGE",     0, true );
4143   createSMESHAction( SMESHOp::OpFreeBorder,            "FREE_BORDER",             "ICON_FREE_EDGE_2D",  0, true );
4144   createSMESHAction( SMESHOp::OpLength,                "LENGTH",                  "ICON_LENGTH",        0, true );
4145   createSMESHAction( SMESHOp::OpConnection,            "CONNECTION",              "ICON_CONNECTION",    0, true );
4146   createSMESHAction( SMESHOp::OpEqualEdge,             "EQUAL_EDGE",              "ICON_EQUAL_EDGE",    0, true );
4147   createSMESHAction( SMESHOp::OpFreeFace,              "FREE_FACES",              "ICON_FREE_FACES",    0, true );
4148   createSMESHAction( SMESHOp::OpBareBorderFace,        "BARE_BORDER_FACE",        "ICON_BARE_BORDER_FACE",        0, true );
4149   createSMESHAction( SMESHOp::OpOverConstrainedFace,   "OVER_CONSTRAINED_FACE",   "ICON_OVER_CONSTRAINED_FACE",   0, true );
4150   createSMESHAction( SMESHOp::OpLength2D,              "LENGTH_2D",               "ICON_LENGTH_2D",     0, true );
4151   createSMESHAction( SMESHOp::OpDeflection2D,          "DEFLECTION_2D",           "ICON_DEFLECTION_2D", 0, true );
4152   createSMESHAction( SMESHOp::OpConnection2D,          "CONNECTION_2D",           "ICON_CONNECTION_2D", 0, true );
4153   createSMESHAction( SMESHOp::OpArea,                  "AREA",                    "ICON_AREA",          0, true );
4154   createSMESHAction( SMESHOp::OpTaper,                 "TAPER",                   "ICON_TAPER",         0, true );
4155   createSMESHAction( SMESHOp::OpAspectRatio,           "ASPECT",                  "ICON_ASPECT",        0, true );
4156   createSMESHAction( SMESHOp::OpMinimumAngle,          "MIN_ANG",                 "ICON_ANGLE",         0, true );
4157   createSMESHAction( SMESHOp::OpWarpingAngle,          "WARP",                    "ICON_WARP",          0, true );
4158   createSMESHAction( SMESHOp::OpSkew,                  "SKEW",                    "ICON_SKEW",          0, true );
4159   createSMESHAction( SMESHOp::OpMaxElementLength2D,    "MAX_ELEMENT_LENGTH_2D",   "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
4160   createSMESHAction( SMESHOp::OpEqualFace,             "EQUAL_FACE",              "ICON_EQUAL_FACE",    0, true );
4161   createSMESHAction( SMESHOp::OpAspectRatio3D,         "ASPECT_3D",               "ICON_ASPECT_3D",     0, true );
4162   createSMESHAction( SMESHOp::OpVolume,                "VOLUME_3D",               "ICON_VOLUME_3D",     0, true );
4163   createSMESHAction( SMESHOp::OpMaxElementLength3D,    "MAX_ELEMENT_LENGTH_3D",   "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
4164   createSMESHAction( SMESHOp::OpBareBorderVolume,      "BARE_BORDER_VOLUME",      "ICON_BARE_BORDER_VOLUME",      0, true );
4165   createSMESHAction( SMESHOp::OpOverConstrainedVolume, "OVER_CONSTRAINED_VOLUME", "ICON_OVER_CONSTRAINED_VOLUME", 0, true );
4166   createSMESHAction( SMESHOp::OpEqualVolume,           "EQUAL_VOLUME",            "ICON_EQUAL_VOLUME",  0, true );
4167   createSMESHAction( SMESHOp::OpOverallMeshQuality,    "OVERALL_MESH_QUALITY",    "ICON_OVL_MESH_QUALITY" );
4168
4169   createSMESHAction( SMESHOp::OpNode,                   "NODE",            "ICON_DLG_NODE" );
4170   createSMESHAction( SMESHOp::OpElem0D,                 "ELEM0D",          "ICON_DLG_ELEM0D" );
4171   createSMESHAction( SMESHOp::OpElem0DOnElemNodes,      "0D_ON_ALL_NODES", "ICON_0D_ON_ALL_NODES" );
4172   createSMESHAction( SMESHOp::OpBall,                   "BALL",            "ICON_DLG_BALL" );
4173   createSMESHAction( SMESHOp::OpEdge,                   "EDGE",            "ICON_DLG_EDGE" );
4174   createSMESHAction( SMESHOp::OpTriangle,               "TRIANGLE",        "ICON_DLG_TRIANGLE" );
4175   createSMESHAction( SMESHOp::OpQuadrangle,             "QUAD",            "ICON_DLG_QUADRANGLE" );
4176   createSMESHAction( SMESHOp::OpPolygon,                "POLYGON",         "ICON_DLG_POLYGON" );
4177   createSMESHAction( SMESHOp::OpTetrahedron,            "TETRA",           "ICON_DLG_TETRAS" );
4178   createSMESHAction( SMESHOp::OpHexahedron,             "HEXA",            "ICON_DLG_HEXAS" );
4179   createSMESHAction( SMESHOp::OpPentahedron,            "PENTA",           "ICON_DLG_PENTA" );
4180   createSMESHAction( SMESHOp::OpPyramid ,               "PYRAMID",         "ICON_DLG_PYRAMID" );
4181   createSMESHAction( SMESHOp::OpHexagonalPrism,         "OCTA",            "ICON_DLG_OCTA" );
4182   createSMESHAction( SMESHOp::OpPolyhedron,             "POLYHEDRON",      "ICON_DLG_POLYHEDRON" );
4183   createSMESHAction( SMESHOp::OpQuadraticEdge,          "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
4184   createSMESHAction( SMESHOp::OpQuadraticTriangle,      "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
4185   createSMESHAction( SMESHOp::OpBiQuadraticTriangle,    "BIQUADRATIC_TRIANGLE",    "ICON_DLG_BIQUADRATIC_TRIANGLE" );
4186   createSMESHAction( SMESHOp::OpQuadraticQuadrangle,    "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
4187   createSMESHAction( SMESHOp::OpBiQuadraticQuadrangle,  "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
4188   createSMESHAction( SMESHOp::OpQuadraticPolygon,       "QUADRATIC_POLYGON",       "ICON_DLG_QUADRATIC_POLYGON" );
4189   createSMESHAction( SMESHOp::OpQuadraticTetrahedron,   "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
4190   createSMESHAction( SMESHOp::OpQuadraticPyramid,       "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
4191   createSMESHAction( SMESHOp::OpQuadraticPentahedron,   "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
4192   createSMESHAction( SMESHOp::OpBiQuadraticPentahedron, "BIQUADRATIC_PENTAHEDRON", "ICON_DLG_BIQUADRATIC_PENTAHEDRON" );
4193   createSMESHAction( SMESHOp::OpQuadraticHexahedron,    "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
4194   createSMESHAction( SMESHOp::OpTriQuadraticHexahedron, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
4195
4196   createSMESHAction( SMESHOp::OpRemoveNodes,       "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
4197   createSMESHAction( SMESHOp::OpRemoveElements,    "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
4198   createSMESHAction( SMESHOp::OpRemoveOrphanNodes, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
4199   createSMESHAction( SMESHOp::OpClearMesh,         "CLEAR_MESH",            "ICON_CLEAR_MESH" );
4200
4201   //createSMESHAction( SMESHOp::OpRenumberingNodes,    "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
4202   //createSMESHAction( SMESHOp::OpRenumberingElements, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
4203
4204   createSMESHAction( SMESHOp::OpTranslation,            "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
4205   createSMESHAction( SMESHOp::OpRotation,               "ROT",             "ICON_DLG_MESH_ROTATION" );
4206   createSMESHAction( SMESHOp::OpSymmetry,               "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
4207   createSMESHAction( SMESHOp::OpScale,                  "SCALE",           "ICON_DLG_MESH_SCALE" );
4208   createSMESHAction( SMESHOp::OpOffset,                 "OFFSET",          "ICON_DLG_MESH_OFFSET" );
4209   createSMESHAction( SMESHOp::OpSewing,                 "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
4210   createSMESHAction( SMESHOp::OpMergeNodes,             "MERGE",           "ICON_SMESH_MERGE_NODES" );
4211   createSMESHAction( SMESHOp::OpMergeElements,          "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
4212   createSMESHAction( SMESHOp::OpMoveNode,               "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
4213   createSMESHAction( SMESHOp::OpDuplicateNodes,         "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
4214   createSMESHAction( SMESHOp::OpDiagonalInversion,      "INV",             "ICON_DLG_MESH_DIAGONAL" );
4215   createSMESHAction( SMESHOp::OpUnionOfTwoTriangle,     "UNION2",          "ICON_UNION2TRI" );
4216   createSMESHAction( SMESHOp::OpOrientation,            "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
4217   createSMESHAction( SMESHOp::OpReorientFaces,          "REORIENT_2D",     "ICON_REORIENT_2D" );
4218   createSMESHAction( SMESHOp::OpUnionOfTriangles,       "UNION",           "ICON_UNIONTRI" );
4219   createSMESHAction( SMESHOp::OpCuttingOfQuadrangles,   "CUT",             "ICON_CUTQUAD" );
4220   createSMESHAction( SMESHOp::OpSplitVolumes,           "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
4221   createSMESHAction( SMESHOp::OpSplitBiQuadratic,       "SPLIT_BIQUAD",    "ICON_SPLIT_BIQUAD" );
4222   createSMESHAction( SMESHOp::OpSmoothing,              "SMOOTH",          "ICON_DLG_SMOOTHING" );
4223   createSMESHAction( SMESHOp::OpExtrusion,              "EXTRUSION",       "ICON_EXTRUSION" );
4224   createSMESHAction( SMESHOp::OpExtrusionAlongAPath,    "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
4225   createSMESHAction( SMESHOp::OpRevolution,             "REVOLUTION",      "ICON_REVOLUTION" );
4226   createSMESHAction( SMESHOp::OpPatternMapping,         "MAP",             "ICON_MAP" );
4227   createSMESHAction( SMESHOp::OpConvertMeshToQuadratic, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
4228   createSMESHAction( SMESHOp::OpCreateBoundaryElements, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
4229
4230   createSMESHAction( SMESHOp::OpReset,               "RESET" );
4231   createSMESHAction( SMESHOp::OpScalarBarProperties, "SCALAR_BAR_PROP" );
4232   createSMESHAction( SMESHOp::OpShowScalarBar,       "SHOW_SCALAR_BAR","",0, true  );
4233   createSMESHAction( SMESHOp::OpSaveDistribution,    "SAVE_DISTRIBUTION" );
4234   createSMESHAction( SMESHOp::OpShowDistribution,    "SHOW_DISTRIBUTION","",0, true );
4235 #ifndef DISABLE_PLOT2DVIEWER
4236   createSMESHAction( SMESHOp::OpPlotDistribution, "PLOT_DISTRIBUTION" );
4237 #endif
4238   createSMESHAction( SMESHOp::OpDMWireframe,  "WIRE",    "ICON_WIRE", 0, true );
4239   createSMESHAction( SMESHOp::OpDMShading,    "SHADE",   "ICON_SHADE", 0, true );
4240   createSMESHAction( SMESHOp::OpDMNodes,      "NODES",   "ICON_POINTS", 0, true );
4241   createSMESHAction( SMESHOp::OpDMShrink,     "SHRINK",  "ICON_SHRINK", 0, true );
4242   createSMESHAction( SMESHOp::OpUpdate,       "UPDATE",  "ICON_UPDATE" );
4243   createSMESHAction( SMESHOp::OpDE0DElements, "ELEMS0D", "ICON_DLG_ELEM0D", 0, true );
4244   createSMESHAction( SMESHOp::OpDEEdges,      "EDGES",   "ICON_DLG_EDGE", 0, true );
4245   createSMESHAction( SMESHOp::OpDEFaces,      "FACES",   "ICON_DLG_TRIANGLE", 0, true );
4246   createSMESHAction( SMESHOp::OpDEVolumes,    "VOLUMES", "ICON_DLG_TETRAS", 0, true );
4247   createSMESHAction( SMESHOp::OpDEBalls,      "BALLS",   "ICON_DLG_BALL", 0, true );
4248   createSMESHAction( SMESHOp::OpDEChoose,     "CHOOSE",  "ICON_DLG_CHOOSE", 0, false );
4249   createSMESHAction( SMESHOp::OpDEAllEntity,  "ALL",     "ICON_DLG_CHOOSE_ALL", 0, false );
4250   createSMESHAction( SMESHOp::OpOrientationOnFaces, "FACE_ORIENTATION", "", 0, true );
4251
4252   createSMESHAction( SMESHOp::OpRepresentationLines, "LINE_REPRESENTATION", "", 0, true );
4253   createSMESHAction( SMESHOp::OpRepresentationArcs,  "ARC_REPRESENTATION", "", 0, true );
4254
4255   createSMESHAction( SMESHOp::OpEditHypothesis,    "EDIT_HYPO" );
4256   createSMESHAction( SMESHOp::OpUnassign,          "UNASSIGN" );
4257   createSMESHAction( SMESHOp::OpNumberingNodes,    "NUM_NODES", "", 0, true );
4258   createSMESHAction( SMESHOp::OpNumberingElements, "NUM_ELEMENTS", "", 0, true );
4259   createSMESHAction( SMESHOp::OpProperties,   "COLORS" );
4260   createSMESHAction( SMESHOp::OpTransparency, "TRANSP" );
4261   createSMESHAction( SMESHOp::OpClipping,     "CLIP" );
4262   createSMESHAction( SMESHOp::OpAutoColor,        "AUTO_COLOR" );
4263   createSMESHAction( SMESHOp::OpDisableAutoColor, "DISABLE_AUTO_COLOR" );
4264
4265   // Adaptation - begin
4266 #ifndef DISABLE_MG_ADAPT
4267   createSMESHAction( SMESHOp::OpMGAdapt, "MG_ADAPT", "ICON_MG_ADAPT" );
4268 #endif
4269   // Adaptation - end
4270
4271   createSMESHAction( SMESHOp::OpMinimumDistance,  "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
4272   createSMESHAction( SMESHOp::OpBoundingBox,      "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
4273   createSMESHAction( SMESHOp::OpPropertiesLength, "MEASURE_LENGTH",   "ICON_MEASURE_LENGTH" );
4274   createSMESHAction( SMESHOp::OpPropertiesArea,   "MEASURE_AREA",     "ICON_MEASURE_AREA" );
4275   createSMESHAction( SMESHOp::OpPropertiesVolume, "MEASURE_VOLUME",   "ICON_MEASURE_VOLUME" );
4276   createSMESHAction( SMESHOp::OpAngle,            "MEASURE_ANGLE",    "ICON_MEASURE_ANGLE" );
4277
4278   createSMESHAction( SMESHOp::OpHide,     "HIDE", "ICON_HIDE" );
4279   createSMESHAction( SMESHOp::OpShow,     "SHOW", "ICON_SHOW" );
4280   createSMESHAction( SMESHOp::OpShowOnly, "DISPLAY_ONLY" );
4281
4282   createSMESHAction( SMESHOp::OpSortChild, "SORT_CHILD_ITEMS" );
4283
4284   createSMESHAction( SMESHOp::OpBreakLink, "BREAK_SHAPER_LINK" );
4285
4286   QList<int> aCtrlActions;
4287   aCtrlActions << SMESHOp::OpFreeNode << SMESHOp::OpEqualNode
4288                << SMESHOp::OpNodeConnectivityNb                                         // node controls
4289                << SMESHOp::OpFreeEdge << SMESHOp::OpFreeBorder
4290                << SMESHOp::OpLength << SMESHOp::OpConnection << SMESHOp::OpEqualEdge    // edge controls
4291                << SMESHOp::OpDeflection2D
4292                << SMESHOp::OpFreeFace << SMESHOp::OpLength2D << SMESHOp::OpConnection2D
4293                << SMESHOp::OpArea << SMESHOp::OpTaper << SMESHOp::OpAspectRatio
4294                << SMESHOp::OpMinimumAngle << SMESHOp::OpWarpingAngle << SMESHOp::OpSkew
4295                << SMESHOp::OpMaxElementLength2D << SMESHOp::OpBareBorderFace
4296                << SMESHOp::OpOverConstrainedFace << SMESHOp::OpEqualFace                // face controls
4297                << SMESHOp::OpAspectRatio3D << SMESHOp::OpVolume
4298                << SMESHOp::OpMaxElementLength3D << SMESHOp::OpBareBorderVolume
4299                << SMESHOp::OpOverConstrainedVolume << SMESHOp::OpEqualVolume;           // volume controls
4300   QActionGroup* aCtrlGroup = new QActionGroup( application()->desktop() );
4301   aCtrlGroup->setExclusive( true );
4302   for( int i = 0; i < aCtrlActions.size(); i++ )
4303     aCtrlGroup->addAction( action( aCtrlActions[i] ) );
4304
4305   // ----- create menu --------------
4306   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
4307       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
4308       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
4309       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
4310       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
4311       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
4312 #ifndef DISABLE_MG_ADAPT
4313       adaptId   = createMenu( tr( "MEN_ADAPT" ),   -1, 80, 10 ),
4314 #endif
4315       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
4316       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
4317
4318   createMenu( separator(), fileId );
4319
4320   QMenu* nodeMenu = new QMenu(); QMenu* edgeMenu = new QMenu();
4321   QMenu* faceMenu = new QMenu(); QMenu* volumeMenu = new QMenu();
4322   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
4323       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
4324       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10, -1, nodeMenu ),
4325       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10, -1, edgeMenu ),
4326       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10, -1, faceMenu ),
4327       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10, -1, volumeMenu ),
4328       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
4329       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
4330     //renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
4331       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
4332       basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 );
4333
4334   //createMenu( SMESHOp::OpImportDAT, importId, -1 );
4335   createMenu( SMESHOp::OpImportUNV,  importId, -1 );
4336   createMenu( SMESHOp::OpImportMED,  importId, -1 );
4337   createMenu( SMESHOp::OpImportSTL,  importId, -1 );
4338 #ifdef WITH_CGNS
4339   createMenu( SMESHOp::OpImportCGNS, importId, -1 );
4340 #endif
4341   createMenu( SMESHOp::OpImportGMF,  importId, -1 );
4342   createMenu( SMESHOp::OpExportDAT,  exportId, -1 );
4343   createMenu( SMESHOp::OpExportMED,  exportId, -1 );
4344   createMenu( SMESHOp::OpExportUNV,  exportId, -1 );
4345   createMenu( SMESHOp::OpExportSTL,  exportId, -1 );
4346 #ifdef WITH_CGNS
4347   createMenu( SMESHOp::OpExportCGNS, exportId, -1 );
4348 #endif
4349   createMenu( SMESHOp::OpExportGMF,  exportId, -1 );
4350   createMenu( separator(), fileId, 10 );
4351
4352   createMenu( SMESHOp::OpDelete, editId, -1 );
4353
4354   createMenu( SMESHOp::OpSelectFiltersLibrary, toolsId, -1 );
4355
4356   createMenu( SMESHOp::OpCreateMesh,           meshId, -1 ); // "Mesh" menu
4357   createMenu( SMESHOp::OpCreateSubMesh,        meshId, -1 );
4358   createMenu( SMESHOp::OpEditMeshOrSubMesh,    meshId, -1 );
4359   createMenu( SMESHOp::OpBuildCompoundMesh,    meshId, -1 );
4360   createMenu( SMESHOp::OpCopyMesh,             meshId, -1 );
4361   createMenu( separator(),                     meshId, -1 );
4362   createMenu( SMESHOp::OpCompute,              meshId, -1 );
4363   createMenu( SMESHOp::OpPreCompute,           meshId, -1 );
4364   createMenu( SMESHOp::OpEvaluate,             meshId, -1 );
4365   createMenu( SMESHOp::OpMeshOrder,            meshId, -1 );
4366   createMenu( separator(),                     meshId, -1 );
4367   createMenu( SMESHOp::OpCreateGroup,          meshId, -1 );
4368   createMenu( SMESHOp::OpCreateGeometryGroup,  meshId, -1 );
4369   createMenu( SMESHOp::OpConstructGroup,       meshId, -1 );
4370   createMenu( SMESHOp::OpEditGroup,            meshId, -1 );
4371   createMenu( SMESHOp::OpEditGeomGroupAsGroup, meshId, -1 );
4372   createMenu( separator(),                     meshId, -1 );
4373   createMenu( SMESHOp::OpUnionGroups,          meshId, -1 );
4374   createMenu( SMESHOp::OpIntersectGroups,      meshId, -1 );
4375   createMenu( SMESHOp::OpCutGroups,            meshId, -1 );
4376   createMenu( separator(),                     meshId, -1 );
4377   createMenu( SMESHOp::OpGroupUnderlyingElem,  meshId, -1 );
4378   createMenu( SMESHOp::OpFaceGroupsByEdges,    meshId, -1 );
4379   createMenu( separator(),                     meshId, -1 );
4380   createMenu( SMESHOp::OpMeshInformation,      meshId, -1 );
4381   //createMenu( SMESHOp::OpStdInfo, meshId, -1 );
4382   //createMenu( SMESHOp::OpWhatIs, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4383   createMenu( SMESHOp::OpFindElementByPoint,   meshId, -1 );
4384   createMenu( separator(),                     meshId, -1 );
4385
4386   createMenu( SMESHOp::OpFreeNode,              nodeId,   -1 );
4387   createMenu( SMESHOp::OpEqualNode,             nodeId,   -1 );
4388   //createMenu( SMESHOp::OpNodeConnectivityNb,    nodeId,   -1 );
4389   createMenu( SMESHOp::OpFreeBorder,            edgeId,   -1 );
4390   createMenu( SMESHOp::OpLength,                edgeId,   -1 );
4391   createMenu( SMESHOp::OpConnection,            edgeId,   -1 );
4392   createMenu( SMESHOp::OpEqualEdge,             edgeId,   -1 );
4393   createMenu( SMESHOp::OpFreeEdge,              faceId,   -1 );
4394   createMenu( SMESHOp::OpFreeFace,              faceId,   -1 );
4395   createMenu( SMESHOp::OpBareBorderFace,        faceId,   -1 );
4396   createMenu( SMESHOp::OpOverConstrainedFace,   faceId,   -1 );
4397   createMenu( SMESHOp::OpLength2D,              faceId,   -1 );
4398   createMenu( SMESHOp::OpConnection2D,          faceId,   -1 );
4399   createMenu( SMESHOp::OpArea,                  faceId,   -1 );
4400   createMenu( SMESHOp::OpTaper,                 faceId,   -1 );
4401   createMenu( SMESHOp::OpAspectRatio,           faceId,   -1 );
4402   createMenu( SMESHOp::OpMinimumAngle,          faceId,   -1 );
4403   createMenu( SMESHOp::OpWarpingAngle,          faceId,   -1 );
4404   createMenu( SMESHOp::OpSkew,                  faceId,   -1 );
4405   createMenu( SMESHOp::OpMaxElementLength2D,    faceId,   -1 );
4406   createMenu( SMESHOp::OpEqualFace,             faceId,   -1 );
4407   createMenu( SMESHOp::OpDeflection2D,          faceId,   -1 );
4408   createMenu( SMESHOp::OpAspectRatio3D,         volumeId, -1 );
4409   createMenu( SMESHOp::OpVolume,                volumeId, -1 );
4410   createMenu( SMESHOp::OpMaxElementLength3D,    volumeId, -1 );
4411   createMenu( SMESHOp::OpBareBorderVolume,      volumeId, -1 );
4412   createMenu( SMESHOp::OpOverConstrainedVolume, volumeId, -1 );
4413   createMenu( SMESHOp::OpEqualVolume,           volumeId, -1 );
4414   createMenu( separator(),                      ctrlId,   -1 );
4415   createMenu( SMESHOp::OpReset,                 ctrlId,   -1 );
4416   createMenu( separator(),                      ctrlId,   -1 );
4417   createMenu( SMESHOp::OpOverallMeshQuality,    ctrlId,   -1 );
4418
4419   createMenu( SMESHOp::OpNode,                   addId, -1 );
4420   createMenu( SMESHOp::OpElem0D,                 addId, -1 );
4421   createMenu( SMESHOp::OpElem0DOnElemNodes,      addId, -1 );
4422   createMenu( SMESHOp::OpBall,                   addId, -1 );
4423   createMenu( SMESHOp::OpEdge,                   addId, -1 );
4424   createMenu( SMESHOp::OpTriangle,               addId, -1 );
4425   createMenu( SMESHOp::OpQuadrangle,             addId, -1 );
4426   createMenu( SMESHOp::OpPolygon,                addId, -1 );
4427   createMenu( SMESHOp::OpTetrahedron,            addId, -1 );
4428   createMenu( SMESHOp::OpHexahedron,             addId, -1 );
4429   createMenu( SMESHOp::OpPentahedron,            addId, -1 );
4430   createMenu( SMESHOp::OpPyramid,                addId, -1 );
4431   createMenu( SMESHOp::OpHexagonalPrism,         addId, -1 );
4432   createMenu( SMESHOp::OpPolyhedron,             addId, -1 );
4433   createMenu( separator(),                       addId, -1 );
4434   createMenu( SMESHOp::OpQuadraticEdge,          addId, -1 );
4435   createMenu( SMESHOp::OpQuadraticTriangle,      addId, -1 );
4436   createMenu( SMESHOp::OpBiQuadraticTriangle ,   addId, -1 );
4437   createMenu( SMESHOp::OpQuadraticQuadrangle,    addId, -1 );
4438   createMenu( SMESHOp::OpBiQuadraticQuadrangle,  addId, -1 );
4439   createMenu( SMESHOp::OpQuadraticPolygon,       addId, -1 );
4440   createMenu( SMESHOp::OpQuadraticTetrahedron,   addId, -1 );
4441   createMenu( SMESHOp::OpQuadraticPyramid,       addId, -1 );
4442   createMenu( SMESHOp::OpQuadraticPentahedron,   addId, -1 );
4443   createMenu( SMESHOp::OpBiQuadraticPentahedron, addId, -1 );
4444   createMenu( SMESHOp::OpQuadraticHexahedron,    addId, -1 );
4445   createMenu( SMESHOp::OpTriQuadraticHexahedron, addId, -1 );
4446
4447   createMenu( SMESHOp::OpRemoveNodes,       removeId, -1 );
4448   createMenu( SMESHOp::OpRemoveElements,    removeId, -1 );
4449   createMenu( SMESHOp::OpRemoveOrphanNodes, removeId, -1 );
4450   createMenu( separator(),                  removeId, -1 );
4451   createMenu( SMESHOp::OpDeleteGroup,       removeId, -1 );
4452   createMenu( separator(),                  removeId, -1 );
4453   createMenu( SMESHOp::OpClearMesh,         removeId, -1 );
4454
4455   //createMenu( SMESHOp::OpRenumberingNodes,    renumId, -1 );
4456   //createMenu( SMESHOp::OpRenumberingElements, renumId, -1 );
4457
4458   createMenu( SMESHOp::OpMergeNodes,     transfId, -1 );
4459   createMenu( SMESHOp::OpMergeElements,  transfId, -1 );
4460   createMenu( SMESHOp::OpTranslation,    transfId, -1 );
4461   createMenu( SMESHOp::OpRotation,       transfId, -1 );
4462   createMenu( SMESHOp::OpSymmetry,       transfId, -1 );
4463   createMenu( SMESHOp::OpScale,          transfId, -1 );
4464   createMenu( SMESHOp::OpOffset,         transfId, -1 );
4465   createMenu( SMESHOp::OpSewing,         transfId, -1 );
4466   createMenu( SMESHOp::OpDuplicateNodes, transfId, -1 );
4467
4468   createMenu( SMESHOp::OpConvertMeshToQuadratic, modifyId, -1 );
4469   createMenu( SMESHOp::OpCreateBoundaryElements, modifyId, -1 );
4470   createMenu( SMESHOp::OpExtrusion,              modifyId, -1 );
4471   createMenu( SMESHOp::OpExtrusionAlongAPath,    modifyId, -1 );
4472   createMenu( SMESHOp::OpRevolution,             modifyId, -1 );
4473   createMenu( SMESHOp::OpOrientation,            modifyId, -1 );
4474   createMenu( SMESHOp::OpReorientFaces,          modifyId, -1 );
4475   createMenu( SMESHOp::OpMoveNode,               modifyId, -1 );
4476   createMenu( SMESHOp::OpDiagonalInversion,      modifyId, -1 );
4477   createMenu( SMESHOp::OpUnionOfTwoTriangle,     modifyId, -1 );
4478   createMenu( SMESHOp::OpUnionOfTriangles,       modifyId, -1 );
4479   createMenu( SMESHOp::OpCuttingOfQuadrangles,   modifyId, -1 );
4480   createMenu( SMESHOp::OpSplitVolumes,           modifyId, -1 );
4481   createMenu( SMESHOp::OpSplitBiQuadratic,       modifyId, -1 );
4482   createMenu( SMESHOp::OpSmoothing,              modifyId, -1 );
4483   createMenu( SMESHOp::OpPatternMapping,         modifyId, -1 );
4484
4485   // Adaptation - begin
4486 #ifndef DISABLE_MG_ADAPT
4487   createMenu( SMESHOp::OpMGAdapt, adaptId, -1 );
4488 #endif
4489   // Adaptation - end
4490
4491   createMenu( SMESHOp::OpMinimumDistance,  measureId,   -1 );
4492   createMenu( SMESHOp::OpBoundingBox,      measureId,   -1 );
4493   createMenu( SMESHOp::OpAngle,            measureId,   -1 );
4494   createMenu( SMESHOp::OpPropertiesLength, basicPropId, -1 );
4495   createMenu( SMESHOp::OpPropertiesArea,   basicPropId, -1 );
4496   createMenu( SMESHOp::OpPropertiesVolume, basicPropId, -1 );
4497   createMenu( SMESHOp::OpUpdate,           viewId,      -1 );
4498
4499   connect( nodeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4500   connect( edgeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4501   connect( faceMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4502   connect( volumeMenu, SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4503
4504   // ----- create toolbars --------------
4505   int meshTb = createTool( tr( "TB_MESH" ), QString( "SMESHMeshToolbar" ) ) ;
4506   createTool( SMESHOp::OpCreateMesh,        meshTb );
4507   createTool( SMESHOp::OpCreateSubMesh,     meshTb );
4508   createTool( SMESHOp::OpEditMeshOrSubMesh, meshTb );
4509   createTool( SMESHOp::OpBuildCompoundMesh, meshTb );
4510   createTool( SMESHOp::OpCopyMesh,          meshTb );
4511   createTool( separator(),                  meshTb );
4512   createTool( SMESHOp::OpCompute,           meshTb );
4513   createTool( SMESHOp::OpPreCompute,        meshTb );
4514   createTool( SMESHOp::OpEvaluate,          meshTb );
4515   createTool( SMESHOp::OpMeshOrder,         meshTb );
4516
4517   int infoTb = createTool( tr( "TB_INFO" ), QString( "SMESHInformationToolbar" ) ) ;
4518   createTool( SMESHOp::OpMeshInformation,    infoTb );
4519   //createTool( SMESHOp::OpStdInfo, meshTb );
4520   //createTool( SMESHOp::OpWhatIs, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4521   createTool( SMESHOp::OpFindElementByPoint, infoTb );
4522
4523   int groupTb = createTool( tr( "TB_GROUP" ), QString( "SMESHGroupToolbar" ) ) ;
4524   createTool( SMESHOp::OpCreateGroup,         groupTb );
4525   createTool( SMESHOp::OpCreateGeometryGroup, groupTb );
4526   createTool( SMESHOp::OpConstructGroup,      groupTb );
4527   createTool( SMESHOp::OpEditGroup,           groupTb );
4528
4529   int ctrl0dTb = createTool( tr( "TB_CTRL0D" ), QString( "SMESHNodeControlsToolbar" ) ) ;
4530   createTool( SMESHOp::OpFreeNode,  ctrl0dTb );
4531   createTool( SMESHOp::OpEqualNode, ctrl0dTb );
4532   //createTool( SMESHOp::OpNodeConnectivityNb, ctrl0dTb );
4533
4534   int ctrl1dTb = createTool( tr( "TB_CTRL1D" ), QString( "SMESHEdgeControlsToolbar" ) ) ;
4535   createTool( SMESHOp::OpFreeBorder, ctrl1dTb );
4536   createTool( SMESHOp::OpLength,     ctrl1dTb );
4537   createTool( SMESHOp::OpConnection, ctrl1dTb );
4538   createTool( SMESHOp::OpEqualEdge,  ctrl1dTb );
4539
4540   int ctrl2dTb = createTool( tr( "TB_CTRL2D" ), QString( "SMESHFaceControlsToolbar" ) ) ;
4541   createTool( SMESHOp::OpFreeEdge,            ctrl2dTb );
4542   createTool( SMESHOp::OpFreeFace,            ctrl2dTb );
4543   createTool( SMESHOp::OpBareBorderFace,      ctrl2dTb );
4544   createTool( SMESHOp::OpOverConstrainedFace, ctrl2dTb );
4545   createTool( SMESHOp::OpLength2D,            ctrl2dTb );
4546   createTool( SMESHOp::OpConnection2D,        ctrl2dTb );
4547   createTool( SMESHOp::OpArea,                ctrl2dTb );
4548   createTool( SMESHOp::OpTaper,               ctrl2dTb );
4549   createTool( SMESHOp::OpAspectRatio,         ctrl2dTb );
4550   createTool( SMESHOp::OpMinimumAngle,        ctrl2dTb );
4551   createTool( SMESHOp::OpWarpingAngle,        ctrl2dTb );
4552   createTool( SMESHOp::OpSkew,                ctrl2dTb );
4553   createTool( SMESHOp::OpMaxElementLength2D,  ctrl2dTb );
4554   createTool( SMESHOp::OpEqualFace,           ctrl2dTb );
4555   createTool( SMESHOp::OpDeflection2D,        ctrl2dTb );
4556
4557   int ctrl3dTb = createTool( tr( "TB_CTRL3D" ), QString( "SMESHVolumeControlsToolbar" ) ) ;
4558   createTool( SMESHOp::OpAspectRatio3D,         ctrl3dTb );
4559   createTool( SMESHOp::OpVolume,                ctrl3dTb );
4560   createTool( SMESHOp::OpMaxElementLength3D,    ctrl3dTb );
4561   createTool( SMESHOp::OpBareBorderVolume,      ctrl3dTb );
4562   createTool( SMESHOp::OpOverConstrainedVolume, ctrl3dTb );
4563   createTool( SMESHOp::OpEqualVolume,           ctrl3dTb );
4564
4565   int addElemTb = createTool( tr( "TB_ADD" ), QString( "SMESHAddElementToolbar" ) ) ;
4566   createTool( SMESHOp::OpNode,              addElemTb );
4567   createTool( SMESHOp::OpElem0D,            addElemTb );
4568   createTool( SMESHOp::OpElem0DOnElemNodes, addElemTb );
4569   createTool( SMESHOp::OpBall,              addElemTb );
4570   createTool( SMESHOp::OpEdge,              addElemTb );
4571   createTool( SMESHOp::OpTriangle,          addElemTb );
4572   createTool( SMESHOp::OpQuadrangle,        addElemTb );
4573   createTool( SMESHOp::OpPolygon,           addElemTb );
4574   createTool( SMESHOp::OpTetrahedron,       addElemTb );
4575   createTool( SMESHOp::OpHexahedron,        addElemTb );
4576   createTool( SMESHOp::OpPentahedron,       addElemTb );
4577   createTool( SMESHOp::OpPyramid,           addElemTb );
4578   createTool( SMESHOp::OpHexagonalPrism,    addElemTb );
4579   createTool( SMESHOp::OpPolyhedron,        addElemTb );
4580
4581   int addNonElemTb = createTool( tr( "TB_ADDNON" ), QString( "SMESHAddElementToolbar" ) ) ;
4582   createTool( SMESHOp::OpQuadraticEdge,          addNonElemTb );
4583   createTool( SMESHOp::OpQuadraticTriangle,      addNonElemTb );
4584   createTool( SMESHOp::OpBiQuadraticTriangle,    addNonElemTb );
4585   createTool( SMESHOp::OpQuadraticQuadrangle,    addNonElemTb );
4586   createTool( SMESHOp::OpBiQuadraticQuadrangle,  addNonElemTb );
4587   createTool( SMESHOp::OpQuadraticPolygon,       addNonElemTb );
4588   createTool( SMESHOp::OpQuadraticTetrahedron,   addNonElemTb );
4589   createTool( SMESHOp::OpQuadraticPyramid,       addNonElemTb );
4590   createTool( SMESHOp::OpQuadraticPentahedron,   addNonElemTb );
4591   createTool( SMESHOp::OpBiQuadraticPentahedron, addNonElemTb );
4592   createTool( SMESHOp::OpQuadraticHexahedron,    addNonElemTb );
4593   createTool( SMESHOp::OpTriQuadraticHexahedron, addNonElemTb );
4594
4595   int remTb = createTool( tr( "TB_REM" ), QString( "SMESHRemoveToolbar" ) ) ;
4596   createTool( SMESHOp::OpRemoveNodes,       remTb );
4597   createTool( SMESHOp::OpRemoveElements,    remTb );
4598   createTool( SMESHOp::OpRemoveOrphanNodes, remTb );
4599   createTool( SMESHOp::OpClearMesh,         remTb );
4600
4601 //   int renumbTb     = createTool( tr( "TB_RENUMBER" ),  QString( "SMESHRenumberingToolbar" ) ) ;
4602   //createTool( SMESHOp::OpRenumberingNodes,    renumbTb );
4603   //createTool( SMESHOp::OpRenumberingElements, renumbTb );
4604
4605   int transformTb = createTool( tr( "TB_TRANSFORM" ), QString( "SMESHTransformationToolbar" ) ) ;
4606   createTool( SMESHOp::OpMergeNodes,     transformTb );
4607   createTool( SMESHOp::OpMergeElements,  transformTb );
4608   createTool( SMESHOp::OpTranslation,    transformTb );
4609   createTool( SMESHOp::OpRotation,       transformTb );
4610   createTool( SMESHOp::OpSymmetry,       transformTb );
4611   createTool( SMESHOp::OpScale,          transformTb );
4612   createTool( SMESHOp::OpOffset,         transformTb );
4613   createTool( SMESHOp::OpSewing,         transformTb );
4614   createTool( SMESHOp::OpDuplicateNodes, transformTb );
4615
4616   int modifyTb = createTool( tr( "TB_MODIFY" ), QString( "SMESHModificationToolbar" ) ) ;
4617   createTool( SMESHOp::OpConvertMeshToQuadratic, modifyTb );
4618   createTool( SMESHOp::OpCreateBoundaryElements, modifyTb );
4619   createTool( SMESHOp::OpExtrusion,              modifyTb );
4620   createTool( SMESHOp::OpExtrusionAlongAPath,    modifyTb );
4621   createTool( SMESHOp::OpRevolution,             modifyTb );
4622   createTool( SMESHOp::OpOrientation,            modifyTb );
4623   createTool( SMESHOp::OpReorientFaces,          modifyTb );
4624   createTool( SMESHOp::OpMoveNode,               modifyTb );
4625   createTool( SMESHOp::OpDiagonalInversion,      modifyTb );
4626   createTool( SMESHOp::OpUnionOfTwoTriangle,     modifyTb );
4627   createTool( SMESHOp::OpUnionOfTriangles,       modifyTb );
4628   createTool( SMESHOp::OpCuttingOfQuadrangles,   modifyTb );
4629   createTool( SMESHOp::OpSplitVolumes,           modifyTb );
4630   createTool( SMESHOp::OpSplitBiQuadratic,       modifyTb );
4631   createTool( SMESHOp::OpSmoothing,              modifyTb );
4632   createTool( SMESHOp::OpPatternMapping,         modifyTb );
4633
4634   // Adaptation - begin
4635 #ifndef DISABLE_MG_ADAPT
4636   int adaptTb = createTool( tr( "TB_ADAPTATION" ), QString( "SMESHAdaptationToolbar" ) ) ;
4637   createTool( SMESHOp::OpMGAdapt, adaptTb );
4638 #endif
4639   // Adaptation - end
4640
4641   int measuremTb = createTool( tr( "TB_MEASUREM" ), QString( "SMESHMeasurementsToolbar" ) ) ;
4642   createTool( SMESHOp::OpMinimumDistance, measuremTb );
4643
4644   int dispModeTb = createTool( tr( "TB_DISP_MODE" ), QString( "SMESHDisplayModeToolbar" ) );
4645   createTool( SMESHOp::OpUpdate, dispModeTb );
4646
4647   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4648   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4649
4650   myRules.clear();
4651   QString
4652     OB      = "'ObjectBrowser'",
4653     View    = "'" + SVTK_Viewer::Type() + "'",
4654     pat     = "'%1'",
4655     mesh    = pat.arg( SMESHGUI_Selection::typeName( SMESH::MESH ) ),
4656     group   = pat.arg( SMESHGUI_Selection::typeName( SMESH::GROUP ) ),
4657     hypo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::HYPOTHESIS ) ),
4658     algo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::ALGORITHM ) ),
4659     smesh   = pat.arg( SMESHGUI_Selection::typeName( SMESH::COMPONENT ) ),
4660     elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
4661     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_VERTEX ) ).
4662     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_EDGE ) ).
4663     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_FACE ) ).
4664     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_SOLID ) ).
4665     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_COMPOUND ) ).
4666     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH ) ),
4667     subMesh      = elems,
4668     mesh_part    = mesh + " " + subMesh + " " + group,
4669     mesh_group   = mesh + " " + group,
4670     mesh_submesh = mesh + " " + subMesh,
4671     hyp_alg      = hypo + " " + algo;
4672
4673   // popup for object browser
4674   QString
4675     isInvisible("not( isVisible )"),
4676     isEmpty("numberOfNodes = 0"),
4677     isNotEmpty("numberOfNodes <> 0"),
4678
4679     // has nodes, edges, etc in VISIBLE! actor
4680     hasNodes("(numberOfNodes > 0 ) && hasActor"),
4681     hasElems("(count( elemTypes ) > 0)"),
4682     hasDifferentElems("(count( elemTypes ) > 1)"),
4683     hasDifferentObjElems("(count( objElemTypes ) > 1)"),
4684     hasBalls("({'BallElem'} in elemTypes)"),
4685     hasElems0d("({'Elem0d'} in elemTypes)"),
4686     hasEdges("({'Edge'} in elemTypes)"),
4687     hasFaces("({'Face'} in elemTypes)"),
4688     hasVolumes("({'Volume'} in elemTypes)"),
4689     hasFacesOrVolumes("(({'Face'} in elemTypes) || ({'Volume'} in elemTypes)) ");
4690
4691   createPopupItem( SMESHOp::OpEditMesh,          OB, mesh, "&& selcount=1" );
4692   createPopupItem( SMESHOp::OpCreateSubMesh,     OB, mesh, "&& hasGeomReference");
4693   createPopupItem( SMESHOp::OpMeshOrder,         OB, mesh, "&& selcount=1 && hasAlgo && hasGeomReference" );
4694   createPopupItem( SMESHOp::OpEditSubMesh,       OB, subMesh, "&& selcount=1 && hasGeomReference" );
4695   createPopupItem( SMESHOp::OpEditGroup,         OB, group );
4696   createPopupItem( SMESHOp::OpEditGeomGroupAsGroup, OB, group, "&& groupType != 'Group'" );
4697
4698   popupMgr()->insert( separator(), -1, 0 );
4699   createPopupItem( SMESHOp::OpCompute,           OB, mesh, "&& selcount=1 && hasAlgo && isComputable" );
4700   createPopupItem( SMESHOp::OpRecompute,         OB, mesh, "&& selcount=1 && hasAlgo && (" + isNotEmpty + " || hasErrors )");
4701   createPopupItem( SMESHOp::OpShowErrors,        OB, mesh, "&& selcount=1 && hasErrors" );
4702   createPopupItem( SMESHOp::OpComputeSubMesh,    OB, subMesh, "&& selcount=1 && hasAlgo && isComputable" );
4703   createPopupItem( SMESHOp::OpPreCompute,        OB, mesh, "&& selcount=1 && hasAlgo && isPreComputable" );
4704   createPopupItem( SMESHOp::OpEvaluate,          OB, mesh, "&& selcount=1 && hasAlgo && isComputable" );
4705   popupMgr()->insert( separator(), -1, 0 );
4706   createPopupItem( SMESHOp::OpFileInformation,   OB, mesh, "&& selcount=1 && isImported" );
4707   createPopupItem( SMESHOp::OpMeshInformation,   OB, mesh_part );
4708   createPopupItem( SMESHOp::OpFindElementByPoint,OB, mesh_group, "&& selcount=1 && " + hasElems );
4709   createPopupItem( SMESHOp::OpOverallMeshQuality,OB, mesh_part );
4710   popupMgr()->insert( separator(), -1, 0 );
4711   createPopupItem( SMESHOp::OpCreateGroup,       OB, mesh, "&& selcount=1" );
4712   createPopupItem( SMESHOp::OpCreateGeometryGroup, OB, mesh, "&& selcount=1 && hasGeomReference" );
4713   createPopupItem( SMESHOp::OpConstructGroup,    OB, subMesh );
4714   popupMgr()->insert( separator(), -1, 0 );
4715   createPopupItem( SMESHOp::OpEditHypothesis,    OB, hypo, "&& isEditableHyp");
4716   createPopupItem( SMESHOp::OpUnassign,          OB, hyp_alg );
4717   popupMgr()->insert( separator(), -1, 0 );
4718   createPopupItem( SMESHOp::OpConvertMeshToQuadratic, OB, mesh_submesh, "&& " + hasElems );
4719   createPopupItem( SMESHOp::OpCreateBoundaryElements, OB, mesh_group, "&& selcount=1 && dim>=2");
4720
4721   // Adaptation - begin
4722 #ifndef DISABLE_MG_ADAPT
4723   popupMgr()->insert( separator(), -1, 0 );
4724   createPopupItem( SMESHOp::OpMGAdapt, OB, mesh );
4725   popupMgr()->insert( separator(), -1, 0 );
4726 #endif
4727   // Adaptation - end
4728
4729   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
4730   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
4731   QString only_one_2D        = only_one_non_empty + " && dim>1";
4732
4733   int anId = popupMgr()->insert( tr( "MEN_EXPORT" ), -1, -1 );        // EXPORT submenu
4734   popupMgr()->findMenu( anId )->menuAction()->setIcon( resourceMgr()->loadPixmap( "SMESH", tr( "ICON_EXPORT" )));
4735   createPopupItem( SMESHOp::OpPopupExportMED,  OB, mesh_group, multiple_non_empty, anId );
4736   createPopupItem( SMESHOp::OpPopupExportUNV,  OB, mesh_group, only_one_non_empty, anId );
4737   createPopupItem( SMESHOp::OpPopupExportSTL,  OB, mesh_group, only_one_2D, anId );
4738 #ifdef WITH_CGNS
4739   createPopupItem( SMESHOp::OpPopupExportCGNS, OB, mesh_group, multiple_non_empty, anId );
4740 #endif
4741   createPopupItem( SMESHOp::OpPopupExportGMF,  OB, mesh_group, only_one_non_empty, anId );
4742   createPopupItem( SMESHOp::OpPopupExportDAT,  OB, mesh_group, only_one_non_empty, anId );
4743
4744   anId = popupMgr()->insert( tr( "MEN_IMPORT" ), -1, -1 );        // IMPORT submenu
4745   createPopupItem( SMESHOp::OpPopupImportMED,  OB, smesh, "", anId );
4746   createPopupItem( SMESHOp::OpPopupImportUNV,  OB, smesh, "", anId );
4747   createPopupItem( SMESHOp::OpPopupImportSTL,  OB, smesh, "", anId );
4748 #ifdef WITH_CGNS
4749   createPopupItem( SMESHOp::OpPopupImportCGNS, OB, smesh, "", anId );
4750 #endif
4751   createPopupItem( SMESHOp::OpPopupImportGMF,  OB, smesh, "", anId );
4752   createPopupItem( SMESHOp::OpPopupImportDAT,  OB, smesh, "", anId );
4753   popupMgr()->insert( separator(), -1, 0 );
4754
4755   createPopupItem( SMESHOp::OpClearMesh,         OB, mesh );
4756   createPopupItem( SMESHOp::OpDelete,            OB, mesh_part + " " + hyp_alg );
4757   createPopupItem( SMESHOp::OpDeleteGroup,       OB, group );
4758
4759   // popup for viewer
4760   createPopupItem( SMESHOp::OpEditGroup,            View, group );
4761   createPopupItem( SMESHOp::OpAddElemGroupPopup,    View, elems, "&& guiState = 800" );
4762   createPopupItem( SMESHOp::OpRemoveElemGroupPopup, View, elems, "&& guiState = 800" );
4763
4764   popupMgr()->insert( separator(), -1, 0 );
4765   createPopupItem( SMESHOp::OpMeshInformation,    View, mesh_part );
4766   createPopupItem( SMESHOp::OpOverallMeshQuality, View, mesh_part );
4767   createPopupItem( SMESHOp::OpFindElementByPoint, View, mesh, "&& " + hasElems);
4768   popupMgr()->insert( separator(), -1, 0 );
4769
4770   createPopupItem( SMESHOp::OpUpdate,           OB + " " + View, mesh_part );
4771   createPopupItem( SMESHOp::OpAutoColor,        OB + " " + View, mesh, "&& (not isAutoColor)" );
4772   createPopupItem( SMESHOp::OpDisableAutoColor, OB + " " + View, mesh, "&& isAutoColor" );
4773   popupMgr()->insert( separator(), -1, 0 );
4774
4775   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
4776   QString aType = QString( "%1type in {%2}" ).arg( lc );
4777   aType = aType.arg( mesh_part );
4778   QString aMeshInVTK = aClient + "&&" + aType;
4779
4780   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
4781   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
4782   QString aSelCount = QString( "%1 > 0" ).arg( dc );
4783
4784   //-------------------------------------------------
4785   // Numbering
4786   //-------------------------------------------------
4787   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
4788
4789   popupMgr()->insert( action( SMESHOp::OpNumberingNodes ), anId, -1 );
4790   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4791   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4792
4793   popupMgr()->insert( action( SMESHOp::OpNumberingElements ), anId, -1 );
4794   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4795   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4796
4797   popupMgr()->insert( separator(), -1, -1 );
4798
4799   //-------------------------------------------------
4800   // Display Mode
4801   //-------------------------------------------------
4802   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4803
4804   popupMgr()->insert( action( SMESHOp::OpDMWireframe ), anId, -1 );
4805   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4806   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4807
4808   popupMgr()->insert( action( SMESHOp::OpDMShading ), anId, -1 );
4809   popupMgr()->setRule( action( SMESHOp::OpDMShading ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4810   popupMgr()->setRule( action( SMESHOp::OpDMShading ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4811
4812   popupMgr()->insert( action( SMESHOp::OpDMNodes ), anId, -1 );
4813   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), aMeshInVTK + "&&" + hasNodes + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4814   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4815
4816   popupMgr()->insert( separator(), anId, -1 );
4817
4818   popupMgr()->insert( action( SMESHOp::OpDMShrink ), anId, -1 );
4819   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4820   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4821
4822   //-------------------------------------------------
4823   // Display Entity
4824   //-------------------------------------------------
4825   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4826
4827   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4828
4829   popupMgr()->insert( action( SMESHOp::OpDE0DElements ), anId, -1 );
4830   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4831   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4832
4833   popupMgr()->insert( action( SMESHOp::OpDEEdges ), anId, -1 );
4834   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4835   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4836
4837   popupMgr()->insert( action( SMESHOp::OpDEFaces ), anId, -1 );
4838   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4839   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4840
4841   popupMgr()->insert( action( SMESHOp::OpDEVolumes ), anId, -1 );
4842   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4843   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4844
4845   popupMgr()->insert( action( SMESHOp::OpDEBalls ), anId, -1 );
4846   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), aDiffElemsInVTK + "&& isVisible &&" + hasBalls, QtxPopupMgr::VisibleRule );
4847   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), "{'BallElem'} in entityMode", QtxPopupMgr::ToggleRule );
4848
4849   popupMgr()->insert( separator(), anId, -1 );
4850
4851   popupMgr()->insert( action( SMESHOp::OpDEChoose ), anId, -1 );
4852   popupMgr()->setRule( action( SMESHOp::OpDEChoose ), aClient + "&& $type in {" + mesh + "} &&" + hasDifferentObjElems, QtxPopupMgr::VisibleRule );
4853
4854   popupMgr()->insert( separator(), anId, -1 );
4855
4856   popupMgr()->insert( action( SMESHOp::OpDEAllEntity ), anId, -1 );
4857   popupMgr()->setRule( action( SMESHOp::OpDEAllEntity ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4858
4859
4860   //-------------------------------------------------
4861   // Representation of the 2D Quadratic elements
4862   //-------------------------------------------------
4863   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4864   popupMgr()->insert( action( SMESHOp::OpRepresentationLines ), anId, -1 );
4865   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), aMeshInVTK + "&& isVisible && isQuadratic",QtxPopupMgr::VisibleRule );
4866   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4867
4868   popupMgr()->insert( action( SMESHOp::OpRepresentationArcs ), anId, -1 );
4869   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), aMeshInVTK + "&& isVisible && isQuadratic", QtxPopupMgr::VisibleRule );
4870   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4871
4872   //-------------------------------------------------
4873   // Orientation of faces
4874   //-------------------------------------------------
4875   popupMgr()->insert( action( SMESHOp::OpOrientationOnFaces ), -1, -1 );
4876   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4877   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4878
4879   //-------------------------------------------------
4880   // Color / Size
4881   //-------------------------------------------------
4882   popupMgr()->insert( action( SMESHOp::OpProperties ), -1, -1 );
4883   popupMgr()->setRule( action( SMESHOp::OpProperties ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4884
4885   //-------------------------------------------------
4886   // Transparency
4887   //-------------------------------------------------
4888   popupMgr()->insert( action( SMESHOp::OpTransparency ), -1, -1 );
4889   popupMgr()->setRule( action( SMESHOp::OpTransparency ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4890
4891   //-------------------------------------------------
4892   // Controls
4893   //-------------------------------------------------
4894   QString
4895     aMeshInVtkHasNodes   = aMeshInVTK + "&&" + hasNodes,
4896     aMeshInVtkHasEdges   = aMeshInVTK + "&&" + hasEdges,
4897     aMeshInVtkHasFaces   = aMeshInVTK + "&&" + hasFaces,
4898     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4899
4900   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4901
4902   popupMgr()->insert( action( SMESHOp::OpReset ), anId, -1 ); // RESET
4903   popupMgr()->setRule( action( SMESHOp::OpReset ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4904
4905   popupMgr()->insert( separator(), anId, -1 );
4906
4907   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4908
4909   popupMgr()->insert( action( SMESHOp::OpFreeNode ), aSubId, -1 );
4910   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4911   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4912
4913   popupMgr()->insert ( action( SMESHOp::OpEqualNode ), aSubId, -1 );
4914   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4915   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4916
4917   // popupMgr()->insert( action( SMESHOp::OpNodeConnectivityNb ), aSubId, -1 );
4918   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4919   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), "controlMode = 'eNodeConnectivityNb'", QtxPopupMgr::ToggleRule );
4920
4921   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4922
4923   popupMgr()->insert( action( SMESHOp::OpFreeBorder ), aSubId, -1 );
4924   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), aMeshInVTK + "&&" + hasEdges + "&&" + hasFacesOrVolumes, QtxPopupMgr::VisibleRule );
4925   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4926
4927   popupMgr()->insert( action( SMESHOp::OpLength ), aSubId, -1 );
4928   popupMgr()->setRule( action( SMESHOp::OpLength ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4929   popupMgr()->setRule( action( SMESHOp::OpLength ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4930
4931   popupMgr()->insert( action( SMESHOp::OpConnection ), aSubId, -1 );
4932   popupMgr()->setRule( action( SMESHOp::OpConnection ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4933   popupMgr()->setRule( action( SMESHOp::OpConnection ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4934   popupMgr()->insert ( action( SMESHOp::OpEqualEdge ), aSubId, -1 ); // EQUAL_EDGE
4935   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4936   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4937
4938   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4939
4940   popupMgr()->insert( action( SMESHOp::OpFreeEdge ), aSubId, -1 );
4941   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4942   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4943
4944   popupMgr()->insert ( action( SMESHOp::OpFreeFace ), aSubId, -1 );
4945   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4946                                        QtxPopupMgr::VisibleRule );
4947   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4948
4949   popupMgr()->insert ( action( SMESHOp::OpLength2D ), aSubId, -1 );
4950   popupMgr()->setRule( action( SMESHOp::OpLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4951   popupMgr()->setRule( action( SMESHOp::OpLength2D ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4952
4953   popupMgr()->insert ( action( SMESHOp::OpConnection2D ), aSubId, -1 );
4954   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4955   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4956
4957   popupMgr()->insert ( action( SMESHOp::OpArea ), aSubId, -1 );
4958   popupMgr()->setRule( action( SMESHOp::OpArea ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4959   popupMgr()->setRule( action( SMESHOp::OpArea ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4960
4961   popupMgr()->insert ( action( SMESHOp::OpTaper ), aSubId, -1 );
4962   popupMgr()->setRule( action( SMESHOp::OpTaper ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4963   popupMgr()->setRule( action( SMESHOp::OpTaper ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4964
4965   popupMgr()->insert ( action( SMESHOp::OpAspectRatio ), aSubId, -1 );
4966   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4967   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4968
4969   popupMgr()->insert ( action( SMESHOp::OpMinimumAngle ), aSubId, -1 );
4970   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4971   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4972
4973   popupMgr()->insert ( action( SMESHOp::OpWarpingAngle ), aSubId, -1 );
4974   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4975   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4976
4977   popupMgr()->insert ( action( SMESHOp::OpSkew ), aSubId, -1 );
4978   popupMgr()->setRule( action( SMESHOp::OpSkew ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4979   popupMgr()->setRule( action( SMESHOp::OpSkew ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4980
4981   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength2D ), aSubId, -1 );
4982   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4983   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4984
4985   popupMgr()->insert ( action( SMESHOp::OpBareBorderFace ), aSubId, -1 );
4986   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4987   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4988
4989   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedFace ), aSubId, -1 );
4990   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4991   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4992
4993   popupMgr()->insert ( action( SMESHOp::OpEqualFace ), aSubId, -1 );
4994   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4995   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4996
4997   popupMgr()->insert ( action( SMESHOp::OpDeflection2D ), aSubId, -1 );
4998   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), aMeshInVtkHasFaces + " && hasGeomReference", QtxPopupMgr::VisibleRule );
4999   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), "controlMode = 'eDeflection2D'", QtxPopupMgr::ToggleRule );
5000
5001   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
5002
5003   popupMgr()->insert ( action( SMESHOp::OpAspectRatio3D  ), aSubId, -1 );
5004   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5005   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
5006
5007   popupMgr()->insert ( action( SMESHOp::OpVolume ), aSubId, -1 );
5008   popupMgr()->setRule( action( SMESHOp::OpVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5009   popupMgr()->setRule( action( SMESHOp::OpVolume ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
5010
5011   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength3D ), aSubId, -1 );
5012   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5013   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
5014
5015   popupMgr()->insert ( action( SMESHOp::OpBareBorderVolume ), aSubId, -1 );
5016   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5017   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
5018
5019   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedVolume ), aSubId, -1 );
5020   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5021   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
5022
5023   popupMgr()->insert ( action( SMESHOp::OpEqualVolume  ), aSubId, -1 );
5024   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5025   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
5026
5027   popupMgr()->insert( separator(), anId, -1 );
5028
5029   popupMgr()->insert( action( SMESHOp::OpShowScalarBar ), anId, -1 );
5030   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
5031   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone' && isScalarBarVisible", QtxPopupMgr::ToggleRule );
5032   popupMgr()->insert( action( SMESHOp::OpScalarBarProperties ), anId, -1 );
5033   popupMgr()->setRule( action( SMESHOp::OpScalarBarProperties ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
5034
5035   popupMgr()->insert( separator(), anId, -1 );
5036
5037   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
5038
5039   popupMgr()->insert( action( SMESHOp::OpSaveDistribution ), aSubId, -1 );
5040   popupMgr()->setRule( action( SMESHOp::OpSaveDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5041
5042   popupMgr()->insert( action( SMESHOp::OpShowDistribution ), aSubId, -1 );
5043   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5044   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor && isScalarBarVisible && isDistributionVisible", QtxPopupMgr::ToggleRule);
5045
5046 #ifndef DISABLE_PLOT2DVIEWER
5047   popupMgr()->insert( action( SMESHOp::OpPlotDistribution ), aSubId, -1 );
5048   popupMgr()->setRule( action( SMESHOp::OpPlotDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5049 #endif
5050
5051   //-------------------------------------------------
5052   // Show / Hide
5053   //-------------------------------------------------
5054   popupMgr()->insert( separator(), -1, -1 );
5055   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
5056     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
5057   popupMgr()->insert( action( SMESHOp::OpShow ), -1, -1 );
5058   popupMgr()->setRule( action( SMESHOp::OpShow ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
5059
5060   popupMgr()->insert( action( SMESHOp::OpHide ), -1, -1 );
5061   popupMgr()->setRule( action( SMESHOp::OpHide ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
5062
5063   popupMgr()->insert( action( SMESHOp::OpShowOnly ), -1, -1 );
5064   popupMgr()->setRule( action( SMESHOp::OpShowOnly ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
5065
5066   popupMgr()->insert( separator(), -1, -1 );
5067
5068   //-------------------------------------------------
5069   // Clipping
5070   //-------------------------------------------------
5071   popupMgr()->insert( action( SMESHOp::OpClipping ), -1, -1 );
5072   popupMgr()->setRule( action( SMESHOp::OpClipping ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
5073
5074   popupMgr()->insert( separator(), -1, -1 );
5075
5076   popupMgr()->insert( action( SMESHOp::OpSortChild ), -1, -1 );
5077   popupMgr()->setRule( action( SMESHOp::OpSortChild ), "$component={'SMESH'} and client='ObjectBrowser' and isContainer and nbChildren>1", QtxPopupMgr::VisibleRule );
5078   popupMgr()->insert( separator(), -1, -1 );
5079
5080   popupMgr()->insert( action( SMESHOp::OpBreakLink), -1, -1 );
5081   popupMgr()->setRule( action( SMESHOp::OpBreakLink), "$component={'SHAPERSTUDY'} and client='ObjectBrowser' and canBreakLink", QtxPopupMgr::VisibleRule );
5082
5083   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
5084            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
5085
5086   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
5087            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
5088 }
5089
5090 //================================================================================
5091 /*!
5092  * \brief Return true if SMESH or GEOM objects are selected.
5093  * Is called form LightApp_Module::activateModule() which clear selection if
5094  * not isSelectionCompatible()
5095  */
5096 //================================================================================
5097
5098 bool SMESHGUI::isSelectionCompatible()
5099 {
5100   bool isCompatible = true;
5101   SALOME_ListIO selected;
5102   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
5103     Sel->selectedObjects( selected );
5104
5105   SALOME_ListIteratorOfListIO It( selected );
5106   for ( ; isCompatible && It.More(); It.Next())
5107     isCompatible =
5108       ( strcmp("GEOM",        It.Value()->getComponentDataType()) == 0 ) ||
5109       ( strcmp("SHAPERSTUDY", It.Value()->getComponentDataType()) == 0 ) ||
5110       ( strcmp("SMESH",       It.Value()->getComponentDataType()) == 0 );
5111
5112   return isCompatible;
5113 }
5114
5115
5116 bool SMESHGUI::reusableOperation( const int id )
5117 {
5118   // compute, evaluate and precompute are not reusable operations
5119   return ( id == SMESHOp::OpCompute || id == SMESHOp::OpPreCompute || id == SMESHOp::OpEvaluate || id == SMESHOp::OpRecompute ) ? false : SalomeApp_Module::reusableOperation( id );
5120 }
5121
5122 namespace
5123 {
5124   QString wrap(const QString& text, const QString& tag)
5125   { return QString("<%1>%2</%3>").arg(tag).arg(text).arg(tag);}
5126 }
5127
5128 bool SMESHGUI::activateModule( SUIT_Study* study )
5129 {
5130   bool res = SalomeApp_Module::activateModule( study );
5131
5132   setMenuShown( true );
5133   setToolShown( true );
5134
5135   // Fill in Help Panel
5136   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
5137   app->infoPanel()->setTitle(tr("INFO_WELCOME_TO_SMESH"));
5138
5139   int gb = app->infoPanel()->addGroup(tr("INFO_GRP_CREATE_MESH"));
5140   QString lab;
5141   QStringList items;
5142   lab =       tr("INFO_DEFINE_ALGOS") + "<br/>";
5143   lab = lab + tr("INFO_DEFINE_HYPOS") + "<br/>";
5144   lab = lab + tr("INFO_COMPUTE") + "<br/>";
5145   lab = lab + tr("INFO_REFINE") + ":";
5146   items << wrap(tr("INFO_REFINE_LOCAL_SIZE"), "li")
5147         << wrap(tr("INFO_REFINE_SUBMESH"), "li");
5148   lab = lab + wrap(items.join(""), "ul");
5149   items.clear();
5150
5151   app->infoPanel()->addLabel(lab, gb);
5152
5153   gb = app->infoPanel()->addGroup(tr("INFO_GRP_IMPORT_MESH"));
5154   items << wrap("UNV", "li")
5155         << wrap("MED", "li")
5156         << wrap("STL", "li")
5157         << wrap("CGNS", "li")
5158         << wrap("GMF", "li");
5159   lab = tr("INFO_AVAILABLE_FORMATS") + ":" + wrap(items.join(""), "ul");
5160   items.clear();
5161
5162   app->infoPanel()->addLabel(lab, gb);
5163
5164   gb = app->infoPanel()->addGroup(tr("INFO_GRP_CHECK_MESH"));
5165   lab = tr("INFO_DISPLAY") + "<br/>";
5166   items << wrap(tr("INFO_QUALITY_AREA"), "li")
5167         << wrap(tr("INFO_QUALITY_VOLUME"), "li")
5168         << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
5169         << wrap("...", "li");
5170   lab = lab + tr("INFO_QUALITY_INFO") + ":" + wrap(items.join(""), "ul");
5171   items.clear();
5172   lab = lab + tr("INFO_CLIPPING");
5173
5174   app->infoPanel()->addLabel(lab, gb);
5175   // << Help Panel
5176
5177   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
5178   PyGILState_STATE gstate = PyGILState_Ensure();
5179   PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
5180   if ( !pluginsmanager ) {
5181     PyErr_Print();
5182   }
5183   else {
5184     PyObject* result = PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toUtf8().data(),tr("SMESH_PLUGINS_OTHER").toUtf8().data());
5185     if ( !result )
5186       PyErr_Print();
5187     Py_XDECREF(result);
5188   }
5189   PyGILState_Release(gstate);
5190   // end of SMESH plugins loading
5191
5192   // Reset actions accelerator keys
5193   action(SMESHOp::OpDelete)->setEnabled(true); // Delete: Key_Delete
5194
5195   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
5196   GetSMESHGen()->UpdateStudy();
5197
5198   // get all view currently opened in the study and connect their signals  to
5199   // the corresponding slots of the class.
5200   SUIT_Desktop* aDesk = study->application()->desktop();
5201   if ( aDesk ) {
5202     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
5203     SUIT_ViewWindow* wnd;
5204     foreach ( wnd, wndList )
5205     {
5206       connectView( wnd );
5207
5208       // remove actors whose objects are removed in GetSMESHGen()->UpdateStudy()
5209       SMESH::UpdateActorsAfterUpdateStudy(wnd);
5210
5211       wnd->update();
5212     }
5213   }
5214
5215   Py_XDECREF(pluginsmanager);
5216   return res;
5217 }
5218
5219 bool SMESHGUI::deactivateModule( SUIT_Study* study )
5220 {
5221   setMenuShown( false );
5222   setToolShown( false );
5223
5224   EmitSignalCloseAllDialogs();
5225
5226   // Unset actions accelerator keys
5227   action(SMESHOp::OpDelete)->setEnabled(false); // Delete: Key_Delete
5228
5229   return SalomeApp_Module::deactivateModule( study );
5230 }
5231
5232 void SMESHGUI::studyClosed( SUIT_Study* s )
5233 {
5234   if( !s )
5235     return;
5236   SMESH::RemoveVisuData();
5237   SalomeApp_Module::studyClosed( s );
5238 }
5239
5240 void SMESHGUI::OnGUIEvent()
5241 {
5242   const QObject* obj = sender();
5243   if ( !obj || !obj->inherits( "QAction" ) )
5244     return;
5245   int id = actionId((QAction*)obj);
5246   if ( id != -1 )
5247     OnGUIEvent( id );
5248 }
5249
5250 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
5251 {
5252   if ( CORBA::is_nil( myComponentSMESH ) )
5253   {
5254     SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
5255     return aGUI.myComponentSMESH;
5256   }
5257   return myComponentSMESH;
5258 }
5259
5260 QString SMESHGUI::engineIOR() const
5261 {
5262   CORBA::ORB_var anORB = getApp()->orb();
5263   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
5264   return QString( anIOR.in() );
5265 }
5266
5267 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
5268 {
5269   SalomeApp_Module::contextMenuPopup( client, menu, title );
5270   SALOME_ListIO lst;
5271   selectionMgr()->selectedObjects( lst );
5272   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
5273     Handle(SALOME_InteractiveObject) io = lst.First();
5274     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
5275     _PTR(Study) study = appStudy->studyDS();
5276     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
5277     if ( obj ) {
5278       QString aName = SMESH::fromUtf8( obj->GetName());
5279       while ( !aName.isEmpty() && aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
5280         aName.remove(( aName.length() - 1 ), 1 );
5281       title = aName;
5282     }
5283   }
5284 }
5285
5286 LightApp_Selection* SMESHGUI::createSelection() const
5287 {
5288   return new SMESHGUI_Selection();
5289 }
5290
5291 void SMESHGUI::windows( QMap<int, int>& aMap ) const
5292 {
5293   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
5294   aMap.insert( SalomeApp_Application::WT_NoteBook, Qt::LeftDockWidgetArea );
5295   aMap.insert( SalomeApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
5296 #ifndef DISABLE_PYCONSOLE
5297   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
5298 #endif
5299 }
5300
5301 void SMESHGUI::viewManagers( QStringList& list ) const
5302 {
5303   list.append( SVTK_Viewer::Type() );
5304 }
5305
5306 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
5307 {
5308   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
5309     SMESH::UpdateSelectionProp( this );
5310
5311     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
5312     for(int i = 0; i < aViews.count() ; i++){
5313       SUIT_ViewWindow *sf = aViews[i];
5314       connectView( sf );
5315     }
5316     EmitSignalActivatedViewManager();
5317   }
5318 }
5319
5320 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
5321 {
5322   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
5323     myClippingPlaneInfoMap.erase( theViewManager );
5324 }
5325
5326 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
5327 {
5328   theActor->AddObserver( SMESH::DeleteActorEvent,
5329                          myEventCallbackCommand.GetPointer(),
5330                          myPriority );
5331 }
5332
5333 void SMESHGUI::ProcessEvents( vtkObject* theObject,
5334                               unsigned long theEvent,
5335                               void* theClientData,
5336                               void* /*theCallData*/ )
5337 {
5338   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
5339     if( theObject && (int) theEvent == SMESH::DeleteActorEvent ) {
5340       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
5341         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
5342         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
5343         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
5344           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
5345           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
5346           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
5347             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
5348             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
5349             SMESH::TActorList::iterator anIter3 = anActorList.begin();
5350             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
5351               if( anActor == *anIter3 ) {
5352                 anActorList.erase( anIter3 );
5353                 break;
5354               }
5355             }
5356           }
5357         }
5358       }
5359     }
5360   }
5361 }
5362
5363 void SMESHGUI::createPreferences()
5364 {
5365   // General tab ------------------------------------------------------------------------
5366   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
5367
5368   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
5369   setPreferenceProperty( autoUpdate, "columns", 2 );
5370   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
5371   setPreferenceProperty( lim, "min",  0 );
5372   setPreferenceProperty( lim, "max",  100000000 );
5373   setPreferenceProperty( lim, "step", 1000 );
5374   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5375   addPreference( tr( "PREF_INCREMENTAL_LIMIT" ), autoUpdate, LightApp_Preferences::Bool, "SMESH", "incremental_limit" );
5376
5377   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE_GROUP" ), genTab );
5378   setPreferenceProperty( dispgroup, "columns", 2 );
5379
5380   addPreference( tr( "PREF_FITALL_ON_DISPLAYONLY" ), dispgroup, LightApp_Preferences::Bool, "SMESH", "fitall_on_displayonly" );
5381
5382   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
5383   QStringList modes;
5384   modes.append( tr("MEN_WIRE") );
5385   modes.append( tr("MEN_SHADE") );
5386   modes.append( tr("MEN_NODES") );
5387   modes.append( tr("MEN_SHRINK") );
5388   QList<QVariant> indices;
5389   indices.append( 0 );
5390   indices.append( 1 );
5391   indices.append( 2 );
5392   indices.append( 3 );
5393   setPreferenceProperty( dispmode, "strings", modes );
5394   setPreferenceProperty( dispmode, "indexes", indices );
5395
5396   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE_GROUP" ), genTab );
5397   setPreferenceProperty( arcgroup, "columns", 2 );
5398   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
5399   QStringList quadraticModes;
5400   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
5401   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
5402   indices.clear();
5403   indices.append( 0 );
5404   indices.append( 1 );
5405   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
5406   setPreferenceProperty( quadraticmode, "indexes", indices );
5407
5408   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
5409                               "SMESH", "max_angle" );
5410   setPreferenceProperty( maxAngle, "min", 1 );
5411   setPreferenceProperty( maxAngle, "max", 90 );
5412
5413   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
5414   setPreferenceProperty( qaGroup, "columns", 2 );
5415   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
5416   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
5417   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
5418   setPreferenceProperty( prec, "min", 0 );
5419   setPreferenceProperty( prec, "max", 100 );
5420   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
5421   setPreferenceProperty( doubleNodesTol, "precision", 10 );
5422   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
5423   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
5424   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
5425
5426   /*
5427   int cinc = addPreference(tr("PREF_CONTROLS_INCREMENT"), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_increment");
5428   setPreferenceProperty( cinc, "min", 0 );
5429   setPreferenceProperty( cinc, "max", 5 );
5430   */
5431
5432   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
5433   setPreferenceProperty( exportgroup, "columns", 2 );
5434   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
5435   addPreference( tr( "PREF_SHOW_WARN" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "show_warning" );
5436   addPreference( tr( "PREF_MED_SAVE_NUMS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "med_save_numbers" );
5437   int zTol = addPreference( tr( "PREF_ZTOLERANCE" ), exportgroup, LightApp_Preferences::DblSpin, "SMESH", "med_ztolerance" );
5438   setPreferenceProperty( zTol, "precision", 10 );
5439   setPreferenceProperty( zTol, "min", 0.0000000001 );
5440   setPreferenceProperty( zTol, "max", 1000000.0 );
5441   setPreferenceProperty( zTol, "step", 1. );
5442   //addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
5443
5444   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
5445   setPreferenceProperty( computeGroup, "columns", 2 );
5446   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
5447   modes.clear();
5448   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
5449   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
5450   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
5451   indices.clear();
5452   indices.append( 0 );
5453   indices.append( 1 );
5454   indices.append( 2 );
5455   setPreferenceProperty( notifyMode, "strings", modes );
5456   setPreferenceProperty( notifyMode, "indexes", indices );
5457
5458   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
5459   setPreferenceProperty( infoGroup, "columns", 2 );
5460   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
5461   modes.clear();
5462   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
5463   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
5464   indices.clear();
5465   indices.append( 0 );
5466   indices.append( 1 );
5467   setPreferenceProperty( elemInfo, "strings", modes );
5468   setPreferenceProperty( elemInfo, "indexes", indices );
5469   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
5470   setPreferenceProperty( nodesLim, "min", 0 );
5471   setPreferenceProperty( nodesLim, "max", 10000000 );
5472   setPreferenceProperty( nodesLim, "step", 10000 );
5473   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5474   int ctrlLim = addPreference( tr( "PREF_CTRL_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_controls_limit" );
5475   setPreferenceProperty( ctrlLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5476   setPreferenceProperty( ctrlLim, "min", 0 );
5477   setPreferenceProperty( ctrlLim, "max", 10000000 );
5478   setPreferenceProperty( ctrlLim, "step", 1000 );
5479   addPreference( tr( "PREF_ELEM_INFO_GRP_DETAILS" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "elem_info_grp_details" );
5480   addPreference( tr( "PREF_DUMP_BASE_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_base" );
5481   addPreference( tr( "PREF_DUMP_ELEM_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_elem" );
5482   addPreference( tr( "PREF_DUMP_ADD_INFO"  ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_add" );
5483   addPreference( tr( "PREF_DUMP_CTRL_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_ctrl" );
5484
5485   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
5486   setPreferenceProperty( segGroup, "columns", 2 );
5487   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
5488                               "SMESH", "segmentation" );
5489   setPreferenceProperty( segLen, "min", 1 );
5490   setPreferenceProperty( segLen, "max", 10000000 );
5491   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
5492                              "SMESH", "nb_segments_per_edge" );
5493   setPreferenceProperty( nbSeg, "min", 1 );
5494   setPreferenceProperty( nbSeg, "max", 10000000 );
5495   addPreference( tr( "PREF_USE_MESHGEMS_HYPOSET" ), segGroup, LightApp_Preferences::Bool, "SMESH", "use-meshgems-hypo-sets" );
5496
5497   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
5498   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
5499                  "SMESH", "forget_mesh_on_hyp_modif" );
5500
5501
5502   // Quantities with individual precision settings
5503   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
5504   setPreferenceProperty( precGroup, "columns", 2 );
5505
5506   const int nbQuantities = 6;
5507   int precs[nbQuantities], ii = 0;
5508   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
5509                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
5510   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
5511                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
5512   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
5513                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
5514   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
5515                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
5516   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
5517                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
5518   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
5519                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
5520
5521   // Set property for precision value for spinboxes
5522   for ( ii = 0; ii < nbQuantities; ii++ ){
5523     setPreferenceProperty( precs[ii], "min", -14 );
5524     setPreferenceProperty( precs[ii], "max", 14 );
5525     setPreferenceProperty( precs[ii], "precision", 2 );
5526   }
5527
5528   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
5529   setPreferenceProperty( previewGroup, "columns", 2 );
5530   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
5531   setPreferenceProperty( chunkSize, "min",  1 );
5532   setPreferenceProperty( chunkSize, "max",  1000 );
5533   setPreferenceProperty( chunkSize, "step", 50 );
5534
5535   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
5536   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
5537
5538   // Mesh tab ------------------------------------------------------------------------
5539   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
5540   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
5541   setPreferenceProperty( nodeGroup, "columns", 3 );
5542
5543   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
5544
5545   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
5546
5547   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5548   QList<QVariant> aMarkerTypeIndicesList;
5549   QList<QVariant> aMarkerTypeIconsList;
5550   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
5551     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
5552     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
5553     aMarkerTypeIndicesList << i;
5554     aMarkerTypeIconsList << pixmap;
5555   }
5556   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
5557   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
5558
5559   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
5560
5561   QList<QVariant> aMarkerScaleIndicesList;
5562   QStringList     aMarkerScaleValuesList;
5563   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
5564     aMarkerScaleIndicesList << i;
5565     //aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
5566     aMarkerScaleValuesList  << QString::number( i );
5567   }
5568   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
5569   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
5570
5571   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
5572   //setPreferenceProperty( elemGroup, "columns", 2 );
5573
5574   int ColorId = addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
5575   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
5576   ColorId = addPreference( tr( "PREF_VOLUME" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "volume_color" );
5577   setPreferenceProperty( ColorId, "text", tr("PREF_REVERSEDVOLUME") );
5578   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
5579   addPreference( tr( "PREF_BALL_COLOR" ), elemGroup, LightApp_Preferences::Color, "SMESH", "ball_elem_color" );
5580   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
5581   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
5582   addPreference( tr( "PREF_PREVIEW_COLOR"  ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "preview_color" );
5583
5584
5585   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
5586   setPreferenceProperty( grpGroup, "columns", 2 );
5587
5588   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
5589   addPreference( tr( "PREF_GRP_DEF_COLOR" ), grpGroup, LightApp_Preferences::Color, "SMESH", "default_grp_color" );
5590
5591   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
5592                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
5593   /* int ballSize = addPreference(tr("PREF_BALL_SIZE"), elemGroup,
5594      LightApp_Preferences::IntSpin, "SMESH", "ball_elem_size"); */
5595   int ballDiameter = addPreference(tr("PREF_BALL_DIAMETER"), elemGroup,
5596                                    LightApp_Preferences::DblSpin, "SMESH", "ball_elem_diameter");
5597   int ballScale    = addPreference(tr("PREF_BALL_SCALE"), elemGroup,
5598                                    LightApp_Preferences::DblSpin, "SMESH", "ball_elem_scale");
5599   int elemW        = addPreference(tr("PREF_WIDTH"), elemGroup,
5600                                    LightApp_Preferences::IntSpin, "SMESH", "element_width");
5601   int outW         = addPreference(tr("PREF_OUTLINE_WIDTH"), elemGroup,
5602                                    LightApp_Preferences::IntSpin, "SMESH", "outline_width");
5603   int shrink       = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
5604                                    LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
5605
5606   setPreferenceProperty( size0d, "min", 1 );
5607   setPreferenceProperty( size0d, "max", 10 );
5608
5609   // setPreferenceProperty( ballSize, "min", 1 );
5610   // setPreferenceProperty( ballSize, "max", 10 );
5611
5612   setPreferenceProperty( ballDiameter, "min", 1e-7 );
5613   setPreferenceProperty( ballDiameter, "max", 1e9 );
5614   setPreferenceProperty( ballDiameter, "step", 0.1 );
5615
5616   setPreferenceProperty( ballScale, "min", 1e-2 );
5617   setPreferenceProperty( ballScale, "max", 1e7 );
5618   setPreferenceProperty( ballScale, "step", 0.5 );
5619
5620   setPreferenceProperty( elemW, "min", 1 );
5621   setPreferenceProperty( elemW, "max", 5 );
5622
5623   setPreferenceProperty( outW, "min", 1 );
5624   setPreferenceProperty( outW, "max", 5 );
5625
5626   setPreferenceProperty( shrink, "min", 0 );
5627   setPreferenceProperty( shrink, "max", 100 );
5628
5629   int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
5630   setPreferenceProperty( numGroup, "columns", 2 );
5631
5632   addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
5633   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
5634
5635   addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
5636   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
5637
5638   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
5639   setPreferenceProperty( orientGroup, "columns", 1 );
5640
5641   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
5642   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
5643
5644   setPreferenceProperty( orientScale, "min", 0.05 );
5645   setPreferenceProperty( orientScale, "max", 0.5 );
5646   setPreferenceProperty( orientScale, "step", 0.05 );
5647
5648   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
5649
5650   // Selection tab ------------------------------------------------------------------------
5651   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
5652
5653   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
5654   setPreferenceProperty( selGroup, "columns", 2 );
5655
5656   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
5657   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
5658
5659   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
5660   setPreferenceProperty( preGroup, "columns", 2 );
5661
5662   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
5663
5664   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
5665   setPreferenceProperty( precSelGroup, "columns", 2 );
5666
5667   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
5668   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
5669   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
5670
5671   int sinc = addPreference(tr("PREF_SELECTION_INCREMENT"), selTab, LightApp_Preferences::IntSpin, "SMESH", "selection_increment");
5672   setPreferenceProperty( sinc, "min", 0 );
5673   setPreferenceProperty( sinc, "max", 5 );
5674
5675   // Scalar Bar tab ------------------------------------------------------------------------
5676   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
5677   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
5678   setPreferenceProperty( fontGr, "columns", 2 );
5679
5680   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
5681   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
5682
5683   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
5684   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
5685
5686   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
5687   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
5688
5689   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
5690   setPreferenceProperty( numcol, "min", 2 );
5691   setPreferenceProperty( numcol, "max", 256 );
5692
5693   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
5694   setPreferenceProperty( numlab, "min", 2 );
5695   setPreferenceProperty( numlab, "max", 65 );
5696
5697   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
5698   setPreferenceProperty( orientGr, "columns", 2 );
5699   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
5700   QStringList orients;
5701   orients.append( tr( "SMESH_VERTICAL" ) );
5702   orients.append( tr( "SMESH_HORIZONTAL" ) );
5703   indices.clear(); indices.append( 0 ); indices.append( 1 );
5704   setPreferenceProperty( orient, "strings", orients );
5705   setPreferenceProperty( orient, "indexes", indices );
5706
5707   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
5708   setPreferenceProperty( posVSizeGr, "columns", 2 );
5709   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
5710   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
5711   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
5712   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
5713   setPreferenceProperty( xv, "step", 0.1 );
5714   setPreferenceProperty( xv, "min", 0.0 );
5715   setPreferenceProperty( xv, "max", 1.0 );
5716   setPreferenceProperty( yv, "step", 0.1 );
5717   setPreferenceProperty( yv, "min", 0.0 );
5718   setPreferenceProperty( yv, "max", 1.0 );
5719   setPreferenceProperty( wv, "step", 0.1 );
5720   setPreferenceProperty( wv, "min", 0.0 );
5721   setPreferenceProperty( wv, "max", 1.0 );
5722   setPreferenceProperty( hv, "min", 0.0 );
5723   setPreferenceProperty( hv, "max", 1.0 );
5724   setPreferenceProperty( hv, "step", 0.1 );
5725
5726   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
5727   setPreferenceProperty( posHSizeGr, "columns", 2 );
5728   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
5729   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
5730   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
5731   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
5732   setPreferenceProperty( xv, "min", 0.0 );
5733   setPreferenceProperty( xv, "max", 1.0 );
5734   setPreferenceProperty( xv, "step", 0.1 );
5735   setPreferenceProperty( xh, "min", 0.0 );
5736   setPreferenceProperty( xh, "max", 1.0 );
5737   setPreferenceProperty( xh, "step", 0.1 );
5738   setPreferenceProperty( yh, "min", 0.0 );
5739   setPreferenceProperty( yh, "max", 1.0 );
5740   setPreferenceProperty( yh, "step", 0.1 );
5741   setPreferenceProperty( wh, "min", 0.0 );
5742   setPreferenceProperty( wh, "max", 1.0 );
5743   setPreferenceProperty( wh, "step", 0.1 );
5744   setPreferenceProperty( hh, "min", 0.0 );
5745   setPreferenceProperty( hh, "max", 1.0 );
5746   setPreferenceProperty( hh, "step", 0.1 );
5747
5748   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
5749   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
5750   setPreferenceProperty( distributionGr, "columns", 3 );
5751   QStringList types;
5752   types.append( tr( "SMESH_MONOCOLOR" ) );
5753   types.append( tr( "SMESH_MULTICOLOR" ) );
5754   indices.clear(); indices.append( 0 ); indices.append( 1 );
5755   setPreferenceProperty( coloringType, "strings", types );
5756   setPreferenceProperty( coloringType, "indexes", indices );
5757   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
5758
5759   // Adaptation - begin
5760 #ifndef DISABLE_MG_ADAPT
5761   // Adaptation tab ------------------------------------------------------------------------
5762   int adaptTab = addPreference( tr( "ADAPT_PREF_TAB_GENERAL" ) );
5763   int bloc, pref ;
5764   // MG-Adapt
5765   bloc = addPreference( tr( "ADAPT_PREF_MG_ADAPT" ), adaptTab );
5766   setPreferenceProperty( bloc, "columns", 1 );
5767   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_FILE_MAILLAGE_OUT" ), bloc, LightApp_Preferences::Bool, "HOMARD", "mg_adapt_file_mesh_out" );
5768   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_PUBLICATION_MAILLAGE_OUT" ), bloc, LightApp_Preferences::Bool, "HOMARD", "mg_adapt_publish_mesh_out" );
5769   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP" ), bloc, LightApp_Preferences::Selector, "HOMARD", "mg_adapt_size_map" );
5770   QStringList aListOfSizeMap;
5771   aListOfSizeMap << tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP_LOCAL" );
5772   aListOfSizeMap << tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP_BACKGROUND" );
5773   aListOfSizeMap << tr( "ADAPT_PREF_NONE" );;
5774   setPreferenceProperty( pref, "strings", aListOfSizeMap );
5775   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP" ), bloc, LightApp_Preferences::Selector, "HOMARD", "mg_adapt_time_step" );
5776   QStringList aListOfTimeStep;
5777   aListOfTimeStep << tr( "ADAPT_PREF_NONE" );
5778   aListOfTimeStep << tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP_LAST" );
5779   aListOfTimeStep << tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP_C" );;
5780   setPreferenceProperty( pref, "strings", aListOfTimeStep );
5781 #endif
5782   // Adaptation - end
5783 }
5784
5785 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
5786 {
5787   if ( sect=="SMESH" ) {
5788     double sbX1 = 0.01, sbY1 = 0.01, sbW = 0.08, sbH = 0.08;
5789     double aTol = 1.00000009999999;
5790     std::string aWarning;
5791     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5792
5793     if ( name ==  "selection_object_color" ||
5794          name == "selection_element_color" ||
5795          name ==         "highlight_color" ||
5796          name == "selection_precision_node"    ||
5797          name == "selection_precision_element" ||
5798          name == "selection_precision_object"  ||
5799          name == "selection_increment")
5800     {
5801       SMESH::UpdateSelectionProp( this );
5802     }
5803     else if (name == "scalar_bar_vertical_x" || name == "scalar_bar_vertical_width")
5804     {
5805       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5806       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
5807       if ( sbX1+sbW > aTol ) {
5808         aWarning = "Origin and Size Vertical: X+Width > 1\n";
5809         sbX1 = 0.01;
5810         sbW  = 0.08;
5811         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5812         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
5813       }
5814     }
5815     else if (name == "scalar_bar_vertical_y" || name == "scalar_bar_vertical_height" )
5816     {
5817       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5818       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
5819       if ( sbY1 + sbH > aTol ) {
5820         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
5821         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5822         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
5823       }
5824     }
5825     else if (name == "scalar_bar_horizontal_x" || name ==  "scalar_bar_horizontal_width")
5826     {
5827       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x",     sbX1);
5828       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
5829       if ( sbX1 + sbW > aTol ) {
5830         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
5831         sbX1=0.1;
5832         sbW =0.08;
5833         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5834         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
5835       }
5836     }
5837     else if (name == "scalar_bar_horizontal_y" || name ==  "scalar_bar_horizontal_height")
5838     {
5839       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y",     sbY1);
5840       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
5841       if ( sbY1 + sbH > aTol ) {
5842         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
5843         sbY1=0.01;
5844         sbH =0.08;
5845         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5846         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
5847       }
5848     }
5849     else if ( name == "segmentation" )
5850     {
5851       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
5852       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
5853     }
5854     else if ( name == "nb_segments_per_edge" )
5855     {
5856       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
5857       myComponentSMESH->SetDefaultNbSegments( nbSeg );
5858     }
5859     else if ( name == "historical_python_dump" || name == "forget_mesh_on_hyp_modif" || name == "default_grp_color" )
5860     {
5861       QString val = aResourceMgr->stringValue( "SMESH", name );
5862       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
5863     }
5864     else if ( name == "numbering_node_color" || name == "numbering_node_font" )
5865     {
5866       SMESH::UpdateFontProp( this );
5867     }
5868     else if ( name == "numbering_elem_color" || name == "numbering_elem_font" )
5869     {
5870       SMESH::UpdateFontProp( this );
5871     }
5872
5873     if ( aWarning.size() != 0 ) {
5874       aWarning += "The default values are applied instead.";
5875       SUIT_MessageBox::warning(SMESHGUI::desktop(),
5876                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
5877                                QObject::tr(aWarning.c_str()));
5878     }
5879   }
5880 }
5881
5882 //================================================================================
5883 /*!
5884  * \brief Update something in accordance with update flags
5885   * \param theFlags - update flags
5886 *
5887 * Update viewer or/and object browser etc. in accordance with update flags ( see
5888 * LightApp_UpdateFlags enumeration ).
5889 */
5890 //================================================================================
5891 void SMESHGUI::update( const int flags )
5892 {
5893   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5894     SMESH::UpdateView();
5895   else
5896     SalomeApp_Module::update( flags );
5897 }
5898
5899 //================================================================================
5900 /*!
5901  * \brief Set default selection mode
5902 *
5903 * SLOT called when operation committed. Sets default selection mode
5904 */
5905 //================================================================================
5906 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5907 {
5908   SVTK_ViewWindow* vtkWnd =
5909     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5910   if ( vtkWnd )
5911     vtkWnd->SetSelectionMode( ActorSelection );
5912 }
5913
5914 //================================================================================
5915 /*!
5916  * \brief Set default selection mode
5917 *
5918 * SLOT called when operation aborted. Sets default selection mode
5919 */
5920 //================================================================================
5921 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5922 {
5923   SVTK_ViewWindow* vtkWnd =
5924     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5925   if ( vtkWnd )
5926     vtkWnd->SetSelectionMode( ActorSelection );
5927 }
5928
5929 //================================================================================
5930 /*!
5931  * \brief Creates operation with given identifier
5932   * \param id - identifier of operation to be started
5933   * \return Pointer on created operation or NULL if operation is not created
5934 *
5935 * Virtual method redefined from the base class creates operation with given id.
5936 * It is called called automatically from startOperation method of base class.
5937 */
5938 //================================================================================
5939 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5940 {
5941   LightApp_Operation* op = 0;
5942   // to do : create operation here
5943   switch( id )
5944   {
5945   case SMESHOp::OpSplitBiQuadratic:
5946     op = new SMESHGUI_SplitBiQuadOp();
5947     break;
5948   case SMESHOp::OpConvertMeshToQuadratic:
5949     op = new SMESHGUI_ConvToQuadOp();
5950     break;
5951   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh as boundary on 3D
5952     op = new SMESHGUI_Make2DFrom3DOp();
5953     break;
5954   case SMESHOp::OpReorientFaces:
5955     op = new SMESHGUI_ReorientFacesOp();
5956     break;
5957   case SMESHOp::OpCreateMesh:
5958     op = new SMESHGUI_MeshOp( true, true );
5959     break;
5960   case SMESHOp::OpCreateSubMesh:
5961     op = new SMESHGUI_MeshOp( true, false );
5962     break;
5963   case SMESHOp::OpEditMeshOrSubMesh:
5964   case SMESHOp::OpEditMesh:
5965   case SMESHOp::OpEditSubMesh:
5966     op = new SMESHGUI_MeshOp( false );
5967     break;
5968   case SMESHOp::OpCompute:
5969   case SMESHOp::OpComputeSubMesh:
5970     op = new SMESHGUI_ComputeOp();
5971     break;
5972   case SMESHOp::OpShowErrors:
5973     op = new SMESHGUI_ShowErrorsOp();
5974     break;
5975   case SMESHOp::OpPreCompute:
5976     op = new SMESHGUI_PrecomputeOp();
5977     break;
5978   case SMESHOp::OpEvaluate:
5979     op = new SMESHGUI_EvaluateOp();
5980     break;
5981   case SMESHOp::OpMeshOrder:
5982     op = new SMESHGUI_MeshOrderOp();
5983     break;
5984   case SMESHOp::OpCreateGeometryGroup:
5985     op = new SMESHGUI_GroupOnShapeOp();
5986     break;
5987   case SMESHOp::OpFindElementByPoint:
5988     op = new SMESHGUI_FindElemByPointOp();
5989     break;
5990   case SMESHOp::OpMoveNode: // Make mesh pass through point
5991     op = new SMESHGUI_MakeNodeAtPointOp();
5992     break;
5993   case SMESHOp::OpElem0DOnElemNodes: // Create 0D elements on all nodes
5994     op = new SMESHGUI_Add0DElemsOnAllNodesOp();
5995     break;
5996   default:
5997     break;
5998   }
5999
6000   if( !op )
6001     op = SalomeApp_Module::createOperation( id );
6002   return op;
6003 }
6004
6005 //================================================================================
6006 /*!
6007  * \brief Stops current operations and starts a given one
6008   * \param id - The id of the operation to start
6009  */
6010 //================================================================================
6011
6012 void SMESHGUI::switchToOperation(int id)
6013 {
6014   activeStudy()->abortAllOperations();
6015   startOperation( id );
6016 }
6017
6018 LightApp_Displayer* SMESHGUI::displayer()
6019 {
6020   if( !myDisplayer )
6021     myDisplayer = new SMESHGUI_Displayer( getApp() );
6022   return myDisplayer;
6023 }
6024
6025 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
6026 {
6027   int aHue = -1;
6028   int aTolerance = 64;
6029   int anIterations = 0;
6030   int aPeriod = 5;
6031
6032   while( 1 )
6033   {
6034     anIterations++;
6035     if( anIterations % aPeriod == 0 )
6036     {
6037       aTolerance /= 2;
6038       if( aTolerance < 1 )
6039         break;
6040     }
6041
6042     aHue = (int)( 360.0 * rand() / RAND_MAX );
6043
6044     bool ok = true;
6045     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
6046     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
6047     for( ; it != itEnd; ++it )
6048     {
6049       SALOMEDS::Color anAutoColor = *it;
6050       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
6051
6052       int h, s, v;
6053       aQColor.getHsv( &h, &s, &v );
6054       if( abs( h - aHue ) < aTolerance )
6055       {
6056         ok = false;
6057         break;
6058       }
6059     }
6060
6061     if( ok )
6062       break;
6063   }
6064
6065   QColor aColor;
6066   aColor.setHsv( aHue, 255, 255 );
6067
6068   SALOMEDS::Color aSColor;
6069   aSColor.R = aColor.redF();
6070   aSColor.G = aColor.greenF();
6071   aSColor.B = aColor.blueF();
6072
6073   return aSColor;
6074 }
6075
6076 const char* gSeparator = "_"; // character used to separate parameter names
6077 const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
6078 const char* gPathSep   = "|"; // character used to separate paths
6079
6080 /*!
6081  * \brief Store visual parameters
6082  *
6083  * This method is called just before the study document is saved.
6084  * Store visual parameters in AttributeParameter attribute(s)
6085  */
6086 void SMESHGUI::storeVisualParameters (int savePoint)
6087 {
6088   // localizing
6089   Kernel_Utils::Localizer loc;
6090
6091   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
6092   if (!appStudy || !appStudy->studyDS())
6093     return;
6094   _PTR(Study) studyDS = appStudy->studyDS();
6095
6096   // componentName is used for encoding of entries when storing them in IParameters
6097   std::string componentName = myComponentSMESH->ComponentDataType();
6098   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
6099   //if (!aSComponent) return;
6100
6101   // IParameters
6102   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
6103                                                              componentName.c_str(),
6104                                                              savePoint);
6105   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
6106
6107   // store custom markers
6108   if( !myMarkerMap.empty() )
6109   {
6110     VTK::MarkerMap::const_iterator anIter = myMarkerMap.begin();
6111     for( ; anIter != myMarkerMap.end(); anIter++ )
6112     {
6113       int anId = anIter->first;
6114       VTK::MarkerData aMarkerData = anIter->second;
6115       std::string aMarkerFileName = aMarkerData.first;
6116       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
6117       if( aMarkerTexture.size() < 3 )
6118         continue; // should contain at least width, height and the first value
6119
6120       QString aPropertyName( "texture" );
6121       aPropertyName += gSeparator;
6122       aPropertyName += QString::number( anId );
6123
6124       QString aPropertyValue = aMarkerFileName.c_str();
6125       aPropertyValue += gPathSep;
6126
6127       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
6128       ushort aWidth = *aTextureIter++;
6129       ushort aHeight = *aTextureIter++;
6130       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
6131       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
6132       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
6133         aPropertyValue += QString::number( *aTextureIter );
6134
6135       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
6136     }
6137   }
6138
6139   // viewers counters are used for storing view_numbers in IParameters
6140   int vtkViewers = 0;
6141
6142   // main cycle to store parameters of displayed objects
6143   QList<SUIT_ViewManager*> lst;
6144   QList<SUIT_ViewManager*>::Iterator it;
6145   getApp()->viewManagers(lst);
6146   for (it = lst.begin(); it != lst.end(); it++)
6147   {
6148     SUIT_ViewManager* vman = *it;
6149     QString vType = vman->getType();
6150
6151     // saving VTK actors properties
6152     if (vType == SVTK_Viewer::Type())
6153     {
6154       // store the clipping planes attached to the view manager
6155       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
6156       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
6157       if( anIter != myClippingPlaneInfoMap.end() )
6158         aClippingPlaneInfoList = anIter->second;
6159
6160       if( !aClippingPlaneInfoList.empty() ) {
6161         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
6162         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
6163         {
6164           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
6165           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
6166
6167           QString aPropertyName( "ClippingPlane" );
6168           aPropertyName += gSeparator;
6169           aPropertyName += QString::number( vtkViewers );
6170           aPropertyName += gSeparator;
6171           aPropertyName += QString::number( anId );
6172
6173           QString aPropertyValue = QString::number( (int)aPlane->PlaneMode ).toLatin1().constData();
6174           aPropertyValue += gDigitsSep;
6175           aPropertyValue += QString::number( aPlane->IsOpenGLClipping ).toLatin1().constData();
6176           aPropertyValue += gDigitsSep;
6177           if ( aPlane->PlaneMode == SMESH::Absolute ) {
6178             aPropertyValue += QString::number( aPlane->myAbsoluteOrientation ).toLatin1().constData();
6179             aPropertyValue += gDigitsSep;
6180             aPropertyValue += QString::number( aPlane->X ).toLatin1().constData();
6181             aPropertyValue += gDigitsSep;
6182             aPropertyValue += QString::number( aPlane->Y ).toLatin1().constData();
6183             aPropertyValue += gDigitsSep;
6184             aPropertyValue += QString::number( aPlane->Z ).toLatin1().constData();
6185             aPropertyValue += gDigitsSep;
6186             aPropertyValue += QString::number( aPlane->Dx ).toLatin1().constData();
6187             aPropertyValue += gDigitsSep;
6188             aPropertyValue += QString::number( aPlane->Dy ).toLatin1().constData();
6189             aPropertyValue += gDigitsSep;
6190             aPropertyValue += QString::number( aPlane->Dz ).toLatin1().constData();
6191           }
6192           else if ( aPlane->PlaneMode == SMESH::Relative ) {
6193             aPropertyValue += QString::number( (int)aPlane->myRelativeOrientation ).toLatin1().constData();
6194             aPropertyValue += gDigitsSep;
6195             aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
6196             aPropertyValue += gDigitsSep;
6197             aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
6198             aPropertyValue += gDigitsSep;
6199             aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
6200           }
6201
6202           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
6203         }
6204       }
6205
6206       QVector<SUIT_ViewWindow*> views = vman->getViews();
6207       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
6208       {
6209         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
6210         {
6211           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
6212           vtkActorCollection* allActors = aCopy.GetActors();
6213           allActors->InitTraversal();
6214           while (vtkActor* actor = allActors->GetNextActor())
6215           {
6216             if (actor->GetVisibility()) // store only visible actors
6217             {
6218               SMESH_Actor* aSmeshActor = 0;
6219               if (actor->IsA("SMESH_Actor"))
6220                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
6221               if (aSmeshActor && aSmeshActor->hasIO())
6222               {
6223                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
6224                 if (io->hasEntry())
6225                 {
6226                   // entry is "encoded" = it does NOT contain component address,
6227                   // since it is a subject to change on next component loading
6228                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
6229
6230                   std::string param, vtkParam = vType.toLatin1().data();
6231                   vtkParam += gSeparator;
6232                   vtkParam += QString::number(vtkViewers).toLatin1().data();
6233                   vtkParam += gSeparator;
6234
6235                   // Visibility
6236                   param = vtkParam + "Visibility";
6237                   ip->setParameter(entry, param, "On");
6238
6239                   // Representation
6240                   param = vtkParam + "Representation";
6241                   ip->setParameter(entry, param, QString::number
6242                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
6243
6244                   // IsShrunk
6245                   param = vtkParam + "IsShrunk";
6246                   ip->setParameter(entry, param, QString::number
6247                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
6248
6249                   // Displayed entities
6250                   unsigned int aMode = aSmeshActor->GetEntityMode();
6251                   bool isE  = aMode & SMESH_Actor::eEdges;
6252                   bool isF  = aMode & SMESH_Actor::eFaces;
6253                   bool isV  = aMode & SMESH_Actor::eVolumes;
6254                   bool is0d = aMode & SMESH_Actor::e0DElements;
6255                   bool isB  = aMode & SMESH_Actor::eBallElem;
6256
6257                   QString modeStr ("e");
6258                   modeStr += gDigitsSep; modeStr += QString::number(isE);
6259                   modeStr += gDigitsSep; modeStr += "f";
6260                   modeStr += gDigitsSep; modeStr += QString::number(isF);
6261                   modeStr += gDigitsSep; modeStr += "v";
6262                   modeStr += gDigitsSep; modeStr += QString::number(isV);
6263                   modeStr += gDigitsSep; modeStr += "0d";
6264                   modeStr += gDigitsSep; modeStr += QString::number(is0d);
6265                   modeStr += gDigitsSep; modeStr += "b";
6266                   modeStr += gDigitsSep; modeStr += QString::number(isB);
6267
6268                   param = vtkParam + "Entities";
6269                   ip->setParameter(entry, param, modeStr.toLatin1().data());
6270
6271                   // Colors
6272                   double r, g, b;
6273                   int delta;
6274
6275                   aSmeshActor->GetSufaceColor(r, g, b, delta);
6276                   QStringList colorStr;
6277                   colorStr << "surface";
6278                   colorStr << QString::number(r);
6279                   colorStr << QString::number(g);
6280                   colorStr << QString::number(b);
6281
6282                   colorStr << "backsurface";
6283                   colorStr << QString::number(delta);
6284
6285                   aSmeshActor->GetVolumeColor(r, g, b, delta);
6286                   colorStr << "volume";
6287                   colorStr << QString::number(r);
6288                   colorStr << QString::number(g);
6289                   colorStr << QString::number(b);
6290                   colorStr << QString::number(delta);
6291
6292                   aSmeshActor->GetEdgeColor(r, g, b);
6293                   colorStr << "edge";
6294                   colorStr << QString::number(r);
6295                   colorStr << QString::number(g);
6296                   colorStr << QString::number(b);
6297
6298                   aSmeshActor->GetNodeColor(r, g, b);
6299                   colorStr << "node";
6300                   colorStr << QString::number(r);
6301                   colorStr << QString::number(g);
6302                   colorStr << QString::number(b);
6303
6304                   aSmeshActor->GetOutlineColor(r, g, b);
6305                   colorStr << "outline";
6306                   colorStr << QString::number(r);
6307                   colorStr << QString::number(g);
6308                   colorStr << QString::number(b);
6309
6310                   aSmeshActor->Get0DColor(r, g, b);
6311                   colorStr << "elem0d";
6312                   colorStr << QString::number(r);
6313                   colorStr << QString::number(g);
6314                   colorStr << QString::number(b);
6315
6316                   aSmeshActor->GetBallColor(r, g, b);
6317                   colorStr << "ball";
6318                   colorStr << QString::number(r);
6319                   colorStr << QString::number(g);
6320                   colorStr << QString::number(b);
6321
6322                   aSmeshActor->GetFacesOrientationColor(r, g, b);
6323                   colorStr << "orientation";
6324                   colorStr << QString::number(r);
6325                   colorStr << QString::number(g);
6326                   colorStr << QString::number(b);
6327
6328                   param = vtkParam + "Colors";
6329                   ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
6330
6331                   // Sizes
6332                   QStringList sizeStr;
6333                   sizeStr << "line";
6334                   sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
6335                   sizeStr << "outline";
6336                   sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
6337                   sizeStr << "elem0d";
6338                   sizeStr << QString::number((int)aSmeshActor->Get0DSize());
6339                   sizeStr << "ball";
6340                   //sizeStr << QString::number((int)aSmeshActor->GetBallSize());
6341                   sizeStr << QString::number((double)aSmeshActor->GetBallSize());
6342                   sizeStr << QString::number((double)aSmeshActor->GetBallScale());
6343                   sizeStr << "shrink";
6344                   sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
6345                   sizeStr << "orientation";
6346                   sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
6347                   sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
6348
6349                   param = vtkParam + "Sizes";
6350                   ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
6351
6352                   // Point marker
6353                   QString markerStr;
6354
6355                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
6356                   if( aMarkerType == VTK::MT_USER ) {
6357                     markerStr += "custom";
6358                     markerStr += gDigitsSep;
6359                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
6360                   }
6361                   else {
6362                     markerStr += "std";
6363                     markerStr += gDigitsSep;
6364                     markerStr += QString::number( (int)aMarkerType );
6365                     markerStr += gDigitsSep;
6366                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
6367                   }
6368
6369                   param = vtkParam + "PointMarker";
6370                   ip->setParameter(entry, param, markerStr.toLatin1().data());
6371
6372                   // Opacity
6373                   param = vtkParam + "Opacity";
6374                   ip->setParameter(entry, param,
6375                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
6376
6377                   // Clipping
6378                   param = vtkParam + "ClippingPlane";
6379                   int aPlaneId = 0;
6380                   if( !aClippingPlaneInfoList.empty() ) {
6381                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
6382                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
6383                     {
6384                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
6385                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
6386                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
6387                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
6388                         if( aSmeshActor == *anIter2 ) {
6389                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
6390                                             QString::number( anId ).toLatin1().constData() );
6391                           break;
6392                         }
6393                       }
6394                     }
6395                   }
6396                   if( aPlaneId == 0 )
6397                     ip->setParameter( entry, param, "Off" );
6398                 } // if (io->hasEntry())
6399               } // SMESH_Actor && hasIO
6400             } // isVisible
6401           } // while.. actors traversal
6402         } // if (vtkView)
6403       } // for (views)
6404       vtkViewers++;
6405     } // if (SVTK view model)
6406   } // for (viewManagers)
6407 }
6408
6409 // data structures for clipping planes processing
6410 typedef struct {
6411   int Id;
6412   int Mode;
6413   bool isOpenGLClipping;
6414   vtkIdType RelativeOrientation;
6415   double Distance;
6416   double Angle[2];
6417   int AbsoluteOrientation;
6418   double X, Y, Z, Dx, Dy, Dz;
6419 } TPlaneData;
6420 typedef std::list<TPlaneData>         TPlaneDataList;
6421 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
6422
6423 typedef std::list<vtkActor*>          TActorList;
6424 typedef struct {
6425   int PlaneId;
6426   TActorList ActorList;
6427   SUIT_ViewManager* ViewManager;
6428 } TPlaneInfo;
6429 typedef std::list<TPlaneInfo>         TPlaneInfoList;
6430 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
6431
6432 /*!
6433  * \brief Restore visual parameters
6434  *
6435  * This method is called after the study document is opened.
6436  * Restore visual parameters from AttributeParameter attribute(s)
6437  */
6438 void SMESHGUI::restoreVisualParameters (int savePoint)
6439 {
6440   // localizing
6441   Kernel_Utils::Localizer loc;
6442
6443   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
6444   if (!appStudy || !appStudy->studyDS())
6445     return;
6446   _PTR(Study) studyDS = appStudy->studyDS();
6447
6448   // componentName is used for encoding of entries when storing them in IParameters
6449   std::string componentName = myComponentSMESH->ComponentDataType();
6450
6451   // IParameters
6452   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
6453                                                              componentName.c_str(),
6454                                                              savePoint);
6455   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
6456
6457   // restore custom markers and map of clipping planes
6458   TPlaneDataMap aPlaneDataMap;
6459
6460   std::vector<std::string> properties = ip->getProperties();
6461   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
6462   {
6463     std::string property = *propIt;
6464     QString aPropertyName( property.c_str() );
6465     QString aPropertyValue( ip->getProperty( property ).c_str() );
6466
6467     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
6468     if( aPropertyNameList.isEmpty() )
6469       continue;
6470
6471     QString aPropertyType = aPropertyNameList[0];
6472     if( aPropertyType == "texture" )
6473     {
6474       if( aPropertyNameList.size() != 2 )
6475         continue;
6476
6477       bool ok = false;
6478       int anId = aPropertyNameList[1].toInt( &ok );
6479       if( !ok || anId < 1 )
6480         continue;
6481
6482       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
6483       if( aPropertyValueList.size() != 2 )
6484         continue;
6485
6486       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
6487       QString aMarkerTextureString = aPropertyValueList[1];
6488       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
6489       if( aMarkerTextureStringList.size() != 3 )
6490         continue;
6491
6492       ok = false;
6493       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
6494       if( !ok )
6495         continue;
6496
6497       ok = false;
6498       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
6499       if( !ok )
6500         continue;
6501
6502       VTK::MarkerTexture aMarkerTexture;
6503       aMarkerTexture.push_back( aWidth );
6504       aMarkerTexture.push_back( aHeight );
6505
6506       QString aMarkerTextureData = aMarkerTextureStringList[2];
6507       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
6508       {
6509         QChar aChar = aMarkerTextureData.at( i );
6510         if( aChar.isDigit() )
6511           aMarkerTexture.push_back( aChar.digitValue() );
6512       }
6513
6514       myMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
6515     }
6516     else if( aPropertyType == "ClippingPlane" )
6517     {
6518       if( aPropertyNameList.size() != 3 )
6519         continue;
6520
6521       bool ok = false;
6522       int aViewId = aPropertyNameList[1].toInt( &ok );
6523       if( !ok || aViewId < 0 )
6524         continue;
6525
6526       ok = false;
6527       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
6528       if( !ok || aClippingPlaneId < 0 )
6529         continue;
6530
6531       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
6532       if( aPropertyValueList.size() != 6 && aPropertyValueList.size() != 9 )
6533         continue;
6534
6535       TPlaneData aPlaneData;
6536       aPlaneData.AbsoluteOrientation = false;
6537       aPlaneData.RelativeOrientation = 0;
6538       aPlaneData.Distance = aPlaneData.Angle[0] = aPlaneData.Angle[1] = 0;
6539       aPlaneData.X = aPlaneData.Y = aPlaneData.Z = 0;
6540       aPlaneData.Dx = aPlaneData.Dy = aPlaneData.Dz = 0;
6541
6542       aPlaneData.Id = aClippingPlaneId;
6543
6544       ok = false;
6545       aPlaneData.Mode = aPropertyValueList[0].toInt( &ok );
6546       if( !ok )
6547         continue;
6548
6549       ok = false;
6550       aPlaneData.isOpenGLClipping = aPropertyValueList[1].toInt( &ok );
6551       if( !ok )
6552         continue;
6553
6554       if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Absolute )
6555       {
6556         ok = false;
6557         aPlaneData.AbsoluteOrientation = aPropertyValueList[2].toInt( &ok );
6558         if( !ok )
6559           continue;
6560
6561         ok = false;
6562         aPlaneData.X = aPropertyValueList[3].toDouble( &ok );
6563         if( !ok )
6564           continue;
6565
6566         ok = false;
6567         aPlaneData.Y = aPropertyValueList[4].toDouble( &ok );
6568         if( !ok )
6569           continue;
6570
6571         ok = false;
6572         aPlaneData.Z = aPropertyValueList[5].toDouble( &ok );
6573         if( !ok )
6574           continue;
6575
6576         ok = false;
6577         aPlaneData.Dx = aPropertyValueList[6].toDouble( &ok );
6578         if( !ok )
6579           continue;
6580
6581         ok = false;
6582         aPlaneData.Dy = aPropertyValueList[7].toDouble( &ok );
6583         if( !ok )
6584           continue;
6585
6586         ok = false;
6587         aPlaneData.Dz = aPropertyValueList[8].toDouble( &ok );
6588         if( !ok )
6589           continue;
6590       }
6591       else if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Relative ) {
6592         ok = false;
6593         aPlaneData.RelativeOrientation = aPropertyValueList[2].toInt( &ok );
6594         if( !ok )
6595           continue;
6596
6597         ok = false;
6598         aPlaneData.Distance = aPropertyValueList[3].toDouble( &ok );
6599         if( !ok )
6600           continue;
6601
6602         ok = false;
6603         aPlaneData.Angle[0] = aPropertyValueList[4].toDouble( &ok );
6604         if( !ok )
6605           continue;
6606
6607         ok = false;
6608         aPlaneData.Angle[1] = aPropertyValueList[5].toDouble( &ok );
6609         if( !ok )
6610           continue;
6611       }
6612
6613       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
6614       aPlaneDataList.push_back( aPlaneData );
6615     }
6616   }
6617
6618   TPlaneInfoMap aPlaneInfoMap;
6619
6620   std::vector<std::string> entries = ip->getEntries();
6621
6622   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
6623   {
6624     // entry is a normal entry - it should be "decoded" (setting base address of component)
6625     QString entry (ip->decodeEntry(*entIt).c_str());
6626
6627     // Check that the entry corresponds to a real object in the Study
6628     // as the object may be deleted or modified after the visual state is saved.
6629     _PTR(SObject) so = studyDS->FindObjectID(entry.toUtf8().data());
6630     if (!so) continue; //Skip the not existent entry
6631
6632     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
6633     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
6634
6635     std::vector<std::string>::iterator namesIt = paramNames.begin();
6636     std::vector<std::string>::iterator valuesIt = paramValues.begin();
6637
6638     // actors are stored in a map after displaying of them for
6639     // quicker access in the future: map < viewID to actor >
6640     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
6641
6642     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
6643     {
6644       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
6645       // '_' is used as separator and should not be used in viewer type or parameter names.
6646       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
6647       if (lst.size() != 3)
6648         continue;
6649
6650       QString viewerTypStr = lst[0];
6651       QString viewIndexStr = lst[1];
6652       QString paramNameStr = lst[2];
6653
6654       bool ok;
6655       int viewIndex = viewIndexStr.toUInt(&ok);
6656       if (!ok) // bad conversion of view index to integer
6657         continue;
6658
6659       // viewers
6660       if (viewerTypStr == SVTK_Viewer::Type())
6661       {
6662         SMESH_Actor* aSmeshActor = 0;
6663         if (vtkActors.IsBound(viewIndex))
6664           aSmeshActor = vtkActors.Find(viewIndex);
6665
6666         QList<SUIT_ViewManager*> lst;
6667         getApp()->viewManagers(viewerTypStr, lst);
6668
6669         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6670         SUIT_ViewManager* vman = NULL;
6671         if (viewIndex >= 0 && viewIndex < lst.count())
6672           vman = lst.at(viewIndex);
6673
6674         if (paramNameStr == "Visibility")
6675         {
6676           if (!aSmeshActor && displayer() && vman)
6677           {
6678             SUIT_ViewModel* vmodel = vman->getViewModel();
6679             // SVTK view model can be casted to SALOME_View
6680             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
6681
6682             // store displayed actor in a temporary map for quicker
6683             // access later when restoring other parameters
6684             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6685             vtkRenderer* Renderer = vtkView->getRenderer();
6686             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
6687             vtkActorCollection* theActors = aCopy.GetActors();
6688             theActors->InitTraversal();
6689             bool isFound = false;
6690             vtkActor *ac = theActors->GetNextActor();
6691             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
6692               if (ac->IsA("SMESH_Actor")) {
6693                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
6694                 if (aGeomAc->hasIO()) {
6695                   Handle(SALOME_InteractiveObject) io = aGeomAc->getIO();
6696                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toUtf8().data()) == 0) {
6697                     isFound = true;
6698                     vtkActors.Bind(viewIndex, aGeomAc);
6699                   }
6700                 }
6701               }
6702             }
6703           }
6704         } // if (paramNameStr == "Visibility")
6705         else
6706         {
6707           // the rest properties "work" with SMESH_Actor
6708           if (aSmeshActor)
6709           {
6710             QString val ((*valuesIt).c_str());
6711
6712             // Representation
6713             if (paramNameStr == "Representation") {
6714               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
6715             }
6716             // IsShrunk
6717             else if (paramNameStr == "IsShrunk") {
6718               if (val.toInt()) {
6719                 if (!aSmeshActor->IsShrunk())
6720                   aSmeshActor->SetShrink();
6721               }
6722               else {
6723                 if (aSmeshActor->IsShrunk())
6724                   aSmeshActor->UnShrink();
6725               }
6726             }
6727             // Displayed entities
6728             else if (paramNameStr == "Entities") {
6729               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
6730               int aEntityMode = SMESH_Actor::eAllEntity;
6731               for ( int i = 0; i < mode.count(); i+=2 ) {
6732                 if ( i < mode.count()-1 ) {
6733                   QString type = mode[i];
6734                   bool val = mode[i+1].toInt();
6735                   if      ( type == "e" && !val )
6736                     aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
6737                   else if ( type == "f" && !val )
6738                     aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
6739                   else if ( type == "v" && !val )
6740                     aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
6741                   else if ( type == "0d" && !val )
6742                     aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
6743                   else if ( type == "b" && !val )
6744                     aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
6745                 }
6746               }
6747               aSmeshActor->SetEntityMode( aEntityMode );
6748             }
6749             // Colors
6750             else if (paramNameStr == "Colors") {
6751               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
6752               QColor nodeColor;
6753               QColor edgeColor;
6754               QColor faceColor;
6755               QColor volumeColor;
6756               QColor elem0dColor;
6757               QColor ballColor;
6758               QColor outlineColor;
6759               QColor orientationColor;
6760               int deltaF;
6761               int deltaV;
6762               QColor c;
6763               double r, g, b;
6764               bool bOk;
6765               // below lines are required to get default values for delta coefficients
6766               // of backface color for faces and color of reversed volumes
6767               SMESH::GetColor( "SMESH", "fill_color",   c, deltaF, "0,170,255|-100" );
6768               SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
6769               for ( int i = 0; i < colors.count(); i++ ) {
6770                 QString type = colors[i];
6771                 if ( type == "surface" ) {
6772                   // face color is set by 3 values r:g:b, where
6773                   // - r,g,b - is rgb color components
6774                   if ( i+1 >= colors.count() ) break;                  // format error
6775                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6776                   if ( i+2 >= colors.count() ) break;                  // format error
6777                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6778                   if ( i+3 >= colors.count() ) break;                  // format error
6779                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6780                   faceColor.setRgbF( r, g, b );
6781                   i += 3;
6782                 }
6783                 else if ( type == "backsurface" ) {
6784                   // backface color can be defined in several ways
6785                   // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
6786                   // - in latest versions, it is set as delta coefficient
6787                   bool rgbOk = false, deltaOk;
6788                   if ( i+1 >= colors.count() ) break;                  // format error
6789                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6790                   int delta = colors[i+1].toInt( &deltaOk );
6791                   i++;                                 // shift index
6792                   if ( i+1 < colors.count() )          // index is shifted to 1
6793                     g = colors[i+1].toDouble( &rgbOk );
6794                   if ( rgbOk ) i++;                    // shift index
6795                   if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
6796                     b = colors[i+1].toDouble( &rgbOk );
6797                   if ( rgbOk ) i++;
6798                   // - as currently there's no way to set directly backsurface color as it was before,
6799                   // we ignore old dump where r,g,b triple was set
6800                   // - also we check that delta parameter is set properly
6801                   if ( !rgbOk && deltaOk )
6802                     deltaF = delta;
6803                 }
6804                 else if ( type == "volume" ) {
6805                   // volume color is set by 4 values r:g:b:delta, where
6806                   // - r,g,b - is a normal volume rgb color components
6807                   // - delta - is a reversed volume color delta coefficient
6808                   if ( i+1 >= colors.count() ) break;                  // format error
6809                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6810                   if ( i+2 >= colors.count() ) break;                  // format error
6811                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6812                   if ( i+3 >= colors.count() ) break;                  // format error
6813                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6814                   if ( i+4 >= colors.count() ) break;                  // format error
6815                   int delta = colors[i+4].toInt( &bOk );
6816                   if ( !bOk ) break;                                   // format error
6817                   volumeColor.setRgbF( r, g, b );
6818                   deltaV = delta;
6819                   i += 4;
6820                 }
6821                 else if ( type == "edge" ) {
6822                   // edge color is set by 3 values r:g:b, where
6823                   // - r,g,b - is rgb color components
6824                   if ( i+1 >= colors.count() ) break;                  // format error
6825                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6826                   if ( i+2 >= colors.count() ) break;                  // format error
6827                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6828                   if ( i+3 >= colors.count() ) break;                  // format error
6829                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6830                   edgeColor.setRgbF( r, g, b );
6831                   i += 3;
6832                 }
6833                 else if ( type == "node" ) {
6834                   // node color is set by 3 values r:g:b, where
6835                   // - r,g,b - is rgb color components
6836                   if ( i+1 >= colors.count() ) break;                  // format error
6837                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6838                   if ( i+2 >= colors.count() ) break;                  // format error
6839                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6840                   if ( i+3 >= colors.count() ) break;                  // format error
6841                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6842                   nodeColor.setRgbF( r, g, b );
6843                   i += 3;
6844                 }
6845                 else if ( type == "elem0d" ) {
6846                   // 0d element color is set by 3 values r:g:b, where
6847                   // - r,g,b - is rgb color components
6848                   if ( i+1 >= colors.count() ) break;                  // format error
6849                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6850                   if ( i+2 >= colors.count() ) break;                  // format error
6851                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6852                   if ( i+3 >= colors.count() ) break;                  // format error
6853                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6854                   elem0dColor.setRgbF( r, g, b );
6855                   i += 3;
6856                 }
6857                 else if ( type == "ball" ) {
6858                   // ball color is set by 3 values r:g:b, where
6859                   // - r,g,b - is rgb color components
6860                   if ( i+1 >= colors.count() ) break;                  // format error
6861                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6862                   if ( i+2 >= colors.count() ) break;                  // format error
6863                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6864                   if ( i+3 >= colors.count() ) break;                  // format error
6865                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6866                   ballColor.setRgbF( r, g, b );
6867                   i += 3;
6868                 }
6869                 else if ( type == "outline" ) {
6870                   // outline color is set by 3 values r:g:b, where
6871                   // - r,g,b - is rgb color components
6872                   if ( i+1 >= colors.count() ) break;                  // format error
6873                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6874                   if ( i+2 >= colors.count() ) break;                  // format error
6875                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6876                   if ( i+3 >= colors.count() ) break;                  // format error
6877                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6878                   outlineColor.setRgbF( r, g, b );
6879                   i += 3;
6880                 }
6881                 else if ( type == "orientation" ) {
6882                   // orientation color is set by 3 values r:g:b, where
6883                   // - r,g,b - is rgb color components
6884                   if ( i+1 >= colors.count() ) break;                  // format error
6885                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6886                   if ( i+2 >= colors.count() ) break;                  // format error
6887                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6888                   if ( i+3 >= colors.count() ) break;                  // format error
6889                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6890                   orientationColor.setRgbF( r, g, b );
6891                   i += 3;
6892                 }
6893               }
6894               // node color
6895               if ( nodeColor.isValid() )
6896                 aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
6897               // edge color
6898               if ( edgeColor.isValid() )
6899                 aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
6900               // face color
6901               if ( faceColor.isValid() )
6902                 aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6903               // volume color
6904               if ( volumeColor.isValid() )
6905                 aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
6906               else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
6907                 aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6908               // 0d element color
6909               if ( elem0dColor.isValid() )
6910                 aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
6911               // ball color
6912               if ( ballColor.isValid() )
6913                 aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
6914               // outline color
6915               if ( outlineColor.isValid() )
6916                 aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
6917               // orientation color
6918               if ( orientationColor.isValid() )
6919                 aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
6920             }
6921             // Sizes
6922             else if (paramNameStr == "Sizes") {
6923               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
6924               bool bOk;
6925               int lineWidth = -1;
6926               int outlineWidth = -1;
6927               int elem0dSize = -1;
6928               //int ballSize = -1;
6929               double ballDiameter = -1.0;
6930               double ballScale = -1.0;
6931               double shrinkSize = -1;
6932               double orientationSize = -1;
6933               bool orientation3d = false;
6934               for ( int i = 0; i < sizes.count(); i++ ) {
6935                 QString type = sizes[i];
6936                 if ( type == "line" ) {
6937                   // line (wireframe) width is given as single integer value
6938                   if ( i+1 >= sizes.count() ) break;                    // format error
6939                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6940                   lineWidth = v;
6941                   i++;
6942                 }
6943                 if ( type == "outline" ) {
6944                   // outline width is given as single integer value
6945                   if ( i+1 >= sizes.count() ) break;                    // format error
6946                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6947                   outlineWidth = v;
6948                   i++;
6949                 }
6950                 else if ( type == "elem0d" ) {
6951                   // 0d element size is given as single integer value
6952                   if ( i+1 >= sizes.count() ) break;                    // format error
6953                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6954                   elem0dSize = v;
6955                   i++;
6956                 }
6957                 else if ( type == "ball" ) {
6958                   // balls are specified by two values: size:scale, where
6959                   // - size - is a integer value specifying size
6960                   // - scale - is a double value specifying scale factor
6961                   if ( i+1 >= sizes.count() ) break;                       // format error
6962                   //int v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6963                   double v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6964                   if ( i+2 >= sizes.count() ) break;                       // format error
6965                   double v2 = sizes[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6966                   //ballSize = v1;
6967                   ballDiameter = v1;
6968                   ballScale = v2;
6969                   i += 2;
6970                 }
6971                 else if ( type == "shrink" ) {
6972                   // shrink factor is given as single floating point value
6973                   if ( i+1 >= sizes.count() ) break;                          // format error
6974                   double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break;  // format error
6975                   shrinkSize = v;
6976                   i++;
6977                 }
6978                 else if ( type == "orientation" ) {
6979                   // orientation vectors are specified by two values size:3d, where
6980                   // - size - is a floating point value specifying scale factor
6981                   // - 3d - is a boolean
6982                   if ( i+1 >= sizes.count() ) break;                          // format error
6983                   double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6984                   if ( i+2 >= sizes.count() ) break;                          // format error
6985                   int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break;       // format error
6986                   orientationSize = v1;
6987                   orientation3d = (bool)v2;
6988                   i += 2;
6989                 }
6990               }
6991               // line (wireframe) width
6992               if ( lineWidth > 0 )
6993                 aSmeshActor->SetLineWidth( lineWidth );
6994               // outline width
6995               if ( outlineWidth > 0 )
6996                 aSmeshActor->SetOutlineWidth( outlineWidth );
6997               else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
6998                 aSmeshActor->SetOutlineWidth( lineWidth );
6999               // 0d element size
7000               if ( elem0dSize > 0 )
7001                 aSmeshActor->Set0DSize( elem0dSize );
7002               // ball size
7003               /*if ( ballSize > 0 )
7004                 aSmeshActor->SetBallSize( ballSize );*/
7005               // ball diameter
7006               if ( ballDiameter > 0 )
7007                 aSmeshActor->SetBallSize( ballDiameter );
7008               // ball scale
7009               if ( ballScale > 0.0 )
7010                 aSmeshActor->SetBallScale( ballScale );
7011               // shrink factor
7012               if ( shrinkSize > 0 )
7013                 aSmeshActor->SetShrinkFactor( shrinkSize );
7014               // orientation vectors
7015               if ( orientationSize > 0 ) {
7016                 aSmeshActor->SetFacesOrientationScale( orientationSize );
7017                 aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
7018               }
7019             }
7020             // Point marker
7021             else if (paramNameStr == "PointMarker") {
7022               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
7023               if( data.count() >= 2 ) {
7024                 bool ok = false;
7025                 int aParam1 = data[1].toInt( &ok );
7026                 if( ok ) {
7027                   if( data[0] == "std" && data.count() == 3 ) {
7028                     int aParam2 = data[2].toInt( &ok );
7029                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
7030                   }
7031                   else if( data[0] == "custom" ) {
7032                     VTK::MarkerMap::const_iterator markerIt = myMarkerMap.find( aParam1 );
7033                     if( markerIt != myMarkerMap.end() ) {
7034                       VTK::MarkerData aMarkerData = markerIt->second;
7035                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
7036                     }
7037                   }
7038                 }
7039               }
7040             }
7041             // Opacity
7042             else if (paramNameStr == "Opacity") {
7043               aSmeshActor->SetOpacity(val.toFloat());
7044             }
7045             // Clipping
7046             else if (paramNameStr.startsWith("ClippingPlane")) {
7047               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
7048               // old format - val looks like "Off" or "1:0:0:0.5:0:0"
7049               // (mode(relative), is OpenGL clipping plane, orientation, distance, two angles)
7050               // or "0:1:1:10.5:1.0:1.0:15.0:10.0:10.0"
7051               // (mode(absolute), is OpenGL clipping plane, orientation, base point(x, y, z), direction (dx, dy, dz))
7052               // new format - val looks like "Off" or "0" (plane id)
7053               // (note: in new format "Off" value is used only for consistency,
7054               //  so it is processed together with values in old format)
7055               bool anIsOldFormat = ( vals.count() == 6 || vals.count() == 9 || val == "Off" );
7056               if( anIsOldFormat ) {
7057                 if (paramNameStr == "ClippingPlane1" || val == "Off")
7058                   aSmeshActor->RemoveAllClippingPlanes();
7059                 if (val != "Off") {
7060                   QList<SUIT_ViewManager*> lst;
7061                   getApp()->viewManagers(viewerTypStr, lst);
7062                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
7063                   if (viewIndex >= 0 && viewIndex < lst.count()) {
7064                     SUIT_ViewManager* vman = lst.at(viewIndex);
7065                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
7066
7067                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
7068
7069                     SMESH::TActorList anActorList;
7070                     anActorList.push_back( aSmeshActor );
7071                     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( vtkView );
7072                     aPlane->myViewWindow = vtkView;
7073                     SMESH::Mode aMode = ( SMESH::Mode )vals[0].toInt();
7074                     aPlane->PlaneMode = aMode;
7075                     bool isOpenGLClipping = ( bool )vals[1].toInt();
7076                     aPlane->IsOpenGLClipping = isOpenGLClipping;
7077                     if ( aMode == SMESH::Absolute ) {
7078                       aPlane->myAbsoluteOrientation = vals[2].toInt();
7079                       aPlane->X = vals[3].toFloat();
7080                       aPlane->Y = vals[4].toFloat();
7081                       aPlane->Z = vals[5].toFloat();
7082                       aPlane->Dx = vals[6].toFloat();
7083                       aPlane->Dy = vals[7].toFloat();
7084                       aPlane->Dz = vals[8].toFloat();
7085                     }
7086                     else if ( aMode == SMESH::Relative ) {
7087                       aPlane->myRelativeOrientation = (SMESH::Orientation)vals[2].toInt();
7088                       aPlane->myDistance = vals[3].toFloat();
7089                       aPlane->myAngle[0] = vals[4].toFloat();
7090                       aPlane->myAngle[1] = vals[5].toFloat();
7091                     }
7092
7093                     if( aPlane ) {
7094                       if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
7095                         SMESH::ClippingPlaneInfo aClippingPlaneInfo;
7096                         aClippingPlaneInfo.Plane = aPlane;
7097                         aClippingPlaneInfo.ActorList = anActorList;
7098                         aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
7099                       }
7100                     }
7101                   }
7102                 }
7103               }
7104               else {
7105                 bool ok = false;
7106                 int aPlaneId = val.toInt( &ok );
7107                 if( ok && aPlaneId >= 0 ) {
7108                   bool anIsDefinedPlane = false;
7109                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
7110                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
7111                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
7112                     TPlaneInfo& aPlaneInfo = *anIter;
7113                     if( aPlaneInfo.PlaneId == aPlaneId ) {
7114                       aPlaneInfo.ActorList.push_back( aSmeshActor );
7115                       anIsDefinedPlane = true;
7116                       break;
7117                     }
7118                   }
7119                   if( !anIsDefinedPlane ) {
7120                     TPlaneInfo aPlaneInfo;
7121                     aPlaneInfo.PlaneId = aPlaneId;
7122                     aPlaneInfo.ActorList.push_back( aSmeshActor );
7123                     aPlaneInfo.ViewManager = vman;
7124
7125                     // to make the list sorted by plane id
7126                     anIter = aPlaneInfoList.begin();
7127                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
7128                       const TPlaneInfo& aPlaneInfoRef = *anIter;
7129                       if( aPlaneInfoRef.PlaneId > aPlaneId )
7130                         break;
7131                     }
7132                     aPlaneInfoList.insert( anIter, aPlaneInfo );
7133                   }
7134                 }
7135               }
7136             }
7137           } // if (aSmeshActor)
7138         } // other parameters than Visibility
7139       }
7140     } // for names/parameters iterator
7141   } // for entries iterator
7142
7143   // take into account planes with empty list of actors referred to them
7144   QList<SUIT_ViewManager*> aVMList;
7145   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
7146
7147   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
7148   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
7149     int aViewId = aPlaneDataIter->first;
7150     if( aViewId >= 0 && aViewId < aVMList.count() ) {
7151       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
7152
7153       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
7154
7155       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
7156       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
7157       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
7158         const TPlaneData& aPlaneData = *anIter2;
7159         int aPlaneId = aPlaneData.Id;
7160
7161         bool anIsFound = false;
7162         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
7163         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
7164           const TPlaneInfo& aPlaneInfo = *anIter3;
7165           if( aPlaneInfo.PlaneId == aPlaneId ) {
7166             anIsFound = true;
7167             break;
7168           }
7169         }
7170
7171         if( !anIsFound ) {
7172           TPlaneInfo aPlaneInfo; // ActorList field is empty
7173           aPlaneInfo.PlaneId = aPlaneId;
7174           aPlaneInfo.ViewManager = aViewManager;
7175
7176           // to make the list sorted by plane id
7177           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
7178           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
7179             const TPlaneInfo& aPlaneInfoRef = *anIter4;
7180             if( aPlaneInfoRef.PlaneId > aPlaneId )
7181               break;
7182           }
7183           aPlaneInfoList.insert( anIter4, aPlaneInfo );
7184         }
7185       }
7186     }
7187   }
7188
7189   // add clipping planes to actors according to the restored parameters
7190   // and update the clipping plane map
7191   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
7192   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
7193     int aViewId = anIter1->first;
7194     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
7195
7196     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
7197     if( anIter2 == aPlaneDataMap.end() )
7198       continue;
7199     const TPlaneDataList& aPlaneDataList = anIter2->second;
7200
7201     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
7202     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
7203       const TPlaneInfo& aPlaneInfo = *anIter3;
7204       int aPlaneId = aPlaneInfo.PlaneId;
7205       const TActorList& anActorList = aPlaneInfo.ActorList;
7206       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
7207       if( !aViewManager )
7208         continue;
7209
7210       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
7211       if( !aViewWindow )
7212         continue;
7213
7214       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
7215
7216       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
7217       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
7218         const TPlaneData& aPlaneData = *anIter4;
7219         if( aPlaneData.Id == aPlaneId ) {
7220           SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( aViewWindow );
7221           aPlane->myViewWindow = aViewWindow;
7222           aPlane->PlaneMode = (SMESH::Mode)aPlaneData.Mode;
7223           aPlane->IsOpenGLClipping = aPlaneData.isOpenGLClipping;
7224           if ( aPlane->PlaneMode == SMESH::Absolute ) {
7225             aPlane->myAbsoluteOrientation = aPlaneData.AbsoluteOrientation;
7226             aPlane->X = aPlaneData.X;
7227             aPlane->Y = aPlaneData.Y;
7228             aPlane->Z = aPlaneData.Z;
7229             aPlane->Dx = aPlaneData.Dx;
7230             aPlane->Dy = aPlaneData.Dy;
7231             aPlane->Dz = aPlaneData.Dz;
7232           }
7233           else if ( aPlane->PlaneMode == SMESH::Relative ) {
7234             aPlane->myRelativeOrientation = (SMESH::Orientation)aPlaneData.RelativeOrientation;
7235             aPlane->myDistance = aPlaneData.Distance;
7236             aPlane->myAngle[0] = aPlaneData.Angle[0];
7237             aPlane->myAngle[1] = aPlaneData.Angle[1];
7238           }
7239           if( aPlane ) {
7240             if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
7241               SMESH::ClippingPlaneInfo aClippingPlaneInfo;
7242               aClippingPlaneInfo.Plane = aPlane;
7243               aClippingPlaneInfo.ActorList = anActorList;
7244               aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
7245             }
7246           }
7247           break;
7248         }
7249       }
7250
7251     }
7252   }
7253
7254
7255   // update all VTK views
7256   QList<SUIT_ViewManager*> lst;
7257   getApp()->viewManagers(lst);
7258   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
7259     SUIT_ViewModel* vmodel = (*it)->getViewModel();
7260     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
7261       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
7262       // set OpenGL clipping planes
7263       VTK::ActorCollectionCopy aCopy( vtkView->getRenderer()->GetActors() );
7264       vtkActorCollection* anAllActors = aCopy.GetActors();
7265       anAllActors->InitTraversal();
7266       while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
7267         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
7268           anActor->SetOpenGLClippingPlane();
7269
7270       vtkView->getRenderer()->ResetCameraClippingRange();
7271       vtkView->Repaint();
7272     }
7273   }
7274 }
7275
7276 /*!
7277   \brief Adds preferences for dfont of VTK viewer
7278   \param label label
7279   \param pIf group identifier
7280   \param param parameter
7281   \return identifier of preferences
7282 */
7283 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
7284 {
7285   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
7286
7287   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
7288
7289   QStringList fam;
7290   fam.append( tr( "SMESH_FONT_ARIAL" ) );
7291   fam.append( tr( "SMESH_FONT_COURIER" ) );
7292   fam.append( tr( "SMESH_FONT_TIMES" ) );
7293
7294   setPreferenceProperty( tfont, "fonts", fam );
7295
7296   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
7297   if ( needSize ) f = f | QtxFontEdit::Size;
7298   setPreferenceProperty( tfont, "features", f );
7299
7300   return tfont;
7301 }
7302
7303 /*!
7304   \brief Actions after hypothesis edition
7305   Updates object browser after hypothesis edition
7306 */
7307 void SMESHGUI::onHypothesisEdit( int result )
7308 {
7309   if( result == 1 )
7310     SMESHGUI::Modified();
7311   updateObjBrowser( true );
7312 }
7313
7314 /*!
7315   \brief Actions after choosing menu of control modes
7316   Updates control mode actions according to current selection
7317 */
7318 void SMESHGUI::onUpdateControlActions()
7319 {
7320   SALOME_ListIO selected;
7321   if ( LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr() )
7322     aSel->selectedObjects( selected );
7323
7324   SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
7325   if ( selected.Extent() ) {
7326     if ( selected.First()->hasEntry() ) {
7327       if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( selected.First()->getEntry() )) {
7328         aControl = anActor->GetControlMode();
7329         SALOME_ListIteratorOfListIO it(selected);
7330         for ( it.Next(); it.More(); it.Next() ) {
7331           Handle(SALOME_InteractiveObject) anIO = it.Value();
7332           if ( anIO->hasEntry() ) {
7333             if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
7334               if ( aControl != anActor->GetControlMode() ) {
7335                 aControl = SMESH_Actor::eNone;
7336                 break;
7337               }
7338             }
7339           }
7340         }
7341       }
7342     }
7343   }
7344
7345   int anAction = ActionToControl( aControl, true );
7346   if ( anAction)
7347     action( anAction )->setChecked( true );
7348   else {
7349     QMenu* send = (QMenu*)sender();
7350     QList<QAction*> actions = send->actions();
7351     for ( int i = 0; i < actions.size(); i++ )
7352       actions[i]->setChecked( false );
7353   }
7354 }
7355
7356
7357 /*!
7358   \brief Signal handler closing(SUIT_ViewWindow*) of a view
7359   \param pview view being closed
7360 */
7361 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
7362 #ifndef DISABLE_PLOT2DVIEWER
7363   //Crear all Plot2d Viewers if need.
7364   SMESH::ClearPlot2Viewers(pview);
7365 #endif
7366   EmitSignalCloseView();
7367 }
7368
7369 void SMESHGUI::message( const QString& msg )
7370 {
7371   // dispatch message
7372   QStringList data = msg.split("/");
7373   if ( data.count() > 0 ) {
7374     if ( data.first() == "mesh_loading" ) {
7375       // get mesh entry
7376       QString entry = data.count() > 1 ? data[1] : QString();
7377       if ( entry.isEmpty() )
7378         return;
7379       // get study
7380       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
7381       // get mesh name
7382       _PTR(SObject) obj = study->FindObjectID( entry.toUtf8().constData() );
7383       QString name;
7384       if ( obj )
7385         name = SMESH::fromUtf8(obj->GetName());
7386       if ( name.isEmpty() )
7387         return;
7388
7389       if ( data.last() == "stop" )
7390         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
7391       else
7392         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
7393       QApplication::processEvents();
7394     }
7395   }
7396 }
7397
7398 /*!
7399   \brief Connects or disconnects signals about activating and cloning view on the module slots
7400   \param pview view which is connected/disconnected
7401 */
7402 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
7403   if(!pview)
7404     return;
7405
7406   SUIT_ViewManager* viewMgr = pview->getViewManager();
7407   if ( viewMgr ) {
7408     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7409                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7410
7411     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7412              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7413   }
7414 }
7415
7416 /*!
7417   \brief Return \c true if object can be renamed
7418 */
7419 bool SMESHGUI::renameAllowed( const QString& entry) const {
7420   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7421   if( !anApp )
7422     return false;
7423
7424   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7425   if( !appStudy )
7426     return false;
7427
7428   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
7429
7430   if(!obj)
7431     return false;
7432
7433   if(appStudy->isComponent(entry) || obj->isReference())
7434     return false;
7435
7436   // check type to prevent renaming of inappropriate objects
7437   int aType = SMESHGUI_Selection::type(qPrintable(entry));
7438   if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7439       aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7440       aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7441       aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7442       aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
7443     return true;
7444
7445   return false;
7446 }
7447
7448 /*!
7449   Rename object by entry.
7450   \param entry entry of the object
7451   \param name new name of the object
7452   \brief Return \c true if rename operation finished successfully, \c false otherwise.
7453 */
7454 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
7455
7456   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7457   if( !anApp )
7458     return false;
7459
7460   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7461
7462   if(!appStudy)
7463     return false;
7464
7465   _PTR(Study) aStudy = appStudy->studyDS();
7466
7467   if(!aStudy)
7468     return false;
7469
7470   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
7471   if ( aLocked ) {
7472     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
7473     return false;
7474   }
7475
7476
7477   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
7478   _PTR(GenericAttribute) anAttr;
7479   _PTR(AttributeName) aName;
7480   if ( obj ) {
7481     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
7482       aName = anAttr;
7483       // check type to prevent renaming of inappropriate objects
7484       int aType = SMESHGUI_Selection::type( qPrintable(entry));
7485       if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7486           aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7487           aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7488           aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7489           aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
7490         if ( !name.isEmpty() ) {
7491           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qUtf8Printable(name) );
7492
7493           // update name of group object and its actor
7494           Handle(SALOME_InteractiveObject) IObject =
7495             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
7496
7497           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
7498           if( !aGroupObject->_is_nil() ) {
7499             aGroupObject->SetName( qUtf8Printable(name) );
7500             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
7501               anActor->setName( qUtf8Printable(name) );
7502           }
7503           return true;
7504         }
7505       }
7506     }
7507   }
7508   return false;
7509 }
7510
7511 SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
7512 {
7513   static QList<QColor> colors;
7514
7515   if ( colors.isEmpty() ) {
7516
7517     for (int s = 0; s < 2 ; s++)
7518     {
7519       for (int v = 100; v >= 40; v = v - 20)
7520       {
7521         for (int h = 0; h < 359 ; h = h + 60)
7522         {
7523           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
7524         }
7525       }
7526     }
7527   }
7528   static int currentColor = randomize( colors.size() );
7529
7530   SALOMEDS::Color color;
7531   color.R = (double)colors[currentColor].red()   / 255.0;
7532   color.G = (double)colors[currentColor].green() / 255.0;
7533   color.B = (double)colors[currentColor].blue()  / 255.0;
7534
7535   currentColor = (currentColor+1) % colors.count();
7536
7537   return color;
7538 }