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