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