Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2012  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.
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 //  SMESH includes
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_AddMeshElementDlg.h"
33 #include "SMESHGUI_AddQuadraticElementDlg.h"
34 #include "SMESHGUI_BuildCompoundDlg.h"
35 #include "SMESHGUI_ClippingDlg.h"
36 #include "SMESHGUI_ComputeDlg.h"
37 #include "SMESHGUI_ConvToQuadOp.h"
38 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
39 #include "SMESHGUI_DeleteGroupDlg.h"
40 #include "SMESHGUI_Displayer.h"
41 #include "SMESHGUI_MergeDlg.h"
42 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
43 #include "SMESHGUI_ExtrusionDlg.h"
44 #include "SMESHGUI_FileInfoDlg.h"
45 #include "SMESHGUI_FileValidator.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_FindElemByPointDlg.h"
49 #include "SMESHGUI_GroupDlg.h"
50 #include "SMESHGUI_GroupOnShapeDlg.h"
51 #include "SMESHGUI_GroupOpDlg.h"
52 #include "SMESHGUI_Hypotheses.h"
53 #include "SMESHGUI_Make2DFrom3DOp.h"
54 #include "SMESHGUI_MakeNodeAtPointDlg.h"
55 #include "SMESHGUI_Measurements.h"
56 #include "SMESHGUI_MeshInfo.h"
57 #include "SMESHGUI_MeshOp.h"
58 #include "SMESHGUI_MeshOrderOp.h"
59 #include "SMESHGUI_MeshPatternDlg.h"
60 #include "SMESHGUI_MultiEditDlg.h"
61 #include "SMESHGUI_NodesDlg.h"
62 #include "SMESHGUI_Preferences_ColorDlg.h"
63 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
64 #include "SMESHGUI_RemoveElementsDlg.h"
65 #include "SMESHGUI_RemoveNodesDlg.h"
66 #include "SMESHGUI_RenumberingDlg.h"
67 #include "SMESHGUI_RevolutionDlg.h"
68 #include "SMESHGUI_RotationDlg.h"
69 #include "SMESHGUI_Selection.h"
70 #include "SMESHGUI_SewingDlg.h"
71 #include "SMESHGUI_SingleEditDlg.h"
72 #include "SMESHGUI_SmoothingDlg.h"
73 #include "SMESHGUI_SymmetryDlg.h"
74 #include "SMESHGUI_TranslationDlg.h"
75 #include "SMESHGUI_ScaleDlg.h"
76 #include "SMESHGUI_TransparencyDlg.h"
77 #include "SMESHGUI_DuplicateNodesDlg.h"
78 #include "SMESHGUI_CopyMeshDlg.h"
79
80 #include "SMESHGUI_Utils.h"
81 #include "SMESHGUI_MeshUtils.h"
82 #include "SMESHGUI_GroupUtils.h"
83 #include "SMESHGUI_FilterUtils.h"
84 #include "SMESHGUI_PatternUtils.h"
85 #include "SMESHGUI_VTKUtils.h"
86 #include "SMESHGUI_HypothesesUtils.h"
87
88 #include <SMESH_version.h>
89
90 #include <SMESH_Client.hxx>
91 #include <SMESH_Actor.h>
92 #include <SMESH_ScalarBarActor.h>
93 #include <SMESH_ActorUtils.h>
94 #include <SMESH_TypeFilter.hxx>
95 #include "SMESH_ControlsDef.hxx"
96
97 // SALOME GUI includes
98 #include <SalomeApp_Tools.h>
99 #include <SalomeApp_Study.h>
100 #include <SalomeApp_Application.h>
101 #include <SalomeApp_CheckFileDlg.h>
102 #include <SalomeApp_DataObject.h>
103
104 #include <LightApp_DataOwner.h>
105 #include <LightApp_Preferences.h>
106 #include <LightApp_SelectionMgr.h>
107 #include <LightApp_UpdateFlags.h>
108 #include <LightApp_NameDlg.h>
109
110 #include <SVTK_ViewWindow.h>
111 #include <SVTK_ViewModel.h>
112 #include <SVTK_ViewManager.h>
113
114 #include <VTKViewer_Algorithm.h>
115
116 #include <SUIT_MessageBox.h>
117 #include <SUIT_ResourceMgr.h>
118 #include <SUIT_FileDlg.h>
119 #include <SUIT_Desktop.h>
120 #include <SUIT_OverrideCursor.h>
121 #include <SUIT_Session.h>
122
123 #include <QtxPopupMgr.h>
124 #include <QtxFontEdit.h>
125
126 #include <SALOME_ListIO.hxx>
127 #include <SALOME_ListIteratorOfListIO.hxx>
128
129 #ifndef DISABLE_PLOT2DVIEWER
130 #include <SPlot2d_ViewModel.h>
131 #include <SPlot2d_Histogram.h>
132 #endif
133
134 // IDL includes
135 #include <SALOMEconfig.h>
136 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
137 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
138 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
139
140 // Qt includes
141 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
142 #include <QApplication>
143 #include <QMenu>
144 #include <QTextStream>
145
146 // BOOST includes
147 #include <boost/shared_ptr.hpp>
148
149 // VTK includes
150 #include <vtkCamera.h>
151 #include <vtkRenderer.h>
152 #include <vtkPlane.h>
153 #include <vtkCallbackCommand.h>
154 #include <vtkLookupTable.h>
155
156 // SALOME KERNEL includes
157 #include <SALOMEDS_Study.hxx>
158 #include <SALOMEDSClient_StudyBuilder.hxx>
159 #include <SALOMEDSClient_SComponent.hxx>
160 #include <SALOMEDSClient_ClientFactory.hxx>
161 #include <SALOMEDSClient_IParameters.hxx>
162
163 // OCCT includes
164 #include <Standard_ErrorHandler.hxx>
165 #include <NCollection_DataMap.hxx>
166
167 //To disable automatic genericobj management, the following line should be commented.
168 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
169 #define WITHGENERICOBJ
170
171 //namespace{
172   // Declarations
173   //=============================================================
174   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
175                             int theCommandID);
176
177   void ExportMeshToFile(int theCommandID);
178
179   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
180
181   void SetDisplayEntity(int theCommandID);
182
183   void Control( int theCommandID );
184
185
186   // Definitions
187   //=============================================================
188   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
189                              int theCommandID )
190   {
191     QStringList filter;
192     std::string myExtension;
193
194     if ( theCommandID == 113 ) {
195       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.med)" );
196       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
197     }
198     else if ( theCommandID == 112 ) {
199       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
200     }
201     else if ( theCommandID == 111 ) {
202       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
203     }
204     else if ( theCommandID == 115 ) {
205       filter.append( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
206     }
207     else if ( theCommandID == 116 ) {
208       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
209     }
210     else if ( theCommandID == 117 ) {
211       filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
212       filter.append( QObject::tr( "All files (*)" ) );
213     }
214
215     QString anInitialPath = "";
216     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
217       anInitialPath = QDir::currentPath();
218
219     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
220                                                             anInitialPath,
221                                                             filter,
222                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
223     if ( filenames.count() > 0 ) {
224       SUIT_OverrideCursor wc;
225       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
226
227       QStringList errors;
228       QStringList anEntryList;
229       bool isEmpty = false;
230       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
231         QString filename = *it;
232         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
233         try {
234           switch ( theCommandID ) {
235           case 111:
236             {
237               // DAT format (currently unsupported)
238               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
239                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
240               break;
241             }
242           case 112:
243             {
244               // UNV format
245               aMeshes->length( 1 );
246               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toLatin1().constData() );
247               if ( aMeshes[0]->_is_nil() )
248                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
249                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
250               break;
251             }
252           case 113:
253             {
254               // MED format
255               SMESH::DriverMED_ReadStatus res;
256               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toLatin1().constData(), res );
257               if ( res != SMESH::DRS_OK ) {
258                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
259                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
260               }
261               break;
262             }
263           case 115:
264             {
265               // STL format
266               aMeshes->length( 1 );
267               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toLatin1().constData() );
268               if ( aMeshes[0]->_is_nil() ) {
269                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
270                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
271               }
272               break;
273             }
274           case 116:
275             {
276               // CGNS format
277               SMESH::DriverMED_ReadStatus res;
278               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toLatin1().constData(), res );
279               if ( res != SMESH::DRS_OK ) {
280                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
281                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
282               }
283               break;
284             }
285           case 117:
286             {
287               // SAUV format
288               SMESH::DriverMED_ReadStatus res;
289               aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toLatin1().constData(), res );
290               if ( res != SMESH::DRS_OK ) {
291                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
292                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
293               }
294               break;
295             }
296           }
297         }
298         catch ( const SALOME::SALOME_Exception& S_ex ) {
299           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
300                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
301         }
302
303         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
304           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
305           if ( aMeshSO ) {
306             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
307             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
308             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
309             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
310               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
311
312             anEntryList.append( aMeshSO->GetID().c_str() );
313
314 #ifdef WITHGENERICOBJ
315             // obj has been published in study. Its refcount has been incremented.
316             // It is safe to decrement its refcount
317             // so that it will be destroyed when the entry in study will be removed
318             aMeshes[i]->UnRegister();
319 #endif
320           }
321           else {
322             isEmpty = true;
323           }
324         }
325       }
326
327       // update Object browser
328       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
329
330       // browse to the published meshes
331       if( LightApp_Application* anApp =
332           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
333         anApp->browseObjects( anEntryList );
334
335       // show Error message box if there were errors
336       if ( errors.count() > 0 ) {
337         SUIT_MessageBox::critical( SMESHGUI::desktop(),
338                                    QObject::tr( "SMESH_ERROR" ),
339                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
340       }
341
342       // show warning message box, if some imported mesh is empty
343       if ( isEmpty ) {
344           SUIT_MessageBox::warning( SMESHGUI::desktop(),
345                                     QObject::tr( "SMESH_WRN_WARNING" ),
346                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
347       }
348     }
349   }
350
351   //================================================================================
352   /*!
353    * \brief Export selected meshes or groups into a file
354    */
355   //================================================================================
356
357   void ExportMeshToFile( int theCommandID )
358   {
359     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
360     SALOME_ListIO selected;
361     if( aSel )
362       aSel->selectedObjects( selected );
363
364     const bool isMED = ( theCommandID == 122 || theCommandID == 125 );
365     const bool isDAT = ( theCommandID == 121 || theCommandID == 124 );
366     const bool isUNV = ( theCommandID == 123 || theCommandID == 126 );
367     const bool isSTL = ( theCommandID == 140 || theCommandID == 141 );
368     const bool isCGNS= ( theCommandID == 142 || theCommandID == 143 );
369     const bool isSAUV= ( theCommandID == 144 || theCommandID == 145 );
370
371     // actually, the following condition can't be met (added for insurance)
372     if( selected.Extent() == 0 ||
373         ( selected.Extent() > 1 && !isMED && !isSTL ))
374       return;
375
376     // get mesh object from selection and check duplication of their names
377     bool hasDuplicatedMeshNames = false;
378     QList< QPair< SMESH::SMESH_IDSource_var, QString > > aMeshList;
379     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
380     SALOME_ListIteratorOfListIO It( selected );
381     for( ; It.More(); It.Next() )
382     {
383       Handle(SALOME_InteractiveObject) anIObject = It.Value();
384       SMESH::SMESH_IDSource_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
385       if ( aMeshItem->_is_nil() ) {
386         SUIT_MessageBox::warning( SMESHGUI::desktop(),
387                                   QObject::tr( "SMESH_WRN_WARNING" ),
388                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
389         return;
390       }
391
392       QString aMeshName = anIObject->getName();
393
394       // check for name duplications
395       if ( !hasDuplicatedMeshNames )
396         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
397           if( aMeshName == (*aMeshIter).second ) {
398             hasDuplicatedMeshNames = true;
399             break;
400           }
401         }
402
403       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
404     }
405
406     if( hasDuplicatedMeshNames && isMED ) {
407       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
408                                           QObject::tr("SMESH_WRN_WARNING"),
409                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
410                                           QObject::tr("SMESH_BUT_YES"),
411                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
412       if (aRet != 0)
413         return;
414     }
415
416     aMeshIter = aMeshList.begin();
417     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
418     SMESH::SMESH_Mesh_var aMesh = aMeshOrGroup->GetMesh();
419     QString aMeshName = (*aMeshIter).second;
420
421     if ( isMED || isCGNS || isSAUV )
422     {
423       // check for equal group names within each mesh
424       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
425         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
426         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
427           int aRet = SUIT_MessageBox::warning
428             (SMESHGUI::desktop(),
429              QObject::tr("SMESH_WRN_WARNING"),
430              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
431              QObject::tr("SMESH_BUT_YES"),
432              QObject::tr("SMESH_BUT_NO"), 0, 1);
433           if (aRet != 0)
434             return;
435         }
436       }
437     }
438     else if ( isUNV )
439     {
440       // warn the user about presence of not supported elements
441       SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
442       int nbNotSupported = ( nbElems[ SMESH::Entity_Pyramid ] +
443                              nbElems[ SMESH::Entity_Quad_Pyramid ] +
444                              nbElems[ SMESH::Entity_Hexagonal_Prism ] +
445                              nbElems[ SMESH::Entity_Polygon ] +
446                              nbElems[ SMESH::Entity_Polyhedra ] );
447       if ( nbNotSupported > 0 ) {
448         int aRet = SUIT_MessageBox::warning
449           (SMESHGUI::desktop(),
450            QObject::tr("SMESH_WRN_WARNING"),
451            QObject::tr("SMESH_EXPORT_UNV").arg(aMeshName),
452            QObject::tr("SMESH_BUT_YES"),
453            QObject::tr("SMESH_BUT_NO"), 0, 1);
454         if (aRet != 0)
455           return;
456       }
457     }
458
459     // Get parameters of export operation
460
461     QString aFilename;
462     SMESH::MED_VERSION aFormat;
463     // Init the parameters with the default values
464     bool aIsASCII_STL = true;
465     bool toCreateGroups = false;
466     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
467     if ( resMgr )
468       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
469     bool toOverwrite = true;
470
471     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
472     QString anInitialPath = "";
473     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
474       anInitialPath = QDir::currentPath();
475
476     if ( isUNV || isDAT )
477     {
478       if ( isUNV )
479         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
480       else
481         aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
482       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
483       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
484                                             anInitialPath + QString("/") + aMeshName,
485                                             aFilter, aTitle, false);
486     }
487     else if ( isCGNS )// Export to CGNS
488     {
489       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
490       fd->setWindowTitle( aTitle );
491       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
492       if ( !anInitialPath.isEmpty() )
493         fd->setDirectory( anInitialPath );
494       fd->selectFile(aMeshName);
495       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
496       fd->setValidator( fv );
497
498       if ( fd->exec() )
499         aFilename = fd->selectedFile();
500       toOverwrite = fv->isOverwrite();
501
502       delete fd;
503     }
504     else if ( isSTL ) // Export to STL
505     {
506       QMap<QString, int> aFilterMap;
507       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
508       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
509
510       QStringList filters;
511       QMap<QString, int>::const_iterator it = aFilterMap.begin();
512       for ( ; it != aFilterMap.end(); ++it )
513         filters.push_back( it.key() );
514
515       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
516       fd->setWindowTitle( aTitle );
517       fd->setNameFilters( filters );
518       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
519       if ( !anInitialPath.isEmpty() )
520         fd->setDirectory( anInitialPath );
521       fd->selectFile(aMeshName);
522       bool is_ok = false;
523       while (!is_ok) {
524         if ( fd->exec() )
525           aFilename = fd->selectedFile();
526         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
527         is_ok = true;
528       }
529       delete fd;
530     }
531     else if ( isMED || isSAUV ) // Export to MED or SAUV
532     {
533       QMap<QString, SMESH::MED_VERSION> aFilterMap;
534       //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
535       if ( isMED ) {
536         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
537         //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
538         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
539       }
540       else { // isSAUV
541         aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
542         aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
543         aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
544       }
545
546       QStringList filters;
547       QString aDefaultFilter;
548       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
549       for ( ; it != aFilterMap.end(); ++it ) {
550         filters.push_back( it.key() );
551         if (it.value() == SMESH::MED_V2_2)
552           aDefaultFilter = it.key();
553       }
554
555       SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
556         ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
557       fd->setWindowTitle( aTitle );
558       fd->setNameFilters( filters );
559       fd->selectNameFilter(aDefaultFilter);
560       fd->SetChecked(toCreateGroups);
561       if ( !anInitialPath.isEmpty() )
562         fd->setDirectory( anInitialPath );
563       fd->selectFile(aMeshName);
564
565       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
566       fd->setValidator( fv );
567
568       bool is_ok = false;
569       while (!is_ok) {
570         if ( fd->exec() )
571           aFilename = fd->selectedFile();
572         else {
573           aFilename = QString::null;
574           break;
575         }
576         aFormat = aFilterMap[fd->selectedNameFilter()];
577         toOverwrite = fv->isOverwrite();
578         is_ok = true;
579         if ( !aFilename.isEmpty() ) {
580           // med-2.1 does not support poly elements
581           if ( aFormat==SMESH::MED_V2_1 )
582             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
583               SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
584               SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
585               if ( nbElems[ SMESH::Entity_Polygon   ] + nbElems[ SMESH::Entity_Quad_Polygon   ] +
586                    nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
587               {
588                 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
589                                                     QObject::tr("SMESH_WRN_WARNING"),
590                                                     QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
591                                                     QObject::tr("SMESH_BUT_YES"),
592                                                     QObject::tr("SMESH_BUT_NO"), 0, 1);
593                 if (aRet != 0) {
594                   is_ok = false;
595                   break;
596                 }
597               }
598             }
599           if( !toOverwrite ) {
600             // can't append to an existing using other format
601             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
602             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
603             if( !isVersionOk || aVersion != aFormat ) {
604               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
605                                                   QObject::tr("SMESH_WRN_WARNING"),
606                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
607                                                   QObject::tr("SMESH_BUT_YES"),
608                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
609               if (aRet == 0)
610                 toOverwrite = true;
611               else
612                 is_ok = false;
613             }
614
615             QStringList aMeshNamesCollisionList;
616             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
617             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
618               QString anExistingMeshName( aMeshNames[ i ] );
619               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
620                 QString anExportMeshName = (*aMeshIter).second;
621                 if( anExportMeshName == anExistingMeshName ) {
622                   aMeshNamesCollisionList.append( anExportMeshName );
623                   break;
624                 }
625               }
626             }
627             if( !aMeshNamesCollisionList.isEmpty() ) {
628               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
629               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
630                                                   QObject::tr("SMESH_WRN_WARNING"),
631                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
632                                                   QObject::tr("SMESH_BUT_YES"),
633                                                   QObject::tr("SMESH_BUT_NO"),
634                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
635               if (aRet == 0)
636                 toOverwrite = true;
637               else if (aRet == 2)
638                 is_ok = false;
639             }
640           }
641         }
642       }
643       toCreateGroups = fd->IsChecked();
644       delete fd;
645     }
646     else
647     {
648       return;
649     }
650
651     // Perform export
652
653     if ( !aFilename.isEmpty() ) {
654       // Check whether the file already exists and delete it if yes
655       QFile aFile( aFilename );
656       if ( aFile.exists() && toOverwrite )
657         aFile.remove();
658       SUIT_OverrideCursor wc;
659
660       try {
661         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
662 //         bool Renumber = false;
663 //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
664 //         if (resMgr)
665 //           Renumber= resMgr->booleanValue("SMESH","renumbering");
666 //         if (Renumber){
667 //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
668 //           aMeshEditor->RenumberNodes();
669 //           aMeshEditor->RenumberElements();
670 //           if ( SMESHGUI::automaticUpdate() )
671 //             SMESH::UpdateView();
672 //         }
673         if ( isMED )
674         {
675           aMeshIter = aMeshList.begin();
676           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
677           {
678             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
679             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
680             if ( aMeshOrGroup->_is_equivalent( aMeshItem ))
681               aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups,
682                                        aFormat, toOverwrite && aMeshIndex == 0 );
683             else
684               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toLatin1().data(), toCreateGroups,
685                                           aFormat, toOverwrite && aMeshIndex == 0 );
686           }
687         }
688         else if ( isSAUV )
689         {
690           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
691           {
692             SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
693             if( !aMeshItem->_is_nil() )
694               aMeshItem->ExportSAUV( aFilename.toLatin1().data(), toCreateGroups );
695           }
696         }
697         else if ( isDAT )
698         {
699           if ( aMeshOrGroup->_is_equivalent( aMesh ))
700             aMesh->ExportDAT( aFilename.toLatin1().data() );
701           else
702             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toLatin1().data() );
703         }
704         else if ( isUNV )
705         {
706           if ( aMeshOrGroup->_is_equivalent( aMesh ))
707             aMesh->ExportUNV( aFilename.toLatin1().data() );
708           else
709             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toLatin1().data() );
710         }
711         else if ( isSTL )
712         {
713           if ( aMeshOrGroup->_is_equivalent( aMesh ))
714             aMesh->ExportSTL( aFilename.toLatin1().data(), aIsASCII_STL );
715           else
716             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toLatin1().data(), aIsASCII_STL );
717         }
718         else if ( isCGNS )
719         {
720           aMeshIter = aMeshList.begin();
721           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
722           {
723             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
724             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
725             aMeshItem->ExportCGNS( aMeshOrGroup,
726                                    aFilename.toLatin1().data(),
727                                    toOverwrite && aMeshIndex == 0 );
728           }
729         }
730       }
731       catch (const SALOME::SALOME_Exception& S_ex){
732         wc.suspend();
733         SUIT_MessageBox::warning(SMESHGUI::desktop(),
734                                  QObject::tr("SMESH_WRN_WARNING"),
735                                  QObject::tr("SMESH_EXPORT_FAILED"));
736         wc.resume();
737       }
738     }
739   }
740
741   inline void InverseEntityMode(unsigned int& theOutputMode,
742                                 unsigned int theMode)
743   {
744     bool anIsNotPresent = ~theOutputMode & theMode;
745     if(anIsNotPresent)
746       theOutputMode |= theMode;
747     else
748       theOutputMode &= ~theMode;
749   }
750
751   void SetDisplayEntity(int theCommandID){
752     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
753     SALOME_ListIO selected;
754     if( aSel )
755       aSel->selectedObjects( selected );
756
757     if(selected.Extent() >= 1){
758       SALOME_ListIteratorOfListIO It( selected );
759       for( ; It.More(); It.Next()){
760         Handle(SALOME_InteractiveObject) IObject = It.Value();
761         if(IObject->hasEntry()){
762           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
763             unsigned int aMode = anActor->GetEntityMode();
764             switch(theCommandID){
765             case 216:
766               InverseEntityMode(aMode,SMESH_Actor::e0DElements);
767               break;
768             case 217:
769               InverseEntityMode(aMode,SMESH_Actor::eEdges);
770               break;
771             case 218:
772               InverseEntityMode(aMode,SMESH_Actor::eFaces);
773               break;
774             case 219:
775               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
776               break;
777             case 220:
778               aMode = SMESH_Actor::eAllEntity;
779               break;
780             }
781             if(aMode)
782               anActor->SetEntityMode(aMode);
783           }
784         }
785       }
786     }
787   }
788
789   void AutoColor(){
790     SALOME_ListIO selected;
791     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
792     if( !app )
793       return;
794
795     LightApp_SelectionMgr* aSel = app->selectionMgr();
796     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
797     if( !aSel || !appStudy )
798       return;
799
800     aSel->selectedObjects( selected );
801     if( selected.IsEmpty() )
802       return;
803
804     Handle(SALOME_InteractiveObject) anIObject = selected.First();
805
806     _PTR(Study) aStudy = appStudy->studyDS();
807     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
808     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
809     if( aMainObject->_is_nil() )
810       return;
811
812     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
813
814     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
815     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
816     {
817       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
818       SALOMEDS::Color aColor = aGroupObject->GetColor();
819       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
820       if (aGroupSObject) {
821         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
822           if( aGroupObject->GetType() == SMESH::NODE )
823             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
824           else if( aGroupObject->GetType() == SMESH::EDGE )
825             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
826           else if( aGroupObject->GetType() == SMESH::ELEM0D )
827             anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
828           else {
829             QColor c;
830             int delta;
831             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
832             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
833           }
834         }
835       }
836     }
837
838     SMESH::RepaintCurrentView();
839   }
840
841   QString functorToString( SMESH::Controls::FunctorPtr f )
842   {
843     QString type = QObject::tr( "UNKNOWN_CONTROL" );
844     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
845       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
846     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
847       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
848     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
849       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
850     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
851       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
852     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
853       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
854     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
855       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
856     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
857       type = QObject::tr( "WARP_ELEMENTS" );
858     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
859       type = QObject::tr( "TAPER_ELEMENTS" );
860     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
861       type = QObject::tr( "SKEW_ELEMENTS" );
862     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
863       type = QObject::tr( "AREA_ELEMENTS" );
864     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
865       type = QObject::tr( "LENGTH_EDGES" );
866     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
867       type = QObject::tr( "LENGTH2D_EDGES" );
868     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
869       type = QObject::tr( "MULTI_BORDERS" );
870     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
871       type = QObject::tr( "MULTI2D_BORDERS" );
872     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
873       type = QObject::tr( "FREE_NODES" );
874     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
875       type = QObject::tr( "FREE_EDGES" );
876     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
877       type = QObject::tr( "FREE_BORDERS" );
878     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
879       type = QObject::tr( "FREE_FACES" );
880     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
881       type = QObject::tr( "BARE_BORDER_VOLUME" );
882     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
883       type = QObject::tr( "BARE_BORDER_FACE" );
884     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
885       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
886     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
887       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
888     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
889       type = QObject::tr( "EQUAL_NODE" );
890     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
891       type = QObject::tr( "EQUAL_EDGE" );
892     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
893       type = QObject::tr( "EQUAL_FACE" );
894     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
895       type = QObject::tr( "EQUAL_VOLUME" );
896     return type;
897   }
898
899   void SaveDistribution()
900   {
901     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
902     SALOME_ListIO selected;
903     if ( aSel )
904       aSel->selectedObjects( selected );
905
906     if ( selected.Extent() == 1 ) {
907       Handle(SALOME_InteractiveObject) anIO = selected.First();
908       if ( anIO->hasEntry() ) {
909         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
910         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
911           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
912           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
913           if ( aScalarBarActor && aFunctor ) {
914             SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
915             if ( aNumFun ) {
916               std::vector<int> elements;
917               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
918               if ( mesh->_is_nil() ) {
919                 SMESH::SMESH_IDSource_var idSource =
920                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
921                 if ( !idSource->_is_nil() )
922                 {
923                   SMESH::long_array_var ids = idSource->GetIDs();
924                   elements.resize( ids->length() );
925                   for ( unsigned i = 0; i < elements.size(); ++i )
926                     elements[i] = ids[i];
927                 }
928               }
929               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
930               vtkLookupTable* lookupTable =
931                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
932               double * minmax = lookupTable->GetRange();
933               std::vector<int>    nbEvents;
934               std::vector<double> funValues;
935               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax );
936               QString anInitialPath = "";
937               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
938                 anInitialPath = QDir::currentPath();
939               QString aMeshName = anIO->getName();
940               QStringList filter;
941               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
942               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
943               QString aFilename = anInitialPath + "/" + aMeshName + "_" + 
944                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
945               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
946                                                      aFilename,
947                                                      filter,
948                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
949                                                      false );
950               if ( !aFilename.isEmpty() ) {
951                 QFile f( aFilename );
952                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
953                   QTextStream out( &f );
954                   out << "# Mesh: " << aMeshName << endl;
955                   out << "# Control: " << functorToString( aFunctor ) << endl;
956                   out << "#" << endl;
957                   out.setFieldWidth( 10 );
958                   for ( int i = 0; i < qMin( nbEvents.size(), funValues.size()-1 ); i++ )
959                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
960                   f.close();
961                 }
962               }
963             }
964           }
965         }
966       }
967     }
968   }
969
970   void ShowDistribution() {
971     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
972     SALOME_ListIO selected;
973     if ( aSel )
974       aSel->selectedObjects( selected );
975     
976     if ( selected.Extent() == 1 ) {
977       Handle(SALOME_InteractiveObject) anIO = selected.First();
978       if ( anIO->hasEntry() ) {
979         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
980         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
981           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
982           aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
983         }
984       }
985     }
986   }
987
988 #ifndef DISABLE_PLOT2DVIEWER
989  void PlotDistribution() {
990    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
991    if( !app )
992      return;
993
994    LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
995    SALOME_ListIO selected;
996    if ( aSel )
997      aSel->selectedObjects( selected );
998     
999    if ( selected.Extent() == 1 ) {
1000      Handle(SALOME_InteractiveObject) anIO = selected.First();
1001      if ( anIO->hasEntry() ) {
1002        //Find Actor by entry before getting Plot2d viewer,
1003        //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1004        SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1005
1006        SUIT_ViewManager* aViewManager = app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1007
1008        if( !aViewManager )
1009          return;
1010        
1011        SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1012        if ( !aView )
1013          return;
1014
1015        Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1016        if ( !aPlot )
1017          return;
1018
1019        if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1020          SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1021          QString functorName = functorToString( anActor->GetFunctor());
1022          QString aHistogramName("%1 : %2");
1023          aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1024          aHistogram->setName(aHistogramName);
1025          aHistogram->setHorTitle(functorName);
1026          aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1027          aPlot->displayObject(aHistogram, true);
1028        }
1029      }
1030    }
1031  }
1032 #endif //DISABLE_PLOT2DVIEWER
1033
1034   void DisableAutoColor(){
1035     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1036     SALOME_ListIO selected;
1037     if( aSel )
1038       aSel->selectedObjects( selected );
1039
1040     if(selected.Extent()){
1041       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1042       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1043       if ( !aMesh->_is_nil() ) {
1044         aMesh->SetAutoColor( false );
1045       }
1046     }
1047   }
1048
1049   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap){
1050     SALOME_ListIO selected;
1051     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1052     if( !app )
1053       return;
1054
1055     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1056     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1057     if( !aSel || !appStudy )
1058       return;
1059
1060     if( theCommandID == 1134 ) { // Clipping dialog can be activated without selection
1061       if( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1062         aModule->EmitSignalDeactivateDialog();
1063         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1064           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1065       }
1066       return;
1067     }
1068
1069     _PTR(Study) aStudy = appStudy->studyDS();
1070
1071     aSel->selectedObjects( selected );
1072
1073     if(selected.Extent() >= 1){
1074       switch(theCommandID){
1075       case 1133:{
1076         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1077         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1078         return;
1079       }
1080       case 1132:{
1081         QColor c, e, b, n, c0D, o, outl, selection, preselection;
1082         int delta;
1083         int size0D = 0;
1084         int Edgewidth = 0;
1085         vtkFloatingPointType Shrink = 0.0;
1086         vtkFloatingPointType faces_orientation_scale = 0.0;
1087         bool faces_orientation_3dvectors = false;
1088
1089         VTK::MarkerType aMarkerTypeCurrent = VTK::MT_NONE;
1090         VTK::MarkerScale aMarkerScaleCurrent = VTK::MS_NONE;
1091         int aMarkerTextureCurrent = 0;
1092
1093         SALOME_ListIteratorOfListIO It( selected );
1094         for( ; It.More(); It.Next()){
1095           Handle(SALOME_InteractiveObject) IObject = It.Value();
1096           if(IObject->hasEntry()){
1097             if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1098               vtkFloatingPointType color[3];
1099               anActor->GetSufaceColor(color[0], color[1], color[2],delta);
1100               int c0 = int (color[0] * 255);
1101               int c1 = int (color[1] * 255);
1102               int c2 = int (color[2] * 255);
1103               c.setRgb(c0, c1, c2);
1104
1105               vtkFloatingPointType edgecolor[3];
1106               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1107               c0 = int (edgecolor[0] * 255);
1108               c1 = int (edgecolor[1] * 255);
1109               c2 = int (edgecolor[2] * 255);
1110               e.setRgb(c0, c1, c2);
1111
1112               vtkFloatingPointType nodecolor[3];
1113               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1114               c0 = int (nodecolor[0] * 255);
1115               c1 = int (nodecolor[1] * 255);
1116               c2 = int (nodecolor[2] * 255);
1117               n.setRgb(c0, c1, c2);
1118
1119               vtkFloatingPointType color0D[3];
1120               anActor->Get0DColor(color0D[0], color0D[1], color0D[2]);
1121               c0 = int (color0D[0] * 255);
1122               c1 = int (color0D[1] * 255);
1123               c2 = int (color0D[2] * 255);
1124               c0D.setRgb(c0, c1, c2);
1125
1126               vtkFloatingPointType outlineColor[3];
1127               anActor->GetOutlineColor(outlineColor[0], outlineColor[1], outlineColor[2]);
1128               c0 = int (outlineColor[0] * 255);
1129               c1 = int (outlineColor[1] * 255);
1130               c2 = int (outlineColor[2] * 255);
1131               outl.setRgb(c0, c1, c2);
1132
1133               vtkFloatingPointType hColor[3];
1134               anActor->GetHighlightColor(hColor[0], hColor[1], hColor[2]);
1135               c0 = int (hColor[0] * 255);
1136               c1 = int (hColor[1] * 255);
1137               c2 = int (hColor[2] * 255);
1138               selection.setRgb(c0, c1, c2);
1139
1140               vtkFloatingPointType phColor[3];
1141               anActor->GetPreHighlightColor(phColor[0], phColor[1], phColor[2]);
1142               c0 = int (phColor[0] * 255);
1143               c1 = int (phColor[1] * 255);
1144               c2 = int (phColor[2] * 255);
1145               preselection.setRgb(c0, c1, c2);
1146
1147               size0D = (int)anActor->Get0DSize();
1148               if(size0D == 0)
1149                 size0D = 1;
1150               Edgewidth = (int)anActor->GetLineWidth();
1151               if(Edgewidth == 0)
1152                 Edgewidth = 1;
1153               Shrink = anActor->GetShrinkFactor();
1154
1155               vtkFloatingPointType faces_orientation_color[3];
1156               anActor->GetFacesOrientationColor(faces_orientation_color);
1157               c0 = int (faces_orientation_color[0] * 255);
1158               c1 = int (faces_orientation_color[1] * 255);
1159               c2 = int (faces_orientation_color[2] * 255);
1160               o.setRgb(c0, c1, c2);
1161
1162               faces_orientation_scale = anActor->GetFacesOrientationScale();
1163               faces_orientation_3dvectors = anActor->GetFacesOrientation3DVectors();
1164
1165               aMarkerTypeCurrent = anActor->GetMarkerType();
1166               aMarkerScaleCurrent = anActor->GetMarkerScale();
1167               aMarkerTextureCurrent = anActor->GetMarkerTexture();
1168
1169               // even if there are multiple objects in the selection,
1170               // we need only the first one to get values for the dialog
1171               break;
1172             }
1173           }
1174         }
1175
1176         SMESHGUI_Preferences_ColorDlg *aDlg =
1177           new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI() );
1178         aDlg->SetColor(1, c);
1179         aDlg->SetColor(2, e);
1180         aDlg->SetColor(3, n);
1181         aDlg->SetColor(4, outl);
1182         aDlg->SetDeltaBrightness(delta);
1183         aDlg->SetColor(5, c0D);
1184         aDlg->SetColor(6, o);
1185         aDlg->SetIntValue(1, Edgewidth);
1186         aDlg->SetIntValue(2, int(Shrink*100.));
1187         aDlg->SetIntValue(3, size0D);
1188         aDlg->SetDoubleValue(1, faces_orientation_scale);
1189         aDlg->SetBooleanValue(1, faces_orientation_3dvectors);
1190         aDlg->SetColor(7, selection);
1191         aDlg->SetColor(8, preselection);
1192  
1193         aDlg->setCustomMarkerMap( theMarkerMap[ aStudy->StudyId() ] );
1194
1195         if( aMarkerTypeCurrent != VTK::MT_USER )
1196           aDlg->setStandardMarker( aMarkerTypeCurrent, aMarkerScaleCurrent );
1197         else
1198           aDlg->setCustomMarker( aMarkerTextureCurrent );
1199
1200         if(aDlg->exec()){
1201           QColor color = aDlg->GetColor(1);
1202           QColor edgecolor = aDlg->GetColor(2);
1203           QColor nodecolor = aDlg->GetColor(3);
1204           QColor outlinecolor = aDlg->GetColor(4);
1205           QColor color0D = aDlg->GetColor(5);
1206           QColor faces_orientation_color = aDlg->GetColor(6);
1207           QColor selectioncolor = aDlg->GetColor(7);
1208           QColor preSelectioncolor = aDlg->GetColor(8);
1209           int delta = aDlg->GetDeltaBrightness();
1210
1211           /* Point marker */
1212           theMarkerMap[ aStudy->StudyId() ] = aDlg->getCustomMarkerMap();
1213
1214           SALOME_ListIteratorOfListIO It( selected );
1215           for( ; It.More(); It.Next()){
1216             Handle(SALOME_InteractiveObject) IObject = It.Value();
1217             if(IObject->hasEntry()){
1218               if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1219                 /* actor color and backface color */
1220                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
1221                                         vtkFloatingPointType (color.green()) / 255.,
1222                                         vtkFloatingPointType (color.blue()) / 255.,
1223                                         delta);
1224                 /* edge color */
1225                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
1226                                       vtkFloatingPointType (edgecolor.green()) / 255.,
1227                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
1228                 /* edge outline */
1229                 anActor->SetOutlineColor(vtkFloatingPointType (outlinecolor.red()) / 255.,
1230                                          vtkFloatingPointType (outlinecolor.green()) / 255.,
1231                                          vtkFloatingPointType (outlinecolor.blue()) / 255.);
1232
1233                 /* selection */
1234                 anActor->SetHighlightColor(vtkFloatingPointType (selectioncolor.red()) / 255.,
1235                                            vtkFloatingPointType (selectioncolor.green()) / 255.,
1236                                            vtkFloatingPointType (selectioncolor.blue()) / 255.);
1237                 /* pre-selection */
1238                 anActor->SetPreHighlightColor(vtkFloatingPointType (preSelectioncolor.red()) / 255.,
1239                                               vtkFloatingPointType (preSelectioncolor.green()) / 255.,
1240                                               vtkFloatingPointType (preSelectioncolor.blue()) / 255.);
1241                 
1242
1243                 /* Shrink factor and size edges */
1244                 anActor->SetShrinkFactor(aDlg->GetIntValue(2) / 100.);
1245                 anActor->SetLineWidth(aDlg->GetIntValue(1));
1246
1247                 /* Nodes color and size */
1248                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
1249                                       vtkFloatingPointType (nodecolor.green()) / 255.,
1250                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
1251
1252                 /* 0D elements */
1253                 anActor->Set0DColor(vtkFloatingPointType (color0D.red()) / 255.,
1254                                     vtkFloatingPointType (color0D.green()) / 255.,
1255                                     vtkFloatingPointType (color0D.blue()) / 255.);
1256                 anActor->Set0DSize(aDlg->GetIntValue(3));
1257
1258                 /* Faces orientation */
1259                 vtkFloatingPointType c[3] = {vtkFloatingPointType(faces_orientation_color.redF()),
1260                                              vtkFloatingPointType(faces_orientation_color.greenF()),
1261                                              vtkFloatingPointType(faces_orientation_color.blueF())};
1262                 anActor->SetFacesOrientationColor(c);
1263                 anActor->SetFacesOrientationScale(aDlg->GetDoubleValue(1));
1264                 anActor->SetFacesOrientation3DVectors(aDlg->GetBooleanValue(1));
1265
1266                 VTK::MarkerType aMarkerTypeNew = aDlg->getMarkerType();
1267                 VTK::MarkerScale aMarkerScaleNew = aDlg->getStandardMarkerScale();
1268                 int aMarkerTextureNew = aDlg->getCustomMarkerID();
1269                 if( aMarkerTypeNew != VTK::MT_USER )
1270                   anActor->SetMarkerStd( aMarkerTypeNew, aMarkerScaleNew );
1271                 else {
1272                   const VTK::MarkerMap& aMarkerMap = theMarkerMap[ aStudy->StudyId() ];
1273                   VTK::MarkerMap::const_iterator anIter = aMarkerMap.find( aMarkerTextureNew );
1274                   if( anIter != aMarkerMap.end() )
1275                     anActor->SetMarkerTexture( aMarkerTextureNew, anIter->second.second );
1276                 }
1277
1278                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1279                 if( !aGroupObject->_is_nil() )
1280                 {
1281                   SMESH::ElementType anElementType = aGroupObject->GetType();
1282                   QColor aColor;
1283                   switch( anElementType )
1284                   {
1285                     case SMESH::NODE: aColor = nodecolor; break;
1286                     case SMESH::EDGE: aColor = edgecolor; break;
1287                     default: aColor = color; break;
1288                   }
1289
1290                   SALOMEDS::Color aGroupColor;
1291                   aGroupColor.R = (float)aColor.red() / 255.0;
1292                   aGroupColor.G = (float)aColor.green() / 255.0;
1293                   aGroupColor.B = (float)aColor.blue() / 255.0;
1294                   aGroupObject->SetColor( aGroupColor );
1295                 }
1296               }
1297             }
1298           }
1299           SMESH::RepaintCurrentView();
1300         }
1301         delete aDlg;
1302         return;
1303       }
1304       }
1305       SALOME_ListIteratorOfListIO It( selected );
1306       for( ; It.More(); It.Next()){
1307         Handle(SALOME_InteractiveObject) IObject = It.Value();
1308         if(IObject->hasEntry()){
1309           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1310             switch(theCommandID){
1311             case 211:
1312               anActor->SetRepresentation(SMESH_Actor::eEdge);
1313               break;
1314             case 212:
1315               anActor->SetRepresentation(SMESH_Actor::eSurface);
1316               break;
1317             case 213:
1318               if(anActor->IsShrunk())
1319                 anActor->UnShrink();
1320               else
1321                 anActor->SetShrink();
1322               break;
1323             case 215:
1324               anActor->SetRepresentation(SMESH_Actor::ePoint);
1325               break;
1326             case 231:
1327               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1328                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1329               break;
1330             case 232:
1331               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1332                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1333               break;
1334             }
1335           }
1336         }
1337       }
1338       SMESH::RepaintCurrentView();
1339     }
1340   }
1341
1342   void Control( int theCommandID )
1343   {
1344     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1345     SALOME_ListIO selected;
1346     if( aSel )
1347       aSel->selectedObjects( selected );
1348
1349     if( !selected.IsEmpty() ){
1350       Handle(SALOME_InteractiveObject) anIO = selected.First();
1351       if(!anIO.IsNull()){
1352         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
1353         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())) {
1354           switch ( theCommandID ){
1355           case 6001:
1356             aControl = SMESH_Actor::eLength;
1357             break;
1358           case 6018:
1359             aControl = SMESH_Actor::eLength2D;
1360             break;
1361           case 6002:
1362             aControl = SMESH_Actor::eFreeEdges;
1363             break;
1364           case 6003:
1365             aControl = SMESH_Actor::eFreeBorders;
1366             break;
1367           case 6004:
1368             aControl = SMESH_Actor::eMultiConnection;
1369             break;
1370           case 6005:
1371             aControl = SMESH_Actor::eFreeNodes;
1372             break;
1373           case 6019:
1374             aControl = SMESH_Actor::eMultiConnection2D;
1375             break;
1376           case 6011:
1377             aControl = SMESH_Actor::eArea;
1378             break;
1379           case 6012:
1380             aControl = SMESH_Actor::eTaper;
1381             break;
1382           case 6013:
1383             aControl = SMESH_Actor::eAspectRatio;
1384             break;
1385           case 6017:
1386             aControl = SMESH_Actor::eAspectRatio3D;
1387             break;
1388           case 6014:
1389             aControl = SMESH_Actor::eMinimumAngle;
1390             break;
1391           case 6015:
1392             aControl = SMESH_Actor::eWarping;
1393             break;
1394           case 6016:
1395             aControl = SMESH_Actor::eSkew;
1396             break;
1397           case 6009:
1398             aControl = SMESH_Actor::eVolume3D;
1399             break;
1400           case 6021:
1401             aControl = SMESH_Actor::eFreeFaces;
1402             break;
1403           case 6022:
1404             aControl = SMESH_Actor::eMaxElementLength2D;
1405             break;
1406           case 6023:
1407             aControl = SMESH_Actor::eMaxElementLength3D;
1408             break;
1409           case 6024:
1410             aControl = SMESH_Actor::eBareBorderVolume;
1411             break;
1412           case 6025:
1413             aControl = SMESH_Actor::eBareBorderFace;
1414             break;
1415           case 6026:
1416             aControl = SMESH_Actor::eOverConstrainedVolume;
1417             break;
1418           case 6027:
1419             aControl = SMESH_Actor::eOverConstrainedFace;
1420             break;
1421           case 6028:
1422             aControl = SMESH_Actor::eCoincidentNodes;
1423             break;
1424           case 6029:
1425             aControl = SMESH_Actor::eCoincidentElems1D;
1426             break;
1427           case 6030:
1428             aControl = SMESH_Actor:: eCoincidentElems2D;
1429             break;
1430           case 6031:
1431             aControl = SMESH_Actor::eCoincidentElems3D;
1432             break;
1433           }
1434             
1435           anActor->SetControlMode(aControl);
1436           anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1437           SMESH::RepaintCurrentView();
1438 #ifndef DISABLE_PLOT2DVIEWER
1439           if(anActor->GetPlot2Histogram()) {
1440             SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1441             QString functorName = functorToString( anActor->GetFunctor());
1442             QString aHistogramName("%1 : %2");
1443             aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1444             aHistogram->setName(aHistogramName);
1445             aHistogram->setHorTitle(functorName);
1446             SMESH::ProcessIn2DViewers(anActor);
1447           }
1448 #endif
1449         }
1450       }
1451     }
1452   }
1453
1454
1455   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1456                    MeshObjectType                           theType,
1457                    const QString                            theInTypeName,
1458                    QString &                                theOutTypeName)
1459   {
1460     SMESH_TypeFilter aTypeFilter( theType );
1461     QString entry;
1462     if( !theIO.IsNull() )
1463     {
1464       entry = theIO->getEntry();
1465       LightApp_DataOwner owner( entry );
1466       if ( aTypeFilter.isOk( &owner )) {
1467         theOutTypeName = theInTypeName;
1468         return true;
1469       }
1470     }
1471     return false;
1472   }
1473
1474
1475   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1476   {
1477     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1478     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1479     if (aSObj) {
1480       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1481       CORBA::String_var anID = aSComp->GetID().c_str();
1482       if (!strcmp(anID.in(),theIO->getEntry()))
1483         return "Component";
1484     }
1485
1486     QString aTypeName;
1487     if (
1488         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1489         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
1490         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
1491         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
1492         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
1493         )
1494       return aTypeName;
1495
1496     return "NoType";
1497   }
1498
1499
1500   QString CheckHomogeneousSelection()
1501   {
1502     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1503     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1504     SALOME_ListIO selected;
1505     if( aSel )
1506       aSel->selectedObjects( selected );
1507
1508     QString RefType = CheckTypeObject(selected.First());
1509     SALOME_ListIteratorOfListIO It(selected);
1510     for ( ; It.More(); It.Next())
1511       {
1512         Handle(SALOME_InteractiveObject) IObject = It.Value();
1513         QString Type = CheckTypeObject(IObject);
1514         if (Type.compare(RefType) != 0)
1515           return "Heterogeneous Selection";
1516       }
1517
1518     return RefType;
1519   }
1520
1521
1522   void SMESHGUI::OnEditDelete()
1523   {
1524     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1525     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1526     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1527
1528     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1529     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1530     _PTR(GenericAttribute) anAttr;
1531     _PTR(AttributeIOR) anIOR;
1532
1533     int objectCount = 0;
1534     QString aNameList;
1535     QString aParentComponent = QString::null;
1536     Handle(SALOME_InteractiveObject) anIO;
1537     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1538     {
1539       anIO = anIt.Value();
1540       QString cur = anIO->getComponentDataType();
1541       _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1542       if (aSO) {
1543         // check if object is reference
1544         _PTR(SObject) aRefSObj;
1545         aNameList.append("\n    - ");
1546         if ( aSO->ReferencedObject( aRefSObj ) ) {
1547           QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1548           aNameList.append( aRefName );
1549           cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1550         }
1551         else
1552           aNameList.append(anIO->getName());
1553         objectCount++;
1554       }
1555
1556       if( aParentComponent.isNull() )
1557         aParentComponent = cur;
1558       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1559         aParentComponent = "";
1560     }
1561
1562     if ( objectCount == 0 )
1563       return; // No Valid Objects Selected
1564
1565     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1566       SUIT_MessageBox::warning( SMESHGUI::desktop(),
1567                                 QObject::tr("ERR_ERROR"),
1568                                 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1569       return;
1570     }
1571     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1572     if (SUIT_MessageBox::warning
1573         (SMESHGUI::desktop(),
1574          QObject::tr("SMESH_WRN_WARNING"),
1575          QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1576          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1577          SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1578       return;
1579
1580     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1581
1582     // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1583     // then treat them all starting from the deepest objects (at list back)
1584     std::list< _PTR(SObject) > listSO;
1585     SALOME_ListIteratorOfListIO It(selected);
1586     for( ; It.More(); It.Next()) // loop on selected IO's
1587     {
1588       Handle(SALOME_InteractiveObject) IObject = It.Value();
1589       if(IObject->hasEntry()) {
1590         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1591
1592         // disable removal of "SMESH" component object
1593         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1594           anIOR = anAttr;
1595           if ( engineIOR() == anIOR->Value().c_str() )
1596             continue;
1597         }
1598         //Check the referenced object
1599         _PTR(SObject) aRefSObject;
1600         if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1601           aSO = aRefSObject; // Delete main Object instead of reference
1602
1603         listSO.push_back( aSO );
1604         std::list< _PTR(SObject) >::iterator itSO = listSO.begin();
1605         for ( ; itSO != listSO.end(); ++itSO ) {
1606           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1607           for (it->InitEx(false); it->More(); it->Next())
1608             listSO.push_back( it->Value() );
1609         }
1610       }
1611     }
1612     // Check if none of objects to delete is referred from outside
1613     std::list< _PTR(SObject) >::reverse_iterator ritSO;
1614     for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1615     {
1616       _PTR(SObject) SO = *ritSO;
1617       if ( !SO ) continue;
1618       std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO  );
1619       for (size_t i = 0; i < aReferences.size(); i++) {
1620         _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1621         std::string type = aComponent->ComponentDataType();
1622         if ( type != "SMESH" )
1623         {
1624           SUIT_MessageBox::warning( anApp->desktop(),
1625                                     QObject::tr("WRN_WARNING"),
1626                                     QObject::tr("DEP_OBJECT") );
1627           return; // outside SMESH, there is an object depending on a SMESH object 
1628         }
1629       }
1630     }
1631
1632     // Treat SO's in the list starting from the back
1633     aStudyBuilder->NewCommand();  // There is a transaction
1634     for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1635     {
1636       _PTR(SObject) SO = *ritSO;
1637       if ( !SO ) continue;
1638       std::string anEntry = SO->GetID();
1639
1640       /** Erase graphical object **/
1641       if(SO->FindAttribute(anAttr, "AttributeIOR")){
1642         ViewManagerList aViewMenegers = anApp->viewManagers();
1643         ViewManagerList::const_iterator it = aViewMenegers.begin();
1644         for( ; it != aViewMenegers.end(); it++) {         
1645           SUIT_ViewManager* vm = *it;
1646           int nbSf = vm ? vm->getViewsCount() : 0;
1647           if(vm) {
1648             QVector<SUIT_ViewWindow*> aViews = vm->getViews();
1649             for(int i = 0; i < nbSf; i++){
1650               SUIT_ViewWindow *sf = aViews[i];
1651               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1652                 SMESH::RemoveActor(sf,anActor);
1653               }
1654             }
1655           }
1656         }
1657       }
1658       /** Remove an object from data structures **/
1659       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1660       SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1661       if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1662         SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1663         aMesh->RemoveGroup( aGroup );
1664       }
1665       else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1666         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1667         aMesh->RemoveSubMesh( aSubMesh );
1668
1669         _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1670         if (aMeshSO)
1671           SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1672       }
1673       else {
1674         Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1675           ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1676         QString objType = CheckTypeObject(IObject);
1677         if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1678           SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1679           aStudyBuilder->RemoveObjectWithChildren( SO );
1680         }
1681         else {// default action: remove SObject from the study
1682               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1683               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1684               //op->start();
1685           aStudyBuilder->RemoveObjectWithChildren( SO );
1686           //op->finish();
1687         }
1688       }
1689     } /* listSO back loop */
1690
1691     aStudyBuilder->CommitCommand();
1692
1693     /* Clear any previous selection */
1694     SALOME_ListIO l1;
1695     aSel->setSelectedObjects( l1 );
1696
1697     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1698   }
1699 //} namespace
1700
1701 extern "C" {
1702   SMESHGUI_EXPORT CAM_Module* createModule()
1703   {
1704     return new SMESHGUI();
1705   }
1706
1707   SMESHGUI_EXPORT  char* getModuleVersion() {
1708     return (char*)SMESH_VERSION_STR;
1709   }
1710 }
1711
1712 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1713
1714 //=============================================================================
1715 /*!
1716  *
1717  */
1718 //=============================================================================
1719 SMESHGUI::SMESHGUI() :
1720 SalomeApp_Module( "SMESH" ),
1721 LightApp_Module( "SMESH" )
1722 {
1723   if ( CORBA::is_nil( myComponentSMESH ) )
1724   {
1725     CORBA::Boolean anIsEmbeddedMode;
1726     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1727     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1728
1729     //  0019923: EDF 765 SMESH : default values of hypothesis
1730     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1731     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1732     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1733     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1734     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1735
1736     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif" };
1737     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
1738       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
1739       {
1740         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
1741         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
1742       }
1743   }
1744
1745   myActiveDialogBox = 0;
1746   myFilterLibraryDlg = 0;
1747   myState = -1;
1748   myDisplayer = 0;
1749
1750   myEventCallbackCommand = vtkCallbackCommand::New();
1751   myEventCallbackCommand->Delete();
1752   myEventCallbackCommand->SetClientData( this );
1753   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1754   myPriority = 0.0;
1755
1756   SMESH::GetFilterManager();
1757   SMESH::GetPattern();
1758   SMESH::GetMeasurements();
1759
1760   /* load resources for all available meshers */
1761   SMESH::InitAvailableHypotheses();
1762 }
1763
1764 //=============================================================================
1765 /*!
1766  *
1767  */
1768 //=============================================================================
1769 SMESHGUI::~SMESHGUI()
1770 {
1771 #ifdef WITHGENERICOBJ
1772   SMESH::GetFilterManager()->UnRegister();
1773   SMESH::GetMeasurements()->UnRegister();
1774 #endif
1775   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1776   SMESH::GetMeasurements() = SMESH::Measurements::_nil();
1777 }
1778
1779 //=============================================================================
1780 /*!
1781  *
1782  */
1783 //=============================================================================
1784 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1785 {
1786   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1787   if( anApp )
1788     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1789   else
1790     return 0;
1791 }
1792
1793 //=============================================================================
1794 /*!
1795  *
1796  */
1797 //=============================================================================
1798 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
1799 {
1800   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1801   if ( !resMgr )
1802     return false;
1803
1804   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
1805   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
1806   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
1807   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
1808   return autoUpdate && !exceeded;
1809 }
1810
1811 //=============================================================================
1812 /*!
1813  *
1814  */
1815 //=============================================================================
1816 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1817 {
1818   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1819 }
1820
1821 //=============================================================================
1822 /*!
1823  *
1824  */
1825 //=============================================================================
1826 SMESHGUI* SMESHGUI::GetSMESHGUI()
1827 {
1828   SMESHGUI* smeshMod = 0;
1829   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1830   if ( app )
1831   {
1832     CAM_Module* module = app->module( "Mesh" );
1833     smeshMod = dynamic_cast<SMESHGUI*>( module );
1834   }
1835
1836   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1837   {
1838     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1839     if ( study )
1840     {
1841       _PTR(Study) aStudy = study->studyDS();
1842       if ( aStudy )
1843         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1844     }
1845   }
1846
1847   return smeshMod;
1848 }
1849
1850 extern "C"
1851 {
1852   Standard_EXPORT SMESHGUI* GetComponentGUI()
1853   {
1854     return SMESHGUI::GetSMESHGUI();
1855   }
1856 }
1857
1858 //=============================================================================
1859 /*!
1860  *
1861  */
1862 //=============================================================================
1863 void SMESHGUI::SetState(int aState)
1864 {
1865   myState = aState;
1866 }
1867
1868 //=============================================================================
1869 /*!
1870  *
1871  */
1872 //=============================================================================
1873 void SMESHGUI::ResetState()
1874 {
1875   myState = -1;
1876 }
1877
1878 //=============================================================================
1879 /*!
1880  *
1881  */
1882 //=============================================================================
1883 void SMESHGUI::EmitSignalDeactivateDialog()
1884 {
1885   emit SignalDeactivateActiveDialog();
1886 }
1887
1888 //=============================================================================
1889 /*!
1890  *
1891  */
1892 //=============================================================================
1893 void SMESHGUI::EmitSignalStudyFrameChanged()
1894 {
1895   emit SignalStudyFrameChanged();
1896 }
1897
1898 //=============================================================================
1899 /*!
1900  *
1901  */
1902 //=============================================================================
1903 void SMESHGUI::EmitSignalCloseAllDialogs()
1904 {
1905   emit SignalCloseAllDialogs();
1906 }
1907
1908 //=============================================================================
1909 /*!
1910  *
1911  */
1912 //=============================================================================
1913 void SMESHGUI::EmitSignalVisibilityChanged()
1914 {
1915   emit SignalVisibilityChanged();
1916 }
1917
1918 //=============================================================================
1919 /*!
1920  *
1921  */
1922 //=============================================================================
1923 QDialog *SMESHGUI::GetActiveDialogBox()
1924 {
1925   return myActiveDialogBox;
1926 }
1927
1928 //=============================================================================
1929 /*!
1930  *
1931  */
1932 //=============================================================================
1933 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1934 {
1935   myActiveDialogBox = (QDialog *) aDlg;
1936   return;
1937 }
1938
1939 //=============================================================================
1940 /*!
1941  *
1942  */
1943 //=============================================================================
1944 SUIT_Desktop* SMESHGUI::desktop()
1945 {
1946   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1947   if( app )
1948     return app->desktop();
1949   else
1950     return 0;
1951 }
1952
1953 //=============================================================================
1954 /*!
1955  *
1956  */
1957 //=============================================================================
1958 SalomeApp_Study* SMESHGUI::activeStudy()
1959 {
1960   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1961   if( app )
1962     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1963   else
1964     return NULL;
1965 }
1966
1967 //=============================================================================
1968 /*!
1969  *
1970  */
1971 //=============================================================================
1972 void SMESHGUI::Modified( bool theIsUpdateActions )
1973 {
1974   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
1975     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
1976       appStudy->Modified();
1977       if( theIsUpdateActions )
1978         app->updateActions();
1979     }
1980   }
1981 }
1982
1983 //=============================================================================
1984 /*!
1985  *
1986  */
1987 //=============================================================================
1988 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1989 {
1990   /* Here the position is on the bottom right corner - 10 */
1991   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1992   aDlg->adjustSize();
1993   SUIT_Desktop *PP = desktop();
1994   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1995   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1996   return true;
1997 }
1998
1999 //=============================================================================
2000 /*!
2001  *
2002  */
2003 //=============================================================================
2004 static int isStudyLocked(_PTR(Study) theStudy){
2005   return theStudy->GetProperties()->IsLocked();
2006 }
2007
2008 static bool checkLock(_PTR(Study) theStudy) {
2009   if (isStudyLocked(theStudy)) {
2010     SUIT_MessageBox::warning( SMESHGUI::desktop(),
2011                               QObject::tr("WRN_WARNING"),
2012                               QObject::tr("WRN_STUDY_LOCKED") );
2013     return true;
2014   }
2015   return false;
2016 }
2017
2018 //=======================================================================
2019 //function : CheckActiveStudyLocked
2020 //purpose  :
2021 //=======================================================================
2022
2023 bool SMESHGUI::isActiveStudyLocked()
2024 {
2025   _PTR(Study) aStudy = activeStudy()->studyDS();
2026   return checkLock( aStudy );
2027 }
2028
2029 //=============================================================================
2030 /*!
2031  *
2032  */
2033 //=============================================================================
2034 bool SMESHGUI::OnGUIEvent( int theCommandID )
2035 {
2036   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2037   if( !anApp )
2038     return false;
2039
2040   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2041   SUIT_ResourceMgr* mgr = resourceMgr();
2042   if( !mgr )
2043     return false;
2044
2045   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2046     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2047   }
2048
2049   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2050   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2051
2052   //QAction* act = action( theCommandID );
2053
2054   switch (theCommandID) {
2055   case 33:                                      // DELETE
2056     if(checkLock(aStudy)) break;
2057     OnEditDelete();
2058     break;
2059
2060   case 116:
2061   case 115:
2062   case 117:
2063   case 113:
2064   case 112:
2065   case 111:                                     // IMPORT
2066     {
2067       if(checkLock(aStudy)) break;
2068       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2069       break;
2070     }
2071
2072   case 150:    //MED FILE INFORMATION
2073     {
2074       SALOME_ListIO selected;
2075       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2076       if( aSel )
2077         aSel->selectedObjects( selected );
2078       if( selected.Extent() )
2079       {
2080         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2081         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2082         if ( !aMesh->_is_nil() )
2083         {
2084           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2085           dlg.exec();
2086         }
2087       }
2088       break;
2089     }
2090
2091   case 122:                                     // EXPORT MED
2092   case 121:
2093   case 123:
2094   case 124:
2095   case 125:
2096   case 126:
2097   case 140:
2098   case 141:
2099   case 142:
2100   case 143:
2101   case 144:
2102   case 145:
2103     {
2104       ::ExportMeshToFile(theCommandID);
2105       break;
2106     }
2107
2108   case 200:                                     // SCALAR BAR
2109     {
2110       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2111       SALOME_ListIO selected;
2112       if( aSel )
2113         aSel->selectedObjects( selected );
2114
2115       if( selected.Extent() ) {
2116         Handle(SALOME_InteractiveObject) anIO = selected.First();
2117         if( anIO->hasEntry() ) {
2118           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2119             anActor->SetControlMode( SMESH_Actor::eNone );
2120 #ifndef DISABLE_PLOT2DVIEWER
2121             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2122 #endif
2123           }
2124         }
2125       }
2126       break;
2127     }
2128   case 201:
2129     {
2130       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2131       break;
2132     }
2133   case 2021:
2134     {
2135       // dump control distribution data to the text file
2136       ::SaveDistribution();
2137       break;
2138     }
2139
2140   case 2022:
2141     {
2142       // show/ distribution
2143       ::ShowDistribution();
2144       break;
2145     }
2146
2147 #ifndef DISABLE_PLOT2DVIEWER
2148   case 2023:
2149     {
2150       // plot distribution
2151       ::PlotDistribution();
2152       break;
2153     }
2154 #endif
2155
2156     // Auto-color
2157   case 1136:
2158     ::AutoColor();
2159   break;
2160
2161   case 1137:
2162     ::DisableAutoColor();
2163   break;
2164
2165   case 1134: // Clipping
2166   case 1133: // Tranparency
2167   case 1132: // Display preferences (colors, shrink size, line width, ...)
2168
2169     // Display Mode
2170   case 215: // Nodes
2171   case 213: // Nodes
2172   case 212: // Nodes
2173   case 211: // Nodes
2174     ::SetDisplayMode(theCommandID, myMarkerMap);
2175   break;
2176
2177   //2D quadratic representation
2178   case 231:
2179   case 232:
2180     ::SetDisplayMode(theCommandID, myMarkerMap);
2181   break;
2182
2183   // Display Entity
2184   case 216: // 0D elements
2185   case 217: // Edges
2186   case 218: // Faces
2187   case 219: // Volumes
2188   case 220: // All Entity
2189     ::SetDisplayEntity(theCommandID);
2190   break;
2191
2192   case 221: // Orientation of faces
2193     {
2194       LightApp_SelectionMgr* mgr = selectionMgr();
2195       SALOME_ListIO selected; mgr->selectedObjects( selected );
2196
2197       SALOME_ListIteratorOfListIO it(selected);
2198       for( ; it.More(); it.Next()) {
2199         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2200         if(anIObject->hasEntry()) {
2201           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2202             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2203           }
2204         }
2205       }
2206       break;
2207     }
2208
2209   case 214:                                     // UPDATE
2210     {
2211       if(checkLock(aStudy)) break;
2212       try {
2213 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2214         OCC_CATCH_SIGNALS;
2215 #endif
2216         SMESH::UpdateView();
2217       }
2218       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2219         SMESH::OnVisuException();
2220       }
2221       catch (...) { // PAL16774 (Crash after display of many groups)
2222         SMESH::OnVisuException();
2223       }
2224
2225       SALOME_ListIO l;
2226       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2227       aSel->selectedObjects( l );
2228       aSel->setSelectedObjects( l );
2229       break;
2230     }
2231
2232   case 300:                                     // ERASE
2233   case 301:                                     // DISPLAY
2234   case 302:                                     // DISPLAY ONLY
2235     {
2236       SMESH::EDisplaing anAction;
2237       switch (theCommandID) {
2238       case 300: anAction = SMESH::eErase; break;
2239       case 301: anAction = SMESH::eDisplay; break;
2240       case 302: anAction = SMESH::eDisplayOnly; break;
2241       }
2242
2243       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2244       SALOME_ListIO sel_objects, to_process;
2245       if (aSel)
2246         aSel->selectedObjects( sel_objects );
2247
2248       if( theCommandID==302 )
2249       {
2250         MESSAGE("anAction = SMESH::eDisplayOnly");
2251         startOperation( myEraseAll );
2252       }
2253
2254       extractContainers( sel_objects, to_process );
2255
2256       try {
2257 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2258         OCC_CATCH_SIGNALS;
2259 #endif
2260         if (vtkwnd) {
2261           SALOME_ListIteratorOfListIO It( to_process );
2262           for ( ; It.More(); It.Next()) {
2263                 MESSAGE("---");
2264             Handle(SALOME_InteractiveObject) IOS = It.Value();
2265             if (IOS->hasEntry()) {
2266                 MESSAGE("---");
2267               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
2268                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2269                 break; // PAL16774 (Crash after display of many groups)
2270               }
2271               if (anAction == SMESH::eDisplayOnly)
2272               {
2273                 MESSAGE("anAction = SMESH::eDisplayOnly");
2274                 anAction = SMESH::eDisplay;
2275               }
2276             }
2277           }
2278         }
2279
2280         // PAL13338 + PAL15161 -->
2281         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
2282                 MESSAGE("anAction = SMESH::eDisplayOnly");
2283           SMESH::UpdateView();
2284           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2285         }
2286         // PAL13338 + PAL15161 <--
2287       }
2288       catch (...) { // PAL16774 (Crash after display of many groups)
2289         SMESH::OnVisuException();
2290       }
2291
2292       if (anAction == SMESH::eErase) {
2293         MESSAGE("anAction == SMESH::eErase");
2294         SALOME_ListIO l1;
2295         aSel->setSelectedObjects( l1 );
2296       }
2297       else
2298         aSel->setSelectedObjects( to_process );
2299
2300       break;
2301     }
2302
2303   case 4000:                                    // NODES
2304     {
2305       if(checkLock(aStudy)) break;
2306
2307       if ( vtkwnd ) {
2308         EmitSignalDeactivateDialog();
2309
2310         ( new SMESHGUI_NodesDlg( this ) )->show();
2311       }
2312       else {
2313         SUIT_MessageBox::warning(desktop(),
2314                                  tr("SMESH_WRN_WARNING"),
2315                                  tr("SMESH_WRN_VIEWER_VTK"));
2316       }
2317       break;
2318     }
2319
2320   case 2151:  // FILTER
2321   {
2322     if ( vtkwnd )
2323     {
2324       EmitSignalDeactivateDialog();
2325       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
2326     }
2327     break;
2328   }
2329
2330   case 701:                                     // COMPUTE MESH
2331   case 711:                                     // PRECOMPUTE MESH
2332   case 712:                                     // EVALUATE MESH
2333   case 713:                                     // MESH ORDER
2334     {
2335       if (checkLock(aStudy)) break;
2336       startOperation( theCommandID );
2337     }
2338     break;
2339
2340   case 702: // Create mesh
2341   case 703: // Create sub-mesh
2342   case 704: // Edit mesh/sub-mesh
2343     startOperation( theCommandID );
2344     break;
2345   case 705: // copy mesh
2346     {
2347       if (checkLock(aStudy)) break;
2348       EmitSignalDeactivateDialog();
2349       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2350     }
2351     break;
2352   case 710: // Build compound mesh
2353     {
2354       if (checkLock(aStudy)) break;
2355       EmitSignalDeactivateDialog();
2356       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2357     }
2358     break;
2359
2360   case 407: // DIAGONAL INVERSION
2361   case 408: // Delete diagonal
2362     {
2363       if ( !vtkwnd )
2364       {
2365         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2366                                   tr( "NOT_A_VTK_VIEWER" ) );
2367         break;
2368       }
2369
2370       if ( checkLock( aStudy ) )
2371         break;
2372
2373       /*Standard_Boolean aRes;
2374       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2375       if ( aMesh->_is_nil() )
2376       {
2377         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2378           tr( "SMESH_BAD_SELECTION" ) );
2379         break;
2380       }
2381       */
2382       EmitSignalDeactivateDialog();
2383       if ( theCommandID == 407 )
2384         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2385       else
2386         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2387       break;
2388     }
2389   case 409: // Change orientation
2390   case 410: // Union of triangles
2391   case 411: // Cutting of quadrangles
2392   case 419: // Splitting volumes into tetrahedra
2393     {
2394       if ( !vtkwnd )
2395       {
2396         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2397                                   tr( "NOT_A_VTK_VIEWER" ) );
2398         break;
2399       }
2400
2401       if ( checkLock( aStudy ) )
2402         break;
2403
2404       EmitSignalDeactivateDialog();
2405       SMESHGUI_MultiEditDlg* aDlg = NULL;
2406       if ( theCommandID == 409 )
2407         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2408       else if ( theCommandID == 410 )
2409         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2410       else if ( theCommandID == 419 )
2411         aDlg = new SMESHGUI_CuttingIntoTetraDlg(this);
2412       else
2413         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2414
2415       aDlg->show();
2416       break;
2417     }
2418   case 412: // Smoothing
2419     {
2420       if(checkLock(aStudy)) break;
2421       if( vtkwnd ) {
2422         EmitSignalDeactivateDialog();
2423         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2424       }
2425       else {
2426         SUIT_MessageBox::warning(desktop(),
2427                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2428       }
2429       break;
2430     }
2431   case 413: // Extrusion
2432     {
2433       if (checkLock(aStudy)) break;
2434       if (vtkwnd) {
2435         EmitSignalDeactivateDialog();
2436         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2437       } else {
2438         SUIT_MessageBox::warning(desktop(),
2439                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2440       }
2441       break;
2442     }
2443   case 414: // Revolution
2444     {
2445       if(checkLock(aStudy)) break;
2446       if( vtkwnd ) {
2447         EmitSignalDeactivateDialog();
2448         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2449       }
2450       else {
2451         SUIT_MessageBox::warning(desktop(),
2452                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2453       }
2454       break;
2455     }
2456   case 415: // Pattern mapping
2457     {
2458       if ( checkLock( aStudy ) )
2459         break;
2460       if ( vtkwnd )
2461       {
2462         EmitSignalDeactivateDialog();
2463         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2464       }
2465       else {
2466         SUIT_MessageBox::warning(desktop(),
2467                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2468       }
2469       break;
2470     }
2471   case 416: // Extrusion along a path
2472     {
2473       if (checkLock(aStudy)) break;
2474       if (vtkwnd) {
2475         EmitSignalDeactivateDialog();
2476         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2477       } else {
2478         SUIT_MessageBox::warning(desktop(),
2479                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2480       }
2481       break;
2482     }
2483   case 417: // Convert mesh to quadratic
2484     {
2485     startOperation( 417 );
2486       /*      if (checkLock(aStudy)) break;
2487       if (vtkwnd) {
2488         EmitSignalDeactivateDialog();
2489         new SMESHGUI_ConvToQuadDlg();
2490       } else {
2491         SUIT_MessageBox::warning(desktop(),
2492                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2493                                }*/
2494       break;
2495     }
2496   case 418: // create 2D mesh from 3D
2497     {
2498       startOperation( 418 );
2499       break;
2500     }
2501   case 806:                                     // CREATE GEO GROUP
2502     {
2503       startOperation( 806 );
2504       break;
2505     }
2506   case 801:                                     // CREATE GROUP
2507     {
2508       if ( !vtkwnd )
2509       {
2510         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2511                                   tr( "NOT_A_VTK_VIEWER" ) );
2512         break;
2513       }
2514
2515       if(checkLock(aStudy)) break;
2516       EmitSignalDeactivateDialog();
2517       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2518
2519       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2520       SALOME_ListIO selected;
2521       if( aSel )
2522         aSel->selectedObjects( selected );
2523
2524       int nbSel = selected.Extent();
2525       if (nbSel == 1) {
2526         // check if mesh is selected
2527         aMesh = SMESH::GetMeshByIO( selected.First() );
2528       }
2529       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2530       aDlg->show();
2531       break;
2532     }
2533
2534   case 802:                                     // CONSTRUCT GROUP
2535     {
2536       if ( !vtkwnd )
2537       {
2538         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2539                                   tr( "NOT_A_VTK_VIEWER" ) );
2540         break;
2541       }
2542
2543       if(checkLock(aStudy)) break;
2544       EmitSignalDeactivateDialog();
2545
2546       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2547       SALOME_ListIO selected;
2548       if( aSel )
2549         aSel->selectedObjects( selected );
2550
2551       int nbSel = selected.Extent();
2552       if (nbSel == 1) {
2553         // check if submesh is selected
2554         Handle(SALOME_InteractiveObject) IObject = selected.First();
2555         if (IObject->hasEntry()) {
2556           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2557           if( aSObj ) {
2558             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2559             if (!aSubMesh->_is_nil()) {
2560               try {
2561                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2562                 // get submesh elements list by types
2563                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2564                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2565                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2566                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2567                 // create group for each type o elements
2568                 QString aName = IObject->getName();
2569                 QStringList anEntryList;
2570                 if (aNodes->length() > 0) {
2571                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2572                   aGroup->Add(aNodes.inout());
2573                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2574                     anEntryList.append( aSObject->GetID().c_str() );
2575                 }
2576                 if (aEdges->length() > 0) {
2577                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2578                   aGroup->Add(aEdges.inout());
2579                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2580                     anEntryList.append( aSObject->GetID().c_str() );
2581                 }
2582                 if (aFaces->length() > 0) {
2583                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2584                   aGroup->Add(aFaces.inout());
2585                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2586                     anEntryList.append( aSObject->GetID().c_str() );
2587                 }
2588                 if (aVolumes->length() > 0) {
2589                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2590                   aGroup->Add(aVolumes.inout());
2591                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2592                     anEntryList.append( aSObject->GetID().c_str() );
2593                 }
2594                 updateObjBrowser();
2595                 anApp->browseObjects( anEntryList );
2596               }
2597               catch(const SALOME::SALOME_Exception & S_ex){
2598                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2599               }
2600             }
2601           }
2602         }
2603       }
2604       else if(nbSel==0) {
2605         SUIT_MessageBox::warning(desktop(),
2606                                  tr("SMESH_WRN_WARNING"),
2607                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2608       }
2609       break;
2610     }
2611
2612   case 803:                                     // EDIT GROUP
2613     {
2614       if ( !vtkwnd )
2615       {
2616         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2617                                   tr( "NOT_A_VTK_VIEWER" ) );
2618         break;
2619       }
2620
2621       if(checkLock(aStudy)) break;
2622       EmitSignalDeactivateDialog();
2623
2624       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2625       SALOME_ListIO selected;
2626       if( aSel )
2627         aSel->selectedObjects( selected );
2628
2629       SALOME_ListIteratorOfListIO It (selected);
2630       int nbSelectedGroups = 0;
2631       for ( ; It.More(); It.Next() )
2632       {
2633         SMESH::SMESH_GroupBase_var aGroup =
2634           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2635         if (!aGroup->_is_nil()) {
2636           nbSelectedGroups++;
2637           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2638           aDlg->show();
2639         }
2640       }
2641       if (nbSelectedGroups == 0)
2642         {
2643           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2644           aDlg->show();
2645         }
2646       break;
2647     }
2648
2649   case 804:                                     // Add elements to group
2650     {
2651       if(checkLock(aStudy)) break;
2652       if (myState == 800) {
2653         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2654         if (aDlg) aDlg->onAdd();
2655       }
2656       break;
2657     }
2658
2659   case 805:                                     // Remove elements from group
2660     {
2661       if(checkLock(aStudy)) break;
2662       if (myState == 800) {
2663         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2664         if (aDlg) aDlg->onRemove();
2665       }
2666       break;
2667     }
2668
2669   case 815:                                     // Edit GEOM GROUP as standalone
2670     {
2671       if ( !vtkwnd )
2672       {
2673         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2674                                   tr( "NOT_A_VTK_VIEWER" ) );
2675         break;
2676       }
2677
2678       if(checkLock(aStudy)) break;
2679       EmitSignalDeactivateDialog();
2680
2681       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2682       SALOME_ListIO selected;
2683       if( aSel )
2684         aSel->selectedObjects( selected );
2685
2686       SALOME_ListIteratorOfListIO It (selected);
2687       for ( ; It.More(); It.Next() )
2688       {
2689         SMESH::SMESH_GroupOnGeom_var aGroup =
2690           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
2691         if (!aGroup->_is_nil()) {
2692           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2693           aDlg->show();
2694         }
2695         else
2696         {
2697           SMESH::SMESH_GroupOnFilter_var aGroup =
2698             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
2699           if (!aGroup->_is_nil()) {
2700             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2701             aDlg->show();
2702           }
2703         }
2704       }
2705       break;
2706     }
2707
2708     case 810: // Union Groups
2709     case 811: // Intersect groups
2710     case 812: // Cut groups
2711     {
2712       if ( !vtkwnd )
2713       {
2714         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2715                                   tr( "NOT_A_VTK_VIEWER" ) );
2716         break;
2717       }
2718
2719       if ( checkLock( aStudy ) )
2720         break;
2721
2722       EmitSignalDeactivateDialog();
2723
2724       SMESHGUI_GroupOpDlg* aDlg = 0;
2725       if ( theCommandID == 810 )
2726         aDlg = new SMESHGUI_UnionGroupsDlg( this );
2727       else if ( theCommandID == 811 )
2728         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
2729       else
2730         aDlg = new SMESHGUI_CutGroupsDlg( this );
2731
2732       aDlg->show();
2733
2734       break;
2735     }
2736
2737     case 814: // Create groups of entities from existing groups of superior dimensions
2738     {
2739       if ( checkLock( aStudy ) )
2740         break;
2741
2742       EmitSignalDeactivateDialog();
2743       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
2744       aDlg->show();
2745
2746       break;
2747     }
2748
2749     case 813: // Delete groups with their contents
2750     {
2751       if ( !vtkwnd )
2752       {
2753         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2754                                   tr( "NOT_A_VTK_VIEWER" ) );
2755         break;
2756       }
2757
2758       if ( checkLock( aStudy ) )
2759         break;
2760
2761       EmitSignalDeactivateDialog();
2762
2763       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
2764       break;
2765     }
2766
2767   case 900:                                     // MESH INFOS
2768   case 903:                                     // WHAT IS
2769     {
2770       int page = theCommandID == 900 ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
2771       EmitSignalDeactivateDialog();
2772       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2773       SALOME_ListIO selected;
2774       if( aSel )
2775         aSel->selectedObjects( selected );
2776
2777       if ( selected.Extent() > 1 ) { // a dlg for each IO
2778         SALOME_ListIteratorOfListIO It( selected );
2779         for ( ; It.More(); It.Next() ) {
2780           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2781           dlg->showInfo( It.Value() ); 
2782           dlg->show();
2783         }
2784       }
2785       else {
2786         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2787         dlg->show();
2788       }
2789       break;
2790     }
2791
2792   case 904:                                     // FIND ELEM
2793     {
2794       startOperation( theCommandID );
2795       break;
2796     }
2797
2798   case 1100:                                    // EDIT HYPOTHESIS
2799     {
2800       if(checkLock(aStudy)) break;
2801
2802       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2803       SALOME_ListIO selected;
2804       if( aSel )
2805         aSel->selectedObjects( selected );
2806
2807       int nbSel = selected.Extent();
2808
2809       if (nbSel == 1) {
2810         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2811         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2812
2813         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2814         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2815         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2816         if ( !aHypothesis->_is_nil() )
2817         {
2818           // BUG 0020378
2819           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2820           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2821           if (aCreator) {
2822             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
2823           }
2824           else
2825           {
2826             // report error
2827           }
2828         }
2829       }
2830       break;
2831     }
2832   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2833     {
2834       if(checkLock(aStudy)) break;
2835       SUIT_OverrideCursor wc;
2836
2837       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2838       SALOME_ListIO selected;
2839       if( aSel )
2840         aSel->selectedObjects( selected, QString::null, false );
2841
2842       SALOME_ListIteratorOfListIO It(selected);
2843       for (int i = 0; It.More(); It.Next(), i++) {
2844         Handle(SALOME_InteractiveObject) IObject = It.Value();
2845         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2846       }
2847       SALOME_ListIO l1;
2848       aSel->setSelectedObjects( l1 );
2849       updateObjBrowser();
2850       break;
2851     }
2852
2853   case 4009:                                    // ELEM0D
2854   case 4010:                                    // EDGE
2855   case 4021:                                    // TRIANGLE
2856   case 4022:                                    // QUAD
2857   case 4023:                                    // POLYGON
2858   case 4031:                                    // TETRA
2859   case 4032:                                    // HEXA
2860   case 4133:                                    // PENTA
2861   case 4134:                                    // PYRAMID
2862   case 4135:                                    // OCTA12
2863     {
2864       if(checkLock(aStudy)) break;
2865       if ( vtkwnd ) {
2866         EmitSignalDeactivateDialog();
2867         SMDSAbs_EntityType type = SMDSEntity_Edge;
2868         switch (theCommandID) {
2869         case 4009:
2870           type = SMDSEntity_0D; break;
2871         case 4021:
2872           type = SMDSEntity_Triangle; break;
2873         case 4022:
2874           type = SMDSEntity_Quadrangle; break;
2875         case 4031:
2876           type = SMDSEntity_Tetra; break;
2877         case 4023:
2878           type = SMDSEntity_Polygon; break;
2879         case 4032:
2880           type = SMDSEntity_Hexa; break;
2881         case 4133:
2882           type = SMDSEntity_Penta; break;
2883         case 4134:
2884           type = SMDSEntity_Pyramid; break;
2885         case 4135:
2886           type = SMDSEntity_Hexagonal_Prism; break;
2887         default:;
2888         }
2889         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
2890       }
2891       else {
2892         SUIT_MessageBox::warning(desktop(),
2893                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2894       }
2895       break;
2896     }
2897   case 4033:                                    // POLYHEDRON
2898     {
2899       if(checkLock(aStudy)) break;
2900       if ( vtkwnd ) {
2901         EmitSignalDeactivateDialog();
2902         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2903       }
2904       else {
2905         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2906                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2907       }
2908       break;
2909     }
2910   case 4034:     // QUADRATIC EDGE
2911   case 4035:     // QUADRATIC TRIANGLE
2912   case 4036:     // QUADRATIC QUADRANGLE
2913   case 4136:     // BIQUADRATIC QUADRANGLE
2914   case 4037:     // QUADRATIC TETRAHEDRON
2915   case 4038:     // QUADRATIC PYRAMID
2916   case 4039:     // QUADRATIC PENTAHEDRON
2917   case 4040:     // QUADRATIC HEXAHEDRON
2918   case 4140:     // TRIQUADRATIC HEXAHEDRON
2919     {
2920       if(checkLock(aStudy)) break;
2921       if ( vtkwnd ) {
2922         EmitSignalDeactivateDialog();
2923         SMDSAbs_EntityType type;
2924
2925         switch (theCommandID) {
2926         case 4034:
2927           type = SMDSEntity_Quad_Edge; break;
2928         case 4035:
2929           type = SMDSEntity_Quad_Triangle; break;
2930         case 4036:
2931           type = SMDSEntity_Quad_Quadrangle; break;
2932         case 4136:
2933           type = SMDSEntity_BiQuad_Quadrangle; break;
2934         case 4037:
2935           type = SMDSEntity_Quad_Tetra; break;
2936         case 4038:
2937           type = SMDSEntity_Quad_Pyramid; break;
2938         case 4039:
2939           type = SMDSEntity_Quad_Penta; break;
2940         case 4040:
2941           type = SMDSEntity_Quad_Hexa;
2942         case 4140:
2943           type = SMDSEntity_TriQuad_Hexa;
2944           break;
2945         default:;
2946         }
2947          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
2948       }
2949       else {
2950         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2951                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2952       }
2953       break;
2954     }
2955   case 4041:                                    // REMOVES NODES
2956     {
2957       if(checkLock(aStudy)) break;
2958       if ( vtkwnd ) {
2959         EmitSignalDeactivateDialog();
2960         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
2961       }
2962       else {
2963         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2964                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2965       }
2966       break;
2967     }
2968   case 4042:                                    // REMOVES ELEMENTS
2969     {
2970       if(checkLock(aStudy)) break;
2971       if( vtkwnd ) {
2972         EmitSignalDeactivateDialog();
2973         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
2974       }
2975       else
2976         {
2977           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2978                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2979         }
2980       break;
2981     }
2982   case 4043: {                                // CLEAR_MESH
2983
2984     if(checkLock(aStudy)) break;
2985
2986     SALOME_ListIO selected;
2987     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2988       aSel->selectedObjects( selected );
2989
2990     SUIT_OverrideCursor wc;
2991     SALOME_ListIteratorOfListIO It (selected);
2992     for ( ; It.More(); It.Next() )
2993     {
2994       Handle(SALOME_InteractiveObject) IOS = It.Value();
2995       SMESH::SMESH_Mesh_var aMesh =
2996         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2997       if ( aMesh->_is_nil()) continue;
2998       try {
2999         SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3000         aMesh->Clear();
3001         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3002         SMESH::ModifiedMesh( aMeshSObj, false, true);
3003         // hide groups and submeshes
3004         _PTR(ChildIterator) anIter =
3005           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3006         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3007         {
3008           _PTR(SObject) so = anIter->Value();
3009           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3010         }
3011       }
3012       catch (const SALOME::SALOME_Exception& S_ex){
3013         wc.suspend();
3014         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3015         wc.resume();
3016       }
3017     }
3018     SMESH::UpdateView();
3019     updateObjBrowser();
3020     break;
3021   }
3022   case 4044:                                     // REMOVE ORPHAN NODES
3023     {
3024       if(checkLock(aStudy)) break;
3025       SALOME_ListIO selected;
3026       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3027         aSel->selectedObjects( selected );
3028       if ( selected.Extent() == 1 ) {
3029         Handle(SALOME_InteractiveObject) anIO = selected.First();
3030         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3031         if ( !aMesh->_is_nil() ) {
3032           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3033                                                     tr( "SMESH_WARNING" ),
3034                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3035                                                     SUIT_MessageBox::Yes |
3036                                                     SUIT_MessageBox::No,
3037                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3038           if( confirm ) {
3039             try {
3040               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3041               int removed = aMeshEditor->RemoveOrphanNodes();
3042               SUIT_MessageBox::information(SMESHGUI::desktop(),
3043                                            tr("SMESH_INFORMATION"),
3044                                            tr("NB_NODES_REMOVED").arg(removed));
3045               if ( removed > 0 ) {
3046                 SMESH::UpdateView();
3047                 SMESHGUI::Modified();
3048               }
3049             }
3050             catch (const SALOME::SALOME_Exception& S_ex) {
3051               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3052             }
3053             catch (...) {
3054             }
3055           }
3056         }
3057       }
3058       break;
3059     }
3060   case 4051:                                    // RENUMBERING NODES
3061     {
3062       if(checkLock(aStudy)) break;
3063       if( vtkwnd ) {
3064         EmitSignalDeactivateDialog();
3065         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3066       }
3067       else
3068         {
3069           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3070                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3071         }
3072       break;
3073     }
3074   case 4052:                                    // RENUMBERING ELEMENTS
3075     {
3076       if(checkLock(aStudy)) break;
3077       if ( vtkwnd ) {
3078         EmitSignalDeactivateDialog();
3079         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3080       }
3081       else
3082         {
3083           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3084                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3085         }
3086       break;
3087     }
3088   case 4061:                                   // TRANSLATION
3089     {
3090       if(checkLock(aStudy)) break;
3091       if ( vtkwnd ) {
3092         EmitSignalDeactivateDialog();
3093         ( new SMESHGUI_TranslationDlg( this ) )->show();
3094       }
3095       else {
3096         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3097                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3098       }
3099       break;
3100     }
3101   case 4062:                                   // ROTATION
3102     {
3103       if(checkLock(aStudy)) break;
3104       if( vtkwnd ) {
3105         EmitSignalDeactivateDialog();
3106         ( new SMESHGUI_RotationDlg( this ) )->show();
3107       }
3108       else {
3109         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3110                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3111       }
3112       break;
3113     }
3114   case 4063:                                   // SYMMETRY
3115     {
3116       if(checkLock(aStudy)) break;
3117       if(vtkwnd) {
3118         EmitSignalDeactivateDialog();
3119         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3120       }
3121       else {
3122         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3123                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3124       }
3125       break;
3126     }
3127   case 4064:                                   // SEWING
3128     {
3129       if(checkLock(aStudy)) break;
3130       if(vtkwnd) {
3131         EmitSignalDeactivateDialog();
3132         ( new SMESHGUI_SewingDlg( this ) )->show();
3133       }
3134       else {
3135         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3136                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3137       }
3138       break;
3139     }
3140   case 4065:                                   // MERGE NODES
3141     {
3142       if(checkLock(aStudy)) break;
3143       if(vtkwnd) {
3144         EmitSignalDeactivateDialog();
3145         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3146       }
3147       else {
3148         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3149                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3150       }
3151       break;
3152     }
3153   case 4066:                                   // MERGE EQUAL ELEMENTS
3154     {
3155       if (checkLock(aStudy)) break;
3156       if (vtkwnd) {
3157         EmitSignalDeactivateDialog();
3158         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3159       } else {
3160         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3161                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3162       }
3163       break;
3164     }
3165
3166   case 4067: // MAKE MESH PASS THROUGH POINT
3167     startOperation( 4067 );
3168     break;
3169
3170   case 4068: // SCALE
3171     {
3172       if(checkLock(aStudy)) break;
3173       if ( vtkwnd ) {
3174         EmitSignalDeactivateDialog();
3175         ( new SMESHGUI_ScaleDlg( this ) )->show();
3176       }
3177       else {
3178         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3179                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3180       }
3181       break;
3182     }
3183
3184   case 4069: // DUPLICATE NODES
3185     {
3186       if(checkLock(aStudy)) break;
3187       if ( vtkwnd ) {
3188         EmitSignalDeactivateDialog();
3189         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3190       }
3191       else {
3192         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3193                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3194       }
3195       break;
3196     }
3197
3198   case 5105: // Library of selection filters
3199   {
3200     static QList<int> aTypes;
3201     if ( aTypes.isEmpty() )
3202     {
3203       aTypes.append( SMESH::NODE );
3204       aTypes.append( SMESH::EDGE );
3205       aTypes.append( SMESH::FACE );
3206       aTypes.append( SMESH::VOLUME );
3207     }
3208     if (!myFilterLibraryDlg)
3209       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3210     else if (myFilterLibraryDlg->isHidden())
3211       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3212     myFilterLibraryDlg->raise();
3213   }
3214   break;
3215
3216   case 6017:                                    // CONTROLS
3217   case 6016:
3218   case 6015:
3219   case 6014:
3220   case 6013:
3221   case 6012:
3222   case 6011:
3223   case 6001:
3224   case 6018:
3225   case 6019:
3226   case 6002:
3227   case 6003:
3228   case 6004:
3229   case 6005:
3230   case 6009:
3231   case 6021:
3232   case 6022:
3233   case 6023:
3234   case 6024:
3235   case 6025:
3236   case 6026:
3237   case 6027:
3238   case 6028:
3239   case 6029:
3240   case 6030:
3241   case 6031:
3242     if ( vtkwnd ) {
3243
3244       LightApp_SelectionMgr* mgr = selectionMgr();
3245       SALOME_ListIO selected; mgr->selectedObjects( selected );
3246
3247       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
3248         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
3249         if ( SO ) {
3250           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
3251           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
3252           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
3253           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
3254           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
3255             ::Control( theCommandID );
3256             break;
3257           }
3258         }
3259       }
3260       SUIT_MessageBox::warning(desktop(),
3261                                tr( "SMESH_WRN_WARNING" ),
3262                                tr( "SMESH_BAD_SELECTION" ) );
3263       break;
3264     }
3265     else {
3266       SUIT_MessageBox::warning(desktop(),
3267                                tr( "SMESH_WRN_WARNING" ),
3268                                tr( "NOT_A_VTK_VIEWER" ) );
3269     }
3270     break;
3271   case 9010:
3272     {
3273       LightApp_SelectionMgr* mgr = selectionMgr();
3274       SALOME_ListIO selected; mgr->selectedObjects( selected );
3275
3276       SALOME_ListIteratorOfListIO it(selected);
3277       for( ; it.More(); it.Next()) {
3278         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3279         if(anIObject->hasEntry()) {
3280           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3281             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3282           }
3283         }
3284       }
3285       break;
3286     }
3287   case 9011:
3288     {
3289       LightApp_SelectionMgr* mgr = selectionMgr();
3290       SALOME_ListIO selected; mgr->selectedObjects( selected );
3291
3292       SALOME_ListIteratorOfListIO it(selected);
3293       for( ; it.More(); it.Next()) {
3294         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3295         if(anIObject->hasEntry())
3296           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3297             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3298           }
3299       }
3300       break;
3301     }
3302   case 501:
3303   case 502:
3304     {
3305       int page = theCommandID == 501 ? SMESHGUI_MeasureDlg::MinDistance : SMESHGUI_MeasureDlg::BoundingBox;
3306       EmitSignalDeactivateDialog();
3307       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3308       dlg->show();
3309       break;
3310     }
3311   }
3312
3313   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3314   //updateObjBrowser();
3315   return true;
3316 }
3317
3318 //=============================================================================
3319 /*!
3320  *
3321  */
3322 //=============================================================================
3323 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3324 {
3325   return false;
3326 }
3327
3328 //=============================================================================
3329 /*!
3330  *
3331  */
3332 //=============================================================================
3333 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3334 {
3335   return true;
3336 }
3337
3338 //=============================================================================
3339 /*!
3340  *
3341  */
3342 //=============================================================================
3343 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
3344 {
3345   return true;
3346 }
3347
3348 //=============================================================================
3349 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3350  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3351  */
3352 //=============================================================================
3353 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3354                                   SUIT_ViewWindow* wnd )
3355 {
3356   if(theIO->hasEntry()){
3357     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3358     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3359   }
3360 }
3361
3362 //=======================================================================
3363 // function : createSMESHAction
3364 // purpose  :
3365 //=======================================================================
3366 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
3367                                   const int key, const bool toggle, const QString& shortcutAction  )
3368 {
3369   QIcon icon;
3370   QWidget* parent = application()->desktop();
3371   SUIT_ResourceMgr* resMgr = resourceMgr();
3372   QPixmap pix;
3373   if ( !icon_id.isEmpty() )
3374     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3375   else
3376     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
3377   if ( !pix.isNull() )
3378     icon = QIcon( pix );
3379
3380   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
3381           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
3382           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
3383
3384   createAction( id, tooltip, icon, menu, status_bar, key, parent,
3385                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
3386 }
3387
3388 //=======================================================================
3389 // function : createPopupItem
3390 // purpose  :
3391 //=======================================================================
3392 void SMESHGUI::createPopupItem( const int id,
3393                                 const QString& clients,
3394                                 const QString& types,
3395                                 const QString& theRule,
3396                                 const int pId )
3397 {
3398   int parentId = pId;
3399   if( pId!=-1 )
3400     parentId = popupMgr()->actionId( action( pId ) );
3401
3402   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
3403     popupMgr()->insert( action( id ), parentId, 0 );
3404
3405   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3406   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
3407   QString rule = "(%1) and (%2) and (%3)";
3408   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
3409   if( clients.isEmpty() )
3410     rule = rule.arg( QString( "true" ) );
3411   else
3412     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
3413   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
3414   rule += theRule;
3415
3416   bool cont = myRules.contains( id );
3417   if( cont )
3418     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
3419
3420   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
3421   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
3422 }
3423
3424 //=======================================================================
3425 // function : initialize
3426 // purpose  :
3427 //=======================================================================
3428 void SMESHGUI::initialize( CAM_Application* app )
3429 {
3430   SalomeApp_Module::initialize( app );
3431
3432 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
3433 //   if ( mgr )
3434   /* Automatic Update flag */
3435 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
3436
3437   // ----- create actions --------------
3438
3439   createSMESHAction(  111, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
3440   createSMESHAction(  112, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_U) );
3441   createSMESHAction(  113, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
3442   createSMESHAction(  114, "NUM" );
3443   createSMESHAction(  115, "IMPORT_STL" );
3444   createSMESHAction(  116, "IMPORT_CGNS" );
3445   createSMESHAction(  117, "IMPORT_SAUV" );
3446   createSMESHAction(  121, "DAT" );
3447   createSMESHAction(  122, "MED" );
3448   createSMESHAction(  123, "UNV" );
3449   createSMESHAction(  140, "STL" );
3450   createSMESHAction(  142, "CGNS" );
3451   createSMESHAction(  144, "SAUV" );
3452   createSMESHAction(  124, "EXPORT_DAT" );
3453   createSMESHAction(  125, "EXPORT_MED" );
3454   createSMESHAction(  126, "EXPORT_UNV" );
3455   createSMESHAction(  141, "EXPORT_STL" );
3456   createSMESHAction(  143, "EXPORT_CGNS" );
3457   createSMESHAction(  145, "EXPORT_SAUV" );
3458   createSMESHAction(  150, "FILE_INFO" );
3459   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
3460   createSMESHAction( 5105, "SEL_FILTER_LIB" );
3461   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
3462   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
3463   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
3464   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
3465   createSMESHAction(  705, "COPY_MESH",       "ICON_COPY_MESH" );
3466   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
3467   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
3468   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
3469   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
3470   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
3471   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
3472   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
3473   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
3474   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
3475   createSMESHAction(  804, "ADD" );
3476   createSMESHAction(  805, "REMOVE" );
3477   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
3478   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
3479   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
3480   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
3481   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
3482   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
3483   //createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
3484   //createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3485   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
3486   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
3487   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
3488   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
3489   createSMESHAction( 6022, "MAX_ELEMENT_LENGTH_2D",  "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
3490   createSMESHAction( 6023, "MAX_ELEMENT_LENGTH_3D",  "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
3491   createSMESHAction( 6024, "BARE_BORDER_VOLUME",     "ICON_BARE_BORDER_VOLUME",      0, true );
3492   createSMESHAction( 6025, "BARE_BORDER_FACE",       "ICON_BARE_BORDER_FACE",        0, true );
3493   createSMESHAction( 6026, "OVER_CONSTRAINED_VOLUME","ICON_OVER_CONSTRAINED_VOLUME", 0, true );
3494   createSMESHAction( 6027, "OVER_CONSTRAINED_FACE",  "ICON_OVER_CONSTRAINED_FACE",   0, true );
3495   createSMESHAction( 6028, "EQUAL_NODE",      "ICON_EQUAL_NODE",    0, true );
3496   createSMESHAction( 6029, "EQUAL_EDGE",      "ICON_EQUAL_EDGE",    0, true );
3497   createSMESHAction( 6030, "EQUAL_FACE",      "ICON_EQUAL_FACE",    0, true );
3498   createSMESHAction( 6031, "EQUAL_VOLUME",    "ICON_EQUAL_VOLUME",  0, true );
3499   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
3500   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
3501   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
3502   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
3503   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
3504   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
3505   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
3506   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
3507   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
3508   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
3509   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
3510   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
3511   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
3512   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
3513   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
3514   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
3515   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
3516   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
3517   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
3518   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
3519   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
3520   createSMESHAction( 4133, "PENTA",           "ICON_DLG_PENTA" );
3521   createSMESHAction( 4134, "PYRAMID",         "ICON_DLG_PYRAMID" );
3522   createSMESHAction( 4135, "OCTA",            "ICON_DLG_OCTA" );
3523   createSMESHAction( 4033, "POLYHEDRON",              "ICON_DLG_POLYHEDRON" );
3524   createSMESHAction( 4034, "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
3525   createSMESHAction( 4035, "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
3526   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
3527   createSMESHAction( 4136, "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
3528   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3529   createSMESHAction( 4038, "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
3530   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3531   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3532   createSMESHAction( 4140, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
3533   createSMESHAction( 4041, "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
3534   createSMESHAction( 4042, "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
3535   createSMESHAction( 4044, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
3536   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
3537   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
3538   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
3539   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
3540   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
3541   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
3542   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
3543   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
3544   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
3545   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
3546   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
3547   createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
3548   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
3549   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
3550   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
3551   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
3552   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
3553   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
3554   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
3555   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
3556   createSMESHAction(  415, "MAP",             "ICON_MAP" );
3557   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
3558   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
3559   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
3560   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
3561   createSMESHAction(  200, "RESET" );
3562   createSMESHAction(  201, "SCALAR_BAR_PROP" );
3563   createSMESHAction(  2021, "SAVE_DISTRIBUTION" );
3564   createSMESHAction(  2022, "SHOW_DISTRIBUTION","",0, true );
3565 #ifndef DISABLE_PLOT2DVIEWER
3566   createSMESHAction(  2023, "PLOT_DISTRIBUTION" );
3567 #endif
3568   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
3569   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
3570   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
3571   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
3572   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
3573   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
3574   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
3575   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
3576   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3577   createSMESHAction(  220, "ALL" );
3578   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3579
3580   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3581   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3582
3583   createSMESHAction( 1100, "EDIT_HYPO" );
3584   createSMESHAction( 1102, "UNASSIGN" );
3585   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3586   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3587   createSMESHAction( 1131, "DISPMODE" );
3588   createSMESHAction( 1132, "COLORS" );
3589   createSMESHAction( 1133, "TRANSP" );
3590   createSMESHAction( 1134, "CLIP" );
3591   createSMESHAction( 1135, "DISP_ENT" );
3592   createSMESHAction( 1136, "AUTO_COLOR" );
3593   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3594   createSMESHAction( 2000, "CTRL" );
3595
3596   createSMESHAction( 501, "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
3597   createSMESHAction( 502, "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
3598
3599   createSMESHAction( 300, "HIDE" );
3600   createSMESHAction( 301, "SHOW" );
3601   createSMESHAction( 302, "DISPLAY_ONLY" );
3602
3603   // ----- create menu --------------
3604   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
3605       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
3606       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
3607       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
3608       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
3609       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
3610       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
3611       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
3612
3613   createMenu( separator(), fileId );
3614
3615   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3616       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3617       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10 ),
3618       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10 ),
3619       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10 ),
3620       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10 ),
3621       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3622       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3623       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3624       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
3625
3626   createMenu( 111, importId, -1 );
3627   createMenu( 112, importId, -1 );
3628   createMenu( 113, importId, -1 );
3629   createMenu( 115, importId, -1 );
3630 #ifdef WITH_CGNS
3631   createMenu( 116, importId, -1 );
3632 #endif
3633   createMenu( 117, importId, -1 );
3634   createMenu( 121, exportId, -1 );
3635   createMenu( 122, exportId, -1 );
3636   createMenu( 123, exportId, -1 );
3637   createMenu( 140, exportId, -1 ); // export to STL
3638 #ifdef WITH_CGNS
3639   createMenu( 142, exportId, -1 ); // export to CGNS
3640 #endif
3641   createMenu( 144, exportId, -1 ); // export to SAUV
3642   createMenu( separator(), fileId, 10 );
3643
3644   createMenu( 33, editId, -1 );
3645
3646   createMenu( 5105, toolsId, -1 );
3647
3648   createMenu( 702, meshId, -1 ); // "Mesh" menu
3649   createMenu( 703, meshId, -1 );
3650   createMenu( 704, meshId, -1 );
3651   createMenu( 710, meshId, -1 );
3652   createMenu( 705, meshId, -1 );
3653   createMenu( separator(), meshId, -1 );
3654   createMenu( 701, meshId, -1 );
3655   createMenu( 711, meshId, -1 );
3656   createMenu( 712, meshId, -1 );
3657   createMenu( 713, meshId, -1 );
3658   createMenu( separator(), meshId, -1 );
3659   createMenu( 801, meshId, -1 );
3660   createMenu( 806, meshId, -1 );
3661   createMenu( 802, meshId, -1 );
3662   createMenu( 803, meshId, -1 );
3663   createMenu( 815, meshId, -1 );
3664   createMenu( separator(), meshId, -1 );
3665   createMenu( 810, meshId, -1 );
3666   createMenu( 811, meshId, -1 );
3667   createMenu( 812, meshId, -1 );
3668   createMenu( separator(), meshId, -1 );
3669   createMenu( 814, meshId, -1 );
3670   createMenu( separator(), meshId, -1 );
3671   createMenu( 900, meshId, -1 );
3672   //createMenu( 902, meshId, -1 );
3673   //createMenu( 903, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3674   createMenu( 904, meshId, -1 );
3675   createMenu( separator(), meshId, -1 );
3676
3677   createMenu( 6005, nodeId, -1 );
3678   createMenu( 6028, nodeId, -1 );
3679   createMenu( 6002, edgeId, -1 );
3680   createMenu( 6003, edgeId, -1 );
3681   createMenu( 6001, edgeId, -1 );
3682   createMenu( 6004, edgeId, -1 );
3683   createMenu( 6029, edgeId, -1 );
3684   createMenu( 6021, faceId, -1 );
3685   createMenu( 6025, faceId, -1 );
3686   createMenu( 6027, faceId, -1 );
3687   createMenu( 6018, faceId, -1 );
3688   createMenu( 6019, faceId, -1 );
3689   createMenu( 6011, faceId, -1 );
3690   createMenu( 6012, faceId, -1 );
3691   createMenu( 6013, faceId, -1 );
3692   createMenu( 6014, faceId, -1 );
3693   createMenu( 6015, faceId, -1 );
3694   createMenu( 6016, faceId, -1 );
3695   createMenu( 6022, faceId, -1 );
3696   createMenu( 6030, faceId, -1 );
3697   createMenu( 6017, volumeId, -1 );
3698   createMenu( 6009, volumeId, -1 );
3699   createMenu( 6023, volumeId, -1 );
3700   createMenu( 6024, volumeId, -1 );
3701   createMenu( 6026, volumeId, -1 );
3702   createMenu( 6031, volumeId, -1 );
3703
3704   createMenu( 4000, addId, -1 );
3705   createMenu( 4009, addId, -1 );
3706   createMenu( 4010, addId, -1 );
3707   createMenu( 4021, addId, -1 );
3708   createMenu( 4022, addId, -1 );
3709   createMenu( 4023, addId, -1 );
3710   createMenu( 4031, addId, -1 );
3711   createMenu( 4032, addId, -1 );
3712   createMenu( 4133, addId, -1 );
3713   createMenu( 4134, addId, -1 );
3714   createMenu( 4135, addId, -1 );
3715   createMenu( 4033, addId, -1 );
3716   createMenu( separator(), addId, -1 );
3717   createMenu( 4034, addId, -1 );
3718   createMenu( 4035, addId, -1 );
3719   createMenu( 4036, addId, -1 );
3720   createMenu( 4136, addId, -1 );
3721   createMenu( 4037, addId, -1 );
3722   createMenu( 4038, addId, -1 );
3723   createMenu( 4039, addId, -1 );
3724   createMenu( 4040, addId, -1 );
3725   createMenu( 4140, addId, -1 );
3726
3727   createMenu( 4041, removeId, -1 );
3728   createMenu( 4042, removeId, -1 );
3729   createMenu( 4044, removeId, -1 );
3730   createMenu( separator(), removeId, -1 );
3731   createMenu( 813, removeId, -1 );
3732   createMenu( separator(), removeId, -1 );
3733   createMenu( 4043, removeId, -1 );
3734
3735   createMenu( 4051, renumId, -1 );
3736   createMenu( 4052, renumId, -1 );
3737
3738   createMenu( 4061, transfId, -1 );
3739   createMenu( 4062, transfId, -1 );
3740   createMenu( 4063, transfId, -1 );
3741   createMenu( 4068, transfId, -1 );
3742   createMenu( 4064, transfId, -1 );
3743   createMenu( 4065, transfId, -1 );
3744   createMenu( 4066, transfId, -1 );
3745   createMenu( 4069, transfId, -1 );
3746
3747   createMenu( 4067,modifyId, -1 );
3748   createMenu( 407, modifyId, -1 );
3749   createMenu( 408, modifyId, -1 );
3750   createMenu( 409, modifyId, -1 );
3751   createMenu( 410, modifyId, -1 );
3752   createMenu( 411, modifyId, -1 );
3753   createMenu( 419, modifyId, -1 );
3754   createMenu( 412, modifyId, -1 );
3755   createMenu( 413, modifyId, -1 );
3756   createMenu( 416, modifyId, -1 );
3757   createMenu( 414, modifyId, -1 );
3758   createMenu( 415, modifyId, -1 );
3759   createMenu( 417, modifyId, -1 );
3760   createMenu( 418, modifyId, -1 );
3761
3762   createMenu( 501, measureId, -1 );
3763   createMenu( 502, measureId, -1 );
3764   createMenu( 214, viewId, -1 );
3765
3766   // ----- create toolbars --------------
3767   int meshTb     = createTool( tr( "TB_MESH" ) ),
3768       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3769       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3770       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3771       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3772
3773   createTool( 702, meshTb );
3774   createTool( 703, meshTb );
3775   createTool( 704, meshTb );
3776   createTool( 710, meshTb );
3777   createTool( 705, meshTb );
3778   createTool( separator(), meshTb );
3779   createTool( 701, meshTb );
3780   createTool( 711, meshTb );
3781   createTool( 712, meshTb );
3782   createTool( 713, meshTb );
3783   createTool( separator(), meshTb );
3784   createTool( 801, meshTb );
3785   createTool( 806, meshTb );
3786   createTool( 802, meshTb );
3787   createTool( 803, meshTb );
3788   //createTool( 815, meshTb );
3789   createTool( separator(), meshTb );
3790   createTool( 900, meshTb );
3791   //createTool( 902, meshTb );
3792   //createTool( 903, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3793   createTool( 904, meshTb );
3794   createTool( separator(), meshTb );
3795
3796   createTool( 6005, ctrlTb );
3797   createTool( 6028, ctrlTb );
3798   createTool( separator(), ctrlTb );
3799   createTool( 6002, ctrlTb );
3800   createTool( 6003, ctrlTb );
3801   createTool( 6001, ctrlTb );
3802   createTool( 6004, ctrlTb );
3803   createTool( 6029, ctrlTb );
3804   createTool( separator(), ctrlTb );
3805   createTool( 6021, ctrlTb );
3806   createTool( 6025, ctrlTb );
3807   createTool( 6027, ctrlTb );
3808   createTool( 6018, ctrlTb );
3809   createTool( 6019, ctrlTb );
3810   createTool( 6011, ctrlTb );
3811   createTool( 6012, ctrlTb );
3812   createTool( 6013, ctrlTb );
3813   createTool( 6014, ctrlTb );
3814   createTool( 6015, ctrlTb );
3815   createTool( 6016, ctrlTb );
3816   createTool( 6022, ctrlTb );
3817   createTool( 6030, ctrlTb );
3818   createTool( separator(), ctrlTb );
3819   createTool( 6017, ctrlTb );
3820   createTool( 6009, ctrlTb );
3821   createTool( 6023, ctrlTb );
3822   createTool( 6024, ctrlTb );
3823   createTool( 6026, ctrlTb );
3824   createTool( 6031, ctrlTb );
3825   createTool( separator(), ctrlTb );
3826
3827   createTool( 4000, addRemTb );
3828   createTool( 4009, addRemTb );
3829   createTool( 4010, addRemTb );
3830   createTool( 4021, addRemTb );
3831   createTool( 4022, addRemTb );
3832   createTool( 4023, addRemTb );
3833   createTool( 4031, addRemTb );
3834   createTool( 4032, addRemTb );
3835   createTool( 4133, addRemTb );
3836   createTool( 4134, addRemTb );
3837   createTool( 4135, addRemTb );
3838   createTool( 4033, addRemTb );
3839   createTool( separator(), addRemTb );
3840   createTool( 4034, addRemTb );
3841   createTool( 4035, addRemTb );
3842   createTool( 4036, addRemTb );
3843   createTool( 4136, addRemTb );
3844   createTool( 4037, addRemTb );
3845   createTool( 4038, addRemTb );
3846   createTool( 4039, addRemTb );
3847   createTool( 4040, addRemTb );
3848   createTool( 4140, addRemTb );
3849   createTool( separator(), addRemTb );
3850   createTool( 4041, addRemTb );
3851   createTool( 4042, addRemTb );
3852   createTool( 4044, addRemTb );
3853   createTool( 4043, addRemTb );
3854   createTool( separator(), addRemTb );
3855   createTool( 4051, addRemTb );
3856   createTool( 4052, addRemTb );
3857   createTool( separator(), addRemTb );
3858   createTool( 4061, addRemTb );
3859   createTool( 4062, addRemTb );
3860   createTool( 4063, addRemTb );
3861   createTool( 4068, addRemTb );
3862   createTool( 4064, addRemTb );
3863   createTool( 4065, addRemTb );
3864   createTool( 4066, addRemTb );
3865   createTool( 4069, addRemTb );
3866   createTool( separator(), addRemTb );
3867
3868   createTool( 4067,modifyTb );
3869   createTool( 407, modifyTb );
3870   createTool( 408, modifyTb );
3871   createTool( 409, modifyTb );
3872   createTool( 410, modifyTb );
3873   createTool( 411, modifyTb );
3874   createTool( 419, modifyTb );
3875   createTool( 412, modifyTb );
3876   createTool( 413, modifyTb );
3877   createTool( 416, modifyTb );
3878   createTool( 414, modifyTb );
3879   createTool( 415, modifyTb );
3880   createTool( 417, modifyTb );
3881   createTool( 418, modifyTb );
3882
3883   createTool( 214, dispModeTb );
3884
3885   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3886   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3887
3888   myRules.clear();
3889   QString OB = "'ObjectBrowser'",
3890           View = "'" + SVTK_Viewer::Type() + "'",
3891           pat = "'%1'",
3892           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3893           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3894           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3895           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3896           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3897                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3898                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3899                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3900                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3901                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3902                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3903           subMesh = elems,
3904           mesh_part = mesh + " " + subMesh + " " + group,
3905           mesh_group = mesh + " " + group,
3906           hyp_alg = hypo + " " + algo;
3907
3908   // popup for object browser
3909   QString
3910     isInvisible("not( isVisible )"),
3911     isEmpty("numberOfNodes = 0"),
3912     isNotEmpty("numberOfNodes <> 0"),
3913
3914     // has nodes, edges, etc in VISIBLE! actor
3915     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3916     hasElems("(count( elemTypes ) > 0)"),
3917     hasDifferentElems("(count( elemTypes ) > 1)"),
3918     hasElems0d("({'Elem0d'} in elemTypes)"),
3919     hasEdges("({'Edge'} in elemTypes)"),
3920     hasFaces("({'Face'} in elemTypes)"),
3921     hasVolumes("({'Volume'} in elemTypes)");
3922
3923   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3924   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3925   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3926   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3927   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3928   createPopupItem( 815, OB, group, "&& groupType != 'Group'" ); // EDIT AS STANDALONE
3929
3930   popupMgr()->insert( separator(), -1, 0 );
3931   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3932   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3933   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
3934   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
3935   createPopupItem( 214, OB, mesh_part );                   // UPDATE
3936   createPopupItem( 900, OB, mesh_part );                   // ADV_INFO
3937   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
3938   popupMgr()->insert( separator(), -1, 0 );
3939   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3940   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3941   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3942   popupMgr()->insert( separator(), -1, 0 );
3943   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3944   createPopupItem( 1102, OB, hyp_alg );                    // REMOVE HYPOTHESIS / ALGORITHMS
3945   popupMgr()->insert( separator(), -1, 0 );
3946   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3947   popupMgr()->insert( separator(), -1, 0 );
3948   createPopupItem( 417, OB, mesh + " " + subMesh );        // convert to quadratic
3949   createPopupItem( 418, OB, mesh + " " + group,            // create 2D mesh from 3D
3950                    "&& dim>=2");
3951   popupMgr()->insert( separator(), -1, 0 );
3952
3953   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3954   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
3955   QString only_one_2D        = only_one_non_empty + " && dim>1";
3956
3957   createPopupItem( 125, OB, mesh_group, multiple_non_empty );   // EXPORT_MED
3958   createPopupItem( 126, OB, mesh_group, only_one_non_empty );   // EXPORT_UNV
3959   createPopupItem( 141, OB, mesh_group, only_one_2D );          // EXPORT_STL
3960 #ifdef WITH_CGNS
3961   createPopupItem( 143, OB, mesh_group, multiple_non_empty );   // EXPORT_CGNS
3962 #endif
3963   createPopupItem( 145, OB, mesh_group, multiple_non_empty );   // EXPORT_SAUV
3964   createPopupItem(  33, OB, mesh_part + " " + hyp_alg );        // DELETE
3965   createPopupItem( 813, OB, group );                            // DEL_GROUP with contents
3966   popupMgr()->insert( separator(), -1, 0 );
3967
3968   // popup for viewer
3969   createPopupItem( 803, View, group ); // EDIT_GROUP
3970   createPopupItem( 804, View, elems ); // ADD
3971   createPopupItem( 805, View, elems ); // REMOVE
3972
3973   popupMgr()->insert( separator(), -1, 0 );
3974   createPopupItem( 214, View, mesh_part );  // UPDATE
3975   createPopupItem( 900, View, mesh_part );  // ADV_INFO
3976   createPopupItem( 904, View, mesh );       // FIND_ELEM
3977   popupMgr()->insert( separator(), -1, 0 );
3978
3979   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3980   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3981   popupMgr()->insert( separator(), -1, 0 );
3982
3983   int anId;
3984   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3985   QString aType = QString( "%1type in {%2}" ).arg( lc );
3986   aType = aType.arg( mesh_part );
3987   QString aMeshInVTK = aClient + "&&" + aType;
3988
3989   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3990   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3991   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3992
3993   //-------------------------------------------------
3994   // Numbering
3995   //-------------------------------------------------
3996   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3997
3998   popupMgr()->insert( action( 9010 ), anId, -1 );
3999   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4000   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4001
4002   popupMgr()->insert( action( 9011 ), anId, -1 );
4003   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4004   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4005
4006   popupMgr()->insert( separator(), -1, -1 );
4007
4008   //-------------------------------------------------
4009   // Display Mode
4010   //-------------------------------------------------
4011   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4012
4013   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
4014   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4015   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4016
4017   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
4018   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4019   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4020
4021   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
4022   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
4023   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4024
4025   popupMgr()->insert( separator(), anId, -1 );
4026
4027   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
4028   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4029   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4030
4031   //-------------------------------------------------
4032   // Display Entity
4033   //-------------------------------------------------
4034   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4035
4036   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4037
4038   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
4039   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4040   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4041
4042   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
4043   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4044   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4045
4046   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
4047   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4048   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4049
4050   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
4051   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4052   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4053
4054   popupMgr()->insert( separator(), anId, -1 );
4055
4056   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
4057   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4058
4059
4060   //-------------------------------------------------
4061   // Representation of the 2D Quadratic elements
4062   //-------------------------------------------------
4063   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4064   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
4065   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
4066   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4067
4068   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
4069   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
4070   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4071
4072   //-------------------------------------------------
4073   // Orientation of faces
4074   //-------------------------------------------------
4075   popupMgr()->insert( action( 221 ), -1, -1 );
4076   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4077   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4078
4079   //-------------------------------------------------
4080   // Color / Size
4081   //-------------------------------------------------
4082   popupMgr()->insert( action( 1132 ), -1, -1 );
4083   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4084
4085   //-------------------------------------------------
4086   // Transparency
4087   //-------------------------------------------------
4088   popupMgr()->insert( action( 1133 ), -1, -1 );
4089   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4090
4091   //-------------------------------------------------
4092   // Controls
4093   //-------------------------------------------------
4094   QString
4095     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
4096     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
4097     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
4098     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4099
4100   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4101
4102   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
4103   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4104
4105   popupMgr()->insert( separator(), anId, -1 );
4106
4107   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4108
4109   popupMgr()->insert( action( 6005 ), aSubId, -1 ); // FREE_NODE
4110   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4111   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4112
4113   popupMgr()->insert ( action( 6028 ), aSubId, -1 ); // EQUAL_NODE
4114   popupMgr()->setRule( action( 6028 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4115   popupMgr()->setRule( action( 6028 ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4116
4117   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4118
4119   popupMgr()->insert( action( 6002 ), aSubId, -1 ); // FREE_EDGE
4120   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4121   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4122
4123   popupMgr()->insert( action( 6003 ), aSubId, -1 ); // FREE_BORDER
4124   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4125   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4126
4127   popupMgr()->insert( action( 6001 ), aSubId, -1 ); // LENGTH
4128   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4129   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4130
4131   popupMgr()->insert( action( 6004 ), aSubId, -1 ); // CONNECTION
4132   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4133   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4134   popupMgr()->insert ( action( 6029 ), aSubId, -1 ); // EQUAL_EDGE
4135   popupMgr()->setRule( action( 6029 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4136   popupMgr()->setRule( action( 6029 ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4137
4138   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4139
4140   popupMgr()->insert ( action( 6021 ), aSubId, -1 ); // FREE_FACE
4141   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4142                                        QtxPopupMgr::VisibleRule );
4143   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4144
4145   popupMgr()->insert ( action( 6018 ), aSubId, -1 ); // LENGTH_2D
4146   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4147   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4148
4149   popupMgr()->insert ( action( 6019 ), aSubId, -1 ); // CONNECTION_2D
4150   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4151   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4152
4153   popupMgr()->insert ( action( 6011 ), aSubId, -1 ); // AREA
4154   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4155   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4156
4157   popupMgr()->insert ( action( 6012 ), aSubId, -1 ); // TAPER
4158   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4159   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4160
4161   popupMgr()->insert ( action( 6013 ), aSubId, -1 ); // ASPECT
4162   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4163   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4164
4165   popupMgr()->insert ( action( 6014 ), aSubId, -1 ); // MIN_ANG
4166   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4167   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4168
4169   popupMgr()->insert ( action( 6015 ), aSubId, -1 ); // WARP
4170   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4171   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4172
4173   popupMgr()->insert ( action( 6016 ), aSubId, -1 ); // SKEW
4174   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4175   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4176
4177   popupMgr()->insert ( action( 6022 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_2D
4178   popupMgr()->setRule( action( 6022 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4179   popupMgr()->setRule( action( 6022 ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4180
4181   popupMgr()->insert ( action( 6025 ), aSubId, -1 ); // BARE_BORDER_FACE
4182   popupMgr()->setRule( action( 6025 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4183   popupMgr()->setRule( action( 6025 ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4184
4185   popupMgr()->insert ( action( 6027 ), aSubId, -1 ); // OVER_CONSTRAINED_FACE
4186   popupMgr()->setRule( action( 6027 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4187   popupMgr()->setRule( action( 6027 ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4188   popupMgr()->insert ( action( 6030 ), aSubId, -1 ); // EQUAL_FACE
4189   popupMgr()->setRule( action( 6030 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4190   popupMgr()->setRule( action( 6030 ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4191
4192   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4193
4194   popupMgr()->insert ( action( 6017 ), aSubId, -1 ); // ASPECT_3D
4195   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4196   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4197
4198   popupMgr()->insert ( action( 6009 ), aSubId, -1 ); // VOLUME_3D
4199   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4200   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4201
4202   popupMgr()->insert ( action( 6023 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_3D
4203   popupMgr()->setRule( action( 6023 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4204   popupMgr()->setRule( action( 6023 ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4205
4206   popupMgr()->insert ( action( 6024 ), aSubId, -1 ); // BARE_BORDER_VOLUME
4207   popupMgr()->setRule( action( 6024 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4208   popupMgr()->setRule( action( 6024 ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4209
4210   popupMgr()->insert ( action( 6026 ), aSubId, -1 ); // OVER_CONSTRAINED_VOLUME
4211   popupMgr()->setRule( action( 6026 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4212   popupMgr()->setRule( action( 6026 ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4213
4214   popupMgr()->insert ( action( 6031 ), aSubId, -1 ); // EQUAL_VOLUME
4215   popupMgr()->setRule( action( 6031 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4216   popupMgr()->setRule( action( 6031 ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
4217
4218   popupMgr()->insert( separator(), anId, -1 );
4219
4220   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
4221   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4222
4223   popupMgr()->insert( separator(), anId, -1 );
4224
4225   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4226
4227   popupMgr()->insert( action( 2021 ), aSubId, -1 ); // SAVE_DISTRIBUTION
4228   popupMgr()->setRule( action( 2021 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4229
4230   popupMgr()->insert( action( 2022 ), aSubId, -1 ); // SHOW_DISTRIBUTION
4231   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4232   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor && isDistributionVisible", QtxPopupMgr::ToggleRule);
4233
4234 #ifndef DISABLE_PLOT2DVIEWER
4235   popupMgr()->insert( action( 2023 ), aSubId, -1 ); // PLOT_DISTRIBUTION
4236   popupMgr()->setRule( action( 2023 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4237 #endif
4238
4239   //-------------------------------------------------
4240   // Display / Erase
4241   //-------------------------------------------------
4242   popupMgr()->insert( separator(), -1, -1 );
4243   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4244     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4245   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
4246   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4247
4248   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
4249   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4250
4251   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
4252   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4253
4254   popupMgr()->insert( separator(), -1, -1 );
4255
4256   //-------------------------------------------------
4257   // Clipping
4258   //-------------------------------------------------
4259   popupMgr()->insert( action( 1134 ), -1, -1 );
4260   popupMgr()->setRule( action( 1134 ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4261
4262   popupMgr()->insert( separator(), -1, -1 );
4263
4264   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4265            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4266
4267   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4268            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4269 }
4270
4271 //================================================================================
4272 /*!
4273  * \brief Return true if SMESH or GEOM objects are selected.
4274  * Is called form LightApp_Module::activateModule() which clear selection if
4275  * not isSelectionCompatible()
4276  */
4277 //================================================================================
4278
4279 bool SMESHGUI::isSelectionCompatible()
4280 {
4281   bool isCompatible = true;
4282   SALOME_ListIO selected;
4283   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4284     Sel->selectedObjects( selected );
4285
4286   SALOME_ListIteratorOfListIO It( selected );
4287   for ( ; isCompatible && It.More(); It.Next())
4288     isCompatible =
4289       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4290       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4291
4292   return isCompatible;
4293 }
4294
4295
4296 bool SMESHGUI::reusableOperation( const int id )
4297 {
4298   // compute, evaluate and precompute are not reusable operations
4299   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
4300 }
4301
4302 bool SMESHGUI::activateModule( SUIT_Study* study )
4303 {
4304   bool res = SalomeApp_Module::activateModule( study );
4305
4306   setMenuShown( true );
4307   setToolShown( true );
4308
4309   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4310   PyGILState_STATE gstate = PyGILState_Ensure();
4311   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
4312   if(pluginsmanager==NULL)
4313     PyErr_Print();
4314   else
4315     {
4316       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
4317       if(result==NULL)
4318         PyErr_Print();
4319       Py_XDECREF(result);
4320     }
4321   PyGILState_Release(gstate);
4322   // end of GEOM plugins loading
4323
4324   // Reset actions accelerator keys
4325   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
4326   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
4327   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
4328
4329   action(  33)->setEnabled(true); // Delete: Key_Delete
4330
4331   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4332   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
4333   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
4334     if ( _PTR(Study) aStudy = s->studyDS()) {
4335       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
4336       updateObjBrowser(); // objects can be removed
4337     }
4338
4339   // get all view currently opened in the study and connect their signals  to
4340   // the corresponding slots of the class.
4341   SUIT_Desktop* aDesk = study->application()->desktop();
4342   if ( aDesk ) {
4343     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4344     SUIT_ViewWindow* wnd;
4345     foreach ( wnd, wndList )
4346       connectView( wnd );
4347   }
4348
4349   return res;
4350 }
4351
4352 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4353 {
4354   setMenuShown( false );
4355   setToolShown( false );
4356
4357   EmitSignalCloseAllDialogs();
4358
4359   // Unset actions accelerator keys
4360   action(111)->setShortcut(QKeySequence()); // Import DAT
4361   action(112)->setShortcut(QKeySequence()); // Import UNV
4362   action(113)->setShortcut(QKeySequence()); // Import MED
4363
4364   action(  33)->setEnabled(false); // Delete: Key_Delete
4365
4366   return SalomeApp_Module::deactivateModule( study );
4367 }
4368
4369 void SMESHGUI::studyClosed( SUIT_Study* s )
4370 {
4371   SMESH::RemoveVisuData( s->id() );
4372   SalomeApp_Module::studyClosed( s );
4373 }
4374
4375 void SMESHGUI::OnGUIEvent()
4376 {
4377   const QObject* obj = sender();
4378   if ( !obj || !obj->inherits( "QAction" ) )
4379     return;
4380   int id = actionId((QAction*)obj);
4381   if ( id != -1 )
4382     OnGUIEvent( id );
4383 }
4384
4385 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
4386 {
4387   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
4388   if ( CORBA::is_nil( myComponentSMESH ) )
4389     {
4390       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
4391       if ( aStudy )
4392         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4393       return aGUI.myComponentSMESH;
4394     }
4395   if ( aStudy )
4396     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4397   return myComponentSMESH;
4398 }
4399
4400 QString SMESHGUI::engineIOR() const
4401 {
4402   CORBA::ORB_var anORB = getApp()->orb();
4403   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
4404   return QString( anIOR.in() );
4405 }
4406
4407 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
4408 {
4409   SalomeApp_Module::contextMenuPopup( client, menu, title );
4410   SALOME_ListIO lst;
4411   selectionMgr()->selectedObjects( lst );
4412   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
4413     Handle(SALOME_InteractiveObject) io = lst.First();
4414     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
4415     _PTR(Study) study = appStudy->studyDS();
4416     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
4417     if ( obj ) {
4418       QString aName = QString( obj->GetName().c_str() );
4419       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
4420           aName.remove( (aName.length() - 1), 1 );
4421       title = aName;
4422     }
4423   }
4424 }
4425
4426 LightApp_Selection* SMESHGUI::createSelection() const
4427 {
4428   return new SMESHGUI_Selection();
4429 }
4430
4431 void SMESHGUI::windows( QMap<int, int>& aMap ) const
4432 {
4433   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
4434   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
4435 }
4436
4437 void SMESHGUI::viewManagers( QStringList& list ) const
4438 {
4439   list.append( SVTK_Viewer::Type() );
4440 }
4441
4442 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
4443 {
4444   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
4445     SMESH::UpdateSelectionProp( this );
4446
4447     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
4448     for(int i = 0; i < aViews.count() ; i++){
4449       SUIT_ViewWindow *sf = aViews[i];
4450       connectView( sf );
4451     }
4452   }
4453 }
4454
4455 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
4456 {
4457   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
4458     myClippingPlaneInfoMap.erase( theViewManager );
4459 }
4460
4461 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
4462 {
4463   theActor->AddObserver( SMESH::DeleteActorEvent,
4464                          myEventCallbackCommand.GetPointer(),
4465                          myPriority );
4466 }
4467
4468 void SMESHGUI::ProcessEvents( vtkObject* theObject,
4469                               unsigned long theEvent,
4470                               void* theClientData,
4471                               void* theCallData )
4472 {
4473   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
4474     if( theObject && theEvent == SMESH::DeleteActorEvent ) {
4475       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
4476         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
4477         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
4478         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
4479           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
4480           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
4481           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
4482             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
4483             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
4484             SMESH::TActorList::iterator anIter3 = anActorList.begin();
4485             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
4486               if( anActor == *anIter3 ) {
4487                 anActorList.erase( anIter3 );
4488                 break;
4489               }
4490             }
4491           }
4492         }
4493       }
4494     }
4495   }
4496 }
4497
4498 void SMESHGUI::createPreferences()
4499 {
4500   // General tab ------------------------------------------------------------------------
4501   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
4502
4503   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
4504   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
4505   setPreferenceProperty( lim, "min",  0 );
4506   setPreferenceProperty( lim, "max",  100000000 );
4507   setPreferenceProperty( lim, "step", 1000 );
4508   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4509
4510   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
4511   setPreferenceProperty( qaGroup, "columns", 2 );
4512   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
4513   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
4514   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
4515   setPreferenceProperty( prec, "min", 0 );
4516   setPreferenceProperty( prec, "max", 16 );
4517   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
4518   setPreferenceProperty( doubleNodesTol, "precision", 10 );
4519   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
4520   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
4521   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
4522
4523   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
4524   setPreferenceProperty( dispgroup, "columns", 2 );
4525   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
4526   QStringList modes;
4527   modes.append( tr("MEN_WIRE") );
4528   modes.append( tr("MEN_SHADE") );
4529   modes.append( tr("MEN_NODES") );
4530   modes.append( tr("MEN_SHRINK") );
4531   QList<QVariant> indices;
4532   indices.append( 0 );
4533   indices.append( 1 );
4534   indices.append( 2 );
4535   indices.append( 3 );
4536   setPreferenceProperty( dispmode, "strings", modes );
4537   setPreferenceProperty( dispmode, "indexes", indices );
4538
4539   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
4540   setPreferenceProperty( arcgroup, "columns", 2 );
4541   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
4542   QStringList quadraticModes;
4543   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
4544   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
4545   indices.clear();
4546   indices.append( 0 );
4547   indices.append( 1 );
4548   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
4549   setPreferenceProperty( quadraticmode, "indexes", indices );
4550
4551   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
4552                               "SMESH", "max_angle" );
4553   setPreferenceProperty( maxAngle, "min", 1 );
4554   setPreferenceProperty( maxAngle, "max", 90 );
4555
4556
4557
4558   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
4559   setPreferenceProperty( exportgroup, "columns", 2 );
4560   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
4561   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
4562
4563   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
4564   setPreferenceProperty( computeGroup, "columns", 2 );
4565   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
4566   modes.clear();
4567   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
4568   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
4569   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
4570   indices.clear();
4571   indices.append( 0 );
4572   indices.append( 1 );
4573   indices.append( 2 );
4574   setPreferenceProperty( notifyMode, "strings", modes );
4575   setPreferenceProperty( notifyMode, "indexes", indices );
4576
4577   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
4578   setPreferenceProperty( infoGroup, "columns", 4 );
4579   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
4580   modes.clear();
4581   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
4582   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
4583   indices.clear();
4584   indices.append( 0 );
4585   indices.append( 1 );
4586   setPreferenceProperty( elemInfo, "strings", modes );
4587   setPreferenceProperty( elemInfo, "indexes", indices );
4588   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
4589   setPreferenceProperty( nodesLim, "min", 0 );
4590   setPreferenceProperty( nodesLim, "max", 10000000 );
4591   setPreferenceProperty( nodesLim, "step", 10000 );
4592   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4593
4594   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
4595   setPreferenceProperty( segGroup, "columns", 2 );
4596   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
4597                               "SMESH", "segmentation" );
4598   setPreferenceProperty( segLen, "min", 1 );
4599   setPreferenceProperty( segLen, "max", 10000000 );
4600   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
4601                              "SMESH", "nb_segments_per_edge" );
4602   setPreferenceProperty( nbSeg, "min", 1 );
4603   setPreferenceProperty( nbSeg, "max", 10000000 );
4604
4605   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
4606   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
4607                  "SMESH", "forget_mesh_on_hyp_modif" );
4608
4609
4610   // Quantities with individual precision settings
4611   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
4612   setPreferenceProperty( precGroup, "columns", 2 );
4613
4614   const int nbQuantities = 6;
4615   int precs[nbQuantities], ii = 0;
4616   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
4617                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
4618   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
4619                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
4620   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
4621                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
4622   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
4623                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
4624   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
4625                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
4626   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
4627                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
4628
4629   // Set property for precision value for spinboxes
4630   for ( ii = 0; ii < nbQuantities; ii++ ){
4631     setPreferenceProperty( precs[ii], "min", -14 );
4632     setPreferenceProperty( precs[ii], "max", 14 );
4633     setPreferenceProperty( precs[ii], "precision", 2 );
4634   }
4635
4636   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
4637   setPreferenceProperty( previewGroup, "columns", 2 );
4638   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
4639   setPreferenceProperty( chunkSize, "min",  0 );
4640   setPreferenceProperty( chunkSize, "max",  1000 );
4641   setPreferenceProperty( chunkSize, "step", 50 );
4642
4643   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
4644   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
4645
4646   // Mesh tab ------------------------------------------------------------------------
4647   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
4648   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
4649   setPreferenceProperty( nodeGroup, "columns", 3 );
4650
4651   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
4652
4653   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
4654
4655   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4656   QList<QVariant> aMarkerTypeIndicesList;
4657   QList<QVariant> aMarkerTypeIconsList;
4658   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
4659     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
4660     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
4661     aMarkerTypeIndicesList << i;
4662     aMarkerTypeIconsList << pixmap;
4663   }
4664   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
4665   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
4666
4667   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
4668
4669   QList<QVariant> aMarkerScaleIndicesList;
4670   QStringList     aMarkerScaleValuesList;
4671   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
4672     aMarkerScaleIndicesList << i;
4673     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
4674   }
4675   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
4676   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
4677
4678   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
4679   setPreferenceProperty( elemGroup, "columns", 2 );
4680
4681   int ColorId = addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
4682   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
4683
4684   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
4685   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
4686
4687   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
4688
4689   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
4690   setPreferenceProperty( grpGroup, "columns", 2 );
4691
4692   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
4693
4694   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
4695                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
4696   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
4697                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
4698   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
4699                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
4700
4701   setPreferenceProperty( size0d, "min", 1 );
4702   setPreferenceProperty( size0d, "max", 10 );
4703
4704   setPreferenceProperty( elemW, "min", 1 );
4705   setPreferenceProperty( elemW, "max", 5 );
4706
4707   setPreferenceProperty( shrink, "min", 0 );
4708   setPreferenceProperty( shrink, "max", 100 );
4709
4710   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
4711   setPreferenceProperty( orientGroup, "columns", 1 );
4712
4713   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
4714   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
4715
4716   setPreferenceProperty( orientScale, "min", 0.05 );
4717   setPreferenceProperty( orientScale, "max", 0.5 );
4718   setPreferenceProperty( orientScale, "step", 0.05 );
4719
4720   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
4721
4722   // Selection tab ------------------------------------------------------------------------
4723   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
4724
4725   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
4726   setPreferenceProperty( selGroup, "columns", 2 );
4727
4728   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
4729   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
4730
4731   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
4732   setPreferenceProperty( preGroup, "columns", 2 );
4733
4734   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
4735
4736   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
4737   setPreferenceProperty( precSelGroup, "columns", 2 );
4738
4739   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
4740   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
4741   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
4742
4743   // Scalar Bar tab ------------------------------------------------------------------------
4744   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
4745   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
4746   setPreferenceProperty( fontGr, "columns", 2 );
4747
4748   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
4749   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
4750
4751   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
4752   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
4753
4754   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
4755   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
4756
4757   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
4758   setPreferenceProperty( numcol, "min", 2 );
4759   setPreferenceProperty( numcol, "max", 256 );
4760
4761   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
4762   setPreferenceProperty( numlab, "min", 2 );
4763   setPreferenceProperty( numlab, "max", 65 );
4764
4765   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
4766   setPreferenceProperty( orientGr, "columns", 2 );
4767   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
4768   QStringList orients;
4769   orients.append( tr( "SMESH_VERTICAL" ) );
4770   orients.append( tr( "SMESH_HORIZONTAL" ) );
4771   indices.clear(); indices.append( 0 ); indices.append( 1 );
4772   setPreferenceProperty( orient, "strings", orients );
4773   setPreferenceProperty( orient, "indexes", indices );
4774
4775   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
4776   setPreferenceProperty( posVSizeGr, "columns", 2 );
4777   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
4778   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
4779   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
4780   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
4781   setPreferenceProperty( xv, "step", 0.1 );
4782   setPreferenceProperty( xv, "min", 0.0 );
4783   setPreferenceProperty( xv, "max", 1.0 );
4784   setPreferenceProperty( yv, "step", 0.1 );
4785   setPreferenceProperty( yv, "min", 0.0 );
4786   setPreferenceProperty( yv, "max", 1.0 );
4787   setPreferenceProperty( wv, "step", 0.1 );
4788   setPreferenceProperty( wv, "min", 0.0 );
4789   setPreferenceProperty( wv, "max", 1.0 );
4790   setPreferenceProperty( hv, "min", 0.0 );
4791   setPreferenceProperty( hv, "max", 1.0 );
4792   setPreferenceProperty( hv, "step", 0.1 );
4793
4794   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4795   setPreferenceProperty( posHSizeGr, "columns", 2 );
4796   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4797   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4798   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4799   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4800   setPreferenceProperty( xv, "min", 0.0 );
4801   setPreferenceProperty( xv, "max", 1.0 );
4802   setPreferenceProperty( xv, "step", 0.1 );
4803   setPreferenceProperty( xh, "min", 0.0 );
4804   setPreferenceProperty( xh, "max", 1.0 );
4805   setPreferenceProperty( xh, "step", 0.1 );
4806   setPreferenceProperty( yh, "min", 0.0 );
4807   setPreferenceProperty( yh, "max", 1.0 );
4808   setPreferenceProperty( yh, "step", 0.1 );
4809   setPreferenceProperty( wh, "min", 0.0 );
4810   setPreferenceProperty( wh, "max", 1.0 );
4811   setPreferenceProperty( wh, "step", 0.1 );
4812   setPreferenceProperty( hh, "min", 0.0 );
4813   setPreferenceProperty( hh, "max", 1.0 );
4814   setPreferenceProperty( hh, "step", 0.1 );
4815
4816   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
4817   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
4818   setPreferenceProperty( distributionGr, "columns", 3 );
4819   QStringList types;
4820   types.append( tr( "SMESH_MONOCOLOR" ) );
4821   types.append( tr( "SMESH_MULTICOLOR" ) );
4822   indices.clear(); indices.append( 0 ); indices.append( 1 );
4823   setPreferenceProperty( coloringType, "strings", types );
4824   setPreferenceProperty( coloringType, "indexes", indices );
4825   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
4826
4827 }
4828
4829 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4830 {
4831   if( sect=="SMESH" ) {
4832     float sbX1,sbY1,sbW,sbH;
4833     float aTol = 1.00000009999999;
4834     std::string aWarning;
4835     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4836     if( name=="selection_object_color" || name=="selection_element_color" ||
4837         name=="highlight_color" ||
4838         name=="selection_precision_node" || name=="selection_precision_element" ||
4839         name=="selection_precision_object")
4840       SMESH::UpdateSelectionProp( this );
4841     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4842       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4843       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4844       if(sbX1+sbW > aTol){
4845         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4846         sbX1=0.01;
4847         sbW=0.08;
4848         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4849         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4850       }
4851     }
4852     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4853       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4854       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4855       if(sbY1+sbH > aTol){
4856         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4857         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4858         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4859       }
4860     }
4861     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4862       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4863       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4864       if(sbX1+sbW > aTol){
4865         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4866         sbX1=0.1;
4867         sbW=0.08;
4868         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4869         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4870       }
4871     }
4872     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4873       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4874       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4875       if(sbY1+sbH > aTol){
4876         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4877         sbY1=0.01;
4878         sbH=0.08;
4879         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4880         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4881       }
4882     }
4883     else if ( name == "segmentation" ) {
4884       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4885       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4886     }
4887     else if ( name == "nb_segments_per_edge" ) {
4888       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4889       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4890     }
4891     else if ( name == "historical_python_dump" ||
4892               name == "forget_mesh_on_hyp_modif") {
4893       QString val = aResourceMgr->stringValue( "SMESH", name );
4894       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
4895     }
4896
4897     if(aWarning.size() != 0){
4898       aWarning += "The default values are applied instead.";
4899       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4900                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4901                                QObject::tr(aWarning.c_str()));
4902     }
4903   }
4904 }
4905
4906 //================================================================================
4907 /*!
4908  * \brief Update something in accordance with update flags
4909   * \param theFlags - update flags
4910 *
4911 * Update viewer or/and object browser etc. in accordance with update flags ( see
4912 * LightApp_UpdateFlags enumeration ).
4913 */
4914 //================================================================================
4915 void SMESHGUI::update( const int flags )
4916 {
4917   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
4918     SMESH::UpdateView();
4919   else
4920     SalomeApp_Module::update( flags );
4921 }
4922
4923 //================================================================================
4924 /*!
4925  * \brief Set default selection mode
4926 *
4927 * SLOT called when operation commited. Sets default selection mode
4928 */
4929 //================================================================================
4930 void SMESHGUI::onOperationCommited( SUIT_Operation* )
4931 {
4932   SVTK_ViewWindow* vtkWnd =
4933     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4934   if ( vtkWnd )
4935     vtkWnd->SetSelectionMode( ActorSelection );
4936 }
4937
4938 //================================================================================
4939 /*!
4940  * \brief Set default selection mode
4941 *
4942 * SLOT called when operation aborted. Sets default selection mode
4943 */
4944 //================================================================================
4945 void SMESHGUI::onOperationAborted( SUIT_Operation* )
4946 {
4947   SVTK_ViewWindow* vtkWnd =
4948     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4949   if ( vtkWnd )
4950     vtkWnd->SetSelectionMode( ActorSelection );
4951 }
4952
4953 //================================================================================
4954 /*!
4955  * \brief Creates operation with given identifier
4956   * \param id - identifier of operation to be started
4957   * \return Pointer on created operation or NULL if operation is not created
4958 *
4959 * Virtual method redefined from the base class creates operation with given id.
4960 * It is called called automatically from startOperation method of base class.
4961 */
4962 //================================================================================
4963 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
4964 {
4965   LightApp_Operation* op = 0;
4966   // to do : create operation here
4967   switch( id )
4968   {
4969     case 417: //convert to quadratic
4970       op = new SMESHGUI_ConvToQuadOp();
4971     break;
4972     case 418: // create 2D mesh as boundary on 3D
4973       op = new SMESHGUI_Make2DFrom3DOp();
4974     break;
4975     case 701: // Compute mesh
4976       op = new SMESHGUI_ComputeOp();
4977     break;
4978     case 702: // Create mesh
4979       op = new SMESHGUI_MeshOp( true, true );
4980     break;
4981     case 703: // Create sub-mesh
4982       op = new SMESHGUI_MeshOp( true, false );
4983     break;
4984     case 704: // Edit mesh/sub-mesh
4985       op = new SMESHGUI_MeshOp( false );
4986     break;
4987     case 711: // Precompute mesh
4988       op = new SMESHGUI_PrecomputeOp();
4989     break;
4990     case 712: // Evaluate mesh
4991       op = new SMESHGUI_EvaluateOp();
4992     break;
4993     case 713: // Evaluate mesh
4994       op = new SMESHGUI_MeshOrderOp();
4995     break;
4996     case 806: // Create group on geom
4997       op = new SMESHGUI_GroupOnShapeOp();
4998       break;
4999     case 904: // Find element
5000       op = new SMESHGUI_FindElemByPointOp();
5001       break;
5002     case 4067: // make mesh pass through point
5003       op = new SMESHGUI_MakeNodeAtPointOp();
5004       break;
5005     default:
5006     break;
5007   }
5008
5009   if( !op )
5010     op = SalomeApp_Module::createOperation( id );
5011   return op;
5012 }
5013
5014 //================================================================================
5015 /*!
5016  * \brief Stops current operations and starts a given one
5017   * \param id - The id of the operation to start
5018  */
5019 //================================================================================
5020
5021 void SMESHGUI::switchToOperation(int id)
5022 {
5023   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
5024     activeStudy()->abortAllOperations();
5025   startOperation( id );
5026 }
5027
5028 LightApp_Displayer* SMESHGUI::displayer()
5029 {
5030   if( !myDisplayer )
5031     myDisplayer = new SMESHGUI_Displayer( getApp() );
5032   return myDisplayer;
5033 }
5034
5035 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
5036 {
5037   int aHue = -1;
5038   int aTolerance = 64;
5039   int anIterations = 0;
5040   int aPeriod = 5;
5041
5042   while( 1 )
5043   {
5044     anIterations++;
5045     if( anIterations % aPeriod == 0 )
5046     {
5047       aTolerance /= 2;
5048       if( aTolerance < 1 )
5049         break;
5050     }
5051
5052     aHue = (int)( 360.0 * rand() / RAND_MAX );
5053
5054     bool ok = true;
5055     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
5056     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
5057     for( ; it != itEnd; ++it )
5058     {
5059       SALOMEDS::Color anAutoColor = *it;
5060       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
5061
5062       int h, s, v;
5063       aQColor.getHsv( &h, &s, &v );
5064       if( abs( h - aHue ) < aTolerance )
5065       {
5066         ok = false;
5067         break;
5068       }
5069     }
5070
5071     if( ok )
5072       break;
5073   }
5074
5075   QColor aColor;
5076   aColor.setHsv( aHue, 255, 255 );
5077
5078   SALOMEDS::Color aSColor;
5079   aSColor.R = (double)aColor.red() / 255.0;
5080   aSColor.G = (double)aColor.green() / 255.0;
5081   aSColor.B = (double)aColor.blue() / 255.0;
5082
5083   return aSColor;
5084 }
5085
5086 const char gSeparator = '_'; // character used to separate parameter names
5087 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
5088 const char gPathSep   = '|'; // character used to separate paths
5089
5090 /*!
5091  * \brief Store visual parameters
5092  *
5093  * This method is called just before the study document is saved.
5094  * Store visual parameters in AttributeParameter attribue(s)
5095  */
5096 void SMESHGUI::storeVisualParameters (int savePoint)
5097 {
5098   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5099   if (!appStudy || !appStudy->studyDS())
5100     return;
5101   _PTR(Study) studyDS = appStudy->studyDS();
5102
5103   // componentName is used for encoding of entries when storing them in IParameters
5104   std::string componentName = myComponentSMESH->ComponentDataType();
5105   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
5106   //if (!aSComponent) return;
5107
5108   // IParameters
5109   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5110                                                              componentName.c_str(),
5111                                                              savePoint);
5112   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5113
5114   // store map of custom markers
5115   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5116   if( !aMarkerMap.empty() )
5117   {
5118     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
5119     for( ; anIter != aMarkerMap.end(); anIter++ )
5120     {
5121       int anId = anIter->first;
5122       VTK::MarkerData aMarkerData = anIter->second;
5123       std::string aMarkerFileName = aMarkerData.first;
5124       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
5125       if( aMarkerTexture.size() < 3 )
5126         continue; // should contain at least width, height and the first value
5127
5128       QString aPropertyName( "texture" );
5129       aPropertyName += gSeparator;
5130       aPropertyName += QString::number( anId );
5131
5132       QString aPropertyValue = aMarkerFileName.c_str();
5133       aPropertyValue += gPathSep;
5134
5135       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
5136       ushort aWidth = *aTextureIter++;
5137       ushort aHeight = *aTextureIter++;
5138       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
5139       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
5140       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
5141         aPropertyValue += QString::number( *aTextureIter );
5142
5143       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5144     }
5145   }
5146
5147   // viewers counters are used for storing view_numbers in IParameters
5148   int vtkViewers = 0;
5149
5150   // main cycle to store parameters of displayed objects
5151   QList<SUIT_ViewManager*> lst;
5152   QList<SUIT_ViewManager*>::Iterator it;
5153   getApp()->viewManagers(lst);
5154   for (it = lst.begin(); it != lst.end(); it++)
5155   {
5156     SUIT_ViewManager* vman = *it;
5157     QString vType = vman->getType();
5158
5159     // saving VTK actors properties
5160     if (vType == SVTK_Viewer::Type())
5161     {
5162       // store the clipping planes attached to the view manager
5163       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
5164       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
5165       if( anIter != myClippingPlaneInfoMap.end() )
5166         aClippingPlaneInfoList = anIter->second;
5167
5168       if( !aClippingPlaneInfoList.empty() ) {
5169         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
5170         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
5171         {
5172           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
5173           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
5174
5175           QString aPropertyName( "ClippingPlane" );
5176           aPropertyName += gSeparator;
5177           aPropertyName += QString::number( vtkViewers );
5178           aPropertyName += gSeparator;
5179           aPropertyName += QString::number( anId );
5180
5181           QString aPropertyValue = QString::number( (int)aPlane->GetOrientation() ).toLatin1().constData();
5182           aPropertyValue += gDigitsSep;
5183           aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5184           aPropertyValue += gDigitsSep;
5185           aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5186           aPropertyValue += gDigitsSep;
5187           aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5188
5189           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5190         }
5191       }
5192
5193       QVector<SUIT_ViewWindow*> views = vman->getViews();
5194       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5195       {
5196         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5197         {
5198           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5199           vtkActorCollection* allActors = aCopy.GetActors();
5200           allActors->InitTraversal();
5201           while (vtkActor* actor = allActors->GetNextActor())
5202           {
5203             if (actor->GetVisibility()) // store only visible actors
5204             {
5205               SMESH_Actor* aSmeshActor = 0;
5206               if (actor->IsA("SMESH_Actor"))
5207                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5208               if (aSmeshActor && aSmeshActor->hasIO())
5209               {
5210                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5211                 if (io->hasEntry())
5212                 {
5213                   // entry is "encoded" = it does NOT contain component adress,
5214                   // since it is a subject to change on next component loading
5215                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5216
5217                   std::string param, vtkParam = vType.toLatin1().data();
5218                   vtkParam += gSeparator;
5219                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5220                   vtkParam += gSeparator;
5221
5222                   // Visibility
5223                   param = vtkParam + "Visibility";
5224                   ip->setParameter(entry, param, "On");
5225
5226                   // Representation
5227                   param = vtkParam + "Representation";
5228                   ip->setParameter(entry, param, QString::number
5229                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5230
5231                   // IsShrunk
5232                   param = vtkParam + "IsShrunk";
5233                   ip->setParameter(entry, param, QString::number
5234                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5235
5236                   // Displayed entities
5237                   unsigned int aMode = aSmeshActor->GetEntityMode();
5238                   bool isE = aMode & SMESH_Actor::eEdges;
5239                   bool isF = aMode & SMESH_Actor::eFaces;
5240                   bool isV = aMode & SMESH_Actor::eVolumes;
5241
5242                   QString modeStr ("e");
5243                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5244                   modeStr += gDigitsSep; modeStr += "f";
5245                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5246                   modeStr += gDigitsSep; modeStr += "v";
5247                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5248
5249                   param = vtkParam + "Entities";
5250                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5251
5252                   // Colors (surface:edge:)
5253                   vtkFloatingPointType r, g, b;
5254                   int delta;
5255
5256                   aSmeshActor->GetSufaceColor(r, g, b, delta);
5257                   QString colorStr ("surface");
5258                   colorStr += gDigitsSep; colorStr += QString::number(r);
5259                   colorStr += gDigitsSep; colorStr += QString::number(g);
5260                   colorStr += gDigitsSep; colorStr += QString::number(b);
5261
5262                   colorStr += gDigitsSep; colorStr += "backsurface";
5263                   colorStr += gDigitsSep; colorStr += QString::number(delta);
5264
5265
5266                   aSmeshActor->GetEdgeColor(r, g, b);
5267                   colorStr += gDigitsSep; colorStr += "edge";
5268                   colorStr += gDigitsSep; colorStr += QString::number(r);
5269                   colorStr += gDigitsSep; colorStr += QString::number(g);
5270                   colorStr += gDigitsSep; colorStr += QString::number(b);
5271
5272                   aSmeshActor->GetNodeColor(r, g, b);
5273                   colorStr += gDigitsSep; colorStr += "node";
5274                   colorStr += gDigitsSep; colorStr += QString::number(r);
5275                   colorStr += gDigitsSep; colorStr += QString::number(g);
5276                   colorStr += gDigitsSep; colorStr += QString::number(b);
5277
5278                   aSmeshActor->GetOutlineColor(r, g, b);
5279                   colorStr += gDigitsSep; colorStr += "outline";
5280                   colorStr += gDigitsSep; colorStr += QString::number(r);
5281                   colorStr += gDigitsSep; colorStr += QString::number(g);
5282                   colorStr += gDigitsSep; colorStr += QString::number(b);
5283
5284                   param = vtkParam + "Colors";
5285                   ip->setParameter(entry, param, colorStr.toLatin1().data());
5286
5287                   // Sizes of lines and points
5288                   QString sizeStr ("line");
5289                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
5290                   sizeStr += gDigitsSep; sizeStr += "shrink";
5291                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
5292
5293                   param = vtkParam + "Sizes";
5294                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
5295
5296                   // Point marker
5297                   QString markerStr;
5298
5299                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5300                   if( aMarkerType == VTK::MT_USER ) {
5301                     markerStr += "custom";
5302                     markerStr += gDigitsSep;
5303                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5304                   }
5305                   else {
5306                     markerStr += "std";
5307                     markerStr += gDigitsSep;
5308                     markerStr += QString::number( (int)aMarkerType );
5309                     markerStr += gDigitsSep;
5310                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5311                   }
5312
5313                   param = vtkParam + "PointMarker";
5314                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5315
5316                   // Opacity
5317                   param = vtkParam + "Opacity";
5318                   ip->setParameter(entry, param,
5319                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5320
5321                   // Clipping
5322                   param = vtkParam + "ClippingPlane";
5323                   int aPlaneId = 0;
5324                   if( !aClippingPlaneInfoList.empty() ) {
5325                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5326                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5327                     {
5328                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5329                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5330                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5331                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5332                         if( aSmeshActor == *anIter2 ) {
5333                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5334                                             QString::number( anId ).toLatin1().constData() );
5335                           break;
5336                         }
5337                       }
5338                     }
5339                   }
5340                   if( aPlaneId == 0 )
5341                     ip->setParameter( entry, param, "Off" );
5342                 } // if (io->hasEntry())
5343               } // SMESH_Actor && hasIO
5344             } // isVisible
5345           } // while.. actors traversal
5346         } // if (vtkView)
5347       } // for (views)
5348       vtkViewers++;
5349     } // if (SVTK view model)
5350   } // for (viewManagers)
5351 }
5352
5353 // data structures for clipping planes processing
5354 typedef struct {
5355   int Id;
5356   vtkIdType Orientation;
5357   vtkFloatingPointType Distance;
5358   vtkFloatingPointType Angle[2];
5359 } TPlaneData;
5360 typedef std::list<TPlaneData>         TPlaneDataList;
5361 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5362
5363 typedef std::list<vtkActor*>          TActorList;
5364 typedef struct {
5365   int PlaneId;
5366   TActorList ActorList;
5367   SUIT_ViewManager* ViewManager;
5368 } TPlaneInfo;
5369 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5370 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5371
5372 /*!
5373  * \brief Restore visual parameters
5374  *
5375  * This method is called after the study document is opened.
5376  * Restore visual parameters from AttributeParameter attribue(s)
5377  */
5378 void SMESHGUI::restoreVisualParameters (int savePoint)
5379 {
5380   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5381   if (!appStudy || !appStudy->studyDS())
5382     return;
5383   _PTR(Study) studyDS = appStudy->studyDS();
5384
5385   // componentName is used for encoding of entries when storing them in IParameters
5386   std::string componentName = myComponentSMESH->ComponentDataType();
5387   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5388   //if (!aSComponent) return;
5389
5390   // IParameters
5391   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5392                                                              componentName.c_str(),
5393                                                              savePoint);
5394   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5395
5396   // restore map of custom markers and map of clipping planes
5397   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5398   TPlaneDataMap aPlaneDataMap;
5399
5400   std::vector<std::string> properties = ip->getProperties();
5401   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5402   {
5403     std::string property = *propIt;
5404     QString aPropertyName( property.c_str() );
5405     QString aPropertyValue( ip->getProperty( property ).c_str() );
5406
5407     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5408     if( aPropertyNameList.isEmpty() )
5409       continue;
5410
5411     QString aPropertyType = aPropertyNameList[0];
5412     if( aPropertyType == "texture" )
5413     {
5414       if( aPropertyNameList.size() != 2 )
5415         continue;
5416
5417       bool ok = false;
5418       int anId = aPropertyNameList[1].toInt( &ok );
5419       if( !ok || anId < 1 )
5420         continue;
5421
5422       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5423       if( aPropertyValueList.size() != 2 )
5424         continue;
5425
5426       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5427       QString aMarkerTextureString = aPropertyValueList[1];
5428       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5429       if( aMarkerTextureStringList.size() != 3 )
5430         continue;
5431
5432       ok = false;
5433       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5434       if( !ok )
5435         continue;
5436
5437       ok = false;
5438       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5439       if( !ok )
5440         continue;
5441
5442       VTK::MarkerTexture aMarkerTexture;
5443       aMarkerTexture.push_back( aWidth );
5444       aMarkerTexture.push_back( aHeight );
5445
5446       QString aMarkerTextureData = aMarkerTextureStringList[2];
5447       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5448       {
5449         QChar aChar = aMarkerTextureData.at( i );
5450         if( aChar.isDigit() )
5451           aMarkerTexture.push_back( aChar.digitValue() );
5452       }
5453
5454       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5455     }
5456     else if( aPropertyType == "ClippingPlane" )
5457     {
5458       if( aPropertyNameList.size() != 3 )
5459         continue;
5460
5461       bool ok = false;
5462       int aViewId = aPropertyNameList[1].toInt( &ok );
5463       if( !ok || aViewId < 0 )
5464         continue;
5465
5466       ok = false;
5467       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5468       if( !ok || aClippingPlaneId < 0 )
5469         continue;
5470
5471       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5472       if( aPropertyValueList.size() != 4 )
5473         continue;
5474
5475       TPlaneData aPlaneData;
5476       aPlaneData.Id = aClippingPlaneId;
5477
5478       ok = false;
5479       aPlaneData.Orientation = aPropertyValueList[0].toInt( &ok );
5480       if( !ok )
5481         continue;
5482
5483       ok = false;
5484       aPlaneData.Distance = aPropertyValueList[1].toDouble( &ok );
5485       if( !ok )
5486         continue;
5487
5488       ok = false;
5489       aPlaneData.Angle[0] = aPropertyValueList[2].toDouble( &ok );
5490       if( !ok )
5491         continue;
5492
5493       ok = false;
5494       aPlaneData.Angle[1] = aPropertyValueList[3].toDouble( &ok );
5495       if( !ok )
5496         continue;
5497
5498       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
5499       aPlaneDataList.push_back( aPlaneData );
5500     }
5501   }
5502
5503   TPlaneInfoMap aPlaneInfoMap;
5504
5505   std::vector<std::string> entries = ip->getEntries();
5506
5507   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
5508   {
5509     // entry is a normal entry - it should be "decoded" (setting base adress of component)
5510     QString entry (ip->decodeEntry(*entIt).c_str());
5511
5512     // Check that the entry corresponds to a real object in the Study
5513     // as the object may be deleted or modified after the visual state is saved.
5514     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
5515     if (!so) continue; //Skip the not existent entry
5516
5517     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
5518     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
5519
5520     std::vector<std::string>::iterator namesIt = paramNames.begin();
5521     std::vector<std::string>::iterator valuesIt = paramValues.begin();
5522
5523     // actors are stored in a map after displaying of them for
5524     // quicker access in the future: map < viewID to actor >
5525     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
5526
5527     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
5528     {
5529       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
5530       // '_' is used as separator and should not be used in viewer type or parameter names.
5531       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
5532       if (lst.size() != 3)
5533         continue;
5534
5535       QString viewerTypStr = lst[0];
5536       QString viewIndexStr = lst[1];
5537       QString paramNameStr = lst[2];
5538
5539       bool ok;
5540       int viewIndex = viewIndexStr.toUInt(&ok);
5541       if (!ok) // bad conversion of view index to integer
5542         continue;
5543
5544       // viewers
5545       if (viewerTypStr == SVTK_Viewer::Type())
5546       {
5547         SMESH_Actor* aSmeshActor = 0;
5548         if (vtkActors.IsBound(viewIndex))
5549           aSmeshActor = vtkActors.Find(viewIndex);
5550
5551         QList<SUIT_ViewManager*> lst;
5552         getApp()->viewManagers(viewerTypStr, lst);
5553
5554         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5555         SUIT_ViewManager* vman = NULL;
5556         if (viewIndex >= 0 && viewIndex < lst.count())
5557           vman = lst.at(viewIndex);
5558
5559         if (paramNameStr == "Visibility")
5560         {
5561           if (!aSmeshActor && displayer() && vman)
5562           {
5563             SUIT_ViewModel* vmodel = vman->getViewModel();
5564             // SVTK view model can be casted to SALOME_View
5565             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
5566
5567             // store displayed actor in a temporary map for quicker
5568             // access later when restoring other parameters
5569             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5570             vtkRenderer* Renderer = vtkView->getRenderer();
5571             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
5572             vtkActorCollection* theActors = aCopy.GetActors();
5573             theActors->InitTraversal();
5574             bool isFound = false;
5575             vtkActor *ac = theActors->GetNextActor();
5576             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
5577               if (ac->IsA("SMESH_Actor")) {
5578                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
5579                 if (aGeomAc->hasIO()) {
5580                   Handle(SALOME_InteractiveObject) io =
5581                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
5582                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
5583                     isFound = true;
5584                     vtkActors.Bind(viewIndex, aGeomAc);
5585                   }
5586                 }
5587               }
5588             }
5589           }
5590         } // if (paramNameStr == "Visibility")
5591         else
5592         {
5593           // the rest properties "work" with SMESH_Actor
5594           if (aSmeshActor)
5595           {
5596             QString val ((*valuesIt).c_str());
5597
5598             // Representation
5599             if (paramNameStr == "Representation") {
5600               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
5601             }
5602             // IsShrunk
5603             else if (paramNameStr == "IsShrunk") {
5604               if (val.toInt()) {
5605                 if (!aSmeshActor->IsShrunk())
5606                   aSmeshActor->SetShrink();
5607               }
5608               else {
5609                 if (aSmeshActor->IsShrunk())
5610                   aSmeshActor->UnShrink();
5611               }
5612             }
5613             // Displayed entities
5614             else if (paramNameStr == "Entities") {
5615               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
5616               if (mode.count() == 6) {
5617                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
5618                   MESSAGE("Invalid order of data in Entities, must be: "
5619                           "e:0/1:f:0/1:v:0/1");
5620                 }
5621                 else {
5622                   unsigned int aMode = aSmeshActor->GetEntityMode();
5623                   unsigned int aNewMode =
5624                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
5625                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
5626                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
5627                   if (aNewMode != aMode)
5628                     aSmeshActor->SetEntityMode(aNewMode);
5629                 }
5630               }
5631             }
5632             // Colors
5633             else if (paramNameStr == "Colors") {
5634               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
5635               if (colors.count() == 16 || colors.count() == 18 ) {
5636                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
5637                     (colors[8] != "edge" && colors[6] != "edge" ) || (colors[12] != "node" && colors[10] != "node") ||
5638                     (colors.count() == 18 && colors[14] != "outline")) {
5639                   MESSAGE("Invalid order of data in Colors, must be: "
5640                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b or surface:r:g:b:backsurface:delta:edge:r:g:b:node:r:g:b:outline:r:g:b");
5641                 }
5642                 else {
5643                   int delta = 0;
5644                   float er,eg,eb;
5645                   float nr,ng,nb;
5646                   vtkFloatingPointType otr,otg,otb;
5647                   //Old case backsurface color is independent
5648                   if( colors.count() == 16 ) {
5649                     QColor ffc;
5650                     SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "0,170,255|-100" ) ;
5651                     er = colors[9].toFloat();
5652                     eg = colors[10].toFloat();
5653                     eb = colors[11].toFloat();
5654
5655                     nr = colors[13].toFloat();
5656                     ng = colors[14].toFloat();
5657                     nb = colors[15].toFloat();
5658                     SMESH::GetColor("SMESH", "outline_color", otr, otg, otb, QColor( 0, 70, 0 ) );
5659                   } else {
5660                     //New case backsurface color depends on surface color
5661                     delta = colors[5].toInt();
5662
5663                     er = colors[7].toFloat();
5664                     eg = colors[8].toFloat();
5665                     eb = colors[9].toFloat();
5666
5667                     nr = colors[11].toFloat();
5668                     ng = colors[12].toFloat();
5669                     nb = colors[13].toFloat();
5670
5671                     otr = colors[15].toFloat();
5672                     otg = colors[16].toFloat();
5673                     otb = colors[17].toFloat();
5674                   }
5675                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat(), delta);
5676                   aSmeshActor->SetEdgeColor(er,eg,eb);
5677                   aSmeshActor->SetNodeColor(nr,ng,nb);
5678                   aSmeshActor->SetOutlineColor(otr,otg,otb);
5679                 }
5680               }
5681             }
5682             // Sizes of lines and points
5683             else if (paramNameStr == "Sizes") {
5684               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
5685               if (sizes.count() == 4) {
5686                 if (sizes[0] != "line" || sizes[2] != "shrink") {
5687                   MESSAGE("Invalid order of data in Sizes, must be: "
5688                           "line:int:shrink:float");
5689                 }
5690                 else {
5691                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5692                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
5693                 }
5694               }
5695               else if (sizes.count() == 6) { // just to support old format
5696                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
5697                   MESSAGE("Invalid order of data in Sizes, must be: "
5698                           "line:int:node:int:shrink:float");
5699                 }
5700                 else {
5701                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5702                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
5703                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
5704                 }
5705               }
5706             }
5707             // Point marker
5708             else if (paramNameStr == "PointMarker") {
5709               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
5710               if( data.count() >= 2 ) {
5711                 bool ok = false;
5712                 int aParam1 = data[1].toInt( &ok );
5713                 if( ok ) {
5714                   if( data[0] == "std" && data.count() == 3 ) {
5715                     int aParam2 = data[2].toInt( &ok );
5716                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
5717                   }
5718                   else if( data[0] == "custom" ) {
5719                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
5720                     if( markerIt != aMarkerMap.end() ) {
5721                       VTK::MarkerData aMarkerData = markerIt->second;
5722                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
5723                     }
5724                   }
5725                 }
5726               }
5727             }
5728             // Opacity
5729             else if (paramNameStr == "Opacity") {
5730               aSmeshActor->SetOpacity(val.toFloat());
5731             }
5732             // Clipping
5733             else if (paramNameStr.startsWith("ClippingPlane")) {
5734               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
5735               // old format - val looks like "Off" or "0:0.5:0:0" (orientation, distance, two angles)
5736               // new format - val looks like "Off" or "0" (plane id)
5737               // (note: in new format "Off" value is used only for consistency,
5738               //  so it is processed together with values in old format)
5739               bool anIsOldFormat = ( vals.count() == 4 || val == "Off" );
5740               if( anIsOldFormat ) {
5741                 if (paramNameStr == "ClippingPlane1" || val == "Off")
5742                   aSmeshActor->RemoveAllClippingPlanes();
5743                 if (val != "Off") {
5744                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
5745                   double aDistance = vals[1].toFloat();
5746                   vtkFloatingPointType anAngle[2];
5747                   anAngle[0] = vals[2].toFloat();
5748                   anAngle[1] = vals[3].toFloat();
5749
5750                   QList<SUIT_ViewManager*> lst;
5751                   getApp()->viewManagers(viewerTypStr, lst);
5752                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5753                   if (viewIndex >= 0 && viewIndex < lst.count()) {
5754                     SUIT_ViewManager* vman = lst.at(viewIndex);
5755                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5756
5757                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
5758
5759                     SMESH::TActorList anActorList;
5760                     anActorList.push_back( aSmeshActor );
5761                     SMESH::OrientedPlane* aPlane =
5762                       SMESHGUI_ClippingDlg::AddPlane(anActorList, vtkView, anOrientation, aDistance, anAngle);
5763                     if( aPlane ) {
5764                       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5765                       aClippingPlaneInfo.Plane = aPlane;
5766                       aClippingPlaneInfo.ActorList = anActorList;
5767                       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5768                     }
5769                   }
5770                 }
5771               }
5772               else {
5773                 bool ok = false;
5774                 int aPlaneId = val.toInt( &ok );
5775                 if( ok && aPlaneId >= 0 ) {
5776                   bool anIsDefinedPlane = false;
5777                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
5778                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
5779                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5780                     TPlaneInfo& aPlaneInfo = *anIter;
5781                     if( aPlaneInfo.PlaneId == aPlaneId ) {
5782                       aPlaneInfo.ActorList.push_back( aSmeshActor );
5783                       anIsDefinedPlane = true;
5784                       break;
5785                     }
5786                   }
5787                   if( !anIsDefinedPlane ) {
5788                     TPlaneInfo aPlaneInfo;
5789                     aPlaneInfo.PlaneId = aPlaneId;
5790                     aPlaneInfo.ActorList.push_back( aSmeshActor );
5791                     aPlaneInfo.ViewManager = vman;
5792
5793                     // to make the list sorted by plane id
5794                     anIter = aPlaneInfoList.begin();
5795                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5796                       const TPlaneInfo& aPlaneInfoRef = *anIter;
5797                       if( aPlaneInfoRef.PlaneId > aPlaneId )
5798                         break;
5799                     }
5800                     aPlaneInfoList.insert( anIter, aPlaneInfo );
5801                   }
5802                 }
5803               }
5804             }
5805           } // if (aSmeshActor)
5806         } // other parameters than Visibility
5807       }
5808     } // for names/parameters iterator
5809   } // for entries iterator
5810
5811   // take into account planes with empty list of actors referred to them
5812   QList<SUIT_ViewManager*> aVMList;
5813   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
5814
5815   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
5816   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
5817     int aViewId = aPlaneDataIter->first;
5818     if( aViewId >= 0 && aViewId < aVMList.count() ) {
5819       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
5820
5821       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
5822
5823       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
5824       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
5825       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
5826         const TPlaneData& aPlaneData = *anIter2;
5827         int aPlaneId = aPlaneData.Id;
5828
5829         bool anIsFound = false;
5830         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5831         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5832           const TPlaneInfo& aPlaneInfo = *anIter3;
5833           if( aPlaneInfo.PlaneId == aPlaneId ) {
5834             anIsFound = true;
5835             break;
5836           }
5837         }
5838
5839         if( !anIsFound ) {
5840           TPlaneInfo aPlaneInfo; // ActorList field is empty
5841           aPlaneInfo.PlaneId = aPlaneId;
5842           aPlaneInfo.ViewManager = aViewManager;
5843
5844           // to make the list sorted by plane id
5845           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
5846           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
5847             const TPlaneInfo& aPlaneInfoRef = *anIter4;
5848             if( aPlaneInfoRef.PlaneId > aPlaneId )
5849               break;
5850           }
5851           aPlaneInfoList.insert( anIter4, aPlaneInfo );
5852         }
5853       }
5854     }
5855   }
5856
5857   // add clipping planes to actors according to the restored parameters
5858   // and update the clipping plane map
5859   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
5860   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
5861     int aViewId = anIter1->first;
5862     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
5863
5864     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
5865     if( anIter2 == aPlaneDataMap.end() )
5866       continue;
5867     const TPlaneDataList& aPlaneDataList = anIter2->second;
5868
5869     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5870     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5871       const TPlaneInfo& aPlaneInfo = *anIter3;
5872       int aPlaneId = aPlaneInfo.PlaneId;
5873       const TActorList& anActorList = aPlaneInfo.ActorList;
5874       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
5875       if( !aViewManager )
5876         continue;
5877
5878       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
5879       if( !aViewWindow )
5880         continue;
5881
5882       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
5883
5884       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
5885       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
5886         const TPlaneData& aPlaneData = *anIter4;
5887         if( aPlaneData.Id == aPlaneId ) {
5888           SMESH::OrientedPlane* aPlane =
5889             SMESHGUI_ClippingDlg::AddPlane( anActorList,
5890                                             aViewWindow,
5891                                             (SMESH::Orientation)aPlaneData.Orientation,
5892                                             aPlaneData.Distance,
5893                                             aPlaneData.Angle );
5894           if( aPlane ) {
5895             SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5896             aClippingPlaneInfo.Plane = aPlane;
5897             aClippingPlaneInfo.ActorList = anActorList;
5898             aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5899           }
5900           break;
5901         }
5902       }
5903     }
5904   }
5905
5906   // update all VTK views
5907   QList<SUIT_ViewManager*> lst;
5908   getApp()->viewManagers(lst);
5909   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
5910     SUIT_ViewModel* vmodel = (*it)->getViewModel();
5911     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
5912       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
5913       vtkView->getRenderer()->ResetCameraClippingRange();
5914       vtkView->Repaint();
5915     }
5916   }
5917 }
5918
5919 /*!
5920   \brief Adds preferences for dfont of VTK viewer
5921   \param label label
5922   \param pIf group identifier
5923   \param param parameter
5924   \return identifier of preferences
5925 */
5926 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
5927 {
5928   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
5929
5930   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
5931
5932   QStringList fam;
5933   fam.append( tr( "SMESH_FONT_ARIAL" ) );
5934   fam.append( tr( "SMESH_FONT_COURIER" ) );
5935   fam.append( tr( "SMESH_FONT_TIMES" ) );
5936
5937   setPreferenceProperty( tfont, "fonts", fam );
5938
5939   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
5940   setPreferenceProperty( tfont, "features", f );
5941
5942   return tfont;
5943 }
5944
5945 /*!
5946   \brief Actions after hypothesis edition
5947   Updates object browser after hypothesis edition
5948 */
5949 void SMESHGUI::onHypothesisEdit( int result )
5950 {
5951   if( result == 1 )
5952     SMESHGUI::Modified();
5953   updateObjBrowser( true );
5954 }
5955
5956
5957 /*!
5958   \brief Signal handler closing(SUIT_ViewWindow*) of a view
5959   \param pview view being closed
5960 */
5961 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
5962 #ifndef DISABLE_PLOT2DVIEWER
5963   //Crear all Plot2d Viewers if need.
5964   SMESH::ClearPlot2Viewers(pview);
5965 #endif
5966 }
5967
5968 void SMESHGUI::message( const QString& msg )
5969 {
5970   // dispatch message
5971   QStringList data = msg.split("/");
5972   if ( data.count() > 0 ) {
5973     if ( data.first() == "mesh_loading" ) {
5974       // get mesh entry
5975       QString entry = data.count() > 1 ? data[1] : QString();
5976       if ( entry.isEmpty() )
5977         return;
5978       // get study
5979       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
5980       // get mesh name
5981       _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().constData() );
5982       QString name;
5983       if ( obj )
5984         name = obj->GetName().c_str();
5985       if ( name.isEmpty() )
5986         return;
5987       
5988       if ( data.last() == "stop" )
5989         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
5990       else
5991         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
5992       QApplication::processEvents();
5993     }
5994   }
5995 }
5996
5997 /*!
5998   \brief Connects or disconnects signals about activating and cloning view on the module slots
5999   \param pview view which is connected/disconnected
6000 */
6001 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
6002   if(!pview)
6003     return;
6004
6005   SUIT_ViewManager* viewMgr = pview->getViewManager();
6006   if ( viewMgr ) {
6007     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6008                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6009
6010     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6011              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6012   }
6013 }
6014
6015 /*!
6016   \brief Return \c true if object can be renamed
6017 */
6018 bool SMESHGUI::renameAllowed( const QString& entry) const {
6019   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6020   if( !anApp )
6021     return false;
6022
6023   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6024   if( !appStudy )
6025     return false;
6026
6027   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
6028   
6029   if(!obj)
6030     return false;
6031
6032   if(appStudy->isComponent(entry) || obj->isReference())
6033     return false;
6034
6035   // check type to prevent renaming of inappropriate objects
6036   int aType = SMESHGUI_Selection::type(qPrintable(entry), SMESH::GetActiveStudyDocument());
6037   if (aType == MESH || aType == GROUP ||
6038       aType == SUBMESH || aType == SUBMESH_COMPOUND ||
6039       aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
6040       aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
6041       aType == HYPOTHESIS || aType == ALGORITHM)
6042     return true;
6043
6044   return false;
6045 }
6046
6047 /*!
6048   Rename object by entry.
6049   \param entry entry of the object
6050   \param name new name of the object
6051   \brief Return \c true if rename operation finished successfully, \c false otherwise.
6052 */
6053 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
6054
6055   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6056   if( !anApp )
6057     return false;
6058     
6059   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6060
6061   if(!appStudy)
6062     return false;
6063   
6064   _PTR(Study) aStudy = appStudy->studyDS();
6065   
6066   if(!aStudy)
6067     return false;
6068   
6069   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
6070   if ( aLocked ) {
6071     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
6072     return false;
6073   }
6074
6075
6076   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
6077   _PTR(GenericAttribute) anAttr;
6078   _PTR(AttributeName) aName;
6079   if ( obj ) {
6080     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
6081       aName = anAttr;
6082       // check type to prevent renaming of inappropriate objects
6083       int aType = SMESHGUI_Selection::type( qPrintable(entry), SMESH::GetActiveStudyDocument() );
6084       if (aType == MESH || aType == GROUP ||
6085           aType == SUBMESH || aType == SUBMESH_COMPOUND ||
6086           aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
6087           aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
6088           aType == HYPOTHESIS || aType == ALGORITHM) {
6089         if ( !name.isEmpty() ) {
6090           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
6091
6092           // update name of group object and its actor
6093           Handle(SALOME_InteractiveObject) IObject =
6094             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
6095
6096           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
6097           if( !aGroupObject->_is_nil() ) {
6098             aGroupObject->SetName( qPrintable(name) );
6099             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
6100               anActor->setName( qPrintable(name) );
6101           }
6102           return true;
6103         }
6104       }
6105     }
6106   }
6107   return false;
6108 }