Salome HOME
c90cb0fa9efe48868146d72afef3b6b371624d3d
[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         double ballScale = 1.0;
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( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
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   double ballScale = addPreference(tr("PREF_BALL_SCALE"), elemGroup,
5062                              LightApp_Preferences::DblSpin, "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", 1e-2 );
5077   setPreferenceProperty( ballScale, "max", 1e7 );
5078   setPreferenceProperty( ballScale, "step", 0.5 );
5079
5080   setPreferenceProperty( elemW, "min", 1 );
5081   setPreferenceProperty( elemW, "max", 5 );
5082
5083   setPreferenceProperty( outW, "min", 1 );
5084   setPreferenceProperty( outW, "max", 5 );
5085
5086   setPreferenceProperty( shrink, "min", 0 );
5087   setPreferenceProperty( shrink, "max", 100 );
5088
5089   int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
5090   setPreferenceProperty( numGroup, "columns", 2 );
5091   
5092   addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
5093   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
5094
5095   addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
5096   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
5097
5098   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
5099   setPreferenceProperty( orientGroup, "columns", 1 );
5100
5101   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
5102   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
5103
5104   setPreferenceProperty( orientScale, "min", 0.05 );
5105   setPreferenceProperty( orientScale, "max", 0.5 );
5106   setPreferenceProperty( orientScale, "step", 0.05 );
5107
5108   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
5109
5110   // Selection tab ------------------------------------------------------------------------
5111   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
5112
5113   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
5114   setPreferenceProperty( selGroup, "columns", 2 );
5115
5116   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
5117   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
5118
5119   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
5120   setPreferenceProperty( preGroup, "columns", 2 );
5121
5122   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
5123
5124   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
5125   setPreferenceProperty( precSelGroup, "columns", 2 );
5126
5127   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
5128   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
5129   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
5130
5131   // Scalar Bar tab ------------------------------------------------------------------------
5132   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
5133   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
5134   setPreferenceProperty( fontGr, "columns", 2 );
5135
5136   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
5137   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
5138
5139   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
5140   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
5141
5142   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
5143   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
5144
5145   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
5146   setPreferenceProperty( numcol, "min", 2 );
5147   setPreferenceProperty( numcol, "max", 256 );
5148
5149   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
5150   setPreferenceProperty( numlab, "min", 2 );
5151   setPreferenceProperty( numlab, "max", 65 );
5152
5153   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
5154   setPreferenceProperty( orientGr, "columns", 2 );
5155   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
5156   QStringList orients;
5157   orients.append( tr( "SMESH_VERTICAL" ) );
5158   orients.append( tr( "SMESH_HORIZONTAL" ) );
5159   indices.clear(); indices.append( 0 ); indices.append( 1 );
5160   setPreferenceProperty( orient, "strings", orients );
5161   setPreferenceProperty( orient, "indexes", indices );
5162
5163   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
5164   setPreferenceProperty( posVSizeGr, "columns", 2 );
5165   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
5166   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
5167   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
5168   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
5169   setPreferenceProperty( xv, "step", 0.1 );
5170   setPreferenceProperty( xv, "min", 0.0 );
5171   setPreferenceProperty( xv, "max", 1.0 );
5172   setPreferenceProperty( yv, "step", 0.1 );
5173   setPreferenceProperty( yv, "min", 0.0 );
5174   setPreferenceProperty( yv, "max", 1.0 );
5175   setPreferenceProperty( wv, "step", 0.1 );
5176   setPreferenceProperty( wv, "min", 0.0 );
5177   setPreferenceProperty( wv, "max", 1.0 );
5178   setPreferenceProperty( hv, "min", 0.0 );
5179   setPreferenceProperty( hv, "max", 1.0 );
5180   setPreferenceProperty( hv, "step", 0.1 );
5181
5182   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
5183   setPreferenceProperty( posHSizeGr, "columns", 2 );
5184   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
5185   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
5186   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
5187   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
5188   setPreferenceProperty( xv, "min", 0.0 );
5189   setPreferenceProperty( xv, "max", 1.0 );
5190   setPreferenceProperty( xv, "step", 0.1 );
5191   setPreferenceProperty( xh, "min", 0.0 );
5192   setPreferenceProperty( xh, "max", 1.0 );
5193   setPreferenceProperty( xh, "step", 0.1 );
5194   setPreferenceProperty( yh, "min", 0.0 );
5195   setPreferenceProperty( yh, "max", 1.0 );
5196   setPreferenceProperty( yh, "step", 0.1 );
5197   setPreferenceProperty( wh, "min", 0.0 );
5198   setPreferenceProperty( wh, "max", 1.0 );
5199   setPreferenceProperty( wh, "step", 0.1 );
5200   setPreferenceProperty( hh, "min", 0.0 );
5201   setPreferenceProperty( hh, "max", 1.0 );
5202   setPreferenceProperty( hh, "step", 0.1 );
5203
5204   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
5205   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
5206   setPreferenceProperty( distributionGr, "columns", 3 );
5207   QStringList types;
5208   types.append( tr( "SMESH_MONOCOLOR" ) );
5209   types.append( tr( "SMESH_MULTICOLOR" ) );
5210   indices.clear(); indices.append( 0 ); indices.append( 1 );
5211   setPreferenceProperty( coloringType, "strings", types );
5212   setPreferenceProperty( coloringType, "indexes", indices );
5213   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
5214
5215 }
5216
5217 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
5218 {
5219   if( sect=="SMESH" ) {
5220     float sbX1,sbY1,sbW,sbH;
5221     float aTol = 1.00000009999999;
5222     std::string aWarning;
5223     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5224     if( name=="selection_object_color" || name=="selection_element_color" ||
5225         name=="highlight_color" ||
5226         name=="selection_precision_node" || name=="selection_precision_element" ||
5227         name=="selection_precision_object")
5228       SMESH::UpdateSelectionProp( this );
5229     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
5230       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
5231       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
5232       if(sbX1+sbW > aTol){
5233         aWarning = "Origin and Size Vertical: X+Width > 1\n";
5234         sbX1=0.01;
5235         sbW=0.08;
5236         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
5237         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
5238       }
5239     }
5240     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
5241       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
5242       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
5243       if(sbY1+sbH > aTol){
5244         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
5245         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
5246         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
5247       }
5248     }
5249     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
5250       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5251       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
5252       if(sbX1+sbW > aTol){
5253         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
5254         sbX1=0.1;
5255         sbW=0.08;
5256         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5257         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
5258       }
5259     }
5260     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
5261       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5262       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
5263       if(sbY1+sbH > aTol){
5264         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
5265         sbY1=0.01;
5266         sbH=0.08;
5267         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5268         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
5269       }
5270     }
5271     else if ( name == "segmentation" ) {
5272       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
5273       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
5274     }
5275     else if ( name == "nb_segments_per_edge" ) {
5276       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
5277       myComponentSMESH->SetDefaultNbSegments( nbSeg );
5278     }
5279     else if ( name == "historical_python_dump" ||
5280               name == "forget_mesh_on_hyp_modif") {
5281       QString val = aResourceMgr->stringValue( "SMESH", name );
5282       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
5283     }
5284     else if ( name == QString( "numbering_node_color" ) || name == QString( "numbering_node_font" ) ) {
5285       SMESH::UpdateFontProp( this );    
5286     }
5287     else if ( name == QString( "numbering_elem_color" ) || name == QString( "numbering_elem_font" ) ) {
5288       SMESH::UpdateFontProp( this );
5289     }
5290
5291     if(aWarning.size() != 0){
5292       aWarning += "The default values are applied instead.";
5293       SUIT_MessageBox::warning(SMESHGUI::desktop(),
5294                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
5295                                QObject::tr(aWarning.c_str()));
5296     }
5297   }
5298 }
5299
5300 //================================================================================
5301 /*!
5302  * \brief Update something in accordance with update flags
5303   * \param theFlags - update flags
5304 *
5305 * Update viewer or/and object browser etc. in accordance with update flags ( see
5306 * LightApp_UpdateFlags enumeration ).
5307 */
5308 //================================================================================
5309 void SMESHGUI::update( const int flags )
5310 {
5311   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5312     SMESH::UpdateView();
5313   else
5314     SalomeApp_Module::update( flags );
5315 }
5316
5317 //================================================================================
5318 /*!
5319  * \brief Set default selection mode
5320 *
5321 * SLOT called when operation commited. Sets default selection mode
5322 */
5323 //================================================================================
5324 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5325 {
5326   SVTK_ViewWindow* vtkWnd =
5327     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5328   if ( vtkWnd )
5329     vtkWnd->SetSelectionMode( ActorSelection );
5330 }
5331
5332 //================================================================================
5333 /*!
5334  * \brief Set default selection mode
5335 *
5336 * SLOT called when operation aborted. Sets default selection mode
5337 */
5338 //================================================================================
5339 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5340 {
5341   SVTK_ViewWindow* vtkWnd =
5342     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5343   if ( vtkWnd )
5344     vtkWnd->SetSelectionMode( ActorSelection );
5345 }
5346
5347 //================================================================================
5348 /*!
5349  * \brief Creates operation with given identifier
5350   * \param id - identifier of operation to be started
5351   * \return Pointer on created operation or NULL if operation is not created
5352 *
5353 * Virtual method redefined from the base class creates operation with given id.
5354 * It is called called automatically from startOperation method of base class.
5355 */
5356 //================================================================================
5357 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5358 {
5359   LightApp_Operation* op = 0;
5360   // to do : create operation here
5361   switch( id )
5362   {
5363     case 417: //convert to quadratic
5364       op = new SMESHGUI_ConvToQuadOp();
5365     break;
5366     case 418: // create 2D mesh as boundary on 3D
5367       op = new SMESHGUI_Make2DFrom3DOp();
5368     break;
5369     case 420: // Reorient faces
5370       op = new SMESHGUI_ReorientFacesOp();
5371       break;
5372     case 701: // Compute mesh
5373       op = new SMESHGUI_ComputeOp();
5374     break;
5375     case 702: // Create mesh
5376       op = new SMESHGUI_MeshOp( true, true );
5377     break;
5378     case 703: // Create sub-mesh
5379       op = new SMESHGUI_MeshOp( true, false );
5380     break;
5381     case 704: // Edit mesh/sub-mesh
5382       op = new SMESHGUI_MeshOp( false );
5383     break;
5384     case 711: // Precompute mesh
5385       op = new SMESHGUI_PrecomputeOp();
5386     break;
5387     case 712: // Evaluate mesh
5388       op = new SMESHGUI_EvaluateOp();
5389     break;
5390     case 713: // Evaluate mesh
5391       op = new SMESHGUI_MeshOrderOp();
5392     break;
5393     case 806: // Create group on geom
5394       op = new SMESHGUI_GroupOnShapeOp();
5395       break;
5396     case 904: // Find element
5397       op = new SMESHGUI_FindElemByPointOp();
5398       break;
5399     case 4067: // Make mesh pass through point
5400       op = new SMESHGUI_MakeNodeAtPointOp();
5401       break;
5402     case 4070: // Create 0D elements on all nodes
5403       op = new SMESHGUI_Add0DElemsOnAllNodesOp();
5404       break;
5405     default:
5406     break;
5407   }
5408
5409   if( !op )
5410     op = SalomeApp_Module::createOperation( id );
5411   return op;
5412 }
5413
5414 //================================================================================
5415 /*!
5416  * \brief Stops current operations and starts a given one
5417   * \param id - The id of the operation to start
5418  */
5419 //================================================================================
5420
5421 void SMESHGUI::switchToOperation(int id)
5422 {
5423   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
5424     activeStudy()->abortAllOperations();
5425   startOperation( id );
5426 }
5427
5428 LightApp_Displayer* SMESHGUI::displayer()
5429 {
5430   if( !myDisplayer )
5431     myDisplayer = new SMESHGUI_Displayer( getApp() );
5432   return myDisplayer;
5433 }
5434
5435 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
5436 {
5437   int aHue = -1;
5438   int aTolerance = 64;
5439   int anIterations = 0;
5440   int aPeriod = 5;
5441
5442   while( 1 )
5443   {
5444     anIterations++;
5445     if( anIterations % aPeriod == 0 )
5446     {
5447       aTolerance /= 2;
5448       if( aTolerance < 1 )
5449         break;
5450     }
5451
5452     aHue = (int)( 360.0 * rand() / RAND_MAX );
5453
5454     bool ok = true;
5455     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
5456     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
5457     for( ; it != itEnd; ++it )
5458     {
5459       SALOMEDS::Color anAutoColor = *it;
5460       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
5461
5462       int h, s, v;
5463       aQColor.getHsv( &h, &s, &v );
5464       if( abs( h - aHue ) < aTolerance )
5465       {
5466         ok = false;
5467         break;
5468       }
5469     }
5470
5471     if( ok )
5472       break;
5473   }
5474
5475   QColor aColor;
5476   aColor.setHsv( aHue, 255, 255 );
5477
5478   SALOMEDS::Color aSColor;
5479   aSColor.R = aColor.redF();
5480   aSColor.G = aColor.greenF();
5481   aSColor.B = aColor.blueF();
5482
5483   return aSColor;
5484 }
5485
5486 const char* gSeparator = "_"; // character used to separate parameter names
5487 const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
5488 const char* gPathSep   = "|"; // character used to separate paths
5489
5490 /*!
5491  * \brief Store visual parameters
5492  *
5493  * This method is called just before the study document is saved.
5494  * Store visual parameters in AttributeParameter attribue(s)
5495  */
5496 void SMESHGUI::storeVisualParameters (int savePoint)
5497 {
5498   // localizing
5499   Kernel_Utils::Localizer loc;
5500
5501   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5502   if (!appStudy || !appStudy->studyDS())
5503     return;
5504   _PTR(Study) studyDS = appStudy->studyDS();
5505
5506   // componentName is used for encoding of entries when storing them in IParameters
5507   std::string componentName = myComponentSMESH->ComponentDataType();
5508   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
5509   //if (!aSComponent) return;
5510
5511   // IParameters
5512   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5513                                                              componentName.c_str(),
5514                                                              savePoint);
5515   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5516
5517   // store map of custom markers
5518   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5519   if( !aMarkerMap.empty() )
5520   {
5521     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
5522     for( ; anIter != aMarkerMap.end(); anIter++ )
5523     {
5524       int anId = anIter->first;
5525       VTK::MarkerData aMarkerData = anIter->second;
5526       std::string aMarkerFileName = aMarkerData.first;
5527       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
5528       if( aMarkerTexture.size() < 3 )
5529         continue; // should contain at least width, height and the first value
5530
5531       QString aPropertyName( "texture" );
5532       aPropertyName += gSeparator;
5533       aPropertyName += QString::number( anId );
5534
5535       QString aPropertyValue = aMarkerFileName.c_str();
5536       aPropertyValue += gPathSep;
5537
5538       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
5539       ushort aWidth = *aTextureIter++;
5540       ushort aHeight = *aTextureIter++;
5541       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
5542       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
5543       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
5544         aPropertyValue += QString::number( *aTextureIter );
5545
5546       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5547     }
5548   }
5549
5550   // viewers counters are used for storing view_numbers in IParameters
5551   int vtkViewers = 0;
5552
5553   // main cycle to store parameters of displayed objects
5554   QList<SUIT_ViewManager*> lst;
5555   QList<SUIT_ViewManager*>::Iterator it;
5556   getApp()->viewManagers(lst);
5557   for (it = lst.begin(); it != lst.end(); it++)
5558   {
5559     SUIT_ViewManager* vman = *it;
5560     QString vType = vman->getType();
5561
5562     // saving VTK actors properties
5563     if (vType == SVTK_Viewer::Type())
5564     {
5565       // store the clipping planes attached to the view manager
5566       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
5567       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
5568       if( anIter != myClippingPlaneInfoMap.end() )
5569         aClippingPlaneInfoList = anIter->second;
5570
5571       if( !aClippingPlaneInfoList.empty() ) {
5572         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
5573         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
5574         {
5575           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
5576           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
5577
5578           QString aPropertyName( "ClippingPlane" );
5579           aPropertyName += gSeparator;
5580           aPropertyName += QString::number( vtkViewers );
5581           aPropertyName += gSeparator;
5582           aPropertyName += QString::number( anId );
5583
5584           QString aPropertyValue = QString::number( (int)aPlane->PlaneMode ).toLatin1().constData();
5585           aPropertyValue += gDigitsSep;
5586           aPropertyValue += QString::number( aPlane->IsOpenGLClipping ).toLatin1().constData();
5587           aPropertyValue += gDigitsSep;
5588           if ( aPlane->PlaneMode == SMESH::Absolute ) {
5589             aPropertyValue += QString::number( aPlane->myAbsoluteOrientation ).toLatin1().constData();
5590             aPropertyValue += gDigitsSep;
5591             aPropertyValue += QString::number( aPlane->X ).toLatin1().constData();
5592             aPropertyValue += gDigitsSep;
5593             aPropertyValue += QString::number( aPlane->Y ).toLatin1().constData();
5594             aPropertyValue += gDigitsSep;
5595             aPropertyValue += QString::number( aPlane->Z ).toLatin1().constData();
5596             aPropertyValue += gDigitsSep;
5597             aPropertyValue += QString::number( aPlane->Dx ).toLatin1().constData();
5598             aPropertyValue += gDigitsSep;
5599             aPropertyValue += QString::number( aPlane->Dy ).toLatin1().constData();
5600             aPropertyValue += gDigitsSep;
5601             aPropertyValue += QString::number( aPlane->Dz ).toLatin1().constData();
5602           }
5603           else if ( aPlane->PlaneMode == SMESH::Relative ) {
5604             aPropertyValue += QString::number( (int)aPlane->myRelativeOrientation ).toLatin1().constData();
5605             aPropertyValue += gDigitsSep;
5606             aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5607             aPropertyValue += gDigitsSep;
5608             aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5609             aPropertyValue += gDigitsSep;
5610             aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5611           }
5612
5613           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5614         }
5615       }
5616
5617       QVector<SUIT_ViewWindow*> views = vman->getViews();
5618       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5619       {
5620         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5621         {
5622           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5623           vtkActorCollection* allActors = aCopy.GetActors();
5624           allActors->InitTraversal();
5625           while (vtkActor* actor = allActors->GetNextActor())
5626           {
5627             if (actor->GetVisibility()) // store only visible actors
5628             {
5629               SMESH_Actor* aSmeshActor = 0;
5630               if (actor->IsA("SMESH_Actor"))
5631                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5632               if (aSmeshActor && aSmeshActor->hasIO())
5633               {
5634                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5635                 if (io->hasEntry())
5636                 {
5637                   // entry is "encoded" = it does NOT contain component adress,
5638                   // since it is a subject to change on next component loading
5639                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5640
5641                   std::string param, vtkParam = vType.toLatin1().data();
5642                   vtkParam += gSeparator;
5643                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5644                   vtkParam += gSeparator;
5645
5646                   // Visibility
5647                   param = vtkParam + "Visibility";
5648                   ip->setParameter(entry, param, "On");
5649
5650                   // Representation
5651                   param = vtkParam + "Representation";
5652                   ip->setParameter(entry, param, QString::number
5653                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5654
5655                   // IsShrunk
5656                   param = vtkParam + "IsShrunk";
5657                   ip->setParameter(entry, param, QString::number
5658                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5659
5660                   // Displayed entities
5661                   unsigned int aMode = aSmeshActor->GetEntityMode();
5662                   bool isE  = aMode & SMESH_Actor::eEdges;
5663                   bool isF  = aMode & SMESH_Actor::eFaces;
5664                   bool isV  = aMode & SMESH_Actor::eVolumes;
5665                   bool is0d = aMode & SMESH_Actor::e0DElements;
5666                   bool isB  = aMode & SMESH_Actor::eBallElem;
5667
5668                   QString modeStr ("e");
5669                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5670                   modeStr += gDigitsSep; modeStr += "f";
5671                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5672                   modeStr += gDigitsSep; modeStr += "v";
5673                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5674                   modeStr += gDigitsSep; modeStr += "0d";
5675                   modeStr += gDigitsSep; modeStr += QString::number(is0d);
5676                   modeStr += gDigitsSep; modeStr += "b";
5677                   modeStr += gDigitsSep; modeStr += QString::number(isB);
5678
5679                   param = vtkParam + "Entities";
5680                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5681
5682                   // Colors
5683                   double r, g, b;
5684                   int delta;
5685
5686                   aSmeshActor->GetSufaceColor(r, g, b, delta);
5687                   QStringList colorStr;
5688                   colorStr << "surface";
5689                   colorStr << QString::number(r);
5690                   colorStr << QString::number(g);
5691                   colorStr << QString::number(b);
5692
5693                   colorStr << "backsurface";
5694                   colorStr << QString::number(delta);
5695
5696                   aSmeshActor->GetVolumeColor(r, g, b, delta);
5697                   colorStr << "volume";
5698                   colorStr << QString::number(r);
5699                   colorStr << QString::number(g);
5700                   colorStr << QString::number(b);
5701                   colorStr << QString::number(delta);
5702
5703                   aSmeshActor->GetEdgeColor(r, g, b);
5704                   colorStr << "edge";
5705                   colorStr << QString::number(r);
5706                   colorStr << QString::number(g);
5707                   colorStr << QString::number(b);
5708
5709                   aSmeshActor->GetNodeColor(r, g, b);
5710                   colorStr << "node";
5711                   colorStr << QString::number(r);
5712                   colorStr << QString::number(g);
5713                   colorStr << QString::number(b);
5714
5715                   aSmeshActor->GetOutlineColor(r, g, b);
5716                   colorStr << "outline";
5717                   colorStr << QString::number(r);
5718                   colorStr << QString::number(g);
5719                   colorStr << QString::number(b);
5720
5721                   aSmeshActor->Get0DColor(r, g, b);
5722                   colorStr << "elem0d";
5723                   colorStr << QString::number(r);
5724                   colorStr << QString::number(g);
5725                   colorStr << QString::number(b);
5726
5727                   aSmeshActor->GetBallColor(r, g, b);
5728                   colorStr << "ball";
5729                   colorStr << QString::number(r);
5730                   colorStr << QString::number(g);
5731                   colorStr << QString::number(b);
5732
5733                   aSmeshActor->GetFacesOrientationColor(r, g, b);
5734                   colorStr << "orientation";
5735                   colorStr << QString::number(r);
5736                   colorStr << QString::number(g);
5737                   colorStr << QString::number(b);
5738
5739                   param = vtkParam + "Colors";
5740                   ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
5741
5742                   // Sizes
5743                   QStringList sizeStr;
5744                   sizeStr << "line";
5745                   sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
5746                   sizeStr << "outline";
5747                   sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
5748                   sizeStr << "elem0d";
5749                   sizeStr << QString::number((int)aSmeshActor->Get0DSize());
5750                   sizeStr << "ball";
5751                   sizeStr << QString::number((int)aSmeshActor->GetBallSize());
5752                   sizeStr << QString::number((double)aSmeshActor->GetBallScale());
5753                   sizeStr << "shrink";
5754                   sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
5755                   sizeStr << "orientation";
5756                   sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
5757                   sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
5758
5759                   param = vtkParam + "Sizes";
5760                   ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
5761
5762                   // Point marker
5763                   QString markerStr;
5764
5765                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5766                   if( aMarkerType == VTK::MT_USER ) {
5767                     markerStr += "custom";
5768                     markerStr += gDigitsSep;
5769                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5770                   }
5771                   else {
5772                     markerStr += "std";
5773                     markerStr += gDigitsSep;
5774                     markerStr += QString::number( (int)aMarkerType );
5775                     markerStr += gDigitsSep;
5776                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5777                   }
5778
5779                   param = vtkParam + "PointMarker";
5780                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5781
5782                   // Opacity
5783                   param = vtkParam + "Opacity";
5784                   ip->setParameter(entry, param,
5785                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5786
5787                   // Clipping
5788                   param = vtkParam + "ClippingPlane";
5789                   int aPlaneId = 0;
5790                   if( !aClippingPlaneInfoList.empty() ) {
5791                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5792                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5793                     {
5794                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5795                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5796                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5797                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5798                         if( aSmeshActor == *anIter2 ) {
5799                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5800                                             QString::number( anId ).toLatin1().constData() );
5801                           break;
5802                         }
5803                       }
5804                     }
5805                   }
5806                   if( aPlaneId == 0 )
5807                     ip->setParameter( entry, param, "Off" );
5808                 } // if (io->hasEntry())
5809               } // SMESH_Actor && hasIO
5810             } // isVisible
5811           } // while.. actors traversal
5812         } // if (vtkView)
5813       } // for (views)
5814       vtkViewers++;
5815     } // if (SVTK view model)
5816   } // for (viewManagers)
5817 }
5818
5819 // data structures for clipping planes processing
5820 typedef struct {
5821   int Id;
5822   int Mode;
5823   bool isOpenGLClipping;
5824   vtkIdType RelativeOrientation;
5825   double Distance;
5826   double Angle[2];
5827   int AbsoluteOrientation;
5828   double X, Y, Z, Dx, Dy, Dz;
5829 } TPlaneData;
5830 typedef std::list<TPlaneData>         TPlaneDataList;
5831 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5832
5833 typedef std::list<vtkActor*>          TActorList;
5834 typedef struct {
5835   int PlaneId;
5836   TActorList ActorList;
5837   SUIT_ViewManager* ViewManager;
5838 } TPlaneInfo;
5839 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5840 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5841
5842 /*!
5843  * \brief Restore visual parameters
5844  *
5845  * This method is called after the study document is opened.
5846  * Restore visual parameters from AttributeParameter attribue(s)
5847  */
5848 void SMESHGUI::restoreVisualParameters (int savePoint)
5849 {
5850   // localizing
5851   Kernel_Utils::Localizer loc;
5852
5853   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5854   if (!appStudy || !appStudy->studyDS())
5855     return;
5856   _PTR(Study) studyDS = appStudy->studyDS();
5857
5858   // componentName is used for encoding of entries when storing them in IParameters
5859   std::string componentName = myComponentSMESH->ComponentDataType();
5860   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5861   //if (!aSComponent) return;
5862
5863   // IParameters
5864   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5865                                                              componentName.c_str(),
5866                                                              savePoint);
5867   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5868
5869   // restore map of custom markers and map of clipping planes
5870   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5871   TPlaneDataMap aPlaneDataMap;
5872
5873   std::vector<std::string> properties = ip->getProperties();
5874   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5875   {
5876     std::string property = *propIt;
5877     QString aPropertyName( property.c_str() );
5878     QString aPropertyValue( ip->getProperty( property ).c_str() );
5879
5880     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5881     if( aPropertyNameList.isEmpty() )
5882       continue;
5883
5884     QString aPropertyType = aPropertyNameList[0];
5885     if( aPropertyType == "texture" )
5886     {
5887       if( aPropertyNameList.size() != 2 )
5888         continue;
5889
5890       bool ok = false;
5891       int anId = aPropertyNameList[1].toInt( &ok );
5892       if( !ok || anId < 1 )
5893         continue;
5894
5895       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5896       if( aPropertyValueList.size() != 2 )
5897         continue;
5898
5899       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5900       QString aMarkerTextureString = aPropertyValueList[1];
5901       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5902       if( aMarkerTextureStringList.size() != 3 )
5903         continue;
5904
5905       ok = false;
5906       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5907       if( !ok )
5908         continue;
5909
5910       ok = false;
5911       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5912       if( !ok )
5913         continue;
5914
5915       VTK::MarkerTexture aMarkerTexture;
5916       aMarkerTexture.push_back( aWidth );
5917       aMarkerTexture.push_back( aHeight );
5918
5919       QString aMarkerTextureData = aMarkerTextureStringList[2];
5920       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5921       {
5922         QChar aChar = aMarkerTextureData.at( i );
5923         if( aChar.isDigit() )
5924           aMarkerTexture.push_back( aChar.digitValue() );
5925       }
5926
5927       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5928     }
5929     else if( aPropertyType == "ClippingPlane" )
5930     {
5931       if( aPropertyNameList.size() != 3 )
5932         continue;
5933
5934       bool ok = false;
5935       int aViewId = aPropertyNameList[1].toInt( &ok );
5936       if( !ok || aViewId < 0 )
5937         continue;
5938
5939       ok = false;
5940       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5941       if( !ok || aClippingPlaneId < 0 )
5942         continue;
5943
5944       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5945       if( aPropertyValueList.size() != 6 && aPropertyValueList.size() != 9 )
5946         continue;
5947
5948       TPlaneData aPlaneData;
5949       aPlaneData.Id = aClippingPlaneId;
5950
5951       ok = false;
5952       aPlaneData.Mode = aPropertyValueList[0].toInt( &ok );
5953       if( !ok )
5954         continue;
5955       
5956       ok = false;
5957       aPlaneData.isOpenGLClipping = aPropertyValueList[1].toInt( &ok );
5958       if( !ok )
5959         continue;
5960
5961       if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Absolute )
5962       {
5963         ok = false;
5964         aPlaneData.AbsoluteOrientation = aPropertyValueList[2].toInt( &ok );
5965         if( !ok )
5966           continue;
5967
5968         ok = false;
5969         aPlaneData.X = aPropertyValueList[3].toDouble( &ok );
5970         if( !ok )
5971           continue;
5972
5973         ok = false;
5974         aPlaneData.Y = aPropertyValueList[4].toDouble( &ok );
5975         if( !ok )
5976           continue;
5977
5978         ok = false;
5979         aPlaneData.Z = aPropertyValueList[5].toDouble( &ok );
5980         if( !ok )
5981           continue;
5982
5983         ok = false;
5984         aPlaneData.Dx = aPropertyValueList[6].toDouble( &ok );
5985         if( !ok )
5986           continue;
5987
5988         ok = false;
5989         aPlaneData.Dy = aPropertyValueList[7].toDouble( &ok );
5990         if( !ok )
5991           continue;
5992
5993         ok = false;
5994         aPlaneData.Dz = aPropertyValueList[8].toDouble( &ok );
5995         if( !ok )
5996           continue;
5997       }
5998       else if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Relative ) {
5999         ok = false;
6000         aPlaneData.RelativeOrientation = aPropertyValueList[2].toInt( &ok );
6001         if( !ok )
6002           continue;
6003
6004         ok = false;
6005         aPlaneData.Distance = aPropertyValueList[3].toDouble( &ok );
6006         if( !ok )
6007           continue;
6008
6009         ok = false;
6010         aPlaneData.Angle[0] = aPropertyValueList[4].toDouble( &ok );
6011         if( !ok )
6012           continue;
6013
6014         ok = false;
6015         aPlaneData.Angle[1] = aPropertyValueList[5].toDouble( &ok );
6016         if( !ok )
6017           continue;
6018       }
6019
6020       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
6021       aPlaneDataList.push_back( aPlaneData );
6022     }
6023   }
6024
6025   TPlaneInfoMap aPlaneInfoMap;
6026
6027   std::vector<std::string> entries = ip->getEntries();
6028
6029   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
6030   {
6031     // entry is a normal entry - it should be "decoded" (setting base adress of component)
6032     QString entry (ip->decodeEntry(*entIt).c_str());
6033
6034     // Check that the entry corresponds to a real object in the Study
6035     // as the object may be deleted or modified after the visual state is saved.
6036     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
6037     if (!so) continue; //Skip the not existent entry
6038
6039     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
6040     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
6041
6042     std::vector<std::string>::iterator namesIt = paramNames.begin();
6043     std::vector<std::string>::iterator valuesIt = paramValues.begin();
6044
6045     // actors are stored in a map after displaying of them for
6046     // quicker access in the future: map < viewID to actor >
6047     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
6048
6049     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
6050     {
6051       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
6052       // '_' is used as separator and should not be used in viewer type or parameter names.
6053       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
6054       if (lst.size() != 3)
6055         continue;
6056
6057       QString viewerTypStr = lst[0];
6058       QString viewIndexStr = lst[1];
6059       QString paramNameStr = lst[2];
6060
6061       bool ok;
6062       int viewIndex = viewIndexStr.toUInt(&ok);
6063       if (!ok) // bad conversion of view index to integer
6064         continue;
6065
6066       // viewers
6067       if (viewerTypStr == SVTK_Viewer::Type())
6068       {
6069         SMESH_Actor* aSmeshActor = 0;
6070         if (vtkActors.IsBound(viewIndex))
6071           aSmeshActor = vtkActors.Find(viewIndex);
6072
6073         QList<SUIT_ViewManager*> lst;
6074         getApp()->viewManagers(viewerTypStr, lst);
6075
6076         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6077         SUIT_ViewManager* vman = NULL;
6078         if (viewIndex >= 0 && viewIndex < lst.count())
6079           vman = lst.at(viewIndex);
6080
6081         if (paramNameStr == "Visibility")
6082         {
6083           if (!aSmeshActor && displayer() && vman)
6084           {
6085             SUIT_ViewModel* vmodel = vman->getViewModel();
6086             // SVTK view model can be casted to SALOME_View
6087             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
6088
6089             // store displayed actor in a temporary map for quicker
6090             // access later when restoring other parameters
6091             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6092             vtkRenderer* Renderer = vtkView->getRenderer();
6093             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
6094             vtkActorCollection* theActors = aCopy.GetActors();
6095             theActors->InitTraversal();
6096             bool isFound = false;
6097             vtkActor *ac = theActors->GetNextActor();
6098             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
6099               if (ac->IsA("SMESH_Actor")) {
6100                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
6101                 if (aGeomAc->hasIO()) {
6102                   Handle(SALOME_InteractiveObject) io =
6103                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
6104                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
6105                     isFound = true;
6106                     vtkActors.Bind(viewIndex, aGeomAc);
6107                   }
6108                 }
6109               }
6110             }
6111           }
6112         } // if (paramNameStr == "Visibility")
6113         else
6114         {
6115           // the rest properties "work" with SMESH_Actor
6116           if (aSmeshActor)
6117           {
6118             QString val ((*valuesIt).c_str());
6119
6120             // Representation
6121             if (paramNameStr == "Representation") {
6122               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
6123             }
6124             // IsShrunk
6125             else if (paramNameStr == "IsShrunk") {
6126               if (val.toInt()) {
6127                 if (!aSmeshActor->IsShrunk())
6128                   aSmeshActor->SetShrink();
6129               }
6130               else {
6131                 if (aSmeshActor->IsShrunk())
6132                   aSmeshActor->UnShrink();
6133               }
6134             }
6135             // Displayed entities
6136             else if (paramNameStr == "Entities") {
6137               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
6138               int aEntityMode = SMESH_Actor::eAllEntity;
6139               for ( int i = 0; i < mode.count(); i+=2 ) {
6140                 if ( i < mode.count()-1 ) {
6141                   QString type = mode[i];
6142                   bool val = mode[i+1].toInt();
6143                   if      ( type == "e" && !val )
6144                     aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
6145                   else if ( type == "f" && !val )
6146                     aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
6147                   else if ( type == "v" && !val )
6148                     aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
6149                   else if ( type == "0d" && !val )
6150                     aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
6151                   else if ( type == "b" && !val )
6152                     aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
6153                 }
6154               }
6155               aSmeshActor->SetEntityMode( aEntityMode );
6156             }
6157             // Colors
6158             else if (paramNameStr == "Colors") {
6159               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
6160               QColor nodeColor;
6161               QColor edgeColor;
6162               QColor faceColor;
6163               QColor volumeColor;
6164               QColor elem0dColor;
6165               QColor ballColor;
6166               QColor outlineColor;
6167               QColor orientationColor;
6168               int deltaF;
6169               int deltaV;
6170               QColor c;
6171               double r, g, b;
6172               bool bOk;
6173               // below lines are required to get default values for delta coefficients
6174               // of backface color for faces and color of reversed volumes
6175               SMESH::GetColor( "SMESH", "fill_color",   c, deltaF, "0,170,255|-100" );
6176               SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
6177               for ( int i = 0; i < colors.count(); i++ ) {
6178                 QString type = colors[i];
6179                 if ( type == "surface" ) {
6180                   // face color is set by 3 values r:g:b, where
6181                   // - r,g,b - is rgb color components
6182                   if ( i+1 >= colors.count() ) break;                  // format error
6183                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6184                   if ( i+2 >= colors.count() ) break;                  // format error
6185                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6186                   if ( i+3 >= colors.count() ) break;                  // format error
6187                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6188                   faceColor.setRgbF( r, g, b );
6189                   i += 3;
6190                 }
6191                 else if ( type == "backsurface" ) {
6192                   // backface color can be defined in several ways
6193                   // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
6194                   // - in latest versions, it is set as delta coefficient
6195                   bool rgbOk = false, deltaOk;
6196                   if ( i+1 >= colors.count() ) break;                  // format error
6197                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6198                   int delta = colors[i+1].toInt( &deltaOk );
6199                   i++;                                 // shift index
6200                   if ( i+1 < colors.count() )          // index is shifted to 1
6201                     g = colors[i+1].toDouble( &rgbOk );
6202                   if ( rgbOk ) i++;                    // shift index
6203                   if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
6204                     b = colors[i+1].toDouble( &rgbOk );
6205                   if ( rgbOk ) i++;
6206                   // - as currently there's no way to set directly backsurface color as it was before,
6207                   // we ignore old dump where r,g,b triple was set
6208                   // - also we check that delta parameter is set properly
6209                   if ( !rgbOk && deltaOk )
6210                     deltaF = delta;
6211                 }
6212                 else if ( type == "volume" ) {
6213                   // volume color is set by 4 values r:g:b:delta, where
6214                   // - r,g,b - is a normal volume rgb color components
6215                   // - delta - is a reversed volume color delta coefficient
6216                   if ( i+1 >= colors.count() ) break;                  // format error
6217                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6218                   if ( i+2 >= colors.count() ) break;                  // format error
6219                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6220                   if ( i+3 >= colors.count() ) break;                  // format error
6221                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6222                   if ( i+4 >= colors.count() ) break;                  // format error
6223                   int delta = colors[i+4].toInt( &bOk );
6224                   if ( !bOk ) break;                                   // format error
6225                   volumeColor.setRgbF( r, g, b );
6226                   deltaV = delta;
6227                   i += 4;
6228                 }
6229                 else if ( type == "edge" ) {
6230                   // edge color is set by 3 values r:g:b, where
6231                   // - r,g,b - is rgb color components
6232                   if ( i+1 >= colors.count() ) break;                  // format error
6233                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6234                   if ( i+2 >= colors.count() ) break;                  // format error
6235                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6236                   if ( i+3 >= colors.count() ) break;                  // format error
6237                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6238                   edgeColor.setRgbF( r, g, b );
6239                   i += 3;
6240                 }
6241                 else if ( type == "node" ) {
6242                   // node color is set by 3 values r:g:b, where
6243                   // - r,g,b - is rgb color components
6244                   if ( i+1 >= colors.count() ) break;                  // format error
6245                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6246                   if ( i+2 >= colors.count() ) break;                  // format error
6247                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6248                   if ( i+3 >= colors.count() ) break;                  // format error
6249                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6250                   nodeColor.setRgbF( r, g, b );
6251                   i += 3;
6252                 }
6253                 else if ( type == "elem0d" ) {
6254                   // 0d element color is set by 3 values r:g:b, where
6255                   // - r,g,b - is rgb color components
6256                   if ( i+1 >= colors.count() ) break;                  // format error
6257                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6258                   if ( i+2 >= colors.count() ) break;                  // format error
6259                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6260                   if ( i+3 >= colors.count() ) break;                  // format error
6261                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6262                   elem0dColor.setRgbF( r, g, b );
6263                   i += 3;
6264                 }
6265                 else if ( type == "ball" ) {
6266                   // ball color is set by 3 values r:g:b, where
6267                   // - r,g,b - is rgb color components
6268                   if ( i+1 >= colors.count() ) break;                  // format error
6269                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6270                   if ( i+2 >= colors.count() ) break;                  // format error
6271                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6272                   if ( i+3 >= colors.count() ) break;                  // format error
6273                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6274                   ballColor.setRgbF( r, g, b );
6275                   i += 3;
6276                 }
6277                 else if ( type == "outline" ) {
6278                   // outline color is set by 3 values r:g:b, where
6279                   // - r,g,b - is rgb color components
6280                   if ( i+1 >= colors.count() ) break;                  // format error
6281                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6282                   if ( i+2 >= colors.count() ) break;                  // format error
6283                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6284                   if ( i+3 >= colors.count() ) break;                  // format error
6285                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6286                   outlineColor.setRgbF( r, g, b );
6287                   i += 3;
6288                 }
6289                 else if ( type == "orientation" ) {
6290                   // orientation color is set by 3 values r:g:b, where
6291                   // - r,g,b - is rgb color components
6292                   if ( i+1 >= colors.count() ) break;                  // format error
6293                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6294                   if ( i+2 >= colors.count() ) break;                  // format error
6295                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6296                   if ( i+3 >= colors.count() ) break;                  // format error
6297                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6298                   orientationColor.setRgbF( r, g, b );
6299                   i += 3;
6300                 }
6301               }
6302               // node color
6303               if ( nodeColor.isValid() )
6304                 aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
6305               // edge color
6306               if ( edgeColor.isValid() )
6307                 aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
6308               // face color
6309               if ( faceColor.isValid() )
6310                 aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6311               // volume color
6312               if ( volumeColor.isValid() )
6313                 aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
6314               else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
6315                 aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6316               // 0d element color
6317               if ( elem0dColor.isValid() )
6318                 aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
6319               // ball color
6320               if ( ballColor.isValid() )
6321                 aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
6322               // outline color
6323               if ( outlineColor.isValid() )
6324                 aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
6325               // orientation color
6326               if ( orientationColor.isValid() )
6327                 aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
6328             }
6329             // Sizes
6330             else if (paramNameStr == "Sizes") {
6331               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
6332               bool bOk;
6333               int lineWidth = -1;
6334               int outlineWidth = -1;
6335               int elem0dSize = -1;
6336               int ballSize = -1;
6337               double ballScale = -1.0;
6338               double shrinkSize = -1;
6339               double orientationSize = -1;
6340               bool orientation3d = false;
6341               for ( int i = 0; i < sizes.count(); i++ ) {
6342                 QString type = sizes[i];
6343                 if ( type == "line" ) {
6344                   // line (wireframe) width is given as single integer value
6345                   if ( i+1 >= sizes.count() ) break;                    // format error
6346                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6347                   lineWidth = v;
6348                   i++;
6349                 }
6350                 if ( type == "outline" ) {
6351                   // outline width is given as single integer value
6352                   if ( i+1 >= sizes.count() ) break;                    // format error
6353                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6354                   outlineWidth = v;
6355                   i++;
6356                 }
6357                 else if ( type == "elem0d" ) {
6358                   // 0d element size is given as single integer value
6359                   if ( i+1 >= sizes.count() ) break;                    // format error
6360                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6361                   elem0dSize = v;
6362                   i++;
6363                 }
6364                 else if ( type == "ball" ) {
6365                   // balls are specified by two values: size:scale, where
6366                   // - size - is a integer value specifying size
6367                   // - scale - is a double value specifying scale factor
6368                   if ( i+1 >= sizes.count() ) break;                       // format error
6369                   int v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6370                   if ( i+2 >= sizes.count() ) break;                       // format error
6371                   double v2 = sizes[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6372                   ballSize = v1;
6373                   ballScale = v2;
6374                   i += 2;
6375                 }
6376                 else if ( type == "shrink" ) {
6377                   // shrink factor is given as single floating point value
6378                   if ( i+1 >= sizes.count() ) break;                          // format error
6379                   double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break;  // format error
6380                   shrinkSize = v;
6381                   i++;
6382                 }
6383                 else if ( type == "orientation" ) {
6384                   // orientation vectors are specified by two values size:3d, where
6385                   // - size - is a floating point value specifying scale factor
6386                   // - 3d - is a boolean
6387                   if ( i+1 >= sizes.count() ) break;                          // format error
6388                   double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6389                   if ( i+2 >= sizes.count() ) break;                          // format error
6390                   int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break;       // format error
6391                   orientationSize = v1;
6392                   orientation3d = (bool)v2;
6393                   i += 2;
6394                 }
6395               }
6396               // line (wireframe) width
6397               if ( lineWidth > 0 )
6398                 aSmeshActor->SetLineWidth( lineWidth );
6399               // outline width
6400               if ( outlineWidth > 0 )
6401                 aSmeshActor->SetOutlineWidth( outlineWidth );
6402               else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
6403                 aSmeshActor->SetOutlineWidth( lineWidth );
6404               // 0d element size
6405               if ( elem0dSize > 0 )
6406                 aSmeshActor->Set0DSize( elem0dSize );
6407               // ball size
6408               if ( ballSize > 0 )
6409                 aSmeshActor->SetBallSize( ballSize );
6410               // ball scale
6411               if ( ballScale > 0.0 )
6412                 aSmeshActor->SetBallScale( ballScale );
6413               // shrink factor
6414               if ( shrinkSize > 0 )
6415                 aSmeshActor->SetShrinkFactor( shrinkSize );
6416               // orientation vectors
6417               if ( orientationSize > 0 ) {
6418                 aSmeshActor->SetFacesOrientationScale( orientationSize );
6419                 aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
6420               }
6421             }
6422             // Point marker
6423             else if (paramNameStr == "PointMarker") {
6424               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
6425               if( data.count() >= 2 ) {
6426                 bool ok = false;
6427                 int aParam1 = data[1].toInt( &ok );
6428                 if( ok ) {
6429                   if( data[0] == "std" && data.count() == 3 ) {
6430                     int aParam2 = data[2].toInt( &ok );
6431                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
6432                   }
6433                   else if( data[0] == "custom" ) {
6434                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
6435                     if( markerIt != aMarkerMap.end() ) {
6436                       VTK::MarkerData aMarkerData = markerIt->second;
6437                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
6438                     }
6439                   }
6440                 }
6441               }
6442             }
6443             // Opacity
6444             else if (paramNameStr == "Opacity") {
6445               aSmeshActor->SetOpacity(val.toFloat());
6446             }
6447             // Clipping
6448             else if (paramNameStr.startsWith("ClippingPlane")) {
6449               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
6450               // old format - val looks like "Off" or "1:0:0:0.5:0:0" 
6451               // (mode(relative), is OpenGL clipping plane, orientation, distance, two angles)
6452               // or "0:1:1:10.5:1.0:1.0:15.0:10.0:10.0" 
6453               // (mode(absolute), is OpenGL clipping plane, orientation, base point(x, y, z), direction (dx, dy, dz))
6454               // new format - val looks like "Off" or "0" (plane id)
6455               // (note: in new format "Off" value is used only for consistency,
6456               //  so it is processed together with values in old format)
6457               bool anIsOldFormat = ( vals.count() == 6 || vals.count() == 9 || val == "Off" );
6458               if( anIsOldFormat ) {
6459                 if (paramNameStr == "ClippingPlane1" || val == "Off")
6460                   aSmeshActor->RemoveAllClippingPlanes();
6461                 if (val != "Off") {
6462                   QList<SUIT_ViewManager*> lst;
6463                   getApp()->viewManagers(viewerTypStr, lst);
6464                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6465                   if (viewIndex >= 0 && viewIndex < lst.count()) {
6466                     SUIT_ViewManager* vman = lst.at(viewIndex);
6467                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6468
6469                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
6470
6471                     SMESH::TActorList anActorList;
6472                     anActorList.push_back( aSmeshActor );
6473                     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( vtkView );
6474                     aPlane->myViewWindow = vtkView;
6475                     SMESH::Mode aMode = ( SMESH::Mode )vals[0].toInt();
6476                     aPlane->PlaneMode = aMode;
6477                     bool isOpenGLClipping = ( bool )vals[1].toInt();
6478                     aPlane->IsOpenGLClipping = isOpenGLClipping;
6479                     if ( aMode == SMESH::Absolute ) {
6480                       aPlane->myAbsoluteOrientation = vals[2].toInt();
6481                       aPlane->X = vals[3].toFloat();
6482                       aPlane->Y = vals[4].toFloat();
6483                       aPlane->Z = vals[5].toFloat();
6484                       aPlane->Dx = vals[6].toFloat();
6485                       aPlane->Dy = vals[7].toFloat();
6486                       aPlane->Dz = vals[8].toFloat();
6487                     }
6488                     else if ( aMode == SMESH::Relative ) {
6489                       aPlane->myRelativeOrientation = (SMESH::Orientation)vals[2].toInt();
6490                       aPlane->myDistance = vals[3].toFloat();
6491                       aPlane->myAngle[0] = vals[4].toFloat();
6492                       aPlane->myAngle[1] = vals[5].toFloat();
6493                     }
6494
6495                     if( aPlane ) {
6496                       if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6497                         SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6498                         aClippingPlaneInfo.Plane = aPlane;
6499                         aClippingPlaneInfo.ActorList = anActorList;
6500                         aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6501                       }
6502                     }
6503                   }
6504                 }
6505               }
6506               else {
6507                 bool ok = false;
6508                 int aPlaneId = val.toInt( &ok );
6509                 if( ok && aPlaneId >= 0 ) {
6510                   bool anIsDefinedPlane = false;
6511                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
6512                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
6513                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6514                     TPlaneInfo& aPlaneInfo = *anIter;
6515                     if( aPlaneInfo.PlaneId == aPlaneId ) {
6516                       aPlaneInfo.ActorList.push_back( aSmeshActor );
6517                       anIsDefinedPlane = true;
6518                       break;
6519                     }
6520                   }
6521                   if( !anIsDefinedPlane ) {
6522                     TPlaneInfo aPlaneInfo;
6523                     aPlaneInfo.PlaneId = aPlaneId;
6524                     aPlaneInfo.ActorList.push_back( aSmeshActor );
6525                     aPlaneInfo.ViewManager = vman;
6526
6527                     // to make the list sorted by plane id
6528                     anIter = aPlaneInfoList.begin();
6529                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6530                       const TPlaneInfo& aPlaneInfoRef = *anIter;
6531                       if( aPlaneInfoRef.PlaneId > aPlaneId )
6532                         break;
6533                     }
6534                     aPlaneInfoList.insert( anIter, aPlaneInfo );
6535                   }
6536                 }
6537               }
6538             }
6539           } // if (aSmeshActor)
6540         } // other parameters than Visibility
6541       }
6542     } // for names/parameters iterator
6543   } // for entries iterator
6544
6545   // take into account planes with empty list of actors referred to them
6546   QList<SUIT_ViewManager*> aVMList;
6547   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
6548
6549   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
6550   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
6551     int aViewId = aPlaneDataIter->first;
6552     if( aViewId >= 0 && aViewId < aVMList.count() ) {
6553       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
6554
6555       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
6556
6557       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
6558       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
6559       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
6560         const TPlaneData& aPlaneData = *anIter2;
6561         int aPlaneId = aPlaneData.Id;
6562
6563         bool anIsFound = false;
6564         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6565         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6566           const TPlaneInfo& aPlaneInfo = *anIter3;
6567           if( aPlaneInfo.PlaneId == aPlaneId ) {
6568             anIsFound = true;
6569             break;
6570           }
6571         }
6572
6573         if( !anIsFound ) {
6574           TPlaneInfo aPlaneInfo; // ActorList field is empty
6575           aPlaneInfo.PlaneId = aPlaneId;
6576           aPlaneInfo.ViewManager = aViewManager;
6577
6578           // to make the list sorted by plane id
6579           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
6580           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
6581             const TPlaneInfo& aPlaneInfoRef = *anIter4;
6582             if( aPlaneInfoRef.PlaneId > aPlaneId )
6583               break;
6584           }
6585           aPlaneInfoList.insert( anIter4, aPlaneInfo );
6586         }
6587       }
6588     }
6589   }
6590
6591   // add clipping planes to actors according to the restored parameters
6592   // and update the clipping plane map
6593   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
6594   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
6595     int aViewId = anIter1->first;
6596     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
6597
6598     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
6599     if( anIter2 == aPlaneDataMap.end() )
6600       continue;
6601     const TPlaneDataList& aPlaneDataList = anIter2->second;
6602
6603     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6604     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6605       const TPlaneInfo& aPlaneInfo = *anIter3;
6606       int aPlaneId = aPlaneInfo.PlaneId;
6607       const TActorList& anActorList = aPlaneInfo.ActorList;
6608       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
6609       if( !aViewManager )
6610         continue;
6611
6612       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
6613       if( !aViewWindow )
6614         continue;
6615
6616       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
6617
6618       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
6619       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
6620         const TPlaneData& aPlaneData = *anIter4;
6621         if( aPlaneData.Id == aPlaneId ) {
6622           SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( aViewWindow );
6623           aPlane->myViewWindow = aViewWindow;
6624           aPlane->PlaneMode = (SMESH::Mode)aPlaneData.Mode;
6625           aPlane->IsOpenGLClipping = aPlaneData.isOpenGLClipping;
6626           if ( aPlane->PlaneMode == SMESH::Absolute ) {
6627             aPlane->myAbsoluteOrientation = aPlaneData.AbsoluteOrientation;
6628             aPlane->X = aPlaneData.X;
6629             aPlane->Y = aPlaneData.Y;
6630             aPlane->Z = aPlaneData.Z;
6631             aPlane->Dx = aPlaneData.Dx;
6632             aPlane->Dy = aPlaneData.Dy;
6633             aPlane->Dz = aPlaneData.Dz;
6634           }
6635           else if ( aPlane->PlaneMode == SMESH::Relative ) {
6636             aPlane->myRelativeOrientation = (SMESH::Orientation)aPlaneData.RelativeOrientation;
6637             aPlane->myDistance = aPlaneData.Distance;
6638             aPlane->myAngle[0] = aPlaneData.Angle[0];
6639             aPlane->myAngle[1] = aPlaneData.Angle[1];
6640           }
6641           if( aPlane ) {
6642             if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6643               SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6644               aClippingPlaneInfo.Plane = aPlane;
6645               aClippingPlaneInfo.ActorList = anActorList;
6646               aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6647             }
6648           }
6649           break;
6650         }
6651       }
6652     
6653     }
6654   }
6655   
6656
6657   // update all VTK views
6658   QList<SUIT_ViewManager*> lst;
6659   getApp()->viewManagers(lst);
6660   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
6661     SUIT_ViewModel* vmodel = (*it)->getViewModel();
6662     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
6663       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
6664       // set OpenGL clipping planes
6665       VTK::ActorCollectionCopy aCopy( vtkView->getRenderer()->GetActors() );
6666       vtkActorCollection* anAllActors = aCopy.GetActors();
6667       anAllActors->InitTraversal();
6668       while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
6669         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
6670           anActor->SetOpenGLClippingPlane();
6671       
6672       vtkView->getRenderer()->ResetCameraClippingRange();
6673       vtkView->Repaint();
6674     }
6675   }
6676 }
6677
6678 /*!
6679   \brief Adds preferences for dfont of VTK viewer
6680   \param label label
6681   \param pIf group identifier
6682   \param param parameter
6683   \return identifier of preferences
6684 */
6685 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
6686 {
6687   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
6688
6689   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
6690
6691   QStringList fam;
6692   fam.append( tr( "SMESH_FONT_ARIAL" ) );
6693   fam.append( tr( "SMESH_FONT_COURIER" ) );
6694   fam.append( tr( "SMESH_FONT_TIMES" ) );
6695
6696   setPreferenceProperty( tfont, "fonts", fam );
6697
6698   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
6699   if ( needSize ) f = f | QtxFontEdit::Size;
6700   setPreferenceProperty( tfont, "features", f );
6701
6702   return tfont;
6703 }
6704
6705 /*!
6706   \brief Actions after hypothesis edition
6707   Updates object browser after hypothesis edition
6708 */
6709 void SMESHGUI::onHypothesisEdit( int result )
6710 {
6711   if( result == 1 )
6712     SMESHGUI::Modified();
6713   updateObjBrowser( true );
6714 }
6715
6716
6717 /*!
6718   \brief Signal handler closing(SUIT_ViewWindow*) of a view
6719   \param pview view being closed
6720 */
6721 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
6722 #ifndef DISABLE_PLOT2DVIEWER
6723   //Crear all Plot2d Viewers if need.
6724   SMESH::ClearPlot2Viewers(pview);
6725 #endif
6726 }
6727
6728 void SMESHGUI::message( const QString& msg )
6729 {
6730   // dispatch message
6731   QStringList data = msg.split("/");
6732   if ( data.count() > 0 ) {
6733     if ( data.first() == "mesh_loading" ) {
6734       // get mesh entry
6735       QString entry = data.count() > 1 ? data[1] : QString();
6736       if ( entry.isEmpty() )
6737         return;
6738       // get study
6739       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
6740       // get mesh name
6741       _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().constData() );
6742       QString name;
6743       if ( obj )
6744         name = obj->GetName().c_str();
6745       if ( name.isEmpty() )
6746         return;
6747       
6748       if ( data.last() == "stop" )
6749         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
6750       else
6751         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
6752       QApplication::processEvents();
6753     }
6754   }
6755 }
6756
6757 /*!
6758   \brief Connects or disconnects signals about activating and cloning view on the module slots
6759   \param pview view which is connected/disconnected
6760 */
6761 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
6762   if(!pview)
6763     return;
6764
6765   SUIT_ViewManager* viewMgr = pview->getViewManager();
6766   if ( viewMgr ) {
6767     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6768                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6769
6770     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
6771              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
6772   }
6773 }
6774
6775 /*!
6776   \brief Return \c true if object can be renamed
6777 */
6778 bool SMESHGUI::renameAllowed( const QString& entry) const {
6779   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6780   if( !anApp )
6781     return false;
6782
6783   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6784   if( !appStudy )
6785     return false;
6786
6787   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
6788   
6789   if(!obj)
6790     return false;
6791
6792   if(appStudy->isComponent(entry) || obj->isReference())
6793     return false;
6794
6795   // check type to prevent renaming of inappropriate objects
6796   int aType = SMESHGUI_Selection::type(qPrintable(entry), SMESH::GetActiveStudyDocument());
6797   if (aType == SMESH::MESH || aType == SMESH::GROUP ||
6798       aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
6799       aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
6800       aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
6801       aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
6802     return true;
6803
6804   return false;
6805 }
6806
6807 /*!
6808   Rename object by entry.
6809   \param entry entry of the object
6810   \param name new name of the object
6811   \brief Return \c true if rename operation finished successfully, \c false otherwise.
6812 */
6813 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
6814
6815   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
6816   if( !anApp )
6817     return false;
6818     
6819   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
6820
6821   if(!appStudy)
6822     return false;
6823   
6824   _PTR(Study) aStudy = appStudy->studyDS();
6825   
6826   if(!aStudy)
6827     return false;
6828   
6829   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
6830   if ( aLocked ) {
6831     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
6832     return false;
6833   }
6834
6835
6836   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
6837   _PTR(GenericAttribute) anAttr;
6838   _PTR(AttributeName) aName;
6839   if ( obj ) {
6840     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
6841       aName = anAttr;
6842       // check type to prevent renaming of inappropriate objects
6843       int aType = SMESHGUI_Selection::type( qPrintable(entry), SMESH::GetActiveStudyDocument() );
6844       if (aType == SMESH::MESH || aType == SMESH::GROUP ||
6845           aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
6846           aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
6847           aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
6848           aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
6849         if ( !name.isEmpty() ) {
6850           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
6851
6852           // update name of group object and its actor
6853           Handle(SALOME_InteractiveObject) IObject =
6854             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
6855
6856           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
6857           if( !aGroupObject->_is_nil() ) {
6858             aGroupObject->SetName( qPrintable(name) );
6859             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
6860               anActor->setName( qPrintable(name) );
6861           }
6862           return true;
6863         }
6864       }
6865     }
6866   }
6867   return false;
6868 }
6869
6870 SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
6871 {
6872   static QList<QColor> colors;
6873
6874   if ( colors.isEmpty() ) {
6875
6876     for (int s = 0; s < 2 ; s++)
6877     {
6878       for (int v = 100; v >= 40; v = v - 20)
6879       {
6880         for (int h = 0; h < 359 ; h = h + 60)
6881         {
6882           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
6883         }
6884       }
6885     }
6886   }
6887   static int currentColor = 0;
6888
6889   SALOMEDS::Color color;
6890   color.R = (double)colors[currentColor].red()   / 255.0;
6891   color.G = (double)colors[currentColor].green() / 255.0;
6892   color.B = (double)colors[currentColor].blue()  / 255.0;
6893
6894   currentColor = (currentColor+1) % colors.count();
6895
6896   return color;
6897 }