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