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