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