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