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