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