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