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