Salome HOME
453dda9b951df97f8787f4a586571ddf1b64c7f1
[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::eLength;
549             break;
550           case 6018:
551             aTitle = QObject::tr( "LENGTH2D_EDGES" );
552             aControl = SMESH_Actor::eLength2D;
553             break;
554           case 6002:
555             aTitle = QObject::tr( "FREE_EDGES" );
556             aControl = SMESH_Actor::eFreeEdges;
557             break;
558           case 6003:
559             aTitle = QObject::tr( "FREE_BORDERS" );
560             aControl = SMESH_Actor::eFreeBorders;
561             break;
562           case 6004:
563             aTitle = QObject::tr( "MULTI_BORDERS" );
564             aControl = SMESH_Actor::eMultiConnection;
565             break;
566           case 6011:
567             aTitle = QObject::tr( "AREA_ELEMENTS" );
568             aControl = SMESH_Actor::eArea;
569             break;
570           case 6012:
571             aTitle = QObject::tr( "TAPER_ELEMENTS" );
572             aControl = SMESH_Actor::eTaper;
573             break;
574           case 6013:
575             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
576             aControl = SMESH_Actor::eAspectRatio;
577             break;
578           case 6017:
579             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
580             aControl = SMESH_Actor::eAspectRatio3D;
581             break;
582           case 6014:
583             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
584             aControl = SMESH_Actor::eMinimumAngle;
585             break;
586           case 6015:
587             aTitle = QObject::tr( "WARP_ELEMENTS" );
588             aControl = SMESH_Actor::eWarping;
589             break;
590           case 6016:
591             aTitle = QObject::tr( "SKEW_ELEMENTS" );
592             aControl = SMESH_Actor::eSkew;
593             break;
594           }
595           anActor->SetControlMode(aControl);
596           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
597         }
598       }
599     }
600   }
601   
602
603   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
604                    MeshObjectType                           theType,
605                    const QString                            theInTypeName,
606                    QString &                                theOutTypeName)
607   {
608     SMESH_TypeFilter aTypeFilter( theType );
609     if ( aTypeFilter.IsOk( theIO )) {
610       theOutTypeName = theInTypeName;
611       return true;
612     }
613     return false;
614   }
615     
616
617   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
618   {
619     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
620     SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theIO->getEntry());
621     if (!aSObj->_is_nil()) {
622       SALOMEDS::SComponent_var aSComp = aSObj->GetFatherComponent();
623       CORBA::String_var anID = aSComp->GetID();
624       if (!strcmp(anID.in(),theIO->getEntry()))
625         return "Component";
626     }
627     
628     QString aTypeName;
629     if (
630         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
631         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
632         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
633         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
634         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
635         )
636       return aTypeName;
637     
638     return "NoType";
639   }
640
641
642   QString CheckHomogeneousSelection()
643   {
644     QAD_Study* aStudy = SMESH::GetActiveStudy();
645     SALOME_Selection *aSel = SALOME_Selection::Selection(aStudy->getSelection());
646     /* copy the list */
647     SALOME_ListIO List;
648     SALOME_ListIteratorOfListIO Itinit(aSel->StoredIObjects());
649     for (; Itinit.More(); Itinit.Next())
650       {
651         List.Append(Itinit.Value());
652       }
653
654     QString RefType = CheckTypeObject(aSel->firstIObject());
655     SALOME_ListIteratorOfListIO It(List);
656     for (; It.More(); It.Next())
657       {
658         Handle(SALOME_InteractiveObject) IObject = It.Value();
659         QString Type = CheckTypeObject(IObject);
660         if (Type.compare(RefType) != 0)
661           return "Heterogeneous Selection";
662       }
663     
664     aSel->ClearIObjects();
665     SALOME_ListIteratorOfListIO It1(List);
666     for (; It1.More(); It1.Next())
667       {
668         int res = aSel->AddIObject(It1.Value());
669         if (res == -1)
670           aStudy->highlight(It1.Value(), false);
671         if (res == 0)
672           aStudy->highlight(It1.Value(), true);
673       }
674     return RefType;
675   }
676
677   void OnEditDelete()
678   {
679     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
680     QString aParentComponent = ((SALOMEGUI_Desktop*)QAD_Application::getDesktop())->getComponentFromSelection();
681     if ( aParentComponent != QAD_Application::getDesktop()->getActiveComponent() )  {
682       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(),
683                               QObject::tr("ERR_ERROR"), 
684                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg(QAD_Application::getDesktop()->getComponentUserName( "SMESH" )),
685                               QObject::tr("BUT_OK") );
686       return;
687     }
688     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
689     if (QAD_MessageBox::warn2
690         (QAD_Application::getDesktop(),
691          QObject::tr("SMESH_WRN_WARNING"),
692          QObject::tr("SMESH_REALLY_DELETE"),
693          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
694       return;
695
696     QAD_Study* anActiveStudy = SMESH::GetActiveStudy();
697     int nbSf = anActiveStudy->getStudyFramesCount();
698     
699     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
700     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
701     SALOMEDS::GenericAttribute_var anAttr;
702     SALOMEDS::AttributeIOR_var anIOR;
703     
704     SALOME_Selection *Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
705     SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
706     for(; It.More(); It.Next()){
707       Handle(SALOME_InteractiveObject) IObject = It.Value();
708       if(IObject->hasEntry()){
709         SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
710         
711         /* Erase child graphical objects */
712         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
713         for(; it->More(); it->Next()){
714           SALOMEDS::SObject_var CSO = it->Value();
715           if(CSO->FindAttribute(anAttr, "AttributeIOR")){
716             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
717             
718             for(int i = 0; i < nbSf; i++){
719               QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
720               CORBA::String_var anEntry = CSO->GetID();
721               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
722                 SMESH::RemoveActor(sf,anActor);
723               }
724             }
725           }
726         }
727         
728         /* Erase main graphical object */
729         for(int i = 0; i < nbSf; i++){
730           QAD_StudyFrame *sf = anActiveStudy->getStudyFrame(i);
731           if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
732             SMESH::RemoveActor(sf,anActor);
733           }
734         }
735         
736         // Remove object(s) from data structures
737         SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
738         if(!obj->_is_nil()){
739           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(obj->GetObject());
740           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
741           
742           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
743             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
744             aMesh->RemoveGroup( aGroup );
745           }
746           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
747             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
748             aMesh->RemoveSubMesh( aSubMesh );
749           }
750           else {// default action: remove SObject from the study
751             // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
752             //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
753             //op->start();
754             aStudyBuilder->RemoveObjectWithChildren( obj );
755             //op->finish();
756           }
757         }
758         
759       } /* IObject->hasEntry() */
760     } /* more/next */
761     
762     /* Clear any previous selection */
763     Sel->ClearIObjects();
764     anActiveStudy->updateObjBrowser();
765   }
766
767
768 }
769
770 //=============================================================================
771 /*!
772  *
773  */
774 //=============================================================================
775 class CustomItem : public QCustomMenuItem
776 {
777 public:
778   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
779   ~CustomItem() {}
780
781   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
782   {
783     p->save();
784     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
785     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
786     p->setFont( myFont );
787     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
788     p->restore();
789   }
790
791   QSize sizeHint()
792   {
793     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
794   }
795
796   bool fullSpan() const
797   {
798     return true;
799   }
800
801 private:
802   QString myString;
803   QFont   myFont;
804 };
805
806 //=============================================================================
807 /*!
808  *
809  */
810 //=============================================================================
811 SMESHGUI::SMESHGUI( const QString& theName, QObject* theParent ) :
812   SALOMEGUI( theName, theParent )
813 {
814   myActiveDialogBox = 0 ;
815   myState = -1 ;
816
817   SMESH::GetSMESHGen();
818   SMESH::GetFilterManager();
819   SMESH::GetPattern();
820
821   /* load resources for all available meshers */
822   SMESH::InitAvailableHypotheses();
823 }
824
825 //=============================================================================
826 /*!
827  *
828  */
829 //=============================================================================
830 SMESHGUI::~SMESHGUI()
831 {
832   SMESH::GetFilterManager()->Destroy();
833 }
834
835 //=============================================================================
836 /*!
837  *
838  */
839 //=============================================================================
840 SMESHGUI* SMESHGUI::GetSMESHGUI()
841 {
842   static SMESHGUI aSMESHGUI;
843   aSMESHGUI.myActiveStudy = SMESH::GetActiveStudy();
844   SMESH::GetSMESHGen()->SetCurrentStudy( SMESH::GetActiveStudyDocument() );
845
846   /* Automatic Update flag */
847   aSMESHGUI.myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
848
849   return &aSMESHGUI;
850 }
851
852 extern "C"
853 {
854   Standard_EXPORT SALOMEGUI* GetComponentGUI() {
855     return SMESHGUI::GetSMESHGUI();
856   }
857 }
858
859 //=============================================================================
860 /*!
861  *
862  */
863 //=============================================================================
864 void SMESHGUI::SetState(int aState)
865 {
866   this->myState = aState;
867   return;
868 }
869
870 //=============================================================================
871 /*!
872  *
873  */
874 //=============================================================================
875 void SMESHGUI::ResetState()
876 {
877   this->myState = -1;
878   return;
879 }
880
881 //=============================================================================
882 /*!
883  *
884  */
885 //=============================================================================
886 void SMESHGUI::EmitSignalDeactivateDialog()
887 {
888   emit this->SignalDeactivateActiveDialog();
889   return;
890 }
891
892 //=============================================================================
893 /*!
894  *
895  */
896 //=============================================================================
897 void SMESHGUI::EmitSignalStudyFrameChanged()
898 {
899   emit this->SignalStudyFrameChanged();
900   return;
901 }
902
903 //=============================================================================
904 /*!
905  *
906  */
907 //=============================================================================
908 void SMESHGUI::EmitSignalCloseAllDialogs()
909 {
910   emit SignalCloseAllDialogs();
911   return;
912 }
913
914 //=============================================================================
915 /*!
916  *
917  */
918 //=============================================================================
919 QDialog *SMESHGUI::GetActiveDialogBox()
920 {
921   return this->myActiveDialogBox;
922 }
923
924 //=============================================================================
925 /*!
926  *
927  */
928 //=============================================================================
929 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
930 {
931   this->myActiveDialogBox = (QDialog *) aDlg;
932   return;
933 }
934
935 //=============================================================================
936 /*!
937  *
938  */
939 //=============================================================================
940 QAD_Study *SMESHGUI::GetActiveStudy()
941 {
942   return this->myActiveStudy;
943 }
944
945 //=============================================================================
946 /*!
947  *
948  */
949 //=============================================================================
950 QAD_Desktop *SMESHGUI::GetDesktop()
951 {
952   return QAD_Application::getDesktop();
953 }
954
955 //=============================================================================
956 /*!
957  *
958  */
959 //=============================================================================
960 bool SMESHGUI::ActiveStudyChanged(QAD_Desktop* parent)
961 {
962   MESSAGE("SMESHGUI::activeStudyChanged init.");
963   QAD_Study* prevStudy = myActiveStudy;
964   /* Create or retrieve an object SMESHGUI */
965   MESSAGE("Active study changed : prev study =" << prevStudy);
966   SMESHGUI::GetSMESHGUI();
967   EmitSignalStudyFrameChanged();
968   MESSAGE("Active study changed : active study =" << myActiveStudy);
969   if ( prevStudy != myActiveStudy ) {
970     EmitSignalCloseAllDialogs();
971     MESSAGE("Active study changed : SMESHGUI nullified" << endl);
972     //smeshGUI = 0;
973     SMESH::UpdateSelectionProp();
974   }
975   MESSAGE("SMESHGUI::activeStudyChanged done.");
976   return true;
977 }
978
979 //=============================================================================
980 /*!
981  *
982  */
983 //=============================================================================
984 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
985 {
986   /* Here the position is on the bottom right corner - 10 */
987   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
988   aDlg->adjustSize();
989   QAD_Desktop *PP = QAD_Application::getDesktop();
990   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
991   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
992   return true;
993 }
994
995 //=============================================================================
996 /*!
997  *
998  */
999 //=============================================================================
1000 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
1001   return theStudy->GetProperties()->IsLocked();
1002 }
1003
1004 static bool checkLock(const SALOMEDS::Study_var& theStudy) {
1005   if (isStudyLocked(theStudy)) {
1006     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
1007                            QObject::tr("WRN_WARNING"), 
1008                            QObject::tr("WRN_STUDY_LOCKED"),
1009                            QObject::tr("BUT_OK") );
1010     return true;
1011   }
1012   return false;
1013 }
1014
1015 //=======================================================================
1016 //function : CheckActiveStudyLocked
1017 //purpose  : 
1018 //=======================================================================
1019
1020 bool SMESHGUI::ActiveStudyLocked()
1021 {
1022   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1023   return checkLock( aStudy );
1024 }
1025
1026 //=============================================================================
1027 /*!
1028  *
1029  */
1030 //=============================================================================
1031 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
1032 {
1033   SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1034
1035   switch (theCommandID) {
1036   case 33:                                      // DELETE
1037     if(checkLock(aStudy)) break;
1038     ::OnEditDelete();
1039     break;
1040     
1041   case 113:                                     // IMPORT
1042   case 112:
1043   case 111:
1044     {
1045       if(checkLock(aStudy)) break;
1046       ::ImportMeshesFromFile(parent,SMESH::GetSMESHGen(),theCommandID);
1047       break;
1048     }
1049
1050   case 122:                                     // EXPORT MED
1051   case 121:
1052   case 123:
1053     {
1054       ::ExportMeshToFile(parent, theCommandID);
1055       break;
1056     }
1057
1058   case 200:                                     // SCALAR BAR
1059     {
1060       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1061       if( Sel && Sel->IObjectCount() ) {
1062         Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
1063         if( anIO->hasEntry() ) {
1064           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1065             anActor->SetControlMode( SMESH_Actor::eNone );
1066           }
1067         }
1068       }
1069       break;
1070     }
1071   case 201:
1072     {
1073       SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1074       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
1075       break;
1076     }
1077
1078   case 1134: // Clipping
1079   case 1133: // Tranparency
1080   case 1132: // Colors / Size
1081
1082     // Display Mode
1083   case 215: // Nodes
1084   case 213: // Nodes
1085   case 212: // Nodes
1086   case 211: // Nodes
1087     ::SetDisplayMode(theCommandID);
1088   break;
1089
1090     // Display Entity
1091   case 217: // Edges
1092   case 218: // Faces
1093   case 219: // Volumes
1094   case 220: // All Entity
1095     ::SetDisplayEntity(theCommandID);
1096   break;
1097
1098   case 214:                                     // UPDATE
1099     {
1100       if(checkLock(aStudy)) break;
1101       SMESH::UpdateView();
1102       break;
1103     }
1104
1105   case 300:                                     // ERASE
1106   case 301:                                     // DISPLAY
1107   case 302:                                     // DISPLAY ONLY
1108     {
1109       SMESH::EDisplaing anAction;
1110       switch(theCommandID){
1111       case 300: anAction = SMESH::eErase; break;
1112       case 301: anAction = SMESH::eDisplay; break;
1113       case 302: anAction = SMESH::eDisplayOnly; break;
1114       }
1115       
1116       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1117       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1118         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1119         for (; It.More(); It.Next()) {
1120           Handle(SALOME_InteractiveObject) IOS = It.Value();
1121           if (IOS->hasEntry()) {
1122             SMESH::UpdateView(anAction,IOS->getEntry());
1123           }
1124         }
1125       }
1126       Sel->ClearIObjects();
1127       break;
1128     }
1129
1130   case 400:                                     // NODES
1131     {
1132       if(checkLock(aStudy)) break;
1133       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1134         EmitSignalDeactivateDialog();
1135         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1136         new SMESHGUI_NodesDlg(parent, "", Sel);
1137       }
1138       else {
1139         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1140                               tr("SMESH_WRN_WARNING"), 
1141                               tr("SMESH_WRN_VIEWER_VTK"),
1142                               tr("SMESH_BUT_OK"));
1143       }
1144       break;
1145     }
1146
1147   case 2151:  // FILTER
1148   {
1149     if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1150     {
1151       EmitSignalDeactivateDialog();
1152       new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
1153     }
1154     break;
1155   }
1156     
1157   case 406:                                     // MOVE NODE
1158     {
1159       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1160       {
1161         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1162           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1163         break;
1164       }
1165       
1166       if(checkLock(aStudy)) break;
1167       SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1168       new SMESHGUI_MoveNodesDlg( parent, Sel );
1169       break;
1170     }
1171     
1172   case 701:                                     // COMPUTE MESH 
1173     {
1174       if(checkLock(aStudy)) break;
1175       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1176         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1177         int nbSel = Sel->IObjectCount();
1178         if (nbSel != 1){
1179           break;
1180         }
1181
1182         SMESH::SMESH_Mesh_var aMesh;
1183         SMESH::SMESH_subMesh_var aSubMesh;
1184         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1185         if (IObject->hasEntry()){
1186           SALOMEDS::SObject_var aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
1187           GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
1188           if ( aShapeObject->_is_nil() ) {
1189             // imported mesh
1190             break;
1191           }
1192           if(!aMeshSObj->_is_nil()) {
1193             SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
1194             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
1195             
1196             if (!aMesh->_is_nil()){
1197               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1198               if (!refShapeObject->_is_nil()) {
1199                 if(!SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject)){
1200                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1201                                         tr("SMESH_WRN_WARNING"),
1202                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1203                                         tr("SMESH_BUT_OK"));
1204                   break;
1205                 }
1206                 try{
1207                   if (SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject))
1208                     SMESH::ModifiedMesh(aMeshSObj,true);
1209                   // TO Do : change icon of all submeshes
1210                   else
1211                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1212                                           tr("SMESH_WRN_WARNING"),
1213                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1214                                           tr("SMESH_BUT_OK"));
1215                 }
1216                 catch(const SALOME::SALOME_Exception & S_ex){
1217                   QtCatchCorbaException(S_ex);
1218                 }
1219               }
1220             }else if(!aSubMesh->_is_nil()){
1221               aMesh = aSubMesh->GetFather();
1222               GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
1223               if(!refShapeObject->_is_nil()){
1224                 bool compute = SMESH::GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject);
1225                 if(!compute){
1226                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1227                                         tr("SMESH_WRN_WARNING"),
1228                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
1229                                         tr("SMESH_BUT_OK"));
1230                   break;
1231                 }
1232                 try{
1233                   if ( SMESH::GetSMESHGen()->Compute(aMesh,refShapeObject) )
1234                     SMESH::ModifiedMesh(aMeshSObj,true);
1235                   // TO Do : change icon of all submeshes
1236                   else
1237                     QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
1238                                           tr("SMESH_WRN_WARNING"),
1239                                           tr("SMESH_WRN_COMPUTE_FAILED"),
1240                                           tr("SMESH_BUT_OK"));
1241                 }catch(const SALOME::SALOME_Exception & S_ex){
1242                   QtCatchCorbaException(S_ex);
1243                 }
1244               }
1245             }
1246           }
1247         }
1248         CORBA::Long anId = aStudy->StudyId();
1249         TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,IObject->getEntry());
1250         if(myAutomaticUpdate && aVisualObj){
1251           aVisualObj->Update();
1252           SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
1253           if(!anActor){
1254             anActor = SMESH::CreateActor(aStudy,IObject->getEntry());
1255             if(anActor){
1256               SMESH::DisplayActor(myActiveStudy->getActiveStudyFrame(),anActor); //apo
1257               SMESH::FitAll();
1258             }
1259           }
1260         }
1261       }else{
1262         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1263                               tr("SMESH_WRN_WARNING"), 
1264                               tr("SMESH_WRN_VIEWER_VTK"),
1265                               tr("SMESH_BUT_OK"));
1266       }
1267       break;
1268     }
1269
1270   case 702:                                     // ADD SUB MESH 
1271     {
1272       if(checkLock(aStudy)) break;
1273       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1274         EmitSignalDeactivateDialog();
1275         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1276         new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
1277       }
1278       else {
1279         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1280                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1281                               tr("SMESH_BUT_OK"));
1282       }
1283       break;
1284     }
1285     
1286   case 703:                                     // INIT MESH 
1287     {
1288       if(checkLock(aStudy)) break;
1289       EmitSignalDeactivateDialog();
1290       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1291       new SMESHGUI_InitMeshDlg(parent, "", Sel);
1292       break;
1293     }
1294
1295   case 704:                                     // EDIT Hypothesis 
1296     {
1297       if(checkLock(aStudy)) break;
1298       EmitSignalDeactivateDialog();
1299       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1300       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1301       break;
1302     }
1303
1304   case 705:                                     //  EDIT Global Hypothesis
1305     {
1306       if(checkLock(aStudy)) break;
1307       EmitSignalDeactivateDialog();
1308       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1309       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1310       break;
1311     }
1312
1313   case 706:                                     //  EDIT Local Hypothesis
1314     {
1315       if(checkLock(aStudy)) break;
1316       EmitSignalDeactivateDialog();
1317       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1318       new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
1319       break;
1320     }
1321
1322   case 407: // DIAGONAL INVERSION
1323   case 408: // Delete diagonal
1324     {
1325       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1326       {
1327         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1328           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1329         break;
1330       }
1331
1332       if ( checkLock( aStudy ) )
1333         break;
1334         
1335       SALOME_Selection *aSel =
1336         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1337       /*Standard_Boolean aRes;
1338       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1339       if ( aMesh->_is_nil() )
1340       {
1341         QAD_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1342           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1343         break;
1344       }
1345       */
1346       EmitSignalDeactivateDialog();
1347       if ( theCommandID == 407 )
1348         new SMESHGUI_TrianglesInversionDlg( parent, aSel );
1349       else
1350         new SMESHGUI_UnionOfTwoTrianglesDlg( parent, aSel );
1351       break;
1352     }
1353     case 409: // Change orientation
1354     case 410: // Union of triangles
1355     case 411: // Cutting of quadrangles
1356     {
1357       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
1358       {
1359         QAD_MessageBox::warn1( GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1360           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1361         break;
1362       }
1363
1364       if ( checkLock( aStudy ) )
1365         break;
1366
1367       SALOME_Selection *aSel =
1368         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1369
1370       EmitSignalDeactivateDialog();
1371       SMESHGUI_MultiEditDlg* aDlg;
1372       if ( theCommandID == 409 )
1373         aDlg = new SMESHGUI_ChangeOrientationDlg( parent, aSel );
1374       else if ( theCommandID == 410 )
1375         aDlg = new SMESHGUI_UnionOfTrianglesDlg( parent, aSel );
1376       else
1377         aDlg = new SMESHGUI_CuttingOfQuadsDlg( parent, aSel );
1378
1379       int x, y ;
1380       DefineDlgPosition( aDlg, x, y );
1381       aDlg->move( x, y );
1382       aDlg->show();
1383       break;
1384     }
1385   case 412: // Smoothing
1386     {
1387       if(checkLock(aStudy)) break;
1388       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1389         EmitSignalDeactivateDialog();
1390         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1391         new SMESHGUI_SmoothingDlg(parent, "", Sel);
1392       }
1393       else {
1394         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1395                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1396                               tr("SMESH_BUT_OK"));
1397       }
1398       break;
1399     }
1400   case 413: // Extrusion
1401     {
1402       if(checkLock(aStudy)) break;
1403       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1404         EmitSignalDeactivateDialog();
1405         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1406         new SMESHGUI_ExtrusionDlg(parent, "", Sel);
1407       }
1408       else {
1409         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1410                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1411                               tr("SMESH_BUT_OK"));
1412       }
1413       break;
1414     }
1415   case 414: // Revolution
1416     {
1417       if(checkLock(aStudy)) break;
1418       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1419         EmitSignalDeactivateDialog();
1420         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1421         new SMESHGUI_RevolutionDlg(parent, "", Sel);
1422       }
1423       else {
1424         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1425                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1426                               tr("SMESH_BUT_OK"));
1427       }
1428       break;
1429     }
1430   case 415: // Pattern mapping
1431     {
1432       if ( checkLock( aStudy ) )
1433         break;
1434       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
1435       {
1436         EmitSignalDeactivateDialog();
1437         SALOME_Selection *Sel = SALOME_Selection::Selection(
1438           myActiveStudy->getSelection() );
1439         new SMESHGUI_MeshPatternDlg( parent, Sel );
1440       }
1441       else {
1442         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1443                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1444                               tr("SMESH_BUT_OK"));
1445       }
1446       break;
1447     }
1448   case 801:                                     // CREATE GROUP
1449     {
1450       if(checkLock(aStudy)) break;
1451       EmitSignalDeactivateDialog();
1452       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1453       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1454       int nbSel = Sel->IObjectCount();
1455       if (nbSel == 1) {
1456         // check if mesh is selected
1457         aMesh = SMESH::GetMeshByIO(Sel->firstIObject());
1458       }
1459       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
1460       aDlg->show();
1461       break;
1462     }
1463
1464   case 802:                                     // CONSTRUCT GROUP
1465     {
1466       if(checkLock(aStudy)) break;
1467       EmitSignalDeactivateDialog();
1468       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1469       int nbSel = Sel->IObjectCount();
1470       if (nbSel == 1) {
1471         // check if submesh is selected
1472         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1473         if (IObject->hasEntry()) {
1474           SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(IObject->getEntry());
1475           if(!aSObj->_is_nil()) {
1476             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
1477             if (!aSubMesh->_is_nil()) {
1478               try {
1479                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1480                 // get submesh elements list by types
1481                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1482                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1483                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1484                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1485                 // create group for each type o elements
1486                 QString aName = IObject->getName();
1487                 if (aNodes->length() > 0) {
1488                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName);
1489                   aGroup->Add(aNodes.inout());
1490                 }
1491                 if (aEdges->length() > 0) {
1492                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName);
1493                   aGroup->Add(aEdges.inout());
1494                 }
1495                 if (aFaces->length() > 0) {
1496                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName);
1497                   aGroup->Add(aFaces.inout());
1498                 }
1499                 if (aVolumes->length() > 0) {
1500                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName);
1501                   aGroup->Add(aVolumes.inout());
1502                 }
1503                 myActiveStudy->updateObjBrowser(true);
1504               }catch(const SALOME::SALOME_Exception & S_ex){
1505                 QtCatchCorbaException(S_ex);
1506               }
1507             }
1508           }
1509         }
1510       }
1511       break;
1512     }
1513
1514   case 803:                                     // EDIT GROUP
1515     {
1516       if(checkLock(aStudy)) break;
1517       EmitSignalDeactivateDialog();
1518       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1519       SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1520       SALOME_ListIteratorOfListIO It (IOs);
1521       int nbSelectedGroups = 0;
1522       for ( ; It.More(); It.Next() )
1523       {
1524         SMESH::SMESH_Group_var aGroup =
1525           SMESH::IObjectToInterface<SMESH::SMESH_Group>(It.Value());
1526         if (!aGroup->_is_nil()) {
1527           nbSelectedGroups++;
1528           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
1529           aDlg->show();
1530         }
1531       }
1532       if (nbSelectedGroups == 0)
1533         {
1534           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, SMESH::SMESH_Group::_nil());
1535           aDlg->show();
1536         }
1537       break;
1538     }
1539
1540   case 804:                                     // Add elements to group
1541     {
1542       if(checkLock(aStudy)) break;
1543       if (myState == 800) {
1544         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1545         if (aDlg) aDlg->onAdd();
1546       }
1547       break;
1548     }
1549
1550   case 805:                                     // Remove elements from group
1551     {
1552       if(checkLock(aStudy)) break;
1553       if (myState == 800) {
1554         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1555         if (aDlg) aDlg->onRemove();
1556       }
1557       break;
1558     }
1559
1560     case 810: // Union Groups
1561     case 811: // Intersect groups
1562     case 812: // Cut groups
1563     {
1564       if ( checkLock( aStudy ) )
1565         break;
1566
1567       EmitSignalDeactivateDialog();
1568       SALOME_Selection *Sel = SALOME_Selection::Selection(
1569         myActiveStudy->getSelection() );
1570
1571       int aMode;
1572       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1573       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1574       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1575
1576       ( new SMESHGUI_GroupOpDlg( parent, Sel, aMode ) )->show();
1577       break;
1578     }
1579
1580     case 813: // Delete groups with their contents
1581     {
1582       if ( checkLock( aStudy ) )
1583         break;
1584
1585       EmitSignalDeactivateDialog();
1586       SALOME_Selection *Sel = SALOME_Selection::Selection(
1587         myActiveStudy->getSelection() );
1588
1589       ( new SMESHGUI_DeleteGroupDlg( parent, Sel ) )->show();
1590       break;
1591     }
1592
1593   case 900:                                     // MESH INFOS
1594     {
1595       EmitSignalDeactivateDialog();
1596       SALOME_Selection *Sel =
1597         SALOME_Selection::Selection(myActiveStudy->getSelection());
1598       if ( Sel->IObjectCount() > 1 ) { // a dlg for each IO
1599         SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1600         SALOME_ListIteratorOfListIO It (IOs);
1601         for ( ; It.More(); It.Next() ) {
1602           Sel->ClearIObjects();
1603           Sel->AddIObject( It.Value() );
1604           new SMESHGUI_MeshInfosDlg(parent, "", false);
1605         }
1606         // restore selection
1607         Sel->ClearIObjects();
1608         for (It.Initialize( IOs ) ; It.More(); It.Next() )
1609           Sel->AddIObject( It.Value() );
1610       }
1611       else
1612         new SMESHGUI_MeshInfosDlg(parent, "", false);
1613       break;
1614     }
1615
1616   case 902:                                     // STANDARD MESH INFOS
1617     {
1618       EmitSignalDeactivateDialog();
1619       SALOME_Selection *Sel =
1620         SALOME_Selection::Selection(myActiveStudy->getSelection());
1621       if ( Sel->IObjectCount() > 1 ) { // a dlg for each IO
1622         SALOME_ListIO IOs; IOs = Sel->StoredIObjects(); // list copy
1623         SALOME_ListIteratorOfListIO It (IOs);
1624         for ( ; It.More(); It.Next() ) {
1625           Sel->ClearIObjects();
1626           Sel->AddIObject( It.Value() );
1627           new SMESHGUI_StandardMeshInfosDlg(parent, "", false);
1628         }
1629         // restore selection
1630         Sel->ClearIObjects();
1631         for (It.Initialize( IOs ) ; It.More(); It.Next() )
1632           Sel->AddIObject( It.Value() );
1633       }
1634       else
1635         new SMESHGUI_StandardMeshInfosDlg(parent, "", false);
1636       break;
1637     } 
1638     
1639   case 1001:                                    // AUTOMATIC UPDATE PREFERENCES
1640     {
1641       parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
1642       if (parent->menuBar()->isItemChecked(1001)) {
1643         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
1644         myAutomaticUpdate = true;
1645       }
1646       else {
1647         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
1648         myAutomaticUpdate = false;
1649       }
1650       break;
1651     }
1652
1653   case 1003:                                    // MESH PREFERENCES
1654     {
1655       ::SetDisplaySettings();
1656       break;
1657     }
1658
1659   case 1005:
1660     {
1661       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
1662       break;
1663     }
1664
1665   case 10070:
1666     {
1667       ( new SMESHGUI_PrecisionDlg( parent ) )->exec();
1668       break;
1669     }
1670
1671   case 10071:
1672     {
1673       parent->menuBar()->setItemChecked(10071, !parent->menuBar()->isItemChecked(10071));
1674       if (parent->menuBar()->isItemChecked(10071)) {
1675         QAD_CONFIG->addSetting("SMESH:DispayEntity","true");
1676       }
1677       else {
1678         QAD_CONFIG->addSetting("SMESH:DispayEntity","false");
1679       }
1680       break;
1681     }
1682   case 1006: 
1683     {
1684       SMESHGUI_Preferences_SelectionDlg* aDlg = 
1685         new SMESHGUI_Preferences_SelectionDlg(parent);
1686
1687       QColor aColor;
1688       QString SCr, SCg, SCb;
1689       SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
1690       SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
1691       SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
1692       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1693         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1694       else aColor = Qt::cyan;
1695       aDlg->SetColor(1, aColor);
1696
1697       SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
1698       SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
1699       SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
1700       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1701         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1702       else aColor = Qt::yellow;
1703       aDlg->SetColor(2, aColor);
1704
1705       SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
1706       SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
1707       SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
1708       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
1709         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
1710       else aColor = Qt::white;
1711       aDlg->SetColor(3, aColor);
1712
1713       QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
1714       if (SW1.isEmpty()) SW1 = "5";
1715       aDlg->SetWidth(1, SW1.toInt());
1716
1717       QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
1718       if (SW2.isEmpty()) SW2 = "5";
1719       aDlg->SetWidth(2, SW2.toInt());
1720
1721       QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
1722       if (SP1.isEmpty()) SP1 = "0.025";
1723       aDlg->SetPrecision(1, SP1.toDouble());
1724
1725       QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
1726       if (SP2.isEmpty()) SP2 = "0.001";
1727       aDlg->SetPrecision(2, SP2.toDouble());
1728
1729       if (aDlg->exec()) {
1730         QColor aPreColor = aDlg->GetColor(1);
1731         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
1732         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
1733         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
1734
1735         QColor aSelColor = aDlg->GetColor(2);
1736         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
1737         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
1738         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
1739
1740         QColor aHiColor = aDlg->GetColor(3);
1741         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
1742         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
1743         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
1744
1745         int aPreWidth = aDlg->GetWidth(1);
1746         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
1747         int aSelWidth = aDlg->GetWidth(2);
1748         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
1749
1750         double aTolNodes = aDlg->GetPrecision(1);
1751         QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
1752         double aTolItems = aDlg->GetPrecision(2);
1753         QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
1754
1755         // update current study settings
1756         SMESH::UpdateSelectionProp();
1757
1758         QAD_StudyFrame* studyFrame = myActiveStudy->getActiveStudyFrame();
1759         if (studyFrame->getTypeView() == VIEW_VTK) {
1760           VTKViewer_ViewFrame* aViewFrame = SMESH::GetVtkViewFrame(studyFrame);
1761           // update VTK viewer properties
1762           VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
1763           if (anInteractor) {
1764             anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
1765                                            aSelColor.blue()/255., aSelWidth);
1766             anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
1767             VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
1768             if (aStyle)
1769               aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
1770                                           aPreColor.blue()/255., aPreWidth);
1771           }
1772           // update actors
1773           vtkRenderer* aRenderer = aViewFrame->getRenderer();
1774           vtkActorCollection *aCollection = aRenderer->GetActors();
1775           aCollection->InitTraversal();
1776           while(vtkActor *anAct = aCollection->GetNextActor()){
1777             if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1778               anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
1779                                          aHiColor.blue()/255.);
1780               anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
1781                                             aPreColor.blue()/255.);
1782             }
1783           }
1784         }
1785       }
1786
1787       break;
1788     }
1789
1790   case 1100:                                    // EDIT HYPOTHESIS
1791     {
1792       if(checkLock(aStudy)) break;
1793       SALOME_Selection *Sel =
1794         SALOME_Selection::Selection(myActiveStudy->getSelection());
1795       int nbSel = Sel->IObjectCount();
1796
1797       if (nbSel == 1) {
1798         SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(Sel->firstIObject());
1799
1800         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1801         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1802         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1803         if ( !Hyp->_is_nil() )
1804         {
1805           char* sName = Hyp->GetName();
1806           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
1807           if (aCreator)
1808           {
1809             aCreator->EditHypothesis(Hyp);
1810           }
1811           else
1812           {
1813             // report error
1814           }
1815         }
1816       }
1817       break;
1818     }
1819
1820   case 1101:                                    // RENAME
1821     {
1822       if ( checkLock( aStudy ) )
1823         break;
1824         
1825       SALOME_Selection *Sel =
1826         SALOME_Selection::Selection( myActiveStudy->getSelection() );
1827         
1828       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1829       for ( ; It.More(); It.Next() )
1830       {
1831         Handle(SALOME_InteractiveObject) IObject = It.Value();
1832         SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
1833         SALOMEDS::GenericAttribute_var anAttr;
1834         SALOMEDS::AttributeName_var aName;
1835         if ( !obj->_is_nil() )
1836         {
1837           if ( obj->FindAttribute(anAttr, "AttributeName") )
1838           {
1839             aName = SALOMEDS::AttributeName::_narrow( anAttr );
1840             QString newName = QString(aName->Value());
1841             newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName );
1842             if ( !newName.isEmpty() )
1843             {
1844               myActiveStudy->renameIObject( IObject, newName );
1845
1846               // if current object is group update group's name
1847               SMESH::SMESH_GroupBase_var aGroup =
1848                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1849               if (!aGroup->_is_nil() )
1850                 aGroup->SetName( newName.latin1() );
1851             }
1852           }
1853         }
1854       }
1855       break;
1856     }
1857     
1858   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1859     {
1860       if(checkLock(aStudy)) break;
1861       QAD_WaitCursor wc;
1862       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1863       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1864       for (int i = 0; It.More(); It.Next(), i++) {
1865         Handle(SALOME_InteractiveObject) IObject = It.Value();
1866         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1867       }
1868       Sel->ClearIObjects();
1869       myActiveStudy->updateObjBrowser(true);
1870       break;
1871     }
1872
1873   case 401:                                     // GEOM::EDGE
1874   case 4021:                                    // TRIANGLE
1875   case 4022:                                    // QUAD
1876   case 4031:                                    // TETRA
1877   case 4032:                                    // HEXA
1878     {
1879       if(checkLock(aStudy)) break;
1880       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1881         EmitSignalDeactivateDialog();
1882         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1883         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1884         int                 nbNodes = 2;
1885         switch (theCommandID) {
1886         case 4021:                                      // TRIANGLE
1887           type = SMDSAbs_Face; nbNodes = 3; break;
1888         case 4022:                                      // QUAD
1889           type = SMDSAbs_Face; nbNodes = 4; break;
1890         case 4031:                                      // TETRA
1891           type = SMDSAbs_Volume; nbNodes = 4; break;
1892         case 4032:                                      // HEXA
1893           type = SMDSAbs_Volume; nbNodes = 8; break;
1894         default:;
1895         }
1896         new SMESHGUI_AddMeshElementDlg(parent, "", Sel, type, nbNodes);
1897       }
1898       else {
1899         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1900                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1901                               tr("SMESH_BUT_OK"));
1902       }
1903       break;
1904     }
1905
1906   case 4041:                                    // REMOVES NODES
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_RemoveNodesDlg(parent, "", Sel);
1913       }
1914       else {
1915         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1916                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1917                               tr("SMESH_BUT_OK"));
1918       }
1919       break;
1920     }
1921   case 4042:                                    // REMOVES ELEMENTS
1922     {
1923       if(checkLock(aStudy)) break;
1924       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1925         EmitSignalDeactivateDialog();
1926         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1927         new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
1928       }
1929       else
1930         {
1931           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1932                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1933                                 tr("SMESH_BUT_OK"));
1934         }
1935       break;
1936     }
1937   case 4051:                                    // RENUMBERING NODES
1938     {
1939       if(checkLock(aStudy)) break;
1940       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1941         EmitSignalDeactivateDialog();
1942         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1943         new SMESHGUI_RenumberingDlg(parent, "", Sel, 0);
1944       }
1945       else
1946         {
1947           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1948                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1949                                 tr("SMESH_BUT_OK"));
1950         }
1951       break;
1952     }
1953   case 4052:                                    // RENUMBERING ELEMENTS
1954     {
1955       if(checkLock(aStudy)) break;
1956       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1957         EmitSignalDeactivateDialog();
1958         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1959         new SMESHGUI_RenumberingDlg(parent, "", Sel, 1);
1960       }
1961       else
1962         {
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 4061:                                   // TRANSLATION
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_TranslationDlg(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 4062:                                   // ROTATION
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_RotationDlg(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 4063:                                   // SYMMETRY 
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_SymmetryDlg(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 4064:                                   // SEWING
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_SewingDlg(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   case 4065:                                   // MERGE NODES
2030     {
2031       if(checkLock(aStudy)) break;
2032       if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2033         EmitSignalDeactivateDialog();
2034         SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2035         new SMESHGUI_MergeNodesDlg(parent, "", Sel);
2036       }
2037       else {
2038         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2039                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2040                               tr("SMESH_BUT_OK"));
2041       }
2042       break;
2043     }
2044     
2045
2046   case 5000: // HYPOTHESIS
2047     {
2048       if(checkLock(aStudy)) break;
2049       EmitSignalDeactivateDialog();
2050       new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
2051       break;
2052     }
2053   case 5010: // ALGO
2054     {
2055       if(checkLock(aStudy)) break;
2056       EmitSignalDeactivateDialog();
2057       new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
2058       break;
2059     }
2060
2061   case 5105: // Library of selection filters
2062   {
2063     static QValueList<int> aTypes;
2064     if ( aTypes.isEmpty() )
2065     {
2066       aTypes.append( SMESH::NODE );
2067       aTypes.append( SMESH::EDGE );
2068       aTypes.append( SMESH::FACE );
2069       aTypes.append( SMESH::VOLUME );
2070     }
2071     new SMESHGUI_FilterLibraryDlg( parent, aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2072   }
2073   break;
2074
2075   case 6017:                                    // CONTROLS 
2076   case 6016:
2077   case 6015:
2078   case 6014:
2079   case 6013:
2080   case 6012:
2081   case 6011:
2082   case 6001:
2083   case 6018:
2084   case 6002:
2085   case 6003:
2086   case 6004:    
2087     if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2088       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2089       if ( Sel->IObjectCount() == 1 && Sel->firstIObject()->hasEntry() ) {
2090         SALOMEDS::SObject_var SO = aStudy->FindObjectID( Sel->firstIObject()->getEntry() );
2091         if ( !SO->_is_nil() ) {
2092           CORBA::Object_var aObject = SO->GetObject();
2093           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2094           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2095           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2096           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2097             ::Control( theCommandID );
2098             break;
2099           }
2100         }
2101       }
2102       QAD_MessageBox::warn1(GetDesktop(), 
2103                             tr( "SMESH_WRN_WARNING" ),
2104                             tr( "SMESH_BAD_SELECTION" ), 
2105                             tr( "SMESH_BUT_OK" ) );
2106       break;
2107     }
2108     else {
2109       QAD_MessageBox::warn1(GetDesktop(), 
2110                             tr( "SMESH_WRN_WARNING" ),
2111                             tr( "NOT_A_VTK_VIEWER" ), 
2112                             tr( "SMESH_BUT_OK" ) );
2113     }
2114     break;
2115   case 9010:
2116     {
2117       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2118       if (Sel->IObjectCount() == 1)     {
2119         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
2120         if(anIObject->hasEntry())
2121           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2122             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2123           }
2124       }
2125       break;
2126     }
2127   case 9011:
2128     {
2129       SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
2130       if (Sel->IObjectCount() == 1)     {
2131         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
2132         if(anIObject->hasEntry())
2133           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2134             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2135           }
2136       }
2137       break;
2138     }
2139   case 10001:                           // DISPLAY MODE PREFERENCE
2140     {
2141       // Wireframe
2142       parent->menuBar()->setItemChecked(10001, true);
2143       parent->menuBar()->setItemChecked(10002, false);
2144       parent->menuBar()->setItemChecked(10004, false);
2145       parent->menuBar()->setItemEnabled(10003, true);
2146       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2147       break;
2148     }
2149   case 10002:
2150     {
2151       parent->menuBar()->setItemChecked(10002, true);
2152       parent->menuBar()->setItemChecked(10001, false);
2153       parent->menuBar()->setItemChecked(10004, false);
2154       parent->menuBar()->setItemEnabled(10003, true);
2155       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2156       break;
2157     }
2158   case 10003:
2159     {
2160       parent->menuBar()->setItemChecked(10003,!parent->menuBar()->isItemChecked(10003));
2161       QAD_CONFIG->addSetting("SMESH:Shrink", parent->menuBar()->isItemChecked(10003) ? "yes" : "no");
2162       break;
2163     }
2164   case 10004:
2165     {
2166       parent->menuBar()->setItemChecked(10001, false);
2167       parent->menuBar()->setItemChecked(10004, true);
2168       parent->menuBar()->setItemChecked(10002, false);
2169       parent->menuBar()->setItemEnabled(10003, false);
2170       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Nodes");
2171       break;
2172     }
2173     
2174   }
2175
2176   myActiveStudy->updateObjBrowser(true);
2177   return true;
2178 }
2179
2180 //=============================================================================
2181 /*!
2182  *
2183  */
2184 //=============================================================================
2185 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
2186                             QAD_StudyFrame * studyFrame)
2187 {
2188   return false;
2189 }
2190
2191 //=============================================================================
2192 /*!
2193  *
2194  */
2195 //=============================================================================
2196 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
2197                            QAD_StudyFrame * studyFrame)
2198 {
2199   return true;
2200 }
2201
2202 //=============================================================================
2203 /*!
2204  *
2205  */
2206 //=============================================================================
2207 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
2208                           QAD_StudyFrame * studyFrame)
2209 {
2210   return true;
2211 }
2212
2213 //=============================================================================
2214 /*!
2215  *
2216  */
2217 //=============================================================================
2218 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
2219 {
2220   MESSAGE("SMESHGUI::SetSettings.");
2221   SMESHGUI::GetSMESHGUI();
2222
2223   /* Display mode */
2224   QString DisplayMode = "Shading";
2225   if ( QAD_CONFIG->hasSetting("SMESH:DisplayMode") )
2226     DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
2227   else
2228     QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2229
2230   bool Shrink = false;
2231   if ( QAD_CONFIG->hasSetting("SMESH:Shrink") )
2232     Shrink = QAD_CONFIG->getSetting("SMESH:Shrink") == "yes";
2233
2234   if (DisplayMode == "Wireframe") {
2235     // wireframe
2236     parent->menuBar()->setItemChecked(10004, false);
2237     parent->menuBar()->setItemChecked(10002, false);
2238     parent->menuBar()->setItemChecked(10001, true);
2239     parent->menuBar()->setItemEnabled(10003, true);
2240   }
2241   else if (DisplayMode == "Nodes") {
2242     // poins
2243     parent->menuBar()->setItemChecked(10004, true);
2244     parent->menuBar()->setItemChecked(10002, false);
2245     parent->menuBar()->setItemChecked(10001, false);
2246     parent->menuBar()->setItemEnabled(10003, false);
2247   }
2248   else {
2249     // default is shading
2250     parent->menuBar()->setItemChecked(10004, false);
2251     parent->menuBar()->setItemChecked(10002, true);
2252     parent->menuBar()->setItemChecked(10001, false);
2253     parent->menuBar()->setItemEnabled(10003, true);
2254   }
2255   parent->menuBar()->setItemChecked(10003, Shrink);
2256
2257   /* Automatic Update */
2258   QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
2259   if (AutoUpdate.compare("true") == 0) {
2260     parent->menuBar()->setItemChecked(1001, true);
2261     myAutomaticUpdate = true;
2262   }
2263   else {
2264     parent->menuBar()->setItemChecked(1001, false);
2265     myAutomaticUpdate = false;
2266   }
2267
2268   QString anIsDisplayEntity = QAD_CONFIG->getSetting("SMESH:DispayEntity");
2269   if(anIsDisplayEntity.compare("true") == 0)
2270     parent->menuBar()->setItemChecked(10071,true);
2271   else
2272     parent->menuBar()->setItemChecked(10071,false);
2273
2274   /* Selection */
2275   SMESH::UpdateSelectionProp();
2276
2277   /* menus disable */
2278   parent->menuBar()->setItemEnabled(111, false);        // IMPORT DAT
2279   //parent->menuBar()->setItemEnabled(112, false);      // IMPORT UNV
2280
2281   return true;
2282 }
2283
2284 //=============================================================================
2285 /*!
2286  *
2287  */
2288 //=============================================================================
2289 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
2290 {
2291   // NRI : Temporary added
2292   //  if ( myStudy->GetProperties()->IsLocked() ) {
2293   //    theObject = "NothingSelected";
2294   //    theContext = "NothingSelected";
2295   //  }
2296   // NRI
2297
2298   SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2299   int nbSel = Sel->IObjectCount();
2300   switch ( nbSel ) {
2301   case 0:
2302     theObject = "NothingSelected";
2303     theContext = "NothingSelected";
2304     break;
2305   case 1:
2306     if ( myState == 800 && Sel->HasIndex( Sel->firstIObject() ) )
2307       theObject = "Elements";
2308     else
2309       theObject = ::CheckTypeObject( Sel->firstIObject() );
2310     theContext = "";
2311     break;
2312   default:
2313     theObject = ::CheckHomogeneousSelection();
2314     theContext = "";
2315   }
2316 }
2317
2318 //=============================================================================
2319 /*!
2320  *
2321  */
2322 //=============================================================================
2323 bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
2324                            const QString& theParent, const QString& theObject)
2325 {
2326   // get active study frame
2327   QAD_StudyFrame* studyFrame = myActiveStudy->getActiveStudyFrame();
2328   
2329   // get parent component which selected object(s) belongs to
2330   QString parentComp = ( (SALOMEGUI_Desktop*)parent )->getComponentFromSelection();
2331
2332   // get selection
2333   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2334   int nbSel = Sel->IObjectCount();
2335
2336   if ( nbSel == 0 ) {
2337     popup->clear();
2338   }
2339   else if ( nbSel == 1 ) {
2340     if ( parentComp != parent->getActiveComponent() ) {
2341       // object not belongs to SMESH module - remove all commands except common Display/Erase...
2342       while ( 1 ) {
2343         int id = popup->idAt( 0 );
2344         if ( id <= QAD_TopLabel_Popup_ID )
2345           popup->removeItemAt( 0 );
2346         else
2347           break;
2348       }
2349     }
2350     else {
2351       // get selected interactive object 
2352       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2353       SALOMEDS::SObject_var SO = SMESH::GetActiveStudyDocument()->FindObjectID( IObject->getEntry() );
2354       // find popup menu's TopLabel item
2355       int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
2356       if ( topItem >= 0 ) {
2357         if ( theParent == "Viewer" ) {
2358           // set bold font for popup menu's TopLabel item (Viewer popup)
2359           QFont fnt = popup->font(); fnt.setBold( TRUE );
2360           popup->removeItem( QAD_TopLabel_Popup_ID );
2361           popup->insertItem( new CustomItem( QString( IObject->getName() ), fnt ), QAD_TopLabel_Popup_ID, topItem );
2362         }
2363         else if ( theParent == "ObjectBrowser" ) {
2364           // remove popup menu's TopLabel item (Object Browser popup)
2365           popup->removeItem( QAD_TopLabel_Popup_ID );
2366         }
2367       }
2368
2369       if ( theObject == "Hypothesis" || theObject == "Algorithm" ) {
2370         // remove Display/Erase commands
2371         popup->removeItem( QAD_Display_Popup_ID );
2372         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2373         popup->removeItem( QAD_Erase_Popup_ID );
2374         // remove "Unassign ..." command if hyp/algo is not assigned
2375         if ( SO->_is_nil() || !IObject->hasReference()/* !IsReferencedObject( SO ) */)
2376           popup->removeItem( 1102 );
2377       }
2378       else if ( theObject == "Mesh" || theObject == "SubMesh" || theObject == "Group" ) {
2379         // get actor
2380         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( SO );
2381         if ( aShapeObject->_is_nil() ) {
2382           // imported mesh
2383           popup->removeItem( 701 ); // Compute
2384           popup->removeItem( 705 ); // Edit hypothesis
2385           popup->removeItem( 706 ); // ...
2386         }
2387         SMESH::SMESH_GroupOnGeom_var aGeomGroup =
2388           SMESH::SMESH_GroupOnGeom::_narrow( SO->GetObject() );
2389         if ( !aGeomGroup->_is_nil()  ) // group linked on geometry
2390           popup->removeItem( 803 ); // EDIT GROUP
2391           
2392         SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
2393         // if object has actor
2394         if ( anActor && studyFrame->getTypeView() == VIEW_VTK ) {
2395           VTKViewer_RenderWindowInteractor* myRenderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
2396           if ( myRenderInter->isVisible( IObject ) ) {
2397             popup->removeItem( QAD_Display_Popup_ID );
2398             popup->setItemChecked( 9010, anActor->GetPointsLabeled() ); // Numbering / Display Nodes #
2399             popup->setItemChecked( 9011, anActor->GetCellsLabeled() );  // Numbering / Display Elements #
2400             TVisualObjPtr aVisualObj = anActor->GetObject();
2401             int aNbEdges = aVisualObj->GetNbEntities(SMDSAbs_Edge);
2402             int aNbFaces = aVisualObj->GetNbEntities(SMDSAbs_Face);
2403             int aNbVolumes = aVisualObj->GetNbEntities(SMDSAbs_Volume);
2404
2405             QMenuItem* mi = popup->findItem( 1131 );
2406             if ( mi && mi->popup() ) {
2407               int  prType = anActor->GetRepresentation();
2408               // Display Mode / Wireframe
2409               if(aNbVolumes == 0 && aNbFaces == 0 && aNbEdges == 0){
2410                 mi->popup()->removeItem( 211 );
2411               }else{
2412                 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
2413               }
2414               // Display Mode / Shading
2415               if(aNbFaces == 0 && aNbVolumes == 0){
2416                 mi->popup()->removeItem( 212 );
2417               }else{
2418                 mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface );
2419               }
2420               // Display Mode / Points
2421               mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint );  
2422               // Display Mode / Shrink
2423               bool isShrunk = anActor->IsShrunk();
2424               bool isShrunkable = anActor->IsShrunkable();
2425               mi->popup()->setItemChecked( 213, isShrunk );   
2426               mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable);
2427             }
2428
2429             // Display Entity
2430             mi = popup->findItem( 1135 );
2431             if ( mi && mi->popup() ) {
2432               QPopupMenu* aPopup = mi->popup();
2433               unsigned int aMode = anActor->GetEntityMode();
2434
2435               if(aNbVolumes == 0)
2436                 aPopup->removeItem( 219 );
2437               else
2438                 aPopup->setItemChecked( 219, aMode & SMESH_Actor::eVolumes );
2439
2440               if(aNbFaces == 0)
2441                 aPopup->removeItem( 218 );
2442               else
2443                 aPopup->setItemChecked( 218, aMode & SMESH_Actor::eFaces );
2444
2445
2446               if(aNbEdges == 0)
2447                 aPopup->removeItem( 217 );
2448               else
2449                 aPopup->setItemChecked( 217, aMode & SMESH_Actor::eEdges );
2450
2451
2452               bool aIsRemove = (aNbVolumes == 0 || aMode & SMESH_Actor::eVolumes);
2453               aIsRemove &= (aNbFaces == 0 || aMode & SMESH_Actor::eFaces);
2454               aIsRemove &= (aNbEdges == 0 || aMode & SMESH_Actor::eEdges);
2455
2456               if(aIsRemove)
2457                 aPopup->removeItem( 220 );
2458             }
2459
2460             // Controls
2461             mi = popup->findItem( 2000 );
2462             if ( mi && mi->popup() ) {
2463               SMESH_Actor::eControl cMode = anActor->GetControlMode();
2464               switch ( cMode ) {
2465               case SMESH_Actor::eLength:
2466                 mi->popup()->setItemChecked( 6001, true ); break;
2467               case SMESH_Actor::eLength2D:
2468                 mi->popup()->setItemChecked( 6018, true ); break;
2469               case SMESH_Actor::eFreeEdges:
2470                 mi->popup()->setItemChecked( 6002, true );
2471                 mi->popup()->removeItem( 201 );
2472                 break;
2473               case SMESH_Actor::eFreeBorders:
2474                 mi->popup()->setItemChecked( 6003, true );
2475                 mi->popup()->removeItem( 201 );
2476                 break;
2477               case SMESH_Actor::eMultiConnection:
2478                 mi->popup()->setItemChecked( 6004, true ); break;
2479               case SMESH_Actor::eArea:
2480                 mi->popup()->setItemChecked( 6011, true ); break;
2481               case SMESH_Actor::eTaper:
2482                 mi->popup()->setItemChecked( 6012, true ); break;
2483               case SMESH_Actor::eAspectRatio:
2484                 mi->popup()->setItemChecked( 6013, true ); break;
2485               case SMESH_Actor::eAspectRatio3D:
2486                 mi->popup()->setItemChecked( 6017, true ); break;
2487               case SMESH_Actor::eMinimumAngle:
2488                 mi->popup()->setItemChecked( 6014, true ); break;
2489               case SMESH_Actor::eWarping:
2490                 mi->popup()->setItemChecked( 6015, true ); break;
2491               case SMESH_Actor::eSkew:
2492                 mi->popup()->setItemChecked( 6016, true ); break;
2493               case SMESH_Actor::eNone:
2494               default:
2495                 mi->popup()->removeItem( 200 );
2496                 mi->popup()->removeItem( 201 );
2497                 break;
2498               }
2499               TVisualObjPtr aVisualObj = anActor->GetObject();
2500               if(aNbEdges == 0){
2501                 mi->popup()->removeItem( 6001 );
2502                 mi->popup()->removeItem( 6018 );
2503                 mi->popup()->removeItem( 6003 );
2504                 mi->popup()->removeItem( 6004 );
2505               }
2506               if(aNbFaces == 0){
2507                 mi->popup()->removeItem( 6002 );
2508                 mi->popup()->removeItem( 6011 );
2509                 mi->popup()->removeItem( 6012 );
2510                 mi->popup()->removeItem( 6013 );
2511                 mi->popup()->removeItem( 6014 );
2512                 mi->popup()->removeItem( 6015 );
2513                 mi->popup()->removeItem( 6016 );
2514               }
2515               if(aNbVolumes == 0){
2516                 mi->popup()->removeItem( 6017 );
2517               }
2518               if(aNbFaces == 0 && aNbEdges == 0 && aNbVolumes == 0)
2519                 popup->removeItem( 2000 );                         // Scalar Bar
2520             }
2521           }
2522           else {
2523             popup->removeItem( QAD_Erase_Popup_ID );
2524             popup->removeItem( 114 );                              // Numbering popup menu
2525             popup->removeItem( 1131 );                             // Display mode
2526             popup->removeItem( 1132 );                             // Color / size
2527             popup->removeItem( 1133 );                             // Transparency
2528             popup->removeItem( 1134 );                             // Clipping
2529             popup->removeItem( 2000 );                             // Scalar Bar
2530           }
2531         }
2532         else {
2533           // object doesn't have actor
2534           CORBA::Object_var anObject = SO->GetObject();
2535           bool bDisplay = false;
2536           if ( !CORBA::is_nil( anObject ) ) {
2537             SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
2538             if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0  || aMeshObj->NbVolumes() > 0 ) )
2539               bDisplay = true;
2540             SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
2541             if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes(false) > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
2542               bDisplay = true;
2543             SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( anObject );
2544             if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
2545               bDisplay = true;
2546           }
2547           if ( !bDisplay ) {
2548             popup->removeItem( QAD_Display_Popup_ID );
2549             popup->removeItem( QAD_DisplayOnly_Popup_ID );
2550           }
2551           popup->removeItem( QAD_Erase_Popup_ID );
2552           popup->removeItem( 114 );                              // Numbering popup menu
2553           popup->removeItem( 1131 );                             // Display mode
2554           popup->removeItem( 1132 );                             // Color / size
2555           popup->removeItem( 1133 );                             // Transparency
2556           popup->removeItem( 1134 );                             // Clipping
2557           popup->removeItem( 2000 );                             // Scalar Bar
2558         }
2559       }
2560       else if( theObject!="Component" ) {
2561         // another SMESH object
2562         popup->removeItem( QAD_Display_Popup_ID );
2563         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2564         popup->removeItem( QAD_Erase_Popup_ID );
2565       }
2566     }
2567   }
2568   else {
2569     // multiple selection
2570     if ( parentComp != parent->getActiveComponent() ) {
2571       // object not belongs to SMESH module - remove all commands except common Display/Erase...
2572       while ( 1 )       {
2573         int id = popup->idAt( 0 );
2574         if ( id <= QAD_TopLabel_Popup_ID )
2575           popup->removeItemAt( 0 );
2576         else
2577           break;
2578       }
2579       if ( parentComp.isNull() ) {
2580         // objects from different components are selected
2581         popup->removeItem( QAD_DisplayOnly_Popup_ID );
2582         popup->removeItem( QAD_Display_Popup_ID );
2583         popup->removeItem( QAD_Erase_Popup_ID );
2584       }
2585     }
2586     else {
2587       QString type = ::CheckHomogeneousSelection();
2588       if ( type != "Heterogeneous Selection" ) {
2589         int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
2590         if ( topItem >= 0 ) {
2591           // set bold font for popup menu's TopLabel item
2592           QFont fnt = popup->font(); fnt.setBold( TRUE );
2593           popup->removeItem( QAD_TopLabel_Popup_ID );
2594           popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
2595         }
2596       }
2597     }
2598   }
2599   return false;
2600 }
2601
2602 //=============================================================================
2603 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2604  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2605  */
2606 //=============================================================================
2607 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2608                                   QAD_ViewFrame* )
2609 {
2610   if(theIO->hasEntry()){
2611     QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
2612     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
2613     SMESH::UpdateView(aStudyFrame,SMESH::eDisplay,theIO->getEntry());
2614   }
2615 }
2616
2617 void SMESHGUI::SupportedViewType(int *buffer, int bufferSize)
2618 {
2619   if (!buffer || !bufferSize)
2620     return;
2621   buffer[0] = (int)VIEW_VTK;
2622 }
2623
2624 void SMESHGUI::Deactivate()
2625 {
2626   if ( SMESHGUI::GetSMESHGUI() ) {
2627     SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
2628   }
2629 }