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