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