Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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 #include "SMESHGUI_InitMeshDlg.h"
29 #include "SMESHGUI_AddSubMeshDlg.h"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_Preferences_ColorDlg.h"
38 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
39 #include "SMESHGUI_Preferences_SelectionDlg.h"
40 #include "SMESHGUI_Hypotheses.h"
41 #include "SMESHGUI_HypothesesUtils.h"
42 #include "SMESHGUI_MoveNodesDlg.h"
43 #include "SMESHGUI_AddMeshElementDlg.h"
44 #include "SMESHGUI_EditHypothesesDlg.h"
45 #include "SMESHGUI_CreateHypothesesDlg.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_SingleEditDlg.h"
49 #include "SMESHGUI_MultiEditDlg.h"
50 #include "SMESHGUI_GroupOpDlg.h"
51 #include "SMESHGUI_DeleteGroupDlg.h"
52 #include "SMESHGUI_SmoothingDlg.h"
53 #include "SMESHGUI_RenumberingDlg.h"
54 #include "SMESHGUI_ExtrusionDlg.h"
55 #include "SMESHGUI_RevolutionDlg.h"
56 #include "SMESHGUI_TranslationDlg.h"
57 #include "SMESHGUI_RotationDlg.h"
58 #include "SMESHGUI_SymmetryDlg.h"
59 #include "SMESHGUI_SewingDlg.h"
60 #include "SMESHGUI_MergeNodesDlg.h"
61 #include "SMESHGUI_MeshPatternDlg.h"
62 #include "SMESHGUI_PrecisionDlg.h"
63
64 #include "VTKViewer_ViewFrame.h"
65 #include "VTKViewer_InteractorStyleSALOME.h"
66 #include "VTKViewer_RenderWindowInteractor.h"
67
68 #include "SMESH_Actor.h"
69 #include "SMESH_Object.h"
70
71 #include "QAD.h"
72 #include "QAD_Tools.h"
73 #include "QAD_Config.h"
74 #include "QAD_Settings.h"
75 #include "QAD_RightFrame.h"
76 #include "QAD_MessageBox.h"
77 #include "QAD_Resource.h"
78 #include "QAD_FileDlg.h"
79 #include "QAD_Desktop.h"
80 #include "QAD_ResourceMgr.h"
81 #include "QAD_WaitCursor.h"
82
83 #include "SALOME_NamingService.hxx"
84 #include "SALOME_ListIteratorOfListIO.hxx"
85 #include "SALOME_InteractiveObject.hxx"
86
87 #include "SALOMEGUI_Desktop.h"
88 #include "SALOMEGUI_NameDlg.h"
89 #include "SALOMEGUI_ImportOperation.h"
90 #include "SALOMEGUI_QtCatchCorbaException.hxx"
91
92 #include "SMESHGUI_Utils.h"
93 #include "SMESHGUI_SMESHGenUtils.h"
94 #include "SMESHGUI_GEOMGenUtils.h"
95 #include "SMESHGUI_MeshUtils.h"
96 #include "SMESHGUI_GroupUtils.h"
97 #include "SMESHGUI_FilterUtils.h"
98 #include "SMESHGUI_PatternUtils.h"
99 #include "SMESHGUI_VTKUtils.h"
100
101 #include "SALOMEconfig.h"
102 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
103
104 // QT Includes
105 #define  INCLUDE_MENUITEM_DEF
106 #include <qapplication.h>
107 #include <qlineedit.h>
108 #include <qmenudata.h>
109 #include <qmenubar.h>
110 #include <qpopupmenu.h>
111 #include <qfont.h>
112 #include <qstring.h>
113 #include <qpainter.h>
114 #include <qcheckbox.h>
115 #include <qcolordialog.h>
116 #include <qspinbox.h>
117 #include <qlist.h>
118 #include <qwidget.h>
119 #include <qevent.h>
120 #include <qradiobutton.h>
121
122 #include <boost/shared_ptr.hpp>
123
124 #include <vtkRenderer.h>
125 #include <vtkRenderWindow.h>
126 #include <vtkActorCollection.h>
127 #include <vtkScalarBarActor.h>
128
129 #include "utilities.h"
130
131 using namespace std;
132
133 namespace{
134   // Decalarations
135   //=============================================================
136   void ImportMeshesFromFile(QAD_Desktop * parent, 
137                             SMESH::SMESH_Gen_ptr theComponentMesh,
138                             int theCommandID);
139
140   void ExportMeshToFile(QAD_Desktop * parent, int theCommandID);
141
142   void SetViewMode(int theCommandID);
143
144   void Control( int theCommandID );
145
146   void SetDisplaySettings();
147
148
149   // Definitions
150   //=============================================================
151   void ImportMeshesFromFile(QAD_Desktop * parent, 
152                             SMESH::SMESH_Gen_ptr theComponentMesh,
153                             int theCommandID)
154   {
155     QString filter;
156     string myExtension;
157   
158     if(theCommandID == 113){
159       filter = QObject::tr("MED files (*.med)");
160     }else if (theCommandID == 112){
161       filter = QObject::tr("IDEAS files (*.unv)");
162     }else if (theCommandID == 111){
163       filter = QObject::tr("DAT files (*.dat)");
164     }
165     QString filename = QAD_FileDlg::getFileName(parent,
166                                                 "",
167                                                 filter,
168                                                 QObject::tr("Import mesh"),
169                                                 true);
170     if(!filename.isEmpty()) {
171       QAD_WaitCursor wc;
172       SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
173
174       try {
175         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
176         switch ( theCommandID ) {
177         case 112:
178           {
179             aMeshes->length( 1 );
180             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
181             break;
182           }
183         case 113:
184           {
185             SMESH::DriverMED_ReadStatus res;
186             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
187             if ( res != SMESH::DRS_OK ) {
188               wc.stop();
189               QAD_MessageBox::warn1(QAD_Application::getDesktop(),
190                                     QObject::tr("SMESH_WRN_WARNING"),
191                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
192                                     QObject::tr("SMESH_BUT_OK"));
193               aMeshes->length( 0 );
194               wc.start();
195             }
196             break;
197           }
198         }
199
200         bool isEmpty = false;
201         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
202           SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( aMeshes[i] );
203           if ( !aMeshSO->_is_nil() ) {
204             SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
205             SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow( aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ) );
206             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
207             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
208               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
209           } else
210             isEmpty = true;
211         }
212
213         if ( isEmpty ) {
214           wc.stop();
215           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
216                                 QObject::tr("SMESH_WRN_WARNING"),
217                                 QObject::tr("SMESH_DRS_EMPTY"),
218                                 QObject::tr("SMESH_BUT_OK"));
219           wc.start();
220         }
221       }
222       catch (const SALOME::SALOME_Exception& S_ex){
223         wc.stop();
224         QtCatchCorbaException(S_ex);
225         wc.start();
226       }
227     }
228   }
229
230
231   void ExportMeshToFile(QAD_Desktop * parent, int theCommandID)
232   {
233     SALOME_Selection *aSel = SALOME_Selection::Selection(SMESH::GetActiveStudy()->getSelection());
234     if(aSel->IObjectCount()){
235       Handle(SALOME_InteractiveObject) anIObject = aSel->firstIObject();
236       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
237       if ( !aMesh->_is_nil() ) {
238         QString aFilter, aTitle = QObject::tr("Export mesh");
239         switch ( theCommandID ) {
240         case 122:
241           aFilter = QObject::tr("MED files (*.med)");
242           break;
243         case 121:
244           aFilter = QObject::tr("DAT files (*.dat)");
245           break;
246         case 123: {
247           if(aMesh->NbPyramids()){
248             int aRet = QAD_MessageBox::warn2(QAD_Application::getDesktop(),
249                                              QObject::tr("SMESH_WRN_WARNING"),
250                                              QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
251                                              QObject::tr("SMESH_BUT_YES"),
252                                              QObject::tr("SMESH_BUT_NO"),
253                                              0,1,0);
254             if(aRet)
255               return;
256           }
257           aFilter = QObject::tr("IDEAS files (*.unv)");
258           break;
259         default:
260           return;
261         }}
262         
263         QString aFilename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false);
264         if ( !aFilename.isEmpty() ) {
265           // Check whether the file already exists and delete it if yes
266           QFile aFile( aFilename );
267           if ( aFile.exists() )
268             aFile.remove();
269           QAD_WaitCursor wc;
270           switch ( theCommandID ) {
271           case 122:
272             aMesh->ExportMED( aFilename.latin1(), true ); // currently, automatic groups are always created
273             break;
274           case 121:
275             aMesh->ExportDAT( aFilename.latin1() );
276             break;
277           case 123:
278             aMesh->ExportUNV( aFilename.latin1() );
279             break;
280           default:
281             break;
282           }
283         }
284       }
285     }
286   }  
287   
288   void SetViewMode(int theCommandID){
289     SALOME_Selection *Sel = SALOME_Selection::Selection(SMESH::GetActiveStudy()->getSelection());
290     if(Sel->IObjectCount() >= 1){
291       switch(theCommandID){
292       case 1134:{
293         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
294         SMESHGUI_ClippingDlg *aDlg = 
295           new SMESHGUI_ClippingDlg(QAD_Application::getDesktop(),"",false);
296         return;
297       }
298       case 1133:{
299         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
300         SMESHGUI_TransparencyDlg *aDlg = 
301           new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false);
302         return;
303       }}
304       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
305       for(; It.More(); It.Next()){
306         Handle(SALOME_InteractiveObject) IObject = It.Value();
307         if(IObject->hasEntry()){
308           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
309             switch(theCommandID){
310             case 211:
311               anActor->SetRepresentation(SMESH_Actor::eEdge);
312               break;
313             case 212:
314               anActor->SetRepresentation(SMESH_Actor::eSurface);
315               break;
316             case 213:
317               if(anActor->IsShrunk()) 
318                 anActor->UnShrink();
319               else
320                 anActor->SetShrink();
321               break;
322             case 215:
323               anActor->SetRepresentation(SMESH_Actor::ePoint);
324               break;
325             case 1132:{
326               float color[3];
327               anActor->GetSufaceColor(color[0], color[1], color[2]);
328               int c0 = int (color[0] * 255);
329               int c1 = int (color[1] * 255);
330               int c2 = int (color[2] * 255);
331               QColor c(c0, c1, c2);
332               
333               float edgecolor[3];
334               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
335               c0 = int (edgecolor[0] * 255);
336               c1 = int (edgecolor[1] * 255);
337               c2 = int (edgecolor[2] * 255);
338               QColor e(c0, c1, c2);
339               
340               float backfacecolor[3];
341               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
342               c0 = int (backfacecolor[0] * 255);
343               c1 = int (backfacecolor[1] * 255);
344               c2 = int (backfacecolor[2] * 255);
345               QColor b(c0, c1, c2);
346               
347               float nodecolor[3];
348               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
349               c0 = int (nodecolor[0] * 255);
350               c1 = int (nodecolor[1] * 255);
351               c2 = int (nodecolor[2] * 255);
352               QColor n(c0, c1, c2);
353               
354               int Edgewidth = (int)anActor->GetLineWidth();
355               if(Edgewidth == 0)
356                 Edgewidth = 1;
357               int intValue = int(anActor->GetNodeSize());
358               float Shrink = anActor->GetShrinkFactor();
359               
360               SMESHGUI_Preferences_ColorDlg *aDlg = 
361                 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),"");
362               aDlg->SetColor(1, c);
363               aDlg->SetColor(2, e);
364               aDlg->SetColor(3, n);
365               aDlg->SetColor(4, b);
366               aDlg->SetIntValue(1, Edgewidth);
367               aDlg->SetIntValue(2, intValue);
368               aDlg->SetIntValue(3, int(Shrink*100.));
369               if(aDlg->exec()){
370                 QColor color = aDlg->GetColor(1);
371                 QColor edgecolor = aDlg->GetColor(2);
372                 QColor nodecolor = aDlg->GetColor(3);
373                 QColor backfacecolor = aDlg->GetColor(4);
374                 /* actor color and backface color */
375                 anActor->SetSufaceColor(float (color.red()) / 255.,
376                                          float (color.green()) / 255., 
377                                          float (color.blue()) / 255.);
378                 anActor->SetBackSufaceColor(float (backfacecolor.red()) / 255., 
379                                              float (backfacecolor.green()) / 255.,
380                                              float (backfacecolor.blue()) / 255.);
381                 
382                 /* edge color */
383                 anActor->SetEdgeColor(float (edgecolor.red()) / 255.,
384                                        float (edgecolor.green()) / 255.,
385                                        float (edgecolor.blue()) / 255.);
386                 
387                 /* Shrink factor and size edges */
388                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
389                 anActor->SetLineWidth(aDlg->GetIntValue(1));
390                 
391                 /* Nodes color and size */
392                 anActor->SetNodeColor(float (nodecolor.red()) / 255.,
393                                float (nodecolor.green()) / 255.,
394                                        float (nodecolor.blue()) / 255.);
395                 anActor->SetNodeSize(aDlg->GetIntValue(2));
396                 
397                 delete aDlg;
398               }
399               break;
400             }}
401           }
402         }
403       }
404       SMESH::RepaintCurrentView();
405     }
406   }
407
408
409   void SetDisplaySettings()
410   {
411     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
412     SMESHGUI_Preferences_ColorDlg *aDlg =
413       new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
414
415     QColor color;
416     QString SCr, SCg, SCb;
417     SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
418     SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
419     SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
420     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
421       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
422     else color = QColor(0, 170, 255);
423     aDlg->SetColor(1, color);
424     
425     SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
426     SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
427     SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
428     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
429       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
430     else color = QColor(0, 170, 255);
431     aDlg->SetColor(2, color);
432     
433     SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
434     SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
435     SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
436     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
437       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
438     else color = Qt::red;
439     aDlg->SetColor(3, color);
440     
441     QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
442     QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
443     QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
444     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
445       color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
446     else color = Qt::blue;
447     aDlg->SetColor(4, color);
448     
449     QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
450     if (intValue.isEmpty()) intValue = "1";
451     aDlg->SetIntValue(1, intValue.toInt());
452     intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
453     if (intValue.isEmpty()) intValue = "3";
454     aDlg->SetIntValue(2, intValue.toInt());
455     intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
456     if (intValue.isEmpty()) intValue = "75";
457     aDlg->SetIntValue(3, intValue.toInt());
458     
459     if (aDlg->exec()) {
460       QColor colorFill = aDlg->GetColor(1);
461       QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
462       QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
463       QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
464       
465       QColor colorOutline = aDlg->GetColor(2);
466       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
467       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
468       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
469       
470       QColor colorNode = aDlg->GetColor(3);
471       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
472       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
473       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
474       
475       QColor colorBackFace = aDlg->GetColor(4);
476       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
477       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
478       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
479       
480       int width = aDlg->GetIntValue(1);
481       QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
482       
483       int nodes_size = aDlg->GetIntValue(2);
484       QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
485       
486       int shrink_coeff = aDlg->GetIntValue(3);
487       QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
488     }
489     
490     delete aDlg;
491   }
492   
493   
494   void Control( int theCommandID )
495   {
496     SALOME_Selection *Sel = SALOME_Selection::Selection( SMESH::GetActiveStudy()->getSelection() );
497     if(Sel){
498       Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
499       if(!anIO.IsNull()){
500         QString aTitle;
501         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
502         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
503           switch ( theCommandID ){
504           case 6001:
505             aTitle = QObject::tr( "LENGTH_EDGES" );
506             aControl = SMESH_Actor::eLengthEdges;
507             break;
508           case 6002:
509             aTitle = QObject::tr( "FREE_EDGES" );
510             aControl = SMESH_Actor::eFreeEdges;
511             break;
512           case 6003:
513             aTitle = QObject::tr( "FREE_BORDERS" );
514             aControl = SMESH_Actor::eFreeBorders;
515             break;
516           case 6004:
517             aTitle = QObject::tr( "MULTI_BORDERS" );
518             aControl = SMESH_Actor::eMultiConnection;
519             break;
520           case 6011:
521             aTitle = QObject::tr( "AREA_ELEMENTS" );
522             aControl = SMESH_Actor::eArea;
523             break;
524           case 6012:
525             aTitle = QObject::tr( "TAPER_ELEMENTS" );
526             aControl = SMESH_Actor::eTaper;
527             break;
528           case 6013:
529             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
530             aControl = SMESH_Actor::eAspectRatio;
531             break;
532           case 6014:
533             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
534             aControl = SMESH_Actor::eMinimumAngle;
535             break;
536           case 6015:
537             aTitle = QObject::tr( "WARP_ELEMENTS" );
538             aControl = SMESH_Actor::eWarping;
539             break;
540           case 6016:
541             aTitle = QObject::tr( "SKEW_ELEMENTS" );
542             aControl = SMESH_Actor::eSkew;
543             break;
544           }
545           anActor->SetControlMode(aControl);
546           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
547         }
548       }
549     }
550   }
551   
552
553   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
554                    MeshObjectType                           theType,
555                    const QString                            theInTypeName,
556                    QString &                                theOutTypeName)
557   {
558     SMESH_TypeFilter aTypeFilter( theType );
559     if ( aTypeFilter.IsOk( theIO )) {
560       theOutTypeName = theInTypeName;
561       return true;
562     }
563     return false;
564   }
565     
566
567   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
568   {
569     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
570     SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theIO->getEntry());
571     if (!aSObj->_is_nil()) {
572       SALOMEDS::SComponent_var aSComp = aSObj->GetFatherComponent();
573       CORBA::String_var anID = aSComp->GetID();
574       if (!strcmp(anID.in(),theIO->getEntry()))
575         return "Component";
576     }
577     
578     QString aTypeName;
579     if (
580         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
581         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
582         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
583         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
584         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
585         )
586       return aTypeName;
587     
588     return "NoType";
589   }
590
591
592   QString CheckHomogeneousSelection()
593   {
594     QAD_Study* aStudy = SMESH::GetActiveStudy();
595     SALOME_Selection *aSel = SALOME_Selection::Selection(aStudy->getSelection());
596     /* copy the list */
597     SALOME_ListIO List;
598     SALOME_ListIteratorOfListIO Itinit(aSel->StoredIObjects());
599     for (; Itinit.More(); Itinit.Next())
600       {
601         List.Append(Itinit.Value());
602       }
603
604     QString RefType = CheckTypeObject(aSel->firstIObject());
605     SALOME_ListIteratorOfListIO It(List);
606     for (; It.More(); It.Next())
607       {
608         Handle(SALOME_InteractiveObject) IObject = It.Value();
609         QString Type = CheckTypeObject(IObject);
610         if (Type.compare(RefType) != 0)
611           return "Heterogeneous Selection";
612       }
613     
614     aSel->ClearIObjects();
615     SALOME_ListIteratorOfListIO It1(List);
616     for (; It1.More(); It1.Next())
617       {
618         int res = aSel->AddIObject(It1.Value());
619         if (res == -1)
620           aStudy->highlight(It1.Value(), false);
621         if (res == 0)
622           aStudy->highlight(It1.Value(), true);
623       }
624     return RefType;
625   }
626
627   void OnEditDelete()
628   {
629     if (QAD_MessageBox::warn2
630         (QAD_Application::getDesktop(),
631          QObject::tr("SMESH_WRN_WARNING"),
632          QObject::tr("SMESH_REALLY_DELETE"),
633          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
634       return;
635
636     QAD_Study* anActiveStudy = SMESH::GetActiveStudy();
637     int nbSf = anActiveStudy->getStudyFramesCount();
638     
639     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
640     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
641     SALOMEDS::GenericAttribute_var anAttr;
642     SALOMEDS::AttributeIOR_var anIOR;
643     
644     SALOME_Selection *Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
645     SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
646     for(; It.More(); It.Next()){
647       Handle(SALOME_InteractiveObject) IObject = It.Value();
648       if(IObject->hasEntry()){
649         SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
650         
651         /* Erase child graphical objects */
652         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
653         for(; it->More(); it->Next()){
654           SALOMEDS::SObject_var CSO = it->Value();
655           if(CSO->FindAttribute(anAttr, "AttributeIOR")){
656             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
657             
658             for(int i = 0; i < nbSf; i++){
659               QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
660               CORBA::String_var anEntry = CSO->GetID();
661               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
662                 SMESH::RemoveActor(sf,anActor);
663               }
664             }
665           }
666         }
667         
668         /* Erase main graphical object */
669         for(int i = 0; i < nbSf; i++){
670           QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
671           if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
672             SMESH::RemoveActor(sf,anActor);
673           }
674         }
675         
676         // Remove object(s) from data structures
677         SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
678         if(!obj->_is_nil()){
679           SMESH::SMESH_Group_var     aGroup = SMESH::SMESH_Group  ::_narrow(obj->GetObject());
680           SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
681           
682           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
683             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
684             aMesh->RemoveGroup( aGroup );
685           }
686           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
687             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
688             aMesh->RemoveSubMesh( aSubMesh );
689           }
690           else {// default action: remove SObject from the study
691             // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
692             //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
693             //op->start();
694             aStudyBuilder->RemoveObjectWithChildren( obj );
695             //op->finish();
696           }
697         }
698         
699       } /* IObject->hasEntry() */
700     } /* more/next */
701     
702     /* Clear any previous selection */
703     Sel->ClearIObjects();
704     anActiveStudy->updateObjBrowser();
705   }
706
707
708 }
709
710 //=============================================================================
711 /*!
712  *
713  */
714 //=============================================================================
715 class CustomItem:public QCustomMenuItem
716 {
717  public:
718   CustomItem(const QString & s, const QFont & f):string(s), font(f)
719   {
720   };
721   ~CustomItem()
722   {
723   }
724
725   void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
726              bool /*enabled */ , int x, int y, int w, int h)
727   {
728     p->setFont(font);
729     p->drawText(x, y, w, h,
730                 AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
731   }
732
733   QSize sizeHint()
734   {
735     return QFontMetrics(font).
736       size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
737   }
738  private:
739   QString string;
740   QFont font;
741 };
742
743 //=============================================================================
744 /*!
745  *
746  */
747 //=============================================================================
748 SMESHGUI::SMESHGUI( const QString& theName, QObject* theParent ) :
749   SALOMEGUI( theName, theParent )
750 {
751   myActiveDialogBox = 0 ;
752   myState = -1 ;
753
754   SMESH::GetSMESHGen();
755   SMESH::GetFilterManager();
756   SMESH::GetPattern();
757
758   /* load resources for all available meshers */
759   SMESH::InitAvailableHypotheses();
760 }
761
762 //=============================================================================
763 /*!
764  *
765  */
766 //=============================================================================
767 SMESHGUI::~SMESHGUI()
768 {
769   SMESH::GetFilterManager()->Destroy();
770 }
771
772 //=============================================================================
773 /*!
774  *
775  */
776 //=============================================================================
777 SMESHGUI* SMESHGUI::GetSMESHGUI()
778 {
779   static SMESHGUI aSMESHGUI;
780   aSMESHGUI.myActiveStudy = SMESH::GetActiveStudy();
781   SMESH::GetSMESHGen()->SetCurrentStudy( SMESH::GetActiveStudyDocument() );
782
783   /* Automatic Update flag */
784   aSMESHGUI.myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
785
786   return &aSMESHGUI;
787 }
788
789 extern "C"
790 {
791   Standard_EXPORT SALOMEGUI* GetComponentGUI() {
792     return SMESHGUI::GetSMESHGUI();
793   }
794 }
795
796 //=============================================================================
797 /*!
798  *
799  */
800 //=============================================================================
801 void SMESHGUI::SetState(int aState)
802 {
803   this->myState = aState;
804   return;
805 }
806
807 //=============================================================================
808 /*!
809  *
810  */
811 //=============================================================================
812 void SMESHGUI::ResetState()
813 {
814   this->myState = -1;
815   return;
816 }
817
818 //=============================================================================
819 /*!
820  *
821  */
822 //=============================================================================
823 void SMESHGUI::EmitSignalDeactivateDialog()
824 {
825   emit this->SignalDeactivateActiveDialog();
826   return;
827 }
828
829 //=============================================================================
830 /*!
831  *
832  */
833 //=============================================================================
834 void SMESHGUI::EmitSignalStudyFrameChanged()
835 {
836   emit this->SignalStudyFrameChanged();
837   return;
838 }
839
840 //=============================================================================
841 /*!
842  *
843  */
844 //=============================================================================
845 void SMESHGUI::EmitSignalCloseAllDialogs()
846 {
847   emit SignalCloseAllDialogs();
848   return;
849 }
850
851 //=============================================================================
852 /*!
853  *
854  */
855 //=============================================================================
856 QDialog *SMESHGUI::GetActiveDialogBox()
857 {
858   return this->myActiveDialogBox;
859 }
860
861 //=============================================================================
862 /*!
863  *
864  */
865 //=============================================================================
866 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
867 {
868   this->myActiveDialogBox = (QDialog *) aDlg;
869   return;
870 }
871
872 //=============================================================================
873 /*!
874  *
875  */
876 //=============================================================================
877 QAD_Study *SMESHGUI::GetActiveStudy()
878 {
879   return this->myActiveStudy;
880 }
881
882 //=============================================================================
883 /*!
884  *
885  */
886 //=============================================================================
887 QAD_Desktop *SMESHGUI::GetDesktop()
888 {
889   return QAD_Application::getDesktop();
890 }
891
892 //=============================================================================
893 /*!
894  *
895  */
896 //=============================================================================
897 bool SMESHGUI::ActiveStudyChanged(QAD_Desktop* parent)
898 {
899   MESSAGE("SMESHGUI::activeStudyChanged init.");
900   QAD_Study* prevStudy = myActiveStudy;
901   /* Create or retrieve an object SMESHGUI */
902   MESSAGE("Active study changed : prev study =" << prevStudy);
903   SMESHGUI::GetSMESHGUI();
904   EmitSignalStudyFrameChanged();
905   MESSAGE("Active study changed : active study =" << myActiveStudy);
906   if ( prevStudy != myActiveStudy ) {
907     EmitSignalCloseAllDialogs();
908     MESSAGE("Active study changed : SMESHGUI nullified" << endl);
909     //smeshGUI = 0;
910     SMESH::UpdateSelectionProp();
911   }
912   MESSAGE("SMESHGUI::activeStudyChanged done.");
913   return true;
914 }
915
916 //=============================================================================
917 /*!
918  *
919  */
920 //=============================================================================
921 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
922 {
923   /* Here the position is on the bottom right corner - 10 */
924   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
925   aDlg->adjustSize();
926   QAD_Desktop *PP = QAD_Application::getDesktop();
927   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
928   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
929   return true;
930 }
931
932 //=============================================================================
933 /*!
934  *
935  */
936 //=============================================================================
937 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
938   return theStudy->GetProperties()->IsLocked();
939 }
940
941 static bool checkLock(const SALOMEDS::Study_var& theStudy) {
942   if (isStudyLocked(theStudy)) {
943     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
944                            QObject::tr("WRN_WARNING"), 
945                            QObject::tr("WRN_STUDY_LOCKED"),
946                            QObject::tr("BUT_OK") );
947     return true;
948   }
949   return false;
950 }
951
952 //=======================================================================
953 //function : CheckActiveStudyLocked
954 //purpose  : 
955 //=======================================================================
956
957 bool SMESHGUI::ActiveStudyLocked()
958 {
959   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
960   return checkLock( aStudy );
961 }
962
963 //=============================================================================
964 /*!
965  *
966  */
967 //=============================================================================
968 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
969 {
970   SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
971
972   switch (theCommandID) {
973   case 33:                                      // DELETE
974     if(checkLock(aStudy)) break;
975     ::OnEditDelete();
976     break;
977     
978   case 113:                                     // IMPORT
979   case 112:
980   case 111:
981     {
982       if(checkLock(aStudy)) break;
983       ::ImportMeshesFromFile(parent,SMESH::GetSMESHGen(),theCommandID);
984       break;
985     }
986
987   case 122:                                     // EXPORT MED
988   case 121:
989   case 123:
990     {
991       ::ExportMeshToFile(parent, theCommandID);
992       break;
993     }
994
995   case 200:                                     // SCALAR BAR
996     {
997       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
998       if( Sel && Sel->IObjectCount() ) {
999         Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
1000         if( anIO->hasEntry() ) {
1001           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1002             anActor->SetControlMode( SMESH_Actor::eNone );
1003           }
1004         }
1005       }
1006       break;
1007     }
1008   case 201:
1009     {
1010       SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1011       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
1012       break;
1013     }
1014
1015   case 1134: // Clipping
1016   case 1133: // Tranparency
1017   case 1132: // Colors / Size
1018   case 215:
1019   case 213:
1020   case 212:
1021   case 211:
1022     {
1023       ::SetViewMode(theCommandID);
1024       break;
1025     }
1026
1027   case 214:                                     // UPDATE
1028     {
1029       if(checkLock(aStudy)) break;
1030       SMESH::UpdateView();
1031       break;
1032     }
1033
1034   case 300:                                     // ERASE
1035   case 301:                                     // DISPLAY
1036   case 302:                                     // DISPLAY ONLY
1037     {
1038       SMESH::EDisplaing anAction;
1039       switch(theCommandID){
1040       case 300: anAction = SMESH::eErase; break;
1041       case 301: anAction = SMESH::eDisplay; break;
1042       case 302: anAction = SMESH::eDisplayOnly; break;
1043       }
1044       
1045       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1046       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1047         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1048         for (; It.More(); It.Next()) {
1049           Handle(SALOME_InteractiveObject) IOS = It.Value();
1050           if (IOS->hasEntry()) {
1051             SMESH::UpdateView(anAction,IOS->getEntry());
1052           }
1053         }
1054       }
1055       Sel->ClearIObjects();
1056       break;
1057     }
1058
1059   case 400:                                     // NODES
1060     {
1061       if(checkLock(aStudy)) break;
1062       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1063         EmitSignalDeactivateDialog();
1064         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1065         SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
1066       }
1067       else {
1068         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1069                               tr("SMESH_WRN_WARNING"), 
1070                               tr("SMESH_WRN_VIEWER_VTK"),
1071                               tr("SMESH_BUT_OK"));
1072       }
1073       break;
1074     }
1075
1076   case 2151:  // FILTER
1077   {
1078     if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1079     {
1080       EmitSignalDeactivateDialog();
1081       SMESHGUI_FilterDlg *aDlg = new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
1082     }
1083     break;
1084   }
1085     
1086   case 406:                                     // MOVE NODE
1087     {
1088       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1089       {
1090         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1091           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1092         break;
1093       }
1094       
1095       if(checkLock(aStudy)) break;
1096       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1097       SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, Sel );
1098       break;
1099     }
1100     
1101   case 701:                                     // COMPUTE MESH 
1102     {
1103       if(checkLock(aStudy)) break;
1104       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1105         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1106         int nbSel = Sel->IObjectCount();
1107         if (nbSel != 1){
1108           break;
1109         }
1110
1111         SMESH::SMESH_Mesh_var aMesh;
1112         SMESH::SMESH_subMesh_var aSubMesh;
1113         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1114         if (IObject->hasEntry()){
1115           SALOMEDS::SObject_var aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
1116           GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
1117           if ( aShapeObject->_is_nil() ) {
1118             // imported mesh
1119             break;
1120           }
1121           if(!aMeshSObj->_is_nil()) {
1122             SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
1123             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
1124             
1125             if (!aMesh->_is_nil()){
1126               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1127               if (!refShapeObject->_is_nil()) {
1128                 if(!SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject)){
1129                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1130                                         tr("SMESH_WRN_WARNING"),
1131                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1132                                         tr("SMESH_BUT_OK"));
1133                   break;
1134                 }
1135                 try{
1136                   if (SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject))
1137                     SMESH::ModifiedMesh(aMeshSObj,true);
1138                   // TO Do : change icon of all submeshes
1139                   else
1140                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1141                                           tr("SMESH_WRN_WARNING"),
1142                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1143                                           tr("SMESH_BUT_OK"));
1144                 }
1145                 catch(const SALOME::SALOME_Exception & S_ex){
1146                   QtCatchCorbaException(S_ex);
1147                 }
1148               }
1149             }else if(!aSubMesh->_is_nil()){
1150               aMesh = aSubMesh->GetFather();
1151               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1152               if(!refShapeObject->_is_nil()){
1153                 bool compute = SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject);
1154                 if(!compute){
1155                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1156                                         tr("SMESH_WRN_WARNING"),
1157                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1158                                         tr("SMESH_BUT_OK"));
1159                   break;
1160                 }
1161                 try{
1162                   if ( SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject) )
1163                     SMESH::ModifiedMesh(aMeshSObj,true);
1164                   // TO Do : change icon of all submeshes
1165                   else
1166                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1167                                           tr("SMESH_WRN_WARNING"),
1168                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1169                                           tr("SMESH_BUT_OK"));
1170                 }catch(const SALOME::SALOME_Exception & S_ex){
1171                   QtCatchCorbaException(S_ex);
1172                 }
1173               }
1174             }
1175           }
1176         }
1177         CORBA::Long anId = aStudy->StudyId();
1178         TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,IObject->getEntry());
1179         if(myAutomaticUpdate && aVisualObj){
1180           aVisualObj->Update();
1181           SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
1182           if(!anActor){
1183             anActor = SMESH::CreateActor(aStudy,IObject->getEntry());
1184             if(anActor){
1185               SMESH::DisplayActor(myActiveStudy->getActiveStudyFrame(),anActor); //apo
1186               SMESH::FitAll();
1187             }
1188           }
1189         }
1190       }else{
1191         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1192                               tr("SMESH_WRN_WARNING"), 
1193                               tr("SMESH_WRN_VIEWER_VTK"),
1194                               tr("SMESH_BUT_OK"));
1195       }
1196       break;
1197     }
1198
1199   case 702:                                     // ADD SUB MESH 
1200     {
1201       if(checkLock(aStudy)) break;
1202       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1203         EmitSignalDeactivateDialog();
1204         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1205         SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
1206       }
1207       else {
1208         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1209                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1210                               tr("SMESH_BUT_OK"));
1211       }
1212       break;
1213     }
1214     
1215   case 703:                                     // INIT MESH 
1216     {
1217       if(checkLock(aStudy)) break;
1218       EmitSignalDeactivateDialog();
1219       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1220       SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
1221       break;
1222     }
1223
1224   case 704:                                     // EDIT Hypothesis 
1225     {
1226       if(checkLock(aStudy)) break;
1227       EmitSignalDeactivateDialog();
1228       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1229       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1230       break;
1231     }
1232
1233   case 705:                                     //  EDIT Global Hypothesis
1234     {
1235       if(checkLock(aStudy)) break;
1236       EmitSignalDeactivateDialog();
1237       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1238       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1239       break;
1240     }
1241
1242   case 706:                                     //  EDIT Local Hypothesis
1243     {
1244       if(checkLock(aStudy)) break;
1245       EmitSignalDeactivateDialog();
1246       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1247       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1248       break;
1249     }
1250
1251   case 407: // DIAGONAL INVERSION
1252   case 408: // Delete diagonal
1253     {
1254       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1255       {
1256         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1257           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1258         break;
1259       }
1260
1261       if ( checkLock( aStudy ) )
1262         break;
1263         
1264       SALOME_Selection *aSel =
1265         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1266       /*Standard_Boolean aRes;
1267       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1268       if ( aMesh->_is_nil() )
1269       {
1270         QAD_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1271           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1272         break;
1273       }
1274       */
1275       EmitSignalDeactivateDialog();
1276       if ( theCommandID == 407 )
1277         new SMESHGUI_TrianglesInversionDlg( parent, aSel );
1278       else
1279         new SMESHGUI_UnionOfTwoTrianglesDlg( parent, aSel );
1280       break;
1281     }
1282     case 409: // Change orientation
1283     case 410: // Union of triangles
1284     case 411: // Cutting of quadrangles
1285     {
1286       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1287       {
1288         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1289           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1290         break;
1291       }
1292
1293       if ( checkLock( aStudy ) )
1294         break;
1295
1296       SALOME_Selection *aSel =
1297         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1298
1299       EmitSignalDeactivateDialog();
1300       SMESHGUI_MultiEditDlg* aDlg;
1301       if ( theCommandID == 409 )
1302         aDlg = new SMESHGUI_ChangeOrientationDlg( parent, aSel );
1303       else if ( theCommandID == 410 )
1304         aDlg = new SMESHGUI_UnionOfTrianglesDlg( parent, aSel );
1305       else
1306         aDlg = new SMESHGUI_CuttingOfQuadsDlg( parent, aSel );
1307
1308       int x, y ;
1309       DefineDlgPosition( aDlg, x, y );
1310       aDlg->move( x, y );
1311       aDlg->show();
1312       break;
1313     }
1314   case 412: // Smoothing
1315     {
1316       if(checkLock(aStudy)) break;
1317       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1318         EmitSignalDeactivateDialog();
1319         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1320         SMESHGUI_SmoothingDlg *aDlg = new SMESHGUI_SmoothingDlg(parent, "", Sel);
1321       }
1322       else {
1323         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1324                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1325                               tr("SMESH_BUT_OK"));
1326       }
1327       break;
1328     }
1329   case 413: // Extrusion
1330     {
1331       if(checkLock(aStudy)) break;
1332       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1333         EmitSignalDeactivateDialog();
1334         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1335         SMESHGUI_ExtrusionDlg *aDlg = new SMESHGUI_ExtrusionDlg(parent, "", Sel);
1336       }
1337       else {
1338         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1339                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1340                               tr("SMESH_BUT_OK"));
1341       }
1342       break;
1343     }
1344   case 414: // Revolution
1345     {
1346       if(checkLock(aStudy)) break;
1347       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1348         EmitSignalDeactivateDialog();
1349         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1350         SMESHGUI_RevolutionDlg *aDlg = new SMESHGUI_RevolutionDlg(parent, "", Sel);
1351       }
1352       else {
1353         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1354                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1355                               tr("SMESH_BUT_OK"));
1356       }
1357       break;
1358     }
1359   case 415: // Pattern mapping
1360     {
1361       if ( checkLock( aStudy ) )
1362         break;
1363       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1364       {
1365         EmitSignalDeactivateDialog();
1366         SALOME_Selection *Sel = SALOME_Selection::Selection(
1367           myActiveStudy->getSelection() );
1368         new SMESHGUI_MeshPatternDlg( parent, Sel );
1369       }
1370       else {
1371         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1372                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1373                               tr("SMESH_BUT_OK"));
1374       }
1375       break;
1376     }
1377   case 801:                                     // CREATE GROUP
1378     {
1379       if(checkLock(aStudy)) break;
1380       EmitSignalDeactivateDialog();
1381       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1382       int nbSel = Sel->IObjectCount();
1383       if (nbSel == 1) {
1384         // check if mesh is selected
1385         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(Sel->firstIObject());
1386         if (!aMesh->_is_nil()) {
1387           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
1388           aDlg->show();
1389         }
1390       }
1391       break;
1392     }
1393
1394   case 802:                                     // CONSTRUCT GROUP
1395     {
1396       if(checkLock(aStudy)) break;
1397       EmitSignalDeactivateDialog();
1398       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1399       int nbSel = Sel->IObjectCount();
1400       if (nbSel == 1) {
1401         // check if submesh is selected
1402         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1403         if (IObject->hasEntry()) {
1404           SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(IObject->getEntry());
1405           if(!aSObj->_is_nil()) {
1406             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
1407             if (!aSubMesh->_is_nil()) {
1408               try {
1409                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1410                 // get submesh elements list by types
1411                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1412                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1413                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1414                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1415                 // create group for each type o elements
1416                 QString aName = IObject->getName();
1417                 if (aNodes->length() > 0) {
1418                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName);
1419                   aGroup->Add(aNodes.inout());
1420                 }
1421                 if (aEdges->length() > 0) {
1422                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName);
1423                   aGroup->Add(aEdges.inout());
1424                 }
1425                 if (aFaces->length() > 0) {
1426                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName);
1427                   aGroup->Add(aFaces.inout());
1428                 }
1429                 if (aVolumes->length() > 0) {
1430                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName);
1431                   aGroup->Add(aVolumes.inout());
1432                 }
1433                 myActiveStudy->updateObjBrowser(true);
1434               }catch(const SALOME::SALOME_Exception & S_ex){
1435                 QtCatchCorbaException(S_ex);
1436               }
1437             }
1438           }
1439         }
1440       }
1441       break;
1442     }
1443
1444   case 803:                                     // EDIT GROUP
1445     {
1446       if(checkLock(aStudy)) break;
1447       EmitSignalDeactivateDialog();
1448       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1449       SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1450       SALOME_ListIteratorOfListIO It (IOs);
1451       for ( ; It.More(); It.Next() )
1452       {
1453         SMESH::SMESH_Group_var aGroup =
1454           SMESH::IObjectToInterface<SMESH::SMESH_Group>(It.Value());
1455         if (!aGroup->_is_nil()) {
1456           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
1457           aDlg->show();
1458         }
1459       }
1460       break;
1461     }
1462
1463   case 804:                                     // Add elements to group
1464     {
1465       if(checkLock(aStudy)) break;
1466       if (myState == 800) {
1467         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1468         if (aDlg) aDlg->onAdd();
1469       }
1470       break;
1471     }
1472
1473   case 805:                                     // Remove elements from group
1474     {
1475       if(checkLock(aStudy)) break;
1476       if (myState == 800) {
1477         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1478         if (aDlg) aDlg->onRemove();
1479       }
1480       break;
1481     }
1482
1483     case 810: // Union Groups
1484     case 811: // Intersect groups
1485     case 812: // Cut groups
1486     {
1487       if ( checkLock( aStudy ) )
1488         break;
1489
1490       EmitSignalDeactivateDialog();
1491       SALOME_Selection *Sel = SALOME_Selection::Selection(
1492         myActiveStudy->getSelection() );
1493
1494       int aMode;
1495       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1496       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1497       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1498
1499       ( new SMESHGUI_GroupOpDlg( parent, Sel, aMode ) )->show();
1500       break;
1501     }
1502
1503     case 813: // Delete groups with their contents
1504     {
1505       if ( checkLock( aStudy ) )
1506         break;
1507
1508       EmitSignalDeactivateDialog();
1509       SALOME_Selection *Sel = SALOME_Selection::Selection(
1510         myActiveStudy->getSelection() );
1511
1512       ( new SMESHGUI_DeleteGroupDlg( parent, Sel ) )->show();
1513       break;
1514     }
1515
1516   case 900:                                     // MESH INFOS
1517     {
1518       EmitSignalDeactivateDialog();
1519       SALOME_Selection *Sel =
1520         SALOME_Selection::Selection(myActiveStudy->getSelection());
1521       if ( Sel->IObjectCount() > 1 ) { // a dlg for each IO
1522         SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1523         SALOME_ListIteratorOfListIO It (IOs);
1524         for ( ; It.More(); It.Next() ) {
1525           Sel->ClearIObjects();
1526           Sel->AddIObject( It.Value() );
1527           SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false);
1528         }
1529         // restore selection
1530         Sel->ClearIObjects();
1531         for (It.Initialize( IOs ) ; It.More(); It.Next() )
1532           Sel->AddIObject( It.Value() );
1533       }
1534       else
1535         SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false);
1536       break;
1537     }
1538
1539   case 1001:                                    // AUTOMATIC UPDATE PREFERENCES
1540     {
1541       parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
1542       if (parent->menuBar()->isItemChecked(1001)) {
1543         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
1544         myAutomaticUpdate = true;
1545       }
1546       else {
1547         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
1548         myAutomaticUpdate = false;
1549       }
1550       break;
1551     }
1552
1553   case 1003:                                    // MESH PREFERENCES
1554     {
1555       ::SetDisplaySettings();
1556       break;
1557     }
1558
1559   case 1005:
1560     {
1561       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
1562       break;
1563     }
1564
1565   case 1007:
1566     {
1567       ( new SMESHGUI_PrecisionDlg( parent ) )->exec();
1568       break;
1569     }
1570
1571   case 1006: 
1572     {
1573       SMESHGUI_Preferences_SelectionDlg* aDlg = 
1574         new SMESHGUI_Preferences_SelectionDlg(parent);
1575
1576       QColor aColor;
1577       QString SCr, SCg, SCb;
1578       SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
1579       SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
1580       SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
1581       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1582         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1583       else aColor = Qt::cyan;
1584       aDlg->SetColor(1, aColor);
1585
1586       SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
1587       SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
1588       SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
1589       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1590         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1591       else aColor = Qt::yellow;
1592       aDlg->SetColor(2, aColor);
1593
1594       SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
1595       SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
1596       SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
1597       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1598         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1599       else aColor = Qt::white;
1600       aDlg->SetColor(3, aColor);
1601
1602       QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
1603       if (SW1.isEmpty()) SW1 = "5";
1604       aDlg->SetWidth(1, SW1.toInt());
1605
1606       QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
1607       if (SW2.isEmpty()) SW2 = "5";
1608       aDlg->SetWidth(2, SW2.toInt());
1609
1610       QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
1611       if (SP1.isEmpty()) SP1 = "0.025";
1612       aDlg->SetPrecision(1, SP1.toDouble());
1613
1614       QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
1615       if (SP2.isEmpty()) SP2 = "0.001";
1616       aDlg->SetPrecision(2, SP2.toDouble());
1617
1618       if (aDlg->exec()) {
1619         QColor aPreColor = aDlg->GetColor(1);
1620         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
1621         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
1622         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
1623
1624         QColor aSelColor = aDlg->GetColor(2);
1625         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
1626         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
1627         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
1628
1629         QColor aHiColor = aDlg->GetColor(3);
1630         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
1631         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
1632         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
1633
1634         int aPreWidth = aDlg->GetWidth(1);
1635         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
1636         int aSelWidth = aDlg->GetWidth(2);
1637         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
1638
1639         double aTolNodes = aDlg->GetPrecision(1);
1640         QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
1641         double aTolItems = aDlg->GetPrecision(2);
1642         QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
1643
1644         // update current study settings
1645         SMESH::UpdateSelectionProp();
1646
1647         QAD_StudyFrame* studyFrame = myActiveStudy->getActiveStudyFrame();
1648         if (studyFrame->getTypeView() == VIEW_VTK) {
1649           VTKViewer_ViewFrame* aViewFrame = SMESH::GetVtkViewFrame(studyFrame);
1650           // update VTK viewer properties
1651           VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
1652           if (anInteractor) {
1653             anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
1654                                            aSelColor.blue()/255., aSelWidth);
1655             anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
1656             VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
1657             if (aStyle)
1658               aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
1659                                           aPreColor.blue()/255., aPreWidth);
1660           }
1661           // update actors
1662           vtkRenderer* aRenderer = aViewFrame->getRenderer();
1663           vtkActorCollection *aCollection = aRenderer->GetActors();
1664           aCollection->InitTraversal();
1665           while(vtkActor *anAct = aCollection->GetNextActor()){
1666             if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1667               anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
1668                                          aHiColor.blue()/255.);
1669               anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
1670                                             aPreColor.blue()/255.);
1671             }
1672           }
1673         }
1674       }
1675
1676       break;
1677     }
1678
1679   case 1100:                                    // EDIT HYPOTHESIS
1680     {
1681       if(checkLock(aStudy)) break;
1682       SALOME_Selection *Sel =
1683         SALOME_Selection::Selection(myActiveStudy->getSelection());
1684       int nbSel = Sel->IObjectCount();
1685
1686       if (nbSel == 1) {
1687         SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(Sel->firstIObject());
1688
1689         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1690         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1691         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1692         if ( !Hyp->_is_nil() )
1693         {
1694           char* sName = Hyp->GetName();
1695           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
1696           if (aCreator)
1697           {
1698             aCreator->EditHypothesis(Hyp);
1699           }
1700           else
1701           {
1702             // report error
1703           }
1704         }
1705       }
1706       break;
1707     }
1708
1709   case 1101:                                    // RENAME
1710     {
1711       if ( checkLock( aStudy ) )
1712         break;
1713         
1714       SALOME_Selection *Sel =
1715         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1716         
1717       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1718       for ( ; It.More(); It.Next() )
1719       {
1720         Handle(SALOME_InteractiveObject) IObject = It.Value();
1721         SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
1722         SALOMEDS::GenericAttribute_var anAttr;
1723         SALOMEDS::AttributeName_var aName;
1724         if ( !obj->_is_nil() )
1725         {
1726           if ( obj->FindAttribute(anAttr, "AttributeName") )
1727           {
1728             aName = SALOMEDS::AttributeName::_narrow( anAttr );
1729             QString newName = QString(aName->Value());
1730             newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName );
1731             if ( !newName.isEmpty() )
1732             {
1733               myActiveStudy->renameIObject( IObject, newName );
1734
1735               // if current object is group update group's name
1736               SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IObject);
1737               if (!aGroup->_is_nil() )
1738                 aGroup->SetName( newName.latin1() );
1739             }
1740           }
1741         }
1742       }
1743       break;
1744     }
1745     
1746   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1747     {
1748       if(checkLock(aStudy)) break;
1749       QAD_WaitCursor wc;
1750       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1751       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1752       for (int i = 0; It.More(); It.Next(), i++) {
1753         Handle(SALOME_InteractiveObject) IObject = It.Value();
1754         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1755       }
1756       Sel->ClearIObjects();
1757       myActiveStudy->updateObjBrowser(true);
1758       break;
1759     }
1760
1761   case 401:                                     // GEOM::EDGE
1762   case 4021:                                    // TRIANGLE
1763   case 4022:                                    // QUAD
1764   case 4031:                                    // TETRA
1765   case 4032:                                    // HEXA
1766     {
1767       if(checkLock(aStudy)) break;
1768       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1769         EmitSignalDeactivateDialog();
1770         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1771         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1772         int                 nbNodes = 2;
1773         switch (theCommandID) {
1774         case 4021:                                      // TRIANGLE
1775           type = SMDSAbs_Face; nbNodes = 3; break;
1776         case 4022:                                      // QUAD
1777           type = SMDSAbs_Face; nbNodes = 4; break;
1778         case 4031:                                      // TETRA
1779           type = SMDSAbs_Volume; nbNodes = 4; break;
1780         case 4032:                                      // HEXA
1781           type = SMDSAbs_Volume; nbNodes = 8; break;
1782         default:;
1783         }
1784         SMESHGUI_AddMeshElementDlg *aDlg =
1785           new SMESHGUI_AddMeshElementDlg(parent, "", Sel, type, nbNodes);
1786       }
1787       else {
1788         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1789                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1790                               tr("SMESH_BUT_OK"));
1791       }
1792       break;
1793     }
1794
1795   case 4041:                                    // REMOVES NODES
1796     {
1797       if(checkLock(aStudy)) break;
1798       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1799         EmitSignalDeactivateDialog();
1800         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1801         SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
1802       }
1803       else {
1804         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1805                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1806                               tr("SMESH_BUT_OK"));
1807       }
1808       break;
1809     }
1810   case 4042:                                    // REMOVES ELEMENTS
1811     {
1812       if(checkLock(aStudy)) break;
1813       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1814         EmitSignalDeactivateDialog();
1815         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1816         SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
1817       }
1818       else
1819         {
1820           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1821                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1822                                 tr("SMESH_BUT_OK"));
1823         }
1824       break;
1825     }
1826   case 4051:                                    // RENUMBERING NODES
1827     {
1828       if(checkLock(aStudy)) break;
1829       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1830         EmitSignalDeactivateDialog();
1831         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1832         SMESHGUI_RenumberingDlg *aDlg = new SMESHGUI_RenumberingDlg(parent, "", Sel, 0);
1833       }
1834       else
1835         {
1836           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1837                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1838                                 tr("SMESH_BUT_OK"));
1839         }
1840       break;
1841     }
1842   case 4052:                                    // RENUMBERING ELEMENTS
1843     {
1844       if(checkLock(aStudy)) break;
1845       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1846         EmitSignalDeactivateDialog();
1847         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1848         SMESHGUI_RenumberingDlg *aDlg = new SMESHGUI_RenumberingDlg(parent, "", Sel, 1);
1849       }
1850       else
1851         {
1852           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1853                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1854                                 tr("SMESH_BUT_OK"));
1855         }
1856       break;
1857     }
1858   case 4061:                                   // TRANSLATION
1859     {
1860       if(checkLock(aStudy)) break;
1861       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1862         EmitSignalDeactivateDialog();
1863         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1864         SMESHGUI_TranslationDlg *aDlg = new SMESHGUI_TranslationDlg(parent, "", Sel);
1865       }
1866       else {
1867         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1868                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1869                               tr("SMESH_BUT_OK"));
1870       }
1871       break;
1872     }
1873   case 4062:                                   // ROTATION
1874     {
1875       if(checkLock(aStudy)) break;
1876       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1877         EmitSignalDeactivateDialog();
1878         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1879         SMESHGUI_RotationDlg *aDlg = new SMESHGUI_RotationDlg(parent, "", Sel);
1880       }
1881       else {
1882         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1883                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1884                               tr("SMESH_BUT_OK"));
1885       }
1886       break;
1887     }
1888   case 4063:                                   // SYMMETRY 
1889     {
1890       if(checkLock(aStudy)) break;
1891       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1892         EmitSignalDeactivateDialog();
1893         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1894         SMESHGUI_SymmetryDlg *aDlg = new SMESHGUI_SymmetryDlg(parent, "", Sel);
1895       }
1896       else {
1897         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1898                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1899                               tr("SMESH_BUT_OK"));
1900       }
1901       break;
1902     }
1903   case 4064:                                   // SEWING
1904     {
1905       if(checkLock(aStudy)) break;
1906       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1907         EmitSignalDeactivateDialog();
1908         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1909         SMESHGUI_SewingDlg *aDlg = new SMESHGUI_SewingDlg(parent, "", Sel);
1910       }
1911       else {
1912         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1913                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1914                               tr("SMESH_BUT_OK"));
1915       }
1916       break;
1917     }
1918   case 4065:                                   // MERGE NODES
1919     {
1920       if(checkLock(aStudy)) break;
1921       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1922         EmitSignalDeactivateDialog();
1923         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1924         SMESHGUI_MergeNodesDlg *aDlg = new SMESHGUI_MergeNodesDlg(parent, "", Sel);
1925       }
1926       else {
1927         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1928                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1929                               tr("SMESH_BUT_OK"));
1930       }
1931       break;
1932     }
1933     
1934
1935   case 5000: // HYPOTHESIS
1936     {
1937       if(checkLock(aStudy)) break;
1938       EmitSignalDeactivateDialog();
1939       SMESHGUI_CreateHypothesesDlg *aDlg =
1940         new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
1941       break;
1942     }
1943   case 5010: // ALGO
1944     {
1945       if(checkLock(aStudy)) break;
1946       EmitSignalDeactivateDialog();
1947       SMESHGUI_CreateHypothesesDlg *aDlg =
1948         new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
1949       break;
1950     }
1951
1952   case 5105: // Library of selection filters
1953   {
1954     static QValueList<int> aTypes;
1955     if ( aTypes.isEmpty() )
1956     {
1957       aTypes.append( SMESH::NODE );
1958       aTypes.append( SMESH::EDGE );
1959       aTypes.append( SMESH::FACE );
1960       aTypes.append( SMESH::VOLUME );
1961     }
1962     new SMESHGUI_FilterLibraryDlg( parent, aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
1963   }
1964   break;
1965
1966   case 6016:                                    // CONTROLS 
1967   case 6015:
1968   case 6014:
1969   case 6013:
1970   case 6012:
1971   case 6011:
1972   case 6001:
1973   case 6002:
1974   case 6003:
1975   case 6004:    
1976     if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1977       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1978       if ( Sel->IObjectCount() == 1 && Sel->firstIObject()->hasEntry() ) {
1979         SALOMEDS::SObject_var SO = aStudy->FindObjectID( Sel->firstIObject()->getEntry() );
1980         if ( !SO->_is_nil() ) {
1981           CORBA::Object_var aObject = SO->GetObject();
1982           SMESH::SMESH_Mesh_var    aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
1983           SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
1984           SMESH::SMESH_Group_var   aGroup   = SMESH::SMESH_Group::_narrow( aObject );
1985           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
1986             ::Control( theCommandID );
1987             break;
1988           }
1989         }
1990       }
1991       QAD_MessageBox::warn1(GetDesktop(), 
1992                             tr( "SMESH_WRN_WARNING" ),
1993                             tr( "SMESH_BAD_SELECTION" ), 
1994                             tr( "SMESH_BUT_OK" ) );
1995       break;
1996     }
1997     else {
1998       QAD_MessageBox::warn1(GetDesktop(), 
1999                             tr( "SMESH_WRN_WARNING" ),
2000                             tr( "NOT_A_VTK_VIEWER" ), 
2001                             tr( "SMESH_BUT_OK" ) );
2002     }
2003     break;
2004   case 9010:
2005     {
2006       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2007       if (Sel->IObjectCount() == 1)     {
2008         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
2009         if(anIObject->hasEntry())
2010           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2011             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2012           }
2013       }
2014       break;
2015     }
2016   case 9011:
2017     {
2018       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2019       if (Sel->IObjectCount() == 1)     {
2020         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
2021         if(anIObject->hasEntry())
2022           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2023             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2024           }
2025       }
2026       break;
2027     }
2028   case 10001:                           // DISPLAY MODE PREFERENCE
2029     {
2030       // Wireframe
2031       parent->menuBar()->setItemChecked(10001, true);
2032       parent->menuBar()->setItemChecked(10002, false);
2033       parent->menuBar()->setItemChecked(10004, false);
2034       parent->menuBar()->setItemEnabled(10003, true);
2035       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2036       break;
2037     }
2038   case 10002:
2039     {
2040       parent->menuBar()->setItemChecked(10002, true);
2041       parent->menuBar()->setItemChecked(10001, false);
2042       parent->menuBar()->setItemChecked(10004, false);
2043       parent->menuBar()->setItemEnabled(10003, true);
2044       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2045       break;
2046     }
2047   case 10003:
2048     {
2049       parent->menuBar()->setItemChecked(10003,!parent->menuBar()->isItemChecked(10003));
2050       QAD_CONFIG->addSetting("SMESH:Shrink", parent->menuBar()->isItemChecked(10003) ? "yes" : "no");
2051       break;
2052     }
2053   case 10004:
2054     {
2055       parent->menuBar()->setItemChecked(10001, false);
2056       parent->menuBar()->setItemChecked(10004, true);
2057       parent->menuBar()->setItemChecked(10002, false);
2058       parent->menuBar()->setItemEnabled(10003, false);
2059       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Nodes");
2060       break;
2061     }
2062     
2063   }
2064
2065   myActiveStudy->updateObjBrowser(true);
2066   return true;
2067 }
2068
2069 //=============================================================================
2070 /*!
2071  *
2072  */
2073 //=============================================================================
2074 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
2075                             QAD_StudyFrame * studyFrame)
2076 {
2077   return false;
2078 }
2079
2080 //=============================================================================
2081 /*!
2082  *
2083  */
2084 //=============================================================================
2085 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
2086                            QAD_StudyFrame * studyFrame)
2087 {
2088   return true;
2089 }
2090
2091 //=============================================================================
2092 /*!
2093  *
2094  */
2095 //=============================================================================
2096 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
2097                           QAD_StudyFrame * studyFrame)
2098 {
2099   return true;
2100 }
2101
2102 //=============================================================================
2103 /*!
2104  *
2105  */
2106 //=============================================================================
2107 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
2108 {
2109   MESSAGE("SMESHGUI::SetSettings.");
2110   SMESHGUI::GetSMESHGUI();
2111
2112   /* Display mode */
2113   QString DisplayMode = "Shading";
2114   if ( QAD_CONFIG->hasSetting("SMESH:DisplayMode") )
2115     DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
2116   else
2117     QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2118
2119   bool Shrink = false;
2120   if ( QAD_CONFIG->hasSetting("SMESH:Shrink") )
2121     Shrink = QAD_CONFIG->getSetting("SMESH:Shrink") == "yes";
2122
2123   if (DisplayMode == "Wireframe") {
2124     // wireframe
2125     parent->menuBar()->setItemChecked(10004, false);
2126     parent->menuBar()->setItemChecked(10002, false);
2127     parent->menuBar()->setItemChecked(10001, true);
2128     parent->menuBar()->setItemEnabled(10003, true);
2129   }
2130   else if (DisplayMode == "Nodes") {
2131     // poins
2132     parent->menuBar()->setItemChecked(10004, true);
2133     parent->menuBar()->setItemChecked(10002, false);
2134     parent->menuBar()->setItemChecked(10001, false);
2135     parent->menuBar()->setItemEnabled(10003, false);
2136   }
2137   else {
2138     // default is shading
2139     parent->menuBar()->setItemChecked(10004, false);
2140     parent->menuBar()->setItemChecked(10002, true);
2141     parent->menuBar()->setItemChecked(10001, false);
2142     parent->menuBar()->setItemEnabled(10003, true);
2143   }
2144   parent->menuBar()->setItemChecked(10003, Shrink);
2145
2146   /* Automatic Update */
2147   QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
2148   if (AutoUpdate.compare("true") == 0) {
2149     parent->menuBar()->setItemChecked(1001, true);
2150     myAutomaticUpdate = true;
2151   }
2152   else {
2153     parent->menuBar()->setItemChecked(1001, false);
2154     myAutomaticUpdate = false;
2155   }
2156
2157   /* Selection */
2158   SMESH::UpdateSelectionProp();
2159
2160   /* menus disable */
2161   parent->menuBar()->setItemEnabled(111, false);        // IMPORT DAT
2162   //parent->menuBar()->setItemEnabled(112, false);      // IMPORT UNV
2163
2164   return true;
2165 }
2166
2167 //=============================================================================
2168 /*!
2169  *
2170  */
2171 //=============================================================================
2172 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
2173 {
2174   // NRI : Temporary added
2175   //  if ( myStudy->GetProperties()->IsLocked() ) {
2176   //    theObject = "NothingSelected";
2177   //    theContext = "NothingSelected";
2178   //  }
2179   // NRI
2180
2181   SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2182   int nbSel = Sel->IObjectCount();
2183   switch ( nbSel ) {
2184   case 0:
2185     theObject = "NothingSelected";
2186     theContext = "NothingSelected";
2187     break;
2188   case 1:
2189     if ( myState == 800 && Sel->HasIndex( Sel->firstIObject() ) )
2190       theObject = "Elements";
2191     else
2192       theObject = ::CheckTypeObject( Sel->firstIObject() );
2193     theContext = "";
2194     break;
2195   default:
2196     theObject = ::CheckHomogeneousSelection();
2197     theContext = "";
2198   }
2199 }
2200
2201 //=============================================================================
2202 /*!
2203  *
2204  */
2205 //=============================================================================
2206 bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
2207                            const QString& theParent, const QString& theObject)
2208 {
2209   // get active study frame
2210   QAD_StudyFrame* studyFrame = myActiveStudy->getActiveStudyFrame();
2211   
2212   // get parent component which selected object(s) belongs to
2213   QString parentComp = ( (SALOMEGUI_Desktop*)parent )->getComponentFromSelection();
2214
2215   // get selection
2216   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2217   int nbSel = Sel->IObjectCount();
2218
2219   if ( nbSel == 0 ) {
2220     popup->clear();
2221   }
2222   else if ( nbSel == 1 ) {
2223     if ( parentComp != parent->getActiveComponent() ) {
2224       // object not belongs to SMESH module - remove all commands except common Display/Erase...
2225       while ( 1 ) {
2226         int id = popup->idAt( 0 );
2227         if ( id <= QAD_TopLabel_Popup_ID )
2228           popup->removeItemAt( 0 );
2229         else
2230           break;
2231       }
2232     }
2233     else {
2234       // get selected interactive object 
2235       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2236       SALOMEDS::SObject_var SO = SMESH::GetActiveStudyDocument()->FindObjectID( IObject->getEntry() );
2237       // find popup menu's TopLabel item
2238       int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
2239       if ( topItem >= 0 ) {
2240         if ( theParent == "Viewer" ) {
2241           // set bold font for popup menu's TopLabel item (Viewer popup)
2242           QFont fnt = QApplication::font(); fnt.setBold( TRUE );
2243           popup->removeItem( QAD_TopLabel_Popup_ID );
2244           popup->insertItem( new CustomItem( QString( IObject->getName() ), fnt ), QAD_TopLabel_Popup_ID, topItem );
2245         }
2246         else if ( theParent == "ObjectBrowser" ) {
2247           // remove popup menu's TopLabel item (Object Browser popup)
2248           popup->removeItem( QAD_TopLabel_Popup_ID );
2249         }
2250       }
2251
2252       if ( theObject == "Hypothesis" || theObject == "Algorithm" ) {
2253         // remove Display/Erase commands
2254         popup->removeItem( QAD_Display_Popup_ID );
2255         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2256         popup->removeItem( QAD_Erase_Popup_ID );
2257         // remove "Unassign ..." command if hyp/algo is not assigned
2258         if ( SO->_is_nil() || !IObject->hasReference()/* !IsReferencedObject( SO ) */)
2259           popup->removeItem( 1102 );
2260       }
2261       else if ( theObject == "Mesh" || theObject == "SubMesh" || theObject == "Group" ) {
2262         // get actor
2263         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( SO );
2264         if ( aShapeObject->_is_nil() ) {
2265           // imported mesh
2266           popup->removeItem( 701 ); // Compute
2267           popup->removeItem( 705 ); // Edit hypothesis
2268           popup->removeItem( 706 ); // ...
2269         }
2270         SMESH_Actor* ac = SMESH::FindActorByEntry(IObject->getEntry());
2271         // if object has actor
2272         if ( ac && studyFrame->getTypeView() == VIEW_VTK ) {
2273           VTKViewer_RenderWindowInteractor* myRenderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
2274           if ( myRenderInter->isVisible( IObject ) ) {
2275             popup->removeItem( QAD_Display_Popup_ID );
2276             popup->setItemChecked( 9010, ac->GetPointsLabeled() ); // Numbering / Display Nodes #
2277             popup->setItemChecked( 9011, ac->GetCellsLabeled() );  // Numbering / Display Elements #
2278             TVisualObjPtr aVisualObj = ac->GetObject();
2279             int aNbEdges = aVisualObj->GetNbEntities(SMESH::EDGE);
2280             int aNbFaces = aVisualObj->GetNbEntities(SMESH::FACE);
2281             int aNbVolumes = aVisualObj->GetNbEntities(SMESH::VOLUME);
2282             QMenuItem* mi = popup->findItem( 1131 );
2283             if ( mi && mi->popup() ) {
2284               int  prType = ac->GetRepresentation();
2285               // Display Mode / Wireframe
2286               if(!aNbFaces && !aNbVolumes && !aNbEdges){
2287                 mi->popup()->removeItem( 211 );
2288               }else{
2289                 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
2290               }
2291               // Display Mode / Shading
2292               if(!aNbFaces && !aNbVolumes){
2293                 mi->popup()->removeItem( 212 );
2294               }else{
2295                 mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface );
2296               }
2297               // Display Mode / Points
2298               mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint );  
2299               // Display Mode / Shrink
2300               bool isShrunk = ac->IsShrunk();
2301               bool isShrunkable = ac->IsShrunkable();
2302               mi->popup()->setItemChecked( 213, isShrunk );   
2303               mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable);
2304             }
2305             // Scalar Bar
2306             mi = popup->findItem( 2000 );
2307             if ( mi && mi->popup() ) {
2308               SMESH_Actor::eControl cMode = ac->GetControlMode();
2309               switch ( cMode ) {
2310               case SMESH_Actor::eLengthEdges:
2311                 mi->popup()->setItemChecked( 6001, true ); break;
2312               case SMESH_Actor::eFreeEdges:
2313                 mi->popup()->setItemChecked( 6002, true );
2314                 mi->popup()->removeItem( 201 );
2315                 break;
2316               case SMESH_Actor::eFreeBorders:
2317                 mi->popup()->setItemChecked( 6003, true );
2318                 mi->popup()->removeItem( 201 );
2319                 break;
2320               case SMESH_Actor::eMultiConnection:
2321                 mi->popup()->setItemChecked( 6004, true ); break;
2322               case SMESH_Actor::eArea:
2323                 mi->popup()->setItemChecked( 6011, true ); break;
2324               case SMESH_Actor::eTaper:
2325                 mi->popup()->setItemChecked( 6012, true ); break;
2326               case SMESH_Actor::eAspectRatio:
2327                 mi->popup()->setItemChecked( 6013, true ); break;
2328               case SMESH_Actor::eMinimumAngle:
2329                 mi->popup()->setItemChecked( 6014, true ); break;
2330               case SMESH_Actor::eWarping:
2331                 mi->popup()->setItemChecked( 6015, true ); break;
2332               case SMESH_Actor::eSkew:
2333                 mi->popup()->setItemChecked( 6016, true ); break;
2334               case SMESH_Actor::eNone:
2335               default:
2336                 mi->popup()->removeItem( 200 );
2337                 mi->popup()->removeItem( 201 );
2338                 break;
2339               }
2340               TVisualObjPtr aVisualObj = ac->GetObject();
2341               if(!aNbEdges){
2342                 mi->popup()->removeItem( 6001 );
2343                 mi->popup()->removeItem( 6003 );
2344                 mi->popup()->removeItem( 6004 );
2345               }
2346               if(!aNbFaces){
2347                 mi->popup()->removeItem( 6002 );
2348                 mi->popup()->removeItem( 6011 );
2349                 mi->popup()->removeItem( 6012 );
2350                 mi->popup()->removeItem( 6013 );
2351                 mi->popup()->removeItem( 6014 );
2352                 mi->popup()->removeItem( 6015 );
2353                 mi->popup()->removeItem( 6016 );
2354               }
2355               if(!aNbFaces && !aNbEdges)
2356                 popup->removeItem( 2000 );                         // Scalar Bar
2357             }
2358           }
2359           else {
2360             popup->removeItem( QAD_Erase_Popup_ID );
2361             popup->removeItem( 114 );                              // Numbering popup menu
2362             popup->removeItem( 1131 );                             // Display mode
2363             popup->removeItem( 1132 );                             // Color / size
2364             popup->removeItem( 1133 );                             // Transparency
2365             popup->removeItem( 1134 );                             // Clipping
2366             popup->removeItem( 2000 );                             // Scalar Bar
2367           }
2368         }
2369         else {
2370           // object doesn't have actor
2371           CORBA::Object_var anObject = SO->GetObject();
2372           bool bDisplay = false;
2373           if ( !CORBA::is_nil( anObject ) ) {
2374             SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
2375             if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0  || aMeshObj->NbVolumes() > 0 ) )
2376               bDisplay = true;
2377             SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
2378             if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes(false) > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
2379               bDisplay = true;
2380             SMESH::SMESH_Group_var aGroupObj = SMESH::SMESH_Group::_narrow( anObject );
2381             if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
2382               bDisplay = true;
2383           }
2384           if ( !bDisplay ) {
2385             popup->removeItem( QAD_Display_Popup_ID );
2386             popup->removeItem( QAD_DisplayOnly_Popup_ID );
2387           }
2388           popup->removeItem( QAD_Erase_Popup_ID );
2389           popup->removeItem( 114 );                              // Numbering popup menu
2390           popup->removeItem( 1131 );                             // Display mode
2391           popup->removeItem( 1132 );                             // Color / size
2392           popup->removeItem( 1133 );                             // Transparency
2393           popup->removeItem( 1134 );                             // Clipping
2394           popup->removeItem( 2000 );                             // Scalar Bar
2395         }
2396       }
2397       else if( theObject!="Component" ) {
2398         // another SMESH object
2399         popup->removeItem( QAD_Display_Popup_ID );
2400         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2401         popup->removeItem( QAD_Erase_Popup_ID );
2402       }
2403     }
2404   }
2405   else {
2406     // multiple selection
2407     if ( parentComp != parent->getActiveComponent() ) {
2408       // object not belongs to SMESH module - remove all commands except common Display/Erase...
2409       while ( 1 )       {
2410         int id = popup->idAt( 0 );
2411         if ( id <= QAD_TopLabel_Popup_ID )
2412           popup->removeItemAt( 0 );
2413         else
2414           break;
2415       }
2416       if ( parentComp.isNull() ) {
2417         // objects from different components are selected
2418         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2419         popup->removeItem( QAD_Display_Popup_ID );
2420         popup->removeItem( QAD_Erase_Popup_ID );
2421       }
2422     }
2423     else {
2424       QString type = ::CheckHomogeneousSelection();
2425       if ( type != "Heterogeneous Selection" ) {
2426         int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
2427         if ( topItem >= 0 ) {
2428           // set bold font for popup menu's TopLabel item
2429           QFont fnt = QApplication::font(); fnt.setBold( TRUE );
2430           popup->removeItem( QAD_TopLabel_Popup_ID );
2431           popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
2432         }
2433       }
2434     }
2435   }
2436   return false;
2437 }
2438
2439 //=============================================================================
2440 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2441  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2442  */
2443 //=============================================================================
2444 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
2445 {
2446   if(theIO->hasEntry()){
2447     QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
2448     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
2449     SMESH::UpdateView(aStudyFrame,SMESH::eDisplay,theIO->getEntry());
2450   }
2451 }
2452
2453 void SMESHGUI::SupportedViewType(int *buffer, int bufferSize)
2454 {
2455   if (!buffer || !bufferSize)
2456     return;
2457   buffer[0] = (int)VIEW_VTK;
2458 }
2459
2460 void SMESHGUI::Deactivate()
2461 {
2462   if ( SMESHGUI::GetSMESHGUI() ) {
2463     SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
2464   }
2465 }