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