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