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