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