Salome HOME
PAL13330( When mesh generation does not success, trace where )
[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               int aRet = 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 or 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   Standard_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       if (vtkwnd) {
1294         SALOME_ListIteratorOfListIO It( to_process );
1295         for (; It.More(); It.Next()) {
1296           Handle(SALOME_InteractiveObject) IOS = It.Value();
1297           if (IOS->hasEntry()) {
1298             SMESH::UpdateView(anAction, IOS->getEntry());
1299             if (anAction == SMESH::eDisplayOnly)
1300               anAction = SMESH::eDisplay;
1301           }
1302         }
1303       }
1304
1305       // PAL13338 + PAL15161 -->
1306       if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy) /*&& !automaticUpdate()*/ )
1307         SMESH::UpdateView();
1308       // PAL13338 + PAL15161 <--
1309
1310       if (anAction == SMESH::eErase) {
1311         SALOME_ListIO l1;
1312         aSel->setSelectedObjects( l1 );
1313       }
1314       else
1315         aSel->setSelectedObjects( to_process );
1316
1317       break;
1318     }
1319
1320   case 400:                                     // NODES
1321     {
1322       if(checkLock(aStudy)) break;
1323
1324       if ( vtkwnd ) {
1325         EmitSignalDeactivateDialog();
1326
1327         new SMESHGUI_NodesDlg(this);
1328       }
1329       else {
1330         SUIT_MessageBox::warn1(desktop(),
1331                               tr("SMESH_WRN_WARNING"),
1332                               tr("SMESH_WRN_VIEWER_VTK"),
1333                               tr("SMESH_BUT_OK"));
1334       }
1335       break;
1336     }
1337
1338   case 2151:  // FILTER
1339   {
1340     if ( vtkwnd )
1341     {
1342       EmitSignalDeactivateDialog();
1343       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1344     }
1345     break;
1346   }
1347
1348   case 406:                                     // MOVE NODE
1349     {
1350       if ( !vtkwnd )
1351       {
1352         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1353           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1354         break;
1355       }
1356
1357       if(checkLock(aStudy)) break;
1358       new SMESHGUI_MoveNodesDlg(this);
1359       break;
1360     }
1361
1362   case 701:                                     // COMPUTE MESH
1363     {
1364       if (checkLock(aStudy)) break;
1365
1366       startOperation( 701 );
1367 //       LightApp_SelectionMgr *Sel = selectionMgr();
1368 //       SALOME_ListIO selected; Sel->selectedObjects( selected );
1369
1370 //       int nbSel = selected.Extent();
1371 //       if (nbSel != 1) {
1372 //         SUIT_MessageBox::warn1(desktop(),
1373 //                                tr("SMESH_WRN_WARNING"),
1374 //                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1375 //                                tr("SMESH_BUT_OK"));
1376 //         break;
1377 //       }
1378
1379 //       SMESH::SMESH_Mesh_var aMesh;
1380 //       SMESH::SMESH_subMesh_var aSubMesh;
1381 //       Handle(SALOME_InteractiveObject) IObject = selected.First();
1382 //       if (IObject->hasEntry()) {
1383 //         _PTR(SObject) aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
1384 //         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
1385 //         if ( aShapeObject->_is_nil() ) {
1386 //           // imported mesh
1387 //           break;
1388 //         }
1389 //         if ( aMeshSObj ) {
1390 //           aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
1391 //           aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
1392 //           if ( !aSubMesh->_is_nil() )
1393 //             aMesh = aSubMesh->GetFather();
1394
1395 //           if (!aMesh->_is_nil()) {
1396 //             SMESH::algo_error_array_var errors = GetSMESHGen()->GetAlgoState(aMesh,aShapeObject);
1397 //             if ( errors->length() > 0 ) {
1398 //               SUIT_MessageBox::warn1(desktop(),
1399 //                                      tr("SMESH_WRN_WARNING"),
1400 //                                      SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
1401 //                                      tr("SMESH_BUT_OK"));
1402 //               break;
1403 //             }
1404
1405 //             try {
1406 //               if (GetSMESHGen()->Compute(aMesh, aShapeObject))
1407 //                 SMESH::ModifiedMesh(aMeshSObj, true);
1408 //               else
1409 //                 SUIT_MessageBox::warn1(desktop(),
1410 //                                        tr("SMESH_WRN_WARNING"),
1411 //                                        tr("SMESH_WRN_COMPUTE_FAILED"),
1412 //                                        tr("SMESH_BUT_OK"));
1413 //             }
1414 //             catch(const SALOME::SALOME_Exception & S_ex){
1415 //               SalomeApp_Tools::QtCatchCorbaException(S_ex);
1416 //             }
1417
1418 //             updateObjBrowser();
1419
1420 //             if (automaticUpdate()) {
1421 //               SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(this, /*create*/true);
1422 //               if (aVTKView) {
1423 //                 CORBA::Long anId = aStudy->StudyId();
1424 //                 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
1425 //                 if (aVisualObj) {
1426 //                   aVisualObj->Update();
1427 //                   SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
1428 //                   if (!anActor) {
1429 //                     anActor = SMESH::CreateActor(aStudy, IObject->getEntry());
1430 //                     if (anActor) {
1431 //                       SMESH::DisplayActor(aVTKView, anActor); //apo
1432 //                       SMESH::FitAll();
1433 //                     }
1434 //                   }
1435 //                   SMESH::RepaintCurrentView();
1436 //                   Sel->setSelectedObjects( selected );
1437 //                 }
1438 //               }
1439 //             }
1440 //           }
1441 //         }
1442 //       }
1443     }
1444     break;
1445
1446   case 702:  // Create mesh
1447     startOperation( 702 );
1448     break;
1449   case 703:  // Create sub-mesh
1450     startOperation( 703 );
1451     break;
1452   case 704: // Edit mesh/sub-mesh
1453     startOperation( 704 );
1454     break;
1455   case 710: // Build compound mesh
1456     {
1457       if (checkLock(aStudy)) break;
1458       EmitSignalDeactivateDialog();
1459       new SMESHGUI_BuildCompoundDlg( this );
1460     }
1461     break;
1462   case 407: // DIAGONAL INVERSION
1463   case 408: // Delete diagonal
1464     {
1465       if ( !vtkwnd )
1466       {
1467         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1468           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1469         break;
1470       }
1471
1472       if ( checkLock( aStudy ) )
1473         break;
1474
1475       /*Standard_Boolean aRes;
1476       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1477       if ( aMesh->_is_nil() )
1478       {
1479         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1480           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1481         break;
1482       }
1483       */
1484       EmitSignalDeactivateDialog();
1485       if ( theCommandID == 407 )
1486         new SMESHGUI_TrianglesInversionDlg(this);
1487       else
1488         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1489       break;
1490     }
1491     case 409: // Change orientation
1492     case 410: // Union of triangles
1493     case 411: // Cutting of quadrangles
1494     {
1495       if ( !vtkwnd )
1496       {
1497         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1498           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1499         break;
1500       }
1501
1502       if ( checkLock( aStudy ) )
1503         break;
1504
1505       EmitSignalDeactivateDialog();
1506       SMESHGUI_MultiEditDlg* aDlg = NULL;
1507       if ( theCommandID == 409 )
1508         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1509       else if ( theCommandID == 410 )
1510         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1511       else
1512         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1513
1514       aDlg->show();
1515       break;
1516     }
1517   case 412: // Smoothing
1518     {
1519       if(checkLock(aStudy)) break;
1520       if( vtkwnd ) {
1521         EmitSignalDeactivateDialog();
1522         new SMESHGUI_SmoothingDlg( this );
1523       }
1524       else {
1525         SUIT_MessageBox::warn1(desktop(),
1526                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1527                               tr("SMESH_BUT_OK"));
1528       }
1529       break;
1530     }
1531   case 413: // Extrusion
1532     {
1533       if (checkLock(aStudy)) break;
1534       if (vtkwnd) {
1535         EmitSignalDeactivateDialog();
1536         new SMESHGUI_ExtrusionDlg ( this );
1537       } else {
1538         SUIT_MessageBox::warn1(desktop(),
1539                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1540                                tr("SMESH_BUT_OK"));
1541       }
1542       break;
1543     }
1544   case 414: // Revolution
1545     {
1546       if(checkLock(aStudy)) break;
1547       if( vtkwnd ) {
1548         EmitSignalDeactivateDialog();
1549         new SMESHGUI_RevolutionDlg( this );
1550       }
1551       else {
1552         SUIT_MessageBox::warn1(desktop(),
1553                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1554                               tr("SMESH_BUT_OK"));
1555       }
1556       break;
1557     }
1558   case 415: // Pattern mapping
1559     {
1560       if ( checkLock( aStudy ) )
1561         break;
1562       if ( vtkwnd )
1563       {
1564         EmitSignalDeactivateDialog();
1565         new SMESHGUI_MeshPatternDlg( this );
1566       }
1567       else {
1568         SUIT_MessageBox::warn1(desktop(),
1569                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1570                               tr("SMESH_BUT_OK"));
1571       }
1572       break;
1573     }
1574   case 416: // Extrusion along a path
1575     {
1576       if (checkLock(aStudy)) break;
1577       if (vtkwnd) {
1578         EmitSignalDeactivateDialog();
1579         new SMESHGUI_ExtrusionAlongPathDlg( this );
1580       } else {
1581         SUIT_MessageBox::warn1(desktop(),
1582                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1583                                tr("SMESH_BUT_OK"));
1584       }
1585       break;
1586     }
1587   case 417: // Convert mesh to quadratic
1588     {
1589     startOperation( 417 );
1590       /*      if (checkLock(aStudy)) break;
1591       if (vtkwnd) {
1592         EmitSignalDeactivateDialog();
1593         new SMESHGUI_ConvToQuadDlg();
1594       } else {
1595         SUIT_MessageBox::warn1(desktop(),
1596                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1597                                tr("SMESH_BUT_OK"));
1598                                }*/
1599       break;
1600     }
1601   case 801:                                     // CREATE GROUP
1602     {
1603       if ( !vtkwnd )
1604       {
1605         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1606           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1607         break;
1608       }
1609
1610       if(checkLock(aStudy)) break;
1611       EmitSignalDeactivateDialog();
1612       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1613
1614       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1615       SALOME_ListIO selected;
1616       if( aSel )
1617         aSel->selectedObjects( selected );
1618
1619       int nbSel = selected.Extent();
1620       if (nbSel == 1) {
1621         // check if mesh is selected
1622         aMesh = SMESH::GetMeshByIO( selected.First() );
1623       }
1624       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1625       aDlg->show();
1626       break;
1627     }
1628
1629   case 802:                                     // CONSTRUCT GROUP
1630     {
1631       if ( !vtkwnd )
1632       {
1633         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1634           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1635         break;
1636       }
1637
1638       if(checkLock(aStudy)) break;
1639       EmitSignalDeactivateDialog();
1640
1641       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1642       SALOME_ListIO selected;
1643       if( aSel )
1644         aSel->selectedObjects( selected );
1645
1646       int nbSel = selected.Extent();
1647       if (nbSel == 1) {
1648         // check if submesh is selected
1649         Handle(SALOME_InteractiveObject) IObject = selected.First();
1650         if (IObject->hasEntry()) {
1651           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1652           if( aSObj ) {
1653             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1654             if (!aSubMesh->_is_nil()) {
1655               try {
1656                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1657                 // get submesh elements list by types
1658                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1659                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1660                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1661                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1662                 // create group for each type o elements
1663                 QString aName = IObject->getName();
1664                 if (aNodes->length() > 0) {
1665                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1666                   aGroup->Add(aNodes.inout());
1667                 }
1668                 if (aEdges->length() > 0) {
1669                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1670                   aGroup->Add(aEdges.inout());
1671                 }
1672                 if (aFaces->length() > 0) {
1673                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1674                   aGroup->Add(aFaces.inout());
1675                 }
1676                 if (aVolumes->length() > 0) {
1677                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1678                   aGroup->Add(aVolumes.inout());
1679                 }
1680                 updateObjBrowser();
1681
1682               }
1683               catch(const SALOME::SALOME_Exception & S_ex){
1684                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1685               }
1686             }
1687           }
1688         }
1689       }
1690       else if(nbSel==0) {
1691         SUIT_MessageBox::warn1(desktop(),
1692                                tr("SMESH_WRN_WARNING"),
1693                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1694                                tr("SMESH_BUT_OK"));
1695       }
1696       break;
1697     }
1698
1699   case 803:                                     // EDIT GROUP
1700     {
1701       if ( !vtkwnd )
1702       {
1703         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1704           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1705         break;
1706       }
1707
1708       if(checkLock(aStudy)) break;
1709       EmitSignalDeactivateDialog();
1710
1711       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1712       SALOME_ListIO selected;
1713       if( aSel )
1714         aSel->selectedObjects( selected );
1715
1716       SALOME_ListIteratorOfListIO It (selected);
1717       int nbSelectedGroups = 0;
1718       for ( ; It.More(); It.Next() )
1719       {
1720         SMESH::SMESH_GroupBase_var aGroup =
1721           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1722         if (!aGroup->_is_nil()) {
1723           nbSelectedGroups++;
1724           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1725           aDlg->show();
1726         }
1727       }
1728       if (nbSelectedGroups == 0)
1729         {
1730           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1731           aDlg->show();
1732         }
1733       break;
1734     }
1735
1736   case 804:                                     // Add elements to group
1737     {
1738       if(checkLock(aStudy)) break;
1739       if (myState == 800) {
1740         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1741         if (aDlg) aDlg->onAdd();
1742       }
1743       break;
1744     }
1745
1746   case 805:                                     // Remove elements from group
1747     {
1748       if(checkLock(aStudy)) break;
1749       if (myState == 800) {
1750         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1751         if (aDlg) aDlg->onRemove();
1752       }
1753       break;
1754     }
1755
1756     case 810: // Union Groups
1757     case 811: // Intersect groups
1758     case 812: // Cut groups
1759     {
1760       if ( !vtkwnd )
1761       {
1762         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1763           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1764         break;
1765       }
1766
1767       if ( checkLock( aStudy ) )
1768         break;
1769
1770       EmitSignalDeactivateDialog();
1771
1772       int aMode;
1773       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1774       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1775       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1776
1777       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1778       break;
1779     }
1780
1781     case 813: // Delete groups with their contents
1782     {
1783       if ( !vtkwnd )
1784       {
1785         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1786           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1787         break;
1788       }
1789
1790       if ( checkLock( aStudy ) )
1791         break;
1792
1793       EmitSignalDeactivateDialog();
1794
1795       new SMESHGUI_DeleteGroupDlg( this );
1796       break;
1797     }
1798
1799   case 900:                                     // MESH INFOS
1800     {
1801       EmitSignalDeactivateDialog();
1802       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1803       SALOME_ListIO selected;
1804       if( aSel )
1805         aSel->selectedObjects( selected );
1806
1807       if ( selected.Extent() > 1 ) { // a dlg for each IO
1808         SALOME_ListIO IOs;
1809         SALOME_ListIteratorOfListIO It (selected);
1810         for ( ; It.More(); It.Next() ) {
1811           IOs.Clear(); IOs.Append( It.Value() );
1812           aSel->setSelectedObjects( IOs );
1813           new SMESHGUI_MeshInfosDlg(this, "", false);
1814         }
1815         // restore selection
1816         aSel->setSelectedObjects( selected );
1817       }
1818       else
1819         new SMESHGUI_MeshInfosDlg(this, "", false);
1820       break;
1821     }
1822
1823   case 902:                                     // STANDARD MESH INFOS
1824     {
1825       EmitSignalDeactivateDialog();
1826       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1827       SALOME_ListIO selected;
1828       if( aSel )
1829         aSel->selectedObjects( selected );
1830
1831       if ( selected.Extent() > 1 ) { // a dlg for each IO
1832         SALOME_ListIO IOs;
1833         SALOME_ListIteratorOfListIO It (selected);
1834         for ( ; It.More(); It.Next() ) {
1835           IOs.Clear();
1836           IOs.Append( It.Value() );
1837           aSel->setSelectedObjects( IOs );
1838           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1839         }
1840         // restore selection
1841         aSel->setSelectedObjects( selected );
1842       }
1843       else
1844         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1845       break;
1846     }
1847
1848   case 1100:                                    // EDIT HYPOTHESIS
1849     {
1850       if(checkLock(aStudy)) break;
1851
1852       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1853       SALOME_ListIO selected;
1854       if( aSel )
1855         aSel->selectedObjects( selected );
1856
1857       int nbSel = selected.Extent();
1858
1859       if (nbSel == 1) {
1860         SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(selected.First());
1861
1862         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1863         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1864         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1865         if ( !Hyp->_is_nil() )
1866         {
1867           char* sName = Hyp->GetName();
1868           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
1869           if (aCreator)
1870             aCreator->edit( Hyp.in(), desktop() );
1871           else
1872           {
1873             // report error
1874           }
1875         }
1876       }
1877       updateObjBrowser( true );
1878       break;
1879     }
1880
1881   case 1101:                                    // RENAME
1882     {
1883       if ( checkLock( aStudy ) )
1884         break;
1885
1886       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1887       SALOME_ListIO selected;
1888       if( aSel )
1889         aSel->selectedObjects( selected );
1890
1891       SALOME_ListIteratorOfListIO It( selected );
1892       for ( ; It.More(); It.Next() )
1893       {
1894         Handle(SALOME_InteractiveObject) IObject = It.Value();
1895         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
1896         _PTR(GenericAttribute) anAttr;
1897         _PTR(AttributeName) aName;
1898         if ( obj )
1899         {
1900           if ( obj->FindAttribute(anAttr, "AttributeName") )
1901           {
1902             aName = anAttr;
1903             QString newName = QString(aName->Value().c_str());
1904             newName = LightApp_NameDlg::getName(desktop(), newName);
1905             if ( !newName.isEmpty() )
1906             {
1907               //old source: aStudy->renameIObject( IObject, newName );
1908               aName->SetValue( newName.latin1() );
1909
1910               // if current object is group update group's name
1911               SMESH::SMESH_GroupBase_var aGroup =
1912                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1913               if (!aGroup->_is_nil() )
1914                 aGroup->SetName( newName.latin1() );
1915
1916               updateObjBrowser();
1917             }
1918           }
1919         }
1920       }
1921       break;
1922     }
1923
1924   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1925     {
1926       if(checkLock(aStudy)) break;
1927       SUIT_OverrideCursor wc;
1928
1929       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1930       SALOME_ListIO selected;
1931       if( aSel )
1932         aSel->selectedObjects( selected, QString::null, false );
1933
1934       SALOME_ListIteratorOfListIO It(selected);
1935       for (int i = 0; It.More(); It.Next(), i++) {
1936         Handle(SALOME_InteractiveObject) IObject = It.Value();
1937         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1938       }
1939       SALOME_ListIO l1;
1940       aSel->setSelectedObjects( l1 );
1941       updateObjBrowser();
1942       break;
1943     }
1944
1945   case 401:                                     // GEOM::EDGE
1946   case 4021:                                    // TRIANGLE
1947   case 4022:                                    // QUAD
1948   case 4023:                                    // POLYGON
1949   case 4031:                                    // TETRA
1950   case 4032:                                    // HEXA
1951     {
1952       if(checkLock(aStudy)) break;
1953       if ( vtkwnd ) {
1954         EmitSignalDeactivateDialog();
1955         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1956         int                 nbNodes = 2;
1957         switch (theCommandID) {
1958         case 4021:                                      // TRIANGLE
1959           type = SMDSAbs_Face; nbNodes = 3; break;
1960         case 4022:                                      // QUAD
1961           type = SMDSAbs_Face; nbNodes = 4; break;
1962         case 4031:                                      // TETRA
1963           type = SMDSAbs_Volume; nbNodes = 4; break;
1964         case 4023:                                      // POLYGON
1965           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
1966         case 4032:                                      // HEXA
1967           type = SMDSAbs_Volume; nbNodes = 8; break;
1968         case 4033:                                      // POLYHEDRE
1969           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
1970         default:;
1971         }
1972         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
1973       }
1974       else {
1975         SUIT_MessageBox::warn1(desktop(),
1976                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1977                               tr("SMESH_BUT_OK"));
1978       }
1979       break;
1980     }
1981   case 4033:                                    // POLYHEDRON
1982     {
1983       if(checkLock(aStudy)) break;
1984       if ( vtkwnd ) {
1985         EmitSignalDeactivateDialog();
1986         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
1987       }
1988       else {
1989         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
1990                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1991                               tr("SMESH_BUT_OK"));
1992       }
1993       break;
1994     }
1995   case 4034:     // QUADRATIC EDGE
1996   case 4035:     // QUADRATIC TRIANGLE
1997   case 4036:     // QUADRATIC QUADRANGLE
1998   case 4037:     // QUADRATIC TETRAHEDRON
1999   case 4038:     // QUADRATIC PYRAMID
2000   case 4039:     // QUADRATIC PENTAHEDRON
2001   case 4040:     // QUADRATIC HEXAHEDRON
2002     {
2003       if(checkLock(aStudy)) break;
2004       if ( vtkwnd ) {
2005         EmitSignalDeactivateDialog();
2006         int type;
2007
2008         switch (theCommandID) {
2009         case 4034:
2010           type = QUAD_EDGE; break;
2011         case 4035:
2012           type = QUAD_TRIANGLE; break;
2013         case 4036:
2014           type = QUAD_QUADRANGLE; break;
2015         case 4037:
2016           type = QUAD_TETRAHEDRON; break;
2017         case 4038:
2018           type = QUAD_PYRAMID; break;
2019         case 4039:
2020           type = QUAD_PENTAHEDRON; break;
2021         case 4040:
2022           type = QUAD_HEXAHEDRON;
2023           break;
2024         default:;
2025         }
2026          new SMESHGUI_AddQuadraticElementDlg( this, type );
2027       }
2028       else {
2029         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2030                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2031                                tr("SMESH_BUT_OK"));
2032       }
2033       break;
2034     }
2035   case 4041:                                    // REMOVES NODES
2036     {
2037       if(checkLock(aStudy)) break;
2038       if ( vtkwnd ) {
2039         EmitSignalDeactivateDialog();
2040         new SMESHGUI_RemoveNodesDlg(this);
2041       }
2042       else {
2043         SUIT_MessageBox::warn1(desktop(),
2044                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2045                               tr("SMESH_BUT_OK"));
2046       }
2047       break;
2048     }
2049   case 4042:                                    // REMOVES ELEMENTS
2050     {
2051       if(checkLock(aStudy)) break;
2052       if( vtkwnd ) {
2053         EmitSignalDeactivateDialog();
2054         new SMESHGUI_RemoveElementsDlg(this);
2055       }
2056       else
2057         {
2058           SUIT_MessageBox::warn1(desktop(),
2059                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2060                                 tr("SMESH_BUT_OK"));
2061         }
2062       break;
2063     }
2064   case 4051:                                    // RENUMBERING NODES
2065     {
2066       if(checkLock(aStudy)) break;
2067       if( vtkwnd ) {
2068         EmitSignalDeactivateDialog();
2069         new SMESHGUI_RenumberingDlg( this, "", 0);
2070       }
2071       else
2072         {
2073           SUIT_MessageBox::warn1(desktop(),
2074                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2075                                 tr("SMESH_BUT_OK"));
2076         }
2077       break;
2078     }
2079   case 4052:                                    // RENUMBERING ELEMENTS
2080     {
2081       if(checkLock(aStudy)) break;
2082       if ( vtkwnd ) {
2083         EmitSignalDeactivateDialog();
2084         new SMESHGUI_RenumberingDlg( this, "", 1);
2085       }
2086       else
2087         {
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 4061:                                   // TRANSLATION
2095     {
2096       if(checkLock(aStudy)) break;
2097       if ( vtkwnd ) {
2098         EmitSignalDeactivateDialog();
2099         new SMESHGUI_TranslationDlg( this );
2100       }
2101       else {
2102         SUIT_MessageBox::warn1(desktop(),
2103                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2104                               tr("SMESH_BUT_OK"));
2105       }
2106       break;
2107     }
2108   case 4062:                                   // ROTATION
2109     {
2110       if(checkLock(aStudy)) break;
2111       if( vtkwnd ) {
2112         EmitSignalDeactivateDialog();
2113         new SMESHGUI_RotationDlg( this );
2114       }
2115       else {
2116         SUIT_MessageBox::warn1(desktop(),
2117                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2118                               tr("SMESH_BUT_OK"));
2119       }
2120       break;
2121     }
2122   case 4063:                                   // SYMMETRY
2123     {
2124       if(checkLock(aStudy)) break;
2125       if(vtkwnd) {
2126         EmitSignalDeactivateDialog();
2127         new SMESHGUI_SymmetryDlg( this );
2128       }
2129       else {
2130         SUIT_MessageBox::warn1(desktop(),
2131                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2132                               tr("SMESH_BUT_OK"));
2133       }
2134       break;
2135     }
2136   case 4064:                                   // SEWING
2137     {
2138       if(checkLock(aStudy)) break;
2139       if(vtkwnd) {
2140         EmitSignalDeactivateDialog();
2141         new SMESHGUI_SewingDlg( this );
2142       }
2143       else {
2144         SUIT_MessageBox::warn1(desktop(),
2145                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2146                               tr("SMESH_BUT_OK"));
2147       }
2148       break;
2149     }
2150   case 4065:                                   // MERGE NODES
2151     {
2152       if(checkLock(aStudy)) break;
2153       if(vtkwnd) {
2154         EmitSignalDeactivateDialog();
2155         new SMESHGUI_EditMeshDlg( this, 0 );
2156       }
2157       else {
2158         SUIT_MessageBox::warn1(desktop(),
2159                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2160                               tr("SMESH_BUT_OK"));
2161       }
2162       break;
2163     }
2164   case 4066:                                   // MERGE EQUAL ELEMENTS
2165     {
2166       if (checkLock(aStudy)) break;
2167       if (vtkwnd) {
2168         EmitSignalDeactivateDialog();
2169         new SMESHGUI_EditMeshDlg( this, 1 );
2170       } else {
2171         SUIT_MessageBox::warn1(desktop(),
2172                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2173                               tr("SMESH_BUT_OK"));
2174       }
2175       break;
2176     }
2177
2178   case 4067: // MAKE MESH PASS THROUGH POINT
2179     startOperation( 4067 );
2180     break;
2181
2182   case 5105: // Library of selection filters
2183   {
2184     static QValueList<int> aTypes;
2185     if ( aTypes.isEmpty() )
2186     {
2187       aTypes.append( SMESH::NODE );
2188       aTypes.append( SMESH::EDGE );
2189       aTypes.append( SMESH::FACE );
2190       aTypes.append( SMESH::VOLUME );
2191     }
2192     if (!myFilterLibraryDlg)
2193       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2194     else if (myFilterLibraryDlg->isHidden())
2195       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2196     myFilterLibraryDlg->raise();
2197   }
2198   break;
2199
2200   case 6017:                                    // CONTROLS
2201   case 6016:
2202   case 6015:
2203   case 6014:
2204   case 6013:
2205   case 6012:
2206   case 6011:
2207   case 6001:
2208   case 6018:
2209   case 6019:
2210   case 6002:
2211   case 6003:
2212   case 6004:
2213   case 6009:
2214     if ( vtkwnd ) {
2215
2216       LightApp_SelectionMgr* mgr = selectionMgr();
2217       SALOME_ListIO selected; mgr->selectedObjects( selected );
2218
2219       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2220         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2221         if ( SO ) {
2222           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2223           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2224           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2225           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2226           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2227             ::Control( theCommandID );
2228             break;
2229           }
2230         }
2231       }
2232       SUIT_MessageBox::warn1(desktop(),
2233                             tr( "SMESH_WRN_WARNING" ),
2234                             tr( "SMESH_BAD_SELECTION" ),
2235                             tr( "SMESH_BUT_OK" ) );
2236       break;
2237     }
2238     else {
2239       SUIT_MessageBox::warn1(desktop(),
2240                             tr( "SMESH_WRN_WARNING" ),
2241                             tr( "NOT_A_VTK_VIEWER" ),
2242                             tr( "SMESH_BUT_OK" ) );
2243     }
2244     break;
2245   case 9010:
2246     {
2247       LightApp_SelectionMgr* mgr = selectionMgr();
2248       SALOME_ListIO selected; mgr->selectedObjects( selected );
2249
2250       SALOME_ListIteratorOfListIO it(selected);
2251       for(; it.More(); it.Next()) {
2252         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2253         if(anIObject->hasEntry()) {
2254           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2255             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2256           }
2257         }
2258       }
2259       break;
2260     }
2261   case 9011:
2262     {
2263       LightApp_SelectionMgr* mgr = selectionMgr();
2264       SALOME_ListIO selected; mgr->selectedObjects( selected );
2265
2266       if (selected.Extent() == 1)       {
2267         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2268         if(anIObject->hasEntry())
2269           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2270             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2271           }
2272       }
2273       break;
2274     }
2275   }
2276
2277   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2278   //updateObjBrowser();
2279   return true;
2280 }
2281
2282 //=============================================================================
2283 /*!
2284  *
2285  */
2286 //=============================================================================
2287 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2288 {
2289   return false;
2290 }
2291
2292 //=============================================================================
2293 /*!
2294  *
2295  */
2296 //=============================================================================
2297 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2298 {
2299   return true;
2300 }
2301
2302 //=============================================================================
2303 /*!
2304  *
2305  */
2306 //=============================================================================
2307 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2308 {
2309   return true;
2310 }
2311
2312 //=============================================================================
2313 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2314  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2315  */
2316 //=============================================================================
2317 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2318                                   SUIT_ViewWindow* wnd )
2319 {
2320   if(theIO->hasEntry()){
2321     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2322     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2323   }
2324 }
2325
2326 //=======================================================================
2327 // function : createSMESHAction
2328 // purpose  :
2329 //=======================================================================
2330 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2331 {
2332   QIconSet icon;
2333   QWidget* parent = application()->desktop();
2334   SUIT_ResourceMgr* resMgr = resourceMgr();
2335   QPixmap pix;
2336   if ( icon_id.length() )
2337     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2338   else
2339     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2340   if ( !pix.isNull() )
2341     icon = QIconSet( pix );
2342
2343   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2344           menu       = tr( QString( "MEN_" )+po_id ),
2345           status_bar = tr( QString( "STB_" )+po_id );
2346
2347   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2348 }
2349
2350 //=======================================================================
2351 // function : createPopupItem
2352 // purpose  :
2353 //=======================================================================
2354 void SMESHGUI::createPopupItem( const int id,
2355                                 const QString& clients,
2356                                 const QString& types,
2357                                 const QString& theRule,
2358                                 const int pId )
2359 {
2360   int parentId = pId;
2361   if( pId!=-1 )
2362     parentId = popupMgr()->actionId( action( pId ) );
2363
2364   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2365     popupMgr()->insert( action( id ), parentId, 0 );
2366
2367   QChar lc = QtxPopupMgr::Selection::defEquality();
2368   QString rule = "(%1) and (%2) and (%3)";
2369   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2370   if( clients.isEmpty() )
2371     rule = rule.arg( QString( "true" ) );
2372   else
2373     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2374   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2375   rule += theRule;
2376
2377   bool cont = myRules.contains( id );
2378   if( cont )
2379     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2380
2381   popupMgr()->setRule( action( id ), rule, true );
2382   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2383 }
2384
2385 //=======================================================================
2386 // function : initialize
2387 // purpose  :
2388 //=======================================================================
2389 void SMESHGUI::initialize( CAM_Application* app )
2390 {
2391   SalomeApp_Module::initialize( app );
2392
2393 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2394 //   if ( mgr )
2395   /* Automatic Update flag */
2396 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2397
2398   // ----- create actions --------------
2399
2400   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2401   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2402   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2403   createSMESHAction(  114, "NUM" );
2404   createSMESHAction(  121, "DAT" );
2405   createSMESHAction(  122, "MED" );
2406   createSMESHAction(  123, "UNV" );
2407   createSMESHAction(  140, "STL" );
2408   createSMESHAction(  124, "EXPORT_DAT" );
2409   createSMESHAction(  125, "EXPORT_MED" );
2410   createSMESHAction(  126, "EXPORT_UNV" );
2411   createSMESHAction(  141, "EXPORT_STL" );
2412   createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
2413   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2414   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2415   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2416   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2417   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2418   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2419   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2420   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2421   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2422   createSMESHAction(  804, "ADD" );
2423   createSMESHAction(  805, "REMOVE" );
2424   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2425   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2426   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2427   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2428   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2429   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2430   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2431   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2432   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2433   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2434   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2435   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2436   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2437   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2438   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2439   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2440   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2441   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2442   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2443   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2444   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2445   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2446   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2447   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2448   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2449   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2450   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2451   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2452   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2453   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2454   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2455   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2456   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2457   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2458   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2459   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2460   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2461   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2462   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2463   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2464   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2465   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2466   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2467   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2468   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2469   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2470   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2471   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2472   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2473   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2474   createSMESHAction(  200, "RESET" );
2475   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2476   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2477   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2478   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2479   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2480   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2481   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2482   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2483   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2484   createSMESHAction(  220, "ALL" );
2485   createSMESHAction( 1100, "EDIT_HYPO" );
2486   createSMESHAction( 1101, "RENAME" );
2487   createSMESHAction( 1102, "UNASSIGN" );
2488   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2489   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2490   createSMESHAction( 1131, "DISPMODE" );
2491   createSMESHAction( 1132, "COLORS" );
2492   createSMESHAction( 1133, "TRANSP" );
2493   createSMESHAction( 1134, "CLIP" );
2494   createSMESHAction( 1135, "DISP_ENT" );
2495   createSMESHAction( 2000, "CTRL" );
2496
2497   createSMESHAction( 300, "ERASE" );
2498   createSMESHAction( 301, "DISPLAY" );
2499   createSMESHAction( 302, "DISPLAY_ONLY" );
2500   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2501   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2502   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2503   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2504   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2505   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2506   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2507   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2508
2509   // ----- create menu --------------
2510   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2511       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2512       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2513       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2514       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2515       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2516       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2517
2518   createMenu( separator(), fileId );
2519
2520   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2521       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2522       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2523       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2524       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2525       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2526
2527   createMenu( 111, importId, -1 );
2528   createMenu( 112, importId, -1 );
2529   createMenu( 113, importId, -1 );
2530
2531   createMenu( 121, exportId, -1 );
2532   createMenu( 122, exportId, -1 );
2533   createMenu( 123, exportId, -1 );
2534   createMenu( 140, exportId, -1 ); // export to stl STL
2535
2536   createMenu( separator(), fileId, 10 );
2537
2538   createMenu( 33, editId, -1 );
2539
2540   createMenu( 5105, toolsId, -1 );
2541
2542   createMenu( 702, meshId, -1 );
2543   createMenu( 703, meshId, -1 );
2544   createMenu( 704, meshId, -1 );
2545   createMenu( 710, meshId, -1 );
2546   createMenu( separator(), meshId, -1 );
2547   createMenu( 701, meshId, -1 );
2548   createMenu( separator(), meshId, -1 );
2549   createMenu( 801, meshId, -1 );
2550   createMenu( 802, meshId, -1 );
2551   createMenu( 803, meshId, -1 );
2552   createMenu( separator(), meshId, -1 );
2553   createMenu( 810, meshId, -1 );
2554   createMenu( 811, meshId, -1 );
2555   createMenu( 812, meshId, -1 );
2556   createMenu( separator(), meshId, -1 );
2557   createMenu( 813, meshId, -1 );
2558   createMenu( separator(), meshId, -1 );
2559   createMenu( 900, meshId, -1 );
2560   createMenu( 902, meshId, -1 );
2561   createMenu( separator(), meshId, -1 );
2562
2563   createMenu( 6003, ctrlId, -1 );
2564   createMenu( 6001, ctrlId, -1 );
2565   createMenu( 6004, ctrlId, -1 );
2566   createMenu( separator(), ctrlId, -1 );
2567   createMenu( 6002, ctrlId, -1 );
2568   createMenu( 6018, ctrlId, -1 );
2569   createMenu( 6019, ctrlId, -1 );
2570   createMenu( 6011, ctrlId, -1 );
2571   createMenu( 6012, ctrlId, -1 );
2572   createMenu( 6013, ctrlId, -1 );
2573   createMenu( 6014, ctrlId, -1 );
2574   createMenu( 6015, ctrlId, -1 );
2575   createMenu( 6016, ctrlId, -1 );
2576   createMenu( separator(), ctrlId, -1 );
2577   createMenu( 6017, ctrlId, -1 );
2578   createMenu( 6009, ctrlId, -1 );
2579   createMenu( separator(), ctrlId, -1 );
2580
2581   createMenu( 400, addId, -1 );
2582   createMenu( 401, addId, -1 );
2583   createMenu( 4021, addId, -1 );
2584   createMenu( 4022, addId, -1 );
2585   createMenu( 4023, addId, -1 );
2586   createMenu( 4031, addId, -1 );
2587   createMenu( 4032, addId, -1 );
2588   createMenu( 4033, addId, -1 );
2589   createMenu( separator(), addId, -1 );
2590   createMenu( 4034, addId, -1 );
2591   createMenu( 4035, addId, -1 );
2592   createMenu( 4036, addId, -1 );
2593   createMenu( 4037, addId, -1 );
2594   createMenu( 4038, addId, -1 );
2595   createMenu( 4039, addId, -1 );
2596   createMenu( 4040, addId, -1 );
2597
2598   createMenu( 4041, removeId, -1 );
2599   createMenu( 4042, removeId, -1 );
2600
2601   createMenu( 4051, renumId, -1 );
2602   createMenu( 4052, renumId, -1 );
2603
2604   createMenu( 4061, transfId, -1 );
2605   createMenu( 4062, transfId, -1 );
2606   createMenu( 4063, transfId, -1 );
2607   createMenu( 4064, transfId, -1 );
2608   createMenu( 4065, transfId, -1 );
2609   createMenu( 4066, transfId, -1 );
2610
2611   createMenu( 406, modifyId, -1 );
2612   createMenu( 4067,modifyId, -1 );
2613   createMenu( 407, modifyId, -1 );
2614   createMenu( 408, modifyId, -1 );
2615   createMenu( 409, modifyId, -1 );
2616   createMenu( 410, modifyId, -1 );
2617   createMenu( 411, modifyId, -1 );
2618   createMenu( 412, modifyId, -1 );
2619   createMenu( 413, modifyId, -1 );
2620   createMenu( 416, modifyId, -1 );
2621   createMenu( 414, modifyId, -1 );
2622   createMenu( 415, modifyId, -1 );
2623   createMenu( 417, modifyId, -1 );
2624
2625   createMenu( 214, viewId, -1 );
2626
2627   // ----- create toolbars --------------
2628   int meshTb     = createTool( tr( "TB_MESH" ) ),
2629       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2630       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2631       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2632       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2633
2634   createTool( 702, meshTb );
2635   createTool( 703, meshTb );
2636   createTool( 704, meshTb );
2637   createTool( 710, meshTb );
2638   createTool( separator(), meshTb );
2639   createTool( 701, meshTb );
2640   createTool( separator(), meshTb );
2641   createTool( 801, meshTb );
2642   createTool( 802, meshTb );
2643   createTool( 803, meshTb );
2644   createTool( separator(), meshTb );
2645   createTool( 900, meshTb );
2646   createTool( 902, meshTb );
2647   createTool( separator(), meshTb );
2648
2649   createTool( 6001, ctrlTb );
2650   createTool( 6003, ctrlTb );
2651   createTool( 6004, ctrlTb );
2652   createTool( separator(), ctrlTb );
2653   createTool( 6002, ctrlTb );
2654   createTool( 6018, ctrlTb );
2655   createTool( 6019, ctrlTb );
2656   createTool( 6011, ctrlTb );
2657   createTool( 6012, ctrlTb );
2658   createTool( 6013, ctrlTb );
2659   createTool( 6014, ctrlTb );
2660   createTool( 6015, ctrlTb );
2661   createTool( 6016, ctrlTb );
2662   createTool( separator(), ctrlTb );
2663   createTool( 6017, ctrlTb );
2664   createTool( 6009, ctrlTb );
2665   createTool( separator(), ctrlTb );
2666
2667   createTool( 400, addRemTb );
2668   createTool( 401, addRemTb );
2669   createTool( 4021, addRemTb );
2670   createTool( 4022, addRemTb );
2671   createTool( 4023, addRemTb );
2672   createTool( 4031, addRemTb );
2673   createTool( 4032, addRemTb );
2674   createTool( 4033, addRemTb );
2675   createTool( separator(), addRemTb );
2676   createTool( 4034, addRemTb );
2677   createTool( 4035, addRemTb );
2678   createTool( 4036, addRemTb );
2679   createTool( 4037, addRemTb );
2680   createTool( 4038, addRemTb );
2681   createTool( 4039, addRemTb );
2682   createTool( 4040, addRemTb );
2683   createTool( separator(), addRemTb );
2684   createTool( 4041, addRemTb );
2685   createTool( 4042, addRemTb );
2686   createTool( separator(), addRemTb );
2687   createTool( 4051, addRemTb );
2688   createTool( 4052, addRemTb );
2689   createTool( separator(), addRemTb );
2690   createTool( 4061, addRemTb );
2691   createTool( 4062, addRemTb );
2692   createTool( 4063, addRemTb );
2693   createTool( 4064, addRemTb );
2694   createTool( 4065, addRemTb );
2695   createTool( 4066, addRemTb );
2696   createTool( separator(), addRemTb );
2697
2698   createTool( 406, modifyTb );
2699   createTool( 4067,modifyTb );
2700   createTool( 407, modifyTb );
2701   createTool( 408, modifyTb );
2702   createTool( 409, modifyTb );
2703   createTool( 410, modifyTb );
2704   createTool( 411, modifyTb );
2705   createTool( 412, modifyTb );
2706   createTool( 413, modifyTb );
2707   createTool( 416, modifyTb );
2708   createTool( 414, modifyTb );
2709   createTool( 415, modifyTb );
2710   createTool( 417, modifyTb );
2711
2712   createTool( 214, dispModeTb );
2713
2714
2715   myRules.clear();
2716   QString OB = "'ObjectBrowser'",
2717           View = "'" + SVTK_Viewer::Type() + "'",
2718           pat = "'%1'",
2719           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2720           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2721           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2722           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2723           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2724                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2725                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2726                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2727                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2728                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2729                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2730           subMesh = elems,
2731           mesh_group = mesh + " " + subMesh + " " + group,
2732           hyp_alg = hypo + " " + algo;
2733
2734   // popup for object browser
2735
2736   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2737   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2738   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2739   popupMgr()->insert( separator(), -1, 0 );
2740   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2741   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2742   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2743   createPopupItem( 902, OB, mesh );                        // STD_INFO
2744   popupMgr()->insert( separator(), -1, 0 );
2745   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2746   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2747   popupMgr()->insert( separator(), -1, 0 );
2748   createPopupItem( 1100, OB, hypo, "" /*"&& $hasReference={false}"*/ );   // EDIT HYPOTHESIS
2749   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2750   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "" /*"&& $hasReference={false}"*/ ); // RENAME
2751   popupMgr()->insert( separator(), -1, 0 );
2752
2753   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2754   createPopupItem( 125, OB, mesh, only_one_non_empty );    // EXPORT_MED
2755   createPopupItem( 126, OB, mesh, only_one_non_empty );    // EXPORT_UNV
2756   createPopupItem( 141, OB, mesh, only_one_non_empty );    // EXPORT_STL
2757   createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
2758   popupMgr()->insert( separator(), -1, 0 );
2759
2760   // popup for viewer
2761   createPopupItem( 803, View, group ); // EDIT_GROUP
2762   createPopupItem( 804, View, elems ); // ADD
2763   createPopupItem( 805, View, elems ); // REMOVE
2764   popupMgr()->insert( separator(), -1, 0 );
2765   createPopupItem( 214, View, mesh_group ); // UPDATE
2766   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2767   createPopupItem( 902, View, mesh );       // STD_INFO
2768   popupMgr()->insert( separator(), -1, 0 );
2769
2770   int anId;
2771   QString
2772     isInvisible("not( isVisible )"),
2773     isEmpty("numberOfNodes = 0"),
2774     isNotEmpty("numberOfNodes <> 0"),
2775
2776     // has nodes, edges, etc in VISIBLE! actor
2777     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2778     hasElems("(count( elemTypes ) > 0)"),
2779     hasDifferentElems("(count( elemTypes ) > 1)"),
2780     hasEdges("({'Edge'} in elemTypes)"),
2781     hasFaces("({'Face'} in elemTypes)"),
2782     hasVolumes("({'Volume'} in elemTypes)");
2783
2784   QString lc = QtxPopupMgr::Selection::defEquality();
2785   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2786   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
2787   aType = aType.arg( mesh_group );
2788   QString aMeshInVTK = aClient + "&&" + aType;
2789
2790   //-------------------------------------------------
2791   // Numbering
2792   //-------------------------------------------------
2793   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2794
2795   popupMgr()->insert( action( 9010 ), anId, -1 );
2796   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2797   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2798
2799   popupMgr()->insert( action( 9011 ), anId, -1 );
2800   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2801   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2802
2803   popupMgr()->insert( separator(), -1, -1 );
2804
2805   //-------------------------------------------------
2806   // Display Mode
2807   //-------------------------------------------------
2808   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2809
2810   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2811   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2812   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2813
2814   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2815   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2816   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2817
2818   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2819   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2820   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2821
2822   popupMgr()->insert( separator(), anId, -1 );
2823
2824   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2825   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2826   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2827
2828   //-------------------------------------------------
2829   // Display Entity
2830   //-------------------------------------------------
2831   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2832
2833   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2834
2835   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2836   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
2837   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2838
2839   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2840   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
2841   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2842
2843   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2844   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
2845   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2846
2847   popupMgr()->insert( separator(), anId, -1 );
2848
2849   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2850   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
2851
2852   //-------------------------------------------------
2853   // Color / Size
2854   //-------------------------------------------------
2855   popupMgr()->insert( action( 1132 ), -1, -1 );
2856   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
2857
2858   //-------------------------------------------------
2859   // Transparency
2860   //-------------------------------------------------
2861   popupMgr()->insert( action( 1133 ), -1, -1 );
2862   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
2863
2864   //-------------------------------------------------
2865   // Clipping
2866   //-------------------------------------------------
2867   popupMgr()->insert( action( 1134 ), -1, -1 );
2868   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
2869
2870   popupMgr()->insert( separator(), -1, -1 );
2871
2872   //-------------------------------------------------
2873   // Controls
2874   //-------------------------------------------------
2875   QString
2876     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
2877     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
2878     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
2879
2880   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
2881
2882   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
2883   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2884
2885   popupMgr()->insert( separator(), anId, -1 );
2886
2887   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
2888   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
2889   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
2890
2891   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
2892   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
2893   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
2894
2895   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
2896   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
2897   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
2898
2899   popupMgr()->insert( separator(), anId, -1 );
2900
2901   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
2902   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
2903   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
2904
2905   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
2906   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
2907   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
2908
2909   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
2910   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
2911   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
2912
2913   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
2914   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
2915   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
2916
2917   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
2918   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
2919   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
2920
2921   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
2922   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
2923   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
2924
2925   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
2926   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
2927   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
2928
2929   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
2930   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
2931   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
2932
2933   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
2934   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
2935   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
2936
2937   popupMgr()->insert( separator(), anId, -1 );
2938
2939   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
2940   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
2941   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
2942
2943   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
2944   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
2945   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
2946
2947   popupMgr()->insert( separator(), anId, -1 );
2948
2949   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
2950   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2951
2952   popupMgr()->insert( separator(), -1, -1 );
2953
2954   //-------------------------------------------------
2955   // Display / Erase
2956   //-------------------------------------------------
2957   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2958   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2959   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2960
2961   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
2962     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
2963   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
2964   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
2965
2966   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
2967   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
2968
2969   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
2970   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
2971
2972   popupMgr()->insert( separator(), -1, -1 );
2973
2974   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
2975            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
2976 }
2977
2978 bool SMESHGUI::activateModule( SUIT_Study* study )
2979 {
2980   bool res = SalomeApp_Module::activateModule( study );
2981
2982   setMenuShown( true );
2983   setToolShown( true );
2984
2985   // Reset actions accelerator keys
2986   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
2987   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
2988   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
2989
2990   return res;
2991 }
2992
2993 bool SMESHGUI::deactivateModule( SUIT_Study* study )
2994 {
2995   setMenuShown( false );
2996   setToolShown( false );
2997
2998   EmitSignalCloseAllDialogs();
2999
3000   // Unset actions accelerator keys
3001   action(111)->setAccel(QKeySequence()); // Import DAT
3002   action(112)->setAccel(QKeySequence()); // Import UNV
3003   action(113)->setAccel(QKeySequence()); // Import MED
3004
3005   return SalomeApp_Module::deactivateModule( study );
3006 }
3007
3008 void SMESHGUI::OnGUIEvent()
3009 {
3010   const QObject* obj = sender();
3011   if ( !obj || !obj->inherits( "QAction" ) )
3012     return;
3013   int id = actionId((QAction*)obj);
3014   if ( id != -1 )
3015     OnGUIEvent( id );
3016 }
3017
3018 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3019 {
3020   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3021   if ( CORBA::is_nil( myComponentSMESH ) )
3022     {
3023       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3024       if ( aStudy )
3025         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3026       return aGUI.myComponentSMESH;
3027     }
3028   if ( aStudy )
3029     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3030   return myComponentSMESH;
3031 }
3032
3033 QString SMESHGUI::engineIOR() const
3034 {
3035   CORBA::ORB_var anORB = getApp()->orb();
3036   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3037   return anIOR.in();
3038 }
3039
3040 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
3041 {
3042   SMESHGUI_Selection sel;
3043   sel.init( client, selectionMgr() );
3044   popupMgr()->updatePopup( menu, &sel );
3045 }
3046
3047 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3048 {
3049   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3050   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3051 }
3052
3053 void SMESHGUI::viewManagers( QStringList& list ) const
3054 {
3055   list.append( SVTK_Viewer::Type() );
3056 }
3057
3058 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3059 {
3060   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3061     SMESH::UpdateSelectionProp( this );
3062 }
3063
3064 void SMESHGUI::createPreferences()
3065 {
3066   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3067
3068   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3069   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3070
3071   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3072   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3073   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3074
3075   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3076   setPreferenceProperty( precGroup, "columns", 1 );
3077
3078   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3079
3080   setPreferenceProperty( prec, "min", 0 );
3081   setPreferenceProperty( prec, "max", 16 );
3082
3083   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3084   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3085   QStringList modes;
3086   modes.append( "Wireframe" );
3087   modes.append( "Shading" );
3088   modes.append( "Nodes" );
3089   modes.append( "Shrink" );
3090   QValueList<QVariant> indices;
3091   indices.append( 0 );
3092   indices.append( 1 );
3093   indices.append( 2 );
3094   indices.append( 3 );
3095   setPreferenceProperty( dispmode, "strings", modes );
3096   setPreferenceProperty( dispmode, "indexes", indices );
3097
3098   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3099   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3100   int renumber=addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3101
3102   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3103   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3104
3105   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3106   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3107
3108   setPreferenceProperty( nodeSz, "min", 1 );
3109   setPreferenceProperty( nodeSz, "max", 5 );
3110
3111   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3112
3113   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3114   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3115   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3116   addPreference( "", elemGroup, LightApp_Preferences::Space );
3117
3118   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3119   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3120
3121   setPreferenceProperty( elemW, "min", 1 );
3122   setPreferenceProperty( elemW, "max", 5 );
3123
3124   setPreferenceProperty( shrink, "min", 0 );
3125   setPreferenceProperty( shrink, "max", 100 );
3126
3127   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3128
3129   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3130
3131   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3132   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3133   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3134
3135   setPreferenceProperty( selW, "min", 1 );
3136   setPreferenceProperty( selW, "max", 5 );
3137
3138   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3139
3140   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3141   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3142
3143   setPreferenceProperty( preW, "min", 1 );
3144   setPreferenceProperty( preW, "max", 5 );
3145
3146   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3147
3148   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3149   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3150
3151   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3152   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3153
3154   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3155   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3156   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3157   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3158
3159   QStringList fam;
3160   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3161   fam.append( tr( "SMESH_FONT_COURIER" ) );
3162   fam.append( tr( "SMESH_FONT_TIMES" ) );
3163   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3164
3165   setPreferenceProperty( tfont, "families", fam );
3166   setPreferenceProperty( tfont, "system", false );
3167   setPreferenceProperty( tfont, "widget_flags", wflag );
3168   setPreferenceProperty( lfont, "families", fam );
3169   setPreferenceProperty( lfont, "system", false );
3170   setPreferenceProperty( lfont, "widget_flags", wflag );
3171
3172   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3173
3174   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3175   setPreferenceProperty( numcol, "min", 2 );
3176   setPreferenceProperty( numcol, "max", 256 );
3177
3178   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3179   setPreferenceProperty( numlab, "min", 2 );
3180   setPreferenceProperty( numlab, "max", 65 );
3181
3182   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3183   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3184   QStringList orients;
3185   orients.append( tr( "SMESH_VERTICAL" ) );
3186   orients.append( tr( "SMESH_HORIZONTAL" ) );
3187   indices.clear(); indices.append( 0 ); indices.append( 1 );
3188   setPreferenceProperty( orient, "strings", orients );
3189   setPreferenceProperty( orient, "indexes", indices );
3190
3191   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3192   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3193   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3194   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3195   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3196   setPreferenceProperty( xv, "step", 0.1 );
3197   setPreferenceProperty( xv, "min", 0.0 );
3198   setPreferenceProperty( xv, "max", 1.0 );
3199   setPreferenceProperty( yv, "step", 0.1 );
3200   setPreferenceProperty( yv, "min", 0.0 );
3201   setPreferenceProperty( yv, "max", 1.0 );
3202   setPreferenceProperty( wv, "step", 0.1 );
3203   setPreferenceProperty( wv, "min", 0.0 );
3204   setPreferenceProperty( wv, "max", 1.0 );
3205   setPreferenceProperty( hv, "min", 0.0 );
3206   setPreferenceProperty( hv, "max", 1.0 );
3207   setPreferenceProperty( hv, "step", 0.1 );
3208
3209   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3210   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3211   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3212   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3213   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3214   setPreferenceProperty( xv, "min", 0.0 );
3215   setPreferenceProperty( xv, "max", 1.0 );
3216   setPreferenceProperty( xv, "step", 0.1 );
3217   setPreferenceProperty( xh, "min", 0.0 );
3218   setPreferenceProperty( xh, "max", 1.0 );
3219   setPreferenceProperty( xh, "step", 0.1 );
3220   setPreferenceProperty( yh, "min", 0.0 );
3221   setPreferenceProperty( yh, "max", 1.0 );
3222   setPreferenceProperty( yh, "step", 0.1 );
3223   setPreferenceProperty( wh, "min", 0.0 );
3224   setPreferenceProperty( wh, "max", 1.0 );
3225   setPreferenceProperty( wh, "step", 0.1 );
3226   setPreferenceProperty( hh, "min", 0.0 );
3227   setPreferenceProperty( hh, "max", 1.0 );
3228   setPreferenceProperty( hh, "step", 0.1 );
3229 }
3230
3231 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3232 {
3233   if( sect=="SMESH" ){
3234     float sbX1,sbY1,sbW,sbH;
3235     float aTol = 1.00000009999999;
3236     std::string aWarning;
3237     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3238     if( name=="selection_object_color" || name=="selection_element_color" ||
3239         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3240         name=="selection_precision_node" || name=="selection_precision_element" )
3241       SMESH::UpdateSelectionProp( this );
3242     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3243       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3244       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3245       if(sbX1+sbW > aTol){
3246         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3247         sbX1=0.01;
3248         sbW=0.05;
3249         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3250         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3251       }
3252     }
3253     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3254       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3255       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3256       if(sbY1+sbH > aTol){
3257         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3258         sbY1=0.01;
3259         sbH=0.5;
3260         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3261         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3262       }
3263     }
3264     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3265       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3266       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3267       if(sbX1+sbW > aTol){
3268         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3269         sbX1=0.2;
3270         sbW=0.6;
3271         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3272         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3273       }
3274     }
3275     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3276       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3277       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3278       if(sbY1+sbH > aTol){
3279         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3280         sbY1=0.01;
3281         sbH=0.12;
3282         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3283         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3284       }
3285     }
3286
3287     if(aWarning.size() != 0){
3288       aWarning += "The default values are applied instead.";
3289       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3290                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3291                              QObject::tr(aWarning.c_str()),
3292                              QObject::tr("SMESH_BUT_OK"));
3293     }
3294   }
3295 }
3296
3297 //================================================================================
3298 /*!
3299  * \brief Update something in accordance with update flags
3300   * \param theFlags - update flags
3301 *
3302 * Update viewer or/and object browser etc. in accordance with update flags ( see
3303 * LightApp_UpdateFlags enumeration ).
3304 */
3305 //================================================================================
3306 void SMESHGUI::update( const int flags )
3307 {
3308   if ( flags & UF_Viewer | flags & UF_Forced )
3309     SMESH::UpdateView();
3310   else
3311     SalomeApp_Module::update( flags );
3312 }
3313
3314 //================================================================================
3315 /*!
3316  * \brief Set default selection mode
3317 *
3318 * SLOT called when operation commited. Sets default selection mode
3319 */
3320 //================================================================================
3321 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3322 {
3323   SVTK_ViewWindow* vtkWnd =
3324     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3325   if ( vtkWnd )
3326     vtkWnd->SetSelectionMode( ActorSelection );
3327 }
3328
3329 //================================================================================
3330 /*!
3331  * \brief Set default selection mode
3332 *
3333 * SLOT called when operation aborted. Sets default selection mode
3334 */
3335 //================================================================================
3336 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3337 {
3338   SVTK_ViewWindow* vtkWnd =
3339     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3340   if ( vtkWnd )
3341     vtkWnd->SetSelectionMode( ActorSelection );
3342 }
3343
3344 //================================================================================
3345 /*!
3346  * \brief Creates operation with given identifier
3347   * \param id - identifier of operation to be started
3348   * \return Pointer on created operation or NULL if operation is not created
3349 *
3350 * Virtual method redefined from the base class creates operation with given id.
3351 * It is called called automatically from startOperation method of base class.
3352 */
3353 //================================================================================
3354 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3355 {
3356   LightApp_Operation* op = 0;
3357   // to do : create operation here
3358   switch( id )
3359   {
3360     case 701: // Compute mesh
3361       op = new SMESHGUI_ComputeOp();
3362     break;
3363     case 702: // Create mesh
3364       op = new SMESHGUI_MeshOp( true, true );
3365     break;
3366     case 703: // Create sub-mesh
3367       op = new SMESHGUI_MeshOp( true, false );
3368     break;
3369     case 704: // Edit mesh/sub-mesh
3370       op = new SMESHGUI_MeshOp( false );
3371     break;
3372     case 417: //convert to quadratic
3373       op = new SMESHGUI_ConvToQuadOp();
3374     break;
3375     case 4067: // make mesh pass through point
3376       op = new SMESHGUI_MakeNodeAtPointOp();
3377       break;
3378     default:
3379     break;
3380   }
3381
3382   if( !op )
3383     op = SalomeApp_Module::createOperation( id );
3384   return op;
3385 }
3386
3387 //================================================================================
3388 /*!
3389  * \brief Stops current operations and starts a given one
3390   * \param id - The id of the operation to start
3391  */
3392 //================================================================================
3393
3394 void SMESHGUI::switchToOperation(int id)
3395 {
3396   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3397     activeStudy()->abortAllOperations();
3398   startOperation( id );
3399 }
3400
3401 LightApp_Displayer* SMESHGUI::displayer()
3402 {
3403   if( !myDisplayer )
3404     myDisplayer = new SMESHGUI_Displayer( getApp() );
3405   return myDisplayer;
3406 }