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