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