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