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