]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI.cxx
Salome HOME
089f08e06b758c0fb8fd079ce718323c87a7da7c
[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_AddHypothesisDlg.h"
29 #include "SMESHGUI_AddAlgorithmDlg.h"
30 #include "SMESHGUI_InitMeshDlg.h"
31 #include "SMESHGUI_AddSubMeshDlg.h"
32 #include "SMESHGUI_NodesDlg.h"
33 #include "SMESHGUI_TransparencyDlg.h"
34 #include "SMESHGUI_GroupDlg.h"
35 #include "SMESHGUI_RemoveNodesDlg.h"
36 #include "SMESHGUI_RemoveElementsDlg.h"
37 #include "SMESHGUI_MeshInfosDlg.h"
38 #include "SMESHGUI_Preferences_ColorDlg.h"
39 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
40 #include "SMESHGUI_Preferences_SelectionDlg.h"
41 #include "SMESHGUI_aParameterDlg.h"
42 #include "SMESHGUI_ComputeScalarValue.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_OrientationElementsDlg.h"
45 #include "SMESHGUI_DiagonalInversionDlg.h"
46 #include "SMESHGUI_AddFaceDlg.h"
47 #include "SMESHGUI_AddEdgeDlg.h"
48 #include "SMESHGUI_AddVolumeDlg.h"
49 #include "SMESHGUI_EditHypothesesDlg.h"
50 #include "SMESHGUI_CreateHypothesesDlg.h"
51 #include "SMESHGUI_FilterDlg.h"
52 #include "SMESHGUI_XmlHandler.h"
53
54 #include "SMESH_Actor.h"
55 #include "SMESH_Object.h"
56
57 // SALOME Includes
58 #include "Utils_ORB_INIT.hxx"
59 #include "Utils_SINGLETON.hxx"
60
61 #include "QAD.h"
62 #include "QAD_Tools.h"
63 #include "QAD_Config.h"
64 #include "QAD_Settings.h"
65 #include "QAD_RightFrame.h"
66 #include "QAD_MessageBox.h"
67 #include "QAD_Resource.h"
68 #include "QAD_FileDlg.h"
69 #include "QAD_Desktop.h"
70 #include "QAD_ResourceMgr.h"
71 #include "QAD_WaitCursor.h"
72
73 #include "OCCViewer_ViewPort.h"
74 #include "OCCViewer_ViewPort3d.h"
75 #include "OCCViewer_Viewer3d.h"
76
77 #include "GEOM_InteractiveObject.hxx"
78
79 #include "SALOME_NamingService.hxx"
80 #include "SALOME_ListIteratorOfListIO.hxx"
81 #include "SALOME_InteractiveObject.hxx"
82
83 #include "SALOMEGUI_Desktop.h"
84 #include "SALOMEGUI_NameDlg.h"
85 #include "SALOMEGUI_ImportOperation.h"
86 #include "SALOMEGUI_QtCatchCorbaException.hxx"
87
88 #include "utilities.h"
89 #include <dlfcn.h>
90
91 #include "SMDS_Mesh.hxx"
92 #include "SMESHDS_Document.hxx"
93 #include "Document_Reader.h"
94 #include "Document_Writer.h"
95 #include "Mesh_Reader.h"
96 #include "Mesh_Writer.h"
97
98 #include "DriverDAT_R_SMESHDS_Document.h"
99 #include "DriverMED_R_SMESHDS_Document.h"
100 #include "DriverUNV_R_SMESHDS_Document.h"
101 #include "DriverDAT_W_SMESHDS_Document.h"
102 #include "DriverMED_W_SMESHDS_Document.h"
103 #include "DriverUNV_W_SMESHDS_Document.h"
104 #include "DriverDAT_R_SMESHDS_Mesh.h"
105 #include "DriverMED_R_SMESHDS_Mesh.h"
106 #include "DriverUNV_R_SMESHDS_Mesh.h"
107 #include "DriverDAT_W_SMESHDS_Mesh.h"
108 #include "DriverMED_W_SMESHDS_Mesh.h"
109 #include "DriverUNV_W_SMESHDS_Mesh.h"
110
111 // QT Includes
112 #define  INCLUDE_MENUITEM_DEF
113 #include <qapplication.h>
114 #include <qlineedit.h>
115 #include <qmenudata.h>
116 #include <qmenubar.h>
117 #include <qpopupmenu.h>
118 #include <qfont.h>
119 #include <qstring.h>
120 #include <qcheckbox.h>
121 #include <qcolordialog.h>
122 #include <qspinbox.h>
123 #include <qlist.h>
124 #include <qwidget.h>
125 #include <qevent.h>
126 #include <qradiobutton.h>
127
128 // VTK Includes
129 #include "VTKViewer_Common.h"
130 #include "VTKViewer_ViewFrame.h"
131 #include "VTKViewer_InteractorStyleSALOME.h"
132
133 #include <vtkScalarBarActor.h>
134 #include <vtkLegendBoxActor.h>
135 #include <vtkFeatureEdges.h>
136 #include <vtkDoubleArray.h>
137 #include <vtkTextProperty.h>
138
139 // Open CASCADE Includes
140 #include <gp_Pnt.hxx>
141 #include <gp_Vec.hxx>
142
143 #include <boost/shared_ptr.hpp>
144
145 static SMESHGUI *smeshGUI = 0;
146 static CORBA::ORB_var _orb;
147
148 using namespace std;
149
150 typedef pair<int,string> TKeyOfVisualObj;
151 typedef boost::shared_ptr<SMESH_VisualObj> TVisualObjPtr;
152 typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
153 static TVisualObjCont VISUALOBJCONT;
154
155
156 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
157   TVisualObjPtr aVisualObj;
158   try{
159     TVisualObjCont::key_type aKey(theStudyId,theEntry);
160     TVisualObjCont::iterator anIter = VISUALOBJCONT.find(aKey);
161     if(anIter != VISUALOBJCONT.end()){
162       aVisualObj = anIter->second;
163     }else{
164       SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
165       SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theEntry);
166       if(!CORBA::is_nil(aSObj)){
167         SALOMEDS::GenericAttribute_var anAttr;
168         if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
169           SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
170           CORBA::String_var aVal = anIOR->Value();
171           CORBA::Object_var anObj =_orb->string_to_object(aVal.in());
172           if(!CORBA::is_nil(anObj)){
173             //Try narrow to SMESH_Mesh interafce
174             SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
175             if(!aMesh->_is_nil()){
176               aVisualObj.reset(new SMESH_MeshObj(aMesh));
177               aVisualObj->Update();
178               TVisualObjCont::value_type aValue(aKey,aVisualObj); 
179               VISUALOBJCONT.insert(aValue);
180               return aVisualObj;
181             }
182             //Try narrow to SMESH_Group interafce
183             SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(anObj);
184             if(!aGroup->_is_nil()){
185               SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
186               if(aFatherSObj->_is_nil()) return aVisualObj;
187               aFatherSObj = aFatherSObj->GetFather();
188               if(aFatherSObj->_is_nil()) return aVisualObj;
189               CORBA::String_var anEntry = aFatherSObj->GetID();
190               TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
191               if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
192                 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
193                 aVisualObj->Update();
194                 TVisualObjCont::value_type aValue(aKey,aVisualObj); 
195                 VISUALOBJCONT.insert(aValue);
196                 return aVisualObj;
197               }
198             }
199             //Try narrow to SMESH_subMesh interafce
200             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
201             if(!aSubMesh->_is_nil()){
202               SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
203               if(aFatherSObj->_is_nil()) return aVisualObj;
204               aFatherSObj = aFatherSObj->GetFather();
205               if(aFatherSObj->_is_nil()) return aVisualObj;
206               CORBA::String_var anEntry = aFatherSObj->GetID();
207               TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
208               if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
209                 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
210                 aVisualObj->Update();
211                 TVisualObjCont::value_type aValue(aKey,aVisualObj); 
212                 VISUALOBJCONT.insert(aValue);
213                 return aVisualObj;
214               }
215             }
216           }
217         }
218       }
219     }
220   }catch(...){
221     INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
222   }
223   return aVisualObj;
224 }
225
226
227 VTKViewer_ViewFrame* GetVtkViewFrame(QAD_StudyFrame* theStudyFrame){
228   QAD_ViewFrame* aViewFrame = theStudyFrame->getRightFrame()->getViewFrame();
229   return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
230 }
231
232 void UpdateSelectionProp() {
233   QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
234   QList<QAD_StudyFrame> aFrameList = aStudy->getStudyFrames();
235
236   QString SCr, SCg, SCb;
237   SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
238   SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
239   SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
240   QColor aHiColor = Qt::white;
241   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
242     aHiColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
243
244   SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
245   SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
246   SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
247   QColor aSelColor = Qt::yellow;
248   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
249     aSelColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
250   QString SW = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
251   if (SW.isEmpty()) SW = "5";
252
253   SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
254   SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
255   SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
256   QColor aPreColor = Qt::cyan;
257   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
258     aPreColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
259   QString PW = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
260   if (PW.isEmpty()) PW = "5";
261
262   QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
263   if (SP1.isEmpty()) SP1 = "0.025";
264   QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
265   if (SP2.isEmpty()) SP2 = "0.001";
266
267   for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
268     if (aStudyFrame->getTypeView() == VIEW_VTK) {
269       VTKViewer_ViewFrame* aVtkViewFrame = GetVtkViewFrame(aStudyFrame);
270       if (!aVtkViewFrame) continue;
271       // update VTK viewer properties
272       VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
273       if (anInteractor) {
274         // mesh element selection
275         anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
276                                        aSelColor.blue()/255., SW.toInt());
277           
278         // tolerances
279         anInteractor->SetSelectionTolerance(SP1.toDouble(), SP2.toDouble());
280           
281         // pre-selection
282         VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
283         if (aStyle) {
284           aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
285                                       aPreColor.blue()/255., PW.toInt());
286         }
287       }
288       // update actors
289       vtkRenderer* aRenderer = aVtkViewFrame->getRenderer();
290       vtkActorCollection *aCollection = aRenderer->GetActors();
291       aCollection->InitTraversal();
292       while(vtkActor *anAct = aCollection->GetNextActor()){
293         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
294           anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
295                                      aHiColor.blue()/255.);
296           anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
297                                         aPreColor.blue()/255.);
298         }
299       }
300     }
301   }
302 }
303
304 VTKViewer_ViewFrame* GetCurrentVtkView(){
305   QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
306   QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
307   return GetVtkViewFrame(aStudyFrame);
308 }
309
310
311 SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame, 
312                               const char* theEntry)
313 {
314   if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
315     vtkRenderer *aRenderer = aViewFrame->getRenderer();
316     vtkActorCollection *aCollection = aRenderer->GetActors();
317     aCollection->InitTraversal();
318     while(vtkActor *anAct = aCollection->GetNextActor()){
319       if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
320         if(anActor->hasIO()){
321           Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
322           if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
323             return anActor;
324           }
325         }
326       }
327     }
328   }
329   return NULL;
330 }
331
332
333 SMESH_Actor* FindActorByEntry(const char* theEntry){
334   QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
335   QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
336   return FindActorByEntry(aStudyFrame,theEntry);
337 }
338
339
340 SMESH_Actor* CreateActor(SALOMEDS::Study_ptr theStudy,
341                          const char* theEntry,
342                          int theIsClear = false)
343 {
344   SMESH_Actor *anActor = NULL;
345   CORBA::Long anId = theStudy->StudyId();
346   if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
347     SALOMEDS::SObject_var aSObj = theStudy->FindObjectID(theEntry);
348     if(!aSObj->_is_nil()){
349       SALOMEDS::GenericAttribute_var anAttr;
350       if(aSObj->FindAttribute(anAttr,"AttributeName")){
351         SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
352         CORBA::String_var aVal = aName->Value();
353         string aNameVal = aVal.in();
354         SMESH::FilterManager_ptr aFilterMgr = smeshGUI->GetFilterMgr();
355         anActor = SMESH_Actor::New(aVisualObj,aFilterMgr,theEntry,aNameVal.c_str(),theIsClear);
356       }
357     }
358   }
359   return anActor;
360 }
361
362
363 void DisplayActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
364   if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
365     aViewFrame->AddActor(theActor);
366     aViewFrame->Repaint();
367   }
368 }
369
370
371 void RemoveActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
372   if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
373     aViewFrame->RemoveActor(theActor);
374     aViewFrame->Repaint();
375   }
376 }
377
378
379 void FitAll(){
380   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
381     aViewFrame->onViewFitAll();
382     aViewFrame->Repaint();
383   }
384 }
385
386 vtkRenderer* GetCurrentRenderer(){
387   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView())
388     return aViewFrame->getRenderer();
389   return NULL;
390 }
391
392 void RepaintCurrentView(){
393   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView())
394     aViewFrame->Repaint();
395 }
396
397
398 enum EDisplaing {eDisplayAll, eDisplay, eDisplayOnly, eErase, eEraseAll};
399 void UpdateView(QAD_StudyFrame *theStudyFrame, EDisplaing theAction,
400                 const char* theEntry = "")
401 {
402   if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
403     vtkRenderer *aRenderer = aViewFrame->getRenderer();
404     vtkActorCollection *aCollection = aRenderer->GetActors();
405     aCollection->InitTraversal();
406     switch(theAction){
407       case eDisplayAll: {
408         while(vtkActor *anAct = aCollection->GetNextActor()){
409           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
410             anActor->SetVisibility(true);
411           }
412         }
413         break;
414       }
415       case eDisplayOnly:
416       case eEraseAll: {
417         while(vtkActor *anAct = aCollection->GetNextActor()){
418           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
419             anActor->SetVisibility(false);
420           }
421         }
422       }
423       default: {
424         if(SMESH_Actor *anActor = FindActorByEntry(theStudyFrame,theEntry)){
425           switch(theAction) {
426             case eDisplay:
427             case eDisplayOnly:
428               anActor->SetVisibility(true);
429               break;
430             case eErase:
431               anActor->SetVisibility(false);
432               break;
433             }
434         } else {
435           switch(theAction){
436             case eDisplay:
437             case eDisplayOnly:{
438               QAD_Study* aStudy = theStudyFrame->getStudy();
439               SALOMEDS::Study_var aDocument = aStudy->getStudyDocument();
440               if(anActor = CreateActor(aDocument,theEntry,true)) {
441                 DisplayActor(theStudyFrame,anActor);
442                 FitAll();
443               }
444               break;
445             }
446           }
447         }
448       }
449     }
450   }
451 }
452
453
454 void UpdateView(EDisplaing theAction, const char* theEntry = ""){
455   QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
456   QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
457   UpdateView(aStudyFrame,theAction,theEntry);
458 }
459
460 static bool IsReferencedObject( SALOMEDS::SObject_ptr SO ) 
461 {
462   if ( !SO->_is_nil() ) {
463     SALOMEDS::GenericAttribute_var anAttr;
464     if ( SO->FindAttribute( anAttr, "AttributeTarget" ) ) {
465       SALOMEDS::AttributeTarget_var aTarget = SALOMEDS::AttributeTarget::_narrow( anAttr );
466       SALOMEDS::Study::ListOfSObject_var aList = aTarget->Get();
467       if ( aList->length() > 0 ) {
468         return true;
469       }
470     }
471   }
472   return false;
473 }
474
475 void SetPointRepresentation(bool theIsVisible){
476   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
477     vtkRenderer *aRenderer = aViewFrame->getRenderer();
478     vtkActorCollection *aCollection = aRenderer->GetActors();
479     aCollection->InitTraversal();
480     while(vtkActor *anAct = aCollection->GetNextActor()){
481       if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
482         if(anActor->GetVisibility()){
483           anActor->SetPointRepresentation(theIsVisible);
484         }
485       }
486     }
487     RepaintCurrentView();
488   }
489 }
490
491
492 //=============================================================================
493 /*!
494  *
495  */
496 //=============================================================================
497 class CustomItem:public QCustomMenuItem
498 {
499  public:
500   CustomItem(const QString & s, const QFont & f):string(s), font(f)
501   {
502   };
503   ~CustomItem()
504   {
505   }
506
507   void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
508              bool /*enabled */ , int x, int y, int w, int h)
509   {
510     p->setFont(font);
511     p->drawText(x, y, w, h,
512                 AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
513   }
514
515   QSize sizeHint()
516   {
517     return QFontMetrics(font).
518       size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
519   }
520  private:
521   QString string;
522   QFont font;
523 };
524
525 //=============================================================================
526 /*!
527  *
528  */
529 //=============================================================================
530 SMESHGUI::SMESHGUI():
531 QObject()
532 {
533 }
534
535 //=============================================================================
536 /*!
537  *
538  */
539 //=============================================================================
540 SMESHGUI::~SMESHGUI()
541 {
542 }
543
544 //=============================================================================
545 /*!
546  *
547  */
548 //=============================================================================
549 SMESHGUI* SMESHGUI::GetSMESHGUI()
550 {
551   if ( !smeshGUI )
552     GetOrCreateSMESHGUI( QAD_Application::getDesktop() );
553   return smeshGUI;
554 }
555
556 //=============================================================================
557 /*!
558  *
559  */
560 //=============================================================================
561 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
562 {
563   if( !smeshGUI ) {
564     setOrb();
565     smeshGUI = new SMESHGUI;
566     smeshGUI->myActiveDialogBox = 0 ;
567     smeshGUI->myState = -1 ;
568     smeshGUI->myDesktop = desktop ; 
569
570     /* get smesh engine */
571     Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
572     smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
573     
574     /* get geom engine */
575     Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");    
576     smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
577       
578     /* set current study */
579     smeshGUI->myActiveStudy = desktop->getActiveStudy();
580     smeshGUI->myStudyId     = smeshGUI->myActiveStudy->getStudyId();
581     smeshGUI->myStudy       = smeshGUI->myActiveStudy->getStudyDocument();
582     smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
583     smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
584     //    smeshGUI->myComponentGeom->NbLabels();
585     
586     /* create service object */
587     smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
588
589     smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
590
591     smeshGUI->mySimulationActors = vtkActorCollection::New();
592     smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
593
594     /*filter manager*/
595     smeshGUI->myFilterMgr = smeshGUI->myComponentMesh->CreateFilterManager();
596
597     /* load resources for all available meshers */
598     smeshGUI->InitAvailableHypotheses();
599   } else {
600     /* study may have changed - set current study */
601     smeshGUI->myActiveStudy = desktop->getActiveStudy();
602     smeshGUI->myStudyId     = smeshGUI->myActiveStudy->getStudyId();
603     smeshGUI->myStudy       = smeshGUI->myActiveStudy->getStudyDocument();
604     smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
605     smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
606     
607     // Set active study to Study API
608     smeshGUI->myStudyAPI.Update( smeshGUI->myStudy );
609   }
610   
611   /* Automatic Update flag */
612   smeshGUI->myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
613
614   return smeshGUI;
615 }
616
617 //=============================================================================
618 /*!
619  *
620  */
621 //=============================================================================
622 void SMESHGUI::SetState(int aState)
623 {
624   this->myState = aState;
625   return;
626 }
627
628 //=============================================================================
629 /*!
630  *
631  */
632 //=============================================================================
633 void SMESHGUI::ResetState()
634 {
635   this->myState = -1;
636   return;
637 }
638
639 //=============================================================================
640 /*!
641  *
642  */
643 //=============================================================================
644 void SMESHGUI::EmitSignalDeactivateDialog()
645 {
646   emit this->SignalDeactivateActiveDialog();
647   return;
648 }
649
650 //=============================================================================
651 /*!
652  *
653  */
654 //=============================================================================
655 void SMESHGUI::EmitSignalCloseAllDialogs()
656 {
657   emit SignalCloseAllDialogs();
658   return;
659 }
660
661 //=============================================================================
662 /*!
663  *
664  */
665 //=============================================================================
666 QDialog *SMESHGUI::GetActiveDialogBox()
667 {
668   return this->myActiveDialogBox;
669 }
670
671 //=============================================================================
672 /*!
673  *
674  */
675 //=============================================================================
676 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
677 {
678   this->myActiveDialogBox = (QDialog *) aDlg;
679   return;
680 }
681
682 //=============================================================================
683 /*!
684  *
685  */
686 //=============================================================================
687 QAD_Study *SMESHGUI::GetActiveStudy()
688 {
689   return this->myActiveStudy;
690 }
691
692 //=============================================================================
693 /*!
694  *
695  */
696 //=============================================================================
697 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
698 {
699   return SALOMEDS::Study::_narrow(myStudy);
700 }
701
702 //=============================================================================
703 /*!
704  *
705  */
706 //=============================================================================
707 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
708 {
709   return myStudyAPI;
710 }
711
712 //=============================================================================
713 /*!
714  *
715  */
716 //=============================================================================
717 QAD_Desktop *SMESHGUI::GetDesktop()
718 {
719   return this->myDesktop;
720 }
721
722 //=============================================================================
723 /*!
724  *
725  */
726 //=============================================================================
727 void SMESHGUI::activeStudyChanged(QAD_Desktop* parent)
728 {
729   MESSAGE("SMESHGUI::activeStudyChanged init.");
730   QAD_Study* prevStudy = 0;
731   if ( smeshGUI )
732     prevStudy = smeshGUI->myActiveStudy;
733   /* Create or retrieve an object SMESHGUI */
734   MESSAGE("Active study changed : prev study =" << prevStudy);
735   SMESHGUI::GetOrCreateSMESHGUI( parent );
736   MESSAGE("Active study changed : active study =" << smeshGUI->myActiveStudy);
737   if ( prevStudy != smeshGUI->myActiveStudy ) {
738     smeshGUI->EmitSignalCloseAllDialogs();
739     MESSAGE("Active study changed : SMESHGUI nullified" << endl);
740     //smeshGUI = 0;
741     ::UpdateSelectionProp();
742   }
743   MESSAGE("SMESHGUI::activeStudyChanged done.") return;
744 }
745
746 //=============================================================================
747 /*!
748  *
749  */
750 //=============================================================================
751 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
752 {
753   /* Here the position is on the bottom right corner - 10 */
754   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
755   aDlg->adjustSize();
756   QAD_Desktop *PP = QAD_Application::getDesktop();
757   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
758   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
759   return true;
760 }
761
762 //=============================================================================
763 /*!
764  *
765  */
766 //=============================================================================
767 void SMESHGUI::EraseSimulationActors()
768 {
769   if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
770   {                                                     //VTK
771     vtkRenderer *theRenderer =
772       ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
773        getRightFrame()->getViewFrame())->getRenderer();
774     vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
775
776     if (mySimulationActors != NULL)
777     {
778       mySimulationActors->InitTraversal();
779       vtkActor *ac = mySimulationActors->GetNextActor();
780       while (!(ac == NULL))
781       {
782         theRenderer->RemoveActor(ac);
783         ac = mySimulationActors->GetNextActor();
784       }
785       mySimulationActors->RemoveAllItems();
786     }
787     if (mySimulationActors2D != NULL)
788     {
789       mySimulationActors2D->InitTraversal();
790       vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
791       while (!(ac == NULL))
792       {
793         theRenderer->RemoveActor2D(ac);
794         ac = mySimulationActors2D->GetNextActor2D();
795       }
796       mySimulationActors2D->RemoveAllItems();
797     }
798     SetPointRepresentation(false);
799   }
800 }
801
802 //=============================================================================
803 /*!
804  *
805  */
806 //=============================================================================
807 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape,
808                                           QString              NameMesh )
809 {
810   try {
811     if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
812       SMESH::SMESH_Mesh_var aMesh = myComponentMesh->CreateMesh( aShape );
813       if ( !aMesh->_is_nil() ) {
814         SALOMEDS::SObject_var SM = smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( aMesh ) );
815         myStudyAPI.SetName( SM, NameMesh );
816         return SMESH::SMESH_Mesh::_narrow(aMesh);
817       }
818     }
819   }
820   catch( const SALOME::SALOME_Exception& S_ex ) {
821     QtCatchCorbaException( S_ex );
822   }
823   return SMESH::SMESH_Mesh::_nil();
824 }
825
826 //=============================================================================
827 /*!
828  *
829  */
830 //=============================================================================
831 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh,
832                                                GEOM::GEOM_Shape_ptr  aShape,
833                                                QString               NameMesh )
834 {
835   SMESH::SMESH_subMesh_var aSubMesh;
836   try {
837     if ( !aMesh->_is_nil() && !aShape->_is_nil() )
838       // create sub mesh
839       aSubMesh = SMESH::SMESH_subMesh::_duplicate( aMesh->GetSubMesh( aShape, NameMesh.latin1() ) ); //VSR: published automatically
840   }
841   catch( const SALOME::SALOME_Exception& S_ex ) {
842     QtCatchCorbaException( S_ex );
843     aSubMesh = SMESH::SMESH_subMesh::_nil();
844   }
845   return aSubMesh._retn();
846 }
847
848 //=============================================================================
849 /*!
850  *
851  */
852 //=============================================================================
853 SMESH::SMESH_Group_ptr SMESHGUI::AddGroup( SMESH::SMESH_Mesh_ptr    aMesh,
854                                            SMESH::ElementType       aType,
855                                            QString                  aName )
856 {
857   SMESH::SMESH_Group_var aGroup;
858   try {
859     if ( !aMesh->_is_nil() )
860       // create group
861       aGroup = SMESH::SMESH_Group::_duplicate( aMesh->CreateGroup( aType, strdup(aName) ) ); //VSR: published automatically
862   }
863   catch( const SALOME::SALOME_Exception& S_ex ) {
864     QtCatchCorbaException( S_ex );
865     aGroup = SMESH::SMESH_Group::_nil();
866   }
867   myActiveStudy->updateObjBrowser( true );
868   return aGroup._retn();
869 }
870
871 //=============================================================================
872 /*!
873  *
874  */
875 //=============================================================================
876
877 static void addMap( const map<string, HypothesisData*>& theMap,
878                    map<string, HypothesisData*>&       toMap)
879 {
880   map<string, HypothesisData*>::const_iterator it;
881   for ( it = theMap.begin(); it != theMap.end(); it++ )
882     toMap.insert( *it );
883 }
884
885     
886 //=============================================================================
887 /*!
888  *  InitAvailableHypotheses (read from resource XML file)
889  */
890 //=============================================================================
891 void SMESHGUI::InitAvailableHypotheses ()
892 {
893   QAD_WaitCursor wc;
894   if ((myHypothesesMap.begin() == myHypothesesMap.end()) &&
895       (myAlgorithmsMap.begin() == myAlgorithmsMap.end()))
896   {
897     // Resource manager
898     QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
899     if (!resMgr) return;
900
901     // Find name of a resource XML file ("SMESH_Meshers.xml");
902     QString HypsXml;
903     char* cenv = getenv("SMESH_MeshersList");
904     if (cenv)
905       HypsXml.sprintf("%s", cenv);
906
907     QStringList HypsXmlList = QStringList::split( ":", HypsXml, false );
908     if (HypsXmlList.count() == 0)
909     {
910       QAD_MessageBox::error1(QAD_Application::getDesktop(),
911                              tr("SMESH_WRN_WARNING"),
912                              tr("MESHERS_FILE_NO_VARIABLE"),
913                              tr("SMESH_BUT_OK"));
914       return;
915     }
916
917     // loop on files in HypsXml
918     QString aNoAccessFiles;
919     for ( int i = 0; i < HypsXmlList.count(); i++ ) {
920       QString HypsXml = HypsXmlList[ i ];
921
922       // Find full path to the resource XML file
923       QString xmlFile = HypsXml + ".xml";
924       xmlFile = QAD_Tools::addSlash(resMgr->findFile(xmlFile, HypsXml)) + xmlFile;
925
926       QFile file (QAD_Tools::unix2win(xmlFile));
927       if (file.exists() && file.open(IO_ReadOnly))
928       {
929         file.close();
930
931         SMESHGUI_XmlHandler* myXmlHandler = new SMESHGUI_XmlHandler();
932         ASSERT(myXmlHandler);
933
934         QXmlInputSource source (file);
935         QXmlSimpleReader reader;
936         reader.setContentHandler(myXmlHandler);
937         reader.setErrorHandler(myXmlHandler);
938         bool ok = reader.parse(source);
939         file.close();
940         if (ok)
941         {
942           addMap( myXmlHandler->myHypothesesMap, myHypothesesMap );
943           addMap( myXmlHandler->myAlgorithmsMap, myAlgorithmsMap );
944         }
945         else
946         {
947           QAD_MessageBox::error1(myDesktop, 
948                                  tr("INF_PARSE_ERROR"),
949                                  tr(myXmlHandler->errorProtocol()),
950                                  tr("SMESH_BUT_OK"));
951         }
952       }
953       else
954       {
955         if (aNoAccessFiles.isEmpty())
956           aNoAccessFiles = xmlFile;
957         else
958           aNoAccessFiles += ", " + xmlFile;
959       }
960     } // end loop
961
962
963     if (!aNoAccessFiles.isEmpty())
964     {
965       QString aMess = tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
966       aMess += tr("MESHERS_FILE_CHECK_VARIABLE");
967       wc.stop();
968       QAD_MessageBox::warn1(QAD_Application::getDesktop(),
969                             tr("SMESH_WRN_WARNING"),
970                             aMess,
971                             tr("SMESH_BUT_OK"));
972       wc.start();
973     }
974   }
975 }
976
977 //=============================================================================
978 /*!
979  *  GetAvailableHypotheses (read from resource XML file)
980  */
981 //=============================================================================
982 QStringList SMESHGUI::GetAvailableHypotheses (const bool isAlgo)
983 {
984   QStringList aHypList;
985
986   // Init list of available hypotheses, if needed
987   InitAvailableHypotheses();
988
989   // fill list of hypotheses/algorithms
990   map<string, HypothesisData*>::iterator anIter;
991   if (isAlgo)
992   {
993     anIter = myAlgorithmsMap.begin();
994     for (; anIter != myAlgorithmsMap.end(); anIter++)
995     {
996       aHypList.append(((*anIter).first).c_str());
997     }
998   }
999   else
1000   {
1001     anIter = myHypothesesMap.begin();
1002     for (; anIter != myHypothesesMap.end(); anIter++)
1003     {
1004       aHypList.append(((*anIter).first).c_str());
1005     }
1006   }
1007
1008   return aHypList;
1009 }
1010
1011 //=============================================================================
1012 /*!
1013  *  GetHypothesisData
1014  */
1015 //=============================================================================
1016 HypothesisData* SMESHGUI::GetHypothesisData (const char* aHypType)
1017 {
1018   HypothesisData* aHypData = 0;
1019
1020   // Init list of available hypotheses, if needed
1021   InitAvailableHypotheses();
1022
1023   if (myHypothesesMap.find(aHypType) == myHypothesesMap.end())
1024   {
1025     if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end())
1026     {
1027       aHypData = myAlgorithmsMap[aHypType];
1028     }
1029   }
1030   else
1031   {
1032     aHypData = myHypothesesMap[aHypType];
1033   }
1034   return aHypData;
1035 }
1036
1037 //=============================================================================
1038 /*! 
1039  *  Get a Hypothesis Creator from a Plugin Library
1040  */
1041 //=============================================================================
1042 SMESHGUI_GenericHypothesisCreator* SMESHGUI::GetHypothesisCreator(const QString& aHypType)
1043 {
1044   char* sHypType = (char*)aHypType.latin1();
1045   MESSAGE("Get HypothesisCreator for " << sHypType);
1046
1047   SMESHGUI_GenericHypothesisCreator* aCreator = 0;
1048
1049   // check, if creator for this hypothesis type already exists
1050   if (myHypCreatorMap.find(sHypType) != myHypCreatorMap.end())
1051   {
1052     aCreator = myHypCreatorMap[sHypType];
1053   }
1054   else
1055   {
1056     // 1. Init list of available hypotheses, if needed
1057     InitAvailableHypotheses();
1058
1059     // 2. Get names of plugin libraries
1060     HypothesisData* aHypData = GetHypothesisData(sHypType);
1061     if (!aHypData)
1062     {
1063       return aCreator;
1064     }
1065     QString aClientLibName = aHypData->ClientLibName;
1066     QString aServerLibName = aHypData->ServerLibName;
1067
1068     // 3. Load Client Plugin Library
1069     try
1070     {
1071       // load plugin library
1072       MESSAGE("Loading client meshers plugin library ...");
1073       void* libHandle = dlopen (aClientLibName, RTLD_LAZY);
1074       if (!libHandle)
1075       {
1076         // report any error, if occured
1077         const char* anError = dlerror();
1078         MESSAGE(anError);
1079       }
1080       else
1081       {
1082         // get method, returning hypothesis creator
1083         MESSAGE("Find GetHypothesisCreator() method ...");
1084         typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
1085           (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI);
1086         GetHypothesisCreator procHandle =
1087           (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
1088         if (!procHandle)
1089         {
1090           MESSAGE("bad hypothesis client plugin library");
1091           dlclose(libHandle);
1092         }
1093         else
1094         {
1095           // get hypothesis creator
1096           MESSAGE("Get Hypothesis Creator for " << aHypType);
1097           aCreator = procHandle(aHypType, aServerLibName, smeshGUI);
1098           if (!aCreator)
1099           {
1100             MESSAGE("no such a hypothesis in this plugin");
1101           }
1102           else
1103           {
1104             // map hypothesis creator to a hypothesis name
1105             myHypCreatorMap[sHypType] = aCreator;
1106           }
1107         }
1108       }
1109     }
1110     catch (const SALOME::SALOME_Exception& S_ex)
1111     {
1112       QtCatchCorbaException(S_ex);
1113     }
1114   }
1115
1116   return aCreator;
1117 }
1118
1119 //=============================================================================
1120 /*!
1121  *
1122  */
1123 //=============================================================================
1124 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis (const QString& aHypType,
1125                                                         const QString& aHypName,
1126                                                         const bool     isAlgo)
1127 {
1128   MESSAGE("Create " << aHypType << " with name " << aHypName);
1129
1130   SMESH::SMESH_Hypothesis_var Hyp;
1131
1132   HypothesisData* aHypData = GetHypothesisData((char*)aHypType.latin1());
1133   QString aServLib = aHypData->ServerLibName;
1134
1135   try
1136   {
1137     Hyp = myComponentMesh->CreateHypothesis(aHypType, aServLib);
1138     if (!Hyp->_is_nil())
1139     {
1140       SALOMEDS::SObject_var SHyp =
1141         smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( Hyp ) );
1142       if (!SHyp->_is_nil())
1143       {
1144         if ( !aHypName.isEmpty() )
1145           myStudyAPI.SetName( SHyp, aHypName );
1146         myActiveStudy->updateObjBrowser(true);
1147         return Hyp._retn();
1148       }
1149     }
1150   }
1151   catch (const SALOME::SALOME_Exception & S_ex)
1152   {
1153     QtCatchCorbaException(S_ex);
1154   }
1155
1156   return SMESH::SMESH_Hypothesis::_nil();
1157 }
1158
1159 //=============================================================================
1160 /*!
1161  *
1162  */
1163 //=============================================================================
1164 bool SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
1165                                    SMESH::SMESH_Hypothesis_ptr aHyp)
1166 {
1167   int res = SMESH::HYP_UNKNOWN_FATAL; 
1168   QAD_WaitCursor wc;
1169
1170   if ( !aMesh->_is_nil() ) {
1171     SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1172     GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
1173     try {
1174       res = aMesh->AddHypothesis( aShape, aHyp );
1175       if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1176         SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1177         if ( !SM->_is_nil() && !SH->_is_nil() ) {
1178           //myStudyAPI.SetHypothesis(SM, SH); // VSR: published automatically by engine
1179           myStudyAPI.ModifiedMesh(SM, false);
1180         }
1181       }
1182       if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1183         wc.stop();
1184         QAD_MessageBox::error1(QAD_Application::getDesktop(),
1185                               tr("SMESH_ERROR"),
1186                               tr(QString("SMESH_HYP_%1").arg(res)),
1187                               tr("SMESH_BUT_OK"));
1188         wc.start();
1189       }
1190       else if ( res > SMESH::HYP_OK ) {
1191         wc.stop();
1192         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1193                               tr("SMESH_WRN_WARNING"),
1194                               tr(QString("SMESH_HYP_%1").arg(res)),
1195                               tr("SMESH_BUT_OK"));
1196         wc.start();
1197       }
1198     }
1199     catch( const SALOME::SALOME_Exception& S_ex ) {
1200       wc.stop();
1201       QtCatchCorbaException( S_ex );
1202       res = SMESH::HYP_UNKNOWN_FATAL;
1203     }
1204   }
1205   return res < SMESH::HYP_UNKNOWN_FATAL;
1206 }
1207
1208 //=============================================================================
1209 /*!
1210  *
1211  */
1212 //=============================================================================
1213 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh
1214                (const Handle(SALOME_InteractiveObject)& IObject)
1215 {
1216   int res = SMESH::HYP_UNKNOWN_FATAL;
1217   QAD_WaitCursor wc;
1218
1219   if (IObject->hasReference())
1220   {
1221     try {
1222       SMESH::SMESH_Hypothesis_var anHyp;
1223       SALOMEDS::SObject_var SO_Hypothesis =
1224         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
1225       SALOMEDS::GenericAttribute_var anAttr;
1226       SALOMEDS::AttributeIOR_var anIOR;
1227
1228       if (!SO_Hypothesis->_is_nil()) {
1229         if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
1230           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1231           anHyp = SMESH::SMESH_Hypothesis::_narrow
1232             (_orb->string_to_object(anIOR->Value()));
1233         }
1234
1235         SALOMEDS::SObject_var SO_Applied_Hypothesis =
1236           smeshGUI->myStudy->FindObjectID(IObject->getReference());
1237         if (!SO_Applied_Hypothesis->_is_nil()) {
1238           SALOMEDS::SObject_var MorSM =
1239             smeshGUI->myStudyAPI.GetMeshOrSubmesh(SO_Applied_Hypothesis);
1240           if (!MorSM->_is_nil()) {
1241             GEOM::GEOM_Shape_var aShape =
1242               smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1243             if (!aShape->_is_nil() && MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1244               anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1245               SMESH::SMESH_Mesh_var aMesh =
1246                 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1247               SMESH::SMESH_subMesh_var aSubMesh =
1248                 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1249
1250               if (!aSubMesh->_is_nil())
1251                 aMesh = aSubMesh->GetFather();
1252
1253               if (!aMesh->_is_nil())
1254               {
1255                 res = aMesh->RemoveHypothesis(aShape, anHyp);
1256                 if ( res < SMESH::HYP_UNKNOWN_FATAL )
1257                   smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1258                 if ( res > SMESH::HYP_OK ) {
1259                   wc.stop();
1260                   QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1261                                         tr("SMESH_WRN_WARNING"),
1262                                         tr(QString("SMESH_HYP_%1").arg(res)),
1263                                         tr("SMESH_BUT_OK"));
1264                   wc.start();
1265                 }
1266               }
1267             }
1268           }
1269         }
1270       }
1271     }
1272     catch( const SALOME::SALOME_Exception& S_ex ) {
1273       wc.stop();
1274       QtCatchCorbaException( S_ex );
1275       res = SMESH::HYP_UNKNOWN_FATAL;
1276     }
1277   }
1278   else if (IObject->hasEntry())
1279   {
1280     MESSAGE("IObject entry " << IObject->getEntry());
1281   }
1282   return res < SMESH::HYP_UNKNOWN_FATAL;
1283 }
1284
1285 //=============================================================================
1286 /*!
1287  *
1288  */
1289 //=============================================================================
1290 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
1291         SMESH::SMESH_Hypothesis_ptr anHyp)
1292 {
1293   SALOMEDS::SObject_var AHR, aRef;
1294   SALOMEDS::GenericAttribute_var anAttr;
1295   SALOMEDS::AttributeIOR_var anIOR;
1296   int res = SMESH::HYP_UNKNOWN_FATAL;
1297   QAD_WaitCursor wc;
1298
1299   if (!MorSM->_is_nil()) {
1300     try {
1301       GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1302       if (!aShape->_is_nil()) {
1303         if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1304           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1305           SMESH::SMESH_Mesh_var aMesh =
1306             SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1307           SMESH::SMESH_subMesh_var aSubMesh =
1308             SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1309           
1310           if ( !aSubMesh->_is_nil() )
1311             aMesh = aSubMesh->GetFather();
1312           
1313           if (!aMesh->_is_nil()) {
1314             res = aMesh->RemoveHypothesis(aShape, anHyp);
1315             if ( res < SMESH::HYP_UNKNOWN_FATAL )
1316               smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1317             if ( res > SMESH::HYP_OK ) {
1318               wc.stop();
1319               QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1320                                     tr("SMESH_WRN_WARNING"),
1321                                     tr(QString("SMESH_HYP_%1").arg(res)),
1322                                     tr("SMESH_BUT_OK"));
1323               wc.start();
1324             }
1325           }
1326         }
1327       }
1328     }
1329     catch( const SALOME::SALOME_Exception& S_ex ) {
1330       wc.stop();
1331       QtCatchCorbaException( S_ex );
1332       res = SMESH::HYP_UNKNOWN_FATAL;
1333     }
1334   }
1335   return res < SMESH::HYP_UNKNOWN_FATAL;
1336 }
1337
1338 //=============================================================================
1339 /*!
1340  *
1341  */
1342 //=============================================================================
1343 bool SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr       aMesh,
1344                                    SMESH::SMESH_Hypothesis_ptr aHyp )
1345 {
1346   int res = SMESH::HYP_UNKNOWN_FATAL;
1347   QAD_WaitCursor wc;
1348
1349   if ( !aMesh->_is_nil() ) {
1350     SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1351     GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
1352     try {
1353       res = aMesh->AddHypothesis( aShape, aHyp );
1354       if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1355         //SALOMEDS::SObject_var SH = myStudyAPI.FindObject( aHyp );
1356         //if ( !SM->_is_nil() && !SH->_is_nil() ) {
1357           //myStudyAPI.SetAlgorithms(SM, SH);
1358         myStudyAPI.ModifiedMesh( SM, false );
1359         //}
1360       }
1361       if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1362         wc.stop();
1363         QAD_MessageBox::error1(QAD_Application::getDesktop(),
1364                               tr("SMESH_ERROR"),
1365                               tr(QString("SMESH_HYP_%1").arg(res)),
1366                               tr("SMESH_BUT_OK"));
1367         wc.start();
1368       }
1369       else if ( res > SMESH::HYP_OK ) {
1370         wc.stop();
1371         QAD_MessageBox::warn1( QAD_Application::getDesktop(),
1372                                tr( "SMESH_WRN_WARNING" ),
1373                                tr(QString("SMESH_HYP_%1").arg(res)),
1374                                tr( "SMESH_BUT_OK" ) );
1375         wc.start();
1376       }
1377     }
1378     catch( const SALOME::SALOME_Exception& S_ex ) {
1379       wc.stop();
1380       QtCatchCorbaException( S_ex );
1381       res = SMESH::HYP_UNKNOWN_FATAL;
1382     }
1383   }
1384   return res < SMESH::HYP_UNKNOWN_FATAL;
1385 }
1386
1387 //=============================================================================
1388 /*!
1389  *
1390  */
1391 //=============================================================================
1392 bool SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr    aSubMesh,
1393                                        SMESH::SMESH_Hypothesis_ptr aHyp )
1394 {
1395   int res = SMESH::HYP_UNKNOWN_FATAL;
1396   QAD_WaitCursor wc;
1397
1398   if ( !aSubMesh->_is_nil() ) {
1399     try {
1400       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1401       SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject( aSubMesh );
1402       GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
1403       if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1404         res = aMesh->AddHypothesis( aShape, aHyp );
1405         if ( res < SMESH::HYP_UNKNOWN_FATAL )  {
1406           //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1407           //                    if (!SsubM->_is_nil() && !SH->_is_nil())
1408           //                    {
1409           //                            myStudyAPI.SetHypothesis(SsubM, SH);
1410           myStudyAPI.ModifiedMesh( SsubM, false );
1411           //                    }
1412         }
1413         if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1414           wc.stop();
1415           QAD_MessageBox::error1(QAD_Application::getDesktop(),
1416                                  tr("SMESH_ERROR"),
1417                                  tr(QString("SMESH_HYP_%1").arg(res)),
1418                                  tr("SMESH_BUT_OK"));
1419           wc.start();
1420         }
1421         else if ( res > SMESH::HYP_OK ) {
1422           wc.stop();
1423           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1424                                 tr( "SMESH_WRN_WARNING" ),
1425                                 tr(QString("SMESH_HYP_%1").arg(res)),
1426                                 tr( "SMESH_BUT_OK" ) );
1427           wc.start();
1428         }
1429       }
1430     }
1431     catch( const SALOME::SALOME_Exception& S_ex ) {
1432       wc.stop();
1433       QtCatchCorbaException( S_ex );
1434       res = SMESH::HYP_UNKNOWN_FATAL;
1435     }
1436   }
1437   return res < SMESH::HYP_UNKNOWN_FATAL;
1438 }
1439
1440 //=============================================================================
1441 /*!
1442  *
1443  */
1444 //=============================================================================
1445 bool SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr    aSubMesh,
1446                                       SMESH::SMESH_Hypothesis_ptr aHyp )
1447 {
1448   int res = SMESH::HYP_UNKNOWN_FATAL;
1449   QAD_WaitCursor wc;
1450
1451   if ( !aSubMesh->_is_nil() ) {
1452     try {
1453       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1454       SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject(aSubMesh);
1455       GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
1456       if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1457         res = aMesh->AddHypothesis( aShape, aHyp );
1458         if ( res < SMESH::HYP_UNKNOWN_FATAL )  {
1459           //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1460           //if (!SsubM->_is_nil() && !SH->_is_nil()) {
1461           //myStudyAPI.SetAlgorithms(SsubM, SH);
1462           myStudyAPI.ModifiedMesh( SsubM, false );
1463           //}
1464         }
1465         if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1466           wc.stop();
1467           QAD_MessageBox::error1(QAD_Application::getDesktop(),
1468                                  tr("SMESH_ERROR"),
1469                                  tr(QString("SMESH_HYP_%1").arg(res)),
1470                                  tr("SMESH_BUT_OK"));
1471           wc.start();
1472         }
1473         else if ( res > SMESH::HYP_OK ) {
1474           wc.stop();
1475           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1476                                 tr( "SMESH_WRN_WARNING" ),
1477                                 tr(QString("SMESH_HYP_%1").arg(res)),
1478                                 tr( "SMESH_BUT_OK" ) );
1479           wc.start();
1480         }
1481       }
1482     }
1483     catch( const SALOME::SALOME_Exception& S_ex ) {
1484       wc.stop();
1485       QtCatchCorbaException( S_ex );
1486       res = SMESH::HYP_UNKNOWN_FATAL;
1487     }
1488   }
1489   return res < SMESH::HYP_UNKNOWN_FATAL;
1490 }
1491
1492 //=============================================================================
1493 /*!
1494  *
1495  */
1496 //=============================================================================
1497 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1498 {
1499         int nbSel = Sel->IObjectCount();
1500         if (nbSel == 1)
1501         {
1502                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1503                 aName = IObject->getName();
1504         }
1505         else
1506         {
1507                 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1508         }
1509         return nbSel;
1510 }
1511
1512 //=============================================================================
1513 /*!
1514  *
1515  */
1516 //=============================================================================
1517 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName){
1518   aName = "";
1519   if(Sel->IObjectCount() == 1){
1520     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1521     if(IObject->hasEntry()){
1522       if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1523         TColStd_MapOfInteger MapIndex;
1524         Sel->GetIndex(IObject, MapIndex);
1525         TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1526         for(; ite.More(); ite.Next()){
1527           aName += QString(" %1").arg(anActor->GetNodeObjId(ite.Key()));
1528         }
1529         return MapIndex.Extent();
1530       }
1531     }
1532   }
1533   return -1;
1534 }
1535
1536 //=============================================================================
1537 /*!
1538  *
1539  */
1540 //=============================================================================
1541 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName){
1542   aName = "";
1543   if(Sel->IObjectCount() == 1){
1544     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1545     if(IObject->hasEntry()){
1546       if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1547         TColStd_MapOfInteger MapIndex;
1548         Sel->GetIndex(IObject, MapIndex);
1549         TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1550         std::vector<int> aList;
1551         for(; ite.More(); ite.Next()){
1552           int aVtkId = ite.Key();
1553           int anObjId = anActor->GetElemObjId(aVtkId);
1554           std::vector<int>::iterator found = find(aList.begin(), aList.end(), anObjId);
1555           //      MESSAGE("GetNameOfSelectedElements(): VTK Id = " << aVtkId << ", OBJECT Id = " << anObjId);
1556           if (found == aList.end()) {
1557             aList.push_back(anObjId);
1558             aName += QString(" %1").arg(anObjId);
1559           }
1560         }
1561         return aList.size();
1562       }
1563     }
1564   }
1565   return -1;
1566 }
1567
1568
1569 //=============================================================================
1570 /*!
1571  *
1572  */
1573 //=============================================================================
1574 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName){
1575   aName = "";
1576   if(Sel->IObjectCount() == 1){
1577     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1578     if(IObject->hasEntry()){
1579       if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1580         TColStd_MapOfInteger MapIndex;
1581         Sel->GetIndex(IObject, MapIndex);
1582         TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1583         for(; ite.More(); ite.Next()){
1584           aName += QString(" %1").arg(ite.Key());
1585         }
1586         return MapIndex.Extent();
1587       }
1588     }
1589   }
1590   return -1;
1591 }
1592
1593
1594 //=============================================================================
1595 /*!
1596  *
1597  */
1598 //=============================================================================
1599 SMESH_Actor *SMESHGUI::FindActorByEntry(QString theEntry,
1600                                         Standard_Boolean & theResult, 
1601                                         bool onlyInActiveView)
1602 {
1603   theResult = false;
1604   int aNbStudyFrames = myActiveStudy->getStudyFramesCount();
1605   for (int i = 0; i < aNbStudyFrames; i++){
1606     QAD_StudyFrame *aStudyFrame = myActiveStudy->getStudyFrame(i);
1607     if(SMESH_Actor *anActor = ::FindActorByEntry(aStudyFrame,theEntry.latin1())){
1608       theResult = true;
1609       return anActor;
1610     }
1611   }
1612   return NULL;
1613 }
1614
1615 //=============================================================================
1616 /*!
1617  *
1618  */
1619 //=============================================================================
1620 SMESH_Actor* SMESHGUI::FindActor(CORBA::Object_ptr theObj,
1621                                  Standard_Boolean & theResult, 
1622                                  bool theOnlyInActiveView)
1623 {
1624   theResult = false;
1625   SMESH_Actor* aRes = NULL;
1626   if ( !CORBA::is_nil( theObj ) ) {
1627     SALOMEDS::SObject_var aSObject = SALOMEDS::SObject::_narrow( myStudy->FindObjectIOR( _orb->object_to_string( theObj ) ) );
1628     if( !aSObject->_is_nil()) {
1629       CORBA::String_var anEntry = aSObject->GetID();
1630       aRes = FindActorByEntry( anEntry.in(), theResult, theOnlyInActiveView );
1631     }
1632   }
1633   return aRes;
1634 }
1635
1636 //=============================================================================
1637 /*!
1638  *
1639  */
1640 //=============================================================================
1641 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1642                                                 Standard_Boolean & testResult)
1643 {
1644   SMESH::SMESH_Mesh_var aMesh;
1645   testResult = false;
1646
1647   /* case SObject */
1648   if (IO->hasEntry())
1649   {
1650     SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1651     SALOMEDS::GenericAttribute_var anAttr;
1652     SALOMEDS::AttributeIOR_var anIOR;
1653     if (!obj->_is_nil())
1654     {
1655       if (obj->FindAttribute(anAttr, "AttributeIOR"))
1656       {
1657         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1658         aMesh =
1659           SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1660         if (!aMesh->_is_nil())
1661         {
1662           testResult = true;
1663           return SMESH::SMESH_Mesh::_duplicate(aMesh);
1664         }
1665       }
1666     }
1667   }
1668   return SMESH::SMESH_Mesh::_nil();
1669 }
1670
1671 //=============================================================================
1672 /*!
1673  *
1674  */
1675 //=============================================================================
1676 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1677                                                       Standard_Boolean & testResult)
1678 {
1679   SMESH::SMESH_subMesh_var aSubMesh;
1680   testResult = false;
1681
1682   /* case SObject */
1683   if (IO->hasEntry())
1684   {
1685     SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1686     SALOMEDS::GenericAttribute_var anAttr;
1687     SALOMEDS::AttributeIOR_var anIOR;
1688     if (!obj->_is_nil())
1689     {
1690       if (obj->FindAttribute(anAttr, "AttributeIOR"))
1691       {
1692         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1693         aSubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1694         if (!aSubMesh->_is_nil())
1695         {
1696           testResult = true;
1697           return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1698         }
1699       }
1700     }
1701   }
1702   return SMESH::SMESH_subMesh::_nil();
1703 }
1704
1705 //=============================================================================
1706 /*!
1707  *
1708  */
1709 //=============================================================================
1710 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1711                                                                  Standard_Boolean & testResult)
1712 {
1713   SMESH::SMESH_Hypothesis_var aHyp;
1714   testResult = false;
1715
1716   /* case SObject */
1717   if (IO->hasEntry())
1718   {
1719     SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1720     SALOMEDS::GenericAttribute_var anAttr;
1721     SALOMEDS::AttributeIOR_var anIOR;
1722     if (!obj->_is_nil())
1723     {
1724       if (obj->FindAttribute(anAttr, "AttributeIOR"))
1725       {
1726         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1727         aHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1728         if (!aHyp->_is_nil())
1729         {
1730           testResult = true;
1731           return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1732         }
1733       }
1734     }
1735   }
1736   return SMESH::SMESH_Hypothesis::_nil();
1737 }
1738
1739 //=============================================================================
1740 /*!
1741  *
1742  */
1743 //=============================================================================
1744 SMESH::SMESH_Group_ptr SMESHGUI::ConvertIOinSMESHGroup(const Handle(SALOME_InteractiveObject) & IO,
1745                                                        Standard_Boolean & testResult)
1746 {
1747   SMESH::SMESH_Group_var aGroup;
1748   testResult = false;
1749
1750   /* case SObject */
1751   if (IO->hasEntry()) {
1752     SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1753     SALOMEDS::GenericAttribute_var anAttr;
1754     SALOMEDS::AttributeIOR_var anIOR;
1755     if (!obj->_is_nil()) {
1756       if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1757         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1758         aGroup = SMESH::SMESH_Group::_narrow(_orb->string_to_object(anIOR->Value()));
1759         if (!aGroup->_is_nil()) {
1760           testResult = true;
1761           return SMESH::SMESH_Group::_duplicate(aGroup);
1762         }
1763       }
1764     }
1765   }
1766   return SMESH::SMESH_Group::_nil();
1767 }
1768
1769 //=============================================================================
1770 /*!
1771  *
1772  */
1773 //=============================================================================
1774 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1775                                                     Standard_Boolean & testResult)
1776 {
1777   GEOM::GEOM_Shape_var aShape;
1778   testResult = false;
1779
1780   /* case SObject */
1781   if (IO->hasEntry()) {
1782     SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1783     SALOMEDS::GenericAttribute_var anAttr;
1784     SALOMEDS::AttributeIOR_var anIOR;
1785     if (!obj->_is_nil()) {
1786       if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1787         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1788         aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1789         if (!aShape->_is_nil()) {
1790           testResult = true;
1791           return GEOM::GEOM_Shape::_duplicate(aShape);
1792         }
1793       }
1794     }
1795   }
1796   return GEOM::GEOM_Shape::_nil();
1797 }
1798
1799 //=============================================================================
1800 /*!
1801  *
1802  */
1803 //=============================================================================
1804 void SMESHGUI::SetViewMode(int commandId){
1805   SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1806   if(Sel->IObjectCount() >= 1){
1807     SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1808     for(; It.More(); It.Next()){
1809       Handle(SALOME_InteractiveObject) IObject = It.Value();
1810       if(IObject->hasEntry()){
1811         if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1812           switch(commandId){
1813           case 211:
1814             ChangeRepresentation(anActor,0);
1815             break;
1816           case 212:
1817             ChangeRepresentation(anActor,1);
1818             break;
1819           case 213:
1820             ChangeRepresentation(anActor,2);
1821             break;
1822           case 215:
1823             ChangeRepresentation(anActor,5);
1824             break;
1825           case 1132:
1826             ChangeRepresentation(anActor,3);
1827             break;
1828           }
1829         }
1830       }
1831     }
1832     if(commandId == 1133)
1833       ChangeRepresentation(NULL,4);
1834   }
1835 }
1836
1837 //=============================================================================
1838 /*!
1839  *
1840  */
1841 //=============================================================================
1842 void SMESHGUI::ChangeRepresentation(SMESH_Actor * theActor, int type){
1843   switch (type){
1844   case 0:{
1845     //theActor->UnShrink();
1846     theActor->SetRepresentation(SMESH_Actor::eEdge);
1847     break;
1848   }
1849   case 1:{
1850     //theActor->UnShrink();
1851     theActor->SetRepresentation(SMESH_Actor::eSurface);
1852     break;
1853   }
1854   case 2:{
1855     theActor->IsShrunk() ? theActor->UnShrink() : theActor->SetShrink();
1856     //theActor->SetRepresentation(SMESH_Actor::eSurface);
1857     break;
1858   }
1859   case 5:{
1860     //theActor->UnShrink();
1861     theActor->SetRepresentation(SMESH_Actor::ePoint);
1862     break;
1863   }
1864   case 3:{
1865     float color[3];
1866     theActor->GetSufaceColor(color[0], color[1], color[2]);
1867     int c0 = int (color[0] * 255);
1868     int c1 = int (color[1] * 255);
1869     int c2 = int (color[2] * 255);
1870     QColor c(c0, c1, c2);
1871
1872     float edgecolor[3];
1873     theActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1874     c0 = int (edgecolor[0] * 255);
1875     c1 = int (edgecolor[1] * 255);
1876     c2 = int (edgecolor[2] * 255);
1877     QColor e(c0, c1, c2);
1878
1879     float backfacecolor[3];
1880     theActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
1881     c0 = int (backfacecolor[0] * 255);
1882     c1 = int (backfacecolor[1] * 255);
1883     c2 = int (backfacecolor[2] * 255);
1884     QColor b(c0, c1, c2);
1885
1886     float nodecolor[3];
1887     theActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1888     c0 = int (nodecolor[0] * 255);
1889     c1 = int (nodecolor[1] * 255);
1890     c2 = int (nodecolor[2] * 255);
1891     QColor n(c0, c1, c2);
1892
1893     int Edgewidth = (int)theActor->GetLineWidth();
1894     if(Edgewidth == 0)
1895       Edgewidth = 1;
1896     int intValue = int(theActor->GetNodeSize());
1897     float Shrink = theActor->GetShrinkFactor();
1898
1899     SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),"");
1900     aDlg->SetColor(1, c);
1901     aDlg->SetColor(2, e);
1902     aDlg->SetColor(3, n);
1903     aDlg->SetColor(4, b);
1904     aDlg->SetIntValue(1, Edgewidth);
1905     aDlg->SetIntValue(2, intValue);
1906     aDlg->SetIntValue(3, int(Shrink*100.));
1907     if(aDlg->exec()){
1908       QColor color = aDlg->GetColor(1);
1909       QColor edgecolor = aDlg->GetColor(2);
1910       QColor nodecolor = aDlg->GetColor(3);
1911       QColor backfacecolor = aDlg->GetColor(4);
1912       /* actor color and backface color */
1913       theActor->SetSufaceColor(float (color.red()) / 255.,
1914                                float (color.green()) / 255., 
1915                                float (color.blue()) / 255.);
1916       theActor->SetBackSufaceColor(float (backfacecolor.red()) / 255., 
1917                                    float (backfacecolor.green()) / 255.,
1918                                    float (backfacecolor.blue()) / 255.);
1919
1920       /* edge color */
1921       theActor->SetEdgeColor(float (edgecolor.red()) / 255.,
1922                              float (edgecolor.green()) / 255.,
1923                              float (edgecolor.blue()) / 255.);
1924       
1925       /* Shrink factor and size edges */
1926       theActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1927       theActor->SetLineWidth(aDlg->GetIntValue(1));
1928       
1929       /* Nodes color and size */
1930       theActor->SetNodeColor(float (nodecolor.red()) / 255.,
1931                              float (nodecolor.green()) / 255.,
1932                              float (nodecolor.blue()) / 255.);
1933       theActor->SetNodeSize(aDlg->GetIntValue(2));
1934
1935       delete aDlg;
1936     }
1937     break;
1938   }
1939   case 4:{
1940     EmitSignalDeactivateDialog();
1941     SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false);
1942     break;
1943   }
1944   }
1945   UpdateView();
1946 }
1947
1948 //=============================================================================
1949 /*!
1950  *
1951  */
1952 //=============================================================================
1953 void SMESHGUI::UpdateView(){
1954   ::RepaintCurrentView();
1955 }
1956
1957 //=============================================================================
1958 /*!
1959  *
1960  */
1961 //=============================================================================
1962 void SMESHGUI::DisplayActor(SMESH_Actor * theActor, bool theVisibility){
1963   theActor->SetVisibility(theVisibility);
1964   ::DisplayActor(myActiveStudy->getActiveStudyFrame(),theActor);
1965 }
1966
1967 //=============================================================================
1968 /*!
1969  *
1970  */
1971 //=============================================================================
1972 void SMESHGUI::EraseActor(SMESH_Actor * theActor){
1973   theActor->SetVisibility(false);
1974 }
1975
1976 //=============================================================================
1977 /*!
1978  *
1979  */
1980 //=============================================================================
1981 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1982 {
1983         SALOME_Selection *Sel =
1984                 SALOME_Selection::Selection(myActiveStudy->getSelection());
1985         Sel->ClearIObjects();
1986         if (ac->hasIO())
1987                 return Sel->AddIObject(ac->getIO());
1988         else
1989                 return -1;
1990 }
1991
1992 //=============================================================================
1993 /*!
1994  *
1995  */
1996 //=============================================================================
1997 QString SMESHGUI::CheckHomogeneousSelection()
1998 {
1999         SALOME_Selection *Sel =
2000                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2001         /* copy the list */
2002         SALOME_ListIO List;
2003         SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
2004         for (; Itinit.More(); Itinit.Next())
2005         {
2006                 List.Append(Itinit.Value());
2007         }
2008
2009         QString RefType = CheckTypeObject(Sel->firstIObject());
2010         SALOME_ListIteratorOfListIO It(List);
2011         for (; It.More(); It.Next())
2012         {
2013                 Handle(SALOME_InteractiveObject) IObject = It.Value();
2014                 QString Type = CheckTypeObject(IObject);
2015                 if (Type.compare(RefType) != 0)
2016                         return "Heterogeneous Selection";
2017         }
2018
2019         Sel->ClearIObjects();
2020         SALOME_ListIteratorOfListIO It1(List);
2021         for (; It1.More(); It1.Next())
2022         {
2023                 int res = Sel->AddIObject(It1.Value());
2024                 if (res == -1)
2025                         myActiveStudy->highlight(It1.Value(), false);
2026                 if (res == 0)
2027                         myActiveStudy->highlight(It1.Value(), true);
2028         }
2029         return RefType;
2030 }
2031
2032 //=============================================================================
2033 /*!
2034  *
2035  */
2036 //=============================================================================
2037 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
2038 {
2039   SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
2040   if (!sobj->_is_nil()) {
2041     SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
2042     if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
2043       {                                         // component is selected
2044         return "Component";
2045       }
2046   }
2047
2048   SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2049   Sel->ClearIObjects();
2050
2051   Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
2052   Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
2053   Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
2054   Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
2055   Handle(SMESH_TypeFilter) aGroupFilter = new SMESH_TypeFilter(GROUP);
2056   Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
2057   Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter(SUBMESH_VERTEX);
2058   Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter(SUBMESH_EDGE);
2059   Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter(SUBMESH_FACE);
2060   Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter(SUBMESH_SOLID);
2061   Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter(SUBMESH_COMPOUND);
2062
2063   Sel->AddFilter(aHypFilter);
2064   if (Sel->AddIObject(IO) != -1) {
2065     Sel->ClearFilters();
2066     return "Hypothesis";
2067   }
2068
2069   Sel->ClearFilters();
2070   Sel->AddFilter(anAlgoFilter);
2071   if (Sel->AddIObject(IO) != -1) {
2072     Sel->ClearFilters();
2073     return "Algorithm";
2074   }
2075
2076   Sel->ClearFilters();
2077   Sel->AddFilter(aMeshFilter);
2078   if (Sel->AddIObject(IO) != -1) {
2079     Sel->ClearFilters();
2080     return "Mesh";
2081   }
2082
2083   Sel->ClearFilters();
2084   Sel->AddFilter(aSubMeshFilter);
2085   if (Sel->AddIObject(IO) != -1) {
2086     Sel->ClearFilters();
2087     return "SubMesh";
2088   }
2089
2090   Sel->ClearFilters();
2091   Sel->AddFilter(aGroupFilter);
2092   if (Sel->AddIObject(IO) != -1) {
2093     Sel->ClearFilters();
2094     return "Group";
2095   }
2096
2097   Sel->ClearFilters();
2098   Sel->AddFilter(aSubMeshVextexFilter);
2099   if (Sel->AddIObject(IO) != -1) {
2100     Sel->ClearFilters();
2101     return "SubMeshVertex";
2102   }
2103
2104   Sel->ClearFilters();
2105   Sel->AddFilter(aSubMeshEdgeFilter);
2106   if (Sel->AddIObject(IO) != -1) {
2107     Sel->ClearFilters();
2108     return "SubMeshEdge";
2109   }
2110
2111   Sel->ClearFilters();
2112   Sel->AddFilter(aSubMeshFaceFilter);
2113   if (Sel->AddIObject(IO) != -1) {
2114     Sel->ClearFilters();
2115     return "SubMeshFace";
2116   }
2117
2118   Sel->ClearFilters();
2119   Sel->AddFilter(aSubMeshSolidFilter);
2120   if (Sel->AddIObject(IO) != -1) {
2121     Sel->ClearFilters();
2122     return "SubMeshSolid";
2123   }
2124
2125   Sel->ClearFilters();
2126   Sel->AddFilter(aSubMeshCompoundFilter);
2127   if (Sel->AddIObject(IO) != -1) {
2128     Sel->ClearFilters();
2129     return "SubMeshCompound";
2130   }
2131
2132   Sel->ClearFilters();
2133   Sel->AddIObject(IO);
2134   return "NoType";
2135 }
2136
2137
2138 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
2139   return theStudy->GetProperties()->IsLocked();
2140 }
2141
2142 static int checkLock(const SALOMEDS::Study_var& theStudy) {
2143   if (isStudyLocked(theStudy)) {
2144     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
2145                            QObject::tr("WRN_WARNING"), 
2146                            QObject::tr("WRN_STUDY_LOCKED"),
2147                            QObject::tr("BUT_OK") );
2148     return true;
2149   }
2150   return false;
2151 }
2152
2153 //=============================================================================
2154 /*!
2155  *
2156  */
2157 //=============================================================================
2158 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2159 {
2160   SALOMEDS::Study_var aStudy = smeshGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
2161   //  QAD_Viewer3d* v3d;
2162   OCCViewer_Viewer3d *v3d;
2163
2164   Handle(AIS_InteractiveContext) ic;
2165   vtkRenderer *Renderer;
2166   vtkRenderWindow *RenWin;
2167
2168   if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
2169     v3d = ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2170            getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2171     ic = v3d->getAISContext();
2172   }
2173   else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2174     Renderer = ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2175                 getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
2176     RenWin = Renderer->GetRenderWindow();
2177   }
2178
2179   switch (theCommandID) {
2180   case 33:                                      // DELETE
2181     if(checkLock(aStudy)) break;
2182     smeshGUI->OnEditDelete();
2183     break;
2184     
2185   case 113:                                     // IMPORT
2186   case 112:
2187   case 111:
2188     {
2189       if(checkLock(aStudy)) break;
2190       //Import_Document(parent, theCommandID);  //NBU
2191       Import_Mesh(parent,theCommandID);
2192       break;
2193     }
2194
2195   case 122:                                     // EXPORT MED
2196   case 121:
2197   case 123:
2198     {
2199       Export_Mesh(parent, theCommandID);
2200       break;
2201     }
2202
2203   case 200:                                     // SCALAR BAR
2204     {
2205       SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2206       if( Sel && Sel->IObjectCount() ) {
2207         Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
2208         if( anIO->hasEntry() ) {
2209           if( SMESH_Actor* anActor = ::FindActorByEntry( anIO->getEntry() ) ) {
2210             anActor->SetControlMode( SMESH_Actor::eNone );
2211           }
2212         }
2213       }
2214       break;
2215     }
2216   case 201:
2217     {
2218       SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2219       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
2220       break;
2221     }
2222
2223   case 1133:                                    // DISPLAY MODE : WireFrame, Surface, Shrink
2224   case 1132:
2225   case 215:
2226   case 213:
2227   case 212:
2228   case 211:
2229     {
2230       smeshGUI->SetViewMode(theCommandID);
2231       break;
2232     }
2233
2234   case 214:                                     // UPDATE
2235     {
2236       if(checkLock(aStudy)) break;
2237       smeshGUI->Update();
2238       break;
2239     }
2240
2241   case 300:                                     // ERASE
2242   case 301:                                     // DISPLAY
2243   case 302:                                     // DISPLAY ONLY
2244     {
2245       EDisplaing anAction;
2246       switch(theCommandID){
2247       case 300: anAction = eErase; break;
2248       case 301: anAction = eDisplay; break;
2249       case 302: anAction = eDisplayOnly; break;
2250       }
2251       
2252       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2253       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2254         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2255         for (; It.More(); It.Next()) {
2256           Handle(SALOME_InteractiveObject) IOS = It.Value();
2257           if (IOS->hasEntry()) {
2258             ::UpdateView(anAction,IOS->getEntry());
2259           }
2260         }
2261       }
2262       Sel->ClearIObjects();
2263       break;
2264     }
2265
2266   case 400:                                     // NODES
2267     {
2268       if(checkLock(aStudy)) break;
2269       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2270         smeshGUI->EmitSignalDeactivateDialog();
2271         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2272         Sel->ClearIObjects();
2273         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2274         smeshGUI->ViewNodes();
2275         SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2276       }
2277       else {
2278         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2279                               tr("SMESH_WRN_WARNING"), 
2280                               tr("SMESH_WRN_VIEWER_VTK"),
2281                               tr("SMESH_BUT_OK"));
2282       }
2283       break;
2284     }
2285
2286   case 2151:  // FILTER
2287   {
2288     if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
2289     {
2290       smeshGUI->EmitSignalDeactivateDialog();
2291       SMESHGUI_FilterDlg *aDlg = new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
2292     }
2293     break;
2294   }
2295     
2296   case 405:                                     // MOVE NODE
2297     {
2298       if(checkLock(aStudy)) break;
2299       smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2300       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2301       SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2302       break;
2303     }
2304     
2305   case 701:                                     // COMPUTE MESH 
2306     {
2307       if(checkLock(aStudy)) break;
2308       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2309         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2310         int nbSel = Sel->IObjectCount();
2311         if (nbSel != 1){
2312           break;
2313         }
2314
2315         SMESH::SMESH_Mesh_var aMesh;
2316         SMESH::SMESH_subMesh_var aSubMesh;
2317         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2318         if (IObject->hasEntry()){
2319           SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2320           GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( aMeshSObj );
2321           if ( aShape->_is_nil() ) {
2322             // imported mesh
2323             break;
2324           }
2325           SALOMEDS::GenericAttribute_var anAttr;
2326           if(!aMeshSObj->_is_nil() && aMeshSObj->FindAttribute(anAttr, "AttributeIOR")){
2327             SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2328             MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "<< anIOR->Value());
2329             CORBA::Object_var anObj;
2330             try{
2331               anObj = _orb->string_to_object(anIOR->Value());
2332               if (CORBA::is_nil(anObj)){
2333                 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : nil object");
2334               }
2335             }catch(CORBA::COMM_FAILURE & ex){
2336               INFOS("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)");
2337             }
2338             aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2339             aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2340             if (!aMesh->_is_nil()){
2341               GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2342               if (!refShape->_is_nil()) {
2343                 if(!smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape)){
2344                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
2345                                         tr("SMESH_WRN_WARNING"),
2346                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
2347                                         tr("SMESH_BUT_OK"));
2348                   break;
2349                 }
2350                 try{
2351                   if (smeshGUI->myComponentMesh->Compute(aMesh,refShape))
2352                     smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2353                   // TO Do : change icon of all submeshes
2354                 }
2355                 catch(const SALOME::SALOME_Exception & S_ex){
2356                   QtCatchCorbaException(S_ex);
2357                 }
2358               }
2359             }else if(!aSubMesh->_is_nil()){
2360               aMesh = aSubMesh->GetFather();
2361               GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2362               if(!refShape->_is_nil()){
2363                 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape);
2364                 if(!compute){
2365                   QAD_MessageBox::warn1(QAD_Application::getDesktop(), 
2366                                         tr("SMESH_WRN_WARNING"),
2367                                         tr("SMESH_WRN_MISSING_PARAMETERS"),
2368                                         tr("SMESH_BUT_OK"));
2369                   break;
2370                 }
2371                 try{
2372                   if ( smeshGUI->myComponentMesh->Compute(aMesh,refShape) )
2373                     smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2374                   // TO Do : change icon of all submeshes
2375                 }catch(const SALOME::SALOME_Exception & S_ex){
2376                   QtCatchCorbaException(S_ex);
2377                 }
2378               }
2379             }
2380           }
2381         }
2382         CORBA::Long anId = smeshGUI->myStudy->StudyId();
2383         TVisualObjPtr aVisualObj = GetVisualObj(anId,IObject->getEntry());
2384         if(smeshGUI->myAutomaticUpdate && aVisualObj){
2385           aVisualObj->Update();
2386           SMESH_Actor* anActor = ::FindActorByEntry(IObject->getEntry());
2387           if(!anActor){
2388             anActor = ::CreateActor(smeshGUI->myStudy,IObject->getEntry());
2389             if(anActor){
2390               ::DisplayActor(smeshGUI->myActiveStudy->getActiveStudyFrame(),anActor); //apo
2391               ::FitAll();
2392             }
2393           }
2394         }
2395       }else{
2396         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2397                               tr("SMESH_WRN_WARNING"), 
2398                               tr("SMESH_WRN_VIEWER_VTK"),
2399                               tr("SMESH_BUT_OK"));
2400       }
2401       break;
2402     }
2403
2404   case 702:                                     // ADD SUB MESH 
2405     {
2406       if(checkLock(aStudy)) break;
2407       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2408         smeshGUI->EmitSignalDeactivateDialog();
2409         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2410         SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
2411       }
2412       else {
2413         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2414                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2415                               tr("SMESH_BUT_OK"));
2416       }
2417       break;
2418     }
2419     
2420   case 703:                                     // INIT MESH 
2421     {
2422       if(checkLock(aStudy)) break;
2423       smeshGUI->EmitSignalDeactivateDialog();
2424       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2425       SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2426       break;
2427     }
2428
2429   case 704:                                     // EDIT Hypothesis 
2430     {
2431       if(checkLock(aStudy)) break;
2432       smeshGUI->EmitSignalDeactivateDialog();
2433       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2434       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2435       break;
2436     }
2437
2438   case 705:                                     //  EDIT Global Hypothesis
2439     {
2440       if(checkLock(aStudy)) break;
2441       smeshGUI->EmitSignalDeactivateDialog();
2442       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2443       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2444       break;
2445     }
2446
2447   case 706:                                     //  EDIT Local Hypothesis
2448     {
2449       if(checkLock(aStudy)) break;
2450       smeshGUI->EmitSignalDeactivateDialog();
2451       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2452       SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2453       break;
2454     }
2455
2456   case 406:                                     // ORIENTATION ELEMENTS
2457     {
2458       if(checkLock(aStudy)) break;
2459       smeshGUI->EmitSignalDeactivateDialog();
2460       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2461       smeshGUI->myDesktop->SetSelectionMode(FaceSelection, true);
2462       SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2463       break;
2464     }
2465
2466   case 407:                                     // DIAGONAL INVERSION
2467     {
2468       if(checkLock(aStudy)) break;
2469       smeshGUI->EmitSignalDeactivateDialog();
2470       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2471       Sel->ClearIObjects();
2472       smeshGUI->myDesktop->SetSelectionMode(EdgeOfCellSelection, true);
2473       SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2474       break;
2475     }
2476
2477   case 801:                                     // CREATE GROUP
2478     {
2479       if(checkLock(aStudy)) break;
2480       smeshGUI->EmitSignalDeactivateDialog();
2481       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2482       int nbSel = Sel->IObjectCount();
2483       if (nbSel == 1) {
2484         // check if mesh is selected
2485         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2486         if (IObject->hasEntry()) {
2487           SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2488           if (!aMeshSObj->_is_nil()) {
2489             CORBA::Object_var anObj = aMeshSObj->GetObject();
2490             SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2491             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2492             if (aMesh->_is_nil() && !aSubMesh->_is_nil()) {
2493               aMesh = aSubMesh->GetFather();
2494             }
2495             if (!aMesh->_is_nil()) {
2496               SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
2497               aDlg->show();
2498             }
2499           }
2500         }
2501       }
2502       break;
2503     }
2504
2505   case 802:                                     // CONSTRUCT GROUP
2506     {
2507       if(checkLock(aStudy)) break;
2508       smeshGUI->EmitSignalDeactivateDialog();
2509       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2510       int nbSel = Sel->IObjectCount();
2511       if (nbSel == 1) {
2512         // check if submesh is selected
2513         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2514         if (IObject->hasEntry()) {
2515           SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2516           if(!aSObj->_is_nil()) {
2517             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
2518             if (!aSubMesh->_is_nil()) {
2519               try {
2520                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2521                 // get submesh elements list by types
2522                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2523                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2524                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2525                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2526                 // create group for each type o elements
2527                 QString aName = IObject->getName();
2528                 MESSAGE("SMESHGUI::OnGUIEvent - Construct group on submesh : "<<aName);
2529                 MESSAGE(" Number of elements : nodes "<<aNodes->length() << ", edges " << aEdges->length()
2530                         << ", faces " << aFaces->length() << ", volumes " << aVolumes->length());
2531                 if (aNodes->length() > 0) {
2532                   SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::NODE, aName);
2533                   aGroup->Add(aNodes);
2534                 }
2535                 if (aEdges->length() > 0) {
2536                   SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::EDGE, aName);
2537                   aGroup->Add(aEdges);
2538                 }
2539                 if (aFaces->length() > 0) {
2540                   SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::FACE, aName);
2541                   aGroup->Add(aFaces);
2542                 }
2543                 if (aVolumes->length() > 0) {
2544                   SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::VOLUME, aName);
2545                   aGroup->Add(aVolumes);
2546                 }
2547                 smeshGUI->myActiveStudy->updateObjBrowser(true);
2548               }catch(const SALOME::SALOME_Exception & S_ex){
2549                 QtCatchCorbaException(S_ex);
2550               }
2551             }
2552           }
2553         }
2554       }
2555       break;
2556     }
2557
2558   case 803:                                     // EDIT GROUP
2559     {
2560       if(checkLock(aStudy)) break;
2561       smeshGUI->EmitSignalDeactivateDialog();
2562       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2563       int nbSel = Sel->IObjectCount();
2564       if (nbSel == 1) {
2565         // check if group is selected
2566         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2567         if (IObject->hasEntry()) {
2568           SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2569           if(!aSObj->_is_nil()) {
2570             SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(aSObj->GetObject());
2571             if (!aGroup->_is_nil()) {
2572               SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
2573               aDlg->show();
2574             }
2575           }
2576         }
2577       }
2578       break;
2579     }
2580
2581   case 804:                                     // Add elements to group
2582     {
2583       if(checkLock(aStudy)) break;
2584       if (smeshGUI->myState == 800) {
2585         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2586         if (aDlg) aDlg->onAdd();
2587       }
2588       break;
2589     }
2590
2591   case 805:                                     // Remove elements from group
2592     {
2593       if(checkLock(aStudy)) break;
2594       if (smeshGUI->myState == 800) {
2595         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2596         if (aDlg) aDlg->onRemove();
2597       }
2598       break;
2599     }
2600
2601   case 900:                                     // MESH INFOS
2602     {
2603       smeshGUI->EmitSignalDeactivateDialog();
2604       SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false);
2605       break;
2606     }
2607
2608   case 1001:                                    // AUTOMATIC UPDATE PREFERENCES
2609     {
2610       parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
2611       if (parent->menuBar()->isItemChecked(1001)) {
2612         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2613         smeshGUI->myAutomaticUpdate = true;
2614       }
2615       else {
2616         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2617         smeshGUI->myAutomaticUpdate = false;
2618       }
2619       break;
2620     }
2621
2622   case 1003:                                    // MESH PREFERENCES
2623     {
2624       smeshGUI->SetDisplaySettings();
2625       break;
2626     }
2627
2628   case 1005:
2629     {
2630       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
2631       break;
2632     }
2633
2634   case 1006: 
2635     {
2636       SMESHGUI_Preferences_SelectionDlg* aDlg = 
2637         new SMESHGUI_Preferences_SelectionDlg(parent);
2638
2639       QColor aColor;
2640       QString SCr, SCg, SCb;
2641       SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
2642       SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
2643       SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
2644       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2645         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2646       else aColor = Qt::cyan;
2647       aDlg->SetColor(1, aColor);
2648
2649       SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
2650       SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
2651       SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
2652       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2653         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2654       else aColor = Qt::yellow;
2655       aDlg->SetColor(2, aColor);
2656
2657       SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
2658       SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
2659       SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
2660       if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2661         aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2662       else aColor = Qt::white;
2663       aDlg->SetColor(3, aColor);
2664
2665       QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
2666       if (SW1.isEmpty()) SW1 = "5";
2667       aDlg->SetWidth(1, SW1.toInt());
2668
2669       QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
2670       if (SW2.isEmpty()) SW2 = "5";
2671       aDlg->SetWidth(2, SW2.toInt());
2672
2673       QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
2674       if (SP1.isEmpty()) SP1 = "0.025";
2675       aDlg->SetPrecision(1, SP1.toDouble());
2676
2677       QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
2678       if (SP2.isEmpty()) SP2 = "0.001";
2679       aDlg->SetPrecision(2, SP2.toDouble());
2680
2681       if (aDlg->exec()) {
2682         QColor aPreColor = aDlg->GetColor(1);
2683         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
2684         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
2685         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
2686
2687         QColor aSelColor = aDlg->GetColor(2);
2688         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
2689         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
2690         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
2691
2692         QColor aHiColor = aDlg->GetColor(3);
2693         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
2694         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
2695         QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
2696
2697         int aPreWidth = aDlg->GetWidth(1);
2698         QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
2699         int aSelWidth = aDlg->GetWidth(2);
2700         QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
2701
2702         double aTolNodes = aDlg->GetPrecision(1);
2703         QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
2704         double aTolItems = aDlg->GetPrecision(2);
2705         QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
2706
2707         // update current study settings
2708         ::UpdateSelectionProp();
2709
2710         QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
2711         if (studyFrame->getTypeView() == VIEW_VTK) {
2712           VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(studyFrame);
2713           // update VTK viewer properties
2714           VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
2715           if (anInteractor) {
2716             anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
2717                                            aSelColor.blue()/255., aSelWidth);
2718             anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
2719             VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
2720             if (aStyle)
2721               aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
2722                                           aPreColor.blue()/255., aPreWidth);
2723           }
2724           // update actors
2725           vtkRenderer* aRenderer = aViewFrame->getRenderer();
2726           vtkActorCollection *aCollection = aRenderer->GetActors();
2727           aCollection->InitTraversal();
2728           while(vtkActor *anAct = aCollection->GetNextActor()){
2729             if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
2730               anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
2731                                          aHiColor.blue()/255.);
2732               anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
2733                                             aPreColor.blue()/255.);
2734             }
2735           }
2736         }
2737       }
2738
2739       break;
2740     }
2741
2742   case 1100:                                    // EDIT HYPOTHESIS
2743     {
2744       if(checkLock(aStudy)) break;
2745       SALOME_Selection *Sel =
2746         SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2747       int nbSel = Sel->IObjectCount();
2748
2749       if (nbSel == 1) {
2750         Standard_Boolean res;
2751         SMESH::SMESH_Hypothesis_var Hyp =
2752           smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2753
2754         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2755         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2756         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2757         if ( res )
2758         {
2759           char* sName = Hyp->GetName();
2760           SMESHGUI_GenericHypothesisCreator* aCreator = smeshGUI->GetHypothesisCreator(sName);
2761           if (aCreator)
2762           {
2763             aCreator->EditHypothesis(Hyp);
2764           }
2765           else
2766           {
2767             // report error
2768           }
2769         }
2770       }
2771       break;
2772     }
2773
2774   case 1101:                                    // RENAME
2775     {
2776       if(checkLock(aStudy)) break;
2777       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2778       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2779       for (; It.More(); It.Next()) {
2780         Handle(SALOME_InteractiveObject) IObject = It.Value();
2781
2782         SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2783         SALOMEDS::GenericAttribute_var anAttr;
2784         SALOMEDS::AttributeName_var aName;
2785         if (!obj->_is_nil()) {
2786           if (obj->FindAttribute(anAttr, "AttributeName")) {
2787             aName = SALOMEDS::AttributeName::_narrow(anAttr);
2788             QString newName = QString(aName->Value());
2789             newName = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), newName);
2790             if (!newName.isEmpty()) {
2791               smeshGUI->myActiveStudy->renameIObject(IObject, newName);
2792             }
2793           }
2794         }
2795       }
2796       break;
2797     }
2798     
2799   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2800     {
2801       if(checkLock(aStudy)) break;
2802       QAD_WaitCursor wc;
2803       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2804       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2805       for (int i = 0; It.More(); It.Next(), i++) {
2806         Handle(SALOME_InteractiveObject) IObject = It.Value();
2807         smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2808       }
2809       Sel->ClearIObjects();
2810       smeshGUI->myActiveStudy->updateObjBrowser(true);
2811       break;
2812     }
2813
2814   case 401:                                     // GEOM::EDGE
2815     {
2816       if(checkLock(aStudy)) break;
2817       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2818         smeshGUI->EmitSignalDeactivateDialog();
2819         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2820         Sel->ClearIObjects();
2821         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2822         smeshGUI->ViewNodes();
2823         SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2824       }
2825       else {
2826         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2827                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2828                               tr("SMESH_BUT_OK"));
2829       }
2830       break;
2831     }
2832   case 4021:                                    // TRIANGLE
2833     {
2834       if(checkLock(aStudy)) break;
2835       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2836         smeshGUI->EmitSignalDeactivateDialog();
2837         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2838         Sel->ClearIObjects();
2839         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2840         smeshGUI->ViewNodes();
2841         SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2842       }
2843       else {
2844         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2845                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2846                               tr("SMESH_BUT_OK"));
2847       }
2848       break;
2849     }
2850   case 4022:                                    // QUAD
2851     {
2852       if(checkLock(aStudy)) break;
2853       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2854         smeshGUI->EmitSignalDeactivateDialog();
2855         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2856         Sel->ClearIObjects();
2857         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2858         smeshGUI->ViewNodes();
2859         SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2860       }
2861       else
2862         {
2863           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2864                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2865                                 tr("SMESH_BUT_OK"));
2866         }
2867       break;
2868     }
2869   case 4031:                                    // TETRA
2870     {
2871       if(checkLock(aStudy)) break;
2872       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2873         smeshGUI->EmitSignalDeactivateDialog();
2874         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2875         Sel->ClearIObjects();
2876         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2877         smeshGUI->ViewNodes();
2878         SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
2879       }
2880       else {
2881         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2882                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2883                               tr("SMESH_BUT_OK"));
2884       }
2885       break;
2886     }
2887   case 4032:                                    // HEXA
2888     {
2889       if(checkLock(aStudy)) break;
2890       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2891         smeshGUI->EmitSignalDeactivateDialog();
2892         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2893         Sel->ClearIObjects();
2894         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2895         smeshGUI->ViewNodes();
2896         SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
2897       }
2898       else {
2899         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2900                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2901                               tr("SMESH_BUT_OK"));
2902       }
2903       break;
2904     }
2905
2906   case 4041:                                    // REMOVES NODES
2907     {
2908       if(checkLock(aStudy)) break;
2909       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2910         smeshGUI->EmitSignalDeactivateDialog();
2911         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2912         Sel->ClearIObjects();
2913         smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2914         smeshGUI->ViewNodes();
2915         SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
2916       }
2917       else {
2918         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2919                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2920                               tr("SMESH_BUT_OK"));
2921       }
2922       break;
2923     }
2924   case 4042:                                    // REMOVES ELEMENTS
2925     {
2926       if(checkLock(aStudy)) break;
2927       if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2928         smeshGUI->EmitSignalDeactivateDialog();
2929         SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2930         Sel->ClearIObjects();
2931         smeshGUI->myDesktop->SetSelectionMode(CellSelection, true);
2932         SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
2933       }
2934       else
2935         {
2936           QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2937                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2938                                 tr("SMESH_BUT_OK"));
2939         }
2940       break;
2941     }
2942
2943   case 5000: // HYPOTHESIS
2944     {
2945       if(checkLock(aStudy)) break;
2946       smeshGUI->EmitSignalDeactivateDialog();
2947       SMESHGUI_CreateHypothesesDlg *aDlg =
2948         new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
2949       break;
2950     }
2951   case 5010: // ALGO
2952     {
2953       if(checkLock(aStudy)) break;
2954       smeshGUI->EmitSignalDeactivateDialog();
2955       SMESHGUI_CreateHypothesesDlg *aDlg =
2956         new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
2957       break;
2958     }
2959
2960   case 6016:                                    // CONTROLS 
2961   case 6015:
2962   case 6014:
2963   case 6013:
2964   case 6012:
2965   case 6011:
2966   case 6001:
2967   case 6003:
2968   case 6004:    
2969     if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2970       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2971       if ( Sel->IObjectCount() == 1 && Sel->firstIObject()->hasEntry() ) {
2972         SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( Sel->firstIObject()->getEntry() );
2973         if ( !SO->_is_nil() ) {
2974           CORBA::Object_var aObject = SO->GetObject();
2975           SMESH::SMESH_Mesh_var    aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2976           SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2977           SMESH::SMESH_Group_var   aGroup   = SMESH::SMESH_Group::_narrow( aObject );
2978           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2979             smeshGUI->Control( theCommandID );
2980             break;
2981           }
2982         }
2983       }
2984       QAD_MessageBox::warn1(smeshGUI->GetDesktop(), 
2985                             tr( "SMESH_WRN_WARNING" ),
2986                             tr( "SMESH_BAD_SELECTION" ), 
2987                             tr( "SMESH_BUT_OK" ) );
2988       break;
2989     }
2990     else {
2991       QAD_MessageBox::warn1(smeshGUI->GetDesktop(), 
2992                             tr( "SMESH_WRN_WARNING" ),
2993                             tr( "NOT_A_VTK_VIEWER" ), 
2994                             tr( "SMESH_BUT_OK" ) );
2995     }
2996     break;
2997   case 9010:
2998     {
2999       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3000       if (Sel->IObjectCount() == 1)     {
3001         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3002         if(anIObject->hasEntry())
3003           if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3004             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3005           }
3006       }
3007       break;
3008     }
3009   case 9011:
3010     {
3011       SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3012       if (Sel->IObjectCount() == 1)     {
3013         Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3014         if(anIObject->hasEntry())
3015           if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3016             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3017           }
3018       }
3019       break;
3020     }
3021   case 10001:                           // DISPLAY MODE PREFERENCE
3022     {
3023       // Wireframe
3024       parent->menuBar()->setItemChecked(10001, true);
3025       parent->menuBar()->setItemChecked(10002, false);
3026       parent->menuBar()->setItemChecked(10004, false);
3027       parent->menuBar()->setItemEnabled(10003, true);
3028       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3029       break;
3030     }
3031   case 10002:
3032     {
3033       parent->menuBar()->setItemChecked(10002, true);
3034       parent->menuBar()->setItemChecked(10001, false);
3035       parent->menuBar()->setItemChecked(10004, false);
3036       parent->menuBar()->setItemEnabled(10003, true);
3037       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3038       break;
3039     }
3040   case 10003:
3041     {
3042       parent->menuBar()->setItemChecked(10003,!parent->menuBar()->isItemChecked(10003));
3043       QAD_CONFIG->addSetting("SMESH:Shrink", parent->menuBar()->isItemChecked(10003) ? "yes" : "no");
3044       break;
3045     }
3046   case 10004:
3047     {
3048       parent->menuBar()->setItemChecked(10001, false);
3049       parent->menuBar()->setItemChecked(10004, true);
3050       parent->menuBar()->setItemChecked(10002, false);
3051       parent->menuBar()->setItemEnabled(10003, false);
3052       QAD_CONFIG->addSetting("SMESH:DisplayMode", "Nodes");
3053       break;
3054     }
3055     
3056   }
3057
3058   smeshGUI->myActiveStudy->updateObjBrowser(true);
3059   return true;
3060 }
3061
3062 //=============================================================================
3063 /*! function : GetMeshesUsingAlgoOrHypothesis()
3064  *  purpose  : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3065  *           : However is supposed here that father of father of an hypothesis is a Mesh Object.
3066  */
3067 //=============================================================================      
3068 SALOMEDS::Study::ListOfSObject *
3069         SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3070         SMESH_Hypothesis_ptr AlgoOrHyp)
3071 {
3072   SALOMEDS::Study::ListOfSObject_var listSOmesh =
3073     new SALOMEDS::Study::ListOfSObject;
3074   listSOmesh->length(0);
3075   unsigned int index = 0;
3076   if (!AlgoOrHyp->_is_nil()) {
3077     SALOMEDS::SObject_var SO_Hypothesis =
3078       smeshGUI->GetStudyAPI().FindObject(AlgoOrHyp);
3079     if (!SO_Hypothesis->_is_nil()) {
3080       SALOMEDS::Study::ListOfSObject_var listSO =
3081         smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3082       MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO->length());
3083       for (unsigned int i = 0; i < listSO->length(); i++) {
3084         SALOMEDS::SObject_ptr SO = listSO[i];
3085         if (!SO->_is_nil()) { 
3086           SALOMEDS::SObject_var aFather = SO->GetFather();
3087           if (!aFather->_is_nil()) {
3088             SALOMEDS::SObject_var SOfatherFather = aFather->GetFather();
3089             if (!SOfatherFather->_is_nil()) {
3090               MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
3091               index++;
3092               listSOmesh->length(index);
3093               listSOmesh[index - 1] = SOfatherFather;
3094             }
3095           }
3096         }
3097       }
3098     }
3099   }
3100   MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
3101   return listSOmesh._retn();
3102 }
3103
3104 //=============================================================================
3105 /*!
3106  *
3107  */
3108 //=============================================================================
3109 void SMESHGUI::Import_Mesh(QAD_Desktop * parent, int theCommandID){
3110   QString filter;
3111   string myExtension;
3112   
3113   if(theCommandID == 113){
3114     filter = tr("MED files (*.med)");
3115   }else if (theCommandID == 112){
3116     filter = tr("IDEAS files (*.unv)");
3117   }else if (theCommandID == 111){
3118     filter = tr("DAT files (*.dat)");
3119   }
3120   QString filename = QAD_FileDlg::getFileName(parent,
3121                                               "",
3122                                               filter,
3123                                               tr("Import mesh"),
3124                                               true);
3125   if(!filename.isEmpty()){
3126     QAD_WaitCursor wc;
3127     SMESH::mesh_array_var aMeshes;
3128     try {
3129       SMESH::DriverMED_ReadStatus res;
3130       aMeshes = smeshGUI->myComponentMesh->CreateMeshesFromMED(filename.latin1(),
3131                                                                res);
3132       if ( res > SMESH::DRS_OK ) {
3133         wc.stop();
3134         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3135                               tr("SMESH_WRN_WARNING"),
3136                               tr(QString("SMESH_DRS_%1").arg(res)),
3137                               tr("SMESH_BUT_OK"));
3138         wc.start();
3139
3140       }
3141     }
3142     catch (const SALOME::SALOME_Exception& S_ex)
3143     {
3144       wc.stop();
3145       QtCatchCorbaException(S_ex);
3146       wc.start();
3147     }
3148     for ( int i = 0, n = aMeshes->length(); i < n; i++ ) {
3149       SALOMEDS::SObject_var aMeshSO = smeshGUI->myStudyAPI.FindObject( aMeshes[i] );
3150       if ( !aMeshSO->_is_nil() ) {
3151         SALOMEDS::StudyBuilder_var aBuilder = smeshGUI->myStudy->NewBuilder();
3152         SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow( aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ) );
3153         aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3154       }
3155     }
3156   }
3157 }
3158
3159 //=============================================================================
3160 /*!
3161  *
3162  */
3163 //=============================================================================
3164 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3165 {
3166   SALOME_Selection *Sel =
3167     SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3168   int nbSel = Sel->IObjectCount();
3169   if ( !nbSel )
3170     return;
3171   Standard_Boolean res;
3172   Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3173   SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3174   if ( res && ( nbSel == 1 || theCommandID == 122 ) ) {// MED export supports multiple meshes
3175     QString aFilter, aTitle = tr("Export mesh");
3176     switch ( theCommandID ) {
3177     case 122:
3178       aFilter = tr("MED files (*.med)");
3179       break;
3180     case 121:
3181       aFilter = tr("DAT files (*.dat)");
3182       break;
3183     case 123:
3184       aFilter = tr("IDEAS files (*.unv)");
3185       break;
3186     default:
3187       break;
3188     }
3189     
3190     QString filename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false);
3191     
3192     if ( !filename.isEmpty() ) {
3193       // Check whether the file already exists and delete it if yes
3194       QFile aFile( filename );
3195       if ( aFile.exists() )
3196         aFile.remove();
3197       
3198       QAD_WaitCursor wc;
3199       for ( SALOME_ListIteratorOfListIO it( Sel->StoredIObjects() ); it.More(); it.Next() ) {
3200         aMesh = smeshGUI->ConvertIOinMesh( it.Value(), res );
3201         if ( res ) {
3202           switch ( theCommandID ) {
3203           case 122:
3204             aMesh->ExportMED( filename.latin1(), true ); // currently, automatic groups are always created
3205             break;
3206           case 121:
3207             aMesh->ExportDAT( filename.latin1() );
3208             break;
3209           case 123:
3210             aMesh->ExportUNV( filename.latin1() );
3211             break;
3212           default:
3213             break;
3214           }
3215         }
3216       }
3217     }
3218   }
3219 }
3220
3221 //=============================================================================
3222 /*!
3223  *
3224  */
3225 //=============================================================================
3226 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3227                             QAD_StudyFrame * studyFrame)
3228 {
3229   return false;
3230 }
3231
3232 //=============================================================================
3233 /*!
3234  *
3235  */
3236 //=============================================================================
3237 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3238                            QAD_StudyFrame * studyFrame)
3239 {
3240   return true;
3241 }
3242
3243 //=============================================================================
3244 /*!
3245  *
3246  */
3247 //=============================================================================
3248 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3249                           QAD_StudyFrame * studyFrame)
3250 {
3251   return true;
3252 }
3253
3254 //=============================================================================
3255 /*!
3256  *
3257  */
3258 //=============================================================================
3259 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3260 {
3261   MESSAGE("SMESHGUI::SetSettings.");
3262   SMESHGUI::GetOrCreateSMESHGUI(parent);
3263
3264   /* Display mode */
3265   QString DisplayMode = "Shading";
3266   if ( QAD_CONFIG->hasSetting("SMESH:DisplayMode") )
3267     DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3268   else
3269     QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3270
3271   bool Shrink = false;
3272   if ( QAD_CONFIG->hasSetting("SMESH:Shrink") )
3273     Shrink = QAD_CONFIG->getSetting("SMESH:Shrink") == "yes";
3274
3275   if (DisplayMode == "Wireframe") {
3276     // wireframe
3277     parent->menuBar()->setItemChecked(10004, false);
3278     parent->menuBar()->setItemChecked(10002, false);
3279     parent->menuBar()->setItemChecked(10001, true);
3280     parent->menuBar()->setItemEnabled(10003, true);
3281   }
3282   else if (DisplayMode == "Nodes") {
3283     // poins
3284     parent->menuBar()->setItemChecked(10004, true);
3285     parent->menuBar()->setItemChecked(10002, false);
3286     parent->menuBar()->setItemChecked(10001, false);
3287     parent->menuBar()->setItemEnabled(10003, false);
3288   }
3289   else {
3290     // default is shading
3291     parent->menuBar()->setItemChecked(10004, false);
3292     parent->menuBar()->setItemChecked(10002, true);
3293     parent->menuBar()->setItemChecked(10001, false);
3294     parent->menuBar()->setItemEnabled(10003, true);
3295   }
3296   parent->menuBar()->setItemChecked(10003, Shrink);
3297
3298   /* Automatic Update */
3299   QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3300   if (AutoUpdate.compare("true") == 0) {
3301     parent->menuBar()->setItemChecked(1001, true);
3302     smeshGUI->myAutomaticUpdate = true;
3303   }
3304   else {
3305     parent->menuBar()->setItemChecked(1001, false);
3306     smeshGUI->myAutomaticUpdate = false;
3307   }
3308
3309   /* Selection */
3310   ::UpdateSelectionProp();
3311
3312   /* menus disable */
3313   parent->menuBar()->setItemEnabled(111, false);        // IMPORT DAT
3314   parent->menuBar()->setItemEnabled(112, false);        // IMPORT UNV
3315
3316   return true;
3317 }
3318
3319 //=============================================================================
3320 /*!
3321  *
3322  */
3323 //=============================================================================
3324 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
3325 {
3326   // NRI : Temporary added
3327   //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3328   //    theObject = "NothingSelected";
3329   //    theContext = "NothingSelected";
3330   //  }
3331   // NRI
3332
3333   SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3334   int nbSel = Sel->IObjectCount();
3335   switch ( nbSel ) {
3336   case 0:
3337     theObject = "NothingSelected";
3338     theContext = "NothingSelected";
3339     break;
3340   case 1:
3341     if ( smeshGUI->myState == 800 && Sel->HasIndex( Sel->firstIObject() ) )
3342       theObject = "Elements";
3343     else
3344       theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3345     theContext = "";
3346     break;
3347   default:
3348     theObject = smeshGUI->CheckHomogeneousSelection();
3349     theContext = "";
3350   }
3351 }
3352
3353 //=============================================================================
3354 /*!
3355  *
3356  */
3357 //=============================================================================
3358 bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
3359                            const QString& theParent, const QString& theObject)
3360 {
3361   // get active study frame
3362   QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3363   
3364   // get parent component which selected object(s) belongs to
3365   QString parentComp = ( (SALOMEGUI_Desktop*)parent )->getComponentFromSelection();
3366
3367   // get selection
3368   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3369   int nbSel = Sel->IObjectCount();
3370
3371   if ( nbSel == 0 ) {
3372     popup->clear();
3373   }
3374   else if ( nbSel == 1 ) {
3375     if ( parentComp != parent->getActiveComponent() ) {
3376       // object not belongs to SMESH module - remove all commands except common Display/Erase...
3377       while ( 1 ) {
3378         int id = popup->idAt( 0 );
3379         if ( id <= QAD_TopLabel_Popup_ID )
3380           popup->removeItemAt( 0 );
3381         else
3382           break;
3383       }
3384     }
3385     else {
3386       // get selected interactive object 
3387       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3388       SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3389       // find popup menu's TopLabel item
3390       int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3391       if ( topItem >= 0 ) {
3392         if ( theParent == "Viewer" ) {
3393           // set bold font for popup menu's TopLabel item (Viewer popup)
3394           QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3395           popup->removeItem( QAD_TopLabel_Popup_ID );
3396           popup->insertItem( new CustomItem( QString( IObject->getName() ), fnt ), QAD_TopLabel_Popup_ID, topItem );
3397         }
3398         else if ( theParent == "ObjectBrowser" ) {
3399           // remove popup menu's TopLabel item (Object Browser popup)
3400           popup->removeItem( QAD_TopLabel_Popup_ID );
3401         }
3402       }
3403
3404       // remove "Display only" command for component object
3405       if ( theObject.compare( "Component" ) == 0 ) {
3406         popup->removeItem( QAD_DisplayOnly_Popup_ID );
3407       }
3408       else if ( theObject == "Hypothesis" || theObject == "Algorithm" ) {
3409         // remove Display/Erase commands
3410         popup->removeItem( QAD_Display_Popup_ID );
3411         popup->removeItem( QAD_DisplayOnly_Popup_ID );
3412         popup->removeItem( QAD_Erase_Popup_ID );
3413         // remove "Unassign ..." command if hyp/algo is not assigned
3414         if ( SO->_is_nil() || !IObject->hasReference()/* !IsReferencedObject( SO ) */)
3415           popup->removeItem( 1102 );
3416       }
3417       else if ( theObject == "Mesh" || theObject == "SubMesh" || theObject == "Group" ) {
3418         // get actor
3419         GEOM::GEOM_Shape_var aShape = GetSMESHGUI()->GetStudyAPI().GetShapeOnMeshOrSubMesh( SO );
3420         if ( aShape->_is_nil() ) {
3421           // imported mesh
3422           popup->removeItem( 701 ); // Compute
3423           popup->removeItem( 705 ); // Edit hypothesis
3424           popup->removeItem( 706 ); // ...
3425         }
3426         SMESH_Actor* ac = ::FindActorByEntry(IObject->getEntry());
3427         // if object has actor
3428         if ( ac && studyFrame->getTypeView() == VIEW_VTK ) {
3429           VTKViewer_RenderWindowInteractor* myRenderInter =
3430             ( ( VTKViewer_ViewFrame* ) studyFrame->getRightFrame()->getViewFrame() )->getRWInteractor();
3431           if ( myRenderInter->isVisible( IObject ) ) {
3432             popup->removeItem( QAD_Display_Popup_ID );
3433             popup->setItemChecked( 9010, ac->GetPointsLabeled() ); // Numbering / Display Nodes #
3434             popup->setItemChecked( 9011, ac->GetCellsLabeled() );  // Numbering / Display Elements #
3435             TVisualObjPtr aVisualObj = ac->GetObject();
3436             int aNbEdges = aVisualObj->GetNbEntities(SMESH::EDGE);
3437             int aNbFaces = aVisualObj->GetNbEntities(SMESH::FACE);
3438             int aNbVolumes = aVisualObj->GetNbEntities(SMESH::VOLUME);
3439             QMenuItem* mi = popup->findItem( 1131 );
3440             if ( mi && mi->popup() ) {
3441               int  prType = ac->GetRepresentation();
3442               // Display Mode / Wireframe
3443               if(!aNbFaces && !aNbVolumes && !aNbEdges){
3444                 mi->popup()->removeItem( 211 );
3445               }else{
3446                 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
3447               }
3448               // Display Mode / Shading
3449               if(!aNbFaces && !aNbVolumes){
3450                 mi->popup()->removeItem( 212 );
3451               }else{
3452                 mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface );
3453               }
3454               // Display Mode / Points
3455               mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint );  
3456               // Display Mode / Shrink
3457               bool isShrunk = ac->IsShrunk();
3458               bool isShrunkable = ac->IsShrunkable();
3459               mi->popup()->setItemChecked( 213, isShrunk );   
3460               mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable);
3461             }
3462             // Scalar Bar
3463             mi = popup->findItem( 2000 );
3464             if ( mi && mi->popup() ) {
3465               SMESH_Actor::eControl cMode = ac->GetControlMode();
3466               switch ( cMode ) {
3467               case SMESH_Actor::eLengthEdges:
3468                 mi->popup()->setItemChecked( 6001, true ); break;
3469               case SMESH_Actor::eFreeBorders:
3470                 mi->popup()->setItemChecked( 6003, true );
3471                 mi->popup()->removeItem( 201 );
3472                 break;
3473               case SMESH_Actor::eMultiConnection:
3474                 mi->popup()->setItemChecked( 6004, true ); break;
3475               case SMESH_Actor::eArea:
3476                 mi->popup()->setItemChecked( 6011, true ); break;
3477               case SMESH_Actor::eTaper:
3478                 mi->popup()->setItemChecked( 6012, true ); break;
3479               case SMESH_Actor::eAspectRatio:
3480                 mi->popup()->setItemChecked( 6013, true ); break;
3481               case SMESH_Actor::eMinimumAngle:
3482                 mi->popup()->setItemChecked( 6014, true ); break;
3483               case SMESH_Actor::eWarping:
3484                 mi->popup()->setItemChecked( 6015, true ); break;
3485               case SMESH_Actor::eSkew:
3486                 mi->popup()->setItemChecked( 6016, true ); break;
3487               case SMESH_Actor::eNone:
3488               default:
3489                 mi->popup()->removeItem( 200 );
3490                 mi->popup()->removeItem( 201 );
3491                 break;
3492               }
3493               TVisualObjPtr aVisualObj = ac->GetObject();
3494               SMESH::ElementType aType;
3495               if(!aNbEdges){
3496                 mi->popup()->removeItem( 6001 );
3497                 mi->popup()->removeItem( 6003 );
3498                 mi->popup()->removeItem( 6004 );
3499               }
3500               if(!aNbFaces){
3501                 mi->popup()->removeItem( 6011 );
3502                 mi->popup()->removeItem( 6012 );
3503                 mi->popup()->removeItem( 6013 );
3504                 mi->popup()->removeItem( 6014 );
3505                 mi->popup()->removeItem( 6015 );
3506                 mi->popup()->removeItem( 6016 );
3507               }
3508               if(!aNbFaces && !aNbEdges)
3509                 popup->removeItem( 2000 );                         // Scalar Bar
3510             }
3511           }
3512           else {
3513             popup->removeItem( QAD_Erase_Popup_ID );
3514             popup->removeItem( 114 );                              // Numbering popup menu
3515             popup->removeItem( 1131 );                             // Display mode
3516             popup->removeItem( 1132 );                             // Color / size
3517             popup->removeItem( 1133 );                             // Transparency
3518             popup->removeItem( 2000 );                             // Scalar Bar
3519           }
3520         }
3521         else {
3522           // object doesn't have actor
3523           CORBA::Object_var anObject = SO->GetObject();
3524           bool bDisplay = false;
3525           if ( !CORBA::is_nil( anObject ) ) {
3526             SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
3527             if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0  || aMeshObj->NbVolumes() > 0 ) )
3528               bDisplay = true;
3529             SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
3530             if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes() > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
3531               bDisplay = true;
3532             SMESH::SMESH_Group_var aGroupObj = SMESH::SMESH_Group::_narrow( anObject );
3533             if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
3534               bDisplay = true;
3535           }
3536           if ( !bDisplay ) {
3537             popup->removeItem( QAD_Display_Popup_ID );
3538             popup->removeItem( QAD_DisplayOnly_Popup_ID );
3539           }
3540           popup->removeItem( QAD_Erase_Popup_ID );
3541           popup->removeItem( 114 );                              // Numbering popup menu
3542           popup->removeItem( 1131 );                             // Display mode
3543           popup->removeItem( 1132 );                             // Color / size
3544           popup->removeItem( 1133 );                             // Transparency
3545           popup->removeItem( 2000 );                             // Scalar Bar
3546         }
3547       }
3548       else {
3549         // another SMESH object
3550         popup->removeItem( QAD_Display_Popup_ID );
3551         popup->removeItem( QAD_DisplayOnly_Popup_ID );
3552         popup->removeItem( QAD_Erase_Popup_ID );
3553       }
3554     }
3555   }
3556   else {
3557     // multiple selection
3558     if ( parentComp != parent->getActiveComponent() ) {
3559       // object not belongs to SMESH module - remove all commands except common Display/Erase...
3560       while ( 1 )       {
3561         int id = popup->idAt( 0 );
3562         if ( id <= QAD_TopLabel_Popup_ID )
3563           popup->removeItemAt( 0 );
3564         else
3565           break;
3566       }
3567       if ( parentComp.isNull() ) {
3568         // objects from different components are selected
3569         popup->removeItem( QAD_DisplayOnly_Popup_ID );
3570         popup->removeItem( QAD_Display_Popup_ID );
3571         popup->removeItem( QAD_Erase_Popup_ID );
3572       }
3573     }
3574     else {
3575       QString type = smeshGUI->CheckHomogeneousSelection();
3576       if ( type != "Heterogeneous Selection" ) {
3577         int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3578         if ( topItem >= 0 ) {
3579           // set bold font for popup menu's TopLabel item
3580           QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3581           popup->removeItem( QAD_TopLabel_Popup_ID );
3582           popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
3583         }
3584       }
3585     }
3586   }
3587   return false;
3588 }
3589
3590 //=============================================================================
3591 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3592  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3593  */
3594 //=============================================================================
3595 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3596 {
3597   if(theIO->hasEntry()){
3598     QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
3599     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
3600     ::UpdateView(aStudyFrame,eDisplay,theIO->getEntry());
3601   }
3602 }
3603
3604 //=============================================================================
3605 /*!
3606  *
3607  */
3608 //=============================================================================
3609 void SMESHGUI::setOrb()
3610 {
3611         try
3612         {
3613                 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
3614                 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
3615                 _orb = init(0, 0);
3616         } catch(...)
3617         {
3618                 INFOS("internal error : orb not found");
3619                 _orb = 0;
3620         }
3621         ASSERT(!CORBA::is_nil(_orb));
3622 }
3623
3624 //=============================================================================
3625 /*!
3626  *
3627  */
3628 //=============================================================================
3629 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr theMesh){}
3630
3631 //=============================================================================
3632 /*!
3633  *
3634  */
3635 //=============================================================================
3636 void SMESHGUI::Dump(SMESH_Actor * Mactor)
3637 {
3638         vtkUnstructuredGrid *ugrid = Mactor->GetUnstructuredGrid();
3639         vtkPoints *Pts = ugrid->GetPoints();
3640         int nbPts = Pts->GetNumberOfPoints();
3641         int nbCells = ugrid->GetNumberOfCells();
3642
3643         FILE *In;
3644         int i, j;
3645         In = fopen("/tmp/dumpMesh", "w+");
3646         fprintf(In, "%d %d\n", nbPts, nbCells);
3647         for (int i = 0; i < nbPts; i++)
3648         {
3649                 float *p = ugrid->GetPoint(i);
3650                 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
3651         }
3652
3653         for (int i = 0; i < nbCells; i++)
3654         {
3655                 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
3656                 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3657                 for (j = 0; j < Id->GetNumberOfIds(); j++)
3658                 {
3659                         fprintf(In, " %d", Id->GetId(j));
3660                 }
3661                 fprintf(In, "\n");
3662         }
3663         fclose(In);
3664 }
3665
3666 //=============================================================================
3667 /*!
3668  *
3669  */
3670 //=============================================================================
3671 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr theMesh,
3672                            const TColStd_MapOfInteger & MapIndex)
3673 {
3674   QAD_WaitCursor wc;
3675   try{
3676     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3677     CORBA::String_var anEntry = aSobj->GetID();
3678     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3679       SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3680       anArrayOfIdeces->length(MapIndex.Extent());
3681       TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3682       for(int i = 0; ite.More(); ite.Next(), i++){
3683         anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
3684       }
3685       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3686       aMeshEditor->RemoveNodes(anArrayOfIdeces);
3687       if(myAutomaticUpdate){
3688         CORBA::Long anId = smeshGUI->myStudy->StudyId();
3689         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3690           aVisualObj->Update(true);
3691         }
3692       }
3693     }
3694   }catch(SALOME::SALOME_Exception& exc) {
3695     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3696   }catch(const std::exception& exc){
3697     INFOS("Follow exception was cought:\n\t"<<exc.what());
3698   }catch(...){
3699     INFOS("Unknown exception was cought !!!");
3700   }
3701 }
3702
3703 //=============================================================================
3704 /*!
3705  *
3706  */
3707 //=============================================================================
3708 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr theMesh,
3709                               const TColStd_MapOfInteger & MapIndex)
3710 {
3711   QAD_WaitCursor wc;
3712   try{
3713     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3714     CORBA::String_var anEntry = aSobj->GetID();
3715     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3716       SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3717       anArrayOfIdeces->length(MapIndex.Extent());
3718       TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3719       for(int i = 0; ite.More(); ite.Next(), i++){
3720         anArrayOfIdeces[i] = anActor->GetElemObjId(ite.Key());
3721       }
3722       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3723       aMeshEditor->RemoveElements(anArrayOfIdeces);
3724       if(myAutomaticUpdate){
3725         CORBA::Long anId = smeshGUI->myStudy->StudyId();
3726         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3727           aVisualObj->Update(true);
3728         }
3729       }
3730     }
3731   }catch(SALOME::SALOME_Exception& exc) {
3732     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3733   }catch(const std::exception& exc){
3734     INFOS("Follow exception was cought:\n\t"<<exc.what());
3735   }catch(...){
3736     INFOS("Unknown exception was cought !!!");
3737   }
3738 }
3739
3740 //=============================================================================
3741 /*!
3742  *
3743  */
3744 //=============================================================================
3745 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
3746         const TColStd_MapOfInteger & MapIndex)
3747 {
3748   MESSAGE("OrientationElements - not implemeted yet!");
3749 }
3750
3751 //=============================================================================
3752 /*!
3753  *
3754  */
3755 //=============================================================================
3756 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
3757         const TColStd_MapOfInteger & MapIndex)
3758 {
3759   MESSAGE("OrientationElements - not implemeted yet!");
3760 }
3761
3762 //=====================================================================================
3763 // EXPORTED METHODS
3764 //=====================================================================================
3765 extern "C"
3766 {
3767         bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
3768         {
3769                 return SMESHGUI::OnGUIEvent(theCommandID, parent);
3770         }
3771
3772         bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3773                 QAD_StudyFrame * studyFrame)
3774         {
3775                 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
3776         }
3777
3778         bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3779                 QAD_StudyFrame * studyFrame)
3780         {
3781                 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
3782         }
3783
3784         bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3785                 QAD_StudyFrame * studyFrame)
3786         {
3787                 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
3788         }
3789
3790         bool SetSettings(QAD_Desktop * parent)
3791         {
3792                 return SMESHGUI::SetSettings(parent);
3793         }
3794
3795         bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
3796                 const QString & theContext, const QString & theParent,
3797                 const QString & theObject)
3798         {
3799                 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
3800                         theObject);
3801         }
3802
3803         void definePopup(QString & theContext, QString & theParent,
3804                 QString & theObject)
3805         {
3806                 SMESHGUI::DefinePopup(theContext, theParent, theObject);
3807         }
3808
3809         bool activeStudyChanged(QAD_Desktop * parent)
3810         {
3811                 SMESHGUI::activeStudyChanged(parent);
3812         }
3813
3814         void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3815         {
3816                 SMESHGUI::BuildPresentation(theIO);
3817         }
3818
3819         void supportedViewType(int *buffer, int bufferSize)
3820         {
3821                 if (!buffer || !bufferSize)
3822                         return;
3823                 buffer[0] = (int)VIEW_VTK;
3824         }
3825
3826         void deactivate()
3827         {
3828           if ( SMESHGUI::GetSMESHGUI() ) {
3829             SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
3830           }
3831         }
3832
3833 }
3834
3835 //=============================================================================
3836 /*!
3837  *
3838  */
3839 //=============================================================================
3840 void SMESHGUI::SetPickable(SMESH_Actor* theActor){
3841   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
3842     int anIsAllPickable = (theActor == NULL);
3843     vtkRenderer *aRenderer = aViewFrame->getRenderer();
3844     vtkActorCollection *aCollection = aRenderer->GetActors();
3845     aCollection->InitTraversal();
3846     while(vtkActor *anAct = aCollection->GetNextActor()){
3847       if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
3848         if(anActor->GetVisibility()){
3849           anActor->SetPickable(anIsAllPickable);
3850         }
3851       }
3852     }
3853     if(theActor)
3854       theActor->SetPickable(!anIsAllPickable);
3855     RepaintCurrentView();
3856   }
3857 }
3858
3859
3860 void SMESHGUI::ViewNodes(){
3861   EraseSimulationActors();
3862   ::SetPointRepresentation(true);
3863 }
3864
3865 //=============================================================================
3866 /*!
3867  *
3868  */
3869 //=============================================================================
3870 void SMESHGUI::Control( int theCommandID ){
3871   SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3872   if(Sel){
3873     Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
3874     if(!anIO.IsNull()){
3875       QString aTitle;
3876       SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
3877       if(SMESH_Actor *anActor = ::FindActorByEntry(anIO->getEntry())){
3878         switch ( theCommandID ){
3879         case 6001:
3880           aTitle = tr( "LENGTH_EDGES" );
3881           aControl = SMESH_Actor::eLengthEdges;
3882           break;
3883         case 6003:
3884           aTitle = tr( "FREE_BORDERS" );
3885           aControl = SMESH_Actor::eFreeBorders;
3886           break;
3887         case 6004:
3888           aTitle = tr( "MULTI_BORDERS" );
3889           aControl = SMESH_Actor::eMultiConnection;
3890           break;
3891         case 6011:
3892           aTitle = tr( "AREA_ELEMENTS" );
3893           aControl = SMESH_Actor::eArea;
3894           break;
3895         case 6012:
3896           aTitle = tr( "TAPER_ELEMENTS" );
3897           aControl = SMESH_Actor::eTaper;
3898           break;
3899         case 6013:
3900           aTitle = tr( "ASPECTRATIO_ELEMENTS" );
3901           aControl = SMESH_Actor::eAspectRatio;
3902           break;
3903         case 6014:
3904           aTitle = tr( "MINIMUMANGLE_ELEMENTS" );
3905           aControl = SMESH_Actor::eMinimumAngle;
3906           break;
3907         case 6015:
3908           aTitle = tr( "WARP_ELEMENTS" );
3909           aControl = SMESH_Actor::eWarping;
3910           break;
3911         case 6016:
3912           aTitle = tr( "SKEW_ELEMENTS" );
3913           aControl = SMESH_Actor::eSkew;
3914           break;
3915         }
3916         anActor->SetControlMode(aControl);
3917         anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
3918       }
3919     }
3920   }
3921 }
3922
3923 //=============================================================================
3924 /*!
3925  *
3926  */
3927 //=============================================================================
3928 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
3929                                     QString Bold, 
3930                                     QString Italic,
3931                                     QString Shadow, 
3932                                     QString FontFamily,
3933                                     QString Orientation, 
3934                                     float Width, 
3935                                     float Height, 
3936                                     int NbColors, 
3937                                     int NbLabels)
3938 {
3939   if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
3940     theScalarBar->BoldOn();
3941   else
3942     theScalarBar->BoldOff();
3943   
3944   if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
3945     theScalarBar->ItalicOn();
3946   else
3947     theScalarBar->ItalicOff();
3948   
3949   if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
3950     theScalarBar->ShadowOn();
3951   else
3952     theScalarBar->ShadowOff();
3953   
3954   if (FontFamily.compare("Arial") == 0)
3955     theScalarBar->SetFontFamilyToArial();
3956   else if (FontFamily.compare("Courier") == 0)
3957     theScalarBar->SetFontFamilyToCourier();
3958   else if (FontFamily.compare("Times") == 0)
3959     theScalarBar->SetFontFamilyToTimes();
3960   else
3961     theScalarBar->SetFontFamilyToArial();
3962   
3963   if (Orientation.isNull() || Orientation.isEmpty() ||
3964       (Orientation.compare("Vertical") == 0))
3965     theScalarBar->SetOrientationToVertical();
3966   else
3967     theScalarBar->SetOrientationToHorizontal();
3968   
3969   theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
3970   theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
3971   
3972   theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
3973   theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
3974 }
3975
3976 //=============================================================================
3977 /*!
3978  *
3979  */
3980 //=============================================================================
3981 void SMESHGUI::SetDisplaySettings()
3982 {
3983   EmitSignalDeactivateDialog();
3984   SMESHGUI_Preferences_ColorDlg *aDlg =
3985     new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
3986
3987   QColor color;
3988   QString SCr, SCg, SCb;
3989   SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
3990   SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
3991   SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
3992   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3993     color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
3994   else color = QColor(0, 170, 255);
3995   aDlg->SetColor(1, color);
3996
3997   SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
3998   SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
3999   SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4000   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4001     color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4002   else color = QColor(0, 170, 255);
4003   aDlg->SetColor(2, color);
4004
4005   SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4006   SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4007   SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4008   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4009     color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4010   else color = Qt::red;
4011   aDlg->SetColor(3, color);
4012
4013   QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4014   QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4015   QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4016   if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4017     color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
4018   else color = Qt::blue;
4019   aDlg->SetColor(4, color);
4020
4021   QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4022   if (intValue.isEmpty()) intValue = "1";
4023   aDlg->SetIntValue(1, intValue.toInt());
4024   intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4025   if (intValue.isEmpty()) intValue = "3";
4026   aDlg->SetIntValue(2, intValue.toInt());
4027   intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4028   if (intValue.isEmpty()) intValue = "75";
4029   aDlg->SetIntValue(3, intValue.toInt());
4030
4031   if (aDlg->exec()) {
4032     QColor colorFill = aDlg->GetColor(1);
4033     QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4034     QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4035     QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4036
4037     QColor colorOutline = aDlg->GetColor(2);
4038     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4039     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4040     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4041
4042     QColor colorNode = aDlg->GetColor(3);
4043     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4044     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4045     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4046
4047     QColor colorBackFace = aDlg->GetColor(4);
4048     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4049     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4050     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4051
4052     int width = aDlg->GetIntValue(1);
4053     QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4054
4055     int nodes_size = aDlg->GetIntValue(2);
4056     QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4057
4058     int shrink_coeff = aDlg->GetIntValue(3);
4059     QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4060   }
4061
4062   delete aDlg;
4063 }
4064
4065 //=======================================================================
4066 // function : Parameter()
4067 // purpose  : return a parameter (double) from a dialog box
4068 //
4069 //  aValue     : is a double used as a default value displayed
4070 //  aLabel     : is the title for aValue1
4071 //  aTitle     : is the main title
4072 //  bottom     : maximum value to be entered
4073 //  top        : minimum value to be entered
4074 //  decimals   : number of decimals
4075 //=======================================================================
4076 double SMESHGUI::Parameter(Standard_Boolean & res,
4077         const double aValue,
4078         const char *aLabel,
4079         const char *aTitle,
4080         const double bottom, const double top, const int decimals)
4081 {
4082         SMESHGUI_aParameterDlg *Dialog =
4083                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4084                 aTitle,
4085                 aLabel,
4086                 bottom, top, decimals,
4087                 TRUE);
4088         Dialog->setValue(aValue);
4089         double X = 0.0;
4090         res = (Dialog->exec() == QDialog::Accepted);
4091         if (res)
4092                 X = Dialog->getDblValue();
4093         return X;
4094 }
4095
4096 //=======================================================================
4097 // function : Parameter()
4098 // purpose  : return a parameter (int) from a dialog box
4099 //
4100 //  aValue     : is a int used as a default value displayed
4101 //  aLabel     : is the title for aValue1
4102 //  aTitle     : is the main title
4103 //  bottom     : maximum value to be entered
4104 //  top        : minimum value to be entered
4105 //=======================================================================
4106 int SMESHGUI::Parameter(Standard_Boolean & res,
4107         const int aValue,
4108         const char *aLabel, const char *aTitle, const int bottom, const int top)
4109 {
4110         SMESHGUI_aParameterDlg *Dialog =
4111                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4112                 aTitle,
4113                 aLabel,
4114                 bottom, top,
4115                 TRUE);
4116         Dialog->setValue(aValue);
4117         int X = 0;
4118         res = (Dialog->exec() == QDialog::Accepted);
4119         if (res)
4120                 X = Dialog->getIntValue();
4121         return X;
4122 }
4123
4124 //=============================================================================
4125 /*!
4126  *
4127  */
4128 //=============================================================================
4129 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility){}
4130
4131 //=============================================================================
4132 /*!
4133  *
4134  */
4135 //=============================================================================
4136 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh){}
4137
4138 //=============================================================================
4139 /*!
4140  *
4141  */
4142 //=============================================================================
4143 void SMESHGUI::Update(){
4144   if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
4145     SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4146     if(Sel->IObjectCount() == 0){
4147       vtkRenderer* aRenderer = aViewFrame->getRenderer();
4148       vtkActorCollection *aCollection = aRenderer->GetActors();
4149       aCollection->InitTraversal();
4150       while(vtkActor *anAct = aCollection->GetNextActor()){
4151         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
4152           if(anActor->hasIO()){
4153             Update(anActor->getIO());
4154           }
4155         }
4156       }
4157     }else{
4158       SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4159       for(; It.More(); It.Next()){
4160         Handle(SALOME_InteractiveObject) IO = It.Value();
4161         Update(IO);
4162       }
4163     }
4164     ::RepaintCurrentView();
4165   }
4166 }
4167
4168 //=============================================================================
4169 /*!
4170  *
4171  */
4172 //=============================================================================
4173 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & theIO){
4174   CORBA::Long anId = smeshGUI->myStudy->StudyId();
4175   TVisualObjPtr aVisualObj = ::GetVisualObj(anId,theIO->getEntry());
4176   aVisualObj->Update();
4177   ::UpdateView(eDisplay,theIO->getEntry());
4178 }
4179
4180 //=============================================================================
4181 /*!
4182  *
4183  */
4184 //=============================================================================
4185 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
4186 {
4187         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4188                 return NULL;
4189
4190         mySimulationActors = vtkActorCollection::New();
4191         vtkRenderer *theRenderer =
4192                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4193                 getRightFrame()->getViewFrame())->getRenderer();
4194
4195         vtkUnstructuredGrid *ugrid =
4196                 vtkUnstructuredGrid::SafeDownCast(Mactor->GetUnstructuredGrid());
4197         vtkIdList *IdCells = vtkIdList::New();
4198         ugrid->GetPointCells(idnode, IdCells);
4199
4200         vtkPoints *Pts = vtkPoints::New();
4201         Pts = ugrid->GetPoints();
4202
4203         vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
4204         ugridSimulation->SetPoints(Pts);
4205         vtkIdList *IdPts = vtkIdList::New();
4206         for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
4207         {
4208                 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
4209                 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
4210                         IdPts);
4211         }
4212
4213         vtkProperty *prop = vtkProperty::New();
4214         prop->SetColor(1., 0., 0.);
4215         prop->SetRepresentationToWireframe();
4216
4217         int Edgewidth = (int)Mactor->GetLineWidth();
4218         if (Edgewidth == 0)
4219                 Edgewidth = 1;
4220         prop->SetLineWidth(Edgewidth + 1);
4221
4222         vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4223         Mapper->SetInput(ugridSimulation);
4224         vtkActor *ac = vtkActor::New();
4225         ac->SetMapper(Mapper);
4226         ac->SetProperty(prop);
4227
4228         ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
4229         ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
4230
4231         mySimulationActors->AddItem(ac);
4232         theRenderer->AddActor(ac);
4233
4234         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4235         renWin->Render();
4236
4237         return ac;
4238 }
4239
4240 //=============================================================================
4241 /*!
4242  *
4243  */
4244 //=============================================================================
4245 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
4246         float y, float z)
4247 {
4248         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4249                 return;
4250
4251         EraseSimulationActors();
4252         mySimulationActors = vtkActorCollection::New();
4253         vtkRenderer *theRenderer =
4254                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4255                 getRightFrame()->getViewFrame())->getRenderer();
4256         Standard_Boolean result;
4257         SMESH_Actor *ac = FindActor(aMesh, result, true);
4258
4259         if (result)
4260         {
4261                 vtkUnstructuredGrid *ugrid =
4262                         vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4263                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4264
4265                 vtkPoints *Pts = ugrid->GetPoints();
4266                 vtkPoints *newPts = vtkPoints::New();
4267                 int nbPts = Pts->GetNumberOfPoints();
4268                 for (int i = 0; i < nbPts; i++)
4269                 {
4270                         newPts->InsertPoint(i, Pts->GetPoint(i));
4271                 }
4272
4273                 newugrid->SetPoints(newPts);
4274                 newugrid->GetPoints()->InsertNextPoint(x, y, z);
4275
4276                 vtkMaskPoints *verts = vtkMaskPoints::New();
4277                 verts->SetInput(newugrid);
4278                 verts->SetGenerateVertices(1);
4279                 verts->SetOnRatio(1);
4280
4281                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4282                 vertMapper->SetInput(verts->GetOutput());
4283                 vertMapper->ScalarVisibilityOff();
4284
4285                 vtkActor *node = vtkActor::New();
4286                 node->SetMapper(vertMapper);
4287
4288                 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4289                 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4290                 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4291                 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4292                 if (!nodecolor.isValid())
4293 //       nodecolor = QColor(0.,1.,0.);
4294                         nodecolor = QColor(0, 1, 0);
4295
4296                 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
4297                         float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
4298
4299                 int intValue =
4300                         QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
4301                 if (intValue < 1)
4302                         intValue == 1;
4303
4304                 node->GetProperty()->SetPointSize(intValue);
4305
4306                 node->VisibilityOn();
4307
4308                 mySimulationActors->AddItem(node);
4309                 theRenderer->AddActor(node);
4310         }
4311
4312         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4313         renWin->Render();
4314 }
4315
4316 //=============================================================================
4317 /*!
4318  *
4319  */
4320 //=============================================================================
4321 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
4322         float y, float z)
4323 {
4324         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4325                 return;
4326
4327         vtkRenderer *theRenderer =
4328                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4329                 getRightFrame()->getViewFrame())->getRenderer();
4330         float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
4331         pt[0] = x;
4332         pt[1] = y;
4333         pt[2] = z;
4334
4335         ac->GetMapper()->ImmediateModeRenderingOn();
4336         ac->GetProperty()->SetRepresentationToWireframe();
4337
4338         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4339
4340         renWin->Render();
4341 }
4342
4343 //=============================================================================
4344 /*!
4345  *
4346  */
4347 //=============================================================================
4348 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
4349         float y, float z)
4350 {
4351         Standard_Boolean result;
4352
4353         SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
4354         if (result)
4355         {
4356         }
4357 }
4358
4359 //=============================================================================
4360 /*!
4361  *
4362  */
4363 //=============================================================================
4364 void SMESHGUI::ScalarVisibilityOff(){
4365   if(vtkRenderer *aRenderer = ::GetCurrentRenderer()){
4366     vtkActorCollection *actorList = aRenderer->GetActors();
4367     actorList->InitTraversal();
4368     while(vtkActor *ac = actorList->GetNextActor()){
4369       if(SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac)){
4370         anActor->GetMapper()->ScalarVisibilityOff();
4371       }
4372     }
4373     ::RepaintCurrentView();
4374   }
4375 }
4376
4377 //=============================================================================
4378 /*!
4379  *
4380  */
4381 //=============================================================================
4382 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
4383         const TColStd_MapOfInteger & MapIndex)
4384 {
4385         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4386                 return;
4387
4388         EraseSimulationActors();
4389         mySimulationActors = vtkActorCollection::New();
4390         vtkRenderer *theRenderer =
4391                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4392                 getRightFrame()->getViewFrame())->getRenderer();
4393         Standard_Boolean result;
4394         SMESH_Actor *ac = FindActor(aMesh, result, true);
4395         if (result)
4396         {
4397                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4398                 int idNodes[2];
4399                 int pts[2];
4400                 int i = 0;
4401                 vtkIdList *Ids = vtkIdList::New();
4402                 for (; ite.More(); ite.Next())
4403                 {
4404                         idNodes[i] = ite.Key();
4405                         i++;
4406                 }
4407
4408                 Ids->InsertId(0, idNodes[0]);
4409                 pts[0] = idNodes[0];
4410                 Ids->InsertId(1, idNodes[1]);
4411                 pts[1] = idNodes[1];
4412
4413                 vtkUnstructuredGrid *ugrid =
4414                         vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4415                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4416                 newugrid->SetPoints(ugrid->GetPoints());
4417                 newugrid->InsertNextCell(VTK_LINE, 2, pts);
4418
4419                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4420                 Mapper->SetInput(newugrid);
4421                 Mapper->Update();
4422
4423                 vtkActor *edge = vtkActor::New();
4424                 edge->SetMapper(Mapper);
4425                 edge->SetProperty(ac->GetProperty());
4426                 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
4427                 edge->VisibilityOn();
4428                 mySimulationActors->AddItem(edge);
4429                 theRenderer->AddActor(edge);
4430         }
4431
4432         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4433         renWin->Render();
4434 }
4435
4436 //=============================================================================
4437 /*!
4438  *
4439  */
4440 //=============================================================================
4441 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
4442         const TColStd_MapOfInteger & MapIndex, bool reverse)
4443 {
4444         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4445                 return;
4446
4447         EraseSimulationActors();
4448         mySimulationActors = vtkActorCollection::New();
4449         vtkRenderer *theRenderer =
4450                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4451                 getRightFrame()->getViewFrame())->getRenderer();
4452         Standard_Boolean result;
4453         SMESH_Actor *ac = FindActor(aMesh, result, true);
4454         if (result)
4455         {
4456                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4457                 int idNodes[3];
4458                 int pts[3];
4459                 int i = 0;
4460                 vtkIdList *Ids = vtkIdList::New();
4461                 for (; ite.More(); ite.Next())
4462                 {
4463                         idNodes[i] = ite.Key();
4464                         i++;
4465                 }
4466
4467                 if (reverse)
4468                 {
4469                         Ids->InsertId(0, idNodes[2]);
4470                         pts[0] = idNodes[2];
4471                         Ids->InsertId(1, idNodes[1]);
4472                         pts[1] = idNodes[1];
4473                         Ids->InsertId(2, idNodes[0]);
4474                         pts[2] = idNodes[0];
4475                 }
4476                 else
4477                 {
4478                         Ids->InsertId(0, idNodes[0]);
4479                         pts[0] = idNodes[0];
4480                         Ids->InsertId(1, idNodes[1]);
4481                         pts[1] = idNodes[1];
4482                         Ids->InsertId(2, idNodes[2]);
4483                         pts[2] = idNodes[2];
4484                 }
4485                 vtkUnstructuredGrid *ugrid =
4486                         vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4487                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4488                 newugrid->SetPoints(ugrid->GetPoints());
4489                 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
4490
4491                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4492                 Mapper->SetInput(newugrid);
4493                 Mapper->Update();
4494
4495                 vtkActor *tri = vtkActor::New();
4496                 tri->SetMapper(Mapper);
4497                 tri->SetProperty(ac->GetProperty());
4498                 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
4499                 tri->VisibilityOn();
4500                 mySimulationActors->AddItem(tri);
4501                 theRenderer->AddActor(tri);
4502         }
4503
4504         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4505         renWin->Render();
4506 }
4507
4508 //=============================================================================
4509 /*!
4510  *
4511  */
4512 //=============================================================================
4513 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
4514         const TColStd_MapOfInteger & MapIndex, bool reverse)
4515 {
4516         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4517                 return;
4518
4519         EraseSimulationActors();
4520         mySimulationActors = vtkActorCollection::New();
4521         vtkRenderer *theRenderer =
4522                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4523                 getRightFrame()->getViewFrame())->getRenderer();
4524         Standard_Boolean result;
4525         SMESH_Actor *ac = FindActor(aMesh, result, true);
4526
4527         vtkUnstructuredGrid *ugrid =
4528                 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4529
4530         if (result)
4531         {
4532                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4533                 int i = 0;
4534                 int idNodes[4];
4535                 vtkIdList *Ids = vtkIdList::New();
4536                 for (; ite.More(); ite.Next())
4537                 {
4538                         idNodes[i] = ite.Key();
4539                         i++;
4540                 }
4541
4542                 float *p0 = ugrid->GetPoint(idNodes[0]);
4543                 float *p1 = ugrid->GetPoint(idNodes[1]);
4544                 float *p2 = ugrid->GetPoint(idNodes[2]);
4545                 float *p3 = ugrid->GetPoint(idNodes[3]);
4546
4547                 gp_Pnt P0(p0[0], p0[1], p0[2]);
4548
4549                 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4550                 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4551                 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4552
4553                 gp_Vec Cross1 = V1 ^ V2;
4554                 gp_Vec Cross2 = V2 ^ V3;
4555
4556                 int tmp;
4557                 if (Cross1.Dot(Cross2) < 0)
4558                 {
4559                         V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4560                         V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4561                         Cross1 = V1 ^ V2;
4562                         Cross2 = V2 ^ V3;
4563
4564                         if (Cross1.Dot(Cross2) < 0)
4565                         {
4566                                 tmp = idNodes[2];
4567                                 idNodes[2] = idNodes[3];
4568                                 idNodes[3] = tmp;
4569                         }
4570                         else
4571                         {
4572                                 tmp = idNodes[1];
4573                                 idNodes[1] = idNodes[2];
4574                                 idNodes[2] = tmp;
4575                         }
4576                 }
4577
4578                 if (reverse)
4579                 {
4580                         Ids->InsertId(0, idNodes[3]);
4581                         Ids->InsertId(1, idNodes[2]);
4582                         Ids->InsertId(2, idNodes[1]);
4583                         Ids->InsertId(3, idNodes[0]);
4584                 }
4585                 else
4586                 {
4587                         Ids->InsertId(0, idNodes[0]);
4588                         Ids->InsertId(1, idNodes[1]);
4589                         Ids->InsertId(2, idNodes[2]);
4590                         Ids->InsertId(3, idNodes[3]);
4591                 }
4592
4593                 //    vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->GetUnstructuredGrid() );
4594                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4595                 newugrid->SetPoints(ugrid->GetPoints());
4596                 newugrid->InsertNextCell(VTK_QUAD, Ids);
4597
4598                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4599                 Mapper->SetInput(newugrid);
4600                 Mapper->Update();
4601
4602                 vtkActor *quad = vtkActor::New();
4603                 quad->SetMapper(Mapper);
4604                 quad->SetProperty(ac->GetProperty());
4605                 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
4606                 quad->VisibilityOn();
4607                 mySimulationActors->AddItem(quad);
4608                 theRenderer->AddActor(quad);
4609         }
4610         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4611         renWin->Render();
4612 }
4613
4614 //=============================================================================
4615 /*!
4616  *
4617  */
4618 //=============================================================================
4619 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
4620         const TColStd_MapOfInteger & MapIndex)
4621 {
4622         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4623                 return;
4624
4625         EraseSimulationActors();
4626         mySimulationActors = vtkActorCollection::New();
4627         vtkRenderer *theRenderer =
4628                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4629                 getRightFrame()->getViewFrame())->getRenderer();
4630         Standard_Boolean result;
4631         SMESH_Actor *ac = FindActor(aMesh, result, true);
4632         if (result)
4633         {
4634                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4635                 int i = 0;
4636                 int idNodes[4];
4637                 vtkIdList *Ids = vtkIdList::New();
4638                 for (; ite.More(); ite.Next())
4639                 {
4640                         idNodes[i] = ite.Key();
4641                         i++;
4642                 }
4643
4644                 Ids->InsertId(0, idNodes[0]);
4645                 Ids->InsertId(1, idNodes[1]);
4646                 Ids->InsertId(2, idNodes[2]);
4647                 Ids->InsertId(3, idNodes[3]);
4648
4649                 vtkUnstructuredGrid *ugrid =
4650                         vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4651                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4652                 newugrid->SetPoints(ugrid->GetPoints());
4653                 newugrid->InsertNextCell(VTK_TETRA, Ids);
4654
4655                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4656                 Mapper->SetInput(newugrid);
4657                 Mapper->Update();
4658
4659                 vtkActor *tetra = vtkActor::New();
4660                 tetra->SetMapper(Mapper);
4661                 tetra->SetProperty(ac->GetProperty());
4662                 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
4663                 tetra->VisibilityOn();
4664                 mySimulationActors->AddItem(tetra);
4665                 theRenderer->AddActor(tetra);
4666         }
4667         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4668         renWin->Render();
4669 }
4670
4671 //=============================================================================
4672 /*!
4673  *
4674  */
4675 //=============================================================================
4676 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
4677         const TColStd_MapOfInteger & MapIndex)
4678 {
4679         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4680                 return;
4681
4682         EraseSimulationActors();
4683         mySimulationActors = vtkActorCollection::New();
4684         vtkRenderer *theRenderer =
4685                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4686                 getRightFrame()->getViewFrame())->getRenderer();
4687         Standard_Boolean result;
4688         SMESH_Actor *ac = FindActor(aMesh, result, true);
4689         if (result)
4690         {
4691                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4692                 int i = 0;
4693                 int idNodes[8];
4694                 vtkIdList *Ids = vtkIdList::New();
4695                 for (; ite.More(); ite.Next())
4696                 {
4697                         idNodes[i] = ite.Key();
4698                         i++;
4699                 }
4700
4701                 Ids->InsertId(0, idNodes[0]);
4702                 Ids->InsertId(1, idNodes[1]);
4703                 Ids->InsertId(2, idNodes[2]);
4704                 Ids->InsertId(3, idNodes[3]);
4705                 Ids->InsertId(4, idNodes[4]);
4706                 Ids->InsertId(5, idNodes[5]);
4707                 Ids->InsertId(6, idNodes[6]);
4708                 Ids->InsertId(7, idNodes[7]);
4709
4710                 vtkUnstructuredGrid *ugrid =
4711                         vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4712                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4713                 newugrid->SetPoints(ugrid->GetPoints());
4714                 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4715
4716                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4717                 Mapper->SetInput(newugrid);
4718                 Mapper->Update();
4719
4720                 vtkActor *hexa = vtkActor::New();
4721                 hexa->SetMapper(Mapper);
4722                 hexa->SetProperty(ac->GetProperty());
4723                 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
4724                 hexa->VisibilityOn();
4725                 mySimulationActors->AddItem(hexa);
4726                 theRenderer->AddActor(hexa);
4727         }
4728         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4729         renWin->Render();
4730 }
4731
4732 //=============================================================================
4733 /*!
4734  *
4735  */
4736 //=============================================================================
4737 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr theMesh,
4738                        const TColStd_MapOfInteger & MapIndex, 
4739                        bool reverse)
4740 {
4741   QAD_WaitCursor wc;
4742   try{
4743     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4744     CORBA::String_var anEntry = aSobj->GetID();
4745     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4746       SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4747       anArrayOfIdeces->length(MapIndex.Extent());
4748       TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4749       for(int i = 0; ite.More(); ite.Next(), i++){
4750         anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4751       }
4752       int tmp;
4753       if(MapIndex.Extent() == 4){
4754         int idNodes[4];
4755         TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
4756         for(int i = 0; ite1.More(); ite1.Next(), i++){
4757           idNodes[i] = ite1.Key();
4758         }
4759         vtkUnstructuredGrid *ugrid = anActor->GetUnstructuredGrid();
4760         float *p0 = ugrid->GetPoint(idNodes[0]);
4761         float *p1 = ugrid->GetPoint(idNodes[1]);
4762         float *p2 = ugrid->GetPoint(idNodes[2]);
4763         float *p3 = ugrid->GetPoint(idNodes[3]);
4764         
4765         gp_Pnt P0(p0[0], p0[1], p0[2]);
4766         
4767         gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4768         gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4769         gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4770         
4771         gp_Vec Cross1 = V1 ^ V2;
4772         gp_Vec Cross2 = V2 ^ V3;
4773         
4774         if(Cross1.Dot(Cross2) < 0){
4775           V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4776           V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4777           Cross1 = V1 ^ V2;
4778           Cross2 = V2 ^ V3;
4779           
4780           if(Cross1.Dot(Cross2) < 0){
4781             tmp = anArrayOfIdeces[2];
4782             anArrayOfIdeces[2] = anArrayOfIdeces[3];
4783             anArrayOfIdeces[3] = tmp;
4784           }else{
4785             tmp = anArrayOfIdeces[1];
4786             anArrayOfIdeces[1] = anArrayOfIdeces[2];
4787             anArrayOfIdeces[2] = tmp;
4788           }
4789         }
4790       }
4791       if(reverse){
4792         for(int i = 0; i < (MapIndex.Extent() / 2); i++){
4793           tmp = anArrayOfIdeces[i];
4794           anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
4795           anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
4796         }
4797       }
4798       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4799       aMeshEditor->AddFace(anArrayOfIdeces);
4800       if(myAutomaticUpdate){
4801         CORBA::Long anId = smeshGUI->myStudy->StudyId();
4802         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4803           aVisualObj->Update(true);
4804         }
4805         AddActorInSelection(anActor);
4806       }
4807     }
4808   }catch(SALOME::SALOME_Exception& exc) {
4809     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4810   }catch(const std::exception& exc){
4811     INFOS("Follow exception was cought:\n\t"<<exc.what());
4812   }catch(...){
4813     INFOS("Unknown exception was cought !!!");
4814   }
4815 }
4816
4817 //=============================================================================
4818 /*!
4819  *
4820  */
4821 //=============================================================================
4822 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr theMesh,
4823                          const TColStd_MapOfInteger & MapIndex)
4824 {
4825   QAD_WaitCursor wc;
4826   try{
4827     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4828     CORBA::String_var anEntry = aSobj->GetID();
4829     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4830       SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4831       anArrayOfIdeces->length(MapIndex.Extent());
4832       TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4833       for(int i = 0; ite.More(); ite.Next(), i++){
4834         anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4835       }
4836       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4837       aMeshEditor->AddVolume(anArrayOfIdeces);
4838       if(myAutomaticUpdate){
4839         CORBA::Long anId = smeshGUI->myStudy->StudyId();
4840         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4841           aVisualObj->Update(true);
4842         }
4843       }
4844     }
4845   }catch(SALOME::SALOME_Exception& exc) {
4846     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4847   }catch(const std::exception& exc){
4848     INFOS("Follow exception was cought:\n\t"<<exc.what());
4849   }catch(...){
4850     INFOS("Unknown exception was cought !!!");
4851   }
4852 }
4853 //=============================================================================
4854 /*!
4855  *
4856  */
4857 //=============================================================================
4858 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr theMesh,
4859                        const TColStd_MapOfInteger & MapIndex)
4860 {
4861   QAD_WaitCursor wc;
4862   try{
4863     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4864     CORBA::String_var anEntry = aSobj->GetID();
4865     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4866       SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4867       anArrayOfIdeces->length(MapIndex.Extent());
4868       TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4869       for(int i = 0; ite.More(); ite.Next(), i++){
4870         anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4871       }
4872       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4873       aMeshEditor->AddEdge(anArrayOfIdeces);
4874       if(myAutomaticUpdate){
4875         CORBA::Long anId = smeshGUI->myStudy->StudyId();
4876         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4877           aVisualObj->Update(true);
4878         }
4879       }
4880     }
4881   }catch(SALOME::SALOME_Exception& exc) {
4882     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4883   }catch(const std::exception& exc){
4884     INFOS("Follow exception was cought:\n\t"<<exc.what());
4885   }catch(...){
4886     INFOS("Unknown exception was cought !!!");
4887   }
4888 }
4889 //=============================================================================
4890 /*!
4891  *
4892  */
4893 //=============================================================================
4894 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr theMesh, 
4895                        float x, float y, float z)
4896 {
4897   QAD_WaitCursor wc;
4898   try{
4899     SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4900     CORBA::String_var anEntry = aSobj->GetID();
4901     if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4902       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4903       aMeshEditor->AddNode(x, y, z);
4904       if(myAutomaticUpdate){
4905         CORBA::Long anId = smeshGUI->myStudy->StudyId();
4906         if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4907           aVisualObj->Update(true);
4908         }
4909       }
4910     }
4911   }catch(SALOME::SALOME_Exception& exc) {
4912     INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4913   }catch(const std::exception& exc){
4914     INFOS("Follow exception was cought:\n\t"<<exc.what());
4915   }catch(...){
4916     INFOS("Unknown exception was cought !!!");
4917   }
4918 }
4919 //=============================================================================
4920 /*!
4921  *
4922  */
4923 //=============================================================================
4924 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
4925 {
4926         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4927                 return;
4928
4929         EraseSimulationActors();
4930         mySimulationActors2D = vtkActor2DCollection::New();
4931
4932         vtkRenderer *theRenderer =
4933                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4934                 getRightFrame()->getViewFrame())->getRenderer();
4935
4936         vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
4937         gs2->SetGlyphTypeToTriangle();
4938         gs2->FilledOff();
4939
4940         vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
4941         legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
4942         legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.);       //relative to Position
4943
4944         legend->SetNumberOfEntries(4);
4945         legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
4946         legend->SetEntrySymbol(0, gs2->GetOutput());
4947         legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
4948         legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
4949         legend->SetEntrySymbol(1, gs2->GetOutput());
4950         legend->SetEntryColor(1,
4951                 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
4952         legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
4953         legend->SetEntrySymbol(2, gs2->GetOutput());
4954         legend->SetEntryColor(2,
4955                 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
4956         legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
4957         legend->SetEntrySymbol(3, gs2->GetOutput());
4958         legend->SetEntryColor(3,
4959                 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
4960         legend->SetPadding(5);
4961         //  legend->GetProperty()->SetColor();
4962
4963         mySimulationActors2D->AddItem(legend);
4964         theRenderer->AddActor2D(legend);
4965
4966         // Update the view
4967         myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
4968                 Repaint();
4969 }
4970
4971 //===============================================================================
4972 // function : OnEditDelete()
4973 // purpose  :
4974 //===============================================================================
4975 void SMESHGUI::OnEditDelete()
4976 {
4977   if (QAD_MessageBox::warn2
4978       (QAD_Application::getDesktop(),
4979        tr("SMESH_WRN_WARNING"),
4980        tr("SMESH_REALLY_DELETE"),
4981        tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
4982     return;
4983
4984   int nbSf = myActiveStudy->getStudyFramesCount();
4985
4986   Standard_Boolean found;
4987   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4988   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4989   SALOMEDS::GenericAttribute_var anAttr;
4990   SALOMEDS::AttributeIOR_var anIOR;
4991
4992   SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4993   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4994   for(; It.More(); It.Next()){
4995     Handle(SALOME_InteractiveObject) IObject = It.Value();
4996     if(IObject->hasEntry()){
4997       SALOMEDS::SObject_var SO = myStudy->FindObjectID(IObject->getEntry());
4998
4999       /* Erase child graphical objects */
5000       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5001       for(; it->More(); it->Next()){
5002         SALOMEDS::SObject_var CSO = it->Value();
5003         if(CSO->FindAttribute(anAttr, "AttributeIOR")){
5004           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5005           
5006           for(int i = 0; i < nbSf; i++){
5007             QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
5008             CORBA::String_var anEntry = CSO->GetID();
5009             if(SMESH_Actor* anActor = ::FindActorByEntry(sf,anEntry.in())){
5010               RemoveActor(sf,anActor);
5011             }
5012           }
5013         }
5014       }
5015
5016       /* Erase main graphical object */
5017       for(int i = 0; i < nbSf; i++){
5018         QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
5019         if(SMESH_Actor* anActor = ::FindActorByEntry(sf,IObject->getEntry())){
5020           RemoveActor(sf,anActor);
5021         }
5022       }
5023
5024       // Remove object(s) from data structures
5025       SALOMEDS::SObject_var obj = myStudy->FindObjectID(IObject->getEntry());
5026       if(!obj->_is_nil()){
5027         SMESH::SMESH_Group_var     aGroup = SMESH::SMESH_Group  ::_narrow(obj->GetObject());
5028         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
5029
5030         if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
5031           SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
5032           aMesh->RemoveGroup( aGroup );
5033         }
5034         else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
5035           SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
5036           aMesh->RemoveSubMesh( aSubMesh );
5037         }
5038         else {// default action: remove SObject from the study
5039           // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
5040           //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
5041           //op->start();
5042           aStudyBuilder->RemoveObjectWithChildren( obj );
5043           //op->finish();
5044         }
5045       }
5046
5047     } /* IObject->hasEntry() */
5048   } /* more/next */
5049
5050   /* Clear any previous selection */
5051   Sel->ClearIObjects();
5052   myActiveStudy->updateObjBrowser();
5053 }
5054
5055 //=======================================================================
5056 // name    : SMESHGUI::GetFilterMgr
5057 // Purpose : Get filter manager
5058 //=======================================================================
5059 SMESH::FilterManager_ptr SMESHGUI::GetFilterMgr()
5060 {
5061    return myFilterMgr;
5062 }