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