Salome HOME
Traduction
[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         // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
2087         //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
2088         //op->start();
2089         aStudyBuilder->RemoveObjectWithChildren( SO );
2090         //op->finish();
2091       }
2092     }
2093   } /* listSO back loop */
2094
2095   aStudyBuilder->CommitCommand();
2096
2097   /* Clear any previous selection */
2098   SALOME_ListIO l1;
2099   aSel->setSelectedObjects( l1 );
2100
2101   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
2102 }
2103
2104 extern "C" {
2105   SMESHGUI_EXPORT CAM_Module* createModule()
2106   {
2107     return new SMESHGUI();
2108   }
2109
2110   SMESHGUI_EXPORT  char* getModuleVersion() {
2111     return (char*)SMESH_VERSION_STR;
2112   }
2113 }
2114
2115 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
2116
2117 //=============================================================================
2118 /*!
2119  *
2120  */
2121 //=============================================================================
2122 SMESHGUI::SMESHGUI() : SalomeApp_Module( "SMESH" )
2123 {
2124   if ( CORBA::is_nil( myComponentSMESH ) )
2125   {
2126     CORBA::Boolean anIsEmbeddedMode;
2127     SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
2128     if( dynamic_cast<SALOME_NamingService *>(ns) )
2129       myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
2130     else
2131       {
2132         Engines::EngineComponent_var comp = RetrieveSMESHInstance();
2133         myComponentSMESH = SMESH::SMESH_Gen::_narrow(comp);
2134       }
2135     
2136     //MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
2137
2138     //  0019923: EDF 765 SMESH : default values of hypothesis
2139     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
2140     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
2141     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
2142     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
2143     myComponentSMESH->SetDefaultNbSegments( nbSeg );
2144
2145     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
2146     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
2147       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
2148       {
2149         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
2150         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
2151       }
2152   }
2153
2154   myActiveDialogBox = 0;
2155   myFilterLibraryDlg = 0;
2156   myState = -1;
2157   myDisplayer = 0;
2158
2159   myEventCallbackCommand = vtkCallbackCommand::New();
2160   myEventCallbackCommand->Delete();
2161   myEventCallbackCommand->SetClientData( this );
2162   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
2163   myPriority = 0.0;
2164
2165   /* load resources for all available meshers */
2166   SMESH::InitAvailableHypotheses();
2167 }
2168
2169 //=============================================================================
2170 /*!
2171  *
2172  */
2173 //=============================================================================
2174 SMESHGUI::~SMESHGUI()
2175 {
2176 }
2177
2178 //=============================================================================
2179 /*!
2180  *
2181  */
2182 //=============================================================================
2183 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
2184 {
2185   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2186   if( anApp )
2187     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2188   else
2189     return 0;
2190 }
2191
2192 //=============================================================================
2193 /*!
2194  *
2195  */
2196 //=============================================================================
2197 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2198 {
2199   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2200   if ( !resMgr )
2201     return false;
2202
2203   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
2204   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2205   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2206   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2207   return autoUpdate && !exceeded;
2208 }
2209
2210 //=============================================================================
2211 /*!
2212  *
2213  */
2214 //=============================================================================
2215 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2216                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2217 {
2218   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2219   if ( !resMgr )
2220     return false;
2221
2222   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update", false );
2223   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2224   bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2225
2226   SMESH::smIdType_array_var info = theMesh->GetMeshInfo();
2227   long nbOdElems = info[SMDSEntity_0D];
2228   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2229   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] +
2230                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] +
2231                    info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2232   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] +
2233                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] +
2234                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] +
2235                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + info[SMDSEntity_BiQuad_Penta] +
2236                    info[SMDSEntity_Polyhedra] +
2237                    info[SMDSEntity_Hexagonal_Prism];
2238   long nbBalls   = info[SMDSEntity_Ball];
2239
2240   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2241   *nbElements = requestedSize;
2242
2243   *entities = SMESH_Actor::eAllEntity;
2244   *hidden   = 0;
2245
2246   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2247
2248   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2249
2250   if ( incrementalLimit ) {
2251     long total     = 0;
2252
2253     if ( nbOdElems > 0 ) {
2254       if ( total + nbOdElems > updateLimit ) {
2255         *entities = *entities & ~SMESH_Actor::e0DElements;
2256         *hidden = *hidden | SMESH_Actor::e0DElements;
2257       }
2258       else
2259         exceeded = false;
2260     }
2261     total += nbOdElems;
2262
2263     if ( nbEdges > 0 ) {
2264       if ( total + nbEdges > updateLimit ) {
2265         *entities = *entities & ~SMESH_Actor::eEdges;
2266         *hidden = *hidden | SMESH_Actor::eEdges;
2267       }
2268       else
2269         exceeded = false;
2270     }
2271     total += nbEdges;
2272
2273     if ( nbFaces > 0 ) {
2274       if ( total + nbFaces > updateLimit ) {
2275         *entities = *entities & ~SMESH_Actor::eFaces;
2276         *hidden = *hidden | SMESH_Actor::eFaces;
2277       }
2278       else
2279         exceeded = false;
2280     }
2281     total += nbFaces;
2282
2283     if ( nbVolumes > 0 ) {
2284       if ( total + nbVolumes > updateLimit ) {
2285         *entities = *entities & ~SMESH_Actor::eVolumes;
2286         *hidden = *hidden | SMESH_Actor::eVolumes;
2287       }
2288       else
2289         exceeded = false;
2290     }
2291     total += nbVolumes;
2292
2293     if ( nbBalls > 0 ) {
2294       if ( total + nbBalls > updateLimit ) {
2295         *entities = *entities & ~SMESH_Actor::eBallElem;
2296         *hidden = *hidden | SMESH_Actor::eBallElem;
2297       }
2298       else
2299         exceeded = false;
2300     }
2301     total += nbBalls;
2302   }
2303
2304   return autoUpdate && !exceeded;
2305 }
2306
2307 //=============================================================================
2308 /*!
2309  *
2310  */
2311 //=============================================================================
2312 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2313 {
2314   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2315 }
2316
2317 //=============================================================================
2318 /*!
2319  *
2320  */
2321 //=============================================================================
2322 SMESHGUI* SMESHGUI::GetSMESHGUI()
2323 {
2324   SMESHGUI* smeshMod = 0;
2325   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2326   if ( app )
2327   {
2328     CAM_Module* module = app->module( "Mesh" );
2329     smeshMod = dynamic_cast<SMESHGUI*>( module );
2330   }
2331
2332   return smeshMod;
2333 }
2334
2335 extern "C"
2336 {
2337   Standard_EXPORT SMESHGUI* GetComponentGUI()
2338   {
2339     return SMESHGUI::GetSMESHGUI();
2340   }
2341 }
2342
2343 //=============================================================================
2344 /*!
2345  *
2346  */
2347 //=============================================================================
2348 void SMESHGUI::SetState(int aState)
2349 {
2350   myState = aState;
2351 }
2352
2353 //=============================================================================
2354 /*!
2355  *
2356  */
2357 //=============================================================================
2358 void SMESHGUI::ResetState()
2359 {
2360   myState = -1;
2361 }
2362
2363 //=============================================================================
2364 /*!
2365  *
2366  */
2367 //=============================================================================
2368 void SMESHGUI::EmitSignalDeactivateDialog()
2369 {
2370   emit SignalDeactivateActiveDialog();
2371 }
2372
2373 //=============================================================================
2374 /*!
2375  *
2376  */
2377 //=============================================================================
2378 void SMESHGUI::EmitSignalStudyFrameChanged()
2379 {
2380   emit SignalStudyFrameChanged();
2381 }
2382
2383 //=============================================================================
2384 /*!
2385  *
2386  */
2387 //=============================================================================
2388 void SMESHGUI::EmitSignalCloseAllDialogs()
2389 {
2390   emit SignalCloseAllDialogs();
2391 }
2392
2393 //=============================================================================
2394 /*!
2395  *
2396  */
2397 //=============================================================================
2398 void SMESHGUI::EmitSignalVisibilityChanged()
2399 {
2400   emit SignalVisibilityChanged();
2401 }
2402
2403 //=============================================================================
2404 /*!
2405  *
2406  */
2407 //=============================================================================
2408 void SMESHGUI::EmitSignalCloseView()
2409 {
2410   emit SignalCloseView();
2411 }
2412
2413 //=============================================================================
2414 /*!
2415  *
2416  */
2417 //=============================================================================
2418 void SMESHGUI::EmitSignalActivatedViewManager()
2419 {
2420   emit SignalActivatedViewManager();
2421 }
2422
2423 //=============================================================================
2424 /*!
2425  *
2426  */
2427 //=============================================================================
2428 QDialog *SMESHGUI::GetActiveDialogBox()
2429 {
2430   return myActiveDialogBox;
2431 }
2432
2433 //=============================================================================
2434 /*!
2435  *
2436  */
2437 //=============================================================================
2438 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2439 {
2440   myActiveDialogBox = (QDialog *) aDlg;
2441   return;
2442 }
2443
2444 //=============================================================================
2445 /*!
2446  *
2447  */
2448 //=============================================================================
2449 SUIT_Desktop* SMESHGUI::desktop()
2450 {
2451   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2452   if( app )
2453     return app->desktop();
2454   else
2455     return 0;
2456 }
2457
2458 //=============================================================================
2459 /*!
2460  *
2461  */
2462 //=============================================================================
2463 SalomeApp_Study* SMESHGUI::activeStudy()
2464 {
2465   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2466   if( app )
2467     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2468   else
2469     return NULL;
2470 }
2471
2472 //=============================================================================
2473 /*!
2474  *
2475  */
2476 //=============================================================================
2477 void SMESHGUI::Modified( bool theIsUpdateActions )
2478 {
2479   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2480     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2481       appStudy->Modified();
2482       if( theIsUpdateActions )
2483         app->updateActions();
2484     }
2485   }
2486 }
2487
2488 //=============================================================================
2489 /*!
2490  *
2491  */
2492 //=============================================================================
2493 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2494 {
2495   /* Here the position is on the bottom right corner - 10 */
2496   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2497   aDlg->adjustSize();
2498   SUIT_Desktop *PP = desktop();
2499   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2500   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2501   return true;
2502 }
2503
2504 /*!
2505  * \brief Verifies whether study of operation is locked
2506   * \param theMess - specifies whether message box must be shown if study is locked
2507   * \return State of study.
2508 *
2509 * Verifies whether study of operation is locked. If second parameter is TRUE and study
2510 * is locked when corresponding message box appears
2511 */
2512 bool SMESHGUI::isStudyLocked( bool theMessage )
2513 {
2514   if ( SMESH::getStudy()->GetProperties()->IsLocked() )
2515   {
2516     if ( theMessage )
2517       SUIT_MessageBox::warning( SMESHGUI::desktop(),
2518                                 QObject::tr( "WRN_WARNING" ),
2519                                 QObject::tr( "WRN_STUDY_LOCKED" ) );
2520     return true;
2521   }
2522   return false;
2523 }
2524
2525 //=============================================================================
2526 /*!
2527  *
2528  */
2529 //=============================================================================
2530 bool SMESHGUI::OnGUIEvent( int theCommandID )
2531 {
2532   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2533   if( !anApp )
2534     return false;
2535
2536   SUIT_ResourceMgr* mgr = resourceMgr();
2537   if( !mgr )
2538     return false;
2539
2540   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2541   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2542
2543   //QAction* act = action( theCommandID );
2544
2545   switch (theCommandID) {
2546   case SMESHOp::OpDelete:
2547     if(isStudyLocked()) break;
2548     OnEditDelete();
2549     break;
2550   case SMESHOp::OpImportDAT:
2551   case SMESHOp::OpImportUNV:
2552   case SMESHOp::OpImportMED:
2553   case SMESHOp::OpImportSTL:
2554   case SMESHOp::OpImportCGNS:
2555   case SMESHOp::OpImportGMF:
2556   case SMESHOp::OpPopupImportDAT:
2557   case SMESHOp::OpPopupImportUNV:
2558   case SMESHOp::OpPopupImportMED:
2559   case SMESHOp::OpPopupImportSTL:
2560   case SMESHOp::OpPopupImportCGNS:
2561   case SMESHOp::OpPopupImportGMF:
2562     {
2563       if(isStudyLocked()) break;
2564       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2565       break;
2566     }
2567
2568   case SMESHOp::OpFileInformation:
2569     {
2570       SALOME_ListIO selected;
2571       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2572       if( aSel )
2573         aSel->selectedObjects( selected );
2574       if( selected.Extent() )
2575       {
2576         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2577         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2578         if ( !aMesh->_is_nil() )
2579         {
2580           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2581           dlg.exec();
2582         }
2583       }
2584       break;
2585     }
2586   case SMESHOp::OpExportDAT:
2587   case SMESHOp::OpExportMED:
2588   case SMESHOp::OpExportUNV:
2589   case SMESHOp::OpExportSTL:
2590   case SMESHOp::OpExportCGNS:
2591   case SMESHOp::OpExportGMF:
2592   case SMESHOp::OpPopupExportDAT:
2593   case SMESHOp::OpPopupExportMED:
2594   case SMESHOp::OpPopupExportUNV:
2595   case SMESHOp::OpPopupExportSTL:
2596   case SMESHOp::OpPopupExportCGNS:
2597   case SMESHOp::OpPopupExportGMF:
2598     {
2599       ::ExportMeshToFile(theCommandID);
2600       break;
2601     }
2602
2603   case SMESHOp::OpReset:                      // SCALAR BAR
2604     {
2605       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2606       SALOME_ListIO selected;
2607       if( aSel )
2608         aSel->selectedObjects( selected );
2609
2610       SALOME_ListIteratorOfListIO it(selected);
2611       for( ; it.More(); it.Next()) {
2612         Handle(SALOME_InteractiveObject) anIO = it.Value();
2613         if( anIO->hasEntry() ) {
2614           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2615             anActor->SetControlMode( SMESH_Actor::eNone );
2616 #ifndef DISABLE_PLOT2DVIEWER
2617             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2618 #endif
2619             anActor->UpdateFilter();
2620           }
2621         }
2622       }
2623       SMESH::UpdateView();
2624       break;
2625     }
2626   case SMESHOp::OpScalarBarProperties:
2627     {
2628       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2629       break;
2630     }
2631   case SMESHOp::OpShowScalarBar:
2632     {
2633       // show/hide scalar bar
2634       ::ShowElement(theCommandID);
2635       break;
2636     }
2637   case SMESHOp::OpSaveDistribution:
2638     {
2639       // dump control distribution data to the text file
2640       ::SaveDistribution();
2641       break;
2642     }
2643
2644   case SMESHOp::OpShowDistribution:
2645     {
2646       // show/hide distribution
2647       ::ShowElement(theCommandID);
2648       break;
2649     }
2650
2651 #ifndef DISABLE_PLOT2DVIEWER
2652   case SMESHOp::OpPlotDistribution:
2653     {
2654       // plot distribution
2655       ::PlotDistribution();
2656       break;
2657     }
2658 #endif
2659
2660     // Auto-color
2661   case SMESHOp::OpAutoColor:
2662     ::AutoColor();
2663   break;
2664
2665   case SMESHOp::OpDisableAutoColor:
2666     ::DisableAutoColor();
2667   break;
2668
2669   case SMESHOp::OpClipping:
2670   case SMESHOp::OpTransparency:
2671   case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2672
2673     // Display Mode
2674   case SMESHOp::OpDMWireframe:
2675   case SMESHOp::OpDMShading:
2676   case SMESHOp::OpDMNodes:
2677   case SMESHOp::OpDMShrink:
2678     ::SetDisplayMode(theCommandID, myMarkerMap);
2679   break;
2680
2681   //2D quadratic representation
2682   case SMESHOp::OpRepresentationLines:
2683   case SMESHOp::OpRepresentationArcs:
2684     ::SetDisplayMode(theCommandID, myMarkerMap);
2685   break;
2686
2687   // Display Entity
2688   case SMESHOp::OpDE0DElements:
2689   case SMESHOp::OpDEEdges:
2690   case SMESHOp::OpDEFaces:
2691   case SMESHOp::OpDEVolumes:
2692   case SMESHOp::OpDEBalls:
2693   case SMESHOp::OpDEAllEntity:
2694     ::SetDisplayEntity(theCommandID);
2695   break;
2696
2697   // Choose entities to be displayed
2698   case SMESHOp::OpDEChoose:
2699     {
2700       ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2701       break;
2702     }
2703
2704   case SMESHOp::OpOrientationOnFaces:
2705     {
2706       SUIT_OverrideCursor wc;
2707       LightApp_SelectionMgr* mgr = selectionMgr();
2708       SALOME_ListIO selected; mgr->selectedObjects( selected );
2709
2710       SALOME_ListIteratorOfListIO it(selected);
2711       for( ; it.More(); it.Next()) {
2712         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2713         if(anIObject->hasEntry()) {
2714           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2715             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2716           }
2717         }
2718       }
2719       break;
2720     }
2721
2722   case SMESHOp::OpUpdate:
2723     {
2724       if(isStudyLocked()) break;
2725       SUIT_OverrideCursor wc;
2726       try {
2727         OCC_CATCH_SIGNALS;
2728         SMESH::UpdateView();
2729       }
2730       catch (std::bad_alloc&) { // PAL16774 (Crash after display of many groups)
2731         SMESH::OnVisuException();
2732       }
2733       catch (...) { // PAL16774 (Crash after display of many groups)
2734         SMESH::OnVisuException();
2735       }
2736
2737       SALOME_ListIO l;
2738       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2739       aSel->selectedObjects( l );
2740       aSel->setSelectedObjects( l );
2741       break;
2742     }
2743
2744   case SMESHOp::OpHide:
2745   case SMESHOp::OpShow:
2746   case SMESHOp::OpShowOnly:
2747     {
2748       SUIT_OverrideCursor wc;
2749       SMESH::EDisplaing anAction;
2750       switch (theCommandID) {
2751       case SMESHOp::OpHide:     anAction = SMESH::eErase; break;
2752       case SMESHOp::OpShow:     anAction = SMESH::eDisplay; break;
2753       case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2754       }
2755
2756       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2757       SALOME_ListIO sel_objects, to_process;
2758       if (aSel)
2759         aSel->selectedObjects( sel_objects );
2760
2761       if ( theCommandID==SMESHOp::OpShowOnly )
2762       {
2763         //MESSAGE("anAction = SMESH::eDisplayOnly");
2764         startOperation( myEraseAll );
2765       }
2766
2767       extractContainers( sel_objects, to_process );
2768
2769       try {
2770         OCC_CATCH_SIGNALS;
2771         if (vtkwnd) {
2772           SALOME_ListIteratorOfListIO It( to_process );
2773           for ( ; It.More(); It.Next())
2774           {
2775             Handle(SALOME_InteractiveObject) IOS = It.Value();
2776             if ( IOS->hasEntry() )
2777             {
2778               if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2779                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2780                 break; // PAL16774 (Crash after display of many groups)
2781               }
2782               if (anAction == SMESH::eDisplayOnly)
2783                 anAction = SMESH::eDisplay;
2784             }
2785           }
2786         }
2787
2788         // PAL13338 + PAL15161 -->
2789         if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !isStudyLocked()) {
2790           SMESH::UpdateView();
2791           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2792         }
2793         // PAL13338 + PAL15161 <--
2794       }
2795       catch (...) { // PAL16774 (Crash after display of many groups)
2796         SMESH::OnVisuException();
2797       }
2798
2799       if (anAction == SMESH::eErase) {
2800         SALOME_ListIO l1;
2801         aSel->setSelectedObjects( l1 );
2802       }
2803       else
2804         aSel->setSelectedObjects( to_process );
2805
2806       if ( vtkwnd && vtkwnd->GetRenderer() && !isStudyLocked() &&
2807            ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) )
2808         vtkwnd->GetRenderer()->AdjustActors();
2809
2810       break;
2811     }
2812
2813   case SMESHOp::OpNode:
2814     {
2815       if(isStudyLocked()) break;
2816
2817       if ( vtkwnd ) {
2818         EmitSignalDeactivateDialog();
2819
2820         ( new SMESHGUI_NodesDlg( this ) )->show();
2821       }
2822       else {
2823         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"),tr("SMESH_WRN_VIEWER_VTK"));
2824       }
2825       break;
2826     }
2827
2828   case SMESHOp::OpEditMeshOrSubMesh:
2829   case SMESHOp::OpEditMesh:
2830   case SMESHOp::OpEditSubMesh:
2831   case SMESHOp::OpMeshOrder:
2832   case SMESHOp::OpCreateSubMesh:
2833     if ( warnOnGeomModif() )
2834       break; // action forbidden as geometry modified
2835     // fall through
2836   case SMESHOp::OpCreateMesh:
2837   case SMESHOp::OpCompute:
2838   case SMESHOp::OpComputeSubMesh:
2839   case SMESHOp::OpPreCompute:
2840   case SMESHOp::OpEvaluate:
2841   case SMESHOp::OpShowErrors:
2842     startOperation( theCommandID );
2843     break;
2844   case SMESHOp::OpRecompute:
2845     {
2846       if ( isStudyLocked() )
2847         break;
2848       SALOME_ListIO selected;
2849       if ( LightApp_SelectionMgr *sel = selectionMgr() )
2850         sel->selectedObjects( selected );
2851       if ( selected.Extent() == 1 ) {
2852         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( selected.First() );
2853         if ( !aMesh->_is_nil() )
2854           aMesh->Clear();
2855         startOperation( SMESHOp::OpCompute );
2856       }
2857     }
2858     break;
2859   case SMESHOp::OpCopyMesh:
2860     {
2861       if (isStudyLocked()) break;
2862       EmitSignalDeactivateDialog();
2863       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2864     }
2865     break;
2866   case SMESHOp::OpBuildCompoundMesh:
2867     {
2868       if (isStudyLocked()) break;
2869       EmitSignalDeactivateDialog();
2870       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2871     }
2872     break;
2873
2874   case SMESHOp::OpDiagonalInversion:
2875   case SMESHOp::OpUnionOfTwoTriangle:
2876     {
2877       if ( !vtkwnd )
2878       {
2879         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2880         break;
2881       }
2882
2883       if ( isStudyLocked() )
2884         break;
2885       if ( warnOnGeomModif() )
2886         break; // action forbidden as geometry modified
2887
2888       /*Standard_Boolean aRes;
2889       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2890       if ( aMesh->_is_nil() )
2891       {
2892         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2893           tr( "SMESH_BAD_SELECTION" ) );
2894         break;
2895       }
2896       */
2897       EmitSignalDeactivateDialog();
2898       if ( theCommandID == SMESHOp::OpDiagonalInversion )
2899         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2900       else
2901         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2902       break;
2903     }
2904   case SMESHOp::OpOrientation:
2905   case SMESHOp::OpUnionOfTriangles:
2906   case SMESHOp::OpCuttingOfQuadrangles:
2907   case SMESHOp::OpSplitVolumes:
2908     {
2909       if ( !vtkwnd )
2910       {
2911         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2912         break;
2913       }
2914
2915       if ( isStudyLocked() )
2916         break;
2917       if ( warnOnGeomModif() )
2918         break; // action forbidden as geometry modified
2919
2920       EmitSignalDeactivateDialog();
2921       SMESHGUI_MultiEditDlg* aDlg = NULL;
2922       if ( theCommandID == SMESHOp::OpOrientation )
2923         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2924       else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2925         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2926       else if ( theCommandID == SMESHOp::OpSplitVolumes )
2927         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2928       else
2929         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2930
2931       aDlg->show();
2932       break;
2933     }
2934   case SMESHOp::OpSmoothing:
2935     {
2936       if(isStudyLocked()) break;
2937       if ( warnOnGeomModif() )
2938         break; // action forbidden as geometry modified
2939       if( vtkwnd ) {
2940         EmitSignalDeactivateDialog();
2941         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2942       }
2943       else {
2944         SUIT_MessageBox::warning(desktop(), tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2945       }
2946       break;
2947     }
2948   case SMESHOp::OpExtrusion:
2949     {
2950       if (isStudyLocked()) break;
2951       if ( warnOnGeomModif() )
2952         break; // action forbidden as geometry modified
2953       if (vtkwnd) {
2954         EmitSignalDeactivateDialog();
2955         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2956       } else {
2957         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2958       }
2959       break;
2960     }
2961   case SMESHOp::OpExtrusionAlongAPath:
2962     {
2963       if (isStudyLocked()) break;
2964       if ( warnOnGeomModif() )
2965         break; // action forbidden as geometry modified
2966       if (vtkwnd) {
2967         EmitSignalDeactivateDialog();
2968         ( new SMESHGUI_ExtrusionAlongPathDlg( 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::OpRevolution:
2975     {
2976       if(isStudyLocked()) break;
2977       if ( warnOnGeomModif() )
2978         break; // action forbidden as geometry modified
2979       if( vtkwnd ) {
2980         EmitSignalDeactivateDialog();
2981         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2982       }
2983       else {
2984         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2985       }
2986       break;
2987     }
2988   case SMESHOp::OpPatternMapping:
2989     {
2990       if ( isStudyLocked() )
2991         break;
2992       if ( warnOnGeomModif() )
2993         break; // action forbidden as geometry modified
2994       if ( vtkwnd )
2995       {
2996         EmitSignalDeactivateDialog();
2997         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2998       }
2999       else {
3000         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3001       }
3002       break;
3003     }
3004   // Adaptation - begin
3005 #ifndef DISABLE_MG_ADAPT
3006   case SMESHOp::OpMGAdapt:
3007     {
3008       if ( isStudyLocked() )
3009         break;
3010       EmitSignalDeactivateDialog();
3011
3012       SALOME::GenericObj_wrap< SMESH::MG_ADAPT > model = GetSMESHGen()->CreateMG_ADAPT();
3013       bool isCreation = false;
3014       ( new SMESHGUI_MG_ADAPTDRIVER( this, model, isCreation ))->show();
3015       break;
3016     }
3017 #endif
3018   // Adaptation - end
3019   case SMESHOp::OpSplitBiQuadratic:
3020   case SMESHOp::OpConvertMeshToQuadratic:
3021   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
3022   case SMESHOp::OpReorientFaces:
3023   case SMESHOp::OpCreateGeometryGroup:
3024     {
3025       if ( warnOnGeomModif() )
3026         break; // action forbidden as geometry modified
3027       startOperation( theCommandID );
3028       break;
3029     }
3030   case SMESHOp::OpCreateGroup:
3031     {
3032       if ( !vtkwnd )
3033       {
3034         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3035         break;
3036       }
3037
3038       if(isStudyLocked()) break;
3039       if ( warnOnGeomModif() )
3040         break; // action forbidden as geometry modified
3041       EmitSignalDeactivateDialog();
3042       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
3043
3044       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3045       SALOME_ListIO selected;
3046       if( aSel )
3047         aSel->selectedObjects( selected );
3048
3049       int nbSel = selected.Extent();
3050       if (nbSel == 1) {
3051         // check if mesh is selected
3052         aMesh = SMESH::GetMeshByIO( selected.First() );
3053       }
3054       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
3055       aDlg->show();
3056       break;
3057     }
3058
3059   case SMESHOp::OpConstructGroup:
3060     {
3061       if ( !vtkwnd )
3062       {
3063         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3064         break;
3065       }
3066
3067       if(isStudyLocked()) break;
3068       if ( warnOnGeomModif() )
3069         break; // action forbidden as geometry modified
3070       EmitSignalDeactivateDialog();
3071
3072       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3073       SALOME_ListIO selected;
3074       if( aSel )
3075         aSel->selectedObjects( selected );
3076
3077       int nbSel = selected.Extent();
3078       if (nbSel == 1) {
3079         // check if submesh is selected
3080         Handle(SALOME_InteractiveObject) IObject = selected.First();
3081         if (IObject->hasEntry()) {
3082           _PTR(SObject) aSObj = SMESH::getStudy()->FindObjectID(IObject->getEntry());
3083           if( aSObj ) {
3084             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
3085             if (!aSubMesh->_is_nil()) {
3086               try {
3087                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
3088                 // get submesh elements list by types
3089                 SMESH::smIdType_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
3090                 SMESH::smIdType_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
3091                 SMESH::smIdType_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
3092                 SMESH::smIdType_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
3093                 // create group for each type o elements
3094                 QString aName = IObject->getName();
3095                 QStringList anEntryList;
3096                 if (aNodes->length() > 0) {
3097                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
3098                   aGroup->Add(aNodes.inout());
3099                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3100                     anEntryList.append( aSObject->GetID().c_str() );
3101                 }
3102                 if (aEdges->length() > 0) {
3103                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
3104                   aGroup->Add(aEdges.inout());
3105                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3106                     anEntryList.append( aSObject->GetID().c_str() );
3107                 }
3108                 if (aFaces->length() > 0) {
3109                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
3110                   aGroup->Add(aFaces.inout());
3111                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3112                     anEntryList.append( aSObject->GetID().c_str() );
3113                 }
3114                 if (aVolumes->length() > 0) {
3115                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
3116                   aGroup->Add(aVolumes.inout());
3117                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3118                     anEntryList.append( aSObject->GetID().c_str() );
3119                 }
3120                 updateObjBrowser();
3121                 anApp->browseObjects( anEntryList );
3122               }
3123               catch(const SALOME::SALOME_Exception & S_ex){
3124                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3125               }
3126             }
3127           }
3128         }
3129       }
3130       else if(nbSel==0) {
3131         SUIT_MessageBox::warning(desktop(),
3132                                  tr("SMESH_WRN_WARNING"),
3133                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
3134       }
3135       break;
3136     }
3137
3138   case SMESHOp::OpEditGroup:
3139     {
3140       if ( !vtkwnd )
3141       {
3142         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3143         break;
3144       }
3145
3146       if(isStudyLocked()) break;
3147       if ( warnOnGeomModif() )
3148         break; // action forbidden as geometry modified
3149       EmitSignalDeactivateDialog();
3150
3151       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3152       SALOME_ListIO selected;
3153       if( aSel )
3154         aSel->selectedObjects( selected );
3155
3156       SALOME_ListIteratorOfListIO It (selected);
3157       int nbSelectedGroups = 0;
3158       for ( ; It.More(); It.Next() )
3159       {
3160         SMESH::SMESH_GroupBase_var aGroup =
3161           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
3162         if (!aGroup->_is_nil()) {
3163           nbSelectedGroups++;
3164           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
3165           aDlg->show();
3166         }
3167       }
3168       if (nbSelectedGroups == 0)
3169         {
3170           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
3171           aDlg->show();
3172         }
3173       break;
3174     }
3175
3176   case SMESHOp::OpAddElemGroupPopup:     // Add elements to group
3177     {
3178       if(isStudyLocked()) break;
3179       if (myState == 800) {
3180         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3181         if (aDlg) aDlg->onAdd();
3182       }
3183       break;
3184     }
3185
3186   case SMESHOp::OpRemoveElemGroupPopup:  // Remove elements from group
3187     {
3188       if(isStudyLocked()) break;
3189       if (myState == 800) {
3190         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3191         if (aDlg) aDlg->onRemove();
3192       }
3193       break;
3194     }
3195
3196   case SMESHOp::OpEditGeomGroupAsGroup:
3197     {
3198       if ( !vtkwnd )
3199       {
3200         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3201         break;
3202       }
3203
3204       if(isStudyLocked()) break;
3205       EmitSignalDeactivateDialog();
3206
3207       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3208       SALOME_ListIO selected;
3209       if( aSel )
3210         aSel->selectedObjects( selected );
3211
3212       SALOME_ListIteratorOfListIO It (selected);
3213       for ( ; It.More(); It.Next() )
3214       {
3215         SMESH::SMESH_GroupOnGeom_var aGroup =
3216           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3217         if (!aGroup->_is_nil()) {
3218           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3219           aDlg->show();
3220         }
3221         else
3222         {
3223           SMESH::SMESH_GroupOnFilter_var aGroup =
3224             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3225           if (!aGroup->_is_nil()) {
3226             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3227             aDlg->show();
3228           }
3229         }
3230       }
3231       break;
3232     }
3233
3234     case SMESHOp::OpUnionGroups:
3235     case SMESHOp::OpIntersectGroups:
3236     case SMESHOp::OpCutGroups:
3237     {
3238       if ( !vtkwnd )
3239       {
3240         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3241         break;
3242       }
3243
3244       if ( isStudyLocked() )
3245         break;
3246       if ( warnOnGeomModif() )
3247         break; // action forbidden as geometry modified
3248
3249       EmitSignalDeactivateDialog();
3250
3251       SMESHGUI_GroupOpDlg* aDlg = 0;
3252       if ( theCommandID == SMESHOp::OpUnionGroups )
3253         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3254       else if ( theCommandID == SMESHOp::OpIntersectGroups )
3255         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3256       else
3257         aDlg = new SMESHGUI_CutGroupsDlg( this );
3258
3259       aDlg->show();
3260
3261       break;
3262     }
3263
3264     case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3265     {
3266       if ( isStudyLocked() )
3267         break;
3268       if ( warnOnGeomModif() )
3269         break; // action forbidden as geometry modified
3270
3271       EmitSignalDeactivateDialog();
3272       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3273       aDlg->show();
3274
3275       break;
3276     }
3277
3278     case SMESHOp::OpFaceGroupsByEdges: // Create face groups separated by sharp edges
3279     {
3280       if ( isStudyLocked() )
3281         break;
3282       if ( warnOnGeomModif() )
3283         break; // action forbidden as geometry modified
3284
3285       EmitSignalDeactivateDialog();
3286       SMESHGUI_FaceGroupsSeparatedByEdgesDlg* aDlg = new SMESHGUI_FaceGroupsSeparatedByEdgesDlg( this );
3287       aDlg->show();
3288
3289       break;
3290     }
3291
3292     case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3293     {
3294       if ( !vtkwnd )
3295       {
3296         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3297         break;
3298       }
3299
3300       if ( isStudyLocked() )
3301         break;
3302
3303       EmitSignalDeactivateDialog();
3304
3305       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3306       break;
3307     }
3308
3309   case SMESHOp::OpMeshInformation:
3310   case SMESHOp::OpWhatIs:
3311     {
3312       int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3313       EmitSignalDeactivateDialog();
3314       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3315       SALOME_ListIO selected;
3316       if( aSel )
3317         aSel->selectedObjects( selected );
3318
3319       if ( selected.Extent() > 1 ) { // a dlg for each IO
3320         SALOME_ListIteratorOfListIO It( selected );
3321         for ( ; It.More(); It.Next() ) {
3322           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3323           dlg->showInfo( It.Value() );
3324           dlg->show();
3325         }
3326       }
3327       else {
3328         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3329         dlg->show();
3330       }
3331       break;
3332     }
3333
3334   case SMESHOp::OpFindElementByPoint:
3335     {
3336       startOperation( theCommandID );
3337       break;
3338     }
3339
3340   case SMESHOp::OpEditHypothesis:
3341     {
3342       if(isStudyLocked()) break;
3343       if ( warnOnGeomModif() )
3344         break; // action forbidden as geometry modified
3345
3346       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3347       SALOME_ListIO selected;
3348       if( aSel )
3349         aSel->selectedObjects( selected );
3350
3351       int nbSel = selected.Extent();
3352
3353       if (nbSel == 1) {
3354         Handle(SALOME_InteractiveObject) anIObject = selected.First();
3355         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3356
3357         if ( !aHypothesis->_is_nil() )
3358         {
3359           SMESHGUI_GenericHypothesisCreator* aCreator =
3360             SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3361           if (aCreator)
3362           {
3363             // set geometry of mesh and sub-mesh to aCreator
3364             aSel->selectedObjects( selected, "",  /*convertReferences=*/false);
3365             if ( selected.Extent() == 1 )
3366             {
3367               QString subGeomID, meshGeomID;
3368               Handle(SALOME_InteractiveObject) hypIO = selected.First();
3369               if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3370               {
3371                 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3372                 aCreator->setShapeEntry( subGeomID );
3373                 aCreator->setMainShapeEntry( meshGeomID );
3374               }
3375             }
3376
3377             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3378           }
3379           else
3380           {
3381             // report error
3382           }
3383         }
3384       }
3385       break;
3386     }
3387   case SMESHOp::OpUnassign:                      // REMOVE HYPOTHESIS / ALGORITHMS
3388     {
3389       if(isStudyLocked()) break;
3390       if ( warnOnGeomModif() )
3391         break; // action forbidden as geometry modified
3392       SUIT_OverrideCursor wc;
3393
3394       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3395       SALOME_ListIO selected;
3396       if( aSel )
3397         aSel->selectedObjects( selected, QString::null, false );
3398
3399       SALOME_ListIteratorOfListIO It(selected);
3400       for (int i = 0; It.More(); It.Next(), i++) {
3401         Handle(SALOME_InteractiveObject) IObject = It.Value();
3402         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3403       }
3404       SALOME_ListIO l1;
3405       aSel->setSelectedObjects( l1 );
3406       updateObjBrowser();
3407       break;
3408     }
3409
3410   case SMESHOp::OpElem0D:
3411   case SMESHOp::OpBall:
3412   case SMESHOp::OpEdge:
3413   case SMESHOp::OpTriangle:
3414   case SMESHOp::OpQuadrangle:
3415   case SMESHOp::OpPolygon:
3416   case SMESHOp::OpTetrahedron:
3417   case SMESHOp::OpHexahedron:
3418   case SMESHOp::OpPentahedron:
3419   case SMESHOp::OpPyramid:
3420   case SMESHOp::OpHexagonalPrism:
3421     {
3422       if(isStudyLocked()) break;
3423       if ( warnOnGeomModif() )
3424         break; // action forbidden as geometry modified
3425       if ( vtkwnd ) {
3426         EmitSignalDeactivateDialog();
3427         SMDSAbs_EntityType type = SMDSEntity_Edge;
3428         switch (theCommandID) {
3429         case SMESHOp::OpElem0D: type = SMDSEntity_0D;                      break;
3430         case SMESHOp::OpBall: type = SMDSEntity_Ball;                      break;
3431         case SMESHOp::OpTriangle: type = SMDSEntity_Triangle;              break;
3432         case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle;          break;
3433         case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra;              break;
3434         case SMESHOp::OpPolygon: type = SMDSEntity_Polygon;                break;
3435         case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa;                break;
3436         case SMESHOp::OpPentahedron: type = SMDSEntity_Penta;              break;
3437         case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid;                break;
3438         case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3439         default:;
3440         }
3441         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3442       }
3443       else {
3444         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3445       }
3446       break;
3447     }
3448   case SMESHOp::OpPolyhedron:
3449     {
3450       if(isStudyLocked()) break;
3451       if ( warnOnGeomModif() )
3452         break; // action forbidden as geometry modified
3453       if ( vtkwnd ) {
3454         EmitSignalDeactivateDialog();
3455         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3456       }
3457       else {
3458         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3459       }
3460       break;
3461     }
3462   case SMESHOp::OpQuadraticEdge:
3463   case SMESHOp::OpQuadraticTriangle:
3464   case SMESHOp::OpBiQuadraticTriangle:
3465   case SMESHOp::OpQuadraticQuadrangle:
3466   case SMESHOp::OpBiQuadraticQuadrangle:
3467   case SMESHOp::OpQuadraticPolygon:
3468   case SMESHOp::OpQuadraticTetrahedron:
3469   case SMESHOp::OpQuadraticPyramid:
3470   case SMESHOp::OpQuadraticPentahedron:
3471   case SMESHOp::OpBiQuadraticPentahedron:
3472   case SMESHOp::OpQuadraticHexahedron:
3473   case SMESHOp::OpTriQuadraticHexahedron:
3474     {
3475       if(isStudyLocked()) break;
3476       if ( warnOnGeomModif() )
3477         break; // action forbidden as geometry modified
3478       if ( vtkwnd ) {
3479         EmitSignalDeactivateDialog();
3480         SMDSAbs_EntityType type = SMDSEntity_Last;
3481
3482         switch (theCommandID) {
3483         case SMESHOp::OpQuadraticEdge:          type = SMDSEntity_Quad_Edge; break;
3484         case SMESHOp::OpQuadraticTriangle:      type = SMDSEntity_Quad_Triangle; break;
3485         case SMESHOp::OpBiQuadraticTriangle:    type = SMDSEntity_BiQuad_Triangle; break;
3486         case SMESHOp::OpQuadraticQuadrangle:    type = SMDSEntity_Quad_Quadrangle; break;
3487         case SMESHOp::OpBiQuadraticQuadrangle:  type = SMDSEntity_BiQuad_Quadrangle; break;
3488         case SMESHOp::OpQuadraticPolygon:       type = SMDSEntity_Quad_Polygon; break;
3489         case SMESHOp::OpQuadraticTetrahedron:   type = SMDSEntity_Quad_Tetra; break;
3490         case SMESHOp::OpQuadraticPyramid:       type = SMDSEntity_Quad_Pyramid; break;
3491         case SMESHOp::OpQuadraticPentahedron:   type = SMDSEntity_Quad_Penta; break;
3492         case SMESHOp::OpBiQuadraticPentahedron: type = SMDSEntity_BiQuad_Penta; break;
3493         case SMESHOp::OpQuadraticHexahedron:    type = SMDSEntity_Quad_Hexa; break;
3494         case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3495         default: break;
3496         }
3497         if ( type != SMDSEntity_Last )
3498           ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3499       }
3500       else {
3501         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3502                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3503       }
3504       break;
3505     }
3506   case SMESHOp::OpRemoveNodes:
3507     {
3508       if(isStudyLocked()) break;
3509       if ( warnOnGeomModif() )
3510         break; // action forbidden as geometry modified
3511       if ( vtkwnd ) {
3512         EmitSignalDeactivateDialog();
3513         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3514       }
3515       else {
3516         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3517                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3518       }
3519       break;
3520     }
3521   case SMESHOp::OpRemoveElements:                                    // REMOVES ELEMENTS
3522     {
3523       if(isStudyLocked()) break;
3524       if ( warnOnGeomModif() )
3525         break; // action forbidden as geometry modified
3526       if( vtkwnd ) {
3527         EmitSignalDeactivateDialog();
3528         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3529       }
3530       else
3531         {
3532           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3533                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3534         }
3535       break;
3536     }
3537   case SMESHOp::OpClearMesh: {
3538
3539     if(isStudyLocked()) break;
3540     if ( warnOnGeomModif() )
3541       break; // action forbidden as geometry modified
3542
3543     SALOME_ListIO selected;
3544     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3545       aSel->selectedObjects( selected );
3546
3547     SUIT_OverrideCursor wc;
3548     SALOME_ListIteratorOfListIO It (selected);
3549     for ( ; It.More(); It.Next() )
3550     {
3551       Handle(SALOME_InteractiveObject) IOS = It.Value();
3552       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3553       if ( aMesh->_is_nil()) continue;
3554       try {
3555         aMesh->Clear();
3556         if ( aMesh->NbNodes() == 0 ) // imported mesh is not empty
3557           SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3558         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3559         // hide groups and submeshes
3560         _PTR(ChildIterator) anIter =
3561           SMESH::getStudy()->NewChildIterator( aMeshSObj );
3562         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3563         {
3564           _PTR(SObject) so = anIter->Value();
3565           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3566         }
3567       }
3568       catch (const SALOME::SALOME_Exception& S_ex){
3569         wc.suspend();
3570         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3571         wc.resume();
3572       }
3573     }
3574     SMESH::UpdateView();
3575     updateObjBrowser();
3576     break;
3577   }
3578   case SMESHOp::OpRemoveOrphanNodes:
3579     {
3580       if(isStudyLocked()) break;
3581       if ( warnOnGeomModif() )
3582         break; // action forbidden as geometry modified
3583       SALOME_ListIO selected;
3584       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3585         aSel->selectedObjects( selected );
3586       if ( selected.Extent() == 1 ) {
3587         Handle(SALOME_InteractiveObject) anIO = selected.First();
3588         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3589         if ( !aMesh->_is_nil() ) {
3590           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3591                                                     tr( "SMESH_WARNING" ),
3592                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3593                                                     SUIT_MessageBox::Yes |
3594                                                     SUIT_MessageBox::No,
3595                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3596           if( confirm ) {
3597             try {
3598               SUIT_OverrideCursor wc;
3599               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3600               smIdType removed = aMeshEditor->RemoveOrphanNodes();
3601               SUIT_MessageBox::information(SMESHGUI::desktop(),
3602                                            tr("SMESH_INFORMATION"),
3603                                            tr("NB_NODES_REMOVED").arg(removed));
3604               if ( removed > 0 ) {
3605                 SMESH::UpdateView();
3606                 SMESHGUI::Modified();
3607               }
3608             }
3609             catch (const SALOME::SALOME_Exception& S_ex) {
3610               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3611             }
3612             catch (...) {
3613             }
3614           }
3615         }
3616       }
3617       break;
3618     }
3619   case SMESHOp::OpRenumberingNodes:
3620     {
3621       if(isStudyLocked()) break;
3622       if ( warnOnGeomModif() )
3623         break; // action forbidden as geometry modified
3624       if( vtkwnd ) {
3625         EmitSignalDeactivateDialog();
3626         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3627       }
3628       else
3629         {
3630           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3631                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3632         }
3633       break;
3634     }
3635   case SMESHOp::OpRenumberingElements:
3636     {
3637       if(isStudyLocked()) break;
3638       if ( warnOnGeomModif() )
3639         break; // action forbidden as geometry modified
3640       if ( vtkwnd ) {
3641         EmitSignalDeactivateDialog();
3642         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3643       }
3644       else
3645         {
3646           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3647                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3648         }
3649       break;
3650     }
3651   case SMESHOp::OpTranslation:
3652     {
3653       if(isStudyLocked()) break;
3654       if ( warnOnGeomModif() )
3655         break; // action forbidden as geometry modified
3656       if ( vtkwnd ) {
3657         EmitSignalDeactivateDialog();
3658         ( new SMESHGUI_TranslationDlg( this ) )->show();
3659       }
3660       else {
3661         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3662                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3663       }
3664       break;
3665     }
3666   case SMESHOp::OpRotation:
3667     {
3668       if(isStudyLocked()) break;
3669       if ( warnOnGeomModif() )
3670         break; // action forbidden as geometry modified
3671       if( vtkwnd ) {
3672         EmitSignalDeactivateDialog();
3673         ( new SMESHGUI_RotationDlg( this ) )->show();
3674       }
3675       else {
3676         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3677                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3678       }
3679       break;
3680     }
3681   case SMESHOp::OpSymmetry:
3682     {
3683       if(isStudyLocked()) break;
3684       if ( warnOnGeomModif() )
3685         break; // action forbidden as geometry modified
3686       if(vtkwnd) {
3687         EmitSignalDeactivateDialog();
3688         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3689       }
3690       else {
3691         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3692                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3693       }
3694       break;
3695     }
3696   case SMESHOp::OpScale:
3697     {
3698       if(isStudyLocked()) break;
3699       if ( warnOnGeomModif() )
3700         break; // action forbidden as geometry modified
3701       if ( vtkwnd ) {
3702         EmitSignalDeactivateDialog();
3703         ( new SMESHGUI_ScaleDlg( this ) )->show();
3704       }
3705       else {
3706         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3707                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3708       }
3709       break;
3710     }
3711
3712   case SMESHOp::OpOffset:
3713     {
3714       if(isStudyLocked()) break;
3715       if ( warnOnGeomModif() )
3716         break; // action forbidden as geometry modified
3717       if ( vtkwnd ) {
3718         EmitSignalDeactivateDialog();
3719         ( new SMESHGUI_OffsetDlg( this ) )->show();
3720       }
3721       else {
3722         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3723                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3724       }
3725       break;
3726     }
3727
3728   case SMESHOp::OpSewing:
3729     {
3730       if(isStudyLocked()) break;
3731       if ( warnOnGeomModif() )
3732         break; // action forbidden as geometry modified
3733       if(vtkwnd) {
3734         EmitSignalDeactivateDialog();
3735         ( new SMESHGUI_SewingDlg( this ) )->show();
3736       }
3737       else {
3738         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3739                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3740       }
3741       break;
3742     }
3743   case SMESHOp::OpMergeNodes:
3744     {
3745       if(isStudyLocked()) break;
3746       if ( warnOnGeomModif() )
3747         break; // action forbidden as geometry modified
3748       if(vtkwnd) {
3749         EmitSignalDeactivateDialog();
3750         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3751       }
3752       else {
3753         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3754                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3755       }
3756       break;
3757     }
3758   case SMESHOp::OpMergeElements:
3759     {
3760       if (isStudyLocked()) break;
3761       if ( warnOnGeomModif() )
3762         break; // action forbidden as geometry modified
3763       if (vtkwnd) {
3764         EmitSignalDeactivateDialog();
3765         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3766       } else {
3767         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3768                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3769       }
3770       break;
3771     }
3772
3773   case SMESHOp::OpMoveNode: // MAKE MESH PASS THROUGH POINT
3774     if ( warnOnGeomModif() )
3775       break; // action forbidden as geometry modified
3776     startOperation( SMESHOp::OpMoveNode );
3777     break;
3778
3779   case SMESHOp::OpDuplicateNodes:
3780     {
3781       if(isStudyLocked()) break;
3782       if ( warnOnGeomModif() )
3783         break; // action forbidden as geometry modified
3784       if ( vtkwnd ) {
3785         EmitSignalDeactivateDialog();
3786         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3787       }
3788       else {
3789         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3790                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3791       }
3792       break;
3793     }
3794
3795   case SMESHOp::OpElem0DOnElemNodes: // 0D_ON_ALL_NODES
3796     if ( warnOnGeomModif() )
3797       break; // action forbidden as geometry modified
3798     startOperation( SMESHOp::OpElem0DOnElemNodes );
3799     break;
3800
3801   case SMESHOp::OpSelectFiltersLibrary: // Library of selection filters
3802   {
3803     static QList<int> aTypes;
3804     if ( aTypes.isEmpty() )
3805     {
3806       aTypes.append( SMESH::NODE );
3807       aTypes.append( SMESH::EDGE );
3808       aTypes.append( SMESH::FACE );
3809       aTypes.append( SMESH::VOLUME );
3810     }
3811     if (!myFilterLibraryDlg)
3812       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3813     else if (myFilterLibraryDlg->isHidden())
3814       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3815     myFilterLibraryDlg->raise();
3816   }
3817   break;
3818   // CONTROLS
3819   case SMESHOp::OpFreeNode:
3820   case SMESHOp::OpEqualNode:
3821   case SMESHOp::OpNodeConnectivityNb:
3822   case SMESHOp::OpFreeEdge:
3823   case SMESHOp::OpFreeBorder:
3824   case SMESHOp::OpLength:
3825   case SMESHOp::OpConnection:
3826   case SMESHOp::OpEqualEdge:
3827   case SMESHOp::OpFreeFace:
3828   case SMESHOp::OpBareBorderFace:
3829   case SMESHOp::OpOverConstrainedFace:
3830   case SMESHOp::OpLength2D:
3831   case SMESHOp::OpDeflection2D:
3832   case SMESHOp::OpConnection2D:
3833   case SMESHOp::OpArea:
3834   case SMESHOp::OpTaper:
3835   case SMESHOp::OpAspectRatio:
3836   case SMESHOp::OpMinimumAngle:
3837   case SMESHOp::OpWarpingAngle:
3838   case SMESHOp::OpSkew:
3839   case SMESHOp::OpMaxElementLength2D:
3840   case SMESHOp::OpEqualFace:
3841   case SMESHOp::OpAspectRatio3D:
3842   case SMESHOp::OpVolume:
3843   case SMESHOp::OpMaxElementLength3D:
3844   case SMESHOp::OpBareBorderVolume:
3845   case SMESHOp::OpOverConstrainedVolume:
3846   case SMESHOp::OpEqualVolume:
3847     if ( vtkwnd ) {
3848
3849       LightApp_SelectionMgr* mgr = selectionMgr();
3850       SALOME_ListIO selected; mgr->selectedObjects( selected );
3851
3852       if( !selected.IsEmpty() ) {
3853         SUIT_OverrideCursor wc;
3854         ::Control( theCommandID );
3855         break;
3856       }
3857       SUIT_MessageBox::warning(desktop(),
3858                                tr( "SMESH_WRN_WARNING" ),
3859                                tr( "SMESH_BAD_SELECTION" ) );
3860       break;
3861     }
3862     else {
3863       SUIT_MessageBox::warning(desktop(),
3864                                tr( "SMESH_WRN_WARNING" ),
3865                                tr( "NOT_A_VTK_VIEWER" ) );
3866     }
3867     break;
3868   case SMESHOp::OpOverallMeshQuality:
3869     OverallMeshQuality();
3870     break;
3871   case SMESHOp::OpNumberingNodes:
3872     {
3873       SUIT_OverrideCursor wc;
3874       LightApp_SelectionMgr* mgr = selectionMgr();
3875       SALOME_ListIO selected; mgr->selectedObjects( selected );
3876
3877       SALOME_ListIteratorOfListIO it(selected);
3878       for( ; it.More(); it.Next()) {
3879         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3880         if(anIObject->hasEntry()) {
3881           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3882             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3883           }
3884         }
3885       }
3886       break;
3887     }
3888   case SMESHOp::OpNumberingElements:
3889     {
3890       SUIT_OverrideCursor wc;
3891       LightApp_SelectionMgr* mgr = selectionMgr();
3892       SALOME_ListIO selected; mgr->selectedObjects( selected );
3893
3894       SALOME_ListIteratorOfListIO it(selected);
3895       for( ; it.More(); it.Next()) {
3896         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3897         if(anIObject->hasEntry())
3898           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3899             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3900           }
3901       }
3902       break;
3903     }
3904   case SMESHOp::OpPropertiesLength:
3905   case SMESHOp::OpPropertiesArea:
3906   case SMESHOp::OpPropertiesVolume:
3907   case SMESHOp::OpMinimumDistance:
3908   case SMESHOp::OpBoundingBox:
3909   case SMESHOp::OpAngle:
3910     {
3911       int page = SMESHGUI_MeasureDlg::MinDistance;
3912       if ( theCommandID == SMESHOp::OpBoundingBox )
3913         page = SMESHGUI_MeasureDlg::BoundingBox;
3914       else if ( theCommandID == SMESHOp::OpPropertiesLength )
3915         page = SMESHGUI_MeasureDlg::Length;
3916       else if ( theCommandID == SMESHOp::OpPropertiesArea )
3917         page = SMESHGUI_MeasureDlg::Area;
3918       else if ( theCommandID == SMESHOp::OpPropertiesVolume )
3919         page = SMESHGUI_MeasureDlg::Volume;
3920       else if ( theCommandID == SMESHOp::OpAngle )
3921         page = SMESHGUI_MeasureDlg::Angle;
3922
3923       EmitSignalDeactivateDialog();
3924       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3925       dlg->show();
3926       break;
3927     }
3928   case SMESHOp::OpSortChild:
3929     ::sortChildren();
3930     break;
3931   case SMESHOp::OpBreakLink:
3932     ::breakShaperLink();
3933     break;
3934
3935   }
3936
3937   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3938   //updateObjBrowser();
3939   return true;
3940 }
3941
3942 //=============================================================================
3943 /*!
3944  *
3945  */
3946 //=============================================================================
3947 bool SMESHGUI::OnMousePress( QMouseEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3948 {
3949   return false;
3950 }
3951
3952 //=============================================================================
3953 /*!
3954  *
3955  */
3956 //=============================================================================
3957 bool SMESHGUI::OnMouseMove( QMouseEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3958 {
3959   return true;
3960 }
3961
3962 //=============================================================================
3963 /*!
3964  *
3965  */
3966 //=============================================================================
3967 bool SMESHGUI::OnKeyPress( QKeyEvent * /*pe*/, SUIT_ViewWindow * /*wnd*/ )
3968 {
3969   return true;
3970 }
3971
3972 //=============================================================================
3973 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3974  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3975  */
3976 //=============================================================================
3977 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3978                                   SUIT_ViewWindow* wnd )
3979 {
3980   if(theIO->hasEntry()){
3981     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3982     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3983   }
3984 }
3985
3986 //=======================================================================
3987 // function : createSMESHAction
3988 // purpose  :
3989 //=======================================================================
3990 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
3991                                   const int key, const bool toggle, const QString& shortcutAction  )
3992 {
3993   QIcon icon;
3994   QWidget* parent = application()->desktop();
3995   SUIT_ResourceMgr* resMgr = resourceMgr();
3996   QPixmap pix;
3997   if ( !icon_id.isEmpty() )
3998     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3999   else
4000     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICON_%1" ).arg( po_id ).toLatin1().data() ), false );
4001   if ( !pix.isNull() )
4002     icon = QIcon( pix );
4003
4004   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
4005           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
4006           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
4007
4008   createAction( id, tooltip, icon, menu, status_bar, key, parent,
4009                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
4010 }
4011
4012 //=======================================================================
4013 // function : createPopupItem
4014 // purpose  :
4015 //=======================================================================
4016 void SMESHGUI::createPopupItem( const int id,
4017                                 const QString& clients,
4018                                 const QString& types,
4019                                 const QString& theRule,
4020                                 const int pId )
4021 {
4022   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
4023     popupMgr()->insert( action( id ), pId, 0 );
4024
4025   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4026   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4027   QString rule = "(%1) and (%2) and (%3)";
4028   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
4029   if( clients.isEmpty() )
4030     rule = rule.arg( QString( "true" ) );
4031   else
4032     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
4033   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
4034   rule += theRule;
4035
4036   bool cont = myRules.contains( id );
4037   if( cont )
4038     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
4039
4040   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
4041   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
4042 }
4043
4044 //=======================================================================
4045 // function : initialize
4046 // purpose  :
4047 //=======================================================================
4048 void SMESHGUI::initialize( CAM_Application* app )
4049 {
4050   SalomeApp_Module::initialize( app );
4051
4052 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
4053 //   if ( mgr )
4054   /* Automatic Update flag */
4055 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
4056
4057   // ----- create actions --------------
4058
4059   //createSMESHAction(  SMESHOp::OpImportDAT, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
4060   createSMESHAction( SMESHOp::OpImportUNV, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_I) );
4061   createSMESHAction( SMESHOp::OpImportMED, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
4062   createSMESHAction( SMESHOp::OpImportSTL, "IMPORT_STL"  );
4063 #ifdef WITH_CGNS
4064   createSMESHAction( SMESHOp::OpImportCGNS, "IMPORT_CGNS" );
4065 #endif
4066   createSMESHAction( SMESHOp::OpImportGMF,  "IMPORT_GMF"  );
4067   createSMESHAction( SMESHOp::OpPopupImportUNV, "IMPORT_UNV");
4068   createSMESHAction( SMESHOp::OpPopupImportMED, "IMPORT_MED");
4069   createSMESHAction( SMESHOp::OpPopupImportSTL, "IMPORT_STL"  );
4070 #ifdef WITH_CGNS
4071   createSMESHAction( SMESHOp::OpPopupImportCGNS, "IMPORT_CGNS" );
4072 #endif
4073   createSMESHAction( SMESHOp::OpPopupImportGMF,  "IMPORT_GMF"  );
4074
4075   createSMESHAction( SMESHOp::OpExportDAT,  "DAT" );
4076   createSMESHAction( SMESHOp::OpExportMED,  "MED" );
4077   createSMESHAction( SMESHOp::OpExportUNV,  "UNV" );
4078   createSMESHAction( SMESHOp::OpExportSTL,  "STL" );
4079 #ifdef WITH_CGNS
4080   createSMESHAction( SMESHOp::OpExportCGNS, "CGNS");
4081 #endif
4082   createSMESHAction( SMESHOp::OpExportGMF,      "GMF" );
4083   createSMESHAction( SMESHOp::OpPopupExportDAT, "DAT" );
4084   createSMESHAction( SMESHOp::OpPopupExportMED, "MED" );
4085   createSMESHAction( SMESHOp::OpPopupExportUNV, "UNV" );
4086   createSMESHAction( SMESHOp::OpPopupExportSTL, "STL" );
4087 #ifdef WITH_CGNS
4088   createSMESHAction( SMESHOp::OpPopupExportCGNS, "CGNS");
4089 #endif
4090   createSMESHAction( SMESHOp::OpPopupExportGMF,  "GMF" );
4091   createSMESHAction( SMESHOp::OpFileInformation, "FILE_INFO" );
4092   createSMESHAction( SMESHOp::OpDelete,          "DELETE", "ICON_DELETE", Qt::Key_Delete );
4093   createSMESHAction( SMESHOp::OpSelectFiltersLibrary, "SEL_FILTER_LIB" );
4094   createSMESHAction( SMESHOp::OpCreateMesh,           "CREATE_MESH",             "ICON_DLG_INIT_MESH" );
4095   createSMESHAction( SMESHOp::OpCreateSubMesh,        "CREATE_SUBMESH",          "ICON_DLG_ADD_SUBMESH" );
4096   createSMESHAction( SMESHOp::OpEditMeshOrSubMesh,    "EDIT_MESHSUBMESH",        "ICON_DLG_EDIT_MESH" );
4097   createSMESHAction( SMESHOp::OpEditMesh,             "EDIT_MESH",               "ICON_DLG_EDIT_MESH" );
4098   createSMESHAction( SMESHOp::OpEditSubMesh,          "EDIT_SUBMESH",            "ICON_DLG_EDIT_MESH" );
4099   createSMESHAction( SMESHOp::OpBuildCompoundMesh,    "BUILD_COMPOUND",          "ICON_BUILD_COMPOUND" );
4100   createSMESHAction( SMESHOp::OpCopyMesh,             "COPY_MESH",               "ICON_COPY_MESH" );
4101   createSMESHAction( SMESHOp::OpCompute,              "COMPUTE",                 "ICON_COMPUTE" );
4102   createSMESHAction( SMESHOp::OpComputeSubMesh,       "COMPUTE_SUBMESH",         "ICON_COMPUTE" );
4103   createSMESHAction( SMESHOp::OpRecompute,            "RE_COMPUTE",              "ICON_COMPUTE" );
4104   createSMESHAction( SMESHOp::OpPreCompute,           "PRECOMPUTE",              "ICON_PRECOMPUTE" );
4105   createSMESHAction( SMESHOp::OpShowErrors,           "SHOW_ERRORS",             "ICON_SHOW_ERRORS" );
4106   createSMESHAction( SMESHOp::OpEvaluate,             "EVALUATE",                "ICON_EVALUATE" );
4107   createSMESHAction( SMESHOp::OpMeshOrder,            "MESH_ORDER",              "ICON_MESH_ORDER");
4108   createSMESHAction( SMESHOp::OpCreateGroup,          "CREATE_GROUP",            "ICON_CREATE_GROUP" );
4109   createSMESHAction( SMESHOp::OpCreateGeometryGroup,  "CREATE_GEO_GROUP",        "ICON_CREATE_GEO_GROUP" );
4110   createSMESHAction( SMESHOp::OpConstructGroup,       "CONSTRUCT_GROUP",         "ICON_CONSTRUCT_GROUP" );
4111   createSMESHAction( SMESHOp::OpEditGroup,            "EDIT_GROUP",              "ICON_EDIT_GROUP" );
4112   createSMESHAction( SMESHOp::OpEditGeomGroupAsGroup, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
4113   createSMESHAction( SMESHOp::OpUnionGroups,          "UN_GROUP",                "ICON_UNION" );
4114   createSMESHAction( SMESHOp::OpIntersectGroups,      "INT_GROUP",               "ICON_INTERSECT" );
4115   createSMESHAction( SMESHOp::OpCutGroups,            "CUT_GROUP",               "ICON_CUT" );
4116   createSMESHAction( SMESHOp::OpGroupUnderlyingElem,  "UNDERLYING_ELEMS",        "ICON_UNDERLYING_ELEMS" );
4117   createSMESHAction( SMESHOp::OpFaceGroupsByEdges,    "FACE_GROUPS_BY_EDGES",    "ICON_FACE_GROUPS_BY_EDGES" );
4118   createSMESHAction( SMESHOp::OpAddElemGroupPopup,    "ADD_TO_GROUP" );
4119   createSMESHAction( SMESHOp::OpRemoveElemGroupPopup, "REMOVE_FROM_GROUP" );
4120   createSMESHAction( SMESHOp::OpDeleteGroup,          "DEL_GROUP",               "ICON_DEL_GROUP" );
4121   createSMESHAction( SMESHOp::OpMeshInformation ,     "ADV_INFO",                "ICON_ADV_INFO" );
4122   //createSMESHAction( SMESHOp::OpStdInfo, "STD_INFO",        "ICON_STD_INFO" );
4123   //createSMESHAction( SMESHOp::OpWhatIs, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4124   createSMESHAction( SMESHOp::OpFindElementByPoint,   "FIND_ELEM",               "ICON_FIND_ELEM" );
4125   //update
4126   createSMESHAction( SMESHOp::OpFreeNode,              "FREE_NODE",               "ICON_FREE_NODE",     0, true );
4127   createSMESHAction( SMESHOp::OpEqualNode,             "EQUAL_NODE",              "ICON_EQUAL_NODE",    0, true );
4128   createSMESHAction( SMESHOp::OpNodeConnectivityNb,    "NODE_CONNECTIVITY_NB",    "ICON_NODE_CONN_NB",    0, true );
4129   createSMESHAction( SMESHOp::OpFreeEdge,              "FREE_EDGE",               "ICON_FREE_EDGE",     0, true );
4130   createSMESHAction( SMESHOp::OpFreeBorder,            "FREE_BORDER",             "ICON_FREE_EDGE_2D",  0, true );
4131   createSMESHAction( SMESHOp::OpLength,                "LENGTH",                  "ICON_LENGTH",        0, true );
4132   createSMESHAction( SMESHOp::OpConnection,            "CONNECTION",              "ICON_CONNECTION",    0, true );
4133   createSMESHAction( SMESHOp::OpEqualEdge,             "EQUAL_EDGE",              "ICON_EQUAL_EDGE",    0, true );
4134   createSMESHAction( SMESHOp::OpFreeFace,              "FREE_FACES",              "ICON_FREE_FACES",    0, true );
4135   createSMESHAction( SMESHOp::OpBareBorderFace,        "BARE_BORDER_FACE",        "ICON_BARE_BORDER_FACE",        0, true );
4136   createSMESHAction( SMESHOp::OpOverConstrainedFace,   "OVER_CONSTRAINED_FACE",   "ICON_OVER_CONSTRAINED_FACE",   0, true );
4137   createSMESHAction( SMESHOp::OpLength2D,              "LENGTH_2D",               "ICON_LENGTH_2D",     0, true );
4138   createSMESHAction( SMESHOp::OpDeflection2D,          "DEFLECTION_2D",           "ICON_DEFLECTION_2D", 0, true );
4139   createSMESHAction( SMESHOp::OpConnection2D,          "CONNECTION_2D",           "ICON_CONNECTION_2D", 0, true );
4140   createSMESHAction( SMESHOp::OpArea,                  "AREA",                    "ICON_AREA",          0, true );
4141   createSMESHAction( SMESHOp::OpTaper,                 "TAPER",                   "ICON_TAPER",         0, true );
4142   createSMESHAction( SMESHOp::OpAspectRatio,           "ASPECT",                  "ICON_ASPECT",        0, true );
4143   createSMESHAction( SMESHOp::OpMinimumAngle,          "MIN_ANG",                 "ICON_ANGLE",         0, true );
4144   createSMESHAction( SMESHOp::OpWarpingAngle,          "WARP",                    "ICON_WARP",          0, true );
4145   createSMESHAction( SMESHOp::OpSkew,                  "SKEW",                    "ICON_SKEW",          0, true );
4146   createSMESHAction( SMESHOp::OpMaxElementLength2D,    "MAX_ELEMENT_LENGTH_2D",   "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
4147   createSMESHAction( SMESHOp::OpEqualFace,             "EQUAL_FACE",              "ICON_EQUAL_FACE",    0, true );
4148   createSMESHAction( SMESHOp::OpAspectRatio3D,         "ASPECT_3D",               "ICON_ASPECT_3D",     0, true );
4149   createSMESHAction( SMESHOp::OpVolume,                "VOLUME_3D",               "ICON_VOLUME_3D",     0, true );
4150   createSMESHAction( SMESHOp::OpMaxElementLength3D,    "MAX_ELEMENT_LENGTH_3D",   "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
4151   createSMESHAction( SMESHOp::OpBareBorderVolume,      "BARE_BORDER_VOLUME",      "ICON_BARE_BORDER_VOLUME",      0, true );
4152   createSMESHAction( SMESHOp::OpOverConstrainedVolume, "OVER_CONSTRAINED_VOLUME", "ICON_OVER_CONSTRAINED_VOLUME", 0, true );
4153   createSMESHAction( SMESHOp::OpEqualVolume,           "EQUAL_VOLUME",            "ICON_EQUAL_VOLUME",  0, true );
4154   createSMESHAction( SMESHOp::OpOverallMeshQuality,    "OVERALL_MESH_QUALITY",    "ICON_OVL_MESH_QUALITY" );
4155
4156   createSMESHAction( SMESHOp::OpNode,                   "NODE",            "ICON_DLG_NODE" );
4157   createSMESHAction( SMESHOp::OpElem0D,                 "ELEM0D",          "ICON_DLG_ELEM0D" );
4158   createSMESHAction( SMESHOp::OpElem0DOnElemNodes,      "0D_ON_ALL_NODES", "ICON_0D_ON_ALL_NODES" );
4159   createSMESHAction( SMESHOp::OpBall,                   "BALL",            "ICON_DLG_BALL" );
4160   createSMESHAction( SMESHOp::OpEdge,                   "EDGE",            "ICON_DLG_EDGE" );
4161   createSMESHAction( SMESHOp::OpTriangle,               "TRIANGLE",        "ICON_DLG_TRIANGLE" );
4162   createSMESHAction( SMESHOp::OpQuadrangle,             "QUAD",            "ICON_DLG_QUADRANGLE" );
4163   createSMESHAction( SMESHOp::OpPolygon,                "POLYGON",         "ICON_DLG_POLYGON" );
4164   createSMESHAction( SMESHOp::OpTetrahedron,            "TETRA",           "ICON_DLG_TETRAS" );
4165   createSMESHAction( SMESHOp::OpHexahedron,             "HEXA",            "ICON_DLG_HEXAS" );
4166   createSMESHAction( SMESHOp::OpPentahedron,            "PENTA",           "ICON_DLG_PENTA" );
4167   createSMESHAction( SMESHOp::OpPyramid ,               "PYRAMID",         "ICON_DLG_PYRAMID" );
4168   createSMESHAction( SMESHOp::OpHexagonalPrism,         "OCTA",            "ICON_DLG_OCTA" );
4169   createSMESHAction( SMESHOp::OpPolyhedron,             "POLYHEDRON",      "ICON_DLG_POLYHEDRON" );
4170   createSMESHAction( SMESHOp::OpQuadraticEdge,          "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
4171   createSMESHAction( SMESHOp::OpQuadraticTriangle,      "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
4172   createSMESHAction( SMESHOp::OpBiQuadraticTriangle,    "BIQUADRATIC_TRIANGLE",    "ICON_DLG_BIQUADRATIC_TRIANGLE" );
4173   createSMESHAction( SMESHOp::OpQuadraticQuadrangle,    "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
4174   createSMESHAction( SMESHOp::OpBiQuadraticQuadrangle,  "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
4175   createSMESHAction( SMESHOp::OpQuadraticPolygon,       "QUADRATIC_POLYGON",       "ICON_DLG_QUADRATIC_POLYGON" );
4176   createSMESHAction( SMESHOp::OpQuadraticTetrahedron,   "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
4177   createSMESHAction( SMESHOp::OpQuadraticPyramid,       "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
4178   createSMESHAction( SMESHOp::OpQuadraticPentahedron,   "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
4179   createSMESHAction( SMESHOp::OpBiQuadraticPentahedron, "BIQUADRATIC_PENTAHEDRON", "ICON_DLG_BIQUADRATIC_PENTAHEDRON" );
4180   createSMESHAction( SMESHOp::OpQuadraticHexahedron,    "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
4181   createSMESHAction( SMESHOp::OpTriQuadraticHexahedron, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
4182
4183   createSMESHAction( SMESHOp::OpRemoveNodes,       "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
4184   createSMESHAction( SMESHOp::OpRemoveElements,    "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
4185   createSMESHAction( SMESHOp::OpRemoveOrphanNodes, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
4186   createSMESHAction( SMESHOp::OpClearMesh,         "CLEAR_MESH",            "ICON_CLEAR_MESH" );
4187
4188   //createSMESHAction( SMESHOp::OpRenumberingNodes,    "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
4189   //createSMESHAction( SMESHOp::OpRenumberingElements, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
4190
4191   createSMESHAction( SMESHOp::OpTranslation,            "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
4192   createSMESHAction( SMESHOp::OpRotation,               "ROT",             "ICON_DLG_MESH_ROTATION" );
4193   createSMESHAction( SMESHOp::OpSymmetry,               "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
4194   createSMESHAction( SMESHOp::OpScale,                  "SCALE",           "ICON_DLG_MESH_SCALE" );
4195   createSMESHAction( SMESHOp::OpOffset,                 "OFFSET",          "ICON_DLG_MESH_OFFSET" );
4196   createSMESHAction( SMESHOp::OpSewing,                 "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
4197   createSMESHAction( SMESHOp::OpMergeNodes,             "MERGE",           "ICON_SMESH_MERGE_NODES" );
4198   createSMESHAction( SMESHOp::OpMergeElements,          "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
4199   createSMESHAction( SMESHOp::OpMoveNode,               "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
4200   createSMESHAction( SMESHOp::OpDuplicateNodes,         "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
4201   createSMESHAction( SMESHOp::OpDiagonalInversion,      "INV",             "ICON_DLG_MESH_DIAGONAL" );
4202   createSMESHAction( SMESHOp::OpUnionOfTwoTriangle,     "UNION2",          "ICON_UNION2TRI" );
4203   createSMESHAction( SMESHOp::OpOrientation,            "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
4204   createSMESHAction( SMESHOp::OpReorientFaces,          "REORIENT_2D",     "ICON_REORIENT_2D" );
4205   createSMESHAction( SMESHOp::OpUnionOfTriangles,       "UNION",           "ICON_UNIONTRI" );
4206   createSMESHAction( SMESHOp::OpCuttingOfQuadrangles,   "CUT",             "ICON_CUTQUAD" );
4207   createSMESHAction( SMESHOp::OpSplitVolumes,           "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
4208   createSMESHAction( SMESHOp::OpSplitBiQuadratic,       "SPLIT_BIQUAD",    "ICON_SPLIT_BIQUAD" );
4209   createSMESHAction( SMESHOp::OpSmoothing,              "SMOOTH",          "ICON_DLG_SMOOTHING" );
4210   createSMESHAction( SMESHOp::OpExtrusion,              "EXTRUSION",       "ICON_EXTRUSION" );
4211   createSMESHAction( SMESHOp::OpExtrusionAlongAPath,    "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
4212   createSMESHAction( SMESHOp::OpRevolution,             "REVOLUTION",      "ICON_REVOLUTION" );
4213   createSMESHAction( SMESHOp::OpPatternMapping,         "MAP",             "ICON_MAP" );
4214   createSMESHAction( SMESHOp::OpConvertMeshToQuadratic, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
4215   createSMESHAction( SMESHOp::OpCreateBoundaryElements, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
4216
4217   createSMESHAction( SMESHOp::OpReset,               "RESET" );
4218   createSMESHAction( SMESHOp::OpScalarBarProperties, "SCALAR_BAR_PROP" );
4219   createSMESHAction( SMESHOp::OpShowScalarBar,       "SHOW_SCALAR_BAR","",0, true  );
4220   createSMESHAction( SMESHOp::OpSaveDistribution,    "SAVE_DISTRIBUTION" );
4221   createSMESHAction( SMESHOp::OpShowDistribution,    "SHOW_DISTRIBUTION","",0, true );
4222 #ifndef DISABLE_PLOT2DVIEWER
4223   createSMESHAction( SMESHOp::OpPlotDistribution, "PLOT_DISTRIBUTION" );
4224 #endif
4225   createSMESHAction( SMESHOp::OpDMWireframe,  "WIRE",    "ICON_WIRE", 0, true );
4226   createSMESHAction( SMESHOp::OpDMShading,    "SHADE",   "ICON_SHADE", 0, true );
4227   createSMESHAction( SMESHOp::OpDMNodes,      "NODES",   "ICON_POINTS", 0, true );
4228   createSMESHAction( SMESHOp::OpDMShrink,     "SHRINK",  "ICON_SHRINK", 0, true );
4229   createSMESHAction( SMESHOp::OpUpdate,       "UPDATE",  "ICON_UPDATE" );
4230   createSMESHAction( SMESHOp::OpDE0DElements, "ELEMS0D", "ICON_DLG_ELEM0D", 0, true );
4231   createSMESHAction( SMESHOp::OpDEEdges,      "EDGES",   "ICON_DLG_EDGE", 0, true );
4232   createSMESHAction( SMESHOp::OpDEFaces,      "FACES",   "ICON_DLG_TRIANGLE", 0, true );
4233   createSMESHAction( SMESHOp::OpDEVolumes,    "VOLUMES", "ICON_DLG_TETRAS", 0, true );
4234   createSMESHAction( SMESHOp::OpDEBalls,      "BALLS",   "ICON_DLG_BALL", 0, true );
4235   createSMESHAction( SMESHOp::OpDEChoose,     "CHOOSE",  "ICON_DLG_CHOOSE", 0, false );
4236   createSMESHAction( SMESHOp::OpDEAllEntity,  "ALL",     "ICON_DLG_CHOOSE_ALL", 0, false );
4237   createSMESHAction( SMESHOp::OpOrientationOnFaces, "FACE_ORIENTATION", "", 0, true );
4238
4239   createSMESHAction( SMESHOp::OpRepresentationLines, "LINE_REPRESENTATION", "", 0, true );
4240   createSMESHAction( SMESHOp::OpRepresentationArcs,  "ARC_REPRESENTATION", "", 0, true );
4241
4242   createSMESHAction( SMESHOp::OpEditHypothesis,    "EDIT_HYPO" );
4243   createSMESHAction( SMESHOp::OpUnassign,          "UNASSIGN" );
4244   createSMESHAction( SMESHOp::OpNumberingNodes,    "NUM_NODES", "", 0, true );
4245   createSMESHAction( SMESHOp::OpNumberingElements, "NUM_ELEMENTS", "", 0, true );
4246   createSMESHAction( SMESHOp::OpProperties,   "COLORS" );
4247   createSMESHAction( SMESHOp::OpTransparency, "TRANSP" );
4248   createSMESHAction( SMESHOp::OpClipping,     "CLIP" );
4249   createSMESHAction( SMESHOp::OpAutoColor,        "AUTO_COLOR" );
4250   createSMESHAction( SMESHOp::OpDisableAutoColor, "DISABLE_AUTO_COLOR" );
4251
4252   // Adaptation - begin
4253 #ifndef DISABLE_MG_ADAPT
4254   createSMESHAction( SMESHOp::OpMGAdapt, "MG_ADAPT", "ICON_MG_ADAPT" );
4255 #endif
4256   // Adaptation - end
4257
4258   createSMESHAction( SMESHOp::OpMinimumDistance,  "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
4259   createSMESHAction( SMESHOp::OpBoundingBox,      "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
4260   createSMESHAction( SMESHOp::OpPropertiesLength, "MEASURE_LENGTH",   "ICON_MEASURE_LENGTH" );
4261   createSMESHAction( SMESHOp::OpPropertiesArea,   "MEASURE_AREA",     "ICON_MEASURE_AREA" );
4262   createSMESHAction( SMESHOp::OpPropertiesVolume, "MEASURE_VOLUME",   "ICON_MEASURE_VOLUME" );
4263   createSMESHAction( SMESHOp::OpAngle,            "MEASURE_ANGLE",    "ICON_MEASURE_ANGLE" );
4264
4265   createSMESHAction( SMESHOp::OpHide,     "HIDE", "ICON_HIDE" );
4266   createSMESHAction( SMESHOp::OpShow,     "SHOW", "ICON_SHOW" );
4267   createSMESHAction( SMESHOp::OpShowOnly, "DISPLAY_ONLY" );
4268
4269   createSMESHAction( SMESHOp::OpSortChild, "SORT_CHILD_ITEMS" );
4270
4271   createSMESHAction( SMESHOp::OpBreakLink, "BREAK_SHAPER_LINK" );
4272
4273   QList<int> aCtrlActions;
4274   aCtrlActions << SMESHOp::OpFreeNode << SMESHOp::OpEqualNode
4275                << SMESHOp::OpNodeConnectivityNb                                         // node controls
4276                << SMESHOp::OpFreeEdge << SMESHOp::OpFreeBorder
4277                << SMESHOp::OpLength << SMESHOp::OpConnection << SMESHOp::OpEqualEdge    // edge controls
4278                << SMESHOp::OpDeflection2D
4279                << SMESHOp::OpFreeFace << SMESHOp::OpLength2D << SMESHOp::OpConnection2D
4280                << SMESHOp::OpArea << SMESHOp::OpTaper << SMESHOp::OpAspectRatio
4281                << SMESHOp::OpMinimumAngle << SMESHOp::OpWarpingAngle << SMESHOp::OpSkew
4282                << SMESHOp::OpMaxElementLength2D << SMESHOp::OpBareBorderFace
4283                << SMESHOp::OpOverConstrainedFace << SMESHOp::OpEqualFace                // face controls
4284                << SMESHOp::OpAspectRatio3D << SMESHOp::OpVolume
4285                << SMESHOp::OpMaxElementLength3D << SMESHOp::OpBareBorderVolume
4286                << SMESHOp::OpOverConstrainedVolume << SMESHOp::OpEqualVolume;           // volume controls
4287   QActionGroup* aCtrlGroup = new QActionGroup( application()->desktop() );
4288   aCtrlGroup->setExclusive( true );
4289   for( int i = 0; i < aCtrlActions.size(); i++ )
4290     aCtrlGroup->addAction( action( aCtrlActions[i] ) );
4291
4292   // ----- create menu --------------
4293   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
4294       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
4295       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
4296       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
4297       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
4298       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
4299 #ifndef DISABLE_MG_ADAPT
4300       adaptId   = createMenu( tr( "MEN_ADAPT" ),   -1, 80, 10 ),
4301 #endif
4302       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
4303       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
4304
4305   createMenu( separator(), fileId );
4306
4307   QMenu* nodeMenu = new QMenu(); QMenu* edgeMenu = new QMenu();
4308   QMenu* faceMenu = new QMenu(); QMenu* volumeMenu = new QMenu();
4309   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
4310       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
4311       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10, -1, nodeMenu ),
4312       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10, -1, edgeMenu ),
4313       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10, -1, faceMenu ),
4314       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10, -1, volumeMenu ),
4315       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
4316       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
4317     //renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
4318       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
4319       basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 );
4320
4321   //createMenu( SMESHOp::OpImportDAT, importId, -1 );
4322   createMenu( SMESHOp::OpImportUNV,  importId, -1 );
4323   createMenu( SMESHOp::OpImportMED,  importId, -1 );
4324   createMenu( SMESHOp::OpImportSTL,  importId, -1 );
4325 #ifdef WITH_CGNS
4326   createMenu( SMESHOp::OpImportCGNS, importId, -1 );
4327 #endif
4328   createMenu( SMESHOp::OpImportGMF,  importId, -1 );
4329   createMenu( SMESHOp::OpExportDAT,  exportId, -1 );
4330   createMenu( SMESHOp::OpExportMED,  exportId, -1 );
4331   createMenu( SMESHOp::OpExportUNV,  exportId, -1 );
4332   createMenu( SMESHOp::OpExportSTL,  exportId, -1 );
4333 #ifdef WITH_CGNS
4334   createMenu( SMESHOp::OpExportCGNS, exportId, -1 );
4335 #endif
4336   createMenu( SMESHOp::OpExportGMF,  exportId, -1 );
4337   createMenu( separator(), fileId, 10 );
4338
4339   createMenu( SMESHOp::OpDelete, editId, -1 );
4340
4341   createMenu( SMESHOp::OpSelectFiltersLibrary, toolsId, -1 );
4342
4343   createMenu( SMESHOp::OpCreateMesh,           meshId, -1 ); // "Mesh" menu
4344   createMenu( SMESHOp::OpCreateSubMesh,        meshId, -1 );
4345   createMenu( SMESHOp::OpEditMeshOrSubMesh,    meshId, -1 );
4346   createMenu( SMESHOp::OpBuildCompoundMesh,    meshId, -1 );
4347   createMenu( SMESHOp::OpCopyMesh,             meshId, -1 );
4348   createMenu( separator(),                     meshId, -1 );
4349   createMenu( SMESHOp::OpCompute,              meshId, -1 );
4350   createMenu( SMESHOp::OpPreCompute,           meshId, -1 );
4351   createMenu( SMESHOp::OpEvaluate,             meshId, -1 );
4352   createMenu( SMESHOp::OpMeshOrder,            meshId, -1 );
4353   createMenu( separator(),                     meshId, -1 );
4354   createMenu( SMESHOp::OpCreateGroup,          meshId, -1 );
4355   createMenu( SMESHOp::OpCreateGeometryGroup,  meshId, -1 );
4356   createMenu( SMESHOp::OpConstructGroup,       meshId, -1 );
4357   createMenu( SMESHOp::OpEditGroup,            meshId, -1 );
4358   createMenu( SMESHOp::OpEditGeomGroupAsGroup, meshId, -1 );
4359   createMenu( separator(),                     meshId, -1 );
4360   createMenu( SMESHOp::OpUnionGroups,          meshId, -1 );
4361   createMenu( SMESHOp::OpIntersectGroups,      meshId, -1 );
4362   createMenu( SMESHOp::OpCutGroups,            meshId, -1 );
4363   createMenu( separator(),                     meshId, -1 );
4364   createMenu( SMESHOp::OpGroupUnderlyingElem,  meshId, -1 );
4365   createMenu( SMESHOp::OpFaceGroupsByEdges,    meshId, -1 );
4366   createMenu( separator(),                     meshId, -1 );
4367   createMenu( SMESHOp::OpMeshInformation,      meshId, -1 );
4368   //createMenu( SMESHOp::OpStdInfo, meshId, -1 );
4369   //createMenu( SMESHOp::OpWhatIs, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4370   createMenu( SMESHOp::OpFindElementByPoint,   meshId, -1 );
4371   createMenu( separator(),                     meshId, -1 );
4372
4373   createMenu( SMESHOp::OpFreeNode,              nodeId,   -1 );
4374   createMenu( SMESHOp::OpEqualNode,             nodeId,   -1 );
4375   //createMenu( SMESHOp::OpNodeConnectivityNb,    nodeId,   -1 );
4376   createMenu( SMESHOp::OpFreeBorder,            edgeId,   -1 );
4377   createMenu( SMESHOp::OpLength,                edgeId,   -1 );
4378   createMenu( SMESHOp::OpConnection,            edgeId,   -1 );
4379   createMenu( SMESHOp::OpEqualEdge,             edgeId,   -1 );
4380   createMenu( SMESHOp::OpFreeEdge,              faceId,   -1 );
4381   createMenu( SMESHOp::OpFreeFace,              faceId,   -1 );
4382   createMenu( SMESHOp::OpBareBorderFace,        faceId,   -1 );
4383   createMenu( SMESHOp::OpOverConstrainedFace,   faceId,   -1 );
4384   createMenu( SMESHOp::OpLength2D,              faceId,   -1 );
4385   createMenu( SMESHOp::OpConnection2D,          faceId,   -1 );
4386   createMenu( SMESHOp::OpArea,                  faceId,   -1 );
4387   createMenu( SMESHOp::OpTaper,                 faceId,   -1 );
4388   createMenu( SMESHOp::OpAspectRatio,           faceId,   -1 );
4389   createMenu( SMESHOp::OpMinimumAngle,          faceId,   -1 );
4390   createMenu( SMESHOp::OpWarpingAngle,          faceId,   -1 );
4391   createMenu( SMESHOp::OpSkew,                  faceId,   -1 );
4392   createMenu( SMESHOp::OpMaxElementLength2D,    faceId,   -1 );
4393   createMenu( SMESHOp::OpEqualFace,             faceId,   -1 );
4394   createMenu( SMESHOp::OpDeflection2D,          faceId,   -1 );
4395   createMenu( SMESHOp::OpAspectRatio3D,         volumeId, -1 );
4396   createMenu( SMESHOp::OpVolume,                volumeId, -1 );
4397   createMenu( SMESHOp::OpMaxElementLength3D,    volumeId, -1 );
4398   createMenu( SMESHOp::OpBareBorderVolume,      volumeId, -1 );
4399   createMenu( SMESHOp::OpOverConstrainedVolume, volumeId, -1 );
4400   createMenu( SMESHOp::OpEqualVolume,           volumeId, -1 );
4401   createMenu( separator(),                      ctrlId,   -1 );
4402   createMenu( SMESHOp::OpReset,                 ctrlId,   -1 );
4403   createMenu( separator(),                      ctrlId,   -1 );
4404   createMenu( SMESHOp::OpOverallMeshQuality,    ctrlId,   -1 );
4405
4406   createMenu( SMESHOp::OpNode,                   addId, -1 );
4407   createMenu( SMESHOp::OpElem0D,                 addId, -1 );
4408   createMenu( SMESHOp::OpElem0DOnElemNodes,      addId, -1 );
4409   createMenu( SMESHOp::OpBall,                   addId, -1 );
4410   createMenu( SMESHOp::OpEdge,                   addId, -1 );
4411   createMenu( SMESHOp::OpTriangle,               addId, -1 );
4412   createMenu( SMESHOp::OpQuadrangle,             addId, -1 );
4413   createMenu( SMESHOp::OpPolygon,                addId, -1 );
4414   createMenu( SMESHOp::OpTetrahedron,            addId, -1 );
4415   createMenu( SMESHOp::OpHexahedron,             addId, -1 );
4416   createMenu( SMESHOp::OpPentahedron,            addId, -1 );
4417   createMenu( SMESHOp::OpPyramid,                addId, -1 );
4418   createMenu( SMESHOp::OpHexagonalPrism,         addId, -1 );
4419   createMenu( SMESHOp::OpPolyhedron,             addId, -1 );
4420   createMenu( separator(),                       addId, -1 );
4421   createMenu( SMESHOp::OpQuadraticEdge,          addId, -1 );
4422   createMenu( SMESHOp::OpQuadraticTriangle,      addId, -1 );
4423   createMenu( SMESHOp::OpBiQuadraticTriangle ,   addId, -1 );
4424   createMenu( SMESHOp::OpQuadraticQuadrangle,    addId, -1 );
4425   createMenu( SMESHOp::OpBiQuadraticQuadrangle,  addId, -1 );
4426   createMenu( SMESHOp::OpQuadraticPolygon,       addId, -1 );
4427   createMenu( SMESHOp::OpQuadraticTetrahedron,   addId, -1 );
4428   createMenu( SMESHOp::OpQuadraticPyramid,       addId, -1 );
4429   createMenu( SMESHOp::OpQuadraticPentahedron,   addId, -1 );
4430   createMenu( SMESHOp::OpBiQuadraticPentahedron, addId, -1 );
4431   createMenu( SMESHOp::OpQuadraticHexahedron,    addId, -1 );
4432   createMenu( SMESHOp::OpTriQuadraticHexahedron, addId, -1 );
4433
4434   createMenu( SMESHOp::OpRemoveNodes,       removeId, -1 );
4435   createMenu( SMESHOp::OpRemoveElements,    removeId, -1 );
4436   createMenu( SMESHOp::OpRemoveOrphanNodes, removeId, -1 );
4437   createMenu( separator(),                  removeId, -1 );
4438   createMenu( SMESHOp::OpDeleteGroup,       removeId, -1 );
4439   createMenu( separator(),                  removeId, -1 );
4440   createMenu( SMESHOp::OpClearMesh,         removeId, -1 );
4441
4442   //createMenu( SMESHOp::OpRenumberingNodes,    renumId, -1 );
4443   //createMenu( SMESHOp::OpRenumberingElements, renumId, -1 );
4444
4445   createMenu( SMESHOp::OpMergeNodes,     transfId, -1 );
4446   createMenu( SMESHOp::OpMergeElements,  transfId, -1 );
4447   createMenu( SMESHOp::OpTranslation,    transfId, -1 );
4448   createMenu( SMESHOp::OpRotation,       transfId, -1 );
4449   createMenu( SMESHOp::OpSymmetry,       transfId, -1 );
4450   createMenu( SMESHOp::OpScale,          transfId, -1 );
4451   createMenu( SMESHOp::OpOffset,         transfId, -1 );
4452   createMenu( SMESHOp::OpSewing,         transfId, -1 );
4453   createMenu( SMESHOp::OpDuplicateNodes, transfId, -1 );
4454
4455   createMenu( SMESHOp::OpConvertMeshToQuadratic, modifyId, -1 );
4456   createMenu( SMESHOp::OpCreateBoundaryElements, modifyId, -1 );
4457   createMenu( SMESHOp::OpExtrusion,              modifyId, -1 );
4458   createMenu( SMESHOp::OpExtrusionAlongAPath,    modifyId, -1 );
4459   createMenu( SMESHOp::OpRevolution,             modifyId, -1 );
4460   createMenu( SMESHOp::OpOrientation,            modifyId, -1 );
4461   createMenu( SMESHOp::OpReorientFaces,          modifyId, -1 );
4462   createMenu( SMESHOp::OpMoveNode,               modifyId, -1 );
4463   createMenu( SMESHOp::OpDiagonalInversion,      modifyId, -1 );
4464   createMenu( SMESHOp::OpUnionOfTwoTriangle,     modifyId, -1 );
4465   createMenu( SMESHOp::OpUnionOfTriangles,       modifyId, -1 );
4466   createMenu( SMESHOp::OpCuttingOfQuadrangles,   modifyId, -1 );
4467   createMenu( SMESHOp::OpSplitVolumes,           modifyId, -1 );
4468   createMenu( SMESHOp::OpSplitBiQuadratic,       modifyId, -1 );
4469   createMenu( SMESHOp::OpSmoothing,              modifyId, -1 );
4470   createMenu( SMESHOp::OpPatternMapping,         modifyId, -1 );
4471
4472   // Adaptation - begin
4473 #ifndef DISABLE_MG_ADAPT
4474   createMenu( SMESHOp::OpMGAdapt, adaptId, -1 );
4475 #endif
4476   // Adaptation - end
4477
4478   createMenu( SMESHOp::OpMinimumDistance,  measureId,   -1 );
4479   createMenu( SMESHOp::OpBoundingBox,      measureId,   -1 );
4480   createMenu( SMESHOp::OpAngle,            measureId,   -1 );
4481   createMenu( SMESHOp::OpPropertiesLength, basicPropId, -1 );
4482   createMenu( SMESHOp::OpPropertiesArea,   basicPropId, -1 );
4483   createMenu( SMESHOp::OpPropertiesVolume, basicPropId, -1 );
4484   createMenu( SMESHOp::OpUpdate,           viewId,      -1 );
4485
4486   connect( nodeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4487   connect( edgeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4488   connect( faceMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4489   connect( volumeMenu, SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4490
4491   // ----- create toolbars --------------
4492   int meshTb = createTool( tr( "TB_MESH" ), QString( "SMESHMeshToolbar" ) ) ;
4493   createTool( SMESHOp::OpCreateMesh,        meshTb );
4494   createTool( SMESHOp::OpCreateSubMesh,     meshTb );
4495   createTool( SMESHOp::OpEditMeshOrSubMesh, meshTb );
4496   createTool( SMESHOp::OpBuildCompoundMesh, meshTb );
4497   createTool( SMESHOp::OpCopyMesh,          meshTb );
4498   createTool( separator(),                  meshTb );
4499   createTool( SMESHOp::OpCompute,           meshTb );
4500   createTool( SMESHOp::OpPreCompute,        meshTb );
4501   createTool( SMESHOp::OpEvaluate,          meshTb );
4502   createTool( SMESHOp::OpMeshOrder,         meshTb );
4503
4504   int infoTb = createTool( tr( "TB_INFO" ), QString( "SMESHInformationToolbar" ) ) ;
4505   createTool( SMESHOp::OpMeshInformation,    infoTb );
4506   //createTool( SMESHOp::OpStdInfo, meshTb );
4507   //createTool( SMESHOp::OpWhatIs, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4508   createTool( SMESHOp::OpFindElementByPoint, infoTb );
4509
4510   int groupTb = createTool( tr( "TB_GROUP" ), QString( "SMESHGroupToolbar" ) ) ;
4511   createTool( SMESHOp::OpCreateGroup,         groupTb );
4512   createTool( SMESHOp::OpCreateGeometryGroup, groupTb );
4513   createTool( SMESHOp::OpConstructGroup,      groupTb );
4514   createTool( SMESHOp::OpEditGroup,           groupTb );
4515
4516   int ctrl0dTb = createTool( tr( "TB_CTRL0D" ), QString( "SMESHNodeControlsToolbar" ) ) ;
4517   createTool( SMESHOp::OpFreeNode,  ctrl0dTb );
4518   createTool( SMESHOp::OpEqualNode, ctrl0dTb );
4519   //createTool( SMESHOp::OpNodeConnectivityNb, ctrl0dTb );
4520
4521   int ctrl1dTb = createTool( tr( "TB_CTRL1D" ), QString( "SMESHEdgeControlsToolbar" ) ) ;
4522   createTool( SMESHOp::OpFreeBorder, ctrl1dTb );
4523   createTool( SMESHOp::OpLength,     ctrl1dTb );
4524   createTool( SMESHOp::OpConnection, ctrl1dTb );
4525   createTool( SMESHOp::OpEqualEdge,  ctrl1dTb );
4526
4527   int ctrl2dTb = createTool( tr( "TB_CTRL2D" ), QString( "SMESHFaceControlsToolbar" ) ) ;
4528   createTool( SMESHOp::OpFreeEdge,            ctrl2dTb );
4529   createTool( SMESHOp::OpFreeFace,            ctrl2dTb );
4530   createTool( SMESHOp::OpBareBorderFace,      ctrl2dTb );
4531   createTool( SMESHOp::OpOverConstrainedFace, ctrl2dTb );
4532   createTool( SMESHOp::OpLength2D,            ctrl2dTb );
4533   createTool( SMESHOp::OpConnection2D,        ctrl2dTb );
4534   createTool( SMESHOp::OpArea,                ctrl2dTb );
4535   createTool( SMESHOp::OpTaper,               ctrl2dTb );
4536   createTool( SMESHOp::OpAspectRatio,         ctrl2dTb );
4537   createTool( SMESHOp::OpMinimumAngle,        ctrl2dTb );
4538   createTool( SMESHOp::OpWarpingAngle,        ctrl2dTb );
4539   createTool( SMESHOp::OpSkew,                ctrl2dTb );
4540   createTool( SMESHOp::OpMaxElementLength2D,  ctrl2dTb );
4541   createTool( SMESHOp::OpEqualFace,           ctrl2dTb );
4542   createTool( SMESHOp::OpDeflection2D,        ctrl2dTb );
4543
4544   int ctrl3dTb = createTool( tr( "TB_CTRL3D" ), QString( "SMESHVolumeControlsToolbar" ) ) ;
4545   createTool( SMESHOp::OpAspectRatio3D,         ctrl3dTb );
4546   createTool( SMESHOp::OpVolume,                ctrl3dTb );
4547   createTool( SMESHOp::OpMaxElementLength3D,    ctrl3dTb );
4548   createTool( SMESHOp::OpBareBorderVolume,      ctrl3dTb );
4549   createTool( SMESHOp::OpOverConstrainedVolume, ctrl3dTb );
4550   createTool( SMESHOp::OpEqualVolume,           ctrl3dTb );
4551
4552   int addElemTb = createTool( tr( "TB_ADD" ), QString( "SMESHAddElementToolbar" ) ) ;
4553   createTool( SMESHOp::OpNode,              addElemTb );
4554   createTool( SMESHOp::OpElem0D,            addElemTb );
4555   createTool( SMESHOp::OpElem0DOnElemNodes, addElemTb );
4556   createTool( SMESHOp::OpBall,              addElemTb );
4557   createTool( SMESHOp::OpEdge,              addElemTb );
4558   createTool( SMESHOp::OpTriangle,          addElemTb );
4559   createTool( SMESHOp::OpQuadrangle,        addElemTb );
4560   createTool( SMESHOp::OpPolygon,           addElemTb );
4561   createTool( SMESHOp::OpTetrahedron,       addElemTb );
4562   createTool( SMESHOp::OpHexahedron,        addElemTb );
4563   createTool( SMESHOp::OpPentahedron,       addElemTb );
4564   createTool( SMESHOp::OpPyramid,           addElemTb );
4565   createTool( SMESHOp::OpHexagonalPrism,    addElemTb );
4566   createTool( SMESHOp::OpPolyhedron,        addElemTb );
4567
4568   int addNonElemTb = createTool( tr( "TB_ADDNON" ), QString( "SMESHAddElementToolbar" ) ) ;
4569   createTool( SMESHOp::OpQuadraticEdge,          addNonElemTb );
4570   createTool( SMESHOp::OpQuadraticTriangle,      addNonElemTb );
4571   createTool( SMESHOp::OpBiQuadraticTriangle,    addNonElemTb );
4572   createTool( SMESHOp::OpQuadraticQuadrangle,    addNonElemTb );
4573   createTool( SMESHOp::OpBiQuadraticQuadrangle,  addNonElemTb );
4574   createTool( SMESHOp::OpQuadraticPolygon,       addNonElemTb );
4575   createTool( SMESHOp::OpQuadraticTetrahedron,   addNonElemTb );
4576   createTool( SMESHOp::OpQuadraticPyramid,       addNonElemTb );
4577   createTool( SMESHOp::OpQuadraticPentahedron,   addNonElemTb );
4578   createTool( SMESHOp::OpBiQuadraticPentahedron, addNonElemTb );
4579   createTool( SMESHOp::OpQuadraticHexahedron,    addNonElemTb );
4580   createTool( SMESHOp::OpTriQuadraticHexahedron, addNonElemTb );
4581
4582   int remTb = createTool( tr( "TB_REM" ), QString( "SMESHRemoveToolbar" ) ) ;
4583   createTool( SMESHOp::OpRemoveNodes,       remTb );
4584   createTool( SMESHOp::OpRemoveElements,    remTb );
4585   createTool( SMESHOp::OpRemoveOrphanNodes, remTb );
4586   createTool( SMESHOp::OpClearMesh,         remTb );
4587
4588 //   int renumbTb     = createTool( tr( "TB_RENUMBER" ),  QString( "SMESHRenumberingToolbar" ) ) ;
4589   //createTool( SMESHOp::OpRenumberingNodes,    renumbTb );
4590   //createTool( SMESHOp::OpRenumberingElements, renumbTb );
4591
4592   int transformTb = createTool( tr( "TB_TRANSFORM" ), QString( "SMESHTransformationToolbar" ) ) ;
4593   createTool( SMESHOp::OpMergeNodes,     transformTb );
4594   createTool( SMESHOp::OpMergeElements,  transformTb );
4595   createTool( SMESHOp::OpTranslation,    transformTb );
4596   createTool( SMESHOp::OpRotation,       transformTb );
4597   createTool( SMESHOp::OpSymmetry,       transformTb );
4598   createTool( SMESHOp::OpScale,          transformTb );
4599   createTool( SMESHOp::OpOffset,         transformTb );
4600   createTool( SMESHOp::OpSewing,         transformTb );
4601   createTool( SMESHOp::OpDuplicateNodes, transformTb );
4602
4603   int modifyTb = createTool( tr( "TB_MODIFY" ), QString( "SMESHModificationToolbar" ) ) ;
4604   createTool( SMESHOp::OpConvertMeshToQuadratic, modifyTb );
4605   createTool( SMESHOp::OpCreateBoundaryElements, modifyTb );
4606   createTool( SMESHOp::OpExtrusion,              modifyTb );
4607   createTool( SMESHOp::OpExtrusionAlongAPath,    modifyTb );
4608   createTool( SMESHOp::OpRevolution,             modifyTb );
4609   createTool( SMESHOp::OpOrientation,            modifyTb );
4610   createTool( SMESHOp::OpReorientFaces,          modifyTb );
4611   createTool( SMESHOp::OpMoveNode,               modifyTb );
4612   createTool( SMESHOp::OpDiagonalInversion,      modifyTb );
4613   createTool( SMESHOp::OpUnionOfTwoTriangle,     modifyTb );
4614   createTool( SMESHOp::OpUnionOfTriangles,       modifyTb );
4615   createTool( SMESHOp::OpCuttingOfQuadrangles,   modifyTb );
4616   createTool( SMESHOp::OpSplitVolumes,           modifyTb );
4617   createTool( SMESHOp::OpSplitBiQuadratic,       modifyTb );
4618   createTool( SMESHOp::OpSmoothing,              modifyTb );
4619   createTool( SMESHOp::OpPatternMapping,         modifyTb );
4620
4621   // Adaptation - begin
4622 #ifndef DISABLE_MG_ADAPT
4623   int adaptTb = createTool( tr( "TB_ADAPTATION" ), QString( "SMESHAdaptationToolbar" ) ) ;
4624   createTool( SMESHOp::OpMGAdapt, adaptTb );
4625 #endif
4626   // Adaptation - end
4627
4628   int measuremTb = createTool( tr( "TB_MEASUREM" ), QString( "SMESHMeasurementsToolbar" ) ) ;
4629   createTool( SMESHOp::OpMinimumDistance, measuremTb );
4630
4631   int dispModeTb = createTool( tr( "TB_DISP_MODE" ), QString( "SMESHDisplayModeToolbar" ) );
4632   createTool( SMESHOp::OpUpdate, dispModeTb );
4633
4634   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4635   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4636
4637   myRules.clear();
4638   QString
4639     OB      = "'ObjectBrowser'",
4640     View    = "'" + SVTK_Viewer::Type() + "'",
4641     pat     = "'%1'",
4642     mesh    = pat.arg( SMESHGUI_Selection::typeName( SMESH::MESH ) ),
4643     group   = pat.arg( SMESHGUI_Selection::typeName( SMESH::GROUP ) ),
4644     hypo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::HYPOTHESIS ) ),
4645     algo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::ALGORITHM ) ),
4646     smesh   = pat.arg( SMESHGUI_Selection::typeName( SMESH::COMPONENT ) ),
4647     elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
4648     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_VERTEX ) ).
4649     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_EDGE ) ).
4650     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_FACE ) ).
4651     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_SOLID ) ).
4652     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_COMPOUND ) ).
4653     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH ) ),
4654     subMesh      = elems,
4655     mesh_part    = mesh + " " + subMesh + " " + group,
4656     mesh_group   = mesh + " " + group,
4657     mesh_submesh = mesh + " " + subMesh,
4658     hyp_alg      = hypo + " " + algo;
4659
4660   // popup for object browser
4661   QString
4662     isInvisible("not( isVisible )"),
4663     isEmpty("numberOfNodes = 0"),
4664     isNotEmpty("numberOfNodes <> 0"),
4665
4666     // has nodes, edges, etc in VISIBLE! actor
4667     hasNodes("(numberOfNodes > 0 ) && hasActor"),
4668     hasElems("(count( elemTypes ) > 0)"),
4669     hasDifferentElems("(count( elemTypes ) > 1)"),
4670     hasDifferentObjElems("(count( objElemTypes ) > 1)"),
4671     hasBalls("({'BallElem'} in elemTypes)"),
4672     hasElems0d("({'Elem0d'} in elemTypes)"),
4673     hasEdges("({'Edge'} in elemTypes)"),
4674     hasFaces("({'Face'} in elemTypes)"),
4675     hasVolumes("({'Volume'} in elemTypes)"),
4676     hasFacesOrVolumes("(({'Face'} in elemTypes) || ({'Volume'} in elemTypes)) ");
4677
4678   createPopupItem( SMESHOp::OpEditMesh,          OB, mesh, "&& selcount=1" );
4679   createPopupItem( SMESHOp::OpCreateSubMesh,     OB, mesh, "&& hasGeomReference");
4680   createPopupItem( SMESHOp::OpMeshOrder,         OB, mesh, "&& selcount=1 && hasAlgo && hasGeomReference" );
4681   createPopupItem( SMESHOp::OpEditSubMesh,       OB, subMesh, "&& selcount=1 && hasGeomReference" );
4682   createPopupItem( SMESHOp::OpEditGroup,         OB, group );
4683   createPopupItem( SMESHOp::OpEditGeomGroupAsGroup, OB, group, "&& groupType != 'Group'" );
4684
4685   popupMgr()->insert( separator(), -1, 0 );
4686   createPopupItem( SMESHOp::OpCompute,           OB, mesh, "&& selcount=1 && hasAlgo && isComputable" );
4687   createPopupItem( SMESHOp::OpRecompute,         OB, mesh, "&& selcount=1 && hasAlgo && (" + isNotEmpty + " || hasErrors )");
4688   createPopupItem( SMESHOp::OpShowErrors,        OB, mesh, "&& selcount=1 && hasErrors" );
4689   createPopupItem( SMESHOp::OpComputeSubMesh,    OB, subMesh, "&& selcount=1 && hasAlgo && isComputable" );
4690   createPopupItem( SMESHOp::OpPreCompute,        OB, mesh, "&& selcount=1 && hasAlgo && isPreComputable" );
4691   createPopupItem( SMESHOp::OpEvaluate,          OB, mesh, "&& selcount=1 && hasAlgo && isComputable" );
4692   popupMgr()->insert( separator(), -1, 0 );
4693   createPopupItem( SMESHOp::OpFileInformation,   OB, mesh, "&& selcount=1 && isImported" );
4694   createPopupItem( SMESHOp::OpMeshInformation,   OB, mesh_part );
4695   createPopupItem( SMESHOp::OpFindElementByPoint,OB, mesh_group, "&& selcount=1 && " + hasElems );
4696   createPopupItem( SMESHOp::OpOverallMeshQuality,OB, mesh_part );
4697   popupMgr()->insert( separator(), -1, 0 );
4698   createPopupItem( SMESHOp::OpCreateGroup,       OB, mesh, "&& selcount=1" );
4699   createPopupItem( SMESHOp::OpCreateGeometryGroup, OB, mesh, "&& selcount=1 && hasGeomReference" );
4700   createPopupItem( SMESHOp::OpConstructGroup,    OB, subMesh );
4701   popupMgr()->insert( separator(), -1, 0 );
4702   createPopupItem( SMESHOp::OpEditHypothesis,    OB, hypo, "&& isEditableHyp");
4703   createPopupItem( SMESHOp::OpUnassign,          OB, hyp_alg );
4704   popupMgr()->insert( separator(), -1, 0 );
4705   createPopupItem( SMESHOp::OpConvertMeshToQuadratic, OB, mesh_submesh, "&& " + hasElems );
4706   createPopupItem( SMESHOp::OpCreateBoundaryElements, OB, mesh_group, "&& selcount=1 && dim>=2");
4707
4708   // Adaptation - begin
4709 #ifndef DISABLE_MG_ADAPT
4710   popupMgr()->insert( separator(), -1, 0 );
4711   createPopupItem( SMESHOp::OpMGAdapt, OB, mesh );
4712   popupMgr()->insert( separator(), -1, 0 );
4713 #endif
4714   // Adaptation - end
4715
4716   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
4717   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
4718   QString only_one_2D        = only_one_non_empty + " && dim>1";
4719
4720   int anId = popupMgr()->insert( tr( "MEN_EXPORT" ), -1, -1 );        // EXPORT submenu
4721   popupMgr()->findMenu( anId )->menuAction()->setIcon( resourceMgr()->loadPixmap( "SMESH", tr( "ICON_EXPORT" )));
4722   createPopupItem( SMESHOp::OpPopupExportMED,  OB, mesh_group, multiple_non_empty, anId );
4723   createPopupItem( SMESHOp::OpPopupExportUNV,  OB, mesh_group, only_one_non_empty, anId );
4724   createPopupItem( SMESHOp::OpPopupExportSTL,  OB, mesh_group, only_one_2D, anId );
4725 #ifdef WITH_CGNS
4726   createPopupItem( SMESHOp::OpPopupExportCGNS, OB, mesh_group, multiple_non_empty, anId );
4727 #endif
4728   createPopupItem( SMESHOp::OpPopupExportGMF,  OB, mesh_group, only_one_non_empty, anId );
4729   createPopupItem( SMESHOp::OpPopupExportDAT,  OB, mesh_group, only_one_non_empty, anId );
4730
4731   anId = popupMgr()->insert( tr( "MEN_IMPORT" ), -1, -1 );        // IMPORT submenu
4732   createPopupItem( SMESHOp::OpPopupImportMED,  OB, smesh, "", anId );
4733   createPopupItem( SMESHOp::OpPopupImportUNV,  OB, smesh, "", anId );
4734   createPopupItem( SMESHOp::OpPopupImportSTL,  OB, smesh, "", anId );
4735 #ifdef WITH_CGNS
4736   createPopupItem( SMESHOp::OpPopupImportCGNS, OB, smesh, "", anId );
4737 #endif
4738   createPopupItem( SMESHOp::OpPopupImportGMF,  OB, smesh, "", anId );
4739   createPopupItem( SMESHOp::OpPopupImportDAT,  OB, smesh, "", anId );
4740   popupMgr()->insert( separator(), -1, 0 );
4741
4742   createPopupItem( SMESHOp::OpClearMesh,         OB, mesh );
4743   createPopupItem( SMESHOp::OpDelete,            OB, mesh_part + " " + hyp_alg );
4744   createPopupItem( SMESHOp::OpDeleteGroup,       OB, group );
4745
4746   // popup for viewer
4747   createPopupItem( SMESHOp::OpEditGroup,            View, group );
4748   createPopupItem( SMESHOp::OpAddElemGroupPopup,    View, elems, "&& guiState = 800" );
4749   createPopupItem( SMESHOp::OpRemoveElemGroupPopup, View, elems, "&& guiState = 800" );
4750
4751   popupMgr()->insert( separator(), -1, 0 );
4752   createPopupItem( SMESHOp::OpMeshInformation,    View, mesh_part );
4753   createPopupItem( SMESHOp::OpOverallMeshQuality, View, mesh_part );
4754   createPopupItem( SMESHOp::OpFindElementByPoint, View, mesh, "&& " + hasElems);
4755   popupMgr()->insert( separator(), -1, 0 );
4756
4757   createPopupItem( SMESHOp::OpUpdate,           OB + " " + View, mesh_part );
4758   createPopupItem( SMESHOp::OpAutoColor,        OB + " " + View, mesh, "&& (not isAutoColor)" );
4759   createPopupItem( SMESHOp::OpDisableAutoColor, OB + " " + View, mesh, "&& isAutoColor" );
4760   popupMgr()->insert( separator(), -1, 0 );
4761
4762   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
4763   QString aType = QString( "%1type in {%2}" ).arg( lc );
4764   aType = aType.arg( mesh_part );
4765   QString aMeshInVTK = aClient + "&&" + aType;
4766
4767   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
4768   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
4769   QString aSelCount = QString( "%1 > 0" ).arg( dc );
4770
4771   //-------------------------------------------------
4772   // Numbering
4773   //-------------------------------------------------
4774   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
4775
4776   popupMgr()->insert( action( SMESHOp::OpNumberingNodes ), anId, -1 );
4777   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4778   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4779
4780   popupMgr()->insert( action( SMESHOp::OpNumberingElements ), anId, -1 );
4781   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4782   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4783
4784   popupMgr()->insert( separator(), -1, -1 );
4785
4786   //-------------------------------------------------
4787   // Display Mode
4788   //-------------------------------------------------
4789   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4790
4791   popupMgr()->insert( action( SMESHOp::OpDMWireframe ), anId, -1 );
4792   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4793   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4794
4795   popupMgr()->insert( action( SMESHOp::OpDMShading ), anId, -1 );
4796   popupMgr()->setRule( action( SMESHOp::OpDMShading ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4797   popupMgr()->setRule( action( SMESHOp::OpDMShading ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4798
4799   popupMgr()->insert( action( SMESHOp::OpDMNodes ), anId, -1 );
4800   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), aMeshInVTK + "&&" + hasNodes + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4801   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4802
4803   popupMgr()->insert( separator(), anId, -1 );
4804
4805   popupMgr()->insert( action( SMESHOp::OpDMShrink ), anId, -1 );
4806   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4807   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4808
4809   //-------------------------------------------------
4810   // Display Entity
4811   //-------------------------------------------------
4812   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4813
4814   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4815
4816   popupMgr()->insert( action( SMESHOp::OpDE0DElements ), anId, -1 );
4817   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4818   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4819
4820   popupMgr()->insert( action( SMESHOp::OpDEEdges ), anId, -1 );
4821   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4822   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4823
4824   popupMgr()->insert( action( SMESHOp::OpDEFaces ), anId, -1 );
4825   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4826   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4827
4828   popupMgr()->insert( action( SMESHOp::OpDEVolumes ), anId, -1 );
4829   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4830   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4831
4832   popupMgr()->insert( action( SMESHOp::OpDEBalls ), anId, -1 );
4833   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), aDiffElemsInVTK + "&& isVisible &&" + hasBalls, QtxPopupMgr::VisibleRule );
4834   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), "{'BallElem'} in entityMode", QtxPopupMgr::ToggleRule );
4835
4836   popupMgr()->insert( separator(), anId, -1 );
4837
4838   popupMgr()->insert( action( SMESHOp::OpDEChoose ), anId, -1 );
4839   popupMgr()->setRule( action( SMESHOp::OpDEChoose ), aClient + "&& $type in {" + mesh + "} &&" + hasDifferentObjElems, QtxPopupMgr::VisibleRule );
4840
4841   popupMgr()->insert( separator(), anId, -1 );
4842
4843   popupMgr()->insert( action( SMESHOp::OpDEAllEntity ), anId, -1 );
4844   popupMgr()->setRule( action( SMESHOp::OpDEAllEntity ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4845
4846
4847   //-------------------------------------------------
4848   // Representation of the 2D Quadratic elements
4849   //-------------------------------------------------
4850   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4851   popupMgr()->insert( action( SMESHOp::OpRepresentationLines ), anId, -1 );
4852   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), aMeshInVTK + "&& isVisible && isQuadratic",QtxPopupMgr::VisibleRule );
4853   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4854
4855   popupMgr()->insert( action( SMESHOp::OpRepresentationArcs ), anId, -1 );
4856   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), aMeshInVTK + "&& isVisible && isQuadratic", QtxPopupMgr::VisibleRule );
4857   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4858
4859   //-------------------------------------------------
4860   // Orientation of faces
4861   //-------------------------------------------------
4862   popupMgr()->insert( action( SMESHOp::OpOrientationOnFaces ), -1, -1 );
4863   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4864   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4865
4866   //-------------------------------------------------
4867   // Color / Size
4868   //-------------------------------------------------
4869   popupMgr()->insert( action( SMESHOp::OpProperties ), -1, -1 );
4870   popupMgr()->setRule( action( SMESHOp::OpProperties ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4871
4872   //-------------------------------------------------
4873   // Transparency
4874   //-------------------------------------------------
4875   popupMgr()->insert( action( SMESHOp::OpTransparency ), -1, -1 );
4876   popupMgr()->setRule( action( SMESHOp::OpTransparency ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4877
4878   //-------------------------------------------------
4879   // Controls
4880   //-------------------------------------------------
4881   QString
4882     aMeshInVtkHasNodes   = aMeshInVTK + "&&" + hasNodes,
4883     aMeshInVtkHasEdges   = aMeshInVTK + "&&" + hasEdges,
4884     aMeshInVtkHasFaces   = aMeshInVTK + "&&" + hasFaces,
4885     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4886
4887   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4888
4889   popupMgr()->insert( action( SMESHOp::OpReset ), anId, -1 ); // RESET
4890   popupMgr()->setRule( action( SMESHOp::OpReset ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4891
4892   popupMgr()->insert( separator(), anId, -1 );
4893
4894   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4895
4896   popupMgr()->insert( action( SMESHOp::OpFreeNode ), aSubId, -1 );
4897   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4898   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4899
4900   popupMgr()->insert ( action( SMESHOp::OpEqualNode ), aSubId, -1 );
4901   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4902   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4903
4904   // popupMgr()->insert( action( SMESHOp::OpNodeConnectivityNb ), aSubId, -1 );
4905   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4906   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), "controlMode = 'eNodeConnectivityNb'", QtxPopupMgr::ToggleRule );
4907
4908   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4909
4910   popupMgr()->insert( action( SMESHOp::OpFreeBorder ), aSubId, -1 );
4911   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), aMeshInVTK + "&&" + hasEdges + "&&" + hasFacesOrVolumes, QtxPopupMgr::VisibleRule );
4912   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4913
4914   popupMgr()->insert( action( SMESHOp::OpLength ), aSubId, -1 );
4915   popupMgr()->setRule( action( SMESHOp::OpLength ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4916   popupMgr()->setRule( action( SMESHOp::OpLength ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4917
4918   popupMgr()->insert( action( SMESHOp::OpConnection ), aSubId, -1 );
4919   popupMgr()->setRule( action( SMESHOp::OpConnection ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4920   popupMgr()->setRule( action( SMESHOp::OpConnection ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4921   popupMgr()->insert ( action( SMESHOp::OpEqualEdge ), aSubId, -1 ); // EQUAL_EDGE
4922   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4923   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4924
4925   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4926
4927   popupMgr()->insert( action( SMESHOp::OpFreeEdge ), aSubId, -1 );
4928   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4929   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4930
4931   popupMgr()->insert ( action( SMESHOp::OpFreeFace ), aSubId, -1 );
4932   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4933                                        QtxPopupMgr::VisibleRule );
4934   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4935
4936   popupMgr()->insert ( action( SMESHOp::OpLength2D ), aSubId, -1 );
4937   popupMgr()->setRule( action( SMESHOp::OpLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4938   popupMgr()->setRule( action( SMESHOp::OpLength2D ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4939
4940   popupMgr()->insert ( action( SMESHOp::OpConnection2D ), aSubId, -1 );
4941   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4942   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4943
4944   popupMgr()->insert ( action( SMESHOp::OpArea ), aSubId, -1 );
4945   popupMgr()->setRule( action( SMESHOp::OpArea ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4946   popupMgr()->setRule( action( SMESHOp::OpArea ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4947
4948   popupMgr()->insert ( action( SMESHOp::OpTaper ), aSubId, -1 );
4949   popupMgr()->setRule( action( SMESHOp::OpTaper ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4950   popupMgr()->setRule( action( SMESHOp::OpTaper ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4951
4952   popupMgr()->insert ( action( SMESHOp::OpAspectRatio ), aSubId, -1 );
4953   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4954   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4955
4956   popupMgr()->insert ( action( SMESHOp::OpMinimumAngle ), aSubId, -1 );
4957   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4958   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4959
4960   popupMgr()->insert ( action( SMESHOp::OpWarpingAngle ), aSubId, -1 );
4961   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4962   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4963
4964   popupMgr()->insert ( action( SMESHOp::OpSkew ), aSubId, -1 );
4965   popupMgr()->setRule( action( SMESHOp::OpSkew ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4966   popupMgr()->setRule( action( SMESHOp::OpSkew ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4967
4968   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength2D ), aSubId, -1 );
4969   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4970   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4971
4972   popupMgr()->insert ( action( SMESHOp::OpBareBorderFace ), aSubId, -1 );
4973   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4974   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4975
4976   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedFace ), aSubId, -1 );
4977   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4978   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4979
4980   popupMgr()->insert ( action( SMESHOp::OpEqualFace ), aSubId, -1 );
4981   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4982   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4983
4984   popupMgr()->insert ( action( SMESHOp::OpDeflection2D ), aSubId, -1 );
4985   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), aMeshInVtkHasFaces + " && hasGeomReference", QtxPopupMgr::VisibleRule );
4986   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), "controlMode = 'eDeflection2D'", QtxPopupMgr::ToggleRule );
4987
4988   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4989
4990   popupMgr()->insert ( action( SMESHOp::OpAspectRatio3D  ), aSubId, -1 );
4991   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4992   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4993
4994   popupMgr()->insert ( action( SMESHOp::OpVolume ), aSubId, -1 );
4995   popupMgr()->setRule( action( SMESHOp::OpVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4996   popupMgr()->setRule( action( SMESHOp::OpVolume ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4997
4998   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength3D ), aSubId, -1 );
4999   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5000   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
5001
5002   popupMgr()->insert ( action( SMESHOp::OpBareBorderVolume ), aSubId, -1 );
5003   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5004   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
5005
5006   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedVolume ), aSubId, -1 );
5007   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5008   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
5009
5010   popupMgr()->insert ( action( SMESHOp::OpEqualVolume  ), aSubId, -1 );
5011   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
5012   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
5013
5014   popupMgr()->insert( separator(), anId, -1 );
5015
5016   popupMgr()->insert( action( SMESHOp::OpShowScalarBar ), anId, -1 );
5017   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
5018   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone' && isScalarBarVisible", QtxPopupMgr::ToggleRule );
5019   popupMgr()->insert( action( SMESHOp::OpScalarBarProperties ), anId, -1 );
5020   popupMgr()->setRule( action( SMESHOp::OpScalarBarProperties ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
5021
5022   popupMgr()->insert( separator(), anId, -1 );
5023
5024   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
5025
5026   popupMgr()->insert( action( SMESHOp::OpSaveDistribution ), aSubId, -1 );
5027   popupMgr()->setRule( action( SMESHOp::OpSaveDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5028
5029   popupMgr()->insert( action( SMESHOp::OpShowDistribution ), aSubId, -1 );
5030   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5031   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor && isScalarBarVisible && isDistributionVisible", QtxPopupMgr::ToggleRule);
5032
5033 #ifndef DISABLE_PLOT2DVIEWER
5034   popupMgr()->insert( action( SMESHOp::OpPlotDistribution ), aSubId, -1 );
5035   popupMgr()->setRule( action( SMESHOp::OpPlotDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
5036 #endif
5037
5038   //-------------------------------------------------
5039   // Show / Hide
5040   //-------------------------------------------------
5041   popupMgr()->insert( separator(), -1, -1 );
5042   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
5043     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
5044   popupMgr()->insert( action( SMESHOp::OpShow ), -1, -1 );
5045   popupMgr()->setRule( action( SMESHOp::OpShow ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
5046
5047   popupMgr()->insert( action( SMESHOp::OpHide ), -1, -1 );
5048   popupMgr()->setRule( action( SMESHOp::OpHide ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
5049
5050   popupMgr()->insert( action( SMESHOp::OpShowOnly ), -1, -1 );
5051   popupMgr()->setRule( action( SMESHOp::OpShowOnly ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
5052
5053   popupMgr()->insert( separator(), -1, -1 );
5054
5055   //-------------------------------------------------
5056   // Clipping
5057   //-------------------------------------------------
5058   popupMgr()->insert( action( SMESHOp::OpClipping ), -1, -1 );
5059   popupMgr()->setRule( action( SMESHOp::OpClipping ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
5060
5061   popupMgr()->insert( separator(), -1, -1 );
5062
5063   popupMgr()->insert( action( SMESHOp::OpSortChild ), -1, -1 );
5064   popupMgr()->setRule( action( SMESHOp::OpSortChild ), "$component={'SMESH'} and client='ObjectBrowser' and isContainer and nbChildren>1", QtxPopupMgr::VisibleRule );
5065   popupMgr()->insert( separator(), -1, -1 );
5066
5067   popupMgr()->insert( action( SMESHOp::OpBreakLink), -1, -1 );
5068   popupMgr()->setRule( action( SMESHOp::OpBreakLink), "$component={'SHAPERSTUDY'} and client='ObjectBrowser' and canBreakLink", QtxPopupMgr::VisibleRule );
5069
5070   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
5071            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
5072
5073   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
5074            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
5075 }
5076
5077 //================================================================================
5078 /*!
5079  * \brief Return true if SMESH or GEOM objects are selected.
5080  * Is called form LightApp_Module::activateModule() which clear selection if
5081  * not isSelectionCompatible()
5082  */
5083 //================================================================================
5084
5085 bool SMESHGUI::isSelectionCompatible()
5086 {
5087   bool isCompatible = true;
5088   SALOME_ListIO selected;
5089   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
5090     Sel->selectedObjects( selected );
5091
5092   SALOME_ListIteratorOfListIO It( selected );
5093   for ( ; isCompatible && It.More(); It.Next())
5094     isCompatible =
5095       ( strcmp("GEOM",        It.Value()->getComponentDataType()) == 0 ) ||
5096       ( strcmp("SHAPERSTUDY", It.Value()->getComponentDataType()) == 0 ) ||
5097       ( strcmp("SMESH",       It.Value()->getComponentDataType()) == 0 );
5098
5099   return isCompatible;
5100 }
5101
5102
5103 bool SMESHGUI::reusableOperation( const int id )
5104 {
5105   // compute, evaluate and precompute are not reusable operations
5106   return ( id == SMESHOp::OpCompute || id == SMESHOp::OpPreCompute || id == SMESHOp::OpEvaluate || id == SMESHOp::OpRecompute ) ? false : SalomeApp_Module::reusableOperation( id );
5107 }
5108
5109 namespace
5110 {
5111   QString wrap(const QString& text, const QString& tag)
5112   { return QString("<%1>%2</%3>").arg(tag).arg(text).arg(tag);}
5113 }
5114
5115 bool SMESHGUI::activateModule( SUIT_Study* study )
5116 {
5117   bool res = SalomeApp_Module::activateModule( study );
5118
5119   setMenuShown( true );
5120   setToolShown( true );
5121
5122   // Fill in Help Panel
5123   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
5124   app->infoPanel()->setTitle(tr("INFO_WELCOME_TO_SMESH"));
5125
5126   int gb = app->infoPanel()->addGroup(tr("INFO_GRP_CREATE_MESH"));
5127   QString lab;
5128   QStringList items;
5129   lab =       tr("INFO_DEFINE_ALGOS") + "<br/>";
5130   lab = lab + tr("INFO_DEFINE_HYPOS") + "<br/>";
5131   lab = lab + tr("INFO_COMPUTE") + "<br/>";
5132   lab = lab + tr("INFO_REFINE") + ":";
5133   items << wrap(tr("INFO_REFINE_LOCAL_SIZE"), "li")
5134         << wrap(tr("INFO_REFINE_SUBMESH"), "li");
5135   lab = lab + wrap(items.join(""), "ul");
5136   items.clear();
5137
5138   app->infoPanel()->addLabel(lab, gb);
5139
5140   gb = app->infoPanel()->addGroup(tr("INFO_GRP_IMPORT_MESH"));
5141   items << wrap("UNV", "li")
5142         << wrap("MED", "li")
5143         << wrap("STL", "li")
5144         << wrap("CGNS", "li")
5145         << wrap("GMF", "li");
5146   lab = tr("INFO_AVAILABLE_FORMATS") + ":" + wrap(items.join(""), "ul");
5147   items.clear();
5148
5149   app->infoPanel()->addLabel(lab, gb);
5150
5151   gb = app->infoPanel()->addGroup(tr("INFO_GRP_CHECK_MESH"));
5152   lab = tr("INFO_DISPLAY") + "<br/>";
5153   items << wrap(tr("INFO_QUALITY_AREA"), "li")
5154         << wrap(tr("INFO_QUALITY_VOLUME"), "li")
5155         << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
5156         << wrap("...", "li");
5157   lab = lab + tr("INFO_QUALITY_INFO") + ":" + wrap(items.join(""), "ul");
5158   items.clear();
5159   lab = lab + tr("INFO_CLIPPING");
5160
5161   app->infoPanel()->addLabel(lab, gb);
5162   // << Help Panel
5163
5164   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
5165   PyGILState_STATE gstate = PyGILState_Ensure();
5166   PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
5167   if ( !pluginsmanager ) {
5168     PyErr_Print();
5169   }
5170   else {
5171     PyObject* result = PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toUtf8().data(),tr("SMESH_PLUGINS_OTHER").toUtf8().data());
5172     if ( !result )
5173       PyErr_Print();
5174     Py_XDECREF(result);
5175   }
5176   PyGILState_Release(gstate);
5177   // end of SMESH plugins loading
5178
5179   // Reset actions accelerator keys
5180   action(SMESHOp::OpDelete)->setEnabled(true); // Delete: Key_Delete
5181
5182   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
5183   GetSMESHGen()->UpdateStudy();
5184
5185   // get all view currently opened in the study and connect their signals  to
5186   // the corresponding slots of the class.
5187   SUIT_Desktop* aDesk = study->application()->desktop();
5188   if ( aDesk ) {
5189     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
5190     SUIT_ViewWindow* wnd;
5191     foreach ( wnd, wndList )
5192     {
5193       connectView( wnd );
5194
5195       // remove actors whose objects are removed in GetSMESHGen()->UpdateStudy()
5196       SMESH::UpdateActorsAfterUpdateStudy(wnd);
5197
5198       wnd->update();
5199     }
5200   }
5201
5202   Py_XDECREF(pluginsmanager);
5203   return res;
5204 }
5205
5206 bool SMESHGUI::deactivateModule( SUIT_Study* study )
5207 {
5208   setMenuShown( false );
5209   setToolShown( false );
5210
5211   EmitSignalCloseAllDialogs();
5212
5213   // Unset actions accelerator keys
5214   action(SMESHOp::OpDelete)->setEnabled(false); // Delete: Key_Delete
5215
5216   return SalomeApp_Module::deactivateModule( study );
5217 }
5218
5219 void SMESHGUI::studyClosed( SUIT_Study* s )
5220 {
5221   if( !s )
5222     return;
5223   SMESH::RemoveVisuData();
5224   SalomeApp_Module::studyClosed( s );
5225 }
5226
5227 void SMESHGUI::OnGUIEvent()
5228 {
5229   const QObject* obj = sender();
5230   if ( !obj || !obj->inherits( "QAction" ) )
5231     return;
5232   int id = actionId((QAction*)obj);
5233   if ( id != -1 )
5234     OnGUIEvent( id );
5235 }
5236
5237 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
5238 {
5239   if ( CORBA::is_nil( myComponentSMESH ) )
5240   {
5241     SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
5242     return aGUI.myComponentSMESH;
5243   }
5244   return myComponentSMESH;
5245 }
5246
5247 QString SMESHGUI::engineIOR() const
5248 {
5249   CORBA::ORB_var anORB = getApp()->orb();
5250   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
5251   return QString( anIOR.in() );
5252 }
5253
5254 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
5255 {
5256   SalomeApp_Module::contextMenuPopup( client, menu, title );
5257   SALOME_ListIO lst;
5258   selectionMgr()->selectedObjects( lst );
5259   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
5260     Handle(SALOME_InteractiveObject) io = lst.First();
5261     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
5262     _PTR(Study) study = appStudy->studyDS();
5263     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
5264     if ( obj ) {
5265       QString aName = SMESH::fromUtf8( obj->GetName());
5266       while ( !aName.isEmpty() && aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
5267         aName.remove(( aName.length() - 1 ), 1 );
5268       title = aName;
5269     }
5270   }
5271 }
5272
5273 LightApp_Selection* SMESHGUI::createSelection() const
5274 {
5275   return new SMESHGUI_Selection();
5276 }
5277
5278 void SMESHGUI::windows( QMap<int, int>& aMap ) const
5279 {
5280   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
5281   aMap.insert( SalomeApp_Application::WT_NoteBook, Qt::LeftDockWidgetArea );
5282   aMap.insert( SalomeApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
5283 #ifndef DISABLE_PYCONSOLE
5284   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
5285 #endif
5286 }
5287
5288 void SMESHGUI::viewManagers( QStringList& list ) const
5289 {
5290   list.append( SVTK_Viewer::Type() );
5291 }
5292
5293 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
5294 {
5295   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
5296     SMESH::UpdateSelectionProp( this );
5297
5298     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
5299     for(int i = 0; i < aViews.count() ; i++){
5300       SUIT_ViewWindow *sf = aViews[i];
5301       connectView( sf );
5302     }
5303     EmitSignalActivatedViewManager();
5304   }
5305 }
5306
5307 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
5308 {
5309   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
5310     myClippingPlaneInfoMap.erase( theViewManager );
5311 }
5312
5313 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
5314 {
5315   theActor->AddObserver( SMESH::DeleteActorEvent,
5316                          myEventCallbackCommand.GetPointer(),
5317                          myPriority );
5318 }
5319
5320 void SMESHGUI::ProcessEvents( vtkObject* theObject,
5321                               unsigned long theEvent,
5322                               void* theClientData,
5323                               void* /*theCallData*/ )
5324 {
5325   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
5326     if( theObject && (int) theEvent == SMESH::DeleteActorEvent ) {
5327       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
5328         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
5329         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
5330         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
5331           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
5332           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
5333           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
5334             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
5335             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
5336             SMESH::TActorList::iterator anIter3 = anActorList.begin();
5337             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
5338               if( anActor == *anIter3 ) {
5339                 anActorList.erase( anIter3 );
5340                 break;
5341               }
5342             }
5343           }
5344         }
5345       }
5346     }
5347   }
5348 }
5349
5350 void SMESHGUI::createPreferences()
5351 {
5352   // General tab ------------------------------------------------------------------------
5353   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
5354
5355   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
5356   setPreferenceProperty( autoUpdate, "columns", 2 );
5357   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
5358   setPreferenceProperty( lim, "min",  0 );
5359   setPreferenceProperty( lim, "max",  100000000 );
5360   setPreferenceProperty( lim, "step", 1000 );
5361   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5362   addPreference( tr( "PREF_INCREMENTAL_LIMIT" ), autoUpdate, LightApp_Preferences::Bool, "SMESH", "incremental_limit" );
5363
5364   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE_GROUP" ), genTab );
5365   setPreferenceProperty( dispgroup, "columns", 2 );
5366
5367   addPreference( tr( "PREF_FITALL_ON_DISPLAYONLY" ), dispgroup, LightApp_Preferences::Bool, "SMESH", "fitall_on_displayonly" );
5368
5369   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
5370   QStringList modes;
5371   modes.append( tr("MEN_WIRE") );
5372   modes.append( tr("MEN_SHADE") );
5373   modes.append( tr("MEN_NODES") );
5374   modes.append( tr("MEN_SHRINK") );
5375   QList<QVariant> indices;
5376   indices.append( 0 );
5377   indices.append( 1 );
5378   indices.append( 2 );
5379   indices.append( 3 );
5380   setPreferenceProperty( dispmode, "strings", modes );
5381   setPreferenceProperty( dispmode, "indexes", indices );
5382
5383   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE_GROUP" ), genTab );
5384   setPreferenceProperty( arcgroup, "columns", 2 );
5385   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
5386   QStringList quadraticModes;
5387   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
5388   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
5389   indices.clear();
5390   indices.append( 0 );
5391   indices.append( 1 );
5392   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
5393   setPreferenceProperty( quadraticmode, "indexes", indices );
5394
5395   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
5396                               "SMESH", "max_angle" );
5397   setPreferenceProperty( maxAngle, "min", 1 );
5398   setPreferenceProperty( maxAngle, "max", 90 );
5399
5400   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
5401   setPreferenceProperty( qaGroup, "columns", 2 );
5402   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
5403   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
5404   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
5405   setPreferenceProperty( prec, "min", 0 );
5406   setPreferenceProperty( prec, "max", 100 );
5407   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
5408   setPreferenceProperty( doubleNodesTol, "precision", 10 );
5409   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
5410   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
5411   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
5412
5413   /*
5414   int cinc = addPreference(tr("PREF_CONTROLS_INCREMENT"), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_increment");
5415   setPreferenceProperty( cinc, "min", 0 );
5416   setPreferenceProperty( cinc, "max", 5 );
5417   */
5418
5419   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
5420   setPreferenceProperty( exportgroup, "columns", 2 );
5421   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
5422   addPreference( tr( "PREF_SHOW_WARN" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "show_warning" );
5423   addPreference( tr( "PREF_MED_SAVE_NUMS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "med_save_numbers" );
5424   int zTol = addPreference( tr( "PREF_ZTOLERANCE" ), exportgroup, LightApp_Preferences::DblSpin, "SMESH", "med_ztolerance" );
5425   setPreferenceProperty( zTol, "precision", 10 );
5426   setPreferenceProperty( zTol, "min", 0.0000000001 );
5427   setPreferenceProperty( zTol, "max", 1000000.0 );
5428   setPreferenceProperty( zTol, "step", 1. );
5429   //addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
5430
5431   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
5432   setPreferenceProperty( computeGroup, "columns", 2 );
5433   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
5434   modes.clear();
5435   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
5436   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
5437   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
5438   indices.clear();
5439   indices.append( 0 );
5440   indices.append( 1 );
5441   indices.append( 2 );
5442   setPreferenceProperty( notifyMode, "strings", modes );
5443   setPreferenceProperty( notifyMode, "indexes", indices );
5444
5445   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
5446   setPreferenceProperty( infoGroup, "columns", 2 );
5447   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
5448   modes.clear();
5449   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
5450   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
5451   indices.clear();
5452   indices.append( 0 );
5453   indices.append( 1 );
5454   setPreferenceProperty( elemInfo, "strings", modes );
5455   setPreferenceProperty( elemInfo, "indexes", indices );
5456   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
5457   setPreferenceProperty( nodesLim, "min", 0 );
5458   setPreferenceProperty( nodesLim, "max", 10000000 );
5459   setPreferenceProperty( nodesLim, "step", 10000 );
5460   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5461   int ctrlLim = addPreference( tr( "PREF_CTRL_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_controls_limit" );
5462   setPreferenceProperty( ctrlLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5463   setPreferenceProperty( ctrlLim, "min", 0 );
5464   setPreferenceProperty( ctrlLim, "max", 10000000 );
5465   setPreferenceProperty( ctrlLim, "step", 1000 );
5466   addPreference( tr( "PREF_ELEM_INFO_GRP_DETAILS" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "elem_info_grp_details" );
5467   addPreference( tr( "PREF_DUMP_BASE_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_base" );
5468   addPreference( tr( "PREF_DUMP_ELEM_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_elem" );
5469   addPreference( tr( "PREF_DUMP_ADD_INFO"  ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_add" );
5470   addPreference( tr( "PREF_DUMP_CTRL_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_ctrl" );
5471
5472   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
5473   setPreferenceProperty( segGroup, "columns", 2 );
5474   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
5475                               "SMESH", "segmentation" );
5476   setPreferenceProperty( segLen, "min", 1 );
5477   setPreferenceProperty( segLen, "max", 10000000 );
5478   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
5479                              "SMESH", "nb_segments_per_edge" );
5480   setPreferenceProperty( nbSeg, "min", 1 );
5481   setPreferenceProperty( nbSeg, "max", 10000000 );
5482   addPreference( tr( "PREF_USE_MESHGEMS_HYPOSET" ), segGroup, LightApp_Preferences::Bool, "SMESH", "use-meshgems-hypo-sets" );
5483
5484   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
5485   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
5486                  "SMESH", "forget_mesh_on_hyp_modif" );
5487
5488
5489   // Quantities with individual precision settings
5490   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
5491   setPreferenceProperty( precGroup, "columns", 2 );
5492
5493   const int nbQuantities = 6;
5494   int precs[nbQuantities], ii = 0;
5495   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
5496                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
5497   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
5498                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
5499   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
5500                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
5501   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
5502                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
5503   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
5504                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
5505   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
5506                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
5507
5508   // Set property for precision value for spinboxes
5509   for ( ii = 0; ii < nbQuantities; ii++ ){
5510     setPreferenceProperty( precs[ii], "min", -14 );
5511     setPreferenceProperty( precs[ii], "max", 14 );
5512     setPreferenceProperty( precs[ii], "precision", 2 );
5513   }
5514
5515   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
5516   setPreferenceProperty( previewGroup, "columns", 2 );
5517   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
5518   setPreferenceProperty( chunkSize, "min",  1 );
5519   setPreferenceProperty( chunkSize, "max",  1000 );
5520   setPreferenceProperty( chunkSize, "step", 50 );
5521
5522   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
5523   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
5524
5525   // Mesh tab ------------------------------------------------------------------------
5526   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
5527   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
5528   setPreferenceProperty( nodeGroup, "columns", 3 );
5529
5530   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
5531
5532   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
5533
5534   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5535   QList<QVariant> aMarkerTypeIndicesList;
5536   QList<QVariant> aMarkerTypeIconsList;
5537   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
5538     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
5539     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
5540     aMarkerTypeIndicesList << i;
5541     aMarkerTypeIconsList << pixmap;
5542   }
5543   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
5544   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
5545
5546   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
5547
5548   QList<QVariant> aMarkerScaleIndicesList;
5549   QStringList     aMarkerScaleValuesList;
5550   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
5551     aMarkerScaleIndicesList << i;
5552     //aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
5553     aMarkerScaleValuesList  << QString::number( i );
5554   }
5555   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
5556   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
5557
5558   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
5559   //setPreferenceProperty( elemGroup, "columns", 2 );
5560
5561   int ColorId = addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
5562   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
5563   ColorId = addPreference( tr( "PREF_VOLUME" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "volume_color" );
5564   setPreferenceProperty( ColorId, "text", tr("PREF_REVERSEDVOLUME") );
5565   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
5566   addPreference( tr( "PREF_BALL_COLOR" ), elemGroup, LightApp_Preferences::Color, "SMESH", "ball_elem_color" );
5567   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
5568   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
5569   addPreference( tr( "PREF_PREVIEW_COLOR"  ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "preview_color" );
5570
5571
5572   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
5573   setPreferenceProperty( grpGroup, "columns", 2 );
5574
5575   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
5576   addPreference( tr( "PREF_GRP_DEF_COLOR" ), grpGroup, LightApp_Preferences::Color, "SMESH", "default_grp_color" );
5577
5578   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
5579                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
5580   /* int ballSize = addPreference(tr("PREF_BALL_SIZE"), elemGroup,
5581      LightApp_Preferences::IntSpin, "SMESH", "ball_elem_size"); */
5582   int ballDiameter = addPreference(tr("PREF_BALL_DIAMETER"), elemGroup,
5583                                    LightApp_Preferences::DblSpin, "SMESH", "ball_elem_diameter");
5584   int ballScale    = addPreference(tr("PREF_BALL_SCALE"), elemGroup,
5585                                    LightApp_Preferences::DblSpin, "SMESH", "ball_elem_scale");
5586   int elemW        = addPreference(tr("PREF_WIDTH"), elemGroup,
5587                                    LightApp_Preferences::IntSpin, "SMESH", "element_width");
5588   int outW         = addPreference(tr("PREF_OUTLINE_WIDTH"), elemGroup,
5589                                    LightApp_Preferences::IntSpin, "SMESH", "outline_width");
5590   int shrink       = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
5591                                    LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
5592
5593   setPreferenceProperty( size0d, "min", 1 );
5594   setPreferenceProperty( size0d, "max", 10 );
5595
5596   // setPreferenceProperty( ballSize, "min", 1 );
5597   // setPreferenceProperty( ballSize, "max", 10 );
5598
5599   setPreferenceProperty( ballDiameter, "min", 1e-7 );
5600   setPreferenceProperty( ballDiameter, "max", 1e9 );
5601   setPreferenceProperty( ballDiameter, "step", 0.1 );
5602
5603   setPreferenceProperty( ballScale, "min", 1e-2 );
5604   setPreferenceProperty( ballScale, "max", 1e7 );
5605   setPreferenceProperty( ballScale, "step", 0.5 );
5606
5607   setPreferenceProperty( elemW, "min", 1 );
5608   setPreferenceProperty( elemW, "max", 5 );
5609
5610   setPreferenceProperty( outW, "min", 1 );
5611   setPreferenceProperty( outW, "max", 5 );
5612
5613   setPreferenceProperty( shrink, "min", 0 );
5614   setPreferenceProperty( shrink, "max", 100 );
5615
5616   int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
5617   setPreferenceProperty( numGroup, "columns", 2 );
5618
5619   addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
5620   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
5621
5622   addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
5623   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
5624
5625   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
5626   setPreferenceProperty( orientGroup, "columns", 1 );
5627
5628   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
5629   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
5630
5631   setPreferenceProperty( orientScale, "min", 0.05 );
5632   setPreferenceProperty( orientScale, "max", 0.5 );
5633   setPreferenceProperty( orientScale, "step", 0.05 );
5634
5635   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
5636
5637   // Selection tab ------------------------------------------------------------------------
5638   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
5639
5640   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
5641   setPreferenceProperty( selGroup, "columns", 2 );
5642
5643   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
5644   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
5645
5646   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
5647   setPreferenceProperty( preGroup, "columns", 2 );
5648
5649   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
5650
5651   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
5652   setPreferenceProperty( precSelGroup, "columns", 2 );
5653
5654   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
5655   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
5656   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
5657
5658   int sinc = addPreference(tr("PREF_SELECTION_INCREMENT"), selTab, LightApp_Preferences::IntSpin, "SMESH", "selection_increment");
5659   setPreferenceProperty( sinc, "min", 0 );
5660   setPreferenceProperty( sinc, "max", 5 );
5661
5662   // Scalar Bar tab ------------------------------------------------------------------------
5663   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
5664   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
5665   setPreferenceProperty( fontGr, "columns", 2 );
5666
5667   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
5668   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
5669
5670   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
5671   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
5672
5673   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
5674   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
5675
5676   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
5677   setPreferenceProperty( numcol, "min", 2 );
5678   setPreferenceProperty( numcol, "max", 256 );
5679
5680   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
5681   setPreferenceProperty( numlab, "min", 2 );
5682   setPreferenceProperty( numlab, "max", 65 );
5683
5684   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
5685   setPreferenceProperty( orientGr, "columns", 2 );
5686   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
5687   QStringList orients;
5688   orients.append( tr( "SMESH_VERTICAL" ) );
5689   orients.append( tr( "SMESH_HORIZONTAL" ) );
5690   indices.clear(); indices.append( 0 ); indices.append( 1 );
5691   setPreferenceProperty( orient, "strings", orients );
5692   setPreferenceProperty( orient, "indexes", indices );
5693
5694   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
5695   setPreferenceProperty( posVSizeGr, "columns", 2 );
5696   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
5697   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
5698   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
5699   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
5700   setPreferenceProperty( xv, "step", 0.1 );
5701   setPreferenceProperty( xv, "min", 0.0 );
5702   setPreferenceProperty( xv, "max", 1.0 );
5703   setPreferenceProperty( yv, "step", 0.1 );
5704   setPreferenceProperty( yv, "min", 0.0 );
5705   setPreferenceProperty( yv, "max", 1.0 );
5706   setPreferenceProperty( wv, "step", 0.1 );
5707   setPreferenceProperty( wv, "min", 0.0 );
5708   setPreferenceProperty( wv, "max", 1.0 );
5709   setPreferenceProperty( hv, "min", 0.0 );
5710   setPreferenceProperty( hv, "max", 1.0 );
5711   setPreferenceProperty( hv, "step", 0.1 );
5712
5713   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
5714   setPreferenceProperty( posHSizeGr, "columns", 2 );
5715   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
5716   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
5717   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
5718   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
5719   setPreferenceProperty( xv, "min", 0.0 );
5720   setPreferenceProperty( xv, "max", 1.0 );
5721   setPreferenceProperty( xv, "step", 0.1 );
5722   setPreferenceProperty( xh, "min", 0.0 );
5723   setPreferenceProperty( xh, "max", 1.0 );
5724   setPreferenceProperty( xh, "step", 0.1 );
5725   setPreferenceProperty( yh, "min", 0.0 );
5726   setPreferenceProperty( yh, "max", 1.0 );
5727   setPreferenceProperty( yh, "step", 0.1 );
5728   setPreferenceProperty( wh, "min", 0.0 );
5729   setPreferenceProperty( wh, "max", 1.0 );
5730   setPreferenceProperty( wh, "step", 0.1 );
5731   setPreferenceProperty( hh, "min", 0.0 );
5732   setPreferenceProperty( hh, "max", 1.0 );
5733   setPreferenceProperty( hh, "step", 0.1 );
5734
5735   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
5736   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
5737   setPreferenceProperty( distributionGr, "columns", 3 );
5738   QStringList types;
5739   types.append( tr( "SMESH_MONOCOLOR" ) );
5740   types.append( tr( "SMESH_MULTICOLOR" ) );
5741   indices.clear(); indices.append( 0 ); indices.append( 1 );
5742   setPreferenceProperty( coloringType, "strings", types );
5743   setPreferenceProperty( coloringType, "indexes", indices );
5744   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
5745
5746   // Adaptation - begin
5747 #ifndef DISABLE_MG_ADAPT
5748   // Adaptation tab ------------------------------------------------------------------------
5749   int adaptTab = addPreference( tr( "ADAPT_PREF_TAB_GENERAL" ) );
5750   int bloc, pref ;
5751   // MG-Adapt
5752   bloc = addPreference( tr( "ADAPT_PREF_MG_ADAPT" ), adaptTab );
5753   setPreferenceProperty( bloc, "columns", 1 );
5754   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_FILE_MAILLAGE_OUT" ), bloc, LightApp_Preferences::Bool, "HOMARD", "mg_adapt_file_mesh_out" );
5755   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_PUBLICATION_MAILLAGE_OUT" ), bloc, LightApp_Preferences::Bool, "HOMARD", "mg_adapt_publish_mesh_out" );
5756   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP" ), bloc, LightApp_Preferences::Selector, "HOMARD", "mg_adapt_size_map" );
5757   QStringList aListOfSizeMap;
5758   aListOfSizeMap << tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP_LOCAL" );
5759   aListOfSizeMap << tr( "ADAPT_PREF_MG_ADAPT_SIZE_MAP_BACKGROUND" );
5760   aListOfSizeMap << tr( "ADAPT_PREF_NONE" );;
5761   setPreferenceProperty( pref, "strings", aListOfSizeMap );
5762   pref = addPreference( tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP" ), bloc, LightApp_Preferences::Selector, "HOMARD", "mg_adapt_time_step" );
5763   QStringList aListOfTimeStep;
5764   aListOfTimeStep << tr( "ADAPT_PREF_NONE" );
5765   aListOfTimeStep << tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP_LAST" );
5766   aListOfTimeStep << tr( "ADAPT_PREF_MG_ADAPT_TIME_STEP_C" );;
5767   setPreferenceProperty( pref, "strings", aListOfTimeStep );
5768 #endif
5769   // Adaptation - end
5770 }
5771
5772 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
5773 {
5774   if ( sect=="SMESH" ) {
5775     double sbX1 = 0.01, sbY1 = 0.01, sbW = 0.08, sbH = 0.08;
5776     double aTol = 1.00000009999999;
5777     std::string aWarning;
5778     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5779
5780     if ( name ==  "selection_object_color" ||
5781          name == "selection_element_color" ||
5782          name ==         "highlight_color" ||
5783          name == "selection_precision_node"    ||
5784          name == "selection_precision_element" ||
5785          name == "selection_precision_object"  ||
5786          name == "selection_increment")
5787     {
5788       SMESH::UpdateSelectionProp( this );
5789     }
5790     else if (name == "scalar_bar_vertical_x" || name == "scalar_bar_vertical_width")
5791     {
5792       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5793       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
5794       if ( sbX1+sbW > aTol ) {
5795         aWarning = "Origin and Size Vertical: X+Width > 1\n";
5796         sbX1 = 0.01;
5797         sbW  = 0.08;
5798         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5799         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
5800       }
5801     }
5802     else if (name == "scalar_bar_vertical_y" || name == "scalar_bar_vertical_height" )
5803     {
5804       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5805       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
5806       if ( sbY1 + sbH > aTol ) {
5807         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
5808         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5809         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
5810       }
5811     }
5812     else if (name == "scalar_bar_horizontal_x" || name ==  "scalar_bar_horizontal_width")
5813     {
5814       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x",     sbX1);
5815       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
5816       if ( sbX1 + sbW > aTol ) {
5817         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
5818         sbX1=0.1;
5819         sbW =0.08;
5820         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5821         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
5822       }
5823     }
5824     else if (name == "scalar_bar_horizontal_y" || name ==  "scalar_bar_horizontal_height")
5825     {
5826       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y",     sbY1);
5827       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
5828       if ( sbY1 + sbH > aTol ) {
5829         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
5830         sbY1=0.01;
5831         sbH =0.08;
5832         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5833         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
5834       }
5835     }
5836     else if ( name == "segmentation" )
5837     {
5838       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
5839       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
5840     }
5841     else if ( name == "nb_segments_per_edge" )
5842     {
5843       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
5844       myComponentSMESH->SetDefaultNbSegments( nbSeg );
5845     }
5846     else if ( name == "historical_python_dump" || name == "forget_mesh_on_hyp_modif" || name == "default_grp_color" )
5847     {
5848       QString val = aResourceMgr->stringValue( "SMESH", name );
5849       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
5850     }
5851     else if ( name == "numbering_node_color" || name == "numbering_node_font" )
5852     {
5853       SMESH::UpdateFontProp( this );
5854     }
5855     else if ( name == "numbering_elem_color" || name == "numbering_elem_font" )
5856     {
5857       SMESH::UpdateFontProp( this );
5858     }
5859
5860     if ( aWarning.size() != 0 ) {
5861       aWarning += "The default values are applied instead.";
5862       SUIT_MessageBox::warning(SMESHGUI::desktop(),
5863                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
5864                                QObject::tr(aWarning.c_str()));
5865     }
5866   }
5867 }
5868
5869 //================================================================================
5870 /*!
5871  * \brief Update something in accordance with update flags
5872   * \param theFlags - update flags
5873 *
5874 * Update viewer or/and object browser etc. in accordance with update flags ( see
5875 * LightApp_UpdateFlags enumeration ).
5876 */
5877 //================================================================================
5878 void SMESHGUI::update( const int flags )
5879 {
5880   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5881     SMESH::UpdateView();
5882   else
5883     SalomeApp_Module::update( flags );
5884 }
5885
5886 //================================================================================
5887 /*!
5888  * \brief Set default selection mode
5889 *
5890 * SLOT called when operation committed. Sets default selection mode
5891 */
5892 //================================================================================
5893 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5894 {
5895   SVTK_ViewWindow* vtkWnd =
5896     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5897   if ( vtkWnd )
5898     vtkWnd->SetSelectionMode( ActorSelection );
5899 }
5900
5901 //================================================================================
5902 /*!
5903  * \brief Set default selection mode
5904 *
5905 * SLOT called when operation aborted. Sets default selection mode
5906 */
5907 //================================================================================
5908 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5909 {
5910   SVTK_ViewWindow* vtkWnd =
5911     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5912   if ( vtkWnd )
5913     vtkWnd->SetSelectionMode( ActorSelection );
5914 }
5915
5916 //================================================================================
5917 /*!
5918  * \brief Creates operation with given identifier
5919   * \param id - identifier of operation to be started
5920   * \return Pointer on created operation or NULL if operation is not created
5921 *
5922 * Virtual method redefined from the base class creates operation with given id.
5923 * It is called called automatically from startOperation method of base class.
5924 */
5925 //================================================================================
5926 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5927 {
5928   LightApp_Operation* op = 0;
5929   // to do : create operation here
5930   switch( id )
5931   {
5932   case SMESHOp::OpSplitBiQuadratic:
5933     op = new SMESHGUI_SplitBiQuadOp();
5934     break;
5935   case SMESHOp::OpConvertMeshToQuadratic:
5936     op = new SMESHGUI_ConvToQuadOp();
5937     break;
5938   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh as boundary on 3D
5939     op = new SMESHGUI_Make2DFrom3DOp();
5940     break;
5941   case SMESHOp::OpReorientFaces:
5942     op = new SMESHGUI_ReorientFacesOp();
5943     break;
5944   case SMESHOp::OpCreateMesh:
5945     op = new SMESHGUI_MeshOp( true, true );
5946     break;
5947   case SMESHOp::OpCreateSubMesh:
5948     op = new SMESHGUI_MeshOp( true, false );
5949     break;
5950   case SMESHOp::OpEditMeshOrSubMesh:
5951   case SMESHOp::OpEditMesh:
5952   case SMESHOp::OpEditSubMesh:
5953     op = new SMESHGUI_MeshOp( false );
5954     break;
5955   case SMESHOp::OpCompute:
5956   case SMESHOp::OpComputeSubMesh:
5957     op = new SMESHGUI_ComputeOp();
5958     break;
5959   case SMESHOp::OpShowErrors:
5960     op = new SMESHGUI_ShowErrorsOp();
5961     break;
5962   case SMESHOp::OpPreCompute:
5963     op = new SMESHGUI_PrecomputeOp();
5964     break;
5965   case SMESHOp::OpEvaluate:
5966     op = new SMESHGUI_EvaluateOp();
5967     break;
5968   case SMESHOp::OpMeshOrder:
5969     op = new SMESHGUI_MeshOrderOp();
5970     break;
5971   case SMESHOp::OpCreateGeometryGroup:
5972     op = new SMESHGUI_GroupOnShapeOp();
5973     break;
5974   case SMESHOp::OpFindElementByPoint:
5975     op = new SMESHGUI_FindElemByPointOp();
5976     break;
5977   case SMESHOp::OpMoveNode: // Make mesh pass through point
5978     op = new SMESHGUI_MakeNodeAtPointOp();
5979     break;
5980   case SMESHOp::OpElem0DOnElemNodes: // Create 0D elements on all nodes
5981     op = new SMESHGUI_Add0DElemsOnAllNodesOp();
5982     break;
5983   default:
5984     break;
5985   }
5986
5987   if( !op )
5988     op = SalomeApp_Module::createOperation( id );
5989   return op;
5990 }
5991
5992 //================================================================================
5993 /*!
5994  * \brief Stops current operations and starts a given one
5995   * \param id - The id of the operation to start
5996  */
5997 //================================================================================
5998
5999 void SMESHGUI::switchToOperation(int id)
6000 {
6001   activeStudy()->abortAllOperations();
6002   startOperation( id );
6003 }
6004
6005 LightApp_Displayer* SMESHGUI::displayer()
6006 {
6007   if( !myDisplayer )
6008     myDisplayer = new SMESHGUI_Displayer( getApp() );
6009   return myDisplayer;
6010 }
6011
6012 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
6013 {
6014   int aHue = -1;
6015   int aTolerance = 64;
6016   int anIterations = 0;
6017   int aPeriod = 5;
6018
6019   while( 1 )
6020   {
6021     anIterations++;
6022     if( anIterations % aPeriod == 0 )
6023     {
6024       aTolerance /= 2;
6025       if( aTolerance < 1 )
6026         break;
6027     }
6028
6029     aHue = (int)( 360.0 * rand() / RAND_MAX );
6030
6031     bool ok = true;
6032     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
6033     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
6034     for( ; it != itEnd; ++it )
6035     {
6036       SALOMEDS::Color anAutoColor = *it;
6037       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
6038
6039       int h, s, v;
6040       aQColor.getHsv( &h, &s, &v );
6041       if( abs( h - aHue ) < aTolerance )
6042       {
6043         ok = false;
6044         break;
6045       }
6046     }
6047
6048     if( ok )
6049       break;
6050   }
6051
6052   QColor aColor;
6053   aColor.setHsv( aHue, 255, 255 );
6054
6055   SALOMEDS::Color aSColor;
6056   aSColor.R = aColor.redF();
6057   aSColor.G = aColor.greenF();
6058   aSColor.B = aColor.blueF();
6059
6060   return aSColor;
6061 }
6062
6063 const char* gSeparator = "_"; // character used to separate parameter names
6064 const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
6065 const char* gPathSep   = "|"; // character used to separate paths
6066
6067 /*!
6068  * \brief Store visual parameters
6069  *
6070  * This method is called just before the study document is saved.
6071  * Store visual parameters in AttributeParameter attribute(s)
6072  */
6073 void SMESHGUI::storeVisualParameters (int savePoint)
6074 {
6075   // localizing
6076   Kernel_Utils::Localizer loc;
6077
6078   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
6079   if (!appStudy || !appStudy->studyDS())
6080     return;
6081   _PTR(Study) studyDS = appStudy->studyDS();
6082
6083   // componentName is used for encoding of entries when storing them in IParameters
6084   std::string componentName = myComponentSMESH->ComponentDataType();
6085   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
6086   //if (!aSComponent) return;
6087
6088   // IParameters
6089   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
6090                                                              componentName.c_str(),
6091                                                              savePoint);
6092   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
6093
6094   // store custom markers
6095   if( !myMarkerMap.empty() )
6096   {
6097     VTK::MarkerMap::const_iterator anIter = myMarkerMap.begin();
6098     for( ; anIter != myMarkerMap.end(); anIter++ )
6099     {
6100       int anId = anIter->first;
6101       VTK::MarkerData aMarkerData = anIter->second;
6102       std::string aMarkerFileName = aMarkerData.first;
6103       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
6104       if( aMarkerTexture.size() < 3 )
6105         continue; // should contain at least width, height and the first value
6106
6107       QString aPropertyName( "texture" );
6108       aPropertyName += gSeparator;
6109       aPropertyName += QString::number( anId );
6110
6111       QString aPropertyValue = aMarkerFileName.c_str();
6112       aPropertyValue += gPathSep;
6113
6114       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
6115       ushort aWidth = *aTextureIter++;
6116       ushort aHeight = *aTextureIter++;
6117       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
6118       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
6119       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
6120         aPropertyValue += QString::number( *aTextureIter );
6121
6122       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
6123     }
6124   }
6125
6126   // viewers counters are used for storing view_numbers in IParameters
6127   int vtkViewers = 0;
6128
6129   // main cycle to store parameters of displayed objects
6130   QList<SUIT_ViewManager*> lst;
6131   QList<SUIT_ViewManager*>::Iterator it;
6132   getApp()->viewManagers(lst);
6133   for (it = lst.begin(); it != lst.end(); it++)
6134   {
6135     SUIT_ViewManager* vman = *it;
6136     QString vType = vman->getType();
6137
6138     // saving VTK actors properties
6139     if (vType == SVTK_Viewer::Type())
6140     {
6141       // store the clipping planes attached to the view manager
6142       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
6143       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
6144       if( anIter != myClippingPlaneInfoMap.end() )
6145         aClippingPlaneInfoList = anIter->second;
6146
6147       if( !aClippingPlaneInfoList.empty() ) {
6148         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
6149         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
6150         {
6151           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
6152           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
6153
6154           QString aPropertyName( "ClippingPlane" );
6155           aPropertyName += gSeparator;
6156           aPropertyName += QString::number( vtkViewers );
6157           aPropertyName += gSeparator;
6158           aPropertyName += QString::number( anId );
6159
6160           QString aPropertyValue = QString::number( (int)aPlane->PlaneMode ).toLatin1().constData();
6161           aPropertyValue += gDigitsSep;
6162           aPropertyValue += QString::number( aPlane->IsOpenGLClipping ).toLatin1().constData();
6163           aPropertyValue += gDigitsSep;
6164           if ( aPlane->PlaneMode == SMESH::Absolute ) {
6165             aPropertyValue += QString::number( aPlane->myAbsoluteOrientation ).toLatin1().constData();
6166             aPropertyValue += gDigitsSep;
6167             aPropertyValue += QString::number( aPlane->X ).toLatin1().constData();
6168             aPropertyValue += gDigitsSep;
6169             aPropertyValue += QString::number( aPlane->Y ).toLatin1().constData();
6170             aPropertyValue += gDigitsSep;
6171             aPropertyValue += QString::number( aPlane->Z ).toLatin1().constData();
6172             aPropertyValue += gDigitsSep;
6173             aPropertyValue += QString::number( aPlane->Dx ).toLatin1().constData();
6174             aPropertyValue += gDigitsSep;
6175             aPropertyValue += QString::number( aPlane->Dy ).toLatin1().constData();
6176             aPropertyValue += gDigitsSep;
6177             aPropertyValue += QString::number( aPlane->Dz ).toLatin1().constData();
6178           }
6179           else if ( aPlane->PlaneMode == SMESH::Relative ) {
6180             aPropertyValue += QString::number( (int)aPlane->myRelativeOrientation ).toLatin1().constData();
6181             aPropertyValue += gDigitsSep;
6182             aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
6183             aPropertyValue += gDigitsSep;
6184             aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
6185             aPropertyValue += gDigitsSep;
6186             aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
6187           }
6188
6189           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
6190         }
6191       }
6192
6193       QVector<SUIT_ViewWindow*> views = vman->getViews();
6194       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
6195       {
6196         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
6197         {
6198           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
6199           vtkActorCollection* allActors = aCopy.GetActors();
6200           allActors->InitTraversal();
6201           while (vtkActor* actor = allActors->GetNextActor())
6202           {
6203             if (actor->GetVisibility()) // store only visible actors
6204             {
6205               SMESH_Actor* aSmeshActor = 0;
6206               if (actor->IsA("SMESH_Actor"))
6207                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
6208               if (aSmeshActor && aSmeshActor->hasIO())
6209               {
6210                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
6211                 if (io->hasEntry())
6212                 {
6213                   // entry is "encoded" = it does NOT contain component address,
6214                   // since it is a subject to change on next component loading
6215                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
6216
6217                   std::string param, vtkParam = vType.toLatin1().data();
6218                   vtkParam += gSeparator;
6219                   vtkParam += QString::number(vtkViewers).toLatin1().data();
6220                   vtkParam += gSeparator;
6221
6222                   // Visibility
6223                   param = vtkParam + "Visibility";
6224                   ip->setParameter(entry, param, "On");
6225
6226                   // Representation
6227                   param = vtkParam + "Representation";
6228                   ip->setParameter(entry, param, QString::number
6229                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
6230
6231                   // IsShrunk
6232                   param = vtkParam + "IsShrunk";
6233                   ip->setParameter(entry, param, QString::number
6234                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
6235
6236                   // Displayed entities
6237                   unsigned int aMode = aSmeshActor->GetEntityMode();
6238                   bool isE  = aMode & SMESH_Actor::eEdges;
6239                   bool isF  = aMode & SMESH_Actor::eFaces;
6240                   bool isV  = aMode & SMESH_Actor::eVolumes;
6241                   bool is0d = aMode & SMESH_Actor::e0DElements;
6242                   bool isB  = aMode & SMESH_Actor::eBallElem;
6243
6244                   QString modeStr ("e");
6245                   modeStr += gDigitsSep; modeStr += QString::number(isE);
6246                   modeStr += gDigitsSep; modeStr += "f";
6247                   modeStr += gDigitsSep; modeStr += QString::number(isF);
6248                   modeStr += gDigitsSep; modeStr += "v";
6249                   modeStr += gDigitsSep; modeStr += QString::number(isV);
6250                   modeStr += gDigitsSep; modeStr += "0d";
6251                   modeStr += gDigitsSep; modeStr += QString::number(is0d);
6252                   modeStr += gDigitsSep; modeStr += "b";
6253                   modeStr += gDigitsSep; modeStr += QString::number(isB);
6254
6255                   param = vtkParam + "Entities";
6256                   ip->setParameter(entry, param, modeStr.toLatin1().data());
6257
6258                   // Colors
6259                   double r, g, b;
6260                   int delta;
6261
6262                   aSmeshActor->GetSufaceColor(r, g, b, delta);
6263                   QStringList colorStr;
6264                   colorStr << "surface";
6265                   colorStr << QString::number(r);
6266                   colorStr << QString::number(g);
6267                   colorStr << QString::number(b);
6268
6269                   colorStr << "backsurface";
6270                   colorStr << QString::number(delta);
6271
6272                   aSmeshActor->GetVolumeColor(r, g, b, delta);
6273                   colorStr << "volume";
6274                   colorStr << QString::number(r);
6275                   colorStr << QString::number(g);
6276                   colorStr << QString::number(b);
6277                   colorStr << QString::number(delta);
6278
6279                   aSmeshActor->GetEdgeColor(r, g, b);
6280                   colorStr << "edge";
6281                   colorStr << QString::number(r);
6282                   colorStr << QString::number(g);
6283                   colorStr << QString::number(b);
6284
6285                   aSmeshActor->GetNodeColor(r, g, b);
6286                   colorStr << "node";
6287                   colorStr << QString::number(r);
6288                   colorStr << QString::number(g);
6289                   colorStr << QString::number(b);
6290
6291                   aSmeshActor->GetOutlineColor(r, g, b);
6292                   colorStr << "outline";
6293                   colorStr << QString::number(r);
6294                   colorStr << QString::number(g);
6295                   colorStr << QString::number(b);
6296
6297                   aSmeshActor->Get0DColor(r, g, b);
6298                   colorStr << "elem0d";
6299                   colorStr << QString::number(r);
6300                   colorStr << QString::number(g);
6301                   colorStr << QString::number(b);
6302
6303                   aSmeshActor->GetBallColor(r, g, b);
6304                   colorStr << "ball";
6305                   colorStr << QString::number(r);
6306                   colorStr << QString::number(g);
6307                   colorStr << QString::number(b);
6308
6309                   aSmeshActor->GetFacesOrientationColor(r, g, b);
6310                   colorStr << "orientation";
6311                   colorStr << QString::number(r);
6312                   colorStr << QString::number(g);
6313                   colorStr << QString::number(b);
6314
6315                   param = vtkParam + "Colors";
6316                   ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
6317
6318                   // Sizes
6319                   QStringList sizeStr;
6320                   sizeStr << "line";
6321                   sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
6322                   sizeStr << "outline";
6323                   sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
6324                   sizeStr << "elem0d";
6325                   sizeStr << QString::number((int)aSmeshActor->Get0DSize());
6326                   sizeStr << "ball";
6327                   //sizeStr << QString::number((int)aSmeshActor->GetBallSize());
6328                   sizeStr << QString::number((double)aSmeshActor->GetBallSize());
6329                   sizeStr << QString::number((double)aSmeshActor->GetBallScale());
6330                   sizeStr << "shrink";
6331                   sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
6332                   sizeStr << "orientation";
6333                   sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
6334                   sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
6335
6336                   param = vtkParam + "Sizes";
6337                   ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
6338
6339                   // Point marker
6340                   QString markerStr;
6341
6342                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
6343                   if( aMarkerType == VTK::MT_USER ) {
6344                     markerStr += "custom";
6345                     markerStr += gDigitsSep;
6346                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
6347                   }
6348                   else {
6349                     markerStr += "std";
6350                     markerStr += gDigitsSep;
6351                     markerStr += QString::number( (int)aMarkerType );
6352                     markerStr += gDigitsSep;
6353                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
6354                   }
6355
6356                   param = vtkParam + "PointMarker";
6357                   ip->setParameter(entry, param, markerStr.toLatin1().data());
6358
6359                   // Opacity
6360                   param = vtkParam + "Opacity";
6361                   ip->setParameter(entry, param,
6362                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
6363
6364                   // Clipping
6365                   param = vtkParam + "ClippingPlane";
6366                   int aPlaneId = 0;
6367                   if( !aClippingPlaneInfoList.empty() ) {
6368                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
6369                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
6370                     {
6371                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
6372                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
6373                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
6374                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
6375                         if( aSmeshActor == *anIter2 ) {
6376                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
6377                                             QString::number( anId ).toLatin1().constData() );
6378                           break;
6379                         }
6380                       }
6381                     }
6382                   }
6383                   if( aPlaneId == 0 )
6384                     ip->setParameter( entry, param, "Off" );
6385                 } // if (io->hasEntry())
6386               } // SMESH_Actor && hasIO
6387             } // isVisible
6388           } // while.. actors traversal
6389         } // if (vtkView)
6390       } // for (views)
6391       vtkViewers++;
6392     } // if (SVTK view model)
6393   } // for (viewManagers)
6394 }
6395
6396 // data structures for clipping planes processing
6397 typedef struct {
6398   int Id;
6399   int Mode;
6400   bool isOpenGLClipping;
6401   vtkIdType RelativeOrientation;
6402   double Distance;
6403   double Angle[2];
6404   int AbsoluteOrientation;
6405   double X, Y, Z, Dx, Dy, Dz;
6406 } TPlaneData;
6407 typedef std::list<TPlaneData>         TPlaneDataList;
6408 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
6409
6410 typedef std::list<vtkActor*>          TActorList;
6411 typedef struct {
6412   int PlaneId;
6413   TActorList ActorList;
6414   SUIT_ViewManager* ViewManager;
6415 } TPlaneInfo;
6416 typedef std::list<TPlaneInfo>         TPlaneInfoList;
6417 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
6418
6419 /*!
6420  * \brief Restore visual parameters
6421  *
6422  * This method is called after the study document is opened.
6423  * Restore visual parameters from AttributeParameter attribute(s)
6424  */
6425 void SMESHGUI::restoreVisualParameters (int savePoint)
6426 {
6427   // localizing
6428   Kernel_Utils::Localizer loc;
6429
6430   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
6431   if (!appStudy || !appStudy->studyDS())
6432     return;
6433   _PTR(Study) studyDS = appStudy->studyDS();
6434
6435   // componentName is used for encoding of entries when storing them in IParameters
6436   std::string componentName = myComponentSMESH->ComponentDataType();
6437
6438   // IParameters
6439   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
6440                                                              componentName.c_str(),
6441                                                              savePoint);
6442   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
6443
6444   // restore custom markers and map of clipping planes
6445   TPlaneDataMap aPlaneDataMap;
6446
6447   std::vector<std::string> properties = ip->getProperties();
6448   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
6449   {
6450     std::string property = *propIt;
6451     QString aPropertyName( property.c_str() );
6452     QString aPropertyValue( ip->getProperty( property ).c_str() );
6453
6454     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
6455     if( aPropertyNameList.isEmpty() )
6456       continue;
6457
6458     QString aPropertyType = aPropertyNameList[0];
6459     if( aPropertyType == "texture" )
6460     {
6461       if( aPropertyNameList.size() != 2 )
6462         continue;
6463
6464       bool ok = false;
6465       int anId = aPropertyNameList[1].toInt( &ok );
6466       if( !ok || anId < 1 )
6467         continue;
6468
6469       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
6470       if( aPropertyValueList.size() != 2 )
6471         continue;
6472
6473       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
6474       QString aMarkerTextureString = aPropertyValueList[1];
6475       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
6476       if( aMarkerTextureStringList.size() != 3 )
6477         continue;
6478
6479       ok = false;
6480       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
6481       if( !ok )
6482         continue;
6483
6484       ok = false;
6485       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
6486       if( !ok )
6487         continue;
6488
6489       VTK::MarkerTexture aMarkerTexture;
6490       aMarkerTexture.push_back( aWidth );
6491       aMarkerTexture.push_back( aHeight );
6492
6493       QString aMarkerTextureData = aMarkerTextureStringList[2];
6494       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
6495       {
6496         QChar aChar = aMarkerTextureData.at( i );
6497         if( aChar.isDigit() )
6498           aMarkerTexture.push_back( aChar.digitValue() );
6499       }
6500
6501       myMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
6502     }
6503     else if( aPropertyType == "ClippingPlane" )
6504     {
6505       if( aPropertyNameList.size() != 3 )
6506         continue;
6507
6508       bool ok = false;
6509       int aViewId = aPropertyNameList[1].toInt( &ok );
6510       if( !ok || aViewId < 0 )
6511         continue;
6512
6513       ok = false;
6514       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
6515       if( !ok || aClippingPlaneId < 0 )
6516         continue;
6517
6518       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
6519       if( aPropertyValueList.size() != 6 && aPropertyValueList.size() != 9 )
6520         continue;
6521
6522       TPlaneData aPlaneData;
6523       aPlaneData.AbsoluteOrientation = false;
6524       aPlaneData.RelativeOrientation = 0;
6525       aPlaneData.Distance = aPlaneData.Angle[0] = aPlaneData.Angle[1] = 0;
6526       aPlaneData.X = aPlaneData.Y = aPlaneData.Z = 0;
6527       aPlaneData.Dx = aPlaneData.Dy = aPlaneData.Dz = 0;
6528
6529       aPlaneData.Id = aClippingPlaneId;
6530
6531       ok = false;
6532       aPlaneData.Mode = aPropertyValueList[0].toInt( &ok );
6533       if( !ok )
6534         continue;
6535
6536       ok = false;
6537       aPlaneData.isOpenGLClipping = aPropertyValueList[1].toInt( &ok );
6538       if( !ok )
6539         continue;
6540
6541       if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Absolute )
6542       {
6543         ok = false;
6544         aPlaneData.AbsoluteOrientation = aPropertyValueList[2].toInt( &ok );
6545         if( !ok )
6546           continue;
6547
6548         ok = false;
6549         aPlaneData.X = aPropertyValueList[3].toDouble( &ok );
6550         if( !ok )
6551           continue;
6552
6553         ok = false;
6554         aPlaneData.Y = aPropertyValueList[4].toDouble( &ok );
6555         if( !ok )
6556           continue;
6557
6558         ok = false;
6559         aPlaneData.Z = aPropertyValueList[5].toDouble( &ok );
6560         if( !ok )
6561           continue;
6562
6563         ok = false;
6564         aPlaneData.Dx = aPropertyValueList[6].toDouble( &ok );
6565         if( !ok )
6566           continue;
6567
6568         ok = false;
6569         aPlaneData.Dy = aPropertyValueList[7].toDouble( &ok );
6570         if( !ok )
6571           continue;
6572
6573         ok = false;
6574         aPlaneData.Dz = aPropertyValueList[8].toDouble( &ok );
6575         if( !ok )
6576           continue;
6577       }
6578       else if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Relative ) {
6579         ok = false;
6580         aPlaneData.RelativeOrientation = aPropertyValueList[2].toInt( &ok );
6581         if( !ok )
6582           continue;
6583
6584         ok = false;
6585         aPlaneData.Distance = aPropertyValueList[3].toDouble( &ok );
6586         if( !ok )
6587           continue;
6588
6589         ok = false;
6590         aPlaneData.Angle[0] = aPropertyValueList[4].toDouble( &ok );
6591         if( !ok )
6592           continue;
6593
6594         ok = false;
6595         aPlaneData.Angle[1] = aPropertyValueList[5].toDouble( &ok );
6596         if( !ok )
6597           continue;
6598       }
6599
6600       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
6601       aPlaneDataList.push_back( aPlaneData );
6602     }
6603   }
6604
6605   TPlaneInfoMap aPlaneInfoMap;
6606
6607   std::vector<std::string> entries = ip->getEntries();
6608
6609   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
6610   {
6611     // entry is a normal entry - it should be "decoded" (setting base address of component)
6612     QString entry (ip->decodeEntry(*entIt).c_str());
6613
6614     // Check that the entry corresponds to a real object in the Study
6615     // as the object may be deleted or modified after the visual state is saved.
6616     _PTR(SObject) so = studyDS->FindObjectID(entry.toUtf8().data());
6617     if (!so) continue; //Skip the not existent entry
6618
6619     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
6620     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
6621
6622     std::vector<std::string>::iterator namesIt = paramNames.begin();
6623     std::vector<std::string>::iterator valuesIt = paramValues.begin();
6624
6625     // actors are stored in a map after displaying of them for
6626     // quicker access in the future: map < viewID to actor >
6627     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
6628
6629     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
6630     {
6631       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
6632       // '_' is used as separator and should not be used in viewer type or parameter names.
6633       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
6634       if (lst.size() != 3)
6635         continue;
6636
6637       QString viewerTypStr = lst[0];
6638       QString viewIndexStr = lst[1];
6639       QString paramNameStr = lst[2];
6640
6641       bool ok;
6642       int viewIndex = viewIndexStr.toUInt(&ok);
6643       if (!ok) // bad conversion of view index to integer
6644         continue;
6645
6646       // viewers
6647       if (viewerTypStr == SVTK_Viewer::Type())
6648       {
6649         SMESH_Actor* aSmeshActor = 0;
6650         if (vtkActors.IsBound(viewIndex))
6651           aSmeshActor = vtkActors.Find(viewIndex);
6652
6653         QList<SUIT_ViewManager*> lst;
6654         getApp()->viewManagers(viewerTypStr, lst);
6655
6656         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6657         SUIT_ViewManager* vman = NULL;
6658         if (viewIndex >= 0 && viewIndex < lst.count())
6659           vman = lst.at(viewIndex);
6660
6661         if (paramNameStr == "Visibility")
6662         {
6663           if (!aSmeshActor && displayer() && vman)
6664           {
6665             SUIT_ViewModel* vmodel = vman->getViewModel();
6666             // SVTK view model can be casted to SALOME_View
6667             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
6668
6669             // store displayed actor in a temporary map for quicker
6670             // access later when restoring other parameters
6671             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6672             vtkRenderer* Renderer = vtkView->getRenderer();
6673             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
6674             vtkActorCollection* theActors = aCopy.GetActors();
6675             theActors->InitTraversal();
6676             bool isFound = false;
6677             vtkActor *ac = theActors->GetNextActor();
6678             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
6679               if (ac->IsA("SMESH_Actor")) {
6680                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
6681                 if (aGeomAc->hasIO()) {
6682                   Handle(SALOME_InteractiveObject) io = aGeomAc->getIO();
6683                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toUtf8().data()) == 0) {
6684                     isFound = true;
6685                     vtkActors.Bind(viewIndex, aGeomAc);
6686                   }
6687                 }
6688               }
6689             }
6690           }
6691         } // if (paramNameStr == "Visibility")
6692         else
6693         {
6694           // the rest properties "work" with SMESH_Actor
6695           if (aSmeshActor)
6696           {
6697             QString val ((*valuesIt).c_str());
6698
6699             // Representation
6700             if (paramNameStr == "Representation") {
6701               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
6702             }
6703             // IsShrunk
6704             else if (paramNameStr == "IsShrunk") {
6705               if (val.toInt()) {
6706                 if (!aSmeshActor->IsShrunk())
6707                   aSmeshActor->SetShrink();
6708               }
6709               else {
6710                 if (aSmeshActor->IsShrunk())
6711                   aSmeshActor->UnShrink();
6712               }
6713             }
6714             // Displayed entities
6715             else if (paramNameStr == "Entities") {
6716               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
6717               int aEntityMode = SMESH_Actor::eAllEntity;
6718               for ( int i = 0; i < mode.count(); i+=2 ) {
6719                 if ( i < mode.count()-1 ) {
6720                   QString type = mode[i];
6721                   bool val = mode[i+1].toInt();
6722                   if      ( type == "e" && !val )
6723                     aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
6724                   else if ( type == "f" && !val )
6725                     aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
6726                   else if ( type == "v" && !val )
6727                     aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
6728                   else if ( type == "0d" && !val )
6729                     aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
6730                   else if ( type == "b" && !val )
6731                     aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
6732                 }
6733               }
6734               aSmeshActor->SetEntityMode( aEntityMode );
6735             }
6736             // Colors
6737             else if (paramNameStr == "Colors") {
6738               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
6739               QColor nodeColor;
6740               QColor edgeColor;
6741               QColor faceColor;
6742               QColor volumeColor;
6743               QColor elem0dColor;
6744               QColor ballColor;
6745               QColor outlineColor;
6746               QColor orientationColor;
6747               int deltaF;
6748               int deltaV;
6749               QColor c;
6750               double r, g, b;
6751               bool bOk;
6752               // below lines are required to get default values for delta coefficients
6753               // of backface color for faces and color of reversed volumes
6754               SMESH::GetColor( "SMESH", "fill_color",   c, deltaF, "0,170,255|-100" );
6755               SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
6756               for ( int i = 0; i < colors.count(); i++ ) {
6757                 QString type = colors[i];
6758                 if ( type == "surface" ) {
6759                   // face color is set by 3 values r:g:b, where
6760                   // - r,g,b - is rgb color components
6761                   if ( i+1 >= colors.count() ) break;                  // format error
6762                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6763                   if ( i+2 >= colors.count() ) break;                  // format error
6764                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6765                   if ( i+3 >= colors.count() ) break;                  // format error
6766                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6767                   faceColor.setRgbF( r, g, b );
6768                   i += 3;
6769                 }
6770                 else if ( type == "backsurface" ) {
6771                   // backface color can be defined in several ways
6772                   // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
6773                   // - in latest versions, it is set as delta coefficient
6774                   bool rgbOk = false, deltaOk;
6775                   if ( i+1 >= colors.count() ) break;                  // format error
6776                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6777                   int delta = colors[i+1].toInt( &deltaOk );
6778                   i++;                                 // shift index
6779                   if ( i+1 < colors.count() )          // index is shifted to 1
6780                     g = colors[i+1].toDouble( &rgbOk );
6781                   if ( rgbOk ) i++;                    // shift index
6782                   if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
6783                     b = colors[i+1].toDouble( &rgbOk );
6784                   if ( rgbOk ) i++;
6785                   // - as currently there's no way to set directly backsurface color as it was before,
6786                   // we ignore old dump where r,g,b triple was set
6787                   // - also we check that delta parameter is set properly
6788                   if ( !rgbOk && deltaOk )
6789                     deltaF = delta;
6790                 }
6791                 else if ( type == "volume" ) {
6792                   // volume color is set by 4 values r:g:b:delta, where
6793                   // - r,g,b - is a normal volume rgb color components
6794                   // - delta - is a reversed volume color delta coefficient
6795                   if ( i+1 >= colors.count() ) break;                  // format error
6796                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6797                   if ( i+2 >= colors.count() ) break;                  // format error
6798                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6799                   if ( i+3 >= colors.count() ) break;                  // format error
6800                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6801                   if ( i+4 >= colors.count() ) break;                  // format error
6802                   int delta = colors[i+4].toInt( &bOk );
6803                   if ( !bOk ) break;                                   // format error
6804                   volumeColor.setRgbF( r, g, b );
6805                   deltaV = delta;
6806                   i += 4;
6807                 }
6808                 else if ( type == "edge" ) {
6809                   // edge color is set by 3 values r:g:b, where
6810                   // - r,g,b - is rgb color components
6811                   if ( i+1 >= colors.count() ) break;                  // format error
6812                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6813                   if ( i+2 >= colors.count() ) break;                  // format error
6814                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6815                   if ( i+3 >= colors.count() ) break;                  // format error
6816                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6817                   edgeColor.setRgbF( r, g, b );
6818                   i += 3;
6819                 }
6820                 else if ( type == "node" ) {
6821                   // node color is set by 3 values r:g:b, where
6822                   // - r,g,b - is rgb color components
6823                   if ( i+1 >= colors.count() ) break;                  // format error
6824                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6825                   if ( i+2 >= colors.count() ) break;                  // format error
6826                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6827                   if ( i+3 >= colors.count() ) break;                  // format error
6828                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6829                   nodeColor.setRgbF( r, g, b );
6830                   i += 3;
6831                 }
6832                 else if ( type == "elem0d" ) {
6833                   // 0d element color is set by 3 values r:g:b, where
6834                   // - r,g,b - is rgb color components
6835                   if ( i+1 >= colors.count() ) break;                  // format error
6836                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6837                   if ( i+2 >= colors.count() ) break;                  // format error
6838                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6839                   if ( i+3 >= colors.count() ) break;                  // format error
6840                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6841                   elem0dColor.setRgbF( r, g, b );
6842                   i += 3;
6843                 }
6844                 else if ( type == "ball" ) {
6845                   // ball color is set by 3 values r:g:b, where
6846                   // - r,g,b - is rgb color components
6847                   if ( i+1 >= colors.count() ) break;                  // format error
6848                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6849                   if ( i+2 >= colors.count() ) break;                  // format error
6850                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6851                   if ( i+3 >= colors.count() ) break;                  // format error
6852                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6853                   ballColor.setRgbF( r, g, b );
6854                   i += 3;
6855                 }
6856                 else if ( type == "outline" ) {
6857                   // outline color is set by 3 values r:g:b, where
6858                   // - r,g,b - is rgb color components
6859                   if ( i+1 >= colors.count() ) break;                  // format error
6860                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6861                   if ( i+2 >= colors.count() ) break;                  // format error
6862                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6863                   if ( i+3 >= colors.count() ) break;                  // format error
6864                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6865                   outlineColor.setRgbF( r, g, b );
6866                   i += 3;
6867                 }
6868                 else if ( type == "orientation" ) {
6869                   // orientation color is set by 3 values r:g:b, where
6870                   // - r,g,b - is rgb color components
6871                   if ( i+1 >= colors.count() ) break;                  // format error
6872                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6873                   if ( i+2 >= colors.count() ) break;                  // format error
6874                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6875                   if ( i+3 >= colors.count() ) break;                  // format error
6876                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6877                   orientationColor.setRgbF( r, g, b );
6878                   i += 3;
6879                 }
6880               }
6881               // node color
6882               if ( nodeColor.isValid() )
6883                 aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
6884               // edge color
6885               if ( edgeColor.isValid() )
6886                 aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
6887               // face color
6888               if ( faceColor.isValid() )
6889                 aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6890               // volume color
6891               if ( volumeColor.isValid() )
6892                 aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
6893               else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
6894                 aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6895               // 0d element color
6896               if ( elem0dColor.isValid() )
6897                 aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
6898               // ball color
6899               if ( ballColor.isValid() )
6900                 aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
6901               // outline color
6902               if ( outlineColor.isValid() )
6903                 aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
6904               // orientation color
6905               if ( orientationColor.isValid() )
6906                 aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
6907             }
6908             // Sizes
6909             else if (paramNameStr == "Sizes") {
6910               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
6911               bool bOk;
6912               int lineWidth = -1;
6913               int outlineWidth = -1;
6914               int elem0dSize = -1;
6915               //int ballSize = -1;
6916               double ballDiameter = -1.0;
6917               double ballScale = -1.0;
6918               double shrinkSize = -1;
6919               double orientationSize = -1;
6920               bool orientation3d = false;
6921               for ( int i = 0; i < sizes.count(); i++ ) {
6922                 QString type = sizes[i];
6923                 if ( type == "line" ) {
6924                   // line (wireframe) width is given as single integer value
6925                   if ( i+1 >= sizes.count() ) break;                    // format error
6926                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6927                   lineWidth = v;
6928                   i++;
6929                 }
6930                 if ( type == "outline" ) {
6931                   // outline width is given as single integer value
6932                   if ( i+1 >= sizes.count() ) break;                    // format error
6933                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6934                   outlineWidth = v;
6935                   i++;
6936                 }
6937                 else if ( type == "elem0d" ) {
6938                   // 0d element size is given as single integer value
6939                   if ( i+1 >= sizes.count() ) break;                    // format error
6940                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6941                   elem0dSize = v;
6942                   i++;
6943                 }
6944                 else if ( type == "ball" ) {
6945                   // balls are specified by two values: size:scale, where
6946                   // - size - is a integer value specifying size
6947                   // - scale - is a double value specifying scale factor
6948                   if ( i+1 >= sizes.count() ) break;                       // format error
6949                   //int v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6950                   double v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6951                   if ( i+2 >= sizes.count() ) break;                       // format error
6952                   double v2 = sizes[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6953                   //ballSize = v1;
6954                   ballDiameter = v1;
6955                   ballScale = v2;
6956                   i += 2;
6957                 }
6958                 else if ( type == "shrink" ) {
6959                   // shrink factor is given as single floating point value
6960                   if ( i+1 >= sizes.count() ) break;                          // format error
6961                   double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break;  // format error
6962                   shrinkSize = v;
6963                   i++;
6964                 }
6965                 else if ( type == "orientation" ) {
6966                   // orientation vectors are specified by two values size:3d, where
6967                   // - size - is a floating point value specifying scale factor
6968                   // - 3d - is a boolean
6969                   if ( i+1 >= sizes.count() ) break;                          // format error
6970                   double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6971                   if ( i+2 >= sizes.count() ) break;                          // format error
6972                   int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break;       // format error
6973                   orientationSize = v1;
6974                   orientation3d = (bool)v2;
6975                   i += 2;
6976                 }
6977               }
6978               // line (wireframe) width
6979               if ( lineWidth > 0 )
6980                 aSmeshActor->SetLineWidth( lineWidth );
6981               // outline width
6982               if ( outlineWidth > 0 )
6983                 aSmeshActor->SetOutlineWidth( outlineWidth );
6984               else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
6985                 aSmeshActor->SetOutlineWidth( lineWidth );
6986               // 0d element size
6987               if ( elem0dSize > 0 )
6988                 aSmeshActor->Set0DSize( elem0dSize );
6989               // ball size
6990               /*if ( ballSize > 0 )
6991                 aSmeshActor->SetBallSize( ballSize );*/
6992               // ball diameter
6993               if ( ballDiameter > 0 )
6994                 aSmeshActor->SetBallSize( ballDiameter );
6995               // ball scale
6996               if ( ballScale > 0.0 )
6997                 aSmeshActor->SetBallScale( ballScale );
6998               // shrink factor
6999               if ( shrinkSize > 0 )
7000                 aSmeshActor->SetShrinkFactor( shrinkSize );
7001               // orientation vectors
7002               if ( orientationSize > 0 ) {
7003                 aSmeshActor->SetFacesOrientationScale( orientationSize );
7004                 aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
7005               }
7006             }
7007             // Point marker
7008             else if (paramNameStr == "PointMarker") {
7009               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
7010               if( data.count() >= 2 ) {
7011                 bool ok = false;
7012                 int aParam1 = data[1].toInt( &ok );
7013                 if( ok ) {
7014                   if( data[0] == "std" && data.count() == 3 ) {
7015                     int aParam2 = data[2].toInt( &ok );
7016                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
7017                   }
7018                   else if( data[0] == "custom" ) {
7019                     VTK::MarkerMap::const_iterator markerIt = myMarkerMap.find( aParam1 );
7020                     if( markerIt != myMarkerMap.end() ) {
7021                       VTK::MarkerData aMarkerData = markerIt->second;
7022                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
7023                     }
7024                   }
7025                 }
7026               }
7027             }
7028             // Opacity
7029             else if (paramNameStr == "Opacity") {
7030               aSmeshActor->SetOpacity(val.toFloat());
7031             }
7032             // Clipping
7033             else if (paramNameStr.startsWith("ClippingPlane")) {
7034               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
7035               // old format - val looks like "Off" or "1:0:0:0.5:0:0"
7036               // (mode(relative), is OpenGL clipping plane, orientation, distance, two angles)
7037               // or "0:1:1:10.5:1.0:1.0:15.0:10.0:10.0"
7038               // (mode(absolute), is OpenGL clipping plane, orientation, base point(x, y, z), direction (dx, dy, dz))
7039               // new format - val looks like "Off" or "0" (plane id)
7040               // (note: in new format "Off" value is used only for consistency,
7041               //  so it is processed together with values in old format)
7042               bool anIsOldFormat = ( vals.count() == 6 || vals.count() == 9 || val == "Off" );
7043               if( anIsOldFormat ) {
7044                 if (paramNameStr == "ClippingPlane1" || val == "Off")
7045                   aSmeshActor->RemoveAllClippingPlanes();
7046                 if (val != "Off") {
7047                   QList<SUIT_ViewManager*> lst;
7048                   getApp()->viewManagers(viewerTypStr, lst);
7049                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
7050                   if (viewIndex >= 0 && viewIndex < lst.count()) {
7051                     SUIT_ViewManager* vman = lst.at(viewIndex);
7052                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
7053
7054                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
7055
7056                     SMESH::TActorList anActorList;
7057                     anActorList.push_back( aSmeshActor );
7058                     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( vtkView );
7059                     aPlane->myViewWindow = vtkView;
7060                     SMESH::Mode aMode = ( SMESH::Mode )vals[0].toInt();
7061                     aPlane->PlaneMode = aMode;
7062                     bool isOpenGLClipping = ( bool )vals[1].toInt();
7063                     aPlane->IsOpenGLClipping = isOpenGLClipping;
7064                     if ( aMode == SMESH::Absolute ) {
7065                       aPlane->myAbsoluteOrientation = vals[2].toInt();
7066                       aPlane->X = vals[3].toFloat();
7067                       aPlane->Y = vals[4].toFloat();
7068                       aPlane->Z = vals[5].toFloat();
7069                       aPlane->Dx = vals[6].toFloat();
7070                       aPlane->Dy = vals[7].toFloat();
7071                       aPlane->Dz = vals[8].toFloat();
7072                     }
7073                     else if ( aMode == SMESH::Relative ) {
7074                       aPlane->myRelativeOrientation = (SMESH::Orientation)vals[2].toInt();
7075                       aPlane->myDistance = vals[3].toFloat();
7076                       aPlane->myAngle[0] = vals[4].toFloat();
7077                       aPlane->myAngle[1] = vals[5].toFloat();
7078                     }
7079
7080                     if( aPlane ) {
7081                       if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
7082                         SMESH::ClippingPlaneInfo aClippingPlaneInfo;
7083                         aClippingPlaneInfo.Plane = aPlane;
7084                         aClippingPlaneInfo.ActorList = anActorList;
7085                         aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
7086                       }
7087                     }
7088                   }
7089                 }
7090               }
7091               else {
7092                 bool ok = false;
7093                 int aPlaneId = val.toInt( &ok );
7094                 if( ok && aPlaneId >= 0 ) {
7095                   bool anIsDefinedPlane = false;
7096                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
7097                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
7098                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
7099                     TPlaneInfo& aPlaneInfo = *anIter;
7100                     if( aPlaneInfo.PlaneId == aPlaneId ) {
7101                       aPlaneInfo.ActorList.push_back( aSmeshActor );
7102                       anIsDefinedPlane = true;
7103                       break;
7104                     }
7105                   }
7106                   if( !anIsDefinedPlane ) {
7107                     TPlaneInfo aPlaneInfo;
7108                     aPlaneInfo.PlaneId = aPlaneId;
7109                     aPlaneInfo.ActorList.push_back( aSmeshActor );
7110                     aPlaneInfo.ViewManager = vman;
7111
7112                     // to make the list sorted by plane id
7113                     anIter = aPlaneInfoList.begin();
7114                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
7115                       const TPlaneInfo& aPlaneInfoRef = *anIter;
7116                       if( aPlaneInfoRef.PlaneId > aPlaneId )
7117                         break;
7118                     }
7119                     aPlaneInfoList.insert( anIter, aPlaneInfo );
7120                   }
7121                 }
7122               }
7123             }
7124           } // if (aSmeshActor)
7125         } // other parameters than Visibility
7126       }
7127     } // for names/parameters iterator
7128   } // for entries iterator
7129
7130   // take into account planes with empty list of actors referred to them
7131   QList<SUIT_ViewManager*> aVMList;
7132   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
7133
7134   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
7135   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
7136     int aViewId = aPlaneDataIter->first;
7137     if( aViewId >= 0 && aViewId < aVMList.count() ) {
7138       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
7139
7140       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
7141
7142       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
7143       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
7144       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
7145         const TPlaneData& aPlaneData = *anIter2;
7146         int aPlaneId = aPlaneData.Id;
7147
7148         bool anIsFound = false;
7149         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
7150         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
7151           const TPlaneInfo& aPlaneInfo = *anIter3;
7152           if( aPlaneInfo.PlaneId == aPlaneId ) {
7153             anIsFound = true;
7154             break;
7155           }
7156         }
7157
7158         if( !anIsFound ) {
7159           TPlaneInfo aPlaneInfo; // ActorList field is empty
7160           aPlaneInfo.PlaneId = aPlaneId;
7161           aPlaneInfo.ViewManager = aViewManager;
7162
7163           // to make the list sorted by plane id
7164           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
7165           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
7166             const TPlaneInfo& aPlaneInfoRef = *anIter4;
7167             if( aPlaneInfoRef.PlaneId > aPlaneId )
7168               break;
7169           }
7170           aPlaneInfoList.insert( anIter4, aPlaneInfo );
7171         }
7172       }
7173     }
7174   }
7175
7176   // add clipping planes to actors according to the restored parameters
7177   // and update the clipping plane map
7178   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
7179   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
7180     int aViewId = anIter1->first;
7181     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
7182
7183     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
7184     if( anIter2 == aPlaneDataMap.end() )
7185       continue;
7186     const TPlaneDataList& aPlaneDataList = anIter2->second;
7187
7188     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
7189     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
7190       const TPlaneInfo& aPlaneInfo = *anIter3;
7191       int aPlaneId = aPlaneInfo.PlaneId;
7192       const TActorList& anActorList = aPlaneInfo.ActorList;
7193       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
7194       if( !aViewManager )
7195         continue;
7196
7197       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
7198       if( !aViewWindow )
7199         continue;
7200
7201       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
7202
7203       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
7204       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
7205         const TPlaneData& aPlaneData = *anIter4;
7206         if( aPlaneData.Id == aPlaneId ) {
7207           SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( aViewWindow );
7208           aPlane->myViewWindow = aViewWindow;
7209           aPlane->PlaneMode = (SMESH::Mode)aPlaneData.Mode;
7210           aPlane->IsOpenGLClipping = aPlaneData.isOpenGLClipping;
7211           if ( aPlane->PlaneMode == SMESH::Absolute ) {
7212             aPlane->myAbsoluteOrientation = aPlaneData.AbsoluteOrientation;
7213             aPlane->X = aPlaneData.X;
7214             aPlane->Y = aPlaneData.Y;
7215             aPlane->Z = aPlaneData.Z;
7216             aPlane->Dx = aPlaneData.Dx;
7217             aPlane->Dy = aPlaneData.Dy;
7218             aPlane->Dz = aPlaneData.Dz;
7219           }
7220           else if ( aPlane->PlaneMode == SMESH::Relative ) {
7221             aPlane->myRelativeOrientation = (SMESH::Orientation)aPlaneData.RelativeOrientation;
7222             aPlane->myDistance = aPlaneData.Distance;
7223             aPlane->myAngle[0] = aPlaneData.Angle[0];
7224             aPlane->myAngle[1] = aPlaneData.Angle[1];
7225           }
7226           if( aPlane ) {
7227             if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
7228               SMESH::ClippingPlaneInfo aClippingPlaneInfo;
7229               aClippingPlaneInfo.Plane = aPlane;
7230               aClippingPlaneInfo.ActorList = anActorList;
7231               aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
7232             }
7233           }
7234           break;
7235         }
7236       }
7237
7238     }
7239   }
7240
7241
7242   // update all VTK views
7243   QList<SUIT_ViewManager*> lst;
7244   getApp()->viewManagers(lst);
7245   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
7246     SUIT_ViewModel* vmodel = (*it)->getViewModel();
7247     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
7248       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
7249       // set OpenGL clipping planes
7250       VTK::ActorCollectionCopy aCopy( vtkView->getRenderer()->GetActors() );
7251       vtkActorCollection* anAllActors = aCopy.GetActors();
7252       anAllActors->InitTraversal();
7253       while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
7254         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
7255           anActor->SetOpenGLClippingPlane();
7256
7257       vtkView->getRenderer()->ResetCameraClippingRange();
7258       vtkView->Repaint();
7259     }
7260   }
7261 }
7262
7263 /*!
7264   \brief Adds preferences for dfont of VTK viewer
7265   \param label label
7266   \param pIf group identifier
7267   \param param parameter
7268   \return identifier of preferences
7269 */
7270 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
7271 {
7272   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
7273
7274   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
7275
7276   QStringList fam;
7277   fam.append( tr( "SMESH_FONT_ARIAL" ) );
7278   fam.append( tr( "SMESH_FONT_COURIER" ) );
7279   fam.append( tr( "SMESH_FONT_TIMES" ) );
7280
7281   setPreferenceProperty( tfont, "fonts", fam );
7282
7283   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
7284   if ( needSize ) f = f | QtxFontEdit::Size;
7285   setPreferenceProperty( tfont, "features", f );
7286
7287   return tfont;
7288 }
7289
7290 /*!
7291   \brief Actions after hypothesis edition
7292   Updates object browser after hypothesis edition
7293 */
7294 void SMESHGUI::onHypothesisEdit( int result )
7295 {
7296   if( result == 1 )
7297     SMESHGUI::Modified();
7298   updateObjBrowser( true );
7299 }
7300
7301 /*!
7302   \brief Actions after choosing menu of control modes
7303   Updates control mode actions according to current selection
7304 */
7305 void SMESHGUI::onUpdateControlActions()
7306 {
7307   SALOME_ListIO selected;
7308   if ( LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr() )
7309     aSel->selectedObjects( selected );
7310
7311   SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
7312   if ( selected.Extent() ) {
7313     if ( selected.First()->hasEntry() ) {
7314       if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( selected.First()->getEntry() )) {
7315         aControl = anActor->GetControlMode();
7316         SALOME_ListIteratorOfListIO it(selected);
7317         for ( it.Next(); it.More(); it.Next() ) {
7318           Handle(SALOME_InteractiveObject) anIO = it.Value();
7319           if ( anIO->hasEntry() ) {
7320             if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
7321               if ( aControl != anActor->GetControlMode() ) {
7322                 aControl = SMESH_Actor::eNone;
7323                 break;
7324               }
7325             }
7326           }
7327         }
7328       }
7329     }
7330   }
7331
7332   int anAction = ActionToControl( aControl, true );
7333   if ( anAction)
7334     action( anAction )->setChecked( true );
7335   else {
7336     QMenu* send = (QMenu*)sender();
7337     QList<QAction*> actions = send->actions();
7338     for ( int i = 0; i < actions.size(); i++ )
7339       actions[i]->setChecked( false );
7340   }
7341 }
7342
7343
7344 /*!
7345   \brief Signal handler closing(SUIT_ViewWindow*) of a view
7346   \param pview view being closed
7347 */
7348 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
7349 #ifndef DISABLE_PLOT2DVIEWER
7350   //Crear all Plot2d Viewers if need.
7351   SMESH::ClearPlot2Viewers(pview);
7352 #endif
7353   EmitSignalCloseView();
7354 }
7355
7356 void SMESHGUI::message( const QString& msg )
7357 {
7358   // dispatch message
7359   QStringList data = msg.split("/");
7360   if ( data.count() > 0 ) {
7361     if ( data.first() == "mesh_loading" ) {
7362       // get mesh entry
7363       QString entry = data.count() > 1 ? data[1] : QString();
7364       if ( entry.isEmpty() )
7365         return;
7366       // get study
7367       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
7368       // get mesh name
7369       _PTR(SObject) obj = study->FindObjectID( entry.toUtf8().constData() );
7370       QString name;
7371       if ( obj )
7372         name = SMESH::fromUtf8(obj->GetName());
7373       if ( name.isEmpty() )
7374         return;
7375
7376       if ( data.last() == "stop" )
7377         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
7378       else
7379         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
7380       QApplication::processEvents();
7381     }
7382   }
7383 }
7384
7385 /*!
7386   \brief Connects or disconnects signals about activating and cloning view on the module slots
7387   \param pview view which is connected/disconnected
7388 */
7389 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
7390   if(!pview)
7391     return;
7392
7393   SUIT_ViewManager* viewMgr = pview->getViewManager();
7394   if ( viewMgr ) {
7395     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7396                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7397
7398     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7399              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7400   }
7401 }
7402
7403 /*!
7404   \brief Return \c true if object can be renamed
7405 */
7406 bool SMESHGUI::renameAllowed( const QString& entry) const {
7407   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7408   if( !anApp )
7409     return false;
7410
7411   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7412   if( !appStudy )
7413     return false;
7414
7415   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
7416
7417   if(!obj)
7418     return false;
7419
7420   if(appStudy->isComponent(entry) || obj->isReference())
7421     return false;
7422
7423   // check type to prevent renaming of inappropriate objects
7424   int aType = SMESHGUI_Selection::type(qPrintable(entry));
7425   if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7426       aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7427       aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7428       aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7429       aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
7430     return true;
7431
7432   return false;
7433 }
7434
7435 /*!
7436   Rename object by entry.
7437   \param entry entry of the object
7438   \param name new name of the object
7439   \brief Return \c true if rename operation finished successfully, \c false otherwise.
7440 */
7441 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
7442
7443   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7444   if( !anApp )
7445     return false;
7446
7447   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7448
7449   if(!appStudy)
7450     return false;
7451
7452   _PTR(Study) aStudy = appStudy->studyDS();
7453
7454   if(!aStudy)
7455     return false;
7456
7457   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
7458   if ( aLocked ) {
7459     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
7460     return false;
7461   }
7462
7463
7464   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
7465   _PTR(GenericAttribute) anAttr;
7466   _PTR(AttributeName) aName;
7467   if ( obj ) {
7468     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
7469       aName = anAttr;
7470       // check type to prevent renaming of inappropriate objects
7471       int aType = SMESHGUI_Selection::type( qPrintable(entry));
7472       if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7473           aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7474           aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7475           aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7476           aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
7477         if ( !name.isEmpty() ) {
7478           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qUtf8Printable(name) );
7479
7480           // update name of group object and its actor
7481           Handle(SALOME_InteractiveObject) IObject =
7482             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
7483
7484           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
7485           if( !aGroupObject->_is_nil() ) {
7486             aGroupObject->SetName( qUtf8Printable(name) );
7487             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
7488               anActor->setName( qUtf8Printable(name) );
7489           }
7490           return true;
7491         }
7492       }
7493     }
7494   }
7495   return false;
7496 }
7497
7498 SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
7499 {
7500   static QList<QColor> colors;
7501
7502   if ( colors.isEmpty() ) {
7503
7504     for (int s = 0; s < 2 ; s++)
7505     {
7506       for (int v = 100; v >= 40; v = v - 20)
7507       {
7508         for (int h = 0; h < 359 ; h = h + 60)
7509         {
7510           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
7511         }
7512       }
7513     }
7514   }
7515   static int currentColor = randomize( colors.size() );
7516
7517   SALOMEDS::Color color;
7518   color.R = (double)colors[currentColor].red()   / 255.0;
7519   color.G = (double)colors[currentColor].green() / 255.0;
7520   color.B = (double)colors[currentColor].blue()  / 255.0;
7521
7522   currentColor = (currentColor+1) % colors.count();
7523
7524   return color;
7525 }