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