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