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