Salome HOME
PR: debug gui display
[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     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1097
1098     //  0019923: EDF 765 SMESH : default values of hypothesis
1099     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1100     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1101     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1102     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1103     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1104   }
1105
1106   myActiveDialogBox = 0;
1107   myFilterLibraryDlg = 0;
1108   myState = -1;
1109   myDisplayer = 0;
1110
1111   SMESH::GetFilterManager();
1112   SMESH::GetPattern();
1113
1114   /* load resources for all available meshers */
1115   SMESH::InitAvailableHypotheses();
1116 }
1117
1118 //=============================================================================
1119 /*!
1120  *
1121  */
1122 //=============================================================================
1123 SMESHGUI::~SMESHGUI()
1124 {
1125   SMESH::GetFilterManager()->Destroy();
1126   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1127 }
1128
1129 //=============================================================================
1130 /*!
1131  *
1132  */
1133 //=============================================================================
1134 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1135 {
1136   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1137   if( anApp )
1138     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1139   else
1140     return 0;
1141 }
1142
1143 bool SMESHGUI::automaticUpdate()
1144 {
1145   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1146   if ( !resMgr )
1147     return false;
1148
1149   return resMgr->booleanValue( "SMESH", "auto_update", false );
1150 }
1151
1152 //=============================================================================
1153 /*!
1154  *
1155  */
1156 //=============================================================================
1157 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1158 {
1159   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1160 }
1161
1162 //=============================================================================
1163 /*!
1164  *
1165  */
1166 //=============================================================================
1167 SMESHGUI* SMESHGUI::GetSMESHGUI()
1168 {
1169   SMESHGUI* smeshMod = 0;
1170   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1171   if ( app )
1172   {
1173     CAM_Module* module = app->module( "Mesh" );
1174     smeshMod = dynamic_cast<SMESHGUI*>( module );
1175   }
1176
1177   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1178   {
1179     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1180     if ( study )
1181     {
1182       _PTR(Study) aStudy = study->studyDS();
1183       if ( aStudy )
1184         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1185     }
1186   }
1187
1188   return smeshMod;
1189 }
1190
1191 extern "C"
1192 {
1193   Standard_EXPORT SMESHGUI* GetComponentGUI()
1194   {
1195     return SMESHGUI::GetSMESHGUI();
1196   }
1197 }
1198
1199 //=============================================================================
1200 /*!
1201  *
1202  */
1203 //=============================================================================
1204 void SMESHGUI::SetState(int aState)
1205 {
1206   myState = aState;
1207 }
1208
1209 //=============================================================================
1210 /*!
1211  *
1212  */
1213 //=============================================================================
1214 void SMESHGUI::ResetState()
1215 {
1216   myState = -1;
1217 }
1218
1219 //=============================================================================
1220 /*!
1221  *
1222  */
1223 //=============================================================================
1224 void SMESHGUI::EmitSignalDeactivateDialog()
1225 {
1226   emit SignalDeactivateActiveDialog();
1227 }
1228
1229 //=============================================================================
1230 /*!
1231  *
1232  */
1233 //=============================================================================
1234 void SMESHGUI::EmitSignalStudyFrameChanged()
1235 {
1236   emit SignalStudyFrameChanged();
1237 }
1238
1239 //=============================================================================
1240 /*!
1241  *
1242  */
1243 //=============================================================================
1244 void SMESHGUI::EmitSignalCloseAllDialogs()
1245 {
1246   emit SignalCloseAllDialogs();
1247 }
1248
1249 //=============================================================================
1250 /*!
1251  *
1252  */
1253 //=============================================================================
1254 void SMESHGUI::EmitSignalVisibilityChanged()
1255 {
1256   emit SignalVisibilityChanged();
1257 }
1258
1259 //=============================================================================
1260 /*!
1261  *
1262  */
1263 //=============================================================================
1264 QDialog *SMESHGUI::GetActiveDialogBox()
1265 {
1266   return myActiveDialogBox;
1267 }
1268
1269 //=============================================================================
1270 /*!
1271  *
1272  */
1273 //=============================================================================
1274 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1275 {
1276   myActiveDialogBox = (QDialog *) aDlg;
1277   return;
1278 }
1279
1280 //=============================================================================
1281 /*!
1282  *
1283  */
1284 //=============================================================================
1285 SUIT_Desktop* SMESHGUI::desktop()
1286 {
1287   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1288   if( app )
1289     return app->desktop();
1290   else
1291     return 0;
1292 }
1293
1294 //=============================================================================
1295 /*!
1296  *
1297  */
1298 //=============================================================================
1299 SalomeApp_Study* SMESHGUI::activeStudy()
1300 {
1301   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1302   if( app )
1303     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1304   else
1305     return NULL;
1306 }
1307
1308 //=============================================================================
1309 /*!
1310  *
1311  */
1312 //=============================================================================
1313 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1314 {
1315   /* Here the position is on the bottom right corner - 10 */
1316   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1317   aDlg->adjustSize();
1318   SUIT_Desktop *PP = desktop();
1319   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1320   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1321   return true;
1322 }
1323
1324 //=============================================================================
1325 /*!
1326  *
1327  */
1328 //=============================================================================
1329 static int isStudyLocked(_PTR(Study) theStudy){
1330   return theStudy->GetProperties()->IsLocked();
1331 }
1332
1333 static bool checkLock(_PTR(Study) theStudy) {
1334   if (isStudyLocked(theStudy)) {
1335     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1336                               QObject::tr("WRN_WARNING"),
1337                               QObject::tr("WRN_STUDY_LOCKED") );
1338     return true;
1339   }
1340   return false;
1341 }
1342
1343 //=======================================================================
1344 //function : CheckActiveStudyLocked
1345 //purpose  :
1346 //=======================================================================
1347
1348 bool SMESHGUI::isActiveStudyLocked()
1349 {
1350   _PTR(Study) aStudy = activeStudy()->studyDS();
1351   return checkLock( aStudy );
1352 }
1353
1354 //=============================================================================
1355 /*!
1356  *
1357  */
1358 //=============================================================================
1359 bool SMESHGUI::OnGUIEvent( int theCommandID )
1360 {
1361   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1362   if( !anApp )
1363     return false;
1364
1365   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1366   SUIT_ResourceMgr* mgr = resourceMgr();
1367   if( !mgr )
1368     return false;
1369
1370   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1371     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1372   }
1373
1374   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1375   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1376
1377   //QAction* act = action( theCommandID );
1378
1379   switch (theCommandID) {
1380   case 33:                                      // DELETE
1381     if(checkLock(aStudy)) break;
1382     OnEditDelete();
1383     break;
1384
1385   case 113:                                     // IMPORT
1386   case 112:
1387   case 111:
1388     {
1389       if(checkLock(aStudy)) break;
1390       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1391       break;
1392     }
1393
1394   case 150:    //MED FILE INFORMATION
1395     {
1396       SALOME_ListIO selected;
1397       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1398       if( aSel )
1399         aSel->selectedObjects( selected );
1400       if( selected.Extent() )
1401       {
1402         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1403         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1404         if ( !aMesh->_is_nil() )
1405         {
1406           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1407           dlg.exec();
1408         }
1409       }
1410       break;
1411     }
1412
1413   case 122:                                     // EXPORT MED
1414   case 121:
1415   case 123:
1416   case 124:
1417   case 125:
1418   case 126:
1419   case 140:
1420   case 141:
1421     {
1422       ::ExportMeshToFile(theCommandID);
1423       break;
1424     }
1425
1426   case 200:                                     // SCALAR BAR
1427     {
1428       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1429       SALOME_ListIO selected;
1430       if( aSel )
1431         aSel->selectedObjects( selected );
1432
1433       if( selected.Extent() ) {
1434         Handle(SALOME_InteractiveObject) anIO = selected.First();
1435         if( anIO->hasEntry() ) {
1436           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1437             anActor->SetControlMode( SMESH_Actor::eNone );
1438           }
1439         }
1440       }
1441       break;
1442     }
1443   case 201:
1444     {
1445       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1446       break;
1447     }
1448
1449     // Auto-color
1450   case 1136:
1451     ::AutoColor();
1452   break;
1453
1454   case 1137:
1455     ::DisableAutoColor();
1456   break;
1457
1458   case 1134: // Clipping
1459   case 1133: // Tranparency
1460   case 1132: // Colors / Size
1461
1462     // Display Mode
1463   case 215: // Nodes
1464   case 213: // Nodes
1465   case 212: // Nodes
1466   case 211: // Nodes
1467     ::SetDisplayMode(theCommandID);
1468   break;
1469
1470   //2D quadratic representation
1471   case 231:
1472   case 232:
1473     ::SetDisplayMode(theCommandID);
1474   break;
1475   
1476   // Display Entity
1477   case 216: // 0D elements
1478   case 217: // Edges
1479   case 218: // Faces
1480   case 219: // Volumes
1481   case 220: // All Entity
1482     ::SetDisplayEntity(theCommandID);
1483   break;
1484
1485   case 221: // Orientation of faces
1486     {
1487       LightApp_SelectionMgr* mgr = selectionMgr();
1488       SALOME_ListIO selected; mgr->selectedObjects( selected );
1489
1490       SALOME_ListIteratorOfListIO it(selected);
1491       for( ; it.More(); it.Next()) {
1492         Handle(SALOME_InteractiveObject) anIObject = it.Value();
1493         if(anIObject->hasEntry()) {
1494           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
1495             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
1496           }
1497         }
1498       }
1499       break;
1500     }
1501
1502   case 214:                                     // UPDATE
1503     {
1504       if(checkLock(aStudy)) break;
1505       try {
1506 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1507         OCC_CATCH_SIGNALS;
1508 #endif
1509         SMESH::UpdateView();
1510       }
1511       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1512         SMESH::OnVisuException();
1513       }
1514       catch (...) { // PAL16774 (Crash after display of many groups)
1515         SMESH::OnVisuException();
1516       }
1517
1518       SALOME_ListIO l;
1519       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1520       aSel->selectedObjects( l );
1521       aSel->setSelectedObjects( l );
1522       break;
1523     }
1524
1525   case 300:                                     // ERASE
1526   case 301:                                     // DISPLAY
1527   case 302:                                     // DISPLAY ONLY
1528     {
1529       SMESH::EDisplaing anAction;
1530       switch (theCommandID) {
1531       case 300: anAction = SMESH::eErase; break;
1532       case 301: anAction = SMESH::eDisplay; break;
1533       case 302: anAction = SMESH::eDisplayOnly; break;
1534       }
1535
1536       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1537       SALOME_ListIO sel_objects, to_process;
1538       if (aSel)
1539         aSel->selectedObjects( sel_objects );
1540
1541       if( theCommandID==302 )
1542       {
1543         MESSAGE("anAction = SMESH::eDisplayOnly");
1544         startOperation( myEraseAll );
1545       }
1546
1547       extractContainers( sel_objects, to_process );
1548
1549       try {
1550 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1551         OCC_CATCH_SIGNALS;
1552 #endif
1553         if (vtkwnd) {
1554           SALOME_ListIteratorOfListIO It( to_process );
1555           for ( ; It.More(); It.Next()) {
1556                 MESSAGE("---");
1557             Handle(SALOME_InteractiveObject) IOS = It.Value();
1558             if (IOS->hasEntry()) {
1559                 MESSAGE("---");
1560               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
1561                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
1562                 break; // PAL16774 (Crash after display of many groups)
1563               }
1564               if (anAction == SMESH::eDisplayOnly)
1565               {
1566                 MESSAGE("anAction = SMESH::eDisplayOnly");
1567                 anAction = SMESH::eDisplay;
1568               }
1569             }
1570           }
1571         }
1572
1573         // PAL13338 + PAL15161 -->
1574         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
1575                 MESSAGE("anAction = SMESH::eDisplayOnly");
1576           SMESH::UpdateView();
1577           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
1578         }
1579         // PAL13338 + PAL15161 <--
1580       }
1581       catch (...) { // PAL16774 (Crash after display of many groups)
1582         SMESH::OnVisuException();
1583       }
1584
1585       if (anAction == SMESH::eErase) {
1586         MESSAGE("anAction == SMESH::eErase");
1587         SALOME_ListIO l1;
1588         aSel->setSelectedObjects( l1 );
1589       }
1590       else
1591         aSel->setSelectedObjects( to_process );
1592       
1593       break;
1594     }
1595
1596   case 4000:                                    // NODES
1597     {
1598       if(checkLock(aStudy)) break;
1599
1600       if ( vtkwnd ) {
1601         EmitSignalDeactivateDialog();
1602
1603         ( new SMESHGUI_NodesDlg( this ) )->show();
1604       }
1605       else {
1606         SUIT_MessageBox::warning(desktop(),
1607                                  tr("SMESH_WRN_WARNING"),
1608                                  tr("SMESH_WRN_VIEWER_VTK"));
1609       }
1610       break;
1611     }
1612
1613   case 2151:  // FILTER
1614   {
1615     if ( vtkwnd )
1616     {
1617       EmitSignalDeactivateDialog();
1618       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
1619     }
1620     break;
1621   }
1622
1623   case 406:                                     // MOVE NODE
1624     {
1625       if ( !vtkwnd )
1626       {
1627         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1628                                   tr( "NOT_A_VTK_VIEWER" ) );
1629         break;
1630       }
1631
1632       if(checkLock(aStudy)) break;
1633       ( new SMESHGUI_MoveNodesDlg( this ) )->show();
1634       break;
1635     }
1636
1637   case 701:                                     // COMPUTE MESH
1638   case 711:                                     // PRECOMPUTE MESH
1639   case 712:                                     // EVALUATE MESH
1640     {
1641       if (checkLock(aStudy)) break;
1642       startOperation( theCommandID );
1643     }
1644     break;
1645
1646   case 702: // Create mesh
1647   case 703: // Create sub-mesh
1648   case 704: // Edit mesh/sub-mesh
1649     startOperation( theCommandID );
1650     break;
1651   case 710: // Build compound mesh
1652     {
1653       if (checkLock(aStudy)) break;
1654       EmitSignalDeactivateDialog();
1655       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
1656     }
1657     break;
1658
1659   case 407: // DIAGONAL INVERSION
1660   case 408: // Delete diagonal
1661     {
1662       if ( !vtkwnd )
1663       {
1664         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1665                                   tr( "NOT_A_VTK_VIEWER" ) );
1666         break;
1667       }
1668
1669       if ( checkLock( aStudy ) )
1670         break;
1671
1672       /*Standard_Boolean aRes;
1673       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1674       if ( aMesh->_is_nil() )
1675       {
1676         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1677           tr( "SMESH_BAD_SELECTION" ) );
1678         break;
1679       }
1680       */
1681       EmitSignalDeactivateDialog();
1682       if ( theCommandID == 407 )
1683         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
1684       else
1685         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
1686       break;
1687     }
1688     case 409: // Change orientation
1689     case 410: // Union of triangles
1690     case 411: // Cutting of quadrangles
1691     {
1692       if ( !vtkwnd )
1693       {
1694         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1695                                   tr( "NOT_A_VTK_VIEWER" ) );
1696         break;
1697       }
1698
1699       if ( checkLock( aStudy ) )
1700         break;
1701
1702       EmitSignalDeactivateDialog();
1703       SMESHGUI_MultiEditDlg* aDlg = NULL;
1704       if ( theCommandID == 409 )
1705         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1706       else if ( theCommandID == 410 )
1707         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1708       else
1709         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1710
1711       aDlg->show();
1712       break;
1713     }
1714   case 412: // Smoothing
1715     {
1716       if(checkLock(aStudy)) break;
1717       if( vtkwnd ) {
1718         EmitSignalDeactivateDialog();
1719         ( new SMESHGUI_SmoothingDlg( 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 413: // Extrusion
1728     {
1729       if (checkLock(aStudy)) break;
1730       if (vtkwnd) {
1731         EmitSignalDeactivateDialog();
1732         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
1733       } else {
1734         SUIT_MessageBox::warning(desktop(),
1735                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1736       }
1737       break;
1738     }
1739   case 414: // Revolution
1740     {
1741       if(checkLock(aStudy)) break;
1742       if( vtkwnd ) {
1743         EmitSignalDeactivateDialog();
1744         ( new SMESHGUI_RevolutionDlg( this ) )->show();
1745       }
1746       else {
1747         SUIT_MessageBox::warning(desktop(),
1748                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1749       }
1750       break;
1751     }
1752   case 415: // Pattern mapping
1753     {
1754       if ( checkLock( aStudy ) )
1755         break;
1756       if ( vtkwnd )
1757       {
1758         EmitSignalDeactivateDialog();
1759         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
1760       }
1761       else {
1762         SUIT_MessageBox::warning(desktop(),
1763                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1764       }
1765       break;
1766     }
1767   case 416: // Extrusion along a path
1768     {
1769       if (checkLock(aStudy)) break;
1770       if (vtkwnd) {
1771         EmitSignalDeactivateDialog();
1772         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
1773       } else {
1774         SUIT_MessageBox::warning(desktop(),
1775                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1776       }
1777       break;
1778     }
1779   case 417: // Convert mesh to quadratic
1780     {
1781     startOperation( 417 );
1782       /*      if (checkLock(aStudy)) break;
1783       if (vtkwnd) {
1784         EmitSignalDeactivateDialog();
1785         new SMESHGUI_ConvToQuadDlg();
1786       } else {
1787         SUIT_MessageBox::warning(desktop(),
1788                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1789                                }*/
1790       break;
1791     }
1792   case 418: // create 2D mesh from 3D
1793     {
1794       startOperation( 418 );
1795       break;
1796     }
1797   case 806:                                     // CREATE GEO GROUP
1798     {
1799       startOperation( 806 );
1800       break;
1801     }
1802   case 801:                                     // CREATE GROUP
1803     {
1804       if ( !vtkwnd )
1805       {
1806         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1807                                   tr( "NOT_A_VTK_VIEWER" ) );
1808         break;
1809       }
1810
1811       if(checkLock(aStudy)) break;
1812       EmitSignalDeactivateDialog();
1813       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1814
1815       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1816       SALOME_ListIO selected;
1817       if( aSel )
1818         aSel->selectedObjects( selected );
1819
1820       int nbSel = selected.Extent();
1821       if (nbSel == 1) {
1822         // check if mesh is selected
1823         aMesh = SMESH::GetMeshByIO( selected.First() );
1824       }
1825       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
1826       aDlg->show();
1827       break;
1828     }
1829
1830   case 802:                                     // CONSTRUCT GROUP
1831     {
1832       if ( !vtkwnd )
1833       {
1834         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1835                                   tr( "NOT_A_VTK_VIEWER" ) );
1836         break;
1837       }
1838
1839       if(checkLock(aStudy)) break;
1840       EmitSignalDeactivateDialog();
1841
1842       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1843       SALOME_ListIO selected;
1844       if( aSel )
1845         aSel->selectedObjects( selected );
1846
1847       int nbSel = selected.Extent();
1848       if (nbSel == 1) {
1849         // check if submesh is selected
1850         Handle(SALOME_InteractiveObject) IObject = selected.First();
1851         if (IObject->hasEntry()) {
1852           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1853           if( aSObj ) {
1854             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1855             if (!aSubMesh->_is_nil()) {
1856               try {
1857                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1858                 // get submesh elements list by types
1859                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1860                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1861                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1862                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1863                 // create group for each type o elements
1864                 QString aName = IObject->getName();
1865                 if (aNodes->length() > 0) {
1866                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1867                   aGroup->Add(aNodes.inout());
1868                 }
1869                 if (aEdges->length() > 0) {
1870                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1871                   aGroup->Add(aEdges.inout());
1872                 }
1873                 if (aFaces->length() > 0) {
1874                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1875                   aGroup->Add(aFaces.inout());
1876                 }
1877                 if (aVolumes->length() > 0) {
1878                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1879                   aGroup->Add(aVolumes.inout());
1880                 }
1881                 updateObjBrowser();
1882
1883               }
1884               catch(const SALOME::SALOME_Exception & S_ex){
1885                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1886               }
1887             }
1888           }
1889         }
1890       }
1891       else if(nbSel==0) {
1892         SUIT_MessageBox::warning(desktop(),
1893                                  tr("SMESH_WRN_WARNING"),
1894                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
1895       }
1896       break;
1897     }
1898
1899   case 803:                                     // EDIT GROUP
1900     {
1901       if ( !vtkwnd )
1902       {
1903         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1904                                   tr( "NOT_A_VTK_VIEWER" ) );
1905         break;
1906       }
1907
1908       if(checkLock(aStudy)) break;
1909       EmitSignalDeactivateDialog();
1910
1911       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1912       SALOME_ListIO selected;
1913       if( aSel )
1914         aSel->selectedObjects( selected );
1915
1916       SALOME_ListIteratorOfListIO It (selected);
1917       int nbSelectedGroups = 0;
1918       for ( ; It.More(); It.Next() )
1919       {
1920         SMESH::SMESH_GroupBase_var aGroup =
1921           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1922         if (!aGroup->_is_nil()) {
1923           nbSelectedGroups++;
1924           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
1925           aDlg->show();
1926         }
1927       }
1928       if (nbSelectedGroups == 0)
1929         {
1930           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
1931           aDlg->show();
1932         }
1933       break;
1934     }
1935
1936   case 804:                                     // Add elements to group
1937     {
1938       if(checkLock(aStudy)) break;
1939       if (myState == 800) {
1940         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1941         if (aDlg) aDlg->onAdd();
1942       }
1943       break;
1944     }
1945
1946   case 805:                                     // Remove elements from group
1947     {
1948       if(checkLock(aStudy)) break;
1949       if (myState == 800) {
1950         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1951         if (aDlg) aDlg->onRemove();
1952       }
1953       break;
1954     }
1955
1956   case 815:                                     // Edit GEOM GROUP as standalone
1957     {
1958       if ( !vtkwnd )
1959       {
1960         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1961                                   tr( "NOT_A_VTK_VIEWER" ) );
1962         break;
1963       }
1964
1965       if(checkLock(aStudy)) break;
1966       EmitSignalDeactivateDialog();
1967
1968       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1969       SALOME_ListIO selected;
1970       if( aSel )
1971         aSel->selectedObjects( selected );
1972
1973       SALOME_ListIteratorOfListIO It (selected);
1974       for ( ; It.More(); It.Next() )
1975       {
1976         SMESH::SMESH_GroupOnGeom_var aGroup =
1977           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
1978         if (!aGroup->_is_nil()) {
1979           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
1980           aDlg->show();
1981         }
1982       }
1983       break;
1984     }
1985
1986     case 810: // Union Groups
1987     case 811: // Intersect groups
1988     case 812: // Cut groups
1989     {
1990       if ( !vtkwnd )
1991       {
1992         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1993                                   tr( "NOT_A_VTK_VIEWER" ) );
1994         break;
1995       }
1996
1997       if ( checkLock( aStudy ) )
1998         break;
1999
2000       EmitSignalDeactivateDialog();
2001
2002       SMESHGUI_GroupOpDlg* aDlg = 0;
2003       if ( theCommandID == 810 )
2004         aDlg = new SMESHGUI_UnionGroupsDlg( this );
2005       else if ( theCommandID == 811 )
2006         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
2007       else
2008         aDlg = new SMESHGUI_CutGroupsDlg( this );
2009
2010       aDlg->show();
2011
2012       break;
2013     }
2014
2015     case 814: // Create groups of entities from existing groups of superior dimensions
2016     {
2017       if ( checkLock( aStudy ) )
2018         break;
2019
2020       EmitSignalDeactivateDialog();
2021       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
2022       aDlg->show();
2023
2024       break;
2025     }
2026
2027     case 813: // Delete groups with their contents
2028     {
2029       if ( !vtkwnd )
2030       {
2031         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2032                                   tr( "NOT_A_VTK_VIEWER" ) );
2033         break;
2034       }
2035
2036       if ( checkLock( aStudy ) )
2037         break;
2038
2039       EmitSignalDeactivateDialog();
2040
2041       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
2042       break;
2043     }
2044
2045   case 900:                                     // MESH INFOS
2046     {
2047       EmitSignalDeactivateDialog();
2048       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2049       SALOME_ListIO selected;
2050       if( aSel )
2051         aSel->selectedObjects( selected );
2052
2053       if ( selected.Extent() > 1 ) { // a dlg for each IO
2054         SALOME_ListIO IOs;
2055         SALOME_ListIteratorOfListIO It (selected);
2056         for ( ; It.More(); It.Next() ) {
2057           IOs.Clear(); IOs.Append( It.Value() );
2058           aSel->setSelectedObjects( IOs );
2059           ( new SMESHGUI_MeshInfosDlg( this ) )->show();
2060         }
2061         // restore selection
2062         aSel->setSelectedObjects( selected );
2063       }
2064       else
2065         ( new SMESHGUI_MeshInfosDlg( this ) )->show();
2066       break;
2067     }
2068
2069   case 902:                                     // STANDARD MESH INFOS
2070     {
2071       EmitSignalDeactivateDialog();
2072       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2073       SALOME_ListIO selected;
2074       if( aSel )
2075         aSel->selectedObjects( selected );
2076
2077       if ( selected.Extent() > 1 ) { // a dlg for each IO
2078         SALOME_ListIO IOs;
2079         SALOME_ListIteratorOfListIO It (selected);
2080         for ( ; It.More(); It.Next() ) {
2081           IOs.Clear();
2082           IOs.Append( It.Value() );
2083           aSel->setSelectedObjects( IOs );
2084           ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2085         }
2086         // restore selection
2087         aSel->setSelectedObjects( selected );
2088       }
2089       else
2090         ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2091       break;
2092     }
2093
2094   case 903:                                     // WHAT IS
2095     {
2096       EmitSignalDeactivateDialog();
2097       ( new SMESHGUI_WhatIsDlg( this ) )->show();
2098       break;
2099     }
2100
2101   case 1100:                                    // EDIT HYPOTHESIS
2102     {
2103       if(checkLock(aStudy)) break;
2104
2105       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2106       SALOME_ListIO selected;
2107       if( aSel )
2108         aSel->selectedObjects( selected );
2109
2110       int nbSel = selected.Extent();
2111
2112       if (nbSel == 1) {
2113         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2114         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2115
2116         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2117         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2118         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2119         if ( !aHypothesis->_is_nil() )
2120         {
2121           // BUG 0020378
2122           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2123           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2124           if (aCreator) {
2125             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
2126           }
2127           else
2128           {
2129             // report error
2130           }
2131         }
2132       }
2133       break;
2134     }
2135
2136   case 1101:                                    // RENAME
2137     {
2138       if ( checkLock( aStudy ) )
2139         break;
2140
2141       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2142       SALOME_ListIO selected;
2143       if( aSel )
2144         aSel->selectedObjects( selected );
2145
2146       bool isAny = false; // is there any appropriate object selected
2147
2148       SALOME_ListIteratorOfListIO It( selected );
2149       for ( ; It.More(); It.Next() )
2150       {
2151         Handle(SALOME_InteractiveObject) IObject = It.Value();
2152         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2153         _PTR(GenericAttribute) anAttr;
2154         _PTR(AttributeName) aName;
2155         if ( obj )
2156         {
2157           if ( obj->FindAttribute(anAttr, "AttributeName") )
2158           {
2159             aName = anAttr;
2160             QString newName = QString(aName->Value().c_str());
2161
2162             // check type to prevent renaming of inappropriate objects
2163             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2164             if (aType == MESH || aType == GROUP ||
2165                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2166                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2167                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2168                 aType == HYPOTHESIS || aType == ALGORITHM)
2169             {
2170               isAny = true;
2171               newName = LightApp_NameDlg::getName(desktop(), newName);
2172               if ( !newName.isEmpty() )
2173               {
2174                 SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), newName.toLatin1().data());
2175
2176                 // update name of group object and its actor
2177                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2178                 if( !aGroupObject->_is_nil() )
2179                 {
2180                   aGroupObject->SetName( newName.toLatin1().data() );
2181                   if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( IObject->getEntry() ) )
2182                     anActor->setName( newName.toLatin1().data() );
2183                 }
2184
2185                 updateObjBrowser();
2186               }
2187             }
2188           }
2189         }
2190       } // for
2191
2192       if (!isAny) {
2193         SUIT_MessageBox::warning(desktop(),
2194                                  QObject::tr("SMESH_WRN_WARNING"),
2195                                  QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"));
2196       }
2197       break;
2198     }
2199
2200   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2201     {
2202       if(checkLock(aStudy)) break;
2203       SUIT_OverrideCursor wc;
2204
2205       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2206       SALOME_ListIO selected;
2207       if( aSel )
2208         aSel->selectedObjects( selected, QString::null, false );
2209
2210       SALOME_ListIteratorOfListIO It(selected);
2211       for (int i = 0; It.More(); It.Next(), i++) {
2212         Handle(SALOME_InteractiveObject) IObject = It.Value();
2213         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2214       }
2215       SALOME_ListIO l1;
2216       aSel->setSelectedObjects( l1 );
2217       updateObjBrowser();
2218       break;
2219     }
2220
2221   case 4009:                                    // ELEM0D
2222   case 4010:                                    // GEOM::EDGE
2223   case 4021:                                    // TRIANGLE
2224   case 4022:                                    // QUAD
2225   case 4023:                                    // POLYGON
2226   case 4031:                                    // TETRA
2227   case 4032:                                    // HEXA
2228     {
2229       if(checkLock(aStudy)) break;
2230       if ( vtkwnd ) {
2231         EmitSignalDeactivateDialog();
2232         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2233         int                 nbNodes = 2;
2234         switch (theCommandID) {
2235         case 4009:                                      // ELEM0D
2236           type = SMDSAbs_0DElement; nbNodes = 1; break;
2237         case 4021:                                      // TRIANGLE
2238           type = SMDSAbs_Face; nbNodes = 3; break;
2239         case 4022:                                      // QUAD
2240           type = SMDSAbs_Face; nbNodes = 4; break;
2241         case 4031:                                      // TETRA
2242           type = SMDSAbs_Volume; nbNodes = 4; break;
2243         case 4023:                                      // POLYGON
2244           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2245         case 4032:                                      // HEXA
2246           type = SMDSAbs_Volume; nbNodes = 8; break;
2247         case 4033:                                      // POLYHEDRE
2248           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2249         default:;
2250         }
2251         ( new SMESHGUI_AddMeshElementDlg( this, type, nbNodes ) )->show();
2252       }
2253       else {
2254         SUIT_MessageBox::warning(desktop(),
2255                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2256       }
2257       break;
2258     }
2259   case 4033:                                    // POLYHEDRON
2260     {
2261       if(checkLock(aStudy)) break;
2262       if ( vtkwnd ) {
2263         EmitSignalDeactivateDialog();
2264         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2265       }
2266       else {
2267         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2268                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2269       }
2270       break;
2271     }
2272   case 4034:     // QUADRATIC EDGE
2273   case 4035:     // QUADRATIC TRIANGLE
2274   case 4036:     // QUADRATIC QUADRANGLE
2275   case 4037:     // QUADRATIC TETRAHEDRON
2276   case 4038:     // QUADRATIC PYRAMID
2277   case 4039:     // QUADRATIC PENTAHEDRON
2278   case 4040:     // QUADRATIC HEXAHEDRON
2279     {
2280       if(checkLock(aStudy)) break;
2281       if ( vtkwnd ) {
2282         EmitSignalDeactivateDialog();
2283         int type;
2284
2285         switch (theCommandID) {
2286         case 4034:
2287           type = QUAD_EDGE; break;
2288         case 4035:
2289           type = QUAD_TRIANGLE; break;
2290         case 4036:
2291           type = QUAD_QUADRANGLE; break;
2292         case 4037:
2293           type = QUAD_TETRAHEDRON; break;
2294         case 4038:
2295           type = QUAD_PYRAMID; break;
2296         case 4039:
2297           type = QUAD_PENTAHEDRON; break;
2298         case 4040:
2299           type = QUAD_HEXAHEDRON;
2300           break;
2301         default:;
2302         }
2303          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
2304       }
2305       else {
2306         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2307                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2308       }
2309       break;
2310     }
2311   case 4041:                                    // REMOVES NODES
2312     {
2313       if(checkLock(aStudy)) break;
2314       if ( vtkwnd ) {
2315         EmitSignalDeactivateDialog();
2316         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
2317       }
2318       else {
2319         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2320                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2321       }
2322       break;
2323     }
2324   case 4042:                                    // REMOVES ELEMENTS
2325     {
2326       if(checkLock(aStudy)) break;
2327       if( vtkwnd ) {
2328         EmitSignalDeactivateDialog();
2329         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
2330       }
2331       else
2332         {
2333           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2334                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2335         }
2336       break;
2337     }
2338   case 4043: {                                // CLEAR_MESH
2339
2340     if(checkLock(aStudy)) break;
2341
2342     SALOME_ListIO selected;
2343     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2344       aSel->selectedObjects( selected );
2345
2346     SUIT_OverrideCursor wc;
2347     SALOME_ListIteratorOfListIO It (selected);
2348     for ( ; It.More(); It.Next() )
2349     {
2350       Handle(SALOME_InteractiveObject) IOS = It.Value();
2351       SMESH::SMESH_Mesh_var aMesh =
2352         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2353       if ( aMesh->_is_nil()) continue;
2354       try {
2355         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2356         aMesh->Clear();
2357         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2358         SMESH::ModifiedMesh( aMeshSObj, false, true);
2359         // hide groups and submeshes
2360         _PTR(ChildIterator) anIter =
2361           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2362         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2363         {
2364           _PTR(SObject) so = anIter->Value();
2365           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2366         }
2367       }
2368       catch (const SALOME::SALOME_Exception& S_ex){
2369         wc.suspend();
2370         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2371         wc.resume();
2372       }
2373     }
2374     SMESH::UpdateView();
2375     updateObjBrowser();
2376     break;
2377   }
2378   case 4051:                                    // RENUMBERING NODES
2379     {
2380       if(checkLock(aStudy)) break;
2381       if( vtkwnd ) {
2382         EmitSignalDeactivateDialog();
2383         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
2384       }
2385       else
2386         {
2387           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2388                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2389         }
2390       break;
2391     }
2392   case 4052:                                    // RENUMBERING ELEMENTS
2393     {
2394       if(checkLock(aStudy)) break;
2395       if ( vtkwnd ) {
2396         EmitSignalDeactivateDialog();
2397         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
2398       }
2399       else
2400         {
2401           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2402                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2403         }
2404       break;
2405     }
2406   case 4061:                                   // TRANSLATION
2407     {
2408       if(checkLock(aStudy)) break;
2409       if ( vtkwnd ) {
2410         EmitSignalDeactivateDialog();
2411         ( new SMESHGUI_TranslationDlg( this ) )->show();
2412       }
2413       else {
2414         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2415                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2416       }
2417       break;
2418     }
2419   case 4062:                                   // ROTATION
2420     {
2421       if(checkLock(aStudy)) break;
2422       if( vtkwnd ) {
2423         EmitSignalDeactivateDialog();
2424         ( new SMESHGUI_RotationDlg( this ) )->show();
2425       }
2426       else {
2427         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2428                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2429       }
2430       break;
2431     }
2432   case 4063:                                   // SYMMETRY
2433     {
2434       if(checkLock(aStudy)) break;
2435       if(vtkwnd) {
2436         EmitSignalDeactivateDialog();
2437         ( new SMESHGUI_SymmetryDlg( this ) )->show();
2438       }
2439       else {
2440         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2441                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2442       }
2443       break;
2444     }
2445   case 4064:                                   // SEWING
2446     {
2447       if(checkLock(aStudy)) break;
2448       if(vtkwnd) {
2449         EmitSignalDeactivateDialog();
2450         ( new SMESHGUI_SewingDlg( this ) )->show();
2451       }
2452       else {
2453         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2454                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2455       }
2456       break;
2457     }
2458   case 4065:                                   // MERGE NODES
2459     {
2460       if(checkLock(aStudy)) break;
2461       if(vtkwnd) {
2462         EmitSignalDeactivateDialog();
2463         ( new SMESHGUI_EditMeshDlg( this, 0 ) )->show();
2464       }
2465       else {
2466         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2467                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2468       }
2469       break;
2470     }
2471   case 4066:                                   // MERGE EQUAL ELEMENTS
2472     {
2473       if (checkLock(aStudy)) break;
2474       if (vtkwnd) {
2475         EmitSignalDeactivateDialog();
2476         ( new SMESHGUI_EditMeshDlg( this, 1 ) )->show();
2477       } else {
2478         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2479                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2480       }
2481       break;
2482     }
2483
2484   case 4067: // MAKE MESH PASS THROUGH POINT
2485     startOperation( 4067 );
2486     break;
2487
2488   case 5105: // Library of selection filters
2489   {
2490     static QList<int> aTypes;
2491     if ( aTypes.isEmpty() )
2492     {
2493       aTypes.append( SMESH::NODE );
2494       aTypes.append( SMESH::EDGE );
2495       aTypes.append( SMESH::FACE );
2496       aTypes.append( SMESH::VOLUME );
2497     }
2498     if (!myFilterLibraryDlg)
2499       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2500     else if (myFilterLibraryDlg->isHidden())
2501       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2502     myFilterLibraryDlg->raise();
2503   }
2504   break;
2505
2506   case 6017:                                    // CONTROLS
2507   case 6016:
2508   case 6015:
2509   case 6014:
2510   case 6013:
2511   case 6012:
2512   case 6011:
2513   case 6001:
2514   case 6018:
2515   case 6019:
2516   case 6002:
2517   case 6003:
2518   case 6004:
2519   case 6005:
2520   case 6009:
2521   case 6021:
2522     if ( vtkwnd ) {
2523
2524       LightApp_SelectionMgr* mgr = selectionMgr();
2525       SALOME_ListIO selected; mgr->selectedObjects( selected );
2526
2527       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2528         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2529         if ( SO ) {
2530           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2531           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2532           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2533           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2534           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2535             ::Control( theCommandID );
2536             break;
2537           }
2538         }
2539       }
2540       SUIT_MessageBox::warning(desktop(),
2541                                tr( "SMESH_WRN_WARNING" ),
2542                                tr( "SMESH_BAD_SELECTION" ) );
2543       break;
2544     }
2545     else {
2546       SUIT_MessageBox::warning(desktop(),
2547                                tr( "SMESH_WRN_WARNING" ),
2548                                tr( "NOT_A_VTK_VIEWER" ) );
2549     }
2550     break;
2551   case 9010:
2552     {
2553       LightApp_SelectionMgr* mgr = selectionMgr();
2554       SALOME_ListIO selected; mgr->selectedObjects( selected );
2555
2556       SALOME_ListIteratorOfListIO it(selected);
2557       for( ; it.More(); it.Next()) {
2558         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2559         if(anIObject->hasEntry()) {
2560           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2561             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2562           }
2563         }
2564       }
2565       break;
2566     }
2567   case 9011:
2568     {
2569       LightApp_SelectionMgr* mgr = selectionMgr();
2570       SALOME_ListIO selected; mgr->selectedObjects( selected );
2571
2572       if (selected.Extent() == 1)       {
2573         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2574         if(anIObject->hasEntry())
2575           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2576             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2577           }
2578       }
2579       break;
2580     }
2581   }
2582
2583   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2584   //updateObjBrowser();
2585   return true;
2586 }
2587
2588 //=============================================================================
2589 /*!
2590  *
2591  */
2592 //=============================================================================
2593 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2594 {
2595   return false;
2596 }
2597
2598 //=============================================================================
2599 /*!
2600  *
2601  */
2602 //=============================================================================
2603 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2604 {
2605   return true;
2606 }
2607
2608 //=============================================================================
2609 /*!
2610  *
2611  */
2612 //=============================================================================
2613 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2614 {
2615   return true;
2616 }
2617
2618 //=============================================================================
2619 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2620  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2621  */
2622 //=============================================================================
2623 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2624                                   SUIT_ViewWindow* wnd )
2625 {
2626   if(theIO->hasEntry()){
2627     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2628     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2629   }
2630 }
2631
2632 //=======================================================================
2633 // function : createSMESHAction
2634 // purpose  :
2635 //=======================================================================
2636 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2637 {
2638   QIcon icon;
2639   QWidget* parent = application()->desktop();
2640   SUIT_ResourceMgr* resMgr = resourceMgr();
2641   QPixmap pix;
2642   if ( !icon_id.isEmpty() )
2643     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
2644   else
2645     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
2646   if ( !pix.isNull() )
2647     icon = QIcon( pix );
2648
2649   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
2650           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
2651           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
2652
2653   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2654 }
2655
2656 //=======================================================================
2657 // function : createPopupItem
2658 // purpose  :
2659 //=======================================================================
2660 void SMESHGUI::createPopupItem( const int id,
2661                                 const QString& clients,
2662                                 const QString& types,
2663                                 const QString& theRule,
2664                                 const int pId )
2665 {
2666   int parentId = pId;
2667   if( pId!=-1 )
2668     parentId = popupMgr()->actionId( action( pId ) );
2669
2670   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2671     popupMgr()->insert( action( id ), parentId, 0 );
2672
2673   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
2674   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
2675   QString rule = "(%1) and (%2) and (%3)";
2676   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
2677   if( clients.isEmpty() )
2678     rule = rule.arg( QString( "true" ) );
2679   else
2680     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2681   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2682   rule += theRule;
2683
2684   bool cont = myRules.contains( id );
2685   if( cont )
2686     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2687
2688   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
2689   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2690 }
2691
2692 //=======================================================================
2693 // function : initialize
2694 // purpose  :
2695 //=======================================================================
2696 void SMESHGUI::initialize( CAM_Application* app )
2697 {
2698   SalomeApp_Module::initialize( app );
2699
2700 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2701 //   if ( mgr )
2702   /* Automatic Update flag */
2703 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2704
2705   // ----- create actions --------------
2706
2707   createSMESHAction(  111, "DAT", "", (Qt::CTRL+Qt::Key_B) );
2708   createSMESHAction(  112, "UNV", "", (Qt::CTRL+Qt::Key_U) );
2709   createSMESHAction(  113, "MED", "", (Qt::CTRL+Qt::Key_M) );
2710   createSMESHAction(  114, "NUM" );
2711   createSMESHAction(  121, "DAT" );
2712   createSMESHAction(  122, "MED" );
2713   createSMESHAction(  123, "UNV" );
2714   createSMESHAction(  140, "STL" );
2715   createSMESHAction(  124, "EXPORT_DAT" );
2716   createSMESHAction(  125, "EXPORT_MED" );
2717   createSMESHAction(  126, "EXPORT_UNV" );
2718   createSMESHAction(  141, "EXPORT_STL" );
2719   createSMESHAction(  150, "FILE_INFO" );
2720   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
2721   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2722   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2723   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2724   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2725   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2726   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2727   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
2728   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
2729   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
2730   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
2731   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2732   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2733   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
2734   createSMESHAction(  804, "ADD" );
2735   createSMESHAction(  805, "REMOVE" );
2736   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2737   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2738   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2739   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
2740   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2741   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2742   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2743   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2744   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
2745   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
2746   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
2747   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
2748   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
2749   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
2750   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
2751   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
2752   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
2753   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
2754   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
2755   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2756   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2757   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2758   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2759   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2760   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
2761   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
2762   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
2763   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2764   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2765   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2766   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2767   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2768   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2769   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2770   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2771   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2772   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2773   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2774   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2775   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2776   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2777   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2778   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2779   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2780   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2781   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2782   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2783   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2784   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2785   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2786   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2787   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2788   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2789   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2790   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2791   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2792   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
2793   createSMESHAction(  200, "RESET" );
2794   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2795   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2796   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2797   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2798   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2799   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2800   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
2801   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2802   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2803   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2804   createSMESHAction(  220, "ALL" );
2805   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
2806
2807   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
2808   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
2809
2810   createSMESHAction( 1100, "EDIT_HYPO" );
2811   createSMESHAction( 1101, "RENAME", "", Qt::Key_F2 );
2812   createSMESHAction( 1102, "UNASSIGN" );
2813   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2814   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2815   createSMESHAction( 1131, "DISPMODE" );
2816   createSMESHAction( 1132, "COLORS" );
2817   createSMESHAction( 1133, "TRANSP" );
2818   createSMESHAction( 1134, "CLIP" );
2819   createSMESHAction( 1135, "DISP_ENT" );
2820   createSMESHAction( 1136, "AUTO_COLOR" );
2821   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2822   createSMESHAction( 2000, "CTRL" );
2823
2824   createSMESHAction( 300, "ERASE" );
2825   createSMESHAction( 301, "DISPLAY" );
2826   createSMESHAction( 302, "DISPLAY_ONLY" );
2827   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2828   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2829   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2830   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2831   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2832   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2833   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2834   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2835
2836   // ----- create menu --------------
2837   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2838       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2839       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2840       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2841       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2842       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2843       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2844
2845   createMenu( separator(), fileId );
2846
2847   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
2848       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
2849       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2850       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2851       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2852       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2853
2854   createMenu( 111, importId, -1 );
2855   createMenu( 112, importId, -1 );
2856   createMenu( 113, importId, -1 );
2857
2858   createMenu( 121, exportId, -1 );
2859   createMenu( 122, exportId, -1 );
2860   createMenu( 123, exportId, -1 );
2861   createMenu( 140, exportId, -1 ); // export to stl STL
2862
2863   createMenu( separator(), fileId, 10 );
2864
2865   createMenu( 33, editId, -1 );
2866
2867   createMenu( 5105, toolsId, -1 );
2868
2869   createMenu( 702, meshId, -1 ); // "Mesh" menu
2870   createMenu( 703, meshId, -1 );
2871   createMenu( 704, meshId, -1 );
2872   createMenu( 710, meshId, -1 );
2873   createMenu( separator(), meshId, -1 );
2874   createMenu( 701, meshId, -1 );
2875   createMenu( 711, meshId, -1 );
2876   createMenu( 712, meshId, -1 );
2877   createMenu( separator(), meshId, -1 );
2878   createMenu( 801, meshId, -1 );
2879   createMenu( 806, meshId, -1 );
2880   createMenu( 802, meshId, -1 );
2881   createMenu( 803, meshId, -1 );
2882   createMenu( 815, meshId, -1 );
2883   createMenu( separator(), meshId, -1 );
2884   createMenu( 810, meshId, -1 );
2885   createMenu( 811, meshId, -1 );
2886   createMenu( 812, meshId, -1 );
2887   createMenu( separator(), meshId, -1 );
2888   createMenu( 814, meshId, -1 );
2889   createMenu( separator(), meshId, -1 );
2890   createMenu( 813, meshId, -1 );
2891   createMenu( separator(), meshId, -1 );
2892   createMenu( 900, meshId, -1 );
2893   createMenu( 902, meshId, -1 );
2894   createMenu( 903, meshId, -1 );
2895   createMenu( separator(), meshId, -1 );
2896
2897   createMenu( 6003, ctrlId, -1 );
2898   createMenu( 6001, ctrlId, -1 );
2899   createMenu( 6004, ctrlId, -1 );
2900   createMenu( separator(), ctrlId, -1 );
2901   createMenu( 6005, ctrlId, -1 );
2902   createMenu( 6002, ctrlId, -1 );
2903   createMenu( 6018, ctrlId, -1 );
2904   createMenu( 6019, ctrlId, -1 );
2905   createMenu( 6011, ctrlId, -1 );
2906   createMenu( 6012, ctrlId, -1 );
2907   createMenu( 6013, ctrlId, -1 );
2908   createMenu( 6014, ctrlId, -1 );
2909   createMenu( 6015, ctrlId, -1 );
2910   createMenu( 6016, ctrlId, -1 );
2911   createMenu( separator(), ctrlId, -1 );
2912   createMenu( 6017, ctrlId, -1 );
2913   createMenu( 6009, ctrlId, -1 );
2914   createMenu( 6021, ctrlId, -1 );
2915   createMenu( separator(), ctrlId, -1 );
2916
2917   createMenu( 4000, addId, -1 );
2918   createMenu( 4009, addId, -1 );
2919   createMenu( 4010, addId, -1 );
2920   createMenu( 4021, addId, -1 );
2921   createMenu( 4022, addId, -1 );
2922   createMenu( 4023, addId, -1 );
2923   createMenu( 4031, addId, -1 );
2924   createMenu( 4032, addId, -1 );
2925   createMenu( 4033, addId, -1 );
2926   createMenu( separator(), addId, -1 );
2927   createMenu( 4034, addId, -1 );
2928   createMenu( 4035, addId, -1 );
2929   createMenu( 4036, addId, -1 );
2930   createMenu( 4037, addId, -1 );
2931   createMenu( 4038, addId, -1 );
2932   createMenu( 4039, addId, -1 );
2933   createMenu( 4040, addId, -1 );
2934
2935   createMenu( 4041, removeId, -1 );
2936   createMenu( 4042, removeId, -1 );
2937   createMenu( 4043, removeId, -1 );
2938
2939   createMenu( 4051, renumId, -1 );
2940   createMenu( 4052, renumId, -1 );
2941
2942   createMenu( 4061, transfId, -1 );
2943   createMenu( 4062, transfId, -1 );
2944   createMenu( 4063, transfId, -1 );
2945   createMenu( 4064, transfId, -1 );
2946   createMenu( 4065, transfId, -1 );
2947   createMenu( 4066, transfId, -1 );
2948
2949   createMenu( 406, modifyId, -1 );
2950   createMenu( 4067,modifyId, -1 );
2951   createMenu( 407, modifyId, -1 );
2952   createMenu( 408, modifyId, -1 );
2953   createMenu( 409, modifyId, -1 );
2954   createMenu( 410, modifyId, -1 );
2955   createMenu( 411, modifyId, -1 );
2956   createMenu( 412, modifyId, -1 );
2957   createMenu( 413, modifyId, -1 );
2958   createMenu( 416, modifyId, -1 );
2959   createMenu( 414, modifyId, -1 );
2960   createMenu( 415, modifyId, -1 );
2961   createMenu( 417, modifyId, -1 );
2962   createMenu( 418, modifyId, -1 );
2963
2964   createMenu( 214, viewId, -1 );
2965
2966   // ----- create toolbars --------------
2967   int meshTb     = createTool( tr( "TB_MESH" ) ),
2968       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2969       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2970       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2971       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2972
2973   createTool( 702, meshTb );
2974   createTool( 703, meshTb );
2975   createTool( 704, meshTb );
2976   createTool( 710, meshTb );
2977   createTool( separator(), meshTb );
2978   createTool( 701, meshTb );
2979   createTool( 711, meshTb );
2980   createTool( 712, meshTb );
2981   createTool( separator(), meshTb );
2982   createTool( 801, meshTb );
2983   createTool( 806, meshTb );
2984   createTool( 802, meshTb );
2985   createTool( 803, meshTb );
2986   //createTool( 815, meshTb );
2987   createTool( separator(), meshTb );
2988   createTool( 900, meshTb );
2989   createTool( 902, meshTb );
2990   createTool( 903, meshTb );
2991   createTool( separator(), meshTb );
2992
2993   createTool( 6001, ctrlTb );
2994   createTool( 6003, ctrlTb );
2995   createTool( 6004, ctrlTb );
2996   createTool( separator(), ctrlTb );
2997   createTool( 6005, ctrlTb );
2998   createTool( 6002, ctrlTb );
2999   createTool( 6018, ctrlTb );
3000   createTool( 6019, ctrlTb );
3001   createTool( 6011, ctrlTb );
3002   createTool( 6012, ctrlTb );
3003   createTool( 6013, ctrlTb );
3004   createTool( 6014, ctrlTb );
3005   createTool( 6015, ctrlTb );
3006   createTool( 6016, ctrlTb );
3007   createTool( separator(), ctrlTb );
3008   createTool( 6017, ctrlTb );
3009   createTool( 6009, ctrlTb );
3010   createTool( 6021, ctrlTb );
3011   createTool( separator(), ctrlTb );
3012
3013   createTool( 4000, addRemTb );
3014   createTool( 4009, addRemTb );
3015   createTool( 4010, addRemTb );
3016   createTool( 4021, addRemTb );
3017   createTool( 4022, addRemTb );
3018   createTool( 4023, addRemTb );
3019   createTool( 4031, addRemTb );
3020   createTool( 4032, addRemTb );
3021   createTool( 4033, addRemTb );
3022   createTool( separator(), addRemTb );
3023   createTool( 4034, addRemTb );
3024   createTool( 4035, addRemTb );
3025   createTool( 4036, addRemTb );
3026   createTool( 4037, addRemTb );
3027   createTool( 4038, addRemTb );
3028   createTool( 4039, addRemTb );
3029   createTool( 4040, addRemTb );
3030   createTool( separator(), addRemTb );
3031   createTool( 4041, addRemTb );
3032   createTool( 4042, addRemTb );
3033   createTool( 4043, addRemTb );
3034   createTool( separator(), addRemTb );
3035   createTool( 4051, addRemTb );
3036   createTool( 4052, addRemTb );
3037   createTool( separator(), addRemTb );
3038   createTool( 4061, addRemTb );
3039   createTool( 4062, addRemTb );
3040   createTool( 4063, addRemTb );
3041   createTool( 4064, addRemTb );
3042   createTool( 4065, addRemTb );
3043   createTool( 4066, addRemTb );
3044   createTool( separator(), addRemTb );
3045
3046   createTool( 406, modifyTb );
3047   createTool( 4067,modifyTb );
3048   createTool( 407, modifyTb );
3049   createTool( 408, modifyTb );
3050   createTool( 409, modifyTb );
3051   createTool( 410, modifyTb );
3052   createTool( 411, modifyTb );
3053   createTool( 412, modifyTb );
3054   createTool( 413, modifyTb );
3055   createTool( 416, modifyTb );
3056   createTool( 414, modifyTb );
3057   createTool( 415, modifyTb );
3058   createTool( 417, modifyTb );
3059   createTool( 418, modifyTb );
3060
3061   createTool( 214, dispModeTb );
3062
3063   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3064   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3065
3066   myRules.clear();
3067   QString OB = "'ObjectBrowser'",
3068           View = "'" + SVTK_Viewer::Type() + "'",
3069           pat = "'%1'",
3070           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3071           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3072           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3073           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3074           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3075                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3076                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3077                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3078                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3079                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3080                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3081           subMesh = elems,
3082           mesh_group = mesh + " " + subMesh + " " + group,
3083           hyp_alg = hypo + " " + algo;
3084
3085   // popup for object browser
3086   QString
3087     isInvisible("not( isVisible )"),
3088     isEmpty("numberOfNodes = 0"),
3089     isNotEmpty("numberOfNodes <> 0"),
3090
3091     // has nodes, edges, etc in VISIBLE! actor
3092     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3093     hasElems("(count( elemTypes ) > 0)"),
3094     hasDifferentElems("(count( elemTypes ) > 1)"),
3095     hasElems0d("({'Elem0d'} in elemTypes)"),
3096     hasEdges("({'Edge'} in elemTypes)"),
3097     hasFaces("({'Face'} in elemTypes)"),
3098     hasVolumes("({'Volume'} in elemTypes)");
3099
3100   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3101   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3102   //createPopupItem( 703, OB, subMesh, "&& isComputable" );  // CREATE_SUBMESH
3103   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3104   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3105   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3106   createPopupItem( 815, OB, group, "&& groupType = 'GroupOnGeom'" ); // EDIT_GROUP
3107
3108   popupMgr()->insert( separator(), -1, 0 );
3109   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3110   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3111   createPopupItem( 712, OB, mesh, "&& isComputable" );     // COMPUTE
3112   createPopupItem( 214, OB, mesh_group );                  // UPDATE
3113   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
3114   createPopupItem( 902, OB, mesh );                        // STD_INFO
3115   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
3116   popupMgr()->insert( separator(), -1, 0 );
3117   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3118   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3119   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3120   popupMgr()->insert( separator(), -1, 0 );
3121   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3122   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
3123   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
3124   popupMgr()->insert( separator(), -1, 0 );
3125   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3126   popupMgr()->insert( separator(), -1, 0 );
3127   createPopupItem( 417, OB, mesh/*, "&& " + hasElems*/);       // convert to quadratic
3128   createPopupItem( 418, OB, mesh/*, "&& " + hasVolumes*/);     // create 2D mesh on 3D
3129   popupMgr()->insert( separator(), -1, 0 );
3130
3131   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3132
3133   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
3134   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
3135   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
3136   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
3137   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
3138   popupMgr()->insert( separator(), -1, 0 );
3139
3140   // popup for viewer
3141   createPopupItem( 803, View, group ); // EDIT_GROUP
3142   createPopupItem( 804, View, elems ); // ADD
3143   createPopupItem( 805, View, elems ); // REMOVE
3144
3145   popupMgr()->insert( separator(), -1, 0 );
3146   createPopupItem( 214, View, mesh_group ); // UPDATE
3147   createPopupItem( 900, View, mesh_group ); // ADV_INFO
3148   createPopupItem( 902, View, mesh );       // STD_INFO
3149   createPopupItem( 903, View, mesh_group ); // WHAT_IS
3150   popupMgr()->insert( separator(), -1, 0 );
3151
3152   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3153   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3154   popupMgr()->insert( separator(), -1, 0 );
3155
3156   int anId;
3157   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3158   QString aType = QString( "%1type in {%2}" ).arg( lc );
3159   aType = aType.arg( mesh_group );
3160   QString aMeshInVTK = aClient + "&&" + aType;
3161
3162   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3163   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3164   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3165
3166   //-------------------------------------------------
3167   // Numbering
3168   //-------------------------------------------------
3169   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3170
3171   popupMgr()->insert( action( 9010 ), anId, -1 );
3172   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
3173   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
3174
3175   popupMgr()->insert( action( 9011 ), anId, -1 );
3176   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
3177   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
3178
3179   popupMgr()->insert( separator(), -1, -1 );
3180
3181   //-------------------------------------------------
3182   // Display Mode
3183   //-------------------------------------------------
3184   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3185
3186   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3187   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3188   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3189
3190   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3191   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3192   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3193
3194   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3195   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3196   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3197
3198   popupMgr()->insert( separator(), anId, -1 );
3199
3200   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3201   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3202   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3203
3204   //-------------------------------------------------
3205   // Display Entity
3206   //-------------------------------------------------
3207   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3208
3209   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3210
3211   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
3212   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
3213   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
3214
3215   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3216   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3217   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3218
3219   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3220   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3221   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3222
3223   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3224   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3225   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3226
3227   popupMgr()->insert( separator(), anId, -1 );
3228
3229   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3230   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3231
3232
3233   //-------------------------------------------------
3234   // Representation of the 2D Quadratic elements
3235   //-------------------------------------------------  
3236   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
3237   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
3238   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
3239   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
3240   
3241   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
3242   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
3243   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
3244
3245   //-------------------------------------------------
3246   // Orientation of faces
3247   //-------------------------------------------------
3248   popupMgr()->insert( action( 221 ), -1, -1 );
3249   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3250   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3251
3252   //-------------------------------------------------
3253   // Color / Size
3254   //-------------------------------------------------
3255   popupMgr()->insert( action( 1132 ), -1, -1 );
3256   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3257
3258   //-------------------------------------------------
3259   // Transparency
3260   //-------------------------------------------------
3261   popupMgr()->insert( action( 1133 ), -1, -1 );
3262   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3263
3264   //-------------------------------------------------
3265   // Clipping
3266   //-------------------------------------------------
3267   popupMgr()->insert( action( 1134 ), -1, -1 );
3268   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& selcount=1 && isVisible", QtxPopupMgr::VisibleRule );
3269
3270   popupMgr()->insert( separator(), -1, -1 );
3271
3272   //-------------------------------------------------
3273   // Controls
3274   //-------------------------------------------------
3275   QString
3276     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
3277     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3278     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3279     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3280
3281   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3282   
3283   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3284   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3285
3286   popupMgr()->insert( separator(), anId, -1 );
3287
3288   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3289   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3290   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3291
3292   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3293   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3294   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3295
3296   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3297   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3298   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3299
3300   popupMgr()->insert( separator(), anId, -1 );
3301
3302   popupMgr()->insert( action( 6005 ), anId, -1 ); // FREE_NODE
3303   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
3304   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
3305
3306   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3307   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3308   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3309
3310   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3311   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3312   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3313
3314   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3315   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3316   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3317
3318   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3319   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3320   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3321
3322   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3323   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3324   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
3325
3326   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3327   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3328   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
3329
3330   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3331   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3332   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
3333
3334   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3335   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3336   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
3337
3338   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3339   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3340   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
3341
3342   popupMgr()->insert( separator(), anId, -1 );
3343
3344   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3345   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3346   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
3347
3348   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3349   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3350   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
3351
3352   popupMgr()->insert( action( 6021 ), anId, -1 ); // FREE_FACE
3353   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
3354                                        QtxPopupMgr::VisibleRule );
3355   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
3356
3357   popupMgr()->insert( separator(), anId, -1 );
3358
3359   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3360   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3361
3362   popupMgr()->insert( separator(), -1, -1 );
3363   
3364   //-------------------------------------------------
3365   // Display / Erase
3366   //-------------------------------------------------
3367   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3368     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3369   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3370   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
3371
3372   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3373   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
3374
3375   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3376   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
3377
3378   popupMgr()->insert( separator(), -1, -1 );
3379
3380   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3381            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3382 }
3383
3384 //================================================================================
3385 /*!
3386  * \brief Return true if SMESH or GEOM objects are selected.
3387  * Is called form LightApp_Module::activateModule() which clear selection if
3388  * not isSelectionCompatible()
3389  */
3390 //================================================================================
3391
3392 bool SMESHGUI::isSelectionCompatible()
3393 {
3394   bool isCompatible = true;
3395   SALOME_ListIO selected;
3396   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3397     Sel->selectedObjects( selected );
3398
3399   SALOME_ListIteratorOfListIO It( selected );
3400   for ( ; isCompatible && It.More(); It.Next())
3401     isCompatible =
3402       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3403       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3404
3405   return isCompatible;
3406 }
3407
3408 bool SMESHGUI::activateModule( SUIT_Study* study )
3409 {
3410   bool res = SalomeApp_Module::activateModule( study );
3411
3412   setMenuShown( true );
3413   setToolShown( true );
3414
3415   // Reset actions accelerator keys
3416   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
3417   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
3418   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
3419
3420   action(  33)->setEnabled(true); // Delete: Key_Delete
3421   action(1101)->setEnabled(true); // Rename: Key_F2
3422
3423   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
3424   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
3425   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
3426     if ( _PTR(Study) aStudy = s->studyDS()) {
3427       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
3428       updateObjBrowser(); // objects can be removed
3429     }
3430
3431   return res;
3432 }
3433
3434 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3435 {
3436   setMenuShown( false );
3437   setToolShown( false );
3438
3439   EmitSignalCloseAllDialogs();
3440
3441   // Unset actions accelerator keys
3442   action(111)->setShortcut(QKeySequence()); // Import DAT
3443   action(112)->setShortcut(QKeySequence()); // Import UNV
3444   action(113)->setShortcut(QKeySequence()); // Import MED
3445
3446   action(  33)->setEnabled(false); // Delete: Key_Delete
3447   action(1101)->setEnabled(false); // Rename: Key_F2
3448
3449   return SalomeApp_Module::deactivateModule( study );
3450 }
3451
3452 void SMESHGUI::studyClosed( SUIT_Study* s )
3453 {
3454   SMESH::RemoveVisuData( s->id() );
3455   SalomeApp_Module::studyClosed( s );
3456 }
3457
3458 void SMESHGUI::OnGUIEvent()
3459 {
3460   const QObject* obj = sender();
3461   if ( !obj || !obj->inherits( "QAction" ) )
3462     return;
3463   int id = actionId((QAction*)obj);
3464   if ( id != -1 )
3465     OnGUIEvent( id );
3466 }
3467
3468 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3469 {
3470   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3471   if ( CORBA::is_nil( myComponentSMESH ) )
3472     {
3473       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3474       if ( aStudy )
3475         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3476       return aGUI.myComponentSMESH;
3477     }
3478   if ( aStudy )
3479     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3480   return myComponentSMESH;
3481 }
3482
3483 QString SMESHGUI::engineIOR() const
3484 {
3485   CORBA::ORB_var anORB = getApp()->orb();
3486   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3487   return QString( anIOR.in() );
3488 }
3489
3490 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
3491 {
3492   SalomeApp_Module::contextMenuPopup( client, menu, title );
3493   SALOME_ListIO lst;
3494   selectionMgr()->selectedObjects( lst );
3495   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3496     Handle(SALOME_InteractiveObject) io = lst.First();
3497     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3498     _PTR(Study) study = appStudy->studyDS();
3499     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3500     if ( obj ) {
3501       QString aName = QString( obj->GetName().c_str() );
3502       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3503           aName.remove( (aName.length() - 1), 1 );
3504       title = aName;
3505     }
3506   }
3507 }
3508
3509 LightApp_Selection* SMESHGUI::createSelection() const
3510 {
3511   return new SMESHGUI_Selection();
3512 }
3513
3514 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3515 {
3516   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
3517   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
3518 }
3519
3520 void SMESHGUI::viewManagers( QStringList& list ) const
3521 {
3522   list.append( SVTK_Viewer::Type() );
3523 }
3524
3525 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3526 {
3527   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3528     SMESH::UpdateSelectionProp( this );
3529 }
3530
3531 void SMESHGUI::createPreferences()
3532 {
3533   // General tab ------------------------------------------------------------------------
3534   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3535
3536   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3537   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3538
3539   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3540   setPreferenceProperty( qaGroup, "columns", 2 );
3541   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3542   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3543   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3544   setPreferenceProperty( prec, "min", 0 );
3545   setPreferenceProperty( prec, "max", 16 );
3546
3547   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3548   setPreferenceProperty( dispgroup, "columns", 2 );
3549   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3550   QStringList modes;
3551   modes.append( "Wireframe" );
3552   modes.append( "Shading" );
3553   modes.append( "Nodes" );
3554   modes.append( "Shrink" );
3555   QList<QVariant> indices;
3556   indices.append( 0 );
3557   indices.append( 1 );
3558   indices.append( 2 );
3559   indices.append( 3 );
3560   setPreferenceProperty( dispmode, "strings", modes );
3561   setPreferenceProperty( dispmode, "indexes", indices );
3562
3563   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
3564   setPreferenceProperty( arcgroup, "columns", 2 );
3565   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
3566   QStringList quadraticModes;
3567   quadraticModes.append("Lines");
3568   quadraticModes.append("Arcs");
3569   indices.clear();
3570   indices.append( 0 );
3571   indices.append( 1 );
3572   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
3573   setPreferenceProperty( quadraticmode, "indexes", indices );
3574
3575   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
3576                               "SMESH", "max_angle" );
3577   setPreferenceProperty( maxAngle, "min", 1 );
3578   setPreferenceProperty( maxAngle, "max", 90 );
3579   
3580   
3581
3582   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3583   setPreferenceProperty( exportgroup, "columns", 2 );
3584   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3585   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3586
3587   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
3588   setPreferenceProperty( computeGroup, "columns", 2 );
3589   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
3590   modes.clear();
3591   modes.append( "Never" );
3592   modes.append( "Errors only" );
3593   modes.append( "Always" );
3594   indices.clear();
3595   indices.append( 0 );
3596   indices.append( 1 );
3597   indices.append( 2 );
3598   setPreferenceProperty( notifyMode, "strings", modes );
3599   setPreferenceProperty( notifyMode, "indexes", indices );
3600
3601   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
3602   setPreferenceProperty( segGroup, "columns", 2 );
3603   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
3604                               "SMESH", "segmentation" );
3605   setPreferenceProperty( segLen, "min", 1 );
3606   setPreferenceProperty( segLen, "max", 10000000 );
3607   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
3608                              "SMESH", "nb_segments_per_edge" );
3609   setPreferenceProperty( nbSeg, "min", 1 );
3610   setPreferenceProperty( nbSeg, "max", 10000000 );
3611
3612   // Mesh tab ------------------------------------------------------------------------
3613   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3614   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3615   setPreferenceProperty( nodeGroup, "columns", 2 );
3616
3617   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3618   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3619
3620   setPreferenceProperty( nodeSz, "min", 1 );
3621   setPreferenceProperty( nodeSz, "max", 5 );
3622
3623   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3624   setPreferenceProperty( elemGroup, "columns", 2 );
3625
3626   addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3627   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3628   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3629   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
3630
3631   //int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3632   //setPreferenceProperty( sp, "hstretch", 0 );
3633   //setPreferenceProperty( sp, "vstretch", 0 );
3634
3635   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
3636                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
3637   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3638   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
3639                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
3640   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
3641                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
3642
3643   setPreferenceProperty( size0d, "min", 1 );
3644   setPreferenceProperty( size0d, "max", 10 );
3645
3646   setPreferenceProperty( sp, "hstretch", 0 );
3647   setPreferenceProperty( sp, "vstretch", 0 );
3648
3649   setPreferenceProperty( elemW, "min", 1 );
3650   setPreferenceProperty( elemW, "max", 5 );
3651
3652   setPreferenceProperty( shrink, "min", 0 );
3653   setPreferenceProperty( shrink, "max", 100 );
3654
3655   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
3656   setPreferenceProperty( orientGroup, "columns", 1 );
3657
3658   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
3659   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
3660
3661   setPreferenceProperty( orientScale, "min", 0.05 );
3662   setPreferenceProperty( orientScale, "max", 0.5 );
3663   setPreferenceProperty( orientScale, "step", 0.05 );
3664
3665   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
3666
3667   // Selection tab ------------------------------------------------------------------------
3668   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3669
3670   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3671   setPreferenceProperty( selGroup, "columns", 2 );
3672
3673   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3674   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3675   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3676
3677   setPreferenceProperty( selW, "min", 1 );
3678   setPreferenceProperty( selW, "max", 5 );
3679
3680   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3681   setPreferenceProperty( preGroup, "columns", 2 );
3682
3683   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3684   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3685
3686   setPreferenceProperty( preW, "min", 1 );
3687   setPreferenceProperty( preW, "max", 5 );
3688
3689   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3690   setPreferenceProperty( precSelGroup, "columns", 2 );
3691
3692   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3693   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3694   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3695
3696   // Scalar Bar tab ------------------------------------------------------------------------
3697   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3698   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3699   setPreferenceProperty( fontGr, "columns", 2 );
3700
3701   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
3702   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3703
3704   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
3705   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3706
3707   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3708   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
3709
3710   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3711   setPreferenceProperty( numcol, "min", 2 );
3712   setPreferenceProperty( numcol, "max", 256 );
3713
3714   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3715   setPreferenceProperty( numlab, "min", 2 );
3716   setPreferenceProperty( numlab, "max", 65 );
3717
3718   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3719   setPreferenceProperty( orientGr, "columns", 2 );
3720   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3721   QStringList orients;
3722   orients.append( tr( "SMESH_VERTICAL" ) );
3723   orients.append( tr( "SMESH_HORIZONTAL" ) );
3724   indices.clear(); indices.append( 0 ); indices.append( 1 );
3725   setPreferenceProperty( orient, "strings", orients );
3726   setPreferenceProperty( orient, "indexes", indices );
3727
3728   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3729   setPreferenceProperty( posVSizeGr, "columns", 2 );
3730   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3731   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3732   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3733   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3734   setPreferenceProperty( xv, "step", 0.1 );
3735   setPreferenceProperty( xv, "min", 0.0 );
3736   setPreferenceProperty( xv, "max", 1.0 );
3737   setPreferenceProperty( yv, "step", 0.1 );
3738   setPreferenceProperty( yv, "min", 0.0 );
3739   setPreferenceProperty( yv, "max", 1.0 );
3740   setPreferenceProperty( wv, "step", 0.1 );
3741   setPreferenceProperty( wv, "min", 0.0 );
3742   setPreferenceProperty( wv, "max", 1.0 );
3743   setPreferenceProperty( hv, "min", 0.0 );
3744   setPreferenceProperty( hv, "max", 1.0 );
3745   setPreferenceProperty( hv, "step", 0.1 );
3746
3747   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3748   setPreferenceProperty( posHSizeGr, "columns", 2 );
3749   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3750   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3751   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3752   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3753   setPreferenceProperty( xv, "min", 0.0 );
3754   setPreferenceProperty( xv, "max", 1.0 );
3755   setPreferenceProperty( xv, "step", 0.1 );
3756   setPreferenceProperty( xh, "min", 0.0 );
3757   setPreferenceProperty( xh, "max", 1.0 );
3758   setPreferenceProperty( xh, "step", 0.1 );
3759   setPreferenceProperty( yh, "min", 0.0 );
3760   setPreferenceProperty( yh, "max", 1.0 );
3761   setPreferenceProperty( yh, "step", 0.1 );
3762   setPreferenceProperty( wh, "min", 0.0 );
3763   setPreferenceProperty( wh, "max", 1.0 );
3764   setPreferenceProperty( wh, "step", 0.1 );
3765   setPreferenceProperty( hh, "min", 0.0 );
3766   setPreferenceProperty( hh, "max", 1.0 );
3767   setPreferenceProperty( hh, "step", 0.1 );
3768 }
3769
3770 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3771 {
3772   if( sect=="SMESH" ) {
3773     float sbX1,sbY1,sbW,sbH;
3774     float aTol = 1.00000009999999;
3775     std::string aWarning;
3776     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3777     if( name=="selection_object_color" || name=="selection_element_color" ||
3778         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3779         name=="selection_precision_node" || name=="selection_precision_element" ||
3780         name=="selection_precision_object")
3781       SMESH::UpdateSelectionProp( this );
3782     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3783       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3784       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3785       if(sbX1+sbW > aTol){
3786         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3787         sbX1=0.01;
3788         sbW=0.08;
3789         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3790         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3791       }
3792     }
3793     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3794       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3795       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3796       if(sbY1+sbH > aTol){
3797         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3798         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3799         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3800       }
3801     }
3802     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3803       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3804       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3805       if(sbX1+sbW > aTol){
3806         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3807         sbX1=0.1;
3808         sbW=0.08;
3809         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3810         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3811       }
3812     }
3813     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3814       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3815       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3816       if(sbY1+sbH > aTol){
3817         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3818         sbY1=0.01;
3819         sbH=0.08;
3820         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3821         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3822       }
3823     }
3824     else if ( name == "segmentation" ) {
3825       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
3826       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
3827     }
3828     else if ( name == "nb_segments_per_edge" ) {
3829       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
3830       myComponentSMESH->SetDefaultNbSegments( nbSeg );
3831     }
3832
3833     if(aWarning.size() != 0){
3834       aWarning += "The default values are applied instead.";
3835       SUIT_MessageBox::warning(SMESHGUI::desktop(),
3836                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3837                                QObject::tr(aWarning.c_str()));
3838     }
3839   }
3840 }
3841
3842 //================================================================================
3843 /*!
3844  * \brief Update something in accordance with update flags
3845   * \param theFlags - update flags
3846 *
3847 * Update viewer or/and object browser etc. in accordance with update flags ( see
3848 * LightApp_UpdateFlags enumeration ).
3849 */
3850 //================================================================================
3851 void SMESHGUI::update( const int flags )
3852 {
3853   if ( flags & UF_Viewer | flags & UF_Forced )
3854     SMESH::UpdateView();
3855   else
3856     SalomeApp_Module::update( flags );
3857 }
3858
3859 //================================================================================
3860 /*!
3861  * \brief Set default selection mode
3862 *
3863 * SLOT called when operation commited. Sets default selection mode
3864 */
3865 //================================================================================
3866 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3867 {
3868   SVTK_ViewWindow* vtkWnd =
3869     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3870   if ( vtkWnd )
3871     vtkWnd->SetSelectionMode( ActorSelection );
3872 }
3873
3874 //================================================================================
3875 /*!
3876  * \brief Set default selection mode
3877 *
3878 * SLOT called when operation aborted. Sets default selection mode
3879 */
3880 //================================================================================
3881 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3882 {
3883   SVTK_ViewWindow* vtkWnd =
3884     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3885   if ( vtkWnd )
3886     vtkWnd->SetSelectionMode( ActorSelection );
3887 }
3888
3889 //================================================================================
3890 /*!
3891  * \brief Creates operation with given identifier
3892   * \param id - identifier of operation to be started
3893   * \return Pointer on created operation or NULL if operation is not created
3894 *
3895 * Virtual method redefined from the base class creates operation with given id.
3896 * It is called called automatically from startOperation method of base class.
3897 */
3898 //================================================================================
3899 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3900 {
3901   LightApp_Operation* op = 0;
3902   // to do : create operation here
3903   switch( id )
3904   {
3905     case 701: // Compute mesh
3906       op = new SMESHGUI_ComputeOp();
3907     break;
3908     case 702: // Create mesh
3909       op = new SMESHGUI_MeshOp( true, true );
3910     break;
3911     case 703: // Create sub-mesh
3912       op = new SMESHGUI_MeshOp( true, false );
3913     break;
3914     case 704: // Edit mesh/sub-mesh
3915       op = new SMESHGUI_MeshOp( false );
3916     break;
3917     case 711: // Precompute mesh
3918       op = new SMESHGUI_PrecomputeOp();
3919     break;
3920     case 712: // Evaluate mesh
3921       op = new SMESHGUI_EvaluateOp();
3922     break;
3923     case 806: // Create group on geom
3924       op = new SMESHGUI_GroupOnShapeOp();
3925       break;
3926     case 417: //convert to quadratic
3927       op = new SMESHGUI_ConvToQuadOp();
3928     break;
3929     case 418: // create 2D mesh as boundary on 3D
3930       op = new SMESHGUI_Make2DFrom3DOp();
3931     break;
3932     case 4067: // make mesh pass through point
3933       op = new SMESHGUI_MakeNodeAtPointOp();
3934       break;
3935     default:
3936     break;
3937   }
3938
3939   if( !op )
3940     op = SalomeApp_Module::createOperation( id );
3941   return op;
3942 }
3943
3944 //================================================================================
3945 /*!
3946  * \brief Stops current operations and starts a given one
3947   * \param id - The id of the operation to start
3948  */
3949 //================================================================================
3950
3951 void SMESHGUI::switchToOperation(int id)
3952 {
3953   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3954     activeStudy()->abortAllOperations();
3955   startOperation( id );
3956 }
3957
3958 LightApp_Displayer* SMESHGUI::displayer()
3959 {
3960   if( !myDisplayer )
3961     myDisplayer = new SMESHGUI_Displayer( getApp() );
3962   return myDisplayer;
3963 }
3964
3965 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
3966 {
3967   int aHue = -1;
3968   int aTolerance = 64;
3969   int anIterations = 0;
3970   int aPeriod = 5;
3971
3972   while( 1 )
3973   {
3974     anIterations++;
3975     if( anIterations % aPeriod == 0 )
3976     {
3977       aTolerance /= 2;
3978       if( aTolerance < 1 )
3979         break;
3980     }
3981     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3982
3983     aHue = (int)( 360.0 * rand() / RAND_MAX );
3984     //cout << "Hue = " << aHue << endl;
3985
3986     //cout << "Auto colors : ";
3987     bool ok = true;
3988     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3989     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3990     for( ; it != itEnd; ++it )
3991     {
3992       SALOMEDS::Color anAutoColor = *it;
3993       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3994
3995       int h, s, v;
3996       aQColor.getHsv( &h, &s, &v );
3997       //cout << h << " ";
3998       if( abs( h - aHue ) < aTolerance )
3999       {
4000         ok = false;
4001         //cout << "break (diff = " << abs( h - aHue ) << ")";
4002         break;
4003       }
4004     }
4005     //cout << endl;
4006
4007     if( ok )
4008       break;
4009   }
4010
4011   //cout << "Hue of the returned color = " << aHue << endl;
4012   QColor aColor;
4013   aColor.setHsv( aHue, 255, 255 );
4014
4015   SALOMEDS::Color aSColor;
4016   aSColor.R = (double)aColor.red() / 255.0;
4017   aSColor.G = (double)aColor.green() / 255.0;
4018   aSColor.B = (double)aColor.blue() / 255.0;
4019
4020   return aSColor;
4021 }
4022
4023 const char gSeparator = '_'; // character used to separate parameter names
4024 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
4025
4026 /*!
4027  * \brief Store visual parameters
4028  *
4029  * This method is called just before the study document is saved.
4030  * Store visual parameters in AttributeParameter attribue(s)
4031  */
4032 void SMESHGUI::storeVisualParameters (int savePoint)
4033 {
4034   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4035   if (!appStudy || !appStudy->studyDS())
4036     return;
4037   _PTR(Study) studyDS = appStudy->studyDS();
4038
4039   // componentName is used for encoding of entries when storing them in IParameters
4040   std::string componentName = myComponentSMESH->ComponentDataType();
4041   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
4042   //if (!aSComponent) return;
4043
4044   // IParameters
4045   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4046                                                              componentName.c_str(),
4047                                                              savePoint);
4048   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4049
4050   // viewers counters are used for storing view_numbers in IParameters
4051   int vtkViewers = 0;
4052
4053   // main cycle to store parameters of displayed objects
4054   QList<SUIT_ViewManager*> lst;
4055   QList<SUIT_ViewManager*>::Iterator it;
4056   getApp()->viewManagers(lst);
4057   for (it = lst.begin(); it != lst.end(); it++)
4058   {
4059     SUIT_ViewManager* vman = *it;
4060     QString vType = vman->getType();
4061
4062     // saving VTK actors properties
4063     if (vType == SVTK_Viewer::Type())
4064     {
4065       QVector<SUIT_ViewWindow*> views = vman->getViews();
4066       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
4067       {
4068         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
4069         {
4070           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
4071           vtkActorCollection* allActors = aCopy.GetActors();
4072           allActors->InitTraversal();
4073           while (vtkActor* actor = allActors->GetNextActor())
4074           {
4075             if (actor->GetVisibility()) // store only visible actors
4076             {
4077               SMESH_Actor* aSmeshActor = 0;
4078               if (actor->IsA("SMESH_Actor"))
4079                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
4080               if (aSmeshActor && aSmeshActor->hasIO())
4081               {
4082                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
4083                 if (io->hasEntry())
4084                 {
4085                   // entry is "encoded" = it does NOT contain component adress,
4086                   // since it is a subject to change on next component loading
4087                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
4088
4089                   std::string param, vtkParam = vType.toLatin1().data();
4090                   vtkParam += gSeparator;
4091                   vtkParam += QString::number(vtkViewers).toLatin1().data();
4092                   vtkParam += gSeparator;
4093
4094                   // Visibility
4095                   param = vtkParam + "Visibility";
4096                   ip->setParameter(entry, param, "On");
4097
4098                   // Representation
4099                   param = vtkParam + "Representation";
4100                   ip->setParameter(entry, param, QString::number
4101                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
4102
4103                   // IsShrunk
4104                   param = vtkParam + "IsShrunk";
4105                   ip->setParameter(entry, param, QString::number
4106                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
4107
4108                   // Displayed entities
4109                   unsigned int aMode = aSmeshActor->GetEntityMode();
4110                   bool isE = aMode & SMESH_Actor::eEdges;
4111                   bool isF = aMode & SMESH_Actor::eFaces;
4112                   bool isV = aMode & SMESH_Actor::eVolumes;
4113
4114                   QString modeStr ("e");
4115                   modeStr += gDigitsSep; modeStr += QString::number(isE);
4116                   modeStr += gDigitsSep; modeStr += "f";
4117                   modeStr += gDigitsSep; modeStr += QString::number(isF);
4118                   modeStr += gDigitsSep; modeStr += "v";
4119                   modeStr += gDigitsSep; modeStr += QString::number(isV);
4120
4121                   param = vtkParam + "Entities";
4122                   ip->setParameter(entry, param, modeStr.toLatin1().data());
4123
4124                   // Colors (surface:edge:)
4125                   vtkFloatingPointType r, g, b;
4126
4127                   aSmeshActor->GetSufaceColor(r, g, b);
4128                   QString colorStr ("surface");
4129                   colorStr += gDigitsSep; colorStr += QString::number(r);
4130                   colorStr += gDigitsSep; colorStr += QString::number(g);
4131                   colorStr += gDigitsSep; colorStr += QString::number(b);
4132
4133                   aSmeshActor->GetBackSufaceColor(r, g, b);
4134                   colorStr += gDigitsSep; colorStr += "backsurface";
4135                   colorStr += gDigitsSep; colorStr += QString::number(r);
4136                   colorStr += gDigitsSep; colorStr += QString::number(g);
4137                   colorStr += gDigitsSep; colorStr += QString::number(b);
4138
4139                   aSmeshActor->GetEdgeColor(r, g, b);
4140                   colorStr += gDigitsSep; colorStr += "edge";
4141                   colorStr += gDigitsSep; colorStr += QString::number(r);
4142                   colorStr += gDigitsSep; colorStr += QString::number(g);
4143                   colorStr += gDigitsSep; colorStr += QString::number(b);
4144
4145                   aSmeshActor->GetNodeColor(r, g, b);
4146                   colorStr += gDigitsSep; colorStr += "node";
4147                   colorStr += gDigitsSep; colorStr += QString::number(r);
4148                   colorStr += gDigitsSep; colorStr += QString::number(g);
4149                   colorStr += gDigitsSep; colorStr += QString::number(b);
4150
4151                   param = vtkParam + "Colors";
4152                   ip->setParameter(entry, param, colorStr.toLatin1().data());
4153
4154                   // Sizes of lines and points
4155                   QString sizeStr ("line");
4156                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
4157                   sizeStr += gDigitsSep; sizeStr += "node";
4158                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetNodeSize());
4159                   sizeStr += gDigitsSep; sizeStr += "shrink";
4160                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
4161
4162                   param = vtkParam + "Sizes";
4163                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
4164
4165                   // Opacity
4166                   param = vtkParam + "Opacity";
4167                   ip->setParameter(entry, param,
4168                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
4169
4170                   // Clipping
4171                   param = vtkParam + "ClippingPlane";
4172                   int nPlanes = aSmeshActor->GetNumberOfClippingPlanes();
4173                   if (!nPlanes)
4174                     ip->setParameter(entry, param, "Off");
4175                   for (int ipl = 0; ipl < nPlanes; ipl++) {
4176                     //vtkPlane* plane = aSmeshActor->GetClippingPlane(ipl);
4177                     SMESH::Orientation anOrientation;
4178                     double aDistance;
4179                     vtkFloatingPointType anAngle[2];
4180                     SMESHGUI_ClippingDlg::GetPlaneParam(aSmeshActor, ipl, anOrientation, aDistance, anAngle);
4181                     std::string planeValue = QString::number((int)anOrientation).toLatin1().data();
4182                     planeValue += gDigitsSep; planeValue += QString::number(aDistance).toLatin1().data();
4183                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[0]).toLatin1().data();
4184                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[1]).toLatin1().data();
4185
4186                     ip->setParameter(entry, param + QString::number(ipl+1).toLatin1().data(), planeValue);
4187                   }
4188                 } // if (io->hasEntry())
4189               } // SMESH_Actor && hasIO
4190             } // isVisible
4191           } // while.. actors traversal
4192         } // if (vtkView)
4193       } // for (views)
4194       vtkViewers++;
4195     } // if (SVTK view model)
4196   } // for (viewManagers)
4197 }
4198
4199 /*!
4200  * \brief Restore visual parameters
4201  *
4202  * This method is called after the study document is opened.
4203  * Restore visual parameters from AttributeParameter attribue(s)
4204  */
4205 void SMESHGUI::restoreVisualParameters (int savePoint)
4206 {
4207   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4208   if (!appStudy || !appStudy->studyDS())
4209     return;
4210   _PTR(Study) studyDS = appStudy->studyDS();
4211
4212   // componentName is used for encoding of entries when storing them in IParameters
4213   std::string componentName = myComponentSMESH->ComponentDataType();
4214   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
4215   //if (!aSComponent) return;
4216
4217   // IParameters
4218   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4219                                                              componentName.c_str(),
4220                                                              savePoint);
4221   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4222
4223   std::vector<std::string> entries = ip->getEntries();
4224
4225   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
4226   {
4227     // entry is a normal entry - it should be "decoded" (setting base adress of component)
4228     QString entry (ip->decodeEntry(*entIt).c_str());
4229
4230     // Check that the entry corresponds to a real object in the Study
4231     // as the object may be deleted or modified after the visual state is saved.
4232     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
4233     if (!so) continue; //Skip the not existent entry
4234
4235     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
4236     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
4237
4238     std::vector<std::string>::iterator namesIt = paramNames.begin();
4239     std::vector<std::string>::iterator valuesIt = paramValues.begin();
4240
4241     // actors are stored in a map after displaying of them for
4242     // quicker access in the future: map < viewID to actor >
4243     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
4244
4245     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
4246     {
4247       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
4248       // '_' is used as separator and should not be used in viewer type or parameter names.
4249       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
4250       if (lst.size() != 3)
4251         continue;
4252
4253       QString viewerTypStr = lst[0];
4254       QString viewIndexStr = lst[1];
4255       QString paramNameStr = lst[2];
4256
4257       bool ok;
4258       int viewIndex = viewIndexStr.toUInt(&ok);
4259       if (!ok) // bad conversion of view index to integer
4260         continue;
4261
4262       // viewers
4263       if (viewerTypStr == SVTK_Viewer::Type())
4264       {
4265         SMESH_Actor* aSmeshActor = 0;
4266         if (vtkActors.IsBound(viewIndex))
4267           aSmeshActor = vtkActors.Find(viewIndex);
4268
4269         if (paramNameStr == "Visibility")
4270         {
4271           if (!aSmeshActor && displayer())
4272           {
4273             QList<SUIT_ViewManager*> lst;
4274             getApp()->viewManagers(viewerTypStr, lst);
4275
4276             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4277             if (viewIndex >= 0 && viewIndex < lst.count()) {
4278               SUIT_ViewManager* vman = lst.at(viewIndex);
4279               SUIT_ViewModel* vmodel = vman->getViewModel();
4280               // SVTK view model can be casted to SALOME_View
4281               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
4282
4283               // store displayed actor in a temporary map for quicker
4284               // access later when restoring other parameters
4285               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4286               vtkRenderer* Renderer = vtkView->getRenderer();
4287               VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
4288               vtkActorCollection* theActors = aCopy.GetActors();
4289               theActors->InitTraversal();
4290               bool isFound = false;
4291               vtkActor *ac = theActors->GetNextActor();
4292               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
4293                 if (ac->IsA("SMESH_Actor")) {
4294                   SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
4295                   if (aGeomAc->hasIO()) {
4296                     Handle(SALOME_InteractiveObject) io =
4297                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
4298                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
4299                       isFound = true;
4300                       vtkActors.Bind(viewIndex, aGeomAc);
4301                     }
4302                   }
4303                 }
4304               }
4305             }
4306           }
4307         } // if (paramNameStr == "Visibility")
4308         else
4309         {
4310           // the rest properties "work" with SMESH_Actor
4311           if (aSmeshActor)
4312           {
4313             QString val ((*valuesIt).c_str());
4314
4315             // Representation
4316             if (paramNameStr == "Representation") {
4317               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
4318             }
4319             // IsShrunk
4320             else if (paramNameStr == "IsShrunk") {
4321               if (val.toInt()) {
4322                 if (!aSmeshActor->IsShrunk())
4323                   aSmeshActor->SetShrink();
4324               }
4325               else {
4326                 if (aSmeshActor->IsShrunk())
4327                   aSmeshActor->UnShrink();
4328               }
4329             }
4330             // Displayed entities
4331             else if (paramNameStr == "Entities") {
4332               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
4333               if (mode.count() == 6) {
4334                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
4335                   MESSAGE("Invalid order of data in Entities, must be: "
4336                           "e:0/1:f:0/1:v:0/1");
4337                 }
4338                 else {
4339                   unsigned int aMode = aSmeshActor->GetEntityMode();
4340                   unsigned int aNewMode =
4341                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
4342                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
4343                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
4344                   if (aNewMode != aMode)
4345                     aSmeshActor->SetEntityMode(aNewMode);
4346                 }
4347               }
4348             }
4349             // Colors
4350             else if (paramNameStr == "Colors") {
4351               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
4352               if (colors.count() == 16) {
4353                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
4354                     colors[8] != "edge"    || colors[12] != "node") {
4355                   MESSAGE("Invalid order of data in Colors, must be: "
4356                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
4357                 }
4358                 else {
4359                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
4360                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
4361                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
4362                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
4363                 }
4364               }
4365             }
4366             // Sizes of lines and points
4367             else if (paramNameStr == "Sizes") {
4368               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
4369               if (sizes.count() == 6) {
4370                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
4371                   MESSAGE("Invalid order of data in Sizes, must be: "
4372                           "line:int:node:int:shrink:float");
4373                 }
4374                 else {
4375                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4376                   aSmeshActor->SetNodeSize(sizes[3].toInt());
4377                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
4378                 }
4379               }
4380             }
4381             // Opacity
4382             else if (paramNameStr == "Opacity") {
4383               aSmeshActor->SetOpacity(val.toFloat());
4384             }
4385             // Clipping
4386             else if (paramNameStr.startsWith("ClippingPlane")) {
4387               cout << "$$$ ClippingPlane 1" << endl;
4388               if (paramNameStr == "ClippingPlane1" || val == "Off")
4389                 aSmeshActor->RemoveAllClippingPlanes();
4390               if (val != "Off") {
4391                 cout << "$$$ ClippingPlane 2" << endl;
4392                 QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
4393                 if (vals.count() == 4) { // format check: 4 values
4394                   cout << "$$$ ClippingPlane 3" << endl;
4395                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
4396                   double aDistance = vals[1].toFloat();
4397                   vtkFloatingPointType anAngle[2];
4398                   anAngle[0] = vals[2].toFloat();
4399                   anAngle[1] = vals[3].toFloat();
4400
4401                   QList<SUIT_ViewManager*> lst;
4402                   getApp()->viewManagers(viewerTypStr, lst);
4403                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4404                   if (viewIndex >= 0 && viewIndex < lst.count()) {
4405                     SUIT_ViewManager* vman = lst.at(viewIndex);
4406                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4407                     SMESHGUI_ClippingDlg::AddPlane(aSmeshActor, vtkView,
4408                                                    anOrientation, aDistance, anAngle);
4409                   }
4410                 }
4411               }
4412             }
4413           } // if (aSmeshActor)
4414         } // other parameters than Visibility
4415       }
4416     } // for names/parameters iterator
4417   } // for entries iterator
4418
4419   // update all VTK views
4420   QList<SUIT_ViewManager*> lst;
4421   getApp()->viewManagers(lst);
4422   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
4423     SUIT_ViewModel* vmodel = (*it)->getViewModel();
4424     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
4425       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
4426       vtkView->getRenderer()->ResetCameraClippingRange();
4427       vtkView->Repaint();
4428     }
4429   }
4430 }
4431
4432 /*!
4433   \brief Adds preferences for dfont of VTK viewer
4434   \param label label
4435   \param pIf group identifier
4436   \param param parameter
4437   \return identifier of preferences
4438 */
4439 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
4440 {
4441   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "VISU", param );
4442   
4443   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
4444
4445   QStringList fam;
4446   fam.append( tr( "SMESH_FONT_ARIAL" ) );
4447   fam.append( tr( "SMESH_FONT_COURIER" ) );
4448   fam.append( tr( "SMESH_FONT_TIMES" ) );
4449
4450   setPreferenceProperty( tfont, "fonts", fam );
4451
4452   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
4453   setPreferenceProperty( tfont, "features", f );
4454
4455   return tfont;
4456 }
4457
4458 /*!
4459   \brief Actions after hypothesis edition
4460   Updates object browser after hypothesis edition
4461 */
4462 void SMESHGUI::onHypothesisEdit( int result )
4463 {
4464   updateObjBrowser( true );
4465 }