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