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