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