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