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   createMenu( 116, importId, -1 );
3506
3507   createMenu( 121, exportId, -1 );
3508   createMenu( 122, exportId, -1 );
3509   createMenu( 123, exportId, -1 );
3510   createMenu( 140, exportId, -1 ); // export to STL
3511   createMenu( 142, exportId, -1 ); // export to CGNS
3512
3513   createMenu( separator(), fileId, 10 );
3514
3515   createMenu( 33, editId, -1 );
3516
3517   createMenu( 5105, toolsId, -1 );
3518
3519   createMenu( 702, meshId, -1 ); // "Mesh" menu
3520   createMenu( 703, meshId, -1 );
3521   createMenu( 704, meshId, -1 );
3522   createMenu( 710, meshId, -1 );
3523   createMenu( 705, meshId, -1 );
3524   createMenu( separator(), meshId, -1 );
3525   createMenu( 701, meshId, -1 );
3526   createMenu( 711, meshId, -1 );
3527   createMenu( 712, meshId, -1 );
3528   createMenu( 713, meshId, -1 );
3529   createMenu( separator(), meshId, -1 );
3530   createMenu( 801, meshId, -1 );
3531   createMenu( 806, meshId, -1 );
3532   createMenu( 802, meshId, -1 );
3533   createMenu( 803, meshId, -1 );
3534   createMenu( 815, meshId, -1 );
3535   createMenu( separator(), meshId, -1 );
3536   createMenu( 810, meshId, -1 );
3537   createMenu( 811, meshId, -1 );
3538   createMenu( 812, meshId, -1 );
3539   createMenu( separator(), meshId, -1 );
3540   createMenu( 814, meshId, -1 );
3541   createMenu( separator(), meshId, -1 );
3542   createMenu( 900, meshId, -1 );
3543   //createMenu( 902, meshId, -1 );
3544   //createMenu( 903, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3545   createMenu( 904, meshId, -1 );
3546   createMenu( separator(), meshId, -1 );
3547
3548   createMenu( 6005, nodeId, -1 );
3549   createMenu( 6002, edgeId, -1 );
3550   createMenu( 6003, edgeId, -1 );
3551   createMenu( 6001, edgeId, -1 );
3552   createMenu( 6004, edgeId, -1 );
3553   createMenu( 6021, faceId, -1 );
3554   createMenu( 6025, faceId, -1 );
3555   createMenu( 6027, faceId, -1 );
3556   createMenu( 6018, faceId, -1 );
3557   createMenu( 6019, faceId, -1 );
3558   createMenu( 6011, faceId, -1 );
3559   createMenu( 6012, faceId, -1 );
3560   createMenu( 6013, faceId, -1 );
3561   createMenu( 6014, faceId, -1 );
3562   createMenu( 6015, faceId, -1 );
3563   createMenu( 6016, faceId, -1 );
3564   createMenu( 6022, faceId, -1 );
3565   createMenu( 6017, volumeId, -1 );
3566   createMenu( 6009, volumeId, -1 );
3567   createMenu( 6023, volumeId, -1 );
3568   createMenu( 6024, volumeId, -1 );
3569   createMenu( 6026, volumeId, -1 );
3570
3571   createMenu( 4000, addId, -1 );
3572   createMenu( 4009, addId, -1 );
3573   createMenu( 4010, addId, -1 );
3574   createMenu( 4021, addId, -1 );
3575   createMenu( 4022, addId, -1 );
3576   createMenu( 4023, addId, -1 );
3577   createMenu( 4031, addId, -1 );
3578   createMenu( 4032, addId, -1 );
3579   createMenu( 4033, addId, -1 );
3580   createMenu( separator(), addId, -1 );
3581   createMenu( 4034, addId, -1 );
3582   createMenu( 4035, addId, -1 );
3583   createMenu( 4036, addId, -1 );
3584   createMenu( 4037, addId, -1 );
3585   createMenu( 4038, addId, -1 );
3586   createMenu( 4039, addId, -1 );
3587   createMenu( 4040, addId, -1 );
3588
3589   createMenu( 4041, removeId, -1 );
3590   createMenu( 4042, removeId, -1 );
3591   createMenu( 4044, removeId, -1 );
3592   createMenu( separator(), removeId, -1 );
3593   createMenu( 813, removeId, -1 );
3594   createMenu( separator(), removeId, -1 );
3595   createMenu( 4043, removeId, -1 );
3596
3597   createMenu( 4051, renumId, -1 );
3598   createMenu( 4052, renumId, -1 );
3599
3600   createMenu( 4061, transfId, -1 );
3601   createMenu( 4062, transfId, -1 );
3602   createMenu( 4063, transfId, -1 );
3603   createMenu( 4068, transfId, -1 );
3604   createMenu( 4064, transfId, -1 );
3605   createMenu( 4065, transfId, -1 );
3606   createMenu( 4066, transfId, -1 );
3607   createMenu( 4069, transfId, -1 );
3608
3609   createMenu( 4067,modifyId, -1 );
3610   createMenu( 407, modifyId, -1 );
3611   createMenu( 408, modifyId, -1 );
3612   createMenu( 409, modifyId, -1 );
3613   createMenu( 410, modifyId, -1 );
3614   createMenu( 411, modifyId, -1 );
3615   createMenu( 419, modifyId, -1 );
3616   createMenu( 412, modifyId, -1 );
3617   createMenu( 413, modifyId, -1 );
3618   createMenu( 416, modifyId, -1 );
3619   createMenu( 414, modifyId, -1 );
3620   createMenu( 415, modifyId, -1 );
3621   createMenu( 417, modifyId, -1 );
3622   createMenu( 418, modifyId, -1 );
3623
3624   createMenu( 501, measureId, -1 );
3625   createMenu( 502, measureId, -1 );
3626   createMenu( 214, viewId, -1 );
3627
3628   // ----- create toolbars --------------
3629   int meshTb     = createTool( tr( "TB_MESH" ) ),
3630       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3631       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3632       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3633       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3634
3635   createTool( 702, meshTb );
3636   createTool( 703, meshTb );
3637   createTool( 704, meshTb );
3638   createTool( 710, meshTb );
3639   createTool( 705, meshTb );
3640   createTool( separator(), meshTb );
3641   createTool( 701, meshTb );
3642   createTool( 711, meshTb );
3643   createTool( 712, meshTb );
3644   createTool( 713, meshTb );
3645   createTool( separator(), meshTb );
3646   createTool( 801, meshTb );
3647   createTool( 806, meshTb );
3648   createTool( 802, meshTb );
3649   createTool( 803, meshTb );
3650   //createTool( 815, meshTb );
3651   createTool( separator(), meshTb );
3652   createTool( 900, meshTb );
3653   //createTool( 902, meshTb );
3654   //createTool( 903, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3655   createTool( 904, meshTb );
3656   createTool( separator(), meshTb );
3657
3658   createTool( 6005, ctrlTb );
3659   createTool( separator(), ctrlTb );
3660   createTool( 6002, ctrlTb );
3661   createTool( 6003, ctrlTb );
3662   createTool( 6001, ctrlTb );
3663   createTool( 6004, ctrlTb );
3664   createTool( separator(), ctrlTb );
3665   createTool( 6021, ctrlTb );
3666   createTool( 6025, ctrlTb );
3667   createTool( 6027, ctrlTb );
3668   createTool( 6018, ctrlTb );
3669   createTool( 6019, ctrlTb );
3670   createTool( 6011, ctrlTb );
3671   createTool( 6012, ctrlTb );
3672   createTool( 6013, ctrlTb );
3673   createTool( 6014, ctrlTb );
3674   createTool( 6015, ctrlTb );
3675   createTool( 6016, ctrlTb );
3676   createTool( 6022, ctrlTb );
3677   createTool( separator(), ctrlTb );
3678   createTool( 6017, ctrlTb );
3679   createTool( 6009, ctrlTb );
3680   createTool( 6023, ctrlTb );
3681   createTool( 6024, ctrlTb );
3682   createTool( 6026, ctrlTb );
3683   createTool( separator(), ctrlTb );
3684
3685   createTool( 4000, addRemTb );
3686   createTool( 4009, addRemTb );
3687   createTool( 4010, addRemTb );
3688   createTool( 4021, addRemTb );
3689   createTool( 4022, addRemTb );
3690   createTool( 4023, addRemTb );
3691   createTool( 4031, addRemTb );
3692   createTool( 4032, addRemTb );
3693   createTool( 4033, addRemTb );
3694   createTool( separator(), addRemTb );
3695   createTool( 4034, addRemTb );
3696   createTool( 4035, addRemTb );
3697   createTool( 4036, addRemTb );
3698   createTool( 4037, addRemTb );
3699   createTool( 4038, addRemTb );
3700   createTool( 4039, addRemTb );
3701   createTool( 4040, addRemTb );
3702   createTool( separator(), addRemTb );
3703   createTool( 4041, addRemTb );
3704   createTool( 4042, addRemTb );
3705   createTool( 4044, addRemTb );
3706   createTool( 4043, addRemTb );
3707   createTool( separator(), addRemTb );
3708   createTool( 4051, addRemTb );
3709   createTool( 4052, addRemTb );
3710   createTool( separator(), addRemTb );
3711   createTool( 4061, addRemTb );
3712   createTool( 4062, addRemTb );
3713   createTool( 4063, addRemTb );
3714   createTool( 4068, addRemTb );
3715   createTool( 4064, addRemTb );
3716   createTool( 4065, addRemTb );
3717   createTool( 4066, addRemTb );
3718   createTool( 4069, addRemTb );
3719   createTool( separator(), addRemTb );
3720
3721   createTool( 4067,modifyTb );
3722   createTool( 407, modifyTb );
3723   createTool( 408, modifyTb );
3724   createTool( 409, modifyTb );
3725   createTool( 410, modifyTb );
3726   createTool( 411, modifyTb );
3727   createTool( 419, modifyTb );
3728   createTool( 412, modifyTb );
3729   createTool( 413, modifyTb );
3730   createTool( 416, modifyTb );
3731   createTool( 414, modifyTb );
3732   createTool( 415, modifyTb );
3733   createTool( 417, modifyTb );
3734   createTool( 418, modifyTb );
3735
3736   createTool( 214, dispModeTb );
3737
3738   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3739   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3740
3741   myRules.clear();
3742   QString OB = "'ObjectBrowser'",
3743           View = "'" + SVTK_Viewer::Type() + "'",
3744           pat = "'%1'",
3745           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3746           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3747           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3748           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3749           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3750                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3751                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3752                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3753                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3754                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3755                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3756           subMesh = elems,
3757           mesh_part = mesh + " " + subMesh + " " + group,
3758           mesh_group = mesh + " " + group,
3759           hyp_alg = hypo + " " + algo;
3760
3761   // popup for object browser
3762   QString
3763     isInvisible("not( isVisible )"),
3764     isEmpty("numberOfNodes = 0"),
3765     isNotEmpty("numberOfNodes <> 0"),
3766
3767     // has nodes, edges, etc in VISIBLE! actor
3768     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3769     hasElems("(count( elemTypes ) > 0)"),
3770     hasDifferentElems("(count( elemTypes ) > 1)"),
3771     hasElems0d("({'Elem0d'} in elemTypes)"),
3772     hasEdges("({'Edge'} in elemTypes)"),
3773     hasFaces("({'Face'} in elemTypes)"),
3774     hasVolumes("({'Volume'} in elemTypes)");
3775
3776   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3777   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3778   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3779   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3780   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3781   createPopupItem( 815, OB, group, "&& groupType != 'Group'" ); // EDIT AS STANDALONE
3782
3783   popupMgr()->insert( separator(), -1, 0 );
3784   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3785   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3786   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
3787   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
3788   createPopupItem( 214, OB, mesh_part );                   // UPDATE
3789   createPopupItem( 900, OB, mesh_part );                   // ADV_INFO
3790   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
3791   popupMgr()->insert( separator(), -1, 0 );
3792   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3793   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3794   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3795   popupMgr()->insert( separator(), -1, 0 );
3796   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3797   createPopupItem( 1102, OB, hyp_alg );                    // REMOVE HYPOTHESIS / ALGORITHMS
3798   popupMgr()->insert( separator(), -1, 0 );
3799   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3800   popupMgr()->insert( separator(), -1, 0 );
3801   createPopupItem( 417, OB, mesh + " " + subMesh );        // convert to quadratic
3802   createPopupItem( 418, OB, mesh + " " + group,            // create 2D mesh from 3D
3803                    "&& dim>=2"); 
3804   popupMgr()->insert( separator(), -1, 0 );
3805
3806   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3807   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
3808   QString only_one_2D        = only_one_non_empty + " && dim>1";
3809
3810   createPopupItem( 125, OB, mesh_group, multiple_non_empty );   // EXPORT_MED
3811   createPopupItem( 126, OB, mesh_group, only_one_non_empty );   // EXPORT_UNV
3812   createPopupItem( 141, OB, mesh_group, only_one_2D );          // EXPORT_STL
3813   createPopupItem( 143, OB, mesh_group, multiple_non_empty );   // EXPORT_CGNS
3814   createPopupItem(  33, OB, mesh_part + " " + hyp_alg );        // DELETE
3815   popupMgr()->insert( separator(), -1, 0 );
3816
3817   // popup for viewer
3818   createPopupItem( 803, View, group ); // EDIT_GROUP
3819   createPopupItem( 804, View, elems ); // ADD
3820   createPopupItem( 805, View, elems ); // REMOVE
3821
3822   popupMgr()->insert( separator(), -1, 0 );
3823   createPopupItem( 214, View, mesh_part );  // UPDATE
3824   createPopupItem( 900, View, mesh_part );  // ADV_INFO
3825   createPopupItem( 904, View, mesh );       // FIND_ELEM
3826   popupMgr()->insert( separator(), -1, 0 );
3827
3828   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3829   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3830   popupMgr()->insert( separator(), -1, 0 );
3831
3832   int anId;
3833   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3834   QString aType = QString( "%1type in {%2}" ).arg( lc );
3835   aType = aType.arg( mesh_part );
3836   QString aMeshInVTK = aClient + "&&" + aType;
3837
3838   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3839   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3840   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3841
3842   //-------------------------------------------------
3843   // Numbering
3844   //-------------------------------------------------
3845   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3846
3847   popupMgr()->insert( action( 9010 ), anId, -1 );
3848   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
3849   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
3850
3851   popupMgr()->insert( action( 9011 ), anId, -1 );
3852   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
3853   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
3854
3855   popupMgr()->insert( separator(), -1, -1 );
3856
3857   //-------------------------------------------------
3858   // Display Mode
3859   //-------------------------------------------------
3860   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3861
3862   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3863   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3864   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3865
3866   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3867   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3868   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3869
3870   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3871   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3872   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3873
3874   popupMgr()->insert( separator(), anId, -1 );
3875
3876   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3877   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3878   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3879
3880   //-------------------------------------------------
3881   // Display Entity
3882   //-------------------------------------------------
3883   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3884
3885   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3886
3887   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
3888   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
3889   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
3890
3891   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3892   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3893   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3894
3895   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3896   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3897   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3898
3899   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3900   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3901   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3902
3903   popupMgr()->insert( separator(), anId, -1 );
3904
3905   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3906   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3907
3908
3909   //-------------------------------------------------
3910   // Representation of the 2D Quadratic elements
3911   //-------------------------------------------------
3912   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
3913   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
3914   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
3915   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
3916
3917   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
3918   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
3919   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
3920
3921   //-------------------------------------------------
3922   // Orientation of faces
3923   //-------------------------------------------------
3924   popupMgr()->insert( action( 221 ), -1, -1 );
3925   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3926   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3927
3928   //-------------------------------------------------
3929   // Color / Size
3930   //-------------------------------------------------
3931   popupMgr()->insert( action( 1132 ), -1, -1 );
3932   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3933
3934   //-------------------------------------------------
3935   // Transparency
3936   //-------------------------------------------------
3937   popupMgr()->insert( action( 1133 ), -1, -1 );
3938   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3939
3940   //-------------------------------------------------
3941   // Controls
3942   //-------------------------------------------------
3943   QString
3944     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
3945     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3946     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3947     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3948
3949   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3950
3951   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3952   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3953
3954   popupMgr()->insert( separator(), anId, -1 );
3955
3956   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
3957
3958   popupMgr()->insert( action( 6005 ), aSubId, -1 ); // FREE_NODE
3959   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
3960   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
3961
3962   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
3963
3964   popupMgr()->insert( action( 6002 ), aSubId, -1 ); // FREE_EDGE
3965   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3966   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3967
3968   popupMgr()->insert( action( 6003 ), aSubId, -1 ); // FREE_BORDER
3969   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3970   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3971
3972   popupMgr()->insert( action( 6001 ), aSubId, -1 ); // LENGTH
3973   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3974   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3975
3976   popupMgr()->insert( action( 6004 ), aSubId, -1 ); // CONNECTION
3977   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3978   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3979
3980   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
3981
3982   popupMgr()->insert ( action( 6021 ), aSubId, -1 ); // FREE_FACE
3983   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
3984                                        QtxPopupMgr::VisibleRule );
3985   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
3986
3987   popupMgr()->insert ( action( 6018 ), aSubId, -1 ); // LENGTH_2D
3988   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3989   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3990
3991   popupMgr()->insert ( action( 6019 ), aSubId, -1 ); // CONNECTION_2D
3992   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3993   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3994
3995   popupMgr()->insert ( action( 6011 ), aSubId, -1 ); // AREA
3996   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3997   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3998
3999   popupMgr()->insert ( action( 6012 ), aSubId, -1 ); // TAPER
4000   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4001   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4002
4003   popupMgr()->insert ( action( 6013 ), aSubId, -1 ); // ASPECT
4004   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4005   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4006
4007   popupMgr()->insert ( action( 6014 ), aSubId, -1 ); // MIN_ANG
4008   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4009   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4010
4011   popupMgr()->insert ( action( 6015 ), aSubId, -1 ); // WARP
4012   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4013   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4014
4015   popupMgr()->insert ( action( 6016 ), aSubId, -1 ); // SKEW
4016   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4017   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4018
4019   popupMgr()->insert ( action( 6022 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_2D
4020   popupMgr()->setRule( action( 6022 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4021   popupMgr()->setRule( action( 6022 ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4022
4023   popupMgr()->insert ( action( 6025 ), aSubId, -1 ); // BARE_BORDER_FACE
4024   popupMgr()->setRule( action( 6025 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4025   popupMgr()->setRule( action( 6025 ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4026
4027   popupMgr()->insert ( action( 6027 ), aSubId, -1 ); // OVER_CONSTRAINED_FACE
4028   popupMgr()->setRule( action( 6027 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4029   popupMgr()->setRule( action( 6027 ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4030
4031   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4032
4033   popupMgr()->insert ( action( 6017 ), aSubId, -1 ); // ASPECT_3D
4034   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4035   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4036
4037   popupMgr()->insert ( action( 6009 ), aSubId, -1 ); // VOLUME_3D
4038   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4039   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4040
4041   popupMgr()->insert ( action( 6023 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_3D
4042   popupMgr()->setRule( action( 6023 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4043   popupMgr()->setRule( action( 6023 ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4044
4045   popupMgr()->insert ( action( 6024 ), aSubId, -1 ); // BARE_BORDER_VOLUME
4046   popupMgr()->setRule( action( 6024 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4047   popupMgr()->setRule( action( 6024 ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4048
4049   popupMgr()->insert ( action( 6026 ), aSubId, -1 ); // OVER_CONSTRAINED_VOLUME
4050   popupMgr()->setRule( action( 6026 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4051   popupMgr()->setRule( action( 6026 ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4052
4053   popupMgr()->insert( separator(), anId, -1 );
4054
4055   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
4056   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4057
4058   popupMgr()->insert( separator(), anId, -1 );
4059
4060   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4061
4062   popupMgr()->insert( action( 2021 ), aSubId, -1 ); // SAVE_DISTRIBUTION
4063   popupMgr()->setRule( action( 2021 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4064
4065   popupMgr()->insert( action( 2022 ), aSubId, -1 ); // SHOW_DISTRIBUTION
4066   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4067   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor && isDistributionVisible", QtxPopupMgr::ToggleRule);
4068
4069 #ifndef DISABLE_PLOT2DVIEWER
4070   popupMgr()->insert( action( 2023 ), aSubId, -1 ); // PLOT_DISTRIBUTION
4071   popupMgr()->setRule( action( 2023 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4072 #endif
4073
4074   //-------------------------------------------------
4075   // Display / Erase
4076   //-------------------------------------------------
4077   popupMgr()->insert( separator(), -1, -1 );
4078   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4079     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4080   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
4081   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4082
4083   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
4084   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4085
4086   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
4087   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4088
4089   popupMgr()->insert( separator(), -1, -1 );
4090
4091   //-------------------------------------------------
4092   // Clipping
4093   //-------------------------------------------------
4094   popupMgr()->insert( action( 1134 ), -1, -1 );
4095   popupMgr()->setRule( action( 1134 ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4096
4097   popupMgr()->insert( separator(), -1, -1 );
4098
4099   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4100            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4101
4102   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4103            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4104 }
4105
4106 //================================================================================
4107 /*!
4108  * \brief Return true if SMESH or GEOM objects are selected.
4109  * Is called form LightApp_Module::activateModule() which clear selection if
4110  * not isSelectionCompatible()
4111  */
4112 //================================================================================
4113
4114 bool SMESHGUI::isSelectionCompatible()
4115 {
4116   bool isCompatible = true;
4117   SALOME_ListIO selected;
4118   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4119     Sel->selectedObjects( selected );
4120
4121   SALOME_ListIteratorOfListIO It( selected );
4122   for ( ; isCompatible && It.More(); It.Next())
4123     isCompatible =
4124       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4125       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4126
4127   return isCompatible;
4128 }
4129
4130
4131 bool SMESHGUI::reusableOperation( const int id )
4132 {
4133   // compute, evaluate and precompute are not reusable operations
4134   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
4135 }
4136
4137 bool SMESHGUI::activateModule( SUIT_Study* study )
4138 {
4139   bool res = SalomeApp_Module::activateModule( study );
4140
4141   setMenuShown( true );
4142   setToolShown( true );
4143
4144   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4145   PyGILState_STATE gstate = PyGILState_Ensure();
4146   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
4147   if(pluginsmanager==NULL)
4148     PyErr_Print();
4149   else
4150     {
4151       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
4152       if(result==NULL)
4153         PyErr_Print();
4154       Py_XDECREF(result);
4155     }
4156   PyGILState_Release(gstate);
4157   // end of GEOM plugins loading
4158
4159   // Reset actions accelerator keys
4160   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
4161   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
4162   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
4163
4164   action(  33)->setEnabled(true); // Delete: Key_Delete
4165
4166   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4167   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
4168   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
4169     if ( _PTR(Study) aStudy = s->studyDS()) {
4170       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
4171       updateObjBrowser(); // objects can be removed
4172     }
4173   
4174   // get all view currently opened in the study and connect their signals  to
4175   // the corresponding slots of the class.
4176   SUIT_Desktop* aDesk = study->application()->desktop();
4177   if ( aDesk ) {
4178     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4179     SUIT_ViewWindow* wnd;
4180     foreach ( wnd, wndList )
4181       connectView( wnd );
4182   }
4183
4184   return res;
4185 }
4186
4187 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4188 {
4189   setMenuShown( false );
4190   setToolShown( false );
4191
4192   EmitSignalCloseAllDialogs();
4193
4194   // Unset actions accelerator keys
4195   action(111)->setShortcut(QKeySequence()); // Import DAT
4196   action(112)->setShortcut(QKeySequence()); // Import UNV
4197   action(113)->setShortcut(QKeySequence()); // Import MED
4198
4199   action(  33)->setEnabled(false); // Delete: Key_Delete
4200
4201   return SalomeApp_Module::deactivateModule( study );
4202 }
4203
4204 void SMESHGUI::studyClosed( SUIT_Study* s )
4205 {
4206   SMESH::RemoveVisuData( s->id() );
4207   SalomeApp_Module::studyClosed( s );
4208 }
4209
4210 void SMESHGUI::OnGUIEvent()
4211 {
4212   const QObject* obj = sender();
4213   if ( !obj || !obj->inherits( "QAction" ) )
4214     return;
4215   int id = actionId((QAction*)obj);
4216   if ( id != -1 )
4217     OnGUIEvent( id );
4218 }
4219
4220 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
4221 {
4222   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
4223   if ( CORBA::is_nil( myComponentSMESH ) )
4224     {
4225       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
4226       if ( aStudy )
4227         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4228       return aGUI.myComponentSMESH;
4229     }
4230   if ( aStudy )
4231     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4232   return myComponentSMESH;
4233 }
4234
4235 QString SMESHGUI::engineIOR() const
4236 {
4237   CORBA::ORB_var anORB = getApp()->orb();
4238   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
4239   return QString( anIOR.in() );
4240 }
4241
4242 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
4243 {
4244   SalomeApp_Module::contextMenuPopup( client, menu, title );
4245   SALOME_ListIO lst;
4246   selectionMgr()->selectedObjects( lst );
4247   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
4248     Handle(SALOME_InteractiveObject) io = lst.First();
4249     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
4250     _PTR(Study) study = appStudy->studyDS();
4251     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
4252     if ( obj ) {
4253       QString aName = QString( obj->GetName().c_str() );
4254       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
4255           aName.remove( (aName.length() - 1), 1 );
4256       title = aName;
4257     }
4258   }
4259 }
4260
4261 LightApp_Selection* SMESHGUI::createSelection() const
4262 {
4263   return new SMESHGUI_Selection();
4264 }
4265
4266 void SMESHGUI::windows( QMap<int, int>& aMap ) const
4267 {
4268   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
4269   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
4270 }
4271
4272 void SMESHGUI::viewManagers( QStringList& list ) const
4273 {
4274   list.append( SVTK_Viewer::Type() );
4275 }
4276
4277 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
4278 {
4279   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
4280     SMESH::UpdateSelectionProp( this );
4281     
4282     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
4283     for(int i = 0; i < aViews.count() ; i++){
4284       SUIT_ViewWindow *sf = aViews[i];
4285       connectView( sf );
4286     }
4287   }
4288 }
4289
4290 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
4291 {
4292   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
4293     myClippingPlaneInfoMap.erase( theViewManager );
4294 }
4295
4296 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
4297 {
4298   theActor->AddObserver( SMESH::DeleteActorEvent,
4299                          myEventCallbackCommand.GetPointer(),
4300                          myPriority );
4301 }
4302
4303 void SMESHGUI::ProcessEvents( vtkObject* theObject,
4304                               unsigned long theEvent,
4305                               void* theClientData,
4306                               void* theCallData )
4307 {
4308   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
4309     if( theObject && theEvent == SMESH::DeleteActorEvent ) {
4310       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
4311         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
4312         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
4313         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
4314           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
4315           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
4316           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
4317             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
4318             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
4319             SMESH::TActorList::iterator anIter3 = anActorList.begin();
4320             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
4321               if( anActor == *anIter3 ) {
4322                 anActorList.erase( anIter3 );
4323                 break;
4324               }
4325             }
4326           }
4327         }
4328       }
4329     }
4330   }
4331 }
4332
4333 void SMESHGUI::createPreferences()
4334 {
4335   // General tab ------------------------------------------------------------------------
4336   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
4337
4338   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
4339   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
4340   setPreferenceProperty( lim, "min",  0 );
4341   setPreferenceProperty( lim, "max",  100000000 );
4342   setPreferenceProperty( lim, "step", 1000 );
4343   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4344
4345   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
4346   setPreferenceProperty( qaGroup, "columns", 2 );
4347   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
4348   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
4349   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
4350   setPreferenceProperty( prec, "min", 0 );
4351   setPreferenceProperty( prec, "max", 16 );
4352
4353   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
4354   setPreferenceProperty( dispgroup, "columns", 2 );
4355   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
4356   QStringList modes;
4357   modes.append( "Wireframe" );
4358   modes.append( "Shading" );
4359   modes.append( "Nodes" );
4360   modes.append( "Shrink" );
4361   QList<QVariant> indices;
4362   indices.append( 0 );
4363   indices.append( 1 );
4364   indices.append( 2 );
4365   indices.append( 3 );
4366   setPreferenceProperty( dispmode, "strings", modes );
4367   setPreferenceProperty( dispmode, "indexes", indices );
4368
4369   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
4370   setPreferenceProperty( arcgroup, "columns", 2 );
4371   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
4372   QStringList quadraticModes;
4373   quadraticModes.append("Lines");
4374   quadraticModes.append("Arcs");
4375   indices.clear();
4376   indices.append( 0 );
4377   indices.append( 1 );
4378   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
4379   setPreferenceProperty( quadraticmode, "indexes", indices );
4380
4381   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
4382                               "SMESH", "max_angle" );
4383   setPreferenceProperty( maxAngle, "min", 1 );
4384   setPreferenceProperty( maxAngle, "max", 90 );
4385
4386
4387
4388   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
4389   setPreferenceProperty( exportgroup, "columns", 2 );
4390   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
4391   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
4392
4393   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
4394   setPreferenceProperty( computeGroup, "columns", 2 );
4395   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
4396   modes.clear();
4397   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
4398   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
4399   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
4400   indices.clear();
4401   indices.append( 0 );
4402   indices.append( 1 );
4403   indices.append( 2 );
4404   setPreferenceProperty( notifyMode, "strings", modes );
4405   setPreferenceProperty( notifyMode, "indexes", indices );
4406
4407   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
4408   setPreferenceProperty( computeGroup, "columns", 2 );
4409   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
4410   modes.clear();
4411   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
4412   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
4413   indices.clear();
4414   indices.append( 0 );
4415   indices.append( 1 );
4416   setPreferenceProperty( elemInfo, "strings", modes );
4417   setPreferenceProperty( elemInfo, "indexes", indices );
4418
4419   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
4420   setPreferenceProperty( segGroup, "columns", 2 );
4421   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
4422                               "SMESH", "segmentation" );
4423   setPreferenceProperty( segLen, "min", 1 );
4424   setPreferenceProperty( segLen, "max", 10000000 );
4425   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
4426                              "SMESH", "nb_segments_per_edge" );
4427   setPreferenceProperty( nbSeg, "min", 1 );
4428   setPreferenceProperty( nbSeg, "max", 10000000 );
4429
4430   // Quantities with individual precision settings
4431   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
4432   setPreferenceProperty( precGroup, "columns", 2 );
4433
4434   const int nbQuantities = 6;
4435   int precs[nbQuantities], ii = 0;
4436   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
4437                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
4438   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
4439                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
4440   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
4441                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
4442   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
4443                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
4444   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
4445                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
4446   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
4447                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
4448
4449   // Set property for precision value for spinboxes
4450   for ( ii = 0; ii < nbQuantities; ii++ ){
4451     setPreferenceProperty( precs[ii], "min", -14 );
4452     setPreferenceProperty( precs[ii], "max", 14 );
4453     setPreferenceProperty( precs[ii], "precision", 2 );
4454   }
4455
4456   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
4457   setPreferenceProperty( previewGroup, "columns", 2 );
4458   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
4459   setPreferenceProperty( chunkSize, "min",  0 );
4460   setPreferenceProperty( chunkSize, "max",  1000 );
4461   setPreferenceProperty( chunkSize, "step", 50 );
4462   
4463   // Mesh tab ------------------------------------------------------------------------
4464   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
4465   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
4466   setPreferenceProperty( nodeGroup, "columns", 3 );
4467
4468   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
4469
4470   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
4471
4472   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4473   QList<QVariant> aMarkerTypeIndicesList;
4474   QList<QVariant> aMarkerTypeIconsList;
4475   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
4476     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
4477     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
4478     aMarkerTypeIndicesList << i;
4479     aMarkerTypeIconsList << pixmap;
4480   }
4481   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
4482   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
4483
4484   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
4485
4486   QList<QVariant> aMarkerScaleIndicesList;
4487   QStringList     aMarkerScaleValuesList;
4488   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
4489     aMarkerScaleIndicesList << i;
4490     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
4491   }
4492   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
4493   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
4494
4495   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
4496   setPreferenceProperty( elemGroup, "columns", 2 );
4497
4498   addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
4499   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
4500   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
4501   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
4502
4503   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
4504   setPreferenceProperty( grpGroup, "columns", 2 );
4505
4506   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
4507
4508   //int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
4509   //setPreferenceProperty( sp, "hstretch", 0 );
4510   //setPreferenceProperty( sp, "vstretch", 0 );
4511
4512   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
4513                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
4514   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
4515   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
4516                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
4517   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
4518                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
4519
4520   setPreferenceProperty( size0d, "min", 1 );
4521   setPreferenceProperty( size0d, "max", 10 );
4522
4523   setPreferenceProperty( sp, "hstretch", 0 );
4524   setPreferenceProperty( sp, "vstretch", 0 );
4525
4526   setPreferenceProperty( elemW, "min", 1 );
4527   setPreferenceProperty( elemW, "max", 5 );
4528
4529   setPreferenceProperty( shrink, "min", 0 );
4530   setPreferenceProperty( shrink, "max", 100 );
4531
4532   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
4533   setPreferenceProperty( orientGroup, "columns", 1 );
4534
4535   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
4536   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
4537
4538   setPreferenceProperty( orientScale, "min", 0.05 );
4539   setPreferenceProperty( orientScale, "max", 0.5 );
4540   setPreferenceProperty( orientScale, "step", 0.05 );
4541
4542   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
4543
4544   // Selection tab ------------------------------------------------------------------------
4545   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
4546
4547   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
4548   setPreferenceProperty( selGroup, "columns", 2 );
4549
4550   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
4551   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
4552   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
4553
4554   setPreferenceProperty( selW, "min", 1 );
4555   setPreferenceProperty( selW, "max", 5 );
4556
4557   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
4558   setPreferenceProperty( preGroup, "columns", 2 );
4559
4560   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
4561   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
4562
4563   setPreferenceProperty( preW, "min", 1 );
4564   setPreferenceProperty( preW, "max", 5 );
4565
4566   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
4567   setPreferenceProperty( precSelGroup, "columns", 2 );
4568
4569   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
4570   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
4571   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
4572
4573   // Scalar Bar tab ------------------------------------------------------------------------
4574   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
4575   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
4576   setPreferenceProperty( fontGr, "columns", 2 );
4577
4578   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
4579   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
4580
4581   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
4582   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
4583
4584   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
4585   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
4586
4587   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
4588   setPreferenceProperty( numcol, "min", 2 );
4589   setPreferenceProperty( numcol, "max", 256 );
4590
4591   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
4592   setPreferenceProperty( numlab, "min", 2 );
4593   setPreferenceProperty( numlab, "max", 65 );
4594
4595   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
4596   setPreferenceProperty( orientGr, "columns", 2 );
4597   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
4598   QStringList orients;
4599   orients.append( tr( "SMESH_VERTICAL" ) );
4600   orients.append( tr( "SMESH_HORIZONTAL" ) );
4601   indices.clear(); indices.append( 0 ); indices.append( 1 );
4602   setPreferenceProperty( orient, "strings", orients );
4603   setPreferenceProperty( orient, "indexes", indices );
4604
4605   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
4606   setPreferenceProperty( posVSizeGr, "columns", 2 );
4607   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
4608   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
4609   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
4610   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
4611   setPreferenceProperty( xv, "step", 0.1 );
4612   setPreferenceProperty( xv, "min", 0.0 );
4613   setPreferenceProperty( xv, "max", 1.0 );
4614   setPreferenceProperty( yv, "step", 0.1 );
4615   setPreferenceProperty( yv, "min", 0.0 );
4616   setPreferenceProperty( yv, "max", 1.0 );
4617   setPreferenceProperty( wv, "step", 0.1 );
4618   setPreferenceProperty( wv, "min", 0.0 );
4619   setPreferenceProperty( wv, "max", 1.0 );
4620   setPreferenceProperty( hv, "min", 0.0 );
4621   setPreferenceProperty( hv, "max", 1.0 );
4622   setPreferenceProperty( hv, "step", 0.1 );
4623
4624   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4625   setPreferenceProperty( posHSizeGr, "columns", 2 );
4626   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4627   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4628   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4629   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4630   setPreferenceProperty( xv, "min", 0.0 );
4631   setPreferenceProperty( xv, "max", 1.0 );
4632   setPreferenceProperty( xv, "step", 0.1 );
4633   setPreferenceProperty( xh, "min", 0.0 );
4634   setPreferenceProperty( xh, "max", 1.0 );
4635   setPreferenceProperty( xh, "step", 0.1 );
4636   setPreferenceProperty( yh, "min", 0.0 );
4637   setPreferenceProperty( yh, "max", 1.0 );
4638   setPreferenceProperty( yh, "step", 0.1 );
4639   setPreferenceProperty( wh, "min", 0.0 );
4640   setPreferenceProperty( wh, "max", 1.0 );
4641   setPreferenceProperty( wh, "step", 0.1 );
4642   setPreferenceProperty( hh, "min", 0.0 );
4643   setPreferenceProperty( hh, "max", 1.0 );
4644   setPreferenceProperty( hh, "step", 0.1 );
4645   
4646   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
4647   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
4648   setPreferenceProperty( distributionGr, "columns", 3 );
4649   QStringList types;
4650   types.append( tr( "SMESH_MONOCOLOR" ) ); 
4651   types.append( tr( "SMESH_MULTICOLOR" ) );
4652   indices.clear(); indices.append( 0 ); indices.append( 1 );
4653   setPreferenceProperty( coloringType, "strings", types );
4654   setPreferenceProperty( coloringType, "indexes", indices );
4655   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
4656
4657 }
4658
4659 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4660 {
4661   if( sect=="SMESH" ) {
4662     float sbX1,sbY1,sbW,sbH;
4663     float aTol = 1.00000009999999;
4664     std::string aWarning;
4665     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4666     if( name=="selection_object_color" || name=="selection_element_color" ||
4667         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
4668         name=="selection_precision_node" || name=="selection_precision_element" ||
4669         name=="selection_precision_object")
4670       SMESH::UpdateSelectionProp( this );
4671     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4672       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4673       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4674       if(sbX1+sbW > aTol){
4675         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4676         sbX1=0.01;
4677         sbW=0.08;
4678         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4679         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4680       }
4681     }
4682     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4683       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4684       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4685       if(sbY1+sbH > aTol){
4686         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4687         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4688         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4689       }
4690     }
4691     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4692       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4693       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4694       if(sbX1+sbW > aTol){
4695         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4696         sbX1=0.1;
4697         sbW=0.08;
4698         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4699         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4700       }
4701     }
4702     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4703       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4704       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4705       if(sbY1+sbH > aTol){
4706         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4707         sbY1=0.01;
4708         sbH=0.08;
4709         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4710         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4711       }
4712     }
4713     else if ( name == "segmentation" ) {
4714       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4715       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4716     }
4717     else if ( name == "nb_segments_per_edge" ) {
4718       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4719       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4720     }
4721
4722     if(aWarning.size() != 0){
4723       aWarning += "The default values are applied instead.";
4724       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4725                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4726                                QObject::tr(aWarning.c_str()));
4727     }
4728   }
4729 }
4730
4731 //================================================================================
4732 /*!
4733  * \brief Update something in accordance with update flags
4734   * \param theFlags - update flags
4735 *
4736 * Update viewer or/and object browser etc. in accordance with update flags ( see
4737 * LightApp_UpdateFlags enumeration ).
4738 */
4739 //================================================================================
4740 void SMESHGUI::update( const int flags )
4741 {
4742   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
4743     SMESH::UpdateView();
4744   else
4745     SalomeApp_Module::update( flags );
4746 }
4747
4748 //================================================================================
4749 /*!
4750  * \brief Set default selection mode
4751 *
4752 * SLOT called when operation commited. Sets default selection mode
4753 */
4754 //================================================================================
4755 void SMESHGUI::onOperationCommited( SUIT_Operation* )
4756 {
4757   SVTK_ViewWindow* vtkWnd =
4758     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4759   if ( vtkWnd )
4760     vtkWnd->SetSelectionMode( ActorSelection );
4761 }
4762
4763 //================================================================================
4764 /*!
4765  * \brief Set default selection mode
4766 *
4767 * SLOT called when operation aborted. Sets default selection mode
4768 */
4769 //================================================================================
4770 void SMESHGUI::onOperationAborted( SUIT_Operation* )
4771 {
4772   SVTK_ViewWindow* vtkWnd =
4773     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4774   if ( vtkWnd )
4775     vtkWnd->SetSelectionMode( ActorSelection );
4776 }
4777
4778 //================================================================================
4779 /*!
4780  * \brief Creates operation with given identifier
4781   * \param id - identifier of operation to be started
4782   * \return Pointer on created operation or NULL if operation is not created
4783 *
4784 * Virtual method redefined from the base class creates operation with given id.
4785 * It is called called automatically from startOperation method of base class.
4786 */
4787 //================================================================================
4788 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
4789 {
4790   LightApp_Operation* op = 0;
4791   // to do : create operation here
4792   switch( id )
4793   {
4794     case 417: //convert to quadratic
4795       op = new SMESHGUI_ConvToQuadOp();
4796     break;
4797     case 418: // create 2D mesh as boundary on 3D
4798       op = new SMESHGUI_Make2DFrom3DOp();
4799     break;
4800     case 701: // Compute mesh
4801       op = new SMESHGUI_ComputeOp();
4802     break;
4803     case 702: // Create mesh
4804       op = new SMESHGUI_MeshOp( true, true );
4805     break;
4806     case 703: // Create sub-mesh
4807       op = new SMESHGUI_MeshOp( true, false );
4808     break;
4809     case 704: // Edit mesh/sub-mesh
4810       op = new SMESHGUI_MeshOp( false );
4811     break;
4812     case 711: // Precompute mesh
4813       op = new SMESHGUI_PrecomputeOp();
4814     break;
4815     case 712: // Evaluate mesh
4816       op = new SMESHGUI_EvaluateOp();
4817     break;
4818     case 713: // Evaluate mesh
4819       op = new SMESHGUI_MeshOrderOp();
4820     break;
4821     case 806: // Create group on geom
4822       op = new SMESHGUI_GroupOnShapeOp();
4823       break;
4824     case 904: // Find element
4825       op = new SMESHGUI_FindElemByPointOp();
4826       break;
4827     case 4067: // make mesh pass through point
4828       op = new SMESHGUI_MakeNodeAtPointOp();
4829       break;
4830     default:
4831     break;
4832   }
4833
4834   if( !op )
4835     op = SalomeApp_Module::createOperation( id );
4836   return op;
4837 }
4838
4839 //================================================================================
4840 /*!
4841  * \brief Stops current operations and starts a given one
4842   * \param id - The id of the operation to start
4843  */
4844 //================================================================================
4845
4846 void SMESHGUI::switchToOperation(int id)
4847 {
4848   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
4849     activeStudy()->abortAllOperations();
4850   startOperation( id );
4851 }
4852
4853 LightApp_Displayer* SMESHGUI::displayer()
4854 {
4855   if( !myDisplayer )
4856     myDisplayer = new SMESHGUI_Displayer( getApp() );
4857   return myDisplayer;
4858 }
4859
4860 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
4861 {
4862   int aHue = -1;
4863   int aTolerance = 64;
4864   int anIterations = 0;
4865   int aPeriod = 5;
4866
4867   while( 1 )
4868   {
4869     anIterations++;
4870     if( anIterations % aPeriod == 0 )
4871     {
4872       aTolerance /= 2;
4873       if( aTolerance < 1 )
4874         break;
4875     }
4876
4877     aHue = (int)( 360.0 * rand() / RAND_MAX );
4878
4879     bool ok = true;
4880     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
4881     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
4882     for( ; it != itEnd; ++it )
4883     {
4884       SALOMEDS::Color anAutoColor = *it;
4885       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
4886
4887       int h, s, v;
4888       aQColor.getHsv( &h, &s, &v );
4889       if( abs( h - aHue ) < aTolerance )
4890       {
4891         ok = false;
4892         break;
4893       }
4894     }
4895
4896     if( ok )
4897       break;
4898   }
4899
4900   QColor aColor;
4901   aColor.setHsv( aHue, 255, 255 );
4902
4903   SALOMEDS::Color aSColor;
4904   aSColor.R = (double)aColor.red() / 255.0;
4905   aSColor.G = (double)aColor.green() / 255.0;
4906   aSColor.B = (double)aColor.blue() / 255.0;
4907
4908   return aSColor;
4909 }
4910
4911 const char gSeparator = '_'; // character used to separate parameter names
4912 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
4913 const char gPathSep   = '|'; // character used to separate paths
4914
4915 /*!
4916  * \brief Store visual parameters
4917  *
4918  * This method is called just before the study document is saved.
4919  * Store visual parameters in AttributeParameter attribue(s)
4920  */
4921 void SMESHGUI::storeVisualParameters (int savePoint)
4922 {
4923   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4924   if (!appStudy || !appStudy->studyDS())
4925     return;
4926   _PTR(Study) studyDS = appStudy->studyDS();
4927
4928   // componentName is used for encoding of entries when storing them in IParameters
4929   std::string componentName = myComponentSMESH->ComponentDataType();
4930   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
4931   //if (!aSComponent) return;
4932
4933   // IParameters
4934   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4935                                                              componentName.c_str(),
4936                                                              savePoint);
4937   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4938
4939   // store map of custom markers
4940   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4941   if( !aMarkerMap.empty() )
4942   {
4943     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
4944     for( ; anIter != aMarkerMap.end(); anIter++ )
4945     {
4946       int anId = anIter->first;
4947       VTK::MarkerData aMarkerData = anIter->second;
4948       std::string aMarkerFileName = aMarkerData.first;
4949       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
4950       if( aMarkerTexture.size() < 3 )
4951         continue; // should contain at least width, height and the first value
4952
4953       QString aPropertyName( "texture" );
4954       aPropertyName += gSeparator;
4955       aPropertyName += QString::number( anId );
4956
4957       QString aPropertyValue = aMarkerFileName.c_str();
4958       aPropertyValue += gPathSep;
4959
4960       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
4961       ushort aWidth = *aTextureIter++;
4962       ushort aHeight = *aTextureIter++;
4963       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
4964       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
4965       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
4966         aPropertyValue += QString::number( *aTextureIter );
4967
4968       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
4969     }
4970   }
4971
4972   // viewers counters are used for storing view_numbers in IParameters
4973   int vtkViewers = 0;
4974
4975   // main cycle to store parameters of displayed objects
4976   QList<SUIT_ViewManager*> lst;
4977   QList<SUIT_ViewManager*>::Iterator it;
4978   getApp()->viewManagers(lst);
4979   for (it = lst.begin(); it != lst.end(); it++)
4980   {
4981     SUIT_ViewManager* vman = *it;
4982     QString vType = vman->getType();
4983
4984     // saving VTK actors properties
4985     if (vType == SVTK_Viewer::Type())
4986     {
4987       // store the clipping planes attached to the view manager
4988       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
4989       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
4990       if( anIter != myClippingPlaneInfoMap.end() )
4991         aClippingPlaneInfoList = anIter->second;
4992
4993       if( !aClippingPlaneInfoList.empty() ) {
4994         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
4995         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
4996         {
4997           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
4998           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
4999
5000           QString aPropertyName( "ClippingPlane" );
5001           aPropertyName += gSeparator;
5002           aPropertyName += QString::number( vtkViewers );
5003           aPropertyName += gSeparator;
5004           aPropertyName += QString::number( anId );
5005
5006           QString aPropertyValue = QString::number( (int)aPlane->GetOrientation() ).toLatin1().constData();
5007           aPropertyValue += gDigitsSep;
5008           aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5009           aPropertyValue += gDigitsSep;
5010           aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5011           aPropertyValue += gDigitsSep;
5012           aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5013
5014           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5015         }
5016       }
5017
5018       QVector<SUIT_ViewWindow*> views = vman->getViews();
5019       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5020       {
5021         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5022         {
5023           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5024           vtkActorCollection* allActors = aCopy.GetActors();
5025           allActors->InitTraversal();
5026           while (vtkActor* actor = allActors->GetNextActor())
5027           {
5028             if (actor->GetVisibility()) // store only visible actors
5029             {
5030               SMESH_Actor* aSmeshActor = 0;
5031               if (actor->IsA("SMESH_Actor"))
5032                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5033               if (aSmeshActor && aSmeshActor->hasIO())
5034               {
5035                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5036                 if (io->hasEntry())
5037                 {
5038                   // entry is "encoded" = it does NOT contain component adress,
5039                   // since it is a subject to change on next component loading
5040                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5041
5042                   std::string param, vtkParam = vType.toLatin1().data();
5043                   vtkParam += gSeparator;
5044                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5045                   vtkParam += gSeparator;
5046
5047                   // Visibility
5048                   param = vtkParam + "Visibility";
5049                   ip->setParameter(entry, param, "On");
5050
5051                   // Representation
5052                   param = vtkParam + "Representation";
5053                   ip->setParameter(entry, param, QString::number
5054                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5055
5056                   // IsShrunk
5057                   param = vtkParam + "IsShrunk";
5058                   ip->setParameter(entry, param, QString::number
5059                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5060
5061                   // Displayed entities
5062                   unsigned int aMode = aSmeshActor->GetEntityMode();
5063                   bool isE = aMode & SMESH_Actor::eEdges;
5064                   bool isF = aMode & SMESH_Actor::eFaces;
5065                   bool isV = aMode & SMESH_Actor::eVolumes;
5066
5067                   QString modeStr ("e");
5068                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5069                   modeStr += gDigitsSep; modeStr += "f";
5070                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5071                   modeStr += gDigitsSep; modeStr += "v";
5072                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5073
5074                   param = vtkParam + "Entities";
5075                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5076
5077                   // Colors (surface:edge:)
5078                   vtkFloatingPointType r, g, b;
5079
5080                   aSmeshActor->GetSufaceColor(r, g, b);
5081                   QString colorStr ("surface");
5082                   colorStr += gDigitsSep; colorStr += QString::number(r);
5083                   colorStr += gDigitsSep; colorStr += QString::number(g);
5084                   colorStr += gDigitsSep; colorStr += QString::number(b);
5085
5086                   aSmeshActor->GetBackSufaceColor(r, g, b);
5087                   colorStr += gDigitsSep; colorStr += "backsurface";
5088                   colorStr += gDigitsSep; colorStr += QString::number(r);
5089                   colorStr += gDigitsSep; colorStr += QString::number(g);
5090                   colorStr += gDigitsSep; colorStr += QString::number(b);
5091
5092                   aSmeshActor->GetEdgeColor(r, g, b);
5093                   colorStr += gDigitsSep; colorStr += "edge";
5094                   colorStr += gDigitsSep; colorStr += QString::number(r);
5095                   colorStr += gDigitsSep; colorStr += QString::number(g);
5096                   colorStr += gDigitsSep; colorStr += QString::number(b);
5097
5098                   aSmeshActor->GetNodeColor(r, g, b);
5099                   colorStr += gDigitsSep; colorStr += "node";
5100                   colorStr += gDigitsSep; colorStr += QString::number(r);
5101                   colorStr += gDigitsSep; colorStr += QString::number(g);
5102                   colorStr += gDigitsSep; colorStr += QString::number(b);
5103
5104                   param = vtkParam + "Colors";
5105                   ip->setParameter(entry, param, colorStr.toLatin1().data());
5106
5107                   // Sizes of lines and points
5108                   QString sizeStr ("line");
5109                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
5110                   sizeStr += gDigitsSep; sizeStr += "shrink";
5111                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
5112
5113                   param = vtkParam + "Sizes";
5114                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
5115
5116                   // Point marker
5117                   QString markerStr;
5118
5119                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5120                   if( aMarkerType == VTK::MT_USER ) {
5121                     markerStr += "custom";
5122                     markerStr += gDigitsSep;
5123                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5124                   }
5125                   else {
5126                     markerStr += "std";
5127                     markerStr += gDigitsSep;
5128                     markerStr += QString::number( (int)aMarkerType );
5129                     markerStr += gDigitsSep;
5130                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5131                   }
5132
5133                   param = vtkParam + "PointMarker";
5134                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5135
5136                   // Opacity
5137                   param = vtkParam + "Opacity";
5138                   ip->setParameter(entry, param,
5139                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5140
5141                   // Clipping
5142                   param = vtkParam + "ClippingPlane";
5143                   int aPlaneId = 0;
5144                   if( !aClippingPlaneInfoList.empty() ) {
5145                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5146                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5147                     {
5148                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5149                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5150                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5151                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5152                         if( aSmeshActor == *anIter2 ) {
5153                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5154                                             QString::number( anId ).toLatin1().constData() );                          
5155                           break;
5156                         }
5157                       }
5158                     }
5159                   }
5160                   if( aPlaneId == 0 )
5161                     ip->setParameter( entry, param, "Off" );
5162                 } // if (io->hasEntry())
5163               } // SMESH_Actor && hasIO
5164             } // isVisible
5165           } // while.. actors traversal
5166         } // if (vtkView)
5167       } // for (views)
5168       vtkViewers++;
5169     } // if (SVTK view model)
5170   } // for (viewManagers)
5171 }
5172
5173 // data structures for clipping planes processing
5174 typedef struct {
5175   int Id;
5176   vtkIdType Orientation;
5177   vtkFloatingPointType Distance;
5178   vtkFloatingPointType Angle[2];
5179 } TPlaneData;
5180 typedef std::list<TPlaneData>         TPlaneDataList;
5181 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5182
5183 typedef std::list<vtkActor*>          TActorList;
5184 typedef struct {
5185   int PlaneId;
5186   TActorList ActorList;
5187   SUIT_ViewManager* ViewManager;
5188 } TPlaneInfo;
5189 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5190 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5191
5192 /*!
5193  * \brief Restore visual parameters
5194  *
5195  * This method is called after the study document is opened.
5196  * Restore visual parameters from AttributeParameter attribue(s)
5197  */
5198 void SMESHGUI::restoreVisualParameters (int savePoint)
5199 {
5200   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5201   if (!appStudy || !appStudy->studyDS())
5202     return;
5203   _PTR(Study) studyDS = appStudy->studyDS();
5204
5205   // componentName is used for encoding of entries when storing them in IParameters
5206   std::string componentName = myComponentSMESH->ComponentDataType();
5207   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5208   //if (!aSComponent) return;
5209
5210   // IParameters
5211   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5212                                                              componentName.c_str(),
5213                                                              savePoint);
5214   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5215
5216   // restore map of custom markers and map of clipping planes
5217   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5218   TPlaneDataMap aPlaneDataMap;
5219
5220   std::vector<std::string> properties = ip->getProperties();
5221   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5222   {
5223     std::string property = *propIt;
5224     QString aPropertyName( property.c_str() );
5225     QString aPropertyValue( ip->getProperty( property ).c_str() );
5226
5227     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5228     if( aPropertyNameList.isEmpty() )
5229       continue;
5230
5231     QString aPropertyType = aPropertyNameList[0];
5232     if( aPropertyType == "texture" )
5233     {
5234       if( aPropertyNameList.size() != 2 )
5235         continue;
5236
5237       bool ok = false;
5238       int anId = aPropertyNameList[1].toInt( &ok );
5239       if( !ok || anId < 1 )
5240         continue;
5241
5242       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5243       if( aPropertyValueList.size() != 2 )
5244         continue;
5245
5246       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5247       QString aMarkerTextureString = aPropertyValueList[1];
5248       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5249       if( aMarkerTextureStringList.size() != 3 )
5250         continue;
5251
5252       ok = false;
5253       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5254       if( !ok )
5255         continue;
5256
5257       ok = false;
5258       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5259       if( !ok )
5260         continue;
5261
5262       VTK::MarkerTexture aMarkerTexture;
5263       aMarkerTexture.push_back( aWidth );
5264       aMarkerTexture.push_back( aHeight );
5265
5266       QString aMarkerTextureData = aMarkerTextureStringList[2];
5267       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5268       {
5269         QChar aChar = aMarkerTextureData.at( i );
5270         if( aChar.isDigit() )
5271           aMarkerTexture.push_back( aChar.digitValue() );
5272       }
5273
5274       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5275     }
5276     else if( aPropertyType == "ClippingPlane" )
5277     {
5278       if( aPropertyNameList.size() != 3 )
5279         continue;
5280
5281       bool ok = false;
5282       int aViewId = aPropertyNameList[1].toInt( &ok );
5283       if( !ok || aViewId < 0 )
5284         continue;
5285
5286       ok = false;
5287       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5288       if( !ok || aClippingPlaneId < 0 )
5289         continue;
5290
5291       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5292       if( aPropertyValueList.size() != 4 )
5293         continue;
5294
5295       TPlaneData aPlaneData;
5296       aPlaneData.Id = aClippingPlaneId;
5297
5298       ok = false;
5299       aPlaneData.Orientation = aPropertyValueList[0].toInt( &ok );
5300       if( !ok )
5301         continue;
5302
5303       ok = false;
5304       aPlaneData.Distance = aPropertyValueList[1].toDouble( &ok );
5305       if( !ok )
5306         continue;
5307
5308       ok = false;
5309       aPlaneData.Angle[0] = aPropertyValueList[2].toDouble( &ok );
5310       if( !ok )
5311         continue;
5312
5313       ok = false;
5314       aPlaneData.Angle[1] = aPropertyValueList[3].toDouble( &ok );
5315       if( !ok )
5316         continue;
5317
5318       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
5319       aPlaneDataList.push_back( aPlaneData );      
5320     }
5321   }
5322
5323   TPlaneInfoMap aPlaneInfoMap;
5324
5325   std::vector<std::string> entries = ip->getEntries();
5326
5327   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
5328   {
5329     // entry is a normal entry - it should be "decoded" (setting base adress of component)
5330     QString entry (ip->decodeEntry(*entIt).c_str());
5331
5332     // Check that the entry corresponds to a real object in the Study
5333     // as the object may be deleted or modified after the visual state is saved.
5334     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
5335     if (!so) continue; //Skip the not existent entry
5336
5337     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
5338     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
5339
5340     std::vector<std::string>::iterator namesIt = paramNames.begin();
5341     std::vector<std::string>::iterator valuesIt = paramValues.begin();
5342
5343     // actors are stored in a map after displaying of them for
5344     // quicker access in the future: map < viewID to actor >
5345     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
5346
5347     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
5348     {
5349       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
5350       // '_' is used as separator and should not be used in viewer type or parameter names.
5351       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
5352       if (lst.size() != 3)
5353         continue;
5354
5355       QString viewerTypStr = lst[0];
5356       QString viewIndexStr = lst[1];
5357       QString paramNameStr = lst[2];
5358
5359       bool ok;
5360       int viewIndex = viewIndexStr.toUInt(&ok);
5361       if (!ok) // bad conversion of view index to integer
5362         continue;
5363
5364       // viewers
5365       if (viewerTypStr == SVTK_Viewer::Type())
5366       {
5367         SMESH_Actor* aSmeshActor = 0;
5368         if (vtkActors.IsBound(viewIndex))
5369           aSmeshActor = vtkActors.Find(viewIndex);
5370
5371         QList<SUIT_ViewManager*> lst;
5372         getApp()->viewManagers(viewerTypStr, lst);
5373
5374         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5375         SUIT_ViewManager* vman = NULL;
5376         if (viewIndex >= 0 && viewIndex < lst.count())
5377           vman = lst.at(viewIndex);
5378
5379         if (paramNameStr == "Visibility")
5380         {
5381           if (!aSmeshActor && displayer() && vman)
5382           {
5383             SUIT_ViewModel* vmodel = vman->getViewModel();
5384             // SVTK view model can be casted to SALOME_View
5385             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
5386
5387             // store displayed actor in a temporary map for quicker
5388             // access later when restoring other parameters
5389             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5390             vtkRenderer* Renderer = vtkView->getRenderer();
5391             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
5392             vtkActorCollection* theActors = aCopy.GetActors();
5393             theActors->InitTraversal();
5394             bool isFound = false;
5395             vtkActor *ac = theActors->GetNextActor();
5396             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
5397               if (ac->IsA("SMESH_Actor")) {
5398                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
5399                 if (aGeomAc->hasIO()) {
5400                   Handle(SALOME_InteractiveObject) io =
5401                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
5402                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
5403                     isFound = true;
5404                     vtkActors.Bind(viewIndex, aGeomAc);
5405                   }
5406                 }
5407               }
5408             }
5409           }
5410         } // if (paramNameStr == "Visibility")
5411         else
5412         {
5413           // the rest properties "work" with SMESH_Actor
5414           if (aSmeshActor)
5415           {
5416             QString val ((*valuesIt).c_str());
5417
5418             // Representation
5419             if (paramNameStr == "Representation") {
5420               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
5421             }
5422             // IsShrunk
5423             else if (paramNameStr == "IsShrunk") {
5424               if (val.toInt()) {
5425                 if (!aSmeshActor->IsShrunk())
5426                   aSmeshActor->SetShrink();
5427               }
5428               else {
5429                 if (aSmeshActor->IsShrunk())
5430                   aSmeshActor->UnShrink();
5431               }
5432             }
5433             // Displayed entities
5434             else if (paramNameStr == "Entities") {
5435               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
5436               if (mode.count() == 6) {
5437                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
5438                   MESSAGE("Invalid order of data in Entities, must be: "
5439                           "e:0/1:f:0/1:v:0/1");
5440                 }
5441                 else {
5442                   unsigned int aMode = aSmeshActor->GetEntityMode();
5443                   unsigned int aNewMode =
5444                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
5445                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
5446                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
5447                   if (aNewMode != aMode)
5448                     aSmeshActor->SetEntityMode(aNewMode);
5449                 }
5450               }
5451             }
5452             // Colors
5453             else if (paramNameStr == "Colors") {
5454               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
5455               if (colors.count() == 16) {
5456                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
5457                     colors[8] != "edge"    || colors[12] != "node") {
5458                   MESSAGE("Invalid order of data in Colors, must be: "
5459                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
5460                 }
5461                 else {
5462                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
5463                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
5464                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
5465                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
5466                 }
5467               }
5468             }
5469             // Sizes of lines and points
5470             else if (paramNameStr == "Sizes") {
5471               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
5472               if (sizes.count() == 4) {
5473                 if (sizes[0] != "line" || sizes[2] != "shrink") {
5474                   MESSAGE("Invalid order of data in Sizes, must be: "
5475                           "line:int:shrink:float");
5476                 }
5477                 else {
5478                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5479                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
5480                 }
5481               }
5482               else if (sizes.count() == 6) { // just to support old format
5483                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
5484                   MESSAGE("Invalid order of data in Sizes, must be: "
5485                           "line:int:node:int:shrink:float");
5486                 }
5487                 else {
5488                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5489                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
5490                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
5491                 }
5492               }
5493             }
5494             // Point marker
5495             else if (paramNameStr == "PointMarker") {
5496               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
5497               if( data.count() >= 2 ) {
5498                 bool ok = false;
5499                 int aParam1 = data[1].toInt( &ok );
5500                 if( ok ) {
5501                   if( data[0] == "std" && data.count() == 3 ) {
5502                     int aParam2 = data[2].toInt( &ok );
5503                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
5504                   }
5505                   else if( data[0] == "custom" ) {
5506                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
5507                     if( markerIt != aMarkerMap.end() ) {
5508                       VTK::MarkerData aMarkerData = markerIt->second;
5509                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
5510                     }
5511                   }
5512                 }
5513               }
5514             }
5515             // Opacity
5516             else if (paramNameStr == "Opacity") {
5517               aSmeshActor->SetOpacity(val.toFloat());
5518             }
5519             // Clipping
5520             else if (paramNameStr.startsWith("ClippingPlane")) {
5521               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
5522               // old format - val looks like "Off" or "0:0.5:0:0" (orientation, distance, two angles)
5523               // new format - val looks like "Off" or "0" (plane id)
5524               // (note: in new format "Off" value is used only for consistency,
5525               //  so it is processed together with values in old format)
5526               bool anIsOldFormat = ( vals.count() == 4 || val == "Off" );
5527               if( anIsOldFormat ) {
5528                 if (paramNameStr == "ClippingPlane1" || val == "Off")
5529                   aSmeshActor->RemoveAllClippingPlanes();
5530                 if (val != "Off") {
5531                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
5532                   double aDistance = vals[1].toFloat();
5533                   vtkFloatingPointType anAngle[2];
5534                   anAngle[0] = vals[2].toFloat();
5535                   anAngle[1] = vals[3].toFloat();
5536
5537                   QList<SUIT_ViewManager*> lst;
5538                   getApp()->viewManagers(viewerTypStr, lst);
5539                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5540                   if (viewIndex >= 0 && viewIndex < lst.count()) {
5541                     SUIT_ViewManager* vman = lst.at(viewIndex);
5542                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5543
5544                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
5545
5546                     SMESH::TActorList anActorList;
5547                     anActorList.push_back( aSmeshActor );
5548                     SMESH::OrientedPlane* aPlane =
5549                       SMESHGUI_ClippingDlg::AddPlane(anActorList, vtkView, anOrientation, aDistance, anAngle);
5550                     if( aPlane ) {
5551                       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5552                       aClippingPlaneInfo.Plane = aPlane;
5553                       aClippingPlaneInfo.ActorList = anActorList;
5554                       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5555                     }
5556                   }
5557                 }
5558               }
5559               else {
5560                 bool ok = false;
5561                 int aPlaneId = val.toInt( &ok );
5562                 if( ok && aPlaneId >= 0 ) {
5563                   bool anIsDefinedPlane = false;
5564                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
5565                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
5566                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5567                     TPlaneInfo& aPlaneInfo = *anIter;
5568                     if( aPlaneInfo.PlaneId == aPlaneId ) {
5569                       aPlaneInfo.ActorList.push_back( aSmeshActor );
5570                       anIsDefinedPlane = true;
5571                       break;
5572                     }
5573                   }
5574                   if( !anIsDefinedPlane ) {
5575                     TPlaneInfo aPlaneInfo;
5576                     aPlaneInfo.PlaneId = aPlaneId;
5577                     aPlaneInfo.ActorList.push_back( aSmeshActor );
5578                     aPlaneInfo.ViewManager = vman;
5579
5580                     // to make the list sorted by plane id
5581                     anIter = aPlaneInfoList.begin();
5582                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5583                       const TPlaneInfo& aPlaneInfoRef = *anIter;
5584                       if( aPlaneInfoRef.PlaneId > aPlaneId )
5585                         break;
5586                     }
5587                     aPlaneInfoList.insert( anIter, aPlaneInfo );
5588                   }
5589                 }
5590               }
5591             }
5592           } // if (aSmeshActor)
5593         } // other parameters than Visibility
5594       }
5595     } // for names/parameters iterator
5596   } // for entries iterator
5597
5598   // take into account planes with empty list of actors referred to them
5599   QList<SUIT_ViewManager*> aVMList;
5600   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
5601
5602   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
5603   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
5604     int aViewId = aPlaneDataIter->first;
5605     if( aViewId >= 0 && aViewId < aVMList.count() ) {
5606       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
5607
5608       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
5609
5610       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
5611       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
5612       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
5613         const TPlaneData& aPlaneData = *anIter2;
5614         int aPlaneId = aPlaneData.Id;
5615
5616         bool anIsFound = false;
5617         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5618         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5619           const TPlaneInfo& aPlaneInfo = *anIter3;
5620           if( aPlaneInfo.PlaneId == aPlaneId ) {
5621             anIsFound = true;
5622             break;
5623           }
5624         }
5625
5626         if( !anIsFound ) {
5627           TPlaneInfo aPlaneInfo; // ActorList field is empty
5628           aPlaneInfo.PlaneId = aPlaneId;
5629           aPlaneInfo.ViewManager = aViewManager;
5630
5631           // to make the list sorted by plane id
5632           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
5633           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
5634             const TPlaneInfo& aPlaneInfoRef = *anIter4;
5635             if( aPlaneInfoRef.PlaneId > aPlaneId )
5636               break;
5637           }
5638           aPlaneInfoList.insert( anIter4, aPlaneInfo );
5639         }
5640       }
5641     }
5642   }
5643
5644   // add clipping planes to actors according to the restored parameters
5645   // and update the clipping plane map
5646   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
5647   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
5648     int aViewId = anIter1->first;
5649     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
5650
5651     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
5652     if( anIter2 == aPlaneDataMap.end() )
5653       continue;
5654     const TPlaneDataList& aPlaneDataList = anIter2->second;
5655
5656     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5657     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5658       const TPlaneInfo& aPlaneInfo = *anIter3;
5659       int aPlaneId = aPlaneInfo.PlaneId;
5660       const TActorList& anActorList = aPlaneInfo.ActorList;
5661       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
5662       if( !aViewManager )
5663         continue;
5664
5665       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
5666       if( !aViewWindow )
5667         continue;
5668
5669       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
5670
5671       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
5672       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
5673         const TPlaneData& aPlaneData = *anIter4;
5674         if( aPlaneData.Id == aPlaneId ) {
5675           SMESH::OrientedPlane* aPlane =
5676             SMESHGUI_ClippingDlg::AddPlane( anActorList,
5677                                             aViewWindow,
5678                                             (SMESH::Orientation)aPlaneData.Orientation,
5679                                             aPlaneData.Distance,
5680                                             aPlaneData.Angle );
5681           if( aPlane ) {
5682             SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5683             aClippingPlaneInfo.Plane = aPlane;
5684             aClippingPlaneInfo.ActorList = anActorList;
5685             aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5686           }
5687           break;
5688         }
5689       }
5690     }
5691   }
5692
5693   // update all VTK views
5694   QList<SUIT_ViewManager*> lst;
5695   getApp()->viewManagers(lst);
5696   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
5697     SUIT_ViewModel* vmodel = (*it)->getViewModel();
5698     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
5699       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
5700       vtkView->getRenderer()->ResetCameraClippingRange();
5701       vtkView->Repaint();
5702     }
5703   }
5704 }
5705
5706 /*!
5707   \brief Adds preferences for dfont of VTK viewer
5708   \param label label
5709   \param pIf group identifier
5710   \param param parameter
5711   \return identifier of preferences
5712 */
5713 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
5714 {
5715   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
5716
5717   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
5718
5719   QStringList fam;
5720   fam.append( tr( "SMESH_FONT_ARIAL" ) );
5721   fam.append( tr( "SMESH_FONT_COURIER" ) );
5722   fam.append( tr( "SMESH_FONT_TIMES" ) );
5723
5724   setPreferenceProperty( tfont, "fonts", fam );
5725
5726   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
5727   setPreferenceProperty( tfont, "features", f );
5728
5729   return tfont;
5730 }
5731
5732 /*!
5733   \brief Actions after hypothesis edition
5734   Updates object browser after hypothesis edition
5735 */
5736 void SMESHGUI::onHypothesisEdit( int result )
5737 {
5738   if( result == 1 )
5739     SMESHGUI::Modified();
5740   updateObjBrowser( true );
5741 }
5742
5743
5744 /*!
5745   \brief Signal handler closing(SUIT_ViewWindow*) of a view
5746   \param pview view being closed
5747 */
5748 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
5749 #ifndef DISABLE_PLOT2DVIEWER
5750   //Crear all Plot2d Viewers if need.
5751   SMESH::ClearPlot2Viewers(pview);
5752 #endif  
5753 }
5754
5755 /*!
5756   \brief Connects or disconnects signals about activating and cloning view on the module slots
5757   \param pview view which is connected/disconnected
5758 */
5759 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
5760   if(!pview)
5761     return;
5762   
5763   SUIT_ViewManager* viewMgr = pview->getViewManager();
5764   if ( viewMgr ) {
5765     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
5766                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
5767     
5768     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
5769              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
5770   }
5771 }
5772  
5773 /*!
5774   \brief Return \c true if object can be renamed
5775 */
5776 bool SMESHGUI::renameAllowed( const QString& entry) const {
5777   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
5778   if( !anApp )
5779     return false;
5780
5781   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
5782   if( !aStudy )
5783     return false;
5784
5785   bool appRes = SalomeApp_Module::renameAllowed(entry);
5786   if( !appRes )
5787     return false;
5788   
5789   // check type to prevent renaming of inappropriate objects
5790   int aType = SMESHGUI_Selection::type(qPrintable(entry), aStudy);
5791   if (aType == MESH || aType == GROUP ||
5792       aType == SUBMESH || aType == SUBMESH_COMPOUND ||
5793       aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
5794       aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
5795       aType == HYPOTHESIS || aType == ALGORITHM)
5796     return true;
5797
5798   return false;
5799 }
5800
5801 /*!
5802   Rename object by entry.
5803   \param entry entry of the object
5804   \param name new name of the object
5805   \brief Return \c true if rename operation finished successfully, \c false otherwise.
5806 */
5807 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
5808   
5809   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
5810   if( !anApp )
5811     return false;
5812   
5813   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
5814   if( !aStudy )
5815     return false;
5816
5817   bool appRes = SalomeApp_Module::renameObject(entry,name);
5818   if( !appRes )
5819     return false;
5820   
5821   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
5822   _PTR(GenericAttribute) anAttr;
5823   _PTR(AttributeName) aName;
5824   if ( obj ) {
5825     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
5826       aName = anAttr;
5827       // check type to prevent renaming of inappropriate objects
5828       int aType = SMESHGUI_Selection::type( qPrintable(entry), aStudy );
5829       if (aType == MESH || aType == GROUP ||
5830           aType == SUBMESH || aType == SUBMESH_COMPOUND ||
5831           aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
5832           aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
5833           aType == HYPOTHESIS || aType == ALGORITHM) {
5834         if ( !name.isEmpty() ) {
5835           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
5836           
5837           // update name of group object and its actor
5838           Handle(SALOME_InteractiveObject) IObject = 
5839             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
5840           
5841           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
5842           if( !aGroupObject->_is_nil() ) {
5843             aGroupObject->SetName( qPrintable(name) );
5844             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
5845               anActor->setName( qPrintable(name) );
5846           }
5847           return true;
5848         }
5849       }  
5850     }
5851   }
5852   return false;
5853 }