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