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