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