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