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