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