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