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