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