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