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