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