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