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