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