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