Salome HOME
0020983: EDF 1569 SMESH: Numbering Display Elements with several groups selected...
[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       SALOME_ListIteratorOfListIO it(selected);
2831       for( ; it.More(); it.Next()) {
2832         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2833         if(anIObject->hasEntry())
2834           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2835             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2836           }
2837       }
2838       break;
2839     }
2840   }
2841
2842   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2843   //updateObjBrowser();
2844   return true;
2845 }
2846
2847 //=============================================================================
2848 /*!
2849  *
2850  */
2851 //=============================================================================
2852 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2853 {
2854   return false;
2855 }
2856
2857 //=============================================================================
2858 /*!
2859  *
2860  */
2861 //=============================================================================
2862 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2863 {
2864   return true;
2865 }
2866
2867 //=============================================================================
2868 /*!
2869  *
2870  */
2871 //=============================================================================
2872 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2873 {
2874   return true;
2875 }
2876
2877 //=============================================================================
2878 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2879  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2880  */
2881 //=============================================================================
2882 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2883                                   SUIT_ViewWindow* wnd )
2884 {
2885   if(theIO->hasEntry()){
2886     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2887     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2888   }
2889 }
2890
2891 //=======================================================================
2892 // function : createSMESHAction
2893 // purpose  :
2894 //=======================================================================
2895 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, 
2896                                   const int key, const bool toggle, const QString& shortcutAction  )
2897 {
2898   QIcon icon;
2899   QWidget* parent = application()->desktop();
2900   SUIT_ResourceMgr* resMgr = resourceMgr();
2901   QPixmap pix;
2902   if ( !icon_id.isEmpty() )
2903     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
2904   else
2905     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
2906   if ( !pix.isNull() )
2907     icon = QIcon( pix );
2908
2909   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
2910           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
2911           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
2912
2913   createAction( id, tooltip, icon, menu, status_bar, key, parent, 
2914                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
2915 }
2916
2917 //=======================================================================
2918 // function : createPopupItem
2919 // purpose  :
2920 //=======================================================================
2921 void SMESHGUI::createPopupItem( const int id,
2922                                 const QString& clients,
2923                                 const QString& types,
2924                                 const QString& theRule,
2925                                 const int pId )
2926 {
2927   int parentId = pId;
2928   if( pId!=-1 )
2929     parentId = popupMgr()->actionId( action( pId ) );
2930
2931   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2932     popupMgr()->insert( action( id ), parentId, 0 );
2933
2934   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
2935   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
2936   QString rule = "(%1) and (%2) and (%3)";
2937   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
2938   if( clients.isEmpty() )
2939     rule = rule.arg( QString( "true" ) );
2940   else
2941     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2942   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2943   rule += theRule;
2944
2945   bool cont = myRules.contains( id );
2946   if( cont )
2947     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2948
2949   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
2950   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2951 }
2952
2953 //=======================================================================
2954 // function : initialize
2955 // purpose  :
2956 //=======================================================================
2957 void SMESHGUI::initialize( CAM_Application* app )
2958 {
2959   SalomeApp_Module::initialize( app );
2960
2961 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2962 //   if ( mgr )
2963   /* Automatic Update flag */
2964 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2965
2966   // ----- create actions --------------
2967
2968   createSMESHAction(  111, "DAT", "", (Qt::CTRL+Qt::Key_B) );
2969   createSMESHAction(  112, "UNV", "", (Qt::CTRL+Qt::Key_U) );
2970   createSMESHAction(  113, "MED", "", (Qt::CTRL+Qt::Key_M) );
2971   createSMESHAction(  114, "NUM" );
2972   createSMESHAction(  121, "DAT" );
2973   createSMESHAction(  122, "MED" );
2974   createSMESHAction(  123, "UNV" );
2975   createSMESHAction(  140, "STL" );
2976   createSMESHAction(  124, "EXPORT_DAT" );
2977   createSMESHAction(  125, "EXPORT_MED" );
2978   createSMESHAction(  126, "EXPORT_UNV" );
2979   createSMESHAction(  141, "EXPORT_STL" );
2980   createSMESHAction(  150, "FILE_INFO" );
2981   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
2982   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2983   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2984   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2985   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2986   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2987   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2988   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
2989   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
2990   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
2991   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
2992   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
2993   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2994   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2995   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
2996   createSMESHAction(  804, "ADD" );
2997   createSMESHAction(  805, "REMOVE" );
2998   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2999   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
3000   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
3001   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
3002   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
3003   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
3004   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
3005   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
3006   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
3007   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
3008   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
3009   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
3010   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
3011   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
3012   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
3013   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
3014   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
3015   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
3016   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
3017   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
3018   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
3019   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
3020   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
3021   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
3022   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
3023   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
3024   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
3025   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
3026   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
3027   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
3028   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
3029   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
3030   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
3031   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
3032   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
3033   createSMESHAction( 4044, "REMOVE_ORPHAN_NODES", "ICON_DLG_REM_ORPHAN_NODES" );
3034   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
3035   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
3036   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
3037   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
3038   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
3039   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
3040   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
3041   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
3042   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
3043   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
3044   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
3045   createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
3046   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
3047   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
3048   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
3049   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
3050   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
3051   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
3052   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
3053   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
3054   createSMESHAction(  415, "MAP",             "ICON_MAP" );
3055   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
3056   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
3057   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
3058   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
3059   createSMESHAction(  200, "RESET" );
3060   createSMESHAction(  201, "SCALAR_BAR_PROP" );
3061   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
3062   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
3063   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
3064   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
3065   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
3066   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
3067   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
3068   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
3069   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3070   createSMESHAction(  220, "ALL" );
3071   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3072
3073   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3074   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3075
3076   createSMESHAction( 1100, "EDIT_HYPO" );
3077   createSMESHAction( 1101, "RENAME", "", Qt::Key_F2 );
3078   createSMESHAction( 1102, "UNASSIGN" );
3079   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3080   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3081   createSMESHAction( 1131, "DISPMODE" );
3082   createSMESHAction( 1132, "COLORS" );
3083   createSMESHAction( 1133, "TRANSP" );
3084   createSMESHAction( 1134, "CLIP" );
3085   createSMESHAction( 1135, "DISP_ENT" );
3086   createSMESHAction( 1136, "AUTO_COLOR" );
3087   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3088   createSMESHAction( 2000, "CTRL" );
3089
3090   createSMESHAction( 300, "ERASE" );
3091   createSMESHAction( 301, "DISPLAY" );
3092   createSMESHAction( 302, "DISPLAY_ONLY" );
3093   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
3094   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
3095   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
3096   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
3097   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3098   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
3099   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3100   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3101
3102   // ----- create menu --------------
3103   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
3104       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
3105       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
3106       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
3107       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
3108       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
3109       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
3110
3111   createMenu( separator(), fileId );
3112
3113   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3114       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3115       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3116       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3117       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3118       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
3119
3120   createMenu( 111, importId, -1 );
3121   createMenu( 112, importId, -1 );
3122   createMenu( 113, importId, -1 );
3123
3124   createMenu( 121, exportId, -1 );
3125   createMenu( 122, exportId, -1 );
3126   createMenu( 123, exportId, -1 );
3127   createMenu( 140, exportId, -1 ); // export to stl STL
3128
3129   createMenu( separator(), fileId, 10 );
3130
3131   createMenu( 33, editId, -1 );
3132
3133   createMenu( 5105, toolsId, -1 );
3134
3135   createMenu( 702, meshId, -1 ); // "Mesh" menu
3136   createMenu( 703, meshId, -1 );
3137   createMenu( 704, meshId, -1 );
3138   createMenu( 710, meshId, -1 );
3139   createMenu( separator(), meshId, -1 );
3140   createMenu( 701, meshId, -1 );
3141   createMenu( 711, meshId, -1 );
3142   createMenu( 712, meshId, -1 );
3143   createMenu( 713, meshId, -1 );
3144   createMenu( separator(), meshId, -1 );
3145   createMenu( 801, meshId, -1 );
3146   createMenu( 806, meshId, -1 );
3147   createMenu( 802, meshId, -1 );
3148   createMenu( 803, meshId, -1 );
3149   createMenu( 815, meshId, -1 );
3150   createMenu( separator(), meshId, -1 );
3151   createMenu( 810, meshId, -1 );
3152   createMenu( 811, meshId, -1 );
3153   createMenu( 812, meshId, -1 );
3154   createMenu( separator(), meshId, -1 );
3155   createMenu( 814, meshId, -1 );
3156   createMenu( separator(), meshId, -1 );
3157   createMenu( 813, meshId, -1 );
3158   createMenu( separator(), meshId, -1 );
3159   createMenu( 900, meshId, -1 );
3160   createMenu( 902, meshId, -1 );
3161   createMenu( 903, meshId, -1 );
3162   createMenu( 904, meshId, -1 );
3163   createMenu( separator(), meshId, -1 );
3164
3165   createMenu( 6003, ctrlId, -1 );
3166   createMenu( 6001, ctrlId, -1 );
3167   createMenu( 6004, ctrlId, -1 );
3168   createMenu( separator(), ctrlId, -1 );
3169   createMenu( 6005, ctrlId, -1 );
3170   createMenu( 6002, ctrlId, -1 );
3171   createMenu( 6018, ctrlId, -1 );
3172   createMenu( 6019, ctrlId, -1 );
3173   createMenu( 6011, ctrlId, -1 );
3174   createMenu( 6012, ctrlId, -1 );
3175   createMenu( 6013, ctrlId, -1 );
3176   createMenu( 6014, ctrlId, -1 );
3177   createMenu( 6015, ctrlId, -1 );
3178   createMenu( 6016, ctrlId, -1 );
3179   createMenu( separator(), ctrlId, -1 );
3180   createMenu( 6017, ctrlId, -1 );
3181   createMenu( 6009, ctrlId, -1 );
3182   createMenu( 6021, ctrlId, -1 );
3183   createMenu( separator(), ctrlId, -1 );
3184
3185   createMenu( 4000, addId, -1 );
3186   createMenu( 4009, addId, -1 );
3187   createMenu( 4010, addId, -1 );
3188   createMenu( 4021, addId, -1 );
3189   createMenu( 4022, addId, -1 );
3190   createMenu( 4023, addId, -1 );
3191   createMenu( 4031, addId, -1 );
3192   createMenu( 4032, addId, -1 );
3193   createMenu( 4033, addId, -1 );
3194   createMenu( separator(), addId, -1 );
3195   createMenu( 4034, addId, -1 );
3196   createMenu( 4035, addId, -1 );
3197   createMenu( 4036, addId, -1 );
3198   createMenu( 4037, addId, -1 );
3199   createMenu( 4038, addId, -1 );
3200   createMenu( 4039, addId, -1 );
3201   createMenu( 4040, addId, -1 );
3202
3203   createMenu( 4041, removeId, -1 );
3204   createMenu( 4042, removeId, -1 );
3205   createMenu( 4044, removeId, -1 );
3206   createMenu( separator(), removeId, -1 );
3207   createMenu( 4043, removeId, -1 );
3208
3209   createMenu( 4051, renumId, -1 );
3210   createMenu( 4052, renumId, -1 );
3211
3212   createMenu( 4061, transfId, -1 );
3213   createMenu( 4062, transfId, -1 );
3214   createMenu( 4063, transfId, -1 );
3215   createMenu( 4064, transfId, -1 );
3216   createMenu( 4065, transfId, -1 );
3217   createMenu( 4066, transfId, -1 );
3218   createMenu( 4068, transfId, -1 );
3219   createMenu( 4069, transfId, -1 );
3220
3221   createMenu( 4067,modifyId, -1 );
3222   createMenu( 407, modifyId, -1 );
3223   createMenu( 408, modifyId, -1 );
3224   createMenu( 409, modifyId, -1 );
3225   createMenu( 410, modifyId, -1 );
3226   createMenu( 411, modifyId, -1 );
3227   createMenu( 419, modifyId, -1 );
3228   createMenu( 412, modifyId, -1 );
3229   createMenu( 413, modifyId, -1 );
3230   createMenu( 416, modifyId, -1 );
3231   createMenu( 414, modifyId, -1 );
3232   createMenu( 415, modifyId, -1 );
3233   createMenu( 417, modifyId, -1 );
3234   createMenu( 418, modifyId, -1 );
3235
3236   createMenu( 214, viewId, -1 );
3237
3238   // ----- create toolbars --------------
3239   int meshTb     = createTool( tr( "TB_MESH" ) ),
3240       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3241       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3242       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3243       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3244
3245   createTool( 702, meshTb );
3246   createTool( 703, meshTb );
3247   createTool( 704, meshTb );
3248   createTool( 710, meshTb );
3249   createTool( separator(), meshTb );
3250   createTool( 701, meshTb );
3251   createTool( 711, meshTb );
3252   createTool( 712, meshTb );
3253   createTool( 713, meshTb );
3254   createTool( separator(), meshTb );
3255   createTool( 801, meshTb );
3256   createTool( 806, meshTb );
3257   createTool( 802, meshTb );
3258   createTool( 803, meshTb );
3259   //createTool( 815, meshTb );
3260   createTool( separator(), meshTb );
3261   createTool( 900, meshTb );
3262   createTool( 902, meshTb );
3263   createTool( 903, meshTb );
3264   createTool( 904, meshTb );
3265   createTool( separator(), meshTb );
3266
3267   createTool( 6001, ctrlTb );
3268   createTool( 6003, ctrlTb );
3269   createTool( 6004, ctrlTb );
3270   createTool( separator(), ctrlTb );
3271   createTool( 6005, ctrlTb );
3272   createTool( 6002, ctrlTb );
3273   createTool( 6018, ctrlTb );
3274   createTool( 6019, ctrlTb );
3275   createTool( 6011, ctrlTb );
3276   createTool( 6012, ctrlTb );
3277   createTool( 6013, ctrlTb );
3278   createTool( 6014, ctrlTb );
3279   createTool( 6015, ctrlTb );
3280   createTool( 6016, ctrlTb );
3281   createTool( separator(), ctrlTb );
3282   createTool( 6017, ctrlTb );
3283   createTool( 6009, ctrlTb );
3284   createTool( 6021, ctrlTb );
3285   createTool( separator(), ctrlTb );
3286
3287   createTool( 4000, addRemTb );
3288   createTool( 4009, addRemTb );
3289   createTool( 4010, addRemTb );
3290   createTool( 4021, addRemTb );
3291   createTool( 4022, addRemTb );
3292   createTool( 4023, addRemTb );
3293   createTool( 4031, addRemTb );
3294   createTool( 4032, addRemTb );
3295   createTool( 4033, addRemTb );
3296   createTool( separator(), addRemTb );
3297   createTool( 4034, addRemTb );
3298   createTool( 4035, addRemTb );
3299   createTool( 4036, addRemTb );
3300   createTool( 4037, addRemTb );
3301   createTool( 4038, addRemTb );
3302   createTool( 4039, addRemTb );
3303   createTool( 4040, addRemTb );
3304   createTool( separator(), addRemTb );
3305   createTool( 4041, addRemTb );
3306   createTool( 4042, addRemTb );
3307   createTool( 4044, addRemTb );
3308   createTool( 4043, addRemTb );
3309   createTool( separator(), addRemTb );
3310   createTool( 4051, addRemTb );
3311   createTool( 4052, addRemTb );
3312   createTool( separator(), addRemTb );
3313   createTool( 4061, addRemTb );
3314   createTool( 4062, addRemTb );
3315   createTool( 4063, addRemTb );
3316   createTool( 4064, addRemTb );
3317   createTool( 4065, addRemTb );
3318   createTool( 4066, addRemTb );
3319   createTool( 4068, addRemTb );
3320   createTool( 4069, addRemTb );
3321   createTool( separator(), addRemTb );
3322
3323   createTool( 4067,modifyTb );
3324   createTool( 407, modifyTb );
3325   createTool( 408, modifyTb );
3326   createTool( 409, modifyTb );
3327   createTool( 410, modifyTb );
3328   createTool( 411, modifyTb );
3329   createTool( 419, modifyTb );
3330   createTool( 412, modifyTb );
3331   createTool( 413, modifyTb );
3332   createTool( 416, modifyTb );
3333   createTool( 414, modifyTb );
3334   createTool( 415, modifyTb );
3335   createTool( 417, modifyTb );
3336   createTool( 418, modifyTb );
3337
3338   createTool( 214, dispModeTb );
3339
3340   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3341   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3342
3343   myRules.clear();
3344   QString OB = "'ObjectBrowser'",
3345           View = "'" + SVTK_Viewer::Type() + "'",
3346           pat = "'%1'",
3347           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3348           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3349           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3350           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3351           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3352                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3353                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3354                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3355                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3356                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3357                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3358           subMesh = elems,
3359           mesh_group = mesh + " " + subMesh + " " + group,
3360           hyp_alg = hypo + " " + algo;
3361
3362   // popup for object browser
3363   QString
3364     isInvisible("not( isVisible )"),
3365     isEmpty("numberOfNodes = 0"),
3366     isNotEmpty("numberOfNodes <> 0"),
3367
3368     // has nodes, edges, etc in VISIBLE! actor
3369     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3370     hasElems("(count( elemTypes ) > 0)"),
3371     hasDifferentElems("(count( elemTypes ) > 1)"),
3372     hasElems0d("({'Elem0d'} in elemTypes)"),
3373     hasEdges("({'Edge'} in elemTypes)"),
3374     hasFaces("({'Face'} in elemTypes)"),
3375     hasVolumes("({'Volume'} in elemTypes)");
3376
3377   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3378   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3379   //createPopupItem( 703, OB, subMesh, "&& isComputable" );  // CREATE_SUBMESH
3380   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3381   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3382   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3383   createPopupItem( 815, OB, group, "&& groupType = 'GroupOnGeom'" ); // EDIT_GROUP
3384
3385   popupMgr()->insert( separator(), -1, 0 );
3386   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3387   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3388   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
3389   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
3390   createPopupItem( 214, OB, mesh_group );                  // UPDATE
3391   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
3392   createPopupItem( 902, OB, mesh );                        // STD_INFO
3393   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
3394   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
3395   popupMgr()->insert( separator(), -1, 0 );
3396   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3397   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3398   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3399   popupMgr()->insert( separator(), -1, 0 );
3400   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3401   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
3402   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
3403   popupMgr()->insert( separator(), -1, 0 );
3404   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3405   popupMgr()->insert( separator(), -1, 0 );
3406   createPopupItem( 417, OB, mesh/*, "&& " + hasElems*/);       // convert to quadratic
3407   createPopupItem( 418, OB, mesh/*, "&& " + hasVolumes*/);     // create 2D mesh on 3D
3408   popupMgr()->insert( separator(), -1, 0 );
3409
3410   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3411   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
3412
3413   createPopupItem( 125, OB, mesh, multiple_non_empty );   // EXPORT_MED
3414   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
3415   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
3416   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
3417   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
3418   popupMgr()->insert( separator(), -1, 0 );
3419
3420   // popup for viewer
3421   createPopupItem( 803, View, group ); // EDIT_GROUP
3422   createPopupItem( 804, View, elems ); // ADD
3423   createPopupItem( 805, View, elems ); // REMOVE
3424
3425   popupMgr()->insert( separator(), -1, 0 );
3426   createPopupItem( 214, View, mesh_group ); // UPDATE
3427   createPopupItem( 900, View, mesh_group ); // ADV_INFO
3428   createPopupItem( 902, View, mesh );       // STD_INFO
3429   createPopupItem( 903, View, mesh_group ); // WHAT_IS
3430   createPopupItem( 904, View, mesh_group ); // FIND_ELEM
3431   popupMgr()->insert( separator(), -1, 0 );
3432
3433   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3434   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3435   popupMgr()->insert( separator(), -1, 0 );
3436
3437   int anId;
3438   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3439   QString aType = QString( "%1type in {%2}" ).arg( lc );
3440   aType = aType.arg( mesh_group );
3441   QString aMeshInVTK = aClient + "&&" + aType;
3442
3443   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3444   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3445   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3446
3447   //-------------------------------------------------
3448   // Numbering
3449   //-------------------------------------------------
3450   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3451
3452   popupMgr()->insert( action( 9010 ), anId, -1 );
3453   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
3454   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
3455
3456   popupMgr()->insert( action( 9011 ), anId, -1 );
3457   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
3458   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
3459
3460   popupMgr()->insert( separator(), -1, -1 );
3461
3462   //-------------------------------------------------
3463   // Display Mode
3464   //-------------------------------------------------
3465   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3466
3467   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3468   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3469   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3470
3471   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3472   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3473   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3474
3475   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3476   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3477   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3478
3479   popupMgr()->insert( separator(), anId, -1 );
3480
3481   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3482   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3483   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3484
3485   //-------------------------------------------------
3486   // Display Entity
3487   //-------------------------------------------------
3488   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3489
3490   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3491
3492   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
3493   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
3494   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
3495
3496   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3497   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3498   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3499
3500   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3501   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3502   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3503
3504   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3505   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3506   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3507
3508   popupMgr()->insert( separator(), anId, -1 );
3509
3510   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3511   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3512
3513
3514   //-------------------------------------------------
3515   // Representation of the 2D Quadratic elements
3516   //-------------------------------------------------
3517   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
3518   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
3519   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
3520   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
3521
3522   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
3523   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
3524   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
3525
3526   //-------------------------------------------------
3527   // Orientation of faces
3528   //-------------------------------------------------
3529   popupMgr()->insert( action( 221 ), -1, -1 );
3530   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3531   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3532
3533   //-------------------------------------------------
3534   // Color / Size
3535   //-------------------------------------------------
3536   popupMgr()->insert( action( 1132 ), -1, -1 );
3537   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3538
3539   //-------------------------------------------------
3540   // Transparency
3541   //-------------------------------------------------
3542   popupMgr()->insert( action( 1133 ), -1, -1 );
3543   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3544
3545   //-------------------------------------------------
3546   // Clipping
3547   //-------------------------------------------------
3548   popupMgr()->insert( action( 1134 ), -1, -1 );
3549   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& selcount=1 && isVisible", QtxPopupMgr::VisibleRule );
3550
3551   popupMgr()->insert( separator(), -1, -1 );
3552
3553   //-------------------------------------------------
3554   // Controls
3555   //-------------------------------------------------
3556   QString
3557     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
3558     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3559     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3560     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3561
3562   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3563
3564   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3565   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3566
3567   popupMgr()->insert( separator(), anId, -1 );
3568
3569   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3570   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3571   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3572
3573   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3574   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3575   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3576
3577   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3578   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3579   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3580
3581   popupMgr()->insert( separator(), anId, -1 );
3582
3583   popupMgr()->insert( action( 6005 ), anId, -1 ); // FREE_NODE
3584   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
3585   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
3586
3587   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3588   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3589   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3590
3591   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3592   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3593   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3594
3595   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3596   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3597   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3598
3599   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3600   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3601   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3602
3603   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3604   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3605   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
3606
3607   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3608   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3609   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
3610
3611   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3612   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3613   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
3614
3615   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3616   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3617   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
3618
3619   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3620   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3621   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
3622
3623   popupMgr()->insert( separator(), anId, -1 );
3624
3625   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3626   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3627   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
3628
3629   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3630   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3631   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
3632
3633   popupMgr()->insert( action( 6021 ), anId, -1 ); // FREE_FACE
3634   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
3635                                        QtxPopupMgr::VisibleRule );
3636   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
3637
3638   popupMgr()->insert( separator(), anId, -1 );
3639
3640   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3641   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3642
3643   popupMgr()->insert( separator(), -1, -1 );
3644
3645   //-------------------------------------------------
3646   // Display / Erase
3647   //-------------------------------------------------
3648   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3649     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3650   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3651   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
3652
3653   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3654   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
3655
3656   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3657   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
3658
3659   popupMgr()->insert( separator(), -1, -1 );
3660
3661   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3662            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3663 }
3664
3665 //================================================================================
3666 /*!
3667  * \brief Return true if SMESH or GEOM objects are selected.
3668  * Is called form LightApp_Module::activateModule() which clear selection if
3669  * not isSelectionCompatible()
3670  */
3671 //================================================================================
3672
3673 bool SMESHGUI::isSelectionCompatible()
3674 {
3675   bool isCompatible = true;
3676   SALOME_ListIO selected;
3677   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3678     Sel->selectedObjects( selected );
3679
3680   SALOME_ListIteratorOfListIO It( selected );
3681   for ( ; isCompatible && It.More(); It.Next())
3682     isCompatible =
3683       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3684       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3685
3686   return isCompatible;
3687 }
3688
3689
3690 bool SMESHGUI::reusableOperation( const int id )
3691 {
3692   // compute, evaluate and precompute are not reusable operations
3693   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
3694 }
3695
3696 bool SMESHGUI::activateModule( SUIT_Study* study )
3697 {
3698   bool res = SalomeApp_Module::activateModule( study );
3699
3700   setMenuShown( true );
3701   setToolShown( true );
3702
3703   // Reset actions accelerator keys
3704   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
3705   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
3706   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
3707
3708   action(  33)->setEnabled(true); // Delete: Key_Delete
3709   action(1101)->setEnabled(true); // Rename: Key_F2
3710
3711   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
3712   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
3713   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
3714     if ( _PTR(Study) aStudy = s->studyDS()) {
3715       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
3716       updateObjBrowser(); // objects can be removed
3717     }
3718
3719   return res;
3720 }
3721
3722 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3723 {
3724   setMenuShown( false );
3725   setToolShown( false );
3726
3727   EmitSignalCloseAllDialogs();
3728
3729   // Unset actions accelerator keys
3730   action(111)->setShortcut(QKeySequence()); // Import DAT
3731   action(112)->setShortcut(QKeySequence()); // Import UNV
3732   action(113)->setShortcut(QKeySequence()); // Import MED
3733
3734   action(  33)->setEnabled(false); // Delete: Key_Delete
3735   action(1101)->setEnabled(false); // Rename: Key_F2
3736
3737   return SalomeApp_Module::deactivateModule( study );
3738 }
3739
3740 void SMESHGUI::studyClosed( SUIT_Study* s )
3741 {
3742   SMESH::RemoveVisuData( s->id() );
3743   SalomeApp_Module::studyClosed( s );
3744 }
3745
3746 void SMESHGUI::OnGUIEvent()
3747 {
3748   const QObject* obj = sender();
3749   if ( !obj || !obj->inherits( "QAction" ) )
3750     return;
3751   int id = actionId((QAction*)obj);
3752   if ( id != -1 )
3753     OnGUIEvent( id );
3754 }
3755
3756 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3757 {
3758   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3759   if ( CORBA::is_nil( myComponentSMESH ) )
3760     {
3761       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3762       if ( aStudy )
3763         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3764       return aGUI.myComponentSMESH;
3765     }
3766   if ( aStudy )
3767     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3768   return myComponentSMESH;
3769 }
3770
3771 QString SMESHGUI::engineIOR() const
3772 {
3773   CORBA::ORB_var anORB = getApp()->orb();
3774   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3775   return QString( anIOR.in() );
3776 }
3777
3778 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
3779 {
3780   SalomeApp_Module::contextMenuPopup( client, menu, title );
3781   SALOME_ListIO lst;
3782   selectionMgr()->selectedObjects( lst );
3783   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3784     Handle(SALOME_InteractiveObject) io = lst.First();
3785     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3786     _PTR(Study) study = appStudy->studyDS();
3787     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3788     if ( obj ) {
3789       QString aName = QString( obj->GetName().c_str() );
3790       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3791           aName.remove( (aName.length() - 1), 1 );
3792       title = aName;
3793     }
3794   }
3795 }
3796
3797 LightApp_Selection* SMESHGUI::createSelection() const
3798 {
3799   return new SMESHGUI_Selection();
3800 }
3801
3802 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3803 {
3804   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
3805   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
3806 }
3807
3808 void SMESHGUI::viewManagers( QStringList& list ) const
3809 {
3810   list.append( SVTK_Viewer::Type() );
3811 }
3812
3813 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3814 {
3815   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3816     SMESH::UpdateSelectionProp( this );
3817 }
3818
3819 void SMESHGUI::createPreferences()
3820 {
3821   // General tab ------------------------------------------------------------------------
3822   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3823
3824   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3825   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3826
3827   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3828   setPreferenceProperty( qaGroup, "columns", 2 );
3829   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3830   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3831   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3832   setPreferenceProperty( prec, "min", 0 );
3833   setPreferenceProperty( prec, "max", 16 );
3834
3835   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3836   setPreferenceProperty( dispgroup, "columns", 2 );
3837   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3838   QStringList modes;
3839   modes.append( "Wireframe" );
3840   modes.append( "Shading" );
3841   modes.append( "Nodes" );
3842   modes.append( "Shrink" );
3843   QList<QVariant> indices;
3844   indices.append( 0 );
3845   indices.append( 1 );
3846   indices.append( 2 );
3847   indices.append( 3 );
3848   setPreferenceProperty( dispmode, "strings", modes );
3849   setPreferenceProperty( dispmode, "indexes", indices );
3850
3851   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
3852   setPreferenceProperty( arcgroup, "columns", 2 );
3853   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
3854   QStringList quadraticModes;
3855   quadraticModes.append("Lines");
3856   quadraticModes.append("Arcs");
3857   indices.clear();
3858   indices.append( 0 );
3859   indices.append( 1 );
3860   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
3861   setPreferenceProperty( quadraticmode, "indexes", indices );
3862
3863   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
3864                               "SMESH", "max_angle" );
3865   setPreferenceProperty( maxAngle, "min", 1 );
3866   setPreferenceProperty( maxAngle, "max", 90 );
3867
3868
3869
3870   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3871   setPreferenceProperty( exportgroup, "columns", 2 );
3872   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3873   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3874
3875   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
3876   setPreferenceProperty( computeGroup, "columns", 2 );
3877   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
3878   modes.clear();
3879   modes.append( "Never" );
3880   modes.append( "Errors only" );
3881   modes.append( "Always" );
3882   indices.clear();
3883   indices.append( 0 );
3884   indices.append( 1 );
3885   indices.append( 2 );
3886   setPreferenceProperty( notifyMode, "strings", modes );
3887   setPreferenceProperty( notifyMode, "indexes", indices );
3888
3889   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
3890   setPreferenceProperty( segGroup, "columns", 2 );
3891   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
3892                               "SMESH", "segmentation" );
3893   setPreferenceProperty( segLen, "min", 1 );
3894   setPreferenceProperty( segLen, "max", 10000000 );
3895   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
3896                              "SMESH", "nb_segments_per_edge" );
3897   setPreferenceProperty( nbSeg, "min", 1 );
3898   setPreferenceProperty( nbSeg, "max", 10000000 );
3899
3900   // Quantities with individual precision settings
3901   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
3902   setPreferenceProperty( precGroup, "columns", 2 );
3903
3904   const int nbQuantities = 6;
3905   int precs[nbQuantities], ii = 0;
3906   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
3907                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
3908   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
3909                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
3910   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
3911                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
3912   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
3913                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
3914   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
3915                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
3916   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
3917                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
3918
3919   // Set property for precision value for spinboxes
3920   for ( ii = 0; ii < nbQuantities; ii++ ){
3921     setPreferenceProperty( precs[ii], "min", -14 );
3922     setPreferenceProperty( precs[ii], "max", 14 );
3923     setPreferenceProperty( precs[ii], "precision", 2 );
3924   }
3925
3926   // Mesh tab ------------------------------------------------------------------------
3927   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3928   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3929   setPreferenceProperty( nodeGroup, "columns", 3 );
3930
3931   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3932
3933   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
3934
3935   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3936   QList<QVariant> aMarkerTypeIndicesList;
3937   QList<QVariant> aMarkerTypeIconsList;
3938   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
3939     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
3940     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
3941     aMarkerTypeIndicesList << i;
3942     aMarkerTypeIconsList << pixmap;
3943   }
3944   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
3945   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
3946
3947   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
3948
3949   QList<QVariant> aMarkerScaleIndicesList;
3950   QStringList     aMarkerScaleValuesList;
3951   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
3952     aMarkerScaleIndicesList << i;
3953     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
3954   }
3955   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
3956   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
3957
3958   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3959   setPreferenceProperty( elemGroup, "columns", 2 );
3960
3961   addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3962   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3963   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3964   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
3965
3966   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
3967   setPreferenceProperty( grpGroup, "columns", 2 );
3968
3969   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
3970
3971   //int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3972   //setPreferenceProperty( sp, "hstretch", 0 );
3973   //setPreferenceProperty( sp, "vstretch", 0 );
3974
3975   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
3976                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
3977   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3978   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
3979                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
3980   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
3981                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
3982
3983   setPreferenceProperty( size0d, "min", 1 );
3984   setPreferenceProperty( size0d, "max", 10 );
3985
3986   setPreferenceProperty( sp, "hstretch", 0 );
3987   setPreferenceProperty( sp, "vstretch", 0 );
3988
3989   setPreferenceProperty( elemW, "min", 1 );
3990   setPreferenceProperty( elemW, "max", 5 );
3991
3992   setPreferenceProperty( shrink, "min", 0 );
3993   setPreferenceProperty( shrink, "max", 100 );
3994
3995   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
3996   setPreferenceProperty( orientGroup, "columns", 1 );
3997
3998   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
3999   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
4000
4001   setPreferenceProperty( orientScale, "min", 0.05 );
4002   setPreferenceProperty( orientScale, "max", 0.5 );
4003   setPreferenceProperty( orientScale, "step", 0.05 );
4004
4005   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
4006
4007   // Selection tab ------------------------------------------------------------------------
4008   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
4009
4010   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
4011   setPreferenceProperty( selGroup, "columns", 2 );
4012
4013   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
4014   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
4015   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
4016
4017   setPreferenceProperty( selW, "min", 1 );
4018   setPreferenceProperty( selW, "max", 5 );
4019
4020   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
4021   setPreferenceProperty( preGroup, "columns", 2 );
4022
4023   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
4024   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
4025
4026   setPreferenceProperty( preW, "min", 1 );
4027   setPreferenceProperty( preW, "max", 5 );
4028
4029   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
4030   setPreferenceProperty( precSelGroup, "columns", 2 );
4031
4032   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
4033   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
4034   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
4035
4036   // Scalar Bar tab ------------------------------------------------------------------------
4037   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
4038   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
4039   setPreferenceProperty( fontGr, "columns", 2 );
4040
4041   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
4042   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
4043
4044   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
4045   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
4046
4047   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
4048   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
4049
4050   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
4051   setPreferenceProperty( numcol, "min", 2 );
4052   setPreferenceProperty( numcol, "max", 256 );
4053
4054   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
4055   setPreferenceProperty( numlab, "min", 2 );
4056   setPreferenceProperty( numlab, "max", 65 );
4057
4058   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
4059   setPreferenceProperty( orientGr, "columns", 2 );
4060   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
4061   QStringList orients;
4062   orients.append( tr( "SMESH_VERTICAL" ) );
4063   orients.append( tr( "SMESH_HORIZONTAL" ) );
4064   indices.clear(); indices.append( 0 ); indices.append( 1 );
4065   setPreferenceProperty( orient, "strings", orients );
4066   setPreferenceProperty( orient, "indexes", indices );
4067
4068   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
4069   setPreferenceProperty( posVSizeGr, "columns", 2 );
4070   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
4071   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
4072   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
4073   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
4074   setPreferenceProperty( xv, "step", 0.1 );
4075   setPreferenceProperty( xv, "min", 0.0 );
4076   setPreferenceProperty( xv, "max", 1.0 );
4077   setPreferenceProperty( yv, "step", 0.1 );
4078   setPreferenceProperty( yv, "min", 0.0 );
4079   setPreferenceProperty( yv, "max", 1.0 );
4080   setPreferenceProperty( wv, "step", 0.1 );
4081   setPreferenceProperty( wv, "min", 0.0 );
4082   setPreferenceProperty( wv, "max", 1.0 );
4083   setPreferenceProperty( hv, "min", 0.0 );
4084   setPreferenceProperty( hv, "max", 1.0 );
4085   setPreferenceProperty( hv, "step", 0.1 );
4086
4087   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4088   setPreferenceProperty( posHSizeGr, "columns", 2 );
4089   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4090   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4091   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4092   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4093   setPreferenceProperty( xv, "min", 0.0 );
4094   setPreferenceProperty( xv, "max", 1.0 );
4095   setPreferenceProperty( xv, "step", 0.1 );
4096   setPreferenceProperty( xh, "min", 0.0 );
4097   setPreferenceProperty( xh, "max", 1.0 );
4098   setPreferenceProperty( xh, "step", 0.1 );
4099   setPreferenceProperty( yh, "min", 0.0 );
4100   setPreferenceProperty( yh, "max", 1.0 );
4101   setPreferenceProperty( yh, "step", 0.1 );
4102   setPreferenceProperty( wh, "min", 0.0 );
4103   setPreferenceProperty( wh, "max", 1.0 );
4104   setPreferenceProperty( wh, "step", 0.1 );
4105   setPreferenceProperty( hh, "min", 0.0 );
4106   setPreferenceProperty( hh, "max", 1.0 );
4107   setPreferenceProperty( hh, "step", 0.1 );
4108 }
4109
4110 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4111 {
4112   if( sect=="SMESH" ) {
4113     float sbX1,sbY1,sbW,sbH;
4114     float aTol = 1.00000009999999;
4115     std::string aWarning;
4116     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4117     if( name=="selection_object_color" || name=="selection_element_color" ||
4118         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
4119         name=="selection_precision_node" || name=="selection_precision_element" ||
4120         name=="selection_precision_object")
4121       SMESH::UpdateSelectionProp( this );
4122     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4123       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4124       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4125       if(sbX1+sbW > aTol){
4126         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4127         sbX1=0.01;
4128         sbW=0.08;
4129         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4130         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4131       }
4132     }
4133     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4134       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4135       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4136       if(sbY1+sbH > aTol){
4137         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4138         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4139         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4140       }
4141     }
4142     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4143       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4144       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4145       if(sbX1+sbW > aTol){
4146         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4147         sbX1=0.1;
4148         sbW=0.08;
4149         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4150         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4151       }
4152     }
4153     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4154       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4155       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4156       if(sbY1+sbH > aTol){
4157         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4158         sbY1=0.01;
4159         sbH=0.08;
4160         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4161         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4162       }
4163     }
4164     else if ( name == "segmentation" ) {
4165       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4166       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4167     }
4168     else if ( name == "nb_segments_per_edge" ) {
4169       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4170       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4171     }
4172
4173     if(aWarning.size() != 0){
4174       aWarning += "The default values are applied instead.";
4175       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4176                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4177                                QObject::tr(aWarning.c_str()));
4178     }
4179   }
4180 }
4181
4182 //================================================================================
4183 /*!
4184  * \brief Update something in accordance with update flags
4185   * \param theFlags - update flags
4186 *
4187 * Update viewer or/and object browser etc. in accordance with update flags ( see
4188 * LightApp_UpdateFlags enumeration ).
4189 */
4190 //================================================================================
4191 void SMESHGUI::update( const int flags )
4192 {
4193   if ( flags & UF_Viewer | flags & UF_Forced )
4194     SMESH::UpdateView();
4195   else
4196     SalomeApp_Module::update( flags );
4197 }
4198
4199 //================================================================================
4200 /*!
4201  * \brief Set default selection mode
4202 *
4203 * SLOT called when operation commited. Sets default selection mode
4204 */
4205 //================================================================================
4206 void SMESHGUI::onOperationCommited( SUIT_Operation* )
4207 {
4208   SVTK_ViewWindow* vtkWnd =
4209     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4210   if ( vtkWnd )
4211     vtkWnd->SetSelectionMode( ActorSelection );
4212 }
4213
4214 //================================================================================
4215 /*!
4216  * \brief Set default selection mode
4217 *
4218 * SLOT called when operation aborted. Sets default selection mode
4219 */
4220 //================================================================================
4221 void SMESHGUI::onOperationAborted( SUIT_Operation* )
4222 {
4223   SVTK_ViewWindow* vtkWnd =
4224     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4225   if ( vtkWnd )
4226     vtkWnd->SetSelectionMode( ActorSelection );
4227 }
4228
4229 //================================================================================
4230 /*!
4231  * \brief Creates operation with given identifier
4232   * \param id - identifier of operation to be started
4233   * \return Pointer on created operation or NULL if operation is not created
4234 *
4235 * Virtual method redefined from the base class creates operation with given id.
4236 * It is called called automatically from startOperation method of base class.
4237 */
4238 //================================================================================
4239 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
4240 {
4241   LightApp_Operation* op = 0;
4242   // to do : create operation here
4243   switch( id )
4244   {
4245     case 417: //convert to quadratic
4246       op = new SMESHGUI_ConvToQuadOp();
4247     break;
4248     case 418: // create 2D mesh as boundary on 3D
4249       op = new SMESHGUI_Make2DFrom3DOp();
4250     break;
4251     case 701: // Compute mesh
4252       op = new SMESHGUI_ComputeOp();
4253     break;
4254     case 702: // Create mesh
4255       op = new SMESHGUI_MeshOp( true, true );
4256     break;
4257     case 703: // Create sub-mesh
4258       op = new SMESHGUI_MeshOp( true, false );
4259     break;
4260     case 704: // Edit mesh/sub-mesh
4261       op = new SMESHGUI_MeshOp( false );
4262     break;
4263     case 711: // Precompute mesh
4264       op = new SMESHGUI_PrecomputeOp();
4265     break;
4266     case 712: // Evaluate mesh
4267       op = new SMESHGUI_EvaluateOp();
4268     break;
4269     case 713: // Evaluate mesh
4270       op = new SMESHGUI_MeshOrderOp();
4271     break;
4272     case 806: // Create group on geom
4273       op = new SMESHGUI_GroupOnShapeOp();
4274       break;
4275     case 904: // Find element
4276       op = new SMESHGUI_FindElemByPointOp();
4277       break;
4278     case 4067: // make mesh pass through point
4279       op = new SMESHGUI_MakeNodeAtPointOp();
4280       break;
4281     default:
4282     break;
4283   }
4284
4285   if( !op )
4286     op = SalomeApp_Module::createOperation( id );
4287   return op;
4288 }
4289
4290 //================================================================================
4291 /*!
4292  * \brief Stops current operations and starts a given one
4293   * \param id - The id of the operation to start
4294  */
4295 //================================================================================
4296
4297 void SMESHGUI::switchToOperation(int id)
4298 {
4299   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
4300     activeStudy()->abortAllOperations();
4301   startOperation( id );
4302 }
4303
4304 LightApp_Displayer* SMESHGUI::displayer()
4305 {
4306   if( !myDisplayer )
4307     myDisplayer = new SMESHGUI_Displayer( getApp() );
4308   return myDisplayer;
4309 }
4310
4311 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
4312 {
4313   int aHue = -1;
4314   int aTolerance = 64;
4315   int anIterations = 0;
4316   int aPeriod = 5;
4317
4318   while( 1 )
4319   {
4320     anIterations++;
4321     if( anIterations % aPeriod == 0 )
4322     {
4323       aTolerance /= 2;
4324       if( aTolerance < 1 )
4325         break;
4326     }
4327     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
4328
4329     aHue = (int)( 360.0 * rand() / RAND_MAX );
4330     //cout << "Hue = " << aHue << endl;
4331
4332     //cout << "Auto colors : ";
4333     bool ok = true;
4334     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
4335     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
4336     for( ; it != itEnd; ++it )
4337     {
4338       SALOMEDS::Color anAutoColor = *it;
4339       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
4340
4341       int h, s, v;
4342       aQColor.getHsv( &h, &s, &v );
4343       //cout << h << " ";
4344       if( abs( h - aHue ) < aTolerance )
4345       {
4346         ok = false;
4347         //cout << "break (diff = " << abs( h - aHue ) << ")";
4348         break;
4349       }
4350     }
4351     //cout << endl;
4352
4353     if( ok )
4354       break;
4355   }
4356
4357   //cout << "Hue of the returned color = " << aHue << endl;
4358   QColor aColor;
4359   aColor.setHsv( aHue, 255, 255 );
4360
4361   SALOMEDS::Color aSColor;
4362   aSColor.R = (double)aColor.red() / 255.0;
4363   aSColor.G = (double)aColor.green() / 255.0;
4364   aSColor.B = (double)aColor.blue() / 255.0;
4365
4366   return aSColor;
4367 }
4368
4369 const char gSeparator = '_'; // character used to separate parameter names
4370 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
4371 const char gPathSep   = '|'; // character used to separate paths
4372
4373 /*!
4374  * \brief Store visual parameters
4375  *
4376  * This method is called just before the study document is saved.
4377  * Store visual parameters in AttributeParameter attribue(s)
4378  */
4379 void SMESHGUI::storeVisualParameters (int savePoint)
4380 {
4381   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4382   if (!appStudy || !appStudy->studyDS())
4383     return;
4384   _PTR(Study) studyDS = appStudy->studyDS();
4385
4386   // componentName is used for encoding of entries when storing them in IParameters
4387   std::string componentName = myComponentSMESH->ComponentDataType();
4388   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
4389   //if (!aSComponent) return;
4390
4391   // IParameters
4392   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4393                                                              componentName.c_str(),
4394                                                              savePoint);
4395   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4396
4397   // store map of custom markers
4398   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4399   if( !aMarkerMap.empty() )
4400   {
4401     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
4402     for( ; anIter != aMarkerMap.end(); anIter++ )
4403     {
4404       int anId = anIter->first;
4405       VTK::MarkerData aMarkerData = anIter->second;
4406       std::string aMarkerFileName = aMarkerData.first;
4407       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
4408       if( aMarkerTexture.size() < 3 )
4409         continue; // should contain at least width, height and the first value
4410
4411       QString aPropertyName( "texture" );
4412       aPropertyName += gSeparator;
4413       aPropertyName += QString::number( anId );
4414
4415       QString aPropertyValue = aMarkerFileName.c_str();
4416       aPropertyValue += gPathSep;
4417
4418       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
4419       ushort aWidth = *aTextureIter++;
4420       ushort aHeight = *aTextureIter++;
4421       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
4422       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
4423       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
4424         aPropertyValue += QString::number( *aTextureIter );
4425
4426       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
4427     }
4428   }
4429
4430   // viewers counters are used for storing view_numbers in IParameters
4431   int vtkViewers = 0;
4432
4433   // main cycle to store parameters of displayed objects
4434   QList<SUIT_ViewManager*> lst;
4435   QList<SUIT_ViewManager*>::Iterator it;
4436   getApp()->viewManagers(lst);
4437   for (it = lst.begin(); it != lst.end(); it++)
4438   {
4439     SUIT_ViewManager* vman = *it;
4440     QString vType = vman->getType();
4441
4442     // saving VTK actors properties
4443     if (vType == SVTK_Viewer::Type())
4444     {
4445       QVector<SUIT_ViewWindow*> views = vman->getViews();
4446       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
4447       {
4448         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
4449         {
4450           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
4451           vtkActorCollection* allActors = aCopy.GetActors();
4452           allActors->InitTraversal();
4453           while (vtkActor* actor = allActors->GetNextActor())
4454           {
4455             if (actor->GetVisibility()) // store only visible actors
4456             {
4457               SMESH_Actor* aSmeshActor = 0;
4458               if (actor->IsA("SMESH_Actor"))
4459                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
4460               if (aSmeshActor && aSmeshActor->hasIO())
4461               {
4462                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
4463                 if (io->hasEntry())
4464                 {
4465                   // entry is "encoded" = it does NOT contain component adress,
4466                   // since it is a subject to change on next component loading
4467                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
4468
4469                   std::string param, vtkParam = vType.toLatin1().data();
4470                   vtkParam += gSeparator;
4471                   vtkParam += QString::number(vtkViewers).toLatin1().data();
4472                   vtkParam += gSeparator;
4473
4474                   // Visibility
4475                   param = vtkParam + "Visibility";
4476                   ip->setParameter(entry, param, "On");
4477
4478                   // Representation
4479                   param = vtkParam + "Representation";
4480                   ip->setParameter(entry, param, QString::number
4481                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
4482
4483                   // IsShrunk
4484                   param = vtkParam + "IsShrunk";
4485                   ip->setParameter(entry, param, QString::number
4486                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
4487
4488                   // Displayed entities
4489                   unsigned int aMode = aSmeshActor->GetEntityMode();
4490                   bool isE = aMode & SMESH_Actor::eEdges;
4491                   bool isF = aMode & SMESH_Actor::eFaces;
4492                   bool isV = aMode & SMESH_Actor::eVolumes;
4493
4494                   QString modeStr ("e");
4495                   modeStr += gDigitsSep; modeStr += QString::number(isE);
4496                   modeStr += gDigitsSep; modeStr += "f";
4497                   modeStr += gDigitsSep; modeStr += QString::number(isF);
4498                   modeStr += gDigitsSep; modeStr += "v";
4499                   modeStr += gDigitsSep; modeStr += QString::number(isV);
4500
4501                   param = vtkParam + "Entities";
4502                   ip->setParameter(entry, param, modeStr.toLatin1().data());
4503
4504                   // Colors (surface:edge:)
4505                   vtkFloatingPointType r, g, b;
4506
4507                   aSmeshActor->GetSufaceColor(r, g, b);
4508                   QString colorStr ("surface");
4509                   colorStr += gDigitsSep; colorStr += QString::number(r);
4510                   colorStr += gDigitsSep; colorStr += QString::number(g);
4511                   colorStr += gDigitsSep; colorStr += QString::number(b);
4512
4513                   aSmeshActor->GetBackSufaceColor(r, g, b);
4514                   colorStr += gDigitsSep; colorStr += "backsurface";
4515                   colorStr += gDigitsSep; colorStr += QString::number(r);
4516                   colorStr += gDigitsSep; colorStr += QString::number(g);
4517                   colorStr += gDigitsSep; colorStr += QString::number(b);
4518
4519                   aSmeshActor->GetEdgeColor(r, g, b);
4520                   colorStr += gDigitsSep; colorStr += "edge";
4521                   colorStr += gDigitsSep; colorStr += QString::number(r);
4522                   colorStr += gDigitsSep; colorStr += QString::number(g);
4523                   colorStr += gDigitsSep; colorStr += QString::number(b);
4524
4525                   aSmeshActor->GetNodeColor(r, g, b);
4526                   colorStr += gDigitsSep; colorStr += "node";
4527                   colorStr += gDigitsSep; colorStr += QString::number(r);
4528                   colorStr += gDigitsSep; colorStr += QString::number(g);
4529                   colorStr += gDigitsSep; colorStr += QString::number(b);
4530
4531                   param = vtkParam + "Colors";
4532                   ip->setParameter(entry, param, colorStr.toLatin1().data());
4533
4534                   // Sizes of lines and points
4535                   QString sizeStr ("line");
4536                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
4537                   sizeStr += gDigitsSep; sizeStr += "shrink";
4538                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
4539
4540                   param = vtkParam + "Sizes";
4541                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
4542
4543                   // Point marker
4544                   QString markerStr;
4545
4546                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
4547                   if( aMarkerType == VTK::MT_USER ) {
4548                     markerStr += "custom";
4549                     markerStr += gDigitsSep;
4550                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
4551                   }
4552                   else {
4553                     markerStr += "std";
4554                     markerStr += gDigitsSep;
4555                     markerStr += QString::number( (int)aMarkerType );
4556                     markerStr += gDigitsSep;
4557                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
4558                   }
4559
4560                   param = vtkParam + "PointMarker";
4561                   ip->setParameter(entry, param, markerStr.toLatin1().data());
4562
4563                   // Opacity
4564                   param = vtkParam + "Opacity";
4565                   ip->setParameter(entry, param,
4566                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
4567
4568                   // Clipping
4569                   param = vtkParam + "ClippingPlane";
4570                   int nPlanes = aSmeshActor->GetNumberOfClippingPlanes();
4571                   if (!nPlanes)
4572                     ip->setParameter(entry, param, "Off");
4573                   for (int ipl = 0; ipl < nPlanes; ipl++) {
4574                     //vtkPlane* plane = aSmeshActor->GetClippingPlane(ipl);
4575                     SMESH::Orientation anOrientation;
4576                     double aDistance;
4577                     vtkFloatingPointType anAngle[2];
4578                     SMESHGUI_ClippingDlg::GetPlaneParam(aSmeshActor, ipl, anOrientation, aDistance, anAngle);
4579                     std::string planeValue = QString::number((int)anOrientation).toLatin1().data();
4580                     planeValue += gDigitsSep; planeValue += QString::number(aDistance).toLatin1().data();
4581                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[0]).toLatin1().data();
4582                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[1]).toLatin1().data();
4583
4584                     ip->setParameter(entry, param + QString::number(ipl+1).toLatin1().data(), planeValue);
4585                   }
4586                 } // if (io->hasEntry())
4587               } // SMESH_Actor && hasIO
4588             } // isVisible
4589           } // while.. actors traversal
4590         } // if (vtkView)
4591       } // for (views)
4592       vtkViewers++;
4593     } // if (SVTK view model)
4594   } // for (viewManagers)
4595 }
4596
4597 /*!
4598  * \brief Restore visual parameters
4599  *
4600  * This method is called after the study document is opened.
4601  * Restore visual parameters from AttributeParameter attribue(s)
4602  */
4603 void SMESHGUI::restoreVisualParameters (int savePoint)
4604 {
4605   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4606   if (!appStudy || !appStudy->studyDS())
4607     return;
4608   _PTR(Study) studyDS = appStudy->studyDS();
4609
4610   // componentName is used for encoding of entries when storing them in IParameters
4611   std::string componentName = myComponentSMESH->ComponentDataType();
4612   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
4613   //if (!aSComponent) return;
4614
4615   // IParameters
4616   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4617                                                              componentName.c_str(),
4618                                                              savePoint);
4619   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4620
4621   // restore map of custom markers
4622   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4623
4624   std::vector<std::string> properties = ip->getProperties();
4625   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
4626   {
4627     std::string property = *propIt;
4628     QString aPropertyName( property.c_str() );
4629     QString aPropertyValue( ip->getProperty( property ).c_str() );
4630
4631     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
4632     if( aPropertyNameList.size() != 2 )
4633       continue;
4634
4635     int anId = 0;
4636     bool ok = false;
4637     if( aPropertyNameList[0] == "texture" )
4638       anId = aPropertyNameList[1].toInt( &ok );
4639
4640     if( !ok || anId < 1 )
4641       continue;
4642
4643     QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
4644     if( aPropertyValueList.size() != 2 )
4645       continue;
4646
4647     std::string aMarkerFileName = aPropertyValueList[0].toStdString();
4648     QString aMarkerTextureString = aPropertyValueList[1];
4649     QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
4650     if( aMarkerTextureStringList.size() != 3 )
4651       continue;
4652
4653     ok = false;
4654     ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
4655     if( !ok )
4656       continue;
4657
4658     ok = false;
4659     ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
4660     if( !ok )
4661       continue;
4662
4663     VTK::MarkerTexture aMarkerTexture;
4664     aMarkerTexture.push_back( aWidth );
4665     aMarkerTexture.push_back( aHeight );
4666
4667     QString aMarkerTextureData = aMarkerTextureStringList[2];
4668     for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
4669     {
4670       QChar aChar = aMarkerTextureData.at( i );
4671       if( aChar.isDigit() )
4672         aMarkerTexture.push_back( aChar.digitValue() );
4673     }
4674
4675     aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
4676   }
4677
4678   std::vector<std::string> entries = ip->getEntries();
4679
4680   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
4681   {
4682     // entry is a normal entry - it should be "decoded" (setting base adress of component)
4683     QString entry (ip->decodeEntry(*entIt).c_str());
4684
4685     // Check that the entry corresponds to a real object in the Study
4686     // as the object may be deleted or modified after the visual state is saved.
4687     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
4688     if (!so) continue; //Skip the not existent entry
4689
4690     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
4691     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
4692
4693     std::vector<std::string>::iterator namesIt = paramNames.begin();
4694     std::vector<std::string>::iterator valuesIt = paramValues.begin();
4695
4696     // actors are stored in a map after displaying of them for
4697     // quicker access in the future: map < viewID to actor >
4698     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
4699
4700     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
4701     {
4702       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
4703       // '_' is used as separator and should not be used in viewer type or parameter names.
4704       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
4705       if (lst.size() != 3)
4706         continue;
4707
4708       QString viewerTypStr = lst[0];
4709       QString viewIndexStr = lst[1];
4710       QString paramNameStr = lst[2];
4711
4712       bool ok;
4713       int viewIndex = viewIndexStr.toUInt(&ok);
4714       if (!ok) // bad conversion of view index to integer
4715         continue;
4716
4717       // viewers
4718       if (viewerTypStr == SVTK_Viewer::Type())
4719       {
4720         SMESH_Actor* aSmeshActor = 0;
4721         if (vtkActors.IsBound(viewIndex))
4722           aSmeshActor = vtkActors.Find(viewIndex);
4723
4724         if (paramNameStr == "Visibility")
4725         {
4726           if (!aSmeshActor && displayer())
4727           {
4728             QList<SUIT_ViewManager*> lst;
4729             getApp()->viewManagers(viewerTypStr, lst);
4730
4731             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4732             if (viewIndex >= 0 && viewIndex < lst.count()) {
4733               SUIT_ViewManager* vman = lst.at(viewIndex);
4734               SUIT_ViewModel* vmodel = vman->getViewModel();
4735               // SVTK view model can be casted to SALOME_View
4736               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
4737
4738               // store displayed actor in a temporary map for quicker
4739               // access later when restoring other parameters
4740               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4741               vtkRenderer* Renderer = vtkView->getRenderer();
4742               VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
4743               vtkActorCollection* theActors = aCopy.GetActors();
4744               theActors->InitTraversal();
4745               bool isFound = false;
4746               vtkActor *ac = theActors->GetNextActor();
4747               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
4748                 if (ac->IsA("SMESH_Actor")) {
4749                   SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
4750                   if (aGeomAc->hasIO()) {
4751                     Handle(SALOME_InteractiveObject) io =
4752                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
4753                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
4754                       isFound = true;
4755                       vtkActors.Bind(viewIndex, aGeomAc);
4756                     }
4757                   }
4758                 }
4759               }
4760             }
4761           }
4762         } // if (paramNameStr == "Visibility")
4763         else
4764         {
4765           // the rest properties "work" with SMESH_Actor
4766           if (aSmeshActor)
4767           {
4768             QString val ((*valuesIt).c_str());
4769
4770             // Representation
4771             if (paramNameStr == "Representation") {
4772               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
4773             }
4774             // IsShrunk
4775             else if (paramNameStr == "IsShrunk") {
4776               if (val.toInt()) {
4777                 if (!aSmeshActor->IsShrunk())
4778                   aSmeshActor->SetShrink();
4779               }
4780               else {
4781                 if (aSmeshActor->IsShrunk())
4782                   aSmeshActor->UnShrink();
4783               }
4784             }
4785             // Displayed entities
4786             else if (paramNameStr == "Entities") {
4787               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
4788               if (mode.count() == 6) {
4789                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
4790                   MESSAGE("Invalid order of data in Entities, must be: "
4791                           "e:0/1:f:0/1:v:0/1");
4792                 }
4793                 else {
4794                   unsigned int aMode = aSmeshActor->GetEntityMode();
4795                   unsigned int aNewMode =
4796                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
4797                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
4798                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
4799                   if (aNewMode != aMode)
4800                     aSmeshActor->SetEntityMode(aNewMode);
4801                 }
4802               }
4803             }
4804             // Colors
4805             else if (paramNameStr == "Colors") {
4806               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
4807               if (colors.count() == 16) {
4808                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
4809                     colors[8] != "edge"    || colors[12] != "node") {
4810                   MESSAGE("Invalid order of data in Colors, must be: "
4811                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
4812                 }
4813                 else {
4814                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
4815                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
4816                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
4817                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
4818                 }
4819               }
4820             }
4821             // Sizes of lines and points
4822             else if (paramNameStr == "Sizes") {
4823               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
4824               if (sizes.count() == 4) {
4825                 if (sizes[0] != "line" || sizes[2] != "shrink") {
4826                   MESSAGE("Invalid order of data in Sizes, must be: "
4827                           "line:int:shrink:float");
4828                 }
4829                 else {
4830                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4831                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
4832                 }
4833               }
4834               else if (sizes.count() == 6) { // just to support old format
4835                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
4836                   MESSAGE("Invalid order of data in Sizes, must be: "
4837                           "line:int:node:int:shrink:float");
4838                 }
4839                 else {
4840                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4841                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
4842                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
4843                 }
4844               }
4845             }
4846             // Point marker
4847             else if (paramNameStr == "PointMarker") {
4848               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
4849               if( data.count() >= 2 ) {
4850                 bool ok = false;
4851                 int aParam1 = data[1].toInt( &ok );
4852                 if( ok ) {
4853                   if( data[0] == "std" && data.count() == 3 ) {
4854                     int aParam2 = data[2].toInt( &ok );
4855                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
4856                   }
4857                   else if( data[0] == "custom" ) {
4858                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
4859                     if( markerIt != aMarkerMap.end() ) {
4860                       VTK::MarkerData aMarkerData = markerIt->second;
4861                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
4862                     }
4863                   }
4864                 }
4865               }
4866             }
4867             // Opacity
4868             else if (paramNameStr == "Opacity") {
4869               aSmeshActor->SetOpacity(val.toFloat());
4870             }
4871             // Clipping
4872             else if (paramNameStr.startsWith("ClippingPlane")) {
4873               cout << "$$$ ClippingPlane 1" << endl;
4874               if (paramNameStr == "ClippingPlane1" || val == "Off")
4875                 aSmeshActor->RemoveAllClippingPlanes();
4876               if (val != "Off") {
4877                 cout << "$$$ ClippingPlane 2" << endl;
4878                 QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
4879                 if (vals.count() == 4) { // format check: 4 values
4880                   cout << "$$$ ClippingPlane 3" << endl;
4881                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
4882                   double aDistance = vals[1].toFloat();
4883                   vtkFloatingPointType anAngle[2];
4884                   anAngle[0] = vals[2].toFloat();
4885                   anAngle[1] = vals[3].toFloat();
4886
4887                   QList<SUIT_ViewManager*> lst;
4888                   getApp()->viewManagers(viewerTypStr, lst);
4889                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4890                   if (viewIndex >= 0 && viewIndex < lst.count()) {
4891                     SUIT_ViewManager* vman = lst.at(viewIndex);
4892                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4893                     SMESHGUI_ClippingDlg::AddPlane(aSmeshActor, vtkView,
4894                                                    anOrientation, aDistance, anAngle);
4895                   }
4896                 }
4897               }
4898             }
4899           } // if (aSmeshActor)
4900         } // other parameters than Visibility
4901       }
4902     } // for names/parameters iterator
4903   } // for entries iterator
4904
4905   // update all VTK views
4906   QList<SUIT_ViewManager*> lst;
4907   getApp()->viewManagers(lst);
4908   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
4909     SUIT_ViewModel* vmodel = (*it)->getViewModel();
4910     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
4911       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
4912       vtkView->getRenderer()->ResetCameraClippingRange();
4913       vtkView->Repaint();
4914     }
4915   }
4916 }
4917
4918 /*!
4919   \brief Adds preferences for dfont of VTK viewer
4920   \param label label
4921   \param pIf group identifier
4922   \param param parameter
4923   \return identifier of preferences
4924 */
4925 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
4926 {
4927   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "VISU", param );
4928
4929   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
4930
4931   QStringList fam;
4932   fam.append( tr( "SMESH_FONT_ARIAL" ) );
4933   fam.append( tr( "SMESH_FONT_COURIER" ) );
4934   fam.append( tr( "SMESH_FONT_TIMES" ) );
4935
4936   setPreferenceProperty( tfont, "fonts", fam );
4937
4938   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
4939   setPreferenceProperty( tfont, "features", f );
4940
4941   return tfont;
4942 }
4943
4944 /*!
4945   \brief Actions after hypothesis edition
4946   Updates object browser after hypothesis edition
4947 */
4948 void SMESHGUI::onHypothesisEdit( int result )
4949 {
4950   if( result == 1 )
4951     SMESHGUI::Modified();
4952   updateObjBrowser( true );
4953 }