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