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