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