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