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