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