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