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