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