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