Salome HOME
Bug PAL7334 DEVELOPMENT : Control Improvement
[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         new SMESHGUI_ClippingDlg(QAD_Application::getDesktop(),"",false);
296         return;
297       }
298       case 1133:{
299         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
300         new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false);
301         return;
302       }}
303       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
304       for(; It.More(); It.Next()){
305         Handle(SALOME_InteractiveObject) IObject = It.Value();
306         if(IObject->hasEntry()){
307           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
308             switch(theCommandID){
309             case 211:
310               anActor->SetRepresentation(SMESH_Actor::eEdge);
311               break;
312             case 212:
313               anActor->SetRepresentation(SMESH_Actor::eSurface);
314               break;
315             case 213:
316               if(anActor->IsShrunk()) 
317                 anActor->UnShrink();
318               else
319                 anActor->SetShrink();
320               break;
321             case 215:
322               anActor->SetRepresentation(SMESH_Actor::ePoint);
323               break;
324             case 1132:{
325               float color[3];
326               anActor->GetSufaceColor(color[0], color[1], color[2]);
327               int c0 = int (color[0] * 255);
328               int c1 = int (color[1] * 255);
329               int c2 = int (color[2] * 255);
330               QColor c(c0, c1, c2);
331               
332               float edgecolor[3];
333               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
334               c0 = int (edgecolor[0] * 255);
335               c1 = int (edgecolor[1] * 255);
336               c2 = int (edgecolor[2] * 255);
337               QColor e(c0, c1, c2);
338               
339               float backfacecolor[3];
340               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
341               c0 = int (backfacecolor[0] * 255);
342               c1 = int (backfacecolor[1] * 255);
343               c2 = int (backfacecolor[2] * 255);
344               QColor b(c0, c1, c2);
345               
346               float nodecolor[3];
347               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
348               c0 = int (nodecolor[0] * 255);
349               c1 = int (nodecolor[1] * 255);
350               c2 = int (nodecolor[2] * 255);
351               QColor n(c0, c1, c2);
352               
353               int Edgewidth = (int)anActor->GetLineWidth();
354               if(Edgewidth == 0)
355                 Edgewidth = 1;
356               int intValue = int(anActor->GetNodeSize());
357               float Shrink = anActor->GetShrinkFactor();
358               
359               SMESHGUI_Preferences_ColorDlg *aDlg = 
360                 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),"");
361               aDlg->SetColor(1, c);
362               aDlg->SetColor(2, e);
363               aDlg->SetColor(3, n);
364               aDlg->SetColor(4, b);
365               aDlg->SetIntValue(1, Edgewidth);
366               aDlg->SetIntValue(2, intValue);
367               aDlg->SetIntValue(3, int(Shrink*100.));
368               if(aDlg->exec()){
369                 QColor color = aDlg->GetColor(1);
370                 QColor edgecolor = aDlg->GetColor(2);
371                 QColor nodecolor = aDlg->GetColor(3);
372                 QColor backfacecolor = aDlg->GetColor(4);
373                 /* actor color and backface color */
374                 anActor->SetSufaceColor(float (color.red()) / 255.,
375                                          float (color.green()) / 255., 
376                                          float (color.blue()) / 255.);
377                 anActor->SetBackSufaceColor(float (backfacecolor.red()) / 255., 
378                                              float (backfacecolor.green()) / 255.,
379                                              float (backfacecolor.blue()) / 255.);
380                 
381                 /* edge color */
382                 anActor->SetEdgeColor(float (edgecolor.red()) / 255.,
383                                        float (edgecolor.green()) / 255.,
384                                        float (edgecolor.blue()) / 255.);
385                 
386                 /* Shrink factor and size edges */
387                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
388                 anActor->SetLineWidth(aDlg->GetIntValue(1));
389                 
390                 /* Nodes color and size */
391                 anActor->SetNodeColor(float (nodecolor.red()) / 255.,
392                                float (nodecolor.green()) / 255.,
393                                        float (nodecolor.blue()) / 255.);
394                 anActor->SetNodeSize(aDlg->GetIntValue(2));
395                 
396                 delete aDlg;
397               }
398               break;
399             }}
400           }
401         }
402       }
403       SMESH::RepaintCurrentView();
404     }
405   }
406
407
408   void SetDisplaySettings()
409   {
410     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
411     SMESHGUI_Preferences_ColorDlg *aDlg =
412       new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
413
414     QColor color;
415     QString SCr, SCg, SCb;
416     SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
417     SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
418     SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
419     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
420       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
421     else color = QColor(0, 170, 255);
422     aDlg->SetColor(1, color);
423     
424     SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
425     SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
426     SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
427     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
428       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
429     else color = QColor(0, 170, 255);
430     aDlg->SetColor(2, color);
431     
432     SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
433     SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
434     SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
435     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
436       color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
437     else color = Qt::red;
438     aDlg->SetColor(3, color);
439     
440     QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
441     QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
442     QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
443     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
444       color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
445     else color = Qt::blue;
446     aDlg->SetColor(4, color);
447     
448     QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
449     if (intValue.isEmpty()) intValue = "1";
450     aDlg->SetIntValue(1, intValue.toInt());
451     intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
452     if (intValue.isEmpty()) intValue = "3";
453     aDlg->SetIntValue(2, intValue.toInt());
454     intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
455     if (intValue.isEmpty()) intValue = "75";
456     aDlg->SetIntValue(3, intValue.toInt());
457     
458     if (aDlg->exec()) {
459       QColor colorFill = aDlg->GetColor(1);
460       QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
461       QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
462       QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
463       
464       QColor colorOutline = aDlg->GetColor(2);
465       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
466       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
467       QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
468       
469       QColor colorNode = aDlg->GetColor(3);
470       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
471       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
472       QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
473       
474       QColor colorBackFace = aDlg->GetColor(4);
475       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
476       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
477       QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
478       
479       int width = aDlg->GetIntValue(1);
480       QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
481       
482       int nodes_size = aDlg->GetIntValue(2);
483       QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
484       
485       int shrink_coeff = aDlg->GetIntValue(3);
486       QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
487     }
488     
489     delete aDlg;
490   }
491   
492   
493   void Control( int theCommandID )
494   {
495     SALOME_Selection *Sel = SALOME_Selection::Selection( SMESH::GetActiveStudy()->getSelection() );
496     if(Sel){
497       Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
498       if(!anIO.IsNull()){
499         QString aTitle;
500         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
501         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
502           switch ( theCommandID ){
503           case 6001:
504             aTitle = QObject::tr( "LENGTH_EDGES" );
505             aControl = SMESH_Actor::eLengthEdges;
506             break;
507           case 6002:
508             aTitle = QObject::tr( "FREE_EDGES" );
509             aControl = SMESH_Actor::eFreeEdges;
510             break;
511           case 6003:
512             aTitle = QObject::tr( "FREE_BORDERS" );
513             aControl = SMESH_Actor::eFreeBorders;
514             break;
515           case 6004:
516             aTitle = QObject::tr( "MULTI_BORDERS" );
517             aControl = SMESH_Actor::eMultiConnection;
518             break;
519           case 6011:
520             aTitle = QObject::tr( "AREA_ELEMENTS" );
521             aControl = SMESH_Actor::eArea;
522             break;
523           case 6012:
524             aTitle = QObject::tr( "TAPER_ELEMENTS" );
525             aControl = SMESH_Actor::eTaper;
526             break;
527           case 6013:
528             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
529             aControl = SMESH_Actor::eAspectRatio;
530             break;
531           case 6017:
532             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
533             aControl = SMESH_Actor::eAspectRatio3D;
534             break;
535           case 6014:
536             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
537             aControl = SMESH_Actor::eMinimumAngle;
538             break;
539           case 6015:
540             aTitle = QObject::tr( "WARP_ELEMENTS" );
541             aControl = SMESH_Actor::eWarping;
542             break;
543           case 6016:
544             aTitle = QObject::tr( "SKEW_ELEMENTS" );
545             aControl = SMESH_Actor::eSkew;
546             break;
547           }
548           anActor->SetControlMode(aControl);
549           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
550         }
551       }
552     }
553   }
554   
555
556   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
557                    MeshObjectType                           theType,
558                    const QString                            theInTypeName,
559                    QString &                                theOutTypeName)
560   {
561     SMESH_TypeFilter aTypeFilter( theType );
562     if ( aTypeFilter.IsOk( theIO )) {
563       theOutTypeName = theInTypeName;
564       return true;
565     }
566     return false;
567   }
568     
569
570   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
571   {
572     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
573     SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theIO->getEntry());
574     if (!aSObj->_is_nil()) {
575       SALOMEDS::SComponent_var aSComp = aSObj->GetFatherComponent();
576       CORBA::String_var anID = aSComp->GetID();
577       if (!strcmp(anID.in(),theIO->getEntry()))
578         return "Component";
579     }
580     
581     QString aTypeName;
582     if (
583         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
584         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
585         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
586         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
587         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
588         )
589       return aTypeName;
590     
591     return "NoType";
592   }
593
594
595   QString CheckHomogeneousSelection()
596   {
597     QAD_Study* aStudy = SMESH::GetActiveStudy();
598     SALOME_Selection *aSel = SALOME_Selection::Selection(aStudy->getSelection());
599     /* copy the list */
600     SALOME_ListIO List;
601     SALOME_ListIteratorOfListIO Itinit(aSel->StoredIObjects());
602     for (; Itinit.More(); Itinit.Next())
603       {
604         List.Append(Itinit.Value());
605       }
606
607     QString RefType = CheckTypeObject(aSel->firstIObject());
608     SALOME_ListIteratorOfListIO It(List);
609     for (; It.More(); It.Next())
610       {
611         Handle(SALOME_InteractiveObject) IObject = It.Value();
612         QString Type = CheckTypeObject(IObject);
613         if (Type.compare(RefType) != 0)
614           return "Heterogeneous Selection";
615       }
616     
617     aSel->ClearIObjects();
618     SALOME_ListIteratorOfListIO It1(List);
619     for (; It1.More(); It1.Next())
620       {
621         int res = aSel->AddIObject(It1.Value());
622         if (res == -1)
623           aStudy->highlight(It1.Value(), false);
624         if (res == 0)
625           aStudy->highlight(It1.Value(), true);
626       }
627     return RefType;
628   }
629
630   void OnEditDelete()
631   {
632     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
633     QString aParentComponent = ((SALOMEGUI_Desktop*)QAD_Application::getDesktop())->getComponentFromSelection();
634     if ( aParentComponent != QAD_Application::getDesktop()->getActiveComponent() )  {
635       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(),
636                               QObject::tr("ERR_ERROR"), 
637                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg(QAD_Application::getDesktop()->getComponentUserName( "SMESH" )),
638                               QObject::tr("BUT_OK") );
639       return;
640     }
641     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
642     if (QAD_MessageBox::warn2
643         (QAD_Application::getDesktop(),
644          QObject::tr("SMESH_WRN_WARNING"),
645          QObject::tr("SMESH_REALLY_DELETE"),
646          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
647       return;
648
649     QAD_Study* anActiveStudy = SMESH::GetActiveStudy();
650     int nbSf = anActiveStudy->getStudyFramesCount();
651     
652     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
653     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
654     SALOMEDS::GenericAttribute_var anAttr;
655     SALOMEDS::AttributeIOR_var anIOR;
656     
657     SALOME_Selection *Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
658     SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
659     for(; It.More(); It.Next()){
660       Handle(SALOME_InteractiveObject) IObject = It.Value();
661       if(IObject->hasEntry()){
662         SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
663         
664         /* Erase child graphical objects */
665         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
666         for(; it->More(); it->Next()){
667           SALOMEDS::SObject_var CSO = it->Value();
668           if(CSO->FindAttribute(anAttr, "AttributeIOR")){
669             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
670             
671             for(int i = 0; i < nbSf; i++){
672               QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
673               CORBA::String_var anEntry = CSO->GetID();
674               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
675                 SMESH::RemoveActor(sf,anActor);
676               }
677             }
678           }
679         }
680         
681         /* Erase main graphical object */
682         for(int i = 0; i < nbSf; i++){
683           QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
684           if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
685             SMESH::RemoveActor(sf,anActor);
686           }
687         }
688         
689         // Remove object(s) from data structures
690         SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
691         if(!obj->_is_nil()){
692           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(obj->GetObject());
693           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
694           
695           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
696             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
697             aMesh->RemoveGroup( aGroup );
698           }
699           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
700             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
701             aMesh->RemoveSubMesh( aSubMesh );
702           }
703           else {// default action: remove SObject from the study
704             // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
705             //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
706             //op->start();
707             aStudyBuilder->RemoveObjectWithChildren( obj );
708             //op->finish();
709           }
710         }
711         
712       } /* IObject->hasEntry() */
713     } /* more/next */
714     
715     /* Clear any previous selection */
716     Sel->ClearIObjects();
717     anActiveStudy->updateObjBrowser();
718   }
719
720
721 }
722
723 //=============================================================================
724 /*!
725  *
726  */
727 //=============================================================================
728 class CustomItem : public QCustomMenuItem
729 {
730 public:
731   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
732   ~CustomItem() {}
733
734   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
735   {
736     p->save();
737     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
738     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
739     p->setFont( myFont );
740     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
741     p->restore();
742   }
743
744   QSize sizeHint()
745   {
746     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
747   }
748
749   bool fullSpan() const
750   {
751     return true;
752   }
753
754 private:
755   QString myString;
756   QFont   myFont;
757 };
758
759 //=============================================================================
760 /*!
761  *
762  */
763 //=============================================================================
764 SMESHGUI::SMESHGUI( const QString& theName, QObject* theParent ) :
765   SALOMEGUI( theName, theParent )
766 {
767   myActiveDialogBox = 0 ;
768   myState = -1 ;
769
770   SMESH::GetSMESHGen();
771   SMESH::GetFilterManager();
772   SMESH::GetPattern();
773
774   /* load resources for all available meshers */
775   SMESH::InitAvailableHypotheses();
776 }
777
778 //=============================================================================
779 /*!
780  *
781  */
782 //=============================================================================
783 SMESHGUI::~SMESHGUI()
784 {
785   SMESH::GetFilterManager()->Destroy();
786 }
787
788 //=============================================================================
789 /*!
790  *
791  */
792 //=============================================================================
793 SMESHGUI* SMESHGUI::GetSMESHGUI()
794 {
795   static SMESHGUI aSMESHGUI;
796   aSMESHGUI.myActiveStudy = SMESH::GetActiveStudy();
797   SMESH::GetSMESHGen()->SetCurrentStudy( SMESH::GetActiveStudyDocument() );
798
799   /* Automatic Update flag */
800   aSMESHGUI.myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
801
802   return &aSMESHGUI;
803 }
804
805 extern "C"
806 {
807   Standard_EXPORT SALOMEGUI* GetComponentGUI() {
808     return SMESHGUI::GetSMESHGUI();
809   }
810 }
811
812 //=============================================================================
813 /*!
814  *
815  */
816 //=============================================================================
817 void SMESHGUI::SetState(int aState)
818 {
819   this->myState = aState;
820   return;
821 }
822
823 //=============================================================================
824 /*!
825  *
826  */
827 //=============================================================================
828 void SMESHGUI::ResetState()
829 {
830   this->myState = -1;
831   return;
832 }
833
834 //=============================================================================
835 /*!
836  *
837  */
838 //=============================================================================
839 void SMESHGUI::EmitSignalDeactivateDialog()
840 {
841   emit this->SignalDeactivateActiveDialog();
842   return;
843 }
844
845 //=============================================================================
846 /*!
847  *
848  */
849 //=============================================================================
850 void SMESHGUI::EmitSignalStudyFrameChanged()
851 {
852   emit this->SignalStudyFrameChanged();
853   return;
854 }
855
856 //=============================================================================
857 /*!
858  *
859  */
860 //=============================================================================
861 void SMESHGUI::EmitSignalCloseAllDialogs()
862 {
863   emit SignalCloseAllDialogs();
864   return;
865 }
866
867 //=============================================================================
868 /*!
869  *
870  */
871 //=============================================================================
872 QDialog *SMESHGUI::GetActiveDialogBox()
873 {
874   return this->myActiveDialogBox;
875 }
876
877 //=============================================================================
878 /*!
879  *
880  */
881 //=============================================================================
882 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
883 {
884   this->myActiveDialogBox = (QDialog *) aDlg;
885   return;
886 }
887
888 //=============================================================================
889 /*!
890  *
891  */
892 //=============================================================================
893 QAD_Study *SMESHGUI::GetActiveStudy()
894 {
895   return this->myActiveStudy;
896 }
897
898 //=============================================================================
899 /*!
900  *
901  */
902 //=============================================================================
903 QAD_Desktop *SMESHGUI::GetDesktop()
904 {
905   return QAD_Application::getDesktop();
906 }
907
908 //=============================================================================
909 /*!
910  *
911  */
912 //=============================================================================
913 bool SMESHGUI::ActiveStudyChanged(QAD_Desktop* parent)
914 {
915   MESSAGE("SMESHGUI::activeStudyChanged init.");
916   QAD_Study* prevStudy = myActiveStudy;
917   /* Create or retrieve an object SMESHGUI */
918   MESSAGE("Active study changed : prev study =" << prevStudy);
919   SMESHGUI::GetSMESHGUI();
920   EmitSignalStudyFrameChanged();
921   MESSAGE("Active study changed : active study =" << myActiveStudy);
922   if ( prevStudy != myActiveStudy ) {
923     EmitSignalCloseAllDialogs();
924     MESSAGE("Active study changed : SMESHGUI nullified" << endl);
925     //smeshGUI = 0;
926     SMESH::UpdateSelectionProp();
927   }
928   MESSAGE("SMESHGUI::activeStudyChanged done.");
929   return true;
930 }
931
932 //=============================================================================
933 /*!
934  *
935  */
936 //=============================================================================
937 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
938 {
939   /* Here the position is on the bottom right corner - 10 */
940   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
941   aDlg->adjustSize();
942   QAD_Desktop *PP = QAD_Application::getDesktop();
943   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
944   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
945   return true;
946 }
947
948 //=============================================================================
949 /*!
950  *
951  */
952 //=============================================================================
953 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
954   return theStudy->GetProperties()->IsLocked();
955 }
956
957 static bool checkLock(const SALOMEDS::Study_var& theStudy) {
958   if (isStudyLocked(theStudy)) {
959     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
960                            QObject::tr("WRN_WARNING"), 
961                            QObject::tr("WRN_STUDY_LOCKED"),
962                            QObject::tr("BUT_OK") );
963     return true;
964   }
965   return false;
966 }
967
968 //=======================================================================
969 //function : CheckActiveStudyLocked
970 //purpose  : 
971 //=======================================================================
972
973 bool SMESHGUI::ActiveStudyLocked()
974 {
975   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
976   return checkLock( aStudy );
977 }
978
979 //=============================================================================
980 /*!
981  *
982  */
983 //=============================================================================
984 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
985 {
986   SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
987
988   switch (theCommandID) {
989   case 33:                                      // DELETE
990     if(checkLock(aStudy)) break;
991     ::OnEditDelete();
992     break;
993     
994   case 113:                                     // IMPORT
995   case 112:
996   case 111:
997     {
998       if(checkLock(aStudy)) break;
999       ::ImportMeshesFromFile(parent,SMESH::GetSMESHGen(),theCommandID);
1000       break;
1001     }
1002
1003   case 122:                                     // EXPORT MED
1004   case 121:
1005   case 123:
1006     {
1007       ::ExportMeshToFile(parent, theCommandID);
1008       break;
1009     }
1010
1011   case 200:                                     // SCALAR BAR
1012     {
1013       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1014       if( Sel && Sel->IObjectCount() ) {
1015         Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
1016         if( anIO->hasEntry() ) {
1017           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1018             anActor->SetControlMode( SMESH_Actor::eNone );
1019           }
1020         }
1021       }
1022       break;
1023     }
1024   case 201:
1025     {
1026       SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1027       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
1028       break;
1029     }
1030
1031   case 1134: // Clipping
1032   case 1133: // Tranparency
1033   case 1132: // Colors / Size
1034   case 215:
1035   case 213:
1036   case 212:
1037   case 211:
1038     {
1039       ::SetViewMode(theCommandID);
1040       break;
1041     }
1042
1043   case 214:                                     // UPDATE
1044     {
1045       if(checkLock(aStudy)) break;
1046       SMESH::UpdateView();
1047       break;
1048     }
1049
1050   case 300:                                     // ERASE
1051   case 301:                                     // DISPLAY
1052   case 302:                                     // DISPLAY ONLY
1053     {
1054       SMESH::EDisplaing anAction;
1055       switch(theCommandID){
1056       case 300: anAction = SMESH::eErase; break;
1057       case 301: anAction = SMESH::eDisplay; break;
1058       case 302: anAction = SMESH::eDisplayOnly; break;
1059       }
1060       
1061       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1062       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1063         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1064         for (; It.More(); It.Next()) {
1065           Handle(SALOME_InteractiveObject) IOS = It.Value();
1066           if (IOS->hasEntry()) {
1067             SMESH::UpdateView(anAction,IOS->getEntry());
1068           }
1069         }
1070       }
1071       Sel->ClearIObjects();
1072       break;
1073     }
1074
1075   case 400:                                     // NODES
1076     {
1077       if(checkLock(aStudy)) break;
1078       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1079         EmitSignalDeactivateDialog();
1080         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1081         new SMESHGUI_NodesDlg(parent, "", Sel);
1082       }
1083       else {
1084         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1085                               tr("SMESH_WRN_WARNING"), 
1086                               tr("SMESH_WRN_VIEWER_VTK"),
1087                               tr("SMESH_BUT_OK"));
1088       }
1089       break;
1090     }
1091
1092   case 2151:  // FILTER
1093   {
1094     if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1095     {
1096       EmitSignalDeactivateDialog();
1097       new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
1098     }
1099     break;
1100   }
1101     
1102   case 406:                                     // MOVE NODE
1103     {
1104       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1105       {
1106         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1107           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1108         break;
1109       }
1110       
1111       if(checkLock(aStudy)) break;
1112       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1113       new SMESHGUI_MoveNodesDlg( parent, Sel );
1114       break;
1115     }
1116     
1117   case 701:                                     // COMPUTE MESH 
1118     {
1119       if(checkLock(aStudy)) break;
1120       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1121         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1122         int nbSel = Sel->IObjectCount();
1123         if (nbSel != 1){
1124           break;
1125         }
1126
1127         SMESH::SMESH_Mesh_var aMesh;
1128         SMESH::SMESH_subMesh_var aSubMesh;
1129         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1130         if (IObject->hasEntry()){
1131           SALOMEDS::SObject_var aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
1132           GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
1133           if ( aShapeObject->_is_nil() ) {
1134             // imported mesh
1135             break;
1136           }
1137           if(!aMeshSObj->_is_nil()) {
1138             SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
1139             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
1140             
1141             if (!aMesh->_is_nil()){
1142               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1143               if (!refShapeObject->_is_nil()) {
1144                 if(!SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject)){
1145                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1146                                         tr("SMESH_WRN_WARNING"),
1147                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1148                                         tr("SMESH_BUT_OK"));
1149                   break;
1150                 }
1151                 try{
1152                   if (SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject))
1153                     SMESH::ModifiedMesh(aMeshSObj,true);
1154                   // TO Do : change icon of all submeshes
1155                   else
1156                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1157                                           tr("SMESH_WRN_WARNING"),
1158                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1159                                           tr("SMESH_BUT_OK"));
1160                 }
1161                 catch(const SALOME::SALOME_Exception & S_ex){
1162                   QtCatchCorbaException(S_ex);
1163                 }
1164               }
1165             }else if(!aSubMesh->_is_nil()){
1166               aMesh = aSubMesh->GetFather();
1167               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1168               if(!refShapeObject->_is_nil()){
1169                 bool compute = SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject);
1170                 if(!compute){
1171                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1172                                         tr("SMESH_WRN_WARNING"),
1173                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1174                                         tr("SMESH_BUT_OK"));
1175                   break;
1176                 }
1177                 try{
1178                   if ( SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject) )
1179                     SMESH::ModifiedMesh(aMeshSObj,true);
1180                   // TO Do : change icon of all submeshes
1181                   else
1182                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1183                                           tr("SMESH_WRN_WARNING"),
1184                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1185                                           tr("SMESH_BUT_OK"));
1186                 }catch(const SALOME::SALOME_Exception & S_ex){
1187                   QtCatchCorbaException(S_ex);
1188                 }
1189               }
1190             }
1191           }
1192         }
1193         CORBA::Long anId = aStudy->StudyId();
1194         TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,IObject->getEntry());
1195         if(myAutomaticUpdate && aVisualObj){
1196           aVisualObj->Update();
1197           SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
1198           if(!anActor){
1199             anActor = SMESH::CreateActor(aStudy,IObject->getEntry());
1200             if(anActor){
1201               SMESH::DisplayActor(myActiveStudy->getActiveStudyFrame(),anActor); //apo
1202               SMESH::FitAll();
1203             }
1204           }
1205         }
1206       }else{
1207         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1208                               tr("SMESH_WRN_WARNING"), 
1209                               tr("SMESH_WRN_VIEWER_VTK"),
1210                               tr("SMESH_BUT_OK"));
1211       }
1212       break;
1213     }
1214
1215   case 702:                                     // ADD SUB MESH 
1216     {
1217       if(checkLock(aStudy)) break;
1218       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1219         EmitSignalDeactivateDialog();
1220         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1221         new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
1222       }
1223       else {
1224         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1225                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1226                               tr("SMESH_BUT_OK"));
1227       }
1228       break;
1229     }
1230     
1231   case 703:                                     // INIT MESH 
1232     {
1233       if(checkLock(aStudy)) break;
1234       EmitSignalDeactivateDialog();
1235       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1236       new SMESHGUI_InitMeshDlg(parent, "", Sel);
1237       break;
1238     }
1239
1240   case 704:                                     // EDIT Hypothesis 
1241     {
1242       if(checkLock(aStudy)) break;
1243       EmitSignalDeactivateDialog();
1244       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1245       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1246       break;
1247     }
1248
1249   case 705:                                     //  EDIT Global Hypothesis
1250     {
1251       if(checkLock(aStudy)) break;
1252       EmitSignalDeactivateDialog();
1253       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1254       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1255       break;
1256     }
1257
1258   case 706:                                     //  EDIT Local Hypothesis
1259     {
1260       if(checkLock(aStudy)) break;
1261       EmitSignalDeactivateDialog();
1262       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1263       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1264       break;
1265     }
1266
1267   case 407: // DIAGONAL INVERSION
1268   case 408: // Delete diagonal
1269     {
1270       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1271       {
1272         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1273           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1274         break;
1275       }
1276
1277       if ( checkLock( aStudy ) )
1278         break;
1279         
1280       SALOME_Selection *aSel =
1281         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1282       /*Standard_Boolean aRes;
1283       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1284       if ( aMesh->_is_nil() )
1285       {
1286         QAD_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1287           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1288         break;
1289       }
1290       */
1291       EmitSignalDeactivateDialog();
1292       if ( theCommandID == 407 )
1293         new SMESHGUI_TrianglesInversionDlg( parent, aSel );
1294       else
1295         new SMESHGUI_UnionOfTwoTrianglesDlg( parent, aSel );
1296       break;
1297     }
1298     case 409: // Change orientation
1299     case 410: // Union of triangles
1300     case 411: // Cutting of quadrangles
1301     {
1302       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1303       {
1304         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1305           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1306         break;
1307       }
1308
1309       if ( checkLock( aStudy ) )
1310         break;
1311
1312       SALOME_Selection *aSel =
1313         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1314
1315       EmitSignalDeactivateDialog();
1316       SMESHGUI_MultiEditDlg* aDlg;
1317       if ( theCommandID == 409 )
1318         aDlg = new SMESHGUI_ChangeOrientationDlg( parent, aSel );
1319       else if ( theCommandID == 410 )
1320         aDlg = new SMESHGUI_UnionOfTrianglesDlg( parent, aSel );
1321       else
1322         aDlg = new SMESHGUI_CuttingOfQuadsDlg( parent, aSel );
1323
1324       int x, y ;
1325       DefineDlgPosition( aDlg, x, y );
1326       aDlg->move( x, y );
1327       aDlg->show();
1328       break;
1329     }
1330   case 412: // Smoothing
1331     {
1332       if(checkLock(aStudy)) break;
1333       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1334         EmitSignalDeactivateDialog();
1335         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1336         new SMESHGUI_SmoothingDlg(parent, "", Sel);
1337       }
1338       else {
1339         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1340                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1341                               tr("SMESH_BUT_OK"));
1342       }
1343       break;
1344     }
1345   case 413: // Extrusion
1346     {
1347       if(checkLock(aStudy)) break;
1348       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1349         EmitSignalDeactivateDialog();
1350         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1351         new SMESHGUI_ExtrusionDlg(parent, "", Sel);
1352       }
1353       else {
1354         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1355                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1356                               tr("SMESH_BUT_OK"));
1357       }
1358       break;
1359     }
1360   case 414: // Revolution
1361     {
1362       if(checkLock(aStudy)) break;
1363       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1364         EmitSignalDeactivateDialog();
1365         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1366         new SMESHGUI_RevolutionDlg(parent, "", Sel);
1367       }
1368       else {
1369         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1370                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1371                               tr("SMESH_BUT_OK"));
1372       }
1373       break;
1374     }
1375   case 415: // Pattern mapping
1376     {
1377       if ( checkLock( aStudy ) )
1378         break;
1379       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1380       {
1381         EmitSignalDeactivateDialog();
1382         SALOME_Selection *Sel = SALOME_Selection::Selection(
1383           myActiveStudy->getSelection() );
1384         new SMESHGUI_MeshPatternDlg( parent, Sel );
1385       }
1386       else {
1387         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1388                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1389                               tr("SMESH_BUT_OK"));
1390       }
1391       break;
1392     }
1393   case 801:                                     // CREATE GROUP
1394     {
1395       if(checkLock(aStudy)) break;
1396       EmitSignalDeactivateDialog();
1397       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1398       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1399       int nbSel = Sel->IObjectCount();
1400       if (nbSel == 1) {
1401         // check if mesh is selected
1402         aMesh = SMESH::GetMeshByIO(Sel->firstIObject());
1403       }
1404       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
1405       aDlg->show();
1406       break;
1407     }
1408
1409   case 802:                                     // CONSTRUCT GROUP
1410     {
1411       if(checkLock(aStudy)) break;
1412       EmitSignalDeactivateDialog();
1413       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1414       int nbSel = Sel->IObjectCount();
1415       if (nbSel == 1) {
1416         // check if submesh is selected
1417         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1418         if (IObject->hasEntry()) {
1419           SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(IObject->getEntry());
1420           if(!aSObj->_is_nil()) {
1421             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
1422             if (!aSubMesh->_is_nil()) {
1423               try {
1424                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1425                 // get submesh elements list by types
1426                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1427                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1428                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1429                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1430                 // create group for each type o elements
1431                 QString aName = IObject->getName();
1432                 if (aNodes->length() > 0) {
1433                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName);
1434                   aGroup->Add(aNodes.inout());
1435                 }
1436                 if (aEdges->length() > 0) {
1437                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName);
1438                   aGroup->Add(aEdges.inout());
1439                 }
1440                 if (aFaces->length() > 0) {
1441                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName);
1442                   aGroup->Add(aFaces.inout());
1443                 }
1444                 if (aVolumes->length() > 0) {
1445                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName);
1446                   aGroup->Add(aVolumes.inout());
1447                 }
1448                 myActiveStudy->updateObjBrowser(true);
1449               }catch(const SALOME::SALOME_Exception & S_ex){
1450                 QtCatchCorbaException(S_ex);
1451               }
1452             }
1453           }
1454         }
1455       }
1456       break;
1457     }
1458
1459   case 803:                                     // EDIT GROUP
1460     {
1461       if(checkLock(aStudy)) break;
1462       EmitSignalDeactivateDialog();
1463       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1464       SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1465       SALOME_ListIteratorOfListIO It (IOs);
1466       int nbSelectedGroups = 0;
1467       for ( ; It.More(); It.Next() )
1468       {
1469         SMESH::SMESH_Group_var aGroup =
1470           SMESH::IObjectToInterface<SMESH::SMESH_Group>(It.Value());
1471         if (!aGroup->_is_nil()) {
1472           nbSelectedGroups++;
1473           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
1474           aDlg->show();
1475         }
1476       }
1477       if (nbSelectedGroups == 0)
1478         {
1479           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, SMESH::SMESH_Group::_nil());
1480           aDlg->show();
1481         }
1482       break;
1483     }
1484
1485   case 804:                                     // Add elements to group
1486     {
1487       if(checkLock(aStudy)) break;
1488       if (myState == 800) {
1489         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1490         if (aDlg) aDlg->onAdd();
1491       }
1492       break;
1493     }
1494
1495   case 805:                                     // Remove elements from group
1496     {
1497       if(checkLock(aStudy)) break;
1498       if (myState == 800) {
1499         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1500         if (aDlg) aDlg->onRemove();
1501       }
1502       break;
1503     }
1504
1505     case 810: // Union Groups
1506     case 811: // Intersect groups
1507     case 812: // Cut groups
1508     {
1509       if ( checkLock( aStudy ) )
1510         break;
1511
1512       EmitSignalDeactivateDialog();
1513       SALOME_Selection *Sel = SALOME_Selection::Selection(
1514         myActiveStudy->getSelection() );
1515
1516       int aMode;
1517       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1518       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1519       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1520
1521       ( new SMESHGUI_GroupOpDlg( parent, Sel, aMode ) )->show();
1522       break;
1523     }
1524
1525     case 813: // Delete groups with their contents
1526     {
1527       if ( checkLock( aStudy ) )
1528         break;
1529
1530       EmitSignalDeactivateDialog();
1531       SALOME_Selection *Sel = SALOME_Selection::Selection(
1532         myActiveStudy->getSelection() );
1533
1534       ( new SMESHGUI_DeleteGroupDlg( parent, Sel ) )->show();
1535       break;
1536     }
1537
1538   case 900:                                     // MESH INFOS
1539     {
1540       EmitSignalDeactivateDialog();
1541       SALOME_Selection *Sel =
1542         SALOME_Selection::Selection(myActiveStudy->getSelection());
1543       if ( Sel->IObjectCount() > 1 ) { // a dlg for each IO
1544         SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1545         SALOME_ListIteratorOfListIO It (IOs);
1546         for ( ; It.More(); It.Next() ) {
1547           Sel->ClearIObjects();
1548           Sel->AddIObject( It.Value() );
1549           new SMESHGUI_MeshInfosDlg(parent, "", false);
1550         }
1551         // restore selection
1552         Sel->ClearIObjects();
1553         for (It.Initialize( IOs ) ; It.More(); It.Next() )
1554           Sel->AddIObject( It.Value() );
1555       }
1556       else
1557         new SMESHGUI_MeshInfosDlg(parent, "", false);
1558       break;
1559     }
1560
1561   case 902:                                     // STANDARD MESH INFOS
1562     {
1563       EmitSignalDeactivateDialog();
1564       SALOME_Selection *Sel =
1565         SALOME_Selection::Selection(myActiveStudy->getSelection());
1566       if ( Sel->IObjectCount() > 1 ) { // a dlg for each IO
1567         SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1568         SALOME_ListIteratorOfListIO It (IOs);
1569         for ( ; It.More(); It.Next() ) {
1570           Sel->ClearIObjects();
1571           Sel->AddIObject( It.Value() );
1572           new SMESHGUI_StandardMeshInfosDlg(parent, "", false);
1573         }
1574         // restore selection
1575         Sel->ClearIObjects();
1576         for (It.Initialize( IOs ) ; It.More(); It.Next() )
1577           Sel->AddIObject( It.Value() );
1578       }
1579       else
1580         new SMESHGUI_StandardMeshInfosDlg(parent, "", false);
1581       break;
1582     } 
1583     
1584   case 1001:                                    // AUTOMATIC UPDATE PREFERENCES
1585     {
1586       parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
1587       if (parent->menuBar()->isItemChecked(1001)) {
1588         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
1589         myAutomaticUpdate = true;
1590       }
1591       else {
1592         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
1593         myAutomaticUpdate = false;
1594       }
1595       break;
1596     }
1597
1598   case 1003:                                    // MESH PREFERENCES
1599     {
1600       ::SetDisplaySettings();
1601       break;
1602     }
1603
1604   case 1005:
1605     {
1606       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
1607       break;
1608     }
1609
1610   case 1007:
1611     {
1612       ( new SMESHGUI_PrecisionDlg( parent ) )->exec();
1613       break;
1614     }
1615
1616   case 1006: 
1617     {
1618       SMESHGUI_Preferences_SelectionDlg* aDlg = 
1619         new SMESHGUI_Preferences_SelectionDlg(parent);
1620
1621       QColor aColor;
1622       QString SCr, SCg, SCb;
1623       SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
1624       SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
1625       SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
1626       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1627         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1628       else aColor = Qt::cyan;
1629       aDlg->SetColor(1, aColor);
1630
1631       SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
1632       SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
1633       SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
1634       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1635         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1636       else aColor = Qt::yellow;
1637       aDlg->SetColor(2, aColor);
1638
1639       SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
1640       SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
1641       SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
1642       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1643         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1644       else aColor = Qt::white;
1645       aDlg->SetColor(3, aColor);
1646
1647       QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
1648       if (SW1.isEmpty()) SW1 = "5";
1649       aDlg->SetWidth(1, SW1.toInt());
1650
1651       QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
1652       if (SW2.isEmpty()) SW2 = "5";
1653       aDlg->SetWidth(2, SW2.toInt());
1654
1655       QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
1656       if (SP1.isEmpty()) SP1 = "0.025";
1657       aDlg->SetPrecision(1, SP1.toDouble());
1658
1659       QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
1660       if (SP2.isEmpty()) SP2 = "0.001";
1661       aDlg->SetPrecision(2, SP2.toDouble());
1662
1663       if (aDlg->exec()) {
1664         QColor aPreColor = aDlg->GetColor(1);
1665         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
1666         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
1667         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
1668
1669         QColor aSelColor = aDlg->GetColor(2);
1670         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
1671         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
1672         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
1673
1674         QColor aHiColor = aDlg->GetColor(3);
1675         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
1676         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
1677         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
1678
1679         int aPreWidth = aDlg->GetWidth(1);
1680         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
1681         int aSelWidth = aDlg->GetWidth(2);
1682         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
1683
1684         double aTolNodes = aDlg->GetPrecision(1);
1685         QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
1686         double aTolItems = aDlg->GetPrecision(2);
1687         QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
1688
1689         // update current study settings
1690         SMESH::UpdateSelectionProp();
1691
1692         QAD_StudyFrame* studyFrame = myActiveStudy->getActiveStudyFrame();
1693         if (studyFrame->getTypeView() == VIEW_VTK) {
1694           VTKViewer_ViewFrame* aViewFrame = SMESH::GetVtkViewFrame(studyFrame);
1695           // update VTK viewer properties
1696           VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
1697           if (anInteractor) {
1698             anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
1699                                            aSelColor.blue()/255., aSelWidth);
1700             anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
1701             VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
1702             if (aStyle)
1703               aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
1704                                           aPreColor.blue()/255., aPreWidth);
1705           }
1706           // update actors
1707           vtkRenderer* aRenderer = aViewFrame->getRenderer();
1708           vtkActorCollection *aCollection = aRenderer->GetActors();
1709           aCollection->InitTraversal();
1710           while(vtkActor *anAct = aCollection->GetNextActor()){
1711             if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1712               anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
1713                                          aHiColor.blue()/255.);
1714               anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
1715                                             aPreColor.blue()/255.);
1716             }
1717           }
1718         }
1719       }
1720
1721       break;
1722     }
1723
1724   case 1100:                                    // EDIT HYPOTHESIS
1725     {
1726       if(checkLock(aStudy)) break;
1727       SALOME_Selection *Sel =
1728         SALOME_Selection::Selection(myActiveStudy->getSelection());
1729       int nbSel = Sel->IObjectCount();
1730
1731       if (nbSel == 1) {
1732         SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(Sel->firstIObject());
1733
1734         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1735         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1736         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1737         if ( !Hyp->_is_nil() )
1738         {
1739           char* sName = Hyp->GetName();
1740           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
1741           if (aCreator)
1742           {
1743             aCreator->EditHypothesis(Hyp);
1744           }
1745           else
1746           {
1747             // report error
1748           }
1749         }
1750       }
1751       break;
1752     }
1753
1754   case 1101:                                    // RENAME
1755     {
1756       if ( checkLock( aStudy ) )
1757         break;
1758         
1759       SALOME_Selection *Sel =
1760         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1761         
1762       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1763       for ( ; It.More(); It.Next() )
1764       {
1765         Handle(SALOME_InteractiveObject) IObject = It.Value();
1766         SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
1767         SALOMEDS::GenericAttribute_var anAttr;
1768         SALOMEDS::AttributeName_var aName;
1769         if ( !obj->_is_nil() )
1770         {
1771           if ( obj->FindAttribute(anAttr, "AttributeName") )
1772           {
1773             aName = SALOMEDS::AttributeName::_narrow( anAttr );
1774             QString newName = QString(aName->Value());
1775             newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName );
1776             if ( !newName.isEmpty() )
1777             {
1778               myActiveStudy->renameIObject( IObject, newName );
1779
1780               // if current object is group update group's name
1781               SMESH::SMESH_GroupBase_var aGroup =
1782                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1783               if (!aGroup->_is_nil() )
1784                 aGroup->SetName( newName.latin1() );
1785             }
1786           }
1787         }
1788       }
1789       break;
1790     }
1791     
1792   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1793     {
1794       if(checkLock(aStudy)) break;
1795       QAD_WaitCursor wc;
1796       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1797       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1798       for (int i = 0; It.More(); It.Next(), i++) {
1799         Handle(SALOME_InteractiveObject) IObject = It.Value();
1800         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1801       }
1802       Sel->ClearIObjects();
1803       myActiveStudy->updateObjBrowser(true);
1804       break;
1805     }
1806
1807   case 401:                                     // GEOM::EDGE
1808   case 4021:                                    // TRIANGLE
1809   case 4022:                                    // QUAD
1810   case 4031:                                    // TETRA
1811   case 4032:                                    // HEXA
1812     {
1813       if(checkLock(aStudy)) break;
1814       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1815         EmitSignalDeactivateDialog();
1816         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1817         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1818         int                 nbNodes = 2;
1819         switch (theCommandID) {
1820         case 4021:                                      // TRIANGLE
1821           type = SMDSAbs_Face; nbNodes = 3; break;
1822         case 4022:                                      // QUAD
1823           type = SMDSAbs_Face; nbNodes = 4; break;
1824         case 4031:                                      // TETRA
1825           type = SMDSAbs_Volume; nbNodes = 4; break;
1826         case 4032:                                      // HEXA
1827           type = SMDSAbs_Volume; nbNodes = 8; break;
1828         default:;
1829         }
1830         new SMESHGUI_AddMeshElementDlg(parent, "", Sel, type, nbNodes);
1831       }
1832       else {
1833         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1834                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1835                               tr("SMESH_BUT_OK"));
1836       }
1837       break;
1838     }
1839
1840   case 4041:                                    // REMOVES NODES
1841     {
1842       if(checkLock(aStudy)) break;
1843       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1844         EmitSignalDeactivateDialog();
1845         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1846         new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
1847       }
1848       else {
1849         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1850                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1851                               tr("SMESH_BUT_OK"));
1852       }
1853       break;
1854     }
1855   case 4042:                                    // REMOVES ELEMENTS
1856     {
1857       if(checkLock(aStudy)) break;
1858       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1859         EmitSignalDeactivateDialog();
1860         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1861         new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
1862       }
1863       else
1864         {
1865           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1866                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1867                                 tr("SMESH_BUT_OK"));
1868         }
1869       break;
1870     }
1871   case 4051:                                    // RENUMBERING NODES
1872     {
1873       if(checkLock(aStudy)) break;
1874       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1875         EmitSignalDeactivateDialog();
1876         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1877         new SMESHGUI_RenumberingDlg(parent, "", Sel, 0);
1878       }
1879       else
1880         {
1881           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1882                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1883                                 tr("SMESH_BUT_OK"));
1884         }
1885       break;
1886     }
1887   case 4052:                                    // RENUMBERING ELEMENTS
1888     {
1889       if(checkLock(aStudy)) break;
1890       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1891         EmitSignalDeactivateDialog();
1892         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1893         new SMESHGUI_RenumberingDlg(parent, "", Sel, 1);
1894       }
1895       else
1896         {
1897           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1898                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1899                                 tr("SMESH_BUT_OK"));
1900         }
1901       break;
1902     }
1903   case 4061:                                   // TRANSLATION
1904     {
1905       if(checkLock(aStudy)) break;
1906       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1907         EmitSignalDeactivateDialog();
1908         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1909         new SMESHGUI_TranslationDlg(parent, "", Sel);
1910       }
1911       else {
1912         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1913                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1914                               tr("SMESH_BUT_OK"));
1915       }
1916       break;
1917     }
1918   case 4062:                                   // ROTATION
1919     {
1920       if(checkLock(aStudy)) break;
1921       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1922         EmitSignalDeactivateDialog();
1923         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1924         new SMESHGUI_RotationDlg(parent, "", Sel);
1925       }
1926       else {
1927         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1928                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1929                               tr("SMESH_BUT_OK"));
1930       }
1931       break;
1932     }
1933   case 4063:                                   // SYMMETRY 
1934     {
1935       if(checkLock(aStudy)) break;
1936       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1937         EmitSignalDeactivateDialog();
1938         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1939         new SMESHGUI_SymmetryDlg(parent, "", Sel);
1940       }
1941       else {
1942         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1943                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1944                               tr("SMESH_BUT_OK"));
1945       }
1946       break;
1947     }
1948   case 4064:                                   // SEWING
1949     {
1950       if(checkLock(aStudy)) break;
1951       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1952         EmitSignalDeactivateDialog();
1953         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1954         new SMESHGUI_SewingDlg(parent, "", Sel);
1955       }
1956       else {
1957         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1958                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1959                               tr("SMESH_BUT_OK"));
1960       }
1961       break;
1962     }
1963   case 4065:                                   // MERGE NODES
1964     {
1965       if(checkLock(aStudy)) break;
1966       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1967         EmitSignalDeactivateDialog();
1968         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1969         new SMESHGUI_MergeNodesDlg(parent, "", Sel);
1970       }
1971       else {
1972         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1973                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1974                               tr("SMESH_BUT_OK"));
1975       }
1976       break;
1977     }
1978     
1979
1980   case 5000: // HYPOTHESIS
1981     {
1982       if(checkLock(aStudy)) break;
1983       EmitSignalDeactivateDialog();
1984       new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
1985       break;
1986     }
1987   case 5010: // ALGO
1988     {
1989       if(checkLock(aStudy)) break;
1990       EmitSignalDeactivateDialog();
1991       new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
1992       break;
1993     }
1994
1995   case 5105: // Library of selection filters
1996   {
1997     static QValueList<int> aTypes;
1998     if ( aTypes.isEmpty() )
1999     {
2000       aTypes.append( SMESH::NODE );
2001       aTypes.append( SMESH::EDGE );
2002       aTypes.append( SMESH::FACE );
2003       aTypes.append( SMESH::VOLUME );
2004     }
2005     new SMESHGUI_FilterLibraryDlg( parent, aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2006   }
2007   break;
2008
2009   case 6017:                                    // CONTROLS 
2010   case 6016:
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(aNbVolumes == 0 && aNbFaces == 0 && aNbEdges == 0){
2336                 mi->popup()->removeItem( 211 );
2337               }else{
2338                 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
2339               }
2340               // Display Mode / Shading
2341               if(aNbFaces == 0 && aNbVolumes == 0){
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::eAspectRatio3D:
2378                 mi->popup()->setItemChecked( 6017, true ); break;
2379               case SMESH_Actor::eMinimumAngle:
2380                 mi->popup()->setItemChecked( 6014, true ); break;
2381               case SMESH_Actor::eWarping:
2382                 mi->popup()->setItemChecked( 6015, true ); break;
2383               case SMESH_Actor::eSkew:
2384                 mi->popup()->setItemChecked( 6016, true ); break;
2385               case SMESH_Actor::eNone:
2386               default:
2387                 mi->popup()->removeItem( 200 );
2388                 mi->popup()->removeItem( 201 );
2389                 break;
2390               }
2391               TVisualObjPtr aVisualObj = ac->GetObject();
2392               if(aNbEdges == 0){
2393                 mi->popup()->removeItem( 6001 );
2394                 mi->popup()->removeItem( 6003 );
2395                 mi->popup()->removeItem( 6004 );
2396               }
2397               if(aNbFaces == 0){
2398                 mi->popup()->removeItem( 6002 );
2399                 mi->popup()->removeItem( 6011 );
2400                 mi->popup()->removeItem( 6012 );
2401                 mi->popup()->removeItem( 6013 );
2402                 mi->popup()->removeItem( 6014 );
2403                 mi->popup()->removeItem( 6015 );
2404                 mi->popup()->removeItem( 6016 );
2405               }
2406               if(aNbVolumes == 0){
2407                 mi->popup()->removeItem( 6017 );
2408               }
2409               if(aNbFaces == 0 && aNbEdges == 0 && aNbVolumes == 0)
2410                 popup->removeItem( 2000 );                         // Scalar Bar
2411             }
2412           }
2413           else {
2414             popup->removeItem( QAD_Erase_Popup_ID );
2415             popup->removeItem( 114 );                              // Numbering popup menu
2416             popup->removeItem( 1131 );                             // Display mode
2417             popup->removeItem( 1132 );                             // Color / size
2418             popup->removeItem( 1133 );                             // Transparency
2419             popup->removeItem( 1134 );                             // Clipping
2420             popup->removeItem( 2000 );                             // Scalar Bar
2421           }
2422         }
2423         else {
2424           // object doesn't have actor
2425           CORBA::Object_var anObject = SO->GetObject();
2426           bool bDisplay = false;
2427           if ( !CORBA::is_nil( anObject ) ) {
2428             SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
2429             if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0  || aMeshObj->NbVolumes() > 0 ) )
2430               bDisplay = true;
2431             SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
2432             if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes(false) > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
2433               bDisplay = true;
2434             SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( anObject );
2435             if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
2436               bDisplay = true;
2437           }
2438           if ( !bDisplay ) {
2439             popup->removeItem( QAD_Display_Popup_ID );
2440             popup->removeItem( QAD_DisplayOnly_Popup_ID );
2441           }
2442           popup->removeItem( QAD_Erase_Popup_ID );
2443           popup->removeItem( 114 );                              // Numbering popup menu
2444           popup->removeItem( 1131 );                             // Display mode
2445           popup->removeItem( 1132 );                             // Color / size
2446           popup->removeItem( 1133 );                             // Transparency
2447           popup->removeItem( 1134 );                             // Clipping
2448           popup->removeItem( 2000 );                             // Scalar Bar
2449         }
2450       }
2451       else if( theObject!="Component" ) {
2452         // another SMESH object
2453         popup->removeItem( QAD_Display_Popup_ID );
2454         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2455         popup->removeItem( QAD_Erase_Popup_ID );
2456       }
2457     }
2458   }
2459   else {
2460     // multiple selection
2461     if ( parentComp != parent->getActiveComponent() ) {
2462       // object not belongs to SMESH module - remove all commands except common Display/Erase...
2463       while ( 1 )       {
2464         int id = popup->idAt( 0 );
2465         if ( id <= QAD_TopLabel_Popup_ID )
2466           popup->removeItemAt( 0 );
2467         else
2468           break;
2469       }
2470       if ( parentComp.isNull() ) {
2471         // objects from different components are selected
2472         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2473         popup->removeItem( QAD_Display_Popup_ID );
2474         popup->removeItem( QAD_Erase_Popup_ID );
2475       }
2476     }
2477     else {
2478       QString type = ::CheckHomogeneousSelection();
2479       if ( type != "Heterogeneous Selection" ) {
2480         int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
2481         if ( topItem >= 0 ) {
2482           // set bold font for popup menu's TopLabel item
2483           QFont fnt = popup->font(); fnt.setBold( TRUE );
2484           popup->removeItem( QAD_TopLabel_Popup_ID );
2485           popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
2486         }
2487       }
2488     }
2489   }
2490   return false;
2491 }
2492
2493 //=============================================================================
2494 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2495  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2496  */
2497 //=============================================================================
2498 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2499                                   QAD_ViewFrame* )
2500 {
2501   if(theIO->hasEntry()){
2502     QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
2503     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
2504     SMESH::UpdateView(aStudyFrame,SMESH::eDisplay,theIO->getEntry());
2505   }
2506 }
2507
2508 void SMESHGUI::SupportedViewType(int *buffer, int bufferSize)
2509 {
2510   if (!buffer || !bufferSize)
2511     return;
2512   buffer[0] = (int)VIEW_VTK;
2513 }
2514
2515 void SMESHGUI::Deactivate()
2516 {
2517   if ( SMESHGUI::GetSMESHGUI() ) {
2518     SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
2519   }
2520 }