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