Salome HOME
PAL16760 - MED file information
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28
29 #include "SMESH_Client.hxx"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_StandardMeshInfosDlg.h"
38 #include "SMESHGUI_WhatIsDlg.h"
39 #include "SMESHGUI_Preferences_ColorDlg.h"
40 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
41 #include "SMESHGUI_Preferences_SelectionDlg.h"
42 #include "SMESHGUI_Hypotheses.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_AddMeshElementDlg.h"
45 #include "SMESHGUI_AddQuadraticElementDlg.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_SingleEditDlg.h"
49 #include "SMESHGUI_MultiEditDlg.h"
50 #include "SMESHGUI_GroupOpDlg.h"
51 #include "SMESHGUI_DeleteGroupDlg.h"
52 #include "SMESHGUI_SmoothingDlg.h"
53 #include "SMESHGUI_RenumberingDlg.h"
54 #include "SMESHGUI_ExtrusionDlg.h"
55 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
56 #include "SMESHGUI_RevolutionDlg.h"
57 #include "SMESHGUI_TranslationDlg.h"
58 #include "SMESHGUI_RotationDlg.h"
59 #include "SMESHGUI_SymmetryDlg.h"
60 #include "SMESHGUI_SewingDlg.h"
61 #include "SMESHGUI_EditMeshDlg.h"
62 #include "SMESHGUI_MeshPatternDlg.h"
63 #include "SMESHGUI_Selection.h"
64 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
65 #include "SMESHGUI_ConvToQuadOp.h"
66 #include "SMESHGUI_MeshOp.h"
67 #include "SMESHGUI_Displayer.h"
68 #include "SMESHGUI_MakeNodeAtPointDlg.h"
69 #include "SMESHGUI_BuildCompoundDlg.h"
70 #include "SMESHGUI_ComputeDlg.h"
71 #include "SMESHGUI_FileInfoDlg.h"
72
73 #include "SMESHGUI_Utils.h"
74 #include "SMESHGUI_GEOMGenUtils.h"
75 #include "SMESHGUI_MeshUtils.h"
76 #include "SMESHGUI_GroupUtils.h"
77 #include "SMESHGUI_FilterUtils.h"
78 #include "SMESHGUI_PatternUtils.h"
79 #include "SMESHGUI_VTKUtils.h"
80 #include "SMESHGUI_HypothesesUtils.h"
81
82 #include "SMESH_Actor.h"
83 #include "SMESH_Object.h"
84 #include "SMESH_TypeFilter.hxx"
85
86 #include "SalomeApp_Tools.h"
87 #include "SalomeApp_Study.h"
88 #include "SalomeApp_Application.h"
89 #include "SalomeApp_CheckFileDlg.h"
90 #include "SalomeApp_ImportOperation.h"
91
92 #include "LightApp_DataOwner.h"
93 #include "LightApp_Preferences.h"
94 #include "LightApp_VTKSelector.h"
95 #include "LightApp_Operation.h"
96 #include "LightApp_UpdateFlags.h"
97 #include "LightApp_NameDlg.h"
98
99 #include <SVTK_ViewWindow.h>
100 #include <SVTK_ViewModel.h>
101 #include <SVTK_InteractorStyle.h>
102 #include <SVTK_RenderWindowInteractor.h>
103 #include <SVTK_ViewManager.h>
104
105 #include "OB_Browser.h"
106
107 #include "SUIT_Tools.h"
108 #include "SUIT_MessageBox.h"
109 #include "SUIT_ResourceMgr.h"
110 #include "SUIT_FileDlg.h"
111 #include "SUIT_Desktop.h"
112 #include "SUIT_OverrideCursor.h"
113 #include "SUIT_Study.h"
114 #include "SUIT_Session.h"
115
116 #include "QtxPopupMgr.h"
117
118 #include "SALOME_ListIO.hxx"
119 #include "SALOME_ListIteratorOfListIO.hxx"
120 #include "SALOME_InteractiveObject.hxx"
121 #include "SALOME_NamingService.hxx"
122 #include "SALOME_LifeCycleCORBA.hxx"
123
124 #include "SALOMEconfig.h"
125 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
126 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
127
128 // QT Includes
129 #define  INCLUDE_MENUITEM_DEF
130 #include <qpopupmenu.h>
131 #include <qstring.h>
132 #include <qwidget.h>
133 #include <qaction.h>
134
135 // BOOST Includes
136 #include <boost/shared_ptr.hpp>
137
138 // VTK Includes
139 #include <vtkRenderer.h>
140 #include <vtkRenderWindow.h>
141 #include <vtkActorCollection.h>
142 #include <vtkScalarBarActor.h>
143 #include <vtkUnstructuredGrid.h>
144
145 #include "utilities.h"
146
147 #include "SALOMEDS_Study.hxx"
148 #include "SALOMEDSClient_StudyBuilder.hxx"
149 #include "SALOMEDSClient_SComponent.hxx"
150
151 #include <Standard_ErrorHandler.hxx>
152
153 using namespace std;
154
155 //namespace{
156   // Declarations
157   //=============================================================
158   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
159                             int theCommandID);
160
161   void ExportMeshToFile(int theCommandID);
162
163   void SetDisplayMode(int theCommandID);
164
165   void SetDisplayEntity(int theCommandID);
166
167   void Control( int theCommandID );
168
169
170   // Definitions
171   //=============================================================
172   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
173                             int theCommandID)
174   {
175     QStringList filter;
176     string myExtension;
177
178     if(theCommandID == 113){
179       filter.append(QObject::tr("MED files (*.med)"));
180       filter.append(QObject::tr("All files (*)"));
181     }else if (theCommandID == 112){
182       filter.append(QObject::tr("IDEAS files (*.unv)"));
183     }else if (theCommandID == 111){
184       filter.append(QObject::tr("DAT files (*.dat)"));
185     }
186     QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
187                                                 "",
188                                                 filter,
189                                                 QObject::tr("Import mesh"),
190                                                 true);
191     if(!filename.isEmpty()) {
192       SUIT_OverrideCursor wc;
193       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
194
195       try {
196         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
197         switch ( theCommandID ) {
198         case 112:
199           {
200             aMeshes->length( 1 );
201             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
202             break;
203           }
204         case 113:
205           {
206             SMESH::DriverMED_ReadStatus res;
207             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
208             if ( res != SMESH::DRS_OK ) {
209               wc.suspend();
210               SUIT_MessageBox::warn1(SMESHGUI::desktop(),
211                                     QObject::tr("SMESH_WRN_WARNING"),
212                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
213                                     QObject::tr("SMESH_BUT_OK"));
214               aMeshes->length( 0 );
215               wc.resume();
216             }
217             break;
218           }
219         }
220
221         bool isEmpty = false;
222         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
223           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
224           if ( aMeshSO ) {
225             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
226             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
227             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
228             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
229               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
230           } else
231             isEmpty = true;
232         }
233
234         if ( isEmpty ) {
235           wc.suspend();
236           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
237                                 QObject::tr("SMESH_WRN_WARNING"),
238                                 QObject::tr("SMESH_DRS_EMPTY"),
239                                 QObject::tr("SMESH_BUT_OK"));
240           wc.resume();
241         }
242
243         SMESHGUI::GetSMESHGUI()->updateObjBrowser();
244       }
245       catch (const SALOME::SALOME_Exception& S_ex){
246         wc.suspend();
247         SalomeApp_Tools::QtCatchCorbaException(S_ex);
248         wc.resume();
249       }
250     }
251   }
252
253
254   void ExportMeshToFile( int theCommandID )
255   {
256     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
257     SALOME_ListIO selected;
258     if( aSel )
259       aSel->selectedObjects( selected );
260
261     if(selected.Extent()){
262       Handle(SALOME_InteractiveObject) anIObject = selected.First();
263       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
264       if ( !aMesh->_is_nil() ) {
265         QString aFilter, aTitle = QObject::tr("Export mesh");
266         QMap<QString, SMESH::MED_VERSION> aFilterMap;
267         QMap<QString, int> aFilterMapSTL;
268         switch ( theCommandID ) {
269         case 125:
270         case 122:
271           {
272             if (aMesh->HasDuplicatedGroupNamesMED()) {
273               int aRet = SUIT_MessageBox::warn2
274                 (SMESHGUI::desktop(),
275                  QObject::tr("SMESH_WRN_WARNING"),
276                  QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
277                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
278                  0, 1, 0);
279               if (aRet)
280                 return;
281             }
282             // PAL18696
283             QString v21( aMesh->GetVersionString( SMESH::MED_V2_1, 2));
284             QString v22( aMesh->GetVersionString( SMESH::MED_V2_2, 2));
285             aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
286             aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
287           }
288           break;
289         case 124:
290         case 121:
291           aFilter = QObject::tr("DAT files (*.dat)");
292           break;
293         case 126:
294         case 123:
295           {
296             if (aMesh->NbPyramids()) {
297               int aRet = SUIT_MessageBox::warn2
298                 (SMESHGUI::desktop(),
299                  QObject::tr("SMESH_WRN_WARNING"),
300                  QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
301                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
302                  0, 1, 0);
303               if (aRet)
304                 return;
305             }
306             aFilter = QObject::tr("IDEAS files (*.unv)");
307           }
308           break;
309         case 140:
310         case 141:
311           {
312             // export STL
313             /*
314               there must be check on others mesh elements not equal triangles
315             */
316             if (aMesh->NbTriangles() < 1) {
317               SUIT_MessageBox::warn1
318                 (SMESHGUI::desktop(),
319                  QObject::tr("SMESH_WRN_WARNING"),
320                  QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
321                  QObject::tr("SMESH_BUT_OK"));
322               return;
323             }
324             if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
325               int aRet = SUIT_MessageBox::warn2
326                 (SMESHGUI::desktop(),
327                  QObject::tr("SMESH_WRN_WARNING"),
328                  QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
329                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
330                  0, 1, 0);
331               if (aRet)
332                 return;
333             }
334
335             aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
336             aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
337           }
338           break;
339         default:
340           return;
341         }
342
343         QString aFilename;
344         SMESH::MED_VERSION aFormat;
345         // Init the parameter with the default value
346         bool aIsASCII_STL = true;
347         bool toCreateGroups = false;
348         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
349         if ( resMgr )
350           toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
351
352         if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
353
354           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
355
356         else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
357           QStringList filters;
358           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
359           for ( ; it != aFilterMapSTL.end(); ++it )
360             filters.push_back( it.key() );
361
362           SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
363           fd->setCaption( aTitle );
364           fd->setFilters( filters );
365           fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
366           bool is_ok = false;
367           while (!is_ok) {
368             fd->exec();
369             aFilename = fd->selectedFile();
370             aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
371             is_ok = true;
372           }
373           delete fd;
374         }
375         else {
376           QStringList filters;
377           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
378           for ( ; it != aFilterMap.end(); ++it )
379             filters.push_back( it.key() );
380
381           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
382           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
383             ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
384           fd->setCaption( aTitle );
385           fd->setFilters( filters );
386           fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
387           fd->SetChecked(toCreateGroups);
388           bool is_ok = false;
389           while (!is_ok) {
390             fd->exec();
391             aFilename = fd->selectedFile();
392             aFormat = aFilterMap[fd->selectedFilter()];
393             is_ok = true;
394             if ( !aFilename.isEmpty()
395                  && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
396                  && aFormat==SMESH::MED_V2_1) {
397               int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
398                                                 QObject::tr("SMESH_WRN_WARNING"),
399                                                 QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
400                                                 QObject::tr("SMESH_BUT_YES"),
401                                                 QObject::tr("SMESH_BUT_NO"),
402                                                 0,1,0);
403               if (aRet) {
404                 is_ok = false;
405               }
406             }
407           }
408           toCreateGroups = fd->IsChecked();
409           delete fd;
410         }
411         if ( !aFilename.isEmpty() ) {
412           // Check whether the file already exists and delete it if yes
413           QFile aFile( aFilename );
414           if ( aFile.exists() )
415             aFile.remove();
416           SUIT_OverrideCursor wc;
417
418           try {
419             bool Renumber = false ;
420             // PAL 14172  : Check of we have to renumber or not from the preferences before export
421             if (resMgr)
422               Renumber= resMgr->booleanValue("SMESH","renumbering");
423             if (Renumber){
424               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
425               aMeshEditor->RenumberNodes();
426               aMeshEditor->RenumberElements();
427               if ( SMESHGUI::automaticUpdate() )
428                 SMESH::UpdateView();
429               }
430             switch ( theCommandID ) {
431             case 125:
432             case 122:
433               aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
434               break;
435             case 124:
436             case 121:
437               aMesh->ExportDAT( aFilename.latin1() );
438               break;
439             case 126:
440             case 123:
441               aMesh->ExportUNV( aFilename.latin1() );
442               break;
443             case 140:
444             case 141:
445               aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
446               break;
447             default:
448               break;
449             }
450           }
451           catch (const SALOME::SALOME_Exception& S_ex){
452             wc.suspend();
453             SUIT_MessageBox::warn1(SMESHGUI::desktop(),
454                                     QObject::tr("SMESH_WRN_WARNING"),
455                                     QObject::tr("SMESH_EXPORT_FAILED"),
456                                     QObject::tr("SMESH_BUT_OK"));
457             wc.resume();
458           }
459         }
460       }
461     }
462   }
463
464   inline void InverseEntityMode(unsigned int& theOutputMode,
465                                 unsigned int theMode)
466   {
467     bool anIsNotPresent = ~theOutputMode & theMode;
468     if(anIsNotPresent)
469       theOutputMode |= theMode;
470     else
471       theOutputMode &= ~theMode;
472   }
473
474   void SetDisplayEntity(int theCommandID){
475     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
476     SALOME_ListIO selected;
477     if( aSel )
478       aSel->selectedObjects( selected );
479
480     if(selected.Extent() >= 1){
481       SALOME_ListIteratorOfListIO It( selected );
482       for(; It.More(); It.Next()){
483         Handle(SALOME_InteractiveObject) IObject = It.Value();
484         if(IObject->hasEntry()){
485           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
486             unsigned int aMode = anActor->GetEntityMode();
487             switch(theCommandID){
488             case 217:
489               InverseEntityMode(aMode,SMESH_Actor::eEdges);
490               break;
491             case 218:
492               InverseEntityMode(aMode,SMESH_Actor::eFaces);
493               break;
494             case 219:
495               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
496               break;
497             case 220:
498               aMode = SMESH_Actor::eAllEntity;
499               break;
500             }
501             if(aMode)
502               anActor->SetEntityMode(aMode);
503           }
504         }
505       }
506     }
507   }
508
509   void AutoColor(){
510     SALOME_ListIO selected;
511     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
512     if( !app )
513       return;
514
515     LightApp_SelectionMgr* aSel = app->selectionMgr();
516     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
517     if( !aSel || !appStudy )
518       return;
519
520     aSel->selectedObjects( selected );
521     if( selected.IsEmpty() )
522       return;
523
524     Handle(SALOME_InteractiveObject) anIObject = selected.First();
525
526     _PTR(Study) aStudy = appStudy->studyDS();
527     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
528     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
529     if( aMainObject->_is_nil() )
530       return;
531
532     aMainObject->SetAutoColor( true );
533
534     QValueList<SALOMEDS::Color> aReservedColors;
535
536     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
537     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
538     {
539       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
540       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
541
542       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
543       aGroupObject->SetColor( aColor );
544       aReservedColors.append( aColor );
545
546       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
547       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
548       {
549         if( aGroupObject->GetType() == SMESH::NODE )
550           anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
551         else if( aGroupObject->GetType() == SMESH::EDGE )
552           anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
553         else
554           anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
555       }
556     }
557
558     SMESH::RepaintCurrentView();
559   }
560
561   void DisableAutoColor(){
562     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
563     SALOME_ListIO selected;
564     if( aSel )
565       aSel->selectedObjects( selected );
566
567     if(selected.Extent()){
568       Handle(SALOME_InteractiveObject) anIObject = selected.First();
569       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
570       if ( !aMesh->_is_nil() ) {
571         aMesh->SetAutoColor( false );
572       }
573     }
574   }
575
576   void SetDisplayMode(int theCommandID){
577     SALOME_ListIO selected;
578     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
579     if( !app )
580       return;
581
582     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
583     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
584     if( !aSel || !appStudy )
585       return;
586
587     _PTR(Study) aStudy = appStudy->studyDS();
588
589     aSel->selectedObjects( selected );
590
591     if(selected.Extent() >= 1){
592       switch(theCommandID){
593       case 1134:{
594         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
595         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
596         return;
597       }
598       case 1133:{
599         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
600         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
601         return;
602       }}
603       SALOME_ListIteratorOfListIO It( selected );
604       for(; It.More(); It.Next()){
605         Handle(SALOME_InteractiveObject) IObject = It.Value();
606         if(IObject->hasEntry()){
607           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
608             switch(theCommandID){
609             case 211:
610               anActor->SetRepresentation(SMESH_Actor::eEdge);
611               break;
612             case 212:
613               anActor->SetRepresentation(SMESH_Actor::eSurface);
614               break;
615             case 213:
616               if(anActor->IsShrunk())
617                 anActor->UnShrink();
618               else
619                 anActor->SetShrink();
620               break;
621             case 215:
622               anActor->SetRepresentation(SMESH_Actor::ePoint);
623               break;
624             case 1132:{
625               vtkFloatingPointType color[3];
626               anActor->GetSufaceColor(color[0], color[1], color[2]);
627               int c0 = int (color[0] * 255);
628               int c1 = int (color[1] * 255);
629               int c2 = int (color[2] * 255);
630               QColor c(c0, c1, c2);
631
632               vtkFloatingPointType edgecolor[3];
633               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
634               c0 = int (edgecolor[0] * 255);
635               c1 = int (edgecolor[1] * 255);
636               c2 = int (edgecolor[2] * 255);
637               QColor e(c0, c1, c2);
638
639               vtkFloatingPointType backfacecolor[3];
640               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
641               c0 = int (backfacecolor[0] * 255);
642               c1 = int (backfacecolor[1] * 255);
643               c2 = int (backfacecolor[2] * 255);
644               QColor b(c0, c1, c2);
645
646               vtkFloatingPointType nodecolor[3];
647               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
648               c0 = int (nodecolor[0] * 255);
649               c1 = int (nodecolor[1] * 255);
650               c2 = int (nodecolor[2] * 255);
651               QColor n(c0, c1, c2);
652
653               int Edgewidth = (int)anActor->GetLineWidth();
654               if(Edgewidth == 0)
655                 Edgewidth = 1;
656               int intValue = int(anActor->GetNodeSize());
657               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
658
659               SMESHGUI_Preferences_ColorDlg *aDlg =
660                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
661               aDlg->SetColor(1, c);
662               aDlg->SetColor(2, e);
663               aDlg->SetColor(3, n);
664               aDlg->SetColor(4, b);
665               aDlg->SetIntValue(1, Edgewidth);
666               aDlg->SetIntValue(2, intValue);
667               aDlg->SetIntValue(3, int(Shrink*100.));
668               if(aDlg->exec()){
669                 QColor color = aDlg->GetColor(1);
670                 QColor edgecolor = aDlg->GetColor(2);
671                 QColor nodecolor = aDlg->GetColor(3);
672                 QColor backfacecolor = aDlg->GetColor(4);
673                 /* actor color and backface color */
674                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
675                                         vtkFloatingPointType (color.green()) / 255.,
676                                         vtkFloatingPointType (color.blue()) / 255.);
677                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
678                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
679                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
680
681                 /* edge color */
682                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
683                                       vtkFloatingPointType (edgecolor.green()) / 255.,
684                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
685
686                 /* Shrink factor and size edges */
687                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
688                 anActor->SetLineWidth(aDlg->GetIntValue(1));
689
690                 /* Nodes color and size */
691                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
692                                       vtkFloatingPointType (nodecolor.green()) / 255.,
693                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
694                 anActor->SetNodeSize(aDlg->GetIntValue(2));
695
696                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
697                 if( !aGroupObject->_is_nil() )
698                 {
699                   SALOMEDS::Color aColor;
700                   aColor.R = (float)color.red() / 255.0;
701                   aColor.G = (float)color.green() / 255.0;
702                   aColor.B = (float)color.blue() / 255.0;
703                   aGroupObject->SetColor( aColor );
704                 }
705
706                 delete aDlg;
707               }
708               break;
709             }}
710           }
711         }
712       }
713       SMESH::RepaintCurrentView();
714     }
715   }
716
717   void Control( int theCommandID )
718   {
719     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
720     SALOME_ListIO selected;
721     if( aSel )
722       aSel->selectedObjects( selected );
723
724     if( !selected.IsEmpty() ){
725       Handle(SALOME_InteractiveObject) anIO = selected.First();
726       if(!anIO.IsNull()){
727         QString aTitle;
728         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
729         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
730           switch ( theCommandID ){
731           case 6001:
732             aTitle = QObject::tr( "LENGTH_EDGES" );
733             aControl = SMESH_Actor::eLength;
734             break;
735           case 6018:
736             aTitle = QObject::tr( "LENGTH2D_EDGES" );
737             aControl = SMESH_Actor::eLength2D;
738             break;
739           case 6002:
740             aTitle = QObject::tr( "FREE_EDGES" );
741             aControl = SMESH_Actor::eFreeEdges;
742             break;
743           case 6003:
744             aTitle = QObject::tr( "FREE_BORDERS" );
745             aControl = SMESH_Actor::eFreeBorders;
746             break;
747           case 6004:
748             aTitle = QObject::tr( "MULTI_BORDERS" );
749             aControl = SMESH_Actor::eMultiConnection;
750             break;
751           case 6019:
752             aTitle = QObject::tr( "MULTI2D_BORDERS" );
753             aControl = SMESH_Actor::eMultiConnection2D;
754             break;
755           case 6011:
756             aTitle = QObject::tr( "AREA_ELEMENTS" );
757             aControl = SMESH_Actor::eArea;
758             break;
759           case 6012:
760             aTitle = QObject::tr( "TAPER_ELEMENTS" );
761             aControl = SMESH_Actor::eTaper;
762             break;
763           case 6013:
764             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
765             aControl = SMESH_Actor::eAspectRatio;
766             break;
767           case 6017:
768             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
769             aControl = SMESH_Actor::eAspectRatio3D;
770             break;
771           case 6014:
772             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
773             aControl = SMESH_Actor::eMinimumAngle;
774             break;
775           case 6015:
776             aTitle = QObject::tr( "WARP_ELEMENTS" );
777             aControl = SMESH_Actor::eWarping;
778             break;
779           case 6016:
780             aTitle = QObject::tr( "SKEW_ELEMENTS" );
781             aControl = SMESH_Actor::eSkew;
782             break;
783           case 6009:
784             aTitle = QObject::tr( "SMESH_VOLUME" );
785             aControl = SMESH_Actor::eVolume3D;
786             break;
787           }
788           anActor->SetControlMode(aControl);
789           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
790           SMESH::RepaintCurrentView();
791         }
792       }
793     }
794   }
795
796
797   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
798                    MeshObjectType                           theType,
799                    const QString                            theInTypeName,
800                    QString &                                theOutTypeName)
801   {
802     SMESH_TypeFilter aTypeFilter( theType );
803     QString entry;
804     if( !theIO.IsNull() )
805     {
806       entry = theIO->getEntry();
807       LightApp_DataOwner owner( entry );
808       if ( aTypeFilter.isOk( &owner )) {
809         theOutTypeName = theInTypeName;
810         return true;
811       }
812     }
813     return false;
814   }
815
816
817   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
818   {
819     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
820     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
821     if (aSObj) {
822       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
823       CORBA::String_var anID = aSComp->GetID().c_str();
824       if (!strcmp(anID.in(),theIO->getEntry()))
825         return "Component";
826     }
827
828     QString aTypeName;
829     if (
830         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
831         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
832         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
833         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
834         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
835         )
836       return aTypeName;
837
838     return "NoType";
839   }
840
841
842   QString CheckHomogeneousSelection()
843   {
844     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
845     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
846     SALOME_ListIO selected;
847     if( aSel )
848       aSel->selectedObjects( selected );
849
850     QString RefType = CheckTypeObject(selected.First());
851     SALOME_ListIteratorOfListIO It(selected);
852     for (; It.More(); It.Next())
853       {
854         Handle(SALOME_InteractiveObject) IObject = It.Value();
855         QString Type = CheckTypeObject(IObject);
856         if (Type.compare(RefType) != 0)
857           return "Heterogeneous Selection";
858       }
859
860     return RefType;
861   }
862
863
864   void SMESHGUI::OnEditDelete()
865   {
866     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
867     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
868     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
869
870     QString aParentComponent = QString::null;
871     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
872     {
873       QString cur = anIt.Value()->getComponentDataType();
874       if( aParentComponent.isNull() )
875         aParentComponent = cur;
876       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
877         aParentComponent = "";
878     }
879
880     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
881       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
882                               QObject::tr("ERR_ERROR"),
883                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
884                               QObject::tr("BUT_OK") );
885       return;
886     }
887     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
888     if (SUIT_MessageBox::warn2
889         (SMESHGUI::desktop(),
890          QObject::tr("SMESH_WRN_WARNING"),
891          QObject::tr("SMESH_REALLY_DELETE"),
892          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
893       return;
894
895     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
896     SUIT_ViewManager* vm = anApp->activeViewManager();
897     int nbSf = vm->getViewsCount();
898
899     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
900     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
901     _PTR(GenericAttribute) anAttr;
902     _PTR(AttributeIOR) anIOR;
903
904     SALOME_ListIteratorOfListIO It(selected);
905
906     aStudyBuilder->NewCommand();  // There is a transaction
907     for(; It.More(); It.Next()){ // loop on selected IO's
908       Handle(SALOME_InteractiveObject) IObject = It.Value();
909       if(IObject->hasEntry()) {
910         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
911
912         // disable removal of "SMESH" component object
913         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
914           anIOR = anAttr;
915           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
916             continue;
917         }
918
919         // put the whole hierarchy of sub-objects of the selected SO into a list and
920         // then treat them all starting from the deepest objects (at list back)
921
922         list< _PTR(SObject) > listSO;
923         listSO.push_back( aSO );
924         list< _PTR(SObject) >::iterator itSO = listSO.begin();
925         for ( ; itSO != listSO.end(); ++itSO ) {
926           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
927           for (it->InitEx(false); it->More(); it->Next())
928             listSO.push_back( it->Value() );
929         }
930
931         // treat SO's in the list starting from the back
932
933         list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
934         for ( ; ritSO != listSO.rend(); ++ritSO ) {
935           _PTR(SObject) SO = *ritSO;
936           if ( !SO ) continue;
937           string anEntry = SO->GetID();
938
939           /** Erase graphical object **/
940           if(SO->FindAttribute(anAttr, "AttributeIOR")){
941             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
942             for(int i = 0; i < nbSf; i++){
943               SUIT_ViewWindow *sf = aViews[i];
944               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
945                 SMESH::RemoveActor(sf,anActor);
946               }
947             }
948           }
949
950           /** Remove an object from data structures **/
951           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
952           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
953           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
954             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
955             aMesh->RemoveGroup( aGroup );
956           }
957           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
958             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
959             aMesh->RemoveSubMesh( aSubMesh );
960
961             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
962             if (aMeshSO)
963               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
964           }
965           else {
966             IObject = new SALOME_InteractiveObject
967               ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
968             QString objType = CheckTypeObject(IObject);
969             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
970               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
971               aStudyBuilder->RemoveObjectWithChildren( SO );
972             }
973             else {// default action: remove SObject from the study
974               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
975               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
976               //op->start();
977               aStudyBuilder->RemoveObjectWithChildren( SO );
978               //op->finish();
979             }
980           }
981         } /* listSO back loop */
982       } /* IObject->hasEntry() */
983     } /* more/next */
984     aStudyBuilder->CommitCommand();
985
986     /* Clear any previous selection */
987     SALOME_ListIO l1;
988     aSel->setSelectedObjects( l1 );
989
990     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
991   }
992 //}
993
994 extern "C" {
995   SMESHGUI_EXPORT CAM_Module* createModule()
996   {
997     return new SMESHGUI();
998   }
999 }
1000
1001 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1002
1003 //=============================================================================
1004 /*!
1005  *
1006  */
1007 //=============================================================================
1008 SMESHGUI::SMESHGUI() :
1009 SalomeApp_Module( "SMESH" )
1010 {
1011   if ( CORBA::is_nil( myComponentSMESH ) )
1012   {
1013     CORBA::Boolean anIsEmbeddedMode;
1014     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1015   }
1016
1017   myActiveDialogBox = 0;
1018   myFilterLibraryDlg = 0;
1019   myState = -1;
1020   myDisplayer = 0;
1021
1022   SMESH::GetFilterManager();
1023   SMESH::GetPattern();
1024
1025   /* load resources for all available meshers */
1026   SMESH::InitAvailableHypotheses();
1027 }
1028
1029 //=============================================================================
1030 /*!
1031  *
1032  */
1033 //=============================================================================
1034 SMESHGUI::~SMESHGUI()
1035 {
1036   SMESH::GetFilterManager()->Destroy();
1037   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1038 }
1039
1040 //=============================================================================
1041 /*!
1042  *
1043  */
1044 //=============================================================================
1045 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1046 {
1047   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1048   if( anApp )
1049     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1050   else
1051     return 0;
1052 }
1053
1054 bool SMESHGUI::automaticUpdate()
1055 {
1056   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1057   if ( !resMgr )
1058     return false;
1059
1060   return resMgr->booleanValue( "SMESH", "auto_update", false );
1061 }
1062
1063 //=============================================================================
1064 /*!
1065  *
1066  */
1067 //=============================================================================
1068 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1069 {
1070   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1071 }
1072
1073 //=============================================================================
1074 /*!
1075  *
1076  */
1077 //=============================================================================
1078 SMESHGUI* SMESHGUI::GetSMESHGUI()
1079 {
1080   SMESHGUI* smeshMod = 0;
1081   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1082   if ( app )
1083   {
1084     CAM_Module* module = app->module( "Mesh" );
1085     smeshMod = dynamic_cast<SMESHGUI*>( module );
1086   }
1087
1088   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1089   {
1090     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1091     if ( study )
1092     {
1093       _PTR(Study) aStudy = study->studyDS();
1094       if ( aStudy )
1095         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1096     }
1097   }
1098
1099   return smeshMod;
1100 }
1101
1102 extern "C"
1103 {
1104   Standard_EXPORT SMESHGUI* GetComponentGUI()
1105   {
1106     return SMESHGUI::GetSMESHGUI();
1107   }
1108 }
1109
1110 //=============================================================================
1111 /*!
1112  *
1113  */
1114 //=============================================================================
1115 void SMESHGUI::SetState(int aState)
1116 {
1117   myState = aState;
1118 }
1119
1120 //=============================================================================
1121 /*!
1122  *
1123  */
1124 //=============================================================================
1125 void SMESHGUI::ResetState()
1126 {
1127   myState = -1;
1128 }
1129
1130 //=============================================================================
1131 /*!
1132  *
1133  */
1134 //=============================================================================
1135 void SMESHGUI::EmitSignalDeactivateDialog()
1136 {
1137   emit SignalDeactivateActiveDialog();
1138 }
1139
1140 //=============================================================================
1141 /*!
1142  *
1143  */
1144 //=============================================================================
1145 void SMESHGUI::EmitSignalStudyFrameChanged()
1146 {
1147   emit SignalStudyFrameChanged();
1148 }
1149
1150 //=============================================================================
1151 /*!
1152  *
1153  */
1154 //=============================================================================
1155 void SMESHGUI::EmitSignalCloseAllDialogs()
1156 {
1157   emit SignalCloseAllDialogs();
1158 }
1159
1160 //=============================================================================
1161 /*!
1162  *
1163  */
1164 //=============================================================================
1165 QDialog *SMESHGUI::GetActiveDialogBox()
1166 {
1167   return myActiveDialogBox;
1168 }
1169
1170 //=============================================================================
1171 /*!
1172  *
1173  */
1174 //=============================================================================
1175 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1176 {
1177   myActiveDialogBox = (QDialog *) aDlg;
1178   return;
1179 }
1180
1181 //=============================================================================
1182 /*!
1183  *
1184  */
1185 //=============================================================================
1186 SUIT_Desktop* SMESHGUI::desktop()
1187 {
1188   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1189   if( app )
1190     return app->desktop();
1191   else
1192     return 0;
1193 }
1194
1195 //=============================================================================
1196 /*!
1197  *
1198  */
1199 //=============================================================================
1200 SalomeApp_Study* SMESHGUI::activeStudy()
1201 {
1202   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1203   if( app )
1204     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1205   else
1206     return NULL;
1207 }
1208
1209 //=============================================================================
1210 /*!
1211  *
1212  */
1213 //=============================================================================
1214 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1215 {
1216   /* Here the position is on the bottom right corner - 10 */
1217   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1218   aDlg->adjustSize();
1219   SUIT_Desktop *PP = desktop();
1220   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1221   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1222   return true;
1223 }
1224
1225 //=============================================================================
1226 /*!
1227  *
1228  */
1229 //=============================================================================
1230 static int isStudyLocked(_PTR(Study) theStudy){
1231   return theStudy->GetProperties()->IsLocked();
1232 }
1233
1234 static bool checkLock(_PTR(Study) theStudy) {
1235   if (isStudyLocked(theStudy)) {
1236     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1237                            QObject::tr("WRN_WARNING"),
1238                            QObject::tr("WRN_STUDY_LOCKED"),
1239                            QObject::tr("BUT_OK") );
1240     return true;
1241   }
1242   return false;
1243 }
1244
1245 //=======================================================================
1246 //function : CheckActiveStudyLocked
1247 //purpose  :
1248 //=======================================================================
1249
1250 bool SMESHGUI::isActiveStudyLocked()
1251 {
1252   _PTR(Study) aStudy = activeStudy()->studyDS();
1253   return checkLock( aStudy );
1254 }
1255
1256 //=============================================================================
1257 /*!
1258  *
1259  */
1260 //=============================================================================
1261 bool SMESHGUI::OnGUIEvent( int theCommandID )
1262 {
1263   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1264   if( !anApp )
1265     return false;
1266
1267   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1268   SUIT_ResourceMgr* mgr = resourceMgr();
1269   if( !mgr )
1270     return false;
1271
1272   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1273     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1274   }
1275
1276   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1277   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1278
1279   //QAction* act = action( theCommandID );
1280
1281   switch (theCommandID) {
1282   case 33:                                      // DELETE
1283     if(checkLock(aStudy)) break;
1284     OnEditDelete();
1285     break;
1286
1287   case 113:                                     // IMPORT
1288   case 112:
1289   case 111:
1290     {
1291       if(checkLock(aStudy)) break;
1292       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1293       break;
1294     }
1295
1296   case 150:    //MED FILE INFORMATION
1297     {
1298       SALOME_ListIO selected;
1299       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1300       if( aSel )
1301         aSel->selectedObjects( selected );
1302       if( selected.Extent() )
1303       {
1304         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1305         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1306         if ( !aMesh->_is_nil() )
1307         {
1308           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1309           dlg.exec();
1310         }
1311       }
1312       break;
1313     }
1314   case 122:                                     // EXPORT MED
1315   case 121:
1316   case 123:
1317   case 124:
1318   case 125:
1319   case 126:
1320   case 140:
1321   case 141:
1322     {
1323       ::ExportMeshToFile(theCommandID);
1324       break;
1325     }
1326
1327   case 200:                                     // SCALAR BAR
1328     {
1329       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1330       SALOME_ListIO selected;
1331       if( aSel )
1332         aSel->selectedObjects( selected );
1333
1334       if( selected.Extent() ) {
1335         Handle(SALOME_InteractiveObject) anIO = selected.First();
1336         if( anIO->hasEntry() ) {
1337           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1338             anActor->SetControlMode( SMESH_Actor::eNone );
1339           }
1340         }
1341       }
1342       break;
1343     }
1344   case 201:
1345     {
1346       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1347       break;
1348     }
1349
1350     // Auto-color
1351   case 1136:
1352     ::AutoColor();
1353   break;
1354
1355   case 1137:
1356     ::DisableAutoColor();
1357   break;
1358
1359   case 1134: // Clipping
1360   case 1133: // Tranparency
1361   case 1132: // Colors / Size
1362
1363     // Display Mode
1364   case 215: // Nodes
1365   case 213: // Nodes
1366   case 212: // Nodes
1367   case 211: // Nodes
1368     ::SetDisplayMode(theCommandID);
1369   break;
1370
1371     // Display Entity
1372   case 217: // Edges
1373   case 218: // Faces
1374   case 219: // Volumes
1375   case 220: // All Entity
1376     ::SetDisplayEntity(theCommandID);
1377   break;
1378
1379   case 214:                                     // UPDATE
1380     {
1381       if(checkLock(aStudy)) break;
1382       try {
1383 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1384         OCC_CATCH_SIGNALS;
1385 #endif
1386         SMESH::UpdateView();
1387       }
1388       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1389         SMESH::OnVisuException();
1390       }
1391       catch (...) { // PAL16774 (Crash after display of many groups)
1392         SMESH::OnVisuException();
1393       }
1394
1395       SALOME_ListIO l;
1396       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1397       aSel->selectedObjects( l );
1398       aSel->setSelectedObjects( l );
1399       break;
1400     }
1401
1402   case 300:                                     // ERASE
1403   case 301:                                     // DISPLAY
1404   case 302:                                     // DISPLAY ONLY
1405     {
1406       SMESH::EDisplaing anAction;
1407       switch (theCommandID) {
1408       case 300: anAction = SMESH::eErase; break;
1409       case 301: anAction = SMESH::eDisplay; break;
1410       case 302: anAction = SMESH::eDisplayOnly; break;
1411       }
1412
1413       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1414       SALOME_ListIO sel_objects, to_process;
1415       if (aSel)
1416         aSel->selectedObjects( sel_objects );
1417
1418       if( theCommandID==302 )
1419         startOperation( myEraseAll );
1420
1421       extractContainers( sel_objects, to_process );
1422
1423       try {
1424 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1425         OCC_CATCH_SIGNALS;
1426 #endif
1427         if (vtkwnd) {
1428           SALOME_ListIteratorOfListIO It( to_process );
1429           for (; It.More(); It.Next()) {
1430             Handle(SALOME_InteractiveObject) IOS = It.Value();
1431             if (IOS->hasEntry()) {
1432               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1433                 break; // PAL16774 (Crash after display of many groups)
1434               if (anAction == SMESH::eDisplayOnly)
1435                 anAction = SMESH::eDisplay;
1436             }
1437           }
1438         }
1439
1440         // PAL13338 + PAL15161 -->
1441         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1442           SMESH::UpdateView();
1443         // PAL13338 + PAL15161 <--
1444       }
1445       catch (...) { // PAL16774 (Crash after display of many groups)
1446         SMESH::OnVisuException();
1447       }
1448
1449       if (anAction == SMESH::eErase) {
1450         SALOME_ListIO l1;
1451         aSel->setSelectedObjects( l1 );
1452       }
1453       else
1454         aSel->setSelectedObjects( to_process );
1455
1456       break;
1457     }
1458
1459   case 400:                                     // NODES
1460     {
1461       if(checkLock(aStudy)) break;
1462
1463       if ( vtkwnd ) {
1464         EmitSignalDeactivateDialog();
1465
1466         new SMESHGUI_NodesDlg(this);
1467       }
1468       else {
1469         SUIT_MessageBox::warn1(desktop(),
1470                               tr("SMESH_WRN_WARNING"),
1471                               tr("SMESH_WRN_VIEWER_VTK"),
1472                               tr("SMESH_BUT_OK"));
1473       }
1474       break;
1475     }
1476
1477   case 2151:  // FILTER
1478   {
1479     if ( vtkwnd )
1480     {
1481       EmitSignalDeactivateDialog();
1482       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1483     }
1484     break;
1485   }
1486
1487   case 406:                                     // MOVE NODE
1488     {
1489       if ( !vtkwnd )
1490       {
1491         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1492           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1493         break;
1494       }
1495
1496       if(checkLock(aStudy)) break;
1497       new SMESHGUI_MoveNodesDlg(this);
1498       break;
1499     }
1500
1501   case 701:                                     // COMPUTE MESH
1502     {
1503       if (checkLock(aStudy)) break;
1504
1505       startOperation( 701 );
1506     }
1507     break;
1508
1509   case 702:  // Create mesh
1510     startOperation( 702 );
1511     break;
1512   case 703:  // Create sub-mesh
1513     startOperation( 703 );
1514     break;
1515   case 704: // Edit mesh/sub-mesh
1516     startOperation( 704 );
1517     break;
1518   case 710: // Build compound mesh
1519     {
1520       if (checkLock(aStudy)) break;
1521       EmitSignalDeactivateDialog();
1522       new SMESHGUI_BuildCompoundDlg( this );
1523     }
1524     break;
1525   case 407: // DIAGONAL INVERSION
1526   case 408: // Delete diagonal
1527     {
1528       if ( !vtkwnd )
1529       {
1530         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1531           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1532         break;
1533       }
1534
1535       if ( checkLock( aStudy ) )
1536         break;
1537
1538       /*Standard_Boolean aRes;
1539       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1540       if ( aMesh->_is_nil() )
1541       {
1542         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1543           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1544         break;
1545       }
1546       */
1547       EmitSignalDeactivateDialog();
1548       if ( theCommandID == 407 )
1549         new SMESHGUI_TrianglesInversionDlg(this);
1550       else
1551         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1552       break;
1553     }
1554     case 409: // Change orientation
1555     case 410: // Union of triangles
1556     case 411: // Cutting of quadrangles
1557     {
1558       if ( !vtkwnd )
1559       {
1560         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1561           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1562         break;
1563       }
1564
1565       if ( checkLock( aStudy ) )
1566         break;
1567
1568       EmitSignalDeactivateDialog();
1569       SMESHGUI_MultiEditDlg* aDlg = NULL;
1570       if ( theCommandID == 409 )
1571         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1572       else if ( theCommandID == 410 )
1573         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1574       else
1575         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1576
1577       aDlg->show();
1578       break;
1579     }
1580   case 412: // Smoothing
1581     {
1582       if(checkLock(aStudy)) break;
1583       if( vtkwnd ) {
1584         EmitSignalDeactivateDialog();
1585         new SMESHGUI_SmoothingDlg( this );
1586       }
1587       else {
1588         SUIT_MessageBox::warn1(desktop(),
1589                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1590                               tr("SMESH_BUT_OK"));
1591       }
1592       break;
1593     }
1594   case 413: // Extrusion
1595     {
1596       if (checkLock(aStudy)) break;
1597       if (vtkwnd) {
1598         EmitSignalDeactivateDialog();
1599         new SMESHGUI_ExtrusionDlg ( this );
1600       } else {
1601         SUIT_MessageBox::warn1(desktop(),
1602                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1603                                tr("SMESH_BUT_OK"));
1604       }
1605       break;
1606     }
1607   case 414: // Revolution
1608     {
1609       if(checkLock(aStudy)) break;
1610       if( vtkwnd ) {
1611         EmitSignalDeactivateDialog();
1612         new SMESHGUI_RevolutionDlg( this );
1613       }
1614       else {
1615         SUIT_MessageBox::warn1(desktop(),
1616                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1617                               tr("SMESH_BUT_OK"));
1618       }
1619       break;
1620     }
1621   case 415: // Pattern mapping
1622     {
1623       if ( checkLock( aStudy ) )
1624         break;
1625       if ( vtkwnd )
1626       {
1627         EmitSignalDeactivateDialog();
1628         new SMESHGUI_MeshPatternDlg( this );
1629       }
1630       else {
1631         SUIT_MessageBox::warn1(desktop(),
1632                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1633                               tr("SMESH_BUT_OK"));
1634       }
1635       break;
1636     }
1637   case 416: // Extrusion along a path
1638     {
1639       if (checkLock(aStudy)) break;
1640       if (vtkwnd) {
1641         EmitSignalDeactivateDialog();
1642         new SMESHGUI_ExtrusionAlongPathDlg( this );
1643       } else {
1644         SUIT_MessageBox::warn1(desktop(),
1645                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1646                                tr("SMESH_BUT_OK"));
1647       }
1648       break;
1649     }
1650   case 417: // Convert mesh to quadratic
1651     {
1652     startOperation( 417 );
1653       /*      if (checkLock(aStudy)) break;
1654       if (vtkwnd) {
1655         EmitSignalDeactivateDialog();
1656         new SMESHGUI_ConvToQuadDlg();
1657       } else {
1658         SUIT_MessageBox::warn1(desktop(),
1659                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1660                                tr("SMESH_BUT_OK"));
1661                                }*/
1662       break;
1663     }
1664   case 801:                                     // CREATE GROUP
1665     {
1666       if ( !vtkwnd )
1667       {
1668         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1669           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1670         break;
1671       }
1672
1673       if(checkLock(aStudy)) break;
1674       EmitSignalDeactivateDialog();
1675       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1676
1677       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1678       SALOME_ListIO selected;
1679       if( aSel )
1680         aSel->selectedObjects( selected );
1681
1682       int nbSel = selected.Extent();
1683       if (nbSel == 1) {
1684         // check if mesh is selected
1685         aMesh = SMESH::GetMeshByIO( selected.First() );
1686       }
1687       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1688       aDlg->show();
1689       break;
1690     }
1691
1692   case 802:                                     // CONSTRUCT GROUP
1693     {
1694       if ( !vtkwnd )
1695       {
1696         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1697           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1698         break;
1699       }
1700
1701       if(checkLock(aStudy)) break;
1702       EmitSignalDeactivateDialog();
1703
1704       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1705       SALOME_ListIO selected;
1706       if( aSel )
1707         aSel->selectedObjects( selected );
1708
1709       int nbSel = selected.Extent();
1710       if (nbSel == 1) {
1711         // check if submesh is selected
1712         Handle(SALOME_InteractiveObject) IObject = selected.First();
1713         if (IObject->hasEntry()) {
1714           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1715           if( aSObj ) {
1716             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1717             if (!aSubMesh->_is_nil()) {
1718               try {
1719                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1720                 // get submesh elements list by types
1721                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1722                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1723                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1724                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1725                 // create group for each type o elements
1726                 QString aName = IObject->getName();
1727                 if (aNodes->length() > 0) {
1728                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1729                   aGroup->Add(aNodes.inout());
1730                 }
1731                 if (aEdges->length() > 0) {
1732                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1733                   aGroup->Add(aEdges.inout());
1734                 }
1735                 if (aFaces->length() > 0) {
1736                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1737                   aGroup->Add(aFaces.inout());
1738                 }
1739                 if (aVolumes->length() > 0) {
1740                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1741                   aGroup->Add(aVolumes.inout());
1742                 }
1743                 updateObjBrowser();
1744
1745               }
1746               catch(const SALOME::SALOME_Exception & S_ex){
1747                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1748               }
1749             }
1750           }
1751         }
1752       }
1753       else if(nbSel==0) {
1754         SUIT_MessageBox::warn1(desktop(),
1755                                tr("SMESH_WRN_WARNING"),
1756                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1757                                tr("SMESH_BUT_OK"));
1758       }
1759       break;
1760     }
1761
1762   case 803:                                     // EDIT GROUP
1763     {
1764       if ( !vtkwnd )
1765       {
1766         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1767           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1768         break;
1769       }
1770
1771       if(checkLock(aStudy)) break;
1772       EmitSignalDeactivateDialog();
1773
1774       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1775       SALOME_ListIO selected;
1776       if( aSel )
1777         aSel->selectedObjects( selected );
1778
1779       SALOME_ListIteratorOfListIO It (selected);
1780       int nbSelectedGroups = 0;
1781       for ( ; It.More(); It.Next() )
1782       {
1783         SMESH::SMESH_GroupBase_var aGroup =
1784           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1785         if (!aGroup->_is_nil()) {
1786           nbSelectedGroups++;
1787           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1788           aDlg->show();
1789         }
1790       }
1791       if (nbSelectedGroups == 0)
1792         {
1793           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1794           aDlg->show();
1795         }
1796       break;
1797     }
1798
1799   case 804:                                     // Add elements to group
1800     {
1801       if(checkLock(aStudy)) break;
1802       if (myState == 800) {
1803         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1804         if (aDlg) aDlg->onAdd();
1805       }
1806       break;
1807     }
1808
1809   case 805:                                     // Remove elements from group
1810     {
1811       if(checkLock(aStudy)) break;
1812       if (myState == 800) {
1813         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1814         if (aDlg) aDlg->onRemove();
1815       }
1816       break;
1817     }
1818
1819     case 810: // Union Groups
1820     case 811: // Intersect groups
1821     case 812: // Cut groups
1822     {
1823       if ( !vtkwnd )
1824       {
1825         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1826           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1827         break;
1828       }
1829
1830       if ( checkLock( aStudy ) )
1831         break;
1832
1833       EmitSignalDeactivateDialog();
1834
1835       int aMode;
1836       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1837       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1838       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1839
1840       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1841       break;
1842     }
1843
1844     case 813: // Delete groups with their contents
1845     {
1846       if ( !vtkwnd )
1847       {
1848         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1849           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1850         break;
1851       }
1852
1853       if ( checkLock( aStudy ) )
1854         break;
1855
1856       EmitSignalDeactivateDialog();
1857
1858       new SMESHGUI_DeleteGroupDlg( this );
1859       break;
1860     }
1861
1862   case 900:                                     // MESH INFOS
1863     {
1864       EmitSignalDeactivateDialog();
1865       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1866       SALOME_ListIO selected;
1867       if( aSel )
1868         aSel->selectedObjects( selected );
1869
1870       if ( selected.Extent() > 1 ) { // a dlg for each IO
1871         SALOME_ListIO IOs;
1872         SALOME_ListIteratorOfListIO It (selected);
1873         for ( ; It.More(); It.Next() ) {
1874           IOs.Clear(); IOs.Append( It.Value() );
1875           aSel->setSelectedObjects( IOs );
1876           new SMESHGUI_MeshInfosDlg(this, "", false);
1877         }
1878         // restore selection
1879         aSel->setSelectedObjects( selected );
1880       }
1881       else
1882         new SMESHGUI_MeshInfosDlg(this, "", false);
1883       break;
1884     }
1885
1886   case 902:                                     // STANDARD MESH INFOS
1887     {
1888       EmitSignalDeactivateDialog();
1889       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1890       SALOME_ListIO selected;
1891       if( aSel )
1892         aSel->selectedObjects( selected );
1893
1894       if ( selected.Extent() > 1 ) { // a dlg for each IO
1895         SALOME_ListIO IOs;
1896         SALOME_ListIteratorOfListIO It (selected);
1897         for ( ; It.More(); It.Next() ) {
1898           IOs.Clear();
1899           IOs.Append( It.Value() );
1900           aSel->setSelectedObjects( IOs );
1901           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1902         }
1903         // restore selection
1904         aSel->setSelectedObjects( selected );
1905       }
1906       else
1907         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1908       break;
1909     }
1910
1911   case 903:                                     // WHAT IS
1912     {
1913       EmitSignalDeactivateDialog();
1914       new SMESHGUI_WhatIsDlg( this, "", false);
1915       break;
1916     }
1917
1918   case 1100:                                    // EDIT HYPOTHESIS
1919     {
1920       if(checkLock(aStudy)) break;
1921
1922       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1923       SALOME_ListIO selected;
1924       if( aSel )
1925         aSel->selectedObjects( selected );
1926
1927       int nbSel = selected.Extent();
1928
1929       if (nbSel == 1) {
1930         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1931         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
1932
1933         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1934         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1935         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1936         if ( !aHypothesis->_is_nil() )
1937         {
1938           CORBA::String_var aHypType = aHypothesis->GetName();
1939           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
1940           if (aCreator)
1941             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
1942           else
1943           {
1944             // report error
1945           }
1946         }
1947       }
1948       updateObjBrowser( true );
1949       break;
1950     }
1951
1952   case 1101:                                    // RENAME
1953     {
1954       if ( checkLock( aStudy ) )
1955         break;
1956
1957       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1958       SALOME_ListIO selected;
1959       if( aSel )
1960         aSel->selectedObjects( selected );
1961
1962       SALOME_ListIteratorOfListIO It( selected );
1963       for ( ; It.More(); It.Next() )
1964       {
1965         Handle(SALOME_InteractiveObject) IObject = It.Value();
1966         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
1967         _PTR(GenericAttribute) anAttr;
1968         _PTR(AttributeName) aName;
1969         if ( obj )
1970         {
1971           if ( obj->FindAttribute(anAttr, "AttributeName") )
1972           {
1973             aName = anAttr;
1974             QString newName = QString(aName->Value().c_str());
1975             newName = LightApp_NameDlg::getName(desktop(), newName);
1976             if ( !newName.isEmpty() )
1977             {
1978               //old source: aStudy->renameIObject( IObject, newName );
1979               aName->SetValue( newName.latin1() );
1980
1981               // if current object is group update group's name
1982               SMESH::SMESH_GroupBase_var aGroup =
1983                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1984               if (!aGroup->_is_nil() )
1985                 aGroup->SetName( newName.latin1() );
1986
1987               updateObjBrowser();
1988             }
1989           }
1990         }
1991       }
1992       break;
1993     }
1994
1995   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1996     {
1997       if(checkLock(aStudy)) break;
1998       SUIT_OverrideCursor wc;
1999
2000       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2001       SALOME_ListIO selected;
2002       if( aSel )
2003         aSel->selectedObjects( selected, QString::null, false );
2004
2005       SALOME_ListIteratorOfListIO It(selected);
2006       for (int i = 0; It.More(); It.Next(), i++) {
2007         Handle(SALOME_InteractiveObject) IObject = It.Value();
2008         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2009       }
2010       SALOME_ListIO l1;
2011       aSel->setSelectedObjects( l1 );
2012       updateObjBrowser();
2013       break;
2014     }
2015
2016   case 401:                                     // GEOM::EDGE
2017   case 4021:                                    // TRIANGLE
2018   case 4022:                                    // QUAD
2019   case 4023:                                    // POLYGON
2020   case 4031:                                    // TETRA
2021   case 4032:                                    // HEXA
2022     {
2023       if(checkLock(aStudy)) break;
2024       if ( vtkwnd ) {
2025         EmitSignalDeactivateDialog();
2026         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2027         int                 nbNodes = 2;
2028         switch (theCommandID) {
2029         case 4021:                                      // TRIANGLE
2030           type = SMDSAbs_Face; nbNodes = 3; break;
2031         case 4022:                                      // QUAD
2032           type = SMDSAbs_Face; nbNodes = 4; break;
2033         case 4031:                                      // TETRA
2034           type = SMDSAbs_Volume; nbNodes = 4; break;
2035         case 4023:                                      // POLYGON
2036           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2037         case 4032:                                      // HEXA
2038           type = SMDSAbs_Volume; nbNodes = 8; break;
2039         case 4033:                                      // POLYHEDRE
2040           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2041         default:;
2042         }
2043         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2044       }
2045       else {
2046         SUIT_MessageBox::warn1(desktop(),
2047                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2048                               tr("SMESH_BUT_OK"));
2049       }
2050       break;
2051     }
2052   case 4033:                                    // POLYHEDRON
2053     {
2054       if(checkLock(aStudy)) break;
2055       if ( vtkwnd ) {
2056         EmitSignalDeactivateDialog();
2057         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2058       }
2059       else {
2060         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2061                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2062                               tr("SMESH_BUT_OK"));
2063       }
2064       break;
2065     }
2066   case 4034:     // QUADRATIC EDGE
2067   case 4035:     // QUADRATIC TRIANGLE
2068   case 4036:     // QUADRATIC QUADRANGLE
2069   case 4037:     // QUADRATIC TETRAHEDRON
2070   case 4038:     // QUADRATIC PYRAMID
2071   case 4039:     // QUADRATIC PENTAHEDRON
2072   case 4040:     // QUADRATIC HEXAHEDRON
2073     {
2074       if(checkLock(aStudy)) break;
2075       if ( vtkwnd ) {
2076         EmitSignalDeactivateDialog();
2077         int type;
2078
2079         switch (theCommandID) {
2080         case 4034:
2081           type = QUAD_EDGE; break;
2082         case 4035:
2083           type = QUAD_TRIANGLE; break;
2084         case 4036:
2085           type = QUAD_QUADRANGLE; break;
2086         case 4037:
2087           type = QUAD_TETRAHEDRON; break;
2088         case 4038:
2089           type = QUAD_PYRAMID; break;
2090         case 4039:
2091           type = QUAD_PENTAHEDRON; break;
2092         case 4040:
2093           type = QUAD_HEXAHEDRON;
2094           break;
2095         default:;
2096         }
2097          new SMESHGUI_AddQuadraticElementDlg( this, type );
2098       }
2099       else {
2100         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2101                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2102                                tr("SMESH_BUT_OK"));
2103       }
2104       break;
2105     }
2106   case 4041:                                    // REMOVES NODES
2107     {
2108       if(checkLock(aStudy)) break;
2109       if ( vtkwnd ) {
2110         EmitSignalDeactivateDialog();
2111         new SMESHGUI_RemoveNodesDlg(this);
2112       }
2113       else {
2114         SUIT_MessageBox::warn1(desktop(),
2115                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2116                               tr("SMESH_BUT_OK"));
2117       }
2118       break;
2119     }
2120   case 4042:                                    // REMOVES ELEMENTS
2121     {
2122       if(checkLock(aStudy)) break;
2123       if( vtkwnd ) {
2124         EmitSignalDeactivateDialog();
2125         new SMESHGUI_RemoveElementsDlg(this);
2126       }
2127       else
2128         {
2129           SUIT_MessageBox::warn1(desktop(),
2130                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2131                                 tr("SMESH_BUT_OK"));
2132         }
2133       break;
2134     }
2135   case 4051:                                    // RENUMBERING NODES
2136     {
2137       if(checkLock(aStudy)) break;
2138       if( vtkwnd ) {
2139         EmitSignalDeactivateDialog();
2140         new SMESHGUI_RenumberingDlg( this, "", 0);
2141       }
2142       else
2143         {
2144           SUIT_MessageBox::warn1(desktop(),
2145                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2146                                 tr("SMESH_BUT_OK"));
2147         }
2148       break;
2149     }
2150   case 4052:                                    // RENUMBERING ELEMENTS
2151     {
2152       if(checkLock(aStudy)) break;
2153       if ( vtkwnd ) {
2154         EmitSignalDeactivateDialog();
2155         new SMESHGUI_RenumberingDlg( this, "", 1);
2156       }
2157       else
2158         {
2159           SUIT_MessageBox::warn1(desktop(),
2160                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2161                                 tr("SMESH_BUT_OK"));
2162         }
2163       break;
2164     }
2165   case 4061:                                   // TRANSLATION
2166     {
2167       if(checkLock(aStudy)) break;
2168       if ( vtkwnd ) {
2169         EmitSignalDeactivateDialog();
2170         new SMESHGUI_TranslationDlg( this );
2171       }
2172       else {
2173         SUIT_MessageBox::warn1(desktop(),
2174                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2175                               tr("SMESH_BUT_OK"));
2176       }
2177       break;
2178     }
2179   case 4062:                                   // ROTATION
2180     {
2181       if(checkLock(aStudy)) break;
2182       if( vtkwnd ) {
2183         EmitSignalDeactivateDialog();
2184         new SMESHGUI_RotationDlg( this );
2185       }
2186       else {
2187         SUIT_MessageBox::warn1(desktop(),
2188                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2189                               tr("SMESH_BUT_OK"));
2190       }
2191       break;
2192     }
2193   case 4063:                                   // SYMMETRY
2194     {
2195       if(checkLock(aStudy)) break;
2196       if(vtkwnd) {
2197         EmitSignalDeactivateDialog();
2198         new SMESHGUI_SymmetryDlg( this );
2199       }
2200       else {
2201         SUIT_MessageBox::warn1(desktop(),
2202                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2203                               tr("SMESH_BUT_OK"));
2204       }
2205       break;
2206     }
2207   case 4064:                                   // SEWING
2208     {
2209       if(checkLock(aStudy)) break;
2210       if(vtkwnd) {
2211         EmitSignalDeactivateDialog();
2212         new SMESHGUI_SewingDlg( this );
2213       }
2214       else {
2215         SUIT_MessageBox::warn1(desktop(),
2216                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2217                               tr("SMESH_BUT_OK"));
2218       }
2219       break;
2220     }
2221   case 4065:                                   // MERGE NODES
2222     {
2223       if(checkLock(aStudy)) break;
2224       if(vtkwnd) {
2225         EmitSignalDeactivateDialog();
2226         new SMESHGUI_EditMeshDlg( this, 0 );
2227       }
2228       else {
2229         SUIT_MessageBox::warn1(desktop(),
2230                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2231                               tr("SMESH_BUT_OK"));
2232       }
2233       break;
2234     }
2235   case 4066:                                   // MERGE EQUAL ELEMENTS
2236     {
2237       if (checkLock(aStudy)) break;
2238       if (vtkwnd) {
2239         EmitSignalDeactivateDialog();
2240         new SMESHGUI_EditMeshDlg( this, 1 );
2241       } else {
2242         SUIT_MessageBox::warn1(desktop(),
2243                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2244                               tr("SMESH_BUT_OK"));
2245       }
2246       break;
2247     }
2248
2249   case 4067: // MAKE MESH PASS THROUGH POINT
2250     startOperation( 4067 );
2251     break;
2252
2253   case 5105: // Library of selection filters
2254   {
2255     static QValueList<int> aTypes;
2256     if ( aTypes.isEmpty() )
2257     {
2258       aTypes.append( SMESH::NODE );
2259       aTypes.append( SMESH::EDGE );
2260       aTypes.append( SMESH::FACE );
2261       aTypes.append( SMESH::VOLUME );
2262     }
2263     if (!myFilterLibraryDlg)
2264       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2265     else if (myFilterLibraryDlg->isHidden())
2266       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2267     myFilterLibraryDlg->raise();
2268   }
2269   break;
2270
2271   case 6017:                                    // CONTROLS
2272   case 6016:
2273   case 6015:
2274   case 6014:
2275   case 6013:
2276   case 6012:
2277   case 6011:
2278   case 6001:
2279   case 6018:
2280   case 6019:
2281   case 6002:
2282   case 6003:
2283   case 6004:
2284   case 6009:
2285     if ( vtkwnd ) {
2286
2287       LightApp_SelectionMgr* mgr = selectionMgr();
2288       SALOME_ListIO selected; mgr->selectedObjects( selected );
2289
2290       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2291         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2292         if ( SO ) {
2293           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2294           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2295           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2296           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2297           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2298             ::Control( theCommandID );
2299             break;
2300           }
2301         }
2302       }
2303       SUIT_MessageBox::warn1(desktop(),
2304                             tr( "SMESH_WRN_WARNING" ),
2305                             tr( "SMESH_BAD_SELECTION" ),
2306                             tr( "SMESH_BUT_OK" ) );
2307       break;
2308     }
2309     else {
2310       SUIT_MessageBox::warn1(desktop(),
2311                             tr( "SMESH_WRN_WARNING" ),
2312                             tr( "NOT_A_VTK_VIEWER" ),
2313                             tr( "SMESH_BUT_OK" ) );
2314     }
2315     break;
2316   case 9010:
2317     {
2318       LightApp_SelectionMgr* mgr = selectionMgr();
2319       SALOME_ListIO selected; mgr->selectedObjects( selected );
2320
2321       SALOME_ListIteratorOfListIO it(selected);
2322       for(; it.More(); it.Next()) {
2323         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2324         if(anIObject->hasEntry()) {
2325           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2326             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2327           }
2328         }
2329       }
2330       break;
2331     }
2332   case 9011:
2333     {
2334       LightApp_SelectionMgr* mgr = selectionMgr();
2335       SALOME_ListIO selected; mgr->selectedObjects( selected );
2336
2337       if (selected.Extent() == 1)       {
2338         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2339         if(anIObject->hasEntry())
2340           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2341             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2342           }
2343       }
2344       break;
2345     }
2346   }
2347
2348   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2349   //updateObjBrowser();
2350   return true;
2351 }
2352
2353 //=============================================================================
2354 /*!
2355  *
2356  */
2357 //=============================================================================
2358 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2359 {
2360   return false;
2361 }
2362
2363 //=============================================================================
2364 /*!
2365  *
2366  */
2367 //=============================================================================
2368 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2369 {
2370   return true;
2371 }
2372
2373 //=============================================================================
2374 /*!
2375  *
2376  */
2377 //=============================================================================
2378 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2379 {
2380   return true;
2381 }
2382
2383 //=============================================================================
2384 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2385  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2386  */
2387 //=============================================================================
2388 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2389                                   SUIT_ViewWindow* wnd )
2390 {
2391   if(theIO->hasEntry()){
2392     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2393     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2394   }
2395 }
2396
2397 //=======================================================================
2398 // function : createSMESHAction
2399 // purpose  :
2400 //=======================================================================
2401 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2402 {
2403   QIconSet icon;
2404   QWidget* parent = application()->desktop();
2405   SUIT_ResourceMgr* resMgr = resourceMgr();
2406   QPixmap pix;
2407   if ( icon_id.length() )
2408     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2409   else
2410     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2411   if ( !pix.isNull() )
2412     icon = QIconSet( pix );
2413
2414   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2415           menu       = tr( QString( "MEN_" )+po_id ),
2416           status_bar = tr( QString( "STB_" )+po_id );
2417
2418   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2419 }
2420
2421 //=======================================================================
2422 // function : createPopupItem
2423 // purpose  :
2424 //=======================================================================
2425 void SMESHGUI::createPopupItem( const int id,
2426                                 const QString& clients,
2427                                 const QString& types,
2428                                 const QString& theRule,
2429                                 const int pId )
2430 {
2431   int parentId = pId;
2432   if( pId!=-1 )
2433     parentId = popupMgr()->actionId( action( pId ) );
2434
2435   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2436     popupMgr()->insert( action( id ), parentId, 0 );
2437
2438   QChar lc = QtxPopupMgr::Selection::defEquality();
2439   QString rule = "(%1) and (%2) and (%3)";
2440   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2441   if( clients.isEmpty() )
2442     rule = rule.arg( QString( "true" ) );
2443   else
2444     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2445   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2446   rule += theRule;
2447
2448   bool cont = myRules.contains( id );
2449   if( cont )
2450     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2451
2452   popupMgr()->setRule( action( id ), rule, true );
2453   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2454 }
2455
2456 //=======================================================================
2457 // function : initialize
2458 // purpose  :
2459 //=======================================================================
2460 void SMESHGUI::initialize( CAM_Application* app )
2461 {
2462   SalomeApp_Module::initialize( app );
2463
2464 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2465 //   if ( mgr )
2466   /* Automatic Update flag */
2467 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2468
2469   // ----- create actions --------------
2470
2471   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2472   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2473   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2474   createSMESHAction(  114, "NUM" );
2475   createSMESHAction(  121, "DAT" );
2476   createSMESHAction(  122, "MED" );
2477   createSMESHAction(  123, "UNV" );
2478   createSMESHAction(  140, "STL" );
2479   createSMESHAction(  124, "EXPORT_DAT" );
2480   createSMESHAction(  125, "EXPORT_MED" );
2481   createSMESHAction(  126, "EXPORT_UNV" );
2482   createSMESHAction(  141, "EXPORT_STL" );
2483   createSMESHAction(  150, "FILE_INFO" );
2484   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2485   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2486   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2487   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2488   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2489   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2490   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2491   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2492   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2493   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2494   createSMESHAction(  804, "ADD" );
2495   createSMESHAction(  805, "REMOVE" );
2496   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2497   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2498   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2499   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2500   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2501   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2502   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2503   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2504   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2505   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2506   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2507   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2508   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2509   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2510   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2511   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2512   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2513   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2514   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2515   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2516   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2517   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2518   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2519   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2520   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2521   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2522   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2523   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2524   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2525   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2526   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2527   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2528   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2529   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2530   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2531   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2532   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2533   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2534   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2535   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2536   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2537   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2538   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2539   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2540   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2541   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2542   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2543   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2544   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2545   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2546   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2547   createSMESHAction(  200, "RESET" );
2548   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2549   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2550   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2551   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2552   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2553   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2554   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2555   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2556   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2557   createSMESHAction(  220, "ALL" );
2558   createSMESHAction( 1100, "EDIT_HYPO" );
2559   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2560   createSMESHAction( 1102, "UNASSIGN" );
2561   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2562   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2563   createSMESHAction( 1131, "DISPMODE" );
2564   createSMESHAction( 1132, "COLORS" );
2565   createSMESHAction( 1133, "TRANSP" );
2566   createSMESHAction( 1134, "CLIP" );
2567   createSMESHAction( 1135, "DISP_ENT" );
2568   createSMESHAction( 1136, "AUTO_COLOR" );
2569   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2570   createSMESHAction( 2000, "CTRL" );
2571
2572   createSMESHAction( 300, "ERASE" );
2573   createSMESHAction( 301, "DISPLAY" );
2574   createSMESHAction( 302, "DISPLAY_ONLY" );
2575   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2576   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2577   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2578   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2579   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2580   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2581   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2582   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2583
2584   // ----- create menu --------------
2585   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2586       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2587       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2588       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2589       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2590       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2591       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2592
2593   createMenu( separator(), fileId );
2594
2595   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2596       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2597       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2598       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2599       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2600       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2601
2602   createMenu( 111, importId, -1 );
2603   createMenu( 112, importId, -1 );
2604   createMenu( 113, importId, -1 );
2605
2606   createMenu( 121, exportId, -1 );
2607   createMenu( 122, exportId, -1 );
2608   createMenu( 123, exportId, -1 );
2609   createMenu( 140, exportId, -1 ); // export to stl STL
2610
2611   createMenu( separator(), fileId, 10 );
2612
2613   createMenu( 33, editId, -1 );
2614
2615   createMenu( 5105, toolsId, -1 );
2616
2617   createMenu( 702, meshId, -1 );
2618   createMenu( 703, meshId, -1 );
2619   createMenu( 704, meshId, -1 );
2620   createMenu( 710, meshId, -1 );
2621   createMenu( separator(), meshId, -1 );
2622   createMenu( 701, meshId, -1 );
2623   createMenu( separator(), meshId, -1 );
2624   createMenu( 801, meshId, -1 );
2625   createMenu( 802, meshId, -1 );
2626   createMenu( 803, meshId, -1 );
2627   createMenu( separator(), meshId, -1 );
2628   createMenu( 810, meshId, -1 );
2629   createMenu( 811, meshId, -1 );
2630   createMenu( 812, meshId, -1 );
2631   createMenu( separator(), meshId, -1 );
2632   createMenu( 813, meshId, -1 );
2633   createMenu( separator(), meshId, -1 );
2634   createMenu( 900, meshId, -1 );
2635   createMenu( 902, meshId, -1 );
2636   createMenu( 903, meshId, -1 );
2637   createMenu( separator(), meshId, -1 );
2638
2639   createMenu( 6003, ctrlId, -1 );
2640   createMenu( 6001, ctrlId, -1 );
2641   createMenu( 6004, ctrlId, -1 );
2642   createMenu( separator(), ctrlId, -1 );
2643   createMenu( 6002, ctrlId, -1 );
2644   createMenu( 6018, ctrlId, -1 );
2645   createMenu( 6019, ctrlId, -1 );
2646   createMenu( 6011, ctrlId, -1 );
2647   createMenu( 6012, ctrlId, -1 );
2648   createMenu( 6013, ctrlId, -1 );
2649   createMenu( 6014, ctrlId, -1 );
2650   createMenu( 6015, ctrlId, -1 );
2651   createMenu( 6016, ctrlId, -1 );
2652   createMenu( separator(), ctrlId, -1 );
2653   createMenu( 6017, ctrlId, -1 );
2654   createMenu( 6009, ctrlId, -1 );
2655   createMenu( separator(), ctrlId, -1 );
2656
2657   createMenu( 400, addId, -1 );
2658   createMenu( 401, addId, -1 );
2659   createMenu( 4021, addId, -1 );
2660   createMenu( 4022, addId, -1 );
2661   createMenu( 4023, addId, -1 );
2662   createMenu( 4031, addId, -1 );
2663   createMenu( 4032, addId, -1 );
2664   createMenu( 4033, addId, -1 );
2665   createMenu( separator(), addId, -1 );
2666   createMenu( 4034, addId, -1 );
2667   createMenu( 4035, addId, -1 );
2668   createMenu( 4036, addId, -1 );
2669   createMenu( 4037, addId, -1 );
2670   createMenu( 4038, addId, -1 );
2671   createMenu( 4039, addId, -1 );
2672   createMenu( 4040, addId, -1 );
2673
2674   createMenu( 4041, removeId, -1 );
2675   createMenu( 4042, removeId, -1 );
2676
2677   createMenu( 4051, renumId, -1 );
2678   createMenu( 4052, renumId, -1 );
2679
2680   createMenu( 4061, transfId, -1 );
2681   createMenu( 4062, transfId, -1 );
2682   createMenu( 4063, transfId, -1 );
2683   createMenu( 4064, transfId, -1 );
2684   createMenu( 4065, transfId, -1 );
2685   createMenu( 4066, transfId, -1 );
2686
2687   createMenu( 406, modifyId, -1 );
2688   createMenu( 4067,modifyId, -1 );
2689   createMenu( 407, modifyId, -1 );
2690   createMenu( 408, modifyId, -1 );
2691   createMenu( 409, modifyId, -1 );
2692   createMenu( 410, modifyId, -1 );
2693   createMenu( 411, modifyId, -1 );
2694   createMenu( 412, modifyId, -1 );
2695   createMenu( 413, modifyId, -1 );
2696   createMenu( 416, modifyId, -1 );
2697   createMenu( 414, modifyId, -1 );
2698   createMenu( 415, modifyId, -1 );
2699   createMenu( 417, modifyId, -1 );
2700
2701   createMenu( 214, viewId, -1 );
2702
2703   // ----- create toolbars --------------
2704   int meshTb     = createTool( tr( "TB_MESH" ) ),
2705       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2706       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2707       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2708       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2709
2710   createTool( 702, meshTb );
2711   createTool( 703, meshTb );
2712   createTool( 704, meshTb );
2713   createTool( 710, meshTb );
2714   createTool( separator(), meshTb );
2715   createTool( 701, meshTb );
2716   createTool( separator(), meshTb );
2717   createTool( 801, meshTb );
2718   createTool( 802, meshTb );
2719   createTool( 803, meshTb );
2720   createTool( separator(), meshTb );
2721   createTool( 900, meshTb );
2722   createTool( 902, meshTb );
2723   createTool( 903, meshTb );
2724   createTool( separator(), meshTb );
2725
2726   createTool( 6001, ctrlTb );
2727   createTool( 6003, ctrlTb );
2728   createTool( 6004, ctrlTb );
2729   createTool( separator(), ctrlTb );
2730   createTool( 6002, ctrlTb );
2731   createTool( 6018, ctrlTb );
2732   createTool( 6019, ctrlTb );
2733   createTool( 6011, ctrlTb );
2734   createTool( 6012, ctrlTb );
2735   createTool( 6013, ctrlTb );
2736   createTool( 6014, ctrlTb );
2737   createTool( 6015, ctrlTb );
2738   createTool( 6016, ctrlTb );
2739   createTool( separator(), ctrlTb );
2740   createTool( 6017, ctrlTb );
2741   createTool( 6009, ctrlTb );
2742   createTool( separator(), ctrlTb );
2743
2744   createTool( 400, addRemTb );
2745   createTool( 401, addRemTb );
2746   createTool( 4021, addRemTb );
2747   createTool( 4022, addRemTb );
2748   createTool( 4023, addRemTb );
2749   createTool( 4031, addRemTb );
2750   createTool( 4032, addRemTb );
2751   createTool( 4033, addRemTb );
2752   createTool( separator(), addRemTb );
2753   createTool( 4034, addRemTb );
2754   createTool( 4035, addRemTb );
2755   createTool( 4036, addRemTb );
2756   createTool( 4037, addRemTb );
2757   createTool( 4038, addRemTb );
2758   createTool( 4039, addRemTb );
2759   createTool( 4040, addRemTb );
2760   createTool( separator(), addRemTb );
2761   createTool( 4041, addRemTb );
2762   createTool( 4042, addRemTb );
2763   createTool( separator(), addRemTb );
2764   createTool( 4051, addRemTb );
2765   createTool( 4052, addRemTb );
2766   createTool( separator(), addRemTb );
2767   createTool( 4061, addRemTb );
2768   createTool( 4062, addRemTb );
2769   createTool( 4063, addRemTb );
2770   createTool( 4064, addRemTb );
2771   createTool( 4065, addRemTb );
2772   createTool( 4066, addRemTb );
2773   createTool( separator(), addRemTb );
2774
2775   createTool( 406, modifyTb );
2776   createTool( 4067,modifyTb );
2777   createTool( 407, modifyTb );
2778   createTool( 408, modifyTb );
2779   createTool( 409, modifyTb );
2780   createTool( 410, modifyTb );
2781   createTool( 411, modifyTb );
2782   createTool( 412, modifyTb );
2783   createTool( 413, modifyTb );
2784   createTool( 416, modifyTb );
2785   createTool( 414, modifyTb );
2786   createTool( 415, modifyTb );
2787   createTool( 417, modifyTb );
2788
2789   createTool( 214, dispModeTb );
2790
2791
2792   myRules.clear();
2793   QString OB = "'ObjectBrowser'",
2794           View = "'" + SVTK_Viewer::Type() + "'",
2795           pat = "'%1'",
2796           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2797           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2798           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2799           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2800           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2801                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2802                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2803                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2804                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2805                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2806                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2807           subMesh = elems,
2808           mesh_group = mesh + " " + subMesh + " " + group,
2809           hyp_alg = hypo + " " + algo;
2810
2811   // popup for object browser
2812
2813   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
2814   
2815   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2816   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2817   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2818   popupMgr()->insert( separator(), -1, 0 );
2819   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2820   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2821   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2822   createPopupItem( 902, OB, mesh );                        // STD_INFO
2823   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2824   popupMgr()->insert( separator(), -1, 0 );
2825   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2826   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2827   popupMgr()->insert( separator(), -1, 0 );
2828   createPopupItem( 1100, OB, hypo, "" /*"&& $hasReference={false}"*/ );   // EDIT HYPOTHESIS
2829   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2830   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "" /*"&& $hasReference={false}"*/ ); // RENAME
2831   popupMgr()->insert( separator(), -1, 0 );
2832
2833   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2834   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2835   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2836   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2837   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2838   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2839   popupMgr()->insert( separator(), -1, 0 );
2840
2841   // popup for viewer
2842   createPopupItem( 803, View, group ); // EDIT_GROUP
2843   createPopupItem( 804, View, elems ); // ADD
2844   createPopupItem( 805, View, elems ); // REMOVE
2845   popupMgr()->insert( separator(), -1, 0 );
2846   createPopupItem( 214, View, mesh_group ); // UPDATE
2847   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2848   createPopupItem( 902, View, mesh );       // STD_INFO
2849   createPopupItem( 903, View, mesh_group ); // WHAT_IS
2850   popupMgr()->insert( separator(), -1, 0 );
2851
2852   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2853   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2854   popupMgr()->insert( separator(), -1, 0 );
2855
2856   int anId;
2857   QString
2858     isInvisible("not( isVisible )"),
2859     isEmpty("numberOfNodes = 0"),
2860     isNotEmpty("numberOfNodes <> 0"),
2861
2862     // has nodes, edges, etc in VISIBLE! actor
2863     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2864     hasElems("(count( elemTypes ) > 0)"),
2865     hasDifferentElems("(count( elemTypes ) > 1)"),
2866     hasEdges("({'Edge'} in elemTypes)"),
2867     hasFaces("({'Face'} in elemTypes)"),
2868     hasVolumes("({'Volume'} in elemTypes)");
2869
2870   QString lc = QtxPopupMgr::Selection::defEquality();
2871   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2872   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
2873   aType = aType.arg( mesh_group );
2874   QString aMeshInVTK = aClient + "&&" + aType;
2875
2876   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2877   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2878   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2879
2880   //-------------------------------------------------
2881   // Numbering
2882   //-------------------------------------------------
2883   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2884
2885   popupMgr()->insert( action( 9010 ), anId, -1 );
2886   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2887   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2888
2889   popupMgr()->insert( action( 9011 ), anId, -1 );
2890   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2891   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2892
2893   popupMgr()->insert( separator(), -1, -1 );
2894
2895   //-------------------------------------------------
2896   // Display Mode
2897   //-------------------------------------------------
2898   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2899
2900   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2901   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2902   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2903
2904   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2905   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2906   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2907
2908   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2909   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2910   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2911
2912   popupMgr()->insert( separator(), anId, -1 );
2913
2914   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2915   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2916   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2917
2918   //-------------------------------------------------
2919   // Display Entity
2920   //-------------------------------------------------
2921   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2922
2923   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2924
2925   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2926   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
2927   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2928
2929   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2930   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
2931   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2932
2933   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2934   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
2935   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2936
2937   popupMgr()->insert( separator(), anId, -1 );
2938
2939   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2940   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
2941
2942   //-------------------------------------------------
2943   // Color / Size
2944   //-------------------------------------------------
2945   popupMgr()->insert( action( 1132 ), -1, -1 );
2946   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
2947
2948   //-------------------------------------------------
2949   // Transparency
2950   //-------------------------------------------------
2951   popupMgr()->insert( action( 1133 ), -1, -1 );
2952   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
2953
2954   //-------------------------------------------------
2955   // Clipping
2956   //-------------------------------------------------
2957   popupMgr()->insert( action( 1134 ), -1, -1 );
2958   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
2959
2960   popupMgr()->insert( separator(), -1, -1 );
2961
2962   //-------------------------------------------------
2963   // Controls
2964   //-------------------------------------------------
2965   QString
2966     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
2967     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
2968     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
2969
2970   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
2971
2972   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
2973   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2974
2975   popupMgr()->insert( separator(), anId, -1 );
2976
2977   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
2978   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
2979   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
2980
2981   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
2982   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
2983   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
2984
2985   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
2986   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
2987   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
2988
2989   popupMgr()->insert( separator(), anId, -1 );
2990
2991   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
2992   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
2993   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
2994
2995   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
2996   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
2997   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
2998
2999   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3000   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
3001   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
3002
3003   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3004   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
3005   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
3006
3007   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3008   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
3009   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
3010
3011   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3012   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
3013   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
3014
3015   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3016   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3017   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3018
3019   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3020   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3021   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3022
3023   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3024   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3025   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3026
3027   popupMgr()->insert( separator(), anId, -1 );
3028
3029   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3030   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3031   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3032
3033   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3034   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
3035   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
3036
3037   popupMgr()->insert( separator(), anId, -1 );
3038
3039   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3040   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3041
3042   popupMgr()->insert( separator(), -1, -1 );
3043
3044   //-------------------------------------------------
3045   // Display / Erase
3046   //-------------------------------------------------
3047   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3048     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3049   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3050   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3051
3052   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3053   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3054
3055   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3056   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3057
3058   popupMgr()->insert( separator(), -1, -1 );
3059
3060   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3061            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3062 }
3063
3064 bool SMESHGUI::activateModule( SUIT_Study* study )
3065 {
3066   bool res = SalomeApp_Module::activateModule( study );
3067
3068   setMenuShown( true );
3069   setToolShown( true );
3070
3071   // Reset actions accelerator keys
3072   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3073   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3074   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3075
3076   return res;
3077 }
3078
3079 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3080 {
3081   setMenuShown( false );
3082   setToolShown( false );
3083
3084   EmitSignalCloseAllDialogs();
3085
3086   // Unset actions accelerator keys
3087   action(111)->setAccel(QKeySequence()); // Import DAT
3088   action(112)->setAccel(QKeySequence()); // Import UNV
3089   action(113)->setAccel(QKeySequence()); // Import MED
3090
3091   return SalomeApp_Module::deactivateModule( study );
3092 }
3093
3094 void SMESHGUI::studyClosed( SUIT_Study* s )
3095 {
3096   SMESH::RemoveVisuData( s->id() );
3097   SalomeApp_Module::studyClosed( s );
3098 }
3099
3100 void SMESHGUI::OnGUIEvent()
3101 {
3102   const QObject* obj = sender();
3103   if ( !obj || !obj->inherits( "QAction" ) )
3104     return;
3105   int id = actionId((QAction*)obj);
3106   if ( id != -1 )
3107     OnGUIEvent( id );
3108 }
3109
3110 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3111 {
3112   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3113   if ( CORBA::is_nil( myComponentSMESH ) )
3114     {
3115       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3116       if ( aStudy )
3117         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3118       return aGUI.myComponentSMESH;
3119     }
3120   if ( aStudy )
3121     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3122   return myComponentSMESH;
3123 }
3124
3125 QString SMESHGUI::engineIOR() const
3126 {
3127   CORBA::ORB_var anORB = getApp()->orb();
3128   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3129   return QString( anIOR.in() );
3130 }
3131
3132 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
3133 {
3134   SMESHGUI_Selection sel;
3135   sel.init( client, selectionMgr() );
3136   popupMgr()->updatePopup( menu, &sel );
3137 }
3138
3139 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3140 {
3141   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3142   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3143 }
3144
3145 void SMESHGUI::viewManagers( QStringList& list ) const
3146 {
3147   list.append( SVTK_Viewer::Type() );
3148 }
3149
3150 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3151 {
3152   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3153     SMESH::UpdateSelectionProp( this );
3154 }
3155
3156 void SMESHGUI::createPreferences()
3157 {
3158   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3159
3160   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3161   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3162
3163   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3164   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3165   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3166
3167   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3168   setPreferenceProperty( precGroup, "columns", 1 );
3169
3170   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3171
3172   setPreferenceProperty( prec, "min", 0 );
3173   setPreferenceProperty( prec, "max", 16 );
3174
3175   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3176   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3177   QStringList modes;
3178   modes.append( "Wireframe" );
3179   modes.append( "Shading" );
3180   modes.append( "Nodes" );
3181   modes.append( "Shrink" );
3182   QValueList<QVariant> indices;
3183   indices.append( 0 );
3184   indices.append( 1 );
3185   indices.append( 2 );
3186   indices.append( 3 );
3187   setPreferenceProperty( dispmode, "strings", modes );
3188   setPreferenceProperty( dispmode, "indexes", indices );
3189
3190   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3191   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3192   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3193
3194   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3195   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3196
3197   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3198   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3199
3200   setPreferenceProperty( nodeSz, "min", 1 );
3201   setPreferenceProperty( nodeSz, "max", 5 );
3202
3203   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3204
3205   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3206   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3207   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3208   addPreference( "", elemGroup, LightApp_Preferences::Space );
3209
3210   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3211   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3212
3213   setPreferenceProperty( elemW, "min", 1 );
3214   setPreferenceProperty( elemW, "max", 5 );
3215
3216   setPreferenceProperty( shrink, "min", 0 );
3217   setPreferenceProperty( shrink, "max", 100 );
3218
3219   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3220
3221   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3222
3223   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3224   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3225   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3226
3227   setPreferenceProperty( selW, "min", 1 );
3228   setPreferenceProperty( selW, "max", 5 );
3229
3230   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3231
3232   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3233   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3234
3235   setPreferenceProperty( preW, "min", 1 );
3236   setPreferenceProperty( preW, "max", 5 );
3237
3238   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3239
3240   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3241   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3242   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3243
3244   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3245   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3246
3247   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3248   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3249   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3250   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3251
3252   QStringList fam;
3253   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3254   fam.append( tr( "SMESH_FONT_COURIER" ) );
3255   fam.append( tr( "SMESH_FONT_TIMES" ) );
3256   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3257
3258   setPreferenceProperty( tfont, "families", fam );
3259   setPreferenceProperty( tfont, "system", false );
3260   setPreferenceProperty( tfont, "widget_flags", wflag );
3261   setPreferenceProperty( lfont, "families", fam );
3262   setPreferenceProperty( lfont, "system", false );
3263   setPreferenceProperty( lfont, "widget_flags", wflag );
3264
3265   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3266
3267   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3268   setPreferenceProperty( numcol, "min", 2 );
3269   setPreferenceProperty( numcol, "max", 256 );
3270
3271   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3272   setPreferenceProperty( numlab, "min", 2 );
3273   setPreferenceProperty( numlab, "max", 65 );
3274
3275   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3276   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3277   QStringList orients;
3278   orients.append( tr( "SMESH_VERTICAL" ) );
3279   orients.append( tr( "SMESH_HORIZONTAL" ) );
3280   indices.clear(); indices.append( 0 ); indices.append( 1 );
3281   setPreferenceProperty( orient, "strings", orients );
3282   setPreferenceProperty( orient, "indexes", indices );
3283
3284   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3285   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3286   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3287   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3288   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3289   setPreferenceProperty( xv, "step", 0.1 );
3290   setPreferenceProperty( xv, "min", 0.0 );
3291   setPreferenceProperty( xv, "max", 1.0 );
3292   setPreferenceProperty( yv, "step", 0.1 );
3293   setPreferenceProperty( yv, "min", 0.0 );
3294   setPreferenceProperty( yv, "max", 1.0 );
3295   setPreferenceProperty( wv, "step", 0.1 );
3296   setPreferenceProperty( wv, "min", 0.0 );
3297   setPreferenceProperty( wv, "max", 1.0 );
3298   setPreferenceProperty( hv, "min", 0.0 );
3299   setPreferenceProperty( hv, "max", 1.0 );
3300   setPreferenceProperty( hv, "step", 0.1 );
3301
3302   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3303   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3304   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3305   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3306   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3307   setPreferenceProperty( xv, "min", 0.0 );
3308   setPreferenceProperty( xv, "max", 1.0 );
3309   setPreferenceProperty( xv, "step", 0.1 );
3310   setPreferenceProperty( xh, "min", 0.0 );
3311   setPreferenceProperty( xh, "max", 1.0 );
3312   setPreferenceProperty( xh, "step", 0.1 );
3313   setPreferenceProperty( yh, "min", 0.0 );
3314   setPreferenceProperty( yh, "max", 1.0 );
3315   setPreferenceProperty( yh, "step", 0.1 );
3316   setPreferenceProperty( wh, "min", 0.0 );
3317   setPreferenceProperty( wh, "max", 1.0 );
3318   setPreferenceProperty( wh, "step", 0.1 );
3319   setPreferenceProperty( hh, "min", 0.0 );
3320   setPreferenceProperty( hh, "max", 1.0 );
3321   setPreferenceProperty( hh, "step", 0.1 );
3322 }
3323
3324 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3325 {
3326   if( sect=="SMESH" ){
3327     float sbX1,sbY1,sbW,sbH;
3328     float aTol = 1.00000009999999;
3329     std::string aWarning;
3330     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3331     if( name=="selection_object_color" || name=="selection_element_color" ||
3332         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3333         name=="selection_precision_node" || name=="selection_precision_element" ||
3334         name=="selection_precision_object")
3335       SMESH::UpdateSelectionProp( this );
3336     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3337       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3338       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3339       if(sbX1+sbW > aTol){
3340         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3341         sbX1=0.01;
3342         sbW=0.05;
3343         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3344         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3345       }
3346     }
3347     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3348       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3349       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3350       if(sbY1+sbH > aTol){
3351         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3352         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3353         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3354       }
3355     }
3356     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3357       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3358       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3359       if(sbX1+sbW > aTol){
3360         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3361         sbX1=0.01;
3362         sbW=0.05;
3363         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3364         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3365       }
3366     }
3367     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3368       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3369       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3370       if(sbY1+sbH > aTol){
3371         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3372         sbY1=0.01;
3373         sbH=0.05;
3374         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3375         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3376       }
3377     }
3378
3379     if(aWarning.size() != 0){
3380       aWarning += "The default values are applied instead.";
3381       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3382                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3383                              QObject::tr(aWarning.c_str()),
3384                              QObject::tr("SMESH_BUT_OK"));
3385     }
3386   }
3387 }
3388
3389 //================================================================================
3390 /*!
3391  * \brief Update something in accordance with update flags
3392   * \param theFlags - update flags
3393 *
3394 * Update viewer or/and object browser etc. in accordance with update flags ( see
3395 * LightApp_UpdateFlags enumeration ).
3396 */
3397 //================================================================================
3398 void SMESHGUI::update( const int flags )
3399 {
3400   if ( flags & UF_Viewer | flags & UF_Forced )
3401     SMESH::UpdateView();
3402   else
3403     SalomeApp_Module::update( flags );
3404 }
3405
3406 //================================================================================
3407 /*!
3408  * \brief Set default selection mode
3409 *
3410 * SLOT called when operation commited. Sets default selection mode
3411 */
3412 //================================================================================
3413 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3414 {
3415   SVTK_ViewWindow* vtkWnd =
3416     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3417   if ( vtkWnd )
3418     vtkWnd->SetSelectionMode( ActorSelection );
3419 }
3420
3421 //================================================================================
3422 /*!
3423  * \brief Set default selection mode
3424 *
3425 * SLOT called when operation aborted. Sets default selection mode
3426 */
3427 //================================================================================
3428 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3429 {
3430   SVTK_ViewWindow* vtkWnd =
3431     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3432   if ( vtkWnd )
3433     vtkWnd->SetSelectionMode( ActorSelection );
3434 }
3435
3436 //================================================================================
3437 /*!
3438  * \brief Creates operation with given identifier
3439   * \param id - identifier of operation to be started
3440   * \return Pointer on created operation or NULL if operation is not created
3441 *
3442 * Virtual method redefined from the base class creates operation with given id.
3443 * It is called called automatically from startOperation method of base class.
3444 */
3445 //================================================================================
3446 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3447 {
3448   LightApp_Operation* op = 0;
3449   // to do : create operation here
3450   switch( id )
3451   {
3452     case 701: // Compute mesh
3453       op = new SMESHGUI_ComputeOp();
3454     break;
3455     case 702: // Create mesh
3456       op = new SMESHGUI_MeshOp( true, true );
3457     break;
3458     case 703: // Create sub-mesh
3459       op = new SMESHGUI_MeshOp( true, false );
3460     break;
3461     case 704: // Edit mesh/sub-mesh
3462       op = new SMESHGUI_MeshOp( false );
3463     break;
3464     case 417: //convert to quadratic
3465       op = new SMESHGUI_ConvToQuadOp();
3466     break;
3467     case 4067: // make mesh pass through point
3468       op = new SMESHGUI_MakeNodeAtPointOp();
3469       break;
3470     default:
3471     break;
3472   }
3473
3474   if( !op )
3475     op = SalomeApp_Module::createOperation( id );
3476   return op;
3477 }
3478
3479 //================================================================================
3480 /*!
3481  * \brief Stops current operations and starts a given one
3482   * \param id - The id of the operation to start
3483  */
3484 //================================================================================
3485
3486 void SMESHGUI::switchToOperation(int id)
3487 {
3488   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3489     activeStudy()->abortAllOperations();
3490   startOperation( id );
3491 }
3492
3493 LightApp_Displayer* SMESHGUI::displayer()
3494 {
3495   if( !myDisplayer )
3496     myDisplayer = new SMESHGUI_Displayer( getApp() );
3497   return myDisplayer;
3498 }
3499
3500 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3501 {
3502   int aHue = -1;
3503   int aTolerance = 64;
3504   int anIterations = 0;
3505   int aPeriod = 5;
3506
3507   while( 1 )
3508   {
3509     anIterations++;
3510     if( anIterations % aPeriod == 0 )
3511     {
3512       aTolerance /= 2;
3513       if( aTolerance < 1 )
3514         break;
3515     }
3516     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3517
3518     aHue = (int)( 360.0 * rand() / RAND_MAX );
3519     //cout << "Hue = " << aHue << endl;
3520
3521     //cout << "Auto colors : ";
3522     bool ok = true;
3523     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3524     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3525     for( ; it != itEnd; ++it )
3526     {
3527       SALOMEDS::Color anAutoColor = *it;
3528       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3529
3530       int h, s, v;
3531       aQColor.getHsv( &h, &s, &v );
3532       //cout << h << " ";
3533       if( abs( h - aHue ) < aTolerance )
3534       {
3535         ok = false;
3536         //cout << "break (diff = " << abs( h - aHue ) << ")";
3537         break;
3538       }
3539     }
3540     //cout << endl;
3541
3542     if( ok )
3543       break;
3544   }
3545
3546   //cout << "Hue of the returned color = " << aHue << endl;
3547   QColor aColor;
3548   aColor.setHsv( aHue, 255, 255 );
3549
3550   SALOMEDS::Color aSColor;
3551   aSColor.R = (double)aColor.red() / 255.0;
3552   aSColor.G = (double)aColor.green() / 255.0;
3553   aSColor.B = (double)aColor.blue() / 255.0;
3554
3555   return aSColor;
3556 }