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